:root {
  --bg: #071520;
  --bg2: #0f2a38;
  --panel: #0e2432;
  --panel-alt: #123143;
  --line: #21495f;
  --text: #e6f4ff;
  --muted: #a7c5d8;
  --accent: #4ed0ff;
  --accent-soft: #8be2ff;
  --normal: #58d39b;
  --warning: #f4b343;
  --major: #ef6461;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  color: var(--text);
  font-family: "Space Grotesk", "Trebuchet MS", sans-serif;
  background:
    radial-gradient(900px 600px at 8% -8%, #1c5671 0%, transparent 55%),
    radial-gradient(1200px 800px at 92% 8%, #173e54 0%, transparent 58%),
    linear-gradient(170deg, var(--bg2), var(--bg));
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 14px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(90deg, #0a2230, #123042);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.logo {
  width: 48px;
  height: 48px;
}

.title-block h1 {
  margin: 0;
  font-size: 1.15rem;
  letter-spacing: 0.01em;
}

.title-block p {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 0.8rem;
}

.topbar-actions {
  display: flex;
  gap: 8px;
}

.btn {
  border: 1px solid transparent;
  border-radius: 9px;
  cursor: pointer;
  padding: 8px 11px;
  font: inherit;
  font-size: 0.82rem;
  font-weight: 600;
  color: #032231;
  background: linear-gradient(145deg, var(--accent-soft), var(--accent));
}

.btn:hover {
  filter: brightness(1.05);
}

.btn.secondary {
  background: #204459;
  color: var(--text);
  border-color: #2f5f76;
}

.btn.ghost {
  background: transparent;
  color: var(--muted);
  border-color: #2b5a74;
}

.btn.ghost.active,
.btn.ghost:hover {
  color: var(--text);
  background: #1f4256;
}

.app-grid {
  display: grid;
  grid-template-columns: 1.15fr 0.85fr;
  grid-template-rows: auto minmax(360px, 1fr);
  gap: 14px;
  padding: 14px;
  height: calc(100% - 78px);
}

.panel {
  border: 1px solid var(--line);
  border-radius: 14px;
  background: linear-gradient(170deg, rgba(14, 36, 50, 0.97), rgba(12, 30, 43, 0.96));
  box-shadow: 0 16px 36px rgba(1, 12, 20, 0.32);
}

.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  padding: 12px 14px 0;
}

.panel-head h2 {
  margin: 0;
  font-size: 1.03rem;
  color: var(--accent-soft);
}

.panel-subtitle,
.tiny-text {
  color: var(--muted);
  font-size: 0.76rem;
}

.metrics {
  grid-column: 1 / 3;
  padding: 0 12px 12px;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(150px, 1fr));
  gap: 10px;
  padding: 10px 2px 0;
}

.metric-card {
  border: 1px solid #2a556f;
  background: linear-gradient(150deg, #123044, #173a50);
  border-radius: 10px;
  padding: 10px;
}

.metric-card h3 {
  margin: 0;
  font-size: 0.74rem;
  color: #b8d6e8;
}

.metric-card p {
  margin: 6px 0 0;
  font-size: 1.35rem;
  font-weight: 700;
  letter-spacing: 0.01em;
}

.map-panel {
  grid-column: 1 / 2;
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
  min-height: 0;
  overflow: hidden;
}

.map-sidebar {
  border-right: 1px solid var(--line);
  padding: 10px;
  overflow-y: auto;
  background: linear-gradient(180deg, #102d3f, #0d2432);
}

.control-card {
  border: 1px solid #295873;
  border-radius: 10px;
  padding: 9px;
  margin-bottom: 10px;
  background: rgba(16, 47, 66, 0.75);
}

.control-card h3 {
  margin: 0 0 8px;
  font-size: 0.84rem;
  color: var(--accent-soft);
}

.control-card label {
  display: block;
  margin-bottom: 5px;
  font-size: 0.8rem;
  color: #cfe6f5;
}

.control-card input[type="checkbox"] {
  margin-right: 6px;
}

.control-card input[type="text"],
.control-card select {
  width: 100%;
  border-radius: 8px;
  border: 1px solid #35708d;
  background: #0d2230;
  color: var(--text);
  padding: 8px;
  font: inherit;
  font-size: 0.82rem;
}

.inline-actions {
  display: flex;
  gap: 8px;
  margin-top: 8px;
}

.status {
  font-size: 0.78rem;
  border-radius: 8px;
  border: 1px solid #2e5f78;
  background: rgba(18, 54, 74, 0.62);
  color: #d8edfb;
  padding: 8px;
}

.status.warn {
  border-color: #81621f;
  color: #ffe3a6;
}

.status.error {
  border-color: #8b3d3b;
  color: #ffd3d1;
}

.map-stage {
  position: relative;
  min-height: 0;
}

#map {
  width: 100%;
  height: 100%;
  min-height: 420px;
}

.map-panel.fullscreen {
  position: fixed;
  inset: 8px;
  z-index: 5000;
  grid-template-columns: 300px minmax(0, 1fr);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.45);
}

.map-panel.fullscreen #map {
  min-height: calc(100vh - 16px);
}

.map-panel:not(.fullscreen) #toggleMapFullscreenInline {
  display: none;
}

.selected-points {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  min-height: 22px;
}

.point-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border-radius: 999px;
  padding: 4px 8px;
  border: 1px solid #3c7190;
  background: rgba(21, 63, 86, 0.7);
  font-size: 0.72rem;
  line-height: 1.1;
}

.point-pill button {
  border: none;
  background: transparent;
  color: #b6d9ee;
  cursor: pointer;
  font: inherit;
  padding: 0;
}

.legend {
  position: absolute;
  border: 1px solid #2f5f78;
  border-radius: 10px;
  background: rgba(7, 24, 35, 0.92);
  backdrop-filter: blur(4px);
  padding: 9px;
  font-size: 0.72rem;
  line-height: 1.25;
}

.legend h4 {
  margin: 0 0 8px;
  font-size: 0.76rem;
  color: var(--accent-soft);
}

.legend h5 {
  margin: 0 0 6px;
  font-size: 0.72rem;
  color: #ffdca4;
}

.legend.local-legend {
  left: 10px;
  bottom: 10px;
  width: 210px;
  z-index: 8;
}

.legend.regional-legend {
  right: 10px;
  bottom: 10px;
  width: 235px;
  max-height: 54vh;
  overflow-y: auto;
  z-index: 9;
}

.hidden {
  display: none !important;
}

.legend-scroll {
  max-height: 48vh;
  overflow-y: auto;
}

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

.legend-row img {
  width: 18px;
  height: 13px;
  border: 1px solid #2f5f78;
}

.legend-section {
  border-top: 1px solid #274e62;
  margin-top: 8px;
  padding-top: 8px;
}

.legend-section:first-of-type {
  border-top: none;
  margin-top: 0;
  padding-top: 0;
}

.swatch {
  width: 13px;
  height: 13px;
  border-radius: 3px;
  display: inline-block;
}

.status-normal {
  background: var(--normal);
}

.status-warning {
  background: var(--warning);
}

.status-major {
  background: var(--major);
}

.marker-square {
  border: 2px solid #0c2130;
  background: #7cc9f2;
}

.marker-circle {
  border-radius: 999px;
  border: 2px solid #0c2130;
  background: #ffffff;
}

.gradient-road,
.gradient-bldg {
  background: linear-gradient(90deg, #ffffff, #ffe66d, #ff9f1a, #d7263d);
}

.rain {
  background: #2f80ff;
}

.nwm {
  height: 0;
  width: 16px;
  border-top: 3px solid #6ebcf2;
  border-radius: 0;
  background: transparent;
}

.hurricane-dot {
  width: 16px;
  height: 16px;
  border-radius: 999px;
  border: 1px solid #d8ecfa;
  display: inline-flex;
  justify-content: center;
  align-items: center;
  font-size: 0.62rem;
  font-weight: 700;
  background: #151515;
}

.hurricane-line {
  width: 30px;
  height: 0;
  border-top: 3px solid #fff;
}

.hurricane-line.forecast {
  border-top-color: #161616;
}

.hurricane-line.magenta {
  border-top-color: #f276f0;
}

.hurricane-line.cyan {
  border-top-color: #31b8ff;
}

.hurricane-line.h1 {
  border-top-color: #6fe80f;
}

.hurricane-line.h2 {
  border-top-color: #d6e017;
}

.hurricane-line.h3 {
  border-top-color: #f4a31a;
}

.hurricane-line.h4 {
  border-top-color: #ff1212;
}

.hurricane-line.h5 {
  border-top-color: #161616;
}

.chart-panel {
  grid-column: 2 / 3;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.chart-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

#chart {
  flex: 1;
  min-height: 420px;
}

.maplibregl-popup-content {
  border-radius: 10px;
  background: #0d2432;
  color: var(--text);
  border: 1px solid #2d5f79;
  font-size: 0.78rem;
  font-family: "Space Grotesk", "Trebuchet MS", sans-serif;
  max-width: 280px;
}

.maplibregl-popup-tip {
  border-top-color: #0d2432 !important;
  border-bottom-color: #0d2432 !important;
}

.maplibregl-ctrl-group {
  border: 1px solid #2f5f79;
  background: #0f2b3c;
}

.maplibregl-ctrl button {
  filter: invert(0.87) hue-rotate(170deg) saturate(0.65);
}

@media (max-width: 1320px) {
  .app-grid {
    grid-template-columns: 1fr;
    grid-template-rows: auto minmax(360px, 1fr) minmax(340px, 1fr);
    height: auto;
    min-height: calc(100% - 78px);
  }

  .metrics {
    grid-column: 1 / 2;
  }

  .map-panel {
    grid-column: 1 / 2;
  }

  .chart-panel {
    grid-column: 1 / 2;
  }
}

@media (max-width: 980px) {
  .topbar {
    flex-direction: column;
    align-items: stretch;
  }

  .topbar-actions {
    justify-content: flex-end;
  }

  .metric-grid {
    grid-template-columns: repeat(2, minmax(140px, 1fr));
  }

  .map-panel {
    grid-template-columns: 1fr;
  }

  .map-sidebar {
    border-right: none;
    border-bottom: 1px solid var(--line);
    max-height: 230px;
  }

  #map {
    min-height: 390px;
  }

  #chart {
    min-height: 360px;
  }

  .legend.local-legend {
    width: 180px;
  }
}
