:root {
  color-scheme: light;
  --atlas-deep: #0d2a38;
  --atlas-mid: #264b50;
  --ink: #102d33;
  --muted-ink: #536b69;
  --quiet-ink: #647873;
  --surface: #eef1ea;
  --surface-raised: #fbfaf4;
  --surface-muted: #e5ebe4;
  --line: #cbd3ca;
  --line-strong: #9fac9f;
  --eq: #d92f55;
  --fl: #087fa9;
  --wf: #ce5b1b;
  --green: #237a57;
  --orange: #ad4917;
  --red: #b41f3d;
  --focus: #0969c3;
  --sidebar-width: 390px;
  font-family: Inter, "Helvetica Neue", Arial, sans-serif;
  font-synthesis: none;
}

* {
  box-sizing: border-box;
}

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

body {
  overflow: hidden;
  color: var(--ink);
  background: var(--atlas-deep);
}

button,
select,
input {
  font: inherit;
}

button,
select,
a,
label {
  -webkit-tap-highlight-color: transparent;
}

button,
select,
a[href],
.hazard-toggle {
  cursor: pointer;
}

:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--focus) 62%, transparent);
  outline-offset: 2px;
}

[hidden] {
  display: none !important;
}

#app {
  display: grid;
  grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
  min-height: 0;
}

.sidebar {
  position: relative;
  z-index: 5;
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  border-right: 1px solid var(--line-strong);
  background: var(--surface);
  box-shadow: 8px 0 30px rgb(4 22 31 / 22%);
}

.brand-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 64px;
  padding: 0 24px;
  border-bottom: 1px solid #31505a;
  background: var(--atlas-deep);
}

.brand {
  display: inline-flex;
  gap: 10px;
  align-items: center;
  color: #f7f4e9;
  font-size: 14px;
  font-weight: 760;
  letter-spacing: 0.16em;
  text-decoration: none;
}

.brand svg {
  width: 25px;
  height: 25px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.5;
}

.brand svg circle {
  fill: var(--eq);
  stroke: #f7f4e9;
  stroke-width: 1.5;
}

.brand-slash {
  color: var(--eq);
}

.live-status {
  display: inline-flex;
  gap: 7px;
  align-items: center;
  color: #b9cbc5;
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.16em;
}

.live-status span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #55bd86;
  box-shadow: 0 0 0 3px rgb(85 189 134 / 18%);
}

.controls {
  padding: 23px 24px 20px;
  border-bottom: 1px solid var(--line);
  background: var(--surface-muted);
}

.section-heading,
.feed-heading,
.event-title-line,
.detail-kicker {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--quiet-ink);
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.17em;
  line-height: 1.3;
}

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

h1 {
  margin-bottom: 0;
  font-size: 19px;
  font-weight: 690;
  letter-spacing: -0.025em;
}

.icon-button {
  display: inline-grid;
  width: 38px;
  height: 38px;
  flex: 0 0 auto;
  place-items: center;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 4px;
  color: var(--muted-ink);
  background: var(--surface-raised);
  transition: border-color 160ms ease, color 160ms ease, background 160ms ease;
}

.icon-button:hover {
  border-color: var(--line-strong);
  color: var(--ink);
  background: #edf1eb;
}

.icon-button:disabled {
  cursor: wait;
  opacity: 0.5;
}

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

.hazard-filters {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 7px;
  margin: 20px 0 10px;
  padding: 0;
  border: 0;
}

.hazard-filters legend {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.hazard-toggle {
  position: relative;
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 7px;
  align-items: center;
  min-height: 38px;
  padding: 0 9px;
  border: 1px solid var(--line);
  border-radius: 3px;
  color: var(--muted-ink);
  background: var(--surface-raised);
  font-size: 10px;
  transition: border-color 160ms ease, opacity 160ms ease, box-shadow 160ms ease;
}

.hazard-eq { --hazard: var(--eq); }
.hazard-fl { --hazard: var(--fl); }
.hazard-wf { --hazard: var(--wf); }

.hazard-toggle:has(input:checked) {
  border-color: color-mix(in srgb, var(--hazard) 46%, var(--line));
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--hazard) 10%, transparent);
}

.hazard-toggle:hover {
  border-color: var(--line-strong);
}

.hazard-toggle input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.hazard-toggle:has(input:focus-visible) {
  outline: 3px solid color-mix(in srgb, var(--focus) 62%, transparent);
  outline-offset: 2px;
}

.hazard-toggle:not(:has(input:checked)) {
  opacity: 0.48;
  box-shadow: inset 0 0 0 1px #e8ece6;
}

.hazard-toggle > span:nth-of-type(2) {
  overflow: hidden;
  text-overflow: ellipsis;
}

.hazard-toggle strong {
  color: var(--ink);
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 9px;
}

.filter-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  color: var(--hazard);
  background: currentColor;
}

.hazard-fl .filter-dot { border-radius: 1px; }
.hazard-wf .filter-dot { border-radius: 1px; transform: rotate(45deg); }

.alert-filter {
  display: grid;
  grid-template-columns: 1fr 165px;
  gap: 12px;
  align-items: center;
  min-height: 42px;
  padding: 0 0 0 11px;
  border: 1px solid var(--line);
  border-radius: 3px;
  color: var(--muted-ink);
  background: var(--surface-raised);
  font-size: 11px;
  font-weight: 560;
}

.alert-filter select {
  width: 100%;
  height: 100%;
  padding: 0 28px 0 10px;
  border: 0;
  border-left: 1px solid var(--line);
  border-radius: 0;
  color: var(--ink);
  background: var(--surface-raised);
  font-size: 11px;
}

.event-feed {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  min-height: 0;
  overflow: hidden;
  background: var(--surface-raised);
}

.feed-heading {
  align-items: center;
  padding: 19px 24px 14px;
  border-bottom: 1px solid var(--line);
  background: #f4f5ef;
}

.feed-heading h2 {
  margin: 0;
  font-size: 12px;
  font-weight: 650;
  letter-spacing: -0.01em;
}

#event-count {
  min-width: 39px;
  padding: 6px 7px;
  border: 1px solid var(--line);
  border-radius: 2px;
  color: var(--muted-ink);
  background: #e7ece5;
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 10px;
  font-weight: 700;
  text-align: center;
}

.event-list {
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-color: #aebbb0 transparent;
  scrollbar-width: thin;
}

.event-row {
  position: relative;
  display: grid;
  width: 100%;
  grid-template-columns: 40px minmax(0, 1fr);
  gap: 12px;
  padding: 15px 24px 16px 20px;
  border: 0;
  border-bottom: 1px solid #dde3dc;
  color: inherit;
  background: var(--surface-raised);
  text-align: left;
  transition: background 150ms ease, box-shadow 150ms ease;
}

.event-row:hover {
  background: #edf2ec;
}

.event-row[aria-pressed="true"] {
  z-index: 1;
  background: #e5ece6;
  box-shadow: inset 4px 0 0 var(--ink), inset 0 0 0 1px #bcc9be;
}

.event-row.event-eq[aria-pressed="true"] { box-shadow: inset 4px 0 0 var(--eq), inset 0 0 0 1px #c8b8bd; }
.event-row.event-fl[aria-pressed="true"] { box-shadow: inset 4px 0 0 var(--fl), inset 0 0 0 1px #abc4ca; }
.event-row.event-wf[aria-pressed="true"] { box-shadow: inset 4px 0 0 var(--wf), inset 0 0 0 1px #cfb9a9; }

.hazard-mark {
  display: grid;
  width: 36px;
  height: 36px;
  place-items: center;
  border: 1px solid currentColor;
  border-radius: 50%;
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 9px;
  font-weight: 800;
  letter-spacing: 0.06em;
}

.event-eq .hazard-mark { color: #bd1f45; background: #fcecf0; }
.event-fl .hazard-mark { color: #066889; background: #e8f6f8; border-radius: 5px; }
.event-wf .hazard-mark { color: #a9440d; background: #fbefe6; border-radius: 10px 3px; }

.event-copy {
  display: grid;
  min-width: 0;
  gap: 4px;
}

.event-title-line {
  min-width: 0;
  align-items: center;
}

.event-title {
  min-width: 0;
  overflow: hidden;
  font-size: 12px;
  font-weight: 660;
  line-height: 1.35;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.alert-badge {
  display: inline-flex;
  flex: 0 0 auto;
  align-items: center;
  justify-content: center;
  min-width: 48px;
  padding: 4px 6px 3px;
  border: 1px solid currentColor;
  border-radius: 2px;
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 8px;
  font-weight: 800;
  letter-spacing: 0.1em;
  line-height: 1;
}

.alert-green { color: var(--green); background: #eff9f2; }
.alert-orange { color: var(--orange); background: #fbf0e7; }
.alert-red { color: var(--red); background: #fcecef; }

.event-location,
.event-time {
  overflow: hidden;
  color: var(--muted-ink);
  font-size: 10px;
  line-height: 1.45;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.event-time {
  color: var(--quiet-ink);
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 9px;
}

.feed-message {
  align-self: start;
  margin: 20px 24px;
  padding: 18px;
  border: 1px solid var(--line);
  color: var(--muted-ink);
  background: #f1f4ee;
  font-size: 11px;
  line-height: 1.5;
}

.feed-message p {
  margin-bottom: 12px;
}

.feed-message.is-loading::before,
.geometry-status.is-loading::before {
  content: "";
  display: inline-block;
  width: 10px;
  height: 10px;
  margin-right: 8px;
  border: 1.5px solid color-mix(in srgb, currentColor 25%, transparent);
  border-top-color: currentColor;
  border-radius: 50%;
  vertical-align: -1px;
  animation: loading-turn 900ms linear infinite;
}

@keyframes loading-turn {
  to { transform: rotate(360deg); }
}

.retry-button {
  min-height: 36px;
  padding: 0 14px;
  border: 1px solid var(--ink);
  border-radius: 3px;
  color: white;
  background: var(--ink);
  font-size: 11px;
  font-weight: 650;
}

.sidebar-footer {
  display: flex;
  gap: 12px;
  align-items: center;
  min-height: 44px;
  padding: 0 24px;
  border-top: 1px solid var(--line);
  color: var(--quiet-ink);
  background: #e5eae3;
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 8px;
  letter-spacing: 0.1em;
}

.sidebar-footer a {
  overflow: hidden;
  color: var(--muted-ink);
  font-family: Inter, "Helvetica Neue", Arial, sans-serif;
  font-size: 9px;
  letter-spacing: 0;
  text-decoration-color: #aab3ad;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.map-stage {
  position: relative;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  background: #8bbdcb;
}

#map {
  position: absolute;
  inset: 0;
}

#map.map-fallback {
  background-color: #8bbdcb;
  background-image:
    radial-gradient(ellipse at 72% 34%, rgb(183 200 168 / 78%) 0 8%, transparent 8.2%),
    radial-gradient(ellipse at 48% 62%, rgb(183 200 168 / 68%) 0 12%, transparent 12.2%),
    linear-gradient(rgb(255 250 240 / 18%) 1px, transparent 1px),
    linear-gradient(90deg, rgb(255 250 240 / 18%) 1px, transparent 1px);
  background-size: auto, auto, 80px 80px, 80px 80px;
}

.map-topline {
  position: absolute;
  z-index: 2;
  top: 18px;
  right: 18px;
  left: 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  pointer-events: none;
}

.map-topline > span,
.map-context {
  padding: 8px 10px;
  border: 1px solid rgb(182 205 196 / 36%);
  border-radius: 3px;
  color: #edf3eb;
  background: rgb(13 42 56 / 90%);
  box-shadow: 0 5px 18px rgb(3 19 29 / 20%);
  backdrop-filter: blur(8px);
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 8px;
  font-weight: 700;
  letter-spacing: 0.12em;
}

.map-context {
  pointer-events: auto;
  appearance: none;
  cursor: pointer;
  transition: border-color 150ms ease, background 150ms ease;
}

.map-context:hover {
  border-color: rgb(220 234 226 / 72%);
  background: rgb(20 57 71 / 96%);
}

.map-token-notice {
  position: absolute;
  z-index: 3;
  top: 50%;
  left: 50%;
  display: grid;
  gap: 7px;
  min-width: 290px;
  padding: 19px 21px;
  border: 1px solid #9caca1;
  border-radius: 4px;
  color: var(--muted-ink);
  background: rgb(251 250 244 / 95%);
  box-shadow: 0 14px 44px rgb(3 20 29 / 24%);
  transform: translate(-50%, -50%);
  font-size: 11px;
  text-align: center;
}

.map-token-notice strong {
  color: var(--ink);
  font-size: 13px;
}

.map-token-notice code {
  font-size: 10px;
}

.detail-card {
  position: absolute;
  z-index: 4;
  top: 72px;
  right: 18px;
  width: min(344px, calc(100% - 36px));
  max-height: calc(100% - 130px);
  overflow-y: auto;
  padding: 25px;
  border: 1px solid rgb(164 181 168 / 82%);
  border-radius: 5px;
  background: rgb(251 250 244 / 96%);
  box-shadow: 0 20px 58px rgb(2 20 30 / 28%);
  backdrop-filter: blur(12px);
}

.detail-close {
  position: absolute;
  z-index: 1;
  top: 17px;
  right: 17px;
  width: 34px;
  height: 34px;
}

.detail-kicker {
  align-items: center;
  padding-right: 42px;
}

.detail-type {
  color: var(--muted-ink);
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 9px;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.detail-card h2 {
  max-width: 255px;
  margin: 20px 0 7px;
  font-size: 22px;
  font-weight: 680;
  letter-spacing: -0.035em;
  line-height: 1.16;
}

.detail-location {
  margin-bottom: 15px;
  color: var(--muted-ink);
  font-size: 12px;
  line-height: 1.45;
}

.detail-age {
  margin-bottom: 20px;
  color: var(--ink);
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 10px;
  font-weight: 700;
}

.detail-list {
  display: grid;
  gap: 0;
  margin: 0;
  border-top: 1px solid var(--line);
}

.detail-pair {
  display: grid;
  grid-template-columns: 90px 1fr;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid #dfe5de;
  font-size: 10px;
  line-height: 1.4;
}

.detail-pair dt {
  color: var(--quiet-ink);
  font-family: "SFMono-Regular", Consolas, monospace;
  text-transform: uppercase;
}

.detail-pair dd {
  margin: 0;
  color: var(--ink);
  text-align: right;
}

.geometry-status {
  margin: 18px 0 0;
  padding: 12px;
  border-left: 2px solid var(--atlas-mid);
  color: var(--muted-ink);
  background: #e9eee8;
  font-size: 10px;
  line-height: 1.5;
}

.source-link {
  display: inline-flex;
  color: var(--ink);
  font-size: 11px;
  font-weight: 680;
  text-underline-offset: 4px;
}

.detail-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 16px;
  align-items: center;
  justify-content: space-between;
  margin-top: 18px;
}

.share-button {
  min-height: 34px;
  padding: 0 11px;
  border: 1px solid var(--line-strong);
  border-radius: 3px;
  color: var(--ink);
  background: var(--surface-raised);
  font-size: 10px;
  font-weight: 650;
  transition: border-color 160ms ease, background 160ms ease;
}

.share-button:hover {
  border-color: var(--ink);
  background: #edf1eb;
}

.map-legend {
  position: absolute;
  z-index: 2;
  top: 62px;
  left: 18px;
  display: flex;
  gap: 13px;
  align-items: center;
  min-height: 34px;
  padding: 0 12px;
  border: 1px solid rgb(182 205 196 / 36%);
  border-radius: 3px;
  color: #dce7df;
  background: rgb(13 42 56 / 90%);
  box-shadow: 0 6px 20px rgb(3 19 29 / 22%);
  backdrop-filter: blur(8px);
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 8px;
  font-weight: 700;
  letter-spacing: 0.08em;
}

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

.map-legend i {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: currentColor;
}

.map-legend .legend-eq { color: var(--eq); }
.map-legend .legend-fl { color: var(--fl); border-radius: 1px; }
.map-legend .legend-wf { color: var(--wf); border-radius: 1px; transform: rotate(45deg); }
.legend-separator { width: 1px; height: 14px; background: #78918a; }

.mapboxgl-ctrl-group {
  border: 1px solid rgb(182 205 196 / 34%);
  background: rgb(13 42 56 / 92%);
  box-shadow: 0 6px 20px rgb(3 19 29 / 24%);
}

.mapboxgl-ctrl-group button + button {
  border-top-color: rgb(182 205 196 / 28%);
}

.mapboxgl-ctrl-group button .mapboxgl-ctrl-icon {
  filter: invert(92%) sepia(8%) saturate(178%) hue-rotate(74deg) brightness(104%);
}

.mapboxgl-ctrl-bottom-left,
.mapboxgl-ctrl-bottom-right {
  z-index: 1;
}

.mapboxgl-ctrl-bottom-right {
  bottom: 0;
  right: 0;
}

.mapboxgl-ctrl-attrib {
  font-size: 9px;
}

@media (max-width: 1100px) {
  :root { --sidebar-width: 360px; }
  .hazard-toggle > span:nth-of-type(2) { display: none; }
  .hazard-toggle { grid-template-columns: auto 1fr; }
  .hazard-toggle strong { text-align: right; }
  .map-legend .legend-separator,
  .map-legend .legend-instruction { display: none; }
}

@media (max-width: 900px) {
  body { overflow: hidden; }
  #app {
    grid-template-columns: 1fr;
    grid-template-rows: 52dvh 48dvh;
  }
  .map-stage { grid-row: 1; }
  .sidebar {
    grid-row: 2;
    grid-template-rows: auto minmax(0, 1fr);
    border-top: 1px solid var(--line-strong);
    border-right: 0;
  }
  .brand-bar,
  .sidebar-footer { display: none; }
  .controls {
    display: grid;
    grid-template-columns: minmax(180px, 1fr) minmax(330px, 1.4fr);
    gap: 14px;
    align-items: end;
    padding: 12px 16px;
  }
  .section-heading { align-self: center; }
  .section-heading h1 { font-size: 16px; }
  .hazard-filters { margin: 0 0 7px; }
  .alert-filter { min-height: 38px; }
  .event-feed { grid-template-rows: auto minmax(0, 1fr); }
  .feed-heading { padding: 11px 16px 9px; }
  .event-list {
    display: grid;
    grid-auto-flow: column;
    grid-auto-columns: minmax(290px, 78vw);
    overflow-x: auto;
    overflow-y: hidden;
  }
  .event-row {
    height: 100%;
    min-height: 110px;
    border-right: 1px solid var(--line);
    border-bottom: 0;
  }
  .detail-card {
    top: auto;
    right: 12px;
    bottom: 12px;
    left: 12px;
    width: auto;
    max-height: calc(100% - 70px);
    padding: 20px;
  }
  .detail-card h2 { max-width: calc(100% - 36px); font-size: 19px; }
  .map-legend { display: none; }
  .mapboxgl-ctrl-bottom-right { bottom: 8px; }
}

@media (max-width: 620px) {
  #app { grid-template-rows: 56dvh 44dvh; }
  .controls {
    grid-template-columns: 1fr;
    gap: 10px;
    padding: 10px 12px;
  }
  .section-heading .eyebrow,
  .section-heading h1 { display: none; }
  .section-heading {
    position: absolute;
    right: 12px;
    top: calc(56dvh + 10px);
    z-index: 2;
  }
  .hazard-filters { padding-right: 48px; }
  .feed-heading { padding: 8px 12px 7px; }
  .feed-heading .eyebrow { display: none; }
  .event-list { grid-auto-columns: minmax(280px, 90vw); }
  .event-row { padding: 12px 16px; }
  .map-topline { top: 10px; right: 10px; left: 10px; }
  .map-context { display: none; }
  .map-topline { justify-content: flex-end; }
  .map-token-notice { min-width: 0; width: calc(100% - 40px); }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
  }
}
