:root {
    --ink: #172033;
    --muted: #738097;
    --line: #e7eaf0;
    --surface: #ffffff;
    --canvas: #f4f6fa;
    --brand: #5b5ce2;
    --brand-dark: #4546c8;
    --nav: #111827;
    --green: #16a071;
    --amber: #e39827;
    --blue: #2878dd;
    --radius: 16px;
    --chart-grid: rgba(115,128,151,.12);
}

* { box-sizing: border-box; }
html, body { min-height: 100%; }
html { color-scheme: light; }
body {
    margin: 0;
    background: var(--canvas);
    color: var(--ink);
    font-family: "DM Sans", system-ui, -apple-system, sans-serif;
    font-size: .9rem;
    transition: background-color .2s ease, color .2s ease;
}
a { text-decoration: none; }
.app-shell { min-height: 100vh; display: flex; }
.app-sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 1030;
    display: flex;
    width: 244px;
    flex-direction: column;
    padding: 24px 18px 18px;
    overflow-y: auto;
    background: var(--nav);
    color: #fff;
}
.brand { display: flex; align-items: center; gap: 11px; color: inherit; }
.brand:hover { color: inherit; }
.brand-mark {
    display: inline-grid;
    width: 38px;
    height: 38px;
    place-items: center;
    border-radius: 11px;
    background: linear-gradient(145deg, #7273f4, #4a4bd0);
    color: #fff;
    box-shadow: 0 8px 24px rgba(91,92,226,.35);
    font-size: 1.1rem;
}
.brand strong { display: block; font-size: 1.04rem; letter-spacing: -.02em; }
.brand small, .sidebar-user small, .collector-state small { display: block; color: #8892a7; font-size: .69rem; font-weight: 500; }
.nav-caption { margin: 34px 12px 9px; color: #657086; font-size: .65rem; font-weight: 700; letter-spacing: .12em; text-transform: uppercase; }
.side-nav { display: grid; gap: 5px; }
.side-nav a {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 11px 13px;
    border-radius: 11px;
    color: #9ba5b9;
    font-weight: 600;
    transition: .18s ease;
}
.side-nav a:hover { background: rgba(255,255,255,.055); color: #fff; }
.side-nav a.active { background: rgba(112,113,244,.17); color: #fff; }
.side-nav a.active i { color: #8c8dff; }
.side-nav i { width: 19px; font-size: 1.05rem; }
.sidebar-spacer { flex: 1; min-height: 32px; }
.theme-toggle { display: flex; align-items: center; gap: 10px; width: 100%; margin-bottom: 8px; padding: 9px 8px; border: 0; border-radius: 11px; background: transparent; color: #fff; text-align: left; }
.theme-toggle:hover { background: rgba(255,255,255,.055); }
.theme-toggle-icon { display: grid; width: 34px; height: 34px; flex: 0 0 34px; place-items: center; border-radius: 10px; background: #252f42; color: #c8cfff; font-size: 1rem; }
.theme-toggle strong { display: block; font-size: .78rem; }
.theme-toggle small { display: block; color: #8892a7; font-size: .69rem; }
.collector-state { display: flex; gap: 10px; align-items: center; margin: 0 8px 14px; padding: 11px 0; border-bottom: 1px solid rgba(255,255,255,.08); }
.collector-state strong { display: block; font-size: .78rem; }
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: #3bd29d; box-shadow: 0 0 0 5px rgba(59,210,157,.1); }
.collector-state-live .status-dot { background: #f1ad45; box-shadow: 0 0 0 5px rgba(241,173,69,.12); }
.sidebar-user { width: 100%; display: flex; align-items: center; gap: 10px; padding: 8px; border: 0; border-radius: 11px; background: transparent; color: #fff; text-align: left; }
.sidebar-user:hover { background: rgba(255,255,255,.055); }
.user-avatar { display: grid; width: 34px; height: 34px; place-items: center; border-radius: 10px; background: #2c374c; color: #c8cfff; font-weight: 700; }
.sidebar-user strong { display: block; max-width: 110px; overflow: hidden; text-overflow: ellipsis; }
.app-content { width: calc(100% - 244px); margin-left: 244px; }
.app-main { width: 100%; max-width: 1680px; min-height: 100vh; margin: auto; padding: 31px 34px 48px; }
.mobile-header { display: none; }

.page-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 20px; margin-bottom: 24px; }
.eyebrow { margin-bottom: 7px; color: var(--brand); font-size: .69rem; font-weight: 700; letter-spacing: .12em; text-transform: uppercase; }
.page-title { margin: 0; font-size: clamp(1.55rem, 2vw, 2.1rem); font-weight: 700; letter-spacing: -.04em; }
.page-subtitle { max-width: 720px; margin: 7px 0 0; color: var(--muted); line-height: 1.55; }
.page-meta { display: inline-flex; align-items: center; gap: 8px; white-space: nowrap; padding: 9px 12px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); color: var(--muted); font-weight: 600; }
.page-meta strong { color: var(--ink); }

.metric-card, .panel { border: 1px solid rgba(221,225,234,.85); border-radius: var(--radius); background: var(--surface); box-shadow: 0 7px 24px rgba(33,42,67,.045); }
.card { border-color: rgba(221,225,234,.85); border-radius: var(--radius); background: var(--surface); color: var(--ink); box-shadow: 0 7px 24px rgba(33,42,67,.045); }
.card-header { padding: 16px 20px; border-color: var(--line); border-radius: var(--radius) var(--radius) 0 0 !important; }
.card-body { padding: 20px; }
.metric-card { position: relative; min-height: 128px; padding: 20px; overflow: hidden; }
.metric-card::after { content: ""; position: absolute; width: 90px; height: 90px; top: -35px; right: -25px; border-radius: 50%; background: var(--metric-soft, #eef0ff); }
.metric-label { color: var(--muted); font-size: .74rem; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; }
.metric-value { margin-top: 11px; font-size: 1.8rem; font-weight: 700; letter-spacing: -.045em; }
.metric-note { margin-top: 4px; color: var(--muted); font-size: .74rem; }
.metric-icon { position: absolute; z-index: 1; top: 12px; right: 13px; display: grid; width: 44px; height: 44px; place-items: center; border-radius: 13px; color: var(--metric-color, var(--brand)); background: var(--metric-soft, #eef0ff); font-size: 1.35rem; line-height: 1; }
.metric-purple { --metric-color: var(--brand); --metric-soft: #eeeeff; }
.metric-blue { --metric-color: var(--blue); --metric-soft: #eaf3ff; }
.metric-green { --metric-color: var(--green); --metric-soft: #e9f8f2; }
.metric-amber { --metric-color: var(--amber); --metric-soft: #fff5e6; }

.panel-header { display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 18px 20px; border-bottom: 1px solid var(--line); }
.panel-title { margin: 0; font-size: .98rem; font-weight: 700; letter-spacing: -.015em; }
.panel-kicker { color: var(--muted); font-size: .75rem; }
.panel-body { padding: 20px; }
.chart-wrap { position: relative; min-height: 285px; }

.filter-panel .panel-header { cursor: pointer; }
.filter-panel .panel-header:hover { background: #fafbfc; border-radius: var(--radius) var(--radius) 0 0; }
.form-label { margin-bottom: 6px; color: #58647a; font-size: .73rem; font-weight: 700; }
.form-control, .form-select, .input-group-text {
    min-height: 40px;
    border-color: #dfe3ea;
    border-radius: 10px;
    font-size: .85rem;
}
.form-control:focus, .form-select:focus { border-color: #a9aaf4; box-shadow: 0 0 0 .22rem rgba(91,92,226,.11); }
.btn { border-radius: 10px; font-weight: 600; }
.btn-primary { border-color: var(--brand); background: var(--brand); }
.btn-primary:hover { border-color: var(--brand-dark); background: var(--brand-dark); }
.btn-sm { padding: .45rem .72rem; font-size: .78rem; }

.table-shell { overflow: hidden; }
.table-responsive { scrollbar-width: thin; }
.data-table { margin: 0; }
.data-table thead th { padding: 12px 15px; border: 0; background: #f8f9fb; color: #7a8497; font-size: .66rem; font-weight: 700; letter-spacing: .075em; text-transform: uppercase; white-space: nowrap; }
.data-table tbody td { padding: 13px 15px; border-color: #edf0f4; vertical-align: middle; }
.data-table tbody tr:last-child td { border-bottom: 0; }
.data-table tbody tr:hover td { background: #fafbff; }
.data-table tfoot td { padding: 14px 15px; border-top: 2px solid #dfe3ec; background: #f7f8ff; }
.cohort-total-row .money { color: #30317f; font-weight: 750; }
.cohort-total-chip { background: #e7e8ff; color: #3f40ad; }
.sort-link { display: inline-flex; align-items: center; gap: 6px; color: inherit; }
.sort-link:hover { color: var(--brand); }
.sort-link i { font-size: .78rem; }
.db-id { color: #9aa3b3; font: 600 .74rem/1 "DM Sans", sans-serif; }
.mono-value { max-width: 230px; overflow: hidden; color: #3d485d; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .77rem; text-overflow: ellipsis; white-space: nowrap; }
.empty-value { color: #b3bac6; }
.money { font-variant-numeric: tabular-nums; font-weight: 650; white-space: nowrap; }
.value-state { display: inline-block; margin-top: 3px; font-size: .61rem; font-weight: 750; letter-spacing: .055em; text-transform: uppercase; }
.value-live { color: #17825f; }
.value-live::before { content: ""; display: inline-block; width: 5px; height: 5px; margin-right: 5px; border-radius: 50%; background: #23b584; vertical-align: 1px; }
.value-locked { color: #8a94a6; }
.value-locked::before { content: "\F47A"; margin-right: 4px; font-family: "bootstrap-icons"; font-size: .64rem; }
.status-pill { display: inline-flex; align-items: center; gap: 6px; padding: 5px 9px; border-radius: 999px; font-size: .7rem; font-weight: 700; white-space: nowrap; }
.status-success { background: #e9f8f2; color: #0d7e58; }
.status-warning { background: #fff4df; color: #956011; }
.status-info { background: #eaf3ff; color: #2365b5; }
.status-neutral { background: #f0f2f5; color: #69758a; }
.group-chip { display: inline-flex; align-items: center; gap: 6px; padding: 5px 8px; border-radius: 8px; background: #f0f0ff; color: #4d4ec5; font-size: .76rem; font-weight: 650; white-space: nowrap; }
.currency-chip { padding: 4px 7px; border-radius: 7px; background: #eff2f6; color: #58647a; font-size: .68rem; font-weight: 750; }
.table-empty { padding: 52px 20px !important; color: var(--muted); text-align: center; }
.table-empty i { display: block; margin-bottom: 9px; color: #c1c7d1; font-size: 1.7rem; }
.pagination-bar { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-top: 18px; }
.currency-summary { display: flex; flex-wrap: wrap; gap: 8px; }
.currency-summary span { display: inline-flex; gap: 7px; padding: 6px 9px; border-radius: 9px; background: #f5f6f9; color: var(--muted); font-size: .73rem; }
.currency-summary strong { color: var(--ink); }
.app-alert { border: 0; border-radius: 12px; box-shadow: 0 6px 20px rgba(33,42,67,.05); }

.login-page { min-height: 100vh; display: grid; grid-template-columns: minmax(360px, 44%) 1fr; background: #fff; }
.login-visual { position: relative; display: flex; flex-direction: column; justify-content: space-between; padding: 48px; overflow: hidden; background: #111827; color: #fff; }
.login-visual::before, .login-visual::after { content: ""; position: absolute; border-radius: 50%; filter: blur(2px); }
.login-visual::before { width: 420px; height: 420px; right: -150px; top: -120px; background: radial-gradient(circle, rgba(111,112,245,.55), transparent 66%); }
.login-visual::after { width: 440px; height: 440px; left: -180px; bottom: -180px; background: radial-gradient(circle, rgba(32,180,137,.26), transparent 68%); }
.login-copy { position: relative; z-index: 1; max-width: 470px; }
.login-copy h1 { margin: 22px 0 12px; font-size: clamp(2rem, 4vw, 3.7rem); letter-spacing: -.055em; line-height: 1.02; }
.login-copy p { color: #aab3c4; font-size: 1rem; line-height: 1.7; }
.login-signal { position: relative; z-index: 1; display: flex; gap: 10px; align-items: center; color: #aab3c4; font-size: .8rem; }
.login-form-side { display: grid; place-items: center; padding: 32px; }
.login-card { width: min(410px, 100%); }
.login-card h2 { margin-bottom: 7px; font-size: 1.75rem; font-weight: 700; letter-spacing: -.04em; }
.login-card > p { margin-bottom: 30px; color: var(--muted); }

:root[data-theme="dark"] {
    color-scheme: dark;
    --ink: #eef3ff;
    --muted: #98a7bf;
    --line: #2b374a;
    --surface: #151e2d;
    --canvas: #0c121c;
    --brand: #8587ff;
    --brand-dark: #7174ed;
    --nav: #080d15;
    --green: #37c997;
    --amber: #f1ad45;
    --blue: #65a8ff;
    --chart-grid: rgba(160,176,202,.14);
}
:root[data-theme="dark"] .metric-card,
:root[data-theme="dark"] .panel,
:root[data-theme="dark"] .card {
    border-color: #283447;
    box-shadow: 0 9px 28px rgba(0,0,0,.2);
}
:root[data-theme="dark"] .metric-purple { --metric-soft: #292b55; }
:root[data-theme="dark"] .metric-blue { --metric-soft: #173452; }
:root[data-theme="dark"] .metric-green { --metric-soft: #143d34; }
:root[data-theme="dark"] .metric-amber { --metric-soft: #49361d; }
:root[data-theme="dark"] .filter-panel .panel-header:hover,
:root[data-theme="dark"] .data-table tbody tr:hover td { background: #192334; }
:root[data-theme="dark"] .form-label { color: #b1bdd0; }
:root[data-theme="dark"] .form-control,
:root[data-theme="dark"] .form-select,
:root[data-theme="dark"] .input-group-text {
    border-color: #344158;
    background-color: #101827;
    color: var(--ink);
}
:root[data-theme="dark"] .form-control::placeholder { color: #718098; }
:root[data-theme="dark"] .form-control:focus,
:root[data-theme="dark"] .form-select:focus {
    border-color: #777af0;
    background-color: #101827;
    color: var(--ink);
}
:root[data-theme="dark"] .data-table {
    --bs-table-bg: transparent;
    --bs-table-color: var(--ink);
    --bs-table-border-color: var(--line);
}
:root[data-theme="dark"] .data-table thead th { background: #111a28; color: #94a4bd; }
:root[data-theme="dark"] .data-table tbody td { border-color: #253145; }
:root[data-theme="dark"] .data-table tfoot td { border-color: #3b4961; background: #192238; }
:root[data-theme="dark"] .cohort-total-row .money { color: #b9baff; }
:root[data-theme="dark"] .cohort-total-chip { background: #303264; color: #c5c6ff; }
:root[data-theme="dark"] .mono-value { color: #c0cbdd; }
:root[data-theme="dark"] .db-id,
:root[data-theme="dark"] .empty-value,
:root[data-theme="dark"] .value-locked { color: #7e8da5; }
:root[data-theme="dark"] .group-chip { background: #2b2d59; color: #c5c6ff; }
:root[data-theme="dark"] .currency-chip { background: #263246; color: #bac5d8; }
:root[data-theme="dark"] .status-success { background: #153b32; color: #61d9ad; }
:root[data-theme="dark"] .status-warning { background: #46351d; color: #f2bf69; }
:root[data-theme="dark"] .status-info { background: #183450; color: #82baff; }
:root[data-theme="dark"] .status-neutral { background: #273245; color: #b2bed1; }
:root[data-theme="dark"] .currency-summary span { background: #202b3d; }
:root[data-theme="dark"] .btn-outline-secondary { border-color: #46546b; color: #b6c1d3; }
:root[data-theme="dark"] .btn-outline-secondary:hover { border-color: #66758d; background: #29364a; color: #fff; }
:root[data-theme="dark"] .text-muted { color: var(--muted) !important; }
:root[data-theme="dark"] .login-page { background: var(--canvas); }
:root[data-theme="dark"] .login-form-side { background: var(--surface); }
:root[data-theme="dark"] .btn-close { filter: invert(1) grayscale(100%) brightness(180%); }

@media (max-width: 991.98px) {
    .app-sidebar { display: none; }
    .app-content { width: 100%; margin-left: 0; }
    .mobile-header { position: sticky; top: 0; z-index: 1020; display: flex; align-items: center; justify-content: space-between; height: 64px; padding: 0 20px; border-bottom: 1px solid var(--line); background: rgba(255,255,255,.94); backdrop-filter: blur(12px); }
    .mobile-header .brand { color: var(--ink); }
    .mobile-header .brand-mark { width: 34px; height: 34px; }
    .mobile-header nav { display: flex; gap: 4px; }
    .mobile-header nav a, .mobile-theme-toggle { display: grid; width: 36px; height: 36px; place-items: center; border: 0; border-radius: 9px; background: transparent; color: var(--muted); }
    .mobile-header nav a:hover, .mobile-theme-toggle:hover { background: #f0f1f5; color: var(--brand); }
    .app-main { padding: 24px 20px 42px; }
}

:root[data-theme="dark"] .mobile-header { background: rgba(12,18,28,.94); }
:root[data-theme="dark"] .mobile-header nav a:hover,
:root[data-theme="dark"] .mobile-theme-toggle:hover { background: #202b3d; }

@media (max-width: 767.98px) {
    .page-header { align-items: stretch; flex-direction: column; }
    .page-meta { align-self: flex-start; }
    .metric-card { min-height: 112px; }
    .panel-header, .panel-body { padding: 16px; }
    .login-page { grid-template-columns: 1fr; }
    .login-visual { min-height: 250px; padding: 28px; }
    .login-copy h1 { font-size: 2.15rem; }
    .login-signal { display: none; }
    .login-form-side { padding: 42px 24px; }
    .pagination-bar { align-items: stretch; flex-direction: column; }
}
