:root {
  color-scheme: light;
  --brand: #581825;
  --brand-ink: #ffffff;
  --bg: #f6f3f2;
  --surface: #fcfcfb;
  --surface-2: #f1ecea;
  --border: #e6dfdc;
  --grid: #ebe6e3;
  --text: #1d1416;
  --text-2: #5a4f51;
  --muted: #8a7f81;
  --series: #9b2c46;        /* validated: light surface, >=3:1 */
  --series-muted: #e3c4cc;  /* periode non-terpilih (emphasis) */
  --good: #12804a;
  --bad: #c0392b;
  --shadow: 0 1px 2px rgba(40, 10, 18, .06), 0 2px 8px rgba(40, 10, 18, .05);
  --radius: 14px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #121011;
    --surface: #1a1a19;
    --surface-2: #242022;
    --border: #2f2a2c;
    --grid: #2a2627;
    --text: #f0efec;
    --text-2: #c3c2b7;
    --muted: #8f8a86;
    --series: #d9657f;      /* validated: dark surface, >=3:1 */
    --series-muted: #4a2a32;
    --good: #4cc38a;
    --bad: #ef6f62;
    --shadow: none;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #121011;
  --surface: #1a1a19;
  --surface-2: #242022;
  --border: #2f2a2c;
  --grid: #2a2627;
  --text: #f0efec;
  --text-2: #c3c2b7;
  --muted: #8f8a86;
  --series: #d9657f;
  --series-muted: #4a2a32;
  --good: #4cc38a;
  --bad: #ef6f62;
  --shadow: none;
}

* { 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, "Helvetica Neue", Arial, sans-serif;
  font-variant-numeric: tabular-nums;
}
[hidden] { display: none !important; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.muted { color: var(--muted); }
.small { font-size: 12px; }
h1, h2, h3 { margin: 0; }

/* Buttons */
.btn {
  border: 1px solid transparent; border-radius: 10px; padding: 10px 14px; font: inherit; font-weight: 600;
  cursor: pointer; background: var(--surface-2); color: var(--text);
}
.btn-primary { background: var(--brand); color: var(--brand-ink); }
.btn-primary:disabled { opacity: .6; }
.btn-ghost { background: transparent; border-color: var(--border); padding: 6px 10px; font-size: 13px; }
.icon-btn {
  width: 36px; height: 36px; border-radius: 10px; border: 1px solid var(--border); background: var(--surface);
  color: var(--text); font-size: 18px; line-height: 1; cursor: pointer; flex: none;
}
.icon-btn:disabled { opacity: .4; cursor: default; }
.icon-btn svg { width: 18px; height: 18px; display: block; margin: auto; }

/* Login */
.login { min-height: 100vh; min-height: 100dvh; display: grid; place-items: center; padding: 16px; background: var(--brand); }
.login-card {
  width: 100%; max-width: 340px; background: var(--surface); border-radius: 18px; padding: 28px 22px;
  display: flex; flex-direction: column; gap: 12px; text-align: center; box-shadow: 0 10px 30px rgba(0,0,0,.25);
}
.login-logo { align-self: center; border-radius: 16px; }
.login-card h1 { font-size: 20px; }
.login-card .muted { margin: -8px 0 4px; }
.login-card .muted.small { margin: -4px 0 0; }
.login-card input {
  font: inherit; font-size: 16px; padding: 12px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text);
}
.login-error { min-height: 1.2em; margin: 0; color: var(--bad); font-size: 13px; }

/* Topbar */
.topbar {
  position: sticky; top: 0; z-index: 10; background: var(--brand); color: var(--brand-ink);
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
}
.topbar-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand img { border-radius: 8px; border: 1px solid rgba(255,255,255,.3); }
.brand-title { font-weight: 700; font-size: 15px; }
.brand-sub { font-size: 11px; opacity: .8; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-actions { display: flex; gap: 8px; }
.topbar .icon-btn { background: rgba(255,255,255,.1); border-color: rgba(255,255,255,.25); color: #fff; }
.filters { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; align-items: center; }
.segmented { display: inline-flex; background: rgba(255,255,255,.12); border-radius: 10px; padding: 3px; }
.segmented button {
  border: 0; background: transparent; color: #fff; font: inherit; font-size: 13px; font-weight: 600;
  padding: 6px 14px; border-radius: 8px; cursor: pointer; opacity: .8;
}
.segmented button.active { background: #fff; color: var(--brand); opacity: 1; }
.date-nav { display: flex; align-items: center; gap: 6px; flex: 1 1 280px; min-width: 0; }
.date-nav input {
  font: inherit; font-size: 14px; padding: 6px 8px; border-radius: 10px; border: 1px solid rgba(255,255,255,.25);
  background: rgba(255,255,255,.1); color: #fff; color-scheme: dark; min-width: 0; flex: 1; max-width: 200px;
}
.topbar .btn-ghost { color: #fff; border-color: rgba(255,255,255,.3); }

.banner { margin: 12px 16px 0; padding: 10px 12px; border-radius: 10px; font-size: 13px; background: #fff4d6; color: #6a4b00; }
.banner.error { background: #fde3df; color: #8a1f12; }

/* Content */
.content { max-width: 1200px; margin: 0 auto; padding: 16px 16px calc(32px + env(safe-area-inset-bottom)); display: grid; gap: 16px; }
.periode-title { font-size: 17px; }
.card, .tile { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card { padding: 14px; min-width: 0; }
.card-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; margin-bottom: 10px; flex-wrap: wrap; }
.card-head h3 { font-size: 15px; }

/* KPI */
.kpi-hero { display: grid; gap: 12px; }
.tile { padding: 12px 14px; min-width: 0; }
.tile-label { font-size: 12px; color: var(--text-2); font-weight: 600; }
.tile-value { font-size: 20px; font-weight: 700; margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tile-hero { background: var(--surface); border-left: 4px solid var(--series); }
.tile-hero .tile-value { font-size: 32px; letter-spacing: -.01em; }
.tile-note { font-size: 11px; color: var(--muted); margin-top: 4px; }
.tile-delta { font-size: 12px; margin-top: 2px; color: var(--text-2); min-height: 1.2em; }
.tile-delta .up { color: var(--good); font-weight: 700; }
.tile-delta .down { color: var(--bad); font-weight: 700; }
.kpi-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
@media (min-width: 640px) { .kpi-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (min-width: 1000px) {
  .kpi-hero { grid-template-columns: 1fr 2.4fr; align-items: start; }
  .kpi-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}

/* Charts */
.chart { position: relative; width: 100%; min-height: 200px; }
.chart svg { display: block; width: 100%; height: 220px; overflow: visible; }
.chart .grid line { stroke: var(--grid); stroke-width: 1; }
.chart .axis-label { fill: var(--muted); font-size: 11px; }
.chart .bar { fill: var(--series); }
.chart .bar.muted { fill: var(--series-muted); }
.chart .bar.hover { opacity: .8; }
.chart .hit { fill: transparent; cursor: pointer; }
.chart .value-label { fill: var(--text-2); font-size: 11px; font-weight: 600; }
.chart-empty { display: grid; place-items: center; height: 200px; color: var(--muted); font-size: 13px; }

/* Bar lists */
.barlist { display: grid; gap: 10px; }
.barlist-row { display: grid; gap: 4px; }
.barlist-top { display: flex; justify-content: space-between; gap: 10px; font-size: 13px; }
.barlist-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.barlist-val { font-weight: 600; white-space: nowrap; }
.barlist-track { height: 8px; border-radius: 4px; background: var(--surface-2); overflow: hidden; }
.barlist-fill { height: 100%; border-radius: 4px; background: var(--series); }
.barlist-sub { font-size: 11px; color: var(--muted); }

.two-col { display: grid; gap: 16px; }
@media (min-width: 860px) { .two-col { grid-template-columns: 1fr 1fr; } }

/* Tables */
.table-wrap { overflow-x: auto; margin: 0 -14px; padding: 0 14px; }
.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table th, .table td { padding: 8px 6px; border-bottom: 1px solid var(--border); text-align: left; white-space: nowrap; }
.table th { color: var(--text-2); font-size: 12px; font-weight: 600; }
.table td.wrap { white-space: normal; min-width: 140px; }
.table .num { text-align: right; }
.table tbody tr:last-child td { border-bottom: 0; }
.table .empty { text-align: center; color: var(--muted); padding: 20px; }
.footnote { margin: 0; }

/* Tooltip & loading */
.tooltip {
  position: fixed; z-index: 50; pointer-events: none; background: var(--text); color: var(--surface);
  padding: 8px 10px; border-radius: 8px; font-size: 12px; line-height: 1.4; box-shadow: 0 4px 14px rgba(0,0,0,.2);
  max-width: 240px;
}
.tooltip b { font-size: 13px; }
.loading { position: fixed; inset: 0; z-index: 40; display: grid; place-items: center; background: rgba(0,0,0,.08); }
.spinner {
  width: 36px; height: 36px; border-radius: 50%; border: 3px solid var(--series-muted); border-top-color: var(--series);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 2s; } }
