:root {
  --bg: #f6f7fb;
  --surface: #ffffff;
  --surface-2: #f1f3f8;
  --border: #e3e6ee;
  --text: #161a26;
  --muted: #667085;
  --accent: #5b4bdb;
  --accent-weak: #ecebfd;
  --side: #14162b;
  --side-text: #b9bdd6;
  --side-active: #262a4d;
  --pos: #12805c;
  --pos-bg: #e3f6ee;
  --neg: #c4320a;
  --neg-bg: #fdece6;
  --warn: #b54708;
  --warn-bg: #fff4e5;
  --c1: #5b4bdb; --c2: #12a594; --c3: #f59e0b; --c4: #e5484d; --c5: #3e9ff5; --c6: #a855f7; --c7: #84cc16; --c8: #94a3b8;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 1px 3px rgba(16, 24, 40, .06);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0e1017; --surface: #161925; --surface-2: #1d2131; --border: #2a2f43; --text: #e8eaf2; --muted: #9aa1b9;
    --accent: #8b7ff5; --accent-weak: #262449; --side: #0a0b12; --side-text: #9aa1b9; --side-active: #1f2238;
    --pos: #3ccf91; --pos-bg: #133227; --neg: #ff7a5c; --neg-bg: #3a1d16; --warn: #f5a524; --warn-bg: #3a2a12;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0e1017; --surface: #161925; --surface-2: #1d2131; --border: #2a2f43; --text: #e8eaf2; --muted: #9aa1b9;
  --accent: #8b7ff5; --accent-weak: #262449; --side: #0a0b12; --side-text: #9aa1b9; --side-active: #1f2238;
  --pos: #3ccf91; --pos-bg: #133227; --neg: #ff7a5c; --neg-bg: #3a1d16; --warn: #f5a524; --warn-bg: #3a2a12;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body { background: var(--bg); color: var(--text); font: 14px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, Helvetica, Arial, sans-serif; -webkit-font-smoothing: antialiased; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; margin: 0; letter-spacing: -.01em; }
h2 { font-size: 16px; margin: 0 0 12px; }
h3 { font-size: 14px; margin: 0 0 8px; }
.boot { display: grid; place-items: center; height: 100vh; color: var(--muted); }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.num { font-variant-numeric: tabular-nums; }
.right { text-align: right; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.grow { flex: 1; }
.hidden { display: none !important; }
.pos { color: var(--pos); }
.neg { color: var(--neg); }

/* Layout */
.layout { display: grid; grid-template-columns: 236px 1fr; min-height: 100vh; }
.side { background: var(--side); color: var(--side-text); padding: 16px 12px; position: sticky; top: 0; height: 100vh; overflow-y: auto; display: flex; flex-direction: column; gap: 4px; }
.brand { display: flex; gap: 10px; align-items: center; color: #fff; font-weight: 700; font-size: 17px; padding: 4px 8px 16px; }
.brand svg { flex: none; }
.side .sec { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; padding: 14px 10px 6px; opacity: .7; }
.side a { color: var(--side-text); display: flex; gap: 10px; align-items: center; padding: 8px 10px; border-radius: 8px; font-size: 14px; }
.side a:hover { background: var(--side-active); text-decoration: none; color: #fff; }
.side a.active { background: var(--side-active); color: #fff; box-shadow: inset 3px 0 0 var(--accent); }
.side a svg { width: 18px; height: 18px; flex: none; opacity: .85; }
.side .foot { margin-top: auto; padding-top: 16px; }
.main { min-width: 0; display: flex; flex-direction: column; }
.top { position: sticky; top: 0; z-index: 20; background: color-mix(in srgb, var(--bg) 92%, transparent); backdrop-filter: blur(6px); border-bottom: 1px solid var(--border); padding: 10px 24px; display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.content { padding: 20px 24px 48px; max-width: 1480px; width: 100%; }
.page-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.burger { display: none; }

@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
  .side { position: fixed; z-index: 50; left: 0; top: 0; width: 260px; transform: translateX(-100%); transition: transform .2s; }
  .side.open { transform: none; box-shadow: 0 0 0 100vmax rgba(0,0,0,.4); }
  .burger { display: inline-flex; }
  .top { padding: 10px 16px; }
  .content { padding: 16px 16px 48px; }
}

/* Controls */
button, .btn { font: inherit; border: 1px solid var(--border); background: var(--surface); color: var(--text); border-radius: 8px; padding: 7px 12px; cursor: pointer; display: inline-flex; gap: 6px; align-items: center; white-space: nowrap; }
button:hover, .btn:hover { border-color: color-mix(in srgb, var(--accent) 45%, var(--border)); text-decoration: none; }
button.primary, .btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.primary:hover { filter: brightness(1.07); }
button.danger { color: var(--neg); }
button.ghost { background: transparent; border-color: transparent; }
button:disabled { opacity: .55; cursor: default; }
button svg { width: 16px; height: 16px; }
input, select, textarea { font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 7px 10px; min-width: 0; }
input:focus, select:focus, textarea:focus, button:focus-visible { outline: 2px solid color-mix(in srgb, var(--accent) 50%, transparent); outline-offset: 1px; }
input[type="checkbox"] { width: 16px; height: 16px; accent-color: var(--accent); }
textarea { width: 100%; min-height: 120px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; }
label.field { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
label.field > input, label.field > select, label.field > textarea { color: var(--text); }
label.check { display: flex; gap: 8px; align-items: flex-start; cursor: pointer; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; background: var(--surface); }
.seg button { border: 0; border-radius: 0; padding: 6px 12px; }
.seg button.on { background: var(--accent-weak); color: var(--accent); font-weight: 600; }

/* Cards */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; min-width: 0; }
.card + .card { margin-top: 16px; }
.grid > .card + .card { margin-top: 0; }
.grid { display: grid; gap: 16px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
@media (max-width: 1100px) { .g3 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 760px) { .g2, .g3 { grid-template-columns: 1fr; } }

.kpis { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 0; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
.kpi { background: var(--surface); padding: 14px 16px; min-width: 0; box-shadow: 1px 0 0 var(--border), 0 1px 0 var(--border); }
.kpi .l { font-size: 12.5px; color: var(--muted); display: flex; gap: 4px; align-items: center; }
.kpi .v { font-size: 21px; font-weight: 650; margin: 4px 0 4px; font-variant-numeric: tabular-nums; letter-spacing: -.01em; overflow-wrap: anywhere; }
.kpi.hero { grid-column: span 2; background: linear-gradient(135deg, var(--accent-weak), var(--surface) 70%); }
.kpi.hero .v { font-size: 34px; }
@media (max-width: 520px) { .kpi.hero { grid-column: span 1; } .kpis { grid-template-columns: repeat(2, minmax(0,1fr)); } .kpi.hero { grid-column: span 2; } }
.delta { display: inline-flex; gap: 3px; align-items: center; font-size: 12px; font-weight: 600; padding: 1px 6px; border-radius: 6px; font-variant-numeric: tabular-nums; }
.delta.up { color: var(--pos); background: var(--pos-bg); }
.delta.down { color: var(--neg); background: var(--neg-bg); }
.delta.flat { color: var(--muted); background: var(--surface-2); }
.prev { font-size: 11.5px; color: var(--muted); margin-left: 4px; }
.tip { cursor: help; border-bottom: 1px dashed var(--muted); }

.stat-list { display: grid; gap: 10px; }
.stat-list .it { display: flex; justify-content: space-between; gap: 12px; align-items: baseline; }
.stat-list .it .k { color: var(--muted); }
.stat-list .it .val { font-weight: 600; font-variant-numeric: tabular-nums; text-align: right; }

/* Tables */
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow); }
table { border-collapse: collapse; width: 100%; font-size: 13px; }
th, td { padding: 9px 12px; border-bottom: 1px solid var(--border); text-align: left; white-space: nowrap; }
th { font-size: 12px; color: var(--muted); font-weight: 600; background: var(--surface-2); position: sticky; top: 0; z-index: 1; }
th.sortable { cursor: pointer; user-select: none; }
th.sortable:hover { color: var(--text); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: color-mix(in srgb, var(--accent-weak) 35%, transparent); }
tr.total td { font-weight: 700; background: var(--surface-2); }
tr.sub td:first-child { padding-left: 28px; color: var(--muted); }
tr.strong td { font-weight: 700; }
td.wrap { white-space: normal; min-width: 220px; }
.thumb { width: 34px; height: 34px; border-radius: 6px; object-fit: cover; background: var(--surface-2); flex: none; }
.pcell { display: flex; gap: 10px; align-items: center; min-width: 240px; max-width: 420px; white-space: normal; }
.badge { display: inline-block; font-size: 11.5px; padding: 1px 7px; border-radius: 999px; background: var(--surface-2); color: var(--muted); font-weight: 600; }
.badge.ok { background: var(--pos-bg); color: var(--pos); }
.badge.bad { background: var(--neg-bg); color: var(--neg); }
.badge.warn { background: var(--warn-bg); color: var(--warn); }
.badge.acc { background: var(--accent-weak); color: var(--accent); }
td input { width: 92px; padding: 5px 8px; text-align: right; }
.pager { display: flex; gap: 8px; align-items: center; justify-content: flex-end; padding: 10px 0; }

/* Charts */
.chart { position: relative; width: 100%; }
.chart svg { display: block; width: 100%; overflow: visible; }
.chart .axis { fill: var(--muted); font-size: 11px; }
.chart .grid-line { stroke: var(--border); stroke-width: 1; }
.chart-tip { position: absolute; pointer-events: none; background: var(--surface); border: 1px solid var(--border); box-shadow: 0 6px 20px rgba(0,0,0,.12); border-radius: 8px; padding: 8px 10px; font-size: 12px; z-index: 5; min-width: 150px; }
.chart-tip .t { font-weight: 700; margin-bottom: 4px; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 12px; color: var(--muted); margin-top: 8px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }
.donut-wrap { display: grid; grid-template-columns: 180px 1fr; gap: 16px; align-items: center; }
@media (max-width: 520px) { .donut-wrap { grid-template-columns: 1fr; justify-items: center; } }

/* Date picker */
.dp { position: relative; }
.dp-pop { position: absolute; top: calc(100% + 6px); left: 0; z-index: 40; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; box-shadow: 0 12px 32px rgba(0,0,0,.16); padding: 12px; display: grid; grid-template-columns: 170px 1fr; gap: 12px; width: min(460px, calc(100vw - 32px)); }
.dp-pop .presets { display: grid; gap: 2px; }
.dp-pop .presets button { border: 0; justify-content: flex-start; }
.dp-pop .presets button.on { background: var(--accent-weak); color: var(--accent); }
@media (max-width: 520px) { .dp-pop { grid-template-columns: 1fr; } }

/* Misc */
.notice { padding: 12px 14px; border-radius: 10px; background: var(--accent-weak); color: var(--text); border: 1px solid color-mix(in srgb, var(--accent) 25%, transparent); }
.notice.warn { background: var(--warn-bg); border-color: color-mix(in srgb, var(--warn) 30%, transparent); }
.notice.bad { background: var(--neg-bg); border-color: color-mix(in srgb, var(--neg) 30%, transparent); }
.steps { margin: 8px 0 0; padding-left: 20px; display: grid; gap: 6px; }
.steps li::marker { color: var(--accent); font-weight: 700; }
code, .code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; background: var(--surface-2); padding: 1px 5px; border-radius: 5px; overflow-wrap: anywhere; }
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px; z-index: 100; box-shadow: 0 8px 24px rgba(0,0,0,.25); max-width: calc(100vw - 32px); }
.toast.bad { background: var(--neg); color: #fff; }
.modal-back { position: fixed; inset: 0; background: rgba(10, 12, 20, .45); z-index: 80; display: grid; place-items: center; padding: 16px; }
.modal { background: var(--surface); border-radius: 14px; border: 1px solid var(--border); width: min(640px, 100%); max-height: calc(100vh - 32px); overflow-y: auto; padding: 20px; box-shadow: 0 20px 60px rgba(0,0,0,.3); }
.modal .actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login .card { width: min(380px, 100%); }
.spinner { width: 16px; height: 16px; border: 2px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }
.loading { opacity: .55; pointer-events: none; transition: opacity .15s; }
.empty { padding: 36px; text-align: center; color: var(--muted); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { display: inline-flex; gap: 4px; align-items: center; background: var(--surface-2); border: 1px solid var(--border); border-radius: 999px; padding: 2px 8px; font-size: 12px; }
.chip button { border: 0; padding: 0; background: none; color: var(--muted); }
.bar-track { height: 6px; background: var(--surface-2); border-radius: 4px; overflow: hidden; }
.bar-fill { height: 100%; background: var(--accent); border-radius: 4px; }
.heat { font-variant-numeric: tabular-nums; text-align: right; }
details summary { cursor: pointer; }
