:root {
  --bg: #f2f4f7;
  --card: #ffffff;
  --text: #14202b;
  --muted: #667380;
  --line: #e1e6ec;
  --accent: #0b6e8a;
  --accent-soft: #e1f1f5;
  --accent-text: #ffffff;
  --ok: #1f8a4c;
  --ok-soft: #e3f4ea;
  --warn: #b26a00;
  --warn-soft: #fbf0dc;
  --bad: #c0392b;
  --bad-soft: #fbe6e3;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(16, 32, 48, .06), 0 2px 8px rgba(16, 32, 48, .04);
  --tabbar-h: 62px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1418;
    --card: #182127;
    --text: #e8eef2;
    --muted: #93a1ad;
    --line: #26323a;
    --accent: #3cb4d4;
    --accent-soft: #15333d;
    --accent-text: #06232c;
    --ok: #4cc27f;
    --ok-soft: #173424;
    --warn: #e0a24a;
    --warn-soft: #3a2c15;
    --bad: #ef6f62;
    --bad-soft: #3d1c19;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }

/* ───── estructura ───── */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 8px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(12px);
  -webkit-backdrop-filter: saturate(1.4) blur(12px);
  border-bottom: 1px solid var(--line);
  min-height: 56px;
}
.topbar h1 { font-size: 20px; margin: 0; flex: 1; font-weight: 700; letter-spacing: -.01em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar .back { font-weight: 500; }
main {
  max-width: 760px; margin: 0 auto;
  padding: 16px 16px calc(var(--tabbar-h) + 32px + env(safe-area-inset-bottom));
}
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: flex; justify-content: center;
  background: color-mix(in srgb, var(--card) 92%, transparent);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabbar a {
  flex: 1; max-width: 160px; height: var(--tabbar-h);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  color: var(--muted); text-decoration: none; font-size: 11px; font-weight: 500;
}
.tabbar a.active { color: var(--accent); }
.tabbar svg { width: 24px; height: 24px; }

/* ───── componentes ───── */
.card {
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  border: 1px solid var(--line);
  overflow: hidden;
}
.card + .card, .section + .section { margin-top: 16px; }
.section-title {
  font-size: 13px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em;
  color: var(--muted); margin: 22px 4px 8px;
}
.section-title:first-child { margin-top: 4px; }
.row {
  display: flex; align-items: center; gap: 12px;
  padding: 13px 16px; border-bottom: 1px solid var(--line);
  min-height: 50px;
}
.row:last-child { border-bottom: 0; }
.row .grow { flex: 1; min-width: 0; }
.row .label { color: var(--text); }
.row .value { color: var(--muted); text-align: right; }
a.row { color: inherit; text-decoration: none; }
a.row:active, button.row:active { background: var(--accent-soft); }
.chev::after { content: "›"; color: var(--muted); font-size: 22px; line-height: 1; margin-left: 4px; }
.title { font-weight: 600; }
.sub { color: var(--muted); font-size: 14px; }
.small { font-size: 13px; }
.muted { color: var(--muted); }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.empty { text-align: center; color: var(--muted); padding: 40px 16px; }
.empty svg { width: 44px; height: 44px; opacity: .6; margin-bottom: 8px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 0; border-radius: 12px; padding: 12px 18px; min-height: 46px;
  background: var(--accent); color: var(--accent-text); font-weight: 600; cursor: pointer;
  text-decoration: none;
}
.btn:disabled { opacity: .5; cursor: default; }
.btn.secondary { background: var(--accent-soft); color: var(--accent); }
.btn.danger { background: var(--bad-soft); color: var(--bad); }
.btn.block { width: 100%; }
.btn.small { min-height: 36px; padding: 6px 12px; font-size: 14px; border-radius: 10px; }
.icon-btn {
  border: 0; background: none; color: var(--accent); cursor: pointer;
  width: 40px; height: 40px; border-radius: 10px; display: grid; place-items: center;
  font-size: 15px; font-weight: 600;
}
.icon-btn svg { width: 24px; height: 24px; }
.link-btn { border: 0; background: none; color: var(--accent); cursor: pointer; padding: 8px 4px; font-weight: 500; }
.actions { display: flex; gap: 10px; flex-wrap: wrap; margin: 16px 0 8px; }
.row.link-btn { padding: 13px 16px; font-weight: 400; font-size: 16px; }
.actions .btn { flex: 1; }

/* formularios */
.field { display: block; padding: 10px 16px; border-bottom: 1px solid var(--line); }
.field:last-child { border-bottom: 0; }
.field > span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; }
.field input, .field select, .field textarea {
  width: 100%; border: 0; background: transparent; padding: 4px 0; outline: none; font-size: 17px;
  min-height: 30px;
}
.field textarea { resize: vertical; min-height: 70px; }
.field input:focus, .field textarea:focus, .field select:focus { box-shadow: 0 2px 0 var(--accent); }
.switch-row { display: flex; align-items: center; justify-content: space-between; padding: 12px 16px; border-bottom: 1px solid var(--line); gap: 12px; }
.switch-row:last-child { border-bottom: 0; }
.switch { position: relative; width: 51px; height: 31px; flex: none; }
.switch input { opacity: 0; width: 100%; height: 100%; margin: 0; position: absolute; cursor: pointer; z-index: 1; }
.switch i { position: absolute; inset: 0; border-radius: 99px; background: var(--line); transition: background .2s; }
.switch i::after { content: ""; position: absolute; top: 2px; left: 2px; width: 27px; height: 27px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.25); transition: transform .2s; }
.switch input:checked + i { background: var(--ok); }
.switch input:checked + i::after { transform: translateX(20px); }
.switch input:focus-visible + i { outline: 2px solid var(--accent); outline-offset: 2px; }

.seg { display: flex; background: var(--bg); border-radius: 10px; padding: 3px; gap: 3px; }
.seg button {
  flex: 1; border: 0; background: none; border-radius: 8px; padding: 8px 2px; font-size: 13px; font-weight: 600;
  color: var(--muted); cursor: pointer; min-height: 38px;
}
.seg button.on { background: var(--card); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,.12); }
.seg button.on[data-v="Presente"] { background: var(--ok); color: #fff; }
.seg button.on[data-v="Tarde"] { background: var(--warn); color: #fff; }
.seg button.on[data-v="Ausente"] { background: var(--bad); color: #fff; }

.chips { display: flex; gap: 8px; overflow-x: auto; padding: 2px 0 6px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; border: 1px solid var(--line); background: var(--card); color: var(--text);
  border-radius: 99px; padding: 7px 14px; font-size: 14px; font-weight: 500; cursor: pointer;
}
.chip.on { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }

.badge { display: inline-block; font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 99px; background: var(--accent-soft); color: var(--accent); white-space: nowrap; }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.bad { background: var(--bad-soft); color: var(--bad); }
.badge.gray { background: var(--bg); color: var(--muted); }

.search { width: 100%; border: 1px solid var(--line); background: var(--card); border-radius: 12px; padding: 10px 14px; margin-bottom: 12px; font-size: 16px; outline: none; }
.search:focus { border-color: var(--accent); }

/* estadísticas */
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; box-shadow: var(--shadow); min-width: 0; }
.stat b { display: block; font-size: 24px; font-weight: 700; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.stat span { font-size: 12px; color: var(--muted); }
.bar { height: 8px; background: var(--bg); border-radius: 99px; overflow: hidden; display: flex; }
.bar i { display: block; height: 100%; }
.bar .p { background: var(--ok); } .bar .t { background: var(--warn); } .bar .a { background: var(--bad); }
.num { font-variant-numeric: tabular-nums; }
.chart { padding: 12px 8px 4px; }
.chart svg { width: 100%; height: auto; display: block; overflow: visible; }
.chart text { fill: var(--muted); font-size: 10px; }
.chart .grid { stroke: var(--line); }
.chart .line { stroke: var(--accent); fill: none; stroke-width: 2.5; }
.chart .dot { fill: var(--card); stroke: var(--accent); stroke-width: 2; }
.chart .col { fill: var(--accent); }
.legend { display: flex; gap: 14px; font-size: 13px; color: var(--muted); padding: 0 16px 12px; flex-wrap: wrap; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }

/* asistencia */
.att { padding: 14px 16px; border-bottom: 1px solid var(--line); }
.att:last-child { border-bottom: 0; }
.att .name { font-weight: 600; margin-bottom: 8px; display: flex; justify-content: space-between; gap: 8px; }
.att .extra { display: grid; gap: 8px; margin-top: 10px; }
.att .inline { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.att .inline label { color: var(--accent); font-size: 15px; }
.att input, .att select {
  border: 1px solid var(--line); background: var(--bg); border-radius: 10px; padding: 8px 10px; font-size: 16px; min-height: 40px; outline: none;
}
.att input:focus, .att select:focus { border-color: var(--accent); }
.att input.n { width: 110px; text-align: right; }
.att input.wide { width: 100%; }
.att select { max-width: 60%; }
.sticky-actions {
  position: sticky; bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 10px); z-index: 5;
  display: flex; gap: 10px; margin-top: 16px;
}
.sticky-actions .btn { flex: 1; box-shadow: 0 6px 20px rgba(0,0,0,.18); }

/* login */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.auth .box { width: 100%; max-width: 380px; }
.brand { text-align: center; margin-bottom: 24px; }
.brand img { width: 72px; height: 72px; border-radius: 18px; box-shadow: 0 8px 24px rgba(11,110,138,.25); }
.brand h1 { margin: 12px 0 2px; font-size: 26px; letter-spacing: -.02em; }
.error { color: var(--bad); font-size: 14px; margin: 10px 4px 0; min-height: 20px; }
.note { font-size: 14px; color: var(--muted); margin: 10px 4px; }

/* aviso flotante */
.toast {
  position: fixed; left: 50%; bottom: calc(var(--tabbar-h) + 20px + env(safe-area-inset-bottom)); transform: translateX(-50%) translateY(20px);
  background: var(--text); color: var(--bg); padding: 10px 18px; border-radius: 99px; font-size: 15px; font-weight: 500;
  opacity: 0; transition: all .25s; z-index: 50; pointer-events: none; max-width: calc(100% - 32px); text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.err { background: var(--bad); color: #fff; }

.spinner { width: 28px; height: 28px; border: 3px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; margin: 40px auto; }
@keyframes spin { to { transform: rotate(360deg); } }

table.t { width: 100%; border-collapse: collapse; font-size: 14px; }
table.t th { text-align: left; font-size: 12px; color: var(--muted); font-weight: 600; padding: 10px 16px 6px; }
table.t td { padding: 10px 16px; border-top: 1px solid var(--line); vertical-align: middle; }
table.t td.r, table.t th.r { text-align: right; }

@media (min-width: 700px) {
  .stats { grid-template-columns: repeat(4, 1fr); }
}

/* ───── plan de temporada ───── */
:root { --k-fuerza: #7b4fb8; --k-ergo: #0b6e8a; --k-mar: #1f68c9; --k-test: #b26a00; --k-descanso: #8a96a2; }
@media (prefers-color-scheme: dark) {
  :root { --k-fuerza: #b48cf0; --k-ergo: #3cb4d4; --k-mar: #6aa6f2; --k-test: #e0a24a; --k-descanso: #6d7a86; }
}
.kind { display: inline-block; font-size: 11px; font-weight: 700; padding: 2px 7px; border-radius: 6px; white-space: nowrap; line-height: 1.4;
  color: var(--kc); background: color-mix(in srgb, var(--kc) 14%, transparent); }
.k-fuerza { --kc: var(--k-fuerza); } .k-ergo { --kc: var(--k-ergo); } .k-mar { --kc: var(--k-mar); }
.k-test { --kc: var(--k-test); } .k-descanso { --kc: var(--k-descanso); }
.legend i.k-fuerza, .legend i.k-ergo, .legend i.k-mar, .legend i.k-test { background: var(--kc); }
.legend i.done-dot { background: var(--ok); border-radius: 50%; }
.cal { padding-bottom: 2px; }
.cal-nav { display: flex; align-items: center; justify-content: space-between; padding: 6px 6px 2px; }
.cal-nav b { font-size: 17px; }
.cal-nav .icon-btn { font-size: 26px; text-decoration: none; }
.cal-nav .icon-btn.disabled { opacity: .25; pointer-events: none; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 3px; padding: 4px 8px 10px; }
.cal-h { text-align: center; font-size: 12px; font-weight: 600; color: var(--muted); padding: 4px 0; }
.cal-cell { display: flex; flex-direction: column; align-items: center; justify-content: space-between; gap: 3px;
  min-height: 54px; padding: 5px 1px 6px; border-radius: 10px; text-decoration: none; color: var(--text); border: 1.5px solid transparent; min-width: 0; }
.cal-cell .n { font-size: 14px; font-weight: 500; font-variant-numeric: tabular-nums; position: relative; }
.cal-cell .kind { font-size: 10px; padding: 1px 4px; max-width: 100%; overflow: hidden; text-overflow: ellipsis; }
.cal-cell.out { opacity: .35; }
.cal-cell.none .n { color: var(--muted); }
.cal-cell.today .n { color: var(--accent); font-weight: 800; }
.cal-cell.sel { border-color: var(--accent); background: var(--accent-soft); }
.cal-cell .done { position: absolute; top: -1px; right: -7px; width: 6px; height: 6px; border-radius: 50%; background: var(--ok); }
.plan-day { padding: 14px 16px; }
.plan-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.plan-head .sub { color: var(--text); font-weight: 600; }
.plan-title { font-size: 19px; font-weight: 700; margin: 10px 0 6px; letter-spacing: -.01em; }
.plan-list { margin: 6px 0 4px; padding-left: 20px; }
.plan-list li { margin: 3px 0; }
.plan-note { margin-top: 10px; padding: 10px 12px; border-radius: 10px; background: var(--warn-soft); color: var(--text); font-size: 14px; }
.plan-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 14px; }
.row-sel { background: var(--accent-soft); }
.wd { width: 38px; text-align: center; line-height: 1.1; flex: none; }
.wd b { display: block; font-size: 12px; text-transform: uppercase; color: var(--muted); font-weight: 600; }
.wd span { font-size: 17px; font-weight: 600; font-variant-numeric: tabular-nums; }
.zones { margin-top: 16px; }
.zones summary { padding: 14px 16px; cursor: pointer; font-weight: 600; }
.tabbar a span { white-space: nowrap; }
.cal-cell .pub { position: absolute; top: -1px; left: -7px; width: 6px; height: 6px; border-radius: 50%; background: var(--k-mar); }
.legend i.pub-dot { background: var(--k-mar); border-radius: 50%; }
.pub-row { padding: 12px 0 0; margin-top: 12px; border-top: 1px solid var(--line); border-bottom: 0; }
.split-hint { text-align: right; font-size: 13px; color: var(--muted); margin-top: -4px; }
.split-hint .bad, .split-hint .bad b { color: var(--bad); }
.att input.invalid { border-color: var(--bad); }
