*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

:root {
  --bg: #0f0f11;
  --surface: #1a1a1f;
  --surface2: #222228;
  --border: rgba(255,255,255,0.08);
  --text: #f0ede8;
  --muted: #888580;
  --green: #4ade80;
  --green-bg: rgba(74,222,128,0.1);
  --teal: #2dd4bf;
  --teal-bg: rgba(45,212,191,0.1);
  --amber: #fbbf24;
  --red: #f87171;
  --radius: 10px;
  font-size: 16px;
}

body {
  font-family: 'SF Mono', 'Fira Code', 'Cascadia Code', monospace;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  padding-bottom: 4rem;
}

header {
  padding: 2.5rem 2rem 1.5rem;
  border-bottom: 1px solid var(--border);
  max-width: 920px;
  margin: 0 auto;
}

header h1 { font-size: 1.4rem; font-weight: 600; letter-spacing: -0.02em; }

.subtitle {
  font-size: 0.8rem;
  color: var(--muted);
  margin-top: 4px;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

main { max-width: 920px; margin: 0 auto; padding: 1.5rem 2rem; }

.tabs { display: flex; gap: 8px; margin-bottom: 1.25rem; align-items: center; }
.tablist { display: flex; gap: 8px; }

.tab:focus-visible,
.refresh-btn:focus-visible {
  outline: 2px solid var(--amber);
  outline-offset: 2px;
}

.tab {
  padding: 6px 16px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--muted);
  font-family: inherit;
  font-size: 0.8rem;
  cursor: pointer;
}

.tab.active {
  background: var(--surface2);
  color: var(--text);
  border-color: rgba(255,255,255,0.15);
}

.refresh-btn {
  margin-left: auto;
  padding: 6px 14px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--muted);
  font-family: inherit;
  font-size: 0.8rem;
  cursor: pointer;
}

.refresh-btn:hover { color: var(--text); }
.refresh-btn[disabled] { opacity: 0.6; cursor: progress; }
.refresh-icon { display: inline-block; }
.refresh-btn.loading .refresh-icon { animation: spin 0.7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Respect the OS "reduce motion" setting: drop the spinner spin and chevron transition. */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.001ms !important; animation-iteration-count: 1 !important; transition-duration: 0.001ms !important; }
}

.status-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.75rem;
  color: var(--muted);
  margin-bottom: 1.25rem;
}

.dot { width: 6px; height: 6px; border-radius: 50%; background: var(--green); }
.dot.loading { background: var(--amber); }
.dot.error { background: var(--red); }

.metrics-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  margin-bottom: 1.25rem;
}

.metric-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
}

.metric-label {
  font-size: 0.7rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 6px;
}

.metric-value { font-size: 1.5rem; font-weight: 600; }
.metric-value-sm { font-size: 1rem; padding-top: 4px; }
.metric-sub { font-size: 0.7rem; color: var(--muted); margin-top: 4px; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  margin-bottom: 1rem;
}

.card-title {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin-bottom: 1rem;
  font-weight: 500;
}

.forecast-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 9px 0;
  border-bottom: 1px solid var(--border);
}

.forecast-row:last-child { border-bottom: none; }
.forecast-day { font-size: 0.8rem; min-width: 52px; }

.bar-wrap {
  flex: 1;
  height: 6px;
  background: var(--surface2);
  border-radius: 3px;
  position: relative;
  overflow: hidden;
}

.bar-fill { position: absolute; top: 0; height: 100%; border-radius: 3px; }
.temp-label { font-size: 0.78rem; min-width: 28px; color: var(--muted); text-align: right; }
.temp-label.high { color: var(--amber); }

.pop-badge {
  font-size: 0.68rem;
  padding: 2px 8px;
  border-radius: 4px;
  min-width: 60px;
  text-align: center;
}

.edge-header, .edge-row {
  display: grid;
  grid-template-columns: 1fr 60px 84px 50px 50px 1fr;
  gap: 8px;
  align-items: center;
  font-size: 0.75rem;
}

.edge-header {
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 4px;
}

.edge-row {
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.8rem;
}

/* Illiquid markets: dim the data cells but keep override inputs fully usable. */
.edge-row-illiquid .edge-label,
.edge-row-illiquid .edge-model,
.edge-row-illiquid .edge-market,
.edge-row-illiquid .edge-badge {
  opacity: 0.4;
}

.edge-date-header {
  font-size: 0.72rem;
  color: var(--amber);
  padding: 12px 0 4px;
  letter-spacing: 0.04em;
}

.mu-src {
  display: inline-block;
  margin-left: 5px;
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 0.62rem;
  letter-spacing: 0.04em;
  vertical-align: middle;
}
.mu-src-period { background: var(--surface2); color: var(--muted); }
.mu-src-grid { background: rgba(251,191,36,0.15); color: var(--amber); }
.mu-unavailable { color: var(--red); }

.edge-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Contract is a toggle button revealing the resolution rules. */
.edge-label-toggle {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  max-width: 100%;
  overflow: visible;
  white-space: normal;
  background: none;
  border: none;
  padding: 0;
  margin: 0;
  font: inherit;
  color: inherit;
  text-align: left;
  cursor: pointer;
}
.edge-label-text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.edge-label-chevron { flex-shrink: 0; font-size: 0.7em; color: var(--muted); transition: transform 0.15s; }
.edge-label-toggle.expanded .edge-label-chevron { transform: rotate(90deg); }
.edge-label-toggle:focus-visible { outline: 2px solid var(--amber); outline-offset: 2px; border-radius: 3px; }

.edge-rules {
  grid-column: 1 / -1;
  background: var(--surface2);
  border-radius: 6px;
  padding: 10px 12px;
  margin-top: 6px;
  font-size: 0.72rem;
  line-height: 1.5;
  color: var(--muted);
}
.edge-rules p { margin-bottom: 6px; }
.edge-rules p:last-child { margin-bottom: 0; }
.edge-rules-primary { color: var(--text); }

.edge-model { text-align: center; color: var(--amber); font-weight: 600; }
.edge-market { text-align: center; color: var(--muted); font-size: 0.72rem; }

/* Override field: a <label> wrapping the input. On desktop the label is just the grid cell
   (its caption hidden); on mobile the caption shows and the field stacks in a card. */
.edge-override { width: 100%; }
.edge-override-label { display: none; }

.edge-input {
  width: 100%;
  padding: 4px 6px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface2);
  color: var(--text);
  font-family: inherit;
  font-size: 0.75rem;
  text-align: center;
}

.edge-badge {
  font-size: 0.68rem;
  padding: 3px 8px;
  border-radius: 5px;
  text-align: center;
}

.edge-stale-warning {
  background: rgba(248,113,113,0.12);
  color: var(--red);
  border: 1px solid rgba(248,113,113,0.3);
  border-radius: 6px;
  padding: 8px 12px;
  margin-bottom: 12px;
  font-size: 0.78rem;
  line-height: 1.4;
}

.rec-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  padding: 9px 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.82rem;
}
.rec-row:last-of-type { border-bottom: none; }
.rec-date { color: var(--amber); font-size: 0.72rem; min-width: 72px; }
.rec-contract { color: var(--text); font-weight: 500; flex: 1; min-width: 90px; }
.rec-ask { color: var(--muted); font-size: 0.75rem; }
.rec-flag { color: var(--amber); font-size: 0.68rem; }
.rec-confirmed { color: var(--green); font-size: 0.68rem; font-weight: 600; }
.rec-empty { color: var(--muted); font-size: 0.85rem; padding: 0.5rem 0; }
.rec-foot { margin-top: 0.85rem; margin-bottom: 0; }

.edge-none { background: var(--surface2); color: var(--muted); }
.edge-yes { background: var(--green-bg); color: var(--green); }
.edge-no { background: var(--teal-bg); color: var(--teal); }
.edge-badge-confirmed { outline: 1px solid currentColor; outline-offset: 1px; }

.helper-text { font-size: 0.78rem; color: var(--muted); margin-bottom: 1rem; line-height: 1.6; }
.edge-foot { margin-top: 1rem; margin-bottom: 0; }
.helper-text code { font-size: 0.85em; color: var(--text); }

.info-card ul { list-style: none; display: flex; flex-direction: column; gap: 8px; }
.info-card li { font-size: 0.82rem; color: var(--muted); line-height: 1.6; padding-left: 1em; position: relative; }
.info-card li::before { content: '—'; position: absolute; left: 0; color: var(--border); }
.info-card strong { color: var(--text); font-weight: 500; }

/* Guide tab: numbered steps and a flagged disclaimer */
.guide-steps { list-style: decimal; padding-left: 1.4em; display: flex; flex-direction: column; gap: 8px; }
.guide-steps li { font-size: 0.82rem; color: var(--muted); line-height: 1.6; }
.guide-steps li::before { content: none; }
.guide-disclaimer { border: 1px solid rgba(248,113,113,0.3); background: rgba(248,113,113,0.06); }

.loading { text-align: center; padding: 2rem; color: var(--muted); font-size: 0.85rem; }
.error { color: var(--red); font-size: 0.82rem; padding: 1rem; background: rgba(248,113,113,0.08); border-radius: 6px; }

footer {
  max-width: 920px;
  margin: 2rem auto 0;
  padding: 0 2rem;
  font-size: 0.72rem;
  color: var(--muted);
}

footer a { color: var(--muted); }

/* ── Calibration Tab ── */

.calibration-settings { display: flex; flex-direction: column; gap: 12px; }

.toggle-control {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  cursor: pointer;
  user-select: none;
  margin-top: 0.25rem;
  align-self: flex-start;
}
.toggle-control input { display: none; }

.toggle-switch {
  position: relative;
  width: 44px;
  height: 22px;
  background-color: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 11px;
  transition: background-color 0.2s, border-color 0.2s;
  flex-shrink: 0;
}
.toggle-switch::after {
  content: "";
  position: absolute;
  top: 2px; left: 2px;
  width: 16px; height: 16px;
  background-color: var(--muted);
  border-radius: 50%;
  transition: transform 0.2s, background-color 0.2s;
}
.toggle-control input:checked + .toggle-switch { background-color: var(--green-bg); border-color: var(--green); }
.toggle-control input:checked + .toggle-switch::after { transform: translateX(22px); background-color: var(--green); }
.toggle-label-text { font-size: 0.82rem; font-weight: 500; color: var(--text); }

.calibration-grid {
  display: grid;
  grid-template-columns: 1.2fr 1fr;
  gap: 1.25rem;
  margin-top: 1.25rem;
}

.chart-container {
  position: relative;
  width: 100%;
  height: 280px;
  background-color: #0b0b0d;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px;
  margin-bottom: 1rem;
}
.chart-container svg { width: 100%; height: 100%; }

.chart-legend { display: flex; gap: 16px; justify-content: center; flex-wrap: wrap; font-size: 0.7rem; color: var(--muted); }
.legend-item { display: inline-flex; align-items: center; gap: 6px; }
.legend-dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.perfect-line { background-color: var(--muted); border-radius: 0; height: 2px; width: 12px; }
.kalshi-line { background-color: var(--teal); }
.model-line { background-color: var(--amber); }

.chart-axis-line { stroke: var(--border); stroke-width: 1; }
.chart-axis-text { fill: var(--muted); font-size: 9px; font-family: inherit; }
.chart-line { fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.chart-line.perfect { stroke: var(--muted); stroke-dasharray: 4 4; stroke-width: 1; }
.chart-line.kalshi { stroke: var(--teal); }
.chart-line.model { stroke: var(--amber); }
.chart-dot { stroke-width: 2; }
.chart-dot.kalshi { stroke: var(--teal); fill: var(--bg); }
.chart-dot.model { stroke: var(--amber); fill: var(--bg); }

.stats-table { width: 100%; border-collapse: collapse; font-size: 0.78rem; }
.stats-table th, .stats-table td { padding: 8px 10px; text-align: right; border-bottom: 1px solid var(--border); }
.stats-table th { color: var(--muted); font-weight: 500; text-transform: uppercase; font-size: 0.65rem; letter-spacing: 0.05em; }
.stats-table th:first-child, .stats-table td:first-child { text-align: left; }
.stats-table tr:last-child td { border-bottom: none; }
.stats-table tbody tr:hover { background-color: var(--surface2); }
.stats-val-highlight { color: var(--amber); font-weight: 600; }
.stats-current-month td { background-color: rgba(251,191,36,0.06); }
.stats-sub-title { font-size: 0.7rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.07em; color: var(--muted); margin: 18px 0 8px; }
.stats-month-note { font-size: 0.68rem; margin-top: 6px; }

@media (max-width: 900px) { .calibration-grid { grid-template-columns: 1fr; } }

@media (max-width: 640px) {
  .metrics-grid { grid-template-columns: 1fr 1fr; }
  header, main, footer { padding-left: 1rem; padding-right: 1rem; }
  /* Stacked card per market — column headers don't apply, so hide the header row. */
  .edge-header { display: none; }

  .edge-row {
    grid-template-columns: 1fr 1fr;
    grid-template-areas:
      "contract contract"
      "model    market"
      "yes      no"
      "badge    badge";
    gap: 10px 12px;
    padding: 14px;
    border: 1px solid var(--border);
    border-radius: 8px;
    margin-bottom: 10px;
    align-items: end;
  }

  .edge-label {
    grid-area: contract;
    white-space: normal;        /* let the contract name wrap instead of truncating */
    overflow: visible;
    font-weight: 600;
    font-size: 0.9rem;
  }
  .edge-label-text { white-space: normal; overflow: visible; }
  .edge-model  { grid-area: model;  text-align: left; }
  .edge-market { grid-area: market; text-align: left; font-size: 0.8rem; }
  .edge-override[data-side="yes"] { grid-area: yes; }
  .edge-override[data-side="no"]  { grid-area: no; }
  .edge-badge  { grid-area: badge; padding: 6px 8px; }

  /* Field captions for the otherwise-unlabelled cells in card view. */
  .edge-model::before,
  .edge-market::before,
  .edge-override-label {
    display: block;
    color: var(--muted);
    font-size: 0.6rem;
    font-weight: 400;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 2px;
  }
  .edge-model::before  { content: "Model P"; }
  .edge-market::before { content: "Market YES/NO"; }
  .edge-override { display: block; }
}

/* ── Calibration & Backtest Tab Styles ── */

.calibration-settings {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.toggle-control {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  cursor: pointer;
  user-select: none;
  margin-top: 0.25rem;
  align-self: flex-start;
}

.toggle-control input {
  display: none;
}

.toggle-switch {
  position: relative;
  width: 44px;
  height: 22px;
  background-color: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 11px;
  transition: background-color 0.2s, border-color 0.2s;
  flex-shrink: 0;
}

.toggle-switch::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  background-color: var(--muted);
  border-radius: 50%;
  transition: transform 0.2s, background-color 0.2s;
}

.toggle-control input:checked + .toggle-switch {
  background-color: var(--green-bg);
  border-color: var(--green);
}

.toggle-control input:checked + .toggle-switch::after {
  transform: translateX(22px);
  background-color: var(--green);
}

.toggle-label-text {
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--text);
}

.calibration-grid {
  display: grid;
  grid-template-columns: 1.2fr 1fr;
  gap: 1.25rem;
  margin-top: 1.25rem;
}

.chart-container {
  position: relative;
  width: 100%;
  height: 280px;
  background-color: #0b0b0d;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px;
  margin-bottom: 1rem;
}

.chart-container svg {
  width: 100%;
  height: 100%;
}

.chart-legend {
  display: flex;
  gap: 16px;
  justify-content: center;
  flex-wrap: wrap;
  font-size: 0.7rem;
  color: var(--muted);
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.legend-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
}

.perfect-line {
  background-color: var(--muted);
  border-radius: 0;
  height: 2px;
  width: 12px;
}

.kalshi-line {
  background-color: var(--teal);
}

.model-line {
  background-color: var(--amber);
}

.chart-axis-line {
  stroke: var(--border);
  stroke-width: 1;
}

.chart-axis-text {
  fill: var(--muted);
  font-size: 9px;
  font-family: inherit;
}

.chart-line {
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.chart-line.perfect {
  stroke: var(--muted);
  stroke-dasharray: 4 4;
  stroke-width: 1;
}

.chart-line.kalshi {
  stroke: var(--teal);
}

.chart-line.model {
  stroke: var(--amber);
}

.chart-dot {
  stroke-width: 2;
}

.chart-dot.kalshi {
  stroke: var(--teal);
  fill: var(--bg);
}

.chart-dot.model {
  stroke: var(--amber);
  fill: var(--bg);
}

.stats-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.78rem;
}

.stats-table th, .stats-table td {
  padding: 8px 10px;
  text-align: right;
  border-bottom: 1px solid var(--border);
}

.stats-table th {
  color: var(--muted);
  font-weight: 500;
  text-transform: uppercase;
  font-size: 0.65rem;
  letter-spacing: 0.05em;
}

.stats-table th:first-child, .stats-table td:first-child {
  text-align: left;
}

.stats-table tr:last-child td {
  border-bottom: none;
}

.stats-table tbody tr:hover {
  background-color: var(--surface2);
}

.stats-val-highlight {
  color: var(--amber);
  font-weight: 600;
}

@media (max-width: 900px) {
  .calibration-grid {
    grid-template-columns: 1fr;
  }
}

