/* ================================================================
   ACUMEN FINANCIAL REPORTING DASHBOARD - STYLESHEET
   Dark/Light theme with compact, information-dense layout
   ================================================================ */

@import url('https://fonts.googleapis.com/css2?family=DM+Sans:ital,opsz,wght@0,9..40,300;0,9..40,400;0,9..40,500;0,9..40,600;0,9..40,700;1,9..40,400&family=JetBrains+Mono:wght@400;500&family=Playfair+Display:wght@600;700&display=swap');

/* ── DARK THEME (default) ──────────────────── */
:root, [data-theme="dark"] {
    --bg-primary: #0B1120;
    --bg-secondary: #111827;
    --bg-card: #1a2332;
    --bg-card-hover: #1e2a3a;
    --bg-elevated: #243042;
    --border-subtle: rgba(255,255,255,0.06);
    --border-accent: rgba(212,175,55,0.25);

    --text-primary: #F1F5F9;
    --text-secondary: #94A3B8;
    --text-muted: #64748B;

    --accent-gold: #D4AF37;
    --accent-gold-dim: rgba(212,175,55,0.15);
    --accent-green: #34D399;
    --accent-green-dim: rgba(52,211,153,0.12);
    --accent-red: #F87171;
    --accent-red-dim: rgba(248,113,113,0.12);
    --accent-blue: #60A5FA;
    --accent-blue-dim: rgba(96,165,250,0.12);
    --accent-purple: #A78BFA;
    --accent-orange: #FB923C;
    --accent-cyan: #22D3EE;

    --shadow-card: 0 1px 3px rgba(0,0,0,0.3), 0 1px 2px rgba(0,0,0,0.2);
    --shadow-elevated: 0 10px 40px rgba(0,0,0,0.4);
    --shadow-glow: 0 0 30px rgba(212,175,55,0.08);

    --grain-opacity: 0.03;
    --select-arrow: %2394A3B8;
    --scrollbar-thumb: rgba(255,255,255,0.06);
}

/* ── LIGHT THEME ───────────────────────────── */
[data-theme="light"] {
    --bg-primary: #F8F9FC;
    --bg-secondary: #FFFFFF;
    --bg-card: #FFFFFF;
    --bg-card-hover: #F1F5F9;
    --bg-elevated: #F1F5F9;
    --border-subtle: rgba(0,0,0,0.08);
    --border-accent: rgba(180,140,20,0.25);

    --text-primary: #0F172A;
    --text-secondary: #475569;
    --text-muted: #94A3B8;

    --accent-gold: #B8941E;
    --accent-gold-dim: rgba(184,148,30,0.1);
    --accent-green: #059669;
    --accent-green-dim: rgba(5,150,105,0.08);
    --accent-red: #DC2626;
    --accent-red-dim: rgba(220,38,38,0.08);
    --accent-blue: #2563EB;
    --accent-blue-dim: rgba(37,99,235,0.08);
    --accent-purple: #7C3AED;
    --accent-orange: #EA580C;
    --accent-cyan: #0891B2;

    --shadow-card: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
    --shadow-elevated: 0 10px 40px rgba(0,0,0,0.08);
    --shadow-glow: 0 0 30px rgba(184,148,30,0.06);

    --grain-opacity: 0;
    --select-arrow: %23475569;
    --scrollbar-thumb: rgba(0,0,0,0.12);
}

/* ── Shared tokens ─────────────────────────── */
:root {
    --font-display: 'Playfair Display', Georgia, serif;
    --font-body: 'DM Sans', -apple-system, sans-serif;
    --font-mono: 'JetBrains Mono', monospace;

    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 14px;

    --transition-fast: 150ms cubic-bezier(0.4, 0, 0.2, 1);
    --transition-base: 250ms cubic-bezier(0.4, 0, 0.2, 1);

    --sidebar-width: 240px;
}

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

html {
    font-size: 14px;
    scroll-behavior: smooth;
    -webkit-font-smoothing: antialiased;
}

body {
    font-family: var(--font-body);
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    overflow-x: hidden;
    line-height: 1.55;
    transition: background var(--transition-base), color var(--transition-base);
}

body::before {
    content: '';
    position: fixed; inset: 0;
    background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='0.03'/%3E%3C/svg%3E");
    opacity: var(--grain-opacity);
    pointer-events: none; z-index: 0;
}

/* ── Layout ────────────────────────────────── */
.app-layout {
    display: flex;
    min-height: 100vh;
    position: relative;
    z-index: 1;
}

/* ── Sidebar ───────────────────────────────── */
.sidebar {
    width: var(--sidebar-width);
    background: var(--bg-secondary);
    border-right: 1px solid var(--border-subtle);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0; left: 0; bottom: 0;
    z-index: 100;
    overflow-y: auto;
    transition: transform var(--transition-base), background var(--transition-base);
}

.sidebar-header {
    padding: 16px 16px 12px;
    border-bottom: 1px solid var(--border-subtle);
}

.sidebar-logo {
    display: flex; align-items: center; gap: 10px;
}

.sidebar-logo .logo-icon {
    width: 32px; height: 32px;
    background: linear-gradient(135deg, var(--accent-gold), #b8941e);
    border-radius: var(--radius-sm);
    display: flex; align-items: center; justify-content: center;
    font-family: var(--font-display);
    font-size: 16px; font-weight: 700; color: #0B1120;
    flex-shrink: 0;
}

.sidebar-logo .logo-text {
    font-family: var(--font-display);
    font-size: 15px; font-weight: 700;
    color: var(--text-primary);
    letter-spacing: -0.02em;
    line-height: 1.2;
}

.sidebar-logo .logo-sub {
    font-size: 10px; font-weight: 500;
    color: var(--text-muted);
    font-family: var(--font-body);
    letter-spacing: 0.06em;
    text-transform: uppercase;
    margin-top: 1px;
}

/* Theme toggle */
.theme-toggle {
    display: flex; align-items: center; gap: 8px;
    margin: 10px 12px 6px;
    padding: 6px 10px;
    background: var(--bg-elevated);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.theme-toggle:hover { border-color: var(--accent-gold); }

.theme-toggle-track {
    width: 34px; height: 18px;
    background: var(--border-subtle);
    border-radius: 9px;
    position: relative;
    transition: background var(--transition-fast);
    flex-shrink: 0;
}

[data-theme="light"] .theme-toggle-track { background: var(--accent-gold); }

.theme-toggle-thumb {
    width: 14px; height: 14px;
    background: var(--text-primary);
    border-radius: 50%;
    position: absolute;
    top: 2px; left: 2px;
    transition: transform var(--transition-fast);
}

[data-theme="light"] .theme-toggle-thumb { transform: translateX(16px); }

.theme-toggle-label {
    font-size: 11px;
    color: var(--text-muted);
    font-weight: 500;
    user-select: none;
}

.sidebar-section {
    padding: 12px 10px 4px;
}

.sidebar-section-label {
    font-size: 9.5px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--text-muted);
    padding: 0 8px;
    margin-bottom: 4px;
}

.sidebar-nav { list-style: none; }

.sidebar-nav li a {
    display: flex; align-items: center; gap: 8px;
    padding: 6px 10px;
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 12.5px;
    font-weight: 400;
    transition: all var(--transition-fast);
    cursor: pointer;
}

.sidebar-nav li a:hover {
    background: var(--bg-elevated);
    color: var(--text-primary);
}

.sidebar-nav li a.active {
    background: var(--accent-gold-dim);
    color: var(--accent-gold);
    font-weight: 500;
}

.sidebar-nav li a .nav-icon {
    width: 16px; height: 16px; flex-shrink: 0;
    opacity: 0.6;
}

.sidebar-nav li a.active .nav-icon { opacity: 1; }

/* Company selector */
.company-selector {
    margin: 8px 10px;
}

.company-selector select {
    width: 100%;
    padding: 6px 10px;
    background: var(--bg-elevated);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-family: var(--font-body);
    font-size: 12px;
    cursor: pointer;
    outline: none;
    transition: border-color var(--transition-fast), background var(--transition-base);
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='var(--select-arrow)' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 8px center;
}

.company-selector select:focus { border-color: var(--accent-gold); }
.company-selector select option { background: var(--bg-secondary); color: var(--text-primary); }

/* Year selector */
.year-selector {
    margin: 0 10px 8px;
    display: flex; gap: 4px; flex-wrap: wrap;
}

.year-btn {
    padding: 3px 10px;
    border: 1px solid var(--border-subtle);
    background: transparent;
    color: var(--text-secondary);
    font-family: var(--font-mono);
    font-size: 11px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.year-btn:hover { border-color: var(--accent-gold); color: var(--text-primary); }

.year-btn.active {
    background: var(--accent-gold);
    color: #0B1120;
    border-color: var(--accent-gold);
    font-weight: 600;
}

/* ── Main Content ──────────────────────────── */
.main-content {
    margin-left: var(--sidebar-width);
    flex: 1;
    padding: 20px 24px 32px;
    min-height: 100vh;
    transition: background var(--transition-base);
}

/* ── Page Header ───────────────────────────── */
.page-header {
    margin-bottom: 16px;
    display: flex; align-items: flex-end; justify-content: space-between;
    flex-wrap: wrap; gap: 8px;
}

.page-header h1 {
    font-family: var(--font-display);
    font-size: 22px;
    font-weight: 700;
    color: var(--text-primary);
    letter-spacing: -0.02em;
}

.page-header .subtitle {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 2px;
}

.page-header .header-meta {
    font-family: var(--font-mono);
    font-size: 11px;
    color: var(--text-muted);
    background: var(--bg-card);
    padding: 4px 12px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-subtle);
}

/* ── KPI Cards Row ─────────────────────────── */
.kpi-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 10px;
    margin-bottom: 16px;
}

.kpi-card {
    background: var(--bg-card);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    padding: 12px 14px;
    transition: all var(--transition-base);
    position: relative;
    overflow: hidden;
}

.kpi-card::before {
    content: '';
    position: absolute; top: 0; left: 0;
    width: 3px; height: 100%;
    border-radius: 3px 0 0 3px;
}

.kpi-card.gold::before { background: var(--accent-gold); }
.kpi-card.green::before { background: var(--accent-green); }
.kpi-card.red::before { background: var(--accent-red); }
.kpi-card.blue::before { background: var(--accent-blue); }
.kpi-card.purple::before { background: var(--accent-purple); }
.kpi-card.orange::before { background: var(--accent-orange); }

.kpi-card:hover {
    border-color: var(--border-accent);
    box-shadow: var(--shadow-glow);
    transform: translateY(-1px);
}

.kpi-label {
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-muted);
    margin-bottom: 4px;
}

.kpi-value {
    font-family: var(--font-mono);
    font-size: 18px;
    font-weight: 600;
    color: var(--text-primary);
    line-height: 1.2;
}

.kpi-change {
    display: inline-flex;
    align-items: center;
    gap: 2px;
    font-size: 10.5px;
    font-weight: 500;
    margin-top: 4px;
    padding: 1px 6px;
    border-radius: 20px;
}

.kpi-change.up { color: var(--accent-green); background: var(--accent-green-dim); }
.kpi-change.down { color: var(--accent-red); background: var(--accent-red-dim); }

/* ── Chart Cards ───────────────────────────── */
.charts-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
    margin-bottom: 16px;
}

.charts-grid.single { grid-template-columns: 1fr; }
.charts-grid.triple { grid-template-columns: repeat(3, 1fr); }

.chart-card {
    background: var(--bg-card);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    padding: 14px 16px;
    transition: border-color var(--transition-base), background var(--transition-base);
}

.chart-card:hover { border-color: var(--border-accent); }
.chart-card.full-width { grid-column: 1 / -1; }

.chart-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 8px;
}

.chart-title {
    font-family: var(--font-display);
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
}

.chart-subtitle {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 1px;
}

.chart-container {
    position: relative;
    width: 100%;
    height: 220px;
}

.chart-container canvas {
    width: 100% !important;
    height: 100% !important;
}

/* ── Data Tables ───────────────────────────── */
.table-card {
    background: var(--bg-card);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    overflow: hidden;
    margin-bottom: 16px;
}

.table-card .table-header {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border-subtle);
    display: flex; align-items: center; justify-content: space-between;
}

.table-card .table-title {
    font-family: var(--font-display);
    font-size: 14px;
    font-weight: 600;
}

.data-table { width: 100%; border-collapse: collapse; }

.data-table thead th {
    padding: 8px 14px;
    text-align: left;
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-muted);
    background: var(--bg-elevated);
    border-bottom: 1px solid var(--border-subtle);
    position: sticky; top: 0;
}

.data-table thead th.text-right { text-align: right; }

.data-table tbody tr {
    border-bottom: 1px solid var(--border-subtle);
    transition: background var(--transition-fast);
}

.data-table tbody tr:hover { background: rgba(212,175,55,0.03); }
.data-table tbody tr:last-child { border-bottom: none; }

.data-table tbody td {
    padding: 7px 14px;
    font-size: 12.5px;
    color: var(--text-secondary);
}

.data-table tbody td.text-right {
    text-align: right;
    font-family: var(--font-mono);
    font-size: 12px;
}

.data-table tbody td.label-cell { font-weight: 500; color: var(--text-primary); }
.data-table tbody td.indent { padding-left: 32px; }
.data-table tbody td.indent-2 { padding-left: 48px; }

.data-table tbody tr.subtotal td {
    font-weight: 600;
    color: var(--text-primary);
    border-top: 1px solid var(--border-accent);
    background: rgba(212,175,55,0.03);
}

.data-table tbody tr.total td {
    font-weight: 700;
    font-size: 13px;
    color: var(--accent-gold);
    border-top: 2px solid var(--accent-gold);
    background: var(--accent-gold-dim);
}

.data-table .positive { color: var(--accent-green); }
.data-table .negative { color: var(--accent-red); }

/* ── Tabs ──────────────────────────────────── */
.tab-bar {
    display: flex; gap: 2px;
    background: var(--bg-secondary);
    border-radius: var(--radius-md);
    padding: 3px;
    margin-bottom: 12px;
    border: 1px solid var(--border-subtle);
    width: fit-content;
}

.tab-btn {
    padding: 5px 14px;
    border: none; background: transparent;
    color: var(--text-muted);
    font-family: var(--font-body);
    font-size: 12px; font-weight: 500;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.tab-btn:hover { color: var(--text-primary); }
.tab-btn.active { background: var(--accent-gold); color: #0B1120; font-weight: 600; }

/* ── Report Section ────────────────────────── */
.report-section { display: none; animation: fadeIn 0.3s ease; }
.report-section.active { display: block; }

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

/* ── Loading / Error ───────────────────────── */
.loading-overlay {
    display: flex; align-items: center; justify-content: center;
    min-height: 150px;
    flex-direction: column; gap: 10px;
}

.loading-spinner {
    width: 28px; height: 28px;
    border: 3px solid var(--border-subtle);
    border-top-color: var(--accent-gold);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }
.loading-text { font-size: 12px; color: var(--text-muted); }

.error-box {
    background: var(--accent-red-dim);
    border: 1px solid rgba(248,113,113,0.3);
    border-radius: var(--radius-md);
    padding: 14px 18px;
    margin: 12px 0;
}

.error-box .error-title { font-weight: 600; color: var(--accent-red); font-size: 13px; margin-bottom: 4px; }
.error-box .error-message { font-size: 12px; color: var(--text-secondary); }

/* ── Utility ───────────────────────────────── */
.text-gold { color: var(--accent-gold); }
.text-green { color: var(--accent-green); }
.text-red { color: var(--accent-red); }
.text-blue { color: var(--accent-blue); }
.text-muted { color: var(--text-muted); }
.text-mono { font-family: var(--font-mono); }
.fw-600 { font-weight: 600; }

/* ── Mobile Header (hidden on desktop) ──────── */
.mobile-header {
    display: none;
    position: fixed;
    top: 0; left: 0; right: 0;
    height: 52px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-subtle);
    z-index: 90;
    align-items: center;
    padding: 0 12px;
    gap: 10px;
    transition: background var(--transition-base);
}

.menu-btn {
    width: 38px; height: 38px;
    background: transparent;
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    transition: all var(--transition-fast);
    flex-shrink: 0;
}

.menu-btn:hover { border-color: var(--accent-gold); }
.menu-btn svg { width: 20px; height: 20px; }

.mobile-logo {
    display: flex; align-items: center; gap: 8px;
    flex: 1;
}

.mobile-meta {
    font-family: var(--font-mono);
    font-size: 11px;
    color: var(--text-muted);
    background: var(--bg-elevated);
    padding: 4px 10px;
    border-radius: var(--radius-sm);
}

/* ── Sidebar Overlay (mobile) ──────────────── */
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 99;
    opacity: 0;
    transition: opacity var(--transition-base);
}

.sidebar-overlay.visible {
    opacity: 1;
}

/* ── Sidebar Close Button (hidden on desktop) ─ */
.sidebar-close {
    display: none;
    width: 32px; height: 32px;
    background: transparent;
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    cursor: pointer;
    align-items: center; justify-content: center;
    transition: all var(--transition-fast);
    flex-shrink: 0;
}

.sidebar-close:hover { border-color: var(--accent-red); color: var(--accent-red); }
.sidebar-close svg { width: 16px; height: 16px; }

/* ── Responsive ────────────────────────────── */
@media (max-width: 1200px) {
    .charts-grid, .charts-grid.triple { grid-template-columns: 1fr; }
    .kpi-row { grid-template-columns: repeat(3, 1fr); }
}

@media (max-width: 768px) {
    /* Mobile header visible */
    .mobile-header { display: flex; }

    /* Sidebar: slide-in drawer */
    .sidebar {
        transform: translateX(-100%);
        z-index: 200;
        box-shadow: none;
    }
    .sidebar.open {
        transform: translateX(0);
        box-shadow: 4px 0 24px rgba(0,0,0,0.3);
    }

    /* Show close button and overlay on mobile */
    .sidebar-close { display: flex; }
    .sidebar-overlay { display: block; pointer-events: none; }
    .sidebar-overlay.visible { pointer-events: auto; }

    /* Sidebar header: flex row with close button */
    .sidebar-header {
        display: flex;
        align-items: center;
        justify-content: space-between;
    }

    /* Main content: add top padding for fixed mobile header */
    .main-content {
        margin-left: 0;
        padding: 64px 12px 24px;
    }

    .kpi-row { grid-template-columns: repeat(2, 1fr); }
    .page-header { flex-direction: column; align-items: flex-start; }

    /* Smaller chart heights on mobile */
    .chart-container { height: 180px; }

    /* Full-width KPIs on very small screens */
    @media (max-width: 400px) {
        .kpi-row { grid-template-columns: 1fr; }
    }
}

/* ── Scrollbar ─────────────────────────────── */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--scrollbar-thumb); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ── Print ─────────────────────────────────── */
@media print {
    .sidebar { display: none; }
    .main-content { margin-left: 0; }
    body { background: #fff; color: #000; }
    .chart-card, .kpi-card, .table-card { border: 1px solid #ccc; }
}
