:root {
  --bg: #10151b;
  --panel: #171e26;
  --panel-2: #1c242e;
  --line: #2a333e;
  --text: #d3dae2;
  --muted: #93a0af;
  --accent: #8fb6ff;
  --ok: #7cc98f;
  --warn: #dfb765;
  --err: #e08a8a;
  --agency: #8fb6ff;
  --vendor: #7cc9a2;
  --carrier: #e0a96f;
  --related: #b99ae8;
  --geography: #dcc06a;
  --map-bg: #0b1016;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100svh;
  padding: env(safe-area-inset-top, 0px) env(safe-area-inset-right, 0px) env(safe-area-inset-bottom, 0px) env(safe-area-inset-left, 0px);
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif;
}

h1 { font-size: 1.25rem; margin: 0; }
h2 { font-size: 1.05rem; margin: 4px 0 10px; }
h3 { font-size: 0.95rem; margin: 14px 0 8px; color: var(--muted); }

a { color: var(--accent); }

button, select {
  font: inherit;
  color: var(--text);
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 5px 12px;
  min-height: 44px;
  min-width: 0;
  max-width: 100%;
}

button:disabled { opacity: 0.55; }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.top {
  padding: 14px 18px 10px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}

.masthead {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 16px;
}

.masthead, .controls, .verification, .banner { max-width: 1764px; margin-inline: auto; }
.verification { color: var(--muted); font-size: 0.85rem; margin-block: 12px 0; }
.masthead .pill { flex: 1 1 24rem; }

.pill {
  margin: 0;
  padding: 3px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 0.85rem;
  color: var(--muted);
}

.pill.live { border-color: var(--ok); color: var(--ok); }
.pill.stale { border-color: var(--warn); color: var(--warn); }
.pill.severe { border-color: var(--err); color: var(--err); }

.banner {
  margin: 10px 0 0;
  padding: 8px 12px;
  border-radius: 8px;
  font-size: 0.9rem;
}

.banner.error { border: 1px solid var(--err); background: #2a1b1e; color: var(--err); }

.controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 12px;
  margin-top: 12px;
}

.controls label { color: var(--muted); font-size: 0.85rem; }

.controls nav { display: flex; gap: 6px; margin-left: auto; }

.controls nav button[aria-pressed="true"] {
  border-color: var(--accent);
  background: #1d2a3f;
  color: var(--accent);
}

main {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(320px, 420px);
  gap: 18px;
  padding: 16px 18px 40px;
  align-items: start;
  max-width: 1800px;
  margin-inline: auto;
}

#view-timeline, #view-map, #view-graph, #reports { display: none; }
body[data-view="timeline"] #view-timeline { display: block; grid-column: 1 / -1; }
body[data-view="map"] #view-map, body[data-view="map"] #reports { display: block; }
body[data-view="graph"] #view-graph, body[data-view="graph"] #reports { display: block; }

.hint { color: var(--muted); font-size: 0.85rem; margin: 0 0 12px; }

.empty {
  border: 1px dashed var(--line);
  border-radius: 8px;
  padding: 10px 14px;
  color: var(--muted);
}

ol#timeline, ul#reports-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 12px;
}

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-left: 3px solid var(--line);
  border-radius: 10px;
  padding: 12px 14px;
  min-width: 0;
  overflow-wrap: anywhere;
}

.card.selected {
  border-color: var(--accent);
  border-left-color: var(--accent);
}

.card-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.card-head h3 {
  margin: 0;
  font-size: 1rem;
  color: var(--text);
  flex: 1 1 auto;
  min-width: min(12rem, 100%);
}

.badge {
  font-size: 0.75rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 1px 9px;
  color: var(--muted);
  white-space: nowrap;
}

.badge.confirmed { border-color: var(--ok); color: var(--ok); }
.badge.unconfirmed { border-color: var(--warn); color: var(--warn); }

.card-times {
  margin: 8px 0 4px;
  display: flex;
  flex-wrap: wrap;
  gap: 4px 16px;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 0.82rem;
  color: var(--muted);
}

.card-times .muted { color: var(--muted); }

.card-summary { margin: 6px 0; }

.chips, .sources {
  list-style: none;
  margin: 8px 0 0;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.chip {
  font-size: 0.8rem;
  border: 1px solid var(--line);
  border-left-width: 3px;
  border-radius: 6px;
  padding: 1px 8px;
  color: var(--muted);
}


.sources { flex-direction: column; gap: 2px; font-size: 0.88rem; }
.sources a { display: block; min-height: 44px; padding-block: 10px; word-break: break-all; }

button.select { font-size: 0.8rem; padding: 2px 10px; }
button.select[aria-pressed="true"] { border-color: var(--accent); color: var(--accent); }

#map-wrap {
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: var(--map-bg);
}

#map { display: block; width: 100%; height: auto; }

#graph-wrap {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--map-bg);
  overflow: auto;
  max-height: 72vh;
  max-height: 72dvh;
}

#graph { display: block; }

.world { fill: #182029; stroke: #26313d; stroke-width: 0.5; }
.world.geo-hit { fill: #24344c; stroke: var(--geography); stroke-width: 1.4; }
.grid-frame { fill: none; stroke: var(--line); }

.arrow-head { fill: var(--warn); }

.spread { stroke: var(--warn); stroke-width: 1.4; opacity: 0.65; }
.spread-hit { stroke-width: 2.2; opacity: 1; }

.dot { fill: var(--accent); stroke: var(--map-bg); stroke-width: 1; }
.dot-hit { fill: var(--warn); }

.edge { stroke-width: 1.3; opacity: 0.55; fill: none; }
.edge.ent-agency { stroke: var(--agency); }
.edge.ent-vendor { stroke: var(--vendor); }
.edge.ent-carrier { stroke: var(--carrier); }
.edge.ent-related { stroke: var(--related); }
.edge.ent-geography { stroke: var(--geography); }
.edge.edge-hit { opacity: 1; stroke-width: 2.4; }

.event-box { fill: #1c2632; stroke: #3a4756; }
.entity-box { fill: #161d25; stroke-width: 1.4; }
.entity-box.ent-agency { stroke: var(--agency); }
.entity-box.ent-vendor { stroke: var(--vendor); }
.entity-box.ent-carrier { stroke: var(--carrier); }
.entity-box.ent-related { stroke: var(--related); }
.entity-box.ent-geography { stroke: var(--geography); }

#graph .label {
  fill: var(--text);
  font-size: 13px;
  font-family: inherit;
}

#graph .dim { opacity: 0.18; }

#graph g[role="button"] { cursor: pointer; }
#graph g[role="button"]:focus { outline: none; }
#graph g[role="button"]:focus-visible .event-box,
#graph g[role="button"]:focus-visible.node-hit .event-box {
  stroke: var(--accent);
  stroke-width: 2.4;
}

.legend ul {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 6px;
  font-size: 0.88rem;
}

.legend li { display: flex; align-items: center; gap: 8px; color: var(--muted); }

.sw {
  width: 14px;
  height: 14px;
  border-radius: 4px;
  border: 1px solid var(--line);
  flex: none;
}

.sw.ent-agency { background: var(--agency); }
.sw.ent-vendor { background: var(--vendor); }
.sw.ent-carrier { background: var(--carrier); }
.sw.ent-related { background: var(--related); }
.sw.ent-geography { background: var(--geography); }

@media (min-width: 1200px) {
  #timeline { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 1100px) {
  main { grid-template-columns: minmax(0, 1fr); }
  .controls nav { margin-left: 0; }
}

@media (max-width: 600px), (horizontal-viewport-segments: 2), (vertical-viewport-segments: 2) {
  .top { padding: 12px; }
  main { padding: 14px 12px 28px; }
  .controls { display: grid; grid-template-columns: auto minmax(0, 1fr); }
  .controls nav { grid-column: 1 / -1; }
  .controls nav button { flex: 1; }
  .masthead .pill { order: 2; flex-basis: 100%; border-radius: 8px; }
  #refresh { margin-left: auto; }
  .card { padding: 12px; }
  .card-head h3 { flex-basis: 100%; }
}

/* Safari's optional segment API supplies geometry; never guess a hinge width. */
@media (horizontal-viewport-segments: 2), (vertical-viewport-segments: 2) {
  html { height: 100%; overflow: hidden; }
  body { display: grid; height: 100dvh; padding: 0; }
  .top, main {
    min-height: 0;
    min-width: 0;
    max-width: none;
    margin: 0;
    overflow: auto;
    padding: max(12px, env(safe-area-inset-top, 0px)) max(12px, env(safe-area-inset-right, 0px)) max(12px, env(safe-area-inset-bottom, 0px)) max(12px, env(safe-area-inset-left, 0px));
  }
  main, #timeline { grid-template-columns: minmax(0, 1fr); }
}

@media (horizontal-viewport-segments: 2) {
  body {
    grid-template-columns: env(viewport-segment-width 0 0) calc(env(viewport-segment-left 1 0) - env(viewport-segment-right 0 0)) env(viewport-segment-width 1 0);
    grid-template-rows: minmax(0, 1fr);
  }
  .top { grid-column: 1; }
  main { grid-column: 3; }
}

@media (vertical-viewport-segments: 2) {
  body {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: env(viewport-segment-height 0 0) calc(env(viewport-segment-top 0 1) - env(viewport-segment-bottom 0 0)) env(viewport-segment-height 0 1);
  }
  .top { grid-row: 1; }
  main { grid-row: 3; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
