/* ============================================================
   CA Helper — Main Stylesheet
   ============================================================ */

/* --- Design Tokens --- */
:root {
    --color-primary: #1a1a2e;
    --color-primary-light: #16213e;
    --color-primary-hover: #1a4a8a;
    --color-accent: #0f3460;
    --color-accent-light: #eef2ff;

    --color-credit: #0a7;
    --color-debit: #c44;
    --color-warning: #f59e0b;
    --color-error: #dc2626;
    --color-success: #0a7;

    --color-text: #333;
    --color-text-light: #555;
    --color-text-muted: #888;
    --color-text-faint: #aaa;

    --color-bg: #f5f5f5;
    --color-bg-white: #fff;
    --color-bg-hover: #f0f4ff;
    --color-border: #eee;
    --color-border-dark: #333;

    --font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    --font-mono: "SF Mono", "Fira Code", "Consolas", monospace;

    --radius-sm: 4px;
    --radius-md: 6px;
    --radius-lg: 8px;
    --radius-xl: 10px;
    --radius-2xl: 12px;

    --shadow-sm: 0 1px 3px rgba(0,0,0,0.1);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.1);
    --shadow-lg: 0 8px 30px rgba(0,0,0,0.2);
    --shadow-xl: 0 25px 60px rgba(0,0,0,0.4);
}

/* --- Sidebar User Section --- */
.sidebar-user {
    border-top: 1px solid #333;
    margin-top: 8px;
    padding: 12px 0 4px;
    font-size: 12px;
}
.sidebar-user-name {
    color: #ccc; font-weight: 600;
    padding: 0 4px; margin-bottom: 6px;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.sidebar-user-actions {
    display: flex; gap: 8px; padding: 0 4px;
}
.sidebar-user-link {
    color: #999; text-decoration: none; font-size: 11px;
    transition: color 0.2s;
}
.sidebar-user-link:hover { color: #fff; }
.sidebar-user-signout:hover { color: var(--color-debit); }

/* --- Reset --- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
body {
    font-family: var(--font-family);
    background: var(--color-bg);
    color: var(--color-text);
    line-height: 1.5;
}

/* ============================================================
   LAYOUT — Main App (Sidebar + Content)
   ============================================================ */
.container { display: flex; min-height: 100vh; gap: 0; }

/* --- Upload Panel (Sidebar) --- */
.upload-panel {
    width: 300px; min-width: 300px;
    background: var(--color-primary); color: #eee;
    padding: 24px; display: flex; flex-direction: column; gap: 20px;
    position: relative; z-index: 10;
    transition: width 0.25s ease, min-width 0.25s ease, padding 0.25s ease;
    overflow: hidden;
}
.upload-panel.collapsed {
    width: 60px; min-width: 60px; padding: 16px 8px;
    align-items: center;
}
.upload-panel.collapsed .panel-header h1,
.upload-panel.collapsed .sidebar-nav,
.upload-panel.collapsed .sidebar-user,
.upload-panel.collapsed .sidebar-expanded-only {
    display: none;
}
.upload-panel.collapsed .panel-header {
    border-bottom: none; padding-bottom: 0; justify-content: center;
}
.upload-panel.collapsed .sidebar-toggle {
    font-size: 20px;
}
.sidebar-toggle {
    background: none; border: none; color: #aaa; cursor: pointer;
    font-size: 18px; padding: 4px; transition: color 0.2s; line-height: 1;
}
.sidebar-toggle:hover { color: #fff; }
.upload-panel h1 { font-size: 20px; color: #fff; line-height: 1; }
.upload-panel h2 {
    font-size: 12px; color: var(--color-text-faint);
    text-transform: uppercase; letter-spacing: 1px; font-weight: 600;
}

/* Sidebar navigation tabs */
.sidebar-nav {
    display: flex; flex-direction: column; gap: 2px;
}
.sidebar-nav-item {
    display: block; padding: 10px 14px; font-size: 14px; font-weight: 500;
    color: #aaa; text-decoration: none; border-radius: var(--radius-md);
    transition: all 0.2s;
}
.sidebar-nav-item:hover { background: rgba(255,255,255,0.06); color: #fff; }
.sidebar-nav-item.active {
    background: rgba(255,255,255,0.1); color: #fff; font-weight: 600;
}
.sidebar-nav-item.sub {
    padding-left: 28px; font-size: 13px;
}

/* Sidebar expandable groups */
.sidebar-nav-group { margin: 0; }
.sidebar-nav-group-label {
    display: flex; align-items: center; justify-content: space-between;
    padding: 10px 14px; font-size: 14px; font-weight: 500;
    color: #aaa; cursor: pointer; border-radius: var(--radius-md);
    transition: all 0.2s; user-select: none;
}
.sidebar-nav-group-label:hover { background: rgba(255,255,255,0.06); color: #fff; }
.sidebar-nav-group-label.active { color: #fff; font-weight: 600; }
.sidebar-nav-arrow {
    font-size: 10px; transition: transform 0.2s; display: inline-block;
}
.sidebar-nav-group-label.expanded .sidebar-nav-arrow {
    transform: rotate(180deg);
}
.sidebar-nav-group-items {
    display: none; flex-direction: column; gap: 1px;
}
.sidebar-nav-group-items.open { display: flex; }

/* Header bar with actions */
.panel-header {
    display: flex; align-items: center; justify-content: space-between;
    border-bottom: 1px solid var(--color-border-dark); padding-bottom: 12px;
}
.panel-header-actions { display: flex; gap: 8px; align-items: center; }
.panel-header-actions a {
    font-size: 12px; text-decoration: none; padding: 4px 10px;
    border: 1px solid; border-radius: var(--radius-sm); transition: all 0.2s;
}
.action-clear { color: #c97a4a; border-color: #7a4a2a; }
.action-clear:hover { color: #ffaa66; border-color: #aa6633; }
.action-report { color: #7eb8da; border-color: #3a6a8a; }
.action-report:hover { color: #aad4f0; border-color: #5a8aaa; }
.action-signout { color: #888; border-color: #444; }
.action-signout:hover { color: #fff; border-color: #666; }

/* Mobile hamburger */
.mobile-toggle {
    display: none;
    position: fixed; top: 12px; left: 12px; z-index: 100;
    background: var(--color-primary); color: #fff; border: none;
    width: 40px; height: 40px; border-radius: var(--radius-lg);
    font-size: 20px; cursor: pointer; box-shadow: var(--shadow-md);
    align-items: center; justify-content: center;
}
.mobile-overlay {
    display: none; position: fixed; inset: 0;
    background: rgba(0,0,0,0.5); z-index: 9;
}
.mobile-overlay.active { display: block; }

/* --- Upload Form --- */
.upload-form { display: flex; flex-direction: column; gap: 12px; }

/* Drag-and-drop zone */
.drop-zone {
    border: 2px dashed #445; border-radius: var(--radius-lg);
    padding: 24px 16px; text-align: center; cursor: pointer;
    background: var(--color-primary-light);
    transition: all 0.3s ease; position: relative;
}
.drop-zone:hover, .drop-zone.drag-active {
    border-color: #7eb8da; background: rgba(15, 52, 96, 0.6);
}
.drop-zone.drag-active { transform: scale(1.02); }
.drop-zone-icon {
    font-size: 32px; margin-bottom: 8px; display: block; opacity: 0.6;
    pointer-events: none;
}
.drop-zone-text {
    font-size: 13px; color: #aaa; line-height: 1.5;
    pointer-events: none;
}
.drop-zone-text strong { color: #ccc; }
.drop-zone input[type=file] {
    position: absolute; width: 1px; height: 1px; opacity: 0;
    overflow: hidden; pointer-events: none;
}
.drop-zone-filename {
    display: none; margin-top: 8px; font-size: 12px; color: #e0e0e0;
    word-break: break-all; pointer-events: none;
}
.drop-zone-filename.active { display: block; }

.password-input {
    width: 100%; padding: 8px 12px; background: var(--color-primary-light);
    border: 1px solid #445; border-radius: var(--radius-md);
    color: #ccc; font-size: 14px; transition: border-color 0.2s;
}
.password-input:focus { border-color: #7eb8da; outline: none; }

.supported-text { font-size: 11px; color: #666; text-align: center; }
.statement-count {
    text-align: center; margin-top: 8px; font-size: 12px; color: #667;
}

/* --- Buttons --- */
.btn {
    padding: 10px 16px; border: none; border-radius: var(--radius-md);
    cursor: pointer; font-size: 14px; font-weight: 600;
    transition: all 0.2s; text-align: center; display: inline-block;
    text-decoration: none;
}
.btn-primary { background: var(--color-accent); color: #fff; }
.btn-primary:hover { background: var(--color-primary-hover); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-download {
    background: var(--color-primary-light); color: #ccc; font-size: 13px;
}
.btn-download:hover { background: var(--color-primary-hover); color: #fff; }
.btn-toggle {
    padding: 6px 14px; border: 1px solid #ccc; border-radius: var(--radius-md);
    cursor: pointer; font-size: 13px; background: var(--color-bg-white);
    color: var(--color-text-light); margin-left: 12px;
}
.btn-toggle:hover { background: var(--color-accent-light); border-color: #99b; }

.downloads { display: flex; flex-direction: column; gap: 8px; margin-top: 8px; }

/* Upload progress bar */
.upload-progress {
    display: none; flex-direction: column; gap: 6px; margin-top: 4px;
}
.upload-progress.active { display: flex; }
.progress-bar-track {
    height: 4px; background: #333; border-radius: 2px; overflow: hidden;
}
.progress-bar-fill {
    height: 100%; background: #7eb8da; border-radius: 2px;
    width: 0%; transition: width 0.3s ease;
}
.progress-text { font-size: 11px; color: #888; text-align: center; }

/* --- Results Panel --- */
.results-panel { flex: 1; padding: 24px 28px; overflow-x: auto; min-width: 0; }
.results-panel h2 { font-size: 18px; margin-bottom: 16px; color: var(--color-primary); }

/* Error & placeholder */
.error-msg {
    background: #ffe0e0; color: #900; padding: 14px 18px;
    border-radius: var(--radius-lg); margin-bottom: 16px;
    border-left: 4px solid #c44; font-size: 14px; line-height: 1.5;
}
.error-msg strong { display: block; margin-bottom: 4px; }
.placeholder {
    color: #999; font-size: 16px; margin-top: 60px; text-align: center;
    line-height: 1.8;
}
.placeholder-icon { font-size: 48px; display: block; margin-bottom: 12px; opacity: 0.3; }

/* Privacy banner */
.privacy-banner {
    display: flex; align-items: center; gap: 10px;
    background: #e6f4ea; border: 1px solid #b7e1c8; border-radius: var(--radius-lg);
    padding: 10px 16px; margin-bottom: 16px; font-size: 13px; color: #1b5e20;
}
.privacy-banner-icon { font-size: 18px; flex-shrink: 0; }

/* --- Statement Info --- */
.stmt-info {
    margin-bottom: 20px; padding: 14px 18px;
    background: #e8edf5; border-radius: var(--radius-lg);
}
.stmt-info .name { font-size: 18px; font-weight: 700; color: var(--color-primary); }
.stmt-info .detail { font-size: 13px; color: var(--color-text-light); margin-top: 4px; }

/* --- Analysis Toggle --- */
.analysis-toggle { display: flex; gap: 0; margin-bottom: 20px; }
.analysis-toggle a {
    padding: 8px 20px; font-size: 14px; font-weight: 600; text-decoration: none;
    border: 2px solid var(--color-primary); cursor: pointer; transition: all 0.2s;
}
.analysis-toggle a:first-child { border-radius: var(--radius-md) 0 0 var(--radius-md); }
.analysis-toggle a:last-child { border-radius: 0 var(--radius-md) var(--radius-md) 0; border-left: none; }
.analysis-toggle a.active { background: var(--color-primary); color: #fff; }
.analysis-toggle a:not(.active) { background: var(--color-bg-white); color: var(--color-primary); }
.analysis-toggle a:not(.active):hover { background: var(--color-accent-light); }

/* --- Summary Cards --- */
.summary-cards { display: flex; gap: 14px; margin-bottom: 24px; flex-wrap: wrap; }
.card {
    background: var(--color-bg-white); border-radius: var(--radius-lg);
    padding: 16px 20px; box-shadow: var(--shadow-sm); min-width: 150px;
    flex: 1;
}
.card .label {
    font-size: 11px; color: var(--color-text-muted);
    text-transform: uppercase; letter-spacing: 0.5px; font-weight: 600;
}
.card .value {
    font-size: 22px; font-weight: 700; color: var(--color-primary);
    margin-top: 4px; font-variant-numeric: tabular-nums;
}
.card .value.amount-credit { color: var(--color-credit); }
.card .value.amount-debit { color: var(--color-debit); }

/* ============================================================
   TABLES
   ============================================================ */
.table-section { margin-bottom: 32px; }
.table-section h3 {
    font-size: 15px; margin-bottom: 10px; color: var(--color-text-light);
    display: inline;
}
table {
    border-collapse: collapse; width: 100%; background: var(--color-bg-white);
    border-radius: var(--radius-lg); box-shadow: var(--shadow-sm);
}
table:not(.crosstab) { overflow: hidden; }
th {
    background: var(--color-primary); color: #fff;
    padding: 10px 12px; text-align: left;
    font-size: 13px; font-weight: 600; white-space: nowrap;
    position: sticky; top: 0; z-index: 2;
}
td { padding: 8px 12px; font-size: 13px; border-bottom: 1px solid var(--color-border); }
tr:nth-child(even) td { background: #fafafa; }
tr:hover td { background: var(--color-bg-hover); }
.num {
    text-align: right; font-variant-numeric: tabular-nums;
    white-space: nowrap; font-family: var(--font-mono); font-size: 12px;
}
.total-row td {
    font-weight: 700; background: #e8edf5 !important;
    border-top: 2px solid var(--color-primary);
}
.month-header td {
    background: var(--color-accent-light) !important;
    font-weight: 700; color: var(--color-primary); font-size: 14px;
}
.month-header:hover td { background: #dce4f5 !important; }
.month-arrow {
    display: inline-block; font-size: 10px; margin-right: 6px;
    transition: transform 0.15s;
}

/* --- Crosstab Table --- */
.crosstab, .crosstab th, .crosstab td,
.crosstab tr td, .crosstab tr:nth-child(even) td,
.crosstab tr:hover td, .crosstab .total-row td,
.crosstab .sg-row td, .crosstab .sg-child td {
    background: var(--color-bg-white) !important; color: #000 !important;
}
.crosstab thead th {
    position: sticky; top: 0; z-index: 3;
    background: var(--color-bg-white) !important;
    border-bottom: 2px solid #000 !important;
    box-shadow: 0 2px 4px rgba(0,0,0,0.08);
}
.crosstab .total-row td { border-top: 2px solid #000 !important; }

.crosstab-wrapper {
    overflow-x: auto; overflow-y: auto;
    max-height: 70vh;
    position: relative;
}
.crosstab th, .crosstab td { padding: 6px 10px; font-size: 12px; }
.crosstab td:first-child, .crosstab th:first-child {
    position: sticky; left: 0; z-index: 1;
    background: var(--color-bg-white) !important;
    white-space: nowrap; min-width: 120px;
}
.crosstab thead th:first-child { z-index: 4; }
.crosstab td:first-child { font-weight: 600; cursor: pointer; }
.crosstab td:first-child:hover { text-decoration: underline; }

/* Sort select in crosstab header */
.sort-select {
    font-size: 11px; padding: 1px 4px; margin-left: 6px;
    background: #fff; color: #000; border: 1px solid #ccc;
    border-radius: 3px; cursor: pointer;
}

/* --- Tiered Crosstab: Super-group rows --- */
.sg-row { cursor: pointer; }
.sg-row td { font-weight: 700; }
.sg-name { display: flex; align-items: center; gap: 6px; }
.sg-arrow {
    font-size: 10px; transition: transform 0.2s; display: inline-block;
}
.sg-arrow.open { transform: rotate(90deg); }
.sg-child td:first-child { font-weight: 400; }

/* Action icons in crosstab */
.rename-icon, .move-sg-icon {
    cursor: pointer; font-size: 10px; margin-left: 4px;
    opacity: 0.4; transition: opacity 0.2s;
}
.sg-child:hover .rename-icon,
.sg-child:hover .move-sg-icon { opacity: 1; }

/* --- Filter Bar --- */
.filter-bar {
    display: none; align-items: center; gap: 10px;
    margin-bottom: 16px; padding: 10px 16px;
    background: var(--color-accent-light); border: 1px solid #c5d0f0;
    border-radius: var(--radius-lg); font-size: 14px; color: var(--color-primary);
}
.filter-bar.active { display: flex; }
.filter-bar .filter-label { font-weight: 600; }
.filter-bar .btn-clear {
    margin-left: auto; padding: 4px 12px; border: 1px solid #99b;
    border-radius: var(--radius-sm); background: var(--color-bg-white);
    color: var(--color-text-light); cursor: pointer; font-size: 13px;
}
.filter-bar .btn-clear:hover { background: #f0f0f0; }

/* --- Group Tags --- */
.group-tag {
    display: inline-block; padding: 2px 8px; border-radius: var(--radius-sm);
    font-size: 11px; font-weight: 600; background: var(--color-accent-light); color: #336;
    white-space: nowrap;
}
.group-tag.editable { cursor: pointer; border: 1px dashed transparent; }
.group-tag.editable:hover { border-color: #99b; background: #dde4ff; }
.group-tag.filter-icon {
    cursor: pointer; margin-left: 2px; background: #f0f0f0;
    color: var(--color-text-muted); font-size: 10px;
}
.super-group-label {
    font-size: 9px; color: var(--color-text-muted); margin-bottom: 1px;
}

/* ============================================================
   CATEGORY EDIT MODAL
   ============================================================ */
.cat-edit-overlay {
    display: none; position: fixed; inset: 0;
    background: rgba(0,0,0,0.4); z-index: 1000;
}
.cat-edit-overlay.active { display: flex; align-items: center; justify-content: center; }
.cat-edit-modal {
    background: var(--color-bg-white); border-radius: var(--radius-xl);
    padding: 20px; width: 340px; box-shadow: var(--shadow-lg);
    max-height: 70vh; display: flex; flex-direction: column;
}
.cat-edit-modal h4 { margin: 0 0 4px; font-size: 15px; color: var(--color-primary); }
.cat-edit-modal .txn-desc {
    font-size: 12px; color: #777; margin-bottom: 12px; word-break: break-all;
}
.cat-edit-modal .cat-search {
    width: 100%; padding: 8px 10px; border: 1px solid #ccc;
    border-radius: var(--radius-md); font-size: 13px;
    margin-bottom: 8px; outline: none;
}
.cat-edit-modal .cat-search:focus { border-color: var(--color-accent); }
.cat-edit-modal .cat-list {
    list-style: none; padding: 0; margin: 0; overflow-y: auto; max-height: 40vh;
    border: 1px solid #e0e0e0; border-radius: var(--radius-md);
}
.cat-edit-modal .cat-list li {
    padding: 8px 12px; font-size: 13px; cursor: pointer;
    border-bottom: 1px solid #f0f0f0;
}
.cat-edit-modal .cat-list li:last-child { border-bottom: none; }
.cat-edit-modal .cat-list li:hover { background: var(--color-accent-light); }
.cat-edit-modal .cat-list li.current { background: #e0e8ff; font-weight: 600; }
.cat-edit-modal .cat-list li.add-new {
    color: var(--color-accent); font-weight: 600; border-top: 2px solid #e0e0e0;
}
.cat-edit-modal .new-cat-input {
    display: none; margin-top: 10px; gap: 8px;
}
.cat-edit-modal .new-cat-input.active { display: flex; }
.cat-edit-modal .new-cat-input input {
    flex: 1; padding: 8px; border: 1px solid #ccc;
    border-radius: var(--radius-md); font-size: 13px;
}
.cat-edit-modal .new-cat-input button {
    padding: 8px 14px; background: var(--color-accent); color: #fff;
    border: none; border-radius: var(--radius-md); font-size: 13px;
    cursor: pointer; font-weight: 600;
}
.cat-edit-modal .btn-cancel {
    margin-top: 10px; padding: 6px; background: none;
    border: 1px solid #ccc; border-radius: var(--radius-md);
    cursor: pointer; font-size: 13px; color: #666;
}

/* ============================================================
   TOAST NOTIFICATIONS
   ============================================================ */
.toast-container {
    position: fixed; top: 20px; right: 20px; z-index: 9999;
    display: flex; flex-direction: column; gap: 8px;
    pointer-events: none;
}
.toast {
    padding: 12px 20px; border-radius: var(--radius-lg);
    font-size: 14px; font-weight: 500; color: #fff;
    box-shadow: var(--shadow-md); pointer-events: auto;
    transform: translateX(120%); transition: transform 0.3s ease;
    max-width: 360px;
}
.toast.show { transform: translateX(0); }
.toast-info { background: var(--color-primary); }
.toast-success { background: #0a7; }
.toast-error { background: #c44; }
.toast-warning { background: #e67e22; }

/* ============================================================
   ONBOARDING TOUR
   ============================================================ */
.tour-overlay {
    position: fixed; inset: 0; background: rgba(0,0,0,0.5); z-index: 8000;
}
.tour-tooltip {
    position: fixed; z-index: 8001; background: var(--color-bg-white);
    border-radius: var(--radius-2xl); padding: 16px 20px; max-width: 320px;
    box-shadow: var(--shadow-lg);
}
.tour-tooltip p { font-size: 14px; color: var(--color-text); margin-bottom: 12px; line-height: 1.5; }
.tour-tooltip-actions { display: flex; gap: 8px; justify-content: flex-end; }
.tour-tooltip-actions button {
    padding: 6px 14px; border-radius: var(--radius-md); font-size: 13px;
    cursor: pointer; font-weight: 600;
}
.tour-btn-next {
    background: var(--color-accent); color: #fff; border: none;
}
.tour-btn-skip {
    background: none; border: 1px solid #ccc; color: #666;
}
.tour-step-indicator {
    font-size: 11px; color: var(--color-text-muted); margin-bottom: 4px;
}

/* ============================================================
   LOADING SKELETON
   ============================================================ */
.skeleton {
    background: linear-gradient(90deg, #e0e0e0 25%, #f0f0f0 50%, #e0e0e0 75%);
    background-size: 200% 100%;
    animation: skeleton-pulse 1.5s infinite;
    border-radius: var(--radius-md);
}
@keyframes skeleton-pulse {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}
.skeleton-card { height: 80px; }
.skeleton-table { height: 200px; margin-top: 16px; }

/* ============================================================
   LOGIN PAGE
   ============================================================ */
.login-body {
    min-height: 100vh; display: flex; align-items: center; justify-content: center;
    background: linear-gradient(135deg, #1a1a2e 0%, #16213e 50%, #0f3460 100%);
}
.login-container {
    display: flex; width: 900px; max-width: 95vw; min-height: 520px;
    border-radius: 16px; overflow: hidden; box-shadow: var(--shadow-xl);
}
.brand-panel {
    flex: 1; background: linear-gradient(160deg, #1a1a2e 0%, #0f3460 100%);
    padding: 48px 40px; display: flex; flex-direction: column;
    justify-content: center; position: relative; overflow: hidden;
}
.brand-panel::before {
    content: ''; position: absolute; top: -80px; right: -80px;
    width: 250px; height: 250px; background: rgba(255,255,255,0.03); border-radius: 50%;
}
.brand-panel::after {
    content: ''; position: absolute; bottom: -60px; left: -60px;
    width: 200px; height: 200px; background: rgba(255,255,255,0.02); border-radius: 50%;
}
.brand-logo {
    width: 56px; height: 56px; background: rgba(255,255,255,0.1);
    border-radius: 14px; display: flex; align-items: center; justify-content: center;
    font-size: 24px; font-weight: 800; color: #fff; margin-bottom: 28px;
    backdrop-filter: blur(10px); border: 1px solid rgba(255,255,255,0.1);
}
.brand-panel h1 { font-size: 28px; font-weight: 700; color: #fff; line-height: 1.3; margin-bottom: 12px; }
.brand-panel p { font-size: 15px; color: rgba(255,255,255,0.6); line-height: 1.6; }
.brand-features { margin-top: 32px; display: flex; flex-direction: column; gap: 14px; }
.brand-feature { display: flex; align-items: center; gap: 12px; font-size: 14px; color: rgba(255,255,255,0.7); }
.brand-feature .icon {
    width: 32px; height: 32px; background: rgba(255,255,255,0.08);
    border-radius: 8px; display: flex; align-items: center; justify-content: center;
    font-size: 15px; flex-shrink: 0;
}

.form-panel {
    flex: 1; background: var(--color-bg-white); padding: 48px 40px;
    display: flex; flex-direction: column; justify-content: center;
}
.form-panel h2 { font-size: 24px; font-weight: 700; color: var(--color-primary); margin-bottom: 6px; }
.form-panel .subtitle { font-size: 14px; color: var(--color-text-muted); margin-bottom: 32px; }
.form-group { margin-bottom: 20px; }
.form-group label {
    display: block; font-size: 13px; font-weight: 600; color: var(--color-text-light);
    margin-bottom: 6px; text-transform: uppercase; letter-spacing: 0.5px;
}
.form-group input {
    width: 100%; padding: 12px 16px; font-size: 15px;
    border: 2px solid #e0e0e0; border-radius: var(--radius-xl);
    outline: none; transition: border-color 0.2s, box-shadow 0.2s;
    background: #fafafa; color: var(--color-text);
}
.form-group input:focus {
    border-color: var(--color-accent); box-shadow: 0 0 0 3px rgba(15,52,96,0.1);
    background: var(--color-bg-white);
}
.form-group input::placeholder { color: #bbb; }
.btn-login {
    width: 100%; padding: 14px; font-size: 15px; font-weight: 700; color: #fff;
    background: linear-gradient(135deg, #1a1a2e, #0f3460); border: none;
    border-radius: var(--radius-xl); cursor: pointer;
    transition: transform 0.15s, box-shadow 0.2s; margin-top: 8px; letter-spacing: 0.3px;
}
.btn-login:hover { transform: translateY(-1px); box-shadow: 0 6px 20px rgba(15,52,96,0.35); }
.btn-login:active { transform: translateY(0); }
.login-error {
    background: #fff0f0; color: #c33; padding: 10px 14px; border-radius: var(--radius-lg);
    font-size: 14px; margin-bottom: 20px; border: 1px solid #fdd;
}
.footer-text { margin-top: 32px; font-size: 12px; color: #bbb; text-align: center; }

/* ============================================================
   REPORT PAGE
   ============================================================ */
/* --- Report Tabs --- */
.report-tabs {
    display: flex; gap: 0; margin-bottom: 0;
    border-bottom: 2px solid var(--color-border);
}
.report-tab {
    padding: 10px 20px; background: none; border: none;
    color: var(--color-text-muted); font-size: 13px; font-weight: 600;
    cursor: pointer; border-bottom: 2px solid transparent;
    margin-bottom: -2px; transition: color 0.2s, border-color 0.2s;
}
.report-tab:hover { color: var(--color-accent); }
.report-tab.active { color: var(--color-accent); border-bottom-color: var(--color-accent); }

.report-section { display: none; padding-top: 20px; }
.report-section.active { display: block; }

.report-table-wrap { overflow-x: auto; }
.report-table {
    border-collapse: collapse; width: 100%; font-size: 13px;
}
.report-table th {
    padding: 10px 14px; text-align: center;
    background: var(--color-bg); color: var(--color-text-muted);
    font-weight: 600; font-size: 11px; text-transform: uppercase;
    letter-spacing: 0.5px; border-bottom: 2px solid var(--color-border);
    position: sticky; top: 0; white-space: nowrap;
}
.report-table th.col-total {
    background: var(--color-accent-light); color: var(--color-accent);
}
.report-table td {
    padding: 10px 14px; text-align: center;
    border-bottom: 1px solid var(--color-border);
}
.report-table .cell-user {
    text-align: left; font-weight: 600; color: var(--color-primary);
    white-space: nowrap;
}
.report-table .cell-total { font-weight: 700; color: var(--color-accent); }
.report-table .cell-zero { color: var(--color-text-faint); }
.report-table tbody tr:hover { background: var(--color-bg-hover); }
.report-table tfoot td {
    background: var(--color-accent-light); font-weight: 700;
    color: var(--color-primary); border-top: 2px solid var(--color-accent);
}

/* --- View Toggle (Tables / Analytics) --- */
.view-toggle-btn {
    padding: 8px 20px; border: 1px solid var(--color-border);
    background: var(--color-bg-white); color: var(--color-text-muted);
    font-size: 13px; font-weight: 600; cursor: pointer;
    transition: all 0.2s;
}
.view-toggle-btn:first-child { border-radius: var(--radius-md) 0 0 var(--radius-md); }
.view-toggle-btn:last-child { border-radius: 0 var(--radius-md) var(--radius-md) 0; border-left: none; }
.view-toggle-btn.active {
    background: var(--color-accent); color: #fff;
    border-color: var(--color-accent);
}
.view-toggle-btn:hover:not(.active) { background: var(--color-bg-hover); }

/* --- Sub-category (entity) tags --- */
.sub-cat-tag {
    display: inline-block; font-size: 10px; padding: 1px 6px;
    background: #e8f4f8; color: #0a7; border-radius: var(--radius-sm);
    margin-left: 4px;
}
.sub-cat-tag.clickable, .sub-cat-tag[data-sub-cat] { cursor: pointer; }
.sub-cat-tag:hover { background: #d0ecf4; }

/* --- Confidence & Review Badges --- */
.confidence-badge {
    display: inline-block; font-size: 10px; padding: 1px 6px;
    border-radius: var(--radius-sm); margin-left: 4px;
    font-weight: 600; cursor: default;
}
.confidence-badge small { font-weight: 400; opacity: 0.7; }
.conf-high { background: #d1fae5; color: #047857; }
.conf-mid  { background: #fef3c7; color: #b45309; }
.conf-low  { background: #fee2e2; color: #991b1b; }
.needs-review-badge {
    display: inline-block; font-size: 9px; padding: 1px 6px;
    border-radius: var(--radius-sm); margin-left: 3px;
    background: #fecaca; color: #991b1b; font-weight: 700;
    text-transform: uppercase; letter-spacing: 0.3px;
}

/* --- Analytics Grid Layouts --- */
.analytics-grid { display: grid; gap: 14px; margin-bottom: 14px; }
.analytics-grid-kpi { grid-template-columns: repeat(6, 1fr); gap: 8px; margin-bottom: 16px; }
.analytics-grid-2col-wide { grid-template-columns: 3fr 2fr; }
.analytics-grid-2col { grid-template-columns: 1fr 1fr; }

/* --- Analytics Cards --- */
.analytics-card {
    background: var(--color-bg-white);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    padding: 14px;
    box-shadow: var(--shadow-sm);
}
.analytics-title {
    font-size: 11px; font-weight: 700; color: var(--color-text-muted);
    text-transform: uppercase; letter-spacing: 0.5px;
    margin: 0 0 8px 0;
}

/* ============================================================
   RESPONSIVE
   ============================================================ */
@media (max-width: 768px) {
    .container { flex-direction: column; }
    .upload-panel {
        width: 100%; min-width: auto;
        position: fixed; top: 0; left: 0; bottom: 0; width: 300px;
        transform: translateX(-100%); z-index: 20;
        overflow-y: auto;
    }
    .upload-panel.open { transform: translateX(0); }
    .mobile-toggle { display: flex; }
    .results-panel { padding: 16px; padding-top: 60px; }

    .summary-cards { gap: 8px; }
    .card { min-width: 120px; padding: 12px 14px; }
    .card .value { font-size: 18px; }
    .card .label { font-size: 10px; }

    .analysis-toggle a { padding: 6px 10px; font-size: 12px; }
    .view-toggle-btn { padding: 6px 12px; font-size: 12px; }

    /* Crosstab: sticky first column */
    .crosstab td:first-child, .crosstab th:first-child {
        position: sticky; left: 0; z-index: 1;
        background: var(--color-bg-white) !important;
    }
    .crosstab th:first-child { background: var(--color-primary) !important; color: #fff !important; }

    /* Login */
    .login-container { flex-direction: column; min-height: auto; }
    .brand-panel { padding: 32px 28px; }
    .brand-features { display: none; }
    .form-panel { padding: 32px 28px; }

    /* Analytics: single column on tablet */
    .analytics-grid-2col-wide,
    .analytics-grid-2col { grid-template-columns: 1fr; }
    .analytics-grid-kpi { grid-template-columns: repeat(3, 1fr); }
    #analytics-wrapper { padding: 12px; }
    .analytics-card { padding: 10px; }

    /* Report table */
    .report-table { font-size: 11px; }
    .report-tabs { overflow-x: auto; }
    .report-tab { padding: 8px 12px; font-size: 12px; white-space: nowrap; }

    /* Sidebar user */
    .sidebar-user-name { font-size: 11px; }
}

@media (max-width: 480px) {
    .summary-cards { flex-direction: column; }
    .card { min-width: auto; }
    .panel-header { flex-wrap: wrap; gap: 8px; }
    .panel-header-actions { flex-wrap: wrap; }
    .results-panel { padding: 12px; padding-top: 56px; }

    /* Analytics KPIs: 2 columns on small phones */
    .analytics-grid-kpi { grid-template-columns: repeat(2, 1fr); }

    /* Stack toggles vertically */
    .analysis-toggle { flex-wrap: wrap; }
    .analysis-toggle a { flex: 1; text-align: center; font-size: 11px; padding: 6px 8px; }
    .view-toggle-btn { font-size: 11px; padding: 6px 10px; }
}

/* ============================================================
   PRINT
   ============================================================ */
@media print {
    .upload-panel, .mobile-toggle, .mobile-overlay,
    .analysis-toggle, .filter-bar, .btn-toggle,
    .toast-container, .tour-overlay, .tour-tooltip,
    .cat-edit-overlay, .privacy-banner,
    .rename-icon, .move-sg-icon, .filter-icon,
    .group-tag.filter-icon { display: none !important; }

    body { background: #fff; }
    .container { display: block; }
    .results-panel { padding: 0; }
    table { box-shadow: none; page-break-inside: avoid; }
    .card { box-shadow: none; border: 1px solid #ddd; }
    .summary-cards { gap: 8px; }

    .sg-child { display: table-row !important; }
    .sg-arrow { display: none; }
}
