:root {
    --primary: #818cf8;
    --primary-hover: #6366f1;
    --bg-dark: #0f172a;
    --glass-bg: rgba(15, 23, 42, 0.65);
    --glass-border: rgba(255, 255, 255, 0.12);
    --glass-shadow: rgba(0, 0, 0, 0.25);
    --text-main: #f8fafc;
    --text-muted: #94a3b8;
    --success: #10b981;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
    /* Premium mesh gradient background */
    background-color: #0b0f19;
    background-image: 
        radial-gradient(at 10% 20%, rgba(99, 102, 241, 0.12) 0px, transparent 50%),
        radial-gradient(at 90% 80%, rgba(16, 185, 129, 0.08) 0px, transparent 50%),
        radial-gradient(at 50% 50%, rgba(139, 92, 246, 0.05) 0px, transparent 60%);
    background-attachment: fixed;
    color: var(--text-main);
    min-height: 100vh;
    padding: 3rem 1.5rem;
}

.container {
    max-width: 1000px; /* Make the container slightly tighter for a focused view */
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    gap: 2rem;
}

.glass-panel {
    background: var(--glass-bg);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid var(--glass-border);
    border-radius: 1.5rem;
    padding: 2.5rem;
    box-shadow: 0 10px 40px var(--glass-shadow), inset 0 1px 0 rgba(255,255,255,0.05);
    transition: transform 0.4s cubic-bezier(0.16, 1, 0.3, 1), box-shadow 0.4s ease;
}

.header {
    text-align: center;
    margin-bottom: 1rem;
}

.header h1 {
    font-size: 2.5rem;
    font-weight: 800;
    letter-spacing: -0.02em;
    background: linear-gradient(135deg, #e0e7ff 0%, #818cf8 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    margin-bottom: 0.75rem;
    text-shadow: 0 4px 20px rgba(99, 102, 241, 0.2);
}

.header p {
    color: var(--text-muted);
    font-size: 1.05rem;
}

/* Upload Area */
.upload-area {
    border: 2px dashed rgba(129, 140, 248, 0.4);
    border-radius: 1.25rem;
    padding: 5rem 2rem;
    text-align: center;
    cursor: pointer;
    transition: all 0.3s ease;
    background: rgba(255, 255, 255, 0.01);
}

.upload-area:hover, .upload-area.dragover {
    background: rgba(99, 102, 241, 0.08);
    border-color: #818cf8;
    transform: translateY(-2px);
}

.upload-icon {
    font-size: 3.5rem;
    color: var(--primary);
    margin-bottom: 1rem;
    filter: drop-shadow(0 4px 10px rgba(129, 140, 248, 0.3));
}

.upload-text {
    font-size: 1.25rem;
    font-weight: 600;
    margin-bottom: 0.75rem;
    color: #e2e8f0;
}

.upload-hint {
    color: var(--text-muted);
    font-size: 0.9rem;
}

#file-input {
    display: none;
}

/* Loader */
.loader {
    display: none;
    text-align: center;
    padding: 3rem 1rem;
}

.spinner {
    width: 48px;
    height: 48px;
    border: 4px solid rgba(255,255,255,0.05);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 1s cubic-bezier(0.5, 0.1, 0.4, 0.9) infinite;
    margin: 0 auto 1.5rem;
}

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

/* Gallery Area */
#gallery-section {
    display: none;
}

.gallery-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
    padding-bottom: 1.25rem;
    border-bottom: 1px solid var(--glass-border);
}

.gallery-header h2 {
    font-size: 1.25rem;
    font-weight: 500;
}

.gallery-header h2 span {
    color: var(--primary);
    font-weight: 700;
}

.btn {
    background: var(--primary);
    color: white;
    border: none;
    padding: 0.6rem 1.25rem;
    border-radius: 0.5rem;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
}

.btn:hover {
    background: var(--primary-hover);
    transform: translateY(-2px);
    box-shadow: 0 6px 15px rgba(99, 102, 241, 0.3);
}

.btn:active {
    transform: translateY(0);
}

.btn-secondary {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--glass-border);
}

.btn-secondary:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: rgba(255, 255, 255, 0.2);
    box-shadow: none;
}

/* Tighter grid for thumbnails */
.image-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    margin-bottom: 2rem;
    max-height: 55vh; /* Keep the page height reasonable */
    overflow-y: auto;
    padding-right: 0.5rem;
}

.image-grid::-webkit-scrollbar {
    width: 6px;
}
.image-grid::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.02);
    border-radius: 3px;
}
.image-grid::-webkit-scrollbar-thumb {
    background: rgba(129, 140, 248, 0.4);
    border-radius: 3px;
}
.image-grid::-webkit-scrollbar-thumb:hover {
    background: rgba(129, 140, 248, 0.8);
}

.image-card {
    background: rgba(0, 0, 0, 0.3);
    border-radius: 0.5rem;
    overflow: hidden;
    position: relative;
    cursor: pointer;
    border: 2px solid transparent;
    transition: all 0.25s ease;
    box-shadow: 0 4px 6px rgba(0,0,0,0.2);
    height: 100px; /* EXACTLY 100px as requested */
    width: auto;
    display: flex;
    flex-direction: row;
}

.image-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 12px rgba(0,0,0,0.3);
}

.image-card.selected {
    border-color: var(--success);
    box-shadow: 0 0 0 2px rgba(16, 185, 129, 0.2);
}

.image-card img {
    height: 100%;
    width: auto;
    object-fit: contain;
    display: block;
    background: #fff;
    opacity: 0.9;
    transition: opacity 0.2s;
}

.image-card:hover img {
    opacity: 1;
}

.card-overlay {
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    pointer-events: none; /* Let clicks pass through */
    background: linear-gradient(to bottom, rgba(16, 185, 129, 0.25), transparent);
    display: flex;
    align-items: flex-start;
    justify-content: flex-end;
    padding: 0.5rem;
    opacity: 0;
    transition: opacity 0.2s;
}

.image-card.selected .card-overlay {
    opacity: 1;
}

.check-icon {
    background: var(--success);
    color: white;
    width: 22px; height: 22px;
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-size: 12px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.3);
}

.card-footer {
    padding: 0.4rem 0.5rem;
    font-size: 0.7rem;
    font-weight: 500;
    color: #cbd5e1;
    text-align: center;
    background: rgba(15, 23, 42, 0.9);
    border-top: 1px solid rgba(255,255,255,0.05);
    display: flex;
    justify-content: space-between;
    gap: 0.25rem;
    overflow: hidden;
}

.card-footer-row {
    color: #94a3b8;
    white-space: nowrap;
    flex-shrink: 0;
}

.card-footer-name {
    color: #64748b;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-size: 0.65rem;
}

/* Sequence number badge (top-left) */
.card-seq {
    position: absolute;
    top: 0;
    left: 0;
    min-width: 1.6rem;
    height: 1.4rem;
    background: rgba(99, 102, 241, 0.9);
    color: #fff;
    font-size: 0.7rem;
    font-weight: 800;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 0.35rem;
    border-radius: 0 0 6px 0;
    z-index: 6;
    pointer-events: none;
    font-variant-numeric: tabular-nums;
    text-shadow: 0 1px 2px rgba(0,0,0,0.4);
}

/* Non-table image (logo/decoration) dimmed style */
.image-card.non-table {
    opacity: 0.4;
    border-color: rgba(239, 68, 68, 0.3);
    filter: grayscale(60%);
}

.image-card.non-table:hover {
    opacity: 0.75;
    filter: grayscale(20%);
}

.image-card.non-table.selected {
    opacity: 0.85;
    filter: none;
    border-color: var(--success);
}

.image-card.non-table .card-seq {
    background: rgba(239, 68, 68, 0.8);
}

/* Badge label on cards */
.card-badge {
    position: absolute;
    top: 4px;
    right: 4px;
    background: rgba(239, 68, 68, 0.85);
    color: #fff;
    font-size: 0.65rem;
    font-weight: 700;
    padding: 2px 6px;
    border-radius: 4px;
    z-index: 5;
    pointer-events: none;
    letter-spacing: 0.5px;
    backdrop-filter: blur(4px);
}

/* Gallery header action area — wraps when many buttons */
.gallery-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    align-items: center;
    justify-content: flex-end;
}

/* "原图路径" column — clickable link to open lightbox */
.path-cell {
    max-width: 240px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.path-link {
    color: #818cf8;
    text-decoration: none;
    font-size: 0.85rem;
    border-bottom: 1px dashed rgba(129, 140, 248, 0.4);
    transition: all 0.15s ease;
    cursor: pointer;
}
.path-link:hover {
    color: #c7d2fe;
    border-bottom-color: rgba(199, 210, 254, 0.7);
    background: rgba(99, 102, 241, 0.08);
}

/* Undo/Redo (上一步/下一步) buttons in the gallery header */
.btn-history {
    font-variant-numeric: tabular-nums;
    min-width: 5rem;
}
.btn-history:disabled {
    opacity: 0.38;
    cursor: not-allowed;
    pointer-events: none;
}
.btn-history:not(:disabled):hover {
    background: rgba(99, 102, 241, 0.14);
    border-color: rgba(99, 102, 241, 0.45);
    color: #c7d2fe;
}

/* Class-pick buttons act like radio buttons: at most one is .active at a
   time. Default ("not picked") is a muted outline; .active state pops with
   the category color + a ring so the user can see at a glance which class
   is currently driving the selection. */
.btn-class-pick {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    border: 1px solid rgba(148, 163, 184, 0.3);
    background: transparent;
    color: rgba(203, 213, 225, 0.65);
    opacity: 0.7;
    font-weight: 600;
    transition: all 0.2s ease;
}
.btn-class-pick:hover {
    opacity: 0.95;
    background: rgba(255,255,255,0.04);
    color: rgba(241, 245, 249, 0.9);
}
.btn-class-pick span {
    background: rgba(148, 163, 184, 0.18);
    color: rgba(203, 213, 225, 0.85);
    padding: 0.1rem 0.5rem;
    border-radius: 0.35rem;
    font-size: 0.78rem;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    min-width: 1.4rem;
    text-align: center;
    transition: all 0.2s ease;
}

/* ── Active (picked) state — colored fill + ring ── */
.btn-class-pick.active {
    opacity: 1;
    font-weight: 700;
}
.btn-class-receipt.active {
    background: rgba(16, 185, 129, 0.22);
    border-color: rgba(16, 185, 129, 0.7);
    color: #d1fae5;
    box-shadow: 0 0 0 2px rgba(16, 185, 129, 0.35);
}
.btn-class-receipt.active span { background: rgba(16, 185, 129, 0.4); color: #ecfdf5; }
.btn-class-voucher.active {
    background: rgba(249, 115, 22, 0.22);
    border-color: rgba(249, 115, 22, 0.7);
    color: #ffedd5;
    box-shadow: 0 0 0 2px rgba(249, 115, 22, 0.35);
}
.btn-class-voucher.active span { background: rgba(249, 115, 22, 0.4); color: #fff7ed; }
.btn-class-unknown.active {
    background: rgba(100, 116, 139, 0.3);
    border-color: rgba(100, 116, 139, 0.75);
    color: #f1f5f9;
    box-shadow: 0 0 0 2px rgba(100, 116, 139, 0.4);
}
.btn-class-unknown.active span { background: rgba(100, 116, 139, 0.45); color: #f8fafc; }

/* OCR-content classification badge — sits below the dimension badge.
   Three colors: receipt (绿) / bank_voucher (橙) / unknown (灰). */
.card-class-badge {
    position: absolute;
    top: 28px;
    right: 4px;
    color: #fff;
    font-size: 0.68rem;
    font-weight: 700;
    padding: 2px 7px;
    border-radius: 4px;
    z-index: 5;
    pointer-events: none;
    letter-spacing: 0.5px;
    backdrop-filter: blur(4px);
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.25);
}
.card-class-badge.receipt {
    background: rgba(16, 185, 129, 0.92);   /* emerald */
}
.card-class-badge.bank_voucher {
    background: rgba(249, 115, 22, 0.92);   /* orange */
}
.card-class-badge.unknown {
    background: rgba(100, 116, 139, 0.85);  /* slate */
}

/* Filter-tab variants for content classes */
.filter-tab.class-filter[data-filter="receipt"].active {
    background: rgba(16, 185, 129, 0.18);
    border-color: rgba(16, 185, 129, 0.45);
    color: #6ee7b7;
}
.filter-tab.class-filter[data-filter="receipt"].active span {
    background: rgba(16, 185, 129, 0.32);
    color: #d1fae5;
}
.filter-tab.class-filter[data-filter="bank_voucher"].active {
    background: rgba(249, 115, 22, 0.18);
    border-color: rgba(249, 115, 22, 0.45);
    color: #fdba74;
}
.filter-tab.class-filter[data-filter="bank_voucher"].active span {
    background: rgba(249, 115, 22, 0.32);
    color: #ffedd5;
}
.filter-tab.class-filter[data-filter="unknown"].active {
    background: rgba(100, 116, 139, 0.18);
    border-color: rgba(100, 116, 139, 0.45);
    color: #cbd5e1;
}
.filter-tab.class-filter[data-filter="unknown"].active span {
    background: rgba(100, 116, 139, 0.32);
    color: #f1f5f9;
}

/* Filter hint bar */
.filter-hint {
    background: rgba(234, 179, 8, 0.08);
    border: 1px solid rgba(234, 179, 8, 0.2);
    border-radius: 0.75rem;
    padding: 0.75rem 1.25rem;
    font-size: 0.9rem;
    color: #fbbf24;
    margin-bottom: 1.25rem;
    animation: fadeIn 0.5s ease;
}

.filter-hint strong {
    color: #f59e0b;
    font-weight: 700;
}

/* Image Filter Tab Bar */
.image-filter-bar {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1rem;
    padding: 0.35rem;
    background: rgba(15, 23, 42, 0.5);
    border-radius: 0.75rem;
    border: 1px solid rgba(255,255,255,0.06);
}

.filter-tab {
    flex: 1;
    padding: 0.5rem 0.75rem;
    border: 1px solid transparent;
    border-radius: 0.5rem;
    background: transparent;
    color: #94a3b8;
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.25s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
}

.filter-tab:hover {
    background: rgba(255,255,255,0.05);
    color: #cbd5e1;
}

.filter-tab.active {
    background: rgba(99, 102, 241, 0.15);
    border-color: rgba(99, 102, 241, 0.4);
    color: #a5b4fc;
    font-weight: 600;
}

.filter-tab span {
    background: rgba(255,255,255,0.08);
    padding: 0.1rem 0.45rem;
    border-radius: 0.35rem;
    font-size: 0.75rem;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
}

.filter-tab.active span {
    background: rgba(99, 102, 241, 0.3);
    color: #c7d2fe;
}

/* Action Area */
.action-area {
    text-align: center;
    padding-top: 1.5rem;
    border-top: 1px solid var(--glass-border);
}

.action-title {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text-muted);
    margin-bottom: 1.25rem;
}

.mode-cards {
    display: flex;
    gap: 1rem;
    justify-content: center;
    flex-wrap: wrap;
}

.mode-card {
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 1rem;
    padding: 1.5rem 1.25rem;
    width: 180px;
    cursor: pointer;
    transition: all 0.25s ease;
    text-align: center;
}

.mode-card:hover {
    background: rgba(99, 102, 241, 0.12);
    border-color: rgba(99, 102, 241, 0.4);
    transform: translateY(-4px);
    box-shadow: 0 8px 24px rgba(99, 102, 241, 0.2);
}

.mode-card:active {
    transform: translateY(-1px);
}

.mode-card.primary {
    border-color: rgba(99, 102, 241, 0.35);
    background: rgba(99, 102, 241, 0.08);
}

.mode-card.primary:hover {
    background: rgba(99, 102, 241, 0.2);
    border-color: var(--primary);
    box-shadow: 0 10px 30px rgba(99, 102, 241, 0.3);
}

.mode-card.zip-card {
    border-color: rgba(245, 158, 11, 0.3);
    background: rgba(245, 158, 11, 0.06);
}

.mode-card.zip-card:hover {
    background: rgba(245, 158, 11, 0.15);
    border-color: #f59e0b;
    box-shadow: 0 10px 30px rgba(245, 158, 11, 0.25);
}

.mode-icon {
    font-size: 2rem;
    margin-bottom: 0.5rem;
}

.mode-label {
    font-size: 1rem;
    font-weight: 700;
    color: #e2e8f0;
    margin-bottom: 0.35rem;
}

.mode-desc {
    font-size: 0.78rem;
    color: var(--text-muted);
    line-height: 1.3;
}

/* Live "N 张选中" badge under each selection-driven mode card */
.mode-count {
    margin-top: 0.6rem;
    font-size: 0.72rem;
    color: var(--text-muted);
    padding: 0.2rem 0.55rem;
    background: rgba(255, 255, 255, 0.06);
    border-radius: 0.5rem;
    display: inline-block;
    transition: all 0.2s ease;
    font-variant-numeric: tabular-nums;
}
.mode-count-num {
    color: #e2e8f0;
    font-weight: 700;
    font-size: 0.85rem;
}
/* When the count is non-zero, give it a soft accent */
.mode-card.has-selection .mode-count {
    background: rgba(99, 102, 241, 0.18);
    color: #c7d2fe;
}
.mode-card.has-selection .mode-count-num {
    color: #ffffff;
}
.mode-card.zip-card.has-selection .mode-count {
    background: rgba(245, 158, 11, 0.18);
    color: #fcd34d;
}
/* When count is 0, fade the card so it's clear you need to select first */
.mode-card[data-needs-selection="1"]:not(.has-selection) {
    opacity: 0.55;
}
.mode-card[data-needs-selection="1"]:not(.has-selection) .mode-count {
    color: #f87171;
    background: rgba(239, 68, 68, 0.12);
}

.btn-large {
    font-size: 1.15rem;
    padding: 1rem 3.5rem;
    border-radius: 4rem;
    background: linear-gradient(135deg, #6366f1 0%, #4f46e5 100%);
    box-shadow: 0 8px 25px rgba(79, 70, 229, 0.4), inset 0 1px 0 rgba(255,255,255,0.2);
    font-weight: 700;
    letter-spacing: 0.5px;
}

.btn-large:hover {
    transform: translateY(-3px);
    box-shadow: 0 12px 30px rgba(79, 70, 229, 0.5), inset 0 1px 0 rgba(255,255,255,0.3);
}

/* Progress Bar */
.progress-bar-wrap {
    width: 80%;
    max-width: 400px;
    height: 8px;
    background: rgba(255,255,255,0.08);
    border-radius: 4px;
    margin: 0.75rem auto 0;
    overflow: hidden;
}

.progress-bar {
    height: 100%;
    background: linear-gradient(90deg, #6366f1, #818cf8, #6366f1);
    background-size: 200% 100%;
    border-radius: 4px;
    transition: width 0.4s ease;
    animation: progressShimmer 1.5s linear infinite;
}

@keyframes progressShimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

.progress-image-name {
    color: var(--text-muted);
    font-size: 0.8rem;
    margin-top: 0.4rem;
    font-family: 'Cascadia Code', monospace;
    opacity: 0.7;
}

#result-area {
    display: none;
    padding: 1.5rem;
    animation: fadeIn 0.6s cubic-bezier(0.16, 1, 0.3, 1);
}

.preview-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 1rem;
}

.preview-header h2 { margin: 0; }

.preview-summary {
    color: var(--text-muted);
    margin: 0.25rem 0 0;
    font-size: 0.9rem;
}

/* ─── Result Stats Panel ──────────────────────────────── */
.result-stats {
    margin-top: 0.5rem;
}

.stats-row {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.stats-breakdown {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
}

.stats-chip {
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: #cbd5e1;
    font-size: 0.82rem;
    padding: 0.2rem 0.7rem;
    border-radius: 1rem;
    white-space: nowrap;
}

.stats-chip strong {
    color: var(--primary);
    font-weight: 700;
}

.stats-chip.merged {
    border-color: rgba(16, 185, 129, 0.3);
    background: rgba(16, 185, 129, 0.06);
}

.stats-chip.merged strong {
    color: var(--success);
}

.stats-totals {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-size: 0.95rem;
    color: #e2e8f0;
}

.stats-total-item strong {
    color: var(--success);
    font-weight: 700;
    font-size: 1.1rem;
}

.stats-divider {
    color: rgba(255, 255, 255, 0.15);
    font-size: 1rem;
}

/* Batch-consensus auto-correction badge */
.stats-consensus {
    color: #6ee7b7;
    background: rgba(16, 185, 129, 0.12);
    border: 1px solid rgba(16, 185, 129, 0.3);
    padding: 0.15rem 0.55rem;
    border-radius: 0.4rem;
    cursor: help;
}
.stats-consensus strong {
    color: #d1fae5 !important;
}

.preview-actions-top {
    display: flex;
    gap: 0.5rem;
}

.btn-sm {
    padding: 0.35rem 0.8rem;
    font-size: 0.8rem;
}

/* Sheet tabs */
.sheet-tabs {
    display: flex;
    gap: 0.35rem;
    margin-bottom: 0.75rem;
}

.sheet-tab {
    padding: 0.4rem 1rem;
    border-radius: 0.5rem 0.5rem 0 0;
    background: rgba(255,255,255,0.04);
    border: 1px solid rgba(255,255,255,0.08);
    border-bottom: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 0.85rem;
    transition: all 0.2s;
}

.sheet-tab.active {
    background: rgba(99, 102, 241, 0.15);
    color: #e2e8f0;
    border-color: rgba(99, 102, 241, 0.3);
}

/* Preview table */
/* Sticky header container — title + stats + actions + sheet-tabs + search
   bar all stay pinned to the viewport top while the user scrolls. The
   negative margin pulls the container flush with the panel's edges so the
   blurred background covers the full width when stuck. */
.result-sticky-top {
    position: sticky;
    top: 0;
    z-index: 20;
    margin: -2.5rem -2.5rem 1rem;   /* negate .glass-panel padding (2.5rem) */
    padding: 2.5rem 2.5rem 0.5rem;
    background: rgba(15, 23, 42, 0.92);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border-radius: 1.5rem 1.5rem 0 0;   /* match panel's top corners */
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
    box-shadow: 0 8px 16px -8px rgba(0, 0, 0, 0.35);
}

/* Preview search bar — sits between sheet-tabs and the table */
.preview-search-bar {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.4rem 0.75rem;
    margin-bottom: 0.75rem;
    background: rgba(15, 23, 42, 0.55);
    border: 1px solid rgba(255,255,255,0.08);
    border-radius: 0.6rem;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}
.preview-search-bar:focus-within {
    border-color: rgba(99, 102, 241, 0.55);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.15);
}
.preview-search-icon {
    color: var(--text-muted);
    font-size: 0.95rem;
}
#preview-search {
    flex: 1;
    background: transparent;
    border: none;
    outline: none;
    color: #e2e8f0;
    font-size: 0.9rem;
    padding: 0.25rem 0;
}
#preview-search::placeholder {
    color: rgba(148, 163, 184, 0.55);
}
.preview-search-clear {
    background: rgba(255,255,255,0.06);
    border: 1px solid rgba(255,255,255,0.08);
    color: var(--text-muted);
    width: 1.5rem;
    height: 1.5rem;
    border-radius: 0.35rem;
    cursor: pointer;
    font-size: 0.7rem;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    transition: all 0.15s ease;
}
.preview-search-clear:hover {
    background: rgba(239, 68, 68, 0.18);
    border-color: rgba(239, 68, 68, 0.4);
    color: #fca5a5;
}
.preview-search-stat {
    color: var(--text-muted);
    font-size: 0.78rem;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}
.preview-search-stat.matches {
    color: var(--success);
    font-weight: 600;
}
.preview-search-stat.no-match {
    color: #fca5a5;
}
/* Highlight occurrences inside cells when search is active */
.preview-table mark.search-hit {
    background: rgba(250, 204, 21, 0.32);
    color: #fef9c3;
    padding: 0 1px;
    border-radius: 2px;
}

.preview-table-wrap {
    max-height: 420px;
    overflow: auto;
    border: 1px solid rgba(255,255,255,0.08);
    border-radius: 0.5rem;
    margin-bottom: 1.25rem;
}

.preview-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.82rem;
    white-space: nowrap;
}

.preview-table thead {
    position: sticky;
    top: 0;
    z-index: 2;
}

.preview-table th {
    background: rgba(30, 27, 75, 0.95);
    padding: 0.5rem 0.65rem;
    text-align: left;
    border-bottom: 2px solid rgba(99, 102, 241, 0.3);
    font-weight: 600;
    transition: opacity 0.2s;
}

.preview-table td {
    padding: 0.35rem 0.65rem;
    border-bottom: 1px solid rgba(255,255,255,0.04);
    color: #cbd5e1;
    max-width: 200px;
    overflow: hidden;
    text-overflow: ellipsis;
    transition: opacity 0.2s;
}

.preview-table tbody tr:hover td {
    background: rgba(99, 102, 241, 0.06);
}

.row-num {
    color: var(--text-muted) !important;
    font-size: 0.75rem;
    width: 40px;
    text-align: center !important;
}

/* The "#" row-num column is always frozen on the left */
.preview-table thead .row-num,
.preview-table tbody .row-num {
    position: sticky;
    left: 0;
    z-index: 3;
    background: rgba(30, 27, 75, 0.98);
}
.preview-table tbody tr:hover .row-num {
    background: rgba(48, 42, 95, 0.98);
}

/* User-pinnable columns. The .left value is set inline by JS so multiple
   pinned columns stack horizontally with no gaps. */
.preview-table th.col-pinned,
.preview-table td.col-pinned {
    position: sticky;
    z-index: 2;
    background: rgba(30, 27, 75, 0.98);
    box-shadow: 4px 0 8px -2px rgba(0, 0, 0, 0.4);
}
.preview-table tbody tr:hover td.col-pinned {
    background: rgba(48, 42, 95, 0.98);
}
/* Pin toggle button on each header */
.col-pin-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.5rem;
    height: 1.5rem;
    margin-left: 0.35rem;
    border: 1px solid transparent;
    border-radius: 0.3rem;
    background: transparent;
    color: rgba(148, 163, 184, 0.55);
    cursor: pointer;
    font-size: 0.85rem;
    transition: all 0.15s ease;
    user-select: none;
}
.col-pin-btn:hover {
    background: rgba(99, 102, 241, 0.15);
    color: #c7d2fe;
    border-color: rgba(99, 102, 241, 0.4);
}
.col-pin-btn.active {
    background: rgba(99, 102, 241, 0.3);
    color: #ffffff;
    border-color: rgba(99, 102, 241, 0.7);
    box-shadow: 0 0 0 2px rgba(99, 102, 241, 0.25);
}

/* Wrap each th's content as a flex row so label + pin button align. */
.preview-table th[data-col] {
    /* Don't touch row-num — it's special. */
}
.preview-table th[data-col] > .col-check {
    display: inline-flex;
    vertical-align: middle;
}

/* Column checkbox label */
.col-check {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    cursor: pointer;
    white-space: nowrap;
}

.col-check input[type="checkbox"] {
    accent-color: var(--primary);
    width: 14px;
    height: 14px;
    cursor: pointer;
}

/* Preview footer */
.preview-footer {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 1rem;
    flex-wrap: wrap;
}

@keyframes fadeIn { 
    from { opacity: 0; transform: translateY(15px); } 
    to { opacity: 1; transform: translateY(0); } 
}

.success-icon {
    font-size: 5rem;
    margin-bottom: 1.5rem;
    filter: drop-shadow(0 0 20px rgba(16, 185, 129, 0.4));
}

#result-area h2 {
    font-size: 2rem;
    margin-bottom: 0.5rem;
}

/* Header positioning for gear button */
.header {
    position: relative;
}

/* Header Menu Buttons */
.header-menu {
    display: flex;
    justify-content: center;
    gap: 1rem;
    margin-top: 1.25rem;
}

.btn-menu {
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid var(--glass-border);
    color: var(--text-muted);
    padding: 0.6rem 1.5rem;
    border-radius: 2rem;
    cursor: pointer;
    font-size: 0.95rem;
    font-weight: 500;
    font-family: inherit;
    letter-spacing: 0.02em;
    transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    position: relative;
    overflow: hidden;
}

.btn-menu::before {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(135deg, rgba(99, 102, 241, 0.15), rgba(139, 92, 246, 0.08));
    opacity: 0;
    transition: opacity 0.3s ease;
}

.btn-menu:hover {
    color: var(--text-main);
    border-color: rgba(129, 140, 248, 0.4);
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(99, 102, 241, 0.15);
}

.btn-menu:hover::before {
    opacity: 1;
}

.btn-menu.active {
    color: var(--primary);
    border-color: var(--primary);
    background: rgba(99, 102, 241, 0.12);
    box-shadow: 0 0 20px rgba(99, 102, 241, 0.12), inset 0 1px 0 rgba(255,255,255,0.08);
}


/* Settings Panel */
.settings-panel {
    max-height: 0;
    overflow: hidden;
    padding: 0 2.5rem;
    border-color: transparent;
    box-shadow: none;
    transition: max-height 0.5s cubic-bezier(0.16, 1, 0.3, 1),
                padding 0.4s ease,
                border-color 0.3s ease,
                box-shadow 0.3s ease;
}

.settings-panel.open {
    padding: 2.5rem;
    border-color: var(--glass-border);
    box-shadow: 0 10px 40px var(--glass-shadow), inset 0 1px 0 rgba(255,255,255,0.05);
}

.settings-header h2 {
    font-size: 1.3rem;
    font-weight: 700;
    margin-bottom: 0.5rem;
    background: linear-gradient(135deg, #e2e8f0, #818cf8);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.settings-desc {
    color: var(--text-muted);
    font-size: 0.9rem;
    margin-bottom: 1.5rem;
    line-height: 1.6;
}

.settings-desc strong {
    color: var(--primary);
    -webkit-text-fill-color: var(--primary);
}

.settings-body label {
    display: block;
    font-weight: 500;
    margin-bottom: 0.6rem;
    color: #e2e8f0;
    font-size: 0.95rem;
}

.settings-body textarea {
    width: 100%;
    background: rgba(0, 0, 0, 0.35);
    border: 1px solid var(--glass-border);
    border-radius: 0.75rem;
    color: var(--text-main);
    font-family: 'Inter', 'Consolas', monospace;
    font-size: 0.95rem;
    padding: 1rem 1.25rem;
    resize: vertical;
    line-height: 1.9;
    transition: border-color 0.25s ease, box-shadow 0.25s ease;
}

.settings-body textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(129, 140, 248, 0.12);
}

.settings-body textarea::placeholder {
    color: rgba(148, 163, 184, 0.5);
}

.settings-separator {
    margin: 2rem 0;
    border: none;
    border-top: 1px solid rgba(129, 140, 248, 0.15);
    position: relative;
}

.settings-separator::after {
    content: '';
    position: absolute;
    top: -1px;
    left: 50%;
    transform: translateX(-50%);
    width: 60px;
    height: 2px;
    background: linear-gradient(90deg, transparent, rgba(129, 140, 248, 0.4), transparent);
}

.settings-actions {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-top: 1.5rem;
    padding-top: 1.25rem;
    border-top: 1px solid rgba(255, 255, 255, 0.06);
}

/* ─── Merge Panel ─────────────────────────────────────── */
.merge-panel {
    margin-top: 1rem;
    background: rgba(15, 23, 42, 0.7);
    border: 1px solid rgba(129, 140, 248, 0.2);
    border-radius: 1rem;
    padding: 1.5rem;
    animation: fadeIn 0.3s ease;
}

.merge-panel-header h3 {
    font-size: 1.1rem;
    font-weight: 700;
    margin-bottom: 0.3rem;
    background: linear-gradient(135deg, #e2e8f0, #818cf8);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

.merge-sheet-list {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin: 1rem 0;
    max-height: 200px;
    overflow-y: auto;
    padding: 0.5rem;
}

.merge-sheet-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid var(--glass-border);
    border-radius: 0.6rem;
    padding: 0.5rem 1rem;
    cursor: pointer;
    transition: all 0.2s ease;
    user-select: none;
    font-size: 0.9rem;
}

.merge-sheet-item:hover {
    border-color: rgba(129, 140, 248, 0.4);
    background: rgba(99, 102, 241, 0.08);
}

.merge-sheet-item.checked {
    border-color: var(--primary);
    background: rgba(99, 102, 241, 0.12);
    color: var(--text-main);
}

.merge-sheet-item input[type="checkbox"] {
    accent-color: var(--primary);
    width: 16px;
    height: 16px;
}

.merge-sheet-item .sheet-rows {
    color: var(--text-muted);
    font-size: 0.8rem;
    margin-left: 0.25rem;
}

.merge-actions {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-top: 0.75rem;
    padding-top: 0.75rem;
    border-top: 1px solid rgba(255, 255, 255, 0.06);
}

/* Special merge tab style */
.sheet-tab.merge-tab {
    background: rgba(16, 185, 129, 0.12);
    border-color: rgba(16, 185, 129, 0.3);
    color: var(--success);
}

.sheet-tab.merge-tab.active {
    background: rgba(16, 185, 129, 0.2);
    border-color: var(--success);
}

/* Toast */
.toast {
    display: none;
    padding: 0.5rem 1rem;
    border-radius: 0.5rem;
    font-size: 0.85rem;
    font-weight: 500;
    margin-left: auto;
    animation: fadeIn 0.3s ease;
    white-space: nowrap;
}

.toast.show {
    display: inline-block;
    background: rgba(16, 185, 129, 0.12);
    border: 1px solid rgba(16, 185, 129, 0.25);
    color: var(--success);
}

.toast.show.error {
    background: rgba(239, 68, 68, 0.12);
    border-color: rgba(239, 68, 68, 0.25);
    color: #f87171;
}

/* ─── Card Zoom Button ─────────────────────────────────── */
.card-zoom {
    position: absolute;
    bottom: 28px;
    right: 4px;
    width: 28px;
    height: 28px;
    background: rgba(99, 102, 241, 0.85);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    cursor: pointer;
    opacity: 0;
    transform: scale(0.7);
    transition: all 0.2s ease;
    z-index: 6;
    box-shadow: 0 2px 8px rgba(0,0,0,0.4);
}

.image-card:hover .card-zoom {
    opacity: 1;
    transform: scale(1);
}

.card-zoom:hover {
    background: rgba(99, 102, 241, 1);
    transform: scale(1.15);
}

/* ─── Lightbox Overlay ─────────────────────────────────── */
.lightbox-overlay {
    position: fixed;
    inset: 0;
    z-index: 9999;
    background: rgba(0, 0, 0, 0.88);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: opacity 0.3s ease, visibility 0.3s ease;
}

.lightbox-overlay.open {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
}

/* Close button */
.lightbox-close {
    position: absolute;
    top: 1.25rem;
    right: 1.5rem;
    font-size: 2.5rem;
    color: rgba(255,255,255,0.6);
    cursor: pointer;
    line-height: 1;
    transition: color 0.2s, transform 0.2s;
    z-index: 10001;
}

.lightbox-close:hover {
    color: #fff;
    transform: scale(1.2);
}

/* Toolbar */
.lightbox-toolbar {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 1rem;
    z-index: 10001;
}

.lightbox-btn {
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.15);
    color: #fff;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    font-size: 1.4rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.lightbox-btn:hover {
    background: rgba(99, 102, 241, 0.5);
    border-color: var(--primary);
    transform: scale(1.1);
}

.lightbox-btn:active {
    transform: scale(0.95);
}

.lightbox-angle {
    color: rgba(255, 255, 255, 0.7);
    font-size: 0.95rem;
    font-weight: 600;
    min-width: 40px;
    text-align: center;
    font-variant-numeric: tabular-nums;
}

/* Image container */
.lightbox-img-wrap {
    max-width: 90vw;
    max-height: 72vh;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: visible;
}

.lightbox-img-wrap img {
    max-width: 90vw;
    max-height: 72vh;
    object-fit: contain;
    border-radius: 0.5rem;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
    transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1);
    background: #fff;
}

/* Footer caption */
.lightbox-footer {
    margin-top: 1rem;
    color: rgba(255, 255, 255, 0.55);
    font-size: 0.9rem;
    font-weight: 500;
    z-index: 10001;
}

/* ─── Data-Only Sheets Info ──────────────────────────── */
.data-sheets-info {
    background: rgba(16, 185, 129, 0.06);
    border: 1px solid rgba(16, 185, 129, 0.15);
    border-radius: 0.75rem;
    padding: 1.25rem;
    margin-bottom: 1.5rem;
    animation: fadeIn 0.4s ease;
}

.sheets-summary {
    font-size: 1.05rem;
    color: #e2e8f0;
    margin-bottom: 1rem;
    padding-bottom: 0.75rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.sheets-summary strong {
    color: var(--success);
    font-weight: 700;
    font-size: 1.15rem;
}

.sheets-list {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.sheet-info-card {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 0.5rem;
    padding: 0.5rem 1rem;
    transition: all 0.2s ease;
}

.sheet-info-card:hover {
    border-color: rgba(16, 185, 129, 0.3);
    background: rgba(16, 185, 129, 0.06);
}

.sheet-info-idx {
    background: rgba(16, 185, 129, 0.2);
    color: var(--success);
    width: 22px;
    height: 22px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.75rem;
    font-weight: 700;
    flex-shrink: 0;
}

.sheet-info-name {
    font-weight: 600;
    color: #e2e8f0;
    font-size: 0.9rem;
}

.sheet-info-detail {
    color: var(--text-muted);
    font-size: 0.8rem;
    flex-shrink: 0;
}

.sheet-info-card.merged {
    border-color: rgba(16, 185, 129, 0.3);
    background: rgba(16, 185, 129, 0.06);
}

.batch-files-list {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
    margin: 0.75rem 0;
    padding-bottom: 0.75rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.batch-file-tag {
    background: rgba(99, 102, 241, 0.12);
    border: 1px solid rgba(99, 102, 241, 0.25);
    color: #a5b4fc;
    font-size: 0.8rem;
    padding: 0.25rem 0.65rem;
    border-radius: 1rem;
    white-space: nowrap;
}

/* ─── Batch Upload File List ──────────────────────────── */
.upload-file-list {
    margin-top: 1rem;
    background: rgba(0, 0, 0, 0.25);
    border: 1px solid rgba(129, 140, 248, 0.15);
    border-radius: 0.75rem;
    padding: 1rem 1.25rem;
    animation: fadeIn 0.3s ease;
}

.file-list-title {
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--primary);
    margin-bottom: 0.75rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.file-list-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.4rem 0;
    font-size: 0.88rem;
    color: #cbd5e1;
    border-bottom: 1px solid rgba(255, 255, 255, 0.03);
}

.file-list-item:last-child {
    border-bottom: none;
}

.file-list-idx {
    background: rgba(99, 102, 241, 0.2);
    color: var(--primary);
    width: 22px;
    height: 22px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.75rem;
    font-weight: 700;
    flex-shrink: 0;
}

.file-list-name {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.file-list-size {
    color: var(--text-muted);
    font-size: 0.8rem;
    flex-shrink: 0;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(-8px); }
    to { opacity: 1; transform: translateY(0); }
}
