/* Swim Stats IB · estilos. Paleta de series: categórica validada (6 primeras posiciones), clara y oscura. */
:root {
  color-scheme: light;
  --bg: #f9f9f9;
  --panel: #ffffff;
  --fg: #191919;
  --fg-muted: #666666;
  --line: rgba(11, 11, 11, 0.12);
  --grid: #e7e7e7;
  --axis: #c2c2c2;
  --accent: #1757ac;
  --accent-fg: #ffffff;
  --accent-soft: #e8f1fd;
  --ok: #006c10;
  --bad: #c42b2c;
  --warn: #8f5500;
  --ok-soft: #e6f4e8;
  --bad-soft: #fdeaea;
  --warn-soft: #fff4dc;
  --s1: #257de0; --s2: #f47230; --s3: #00b894; --s4: #f2a600; --s5: #ee7fac; --s6: #008a17;
  --radius: 8px;
  --shadow: 0 6px 24px rgba(0, 0, 0, 0.12);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --fs-caption: 12.5px;
  --fs-body: 14.5px;
  --fs-heading: 17px;
  --fs-title: 26px;
}
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #0b0b0b;
    --panel: #191919;
    --fg: #efefef;
    --fg-muted: #9c9c9c;
    --line: rgba(255, 255, 255, 0.12);
    --grid: #303030;
    --axis: #474747;
    --accent: #338ced;
    --accent-fg: #0b0b0b;
    --accent-soft: #14263d;
    --ok: #53c556;
    --bad: #eb6263;
    --warn: #f2a600;
    --ok-soft: #12301a;
    --bad-soft: #3a1617;
    --warn-soft: #33270b;
    --s1: #338ced; --s2: #e76624; --s3: #00a888; --s4: #d28e05; --s5: #e24d8b; --s6: #0aac23;
    --shadow: 0 6px 24px rgba(0, 0, 0, 0.5);
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { font-family: var(--font); font-size: var(--fs-body); color: var(--fg); background: var(--bg); line-height: 1.45; }
a { color: var(--accent); }
h1 { font-weight: 500; font-size: var(--fs-title); margin: 0 0 6px; letter-spacing: -0.01em; }
h2 { font-size: var(--fs-heading); font-weight: 600; margin: 0; }
h3 { font-size: var(--fs-body); font-weight: 600; margin: 0; }
p { margin: 0; }
[hidden] { display: none !important; }
.muted { color: var(--fg-muted); font-size: var(--fs-caption); }
.main { max-width: 1280px; margin: 0 auto; padding: 20px 20px 60px; display: flex; flex-direction: column; gap: 24px; }
.lede { max-width: 62em; line-height: 1.55; }

/* ---------------------------------------------------------------- barra superior */
.topbar { position: sticky; top: 0; z-index: 20; background: var(--panel); border-bottom: 1px solid var(--line); }
.topbar-in { max-width: 1280px; margin: 0 auto; padding: 8px 20px; display: flex; align-items: center; gap: 18px; flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 600; color: var(--fg); text-decoration: none; }
.brand img { width: 24px; height: 24px; }
.nav { display: flex; gap: 4px; flex-wrap: wrap; flex: 1; }
.nav a { color: var(--fg-muted); text-decoration: none; padding: 6px 10px; border-radius: 6px; }
.nav a:hover { color: var(--fg); background: var(--bg); }
.nav a.on { color: var(--fg); background: var(--accent-soft); font-weight: 500; }
.who { display: flex; align-items: center; gap: 10px; font-size: var(--fs-caption); color: var(--fg-muted); }
.badge { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 11.5px; border: 1px solid var(--line); color: var(--fg-muted); white-space: nowrap; }
.badge.ok { color: var(--ok); background: var(--ok-soft); border-color: transparent; }
.badge.bad { color: var(--bad); background: var(--bad-soft); border-color: transparent; }
.badge.warn { color: var(--warn); background: var(--warn-soft); border-color: transparent; }
.badge.info { color: var(--accent); background: var(--accent-soft); border-color: transparent; }
.banner { max-width: 1280px; margin: 12px auto 0; padding: 10px 14px; border-radius: var(--radius); background: var(--warn-soft); color: var(--fg); display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
#banner:empty { display: none; }
#banner { padding: 0 20px; }

/* ---------------------------------------------------------------- formularios y botones */
button, .btn { font: inherit; cursor: pointer; border-radius: 6px; padding: 7px 14px; border: 1px solid var(--line); background: var(--panel); color: var(--fg); text-decoration: none; display: inline-flex; align-items: center; gap: 6px; }
button:hover, .btn:hover { border-color: var(--fg-muted); }
button:disabled { opacity: 0.55; cursor: default; }
button.primary, .btn.primary { background: var(--accent); color: var(--accent-fg); border-color: transparent; font-weight: 500; }
button.primary:hover { filter: brightness(1.08); }
button.danger { color: var(--bad); }
button.link { border: none; background: none; padding: 0; color: var(--accent); text-decoration: underline; }
button.small, .btn.small { padding: 3px 9px; font-size: var(--fs-caption); }
button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, .has-tip:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
input, select, textarea { font: inherit; color: var(--fg); background: var(--panel); border: 1px solid var(--line); border-radius: 6px; padding: 7px 9px; min-width: 0; }
textarea { width: 100%; min-height: 90px; font-family: ui-monospace, Consolas, monospace; font-size: 12.5px; }
.field { display: flex; flex-direction: column; gap: 4px; }
.field > span { font-size: var(--fs-caption); color: var(--fg-muted); }
.field input, .field select { width: 100%; }
.check { display: flex; gap: 8px; align-items: flex-start; }
.check input { margin-top: 3px; }
.form { display: flex; flex-direction: column; gap: 12px; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; }
.row > .field { flex: 1 1 180px; }
.err { color: var(--bad); font-size: var(--fs-caption); min-height: 1em; }
.okmsg { color: var(--ok); font-size: var(--fs-caption); }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* ---------------------------------------------------------------- tarjetas y bloques */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; display: flex; flex-direction: column; gap: 14px; }
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 14px; }
.card-top { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.dot { width: 12px; height: 12px; border-radius: 50%; flex: none; display: inline-block; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); gap: 14px; }
.stat { display: flex; flex-direction: column; gap: 2px; }
.big { font-size: 24px; font-weight: 500; line-height: 1.15; }
.big.sm { font-size: var(--fs-heading); }
.empty { padding: 18px; color: var(--fg-muted); }
.notice { padding: 12px 14px; border-radius: var(--radius); background: var(--accent-soft); }

/* ---------------------------------------------------------------- landing y registro */
.landing { display: grid; grid-template-columns: minmax(0, 1.2fr) minmax(300px, 400px); gap: 40px; align-items: start; padding-top: 32px; }
.landing .pitch { display: flex; flex-direction: column; gap: 14px; }
.landing ul { margin: 0; padding-left: 1.2em; line-height: 1.6; }
.auth-card { max-width: 400px; }
.wizard { max-width: 760px; width: 100%; margin: 0 auto; }
.steps { display: flex; gap: 8px; font-size: var(--fs-caption); color: var(--fg-muted); }
.steps b { color: var(--fg); }
.roles { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 8px; }
.role-opt { border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px; display: flex; gap: 8px; cursor: pointer; background: var(--panel); }
.role-opt:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.role-opt small { display: block; color: var(--fg-muted); font-size: var(--fs-caption); }
/* casillas de categorías dentro de un .field (que pone los input al 100%) */
.cats .role-opt input { width: auto; flex: none; margin-top: 3px; }
/* nadadores que se reclaman (hijos o uno mismo): nombre, apellidos y año con autocompletado */
.claims { display: flex; flex-direction: column; gap: 12px; }
.claim { border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; display: flex; flex-direction: column; gap: 10px; background: var(--panel); }
.claim-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.row > .field.year { flex: 0 1 150px; }
/* enlace discreto a la derecha de una cabecera (p. ej. «Ver la lista de todos mis nadadores») */
.small-link { margin-left: auto; font-size: var(--fs-caption); }
/* «Mis nadadores»: casilla para llevarlo al panel */
td.pick input { width: 18px; height: 18px; margin: 0; }
@media (max-width: 820px) { .landing { grid-template-columns: 1fr; } }

/* ---------------------------------------------------------------- selector de nadadores */
.picker { display: flex; flex-direction: column; gap: 10px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { display: inline-flex; align-items: center; gap: 7px; padding: 4px 6px 4px 10px; border: 1px solid var(--line); border-radius: 999px; background: var(--panel); }
.chip small { color: var(--fg-muted); }
.chip button { border: none; padding: 0 6px; background: none; color: var(--fg-muted); font-size: 16px; line-height: 1; }
.results-list { display: flex; flex-direction: column; border: 1px solid var(--line); border-radius: var(--radius); max-height: 280px; overflow-y: auto; background: var(--panel); }
.results-list button { border: none; border-bottom: 1px solid var(--line); border-radius: 0; justify-content: space-between; text-align: left; width: 100%; padding: 8px 12px; }
.results-list button:last-child { border-bottom: none; }
.results-list button:hover { background: var(--bg); }

/* ---------------------------------------------------------------- secciones del panel */
.panel-body { display: flex; flex-direction: column; gap: 28px; min-width: 0; }
.main > *, .panel-body > *, .sec > *, .card > *, .form > * { min-width: 0; }
.sec { display: flex; flex-direction: column; gap: 12px; }
.sec-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 10px; }
.ctrls { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.ctrls label { display: flex; flex-direction: column; gap: 2px; font-size: var(--fs-caption); color: var(--fg-muted); }
.ctrls label.chk { flex-direction: row; align-items: center; gap: 6px; align-self: flex-end; padding-bottom: 6px; }
.toggle { all: unset; box-sizing: border-box; display: inline-flex; align-items: center; gap: 0.55em; cursor: pointer; font: inherit; color: inherit; border-radius: 4px; }
.toggle:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
.toggle::before { content: ''; flex: none; width: .45em; height: .45em; border-right: 2px solid currentColor; border-bottom: 2px solid currentColor; transform: translateY(-.15em) rotate(45deg); transition: transform .15s; }
.closed .toggle::before { transform: rotate(-45deg); }
.sec.closed > :not(.sec-head):not(h2) { display: none; }
.sec.closed .ctrls { display: none; }
.plegar { display: flex; gap: 8px; margin-top: 8px; flex-wrap: wrap; align-items: center; }
.plegar button { font-size: var(--fs-caption); color: var(--fg-muted); padding: 4px 10px; }
.plegar label { display: inline-flex; align-items: center; gap: 6px; font-size: var(--fs-caption); color: var(--fg-muted); cursor: pointer; }

/* ---------------------------------------------------------------- gráficos */
.chart { position: relative; min-height: 120px; width: 100%; }
.chart svg { display: block; width: 100%; overflow: visible; }
.chart text { fill: var(--fg-muted); font-size: var(--fs-caption); font-variant-numeric: tabular-nums; }
/* Etiquetas sobre las líneas o barras: un halo del color del fondo las deja legibles aunque las crucen */
.chart text.halo { fill: var(--fg); paint-order: stroke; stroke: var(--panel); stroke-width: 3px; stroke-linejoin: round; }
.chart .grid line { stroke: var(--grid); }
.chart .axis line, .chart .axis path { stroke: var(--axis); }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: var(--fs-caption); color: var(--fg-muted); margin-bottom: 4px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend svg { display: inline-block; width: 34px; height: 12px; flex: none; }
.tip { position: fixed; pointer-events: none; background: var(--panel); border: 1px solid var(--line); box-shadow: var(--shadow); border-radius: var(--radius); padding: 8px 11px; font-size: var(--fs-caption); line-height: 1.45; max-width: 290px; z-index: 50; }
.tip b { font-weight: 600; }
.has-tip { text-decoration: underline dotted; text-underline-offset: 3px; cursor: help; }

/* ---------------------------------------------------------------- tablas */
.tw { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); max-height: 620px; overflow-y: auto; background: var(--panel); }
table { border-collapse: collapse; width: 100%; font-size: var(--fs-caption); font-variant-numeric: tabular-nums; }
th, td { text-align: left; padding: 6px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; vertical-align: top; }
th { position: sticky; top: 0; background: var(--panel); font-weight: 600; z-index: 1; }
td.num, th.num { text-align: right; }
td.wrap { white-space: normal; min-width: 180px; }
td .actions { flex-wrap: nowrap; }
.pb { color: var(--ok); font-weight: 600; }
.bad { color: var(--bad); }
.warn { color: var(--warn); }
details.cov { border-top: 1px solid var(--line); padding-top: 14px; }
details summary { cursor: pointer; font-weight: 600; }
ul.notes { margin: 8px 0 0; padding-left: 1.2em; line-height: 1.55; max-width: 62em; }

/* ---------------------------------------------------------------- administración */
.tabs { display: flex; gap: 4px; flex-wrap: wrap; border-bottom: 1px solid var(--line); }
.tabs a { padding: 8px 12px; text-decoration: none; color: var(--fg-muted); border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs a.on { color: var(--fg); border-bottom-color: var(--accent); font-weight: 500; }
.tabs a .badge { margin-left: 4px; }
.grant { display: grid; grid-template-columns: minmax(0, 1fr) minmax(280px, 420px); gap: 16px; }
@media (max-width: 860px) { .grant { grid-template-columns: 1fr; } }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 4px 12px; font-size: var(--fs-caption); }
.kv dt { color: var(--fg-muted); }
.kv dd { margin: 0; }
.report { border-left: 3px solid var(--line); padding: 6px 12px; display: flex; flex-direction: column; gap: 4px; }
.report.ok { border-left-color: var(--ok); }
.report.ko { border-left-color: var(--bad); }
.report ul { margin: 0; padding-left: 1.2em; font-size: var(--fs-caption); }
.secret { font-family: ui-monospace, Consolas, monospace; padding: 10px; background: var(--bg); border-radius: 6px; word-break: break-all; user-select: all; }

dialog { border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; background: var(--panel); color: var(--fg); box-shadow: var(--shadow); max-width: min(640px, 94vw); width: 100%; }
dialog::backdrop { background: rgba(0, 0, 0, 0.35); }
dialog .form { gap: 14px; }

.toasts { position: fixed; bottom: 16px; right: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 60; }
.toast { background: var(--fg); color: var(--bg); padding: 10px 14px; border-radius: var(--radius); box-shadow: var(--shadow); max-width: 380px; }
.toast.bad { background: var(--bad); color: #fff; }

/* ---------------------------------------------------------------- pantallas táctiles (móvil y tableta) */
@media (pointer: coarse) {
  /* 16 px evita que Safari en iPhone amplíe la página al tocar un campo */
  input, select, textarea { font-size: 16px; }
  button, .btn { min-height: 40px; }
  button.small, .btn.small { min-height: 34px; padding: 5px 12px; }
  button.link { min-height: 0; }
  .chip button { min-height: 32px; min-width: 32px; }
  .nav a, .tabs a { padding: 10px 12px; }
  .check input, .ctrls input[type="checkbox"], .plegar input, .cats .role-opt input { width: 20px; height: 20px; }
}

/* ---------------------------------------------------------------- móvil */
@media (max-width: 640px) {
  :root { --fs-title: 22px; }
  .main { padding: 14px 12px 48px; gap: 18px; }
  .card { padding: 14px; }
  .panel-body { gap: 22px; }

  /* barra superior en una línea: icono, menú (desplazable si no cabe) y Salir */
  .topbar-in { padding: 6px 12px; gap: 8px; flex-wrap: nowrap; }
  .brand-txt, .who-name, .who-role { display: none; }
  .nav { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; }
  .nav::-webkit-scrollbar { display: none; }
  .nav a { white-space: nowrap; }
  #banner { padding: 0 12px; }

  /* portada: título, después el acceso y luego la explicación */
  .landing { gap: 16px; padding-top: 8px; }
  .landing .pitch { display: contents; }
  .landing .pitch h1 { order: -2; }
  .landing .auth-card { order: -1; max-width: none; }

  /* pestañas de administración en una fila desplazable */
  .tabs { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; }
  .tabs::-webkit-scrollbar { display: none; }
  .tabs a { white-space: nowrap; }

  .grant { gap: 12px; }
  .sec-head { align-items: flex-start; }
  .ctrls { width: 100%; }
  .ctrls label:not(.chk) { flex: 1 1 140px; }
  .ctrls select, .ctrls input:not([type="checkbox"]) { width: 100%; }
  .kv { grid-template-columns: 1fr; gap: 0 12px; }
  .kv dd { margin-bottom: 6px; }

  /* tablas de datos: menos alto, para poder seguir desplazando la página */
  .tw { max-height: 70vh; }

  /* tablas de administración: cada fila es una tarjeta con el nombre de cada columna */
  .tw.stack { max-height: none; overflow: visible; border: none; background: none; }
  .tw.stack table, .tw.stack tbody, .tw.stack tr, .tw.stack td { display: block; width: 100%; }
  .tw.stack thead { display: none; }
  .tw.stack tr { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 8px 0; margin-bottom: 10px; }
  .tw.stack td { display: grid; grid-template-columns: minmax(96px, 36%) minmax(0, 1fr); gap: 10px; align-items: baseline;
                 padding: 4px 14px; border-bottom: none; white-space: normal; overflow-wrap: anywhere; text-align: left; }
  .tw.stack td::before { content: attr(data-label); color: var(--fg-muted); }
  .tw.stack td:first-child { display: block; font-weight: 600; font-size: var(--fs-body); padding-bottom: 6px; }
  .tw.stack td:first-child::before, .tw.stack td[data-label=""]::before { content: none; }
  .tw.stack td[data-label=""] { display: block; padding-top: 8px; }
  .tw.stack td:empty { display: none; }
  .tw.stack td[colspan] { display: block; }
  .tw.stack td .actions { flex-wrap: wrap; }
  .tw.stack td select, .tw.stack td input:not([type="checkbox"]) { width: 100%; }
  td.wrap { min-width: 0; }

  dialog { padding: 16px; }
  .toasts { left: 12px; right: 12px; bottom: 12px; }
  .toast { max-width: none; }
}

@media (forced-colors: active) {
  .dot, .chip .dot { forced-color-adjust: none; }
}
@media print {
  .topbar, .plegar, .ctrls, .picker-search { display: none !important; }
  .tw { max-height: none; overflow: visible; }
}
