/* Raincheck NYC public dashboard.
 *
 * Deliberately a single committed dark theme: the map canvas is dark, and a
 * light/dark flip would require a second validated palette for every ramp.
 * Every colour below was validated against the #1a1a19 dark surface with the
 * dataviz palette validator (categorical all-pairs, ordinal ramps, diverging).
 */

.viz-root,
:root {
  color-scheme: dark;

  --page: #0d0d0d;
  --surface-1: #1a1a19;
  --surface-2: #232322;
  --surface-3: #2c2c2a;

  --text-primary: #ffffff;
  --text-secondary: #c3c2b7;
  --text-muted: #898781;

  --grid: #2c2c2a;
  --axis: #383835;
  --border: rgba(255, 255, 255, 0.1);
  --border-strong: rgba(255, 255, 255, 0.18);

  /* categorical — slots 1/2/3, validated all-pairs on dark */
  --series-1: #3987e5;
  --series-2: #d95926;
  --series-3: #199e70;

  /* diverging poles + neutral midpoint */
  --pos: #3987e5;
  --neg: #e66767;
  --mid: #383835;

  --radius: 12px;
  --radius-sm: 8px;
  --font: system-ui, -apple-system, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--page);
  color: var(--text-primary);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
}

/* ── Shell ──────────────────────────────────────────────────────────────── */

.shell {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 0 18px;
  height: 56px;
  flex: 0 0 auto;
  background: var(--surface-1);
  border-bottom: 1px solid var(--border);
}

.brand {
  font-weight: 800;
  font-size: 1.05rem;
  letter-spacing: -0.01em;
  color: var(--text-primary);
  text-decoration: none;
  white-space: nowrap;
}
.brand span { color: var(--series-3); }
.brand { display: inline-flex; align-items: center; gap: 8px; }
.brand-mark { width: 30px; height: 30px; object-fit: contain; }

.topbar .sep {
  width: 1px;
  height: 22px;
  background: var(--border);
}

.topbar h1 {
  font-size: 0.92rem;
  font-weight: 600;
  margin: 0;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar .spacer { flex: 1; }

.topbar .vintage {
  font-size: 0.76rem;
  color: var(--text-muted);
  white-space: nowrap;
}

.topbar .link {
  font-size: 0.85rem;
  color: var(--text-secondary);
  text-decoration: none;
  padding: 6px 11px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  white-space: nowrap;
}
.topbar .link:hover { color: var(--text-primary); border-color: var(--border-strong); }

.body {
  flex: 1;
  display: flex;
  min-height: 0;
}

/* ── Section rail ───────────────────────────────────────────────────────── */

.rail {
  flex: 0 0 auto;
  width: 168px;
  background: var(--surface-1);
  border-right: 1px solid var(--border);
  padding: 12px 10px;
  display: flex;
  flex-direction: column;
  gap: 3px;
  overflow-y: auto;
}

.rail button {
  appearance: none;
  text-align: left;
  background: transparent;
  border: 0;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font: inherit;
  font-size: 0.87rem;
  padding: 9px 11px;
  cursor: pointer;
  line-height: 1.25;
}
.rail button:hover { background: var(--surface-2); color: var(--text-primary); }
.rail button[aria-current="true"] {
  background: var(--surface-3);
  color: var(--text-primary);
  font-weight: 600;
}
.rail button small {
  display: block;
  font-weight: 400;
  font-size: 0.72rem;
  color: var(--text-muted);
  margin-top: 2px;
}

.rail .rail-note {
  margin-top: auto;
  padding: 10px 11px 4px;
  font-size: 0.71rem;
  line-height: 1.45;
  color: var(--text-muted);
  border-top: 1px solid var(--border);
}

/* ── Map ────────────────────────────────────────────────────────────────── */

.stage {
  flex: 1;
  display: flex;
  min-width: 0;
  min-height: 0;
}

.mapwrap {
  position: relative;
  flex: 1;
  min-width: 0;
  background: #101014;
}

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

.maplibregl-ctrl-attrib {
  font-size: 10px;
  background: rgba(13, 13, 13, 0.75) !important;
  color: var(--text-muted);
}
.maplibregl-ctrl-attrib a { color: var(--text-secondary); }

/* Floating overlays on the map */
.overlay {
  position: absolute;
  z-index: 5;
  background: rgba(26, 26, 25, 0.93);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 13px;
}

.metric-switch { top: 12px; left: 12px; min-width: 210px; }
.metric-switch .lab {
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-muted);
  margin-bottom: 8px;
}
.metric-switch .seg { display: flex; flex-direction: column; gap: 2px; }
.metric-switch .seg button {
  appearance: none;
  background: transparent;
  border: 0;
  border-radius: 6px;
  color: var(--text-secondary);
  font: inherit;
  font-size: 0.83rem;
  text-align: left;
  padding: 6px 9px;
  cursor: pointer;
}
.metric-switch .seg button:hover { background: var(--surface-2); color: var(--text-primary); }
.metric-switch .seg button[aria-pressed="true"] {
  background: var(--surface-3);
  color: var(--text-primary);
  font-weight: 600;
}

.legend { bottom: 26px; left: 12px; min-width: 232px; }
.legend .title {
  font-size: 0.74rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 9px;
}
.legend .ramp {
  height: 9px;
  border-radius: 5px;
  margin-bottom: 6px;
}
.legend .ticks {
  display: flex;
  justify-content: space-between;
  font-size: 0.68rem;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}
.legend .items { display: flex; flex-direction: column; gap: 5px; }
.legend .item {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.76rem;
  color: var(--text-secondary);
}
.legend .dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex: 0 0 auto;
  box-shadow: 0 0 0 2px var(--surface-1);
}
.legend .zoomhint {
  margin-top: 9px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
  font-size: 0.7rem;
  color: var(--text-muted);
  line-height: 1.4;
}

/* Hover readout for map features */
.hovercard {
  position: absolute;
  z-index: 7;
  pointer-events: none;
  background: rgba(26, 26, 25, 0.97);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 9px 11px;
  font-size: 0.78rem;
  line-height: 1.5;
  color: var(--text-secondary);
  max-width: 260px;
  display: none;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.5);
}
.hovercard .h {
  color: var(--text-primary);
  font-weight: 600;
  margin-bottom: 3px;
  font-size: 0.82rem;
}
.hovercard .row {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  font-variant-numeric: tabular-nums;
}
.hovercard .row span:last-child { color: var(--text-primary); }

.mapbadge {
  position: absolute;
  z-index: 5;
  top: 12px;
  right: 12px;
  font-size: 0.72rem;
  color: var(--text-muted);
  background: rgba(26, 26, 25, 0.93);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 5px 11px;
  font-variant-numeric: tabular-nums;
}

/* ── Side panel ─────────────────────────────────────────────────────────── */

.panel {
  flex: 0 0 auto;
  width: 372px;
  background: var(--surface-1);
  border-left: 1px solid var(--border);
  overflow-y: auto;
  padding: 14px;
}

.panel h2 {
  font-size: 0.95rem;
  margin: 0 0 4px;
  font-weight: 650;
}
.panel .lede {
  font-size: 0.79rem;
  line-height: 1.55;
  color: var(--text-secondary);
  margin: 0 0 14px;
}

.tiles {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 14px;
}
.tile {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 11px;
}
.tile .k {
  font-size: 0.68rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  line-height: 1.3;
}
.tile .v {
  font-size: 1.32rem;
  font-weight: 700;
  margin-top: 3px;
  letter-spacing: -0.02em;
}
.tile .s {
  font-size: 0.7rem;
  color: var(--text-muted);
  margin-top: 1px;
}

.card {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px;
  margin-bottom: 10px;
}
.card .hd {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 2px;
}
.card h3 {
  font-size: 0.82rem;
  font-weight: 620;
  margin: 0;
  flex: 1;
}
.card .sub {
  font-size: 0.72rem;
  color: var(--text-muted);
  margin: 0 0 10px;
  line-height: 1.45;
}
.card .toggle {
  appearance: none;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
  font: inherit;
  font-size: 0.67rem;
  padding: 2px 7px;
  border-radius: 5px;
  cursor: pointer;
  flex: 0 0 auto;
}
.card .toggle:hover { color: var(--text-primary); border-color: var(--border-strong); }

/* charts */
.chart svg { display: block; width: 100%; overflow: visible; }
.chart .gridline { stroke: var(--grid); stroke-width: 1; }
.chart .axisline { stroke: var(--axis); stroke-width: 1; }
.chart .tick {
  fill: var(--text-muted);
  font-size: 9.5px;
  font-variant-numeric: tabular-nums;
}
.chart .dlabel {
  fill: var(--text-secondary);
  font-size: 9.5px;
  font-variant-numeric: tabular-nums;
}
.chart .bar { transition: opacity 0.12s; }
.chart .hit { fill: transparent; cursor: pointer; }
.chart:hover .bar { opacity: 0.55; }
.chart .bar.on, .chart:hover .bar.on { opacity: 1; }

.tablewrap { overflow-x: auto; }
table.dt {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.73rem;
  font-variant-numeric: tabular-nums;
}
table.dt th, table.dt td {
  text-align: right;
  padding: 5px 6px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
table.dt th {
  color: var(--text-muted);
  font-weight: 600;
  text-align: right;
  position: sticky;
  top: 0;
  background: var(--surface-2);
}
table.dt th:first-child, table.dt td:first-child { text-align: left; }
table.dt td { color: var(--text-secondary); }
table.dt tr:last-child td { border-bottom: 0; }

.legend-inline {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 13px;
  margin-top: 9px;
  font-size: 0.72rem;
  color: var(--text-secondary);
}
.legend-inline .li { display: flex; align-items: center; gap: 6px; }
.legend-inline .sw {
  width: 9px;
  height: 9px;
  border-radius: 2px;
  box-shadow: 0 0 0 2px var(--surface-2);
}

.prose { font-size: 0.79rem; line-height: 1.6; color: var(--text-secondary); }
.prose p { margin: 0 0 9px; }
.prose strong { color: var(--text-primary); font-weight: 620; }
.prose code {
  background: var(--surface-3);
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 0.92em;
}
.prose ol, .prose ul { margin: 0 0 9px; padding-left: 18px; }
.prose li { margin-bottom: 5px; }

.tierlist { display: flex; flex-direction: column; gap: 6px; }
.tierrow {
  display: flex;
  align-items: center;
  gap: 9px;
  font-size: 0.77rem;
  color: var(--text-secondary);
}
.tierrow .bar {
  height: 8px;
  border-radius: 4px;
  background: var(--series-1);
  flex: 0 0 auto;
}
.tierrow .lab { flex: 1; }
.tierrow .val { color: var(--text-primary); font-weight: 600; font-variant-numeric: tabular-nums; }

.disclaim {
  font-size: 0.7rem;
  color: var(--text-muted);
  line-height: 1.5;
  padding: 10px 2px 4px;
  border-top: 1px solid var(--border);
  margin-top: 4px;
}

.loading {
  position: absolute;
  inset: 0;
  z-index: 9;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--page);
  color: var(--text-muted);
  font-size: 0.85rem;
  transition: opacity 0.35s;
}
.loading.done { opacity: 0; pointer-events: none; }

/* ── Responsive ─────────────────────────────────────────────────────────── */

@media (max-width: 1080px) {
  .panel { width: 320px; }
}

@media (max-width: 860px) {
  .shell { height: auto; min-height: 100vh; }
  .body { flex-direction: column; }
  .rail {
    width: 100%;
    flex-direction: row;
    overflow-x: auto;
    border-right: 0;
    border-bottom: 1px solid var(--border);
    padding: 8px;
  }
  .rail button { white-space: nowrap; }
  .rail button small { display: none; }
  .rail .rail-note { display: none; }
  .stage { flex-direction: column; }
  .mapwrap { height: 58vh; flex: 0 0 auto; }
  .panel {
    width: 100%;
    border-left: 0;
    border-top: 1px solid var(--border);
    overflow-y: visible;
  }
  .topbar h1 { display: none; }
  .topbar .vintage { display: none; }
}

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

/* ── Hardware section ── */
.plate { background: #fff; border: 1px solid var(--border); border-radius: 8px; overflow-x: auto; margin: 6px 0 4px; }
.plate svg { display: block; width: 100%; height: auto; }
.plate-detail svg { max-width: 320px; margin: 0 auto; }
.plate-section svg { min-width: 560px; }
ol.keys { list-style: none; margin: 8px 0 14px; padding: 0; display: grid; gap: 0; }
ol.keys li { display: grid; grid-template-columns: 24px 1fr; gap: 10px; align-items: start; padding: 9px 0; border-top: 1px solid var(--border); font-size: 0.86rem; line-height: 1.45; }
ol.keys .num { font-size: 0.72rem; font-weight: 600; line-height: 22px; text-align: center; color: #A3382B; border: 1.5px solid #A3382B; border-radius: 50%; width: 22px; height: 22px; }
ol.keys .kbody { display: block; }
ol.keys strong { display: block; font-weight: 600; }
