:root {
  color-scheme: light;
  --marca: #3a4c98;        /* azul del logo */
  --marca-osc: #26336b;
  --amarillo: #faeb43;     /* amarillo del logo */
  --banda: #151c3f;        /* azul marino de la banda superior (contrasta con el logo) */
  --banda-2: #0c1129;
  --bg: #f3f4f7;
  --surface: #fcfcfb;
  --surface-2: #eff0f4;
  --border: #e1e3ea;
  --text: #0b0b0b;
  --text-2: #52514e;
  --text-3: #7b7a76;
  --series-1: #2a78d6;   /* real / temporada actual */
  --series-2: #eb6834;   /* proyección */
  --series-3: #1baf7a;
  --ref: #c3c6cd;        /* meta / esperado (referencia neutra) */
  --ref-strong: #7d828c;
  --grid: #e9eaed;
  --good: #0a7d32;
  --bad: #c62828;
  --focus: #2a78d6;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --marca: #22306a; --marca-osc: #161f47;
    --bg: #121211; --surface: #1a1a19; --surface-2: #242423; --border: #30302e;
    --text: #f0efec; --text-2: #c3c2b7; --text-3: #8f8e86;
    --series-1: #3987e5; --series-2: #d95926; --series-3: #199e70;
    --ref: #4a4c52; --ref-strong: #8b8f98; --grid: #2a2a28;
    --good: #4cc27a; --bad: #f07070; --shadow: none;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --marca: #22306a; --marca-osc: #161f47;
  --bg: #121211; --surface: #1a1a19; --surface-2: #242423; --border: #30302e;
  --text: #f0efec; --text-2: #c3c2b7; --text-3: #8f8e86;
  --series-1: #3987e5; --series-2: #d95926; --series-3: #199e70;
  --ref: #4a4c52; --ref-strong: #8b8f98; --grid: #2a2a28;
  --good: #4cc27a; --bad: #f07070; --shadow: none;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 14px/1.45 "Inter", system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}
button, select, input { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.num { font-variant-numeric: tabular-nums; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- armazón: banda superior azul con logo, áreas y controles ---------- */
.top {
  display: flex; align-items: center; gap: 12px 24px; flex-wrap: wrap;
  background: linear-gradient(90deg, var(--banda) 0%, var(--banda-2) 100%);
  color: #fff; padding: 8px 24px; border-bottom: 3px solid var(--amarillo);
}
#side { display: flex; align-items: center; gap: 20px; min-width: 0; }
#side .logo { display: block; flex: none; }
#side .logo img { height: 52px; width: auto; display: block; }
#side nav { display: flex; gap: 2px; overflow-x: auto; scrollbar-width: none; }
#side nav a, #side nav span {
  color: rgba(255,255,255,.82); text-decoration: none; padding: 8px 12px; border-radius: 8px; font-size: 14px; white-space: nowrap;
  border-bottom: 3px solid transparent;
}
#side nav a:hover { background: rgba(255,255,255,.08); }
#side nav a.activo { background: rgba(255,255,255,.14); color: #fff; font-weight: 650; border-bottom-color: var(--amarillo); }
#side nav span.off { opacity: .45; cursor: default; }
#barra { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-left: auto; }
#barra .ctl { display: flex; align-items: center; gap: 8px; }
#barra .etq { color: rgba(255,255,255,.75); font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .4px; }
#barra select { background-color: rgba(255,255,255,.1); color: #fff; border-color: rgba(255,255,255,.3);
  background-image: linear-gradient(45deg, transparent 50%, #fff 50%), linear-gradient(135deg, #fff 50%, transparent 50%); }
#barra select option { color: #111; }
#barra .seg { border-color: rgba(255,255,255,.3); }
#barra .seg button { background: transparent; color: rgba(255,255,255,.85); }
#barra .seg button + button { border-left-color: rgba(255,255,255,.3); }
#barra .seg button:hover { background: rgba(255,255,255,.08); }
#barra .seg button[aria-pressed="true"] { background: rgba(255,255,255,.18); color: #fff; box-shadow: inset 0 -2px 0 var(--amarillo); }
#barra .tc { font-size: 12px; color: #1b1b1b; background: var(--amarillo); border-radius: 999px; padding: 3px 10px; font-weight: 600; }
#barra .salir { color: rgba(255,255,255,.8); text-decoration: none; font-size: 13px; }
.contenido { min-width: 0; }
main { max-width: 1440px; margin: 0 auto; padding: 20px 24px 48px; }

/* ---------- controles ---------- */
.encabezado { display: flex; align-items: flex-end; gap: 16px; flex-wrap: wrap; margin-bottom: 14px; }
.encabezado h1 { font-size: 22px; margin: 0; }
.encabezado .corte { color: var(--text-2); font-size: 13px; }
.encabezado .acciones { margin-left: auto; display: flex; gap: 8px; align-items: center; }
.filtros {
  display: flex; flex-wrap: wrap; align-items: center; gap: 10px 18px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 10px 14px; margin-bottom: 16px; box-shadow: var(--shadow); position: sticky; top: 0; z-index: 5;
}
.filtro { display: flex; align-items: center; gap: 8px; min-width: 0; max-width: 100%; }
.filtro select { min-width: 0; max-width: 100%; }
.filtro > label, .filtro > .etq { color: var(--text-2); font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .4px; }
select {
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 6px 28px 6px 10px; appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--text-2) 50%), linear-gradient(135deg, var(--text-2) 50%, transparent 50%);
  background-position: calc(100% - 14px) 52%, calc(100% - 9px) 52%; background-size: 5px 5px; background-repeat: no-repeat;
}
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { border: 1px solid var(--border); background: var(--surface); border-radius: 999px; padding: 4px 12px; cursor: pointer; }
.chip[aria-pressed="true"] { background: var(--marca); color: #fff; border-color: var(--marca); }
.chip:disabled { opacity: .4; cursor: not-allowed; }
.seg { display: flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.seg button { border: 0; background: var(--surface); padding: 5px 12px; cursor: pointer; }
.seg button + button { border-left: 1px solid var(--border); }
.seg button[aria-pressed="true"] { background: var(--surface-2); font-weight: 650; box-shadow: inset 0 -2px 0 var(--marca); }
.btn { border: 1px solid var(--border); background: var(--surface); border-radius: 8px; padding: 6px 12px; cursor: pointer; }
.btn:hover, .chip:not([aria-pressed="true"]):hover, .seg button:hover { background: var(--surface-2); }
.limpiar { color: var(--series-1); background: none; border: 0; cursor: pointer; padding: 4px; }
.limpiar[hidden] { display: none; }

/* ---------- KPIs ---------- */
.kpis { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); min-width: 0; border-top: 3px solid var(--amarillo); }
.kpi .l { color: var(--text-2); font-size: 12.5px; font-weight: 600; }
.kpi .v { font-size: 26px; font-weight: 700; letter-spacing: -.3px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 2px; }
.kpi .v.apagado { color: var(--text-3); font-size: 17px; padding: 6px 0 3px; white-space: normal; }
.kpi .s { color: var(--text-3); font-size: 12px; margin-top: 4px; }
.estado { font-weight: 650; }
.estado.bien { color: var(--good); }
.estado.mal { color: var(--bad); }

/* ---------- tarjetas ---------- */
.grid { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: 16px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px 10px; box-shadow: var(--shadow); min-width: 0; }
.card[hidden] { display: none; }
.c12 { grid-column: span 12; } .c8 { grid-column: span 8; } .c7 { grid-column: span 7; } .c5 { grid-column: span 5; } .c4 { grid-column: span 4; }
.card-h { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 4px; }
.card-h h2 { font-size: 15px; margin: 0; }
.card-h .nota { color: var(--text-3); font-size: 12px; }
.card-h .der { margin-left: auto; display: flex; gap: 8px; align-items: center; }
.chart { width: 100%; height: 320px; transition: opacity .15s; }
.chart.alto { height: 380px; }
.cargando .chart, .cargando .kpi .v, .cargando .prox { opacity: .45; }

/* Próximo juego */
.prox .titulo { font-size: 20px; font-weight: 700; margin: 6px 0 2px; }
.prox .sub { color: var(--text-2); font-size: 13px; }
.prox .dias { display: inline-block; margin-top: 8px; background: var(--amarillo); color: #1b1b1b; font-weight: 700; font-size: 12px; border-radius: 999px; padding: 3px 10px; }
.prox .barra { height: 10px; background: var(--surface-2); border-radius: 999px; margin: 16px 0 6px; position: relative; overflow: hidden; }
.prox .barra i { position: absolute; left: 0; top: 0; bottom: 0; background: var(--series-1); border-radius: 999px; }
.prox .barra b { position: absolute; top: -3px; bottom: -3px; width: 2px; background: var(--text); }
.prox dl { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 16px; margin: 14px 0 4px; }
.prox dt { color: var(--text-2); font-size: 12px; }
.prox dd { margin: 0; font-size: 17px; font-weight: 650; }

/* Tabla */
.tabla-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { padding: 8px 10px; border-bottom: 1px solid var(--border); text-align: right; white-space: nowrap; }
th.izq, td.izq { text-align: left; }
th { color: var(--text-2); font-weight: 600; font-size: 12px; cursor: pointer; user-select: none; background: var(--surface); }
th[aria-sort="ascending"]::after { content: " ▲"; font-size: 10px; }
th[aria-sort="descending"]::after { content: " ▼"; font-size: 10px; }
tbody tr { cursor: pointer; }
tbody tr:hover td { background: var(--surface-2); }
tbody tr.sel td { background: color-mix(in srgb, var(--series-1) 12%, transparent); }
tbody tr.fija { cursor: default; }
tfoot td { font-weight: 700; border-bottom: 0; }

.aviso { background: var(--surface); border: 1px solid var(--border); border-left: 4px solid var(--bad); border-radius: 8px; padding: 12px 14px; margin-bottom: 16px; }
.aviso[hidden] { display: none; }

@media (max-width: 1200px) {
  .kpis { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .c8, .c7, .c5, .c4 { grid-column: span 12; }
}
@media (max-width: 860px) {
  .top { padding: 8px 16px; }
  #side { width: 100%; gap: 12px; }
  #side .logo img { height: 40px; }
  #side nav span.off { display: none; }
  #barra { margin-left: 0; }
}
@media (max-width: 640px) {
  main { padding: 14px 16px 40px; }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .kpi .v { font-size: 21px; }
  .filtros { position: static; }
  .filtro { width: 100%; }
  .filtro select { flex: 1; }
  .chart { height: 280px; }
}

/* ---------- login ---------- */
.login-body { min-height: 100vh; display: grid; place-items: center; background: linear-gradient(180deg, var(--banda), var(--banda-2)); padding: 16px; }
.login { background: var(--surface); border-radius: 14px; padding: 28px; width: 100%; max-width: 360px; box-shadow: 0 10px 30px rgba(0,0,0,.25); border-top: 4px solid var(--amarillo); }
.login img { display: block; width: 120px; margin: 0 auto 12px; }
.login h1 { margin: 0 0 4px; font-size: 20px; text-align: center; }
.login p { margin: 0 0 20px; color: var(--text-2); font-size: 13px; text-align: center; }
.login input { width: 100%; padding: 10px 12px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); margin-bottom: 12px; }
.login button { width: 100%; padding: 10px; border: 0; border-radius: 8px; background: var(--marca); color: #fff; font-weight: 650; cursor: pointer; }
.login .err { color: var(--bad); font-size: 13px; min-height: 18px; margin-top: 10px; }
