/* ===== Reset & Base ===== */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

:root {
    --color-primary: #1F4E79;
    --color-primary-light: #2D6FA3;
    --color-primary-dark: #163A5C;
    --color-accent: #3B82F6;
    --color-bg: #F8FAFC;
    --color-surface: #FFFFFF;
    --color-border: #E2E8F0;
    --color-text: #1E293B;
    --color-text-secondary: #64748B;
    --color-text-muted: #94A3B8;
    --color-error: #DC2626;
    --color-error-bg: #FEF2F2;
    --color-success: #16A34A;
    --color-row-alt: #F1F5F9;
    --radius: 8px;
    --radius-lg: 12px;
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
    --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.07), 0 2px 4px -2px rgba(0,0,0,0.05);
    --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.08), 0 4px 6px -4px rgba(0,0,0,0.04);
    --transition: 150ms ease;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background: var(--color-bg);
    color: var(--color-text);
    line-height: 1.6;
    min-height: 100vh;
}

/* ===== Layout ===== */
.app-container {
    max-width: 1100px;
    margin: 0 auto;
    padding: 0 24px;
}

.app-container.has-preview {
    max-width: 1600px;
}

/* ===== Header ===== */
.app-header {
    padding: 32px 0 24px;
    border-bottom: 1px solid var(--color-border);
    margin-bottom: 32px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.header-content {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.logo {
    display: flex;
    align-items: center;
    gap: 10px;
    color: var(--color-primary);
}

.logo h1 {
    font-size: 22px;
    font-weight: 700;
    letter-spacing: -0.3px;
}

.subtitle {
    color: var(--color-text-secondary);
    font-size: 14px;
    margin-left: 38px;
}

/* ===== Sections ===== */
.section {
    margin-bottom: 32px;
}

.hidden {
    display: none !important;
}

/* ===== Drop Zone ===== */
.drop-zone {
    border: 2px dashed var(--color-border);
    border-radius: var(--radius-lg);
    padding: 48px 24px;
    text-align: center;
    cursor: pointer;
    transition: border-color var(--transition), background-color var(--transition);
    background: var(--color-surface);
}

.drop-zone:hover,
.drop-zone.drag-over {
    border-color: var(--color-accent);
    background: #EFF6FF;
}

.drop-zone-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
}

.upload-icon {
    color: var(--color-text-muted);
    margin-bottom: 8px;
}

.drop-text {
    font-size: 16px;
    font-weight: 600;
    color: var(--color-text);
}

.drop-subtext {
    font-size: 14px;
    color: var(--color-text-secondary);
}

.file-types {
    font-size: 12px;
    color: var(--color-text-muted);
    margin-top: 4px;
}

/* ===== File Info ===== */
.file-info {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    padding: 16px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    box-shadow: var(--shadow-sm);
    margin-top: 16px;
}

.file-details {
    display: flex;
    align-items: center;
    gap: 10px;
    color: var(--color-text);
    font-size: 14px;
    font-weight: 500;
    min-width: 0;
}

.file-details svg {
    flex-shrink: 0;
    color: var(--color-primary);
}

#file-name {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.file-size {
    color: var(--color-text-muted);
    font-size: 13px;
    font-weight: 400;
    flex-shrink: 0;
}

/* ===== Buttons ===== */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 20px;
    border-radius: var(--radius);
    font-size: 14px;
    font-weight: 600;
    border: none;
    cursor: pointer;
    transition: all var(--transition);
    white-space: nowrap;
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-primary {
    background: var(--color-primary);
    color: white;
    flex-shrink: 0;
}

.btn-primary:hover:not(:disabled) {
    background: var(--color-primary-light);
}

.btn-secondary {
    background: var(--color-surface);
    color: var(--color-text);
    border: 1px solid var(--color-border);
}

.btn-secondary:hover:not(:disabled) {
    background: var(--color-bg);
}

.btn-export {
    background: var(--color-surface);
    color: var(--color-text-secondary);
    border: 1px solid var(--color-border);
    padding: 8px 14px;
    font-size: 13px;
}

.btn-export:hover:not(:disabled) {
    color: var(--color-primary);
    border-color: var(--color-primary);
    background: #F0F7FF;
}

.btn-icon {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--color-text-muted);
    padding: 4px;
    border-radius: 4px;
    display: flex;
    align-items: center;
    transition: color var(--transition);
}

.btn-icon:hover {
    color: var(--color-error);
}

/* ===== Progress ===== */
.progress-container {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    padding: 48px 24px;
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
    box-shadow: var(--shadow-sm);
}

.spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--color-border);
    border-top-color: var(--color-primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.progress-text {
    font-size: 15px;
    font-weight: 600;
    color: var(--color-text);
}

.progress-bar {
    width: 100%;
    max-width: 320px;
    height: 4px;
    background: var(--color-border);
    border-radius: 2px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background: var(--color-primary);
    border-radius: 2px;
    transition: width 0.5s ease;
    width: 0%;
}

.progress-note {
    font-size: 13px;
    color: var(--color-text-muted);
}

/* ===== Error ===== */
.error-container {
    background: var(--color-error-bg);
    border: 1px solid #FECACA;
    border-radius: var(--radius-lg);
    padding: 32px 24px;
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
}

.error-container svg {
    color: var(--color-error);
}

.error-text {
    font-size: 14px;
    color: var(--color-error);
    max-width: 500px;
}

/* ===== Export Toolbar ===== */
.export-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
}

.export-toolbar h2 {
    font-size: 18px;
    font-weight: 700;
    color: var(--color-text);
}

.export-buttons {
    display: flex;
    gap: 8px;
}

/* ===== Export All Toggle ===== */
.export-all-toggle {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    font-weight: 500;
    color: var(--color-text-secondary);
    cursor: pointer;
    padding: 8px 12px 8px 8px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    background: var(--color-surface);
    transition: all var(--transition);
    user-select: none;
    margin-right: 4px;
}

.export-all-toggle:hover {
    color: var(--color-primary);
    border-color: var(--color-primary);
    background: #F0F7FF;
}

.export-all-toggle input[type="checkbox"] {
    accent-color: var(--color-primary);
    width: 15px;
    height: 15px;
    cursor: pointer;
}

/* ===== Results Table ===== */
.table-wrapper {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    overflow: hidden;
    box-shadow: var(--shadow-md);
}

.results-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}

.results-table thead th {
    background: var(--color-primary);
    color: white;
    padding: 12px 16px;
    text-align: left;
    font-weight: 600;
    font-size: 13px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border-bottom: 2px solid var(--color-primary-dark);
}

.results-table tbody tr {
    border-bottom: 1px solid var(--color-border);
    transition: background-color var(--transition);
}

.results-table tbody tr:nth-child(even) {
    background: var(--color-row-alt);
}

.results-table tbody tr:hover {
    background: #E8F0FE;
}

.results-table tbody td {
    padding: 12px 16px;
    vertical-align: top;
}

.results-table tbody td:first-child {
    font-weight: 600;
    color: var(--color-primary);
    white-space: nowrap;
    width: 180px;
}

.results-table tbody td:nth-child(3) {
    width: 220px;
}

.results-table tbody td:nth-child(4),
.results-table tbody td:nth-child(5) {
    color: var(--color-text-secondary);
    font-size: 13px;
    white-space: nowrap;
    width: 120px;
}

.field-value {
    white-space: pre-wrap;
    line-height: 1.5;
}

.field-value .member-entry {
    padding: 2px 0;
}

.plain-english {
    font-size: 0.9em;
    color: #475569;
    line-height: 1.5;
}

.not-found {
    color: var(--color-text-muted);
    font-style: italic;
}

.ref-badge {
    display: inline-block;
    background: #EFF6FF;
    color: var(--color-primary);
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 12px;
    font-weight: 500;
}

/* ===== File List ===== */
.file-list {
    margin-top: 16px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.file-list-item {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: 10px 14px;
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 14px;
    box-shadow: var(--shadow-sm);
}

.file-list-item svg {
    flex-shrink: 0;
    color: var(--color-primary);
}

.file-list-item .file-item-name {
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    min-width: 0;
    flex: 1;
}

.file-list-item .file-item-size {
    color: var(--color-text-muted);
    font-size: 13px;
    flex-shrink: 0;
}

.file-list-item .btn-icon {
    flex-shrink: 0;
}

/* ===== Extract Bar ===== */
.extract-bar {
    margin-top: 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: 12px 16px;
    box-shadow: var(--shadow-sm);
}

.file-count {
    font-size: 14px;
    color: var(--color-text-secondary);
    font-weight: 500;
}

/* ===== Result Tabs ===== */
.result-tabs {
    display: flex;
    gap: 0;
    margin-bottom: 16px;
    border-bottom: 2px solid var(--color-border);
    overflow-x: auto;
}

.tab-btn {
    padding: 10px 18px;
    border: none;
    background: none;
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
    color: var(--color-text-muted);
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    white-space: nowrap;
    max-width: 200px;
    overflow: hidden;
    text-overflow: ellipsis;
    transition: color var(--transition), border-color var(--transition);
}

.tab-btn:hover {
    color: var(--color-text);
}

.tab-btn.active {
    color: var(--color-primary);
    border-bottom-color: var(--color-primary);
    font-weight: 600;
}

/* ===== New Extraction ===== */
.new-extraction {
    margin-top: 24px;
    text-align: center;
}

/* ===== Split Panel ===== */
.split-panel {
    display: flex;
    gap: 0;
    min-height: 500px;
    max-height: 80vh;
}

.split-left {
    flex: 1 1 55%;
    min-width: 300px;
    overflow: auto;
}

.split-right {
    flex: 1 1 45%;
    min-width: 250px;
    display: flex;
    flex-direction: column;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    overflow: hidden;
}

.split-divider {
    width: 6px;
    cursor: col-resize;
    background: var(--color-border);
    border-radius: 3px;
    margin: 0 4px;
    flex-shrink: 0;
    transition: background-color var(--transition);
}

.split-divider:hover,
.split-divider.dragging {
    background: var(--color-accent);
}

/* Hide preview when not available */
.split-panel.no-preview .split-right,
.split-panel.no-preview .split-divider {
    display: none;
}

.split-panel.no-preview .split-left {
    flex: 1 1 100%;
}

/* ===== Preview Toolbar ===== */
.preview-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 12px;
    border-bottom: 1px solid var(--color-border);
    background: var(--color-bg);
    flex-shrink: 0;
}

.preview-title {
    font-size: 13px;
    font-weight: 600;
    color: var(--color-text);
}

.preview-controls {
    display: flex;
    align-items: center;
    gap: 4px;
}

.preview-zoom-text {
    font-size: 12px;
    color: var(--color-text-secondary);
    min-width: 36px;
    text-align: center;
}

.preview-separator {
    width: 1px;
    height: 16px;
    background: var(--color-border);
    margin: 0 6px;
}

.preview-page-info {
    font-size: 12px;
    color: var(--color-text-secondary);
    white-space: nowrap;
}

/* ===== Preview Container ===== */
.preview-container {
    flex: 1;
    overflow-y: auto;
    padding: 12px;
    background: #525659;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
}

.preview-container canvas {
    box-shadow: var(--shadow-lg);
    background: white;
    max-width: 100%;
}

.preview-page {
    position: relative;
}

.preview-page.preview-highlight::after {
    content: "";
    position: absolute;
    inset: 0;
    background: rgba(59, 130, 246, 0.2);
    border: 3px solid var(--color-accent);
    border-radius: 4px;
    animation: highlight-fade 1.5s ease-out forwards;
    pointer-events: none;
}

@keyframes highlight-fade {
    0% { opacity: 1; }
    70% { opacity: 1; }
    100% { opacity: 0; }
}

.paragraph-overlay {
    pointer-events: none;
    z-index: 10;
    box-sizing: border-box;
}

/* ===== Preview Placeholder ===== */
.preview-placeholder {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: var(--color-text-muted);
    padding: 32px;
    text-align: center;
    gap: 8px;
}

.preview-placeholder p {
    font-size: 14px;
}

.preview-placeholder-sub {
    font-size: 12px !important;
    color: var(--color-text-muted);
}

/* ===== Clickable Page Reference Badges ===== */
.ref-badge-clickable {
    cursor: pointer;
    transition: background-color var(--transition), color var(--transition);
}

.ref-badge-clickable:hover {
    background: var(--color-primary);
    color: white;
}

/* ===== Login Overlay ===== */
.login-overlay {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.7);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.login-card {
    background: var(--color-surface);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    padding: 40px 48px;
    max-width: 400px;
    width: 90%;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
    text-align: center;
}

.login-card h2 {
    font-size: 20px;
    font-weight: 700;
    color: var(--color-text);
}

.login-card p {
    font-size: 14px;
    color: var(--color-text-secondary);
    line-height: 1.5;
}

.btn-login {
    width: 100%;
    justify-content: center;
    padding: 12px 24px;
    font-size: 15px;
    margin-top: 8px;
}

.login-error {
    color: var(--color-error);
    font-size: 13px;
    margin-top: -8px;
}

/* ===== Header User Info ===== */
.header-user {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-shrink: 0;
}

.user-email {
    font-size: 13px;
    color: var(--color-text-secondary);
    max-width: 200px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.btn-sm {
    padding: 5px 12px;
    font-size: 13px;
}

/* ===== Login Page ===== */
body.login-page {
    background: var(--color-bg);
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

.login-page-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 24px;
    gap: 20px;
}

.login-page-card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    padding: 48px 52px;
    width: 100%;
    max-width: 420px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
    text-align: center;
}

.login-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    color: var(--color-primary);
    margin-bottom: 4px;
}

.login-brand-name {
    font-size: 15px;
    font-weight: 700;
    letter-spacing: -0.2px;
    color: var(--color-primary);
}

.login-heading {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.login-heading h1 {
    font-size: 22px;
    font-weight: 700;
    color: var(--color-text);
    letter-spacing: -0.3px;
}

.login-heading p {
    font-size: 14px;
    color: var(--color-text-secondary);
    line-height: 1.5;
}

.btn-microsoft {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    width: 100%;
    margin-top: 4px;
    padding: 11px 20px;
    background: #ffffff;
    border: 1px solid #8c8c8c;
    border-radius: 4px;
    font-size: 15px;
    font-weight: 600;
    color: #5e5e5e;
    cursor: pointer;
    transition: background var(--transition), box-shadow var(--transition);
    white-space: nowrap;
}

.btn-microsoft:hover {
    background: #f3f2f1;
    box-shadow: var(--shadow-sm);
}

.btn-microsoft:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.login-page-error {
    font-size: 13px;
    color: var(--color-error);
    margin-top: -8px;
}

.login-footer {
    font-size: 12px;
    color: var(--color-text-muted);
}

/* ===== Responsive ===== */
@media (max-width: 768px) {
    .app-container {
        padding: 0 16px;
    }

    .file-info {
        flex-direction: column;
        align-items: stretch;
    }

    .export-toolbar {
        flex-direction: column;
        gap: 12px;
        align-items: flex-start;
    }

    .results-table {
        font-size: 13px;
    }

    .results-table tbody td:first-child {
        width: auto;
    }

    .table-wrapper {
        overflow-x: auto;
    }

    /* Stack split panel vertically on narrow screens */
    .split-panel {
        flex-direction: column;
        max-height: none;
    }

    .split-left {
        min-width: 0;
    }

    .split-right {
        min-width: 0;
        min-height: 400px;
    }

    .split-divider {
        width: 100%;
        height: 6px;
        cursor: row-resize;
        margin: 4px 0;
    }
}
