:root {
  --bg: #f5f6f8; --surface: #ffffff; --surface-2: #f0f2f5; --border: #dfe3e8;
  --text: #17202a; --muted: #5d6b7a; --accent: #d9661f; --accent-soft: #fbeadd;
  --good: #16794a; --good-soft: #dcf2e6; --bad: #b3261e; --bad-soft: #fbe3e1;
  --warn: #8a5a00; --warn-soft: #fdf0cf; --info: #1f5fbf; --info-soft: #e1ecfb;
  --bar-model: #d9661f; --bar-market: #3b6fd1; --bar-elo: #8a94a3;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  --radius: 10px;
  --mono: ui-monospace, "Cascadia Mono", Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1419; --surface: #171d24; --surface-2: #1f2730; --border: #2b3540;
    --text: #e6eaef; --muted: #93a1b0; --accent: #f08a45; --accent-soft: #3a2616;
    --good: #4cc38a; --good-soft: #15301f; --bad: #f2786c; --bad-soft: #3a1b18;
    --warn: #e8b64c; --warn-soft: #362b10; --info: #7aa7ee; --info-soft: #172a45;
    --bar-model: #f08a45; --bar-market: #6f9cf0; --bar-elo: #6d7885;
    --shadow: none;
  }
}
* { box-sizing: border-box; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.5 "Segoe UI", system-ui, -apple-system, sans-serif;
}
code { font-family: var(--mono); font-size: .9em; }
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  padding: 14px 24px; background: var(--surface); border-bottom: 1px solid var(--border);
}
.brand { font-weight: 700; font-size: 19px; display: flex; align-items: center; gap: 10px; }
.brand small { color: var(--muted); font-weight: 600; font-size: 12px; letter-spacing: .08em; }
.ball { width: 22px; height: 22px; border-radius: 50%; background: var(--accent);
  box-shadow: inset -4px -4px 0 rgba(0,0,0,.15); display: inline-block; }
.pills { display: flex; gap: 8px; flex-wrap: wrap; }
.pill { font-size: 12.5px; padding: 3px 10px; border-radius: 999px; background: var(--surface-2);
  color: var(--muted); border: 1px solid var(--border); white-space: nowrap; }
.pill.ok { color: var(--good); background: var(--good-soft); border-color: transparent; }
.pill.off { color: var(--warn); background: var(--warn-soft); border-color: transparent; }

.tabs { display: flex; gap: 2px; padding: 0 24px; background: var(--surface);
  border-bottom: 1px solid var(--border); overflow-x: auto; }
.tabs button { background: none; border: none; color: var(--muted); font: inherit; font-weight: 600;
  padding: 12px 14px; cursor: pointer; border-bottom: 2px solid transparent; white-space: nowrap; }
.tabs button:hover { color: var(--text); }
.tabs button.active { color: var(--accent); border-bottom-color: var(--accent); }

main { max-width: 1240px; margin: 0 auto; padding: 20px 24px 40px; }
.tab { display: none; }
.tab.active { display: block; }
footer { text-align: center; color: var(--muted); font-size: 13px; padding: 12px 16px 28px; }

.toolbar { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.date-nav, .inline { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
input, select { font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border);
  border-radius: 8px; padding: 7px 10px; }
input[type=number] { width: 90px; }
input:focus, select:focus, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
label { display: flex; flex-direction: column; gap: 4px; font-weight: 600; font-size: 13.5px; color: var(--muted); }
.inline label { flex-direction: row; align-items: center; gap: 8px; }
label.check { flex-direction: row; align-items: center; gap: 8px; font-weight: 500; color: var(--text); }

.btn { font: inherit; font-weight: 600; border-radius: 8px; padding: 7px 14px; cursor: pointer;
  border: 1px solid var(--border); background: var(--surface); color: var(--text); }
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.07); }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--bad); }
.btn:disabled { opacity: .55; cursor: progress; }
.btn.small { padding: 4px 10px; font-size: 13px; }

.hint, .meta { color: var(--muted); font-size: 13.5px; margin: 4px 0 12px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px 18px; box-shadow: var(--shadow); }
.card h3 { margin: 0 0 12px; font-size: 16px; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: 16px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }
.tag { font-size: 11px; font-weight: 600; color: var(--muted); background: var(--surface-2);
  border-radius: 4px; padding: 1px 6px; vertical-align: middle; }

.joblog { font-family: var(--mono); font-size: 12.5px; background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 8px; padding: 10px 12px; max-height: 180px; overflow: auto; white-space: pre-wrap; margin: 8px 0 14px; }
.joblog.error { border-color: var(--bad); }
.hidden { display: none !important; }
.empty { grid-column: 1 / -1; text-align: center; padding: 40px 16px; color: var(--muted); background: var(--surface);
  border: 1px dashed var(--border); border-radius: var(--radius); }

/* Partidos */
.games { display: grid; grid-template-columns: repeat(auto-fill, minmax(360px, 1fr)); gap: 16px; }
.game { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); display: flex; flex-direction: column; }
.game-head { display: flex; justify-content: space-between; align-items: center; padding: 14px 16px 10px; gap: 8px; }
.matchup { font-weight: 700; font-size: 17px; }
.matchup .at { color: var(--muted); font-weight: 500; margin: 0 6px; }
.names { color: var(--muted); font-size: 12.5px; }
.score { font-family: var(--mono); font-weight: 700; font-size: 15px; padding: 2px 8px; border-radius: 6px; background: var(--surface-2); }
.game-body { padding: 0 16px 12px; display: flex; flex-direction: column; gap: 10px; }
.probs { display: grid; grid-template-columns: 64px 1fr 48px; gap: 5px 8px; align-items: center; font-size: 13px; }
.probs .lbl { color: var(--muted); }
.probs .val { text-align: right; font-family: var(--mono); font-weight: 600; }
.track { height: 9px; background: var(--surface-2); border-radius: 5px; overflow: hidden; position: relative; }
.track span { display: block; height: 100%; border-radius: 5px; }
.track::after { content: ""; position: absolute; left: 50%; top: -2px; bottom: -2px; width: 1px; background: var(--border); }
.line { display: flex; justify-content: space-between; font-size: 13px; color: var(--muted); gap: 8px; flex-wrap: wrap; }
.line b { color: var(--text); font-family: var(--mono); font-weight: 600; }
.badges { display: flex; gap: 6px; flex-wrap: wrap; }
.badge { font-size: 12.5px; font-weight: 600; padding: 3px 9px; border-radius: 6px; }
.badge.ats { background: var(--good-soft); color: var(--good); }
.badge.ml { background: var(--info-soft); color: var(--info); }
.badge.review { background: var(--warn-soft); color: var(--warn); }
.badge.none { background: var(--surface-2); color: var(--muted); font-weight: 500; }
.badge.win { background: var(--good-soft); color: var(--good); }
.badge.loss { background: var(--bad-soft); color: var(--bad); }
.facts { display: grid; grid-template-columns: 1fr auto auto; gap: 2px 12px; font-size: 12.5px; border-top: 1px solid var(--border); padding-top: 8px; }
.facts .h { color: var(--muted); font-weight: 600; }
.facts .n { text-align: right; font-family: var(--mono); }
.game-foot { border-top: 1px solid var(--border); padding: 10px 16px; margin-top: auto; }
.ai { font-size: 13.5px; }
.ai .sum { margin: 0 0 8px; }
.ai ul { margin: 4px 0 8px; padding-left: 18px; }
.ai .src { font-size: 12px; color: var(--muted); word-break: break-word; }
.ai .src a { color: var(--info); }
.ai .adj { font-family: var(--mono); font-weight: 700; }
.fav-local { color: var(--good); } .fav-visita { color: var(--bad); }

/* Tablas */
.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: 18px; }
table { border-collapse: collapse; width: 100%; font-size: 13.5px; }
th, td { padding: 8px 12px; text-align: left; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { color: var(--muted); font-weight: 600; background: var(--surface-2); font-size: 12.5px; }
td.n, th.n { text-align: right; font-family: var(--mono); }
tr:last-child td { border-bottom: none; }
tr.hl td { background: var(--accent-soft); }
.pos { color: var(--good); font-weight: 600; } .neg { color: var(--bad); font-weight: 600; }
h2 { font-size: 17px; margin: 22px 0 10px; }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-bottom: 18px; }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; }
.kpi .k { color: var(--muted); font-size: 12.5px; font-weight: 600; }
.kpi .v { font-size: 22px; font-weight: 700; font-family: var(--mono); }
.kpi .s { color: var(--muted); font-size: 12px; }
.chart { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px; }
.chart svg { width: 100%; height: auto; display: block; }
.chart svg.square { max-width: 300px; margin: 0 auto; }
.chart text { fill: var(--muted); font-size: 11px; font-family: "Segoe UI", system-ui, sans-serif; }
.callout { border-left: 3px solid var(--accent); background: var(--accent-soft); padding: 10px 14px; border-radius: 6px; margin: 0 0 16px; font-size: 14px; }
.sources-list { display: flex; flex-direction: column; gap: 6px; font-size: 13.5px; }
.src-row { display: flex; justify-content: space-between; gap: 8px; }
.dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; margin-right: 8px; background: var(--bar-elo); }
.dot.ok { background: var(--good); } .dot.bad { background: var(--bad); }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 4px 14px; font-size: 13.5px; }
.kv dt { color: var(--muted); } .kv dd { margin: 0; font-family: var(--mono); }
.settings { max-width: 640px; display: flex; flex-direction: column; gap: 10px; }
.settings h3 { margin-top: 10px; }
.settings input, .settings select { width: 100%; }
.settings .inline select { flex: 1; }
.elo-bar { height: 8px; border-radius: 4px; background: var(--accent); }

#toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--bg);
  padding: 10px 16px; border-radius: 8px; font-size: 14px; opacity: 0; pointer-events: none; transition: opacity .2s; max-width: 90vw; }
#toast.show { opacity: 1; }
#toast.err { background: var(--bad); color: #fff; }

@media (max-width: 600px) {
  .topbar, .tabs { padding-left: 16px; padding-right: 16px; }
  main { padding: 16px; }
  .games { grid-template-columns: 1fr; }
  .grid2 { grid-template-columns: 1fr; }
}
