:root {
  --ink: #101a21;
  --paper: #f4f6f3;
  --accent: #01796f;
  --accent-2: #bd5d38;
  --good: #0f7d3e;
  --warn: #a44322;
  --card: #fefcf8cc;
  --line: #d8ddd8;
  --mono: "IBM Plex Mono", monospace;
  --sans: "Space Grotesk", sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--sans);
  color: var(--ink);
  background:
    radial-gradient(1200px 600px at 15% -10%, #dff0e8 0%, transparent 60%),
    radial-gradient(900px 500px at 100% 100%, #f6e6d6 0%, transparent 55%),
    linear-gradient(180deg, #f7faf7 0%, #f4f6f3 100%);
  min-height: 100vh;
  overflow-x: hidden;
}

.bg-shape { display: none; }

.topbar {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 16px 28px 12px;
  border-bottom: 1px solid #e6ebe4;
  background: rgba(255,255,255,0.55);
  backdrop-filter: saturate(1.2) blur(6px);
}
.topbar-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 24px;
  flex-wrap: wrap;
}
.topbar-actions {
  display: flex;
  gap: 6px;
  align-items: center;
  flex-wrap: wrap;
}

.kicker {
  margin: 0;
  font: 600 11px var(--mono);
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: #4c6a72;
}

.logo {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: inherit;
}
.logo-mark {
  display: block;
  filter: drop-shadow(0 1px 2px rgba(1, 121, 111, 0.25));
  transition: transform 120ms ease;
}
.logo:hover .logo-mark { transform: translateY(-1px); }
.logo-word {
  font: 700 12px var(--mono);
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: #35555f;
  white-space: nowrap;
}
.logo-word-accent { color: var(--accent-2); }
h1 { margin: 2px 0 4px; font-size: clamp(1.05rem, 1.9vw, 1.5rem); font-weight: 700; }
h2 { margin: 0; font-size: 1rem; }
.muted { margin: 0; color: #4d666f; font: 400 12px var(--mono); }
.title-row {
  display: flex;
  align-items: baseline;
  gap: 12px;
  flex-wrap: wrap;
}
.title-row h1 { margin: 0; }
.title-refresh { margin-bottom: 0; }

main { padding: 10px 20px 24px; }
.stack {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

#evMain {
  max-width: 1100px;
  margin: 0 auto;
}

.panel {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 14px;
  box-shadow: 0 7px 25px #162d3111;
}
.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}

.pill-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 0 28px 10px;
}
.pill {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 6px 10px;
  background: #fff;
  font: 500 12px var(--mono);
  color: var(--ink);
}

.badge {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  font: 500 12px var(--mono);
}

.btn-link {
  display: inline-block;
  padding: 6px 12px;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  text-decoration: none;
  font: 500 12px var(--mono);
  letter-spacing: 0.02em;
  transition: background 100ms ease, color 100ms ease, border-color 100ms ease;
}
.btn-link:hover { background: var(--ink); }
.btn-ghost {
  background: transparent;
  color: #35555f;
  border: 1px solid transparent;
}
.btn-ghost:hover {
  background: rgba(255,255,255,0.7);
  color: var(--ink);
  border-color: var(--line);
}
.btn-ghost.is-current {
  background: rgba(1, 121, 111, 0.08);
  color: var(--accent);
  border-color: rgba(1, 121, 111, 0.25);
  pointer-events: none;
}

.toggle {
  display: inline-flex;
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
  background: #fff;
}
.toggle-btn {
  border: 0;
  background: transparent;
  padding: 8px 14px;
  font: 500 13px var(--mono);
  color: var(--ink);
  cursor: pointer;
}
.toggle-btn.is-active {
  background: var(--accent);
  color: #fff;
}

.toggle-mini {
  border-radius: 6px;
}
.toggle-mini .toggle-btn {
  padding: 2px 8px;
  font: 500 10px var(--mono);
}

.inline-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  font: 12px var(--mono);
  flex-wrap: wrap;
}
input, select {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 6px 8px;
  background: #fff;
  font: 500 12px var(--mono);
}

.table-wrap { overflow: auto; }
table { width: 100%; border-collapse: collapse; }
th, td {
  border-bottom: 1px solid var(--line);
  padding: 8px;
  text-align: left;
  font-size: 12px;
}
th {
  font: 600 11px var(--mono);
  color: #3f5d66;
  letter-spacing: 0.3px;
  text-transform: uppercase;
}
.ev-good { color: var(--good); font-weight: 700; }
.ev-bad  { color: var(--warn); }
.action  { font: 700 12px var(--mono); }

.cities-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 16px;
}
.city-card .city-day { margin-top: 10px; }
.city-card .city-day h4 {
  margin: 0 0 4px;
  font: 600 13px var(--mono);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--accent);
}
.city-card .city-day ul { list-style: none; margin: 0; padding: 0; }
.city-card .city-day li {
  padding: 0;
  border-top: 1px dashed var(--line);
  font-size: 13px;
}
.city-card .city-day li:first-child { border-top: none; }

.event-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  padding: 6px 8px;
  color: var(--ink);
  text-decoration: none;
  border-left: 3px solid transparent;
  border-radius: 4px;
  transition: background 80ms, border-color 80ms;
}
.event-row-q { flex: 1 1 auto; min-width: 0; }
.event-row-ev {
  flex: 0 0 auto;
  font: 600 12px var(--mono);
  white-space: nowrap;
}
.event-row:hover {
  background: var(--paper);
  border-left-color: var(--accent);
  cursor: pointer;
}

.qc-good { color: var(--good); font-weight: 600; }
.qc-warn { color: #b8860b; font-weight: 600; }
.qc-bad  { color: var(--warn); font-weight: 700; }
.qc-cell-bad  { background: #fce8e1; }
.qc-cell-warn { background: #fdf3dc; }

.kv {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 4px 14px;
  font: 12px var(--mono);
}
.kv dt { color: #4d666f; }
.kv dd { margin: 0; word-break: break-all; }

.counts-grid {
  display: grid;
  grid-template-columns: max-content repeat(4, 1fr);
  gap: 4px 14px;
  font: 12px var(--mono);
  align-items: baseline;
}
.counts-grid .h { color: #4d666f; text-transform: uppercase; font-size: 11px; }
.counts-grid .v { text-align: right; }

.chart-box {
  width: 100%;
  overflow-x: auto;
}
.chart-box svg { display: block; }
.chart-box .axis text { font: 10px var(--mono); fill: #4d666f; }
.chart-box .axis line, .chart-box .axis path { stroke: #cfd6d2; }
.chart-box .grid line { stroke: #e4e8e3; stroke-dasharray: 2 3; }
.chart-box .series-market { stroke: var(--accent); fill: none; stroke-width: 1.5; }
.chart-box .series-model  { stroke: var(--accent-2); fill: none; stroke-width: 1.5; stroke-dasharray: 4 3; }
.chart-box .series-quote  { stroke: #8aa4ad; fill: none; stroke-width: 1; }
.chart-box .series-quote-bid { stroke: #0f7d3e; fill: none; stroke-width: 1.2; }
.chart-box .series-quote-ask { stroke: #bd5d38; fill: none; stroke-width: 1.2; }
.chart-box .series-trade  { stroke: #444; fill: none; stroke-width: 1; stroke-dasharray: 1 2; }
.chart-box .series-yes-mid   { stroke: #01796f; fill: none; stroke-width: 1.6; }
.chart-box .series-no-mid    { stroke: #5b3a8a; fill: none; stroke-width: 1.6; }
.chart-box .series-yes-quote { stroke: #01796f; fill: none; stroke-width: 0.8; opacity: 0.45; }
.chart-box .series-no-quote  { stroke: #5b3a8a; fill: none; stroke-width: 0.8; opacity: 0.45; }

/* ── Model vs market distribution chart ─────────────────────────────── */
.dist-caption {
  margin: 0 0 12px;
  font-size: 12px;
  line-height: 1.5;
}
.dist-legend-swatch {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 2px;
  vertical-align: middle;
  margin: 0 2px 0 4px;
}
.dist-swatch-model  { background: var(--accent-2); }
.dist-swatch-market { background: var(--accent); opacity: 0.55; }

.dist-svg {
  width: 100%;
  height: auto;
  max-height: 320px;
}
.dist-svg .dist-grid { stroke: #e4e8e3; stroke-dasharray: 2 3; stroke-width: 1; }
.dist-svg .dist-axis { stroke: #8aa4ad; stroke-width: 1; }
.dist-svg .dist-tick { font: 10px var(--mono); fill: #4d666f; }
.dist-svg .dist-axis-label { font: 600 11px var(--mono); fill: #35555f; }
.dist-svg .dist-bar-market {
  fill: var(--accent);
  opacity: 0.35;
  stroke: var(--accent);
  stroke-width: 0.5;
  stroke-opacity: 0.6;
}
.dist-svg .dist-bar-model {
  fill: var(--accent-2);
  opacity: 0.85;
  stroke: var(--accent-2);
  stroke-width: 0.5;
}
.dist-svg .dist-bin-current {
  fill: none;
  stroke: var(--accent);
  stroke-width: 2;
  stroke-dasharray: 4 3;
  opacity: 0.9;
}

.dist-stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-top: 12px;
}
.dist-stat {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.55);
}
.dist-stat-label {
  font: 600 10px var(--mono);
  text-transform: uppercase;
  color: #4d666f;
  letter-spacing: 0.04em;
}
.dist-stat-value {
  font: 700 18px var(--mono);
  color: var(--fg, #1a2226);
}
.dist-stat-sub {
  font: 400 11px var(--mono);
  color: #4d666f;
}

#evTitle {
  font-size: clamp(1.15rem, 2vw, 1.7rem);
}
#evTitle:empty {
  display: none;
}

.event-primary-grid {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.event-summary {
  display: flex;
  flex-direction: column;
  gap: 12px;
  align-items: start;
}
.event-summary-copy {
  width: 100%;
}
.event-summary-title {
  margin: 0 0 8px;
  font-size: clamp(1.05rem, 1.7vw, 1.45rem);
  line-height: 1.25;
}
.event-summary-meta {
  margin: 0;
  color: #35555f;
  font: 600 12px var(--mono);
}
.event-chart-wrap {
  width: 100%;
}
.event-chart-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}
.event-chart-wrap .panel {
  height: 100%;
}
.quote-cards {
  width: 100%;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}
.quote-card {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.6);
  padding: 0;
  overflow: hidden;
}
.quote-card-head {
  margin: 0;
  padding: 10px 14px;
  color: #fff;
  background: var(--accent);
  font: 700 13px var(--mono);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  border-bottom: 1px solid rgba(0,0,0,0.08);
}
.quote-card.qc-side-yes .quote-card-head { background: #01796f; }
.quote-card.qc-side-no  .quote-card-head { background: #5b3a8a; }
.quote-card-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px 12px;
  align-items: end;
  padding: 12px 14px 14px;
}
.summary-metrics {
  width: 100%;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}
.summary-metric {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.55);
  padding: 10px 12px;
  min-width: 0;
}
.summary-metric-label {
  display: block;
  margin-bottom: 5px;
  color: #4d666f;
  font: 600 11px var(--mono);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.summary-metric-value {
  display: block;
  font: 700 16px var(--sans);
  color: var(--ink);
  overflow-wrap: anywhere;
}

.summary-alert {
  margin-top: 10px;
  border-radius: 10px;
  padding: 10px 12px;
  border: 1px solid;
  font: 600 12px var(--mono);
}
.summary-alert.good {
  background: #eaf6ee;
  border-color: #8fcca2;
  color: #16512f;
}
.summary-alert.warn {
  background: #fff3d8;
  border-color: #d8b441;
  color: #6b4d00;
}
.summary-alert.bad {
  background: #fce2de;
  border-color: #c8543b;
  color: #7b1f12;
}

.diagnostics {
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--card);
  box-shadow: 0 7px 25px #162d3111;
  padding: 0;
}
.diagnostics > summary {
  list-style: none;
  cursor: pointer;
  padding: 14px 16px;
  font: 700 13px var(--mono);
  display: flex;
  justify-content: space-between;
  gap: 12px;
}
.diagnostics > summary::-webkit-details-marker { display: none; }
.diagnostics-body {
  padding: 0 14px 14px;
}

.flags-banner {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 12px;
}
.flags-banner.good { background: #eff8f1; }
.flags-banner.warn { background: #fff7df; }
.flags-banner.bad  { background: #fae4df; }
.flags-banner-label {
  display: inline-block;
  margin-bottom: 6px;
  font: 700 12px var(--mono);
}
.flags-banner ul {
  margin: 0;
  padding-left: 18px;
  font: 12px var(--mono);
}

.json-dump {
  margin: 0;
  overflow: auto;
  max-height: 440px;
  font: 11px var(--mono);
  line-height: 1.45;
}

.trades-table {
  width: 100%;
  border-collapse: collapse;
}
.trades-table td,
.trades-table th {
  vertical-align: top;
}
.trade-score {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 8.2rem;
  padding: 4px 8px;
  border-radius: 999px;
  background: #edf4ef;
  color: #33545a;
  font: 700 11px var(--mono);
}
.trade-row-score,
.trade-row-close {
  white-space: nowrap;
}
.trade-close {
  color: #4d666f;
  font: 600 11px var(--mono);
}
.trade-question {
  text-decoration: none;
  color: var(--ink);
  font: 700 0.92rem var(--sans);
  line-height: 1.2;
}
.trade-question:hover {
  text-decoration: underline;
}
.trade-sub {
  margin: 0;
  color: #35555f;
  font: 600 11px var(--mono);
  line-height: 1.25;
}
.trade-empty {
  padding: 22px 0;
  color: #4d666f;
  font: 12px var(--mono);
}

/* EV suspicion flag — see evaluateEvSuspicion() in app.js.
   The tooltip is attached to <body> by installEvFlagTooltip() so it escapes
   the .table-wrap overflow container. Delete this rule block to remove
   styling; the flag character still shows as plain text otherwise. */
.ev-flag {
  display: inline-block;
  margin-right: 3px;
  color: var(--warn);
  font-weight: 700;
  cursor: help;
}
.ev-flag:hover,
.ev-flag:focus {
  color: #7a2a12;
  outline: none;
}
.ev-flag-tooltip {
  display: none;
  position: absolute;
  z-index: 1000;
  width: 380px;
  max-width: 90vw;
  padding: 10px 12px;
  background: #fff;
  color: var(--ink);
  border: 1px solid #d4c3ac;
  border-radius: 6px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.15);
  font: 500 11.5px var(--sans);
  line-height: 1.4;
  text-align: left;
  white-space: normal;
  pointer-events: none;
}
.ev-flag-tooltip-heading {
  display: block;
  margin-bottom: 6px;
  color: var(--warn);
  font-weight: 700;
  font-size: 12px;
}
.ev-flag-tooltip-list {
  margin: 0;
  padding-left: 16px;
}
.ev-flag-tooltip-list li + li {
  margin-top: 6px;
}

#evMain > .panel + .diagnostics {
  margin-top: 0;
}

@media (max-width: 960px) {
  .event-chart-grid {
    grid-template-columns: 1fr;
  }
  .dist-stats {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 760px) {
  .topbar {
    padding: 12px 16px 10px;
  }
  .topbar-row {
    flex-direction: column;
    align-items: stretch;
  }
  .title-row {
    align-items: flex-start;
  }
  .topbar-actions {
    justify-content: flex-start;
  }
  main {
    padding-inline: 12px;
  }
  .pill-row {
    padding-inline: 12px;
  }
  .quote-cards,
  .summary-metrics {
    grid-template-columns: 1fr;
  }
  .panel-head {
    flex-direction: column;
    align-items: flex-start;
  }
  .event-primary-grid {
    grid-template-columns: 1fr;
  }
  .trade-row-score,
  .trade-row-close {
    white-space: normal;
  }
}
