:root {
  --bg: #f3efe2;
  --surface: #fffdf6;
  --line: #e4dcc4;
  --ink: #1b2a1c;
  --ink-soft: #57614f;
  --leaf: #1d3b1f;
  --leaf-soft: #e3ecd6;
  --c1: #2e7d4f;
  --c2: #c98a12;
  --c3: #3a67a8;
  --c4: #8e4a9e;
  --c5: #c0392b;
  --c6: #16899a;
  --c7: #7a8a1e;
  --c8: #d36a9b;
  --c9: #6b5b4a;
  --c10: #e0662b;
  --src-normal: #3a67a8;
  --src-panitia: #c98a12;
  --z-dalam: #2e7d4f;
  --z-luar: #c0562f;
  --z-unknown: #a59d86;
  --boundary: #1d3b1f;
  --radius: 14px;
  --ease-out: cubic-bezier(.16, 1, .3, 1);
  color-scheme: light;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font: 15px/1.5 "Plus Jakarta Sans", system-ui, sans-serif;
  color: var(--ink);
  background: var(--bg);
}
::selection { background: #c9e265; color: var(--leaf); }
a { color: var(--leaf); text-underline-offset: 3px; }
h1, h2 { font-family: "Bricolage Grotesque", sans-serif; letter-spacing: -.02em; margin: 0; }
h2 { font-size: 1.15rem; }
.muted { color: var(--ink-soft); }
.mono { font-variant-numeric: tabular-nums; font-size: .86rem; }
.nowrap, .cand { white-space: nowrap; }

.btn {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: 40px; padding: 0 14px;
  border: 1px solid var(--line); border-radius: 10px;
  background: var(--surface); color: var(--ink);
  font: 600 .88rem/1 inherit; font-family: inherit;
  text-decoration: none; cursor: pointer;
  transition: background-color .2s, border-color .2s, transform .15s var(--ease-out);
}
.btn:hover { border-color: #cbbf9c; background: #fbf6e8; }
.btn:active { transform: scale(.97); }
.btn:focus-visible, select:focus-visible, input:focus-visible { outline: 3px solid #9cc25a; outline-offset: 2px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--leaf); border-color: var(--leaf); color: #fbf8ee; }
.btn-primary:hover { background: #295329; border-color: #295329; }
.btn-ghost { background: transparent; }

/* ---------- Top bar ---------- */
.top { background: var(--leaf); color: #fbf8ee; }
.top-in {
  max-width: 1200px; margin: 0 auto; padding: 18px 16px;
  display: flex; flex-wrap: wrap; gap: 12px; align-items: center; justify-content: space-between;
}
.top h1 { font-size: 1.45rem; }
.top .muted { color: #c9d6b8; margin: 2px 0 0; font-size: .85rem; }
.top-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.top .btn { background: rgb(255 255 255 / .08); border-color: rgb(255 255 255 / .2); color: #fbf8ee; }
.top .btn:hover { background: rgb(255 255 255 / .16); }

/* ---------- Grid ---------- */
.dash {
  max-width: 1200px; margin: 0 auto; padding: 20px 16px 48px;
  display: grid; gap: 16px;
  grid-template-columns: repeat(12, minmax(0, 1fr));
}
.dash > * { grid-column: 1 / -1; }
@media (min-width: 960px) {
  .results { grid-column: span 7; }
  .zones { grid-column: span 5; }
  #tren, #jam { grid-column: span 6; }
}

.stats {
  display: grid; grid-template-columns: repeat(2, minmax(0, 1fr));
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
}
@media (min-width: 720px) { .stats { grid-template-columns: repeat(5, minmax(0, 1fr)); } }
.stat { padding: 14px 16px; display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.stat + .stat { border-left: 1px solid var(--line); }
@media (max-width: 719px) { .stat:nth-child(odd) { border-left: 0; } .stat:nth-child(n+3) { border-top: 1px solid var(--line); } .stat:last-child { grid-column: 1 / -1; border-left: 0; } }
.stat .k { font-size: .8rem; color: var(--ink-soft); font-weight: 600; }
.stat .v { font-family: "Bricolage Grotesque", sans-serif; font-weight: 800; font-size: 1.7rem; line-height: 1.1; font-variant-numeric: tabular-nums; }
.stat .v small { font-size: .9rem; font-weight: 700; color: var(--ink-soft); }
.stat .v-sm { font-size: 1.1rem; padding-top: 6px; overflow-wrap: anywhere; }

.panel {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 18px 16px; min-width: 0;
}
.panel > h2 { margin-bottom: 14px; }
.panel-head { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.note { font-size: .84rem; color: var(--ink-soft); margin: 12px 0 0; }
.empty { color: var(--ink-soft); margin: 4px 0; }
.warn { background: #fbf0d4; border: 1px solid #ecd79c; color: #6b4b0c; border-radius: 10px; padding: 10px 12px; font-size: .86rem; margin: 0 0 12px; }

/* ---------- Segmented ---------- */
.seg { display: inline-flex; background: var(--bg); border-radius: 10px; padding: 3px; }
.seg button {
  border: 0; background: none; font: 600 .82rem/1 "Plus Jakarta Sans", sans-serif;
  padding: 9px 12px; border-radius: 8px; color: var(--ink-soft); cursor: pointer; min-height: 34px;
  transition: background-color .2s, color .2s;
}
.seg button[aria-selected="true"] { background: var(--surface); color: var(--ink); box-shadow: 0 1px 3px rgb(40 30 10 / .14); }

/* ---------- Bars ---------- */
.bars { list-style: none; margin: 0; padding: 0; display: grid; gap: 18px; }
.bar-label { display: flex; align-items: baseline; gap: 10px; margin-bottom: 7px; }
.bar-no {
  flex: none; width: 28px; height: 28px; border-radius: 8px; display: grid; place-items: center;
  background: var(--c); color: #fff; font: 800 .95rem/1 "Bricolage Grotesque", sans-serif;
  align-self: center;
}
.bar-name { font-weight: 700; flex: 1; min-width: 0; overflow-wrap: anywhere; }
.bar-pct { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.bar-pct b { font: 800 1.3rem/1 "Bricolage Grotesque", sans-serif; }
.bar-pct small { display: block; color: var(--ink-soft); font-size: .76rem; margin-top: 2px; }
.track { height: 12px; background: var(--bg); border-radius: 99px; overflow: hidden; }
.fill { height: 100%; background: var(--c); border-radius: inherit; transition: width .7s var(--ease-out); animation: grow 1s var(--ease-out) both; transform-origin: left; }
@keyframes grow { from { transform: scaleX(0); } }

/* ---------- Zones ---------- */
.stack { display: flex; height: 16px; border-radius: 99px; overflow: hidden; gap: 2px; background: var(--bg); }
.seg-dalam { background: var(--z-dalam); }
.seg-luar { background: var(--z-luar); }
.seg-tidak_diketahui { background: var(--z-unknown); }
.legend { list-style: none; padding: 0; margin: 12px 0 0; display: flex; flex-wrap: wrap; gap: 6px 16px; font-size: .86rem; }
.legend b { font-variant-numeric: tabular-nums; margin-left: 2px; }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 7px; vertical-align: 0; }
.dot-dalam { background: var(--z-dalam); }
.dot-luar { background: var(--z-luar); }
.dot-tidak_diketahui { background: var(--z-unknown); }
.dot-line { border-radius: 0; height: 0; border-top: 2.5px dashed var(--boundary); vertical-align: middle; width: 16px; }

.seg-normal { background: var(--src-normal); }
.seg-panitia { background: var(--src-panitia); }
.dot-normal { background: var(--src-normal); }
.dot-panitia { background: var(--src-panitia); }
.source h3 { font: 800 1rem "Bricolage Grotesque", sans-serif; margin: 22px 0 0; }
tfoot th { border-top: 1px solid var(--line); border-bottom: 0; color: var(--ink); }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; margin-top: 16px; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; font-size: .88rem; }
th { text-align: left; font-weight: 600; color: var(--ink-soft); font-size: .78rem; padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: 10px; border-bottom: 1px solid #efe8d4; vertical-align: middle; }
tbody tr:hover { background: #fbf7ea; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.tag { display: inline-block; padding: 3px 9px; border-radius: 99px; font-size: .76rem; font-weight: 600; white-space: nowrap; }
.tag-dalam { background: #dcebdc; color: #1f5a36; }
.tag-luar { background: #f6dfd3; color: #8a3818; }
.tag-panitia { background: #fbecc0; color: #6b4b0c; }
.tag-tidak_diketahui { background: #ece8dc; color: #5c5644; }

.filters { display: flex; gap: 8px; flex-wrap: wrap; }
select {
  min-height: 40px; padding: 0 34px 0 12px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--surface) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8'%3E%3Cpath d='M1 1l5 5 5-5' fill='none' stroke='%2357614f' stroke-width='1.6'/%3E%3C/svg%3E") no-repeat right 12px center;
  appearance: none; font: 500 .88rem "Plus Jakarta Sans", sans-serif; color: var(--ink);
}
.pager { display: flex; flex-wrap: wrap; gap: 10px; justify-content: space-between; align-items: center; margin-top: 14px; font-size: .86rem; }
.pager span:last-child { display: flex; gap: 8px; }

/* ---------- Map ---------- */
.map { height: 420px; border-radius: 12px; border: 1px solid var(--line); z-index: 0; }
@media (max-width: 600px) { .map { height: 340px; } }
.map.editing { cursor: crosshair; outline: 3px solid #d9480f; outline-offset: 2px; }
.leaflet-container { font-family: inherit; }
.legend-map { margin-top: 10px; }
.edit-bar {
  display: flex; flex-wrap: wrap; gap: 10px; justify-content: space-between; align-items: center;
  background: #fdeee4; border: 1px solid #f2c6ab; border-radius: 10px; padding: 10px 12px; margin-bottom: 12px;
  font-size: .86rem; color: #7c3510;
}
.edit-bar[hidden] { display: none; }
.edit-actions { display: flex; gap: 6px; flex-wrap: wrap; }

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

/* ---------- Login ---------- */
.login-body {
  min-height: 100svh; display: grid; place-items: center; padding: 16px;
  background:
    linear-gradient(180deg, rgb(12 30 14 / .55), rgb(10 26 12 / .85)),
    url("../img/sawah-900.jpg") center / cover;
}
.login {
  width: min(100%, 380px); background: var(--surface); border-radius: 18px; padding: 28px 22px;
  box-shadow: 0 20px 44px -14px rgb(0 0 0 / .6);
}
.login h1 { font-size: 1.6rem; line-height: 1.1; margin-bottom: 20px; }
.login-form { display: grid; gap: 14px; }
.login-form label { display: grid; gap: 6px; font-size: .85rem; font-weight: 600; color: var(--ink-soft); }
.login-form input {
  min-height: 46px; padding: 0 12px; border-radius: 10px; border: 1px solid var(--line);
  font: 500 1rem "Plus Jakarta Sans", sans-serif; color: var(--ink); background: #fff;
}
.login-form .btn { min-height: 48px; font-size: 1rem; }
.err { margin: 0; color: #a3301f; font-weight: 600; font-size: .88rem; }
.back { display: inline-block; margin-top: 16px; font-size: .86rem; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

/* ---------- Form kelola (panitia / kandidat) ---------- */
.flash { margin: 0; padding: 10px 14px; border-radius: 10px; font-weight: 600; font-size: .9rem; }
.flash-ok { background: #dcebdc; color: #1f5a36; border: 1px solid #bcd8bf; }
.flash-err { background: #f6dfd3; color: #8a3818; border: 1px solid #ecc0aa; }
.inline-form { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; }
.inline-form label { display: grid; gap: 6px; font-size: .82rem; font-weight: 600; color: var(--ink-soft); flex: 1 1 200px; }
.inline-form .btn { min-height: 44px; }
.panel input:not([type=hidden]) {
  min-height: 40px; padding: 0 10px; border-radius: 10px; border: 1px solid var(--line);
  font: 500 .92rem "Plus Jakarta Sans", sans-serif; color: var(--ink); background: #fff; width: 100%; min-width: 0;
}
.panel input.short { width: 90px; }
.row-form { margin: 0; }
td input { min-width: 140px; }
td input.short { min-width: 0; }
.actions { display: flex; gap: 6px; flex-wrap: wrap; }
.actions .btn { min-height: 36px; padding: 0 10px; font-size: .8rem; }
.btn-danger { color: #a3301f; }
.btn-danger:hover { background: #fbe9e3; border-color: #ecc0aa; }
