:root {
  --bg: #15171b;
  --bg-raised: #1e2126;
  --bg-raised-2: #262a31;
  --line: #33373f;
  --line-dash: #f4b93c;
  --amber: #f4b93c;
  --amber-dim: #8a7135;
  --teal: #4fb0a5;
  --blue: #6d8ba7;
  --orange: #e2793d;
  --red: #d64545;
  --text: #eef0f2;
  --text-muted: #9aa1ab;
  --text-faint: #6a7079;
  --radius-sm: 8px;
  --radius-md: 14px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }

html, body {
  margin: 0; padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: 'Inter', -apple-system, Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

.num {
  font-family: 'Oswald', 'Inter', sans-serif;
  font-weight: 600;
  letter-spacing: 0.01em;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: calc(var(--vh, 1vh) * 100);
}

/* ---------- Header ---------- */
header {
  flex-shrink: 0;
  padding: calc(var(--safe-top) + 14px) 16px 12px;
  background: linear-gradient(180deg, #1a1d22 0%, var(--bg) 100%);
  border-bottom: 1px solid var(--line);
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
}
.brand-mark {
  width: 30px; height: 30px;
  flex-shrink: 0;
}
.brand h1 {
  font-size: 16px;
  margin: 0;
  font-weight: 600;
  letter-spacing: 0.01em;
}
.brand span {
  display: block;
  font-size: 11px;
  color: var(--text-muted);
  font-weight: 400;
}

.filters {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  scrollbar-width: none;
}
.filters::-webkit-scrollbar { display: none; }

.seg {
  display: flex;
  background: var(--bg-raised);
  border-radius: 999px;
  padding: 3px;
  flex-shrink: 0;
  border: 1px solid var(--line);
}
.seg button {
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 500;
  padding: 6px 12px;
  border-radius: 999px;
  font-family: inherit;
}
.seg button.active {
  background: var(--amber);
  color: #15171b;
}

.select-chip {
  flex-shrink: 0;
  background: var(--bg-raised);
  border: 1px solid var(--line);
  color: var(--text);
  font-size: 13px;
  border-radius: 999px;
  padding: 7px 12px;
  font-family: inherit;
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='10' height='6'><path d='M0 0L5 6L10 0Z' fill='%239aa1ab'/></svg>");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 26px;
}

/* ---------- Main scroll area ---------- */
main {
  flex: 1 1 auto;
  overflow-y: auto;
  min-height: 0;
  -webkit-overflow-scrolling: touch;
}
.tab-panel { display: none; padding: 16px 16px calc(24px + var(--safe-bottom)); }
.tab-panel.active { display: block; }

.section-title {
  font-size: 12px;
  text-transform: none;
  color: var(--text-muted);
  margin: 22px 0 10px;
  padding-bottom: 8px;
  border-bottom: 1px dashed var(--line-dash);
  opacity: 0.9;
}
.section-title:first-child { margin-top: 0; }

/* ---------- KPI plates ---------- */
.hero-plate {
  background: linear-gradient(155deg, #2a1616 0%, var(--bg-raised) 55%);
  border: 1px solid #4a2626;
  border-radius: var(--radius-md);
  padding: 16px 18px;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 10px;
}
.hero-plate .num { font-size: 34px; color: var(--red); line-height: 1; }
.hero-plate .lbl { font-size: 13px; color: var(--text-muted); }

.kpi-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.kpi-card {
  background: var(--bg-raised);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  padding: 12px 14px;
  border-top: 3px solid var(--kc, var(--amber));
}
.kpi-card .num { font-size: 22px; display: block; }
.kpi-card .lbl { font-size: 11.5px; color: var(--text-muted); margin-top: 2px; display: block; }

/* ---------- Bars / rankings ---------- */
.bar-row {
  display: grid;
  grid-template-columns: 84px 1fr 46px;
  align-items: center;
  gap: 8px;
  padding: 7px 0;
}
.bar-row .bar-label {
  font-size: 12.5px;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.bar-track {
  height: 9px;
  background: var(--bg-raised-2);
  border-radius: 5px;
  overflow: hidden;
}
.bar-fill {
  height: 100%;
  border-radius: 5px;
  background: var(--amber);
}
.bar-row .bar-val {
  font-size: 12px;
  color: var(--text-muted);
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.stacked-bar {
  display: flex;
  height: 30px;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid var(--line);
}
.stacked-bar div { height: 100%; }
.stacked-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 14px;
  margin-top: 10px;
}
.legend-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11.5px;
  color: var(--text-muted);
}
.legend-dot { width: 9px; height: 9px; border-radius: 2px; flex-shrink: 0; }

.card {
  background: var(--bg-raised);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  margin-bottom: 10px;
}
.card h3 {
  font-size: 13px;
  font-weight: 600;
  margin: 0 0 10px;
  color: var(--text);
}

canvas#trendChart { max-height: 160px; }

/* ---------- Conditions accordion ---------- */
.accordion { border: 1px solid var(--line); border-radius: var(--radius-md); overflow: hidden; margin-bottom: 10px; background: var(--bg-raised); }
.accordion-head {
  display: flex; justify-content: space-between; align-items: center;
  padding: 13px 16px;
}
.accordion-head h3 { margin: 0; font-size: 13.5px; font-weight: 600; }
.accordion-head .chev { color: var(--text-muted); font-size: 13px; transition: transform 0.2s; }
.accordion.open .chev { transform: rotate(180deg); }
.accordion-body { display: none; padding: 0 16px 14px; }
.accordion.open .accordion-body { display: block; }

/* ---------- Map ---------- */
#map-wrap { position: relative; height: 100%; width: 100%; }
#map { position: absolute; inset: 0; }
.tab-panel#panel-harta { padding: 0; height: 100%; }
.map-legend {
  background: rgba(21,23,27,0.9);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 12px;
  font-size: 11.5px;
  color: var(--text-muted);
  backdrop-filter: blur(4px);
}
.map-topright {
  position: absolute; top: 12px; right: 12px; z-index: 500;
  display: flex; flex-direction: column; align-items: flex-end; gap: 8px;
}
.map-legend .legend-item { margin-bottom: 3px; }
.map-legend .legend-item:last-child { margin-bottom: 0; }
.map-count-badge {
  background: rgba(21,23,27,0.9);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 12px;
  font-size: 11.5px;
  color: var(--text-muted);
  backdrop-filter: blur(4px);
}
.map-count-badge b { color: var(--text); font-family: 'Oswald', sans-serif; font-size: 14px; }

.marker-cluster-accidente { background: rgba(244,185,60,0.25); }
.marker-cluster-accidente div { background: var(--amber); color: #15171b; font-weight: 700; font-family: 'Oswald', sans-serif; }
.leaflet-popup-content-wrapper { background: var(--bg-raised); color: var(--text); border-radius: 10px; }
.leaflet-popup-tip { background: var(--bg-raised); }
.leaflet-popup-content { font-size: 12.5px; margin: 10px 12px; font-family: 'Inter', sans-serif; }
.leaflet-popup-content b { color: var(--amber); }
.leaflet-container { background: #0e1013; }
.leaflet-tile-pane { filter: invert(1) hue-rotate(180deg) brightness(0.87) contrast(0.92) saturate(0.65); }

#map-loading {
  position: absolute; inset: 0; z-index: 480;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 12px; background: #0e1013; color: var(--text-muted); font-size: 13px;
  pointer-events: none; opacity: 1; transition: opacity 0.25s ease;
}
#map-loading.hidden { opacity: 0; pointer-events: none; }
#map-loading .spinner {
  width: 26px; height: 26px; border-radius: 50%;
  border: 3px solid var(--line); border-top-color: var(--amber);
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Locate control ---------- */
.locate-control {
  position: absolute; top: 12px; left: 12px; z-index: 500;
  display: flex; flex-direction: column; gap: 8px;
}
.locate-control #locate-btn {
  background: var(--bg-raised); border: 1px solid var(--line); color: var(--text);
  font-size: 12.5px; font-weight: 600; padding: 9px 13px; border-radius: 999px;
  font-family: inherit; backdrop-filter: blur(4px);
}
.locate-control #locate-btn.active { background: var(--amber); color: #15171b; border-color: var(--amber); }
.locate-control #locate-btn:disabled { opacity: 0.6; }
.locate-radius-row {
  display: none; gap: 6px;
  background: rgba(21,23,27,0.9); border: 1px solid var(--line); border-radius: 999px;
  padding: 4px; backdrop-filter: blur(4px);
}
.locate-radius-row.show { display: flex; }
.radius-chip {
  background: transparent; border: none; color: var(--text-muted);
  font-size: 11px; font-family: inherit; padding: 5px 9px; border-radius: 999px;
}
.radius-chip.active { background: var(--amber); color: #15171b; font-weight: 700; }

.locate-result {
  display: none; position: absolute; bottom: calc(14px + var(--safe-bottom));
  right: 12px; left: 12px; z-index: 500;
  background: rgba(21,23,27,0.94); border: 1px solid var(--line); border-radius: 12px;
  padding: 12px 14px; font-size: 12.5px; color: var(--text-muted);
  backdrop-filter: blur(4px);
}
.locate-result.show { display: block; }
.locate-result .big { font-family: 'Oswald', sans-serif; font-size: 20px; color: var(--amber); margin-right: 6px; }
.locate-result .close-x { float: right; color: var(--text-faint); font-size: 13px; }

/* ---------- Bottom nav ---------- */
nav.bottomnav {
  flex-shrink: 0;
  display: flex;
  background: #1a1d22;
  border-top: 1px solid var(--line);
  padding-bottom: var(--safe-bottom);
}
nav.bottomnav button {
  flex: 1;
  background: none;
  border: none;
  color: var(--text-faint);
  font-family: inherit;
  font-size: 11px;
  padding: 9px 0 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
}
nav.bottomnav button svg { width: 21px; height: 21px; }
nav.bottomnav button.active { color: var(--amber); }
nav.bottomnav button.active svg { stroke: var(--amber); }

/* ---------- APK banner ---------- */
#apk-banner {
  display: flex; background: var(--bg-raised-2); color: var(--text); padding: 10px 16px;
  font-size: 12.5px; align-items: center; justify-content: space-between; gap: 10px; flex-shrink: 0;
  border-bottom: 1px solid var(--line);
}
#apk-banner span { line-height: 1.4; }
#apk-btn {
  background: var(--amber); color: #15171b; border: none; padding: 7px 14px;
  border-radius: 999px; font-size: 12.5px; font-weight: 700; font-family: inherit;
  text-decoration: none; white-space: nowrap; flex-shrink: 0;
}

.loading-row { display: flex; align-items: center; justify-content: center; padding: 60px 0; color: var(--text-muted); font-size: 13px; }

/* ---------- Data source note ---------- */
.data-source {
  text-align: center; font-size: 11.5px; color: var(--text-faint);
  padding-top: 14px; margin-top: 6px; border-top: 1px dashed var(--line);
}
.privacy-link { color: var(--text-faint); text-decoration: underline; }
.legend-source { font-size: 10px; color: var(--text-faint); margin-top: 4px; padding-top: 4px; border-top: 1px solid var(--line); }
.legend-note { font-size: 9.5px; color: var(--text-faint); margin-top: 3px; max-width: 130px; line-height: 1.4; }

/* ---------- Filter trigger + count badge ---------- */
.filter-trigger { display: flex; align-items: center; gap: 6px; font-weight: 500; }
#filter-count-badge {
  display: none; min-width: 16px; height: 16px; padding: 0 4px;
  background: var(--amber); color: #15171b; border-radius: 999px;
  font-size: 10px; font-weight: 700; align-items: center; justify-content: center;
  line-height: 16px; text-align: center;
}
#filter-count-badge.show { display: inline-block; }

/* ---------- Filter dialog ---------- */
#filter-overlay {
  display: none; position: fixed; inset: 0; z-index: 900;
  background: rgba(10,11,13,0.66);
  align-items: center; justify-content: center;
  padding: 20px;
}
#filter-overlay.open { display: flex; }
.filter-sheet {
  width: 100%; max-width: 420px;
  background: var(--bg-raised);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 18px 18px calc(18px + var(--safe-bottom));
  max-height: 82vh; overflow-y: auto;
}
.filter-sheet-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.filter-sheet-head h3 { margin: 0; font-size: 16px; font-weight: 600; }
.filter-sheet-head button {
  background: var(--bg-raised-2); border: 1px solid var(--line); color: var(--text-muted);
  width: 30px; height: 30px; border-radius: 999px; font-size: 14px;
}
.filter-field { margin-bottom: 16px; }
.filter-field label { display: block; font-size: 12px; color: var(--text-muted); margin-bottom: 7px; }
.select-full {
  width: 100%; background: var(--bg-raised-2); border: 1px solid var(--line); color: var(--text);
  font-size: 14px; border-radius: 10px; padding: 11px 30px 11px 12px; font-family: inherit;
  appearance: none; -webkit-appearance: none;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='10' height='6'><path d='M0 0L5 6L10 0Z' fill='%239aa1ab'/></svg>");
  background-repeat: no-repeat; background-position: right 12px center;
}
.seg-wrap { flex-wrap: wrap; gap: 6px; background: transparent; border: none; padding: 0; }
.seg-wrap button {
  flex: 1 1 calc(50% - 6px); background: var(--bg-raised-2); border: 1px solid var(--line);
  border-radius: 10px; padding: 10px 8px; color: var(--text-muted); font-size: 13px;
}
.seg-wrap button.active { background: var(--amber); color: #15171b; border-color: var(--amber); font-weight: 600; }
.filter-reset-btn {
  width: 100%; background: none; border: 1px solid var(--line); color: var(--text-muted);
  padding: 12px; border-radius: 10px; font-size: 13.5px; font-family: inherit; margin-top: 4px;
}

.km-range-bounds { font-size: 11px; color: var(--text-faint); margin-bottom: 8px; margin-top: -4px; }
.km-range-inputs { display: flex; align-items: center; gap: 8px; }
.km-input {
  flex: 1; background: var(--bg-raised-2); border: 1px solid var(--line); color: var(--text);
  font-size: 14px; border-radius: 10px; padding: 11px 12px; font-family: inherit; min-width: 0;
}
.km-dash { color: var(--text-faint); flex-shrink: 0; }
.km-range-note {
  font-size: 11px; color: var(--text-faint); margin-top: 8px; line-height: 1.5;
  padding: 8px 10px; background: rgba(244,185,60,0.08); border-radius: 8px; border: 1px solid rgba(244,185,60,0.2);
}

/* ---------- Report / PDF tab ---------- */
.report-card { padding: 18px; }
.report-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 0;
}
.report-row + .report-row { border-top: 1px dashed var(--line); }
.report-label { font-size: 11.5px; color: var(--text-muted); margin-bottom: 4px; }
.report-value { font-size: 14px; color: var(--text); font-weight: 500; }
.report-count { font-size: 26px; color: var(--amber); }
.report-price {
  font-family: 'Oswald', sans-serif; font-size: 20px; color: #15171b;
  background: var(--amber); padding: 6px 14px; border-radius: 999px; font-weight: 600;
}
.report-cap-msg {
  display: none; margin-top: 12px; padding: 10px 12px; border-radius: 10px;
  background: rgba(214,69,69,0.12); border: 1px solid rgba(214,69,69,0.35);
  color: #f0a0a0; font-size: 12.5px;
}
.report-cap-msg.show { display: block; }
.report-btn {
  width: 100%; margin-top: 16px; background: var(--amber); color: #15171b;
  border: none; padding: 14px; border-radius: 12px; font-family: inherit;
  font-size: 15px; font-weight: 700;
}
.report-btn:disabled { opacity: 0.45; }
.report-note { text-align: center; font-size: 11px; color: var(--text-faint); margin-top: 10px; }
.report-save-tip {
  font-size: 12px; color: var(--text-muted); margin-top: 12px; line-height: 1.6;
  padding: 10px 12px; background: var(--bg-raised-2); border-radius: 10px; border: 1px solid var(--line);
}
.report-save-tip b { color: var(--amber); }
.report-desc { font-size: 12.5px; color: var(--text-muted); line-height: 1.6; margin: 0 0 10px; }
.report-desc:last-child { margin-bottom: 0; }
