/* Torneo SAE · estilo "accent ladder" con el azul de la FCAI.
   El azul pleno solo en marcas chicas (botón, ícono activo, datos); sus tintes pálidos en las áreas. */

:root {
  --ground: #f5f8fa;
  --surface: #ffffff;
  --raised: #eef3f6;
  --border: #e3e9ee;
  --rule: #edf1f4;
  --control: #c9d3db;
  --text: #13202a;
  --muted: #55626d;
  --faint: #66727c;
  --accent: #3e789a;        /* azul FCAI */
  --accent-ink: #24506a;    /* tinta oscura del mismo tono */
  --tint-50: #f0f6f9;
  --tint-100: #e1edf4;
  --tint-200: #c6dbe8;
  --positive: #247b50; --negative: #c4242a;
  --pill-positive-bg: #dcfae5; --pill-positive-ink: #04250e;
  --pill-warning-bg: #fffbeb; --pill-warning-ink: #92400e;
  --pill-neutral-bg: #edf1f4; --pill-neutral-ink: #34414b;

  --font: "Public Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  --fs-title: 24px; --fs-section: 16px; --fs-body: 15px; --fs-small: 13px;

  --sidebar: 224px;
  --topbar: 64px;
  --pad: 28px;
  --gap: 16px;
  --card-pad: 20px;
  --radius-card: 8px;
  --radius-control: 6px;
  --control-height: 36px;
  --row: 48px;

  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body { margin: 0; background: var(--ground); color: var(--text); font: 400 var(--fs-body)/22px var(--font); -webkit-font-smoothing: antialiased; }
h1, h2, h3, p, ul, ol, dl, dd, figure { margin: 0; }
ul, ol { padding: 0; list-style: none; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: inherit; text-decoration: none; }
svg { display: block; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
.num, table { font-variant-numeric: tabular-nums; }
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- shell: barra superior + lateral, mismo fondo, separadas por una regla ---------- */
.app { display: grid; grid-template-columns: var(--sidebar) minmax(0, 1fr); grid-template-rows: var(--topbar) 1fr; min-height: 100svh; }
.topbar { grid-column: 1 / -1; display: flex; align-items: center; gap: 16px; padding: 0 var(--pad) 0 20px; border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 5; background: var(--ground); }
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand-mark { flex: none; width: 30px; height: 30px; }
.brand-name { font-weight: 700; font-size: 15px; line-height: 18px; white-space: nowrap; }
.brand-sub { color: var(--muted); font-size: var(--fs-small); line-height: 16px; white-space: nowrap; }
.topbar .spacer { flex: 1; }
.stamp { color: var(--muted); font-size: var(--fs-small); white-space: nowrap; display: flex; align-items: center; gap: 6px; }
.stamp .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--positive); }
.stamp.stale .dot { background: var(--negative); }

/* selector de torneo: el alcance de toda la pantalla */
.switch { display: inline-flex; padding: 3px; gap: 2px; background: var(--raised); border-radius: 999px; }
.switch button { border: 0; background: none; height: 32px; padding: 0 16px; border-radius: 999px; font-weight: 600; color: var(--muted); cursor: pointer; transition: background-color .15s, color .15s; }
.switch button:hover { color: var(--text); }
.switch button[aria-pressed="true"] { background: var(--surface); color: var(--accent-ink); }
.switch-wrap { padding-left: 16px; border-left: 1px solid var(--border); height: 100%; display: flex; align-items: center; }

.sidebar { border-right: 1px solid var(--border); padding: 20px 12px; display: flex; flex-direction: column; gap: 2px; position: sticky; top: var(--topbar); height: calc(100svh - var(--topbar)); }
.nav a { display: flex; align-items: center; gap: 10px; height: 38px; padding: 0 12px; border-radius: var(--radius-control); color: var(--muted); font-weight: 500; transition: background-color .15s, color .15s; }
.nav a:hover { background: var(--raised); color: var(--text); }
.nav a svg { width: 18px; height: 18px; flex: none; }
.nav a[aria-current="page"] { background: var(--tint-100); color: var(--accent-ink); }
.nav a[aria-current="page"] svg { color: var(--accent); }
.nav .count { margin-left: auto; font-size: var(--fs-small); color: var(--accent-ink); font-variant-numeric: tabular-nums; }
.sidebar-foot { margin-top: auto; padding: 12px; color: var(--muted); font-size: var(--fs-small); line-height: 18px; }
.sidebar-foot a { color: var(--accent-ink); font-weight: 500; }

.canvas { padding: 28px var(--pad) 64px; min-width: 0; }
.title-row { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 24px; flex-wrap: wrap; }
.title-row h1 { font-size: var(--fs-title); line-height: 30px; font-weight: 700; letter-spacing: -0.01em; }
.title-row .lead { color: var(--muted); margin-top: 4px; }
.notice { background: var(--pill-warning-bg); border: 1px solid #fde68a; color: var(--pill-warning-ink); border-radius: var(--radius-card); padding: 12px 16px; margin-bottom: var(--gap); font-weight: 500; }

/* ---------- paneles ---------- */
.grid { display: grid; gap: var(--gap); grid-template-columns: minmax(0, 1fr) 384px; align-items: start; }
.stack { display: grid; gap: var(--gap); align-content: start; min-width: 0; }
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-card); min-width: 0; }
.panel-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; padding: 16px var(--card-pad) 8px; }
.panel-head h2 { font-size: var(--fs-section); line-height: 22px; font-weight: 650; }
.panel-head .meta { color: var(--muted); font-size: var(--fs-small); }
.panel-body { padding: 4px var(--card-pad) var(--card-pad); }
.empty { color: var(--muted); padding: 12px 14px; border: 1px dashed var(--control); border-radius: var(--radius-card); }

/* tarjeta de "tu equipo": el bloque que responde la pregunta de la pantalla */
.mine { background: var(--tint-50); border-color: var(--tint-200); }
.mine .panel-head { padding-bottom: 4px; }
.mine-pick { display: flex; gap: 8px; align-items: center; }
.mine-next { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 4px 16px; align-items: end; padding-top: 8px; }
.mine-label { color: var(--accent-ink); font-weight: 600; font-size: var(--fs-small); }
.mine-vs { font-size: 26px; line-height: 32px; font-weight: 700; letter-spacing: -0.01em; }
.mine-meta { color: var(--muted); }
.mine-table { text-align: right; }
.mine-table .n { display: block; font-size: 34px; line-height: 38px; font-weight: 700; color: var(--accent-ink); font-variant-numeric: tabular-nums; }
.mine-table .l { color: var(--muted); font-size: var(--fs-small); }
.mine-zone { margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--tint-200); color: var(--muted); display: flex; gap: 16px; flex-wrap: wrap; }
.mine-zone b { color: var(--text); font-weight: 600; }

/* ---------- filas de partidos ---------- */
.matches li { display: grid; grid-template-columns: 64px minmax(0, 1fr) auto; align-items: center; gap: 12px; min-height: 56px; padding: 8px 0; border-top: 1px solid var(--rule); }
.matches li:first-child { border-top: 0; }
.matches .where, .admin-row .where { font-size: var(--fs-small); color: var(--muted); line-height: 16px; }
.matches .where b, .admin-row .where b { display: block; color: var(--text); font-size: 17px; line-height: 22px; font-weight: 700; font-variant-numeric: tabular-nums; }
.matches .teams { min-width: 0; }
.matches .teams .t, .admin-row .teams .t { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.matches .teams .t.win, .admin-row .t.win { font-weight: 650; }
.matches .teams .t.lose, .admin-row .t.lose { color: var(--muted); }
.matches .teams .sub, .admin-row .teams .sub { color: var(--muted); font-size: var(--fs-small); line-height: 18px; }
.matches .score { text-align: right; font-variant-numeric: tabular-nums; line-height: 22px; }
.matches .score span { display: block; }
.matches .score .win { font-weight: 700; }
.matches .score .lose { color: var(--muted); }
.matches li.me { background: var(--tint-50); margin: 0 calc(var(--card-pad) * -1); padding-left: var(--card-pad); padding-right: var(--card-pad); }
.vs { color: var(--muted); font-size: var(--fs-small); padding: 0 2px; }

.pill { display: inline-flex; align-items: center; gap: 6px; height: 22px; padding: 0 9px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; flex: none; background: var(--pill-neutral-bg); color: var(--pill-neutral-ink); }
.pill.live { background: var(--tint-100); color: var(--accent-ink); }
.pill.live::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--accent); animation: pulse 1.6s ease-in-out infinite; }
.pill.ok { background: var(--pill-positive-bg); color: var(--pill-positive-ink); }
@keyframes pulse { 50% { opacity: .35; } }

/* ---------- tablas de zona ---------- */
.zones { display: grid; gap: var(--gap); grid-template-columns: repeat(auto-fill, minmax(min(100%, 420px), 1fr)); align-items: start; }
table.std { width: 100%; border-collapse: collapse; }
.std th { font-size: 12px; font-weight: 500; color: var(--muted); text-align: right; padding: 0 0 8px 10px; white-space: nowrap; }
.std th:nth-child(2) { text-align: left; }
.std td { height: 44px; border-top: 1px solid var(--rule); text-align: right; padding-left: 10px; white-space: nowrap; }
.std td.pos { width: 28px; text-align: left; padding-left: 0; color: var(--muted); }
.std td.name { text-align: left; white-space: normal; width: 100%; font-weight: 500; }
.std td.pts { font-weight: 700; }
.std tr.q td { background: var(--tint-50); }
.std tr.q td:first-child { border-radius: 6px 0 0 6px; }
.std tr.q td:last-child { border-radius: 0 6px 6px 0; padding-right: 8px; }
.std tr.q td.pos { color: var(--accent-ink); font-weight: 700; padding-left: 8px; }
.std tr.me td.name::after { content: "tu equipo"; margin-left: 8px; font-size: 12px; font-weight: 600; color: var(--accent-ink); }
.legend { display: flex; gap: 16px; color: var(--muted); font-size: var(--fs-small); margin-bottom: 16px; flex-wrap: wrap; }
.legend i { display: inline-block; width: 12px; height: 12px; border-radius: 3px; background: var(--tint-50); border: 1px solid var(--tint-200); vertical-align: -1px; margin-right: 6px; }

/* ---------- llaves ---------- */
.bracket { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(220px, 1fr); gap: var(--gap); overflow-x: auto; padding-bottom: 4px; }
.bracket-round h2 { font-size: var(--fs-section); font-weight: 650; margin-bottom: 10px; }
.bracket-round ol { display: flex; flex-direction: column; justify-content: space-around; gap: 12px; height: calc(100% - 32px); }
.tie { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-card); padding: 6px 12px; }
.tie .row { display: flex; justify-content: space-between; gap: 10px; height: 34px; align-items: center; }
.tie .row + .row { border-top: 1px solid var(--rule); }
.tie .row span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tie .row.win { font-weight: 700; }
.tie .row.lose { color: var(--muted); }
.tie .row.tbd { color: var(--faint); }
.tie .foot { font-size: 12px; color: var(--muted); padding: 2px 0 2px; display: flex; justify-content: space-between; }
.tie.live { border-color: var(--tint-200); background: var(--tint-50); }
.tie.me { border-color: var(--accent); }
.champion { display: flex; align-items: center; gap: 16px; padding: 20px var(--card-pad); }
.champion svg { width: 40px; height: 40px; flex: none; color: var(--accent); }
.champion .who { font-size: 26px; line-height: 32px; font-weight: 700; }

/* ---------- equipos ---------- */
.teams-list { columns: 3 260px; column-gap: 32px; }
.teams-list li { break-inside: avoid; padding: 10px 0; border-top: 1px solid var(--rule); }
.teams-list .n { font-weight: 600; }
.teams-list .p { color: var(--muted); font-size: var(--fs-small); line-height: 18px; }

/* ---------- controles ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; height: var(--control-height); padding: 0 14px; border-radius: var(--radius-control); border: 1px solid var(--control); background: var(--surface); font-weight: 600; cursor: pointer; white-space: nowrap; transition: background-color .15s, border-color .15s, transform .12s; }
.btn:hover { background: var(--raised); }
.btn:active { transform: scale(.97); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-ink); border-color: var(--accent-ink); }
.btn.ghost { border-color: transparent; background: none; color: var(--accent-ink); }
.btn.ghost:hover { background: var(--tint-50); }
.btn.danger { color: var(--negative); }
.btn[disabled] { opacity: .6; cursor: not-allowed; }
.btn.sm { height: 30px; padding: 0 10px; font-size: 14px; }
select, input[type="text"], input[type="number"], input[type="password"], input[type="search"], textarea {
  height: var(--control-height); border: 1px solid var(--control); border-radius: var(--radius-control); background: var(--surface); padding: 0 10px; min-width: 0;
}
textarea { height: auto; padding: 8px 10px; resize: vertical; line-height: 20px; }
select { padding-right: 28px; }
label.field { display: grid; gap: 6px; font-weight: 500; font-size: 14px; }
label.field .hint { color: var(--muted); font-weight: 400; font-size: var(--fs-small); }

/* ---------- carga, error ---------- */
.skeleton { background: var(--raised); border-radius: 4px; height: 14px; }
.error-line { color: var(--muted); }
.error-line button { margin-left: 8px; }

/* ---------- celular ---------- */
.tabbar { display: none; }

@media (max-width: 900px) {
  .grid { grid-template-columns: minmax(0, 1fr); }
}

@media (max-width: 760px) {
  :root { --pad: 16px; --card-pad: 16px; --topbar: 56px; }
  .app { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto 1fr; }
  .topbar { padding: 0 var(--pad); gap: 10px; height: var(--topbar); }
  .brand-sub, .topbar .stamp { display: none; }
  .switch-wrap { border: 0; padding: 0; margin-left: auto; }
  .switch button { padding: 0 13px; height: 34px; }
  .sidebar { display: none; }
  .canvas { padding: 20px var(--pad) calc(96px + env(safe-area-inset-bottom)); }
  .title-row { margin-bottom: 16px; }
  .title-row h1 { font-size: 22px; line-height: 28px; }
  .mobile-stamp { display: flex !important; }
  .tabbar { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; position: fixed; inset: auto 0 0 0; z-index: 6; background: var(--surface); border-top: 1px solid var(--border); padding-bottom: env(safe-area-inset-bottom); }
  .tabbar a { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; height: 60px; font-size: 12px; font-weight: 600; color: var(--muted); }
  .tabbar a svg { width: 22px; height: 22px; }
  .tabbar a[aria-current="page"] { color: var(--accent-ink); }
  .tabbar a[aria-current="page"] svg { color: var(--accent); }
  .mine-vs { font-size: 22px; line-height: 28px; }
  .mine-table .n { font-size: 30px; }
  .bracket { grid-auto-flow: row; grid-auto-columns: auto; overflow: visible; }
  .bracket-round ol { height: auto; }
  .std .hide-sm { display: none; }
  .teams-list { columns: 1; }
}
.mobile-stamp { display: none; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* ---------- panel de organizadores ---------- */
.login { max-width: 380px; margin: 48px auto; }
.login form { display: grid; gap: 16px; }
.login .err { color: var(--negative); font-size: 14px; }
.admin-row { display: grid; grid-template-columns: 64px minmax(0, 1fr) auto; align-items: center; gap: 12px; min-height: 60px; padding: 8px 0; border-top: 1px solid var(--rule); }
.admin-row:first-child { border-top: 0; }
.admin-row .acts { display: flex; gap: 8px; align-items: center; justify-content: flex-end; flex-wrap: wrap; }
.admin-row .acts input { width: 64px; text-align: center; }
.busy-tables { color: var(--muted); font-size: var(--fs-small); }
.form-grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); align-items: end; }
.form-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 16px; }
.check-row { display: grid; grid-template-columns: 28px minmax(0, 1fr) auto; gap: 10px; align-items: center; min-height: 52px; border-top: 1px solid var(--rule); padding: 6px 0; }
.check-row:first-child { border-top: 0; }
.check-row input[type="checkbox"] { width: 22px; height: 22px; accent-color: var(--accent); }
.check-row .p { color: var(--muted); font-size: var(--fs-small); line-height: 18px; }
.check-row.absent .n { color: var(--muted); }
.cols { display: flex; flex-wrap: wrap; gap: 8px 16px; }
.cols label { display: flex; gap: 6px; align-items: center; font-size: 14px; }
.toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 8px; }
.toolbar input[type="search"] { flex: 1; min-width: 160px; }
.zone-chips { display: flex; flex-wrap: wrap; gap: 8px; }
.zone-chip { background: var(--raised); border-radius: var(--radius-card); padding: 10px 12px; min-width: 180px; flex: 1; }
.zone-chip b { display: block; margin-bottom: 4px; }
.zone-chip span { display: block; font-size: 14px; color: var(--muted); }
.edit-ties { display: grid; gap: 8px; }
.edit-ties .tie-edit { display: grid; grid-template-columns: 1fr auto 1fr; gap: 8px; align-items: center; }
.toast { position: fixed; left: 50%; bottom: 88px; transform: translateX(-50%); background: var(--text); color: #fff; padding: 10px 16px; border-radius: 999px; font-weight: 600; font-size: 14px; z-index: 20; box-shadow: 0 6px 20px rgba(19, 32, 42, .2); } /* taste-skill-ignore: flota */
.toast.err { background: var(--negative); }
dialog { border: 0; border-radius: 12px; padding: 0; width: min(440px, calc(100vw - 24px)); box-shadow: 0 16px 48px rgba(19, 32, 42, .24); color: var(--text); } /* taste-skill-ignore: diálogo */
dialog::backdrop { background: rgba(19, 32, 42, .4); }
dialog form { padding: 20px; display: grid; gap: 16px; }
dialog h2 { font-size: 18px; line-height: 24px; }
.winner-pick { display: grid; gap: 8px; }
.winner-pick label { display: grid; grid-template-columns: 22px minmax(0, 1fr) 84px; gap: 10px; align-items: center; min-height: 52px; padding: 6px 12px; border: 1px solid var(--control); border-radius: var(--radius-card); cursor: pointer; }
.winner-pick label:has(input:checked) { border-color: var(--accent); background: var(--tint-50); }
.winner-pick input[type="radio"] { width: 20px; height: 20px; accent-color: var(--accent); }
.winner-pick input[type="number"] { width: 84px; text-align: right; }
.dlg-actions { display: flex; gap: 8px; justify-content: space-between; flex-wrap: wrap; }
.dlg-actions .right { display: flex; gap: 8px; margin-left: auto; }
@media (max-width: 760px) {
  dialog { margin: auto 0 0; width: 100vw; max-width: 100vw; border-radius: 14px 14px 0 0; }
  .admin-row { grid-template-columns: minmax(0, 1fr); gap: 8px; }
  .admin-row .where { display: none; }
  .admin-row .acts { justify-content: flex-start; }
  .admin-row .acts .btn { height: 40px; }
  .toast { bottom: 84px; }
}
