*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box }

:root {
  --bg:       #f0f4f8;
  --surface:  #ffffff;
  --surface2: #f8fafc;
  --border:   #e2e8f0;
  --border2:  #cbd5e1;
  --text:     #0f172a;
  --text2:    #475569;
  --muted:    #94a3b8;
  --sky:      #0ea5e9;
  --teal:     #0d9488;
  --green:    #10b981;
  --amber:    #f59e0b;
  --orange:   #f97316;
  --red:      #ef4444;
  --purple:   #8b5cf6;
  --mono:     'IBM Plex Mono', monospace;
  --sans:     'Plus Jakarta Sans', sans-serif;
  --topbar-h: 54px;
  --footer-h: 72px;
}

html, body { height: 100%; overflow: hidden; background: var(--bg); color: var(--text); font-family: var(--sans) }
#root { display: flex; flex-direction: column; height: 100vh; overflow: hidden }

/* ════════════════════════════════
   TOP BAR
════════════════════════════════ */
#topbar {
  height: var(--topbar-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 14px;
  gap: 0;
  flex-shrink: 0;
  z-index: 200;
  box-shadow: 0 1px 4px rgba(0,0,0,.06);
}

.brand-mark {
  display: flex;
  align-items: center;
  gap: 10px;
  padding-right: 18px;
  border-right: 1px solid var(--border);
  flex-shrink: 0;
}
.brand-name {
  font-size: 14px;
  font-weight: 800;
  letter-spacing: .1em;
  color: var(--text);
}
.brand-sub {
  font-size: 8px;
  font-family: var(--mono);
  color: var(--muted);
  letter-spacing: .08em;
  margin-top: 1px;
}

/* TILE SWITCHER */
.tile-switcher {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 16px;
}
.ts-track {
  display: flex;
  align-items: center;
  gap: 3px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 40px;
  padding: 3px;
}
.ts-tab {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 5px 13px;
  border-radius: 36px;
  border: none;
  background: transparent;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 10px;
  cursor: pointer;
  transition: all .18s ease;
  white-space: nowrap;
}
.ts-tab:hover { color: var(--text2); background: rgba(0,0,0,.04) }
.ts-tab.active {
  background: var(--sky);
  color: #fff;
  font-weight: 600;
  box-shadow: 0 2px 8px rgba(14,165,233,.35);
}
.ts-dot {
  width: 5px; height: 5px;
  border-radius: 50%;
  background: currentColor;
  opacity: 0.6;
}
.ts-tab.active .ts-dot { opacity: 1 }
.ts-dir {
  font-size: 8px;
  background: rgba(255,255,255,.2);
  padding: 1px 4px;
  border-radius: 3px;
}
.ts-tab:not(.active) .ts-dir {
  background: rgba(0,0,0,.06);
  color: var(--text2);
}

/* TOP CONTROLS */
.top-controls {
  display: flex;
  align-items: center;
  gap: 5px;
  padding-left: 14px;
  border-left: 1px solid var(--border);
  flex-shrink: 0;
}
.chip-toggle input { display: none }
.chip {
  padding: 4px 9px;
  border-radius: 20px;
  border: 1px solid var(--border2);
  background: var(--surface);
  color: var(--muted);
  font-family: var(--mono);
  font-size: 8.5px;
  cursor: pointer;
  transition: all .15s;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  user-select: none;
  white-space: nowrap;
}
.chip-toggle input:checked + .c-sky    { color: var(--sky);    border-color: rgba(14,165,233,.5);  background: rgba(14,165,233,.08) }
.chip-toggle input:checked + .c-teal   { color: var(--teal);   border-color: rgba(13,148,136,.5);  background: rgba(13,148,136,.08) }
.chip-toggle input:checked + .c-amber  { color: var(--amber);  border-color: rgba(245,158,11,.5);  background: rgba(245,158,11,.08) }
.chip-toggle input:checked + .c-red    { color: var(--red);    border-color: rgba(239,68,68,.5);   background: rgba(239,68,68,.08)  }
.chip-toggle input:checked + .c-purple { color: var(--purple); border-color: rgba(139,92,246,.5);  background: rgba(139,92,246,.08) }
.chip:hover { border-color: var(--text2); color: var(--text2) }

/* VIEW MODE TOGGLE */
.view-mode-group {
  display: flex;
  border: 1px solid var(--border2);
  border-radius: 6px;
  overflow: hidden;
  margin-left: 3px;
}
.vm-btn {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  border: none;
  background: transparent;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 9px;
  cursor: pointer;
  transition: all .12s;
  border-right: 1px solid var(--border);
  font-weight: 500;
}
.vm-btn:last-child { border-right: none }
.vm-btn:hover { color: var(--text); background: var(--bg) }
.vm-btn.active { background: var(--purple); color: #fff; box-shadow: inset 0 1px 2px rgba(0,0,0,.15) }

.bm-group { display: flex; border: 1px solid var(--border2); border-radius: 6px; overflow: hidden; margin-left: 3px }
.bm {
  padding: 4px 8px;
  border: none;
  background: transparent;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 9px;
  cursor: pointer;
  transition: all .12s;
  border-right: 1px solid var(--border);
}
.bm:last-child { border-right: none }
.bm:hover { color: var(--text); background: var(--bg) }
.bm.active { background: var(--sky); color: #fff }

/* ════════════════════════════════
   BODY
════════════════════════════════ */
#body-wrap {
  flex: 1;
  display: flex;
  overflow: hidden;
  min-height: 0;
}

/* ════════════════════════════════
   LEFT PANEL
════════════════════════════════ */
#left-panel {
  width: 272px;
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  z-index: 10;
}
#left-panel::-webkit-scrollbar { width: 3px }
#left-panel::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px }

/* ════════════════════════════════
   RIGHT PANEL
════════════════════════════════ */
#right-panel {
  width: 240px;
  flex-shrink: 0;
  background: var(--surface);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  z-index: 10;
}
#right-panel::-webkit-scrollbar { width: 3px }
#right-panel::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px }

.lp-section { border-bottom: 1px solid var(--border); padding: 11px 12px }

.lp-head {
  display: flex;
  align-items: center;
  gap: 7px;
  margin-bottom: 10px;
}
.lp-icon-dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  flex-shrink: 0;
}
.lp-title {
  font-family: var(--mono);
  font-size: 8px;
  font-weight: 600;
  letter-spacing: .14em;
  color: var(--muted);
  flex: 1;
  text-transform: uppercase;
}
.lp-count {
  font-family: var(--mono);
  font-size: 10px;
  color: #fff;
  background: var(--red);
  border-radius: 10px;
  padding: 1px 7px;
  font-weight: 600;
}
.lp-empty {
  font-family: var(--mono);
  font-size: 10px;
  color: var(--muted);
  padding: 10px 0;
  text-align: center;
  font-style: italic;
}

/* ROAD ITEMS */
.road-item {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 7px 8px;
  border-radius: 7px;
  border: 1px solid rgba(239,68,68,.18);
  background: rgba(239,68,68,.04);
  margin-bottom: 4px;
  cursor: pointer;
  transition: all .15s;
}
.road-item:hover { background: rgba(239,68,68,.09); border-color: rgba(239,68,68,.35); transform: translateX(2px) }
.road-prio {
  width: 18px; height: 18px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 8px; font-weight: 700;
  flex-shrink: 0;
  font-family: var(--mono);
  color: #fff;
}
.prio-high   { background: var(--red) }
.prio-med    { background: var(--orange) }
.prio-low    { background: var(--amber); color: var(--text) }
.road-info   { flex: 1; min-width: 0 }
.road-name   { font-family: var(--mono); font-size: 10px; font-weight: 600; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis }
.road-meta   { font-family: var(--mono); font-size: 8px; color: var(--muted); margin-top: 2px }

/* BUILDING LEGEND */
.bld-legend { display: flex; flex-direction: column; gap: 8px }
.bld-legend-item {
  display: flex;
  align-items: flex-start;
  gap: 10px;
}
.bld-swatch {
  width: 14px;
  height: 14px;
  border-radius: 3px;
  flex-shrink: 0;
  margin-top: 2px;
}
.bld-leg-label {
  font-family: var(--mono);
  font-size: 9px;
  font-weight: 700;
  letter-spacing: .08em;
  color: var(--text);
  margin-bottom: 2px;
}
.bld-leg-desc {
  font-family: var(--mono);
  font-size: 8px;
  color: var(--muted);
  line-height: 1.5;
}

/* BUILDING LIST ITEMS */
.bld-item {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 6px 8px;
  border-radius: 7px;
  border: 1px solid rgba(239,68,68,.18);
  background: rgba(239,68,68,.04);
  margin-bottom: 4px;
  cursor: pointer;
  transition: all .15s;
}
.bld-item:hover { background: rgba(239,68,68,.09); border-color: rgba(239,68,68,.35); transform: translateX(2px) }
.bld-item.risk {
  border-color: rgba(245,158,11,.2);
  background: rgba(245,158,11,.04);
}
.bld-item.risk:hover { background: rgba(245,158,11,.09); border-color: rgba(245,158,11,.35) }
.bld-dot {
  width: 8px; height: 8px;
  border-radius: 2px;
  flex-shrink: 0;
  margin-top: 3px;
}
.bld-info { flex: 1; min-width: 0 }
.bld-id   { font-family: var(--mono); font-size: 9px; font-weight: 600; color: var(--text) }
.bld-meta { font-family: var(--mono); font-size: 7.5px; color: var(--muted); margin-top: 1px }

/* 3D HELP */
.help-rows { display: flex; flex-direction: column; gap: 5px }
.help-row { display: flex; align-items: center; gap: 8px }
.help-key {
  font-family: var(--mono); font-size: 8px; font-weight: 600;
  background: var(--bg); border: 1px solid var(--border2);
  border-radius: 3px; padding: 1px 6px; color: var(--text2);
  white-space: nowrap; flex-shrink: 0;
}
.help-val { font-family: var(--mono); font-size: 8px; color: var(--muted) }

/* HISTORICAL */
.hist-card {
  margin-bottom: 7px;
  border-radius: 8px;
  padding: 9px 10px 9px 13px;
  border: 1px solid transparent;
  position: relative;
  overflow: hidden;
}
.hist-card::before {
  content: '';
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 4px;
  border-radius: 8px 0 0 8px;
}
.s-extreme { background: #fff5f5; border-color: #fecaca }
.s-extreme::before { background: #ef4444 }
.s-high    { background: #fff7ed; border-color: #fed7aa }
.s-high::before    { background: #f97316 }
.s-med     { background: #fffbeb; border-color: #fde68a }
.s-med::before     { background: #f59e0b }
.s-low     { background: #f0fdf4; border-color: #bbf7d0 }
.s-low::before     { background: #10b981 }

.hist-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 3px }
.hist-date { font-family: var(--mono); font-size: 8px; color: var(--muted); letter-spacing: .06em }
.hist-badge {
  font-family: var(--mono); font-size: 7px; font-weight: 700;
  padding: 1px 5px; border-radius: 3px; letter-spacing: .05em;
}
.b-extreme { background: #fee2e2; color: #b91c1c }
.b-high    { background: #ffedd5; color: #c2410c }
.b-med     { background: #fef3c7; color: #92400e }
.b-low     { background: #d1fae5; color: #065f46 }

.hist-name { font-size: 11px; font-weight: 700; color: var(--text); margin-bottom: 3px }
.hist-body { font-family: var(--mono); font-size: 8.5px; color: var(--text2); line-height: 1.6; margin-bottom: 6px }
.hist-chips { display: flex; flex-wrap: wrap; gap: 3px }
.hist-chips span {
  font-family: var(--mono); font-size: 7.5px; color: var(--text2);
  background: rgba(0,0,0,.05); border: 1px solid var(--border);
  padding: 1px 5px; border-radius: 3px;
}

/* STATS */
.stats-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px }
.stat-cell {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 8px 10px;
}
.stat-val { font-family: var(--mono); font-size: 20px; font-weight: 600; line-height: 1 }
.stat-val.sky    { color: var(--sky) }
.stat-val.amber  { color: var(--amber) }
.stat-val.red    { color: var(--red) }
.stat-val.teal   { color: var(--teal) }
.stat-key { font-family: var(--mono); font-size: 8px; color: var(--muted); letter-spacing: .05em; margin-top: 3px; text-transform: uppercase }

/* ════════════════════════════════
   MAP WRAP + OVERLAY
════════════════════════════════ */
#map-wrap {
  flex: 1;
  position: relative;
  overflow: hidden;
}
#map { width: 100%; height: 100% }

/* 3D CANVAS */
#canvas-3d {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: none;
  cursor: grab;
  background: #0d1520;
}
#canvas-3d:active { cursor: grabbing }
#canvas-3d.visible { display: block }

/* 3D CONTROLS HINT */
#controls-hint {
  position: absolute;
  bottom: 14px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0,0,0,.6);
  backdrop-filter: blur(8px);
  border: 1px solid rgba(255,255,255,.12);
  border-radius: 20px;
  padding: 5px 14px;
  font-family: var(--mono);
  font-size: 10px;
  color: rgba(255,255,255,.75);
  pointer-events: none;
  z-index: 50;
  white-space: nowrap;
  transition: opacity .3s;
}
#controls-hint.hidden { opacity: 0 }

/* LOADING OVERLAY */
#load-overlay {
  position: absolute;
  inset: 0;
  background: rgba(248,250,252,.88);
  backdrop-filter: blur(6px);
  z-index: 500;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity .25s;
}
#load-overlay.hidden { opacity: 0; pointer-events: none }

.load-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
}
.load-spinner {
  position: relative;
  width: 64px; height: 64px;
  display: flex; align-items: center; justify-content: center;
}
.spin-ring {
  position: absolute;
  width: 60px; height: 60px;
  border-radius: 50%;
  border: 3px solid var(--border);
  border-top-color: var(--sky);
  border-right-color: var(--teal);
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg) } }

.spin-wave {
  font-size: 18px;
  animation: wave-pulse 1.4s ease-in-out infinite;
  color: var(--sky);
  letter-spacing: -4px;
}
@keyframes wave-pulse {
  0%, 100% { opacity: 0.3; transform: scale(0.9) }
  50%       { opacity: 1;   transform: scale(1.1) }
}

.load-caption {
  font-family: var(--mono);
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  text-align: center;
  max-width: 260px;
  line-height: 1.5;
}
.load-sub {
  font-family: var(--mono);
  font-size: 10px;
  color: var(--muted);
}
.load-dots::after {
  content: '';
  animation: dots 1.5s steps(4, end) infinite;
}
@keyframes dots {
  0%   { content: '' }
  25%  { content: '.' }
  50%  { content: '..' }
  75%  { content: '...' }
  100% { content: '' }
}

/* ════════════════════════════════
   FOOTER (compact)
════════════════════════════════ */
#footer {
  height: var(--footer-h);
  background: var(--surface);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
  z-index: 100;
  box-shadow: 0 -1px 4px rgba(0,0,0,.05);
}
#footer-content {
  height: 100%;
  display: flex;
  align-items: center;
  padding: 0 16px;
  gap: 16px;
}

/* DEPTH READOUT */
.foot-left {
  display: flex;
  align-items: baseline;
  gap: 3px;
  flex-shrink: 0;
  padding-right: 14px;
  border-right: 1px solid var(--border);
}
.depth-num {
  font-family: var(--mono);
  font-size: 32px;
  font-weight: 600;
  color: var(--sky);
  transition: color .3s;
  line-height: 1;
}
.depth-unit {
  font-family: var(--mono);
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 2px;
}
.rp-pill {
  font-family: var(--mono);
  font-size: 8px;
  background: rgba(14,165,233,.1);
  color: var(--sky);
  border: 1px solid rgba(14,165,233,.3);
  border-radius: 10px;
  padding: 2px 6px;
  white-space: nowrap;
  margin-left: 4px;
  align-self: center;
}

/* SLIDER ZONE */
.foot-center {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 0 4px;
}

.scale-labels {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.scale-labels span:first-child {
  font-family: var(--mono);
  font-size: 7.5px;
  color: var(--muted);
  letter-spacing: .1em;
  font-weight: 600;
}
.scale-labels span:last-child {
  font-family: var(--mono);
  font-size: 8px;
  color: var(--text2);
  font-weight: 500;
}

/* SLIDER */
.slider-row {
  position: relative;
  height: 20px;
  display: flex;
  align-items: center;
}
.color-track {
  position: absolute;
  left: 0; right: 0;
  height: 8px;
  border-radius: 4px;
  overflow: hidden;
  background: linear-gradient(90deg,
    #3b82f6 0%, #06b6d4 14.28%, #10b981 28.57%, #f59e0b 42.85%,
    #f97316 57.14%, #ef4444 71.42%, #dc2626 85.71%, #7f1d1d 100%);
  pointer-events: none;
}
.ct-fill {
  position: absolute;
  left: 0; top: 0; bottom: 0;
  background: rgba(255,255,255,.45);
  transition: right .2s;
}

input[type=range] {
  position: relative;
  width: 100%;
  appearance: none;
  height: 8px;
  background: transparent;
  cursor: pointer;
  outline: none;
  z-index: 2;
}
input[type=range]::-webkit-slider-thumb {
  appearance: none;
  width: 22px; height: 22px;
  border-radius: 50%;
  background: #fff;
  border: 3px solid var(--sky);
  box-shadow: 0 1px 6px rgba(0,0,0,.2), 0 0 0 4px rgba(14,165,233,.15);
  cursor: pointer;
  transition: box-shadow .15s, border-color .3s;
}
input[type=range]::-webkit-slider-thumb:hover {
  box-shadow: 0 1px 6px rgba(0,0,0,.2), 0 0 0 7px rgba(14,165,233,.2);
}

/* COLOR SCALE */
.color-scale {
  display: flex;
  height: 18px;
  border-radius: 4px;
  overflow: hidden;
  border: 1px solid var(--border);
}
.cs-seg {
  flex: 1;
  background: var(--c);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: flex .25s ease;
  cursor: pointer;
  position: relative;
}
.cs-seg span {
  font-family: var(--mono);
  font-size: 7px;
  color: rgba(0,0,0,.65);
  font-weight: 600;
  white-space: nowrap;
  text-shadow: 0 0 3px rgba(255,255,255,.5);
}
.cs-seg.active-seg {
  flex: 2.2;
  outline: 2px solid var(--text);
  outline-offset: -1px;
  z-index: 1;
}
.cs-seg[data-idx="5"] span,
.cs-seg[data-idx="6"] span,
.cs-seg[data-idx="7"] span { color: rgba(255,255,255,.8) }

/* FOOT RIGHT */
.foot-right {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 6px;
  padding-left: 14px;
  border-left: 1px solid var(--border);
  font-family: var(--mono);
  font-size: 9px;
  color: var(--muted);
  white-space: nowrap;
}
.foot-sep { color: var(--border2) }

/* ════════════════════════════════
   LEAFLET OVERRIDES
════════════════════════════════ */
.leaflet-container { background: #e8eff6 }
.leaflet-control-zoom a {
  background: var(--surface) !important;
  color: var(--text) !important;
  border-color: var(--border2) !important;
  font-weight: 600 !important;
}
.leaflet-control-zoom a:hover { background: var(--bg) !important }
.leaflet-popup-content-wrapper {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border2);
  border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0,0,0,.15);
}
.leaflet-popup-tip { background: var(--surface) }
.leaflet-popup-content { font-family: var(--mono); font-size: 11px; line-height: 1.8; color: var(--text) }

/* FLOOD ARROW ICON */
.flood-arrow-icon {
  background: none !important;
  border: none !important;
  box-shadow: none !important;
}

@keyframes flood-bob {
  0%, 100% { transform: translateY(0px);   opacity: 0.85; }
  50%       { transform: translateY(-3px);  opacity: 1.0;  }
}
.flood-arrow-icon svg {
  animation: flood-bob 1.8s ease-in-out infinite;
  filter: drop-shadow(0 1px 2px rgba(0,0,0,0.25));
}

/* 3D TOOLTIP */
#tooltip-3d {
  position: absolute;
  pointer-events: none;
  z-index: 400;
  background: rgba(10,20,35,.92);
  backdrop-filter: blur(8px);
  border: 1px solid rgba(255,255,255,.12);
  border-radius: 9px;
  padding: 8px 12px;
  font-family: var(--mono);
  font-size: 10px;
  color: #e2e8f0;
  line-height: 1.8;
  display: none;
  min-width: 150px;
  box-shadow: 0 8px 32px rgba(0,0,0,.4);
}
#tooltip-3d .tt-status {
  font-size: 9px;
  font-weight: 700;
  letter-spacing: .1em;
  margin-bottom: 2px;
}
#tooltip-3d .tt-status.affected { color: #ef4444 }
#tooltip-3d .tt-status.risk     { color: #f59e0b }
#tooltip-3d .tt-status.safe     { color: #10b981 }