/* ═══════════════════════════════════════════════════════════════
   CarryOn Analytics — Premium Design System
   ═══════════════════════════════════════════════════════════════ */

/* ── Design Tokens ── */
:root {
    --bg: #ffffff;
    --pg: #f8fafc;
    --tx: #1e293b;
    --tl: #64748b;
    --tm: #94a3b8;
    --bd: #e2e8f0;
    --bl: #f1f5f9;
    --ac: #6366f1;
    --al: #818cf8;
    --a2: #a78bfa;
    --ab: rgba(99, 102, 241, .06);
    --sb: #0c1220;
    --sb2: #111827;
    --st: #94a3b8;
    --sw: 260px;
    --r: 12px;
    --r-sm: 8px;
    --sh: 0 1px 3px rgba(0, 0, 0, .04), 0 1px 2px rgba(0, 0, 0, .06);
    --sh-md: 0 4px 6px -1px rgba(0, 0, 0, .07), 0 2px 4px -2px rgba(0, 0, 0, .05);
    --sh-lg: 0 10px 15px -3px rgba(0, 0, 0, .08), 0 4px 6px -4px rgba(0, 0, 0, .04);
    --sh-glow: 0 0 20px rgba(99, 102, 241, .12);
    --pos: #10b981;
    --neg: #ef4444;
    --gradient-accent: linear-gradient(135deg, #6366f1, #8b5cf6, #a78bfa);
    --gradient-header: linear-gradient(135deg, #0f172a 0%, #1e1b4b 50%, #312e81 100%);
    --gradient-sidebar: linear-gradient(180deg, #0c1220 0%, #111827 60%, #0f172a 100%);
    --transition: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ── Reset ── */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }
html { scroll-behavior: smooth; }

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    color: var(--tx);
    background: var(--pg);
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* ── Custom Scrollbar ── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(148, 163, 184, .3); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: rgba(148, 163, 184, .5); }
* { scrollbar-width: thin; scrollbar-color: rgba(148, 163, 184, .3) transparent; }


/* ═══════════════════════════════════════════════════════════════
   SIDEBAR
   ═══════════════════════════════════════════════════════════════ */

nav#sidebar {
    position: fixed; top: 0; left: 0;
    width: var(--sw); height: 100vh;
    overflow-y: auto;
    background: var(--gradient-sidebar);
    z-index: 100;
    display: flex; flex-direction: column;
    border-right: 1px solid rgba(99, 102, 241, .08);
}
nav#sidebar::-webkit-scrollbar { width: 4px; }
nav#sidebar::-webkit-scrollbar-thumb { background: rgba(148, 163, 184, .2); border-radius: 4px; }

.sidebar-brand {
    padding: 22px 20px 18px;
    border-bottom: 1px solid rgba(148, 163, 184, .08);
    background: rgba(99, 102, 241, .03);
}
.sidebar-brand h2 {
    font-size: 15px; font-weight: 800; color: #f8fafc;
    letter-spacing: -.01em;
    background: var(--gradient-accent);
    -webkit-background-clip: text; -webkit-text-fill-color: transparent;
    background-clip: text;
}
.sidebar-brand .brand-sub {
    font-size: 10px; font-weight: 600; color: var(--st);
    text-transform: uppercase; letter-spacing: .1em; margin-top: 2px;
}

.sidebar-test-select, .sidebar-filters {
    padding: 14px 20px;
    border-bottom: 1px solid rgba(148, 163, 184, .08);
}
.sidebar-test-select label, .sidebar-filters .filter-title {
    display: block; font-size: 10px; font-weight: 600;
    text-transform: uppercase; letter-spacing: .1em;
    color: rgba(148, 163, 184, .6); margin-bottom: 6px;
}
.sidebar-filters label {
    display: block; font-size: 10px; font-weight: 500;
    color: rgba(148, 163, 184, .5); margin: 8px 0 3px;
}
.sidebar-test-select select, .sidebar-filters select {
    width: 100%; padding: 8px 10px; font-size: 12px; font-weight: 500;
    border: 1px solid rgba(99, 102, 241, .2); border-radius: var(--r-sm);
    background: rgba(30, 41, 59, .6); color: #e2e8f0;
    cursor: pointer; transition: all var(--transition);
    font-family: inherit;
}
.sidebar-test-select select:focus, .sidebar-filters select:focus {
    outline: none; border-color: var(--ac);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, .15);
}
.sidebar-test-select select:hover, .sidebar-filters select:hover {
    border-color: rgba(99, 102, 241, .4);
}

.btn-apply {
    display: block; width: 100%; margin-top: 14px;
    padding: 9px; font-size: 12px; font-weight: 600; font-family: inherit;
    color: #fff; background: var(--gradient-accent);
    border: none; border-radius: var(--r-sm);
    cursor: pointer; transition: all var(--transition);
    box-shadow: 0 2px 8px rgba(99, 102, 241, .25);
}
.btn-apply:hover {
    box-shadow: 0 4px 16px rgba(99, 102, 241, .35);
    transform: translateY(-1px);
}
.btn-apply:active { transform: translateY(0) scale(.98); }

.sidebar-nav { flex: 1; padding: 8px 0; overflow-y: auto; }
.nav-group { padding: 2px 10px; }
.nav-group-title {
    font-size: 10px; font-weight: 700;
    text-transform: uppercase; letter-spacing: .1em;
    color: rgba(148, 163, 184, .4);
    padding: 10px 10px 6px;
    cursor: pointer; display: flex; align-items: center;
    justify-content: space-between; user-select: none;
    transition: color var(--transition);
}
.nav-group-title:hover { color: rgba(148, 163, 184, .7); }
.nav-group-title::after {
    content: '\25B8'; font-size: 8px;
    transition: transform var(--transition);
}
.nav-group.open .nav-group-title::after { transform: rotate(90deg); }
.nav-group.open .nav-group-title { color: rgba(148, 163, 184, .7); }

nav#sidebar a {
    display: block; padding: 6px 12px;
    font-size: 12px; font-weight: 450; color: var(--st);
    text-decoration: none; border-radius: var(--r-sm);
    transition: all var(--transition);
    border-left: 2px solid transparent; margin: 1px 0;
}
nav#sidebar .nav-group a { display: none; }
nav#sidebar .nav-group.open a {
    display: block;
    animation: slideIn .15s ease-out;
}
nav#sidebar a:hover {
    background: rgba(99, 102, 241, .06); color: #e2e8f0;
    border-left-color: rgba(99, 102, 241, .3);
}
nav#sidebar a.active {
    background: rgba(99, 102, 241, .12); color: var(--al);
    font-weight: 600;
    border-left-color: var(--ac);
    box-shadow: inset 0 0 12px rgba(99, 102, 241, .05);
}

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


/* ═══════════════════════════════════════════════════════════════
   MAIN CONTENT
   ═══════════════════════════════════════════════════════════════ */

main { margin-left: var(--sw); min-height: 100vh; }

.page-header {
    background: var(--gradient-header);
    border-bottom: none;
    padding: 28px 40px;
    position: relative;
    overflow: hidden;
}
.page-header::after {
    content: '';
    position: absolute; bottom: 0; left: 0; right: 0; height: 3px;
    background: var(--gradient-accent);
}
.page-header::before {
    content: '';
    position: absolute; top: -50%; right: -10%; width: 40%; height: 200%;
    background: radial-gradient(ellipse, rgba(99, 102, 241, .08) 0%, transparent 70%);
    pointer-events: none;
}
.page-header h1 {
    font-size: 22px; font-weight: 700; color: #f8fafc;
    letter-spacing: -.02em; position: relative;
}
.page-header .sub {
    font-size: 12px; color: var(--st); margin-top: 4px;
    font-weight: 450; position: relative;
}

.content-area {
    padding: 32px 40px 60px;
    max-width: 1800px;
    margin: 0 auto;
}


/* ═══════════════════════════════════════════════════════════════
   STAT CARDS
   ═══════════════════════════════════════════════════════════════ */

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 16px; margin-bottom: 32px;
}

.stat-card {
    background: var(--bg);
    border: 1px solid var(--bd);
    border-radius: var(--r);
    padding: 22px 20px 18px;
    box-shadow: var(--sh);
    transition: all var(--transition);
    position: relative;
    overflow: hidden;
}
.stat-card::before {
    content: '';
    position: absolute; top: 0; left: 0; right: 0; height: 3px;
    background: var(--gradient-accent);
    opacity: 0; transition: opacity var(--transition);
}
.stat-card:hover {
    box-shadow: var(--sh-md), var(--sh-glow);
    border-color: rgba(99, 102, 241, .2);
    transform: translateY(-2px);
}
.stat-card:hover::before { opacity: 1; }

.stat-card .stat-label {
    font-size: 10px; font-weight: 700;
    text-transform: uppercase; letter-spacing: .08em;
    color: var(--tm); margin-bottom: 8px;
}
.stat-card .stat-value {
    font-size: 30px; font-weight: 800;
    letter-spacing: -.03em; line-height: 1.1;
    background: linear-gradient(135deg, var(--tx), #334155);
    -webkit-background-clip: text; -webkit-text-fill-color: transparent;
    background-clip: text;
}
.stat-card .stat-detail {
    font-size: 11px; color: var(--tl); margin-top: 6px;
    font-weight: 450;
}


/* ═══════════════════════════════════════════════════════════════
   SECTIONS
   ═══════════════════════════════════════════════════════════════ */

section {
    margin-bottom: 24px;
    animation: fadeInUp .4s ease-out both;
}

.section-card {
    background: var(--bg);
    border: 1px solid var(--bd);
    border-radius: var(--r);
    padding: 24px;
    box-shadow: var(--sh);
    transition: all var(--transition);
}
.section-card:hover {
    box-shadow: var(--sh-md);
    border-color: rgba(226, 232, 240, .8);
}

section h3 {
    font-size: 14px; font-weight: 700;
    margin-bottom: 20px; padding-left: 14px;
    border-left: 3px solid transparent;
    border-image: var(--gradient-accent) 1;
    line-height: 1.4; letter-spacing: -.01em;
    color: var(--tx);
}

.section-group-title {
    font-size: 11px; font-weight: 800;
    text-transform: uppercase; letter-spacing: .1em;
    color: var(--ac); margin: 28px 0 12px;
    padding: 10px 16px;
    background: linear-gradient(90deg, rgba(99, 102, 241, .06), transparent);
    border-radius: var(--r-sm);
    border-left: 3px solid var(--ac);
}

.section-divider {
    font-size: 10px; font-weight: 700;
    text-transform: uppercase; letter-spacing: .08em;
    color: var(--tm); margin: 20px 0 10px;
    padding: 8px 0;
    border-bottom: 1px solid var(--bl);
    position: relative;
}
.section-divider::after {
    content: '';
    position: absolute; bottom: -1px; left: 0; width: 60px; height: 1px;
    background: var(--gradient-accent);
}


/* ═══════════════════════════════════════════════════════════════
   CHARTS
   ═══════════════════════════════════════════════════════════════ */

.chart-container { width: 100%; min-height: 340px; }

.charts-row { display: flex; gap: 16px; margin-top: 12px; }
.chart-left { flex: 3; min-height: 340px; }
.chart-right { flex: 2; min-height: 340px; }
@media (max-width: 900px) { .charts-row { flex-direction: column; } }


/* ═══════════════════════════════════════════════════════════════
   DATA TABLES
   ═══════════════════════════════════════════════════════════════ */

.table-container { margin-top: 4px; overflow-x: auto; }

.data-table {
    width: 100%; border-collapse: collapse;
    font-size: 13px; font-variant-numeric: tabular-nums;
}
.data-table th {
    padding: 12px 16px;
    background: linear-gradient(180deg, #f8fafc, #f1f5f9);
    border-bottom: 2px solid var(--bd);
    font-weight: 700; font-size: 10px;
    text-transform: uppercase; letter-spacing: .06em;
    color: var(--tl); white-space: nowrap;
    position: sticky; top: 0; z-index: 2;
}
.data-table td {
    padding: 10px 16px;
    border-bottom: 1px solid rgba(241, 245, 249, .8);
    transition: background var(--transition);
}
.data-table tbody tr:nth-child(even) td {
    background: rgba(248, 250, 252, .6);
}
.data-table tbody tr:hover td {
    background: rgba(99, 102, 241, .04);
}
.data-table .delta-positive { color: var(--pos); font-weight: 600; }
.data-table .delta-negative { color: var(--neg); font-weight: 600; }

/* ── Significance Badges ── */
.sig-yes {
    color: #059669; font-weight: 700;
    background: rgba(16, 185, 129, .1);
    padding: 3px 8px; border-radius: 20px;
    font-size: 11px; white-space: nowrap;
    border: 1px solid rgba(16, 185, 129, .15);
}
.sig-no { color: #64748b; }

/* ── Value Colors ── */
.val-pos {
    color: #059669; font-weight: 600;
}
.val-neg {
    color: #dc2626; font-weight: 600;
}
.val-muted { color: #94a3b8; }


/* ═══════════════════════════════════════════════════════════════
   LOADING
   ═══════════════════════════════════════════════════════════════ */

.loading-overlay {
    display: flex; align-items: center; justify-content: center;
    min-height: 60vh;
}
.loading-spinner {
    text-align: center; padding: 60px 20px;
    font-size: 14px; color: var(--tl); font-weight: 500;
}
.loading-spinner::before {
    content: '';
    display: block; width: 40px; height: 40px;
    margin: 0 auto 20px;
    border: 3px solid rgba(99, 102, 241, .15);
    border-top-color: var(--ac);
    border-radius: 50%;
    animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.no-data {
    text-align: center; padding: 28px;
    color: var(--tm); font-style: italic; font-size: 13px;
}


/* ═══════════════════════════════════════════════════════════════
   LANDING PAGE
   ═══════════════════════════════════════════════════════════════ */

.landing-header {
    background: var(--gradient-header);
    border-bottom: none; padding: 48px;
    text-align: center; position: relative;
}
.landing-header::after {
    content: '';
    position: absolute; bottom: 0; left: 0; right: 0; height: 3px;
    background: var(--gradient-accent);
}
.landing-header h1 {
    font-size: 28px; font-weight: 800; color: #f8fafc;
    letter-spacing: -.02em;
}
.landing-header .sub {
    font-size: 14px; color: var(--st); margin-top: 8px; font-weight: 450;
}

.dashboard-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 20px; padding: 32px 40px;
}
.dashboard-card {
    background: var(--bg); border: 1px solid var(--bd);
    border-radius: var(--r); padding: 28px;
    transition: all var(--transition);
    text-decoration: none; color: var(--tx);
    display: block; box-shadow: var(--sh);
    position: relative; overflow: hidden;
}
.dashboard-card::before {
    content: '';
    position: absolute; top: 0; left: 0; right: 0; height: 3px;
    background: var(--gradient-accent);
    opacity: 0; transition: opacity var(--transition);
}
.dashboard-card:hover {
    box-shadow: var(--sh-lg), var(--sh-glow);
    border-color: rgba(99, 102, 241, .2);
    transform: translateY(-3px);
}
.dashboard-card:hover::before { opacity: 1; }
.dashboard-card h3 {
    font-size: 16px; font-weight: 700; border: none; margin-bottom: 8px;
    padding: 0; color: var(--ac); letter-spacing: -.01em;
}
.dashboard-card p { font-size: 13px; color: var(--tl); font-weight: 450; }


/* ═══════════════════════════════════════════════════════════════
   FOLD / COLLAPSE
   ═══════════════════════════════════════════════════════════════ */

.section-card h3 {
    cursor: pointer; display: flex; align-items: center; gap: 6px;
}
.section-card h3::before {
    content: '\25BE'; font-size: 10px; color: var(--tm);
    transition: transform var(--transition);
}
.section-card.folded h3::before { transform: rotate(-90deg); }
.section-card.folded .table-container,
.section-card.folded .chart-container,
.section-card.folded .charts-row {
    display: none;
}

.fold-toggle {
    display: inline-flex; align-items: center; gap: 5px;
    font-size: 12px; color: var(--st); font-weight: 500;
    margin-left: 12px; cursor: pointer; user-select: none;
}
.fold-toggle input { cursor: pointer; accent-color: var(--ac); }


/* ═══════════════════════════════════════════════════════════════
   HEADER BAR (inline filters)
   ═══════════════════════════════════════════════════════════════ */

.header-bar {
    display: flex; align-items: center;
    justify-content: space-between; gap: 16px;
    flex-wrap: wrap; position: relative;
}
.header-filters {
    display: flex; align-items: center;
    gap: 10px; flex-wrap: wrap;
}
.header-filters label {
    font-size: 10px; font-weight: 700; color: rgba(148, 163, 184, .7);
    text-transform: uppercase; letter-spacing: .06em;
}
.header-filters select {
    padding: 6px 10px; font-size: 12px; font-weight: 500;
    border: 1px solid rgba(148, 163, 184, .2);
    border-radius: 6px; background: rgba(30, 41, 59, .5);
    color: #e2e8f0; cursor: pointer;
    transition: all var(--transition); font-family: inherit;
}
.header-filters select:focus {
    outline: none; border-color: var(--ac);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, .2);
}
.header-filters select:hover { border-color: rgba(99, 102, 241, .4); }

.header-filters .btn-apply {
    padding: 6px 20px; font-size: 12px; font-weight: 600;
    color: #fff; background: var(--gradient-accent);
    border: none; border-radius: 6px; cursor: pointer;
    transition: all var(--transition); font-family: inherit;
    box-shadow: 0 2px 8px rgba(99, 102, 241, .3);
}
.header-filters .btn-apply:hover {
    box-shadow: 0 4px 16px rgba(99, 102, 241, .4);
    transform: translateY(-1px);
}
.header-filters .btn-apply:active { transform: scale(.97); }


/* ═══════════════════════════════════════════════════════════════
   ANIMATIONS
   ═══════════════════════════════════════════════════════════════ */

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


/* ═══════════════════════════════════════════════════════════════
   RESPONSIVE
   ═══════════════════════════════════════════════════════════════ */

@media (max-width: 768px) {
    nav#sidebar {
        position: static; width: 100%; height: auto;
        flex-direction: row; flex-wrap: wrap;
        border-bottom: 2px solid var(--ac);
        border-right: none;
    }
    .sidebar-brand { flex: 1 1 100%; padding: 12px 16px; }
    .sidebar-filters { flex: 1 1 100%; padding: 8px 16px; }
    .sidebar-nav { display: none; }
    main { margin-left: 0; }
    .page-header { padding: 20px 16px; }
    .content-area { padding: 16px; }
    .stats-grid { grid-template-columns: repeat(2, 1fr); }
    section .section-card { padding: 16px; }
}

@media (max-width: 480px) {
    .stats-grid { grid-template-columns: 1fr; }
}
