:root {
  color-scheme: light;
  --bg: #f4f3ef;
  --surface: #fcfcfb;
  --surface-2: #f0efec;
  --border: #e3e1db;
  --text: #0b0b0b;
  --text-2: #52514e;
  --muted: #8a8984;
  --accent: #2a78d6;
  --accent-soft: #e3eefb;
  --cash: #eb6834;
  --cashless: #2a78d6;
  --good: #0f7b3e;
  --bad: #c62f2e;
  --grid: #ecebe6;
  --shadow: 0 1px 2px rgba(0,0,0,.04), 0 4px 16px rgba(0,0,0,.04);
  --seq-0: #f0efec; --seq-1: #cde2fb; --seq-2: #9ec5f4; --seq-3: #6da7ec; --seq-4: #3987e5; --seq-5: #256abf; --seq-6: #184f95;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #121211; --surface: #1a1a19; --surface-2: #232321; --border: #2f2f2c;
    --text: #ffffff; --text-2: #c3c2b7; --muted: #8d8c85;
    --accent: #3987e5; --accent-soft: #1d2d42;
    --cash: #d95926; --cashless: #3987e5; --good: #3fbf72; --bad: #e66767; --grid: #2a2a27;
    --shadow: none;
    --seq-0: #232321; --seq-1: #104281; --seq-2: #184f95; --seq-3: #1c5cab; --seq-4: #2a78d6; --seq-5: #5598e7; --seq-6: #9ec5f4;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 14px/1.45 "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-variant-numeric: tabular-nums;
}
button, input, select { font: inherit; color: inherit; }
a { color: var(--accent); }

/* ---------- login ---------- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card {
  width: 100%; max-width: 360px; background: var(--surface); border: 1px solid var(--border);
  border-radius: 14px; padding: 28px; box-shadow: var(--shadow);
}
.login-card h1 { font-size: 20px; margin: 0 0 4px; }
.login-card p { margin: 0 0 20px; color: var(--text-2); }
.login-card label { display: block; font-size: 12px; color: var(--text-2); margin: 12px 0 4px; }
.login-card input {
  width: 100%; padding: 10px 12px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface);
}
.login-card input:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
.login-card button {
  width: 100%; margin-top: 20px; padding: 11px; border: 0; border-radius: 8px;
  background: var(--accent); color: #fff; font-weight: 600; cursor: pointer;
}
.login-error { background: color-mix(in srgb, var(--bad) 12%, transparent); color: var(--bad); padding: 8px 12px; border-radius: 8px; margin-bottom: 8px; }

/* ---------- layout ---------- */
.topbar {
  display: flex; align-items: center; gap: 12px; padding: 14px 24px;
  background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 20;
}
.topbar h1 { font-size: 17px; margin: 0; font-weight: 650; }
.topbar .updated { color: var(--muted); font-size: 12px; margin-left: auto; }
.btn {
  border: 1px solid var(--border); background: var(--surface); padding: 7px 12px; border-radius: 8px;
  cursor: pointer; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
main { max-width: 1400px; margin: 0 auto; padding: 20px 24px 60px; }

.banner { padding: 10px 14px; border-radius: 10px; margin-bottom: 14px; }
.banner.err { background: color-mix(in srgb, var(--bad) 12%, transparent); color: var(--bad); }
.banner.info { background: var(--accent-soft); color: var(--text); }

/* ---------- filters ---------- */
.filters {
  display: flex; flex-wrap: wrap; gap: 10px 14px; align-items: center;
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 12px 14px; margin-bottom: 16px;
}
.seg { display: inline-flex; background: var(--surface-2); border-radius: 8px; padding: 3px; flex-wrap: wrap; }
.seg button { border: 0; background: transparent; padding: 5px 10px; border-radius: 6px; cursor: pointer; color: var(--text-2); }
.seg button.on { background: var(--surface); color: var(--text); box-shadow: 0 1px 2px rgba(0,0,0,.08); font-weight: 600; }
.dates { display: inline-flex; align-items: center; gap: 6px; }
.dates input { border: 1px solid var(--border); border-radius: 8px; padding: 5px 8px; background: var(--surface); }
.flabel { font-size: 12px; color: var(--muted); }

.dd { position: relative; }
.dd-panel {
  position: absolute; top: calc(100% + 6px); left: 0; z-index: 30; min-width: 240px; max-height: 60vh; overflow: auto;
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 8px; box-shadow: 0 8px 30px rgba(0,0,0,.15);
}
.dd-panel label { display: flex; gap: 8px; align-items: center; padding: 6px 8px; border-radius: 6px; cursor: pointer; }
.dd-panel label:hover { background: var(--surface-2); }
.dd-actions { display: flex; gap: 6px; padding: 4px 4px 8px; border-bottom: 1px solid var(--border); margin-bottom: 4px; }
.dd-actions button { flex: 1; font-size: 12px; padding: 4px; }
.spacer { flex: 1; }

/* ---------- KPI ---------- */
.kpis { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 14px 16px; min-width: 0; }
.kpi .k-label { color: var(--text-2); font-size: 12px; }
.kpi .k-value { font-size: 22px; font-weight: 650; margin-top: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kpi .k-sub { font-size: 12px; color: var(--muted); margin-top: 2px; }
.delta.up { color: var(--good); } .delta.down { color: var(--bad); }

/* ---------- cards ---------- */
.grid2 { display: grid; grid-template-columns: 3fr 2fr; gap: 16px; margin-bottom: 16px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 16px; min-width: 0; margin-bottom: 16px; }
.grid2 .card { margin-bottom: 0; }
.card-h { display: flex; align-items: baseline; gap: 10px; margin-bottom: 10px; flex-wrap: wrap; }
.card-h h2 { font-size: 15px; margin: 0; font-weight: 650; }
.card-h .hint { color: var(--muted); font-size: 12px; }
.legend { display: inline-flex; gap: 14px; font-size: 12px; color: var(--text-2); margin-left: auto; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }
.chart-box { position: relative; height: 300px; }
.chart-box.tall { height: 360px; }

/* ---------- tables ---------- */
.tbl-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 8px 10px; text-align: right; border-bottom: 1px solid var(--grid); white-space: nowrap; }
th { font-size: 12px; font-weight: 600; color: var(--text-2); cursor: pointer; user-select: none; position: sticky; top: 0; background: var(--surface); }
th:first-child, td:first-child, th.l, td.l { text-align: left; }
th.sorted::after { content: " ↓"; } th.sorted.asc::after { content: " ↑"; }
tbody tr:hover { background: var(--surface-2); }
tr.total td { font-weight: 650; border-top: 2px solid var(--border); border-bottom: 0; }
td.pt { cursor: pointer; font-weight: 550; }
td.pt:hover { color: var(--accent); }
.share { display: inline-flex; align-items: center; gap: 6px; }
.share .bar { width: 60px; height: 6px; background: var(--surface-2); border-radius: 3px; overflow: hidden; }
.share .bar b { display: block; height: 100%; background: var(--accent); border-radius: 3px; }
.status-err { color: var(--bad); }
.pivot td { min-width: 84px; }
.pivot td.cell { color: var(--text); }
.pivot td.cell.dark { color: #fff; }
.pivot-scroll { max-height: 520px; overflow: auto; }
.pivot th:first-child, .pivot td:first-child { position: sticky; left: 0; background: var(--surface); z-index: 1; }
.pivot thead th:first-child { z-index: 3; }
.detail-tools { display: flex; gap: 10px; align-items: center; margin-left: auto; }
.detail-tools input[type=search] { border: 1px solid var(--border); border-radius: 8px; padding: 5px 10px; background: var(--surface); width: 200px; }
.detail-scroll { max-height: 520px; overflow: auto; }
.muted { color: var(--muted); }
.empty { padding: 40px; text-align: center; color: var(--muted); }

.chart-tip {
  position: absolute; pointer-events: none; z-index: 40; background: var(--surface); color: var(--text);
  border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; font-size: 12px; box-shadow: 0 6px 20px rgba(0,0,0,.15);
  white-space: nowrap;
}

@media (max-width: 1100px) {
  .kpis { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .grid2 { grid-template-columns: 1fr; }
}
@media (max-width: 640px) {
  .topbar { padding: 12px 16px; flex-wrap: wrap; }
  .topbar .updated { order: 3; width: 100%; margin-left: 0; }
  main { padding: 14px 16px 40px; }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .kpi .k-value { font-size: 18px; }
  .chart-box { height: 240px; }
  .detail-tools { margin-left: 0; width: 100%; }
  .detail-tools input[type=search] { flex: 1; width: auto; }
}
