* { box-sizing: border-box; }
body {
  font: 14px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  margin: 0;
  background: #f7f7f7;
  color: #222;
}
header {
  background: #16202a;
  color: #fff;
  padding: 10px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 2px solid #0f8a4f;
}
.brand {
  font-weight: 700;
  font-size: 16px;
  color: #fff;
  text-decoration: none;
  letter-spacing: 0.5px;
}
.status {
  font-size: 12px;
  color: #b5c2d0;
}
main {
  padding: 16px;
  max-width: 1500px;
  margin: 0 auto;
}
footer {
  text-align: center;
  color: #999;
  padding: 12px;
}
h1 { margin: 0 0 8px 0; font-size: 22px; }
.meta { color: #555; margin: 0 0 12px 0; }
.warning {
  background: #fff8e1;
  border-left: 3px solid #f4a020;
  padding: 8px 12px;
  margin: 12px 0;
}

table {
  width: 100%;
  border-collapse: collapse;
  background: #fff;
  font-size: 13px;
}
th, td {
  text-align: left;
  padding: 6px 8px;
  border-bottom: 1px solid #eee;
}
th { background: #f0f3f5; font-weight: 600; }
th.sortable-th {
  cursor: pointer;
  user-select: none;
}
th.sortable-th:hover { background: #e6ebee; }
th.sortable-th::after {
  content: "";
  display: inline-block;
  width: 0;
  height: 0;
  margin-left: 4px;
  vertical-align: middle;
  opacity: 0.25;
  border-left: 4px solid transparent;
  border-right: 4px solid transparent;
  border-top: 4px solid #444;
}
th.sortable-th.sort-asc::after {
  border-top: 0;
  border-bottom: 4px solid #0f3a6c;
  opacity: 1;
}
th.sortable-th.sort-desc::after {
  border-top: 4px solid #0f3a6c;
  opacity: 1;
}
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
td.bold { font-weight: 700; }
td.side { font-weight: 700; }

.races tr.imminent { background: #fffbcc; }
.races a { color: #0f3a6c; text-decoration: none; font-weight: 600; }
.races a:hover { text-decoration: underline; }

.runners tr.side-back { background: rgba(15, 138, 79, 0.08); }
.runners tr.side-back td.side { color: #0f8a4f; }
.runners tr.side-lay  { background: rgba(232, 67, 67, 0.08); }
.runners tr.side-lay  td.side { color: #d23030; }

.warn-tag {
  display: inline-block;
  background: #ffd6d6;
  color: #b91515;
  font-size: 10px;
  padding: 1px 4px;
  border-radius: 3px;
  margin-left: 6px;
}
.src-tag {
  display: inline-block;
  background: #fff3cd;
  color: #856404;
  font-size: 10px;
  font-weight: 700;
  padding: 1px 4px;
  border-radius: 3px;
  margin-right: 4px;
  vertical-align: middle;
  cursor: help;
}
/* model % column: pin the badge to the left of the number so the
   number's right edge always lands at the cell edge (perfect column
   alignment regardless of whether a PE/? tag is present). */
.runners td.model-pct .model-pct-num {
  display: inline-block;
  min-width: 3em;
  text-align: right;
}
.src-tag.none-tag {
  background: #f3d3d3;
  color: #862020;
}
.thin-banner {
  background: #fff8e1;
  border-left: 4px solid #f4a020;
  padding: 10px 14px;
  margin: 12px 0;
  border-radius: 2px;
  color: #4a3508;
}
.thin-banner strong { color: #1a1a1a; }

.race-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 8px;
}
.race-title h1 { margin: 0 0 4px 0; }
.race-confidence {
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
  padding: 8px 14px;
  background: #fff;
  border: 1px solid #e0e4e8;
  border-radius: 6px;
  cursor: help;
  min-width: 140px;
}
.conf-label {
  font-size: 10px;
  text-transform: uppercase;
  color: #888;
  letter-spacing: 0.6px;
}
.conf-score {
  font-size: 11px;
  color: #888;
  font-variant-numeric: tabular-nums;
}
.conf-badge {
  display: inline-block;
  font-size: 13px;
  font-weight: 700;
  padding: 4px 12px;
  border-radius: 12px;
  vertical-align: middle;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  cursor: help;
}
.conf-badge.conf-high {
  background: #d4f0d8;
  color: #1c5b29;
  border: 1px solid #8ec597;
}
.conf-badge.conf-medium {
  background: #fff3cd;
  color: #6b5008;
  border: 1px solid #e1c870;
}
.conf-badge.conf-low {
  background: #f7d6d6;
  color: #791515;
  border: 1px solid #d99090;
}

/* small "pill" variant used in the index race-list column */
.conf-pill {
  display: inline-block;
  font-size: 10px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 10px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  cursor: help;
  border: 1px solid transparent;
}
.conf-pill.conf-high {
  background: #d4f0d8;
  color: #1c5b29;
  border-color: #8ec597;
}
.conf-pill.conf-medium {
  background: #fff3cd;
  color: #6b5008;
  border-color: #e1c870;
}
.conf-pill.conf-low {
  background: #f7d6d6;
  color: #791515;
  border-color: #d99090;
}

/* /bets page styling */
.nav-row {
  display: flex;
  gap: 14px;
  align-items: baseline;
  margin: 0 0 12px 0;
}
.nav-row .nav-link {
  font-size: 13px;
  color: #0f3a6c;
  text-decoration: none;
  border-bottom: 1px dotted #0f3a6c;
}
.nav-row .nav-link:hover { color: #082147; }

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
  margin: 16px 0 24px;
}
.stat-card {
  background: #fff;
  border: 1px solid #e0e4e8;
  border-radius: 6px;
  padding: 12px 14px;
}
.stat-label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: #888;
  margin-bottom: 4px;
}
.stat-value {
  font-size: 24px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: #16202a;
}
.stat-value.gain { color: #0f8a4f; }
.stat-value.loss { color: #c22a2a; }
.stat-sub {
  font-size: 11px;
  color: #666;
  margin-top: 4px;
}

.bets td.side.side-back { color: #0f8a4f; font-weight: 700; }
.bets td.side.side-lay  { color: #d23030; font-weight: 700; }
.bets td.gain { color: #0f8a4f; font-weight: 600; }
.bets td.loss { color: #c22a2a; font-weight: 600; }
.bets .result-won { color: #0f8a4f; font-weight: 600; text-transform: uppercase; font-size: 11px; }
.bets .result-lost { color: #c22a2a; font-weight: 600; text-transform: uppercase; font-size: 11px; }
.bets .result-void { color: #888; font-style: italic; text-transform: uppercase; font-size: 11px; }
.bets tr.settled-won { background: rgba(15, 138, 79, 0.04); }
.bets tr.settled-lost { background: rgba(232, 67, 67, 0.04); }
.bets tr.settled-void { background: #fafafa; color: #888; }

h2 { font-size: 16px; margin-top: 22px; margin-bottom: 6px; }
h2 .count {
  display: inline-block;
  font-size: 12px;
  font-weight: 500;
  color: #666;
  background: #eef1f3;
  padding: 1px 7px;
  border-radius: 8px;
  margin-left: 6px;
  vertical-align: 2px;
}

/* Kill-switch banner on /orders */
.kill-switch {
  padding: 12px 16px;
  border-radius: 6px;
  margin: 12px 0 20px;
  border-left: 4px solid;
}
.kill-switch.kill-off {
  background: #f3d3d3;
  color: #58151c;
  border-color: #c22a2a;
}
.kill-switch.kill-manual {
  background: #fff3cd;
  color: #5d4708;
  border-color: #e1a526;
}
.kill-switch.kill-auto {
  background: #d4e8d8;
  color: #1c4a26;
  border-color: #0f8a4f;
}
.kill-row {
  display: flex;
  align-items: baseline;
  gap: 12px;
  margin-bottom: 6px;
}
.kill-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  font-weight: 600;
  opacity: 0.7;
}
.kill-value {
  font-size: 18px;
  font-weight: 700;
  text-transform: uppercase;
  font-variant-numeric: tabular-nums;
}
.kill-meta { font-size: 13px; line-height: 1.5; }

.ord-status {
  display: inline-block;
  font-size: 10px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 8px;
  text-transform: uppercase;
  letter-spacing: 0.4px;
}
.ord-pending { background: #fff3cd; color: #6b5008; }
.ord-executable { background: #d4e8f8; color: #0f3a6c; }
.ord-execution_complete { background: #d4f0d8; color: #1c5b29; }
.ord-dry_run { background: #e9ecef; color: #495057; }
.ord-dry_run_won { background: #d4f0d8; color: #1c5b29; }
.ord-dry_run_lost { background: #f7d6d6; color: #791515; }
.ord-dry_run_void { background: #eef1f3; color: #666; font-style: italic; }
.ord-error { background: #f7d6d6; color: #791515; }
.ord-cancelled { background: #eef1f3; color: #666; }

.src-pill {
  display: inline-block;
  font-size: 9px;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 4px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  margin-right: 3px;
  vertical-align: 1px;
}
.src-pill.src-algo { background: #d4e8f8; color: #0f3a6c; }
.src-pill.src-manual { background: #ffd8b1; color: #6e3203; }
.src-pill.src-dry { background: #eef1f3; color: #666; border: 1px dashed #999; }

.legend pre {
  background: #1e2630;
  color: #e6e9ec;
  padding: 10px 12px;
  border-radius: 4px;
  font-size: 12px;
  overflow-x: auto;
  white-space: pre-wrap;
}
.legend pre code { background: transparent; color: inherit; padding: 0; }
.runners a { color: #16202a; text-decoration: none; border-bottom: 1px dotted #999; }
.runners a:hover { color: #0f3a6c; }
.off { color: #999; }
code {
  font: 12px ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  background: #eef1f3;
  padding: 0 4px;
  border-radius: 2px;
}

.legend {
  margin-top: 24px;
  padding: 16px;
  background: #fff;
  border: 1px solid #e0e4e8;
  border-radius: 4px;
}
.legend h2 {
  margin: 0 0 12px 0;
  font-size: 16px;
  color: #16202a;
}
.legend dl {
  margin: 0;
  display: grid;
  grid-template-columns: 110px 1fr;
  gap: 6px 14px;
}
.legend dt {
  font-weight: 600;
  color: #0f3a6c;
  font-variant-numeric: tabular-nums;
}
.legend dd {
  margin: 0;
  color: #333;
}
.legend dd strong { font-weight: 700; }
.legend dd em { font-style: italic; color: #555; }
.legend .caveat {
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px dashed #d0d4d8;
  color: #666;
  font-size: 12px;
}
.legend .conf-badge {
  font-size: 11px;
  font-weight: 700;
  padding: 1px 7px;
  border-radius: 8px;
  letter-spacing: 0.3px;
  text-transform: uppercase;
  vertical-align: 1px;
  margin: 0 2px;
}

.local-time {
  font: 12px ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  background: #eef1f3;
  padding: 0 4px;
  border-radius: 2px;
  white-space: nowrap;
}

/* Narrow viewport — drop secondary columns + tighten layout. The
   essential set on mobile: # · horse · live back · live lay · model $
   · EV % · suggest. */
@media (max-width: 768px) {
  main { padding: 8px; }
  header { padding: 8px 12px; }
  .status { font-size: 10px; }
  h1 { font-size: 18px; }
  .meta { font-size: 12px; }

  .runners .hide-narrow,
  .runners th.hide-narrow,
  .runners td.hide-narrow {
    display: none;
  }
  .runners th, .runners td {
    padding: 6px 5px;
    font-size: 12px;
  }
  .runners td:nth-child(2) { /* horse cell stays compact */
    max-width: 130px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .runners a { font-size: 12px; }

  /* Race header stacks: title + confidence chip on separate lines. */
  .race-header { flex-direction: column; gap: 8px; }
  .race-confidence {
    flex-direction: row;
    align-items: center;
    width: fit-content;
    padding: 6px 10px;
    gap: 8px;
    min-width: 0;
  }
  .conf-label { font-size: 10px; }

  .legend dl {
    grid-template-columns: 1fr;
    gap: 4px 0;
  }
  .legend dt { margin-top: 6px; }
  .thin-banner { font-size: 12px; padding: 8px 10px; }
  .warn-tag, .src-tag { font-size: 9px; }
}
