:root {
  --bg: #f4f5f8; --surface: #ffffff; --surface-2: #eef0f5; --line: #dfe2ea;
  --text: #1b2236; --muted: #5d6679; --brand: #1f2a44; --brand-text: #ffffff;
  --accent: #b8741a; --accent-bg: #fff3dc;
  --good: #1a7f4b; --good-bg: #e3f5ec; --bad: #b3261e; --bad-bg: #fdeceb; --warn: #8a5a00; --warn-bg: #fff3d6;
  --c1: #2f6fdb; --c2: #d9822b; --c3: #1a7f4b; --c4: #8b5cf6; --c5: #d1457c; --c6: #0e8fa3;
  --radius: 14px; --shadow: 0 1px 2px rgba(20,28,48,.06), 0 4px 14px rgba(20,28,48,.05);
  --safe-top: env(safe-area-inset-top, 0px); --safe-bottom: env(safe-area-inset-bottom, 0px);
  --nav-h: 62px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1424; --surface: #181f35; --surface-2: #1f2742; --line: #2a3454;
    --text: #e8ebf5; --muted: #9aa4bf; --brand: #0b1020; --accent: #ffc45e; --accent-bg: #3a2c10;
    --good: #5fd49a; --good-bg: #123325; --bad: #ff8b82; --bad-bg: #3a1714; --warn: #ffcf70; --warn-bg: #3a2c10;
    --c1: #6ea0ff; --c2: #ffa95c; --c3: #5fd49a; --c4: #b392ff; --c5: #ff7fb0; --c6: #5ed3e6;
    --shadow: 0 1px 2px rgba(0,0,0,.4);
  }
}
:root[data-theme="dark"] {
  --bg: #0f1424; --surface: #181f35; --surface-2: #1f2742; --line: #2a3454;
  --text: #e8ebf5; --muted: #9aa4bf; --brand: #0b1020; --accent: #ffc45e; --accent-bg: #3a2c10;
  --good: #5fd49a; --good-bg: #123325; --bad: #ff8b82; --bad-bg: #3a1714; --warn: #ffcf70; --warn-bg: #3a2c10;
  --c1: #6ea0ff; --c2: #ffa95c; --c3: #5fd49a; --c4: #b392ff; --c5: #ff7fb0; --c6: #5ed3e6;
  --shadow: 0 1px 2px rgba(0,0,0,.4);
  }
[hidden] { display: none !important; }
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
a { color: var(--c1); text-decoration: none; } a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; line-height: 1.2; } h1 { font-size: 1.5rem; } h2 { font-size: 1.1rem; } h3 { font-size: .95rem; }
.boot { padding: 40px; text-align: center; color: var(--muted); }
.muted { color: var(--muted); } .small { font-size: .82rem; } .right { text-align: right; } .nowrap { white-space: nowrap; }
.num { font-variant-numeric: tabular-nums; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--c1); outline-offset: 2px; border-radius: 6px; }

/* layout */
.shell { min-height: 100vh; display: block; }
.sidebar { display: none; }
.main { padding: calc(var(--safe-top) + 14px) 16px calc(var(--nav-h) + var(--safe-bottom) + 24px); max-width: 1180px; margin: 0 auto; }
.topbar { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
.topbar .grow { flex: 1; min-width: 0; }
.crumbs { font-size: .82rem; color: var(--muted); margin-bottom: 2px; }
.crumbs a { color: var(--muted); } .crumbs span.sep { margin: 0 5px; }
.page-title { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.nav-bottom { position: fixed; left: 0; right: 0; bottom: 0; background: var(--surface); border-top: 1px solid var(--line);
  display: flex; padding: 4px 6px calc(4px + var(--safe-bottom)); z-index: 20; }
.nav-bottom a, .nav-bottom button { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 6px 2px;
  color: var(--muted); font-size: .68rem; background: none; border: 0; border-radius: 10px; min-height: 48px; text-decoration: none; cursor: pointer; }
.nav-bottom .active { color: var(--text); background: var(--surface-2); }
.icon { width: 22px; height: 22px; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.drawer-back { position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 30; }
.drawer { position: fixed; left: 0; right: 0; bottom: 0; background: var(--surface); z-index: 31; border-radius: 18px 18px 0 0;
  padding: 14px 14px calc(18px + var(--safe-bottom)); max-height: 80vh; overflow: auto; }
.drawer a { display: flex; gap: 12px; align-items: center; padding: 13px 10px; border-radius: 10px; color: var(--text); }
.drawer a.active { background: var(--surface-2); }
@media (min-width: 900px) {
  .shell { display: grid; grid-template-columns: 236px 1fr; }
  .sidebar { display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; background: var(--brand); color: #dfe5f5; padding: 18px 12px; }
  .sidebar .brand { display: flex; align-items: center; gap: 10px; padding: 4px 10px 18px; font-weight: 700; color: #fff; }
  .sidebar .brand img { width: 30px; height: 30px; border-radius: 8px; }
  .sidebar nav { display: flex; flex-direction: column; gap: 2px; overflow: auto; flex: 1; }
  .sidebar a { display: flex; gap: 11px; align-items: center; padding: 9px 12px; border-radius: 10px; color: #c9d1e8; }
  .sidebar a:hover { background: rgba(255,255,255,.07); text-decoration: none; }
  .sidebar a.active { background: rgba(255,255,255,.14); color: #fff; }
  .sidebar .foot { font-size: .78rem; color: #8e99b8; padding: 10px; }
  .main { padding: 28px 32px 48px; width: 100%; }
  .nav-bottom { display: none; }
}

/* components */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.card > h2 + *, .card > h3 + * { margin-top: 10px; }
.grid { display: grid; gap: 12px; }
.kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.cols-2, .cols-3 { grid-template-columns: 1fr; }
@media (min-width: 700px) { .kpis { grid-template-columns: repeat(3, minmax(0, 1fr)); } .cols-2 { grid-template-columns: 1fr 1fr; } }
@media (min-width: 1000px) { .kpis { grid-template-columns: repeat(5, minmax(0, 1fr)); } .cols-3 { grid-template-columns: repeat(3, 1fr); } }
.kpi .label { font-size: .78rem; color: var(--muted); }
.kpi .value { font-size: 1.45rem; font-weight: 700; margin-top: 2px; font-variant-numeric: tabular-nums; }
.kpi .sub { font-size: .75rem; color: var(--muted); margin-top: 2px; }
.pos { color: var(--good); } .neg { color: var(--bad); }
.stack { display: flex; flex-direction: column; gap: 14px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; } .row.between { justify-content: space-between; }
.btn { display: inline-flex; align-items: center; gap: 6px; padding: 9px 14px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface);
  cursor: pointer; font-weight: 600; min-height: 40px; text-decoration: none; color: var(--text); }
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn.primary { background: var(--c1); color: #fff; border-color: var(--c1); } .btn.primary:hover { filter: brightness(1.08); background: var(--c1); }
.btn.danger { color: var(--bad); border-color: var(--bad); } .btn.small { padding: 5px 10px; min-height: 32px; font-size: .85rem; }
.btn[disabled] { opacity: .55; cursor: not-allowed; }
.chip { display: inline-block; padding: 2px 9px; border-radius: 99px; font-size: .75rem; font-weight: 600; background: var(--surface-2); color: var(--muted); }
.chip.good { background: var(--good-bg); color: var(--good); } .chip.bad { background: var(--bad-bg); color: var(--bad); }
.chip.warn { background: var(--warn-bg); color: var(--warn); } .chip.info { background: var(--accent-bg); color: var(--accent); }
.filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 14px; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; background: var(--surface); }
.seg button { border: 0; background: none; padding: 7px 12px; cursor: pointer; font-size: .85rem; color: var(--muted); min-height: 36px; }
.seg button.active { background: var(--brand); color: #fff; }
@media (prefers-color-scheme: dark) { .seg button.active { background: var(--c1); } }
.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; } .field label { font-size: .82rem; color: var(--muted); font-weight: 600; }
input, select, textarea { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 9px 11px; min-height: 40px; width: 100%; }
input[type=date] { min-width: 0; }
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; font-size: .88rem; }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: .75rem; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; white-space: nowrap; }
td.right, th.right { text-align: right; }
tbody tr:hover { background: var(--surface-2); }
.list { list-style: none; margin: 0; padding: 0; } .list li { padding: 10px 0; border-bottom: 1px solid var(--line); } .list li:last-child { border: 0; }
.empty, .errorbox, .loading { text-align: center; padding: 28px 12px; color: var(--muted); }
.errorbox { color: var(--bad); background: var(--bad-bg); border-radius: var(--radius); }
.spinner { width: 22px; height: 22px; border: 3px solid var(--line); border-top-color: var(--c1); border-radius: 50%; animation: spin .8s linear infinite; margin: 0 auto 8px; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 3s; } }
.notice { padding: 10px 12px; border-radius: 10px; background: var(--warn-bg); color: var(--warn); font-size: .88rem; }
.notice.good { background: var(--good-bg); color: var(--good); } .notice.bad { background: var(--bad-bg); color: var(--bad); }
.countdown { font-size: 1.7rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: .78rem; color: var(--muted); margin-top: 6px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }
.chart { width: 100%; height: auto; display: block; } .chart text { fill: var(--muted); font-size: 11px; } .chart .grid { stroke: var(--line); }
.bars .name { display: grid; grid-template-columns: minmax(90px, 32%) 1fr auto; gap: 8px; align-items: center; margin: 7px 0; font-size: .85rem; }
.bars .track { background: var(--surface-2); border-radius: 6px; height: 12px; overflow: hidden; } .bars .fill { height: 100%; border-radius: 6px; background: var(--c1); }
.thumb { width: 100%; max-width: 280px; border-radius: 12px; border: 1px solid var(--line); background: repeating-conic-gradient(var(--surface-2) 0 25%, var(--surface) 0 50%) 0 0 / 16px 16px; }
dialog { border: 1px solid var(--line); border-radius: 16px; background: var(--surface); color: var(--text); padding: 20px; width: min(520px, calc(100vw - 24px)); box-shadow: 0 20px 60px rgba(0,0,0,.35); }
dialog::backdrop { background: rgba(0,0,0,.5); }
.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--nav-h) + var(--safe-bottom) + 16px); background: var(--brand); color: #fff;
  padding: 10px 16px; border-radius: 12px; z-index: 50; max-width: calc(100vw - 32px); box-shadow: var(--shadow); }
.toast.bad { background: var(--bad); }
.login { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login .card { width: min(380px, 100%); } .login img { width: 64px; height: 64px; border-radius: 16px; display: block; margin: 0 auto 12px; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.badge-dot { display: inline-block; min-width: 18px; padding: 0 5px; border-radius: 9px; background: var(--bad); color: #fff; font-size: .7rem; text-align: center; margin-left: 4px; }

/* Tables become stacked cards on phones: each cell shows its column name (set by main.js). */
@media (max-width: 699px) {
  .table-wrap { overflow: visible; }
  table.cards thead { display: none; }
  table.cards, table.cards tbody, table.cards tfoot { display: block; }
  table.cards tr { display: block; padding: 10px 2px; border-bottom: 1px solid var(--line); }
  table.cards td { display: flex; justify-content: space-between; gap: 14px; border: 0; padding: 2px 0; text-align: right; }
  table.cards td::before { content: attr(data-label); color: var(--muted); font-size: .72rem; text-transform: uppercase; letter-spacing: .03em; text-align: left; flex: none; padding-top: 2px; }
  table.cards td:not([data-label])::before, table.cards td[data-label=""]::before { content: none; }
  table.cards td:not([data-label]), table.cards td[data-label=""] { justify-content: flex-end; }
  table.cards tfoot tr { display: flex; justify-content: space-between; }
  table.cards tfoot th { border: 0; padding: 2px 0; }
  table.cards tfoot th[colspan] { flex: 1; }
}
