/* Layout: header + pulau tab bar, sticky filter sidebar on the left, dashboard column (KPI → map + province list → charts → table). */
:root {
  --bg: #f2f4f7;
  --surface: #ffffff;
  --surface-2: #f7f8fa;
  --line: #e2e5eb;
  --line-strong: #cfd4dc;
  --fg: #141821;
  --fg-2: #4a5161;
  --muted: #747b8b;
  --brand: #c8191f;          /* merah BNSP */
  --brand-2: #e8571e;        /* oranye tombol BNSP */
  --brand-soft: #fdecea;
  --p1: #2a78d6;  --p2: #eb6834;  --p3: #1baf7a;
  --ok: #0ca30c;  --ok-text: #006300;  --ok-soft: #e3f4e3;
  --warn: #fab219; --warn-text: #8a5a00; --warn-soft: #fff4d6;
  --crit: #d03b3b; --crit-text: #b12a2a; --crit-soft: #fbe6e6;
  --grid: #e8eaee;
  --shadow: 0 1px 2px rgba(20, 24, 33, .05), 0 4px 16px rgba(20, 24, 33, .05);
  --radius: 12px;
  --font: "Plus Jakarta Sans", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --gutter: max(16px, env(safe-area-inset-left, 0px));
  --gutter-r: max(16px, env(safe-area-inset-right, 0px));
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1116; --surface: #181b22; --surface-2: #1f232b; --line: #2b303a; --line-strong: #3a404c;
    --fg: #eef0f4; --fg-2: #bac0cc; --muted: #8a91a0;
    --brand: #ef4b43; --brand-2: #f06a33; --brand-soft: #3a1c1c;
    --p1: #3987e5; --p2: #d95926; --p3: #199e70;
    --ok: #0ca30c; --ok-text: #4cc44c; --ok-soft: #15301a;
    --warn: #fab219; --warn-text: #fab219; --warn-soft: #3a2e10;
    --crit: #e66767; --crit-text: #f08a8a; --crit-soft: #3a1c1c;
    --grid: #262a33; --shadow: 0 1px 2px rgba(0,0,0,.3);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f1116; --surface: #181b22; --surface-2: #1f232b; --line: #2b303a; --line-strong: #3a404c;
  --fg: #eef0f4; --fg-2: #bac0cc; --muted: #8a91a0;
  --brand: #ef4b43; --brand-2: #f06a33; --brand-soft: #3a1c1c;
  --p1: #3987e5; --p2: #d95926; --p3: #199e70;
  --ok: #0ca30c; --ok-text: #4cc44c; --ok-soft: #15301a;
  --warn: #fab219; --warn-text: #fab219; --warn-soft: #3a2e10;
  --crit: #e66767; --crit-text: #f08a8a; --crit-soft: #3a1c1c;
  --grid: #262a33; --shadow: 0 1px 2px rgba(0,0,0,.3);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--fg); font: 14px/1.5 var(--font); -webkit-font-smoothing: antialiased; }
[hidden] { display: none !important; }
h1, h2, h3 { margin: 0; text-wrap: balance; }
button, input, select { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--brand-2); outline-offset: 2px; }
.only-mobile { display: none !important; }

/* ---------- header ---------- */
body::before { content: ""; position: fixed; inset: 0 0 auto; height: env(safe-area-inset-top, 0px); z-index: 1001; background: var(--surface); }
.topbar { position: sticky; top: env(safe-area-inset-top, 0px); z-index: 1000; background: var(--surface); border-bottom: 1px solid var(--line); }
.topbar-in { display: flex; align-items: center; gap: 16px; padding: 12px var(--gutter-r) 12px var(--gutter); max-width: 1600px; margin: 0 auto; }
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.brand-mark { flex: none; display: grid; }
.brand h1 { font-size: 18px; font-weight: 800; letter-spacing: -.01em; line-height: 1.2; }
.brand .sub { margin: 0; color: var(--muted); font-size: 12.5px; }
.demo-badge { font-size: 11px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--warn-text); background: var(--warn-soft); border-radius: 999px; padding: 3px 10px; white-space: nowrap; }
.actions { margin-left: auto; display: flex; gap: 8px; }
.btn { display: inline-flex; align-items: center; gap: 8px; border-radius: 10px; padding: 9px 14px; font-weight: 600; font-size: 13.5px; cursor: pointer; border: 1px solid transparent; transition: transform .08s, background .15s, border-color .15s; }
.btn:active { transform: translateY(1px); }
.btn-primary { background: linear-gradient(135deg, var(--brand), var(--brand-2)); color: #fff; }
.btn-primary:hover { filter: brightness(1.06); }
.btn-ghost { background: var(--surface); border-color: var(--line-strong); }
.btn-ghost:hover { border-color: var(--fg-2); }
.icon-btn { background: none; border: 1px solid var(--line); border-radius: 8px; width: 36px; height: 36px; display: grid; place-items: center; cursor: pointer; flex: none; }
.link-btn { background: none; border: 0; color: var(--brand); font-weight: 600; cursor: pointer; padding: 4px; font-size: 13px; }

/* ---------- pulau tabs ---------- */
.pulau-bar { background: var(--surface); border-bottom: 1px solid var(--line); }
.pulau-in { display: flex; gap: 6px; overflow-x: auto; padding: 10px var(--gutter-r) 10px var(--gutter); max-width: 1600px; margin: 0 auto; scrollbar-width: thin; }
.ptab { flex: none; display: inline-flex; align-items: center; gap: 8px; border: 1px solid var(--line); background: var(--surface-2); border-radius: 999px; padding: 6px 14px; cursor: pointer; font-weight: 600; font-size: 13px; color: var(--fg-2); }
.ptab .n { font-variant-numeric: tabular-nums; font-weight: 700; color: var(--muted); font-size: 12px; }
.ptab:hover { border-color: var(--line-strong); color: var(--fg); }
.ptab[aria-selected="true"] { background: var(--fg); border-color: var(--fg); color: var(--surface); }
.ptab[aria-selected="true"] .n { color: var(--surface); opacity: .75; }

/* ---------- layout ---------- */
.layout { display: grid; grid-template-columns: 290px minmax(0, 1fr); gap: 20px; max-width: 1600px; margin: 0 auto; padding: 20px var(--gutter-r) 32px var(--gutter); align-items: start; }
.sidebar { position: sticky; top: 132px; max-height: calc(100vh - 150px); overflow-y: auto; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; display: flex; flex-direction: column; gap: 18px; }
.sidebar-head { display: flex; align-items: center; gap: 8px; }
.sidebar-head h2 { font-size: 15px; font-weight: 800; margin-right: auto; }
.fgroup { display: flex; flex-direction: column; gap: 6px; }
.flabel { font-size: 11px; font-weight: 700; letter-spacing: .07em; text-transform: uppercase; color: var(--muted); }
.fsub { font-size: 12.5px; color: var(--fg-2); margin-top: 4px; }
.fsub.inline { margin: 0; }
select, input[type="date"], .search input { width: 100%; border: 1px solid var(--line-strong); background: var(--surface); border-radius: 8px; padding: 8px 10px; font-size: 13.5px; }
select:disabled { opacity: .55; }
.search { position: relative; }
.search svg { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); color: var(--muted); }
.search input { padding-left: 32px; }
.checks { display: flex; flex-direction: column; gap: 4px; }
.check { display: flex; align-items: center; gap: 10px; padding: 7px 10px; border: 1px solid var(--line); border-radius: 8px; cursor: pointer; user-select: none; }
.check:hover { border-color: var(--line-strong); }
.check input { accent-color: var(--brand); width: 16px; height: 16px; margin: 0; }
.check .sw { width: 10px; height: 10px; border-radius: 50%; flex: none; }
.check .lbl { flex: 1; font-weight: 600; font-size: 13px; }
.check .lbl small { display: block; font-weight: 500; color: var(--muted); font-size: 11.5px; }
.check .n { font-variant-numeric: tabular-nums; color: var(--muted); font-size: 12.5px; font-weight: 600; }
.check.off { opacity: .6; }
.hint { margin: 2px 0 0; font-size: 11.5px; color: var(--muted); line-height: 1.45; }
.presets { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 4px; }
.preset { border: 1px dashed var(--line-strong); background: none; border-radius: 999px; padding: 4px 10px; font-size: 12px; font-weight: 600; cursor: pointer; color: var(--fg-2); }
.preset[aria-pressed="true"] { border-style: solid; border-color: var(--brand); color: var(--brand); background: var(--brand-soft); }
.daterow { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 8px; }
.daterow > div { min-width: 0; }
.daterow input { padding: 7px 6px; font-size: 12.5px; }

/* ---------- content ---------- */
.content { display: flex; flex-direction: column; gap: 20px; min-width: 0; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; min-height: 0; }
.chips:empty { display: none; }
.chip { display: inline-flex; align-items: center; gap: 6px; background: var(--brand-soft); color: var(--brand); border-radius: 999px; padding: 4px 6px 4px 12px; font-size: 12.5px; font-weight: 600; }
.chip button { background: none; border: 0; color: inherit; cursor: pointer; width: 20px; height: 20px; border-radius: 50%; display: grid; place-items: center; font-size: 12px; }
.chip button:hover { background: rgba(200, 25, 31, .12); }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); min-width: 0; }
.card-head { display: flex; align-items: flex-start; gap: 12px; padding: 14px 16px 10px; flex-wrap: wrap; }
.card-head > div:first-child { margin-right: auto; }
.card h3 { font-size: 15px; font-weight: 700; }
.card-sub { margin: 2px 0 0; font-size: 12.5px; color: var(--muted); }

/* KPI */
.kpis { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 12px; }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; display: flex; flex-direction: column; gap: 2px; position: relative; overflow: hidden; }
.kpi.main { background: linear-gradient(135deg, var(--brand), var(--brand-2)); border-color: transparent; color: #fff; }
.kpi .k { font-size: 12px; font-weight: 600; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.kpi.main .k, .kpi.main .s { color: rgba(255,255,255,.85); }
.kpi .v { font-size: 28px; font-weight: 800; letter-spacing: -.02em; font-variant-numeric: tabular-nums; line-height: 1.15; }
.kpi .s { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.kpi .bar { height: 4px; border-radius: 4px; background: var(--grid); margin-top: 8px; overflow: hidden; }
.kpi .bar i { display: block; height: 100%; border-radius: 4px; }
.dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; flex: none; }

/* Map */
.maprow { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 20px; }
.mapcard { display: flex; flex-direction: column; overflow: hidden; }
#map { height: 520px; border-top: 1px solid var(--line); background: var(--surface-2); }
.legend { display: flex; gap: 12px; flex-wrap: wrap; font-size: 12.5px; font-weight: 600; color: var(--fg-2); align-items: center; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.provcard { display: flex; flex-direction: column; max-height: 598px; }
.provlist { list-style: none; margin: 0; padding: 0 12px 12px; overflow-y: auto; display: flex; flex-direction: column; gap: 8px; }
.prov { display: grid; grid-template-columns: 34px minmax(0, 1fr) auto; align-items: center; gap: 10px; border: 1px solid var(--line); border-radius: 10px; padding: 9px 12px; cursor: pointer; background: var(--surface); text-align: left; width: 100%; }
.prov:hover { border-color: var(--brand-2); }
.prov[aria-pressed="true"] { border-color: var(--brand); background: var(--brand-soft); }
.prov .pin { width: 34px; height: 34px; border-radius: 50%; background: linear-gradient(135deg, var(--brand), var(--brand-2)); display: grid; place-items: center; color: #fff; }
.prov .nm, .prov .pl { display: block; }
.prov .nm { font-weight: 700; font-size: 14px; line-height: 1.25; }
.prov .pl { font-size: 12px; color: var(--muted); }
.prov .mix { display: flex; height: 4px; border-radius: 4px; overflow: hidden; margin-top: 5px; gap: 2px; background: var(--surface); }
.prov .mix i { display: block; height: 100%; }
.prov .ct { text-align: right; font-variant-numeric: tabular-nums; }
.prov .ct b { display: block; font-size: 18px; font-weight: 800; line-height: 1.1; }
.prov .ct small { font-size: 11px; color: var(--muted); }
.empty { padding: 24px; text-align: center; color: var(--muted); }

/* Leaflet markers */
.lsp-pin { width: 22px; height: 22px; border-radius: 50%; border: 2px solid #fff; color: #fff; font: 700 10px/18px var(--font); text-align: center; box-shadow: 0 1px 4px rgba(0,0,0,.35); }
.lsp-cluster { border-radius: 50%; display: grid; place-items: center; font: 700 12.5px var(--font); color: #141821; font-variant-numeric: tabular-nums; }
.lsp-cluster > div { border-radius: 50%; display: grid; place-items: center; width: 100%; height: 100%; }
.lsp-cluster.c-s { background: rgba(12, 163, 12, .25); } .lsp-cluster.c-s > div { background: rgba(110, 200, 90, .9); transform: scale(.78); }
.lsp-cluster.c-m { background: rgba(250, 178, 25, .28); } .lsp-cluster.c-m > div { background: rgba(250, 200, 60, .95); transform: scale(.78); }
.lsp-cluster.c-l { background: rgba(235, 104, 52, .28); } .lsp-cluster.c-l > div { background: rgba(240, 130, 80, .95); transform: scale(.8); }
.leaflet-popup-content-wrapper { border-radius: 10px; background: var(--surface); color: var(--fg); }
.leaflet-popup-tip { background: var(--surface); }
.leaflet-popup-content { margin: 12px 14px; font: 13px/1.45 var(--font); min-width: 220px; }
.pop h4 { margin: 0 0 4px; font-size: 14px; line-height: 1.3; }
.pop .meta { color: var(--muted); font-size: 12px; margin-bottom: 8px; }
.pop .row { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; margin-bottom: 8px; }
.pop button { width: 100%; border: 0; border-radius: 8px; padding: 7px; background: var(--fg); color: var(--surface); font-weight: 600; cursor: pointer; }
.leaflet-container { font-family: var(--font); }
.leaflet-control-zoom a, .leaflet-bar a { background: var(--surface); color: var(--fg); border-color: var(--line); }

/* Badges */
.jbadge { display: inline-flex; align-items: center; justify-content: center; min-width: 30px; padding: 2px 8px; border-radius: 6px; color: #fff; font-weight: 700; font-size: 11.5px; letter-spacing: .02em; }
.jbadge.P1 { background: var(--p1); } .jbadge.P2 { background: var(--p2); } .jbadge.P3 { background: var(--p3); }
.status { display: inline-flex; align-items: center; gap: 5px; border-radius: 999px; padding: 2px 9px 2px 7px; font-weight: 600; font-size: 12px; white-space: nowrap; }
.status svg { flex: none; }
.status.aktif { background: var(--ok-soft); color: var(--ok-text); }
.status.segera { background: var(--warn-soft); color: var(--warn-text); }
.status.habis { background: var(--crit-soft); color: var(--crit-text); }

/* Charts */
.chartrow { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 20px; }
.chartbox { position: relative; height: 260px; padding: 0 12px 12px; }

/* Table */
.tabletools { display: flex; align-items: center; gap: 8px; }
.tabletools select { width: auto; padding: 5px 8px; }
.tablewrap { overflow-x: auto; border-top: 1px solid var(--line); }
.dtable { width: 100%; border-collapse: collapse; font-size: 13px; min-width: 980px; }
.dtable th { text-align: left; font-size: 11.5px; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; color: var(--muted); padding: 10px 12px; background: var(--surface-2); border-bottom: 1px solid var(--line); cursor: pointer; white-space: nowrap; user-select: none; }
.dtable th:hover { color: var(--fg); }
.dtable th[aria-sort="ascending"]::after { content: " ▲"; font-size: 9px; }
.dtable th[aria-sort="descending"]::after { content: " ▼"; font-size: 9px; }
.dtable td { padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.dtable tbody tr { cursor: pointer; }
.dtable tbody tr:hover { background: var(--surface-2); }
.dtable .mono { font-variant-numeric: tabular-nums; color: var(--fg-2); white-space: nowrap; font-size: 12.5px; }
.dtable .nm { font-weight: 600; }
.dtable .loc small { display: block; color: var(--muted); font-size: 11.5px; }
.pager { display: flex; align-items: center; gap: 6px; padding: 12px 16px; flex-wrap: wrap; font-size: 13px; color: var(--fg-2); }
.pager .info { margin-right: auto; font-variant-numeric: tabular-nums; }
.pager button { min-width: 34px; height: 32px; border: 1px solid var(--line); background: var(--surface); border-radius: 8px; cursor: pointer; font-weight: 600; font-variant-numeric: tabular-nums; }
.pager button[aria-current="page"] { background: var(--fg); color: var(--surface); border-color: var(--fg); }
.pager button:disabled { opacity: .4; cursor: default; }

.foot { color: var(--muted); font-size: 12px; text-align: center; padding: 8px 0 0; }

/* Drawer */
.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(420px, 100vw); background: var(--surface); border-left: 1px solid var(--line); box-shadow: -8px 0 32px rgba(0,0,0,.15); z-index: 1200; transform: translateX(105%); transition: transform .22s ease; display: flex; flex-direction: column; padding-top: env(safe-area-inset-top, 0px); padding-bottom: env(safe-area-inset-bottom, 0px); padding-right: env(safe-area-inset-right, 0px); }
.drawer.open { transform: none; }
.drawer-head { display: flex; justify-content: space-between; align-items: center; padding: 16px 20px 0; }
.drawer-body { padding: 12px 20px 24px; overflow-y: auto; display: flex; flex-direction: column; gap: 16px; }
.drawer h2 { font-size: 20px; font-weight: 800; line-height: 1.25; }
.drawer .lic { color: var(--muted); font-variant-numeric: tabular-nums; font-size: 13px; margin-top: 4px; }
.validity { border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; display: flex; flex-direction: column; gap: 8px; }
.validity .track { height: 8px; border-radius: 8px; background: var(--grid); overflow: hidden; }
.validity .track i { display: block; height: 100%; border-radius: 8px; }
.validity .dates { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.dl { display: grid; grid-template-columns: 120px minmax(0, 1fr); gap: 8px 12px; margin: 0; font-size: 13.5px; }
.dl dt { color: var(--muted); }
.dl dd { margin: 0; font-weight: 500; overflow-wrap: anywhere; }
.stats3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.stats3 div { background: var(--surface-2); border-radius: 10px; padding: 10px; text-align: center; }
.stats3 b { display: block; font-size: 20px; font-variant-numeric: tabular-nums; }
.stats3 span { font-size: 11.5px; color: var(--muted); }

.toast { position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom, 0px)); transform: translateX(-50%); background: var(--fg); color: var(--surface); padding: 10px 16px; border-radius: 10px; font-weight: 600; font-size: 13px; z-index: 1300; box-shadow: var(--shadow); }

/* ---------- responsive ---------- */
@media (max-width: 1280px) {
  .kpis { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .chartrow { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .chartrow .card:last-child { grid-column: 1 / -1; }
}
@media (max-width: 1100px) {
  .maprow { grid-template-columns: minmax(0, 1fr); }
  .provcard { max-height: 360px; }
}
@media (max-width: 900px) {
  .only-mobile { display: grid !important; }
  .layout { grid-template-columns: minmax(0, 1fr); }
  .sidebar { position: fixed; top: 0; left: 0; bottom: 0; width: min(320px, 88vw); max-height: none; border-radius: 0; z-index: 1150; transform: translateX(-105%); transition: transform .22s ease; padding-top: calc(16px + env(safe-area-inset-top, 0px)); padding-left: max(16px, env(safe-area-inset-left, 0px)); }
  .sidebar.open { transform: none; }
  .scrim { position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 1100; }
  .scrim[hidden] { display: none !important; }
  .demo-badge { display: none; }
  .actions .btn span { display: none; }
  .actions .btn { padding: 9px 10px; }
  .chartrow { grid-template-columns: minmax(0, 1fr); }
  #map { height: 420px; }
}
@media (max-width: 560px) {
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .brand .sub { display: none; }
  .brand h1 { font-size: 15px; }
  .kpi .v { font-size: 24px; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
