:root {
  --bge-red: #ce1141;
  --ink: #172033;
  --muted: #657085;
  --line: #d8dee8;
  --panel: #ffffff;
  --surface: #f4f7fb;
  --focus: #0059a4;
  --gray: #9aa4b2;
  --green: #01a75a;
  --blue: #007ea8;
  --purple: #8532b3;
  --orange: #e77204;
  --red: #be281e;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  color: var(--ink);
  font-family: Arial, Helvetica, sans-serif;
  background: var(--surface);
}

button,
input,
select {
  font: inherit;
}

.app-shell {
  display: grid;
  min-height: 100vh;
  grid-template-columns: minmax(0, 1fr) 420px;
}

.map-panel {
  position: relative;
  min-height: 100vh;
}

#map {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  background: #dfe7ef;
}

.brand-bar {
  position: absolute;
  top: 16px;
  left: 16px;
  z-index: 500;
  display: grid;
  grid-template-columns: minmax(170px, 0.8fr) minmax(0, 1.2fr);
  align-items: center;
  gap: 16px;
  width: min(880px, calc(100% - 32px));
  padding: 14px 16px;
  background: rgba(255, 255, 255, 0.94);
  border: 1px solid rgba(216, 222, 232, 0.9);
  box-shadow: 0 16px 42px rgba(23, 32, 51, 0.16);
}

.map-mode-badge {
  position: absolute;
  left: 16px;
  top: 92px;
  z-index: 500;
  max-width: calc(100% - 32px);
  padding: 8px 10px;
  border: 1px solid rgba(216, 222, 232, 0.9);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.94);
  box-shadow: 0 8px 24px rgba(23, 32, 51, 0.14);
  color: var(--ink);
  font-size: 0.78rem;
  font-weight: 800;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--bge-red);
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: 1.35rem;
  line-height: 1.2;
}

h2 {
  margin-bottom: 0;
  font-size: 1.2rem;
}

h3 {
  margin-bottom: 0;
  font-size: 1rem;
}

.report-link,
button {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  text-decoration: none;
  cursor: pointer;
}

.map-actions {
  display: grid;
  grid-template-columns: minmax(160px, 1fr) auto auto auto;
  align-items: center;
  justify-content: end;
  gap: 8px;
  min-width: 0;
}

.utility-picker {
  display: grid;
  min-width: 0;
  position: relative;
}

.utility-picker span {
  color: var(--muted);
  font-size: 0.68rem;
  font-weight: 800;
  text-transform: uppercase;
}

.utility-picker select {
  appearance: none;
  -webkit-appearance: none;
  width: 100%;
  min-height: 38px;
  height: 38px;
  padding: 0 34px 0 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  font-weight: 800;
  line-height: 38px;
}

.utility-picker::after {
  content: "";
  position: absolute;
  right: 12px;
  top: 50%;
  width: 8px;
  height: 8px;
  border-right: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  pointer-events: none;
  transform: translateY(-65%) rotate(45deg);
}

.reset-map,
.find-provider {
  min-height: 38px;
  padding: 0 12px;
  border-radius: 6px;
  font-weight: 800;
}

.find-provider {
  display: inline-grid;
  place-items: center;
}

.find-provider-icon {
  display: none;
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2.3;
}

.report-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 38px;
  padding: 10px 14px;
  border-color: var(--bge-red);
  color: #fff;
  background: var(--bge-red);
  font-weight: 700;
}

.data-panel {
  z-index: 600;
  display: flex;
  flex-direction: column;
  max-height: 100vh;
  padding: 18px;
  background: var(--panel);
  border-left: 1px solid var(--line);
  overflow: auto;
}

.panel-handle {
  display: none;
}

.panel-header,
.list-heading,
.freshness {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.panel-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.icon-button,
#sortButton {
  display: inline-grid;
  place-items: center;
  min-height: 40px;
  min-width: 40px;
  padding: 0 12px;
  border-radius: 6px;
  font-weight: 700;
}

.icon-button {
  line-height: 1;
}

.icon-button[hidden] {
  display: none;
}

.icon-button svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2.3;
}

.metrics {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin: 18px 0 12px;
}

.metrics article {
  min-width: 0;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.metrics span {
  display: block;
  font-size: 1.45rem;
  font-weight: 800;
}

.metrics p,
.freshness,
label span,
.area-meta,
.event-detail,
.selected-card dt {
  color: var(--muted);
  font-size: 0.82rem;
}

.metrics p {
  margin-bottom: 0;
}

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

#statusText {
  color: var(--focus);
  font-weight: 700;
}

.controls {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  margin: 16px 0;
}

.search-field {
  display: grid;
  gap: 6px;
}

input {
  width: 100%;
  min-height: 42px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
}

input:focus,
select:focus,
button:focus,
.report-link:focus {
  outline: 3px solid rgba(0, 89, 164, 0.25);
  outline-offset: 2px;
}

.segmented {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  align-self: end;
  min-width: 148px;
  border: 1px solid var(--line);
  border-radius: 6px;
  overflow: hidden;
}

.segmented button {
  min-height: 42px;
  border: 0;
  border-radius: 0;
  font-weight: 700;
}

.segmented .active {
  color: #fff;
  background: var(--focus);
}

.selected-card {
  padding: 14px;
  margin-bottom: 16px;
  border: 1px solid var(--line);
  border-left: 4px solid var(--bge-red);
  border-radius: 8px;
}

.selected-card dl {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin: 12px 0 0;
}

.selected-card dd {
  margin: 2px 0 0;
  font-weight: 800;
}

.area-list {
  display: grid;
  gap: 8px;
  padding: 10px 0 20px;
}

.area-row {
  width: 100%;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  padding: 12px;
  text-align: left;
  border-radius: 8px;
}

.area-row:hover,
.area-row.active {
  border-color: var(--focus);
  background: #eef6ff;
}

.area-name {
  font-weight: 800;
}

.area-count {
  font-weight: 800;
  color: var(--bge-red);
}

.area-count.zero {
  color: var(--muted);
}

.event-detail {
  display: block;
  margin-top: 4px;
  line-height: 1.25;
}

.event-row {
  align-items: start;
}

.empty-list {
  margin: 8px 0 0;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--muted);
  background: var(--surface);
}

.legend {
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 8px 24px rgba(23, 32, 51, 0.12);
}

.legend-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 4px 0;
  font-size: 0.8rem;
}

.swatch {
  width: 14px;
  height: 14px;
  border-radius: 3px;
  border: 1px solid rgba(0, 0, 0, 0.25);
}

.outage-marker {
  display: grid;
  place-items: center;
}

.area-aggregate-marker {
  display: grid;
  place-items: center;
}

.area-aggregate-marker span {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border: 3px solid #fff;
  border-radius: 999px;
  background: var(--bge-red);
  color: #fff;
  box-shadow: 0 10px 22px rgba(23, 32, 51, 0.32);
  font-size: 0.82rem;
  font-weight: 900;
  line-height: 1;
}

.area-aggregate-marker.zero span {
  width: 30px;
  height: 30px;
  border-width: 2px;
  background: var(--gray);
  color: #fff;
  box-shadow: 0 6px 14px rgba(23, 32, 51, 0.2);
  font-size: 0.72rem;
}

.outage-marker span {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border: 2px solid #fff;
  background: #0f1a2a;
  color: #fff;
  box-shadow: 0 8px 18px rgba(23, 32, 51, 0.28);
  font-size: 0.78rem;
  font-weight: 800;
  line-height: 1;
}

.outage-marker b {
  font: inherit;
}

.single-low span {
  border-radius: 8px;
  background: var(--green);
}

.single-medium span {
  border-radius: 999px;
  background: var(--blue);
}

.single-high span {
  border-radius: 0;
  background: var(--purple);
  clip-path: polygon(50% 0, 100% 100%, 0 100%);
  padding-top: 8px;
}

.single-severe span {
  background: var(--orange);
}

.single-extreme span {
  background: var(--red);
}

.diamond span {
  transform: rotate(45deg);
  border-radius: 5px;
}

.diamond b {
  transform: rotate(-45deg);
}

.event-marker span {
  font-size: 0.72rem;
}

.cluster-event span {
  width: 48px;
  height: 48px;
  border-radius: 999px;
  background: var(--focus);
}

@media (max-width: 1320px) {
  .data-panel {
    padding: 16px;
  }

  .metrics {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .metrics article:nth-child(3) {
    display: none;
  }

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

  .segmented {
    width: 100%;
  }
}

@media (max-width: 1240px) {
  .brand-bar {
    grid-template-columns: 1fr;
    align-items: stretch;
    gap: 8px;
    width: min(620px, calc(100% - 32px));
    padding: 12px;
  }

  .brand-bar h1 {
    display: none;
  }

  .map-actions {
    grid-template-columns: minmax(160px, 1fr) auto auto auto;
    justify-content: stretch;
  }

  .find-provider,
  .reset-map,
  .report-link {
    min-height: 36px;
    padding-inline: 12px;
    white-space: nowrap;
  }

  .map-mode-badge {
    display: none;
  }

  .legend {
    display: none;
  }
}

@media (max-width: 1120px) {
  .app-shell {
    grid-template-columns: minmax(0, 1fr) 380px;
  }
}

@media (max-width: 900px) {
  .app-shell {
    grid-template-columns: 1fr;
    grid-template-rows: 56vh auto;
  }

  .map-panel {
    min-height: 56vh;
  }

  .brand-bar {
    grid-template-columns: 1fr;
    align-items: stretch;
    gap: 10px;
    width: min(720px, calc(100% - 32px));
    max-width: none;
    padding: 12px;
  }

  .map-actions {
    grid-template-columns: minmax(180px, 1fr) auto auto auto;
    justify-content: stretch;
  }

  .map-actions > * {
    min-width: 0;
  }

  .find-provider,
  .reset-map,
  .report-link {
    padding-inline: 12px;
    white-space: nowrap;
  }

  .map-mode-badge {
    display: none;
  }

  .data-panel {
    max-height: none;
    padding: 20px;
    border-left: 0;
    border-top: 1px solid var(--line);
  }

  .controls {
    grid-template-columns: minmax(0, 1fr) minmax(220px, auto);
  }
}

@media (max-width: 560px) {
  .app-shell {
    display: block;
    min-height: 100dvh;
  }

  .map-panel {
    height: 100dvh;
    min-height: 100dvh;
  }

  .brand-bar {
    display: block;
    top: max(8px, env(safe-area-inset-top));
    left: 8px;
    right: auto;
    width: calc(100vw - 16px);
    gap: 8px;
    max-width: none;
    padding: 10px;
    border-radius: 12px;
  }

  .brand-bar h1,
  .map-mode-badge,
  .legend {
    display: none;
  }

  .brand-bar,
  .map-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .map-actions {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    width: 100%;
  }

  .utility-picker {
    grid-column: 1 / -1;
    min-width: 0;
  }

  .map-actions > * {
    min-width: 0;
  }

  .utility-picker select,
  .reset-map,
  .find-provider,
  .report-link {
    min-height: 34px;
    border-radius: 8px;
    font-size: 0.78rem;
  }

  .report-link {
    justify-content: center;
    padding: 0 10px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .find-provider-text {
    display: none;
  }

  .find-provider-icon {
    display: block;
    margin: auto;
  }

  .leaflet-control-attribution {
    position: fixed;
    top: 174px;
    right: 8px;
    bottom: auto;
    max-width: calc(100vw - 16px);
    border-radius: 6px;
    opacity: 0.9;
  }

  .data-panel {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 800;
    max-height: 43dvh;
    padding: 12px 12px calc(12px + env(safe-area-inset-bottom));
    border-top: 1px solid var(--line);
    border-left: 0;
    border-radius: 18px 18px 0 0;
    box-shadow: 0 -14px 36px rgba(23, 32, 51, 0.24);
    transform: translateY(0);
    transition: transform 180ms ease;
    will-change: transform;
  }

  .data-panel.sheet-collapsed {
    transform: translateY(calc(100% - 82px));
  }

  .data-panel.sheet-dragging {
    transition: none;
  }

  .panel-handle {
    display: block;
    width: 100%;
    min-height: 22px;
    padding: 0;
    border: 0;
    background: transparent;
    touch-action: none;
  }

  .panel-handle::before {
    content: "";
    display: block;
    width: 44px;
    height: 5px;
    margin: 0 auto 8px;
    border-radius: 999px;
    background: #b9c2d0;
  }

  .panel-header {
    gap: 8px;
  }

  h1 {
    font-size: 1.05rem;
  }

  .metrics {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 6px;
    margin: 10px 0 8px;
  }

  .metrics article:nth-child(3) {
    display: none;
  }

  .metrics article {
    padding: 8px;
  }

  .metrics span {
    overflow: hidden;
    font-size: 0.92rem;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .metrics p,
  .freshness,
  label span,
  .area-meta,
  .event-detail,
  .selected-card dt {
    font-size: 0.72rem;
  }

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

  input,
  .segmented button {
    min-height: 36px;
  }

  .segmented {
    width: 100%;
  }

  .selected-card dl {
    grid-template-columns: 1fr;
  }

  .area-list {
    padding-bottom: 8px;
  }

  .area-row {
    padding: 10px;
  }

  .leaflet-control-zoom {
    display: none;
  }
}
