:root {
  --bg: #f4f6f3;
  --surface: #ffffff;
  --surface-2: #f8faf7;
  --border: #dfe5dc;
  --text: #1b261e;
  --muted: #5d6b60;
  --accent: #2f7d4f;
  --accent-hover: #276a42;
  --accent-soft: #e3f1e7;
  --on-accent: #ffffff;
  --warn: #a86a00;
  --warn-soft: #fbf0d9;
  --bad: #b3261e;
  --bad-soft: #fbe4e2;
  --info: #2d6fd0;
  --info-soft: #e3edfb;
  --neutral-soft: #eceeea;
  --shadow: 0 1px 2px rgb(0 0 0 / .04), 0 4px 16px rgb(0 0 0 / .06);
  --radius: 12px;
  --sidebar: 232px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1411;
    --surface: #181f1a;
    --surface-2: #1d251f;
    --border: #2b352e;
    --text: #e4ebe5;
    --muted: #97a59a;
    --accent: #6fcf95;
    --accent-hover: #86dba7;
    --accent-soft: #1f3526;
    --on-accent: #0b1a10;
    --warn: #f0b64a;
    --warn-soft: #3a2f16;
    --bad: #f2877e;
    --bad-soft: #3d1f1c;
    --info: #82b1ff;
    --info-soft: #1c2940;
    --neutral-soft: #252d27;
    --shadow: 0 1px 2px rgb(0 0 0 / .3), 0 6px 20px rgb(0 0 0 / .35);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14.5px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); }
h1, h2, h3 { line-height: 1.25; margin: 0; }
h1 { font-size: 22px; letter-spacing: -0.01em; }
h2 { font-size: 16px; }
h3 { font-size: 14.5px; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.nowrap { white-space: nowrap; }
.num { font-variant-numeric: tabular-nums; }
[hidden] { display: none !important; }

/* ---------- Tombol & form ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 36px; padding: 0 14px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  font: inherit; font-weight: 600; cursor: pointer; text-decoration: none; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: .55; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn.primary:hover { background: var(--accent-hover); }
.btn.danger { color: var(--bad); }
.btn.danger.solid { background: var(--bad); border-color: var(--bad); color: #fff; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--neutral-soft); }
.btn.icon { padding: 0; width: 34px; min-height: 34px; }
.btn svg { width: 18px; height: 18px; flex: none; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

label.field { display: block; margin-bottom: 14px; }
label.field > span { display: block; font-size: 13px; font-weight: 600; margin-bottom: 5px; }
input, select, textarea {
  width: 100%; font: inherit; color: var(--text);
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
  padding: 8px 10px; min-height: 38px;
}
textarea { resize: vertical; min-height: 70px; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 520px) { .row2 { grid-template-columns: 1fr; } }
.hint { font-size: 12.5px; color: var(--muted); margin-top: 4px; }
.form-error { background: var(--bad-soft); color: var(--bad); border-radius: 8px; padding: 9px 12px; font-size: 13.5px; margin-bottom: 14px; }

/* ---------- Login ---------- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.login-card { width: 100%; max-width: 380px; background: var(--surface); border: 1px solid var(--border); border-radius: 16px; padding: 28px; box-shadow: var(--shadow); }
.login-card .brand { margin-bottom: 22px; }
.login-card .btn.primary { width: 100%; min-height: 42px; margin-top: 4px; }
.login-foot { margin-top: 18px; font-size: 12.5px; color: var(--muted); text-align: center; }

/* ---------- Shell ---------- */
.brand { display: flex; align-items: center; gap: 10px; }
.brand .logo { width: 34px; height: 34px; flex: none; }
.brand b { display: block; font-size: 16px; }
.brand small { display: block; color: var(--muted); font-size: 12px; }

.shell { display: grid; grid-template-columns: var(--sidebar) 1fr; min-height: 100vh; }
.sidebar {
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
  background: var(--surface); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; padding: 18px 12px;
}
.sidebar .brand { padding: 0 8px 18px; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a {
  display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 8px;
  color: var(--text); text-decoration: none; font-weight: 500;
}
.nav a svg { width: 19px; height: 19px; color: var(--muted); flex: none; }
.nav a:hover { background: var(--neutral-soft); }
.nav a.active { background: var(--accent-soft); color: var(--accent); font-weight: 650; }
.nav a.active svg { color: var(--accent); }
.nav .badge { margin-left: auto; }
.sidebar .me { margin-top: auto; border-top: 1px solid var(--border); padding: 14px 8px 0; }
.me .who b { display: block; font-size: 13.5px; }
.me .who span { font-size: 12px; color: var(--muted); }
.me .btn { width: 100%; margin-top: 10px; }

.topbar { display: none; }
.main { min-width: 0; padding: 26px 28px 60px; }
.page-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 20px; }
.page-head p { margin: 3px 0 0; color: var(--muted); font-size: 13.5px; }
.page-head .actions { display: flex; flex-wrap: wrap; gap: 8px; }

@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; z-index: 1200; left: 0; top: 0; width: 264px;
    transform: translateX(-100%); transition: transform .2s ease; box-shadow: var(--shadow);
  }
  .shell.nav-open .sidebar { transform: none; }
  .scrim { position: fixed; inset: 0; background: rgb(0 0 0 / .35); z-index: 1100; }
  .topbar {
    display: flex; align-items: center; gap: 10px; position: sticky; top: 0; z-index: 1000;
    background: var(--surface); border-bottom: 1px solid var(--border); padding: 8px 12px;
  }
  .topbar .brand b { font-size: 15px; }
  .main { padding: 18px 16px 48px; }
}
@media (prefers-reduced-motion: reduce) { .sidebar { transition: none; } }

/* ---------- Kartu, statistik ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.card.pad { padding: 18px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 14px 18px; border-bottom: 1px solid var(--border); }
.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(180px, 100%), 1fr)); gap: 12px; margin-bottom: 20px; }
.stat { padding: 16px 18px; }
.stat .label { color: var(--muted); font-size: 13px; }
.stat .value { font-size: 28px; font-weight: 700; font-variant-numeric: tabular-nums; margin-top: 2px; }
.stat .detail { color: var(--muted); font-size: 12.5px; }
.stat.link { cursor: pointer; text-decoration: none; color: inherit; display: block; }
.stat.link:hover { border-color: var(--accent); }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 1000px) { .grid-2 { grid-template-columns: 1fr; } }

/* ---------- Badge ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 5px; white-space: nowrap;
  font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 999px;
  background: var(--neutral-soft); color: var(--muted);
}
.badge.ok { background: var(--accent-soft); color: var(--accent); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.bad { background: var(--bad-soft); color: var(--bad); }
.badge.info { background: var(--info-soft); color: var(--info); }
.badge.count { background: var(--bad); color: #fff; min-width: 20px; justify-content: center; padding: 1px 6px; }

/* ---------- Toolbar & tabel ---------- */
.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding: 12px 14px; border-bottom: 1px solid var(--border); }
.toolbar input[type=search] { max-width: 260px; }
.toolbar select, .toolbar input[type=date] { width: auto; }
.toolbar .spacer { flex: 1; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  border-radius: 999px; padding: 5px 12px; font: inherit; font-size: 13px; cursor: pointer;
  display: inline-flex; align-items: center; gap: 6px;
}
.chip b { font-variant-numeric: tabular-nums; }
.chip.active { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); font-weight: 600; }

.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; }
table.data th {
  text-align: left; font-size: 12px; font-weight: 650; color: var(--muted); text-transform: uppercase; letter-spacing: .03em;
  padding: 10px 14px; border-bottom: 1px solid var(--border); background: var(--surface-2); white-space: nowrap;
}
table.data td { padding: 11px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
table.data tr:last-child td { border-bottom: 0; }
table.data tbody tr.click { cursor: pointer; }
table.data tbody tr.click:hover { background: var(--surface-2); }
table.data td.actions { text-align: right; white-space: nowrap; width: 1%; }
.cell-main { font-weight: 600; }
.cell-sub { font-size: 12.5px; color: var(--muted); }
.empty { padding: 40px 16px; text-align: center; color: var(--muted); }
.loading { padding: 40px 16px; text-align: center; color: var(--muted); }
.table-foot { padding: 10px 14px; font-size: 12.5px; color: var(--muted); border-top: 1px solid var(--border); }

@media (max-width: 700px) {
  table.data.stack thead { display: none; }
  table.data.stack tr { display: block; padding: 10px 14px; border-bottom: 1px solid var(--border); }
  table.data.stack tr:last-child { border-bottom: 0; }
  table.data.stack td { display: block; padding: 2px 0; border: 0; }
  table.data.stack td[data-label]::before { content: attr(data-label) ": "; color: var(--muted); font-size: 12.5px; }
  table.data.stack td.actions { text-align: left; width: auto; padding-top: 6px; }
}

/* ---------- Modal ---------- */
.modal-back {
  position: fixed; inset: 0; z-index: 2000; background: rgb(10 20 14 / .45);
  display: flex; align-items: flex-start; justify-content: center; padding: 5vh 16px; overflow-y: auto;
}
.modal { width: 100%; max-width: 560px; background: var(--surface); border-radius: 14px; box-shadow: var(--shadow); border: 1px solid var(--border); }
.modal.wide { max-width: 860px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.modal-body { padding: 18px 20px; }
.modal-foot { display: flex; justify-content: flex-end; flex-wrap: wrap; gap: 8px; padding: 14px 20px; border-top: 1px solid var(--border); }

/* ---------- Detail ---------- */
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; margin: 0; font-size: 14px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
.section-title { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 18px 0 8px; }
.photo { display: block; width: 100%; max-height: 300px; object-fit: contain; background: var(--neutral-soft); border-radius: 10px; }
.photo-missing { display: grid; place-items: center; height: 120px; background: var(--neutral-soft); border-radius: 10px; color: var(--muted); font-size: 13px; }
.map { height: 260px; border-radius: 10px; border: 1px solid var(--border); z-index: 0; }
.map.tall { height: 340px; }
.meter { height: 6px; background: var(--neutral-soft); border-radius: 3px; overflow: hidden; margin-top: 4px; }
.meter > i { display: block; height: 100%; background: var(--accent); }
.meter.bad > i { background: var(--bad); }

.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 11px 18px; border-bottom: 1px solid var(--border); }
.list li:last-child { border-bottom: 0; }
.list li.click { cursor: pointer; }
.list li.click:hover { background: var(--surface-2); }

.split { display: grid; grid-template-columns: minmax(280px, 380px) 1fr; gap: 16px; align-items: start; }
@media (max-width: 1000px) { .split { grid-template-columns: 1fr; } }
.approval-detail { position: sticky; top: 16px; }

/* ---------- Toast ---------- */
#toasts { position: fixed; z-index: 3000; bottom: 16px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; width: min(420px, calc(100vw - 32px)); }
.toast { background: var(--text); color: var(--bg); padding: 11px 16px; border-radius: 10px; box-shadow: var(--shadow); font-size: 14px; }
.toast.bad { background: var(--bad); color: #fff; }

/* Leaflet menyesuaikan tema gelap */
@media (prefers-color-scheme: dark) {
  .leaflet-container { background: #1d251f; }
  .leaflet-tile-pane { filter: brightness(.75) contrast(1.1) saturate(.8); }
}
