:root {
  --bg: #f4f5f7; --card: #ffffff; --text: #1b1f24; --muted: #6b7280; --line: #e3e6ea;
  --grid: rgba(0,0,0,0.07); --accent: #e0562b; --accent-2: #2b6cb0; --good: #1f9d55; --bad: #d64545;
  --p1: #9aa5b1; --p2: #2b6cb0; --p3: #e0562b; --court: #f7efe2; --court-line: #b89a6d;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111418; --card: #1a1f25; --text: #e8eaed; --muted: #9aa3ad; --line: #2c333b;
    --grid: rgba(255,255,255,0.08); --court: #2a2520; --court-line: #8a7556;
  }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
a { color: var(--accent-2); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.5rem; margin: 0 0 .6rem; }
h2 { font-size: 1.15rem; margin: 0 0 .8rem; }
h3 { font-size: .95rem; margin: 1.2rem 0 .5rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
code { background: var(--bg); padding: 1px 5px; border-radius: 4px; }
.top { display: flex; justify-content: space-between; align-items: center; padding: 12px 20px; background: var(--card); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 10; }
.top nav a { margin-left: 18px; }
.brand { font-weight: 700; font-size: 1.1rem; color: var(--text); }
main { max-width: 1280px; margin: 0 auto; padding: 18px 16px 40px; }
footer { text-align: center; color: var(--muted); font-size: 12px; padding: 20px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 18px 20px; margin-bottom: 16px; }
.card.warn { border-color: #e0a52b; background: color-mix(in srgb, #e0a52b 10%, var(--card)); }
.card.warn ul { margin: 6px 0 0; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.error { color: var(--bad); font-weight: 600; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 860px) { .grid2 { grid-template-columns: 1fr; } }
.row-between { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.badge { background: var(--accent); color: #fff; border-radius: 999px; padding: 2px 10px; font-size: 12px; font-weight: 600; }
.dot { display: inline-block; width: 12px; height: 12px; border-radius: 50%; vertical-align: middle; }

.import { display: flex; gap: 10px; flex-wrap: wrap; }
.import textarea { flex: 1 1 400px; padding: 10px; border-radius: 8px; border: 1px solid var(--line); background: var(--bg); color: var(--text); font: inherit; }
button { background: var(--accent); color: #fff; border: 0; border-radius: 8px; padding: 10px 16px; font: inherit; font-weight: 600; cursor: pointer; }
button.ghost { background: transparent; color: var(--text); border: 1px solid var(--line); padding: 6px 12px; font-weight: 500; }
button.ghost.danger { color: var(--bad); }

.kpis { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 10px; margin: 8px 0 4px; }
.kpis > div { background: var(--bg); border-radius: 10px; padding: 10px 12px; }
.kpis b { display: block; font-size: 1.35rem; }
.kpis span { color: var(--muted); font-size: 12px; }

.scoreboard { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 16px; }
.sb-team { display: flex; align-items: center; gap: 10px; font-size: 1.05rem; font-weight: 600; }
.sb-team b { font-size: 2.4rem; margin-left: auto; }
.sb-team.right b { margin-left: 0; margin-right: auto; }
.sb-team.right { justify-content: flex-end; text-align: right; }
.sb-team.win b { color: var(--accent); }
.sb-mid { text-align: center; }
.periods { margin: 6px auto 0; border-collapse: collapse; font-size: 13px; }
.periods th, .periods td { padding: 2px 8px; }
.periods td.hi { font-weight: 700; }
@media (max-width: 700px) { .scoreboard { grid-template-columns: 1fr; } .sb-team b { font-size: 1.8rem; } }

.toolbar { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 10px; margin-bottom: 12px; }
.actions { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.actions form { margin: 0; }
.seg { display: inline-flex; background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 3px; flex-wrap: wrap; }
.seg a { padding: 6px 12px; border-radius: 8px; color: var(--text); cursor: pointer; user-select: none; }
.seg a.on { background: var(--accent); color: #fff; text-decoration: none; }
.seg.small a { padding: 3px 9px; font-size: 12px; }
.seg.small { margin-bottom: 10px; }
.tabs { display: flex; gap: 4px; flex-wrap: wrap; margin-bottom: 12px; border-bottom: 1px solid var(--line); }
.tabs a { padding: 8px 14px; color: var(--muted); border-bottom: 2px solid transparent; }
.tabs a.on { color: var(--text); border-bottom-color: var(--accent); text-decoration: none; font-weight: 600; }

.scroll { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: 13px; font-variant-numeric: tabular-nums; }
table.data th, table.data td { padding: 6px 8px; text-align: center; border-bottom: 1px solid var(--line); white-space: nowrap; }
table.data th { color: var(--muted); font-weight: 600; font-size: 12px; }
table.data .l { text-align: left; }
table.data.compact td, table.data.compact th { padding: 4px 6px; }
table.data.list td { text-align: left; }
table.data.list td.num { text-align: right; }
th.clickable { cursor: pointer; }
th[data-dir="desc"]::after { content: " ▼"; }
th[data-dir="asc"]::after { content: " ▲"; }
td.bad { color: var(--bad); font-weight: 700; }
tr.good td:first-child, td.good { color: var(--good); }
tr.badrow td:first-child, td.badrow { color: var(--bad); }
.st { color: var(--accent); }

.unit { display: inline-flex; gap: 4px; flex-wrap: nowrap; }
.chip { display: inline-flex; flex-direction: column; align-items: center; min-width: 38px; padding: 2px 5px; border-radius: 6px; background: var(--bg); font-weight: 700; line-height: 1.1; }
.chip small { font-weight: 400; font-size: 10px; color: var(--muted); }

table.matrix { border-collapse: collapse; font-size: 12px; font-variant-numeric: tabular-nums; }
table.matrix td { width: 50px; min-width: 50px; height: 30px; text-align: center; border: 1px solid var(--line); }
table.matrix td.self { background: var(--bg); font-weight: 700; }
table.matrix td.empty { color: var(--muted); }
table.matrix th.rowh { text-align: right; padding-right: 8px; white-space: nowrap; font-weight: 500; }
table.matrix th.rot { height: 90px; vertical-align: bottom; padding: 0; }
table.matrix th.rot span { display: inline-block; writing-mode: vertical-rl; transform: rotate(180deg); white-space: nowrap; font-weight: 500; padding-bottom: 4px; }

.mix { display: flex; height: 26px; border-radius: 6px; overflow: hidden; font-size: 12px; color: #fff; font-weight: 600; }
.mix i { font-style: normal; display: flex; align-items: center; justify-content: center; overflow: hidden; white-space: nowrap; }
.mix .p1 { background: var(--p1); } .mix .p2 { background: var(--p2); } .mix .p3 { background: var(--p3); }
.legend { font-size: 12px; color: var(--muted); margin: 4px 0 8px; }
.legend .k { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin: 0 4px 0 10px; vertical-align: middle; }
.legend .k.p1 { background: var(--p1); } .legend .k.p2 { background: var(--p2); } .legend .k.p3 { background: var(--p3); }
.bar { position: relative; background: var(--bg); border-radius: 4px; height: 18px; min-width: 110px; }
.bar i { position: absolute; left: 0; top: 0; bottom: 0; background: var(--accent-2); opacity: .35; border-radius: 4px; }
.bar span { position: relative; font-size: 11px; }

.chart-box { position: relative; height: 320px; margin-bottom: 10px; }
svg.court { width: 100%; max-width: 460px; display: block; margin: 0 auto; background: var(--court); border-radius: 8px; }
svg.court .lines { stroke: var(--court-line); }
svg.rotation { min-width: 800px; font-size: 12px; }
svg.rotation .rlabel { text-anchor: end; fill: var(--text); }
svg.rotation .pline { stroke: var(--line); stroke-dasharray: 3 3; }
svg.rotation .plabel { text-anchor: middle; fill: var(--muted); font-size: 11px; }
svg.rotation .mk-pt { fill: var(--accent); stroke: var(--card); stroke-width: 1; }
svg.rotation .mk-foul { fill: var(--bad); }
svg.rotation .stint { fill: var(--accent-2); fill-opacity: .28; }
svg.rotation .mk-foul { fill: #b3261e; }
.insights { display: grid; grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); gap: 10px; }
.insight { border: 1px solid var(--line); border-left: 4px solid var(--muted); border-radius: 8px; padding: 10px 12px; background: var(--card); }
.insight.good { border-left-color: var(--good); }
.insight.bad { border-left-color: var(--bad); }
.insight .ititle { font-weight: 700; margin-bottom: 3px; }
.insight.good .ititle { color: var(--good); }
.insight.bad .ititle { color: var(--bad); }
.insight .iterm { margin-top: 6px; font-size: 12px; color: var(--muted); border-top: 1px dashed var(--line); padding-top: 5px; }
details.help { margin: -4px 0 12px; font-size: 13px; }
details.help summary { cursor: pointer; color: var(--accent-2); font-size: 12px; }
details.help dl { display: grid; grid-template-columns: max-content 1fr; gap: 4px 14px; background: var(--bg); border-radius: 8px; padding: 10px 14px; margin: 8px 0 0; }
details.help dt { font-weight: 700; }
details.help dd { margin: 0; color: var(--muted); }
@media (max-width: 700px) { details.help dl { grid-template-columns: 1fr; } .insights { grid-template-columns: 1fr; } }
dl.gloss { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; }
dl.gloss dt { font-weight: 700; }
dl.gloss dd { margin: 0; color: var(--muted); }
@media (max-width: 700px) { dl.gloss { grid-template-columns: 1fr; } }

/* ══════════════ Login, formularios y avisos ══════════════ */
.login-page { display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 16px; }
.login-box { width: 100%; max-width: 380px; }
.stack { display: flex; flex-direction: column; gap: 12px; }
label { display: block; font-size: 13px; color: var(--muted); }
input[type=text], input[type=password], input[type=number], input[type=url] {
  display: block; width: 100%; margin-top: 4px; padding: 11px 12px; font: inherit; color: var(--text);
  background: var(--bg); border: 1px solid var(--line); border-radius: 8px; min-height: 44px;
}
.grid-form { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 12px; align-items: end; margin-top: 12px; }
.grid-form .wide { grid-column: 1 / -1; }
.grid-form .check, label.check { display: flex; align-items: center; gap: 8px; color: var(--text); }
.grid-form button { height: 44px; }
form.inline { display: inline-flex; gap: 6px; align-items: center; margin: 0; }
.row-actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }
.row-actions input { width: 150px; min-height: 38px; margin: 0; }
.ok { color: var(--good); font-weight: 600; }
.live { background: var(--bad); color: #fff; border-radius: 999px; padding: 2px 9px; font-size: 12px; font-weight: 700; }

/* ══════════════ Cabecera adaptable ══════════════ */
.burger { display: none; background: transparent; color: var(--text); border: 1px solid var(--line); font-size: 20px; line-height: 1; padding: 6px 12px; }
.top nav { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; }
.top nav a { margin-left: 14px; padding: 6px 0; }

@media (max-width: 760px) {
  .top { flex-wrap: wrap; padding: 10px 14px; }
  .brand span { font-size: .95rem; }
  .burger { display: block; }
  .top nav { display: none; width: 100%; flex-direction: column; align-items: stretch; gap: 0; margin-top: 8px; }
  .top nav.open { display: flex; }
  .top nav a, .top nav form { margin: 0; padding: 12px 4px; border-top: 1px solid var(--line); }
  .top nav form.inline button { width: 100%; }
  main { padding: 12px 12px 32px; }
  .card { padding: 14px; border-radius: 10px; margin-bottom: 12px; }
  h1 { font-size: 1.25rem; }
  h2 { font-size: 1.05rem; }
  .kpis { grid-template-columns: 1fr 1fr; gap: 8px; }
  .kpis > div { padding: 8px 10px; }
  .kpis b { font-size: 1.15rem; }
  .kpis span { font-size: 11px; }
  .chart-box { height: 240px; }
  .tabs { flex-wrap: nowrap; overflow-x: auto; -webkit-overflow-scrolling: touch; scrollbar-width: none; }
  .tabs::-webkit-scrollbar { display: none; }
  .tabs a { white-space: nowrap; padding: 10px 12px; }
  .seg { width: 100%; overflow-x: auto; flex-wrap: nowrap; }
  .seg a { white-space: nowrap; }
  table.data { font-size: 12px; }
  table.data th, table.data td { padding: 7px 6px; }
  .import textarea { flex-basis: 100%; }
  .import button, .grid-form button { width: 100%; }
  .toolbar .actions { width: 100%; justify-content: space-between; }
  svg.court { max-width: 100%; }
}

/* Primera columna fija al desplazar tablas anchas en el móvil */
@media (max-width: 760px) {
  .scroll { -webkit-overflow-scrolling: touch; }
  table.data td.l:first-child, table.data th.l:first-child,
  table.matrix th.rowh { position: sticky; left: 0; z-index: 2; background: var(--card); }
  table.data.sortable td:first-child, table.data.sortable th:first-child { position: sticky; left: 0; z-index: 2; background: var(--card); }
  table.matrix td { width: 44px; min-width: 44px; }
}
.bookmarklet { display: inline-block; background: var(--accent); color: #fff; padding: 6px 12px; border-radius: 8px; font-weight: 600; margin: 6px 0; }
.bookmarklet:hover { text-decoration: none; }
details.help ol { margin: 6px 0 0 18px; }
