:root {
  --ink: #172033;
  --muted: #64748b;
  --paper: #f7f9fc;
  --panel: #ffffff;
  --line: #d8e1ee;
  --blue: #0ea5e9;
  --green: #0f766e;
  --purple: #7c3aed;
  --orange: #f97316;
  --red: #dc2626;
  --charcoal: #243044;
}

* { box-sizing: border-box; }

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

body {
  display: flex;
  flex-direction: column;
}

.app-header {
  min-height: 82px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 16px 22px;
  background: #ffffff;
  border-bottom: 1px solid var(--line);
}

.app-header h1 {
  margin: 0;
  font-size: 24px;
  line-height: 1.1;
  letter-spacing: 0;
}

.app-header p {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.pack-status {
  min-width: 250px;
  border: 1px solid var(--line);
  background: #f8fafc;
  padding: 10px 12px;
  font: 12px ui-monospace, SFMono-Regular, Menlo, monospace;
  color: var(--charcoal);
}

.layout {
  flex: 1;
  display: grid;
  grid-template-columns: 330px minmax(0, 1fr);
  min-height: 0;
}

.sidebar {
  border-right: 1px solid var(--line);
  background: #edf3f8;
  padding: 16px;
  overflow: auto;
}

.panel,
.analysis-panel,
.map-stage {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 6px;
}

.panel {
  padding: 14px;
  margin-bottom: 14px;
}

.panel h2,
.map-head h2,
.panel-title h2 {
  margin: 0;
  font-size: 14px;
  line-height: 1.2;
}

.meta-list {
  margin: 12px 0 0;
}

.meta-list div {
  display: grid;
  grid-template-columns: 76px minmax(0, 1fr);
  gap: 12px;
  padding: 8px 0;
  border-bottom: 1px solid #e7edf5;
}

.meta-list div:last-child {
  border-bottom: 0;
}

dt {
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
}

dd {
  margin: 0;
  font-size: 13px;
  font-weight: 650;
}

.scenario-list {
  display: grid;
  gap: 8px;
  margin: 12px 0;
}

.scenario-btn {
  width: 100%;
  border: 1px solid var(--line);
  border-left-width: 5px;
  border-radius: 5px;
  background: #fff;
  padding: 10px;
  text-align: left;
  cursor: pointer;
}

.scenario-btn strong {
  display: block;
  font-size: 13px;
}

.scenario-btn span {
  display: block;
  margin-top: 3px;
  font-size: 11px;
  color: var(--muted);
}

.scenario-btn.active {
  box-shadow: 0 0 0 2px rgba(14, 165, 233, 0.18);
  background: #f8fbff;
}

.outcome-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-top: 12px;
}

.outcome-btn {
  min-height: 58px;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: #fff;
  padding: 8px;
  text-align: left;
  cursor: pointer;
}

.outcome-btn strong {
  display: block;
  font-size: 12px;
}

.outcome-btn span {
  display: block;
  margin-top: 3px;
  font-size: 11px;
  color: var(--muted);
}

.outcome-btn.active {
  border-color: #111827;
  background: #f8fafc;
  box-shadow: inset 0 0 0 1px #111827;
}

.outcome-readout {
  margin-top: 10px;
  border: 1px solid #dbe5f0;
  border-left: 5px solid var(--charcoal);
  border-radius: 5px;
  background: #fff;
  padding: 9px;
}

.outcome-readout strong,
.outcome-readout span {
  display: block;
}

.outcome-readout strong {
  font-size: 12px;
}

.outcome-readout span {
  margin-top: 4px;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.35;
}

.outcome-readout .is-triggered {
  color: var(--green);
  font-weight: 800;
}

.outcome-readout .is-muted {
  color: #9a3412;
}

.field {
  display: grid;
  gap: 6px;
  margin-top: 12px;
  font-size: 12px;
  color: var(--muted);
}

select,
button {
  font: inherit;
}

select {
  height: 36px;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: #fff;
  padding: 0 9px;
}

.primary-btn {
  margin-top: 12px;
  width: 100%;
  height: 38px;
  border: 0;
  border-radius: 5px;
  background: var(--charcoal);
  color: white;
  cursor: pointer;
}

.basis-card {
  margin-top: 10px;
  border: 1px solid #dbe5f0;
  border-left: 5px solid var(--purple);
  border-radius: 5px;
  background: #fff;
  padding: 10px;
}

.basis-card .basis-kicker {
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 10px;
  text-transform: uppercase;
  font-weight: 800;
}

.basis-card strong {
  display: block;
  font-size: 12px;
  line-height: 1.3;
}

.basis-card p {
  margin: 7px 0 0;
  color: #334155;
  font-size: 11px;
  line-height: 1.4;
}

.basis-card dl {
  margin: 8px 0 0;
  display: grid;
  gap: 6px;
}

.basis-card dl div {
  display: grid;
  grid-template-columns: 64px minmax(0, 1fr);
  gap: 8px;
}

.basis-card dt {
  font-size: 10px;
}

.basis-card dd {
  font-size: 11px;
  font-weight: 500;
  line-height: 1.35;
}

.layer-list {
  display: grid;
  gap: 8px;
  margin-top: 12px;
}

.layer-list label {
  min-height: 34px;
  display: flex;
  align-items: center;
  gap: 9px;
  border: 1px solid #dbe5f0;
  border-radius: 5px;
  background: #fff;
  padding: 8px 9px;
  color: #334155;
  font-size: 12px;
  cursor: pointer;
}

.layer-list input {
  width: 16px;
  height: 16px;
  margin: 0;
  accent-color: var(--charcoal);
}

.qa-list {
  margin: 10px 0 0;
  padding: 0;
  list-style: none;
  display: grid;
  gap: 8px;
}

.qa-list li {
  font-size: 12px;
  color: #334155;
  border-left: 4px solid var(--orange);
  padding-left: 9px;
}

.workspace {
  padding: 16px;
  overflow: auto;
}

.summary-strip {
  display: grid;
  grid-template-columns: repeat(5, minmax(120px, 1fr));
  gap: 12px;
  margin-bottom: 14px;
}

.decision-strip {
  display: grid;
  grid-template-columns: repeat(3, minmax(180px, 1fr));
  gap: 12px;
  margin-bottom: 14px;
}

.decision-card {
  min-height: 82px;
  border: 1px solid var(--line);
  border-left: 6px solid var(--blue);
  border-radius: 6px;
  background: #ffffff;
  padding: 12px;
}

.decision-card.terrain {
  border-left-color: #f59e0b;
}

.decision-card.action {
  border-left-color: var(--green);
}

.decision-card.action.hot {
  border-left-color: var(--red);
  background: #fff7f7;
}

.decision-card strong {
  display: block;
  font-size: 18px;
  line-height: 1.15;
}

.decision-card span {
  display: block;
  margin-top: 6px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.metric {
  min-height: 78px;
  padding: 12px;
  color: white;
  border-radius: 6px;
  overflow: hidden;
}

.metric strong {
  display: block;
  font-size: 24px;
  line-height: 1.1;
}

.metric span {
  display: block;
  margin-top: 6px;
  font-size: 11px;
  text-transform: uppercase;
  opacity: 0.92;
}

.map-stage {
  padding: 14px;
}

.map-head,
.panel-title {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: flex-start;
  margin-bottom: 10px;
}

.map-head p,
.panel-title span {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.confidence-pill {
  border: 1px solid var(--line);
  background: #f8fafc;
  color: var(--charcoal);
  font-size: 12px;
  padding: 7px 10px;
  border-radius: 999px;
  white-space: nowrap;
}

#hydro-map {
  width: 100%;
  height: min(66vh, 760px);
  min-height: 520px;
  display: block;
  border: 1px solid #cbd5e1;
  border-radius: 4px;
  background: #d9efe3;
  overflow: hidden;
}

.leaflet-container {
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

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

.popup-title {
  font-weight: 800;
  margin-bottom: 4px;
}

.popup-meta {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.gauge-marker,
.receptor-marker {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  color: #fff;
  display: grid;
  place-items: center;
  font-size: 13px;
  font-weight: 900;
  border: 2px solid #fff;
  box-shadow: 0 2px 9px rgba(15, 23, 42, 0.35);
}

.gauge-marker.rain {
  background: var(--blue);
}

.gauge-marker.river {
  background: var(--green);
}

.receptor-marker {
  background: var(--charcoal);
}

.receptor-marker.hot {
  background: var(--red);
}

.pulse-marker {
  width: var(--pulse-size);
  height: var(--pulse-size);
  position: relative;
  border-radius: 50%;
  background: color-mix(in srgb, var(--pulse-color) 78%, white 22%);
  border: 3px solid #ffffff;
  box-shadow: 0 0 0 2px rgba(15, 23, 42, 0.34), 0 8px 22px rgba(15, 23, 42, 0.35);
}

.pulse-marker::before,
.pulse-marker::after {
  content: "";
  position: absolute;
  inset: -9px;
  border-radius: 50%;
  border: 3px solid var(--pulse-color);
  opacity: 0.72;
  animation: pulse-ring 1.15s ease-out infinite;
}

.pulse-marker::after {
  animation-delay: 0.38s;
}

.pulse-marker span {
  position: absolute;
  inset: 32%;
  border-radius: 50%;
  background: #ffffff;
}

@keyframes pulse-ring {
  from {
    transform: scale(0.55);
    opacity: 0.78;
  }

  to {
    transform: scale(1.7);
    opacity: 0;
  }
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 9px;
  font-size: 12px;
  color: var(--muted);
}

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

.legend i {
  width: 18px;
  height: 10px;
  display: inline-block;
  border-radius: 2px;
}

.exposure-list {
  display: grid;
  gap: 8px;
  margin-top: 10px;
}

.terrain-list {
  display: grid;
  gap: 8px;
  margin-top: 10px;
}

.terrain-item {
  border: 1px solid #dbe5f0;
  border-left: 5px solid #111827;
  border-radius: 5px;
  background: #fff;
  padding: 9px;
}

.terrain-item.compact {
  display: grid;
  grid-template-columns: 32px minmax(0, 1fr);
  gap: 7px;
  align-items: center;
  border-left-color: var(--blue);
}

.terrain-item strong {
  display: block;
  font-size: 12px;
}

.terrain-item span {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.35;
}

.terrain-item.compact span {
  margin-top: 0;
}

.exposure-item {
  border: 1px solid #dbe5f0;
  border-left: 5px solid var(--green);
  border-radius: 5px;
  background: #fff;
  padding: 9px;
}

.exposure-item.hot {
  border-left-color: var(--red);
  background: #fff7f7;
}

.exposure-item.warn {
  border-left-color: var(--orange);
  background: #fff8ed;
}

.exposure-item strong {
  display: block;
  font-size: 12px;
}

.exposure-item span {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.35;
}

.analysis-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.7fr) minmax(320px, 0.9fr);
  gap: 14px;
  margin-top: 14px;
}

.analysis-panel {
  padding: 14px;
  min-height: 340px;
}

.chart-panel {
  min-width: 0;
}

#timeseries-chart {
  width: 100%;
  height: auto;
  display: block;
  border-top: 1px solid #eef2f7;
}

.evidence-chain {
  margin: 10px 0 0;
  padding-left: 22px;
}

.evidence-chain li {
  margin: 0 0 14px;
  padding-left: 4px;
}

.evidence-chain strong {
  display: block;
  font-size: 13px;
}

.evidence-chain span {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

@media (max-width: 1050px) {
  .layout {
    grid-template-columns: 1fr;
  }

  .sidebar {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .summary-strip,
  .decision-strip,
  .analysis-grid {
    grid-template-columns: 1fr;
  }
}
