* { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: system-ui, -apple-system, sans-serif;
  line-height: 1.5;
  color: #1a1a1a;
  max-width: 960px;
  margin: 0 auto;
  padding: 1rem;
}
h1 { margin-bottom: 0.5rem; }
.abstract {
  margin: 0.5rem 0 1rem;
  padding: 0.75rem 1rem 0.75rem 1.25rem;
  background: #f5f7fa;
  border-left: 4px solid #4a7cbf;
  border-radius: 4px;
}
.abstract ol {
  margin: 0 0 0.4rem 1.2rem;
}
.abstract li {
  margin-bottom: 0.15rem;
}
.abstract .abstract-links {
  margin: 0.3rem 0 0;
  font-size: 0.9rem;
  color: #555;
}
h2 { margin: 1.5rem 0 0.75rem; border-bottom: 2px solid #e0e0e0; padding-bottom: 0.25rem; }
h3 { margin: 0.75rem 0 0.5rem; }
.ai-explainer {
  margin: 0.5rem 0 1rem;
  padding: 0.9rem 1rem;
  background: #fff76a;
  border: 2px dashed #3d2f00;
  border-radius: 6px;
  color: #1f1300;
  font-family: "Courier New", Courier, monospace;
  line-height: 1.45;
}
.ai-explainer summary {
  cursor: pointer;
  font-weight: 700;
  font-size: 1rem;
  margin: 0 0 0.45rem;
}
.ai-explainer h2 {
  margin: 0.6rem 0 0.45rem;
  border: 0;
  padding: 0;
  font-size: 1rem;
}
.ai-explainer p {
  margin: 0 0 0.45rem;
}
.ai-explainer ul {
  margin: 0.25rem 0 0.45rem 1.2rem;
}
.ai-explainer a {
  color: #7a001f;
  font-weight: 700;
}

/* Rate estimator */
.ci-bar-container {
  position: relative;
  height: 28px;
  margin: 0.5rem 0;
  background: #f0f0f0;
  border-radius: 4px;
  overflow: hidden;
}
.ci-bar {
  position: absolute;
  height: 100%;
  background: #b0d0ff;
  border-radius: 4px;
}
.ci-median {
  position: absolute;
  width: 3px;
  height: 100%;
  background: #2060c0;
  border-radius: 1px;
}
.ci-labels {
  display: flex;
  justify-content: space-between;
  font-size: 0.75rem;
  color: #888;
}

/* Incident browser */
.filters { margin: 0.5rem 0; display: flex; gap: 0.25rem; flex-wrap: wrap; }
.filters button {
  padding: 0.25rem 0.75rem;
  border: 1px solid #ccc;
  border-radius: 4px;
  background: #fff;
  cursor: pointer;
  font-size: 0.85rem;
}
.filters button:not(.active):hover { background: #f0f4fa; border-color: #9bb3d4; }
.filters button.active { background: #2060c0; color: #fff; border-color: #2060c0; }
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
  margin-top: 0.5rem;
}
th, td { padding: 0.35rem 0.5rem; text-align: left; border-bottom: 1px solid #e0e0e0; }
th { background: #f5f5f5; position: sticky; top: 0; }
th .sort-arrow { font-size: 0.7em; margin-left: 0.2em; }
tr:hover { background: #f8f8ff; }
/* Scroll container so the sticky header actually sticks (and hundreds of
   incident rows don't make the page itself miles long) */
.table-scroll { overflow: auto; max-height: 80vh; }
.table-scroll th {
  cursor: pointer;
  user-select: none;
  /* border-collapse drops sticky-header borders while stuck; box-shadow stands in */
  border-bottom: none;
  box-shadow: 0 1px 0 #e0e0e0;
}
.table-scroll th:hover { background: #e8e8e8; }
.table-scroll th:focus-visible { outline: 2px solid #2060c0; outline-offset: -2px; }
.table-scroll tbody tr:nth-child(even) { background: #fafbfd; }
.table-scroll tbody tr:hover { background: #f3f6ff; }
.narrative-cell {
  max-width: 300px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  cursor: pointer;
}
.narrative-cell.expanded { white-space: normal; }
.cbi { color: #999; font-style: italic; }
.incident-count { font-size: 0.9rem; color: #666; margin: 0.25rem 0; }
.fault-cell {
  font-variant-numeric: tabular-nums;
  text-align: center;
  white-space: nowrap;
  cursor: help;
}
.fault-bar {
  display: inline-block;
  height: 14px;
  border-radius: 2px;
  vertical-align: middle;
  margin-right: 4px;
}

/* Monthly views */
.month-panel {
  border: 1px solid #d0d0d0;
  border-radius: 6px;
  padding: 1rem;
  margin-bottom: 1rem;
  background: #fafafa;
}
.month-note {
  font-size: 0.9rem;
  color: #5b6475;
  margin-bottom: 0.6rem;
}
/* Date range slider */
#date-range-controls {
  margin: 0.6rem 0 0.4rem;
}
.date-range-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.2rem;
}
.date-range-label {
  font-size: 0.82rem;
  color: #5b6475;
  font-weight: 600;
}
.month-panel.date-filtered {
  border-color: #2060c0;
  background: #f8faff;
}
.date-filtered .date-range-label {
  background: #e0ecff;
  padding: 0.1rem 0.5rem;
  border-radius: 3px;
  color: #1a4a8a;
}
.date-range-slider {
  position: relative;
  height: 24px;
  margin-bottom: 20px;
}
.date-range-track {
  position: absolute;
  left: 0;
  right: 0;
  top: 50%;
  height: 4px;
  transform: translateY(-50%);
  background: #dde2ea;
  border-radius: 2px;
}
.date-range-fill {
  position: absolute;
  top: 50%;
  height: 4px;
  transform: translateY(-50%);
  background: #2060c0;
  border-radius: 2px;
}
.date-range-input {
  -webkit-appearance: none;
  appearance: none;
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  background: transparent;
  margin: 0;
  padding: 0;
  pointer-events: none;
  outline: none;
}
.date-range-input-min { z-index: 2; }
.date-range-input-max { z-index: 3; }
.date-range-input::-webkit-slider-runnable-track {
  height: 4px;
  background: transparent;
  border: none;
}
.date-range-input::-webkit-slider-thumb {
  -webkit-appearance: none;
  pointer-events: auto;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #2060c0;
  border: 2px solid #fff;
  box-shadow: 0 1px 3px rgba(0,0,0,0.25);
  cursor: grab;
  margin-top: -6px;
}
.date-range-input::-moz-range-track {
  height: 4px;
  background: transparent;
  border: none;
}
.date-range-input::-moz-range-thumb {
  pointer-events: auto;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #2060c0;
  border: 2px solid #fff;
  box-shadow: 0 1px 3px rgba(0,0,0,0.25);
  cursor: grab;
}
.date-range-input:focus-visible::-webkit-slider-thumb {
  box-shadow: 0 0 0 3px rgba(32, 96, 192, 0.35);
}
.date-range-input:focus-visible::-moz-range-thumb {
  box-shadow: 0 0 0 3px rgba(32, 96, 192, 0.35);
}
.date-range-end-label {
  position: absolute;
  top: 20px;
  font-size: 10px;
  color: #5b6475;
  white-space: nowrap;
  pointer-events: none;
}
.date-range-end-label.min { left: 0; }
.date-range-end-label.max { right: 0; }
.date-range-tick {
  position: absolute;
  top: 50%;
  transform: translateX(-50%);
  z-index: 1;
  pointer-events: none;
}
.date-range-tick-line {
  width: 1px;
  height: 14px;
  background: #5b6475;
  margin: -7px auto 0;
}
.date-range-tick-label {
  font-size: 10px;
  color: #5b6475;
  text-align: center;
  margin-top: 1px;
  white-space: nowrap;
}

.month-chart {
  margin-bottom: 0.8rem;
}
.month-chart h3 {
  margin: 0 0 0.35rem;
}
.month-helmer-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.9rem;
}
.month-svg {
  width: 100%;
  height: auto;
  display: block;
  background: #fff;
  border: 1px solid #dfe4ef;
  border-radius: 4px;
}
.month-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.7rem;
  margin-top: 0.3rem;
  font-size: 0.82rem;
}
#month-legend-speed {
  row-gap: 0.25rem;
}
#month-legend-mpi-helmers {
  gap: 1.5rem;
}
#month-legend-mpi-lines {
  flex-direction: column;
  gap: 0.25rem;
}
.month-legend-item {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}
.month-legend-label {
  font-weight: 600;
  font-size: 0.78rem;
  color: #5b6475;
}
.month-legend-break {
  flex-basis: 100%;
  height: 0;
}
.month-helmer-toggle {
  cursor: pointer;
  user-select: none;
}
.month-helmer-toggle input[type="checkbox"],
.month-helmer-toggle input[type="radio"] {
  margin: 0 0.2rem 0 0;
}
.month-chip {
  width: 12px;
  height: 12px;
  border-radius: 3px;
  border: 1px solid rgba(0, 0, 0, 0.18);
  display: inline-block;
}
.ci-fan-swatch {
  width: 14px;
  height: 12px;
  border-radius: 2px;
  display: inline-block;
}
.month-grid {
  display: none;
}
.month-axis {
  stroke: #95a0b8;
  stroke-width: 1;
}
.month-vmt-line {
  fill: none;
  stroke-width: 2;
}
.month-mpi-all-line {
  fill: none;
}
.month-inc-count {
  fill: #131313;
  font-size: 9px;
  font-weight: 600;
  text-anchor: middle;
  dominant-baseline: middle;
  paint-order: stroke;
  stroke: #fff;
  stroke-width: 2px;
}
.month-inc-total {
  fill: #131313;
  font-size: 10px;
  font-weight: 700;
  text-anchor: middle;
  dominant-baseline: middle;
}
.month-dot {
  stroke: #fff;
  stroke-width: 1.5;
}
.month-linekey {
  width: 22px;
  height: 0;
  border-top: 2.5px solid #4a5264;
  display: inline-block;
}
.month-linekey.solid {
  border-top-width: 2.5px;
}
.month-linekey.dashed {
  border-top-width: 1.5px;
}
.month-linekey.atfault {
  border-top-width: 1px;
}
.month-tri {
  width: 0;
  height: 0;
  border-left: 4px solid transparent;
  border-right: 4px solid transparent;
  border-bottom: 7px solid #4a5264;
  display: inline-block;
  transform: translateY(1px);
}
.month-err {
  stroke-width: 1.4;
  opacity: 0.9;
}
.month-mark-tri {
  stroke-width: 1.4;
}
.month-tick {
  fill: #5b6475;
  font-size: 10px;
}
.month-label {
  fill: #334;
  font-size: 11px;
}
.mpi-cards {
  display: flex;
  gap: 0.6rem;
  margin: 0.6rem 0;
}
.mpi-card {
  flex: 1;
  background: #fff;
  border: 1px solid #dfe4ef;
  border-radius: 4px;
  border-left: 3px solid #999;
  padding: 0.5rem 0.65rem;
}
.mpi-card-helmer {
  font-weight: 600;
  font-size: 0.85rem;
  margin-bottom: 0.15rem;
}
.mpi-card-vmt {
  font-size: 0.75rem;
  color: #8090a8;
  margin-bottom: 0.35rem;
  font-variant-numeric: tabular-nums;
}
.mpi-card-stress {
  font-size: 0.72rem;
  color: #5b6475;
  margin-bottom: 0.45rem;
  font-variant-numeric: tabular-nums;
}
.mpi-card-metric {
  margin-bottom: 0.4rem;
  font-size: 0.82rem;
  line-height: 1.45;
}
.mpi-card-metric:last-child {
  margin-bottom: 0;
}
.mpi-card-metric:not(.primary) {
  color: #5b6475;
}
.mpi-card-formula {
  font-variant-numeric: tabular-nums;
}
.mpi-card-mpi {
  font-weight: 600;
}
.mpi-card-metric.primary .mpi-card-mpi {
  font-size: 0.95rem;
}
.mpi-card-mult {
  font-size: 0.7rem;
  font-weight: 600;
  margin-left: 0.3em;
  opacity: 0.7;
}
.mpi-card-mult.safer { color: #2a7a3a; }
.mpi-card-mult.worse { color: #a04030; }
.mpi-card-ci {
  font-size: 0.72rem;
  color: #8090a8;
}
.mpi-card-src {
  cursor: help;
  color: #6080b0;
  font-size: 0.65rem;
}
.mpi-card-sources {
  font-size: 0.65rem;
  color: #6080b0;
  margin-top: 0.1rem;
}
.mpi-card-sources a {
  color: #4060a0;
}
.mpi-card-vmt a {
  color: #4060a0;
}
.source-table {
  font-size: 0.8rem;
  border-collapse: collapse;
  margin: 0.5rem 0;
  width: 100%;
}
.source-table th, .source-table td {
  border: 1px solid #bba;
  padding: 0.25rem 0.5rem;
  text-align: left;
}
.source-table th {
  background: #eee3c0;
}
.source-table td:nth-child(2), .source-table td:nth-child(3) {
  text-align: right;
  white-space: nowrap;
}
.source-table a {
  color: #7a001f;
  font-weight: 700;
}
.stress-table td:nth-child(3),
.stress-table td:nth-child(4),
.stress-table td:nth-child(5),
.stress-table td:nth-child(6) {
  text-align: right;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.stress-badge {
  font-weight: 700;
}
.stress-badge.safer {
  color: #2a7a3a;
}
.stress-badge.worse {
  color: #a04030;
}
.stress-badge.ambiguous {
  color: #8a6f19;
}
#sanity-checks p {
  margin: 0.45rem 0 0.7rem;
}
.mpi-card-metric.highlighted {
  background: #eef3ff;
  border-radius: 3px;
  padding: 0.15rem 0.3rem;
  margin-left: -0.3rem;
  margin-right: -0.3rem;
}
.mpi-card-metric.highlighted:not(.primary) {
  color: #333;
}
@media (max-width: 760px) {
  .mpi-cards {
    flex-direction: column;
  }
  body {
    padding: 0.75rem;
  }
  .month-panel {
    padding: 0.75rem;
  }
  .month-tick {
    font-size: 11px;
  }
  .month-label {
    font-size: 12px;
  }
  .month-inc-count {
    font-size: 8px;
  }
  .month-inc-total {
    font-size: 9px;
  }
}

/* Prediction markets panel */
.polymarket-panel {
  margin: 0.5rem 0 1.5rem;
}
.polymarket-loading {
  font-size: 0.85rem;
  color: #888;
  font-style: italic;
}
.polymarket-error {
  font-size: 0.85rem;
  color: #a04030;
}
.polymarket-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0;
}
.pm-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.6rem;
  background: #fff;
  border: 1px solid #e3e8ee;
  border-top: none;
  padding: 0.45rem 0.65rem;
}
.pm-card:first-child { border-top: 1px solid #e3e8ee; border-radius: 4px 4px 0 0; }
.pm-card:last-child { border-radius: 0 0 4px 4px; }
.pm-card:only-child { border-top: 1px solid #e3e8ee; border-radius: 4px; }
.pm-card-question {
  font-size: 0.82rem;
  line-height: 1.3;
  flex: 1;
  color: #3c4257;
}
.pm-card-question a {
  color: #3c4257;
  text-decoration: none;
}
.pm-card-question a:hover {
  color: #556cd6;
}
.pm-card-odds {
  font-family: "SF Mono", "Menlo", "Consolas", monospace;
  font-size: 0.85rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  min-width: 3em;
  text-align: right;
}
.pm-card-odds.high { color: #0e6245; }
.pm-card-odds.mid  { color: #9c6f19; }
.pm-card-odds.low  { color: #cd3d64; }
.pm-card-vol {
  font-family: "SF Mono", "Menlo", "Consolas", monospace;
  font-size: 0.68rem;
  color: #8792a2;
  white-space: nowrap;
  min-width: 3.5em;
  text-align: right;
}
.pm-subcard {
  padding-left: 1.4rem;
  background: #f7f8fa;
}
.pm-subcard .pm-card-question { font-size: 0.8rem; }
.pm-subcard .pm-card-odds { font-size: 0.8rem; }
.pm-footer {
  display: flex;
  align-items: center;
  gap: 0.5em;
  font-size: 0.75rem;
  color: #697386;
  margin-top: 0.45rem;
  justify-content: flex-end;
}
.pm-footer a { color: #556cd6; text-decoration: none; }
.pm-footer a:hover { text-decoration: underline; }
.pm-dot {
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  vertical-align: middle;
}
.pm-dot.fresh  { background: #2a7a3a; }
.pm-dot.stale  { background: #c88a04; }
.pm-dot.rotten { background: #cd3d64; }
.pm-age {
  font-family: "SF Mono", "Menlo", "Consolas", monospace;
  font-size: 0.7rem;
  font-variant-numeric: tabular-nums;
  color: #697386;
}
.pm-refresh {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  background: transparent;
  border: 1px solid #e0e6ed;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.8rem;
  color: #697386;
  padding: 0;
  transition: background 0.12s, border-color 0.12s, color 0.12s;
}
.pm-refresh:hover { background: #f7f8fa; border-color: #c1c9d2; color: #3c4257; }
.pm-refresh:disabled { cursor: default; opacity: 0.35; }

.colophon {
  margin-top: 2rem;
  padding: 0.5rem 0;
  font-size: 0.8rem;
  color: #888;
  text-align: center;
}

/* Floating tooltip (replaces SVG <title> for mobile support) */
.chart-tip {
  display: none;
  position: fixed;
  z-index: 1000;
  max-width: 320px;
  padding: 0.5rem 0.65rem;
  background: #1a1a1a;
  color: #f0f0f0;
  font-size: 0.78rem;
  line-height: 1.45;
  border-radius: 4px;
  white-space: pre-line;
  pointer-events: none;
  box-shadow: 0 2px 8px rgba(0,0,0,0.25);
  font-variant-numeric: tabular-nums;
}
