/* ══ Tokens ─────────────────────────────────────────────────────────────────
   Superficies, tinta y series de la paleta validada (dataviz): azul = el equipo / local,
   naranja = el rival / visitante. Los estados (G/E/P) llevan siempre su letra. */
:root {
  color-scheme: light;
  --bg: #f9f9f7;
  --surface: #fcfcfb;
  --surface-2: #f2f1ed;
  --text: #0b0b0b;
  --muted: #52514e;
  --faint: #898781;
  --border: #e1e0d9;
  --baseline: #c3c2b7;
  --ring: rgba(11, 11, 11, .10);
  --accent: #1f7a45;
  --accent-soft: #e4f2e9;
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --series-3: #1baf7a;
  --neutral: #c9c8c1;
  --good: #0ca30c;
  --good-ink: #006300;
  --warning: #fab219;
  --critical: #d03b3b;
  --radius: 12px;
  --shadow: 0 1px 2px rgb(16 24 40 / 5%), 0 1px 3px rgb(16 24 40 / 8%);
}

@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --bg: #0d0d0d;
    --surface: #1a1a19;
    --surface-2: #232321;
    --text: #ffffff;
    --muted: #c3c2b7;
    --faint: #898781;
    --border: #2c2c2a;
    --baseline: #383835;
    --ring: rgba(255, 255, 255, .10);
    --accent: #4cc27f;
    --accent-soft: #16301f;
    --series-1: #3987e5;
    --series-2: #d95926;
    --series-3: #199e70;
    --neutral: #4a4a46;
    --good-ink: #0ca30c;
    --shadow: none;
  }
}

/* ══ Base ───────────────────────────────────────────────────────────────── */
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: clamp(1.4rem, 3vw, 1.9rem); line-height: 1.2; margin: 0 0 .25rem; }
h2 { font-size: 1.05rem; margin: 0 0 .75rem; }
h3 { font-size: .95rem; margin: 0 0 .5rem; color: var(--muted); font-weight: 600; }
p { margin: 0 0 .5rem; }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.small { font-size: .85rem; }
.num { font-variant-numeric: tabular-nums; text-align: right; }
.nowrap { white-space: nowrap; }
.sr-only {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}

/* ══ Estructura ─────────────────────────────────────────────────────────── */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: .6rem 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.brand { font-weight: 700; color: var(--text); white-space: nowrap; }
.brand:hover { text-decoration: none; }
.nav { display: flex; gap: .25rem; overflow-x: auto; scrollbar-width: none; min-width: 0; }
.nav a {
  color: var(--muted);
  padding: .35rem .6rem;
  border-radius: 8px;
  white-space: nowrap;
}
.nav a:hover { background: var(--surface-2); text-decoration: none; }
.nav a[aria-current="page"] { color: var(--text); background: var(--surface-2); font-weight: 600; }

.search { position: relative; margin-left: auto; width: min(320px, 40vw); }
.search input {
  width: 100%;
  font: inherit;
  padding: .45rem .75rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
}
.search input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.search-results {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 8px 24px rgb(0 0 0 / 12%);
  overflow: hidden;
}
.search-results:empty { display: none; }
.search-results a {
  display: flex;
  justify-content: space-between;
  gap: .5rem;
  padding: .5rem .75rem;
  color: var(--text);
}
.search-results a:hover, .search-results a:focus { background: var(--surface-2); text-decoration: none; }

.container { width: 100%; max-width: 1180px; margin: 0 auto; padding: 1.25rem 16px 2rem; flex: 1; }

.session { display: flex; align-items: center; gap: .5rem; white-space: nowrap; }
.login-card { max-width: 380px; margin: 2rem auto; }
.login-form { display: grid; gap: .85rem; margin: 1rem 0; }
.login-form input {
  font: inherit;
  padding: .5rem .7rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
}
.login-form input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.footer a { color: var(--muted); text-decoration: underline; }

.footer {
  padding: 1rem 16px;
  color: var(--faint);
  font-size: .82rem;
  text-align: center;
  border-top: 1px solid var(--border);
}

.breadcrumb { font-size: .85rem; color: var(--muted); margin-bottom: .5rem; }
.breadcrumb a { color: var(--muted); }

.page-header {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: .75rem 1.5rem;
  margin-bottom: 1.25rem;
}

.grid { display: grid; gap: 1rem; }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(min(100%, 420px), 1fr)); }
.grid-3 { grid-template-columns: repeat(auto-fit, minmax(min(100%, 300px), 1fr)); }
.grid > * { min-width: 0; }
/* Clasificación ancha y resultados al lado; en pantallas medianas, una debajo de otra */
.grid-main { grid-template-columns: minmax(0, 1fr); }
@media (min-width: 1100px) {
  .grid-main { grid-template-columns: minmax(0, 1.5fr) minmax(0, 1fr); }
}
.section { margin-top: 1.5rem; }

/* ══ Tarjetas y cifras ──────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1rem 1.25rem;
  min-width: 0;
}
.card-header { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: baseline; gap: .5rem 1rem; margin-bottom: .75rem; }
.card-header h2 { margin: 0; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 1rem; }
.stat { display: flex; flex-direction: column; }
.stat-value { font-size: 1.6rem; font-weight: 700; line-height: 1.2; }
.stat-label { color: var(--muted); font-size: .85rem; }

.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: .75rem; }
.tile {
  display: block;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: .75rem 1rem;
  color: var(--text);
}
.tile:hover { border-color: var(--accent); text-decoration: none; }
.tile strong { display: block; }

/* ══ Controles ─────────────────────────────────────────────────────────── */
.filters {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  gap: .75rem;
  margin-bottom: 1rem;
}
.field { display: flex; flex-direction: column; gap: .2rem; font-size: .8rem; color: var(--muted); }
select {
  font: inherit;
  font-size: .9rem;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: .4rem .6rem;
  min-width: 9rem;
}
select:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

.chips { display: flex; flex-wrap: wrap; gap: .4rem; }
.chip {
  padding: .25rem .7rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  color: var(--muted);
  background: var(--surface);
  font-size: .85rem;
}
.chip:hover { text-decoration: none; border-color: var(--accent); }
.chip[aria-current="page"] { background: var(--accent); border-color: var(--accent); color: #fff; }

.button {
  appearance: none;
  border: 0;
  border-radius: 8px;
  padding: .5rem 1rem;
  background: var(--accent);
  color: #fff;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}
.button:hover { filter: brightness(1.08); text-decoration: none; }
.button:disabled { opacity: .6; cursor: progress; }
.button-ghost {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
  font-weight: 500;
}
.button-ghost:hover { background: var(--surface-2); filter: none; }
.actions { display: flex; flex-wrap: wrap; gap: .5rem; }

/* ══ Tablas ────────────────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: .9rem; }
.table th, .table td {
  text-align: left;
  padding: .45rem .55rem;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.table th { color: var(--faint); font-weight: 600; font-size: .75rem; text-transform: uppercase; letter-spacing: .02em; }
.table td.num, .table th.num { text-align: right; font-variant-numeric: tabular-nums; }
.table tbody tr:hover { background: var(--surface-2); }
.table tr:last-child td { border-bottom: 0; }
.table .team-cell { font-weight: 600; white-space: nowrap; }
.table .pos { color: var(--faint); width: 2rem; }
.more { text-align: center; padding-top: .75rem; }

/* ══ Resultados (G/E/P) y marcadores ───────────────────────────────────── */
.result {
  display: inline-grid;
  place-items: center;
  width: 1.45rem;
  height: 1.45rem;
  border-radius: 6px;
  font-size: .75rem;
  font-weight: 700;
  color: #fff;
}
.result-W { background: var(--good); }
.result-D { background: var(--faint); }
.result-L { background: var(--critical); }
.form { display: inline-flex; gap: 3px; }

.score { font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.score-big { font-size: clamp(2rem, 6vw, 3rem); font-weight: 800; line-height: 1; }

.match-header {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 1rem;
  text-align: center;
}
.match-team { min-width: 0; overflow-wrap: anywhere; font-size: clamp(1rem, 2.5vw, 1.35rem); font-weight: 700; color: var(--text); }
.match-team .key { display: block; height: 4px; width: 32px; border-radius: 2px; margin: .4rem auto 0; }
.key-1 { background: var(--series-1); }
.key-2 { background: var(--series-2); }

.badge {
  display: inline-block;
  border-radius: 999px;
  padding: .1rem .55rem;
  font-size: .75rem;
  font-weight: 600;
  background: var(--surface-2);
  color: var(--muted);
  white-space: nowrap;
}
.badge-success, .badge-done { background: var(--accent-soft); color: var(--accent); }
.badge-running, .badge-pending { background: #fff4d6; color: #8a5a00; }
.badge-partial, .badge-skipped { background: #ffe9d6; color: #9a4a00; }
.badge-failed { background: #fde2e1; color: #b42318; }
@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) .badge-running,
  :root:where(:not([data-theme="light"])) .badge-pending { background: #3a2e10; color: #f5c451; }
  :root:where(:not([data-theme="light"])) .badge-partial,
  :root:where(:not([data-theme="light"])) .badge-skipped { background: #3d2412; color: #f5a25d; }
  :root:where(:not([data-theme="light"])) .badge-failed { background: #3e1715; color: #f97066; }
}

/* ══ Comparación de estadísticas (local frente a visitante) ────────────── */
.compare { display: grid; gap: .7rem; }
.compare-row { display: grid; grid-template-columns: 4.5rem 1fr 4.5rem; align-items: center; gap: .15rem .75rem; }
.compare-label { grid-column: 1 / -1; display: flex; justify-content: center; align-items: baseline; gap: .4rem; font-size: .85rem; color: var(--muted); }
.compare-value { font-weight: 700; font-variant-numeric: tabular-nums; }
.compare-value.away { text-align: right; }
.compare-bar { display: flex; height: 8px; gap: 2px; }
.compare-bar span { border-radius: 4px; min-width: 2px; }
.compare-bar .home { background: var(--series-1); }
.compare-bar .away { background: var(--series-2); }

/* ══ Probabilidades del mercado ────────────────────────────────────────── */
.prob-bar { display: flex; gap: 2px; height: 30px; margin: .5rem 0; }
.prob-bar span {
  display: grid;
  place-items: center;
  border-radius: 4px;
  font-size: .8rem;
  font-weight: 700;
  color: #fff;
  min-width: 2.75rem;
}
.prob-home { background: var(--series-1); }
.prob-draw { background: var(--neutral); color: var(--text) !important; }
.prob-away { background: var(--series-2); }
.legend { display: flex; flex-wrap: wrap; gap: .25rem 1rem; font-size: .82rem; color: var(--muted); }
.legend i { display: inline-block; width: 14px; height: 3px; border-radius: 2px; margin-right: .35rem; vertical-align: middle; }
.legend .dot { width: 10px; height: 10px; border-radius: 50%; }
.legend .ring { width: 10px; height: 10px; border-radius: 50%; background: transparent; border: 2px solid var(--muted); }

/* ══ Mapa de tiros ─────────────────────────────────────────────────────── */
.pitch { width: 100%; height: auto; display: block; }
.pitch .field-bg { fill: var(--surface-2); }
.pitch .lines { fill: none; stroke: var(--baseline); stroke-width: .35; }
.pitch .shot { stroke: var(--surface); stroke-width: .5; }
.pitch .shot.home { fill: var(--series-1); }
.pitch .shot.away { fill: var(--series-2); }
.pitch .shot.miss { fill-opacity: .2; stroke-width: .6; }
.pitch .shot.home.miss { stroke: var(--series-1); }
.pitch .shot.away.miss { stroke: var(--series-2); }
.pitch .shot:hover { fill-opacity: 1; stroke: var(--text); }

/* ══ Gráficos ──────────────────────────────────────────────────────────── */
.chart { position: relative; height: 240px; }
.chart-table { margin-top: .5rem; }
.chart-table summary { cursor: pointer; font-size: .82rem; color: var(--muted); }
.empty { color: var(--muted); padding: .75rem 0; margin: 0; }
.htmx-request .loading-fade, .htmx-request.loading-fade { opacity: .55; transition: opacity .2s; }

/* ══ Panel de actualizaciones ──────────────────────────────────────────── */
.errors summary { cursor: pointer; color: var(--critical); }
.errors ul { margin: .25rem 0 0; padding-left: 1.1rem; }
.error-text { color: var(--critical); margin: 0; }
.run-header { display: flex; flex-wrap: wrap; align-items: center; gap: .6rem; margin-bottom: .75rem; }
.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: .75rem; margin-bottom: 1.25rem; }
.run { margin-bottom: 1rem; }

@media (max-width: 640px) {
  .topbar { flex-wrap: wrap; }
  .search { order: 3; width: 100%; }
  .nav { flex-basis: 100%; order: 2; }
  .match-header { gap: .5rem; }
  .card { padding: .85rem 1rem; }
  .hide-mobile { display: none; }
}
