:root {
  color-scheme: light;
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #f7f8fa;
  --border: #e3e5e9;
  --text: #15171a;
  --text-2: #4f5560;
  --muted: #7a808b;
  --accent: #2a78d6;
  --accent-ink: #ffffff;
  --accent-soft: #e6f0fc;
  --good: #0ca30c;
  --good-ink: #006300;
  --warn: #fab219;
  --serious: #ec835a;
  --critical: #d03b3b;
  --critical-soft: #fdecec;
  --good-soft: #e7f6e7;
  --warn-soft: #fff5de;
  /* ordinal ramp: log masuk terakhir (gelap = lebih baharu) */
  --r7: #184f95;
  --r30: #2a78d6;
  --r90: #6da7ec;
  --rold: #b7d3f6;
  --rnever: #d6d4cf;
  --s1: #2a78d6;
  --s2: #eb6834;
  --s3: #1baf7a;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #121211;
    --surface: #1a1a19;
    --surface-2: #222220;
    --border: #2f2f2c;
    --text: #f0efec;
    --text-2: #c3c2b7;
    --muted: #8f8e86;
    --accent: #3987e5;
    --accent-soft: #1d2c40;
    --good-ink: #5fd35f;
    --critical-soft: #3a1f1f;
    --good-soft: #1b2f1b;
    --warn-soft: #3a3020;
    --r7: #9ec5f4;
    --r30: #5598e7;
    --r90: #256abf;
    --rold: #184f95;
    --rnever: #4a4a46;
    --s1: #3987e5;
    --s2: #d95926;
    --s3: #199e70;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #121211; --surface: #1a1a19; --surface-2: #222220; --border: #2f2f2c;
  --text: #f0efec; --text-2: #c3c2b7; --muted: #8f8e86; --accent: #3987e5; --accent-soft: #1d2c40;
  --good-ink: #5fd35f; --critical-soft: #3a1f1f; --good-soft: #1b2f1b; --warn-soft: #3a3020;
  --r7: #9ec5f4; --r30: #5598e7; --r90: #256abf; --rold: #184f95; --rnever: #4a4a46;
  --s1: #3987e5; --s2: #d95926; --s3: #199e70;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 14px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; margin: 0 0 4px; letter-spacing: -.01em; }
h2 { font-size: 16px; margin: 0 0 12px; }
h3 { font-size: 14px; margin: 0 0 8px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.num { font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
.wrap { max-width: 1280px; margin: 0 auto; padding: 0 16px; }
.main { padding-top: 20px; padding-bottom: 32px; }
.foot { padding: 16px; font-size: 12px; text-align: center; }

/* Top bar */
.topbar { background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 20; }
.topbar-in { display: flex; align-items: center; gap: 16px; min-height: 56px; }
.brand { display: flex; align-items: center; gap: 10px; color: var(--text); white-space: nowrap; }
.brand:hover { text-decoration: none; }
.logo { width: 30px; height: 30px; border-radius: 8px; background: var(--accent); color: #fff; display: grid; place-items: center; font-weight: 700; }
.nav { display: flex; align-items: center; gap: 4px; flex: 1; }
.nav > a { padding: 8px 12px; border-radius: 8px; color: var(--text-2); }
.nav > a:hover { background: var(--surface-2); text-decoration: none; }
.nav > a.on { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.who { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.who > a:first-child { color: var(--text); font-weight: 500; }
.navtoggle { display: none; margin-left: auto; background: none; border: 1px solid var(--border); color: var(--text); border-radius: 8px; padding: 6px 10px; font-size: 16px; }
@media (max-width: 860px) {
  .navtoggle { display: block; }
  .nav { display: none; position: absolute; top: 56px; left: 0; right: 0; background: var(--surface); border-bottom: 1px solid var(--border); flex-direction: column; align-items: stretch; padding: 8px 16px 12px; }
  .navopen .nav { display: flex; }
  .who { margin: 8px 0 0; flex-wrap: wrap; }
}

/* Cards & layout */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); min-width: 0; }
.grid { display: grid; gap: 16px; }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
@media (max-width: 960px) { .g3, .g4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 640px) { .g2, .g3, .g4 { grid-template-columns: 1fr; } }
.stack > * + * { margin-top: 16px; }
.pagehead { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
.cardhead { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 8px; margin-bottom: 12px; }
.cardhead h2 { margin: 0; }

/* KPI tiles */
.kpi .label { color: var(--text-2); font-weight: 600; display: flex; justify-content: space-between; gap: 8px; }
.kpi .hero { font-size: 34px; font-weight: 700; letter-spacing: -.02em; line-height: 1.1; margin: 8px 0 2px; font-variant-numeric: tabular-nums; }
.kpi .sub { color: var(--muted); font-size: 12px; }
.kpi .row { display: flex; justify-content: space-between; border-top: 1px solid var(--border); margin-top: 12px; padding-top: 10px; gap: 8px; }
.kpi .row div { font-size: 12px; color: var(--muted); }
.kpi .row b { display: block; font-size: 15px; color: var(--text); font-variant-numeric: tabular-nums; }
.delta { font-size: 12px; font-weight: 600; }
.delta.up { color: var(--good-ink); }
.delta.down { color: var(--critical); }

/* Recency bar (stacked, 100%) */
.rbar { display: flex; height: 14px; border-radius: 4px; overflow: hidden; gap: 2px; background: var(--surface); }
.rbar span { display: block; height: 100%; min-width: 0; }
.rbar span:first-child { border-radius: 4px 0 0 4px; }
.rbar span:last-child { border-radius: 0 4px 4px 0; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 12px; color: var(--text-2); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }
.rrow { display: grid; grid-template-columns: 120px 1fr 64px; gap: 12px; align-items: center; padding: 6px 0; }
.rrow .lbl { font-weight: 600; }
@media (max-width: 640px) { .rrow { grid-template-columns: 80px 1fr 52px; } }

/* Inline meter */
.meter { display: flex; align-items: center; gap: 8px; min-width: 120px; }
.meter .track { flex: 1; height: 8px; background: var(--surface-2); border-radius: 4px; overflow: hidden; border: 1px solid var(--border); }
.meter .fill { height: 100%; background: var(--accent); border-radius: 4px; }
.meter .v { width: 48px; text-align: right; font-variant-numeric: tabular-nums; font-size: 13px; }

/* Tables */
.tablewrap { overflow-x: auto; margin: 0 -16px; padding: 0 16px; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 8px 10px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: middle; }
th { font-size: 12px; color: var(--muted); font-weight: 600; white-space: nowrap; background: var(--surface); position: sticky; top: 0; }
th.sort { cursor: pointer; user-select: none; }
th.sort:hover { color: var(--text); }
th.sort[data-dir="asc"]::after { content: " ▲"; }
th.sort[data-dir="desc"]::after { content: " ▼"; }
tbody tr:hover td { background: var(--surface-2); }
td.name { min-width: 220px; }
tr.total td { font-weight: 700; background: var(--surface-2); }

/* Forms */
.form { display: grid; gap: 12px; }
label { display: grid; gap: 4px; font-weight: 500; color: var(--text-2); font-size: 13px; }
input, select, textarea {
  font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border);
  border-radius: 8px; padding: 8px 10px; min-height: 38px; width: 100%;
}
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
.filters { display: flex; flex-wrap: wrap; gap: 8px; align-items: flex-end; }
.filters label { min-width: 160px; }
.filters input[type=search] { min-width: 220px; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; font: inherit; font-weight: 600;
  padding: 8px 14px; min-height: 38px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface);
  color: var(--text); cursor: pointer; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.primary:hover { filter: brightness(1.06); }
.btn.danger { color: var(--critical); }
.btn.sm { padding: 4px 10px; min-height: 30px; font-size: 12px; }
.btn[disabled] { opacity: .6; cursor: progress; }

/* Badges & alerts */
.badge { display: inline-block; font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 999px; background: var(--surface-2); color: var(--text-2); border: 1px solid var(--border); white-space: nowrap; }
.st { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.st::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.st.good { color: var(--good-ink); }
.st.warn { color: #9a6a00; }
.st.serious { color: #b5532c; }
.st.critical { color: var(--critical); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .st.warn { color: var(--warn); } :root:not([data-theme="light"]) .st.serious { color: var(--serious); } }
.alert { padding: 10px 14px; border-radius: 8px; margin-bottom: 16px; border: 1px solid var(--border); background: var(--surface); }
.alert.ok { background: var(--good-soft); border-color: transparent; }
.alert.err { background: var(--critical-soft); border-color: transparent; }
.alert.warn { background: var(--warn-soft); border-color: transparent; }

/* Tabs */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 16px; overflow-x: auto; }
.tabs a { padding: 10px 14px; color: var(--text-2); border-bottom: 2px solid transparent; white-space: nowrap; }
.tabs a.on { color: var(--accent); border-color: var(--accent); font-weight: 600; }
.tabs a:hover { text-decoration: none; color: var(--text); }

/* Auth */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.auth-card { width: 100%; max-width: 400px; padding: 28px; }
.auth-card h1 { margin-bottom: 6px; }

/* Chart */
.chartbox { position: relative; height: 280px; }
.chartbox.tall { height: 340px; }
.empty { padding: 32px 16px; text-align: center; color: var(--muted); }
.pager { display: flex; gap: 6px; justify-content: flex-end; align-items: center; margin-top: 12px; flex-wrap: wrap; }
.codebox { font-family: ui-monospace, Consolas, monospace; font-size: 13px; background: var(--surface-2); padding: 2px 6px; border-radius: 4px; }
.hide { display: none !important; }
