:root {
  color-scheme: light;
  --ground: #EDF0F3;
  --surface: #FFFFFF;
  --surface-2: #F5F7F9;
  --line: #DCE2E8;
  --ink: #17202B;
  --muted: #5B6877;
  --faint: #8794A3;
  --accent: #E8730F;
  --accent-ink: #FFFFFF;
  --bar: #3A4756;
  --block: #D6453D;
  --managed: #7C5CE0;
  --challenge: #E39A2D;
  --js: #CDAA3E;
  --close: #6B7886;
  --other: #A3AEBA;
  --req: #3D6FD8;
  --cache: #1F9A87;
  --danger-soft: #FBE9E7;
  --ok-soft: #E3F4F0;
  --display: "Barlow Condensed", "Arial Narrow", "Roboto Condensed", sans-serif;
  --text: "Barlow", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  box-sizing: border-box;
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --ground: #10161E;
    --surface: #18202A;
    --surface-2: #1E2833;
    --line: #2A3542;
    --ink: #E7ECF1;
    --muted: #9AA7B5;
    --faint: #6E7C8B;
    --accent: #F6913A;
    --accent-ink: #1A1006;
    --bar: #C3CDD8;
    --block: #F0675E;
    --managed: #9D85F5;
    --challenge: #F0AE47;
    --js: #E2C566;
    --close: #8D9AA8;
    --other: #5E6B79;
    --req: #6E98F0;
    --cache: #3CC2AC;
    --danger-soft: #3A1E1E;
    --ok-soft: #173330;
  }
}
*, *::before, *::after { box-sizing: inherit; }
html, body { margin: 0; }
body {
  background: var(--ground);
  color: var(--ink);
  font: 400 16px/1.5 var(--text);
  font-variant-numeric: tabular-nums;
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
[hidden] { display: none !important; }

/* ---------- Login ---------- */
.login {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}
.login form {
  width: min(380px, 100%);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 32px 28px 28px;
}
.login h1 {
  font: 600 2rem/1.1 var(--display);
  margin: 0 0 6px;
}
.login p { margin: 0 0 22px; color: var(--muted); }
.login label { display: block; font-weight: 500; margin-bottom: 6px; }
.login input {
  width: 100%;
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
}
.login button { width: 100%; margin-top: 16px; }
.form-error { color: var(--block); margin: 12px 0 0 !important; font-weight: 500; }

/* ---------- Tombol ---------- */
.btn {
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 8px;
  padding: 8px 14px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
  font-weight: 600;
}
.btn-primary:hover { background: var(--accent); filter: brightness(1.06); }
.btn-danger { background: var(--block); border-color: var(--block); color: #fff; font-weight: 600; }
.btn-danger:hover { background: var(--block); filter: brightness(1.06); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn-ghost:hover { background: var(--surface-2); color: var(--ink); }

/* ---------- Bilah atas ---------- */
.topbar {
  position: sticky;
  top: env(safe-area-inset-top, 0px);
  z-index: 20;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
body::before {
  content: "";
  position: fixed;
  inset: 0 0 auto;
  height: env(safe-area-inset-top, 0px);
  z-index: 10;
  background: var(--surface);
}
@media (max-width: 700px) {
  .topbar { position: static; }
}
.topbar-inner {
  max-width: 1320px;
  margin: 0 auto;
  padding: 10px 20px;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}
.brand {
  font: 700 1.35rem/1 var(--display);
  display: flex;
  align-items: center;
  gap: 8px;
  margin-right: auto;
}
.brand-mark {
  width: 22px; height: 22px;
  border-radius: 6px;
  background: var(--accent);
  display: grid; place-items: center;
}
.brand-mark svg { width: 14px; height: 14px; }
.zone-select {
  padding: 8px 32px 8px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
  font-weight: 600;
  max-width: 240px;
}
.segmented {
  display: inline-flex;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 2px;
  background: var(--surface-2);
}
.segmented button {
  border: 0;
  background: transparent;
  padding: 6px 12px;
  border-radius: 6px;
  cursor: pointer;
  color: var(--muted);
  font-weight: 500;
}
.segmented button[aria-pressed="true"] { background: var(--surface); color: var(--ink); box-shadow: 0 0 0 1px var(--line); }

/* ---------- Tata letak ---------- */
main {
  max-width: 1320px;
  margin: 0 auto;
  padding: 24px 20px 64px;
  transition: opacity .2s;
}
main.loading { opacity: .55; pointer-events: none; }

.hero {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 26px 26px 18px;
}
.hero-headline {
  font: 600 clamp(1.6rem, 3.6vw, 2.6rem)/1.08 var(--display);
  margin: 0;
  max-width: 30ch;
  letter-spacing: -.005em;
}
.hero-headline .num { font-weight: 700; }
.hero-sub { color: var(--muted); margin: 8px 0 0; }
.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 18px;
  margin: 18px 0 8px;
  padding: 0;
  list-style: none;
  font-size: .9rem;
  color: var(--muted);
}
.legend li { display: flex; align-items: center; gap: 7px; }
.legend i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.legend b { color: var(--ink); font-weight: 600; }
.chart-tall { position: relative; height: 300px; }

.grid {
  display: grid;
  gap: 16px;
  margin-top: 16px;
}
.grid-2 { grid-template-columns: 5fr 7fr; }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
@media (max-width: 1000px) {
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
}

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 18px 20px 20px;
  min-width: 0;
}
.panel h2 {
  font: 600 1.25rem/1.2 var(--display);
  margin: 0 0 14px;
}
.panel .hint { color: var(--muted); font-size: .9rem; margin: -10px 0 14px; }

.donut-wrap { display: grid; grid-template-columns: 180px 1fr; gap: 20px; align-items: center; }
@media (max-width: 480px) { .donut-wrap { grid-template-columns: 1fr; justify-items: center; } }
.donut { position: relative; width: 180px; height: 180px; }
.donut-center {
  position: absolute; inset: 0;
  display: grid; place-content: center; text-align: center;
  pointer-events: none;
}
.donut-center strong { font: 700 1.9rem/1 var(--display); }
.donut-center span { color: var(--muted); font-size: .8rem; }
.action-list { list-style: none; margin: 0; padding: 0; width: 100%; }
.action-list li {
  display: grid;
  grid-template-columns: 12px 1fr auto auto;
  gap: 10px;
  align-items: center;
  padding: 7px 0;
  border-bottom: 1px solid var(--line);
}
.action-list li:last-child { border-bottom: 0; }
.action-list i { width: 12px; height: 12px; border-radius: 3px; }
.action-list .pct { color: var(--muted); font-size: .85rem; min-width: 3.5em; text-align: right; }
.action-list .cnt { font-weight: 600; min-width: 4.5em; text-align: right; }

.chart-mid { position: relative; height: 240px; }

.rank-list { list-style: none; margin: 0; padding: 0; }
.rank-list li { padding: 7px 0; }
.rank-row { display: flex; justify-content: space-between; gap: 10px; font-size: .95rem; }
.rank-row .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rank-row .cnt { font-weight: 600; }
.rank-bar { height: 5px; border-radius: 3px; background: var(--surface-2); margin-top: 5px; overflow: hidden; }
.rank-bar span { display: block; height: 100%; background: var(--block); border-radius: 3px; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .92rem; }
th, td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-weight: 500; font-size: .85rem; }
td.num, th.num { text-align: right; font-weight: 600; white-space: nowrap; }
td .sub { display: block; color: var(--muted); font-size: .8rem; max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
td.path { word-break: break-all; }
tr:last-child td { border-bottom: 0; }

.traffic-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0;
  margin: 4px 0 16px;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}
.stats div { padding: 12px 14px; border-left: 1px solid var(--line); }
.stats div:first-child { border-left: 0; padding-left: 0; }
.stats dt { color: var(--muted); font-size: .85rem; }
.stats dd { margin: 2px 0 0; font: 600 1.6rem/1.1 var(--display); }
@media (max-width: 700px) {
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .stats div:nth-child(3) { border-left: 0; padding-left: 0; }
  .stats div:nth-child(n+3) { border-top: 1px solid var(--line); }
}

.empty, .section-error {
  padding: 18px;
  border-radius: 10px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: .95rem;
}
.section-error { background: var(--danger-soft); color: var(--ink); }
.section-error b { display: block; margin-bottom: 2px; }

.updated { color: var(--faint); font-size: .85rem; margin-top: 18px; }
.demo-note {
  max-width: 1320px; margin: 16px auto 0; padding: 0 20px;
}
.demo-note p { margin: 0; padding: 10px 14px; border-radius: 10px; background: var(--ok-soft); font-size: .92rem; }

/* ---------- Dialog purge ---------- */
dialog {
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 0;
  width: min(560px, calc(100% - 32px));
  background: var(--surface);
  color: var(--ink);
}
dialog::backdrop { background: rgba(10, 14, 20, .55); }
.dlg-head { display: flex; justify-content: space-between; align-items: center; padding: 18px 22px 0; }
.dlg-head h2 { font: 600 1.5rem/1.15 var(--display); margin: 0; }
.dlg-body { padding: 8px 22px 22px; }
.dlg-section { padding: 16px 0; border-bottom: 1px solid var(--line); }
.dlg-section:last-of-type { border-bottom: 0; }
.dlg-section h3 { font: 600 1.1rem/1.2 var(--display); margin: 0 0 4px; }
.dlg-section p { margin: 0 0 10px; color: var(--muted); font-size: .92rem; }
.dlg-section textarea, .dlg-section input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
  padding: 10px 12px;
}
.dlg-section textarea { min-height: 110px; resize: vertical; font-size: .92rem; }
.dlg-actions { display: flex; justify-content: flex-end; margin-top: 10px; }
.danger-zone { background: var(--danger-soft); border-radius: 12px; padding: 16px; border-bottom: 0 !important; margin-top: 12px; }
.danger-zone p { color: var(--ink); opacity: .85; }
.status { margin-top: 10px; font-size: .92rem; font-weight: 500; }
.status.ok { color: var(--cache); }
.status.err { color: var(--block); }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(20px + env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%);
  background: var(--ink);
  color: var(--surface);
  padding: 10px 16px;
  border-radius: 10px;
  font-weight: 500;
  z-index: 50;
  max-width: calc(100% - 32px);
}
@media (prefers-reduced-motion: no-preference) {
  .toast { animation: rise .25s ease-out; }
  @keyframes rise { from { transform: translate(-50%, 8px); opacity: 0; } }
}

.nav-link { color: var(--muted); text-decoration: none; font-weight: 500; padding: 8px 10px; border-radius: 8px; white-space: nowrap; }
.nav-link:hover { background: var(--surface-2); color: var(--ink); }
