:root {
  --bg: #f4f6f8;
  --panel: #ffffff;
  --panel-strong: #eef3f4;
  --text: #142326;
  --muted: #607174;
  --line: #d9e1e4;
  --high: #c62828;
  --high-soft: #fde8e7;
  --low: #1769aa;
  --low-soft: #e5f1fb;
  --stale: #7a5a00;
  --stale-soft: #fff4d6;
  --issue: #59636b;
  --issue-soft: #edf0f2;
  --shadow: 0 12px 32px rgba(20, 35, 38, 0.16);
  color-scheme: light;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
}

button,
input {
  font: inherit;
}

.topbar {
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 0 18px;
  background: #ffffff;
  border-bottom: 1px solid var(--line);
  position: relative;
  z-index: 800;
}

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

.brand-mark {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  background:
    linear-gradient(135deg, transparent 0 46%, rgba(255, 255, 255, 0.62) 47% 53%, transparent 54%),
    linear-gradient(180deg, #12343b 0%, #1769aa 100%);
  box-shadow: inset 0 -6px 0 rgba(255, 255, 255, 0.18);
  flex: 0 0 auto;
}

.brand strong,
.brand span {
  display: block;
  line-height: 1.05;
}

.brand strong {
  font-size: 17px;
  letter-spacing: 0;
}

.brand span {
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.status-pill {
  min-height: 32px;
  display: inline-flex;
  align-items: center;
  max-width: min(54vw, 520px);
  padding: 6px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--muted);
  background: #f9fbfb;
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.icon-button {
  width: 36px;
  height: 36px;
  border: 1px solid var(--line);
  border-radius: 8px;
  display: grid;
  place-items: center;
  background: #ffffff;
  color: var(--text);
  cursor: pointer;
}

.icon-button:hover,
.filter-button:hover,
.station-item:hover {
  border-color: #9fb2b8;
}

.icon-button:disabled {
  cursor: progress;
  opacity: 0.55;
}

.portal-shell {
  height: calc(100vh - 64px);
  display: grid;
  grid-template-columns: 410px minmax(0, 1fr);
  min-height: 0;
}

.situation-panel {
  min-height: 0;
  overflow: auto;
  background: #ffffff;
  border-right: 1px solid var(--line);
  padding: 16px;
}

.panel-section {
  padding: 14px 0;
  border-bottom: 1px solid var(--line);
}

.panel-section:first-child {
  padding-top: 0;
}

.section-heading {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
}

.section-heading p,
#chartEyebrow {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

.section-heading time {
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.report {
  margin: 0;
  line-height: 1.5;
  font-size: 15px;
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  padding: 14px 0;
  border-bottom: 1px solid var(--line);
}

.kpi {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: var(--panel-strong);
}

.kpi span,
.kpi strong {
  display: block;
}

.kpi span {
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
}

.kpi strong {
  margin-top: 6px;
  font-size: clamp(22px, 2vw, 28px);
  line-height: 1;
}

.kpi.high {
  background: var(--high-soft);
  border-color: #f4b2ad;
}

.kpi.low {
  background: var(--low-soft);
  border-color: #adcdea;
}

.kpi.stale {
  background: var(--stale-soft);
  border-color: #ead28a;
}

.controls {
  display: grid;
  gap: 10px;
}

.filter-row {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 6px;
}

.filter-button {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  color: var(--text);
  min-height: 36px;
  padding: 7px 8px;
  cursor: pointer;
  font-size: 13px;
}

.filter-button.active {
  background: #12343b;
  border-color: #12343b;
  color: #ffffff;
}

.search-field input {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 11px;
  color: var(--text);
  background: #ffffff;
}

.station-list {
  display: grid;
  gap: 8px;
  padding-top: 14px;
}

.station-item {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  color: var(--text);
  text-align: left;
  padding: 11px;
  cursor: pointer;
}

.station-item.active {
  border-color: #12343b;
  box-shadow: 0 0 0 2px rgba(18, 52, 59, 0.12);
}

.station-topline,
.station-meta,
.station-value {
  display: flex;
  align-items: center;
  gap: 8px;
}

.station-topline {
  justify-content: space-between;
}

.station-name {
  min-width: 0;
  font-weight: 800;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.station-meta {
  margin-top: 6px;
  color: var(--muted);
  font-size: 13px;
  min-width: 0;
}

.station-meta span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.station-value {
  margin-top: 9px;
  justify-content: space-between;
  font-size: 13px;
}

.value-strong {
  font-weight: 800;
  color: var(--text);
}

.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 24px;
  border-radius: 8px;
  padding: 4px 8px;
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

.badge.high {
  color: var(--high);
  background: var(--high-soft);
}

.badge.low {
  color: var(--low);
  background: var(--low-soft);
}

.badge.stale,
.badge.issue {
  color: var(--stale);
  background: var(--stale-soft);
}

.badge.neutral {
  color: var(--muted);
  background: var(--issue-soft);
}

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

.map {
  position: absolute;
  inset: 0;
  z-index: 1;
}

.chart-dock {
  position: absolute;
  left: 18px;
  right: 18px;
  bottom: 18px;
  z-index: 500;
  background: rgba(255, 255, 255, 0.96);
  border: 1px solid rgba(217, 225, 228, 0.9);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 14px;
  display: grid;
  gap: 10px;
  max-width: 780px;
}

.chart-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
}

.chart-header h1 {
  margin: 3px 0 0;
  font-size: clamp(18px, 2.2vw, 24px);
  line-height: 1.12;
  letter-spacing: 0;
}

.chart-meta {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
  text-align: right;
}

.chart-frame {
  height: 210px;
  position: relative;
}

.chart-empty {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: var(--muted);
}

.chart-empty[hidden] {
  display: none;
}

.leaflet-popup-content-wrapper,
.leaflet-popup-tip {
  border-radius: 8px;
}

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

.popup-line {
  color: var(--muted);
  font-size: 13px;
  margin-top: 3px;
}

.marker-dot {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 3px solid #ffffff;
  box-shadow: 0 2px 10px rgba(20, 35, 38, 0.35);
}

.marker-dot.high {
  background: var(--high);
}

.marker-dot.low {
  background: var(--low);
}

.marker-dot.stale,
.marker-dot.issue {
  background: var(--stale);
}

.empty-state {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  color: var(--muted);
  background: #ffffff;
  line-height: 1.45;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@media (max-width: 980px) {
  body {
    overflow: auto;
  }

  .portal-shell {
    height: auto;
    grid-template-columns: 1fr;
  }

  .situation-panel {
    order: 2;
    border-right: 0;
    border-bottom: 1px solid var(--line);
    max-height: none;
  }

  .map-area {
    order: 1;
    min-height: 76vh;
  }

  .chart-dock {
    left: 10px;
    right: 10px;
    bottom: 10px;
  }
}

@media (max-width: 620px) {
  .topbar {
    height: auto;
    min-height: 64px;
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    padding: 10px 12px;
    align-items: start;
  }

  .topbar-actions {
    width: 100%;
    align-items: flex-start;
    justify-content: space-between;
  }

  .status-pill {
    flex: 1 1 auto;
    max-width: none;
    white-space: normal;
  }

  .situation-panel {
    padding: 12px;
  }

  .kpi-grid {
    grid-template-columns: 1fr;
  }

  .chart-header {
    display: grid;
  }

  .chart-meta {
    justify-content: flex-start;
    text-align: left;
  }

  .chart-frame {
    height: 180px;
  }
}
