:root {
  --bg: #f4f6f3;
  --surface: #ffffff;
  --surface-soft: #eef4ee;
  --ink: #1f2726;
  --muted: #63706d;
  --line: #d9dfdc;
  --accent: #0f766e;
  --accent-2: #2563eb;
  --warn: #d97706;
  --danger: #dc2626;
  --good: #15803d;
  --shadow: 0 16px 36px rgba(28, 37, 36, 0.12);
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

button,
input,
select {
  font: inherit;
}

.app-shell {
  display: grid;
  grid-template-columns: 292px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  border-right: 1px solid var(--line);
  background: #f9faf8;
  padding: 22px 18px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 20px;
}

.brand h1,
.brand p,
.topbar h2,
.topbar p,
.panel h3 {
  margin: 0;
}

.brand h1 {
  font-size: 20px;
  line-height: 1.1;
}

.brand p,
.topbar p,
.sidebar-note,
.metric span,
.forecast-main span,
.footer-note {
  color: var(--muted);
}

.brand-source {
  margin-top: 5px;
  font-size: 12px;
  font-weight: 700;
}

.control-group {
  display: grid;
  gap: 8px;
  margin: 16px 0;
}

.control-group label,
.layer-list label {
  color: #33413e;
  font-size: 13px;
  font-weight: 650;
}

select,
input[type="range"] {
  width: 100%;
}

select {
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  padding: 0 10px;
}

input[type="range"] {
  accent-color: var(--accent);
}

output {
  float: right;
  color: var(--accent);
}

.layer-list {
  display: grid;
  gap: 11px;
  padding: 14px 0;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  margin: 18px 0;
}

.layer-list label {
  display: flex;
  align-items: center;
  gap: 9px;
}

.layer-list input {
  accent-color: var(--accent);
}

#refreshButton {
  width: 100%;
  min-height: 42px;
  border: 0;
  border-radius: 8px;
  background: var(--ink);
  color: white;
  cursor: pointer;
  font-weight: 700;
}

#refreshButton:hover {
  background: #101615;
}

.sidebar-note {
  display: grid;
  gap: 6px;
  margin-top: 18px;
  padding: 13px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  font-size: 13px;
  line-height: 1.4;
}

.workspace {
  min-width: 0;
  padding: 22px;
}

.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.topbar h2 {
  font-size: 24px;
  line-height: 1.15;
}

.topbar p {
  margin-top: 5px;
  font-size: 14px;
}

.top-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.pill {
  display: inline-flex;
  align-items: center;
  min-height: 32px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  padding: 0 12px;
  color: #384441;
  font-size: 13px;
  font-weight: 700;
}

.pill.good {
  border-color: rgba(21, 128, 61, 0.35);
  color: var(--good);
}

.pill.warn {
  border-color: rgba(217, 119, 6, 0.35);
  color: var(--warn);
}

.pill.danger {
  border-color: rgba(220, 38, 38, 0.35);
  color: var(--danger);
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 14px;
}

.metric,
.panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 1px 0 rgba(26, 35, 33, 0.03);
}

.metric {
  display: grid;
  gap: 8px;
  padding: 15px;
  min-height: 86px;
}

.metric strong {
  font-size: 26px;
  line-height: 1;
}

.map-panel {
  position: relative;
  height: min(66vh, 720px);
  min-height: 460px;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: #aad3df;
  box-shadow: var(--shadow);
  margin-bottom: 14px;
}

#map,
#fallbackMap {
  width: 100%;
  height: 100%;
  display: block;
}

.map-unavailable {
  display: grid;
  place-items: center;
  padding: 24px;
  background: #dce8e5;
  color: #33413e;
  font-size: 14px;
  font-weight: 750;
  text-align: center;
}

[hidden] {
  display: none !important;
}

.leaflet-container {
  background: #aad3df;
  font: inherit;
}

.leaflet-tile-error {
  opacity: 0 !important;
}

.bmkg-single-wms {
  position: absolute;
  inset: 0;
  overflow: hidden;
  z-index: 200;
  pointer-events: none;
}

.bmkg-wms-image {
  position: absolute;
  max-width: none !important;
  pointer-events: none;
  user-select: none;
  opacity: 0;
  transition: opacity 120ms ease;
}

.event-dom-overlay {
  position: absolute;
  inset: 0;
  z-index: 1100;
  pointer-events: none;
}

.event-map-dot {
  position: absolute;
  left: 0;
  top: 0;
  width: var(--dot-size);
  height: var(--dot-size);
  border: 1px solid #7f1d1d;
  border-radius: 999px;
  background: #ef4444;
  box-shadow:
    0 0 0 1px rgba(255, 255, 255, 0.78),
    0 2px 6px rgba(127, 29, 29, 0.32);
  cursor: pointer;
  pointer-events: auto;
  padding: 0;
}

.event-map-dot.forecast {
  border-color: #064e3b;
  background: #14b8a6;
  box-shadow:
    0 0 0 1px rgba(255, 255, 255, 0.85),
    0 0 0 5px rgba(20, 184, 166, 0.18),
    0 2px 7px rgba(6, 78, 59, 0.35);
}

.event-map-dot.near-forecast {
  border-color: #92400e;
  background: #f59e0b;
  box-shadow:
    0 0 0 1px rgba(255, 255, 255, 0.82),
    0 0 0 4px rgba(245, 158, 11, 0.16),
    0 2px 7px rgba(146, 64, 14, 0.32);
}

.event-map-dot.bmkg-latest {
  border: 2px solid #7f1d1d;
  background: #b91c1c;
  box-shadow:
    0 0 0 2px rgba(255, 255, 255, 0.92),
    0 0 0 7px rgba(220, 38, 38, 0.2),
    0 3px 10px rgba(127, 29, 29, 0.42);
}

.event-map-dot:hover {
  background: #dc2626;
  box-shadow:
    0 0 0 2px rgba(255, 255, 255, 0.9),
    0 0 0 6px rgba(239, 68, 68, 0.18),
    0 4px 10px rgba(127, 29, 29, 0.38);
}

.event-map-dot.forecast:hover {
  background: #0f766e;
}

.event-map-dot.near-forecast:hover {
  background: #d97706;
}

.region-label,
.zone-score-label,
.cluster-label,
.forecast-label {
  pointer-events: none;
}

.region-label span,
.zone-score-label span,
.cluster-label span,
.forecast-label span {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 20px;
  border: 1px solid rgba(31, 39, 38, 0.12);
  border-radius: 999px;
  background: rgba(31, 39, 38, 0.82);
  box-shadow: 0 5px 14px rgba(31, 39, 38, 0.1);
  color: #ffffff;
  font-size: 11px;
  font-weight: 800;
  line-height: 1;
  padding: 3px 8px;
  white-space: nowrap;
}

.region-label span {
  color: rgba(31, 39, 38, 0.68);
  font-size: 12px;
  letter-spacing: 0;
}

.zone-score-label span {
  background: rgba(21, 128, 61, 0.88);
}

.zone-score-label.mid span {
  border-color: rgba(217, 119, 6, 0.2);
  background: rgba(180, 83, 9, 0.9);
  color: #ffffff;
}

.zone-score-label.high span {
  border-color: rgba(220, 38, 38, 0.2);
  background: rgba(185, 28, 28, 0.9);
  color: #ffffff;
}

.cluster-label span {
  border-color: rgba(217, 119, 6, 0.2);
  background: rgba(146, 64, 14, 0.9);
  color: #ffffff;
}

.forecast-label span {
  border-color: rgba(15, 118, 110, 0.2);
  background: rgba(15, 118, 110, 0.9);
  color: #ffffff;
}

.legend {
  position: absolute;
  left: 14px;
  bottom: 14px;
  z-index: 1300;
  display: flex;
  flex-wrap: wrap;
  gap: 9px;
  max-width: calc(100% - 28px);
  padding: 9px 10px;
  border: 1px solid rgba(31, 39, 38, 0.15);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.92);
  box-shadow: 0 10px 26px rgba(31, 39, 38, 0.12);
  font-size: 12px;
  font-weight: 700;
}

.legend span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.legend-summary {
  color: var(--muted);
  font-weight: 650;
}

.legend-dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
}

.legend-dot.event {
  background: #ef4444;
}

.legend-dot.forecast {
  background: #14b8a6;
}

.legend-dot.near-forecast {
  background: #f59e0b;
}

.legend-dot.bmkg {
  background: #b91c1c;
  box-shadow: 0 0 0 3px rgba(220, 38, 38, 0.16);
}

.bmkg-latest {
  margin-bottom: 14px;
}

.bmkg-latest-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 9px;
}

.bmkg-latest-grid div {
  display: grid;
  gap: 6px;
  min-height: 74px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
  padding: 12px;
}

.bmkg-latest-grid span,
.bmkg-meta {
  color: var(--muted);
}

.bmkg-latest-grid span {
  font-size: 12px;
  font-weight: 700;
}

.bmkg-latest-grid strong {
  font-size: 18px;
  line-height: 1.2;
}

.bmkg-region {
  margin: 12px 0 0;
  color: #263230;
  font-size: 15px;
  font-weight: 750;
  line-height: 1.4;
}

.bmkg-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 12px;
  margin-top: 9px;
  font-size: 12px;
  font-weight: 700;
}

.bmkg-meta a {
  color: var(--accent);
  text-decoration: none;
}

.bmkg-meta a:hover {
  text-decoration: underline;
}

.insight-grid {
  display: grid;
  grid-template-columns: 1.15fr 1fr 0.9fr;
  gap: 14px;
  margin-bottom: 14px;
}

.table-grid {
  display: grid;
  grid-template-columns: 1.15fr 0.85fr;
  gap: 14px;
}

.panel {
  min-width: 0;
  padding: 15px;
}

.panel-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 13px;
}

.panel-header h3 {
  font-size: 16px;
}

.panel-header span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.forecast-main {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 9px;
  margin-bottom: 14px;
}

.forecast-main div {
  display: grid;
  gap: 5px;
  min-height: 72px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
  padding: 10px;
}

.forecast-main strong {
  font-size: 20px;
}

.rank-list {
  display: grid;
  gap: 8px;
}

.rank-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
}

.rank-label {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: #33413e;
  font-size: 13px;
  font-weight: 700;
}

.rank-meta {
  margin: 2px 0 5px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 650;
}

.rank-bar {
  position: relative;
  height: 8px;
  overflow: hidden;
  border-radius: 999px;
  background: #e3e9e6;
}

.rank-bar span {
  position: absolute;
  inset: 0 auto 0 0;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
}

.rank-value {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.bar-chart {
  display: flex;
  align-items: end;
  gap: 4px;
  height: 172px;
  padding-top: 8px;
}

.bar {
  flex: 1;
  min-width: 4px;
  border-radius: 4px 4px 0 0;
  background: linear-gradient(180deg, #2563eb, #8ab3ff);
}

.bar.low {
  background: linear-gradient(180deg, #15803d, #9ad0a6);
}

.bar.mid {
  background: linear-gradient(180deg, #d97706, #f5c06a);
}

.bar.high {
  background: linear-gradient(180deg, #dc2626, #f19a9a);
}

.bar-chart.horizontal {
  display: grid;
  align-items: stretch;
  gap: 9px;
  height: auto;
  min-height: 172px;
}

.hbar-row {
  display: grid;
  grid-template-columns: 46px minmax(0, 1fr) 54px;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
}

.hbar-track {
  height: 9px;
  overflow: hidden;
  border-radius: 999px;
  background: #e4eae7;
}

.hbar-track span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #0f766e, #f59e0b);
}

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

th,
td {
  padding: 10px 8px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

th {
  color: #50605c;
  font-size: 12px;
  font-weight: 800;
}

td {
  color: #2e3936;
}

.score {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 36px;
  height: 24px;
  border-radius: 999px;
  background: #edf2ef;
  font-weight: 800;
}

.score.high {
  background: rgba(220, 38, 38, 0.12);
  color: var(--danger);
}

.score.mid {
  background: rgba(217, 119, 6, 0.14);
  color: var(--warn);
}

.footer-note {
  margin-top: 16px;
  font-size: 12px;
}

.leaflet-popup-content {
  min-width: 210px;
}

.popup-title {
  margin: 0 0 6px;
  font-size: 14px;
  font-weight: 800;
}

.popup-grid {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 4px 10px;
  font-size: 12px;
}

.popup-grid span:nth-child(odd) {
  color: #60706b;
  font-weight: 700;
}

@media (max-width: 1180px) {
  .app-shell {
    grid-template-columns: 248px minmax(0, 1fr);
  }

  .kpi-grid,
  .insight-grid,
  .bmkg-latest-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .forecast-panel {
    grid-column: 1 / -1;
  }
}

@media (max-width: 820px) {
  .app-shell {
    display: block;
  }

  .sidebar {
    position: static;
    height: auto;
  }

  .workspace {
    padding: 16px;
  }

  .topbar,
  .top-actions {
    display: grid;
    justify-content: stretch;
  }

  .kpi-grid,
  .insight-grid,
  .table-grid,
  .forecast-main,
  .bmkg-latest-grid {
    grid-template-columns: 1fr;
  }

  .map-panel {
    height: 62vh;
    min-height: 390px;
  }
}
