:root {
  --bg: #eef2ef;
  --panel: #f7faf7;
  --ink: #1a2a22;
  --muted: #5c6f64;
  --line: #c5d2c8;
  --accent: #1f6b4a;
  --accent-2: #c45c26;
  --map-void: #d8e2da;
  --shadow: 0 10px 30px rgba(26, 42, 34, 0.08);
  --radius: 14px;
  --sidebar: 240px;
  --font-display: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  --font-body: "Segoe UI", "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: var(--font-body);
  color: var(--ink);
  background:
    radial-gradient(1200px 600px at 10% -10%, #d9ebe0 0%, transparent 55%),
    radial-gradient(900px 500px at 100% 0%, #f0e6d8 0%, transparent 50%),
    var(--bg);
}

.app {
  display: grid;
  grid-template-columns: var(--sidebar) 1fr auto;
  min-height: 100vh;
}

.sidebar {
  background: linear-gradient(180deg, #163528 0%, #1f4635 100%);
  color: #e8f2ec;
  padding: 1.25rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}
.brand { display: flex; gap: 0.75rem; align-items: center; }
.brand-mark {
  width: 42px; height: 42px; border-radius: 10px;
  display: grid; place-items: center;
  background: #c8e6d4; color: #163528;
  font-family: var(--font-display); font-weight: 700;
}
.brand-name { font-family: var(--font-display); font-size: 1.25rem; line-height: 1.1; }
.brand-sub { font-size: 0.75rem; opacity: 0.75; letter-spacing: 0.04em; text-transform: uppercase; }

.nav { display: flex; flex-direction: column; gap: 0.35rem; }
.nav button {
  appearance: none; border: 0; text-align: left;
  background: transparent; color: inherit;
  padding: 0.65rem 0.75rem; border-radius: 10px;
  cursor: pointer; font: inherit;
}
.nav button:hover { background: rgba(255,255,255,0.08); }
.nav button.active { background: rgba(200, 230, 212, 0.18); color: #fff; }

.sidebar-foot { margin-top: auto; font-size: 0.8rem; opacity: 0.85; }
.live-toggle { display: flex; gap: 0.5rem; align-items: center; margin-bottom: 0.5rem; }
.privacy-note { margin: 0; opacity: 0.7; }

.main { padding: 1.25rem 1.5rem 2rem; min-width: 0; }
.topbar {
  display: flex; flex-wrap: wrap; gap: 1rem;
  justify-content: space-between; align-items: flex-start;
  margin-bottom: 1rem;
}
.topbar h1 {
  margin: 0; font-family: var(--font-display);
  font-size: clamp(1.6rem, 2.5vw, 2.2rem); font-weight: 600;
}
.meta-line { margin: 0.25rem 0 0; color: var(--muted); font-size: 0.9rem; }

.filters {
  display: flex; flex-wrap: wrap; gap: 0.6rem; align-items: end;
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 0.75rem; box-shadow: var(--shadow);
}
.filters label {
  display: flex; flex-direction: column; gap: 0.25rem;
  font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted);
}
.filters label.chk { flex-direction: row; align-items: center; gap: 0.4rem; text-transform: none; letter-spacing: 0; font-size: 0.85rem; color: var(--ink); }
.filters input, .filters select {
  border: 1px solid var(--line); border-radius: 8px;
  padding: 0.4rem 0.5rem; font: inherit; color: var(--ink); background: #fff;
  min-width: 5.5rem;
}
.btn {
  border: 0; border-radius: 8px; padding: 0.5rem 0.9rem;
  background: var(--accent); color: #fff; font: inherit; cursor: pointer;
}
.btn:hover { filter: brightness(1.05); }

.status {
  margin-bottom: 0.75rem; padding: 0.65rem 0.85rem;
  border-radius: 10px; background: #fff4e8; border: 1px solid #efd2b5; color: #6a3b12;
}

.view-root { display: flex; flex-direction: column; gap: 1rem; }
.panel {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 1rem;
}
.panel h2 {
  margin: 0 0 0.75rem; font-family: var(--font-display);
  font-size: 1.15rem; font-weight: 600;
}
.panel-note { margin: 0 0 0.75rem; color: var(--muted); font-size: 0.9rem; }

.kpi-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 0.75rem;
}
.kpi {
  background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 0.85rem;
}
.kpi .label { font-size: 0.75rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
.kpi .value { font-family: var(--font-display); font-size: 1.6rem; margin-top: 0.2rem; }

.split {
  display: grid; grid-template-columns: 1.4fr 1fr; gap: 1rem;
}
@media (max-width: 1100px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { flex-direction: row; flex-wrap: wrap; align-items: center; }
  .nav { flex-direction: row; flex-wrap: wrap; }
  .sidebar-foot { margin-top: 0; width: 100%; }
  .split { grid-template-columns: 1fr; }
}

.map-box {
  height: min(62vh, 640px); border-radius: 12px; overflow: hidden;
  border: 1px solid var(--line); background: var(--map-void);
  z-index: 0;
}
.map-box .leaflet-container {
  width: 100%; height: 100%; font: inherit;
}
.chart-box { height: 320px; }
.chart-box.tall { height: 420px; }

.table-wrap { overflow: auto; max-height: 420px; }
table.data {
  width: 100%; border-collapse: collapse; font-size: 0.9rem;
}
table.data th, table.data td {
  text-align: left; padding: 0.45rem 0.5rem; border-bottom: 1px solid var(--line);
}
table.data th { color: var(--muted); font-weight: 600; font-size: 0.75rem; text-transform: uppercase; }
table.data tr:hover td { background: rgba(31, 107, 74, 0.06); cursor: pointer; }

.detail {
  width: min(360px, 92vw); background: #fff; border-left: 1px solid var(--line);
  padding: 1rem; box-shadow: var(--shadow); position: relative;
}
.detail-close {
  position: absolute; top: 0.5rem; right: 0.6rem;
  border: 0; background: transparent; font-size: 1.4rem; cursor: pointer; color: var(--muted);
}
.legend {
  display: flex; gap: 0.5rem; align-items: center; flex-wrap: wrap;
  font-size: 0.8rem; color: var(--muted); margin-top: 0.5rem;
}
.legend i {
  display: inline-block; width: 12px; height: 12px; border-radius: 50%;
}
.loading { color: var(--muted); padding: 2rem; text-align: center; }
.empty { color: var(--muted); padding: 1rem; }
