:root {
    --accent: #2563eb;
    --accent-soft: rgba(37, 99, 235, 0.14);
    --bg: #0b1120;
    --surface: #111827;
    --surface-2: #1e293b;
    --border: rgba(148, 163, 184, 0.16);
    --text: #f1f5f9;
    --muted: #94a3b8;
    --pos: #10b981;
    --pos-bg: rgba(16, 185, 129, 0.14);
    --neg: #ef4444;
    --neg-bg: rgba(239, 68, 68, 0.14);
    --warn: #f59e0b;
    --warn-bg: rgba(245, 158, 11, 0.14);
    --radius: 14px;
    --shadow: 0 10px 30px rgba(0, 0, 0, 0.25);
    --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, Arial, sans-serif;
}

[data-theme="light"] {
    --bg: #f1f5f9;
    --surface: #ffffff;
    --surface-2: #f8fafc;
    --border: rgba(15, 23, 42, 0.1);
    --text: #0f172a;
    --muted: #64748b;
    --shadow: 0 8px 24px rgba(15, 23, 42, 0.06);
}

* { box-sizing: border-box; }
html, body {
    margin: 0;
    padding: 0;
    min-height: 100%;
    background: var(--bg);
    color: var(--text);
    font-family: var(--font);
    -webkit-font-smoothing: antialiased;
}

.muted { color: var(--muted); font-size: 0.86rem; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }

/* Login Screen */
.login-screen {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    background: radial-gradient(circle at top right, var(--accent-soft), transparent 45%), var(--bg);
}
.login-card {
    width: 100%;
    max-width: 420px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 18px;
    padding: 32px 28px;
    box-shadow: var(--shadow);
}
.login-brand { text-align: center; margin-bottom: 24px; }
.login-brand h1 { margin: 12px 0 4px; font-size: 1.45rem; }
.brand-badge {
    width: 58px; height: 58px; border-radius: 16px;
    background: var(--accent); color: #fff;
    display: inline-flex; align-items: center; justify-content: center;
    font-weight: 800; font-size: 1.5rem; overflow: hidden;
    box-shadow: 0 8px 20px var(--accent-soft);
}
.brand-badge.sm { width: 38px; height: 38px; border-radius: 10px; font-size: 1rem; flex-shrink: 0; }
.brand-badge img { width: 100%; height: 100%; object-fit: contain; background: #fff; padding: 4px; }

.field { margin-bottom: 14px; }
.field label { display: block; font-size: 0.84rem; color: var(--muted); margin-bottom: 6px; font-weight: 500; }
.field input {
    width: 100%; padding: 11px 13px; border-radius: 10px;
    border: 1px solid var(--border); background: var(--surface-2); color: var(--text);
    font-size: 0.95rem; outline: none; transition: border-color 0.15s;
}
.field input:focus { border-color: var(--accent); }

.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    padding: 10px 16px; border-radius: 10px; border: 1px solid var(--border);
    background: var(--surface-2); color: var(--text); font-weight: 600; font-size: 0.9rem;
    cursor: pointer; transition: opacity 0.15s, transform 0.1s;
}
.btn:hover { opacity: 0.9; }
.btn:active { transform: scale(0.98); }
.btn-primary { background: var(--accent); border-color: transparent; color: #fff; }
.btn-ghost { background: transparent; }
.btn-danger-ghost { background: transparent; color: var(--neg); border-color: rgba(239, 68, 68, 0.25); }
.btn-sm { padding: 7px 11px; font-size: 0.82rem; border-radius: 8px; }
.btn-block { width: 100%; padding: 12px; font-size: 0.96rem; margin-top: 4px; }

.login-divider { text-align: center; margin: 20px 0 14px; position: relative; }
.login-divider::before { content: ""; position: absolute; left: 0; right: 0; top: 50%; height: 1px; background: var(--border); }
.login-divider span { position: relative; background: var(--surface); padding: 0 10px; font-size: 0.78rem; color: var(--muted); }
.demo-btn-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.demo-btn-row .btn { font-size: 0.8rem; padding: 9px 8px; }
.login-foot { text-align: center; margin-top: 18px; font-size: 0.78rem; }

.alert { padding: 10px 12px; border-radius: 10px; font-size: 0.86rem; margin-bottom: 14px; }
.alert-danger { background: var(--neg-bg); color: var(--neg); border: 1px solid rgba(239, 68, 68, 0.3); }

/* App Shell */
.app-shell { display: flex; min-height: 100vh; }
.sidebar {
    width: 256px; flex-shrink: 0; background: var(--surface);
    border-right: 1px solid var(--border);
    display: flex; flex-direction: column; padding: 18px 14px;
    position: sticky; top: 0; height: 100vh;
}
.sidebar-brand { display: flex; align-items: center; gap: 11px; padding: 4px 6px 18px; border-bottom: 1px solid var(--border); }
.brand-text { display: flex; flex-direction: column; overflow: hidden; }
.brand-text strong { font-size: 0.96rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.side-nav { display: flex; flex-direction: column; gap: 4px; margin-top: 16px; flex: 1; }
.nav-item {
    display: flex; align-items: center; gap: 10px; padding: 11px 12px;
    border-radius: 10px; border: none; background: transparent; color: var(--muted);
    font-size: 0.92rem; font-weight: 600; cursor: pointer; text-align: left;
    transition: background 0.15s, color 0.15s;
}
.nav-item:hover { background: var(--surface-2); color: var(--text); }
.nav-item.active { background: var(--accent-soft); color: var(--accent); }

.sidebar-footer { border-top: 1px solid var(--border); padding-top: 12px; display: flex; flex-direction: column; gap: 10px; }
.sync-pill { font-size: 0.76rem; color: var(--muted); padding: 6px 8px; background: var(--surface-2); border-radius: 8px; text-align: center; }
.sidebar-footer-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }

.main-col { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
    position: sticky; top: 0; z-index: 20;
    background: var(--surface); border-bottom: 1px solid var(--border);
    padding: 12px 22px; display: flex; align-items: center; justify-content: space-between; gap: 12px;
    flex-wrap: wrap;
}
.topbar-left, .topbar-right { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.company-selector-wrap, .year-selector-wrap { display: flex; align-items: center; gap: 8px; }

.select-control {
    padding: 8px 12px; border-radius: 10px; border: 1px solid var(--border);
    background: var(--surface-2); color: var(--text); font-weight: 600; font-size: 0.9rem;
    max-width: 310px; cursor: pointer;
}
.select-control.sm { max-width: 110px; }

.badge { display: inline-flex; align-items: center; padding: 4px 10px; border-radius: 999px; font-size: 0.75rem; font-weight: 700; white-space: nowrap; }
.badge-info { background: var(--surface-2); color: var(--muted); border: 1px solid var(--border); }
.badge-accent { background: var(--accent-soft); color: var(--accent); }
.badge-pos { background: var(--pos-bg); color: var(--pos); }
.badge-neg { background: var(--neg-bg); color: var(--neg); }
.badge-warn { background: var(--warn-bg); color: var(--warn); }

.canvas { padding: 22px; max-width: 1360px; width: 100%; margin: 0 auto; }

/* Cards & Grids */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 14px; margin-bottom: 20px; }
.kpi-card {
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
    padding: 16px 18px; box-shadow: var(--shadow);
}
.kpi-label { font-size: 0.8rem; color: var(--muted); font-weight: 600; margin-bottom: 8px; display: flex; justify-content: space-between; align-items: center; gap: 6px; }
.kpi-value { font-size: 1.55rem; font-weight: 800; letter-spacing: -0.02em; margin-bottom: 6px; }
.kpi-sub { font-size: 0.8rem; color: var(--muted); display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }

.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; margin-bottom: 20px; }
.card {
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
    padding: 18px 20px; box-shadow: var(--shadow); margin-bottom: 18px;
}
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; }
.card-head h3 { margin: 0; font-size: 1.02rem; }
.chart-box { width: 100%; height: 310px; }
.chart-box.tall { height: 360px; }

/* Tables */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
th, td { padding: 10px 12px; border-bottom: 1px solid var(--border); text-align: left; }
th { font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.03em; color: var(--muted); font-weight: 700; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
tr.row-subtotal { background: var(--surface-2); font-weight: 700; }
tr.row-total { background: var(--accent-soft); font-weight: 800; font-size: 0.94rem; }
.text-pos { color: var(--pos); }
.text-neg { color: var(--neg); }

.search-input {
    padding: 8px 12px; border-radius: 8px; border: 1px solid var(--border);
    background: var(--surface-2); color: var(--text); font-size: 0.86rem; min-width: 220px;
}

.empty-state { text-align: center; padding: 48px 20px; color: var(--muted); }

/* Mobile Responsive */
.mobile-only { display: none; }
.mobile-nav { display: none; }

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

@media (max-width: 780px) {
    .sidebar { display: none; }
    .mobile-only { display: inline-flex; }
    .topbar { padding: 10px 14px; }
    .select-control { max-width: 190px; font-size: 0.84rem; }
    .canvas { padding: 14px 12px 84px; }
    .kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
    .kpi-value { font-size: 1.25rem; }
    .chart-box { height: 250px; }

    .mobile-nav {
        display: flex; position: fixed; bottom: 0; left: 0; right: 0; z-index: 30;
        background: var(--surface); border-top: 1px solid var(--border);
        padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
        justify-content: space-around;
    }
    .m-nav-btn {
        flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px;
        border: none; background: transparent; color: var(--muted);
        font-size: 0.68rem; font-weight: 600; padding: 4px 2px; cursor: pointer;
    }
    .m-nav-btn span.ico { font-size: 1.15rem; }
    .m-nav-btn.active { color: var(--accent); }
}
