:root {
  --bg: #080d16;
  --panel: #101827;
  --panel-2: #152033;
  --border: #26344d;
  --text: #eef4ff;
  --muted: #98a6bd;
  --accent: #85d7aa;
  --accent-2: #6db8ff;
  --header-h: 132px;
}

* { box-sizing: border-box; }

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

.app-header {
  background: #070b13;
  border-bottom: 1px solid var(--border);
}

.header-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 8px 18px 0;
}

.brand-link {
  display: inline-flex;
  align-items: center;
  flex-shrink: 0;
  text-decoration: none;
  line-height: 0;
}

.brand-logo {
  display: block;
  height: 44px;
  width: auto;
  max-width: 196px;
  object-fit: contain;
}

.app-nav {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
}

.nav-link {
  display: inline-flex;
  align-items: center;
  min-height: 36px;
  padding: 0 16px;
  border-radius: 12px 12px 0 0;
  color: var(--muted);
  text-decoration: none;
  font-size: 14px;
  font-weight: 600;
  border: 1px solid transparent;
  border-bottom: none;
}

.nav-link:hover {
  color: var(--text);
  background: rgba(21, 32, 51, 0.6);
}

.nav-link.is-active {
  color: var(--text);
  background: #0f1726;
  border-color: var(--border);
}

.toolbar {
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  gap: 10px;
  padding: 10px 18px 12px;
}

.toolbar-filters {
  display: flex;
  flex: 1;
  flex-wrap: nowrap;
  align-items: center;
  gap: 8px;
  min-width: 0;
  overflow-x: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

.toolbar-filters > * {
  flex: 0 0 auto;
}

.toolbar-filters::-webkit-scrollbar {
  height: 6px;
}

.toolbar-filters::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 999px;
}

.search {
  width: min(240px, 28vw);
  min-width: 160px;
}

.toolbar select {
  width: auto;
  min-width: 96px;
  max-width: 132px;
}

.toolbar input[type="date"] {
  width: auto;
  min-width: 128px;
  max-width: 140px;
}

.toolbar #reset {
  flex: 0 0 auto;
  white-space: nowrap;
}

input, select, button {
  min-height: 40px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: #111a2a;
  color: var(--text);
  padding: 0 12px;
  outline: none;
}

button { cursor: pointer; }
button:hover { border-color: var(--accent); }

.layout {
  display: grid;
  grid-template-columns: 360px 1fr;
  height: calc(100vh - var(--header-h, 120px));
}

.panel {
  border-right: 1px solid var(--border);
  background: linear-gradient(180deg, #0f1726 0%, #0a101a 100%);
  overflow: auto;
  padding: 14px;
  min-height: 0;
}

.map-wrap { position: relative; min-height: 0; }
#map { height: 100%; width: 100%; background: #111; min-height: 320px; }

/* —— Statistics page —— */

.stats-page .stats-layout {
  padding: 18px;
  max-width: 1400px;
  margin: 0 auto;
  overflow: auto;
  height: calc(100vh - var(--header-h, 120px));
}

.stats-page .stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  margin-bottom: 18px;
}

.stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 16px;
}

.stats-card {
  border: 1px solid var(--border);
  background: rgba(15, 23, 38, 0.95);
  border-radius: 16px;
  padding: 16px;
}

.stats-card-wide {
  margin-bottom: 24px;
}

.stats-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 8px;
}

.stats-card-head h2 {
  margin: 0;
  font-size: 15px;
  font-weight: 700;
}

.stats-card-head select {
  min-height: 34px;
  font-size: 12px;
}

.inline-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.inline-controls select {
  min-height: 34px;
  font-size: 12px;
}

.stats-hint {
  margin: 0 0 12px;
  font-size: 12px;
  color: var(--muted);
  line-height: 1.4;
}

.chart-area {
  overflow: auto;
  max-height: 420px;
}

.mix-bar-row {
  display: grid;
  grid-template-columns: minmax(88px, 1.1fr) 1fr 36px;
  gap: 10px;
  align-items: center;
  margin-bottom: 10px;
  font-size: 12px;
}

.mix-bar-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: #d7e3f7;
}

.mix-bar-track {
  display: flex;
  height: 18px;
  background: rgba(255, 255, 255, 0.05);
  border-radius: 999px;
  overflow: hidden;
}

.mix-seg {
  display: block;
  height: 100%;
  min-width: 2px;
}

.mix-seg-empty {
  width: 100%;
  background: rgba(255, 255, 255, 0.04);
}

.mix-bar-total {
  text-align: right;
  font-size: 11px;
}

.mix-legend,
.chart-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 14px;
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

.mix-legend-item,
.chart-legend-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  max-width: 100%;
  font-size: 11px;
  color: #d7e3f7;
}

.mix-swatch {
  width: 10px;
  height: 10px;
  border-radius: 2px;
  flex: 0 0 auto;
}

.mix-legend-label {
  line-height: 1.25;
}

.daily-series {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 14px;
}

.daily-chart-card {
  border: 1px solid var(--border);
  background: rgba(21, 32, 51, 0.9);
  border-radius: 14px;
  padding: 12px;
}

.daily-chart-card h3 {
  margin: 0 0 8px;
  font-size: 14px;
  font-weight: 600;
  color: #e8f0ff;
}

.trend-chart {
  width: 100%;
  height: auto;
  display: block;
}

.chart-grid {
  stroke: rgba(255, 255, 255, 0.08);
  stroke-width: 1;
}

.chart-axis {
  fill: var(--muted);
  font-size: 9px;
}

.chart-line {
  vector-effect: non-scaling-stroke;
}

.heatmap-scroll {
  overflow-x: auto;
  padding-bottom: 4px;
}

.share-row {
  display: grid;
  grid-template-columns: minmax(90px, 1.2fr) 1fr 52px 40px;
  gap: 8px;
  align-items: center;
  margin-bottom: 8px;
  font-size: 12px;
}

.share-label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.share-bar {
  height: 10px;
  background: rgba(255, 255, 255, 0.06);
  border-radius: 999px;
  overflow: hidden;
}

.share-bar span {
  display: block;
  height: 100%;
  border-radius: 999px;
}

.share-val {
  text-align: right;
  font-weight: 700;
  color: var(--accent);
}

.share-abs {
  text-align: right;
  font-size: 11px;
}

.tag-scope, .tag-summary {
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 10px;
  line-height: 1.4;
}

.trend-controls {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 10px;
}

.trend-controls select { min-height: 34px; font-size: 12px; }
.trend-controls select:first-child { grid-column: 1 / -1; }

.heatmap { font-size: 11px; }

.heatmap-grid {
  display: grid;
  gap: 2px;
  align-items: stretch;
}

.mix-grid .hm-cell { min-height: 28px; font-size: 9px; color: #e8f4ff; }

.hm-corner { background: transparent; }

.hm-col {
  font-size: 10px;
  color: var(--muted);
  text-align: center;
  align-self: end;
  padding-bottom: 2px;
  overflow: hidden;
  white-space: nowrap;
}

.hm-col-period {
  writing-mode: vertical-rl;
  transform: rotate(180deg);
  max-height: 64px;
  margin: 0 auto;
  white-space: nowrap;
}

.hm-rowlabel {
  font-size: 11px;
  color: #d7e3f7;
  padding-right: 6px;
  align-self: center;
  line-height: 1.2;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  word-break: break-word;
}

.hm-cell {
  min-height: 22px;
  border-radius: 4px;
  border: 1px solid rgba(255, 255, 255, 0.05);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  color: #06120b;
  font-weight: 700;
}

.mix-cell { color: #e8f4ff; font-weight: 600; }

.hm-legend {
  margin-top: 10px;
  font-size: 11px;
  color: var(--muted);
  line-height: 1.4;
}

.stat, .selection, .card {
  border: 1px solid var(--border);
  background: rgba(21, 32, 51, 0.9);
  border-radius: 14px;
  padding: 12px;
}

.stat .value {
  display: block;
  font-size: 22px;
  font-weight: 700;
  color: var(--accent);
}

.stat .label, .muted {
  color: var(--muted);
  font-size: 12px;
}

.stats-note {
  grid-column: 1 / -1;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
  padding: 0 2px 2px;
}

.selection {
  margin-bottom: 12px;
  color: var(--muted);
}

.result-info {
  color: var(--muted);
  font-size: 12px;
  margin: 0 0 10px;
}

.list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.card h3 {
  margin: 0 0 6px;
  font-size: 15px;
  line-height: 1.25;
}

.card a {
  color: var(--text);
  text-decoration: underline;
}

.tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

.tag {
  border: 1px solid rgba(133, 215, 170, 0.35);
  background: rgba(133, 215, 170, 0.12);
  color: #bdf4d1;
  border-radius: 999px;
  padding: 3px 8px;
  font-size: 11px;
}

.badge {
  display: inline-flex;
  border: 1px solid rgba(109, 184, 255, 0.4);
  background: rgba(109, 184, 255, 0.12);
  color: #cde7ff;
  border-radius: 999px;
  padding: 3px 8px;
  font-size: 11px;
  margin: 0 0 8px;
}

.section-title {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  margin: 4px 0 -2px;
}

.evidence {
  border-left: 3px solid var(--accent-2);
  padding-left: 10px;
  color: #d9e6ff;
  margin: 10px 0;
}

.legend {
  position: absolute;
  right: 16px;
  bottom: 16px;
  z-index: 500;
  background: rgba(8, 13, 22, 0.88);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 12px;
  color: var(--text);
  font-size: 12px;
}

.legend-row {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 4px;
}

.legend-row span {
  width: 10px;
  height: 10px;
  display: inline-block;
  border-radius: 999px;
  border: 1px solid #fff;
}

.leaflet-popup-content-wrapper,
.leaflet-popup-tip {
  background: #111a2a;
  color: var(--text);
}

dialog {
  width: min(860px, 90vw);
  max-height: 86vh;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 18px;
  background: var(--panel);
  color: var(--text);
}

dialog::backdrop { background: rgba(0, 0, 0, 0.72); }

.close {
  float: right;
  min-height: 32px;
  border-radius: 10px;
}

.map-tooltip-wrap {
  background: rgba(16, 24, 39, 0.94);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 9px;
  font-size: 12px;
  line-height: 1.35;
  color: #eef4ff;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.28);
}

.map-tooltip-wrap::before { border-top-color: rgba(16, 24, 39, 0.94); }

.map-tooltip-title {
  font-weight: 600;
  color: #ffffff;
}

.map-tooltip-sub {
  color: #b8c5d6;
  font-size: 11px;
  font-weight: 400;
}

@media (max-width: 1100px) {
  .layout {
    grid-template-columns: 1fr;
    grid-template-rows: 42vh auto;
    height: auto;
    min-height: calc(100vh - var(--header-h, 120px));
  }
  .map-wrap { order: 1; min-height: 42vh; }
  .panel-left { order: 2; border-right: none; border-top: 1px solid var(--border); }
  .stats-page .stats { grid-template-columns: 1fr 1fr; }
  .stats-grid { grid-template-columns: 1fr; }
}

@media (max-width: 600px) {
  .stats-page .stats { grid-template-columns: 1fr; }
  .share-row { grid-template-columns: 1fr; gap: 4px; }
  .share-val, .share-abs { text-align: left; }
}

.parent-note {
  margin-top: 8px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent-2);
  border-radius: 6px;
  background: rgba(109, 184, 255, 0.08);
  color: var(--text);
  font-size: 0.85rem;
  line-height: 1.4;
}

.parent-note .link-btn {
  margin-left: 4px;
  padding: 2px 8px;
  font-size: 0.8rem;
  color: var(--accent-2);
  background: transparent;
  border: 1px solid var(--accent-2);
  border-radius: 4px;
  cursor: pointer;
}

.parent-note .link-btn:hover { background: rgba(109, 184, 255, 0.15); }

/* ---- Conflict & Hazards tab ---- */
.control-group { display: inline-flex; gap: 6px; flex-wrap: wrap; }
.control-group[hidden] { display: none; }

.hazard-summary { padding: 12px 14px; }
.hazard-summary h2 { margin: 0 0 8px; font-size: 1rem; }
.hazard-kpis { display: flex; gap: 14px; margin: 6px 0 8px; flex-wrap: wrap; }
.kpi { display: flex; flex-direction: column; }
.kpi-num { font-size: 1.35rem; font-weight: 700; color: var(--accent); line-height: 1.1; }
.kpi-lbl { font-size: 0.72rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.03em; }

.hazard-chart-card { padding: 10px 14px; }
.hazard-chart-card h3 { margin: 4px 0 8px; font-size: 0.9rem; color: var(--text); }
.mini-chart { width: 100%; height: auto; background: var(--panel-2); border-radius: 6px; }
.mini-legend { display: flex; gap: 12px; font-size: 0.75rem; color: var(--muted); margin-bottom: 6px; }
.mini-legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; vertical-align: middle; margin-right: 3px; }

.legend-scale { display: flex; margin-top: 4px; }
.legend-scale span { flex: 1; height: 10px; }
.legend-scale-lbl { display: flex; justify-content: space-between; font-size: 0.7rem; color: var(--muted); }

.hazard-source { margin: 4px 16px 12px; font-size: 0.72rem; color: var(--muted); }
