:root { color-scheme: light dark;
  --bg: #f3f5f4; --panel: #ffffff; --side: #0f2a1f; --side-ink: #cfe3d9; --side-active: #1c4634;
  --ink: #14201b; --mute: #62706a; --line: #e3e8e5; --soft: #f7f9f8;
  --brand: #0f7a4f; --brand-ink: #ffffff; --brand-2: #e6f4ec;
  --bad: #c0362c; --bad-2: #fdecea; --warn: #9a5b00; --warn-2: #fff4e0; --info: #1f5fa8; --info-2: #e8f0fb;
  --radius: 12px; --shadow: 0 1px 2px rgba(0,0,0,.04), 0 4px 16px rgba(0,0,0,.05);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d1311; --panel: #151c19; --side: #0a1512; --side-ink: #b4cbc0; --side-active: #173a2b;
    --ink: #e6eeea; --mute: #93a29b; --line: #25302b; --soft: #111816;
    --brand: #35c486; --brand-ink: #062015; --brand-2: #133326;
    --bad: #ff7b70; --bad-2: #3a1714; --warn: #f0b350; --warn-2: #3a2a0d; --info: #7fb2f0; --info-2: #132a45;
    --shadow: none;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); font: 14px/1.45 Inter, system-ui, -apple-system, sans-serif; }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; margin: 0; letter-spacing: -.01em; }
h2 { font-size: 16px; margin: 0 0 12px; }
h3 { font-size: 14px; margin: 0 0 8px; }
.mute { color: var(--mute); }
.small { font-size: 12px; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.hidden { display: none !important; }

/* ---------- layout ---------- */
.layout { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; }
.side { background: var(--side); color: var(--side-ink); padding: 18px 12px; display: flex; flex-direction: column; gap: 4px; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 18px; color: #fff; }
.brand img, .brand .ph { width: 36px; height: 36px; border-radius: 10px; object-fit: contain; background: #fff; }
.brand .ph { display: grid; place-items: center; background: var(--brand); color: #fff; font-weight: 700; }
.brand b { font-size: 14px; line-height: 1.2; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 9px; color: var(--side-ink); font-weight: 500; }
.nav a:hover { background: rgba(255,255,255,.06); text-decoration: none; }
.nav a.active { background: var(--side-active); color: #fff; }
.nav svg { width: 18px; height: 18px; flex: none; opacity: .9; }
.nav .badge { margin-left: auto; background: #f0b350; color: #2a1a00; border-radius: 99px; font-size: 11px; padding: 1px 7px; font-weight: 700; }
.side .me { margin-top: auto; padding: 12px 10px 4px; border-top: 1px solid rgba(255,255,255,.08); font-size: 13px; }
.side .me b { color: #fff; display: block; }
.side .me button { margin-top: 8px; }
.main { padding: 24px 28px 48px; min-width: 0; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.topbar .actions { display: flex; gap: 8px; flex-wrap: wrap; }
.mobile-bar { display: none; }

@media (max-width: 860px) {
  .layout { grid-template-columns: 1fr; }
  .side { position: fixed; inset: 0 auto 0 0; width: 260px; z-index: 50; transform: translateX(-100%); transition: transform .2s; }
  .side.open { transform: none; box-shadow: 0 0 0 100vmax rgba(0,0,0,.35); }
  .mobile-bar { display: flex; align-items: center; gap: 10px; padding: 10px 16px; background: var(--side); color: #fff; position: sticky; top: 0; z-index: 40; }
  .mobile-bar button { background: none; border: 0; color: #fff; padding: 4px; }
  .main { padding: 16px 16px 40px; }
}

/* ---------- componentes ---------- */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); }
.card + .card { margin-top: 16px; }
.grid { display: grid; gap: 16px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
@media (max-width: 1100px) { .g4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } .g3 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 640px) { .g2, .g3, .g4 { grid-template-columns: 1fr; } }
.stat { display: flex; flex-direction: column; gap: 2px; }
.stat .k { color: var(--mute); font-size: 12px; font-weight: 500; }
.stat .v { font-size: 26px; font-weight: 700; letter-spacing: -.02em; }
.stat a { font-size: 12px; }

button, .btn { font: inherit; font-weight: 600; border: 1px solid var(--line); background: var(--panel); color: var(--ink); border-radius: 9px; padding: 8px 14px; cursor: pointer; display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
button:hover, .btn:hover { background: var(--soft); text-decoration: none; }
button.primary, .btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
button.primary:hover { filter: brightness(1.06); }
button.danger { color: var(--bad); }
button.ghost { background: none; border-color: transparent; }
button.sm, .btn.sm { padding: 4px 10px; font-size: 12px; border-radius: 7px; }
button:disabled { opacity: .5; cursor: default; }
button svg, .btn svg { width: 16px; height: 16px; flex: none; }

label { display: block; font-weight: 500; font-size: 12px; color: var(--mute); margin-bottom: 4px; }
input, select, textarea { font: inherit; width: 100%; padding: 9px 11px; border: 1px solid var(--line); border-radius: 9px; background: var(--panel); color: var(--ink); }
input:focus, select:focus, textarea:focus { outline: 2px solid color-mix(in srgb, var(--brand) 40%, transparent); border-color: var(--brand); }
input[type=checkbox] { width: auto; }
textarea { min-height: 70px; resize: vertical; }
.check { display: flex; align-items: center; gap: 8px; font-size: 14px; color: var(--ink); font-weight: 500; }
.form { display: grid; gap: 14px; grid-template-columns: repeat(2, minmax(0, 1fr)); }
.form .full { grid-column: 1 / -1; }
@media (max-width: 640px) { .form { grid-template-columns: 1fr; } }
.hint { font-size: 12px; color: var(--mute); margin-top: 4px; }

.table-wrap { overflow-x: auto; margin: 0 -18px; padding: 0 18px; }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 12px; color: var(--mute); font-weight: 600; padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
tr.click { cursor: pointer; }
tr.click:hover td { background: var(--soft); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }

.pill { display: inline-flex; align-items: center; gap: 5px; border-radius: 99px; padding: 2px 9px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.pill::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.pill.ok { background: var(--brand-2); color: var(--brand); }
.pill.bad { background: var(--bad-2); color: var(--bad); }
.pill.warn { background: var(--warn-2); color: var(--warn); }
.pill.info { background: var(--info-2); color: var(--info); }
.pill.plain { background: var(--soft); color: var(--mute); border: 1px solid var(--line); }
.pill.plain::before { display: none; }

.tabs { display: flex; gap: 4px; box-shadow: inset 0 -1px 0 var(--line); margin-bottom: 16px; overflow-x: auto; overflow-y: hidden; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tabs a { padding: 9px 14px; color: var(--mute); font-weight: 600; border-bottom: 2px solid transparent; white-space: nowrap; }
.tabs a:hover { color: var(--ink); text-decoration: none; }
.tabs a.active { color: var(--brand); border-color: var(--brand); }

.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 14px; }
.toolbar input[type=search] { max-width: 320px; }
.toolbar select { width: auto; }
.empty { text-align: center; color: var(--mute); padding: 28px 10px; }
.alert { border-radius: 10px; padding: 10px 12px; font-size: 13px; margin-bottom: 12px; }
.alert.warn { background: var(--warn-2); color: var(--warn); }
.alert.bad { background: var(--bad-2); color: var(--bad); }
.alert.ok { background: var(--brand-2); color: var(--brand); }
.alert.info { background: var(--info-2); color: var(--info); }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; }
.kv dt { color: var(--mute); }
.kv dd { margin: 0; font-weight: 500; min-width: 0; overflow-wrap: anywhere; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.between { justify-content: space-between; }
.avatar { width: 52px; height: 52px; border-radius: 14px; display: grid; place-items: center; background: var(--brand-2); color: var(--brand); font-weight: 700; font-size: 20px; flex: none; }
.qr img { width: 100%; max-width: 200px; display: block; border-radius: 8px; background: #fff; padding: 6px; }
.code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; background: var(--soft); border: 1px solid var(--line); border-radius: 6px; padding: 2px 6px; font-size: 12px; overflow-wrap: anywhere; }
pre.code { padding: 10px 12px; white-space: pre-wrap; margin: 0; }
.meter { height: 8px; background: var(--line); border-radius: 9px; overflow: hidden; }
.meter i { display: block; height: 100%; background: var(--brand); }

/* ---------- modal / toasts ---------- */
.modal-bg { position: fixed; inset: 0; background: rgba(8,15,12,.5); display: grid; place-items: center; padding: 16px; z-index: 100; animation: fade .12s; }
.modal { background: var(--panel); border-radius: 16px; width: min(640px, 100%); max-height: calc(100vh - 32px); display: flex; flex-direction: column; box-shadow: 0 20px 60px rgba(0,0,0,.3); }
.modal.wide { width: min(900px, 100%); }
.modal header { padding: 16px 20px; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.modal header h2 { margin: 0; }
.modal .body { padding: 18px 20px; overflow-y: auto; }
.modal footer { padding: 12px 20px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap; }
@keyframes fade { from { opacity: 0; } }
#toasts { position: fixed; bottom: 16px; right: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 200; max-width: calc(100vw - 32px); }
.toast { background: var(--ink); color: var(--panel); padding: 10px 14px; border-radius: 10px; font-weight: 500; box-shadow: var(--shadow); animation: fade .15s; }
.toast.error { background: var(--bad); color: #fff; }

/* ---------- login ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; background: radial-gradient(1200px 600px at 20% 0%, var(--brand-2), transparent), var(--bg); }
.login .card { width: min(380px, 100%); padding: 28px; }
.login .brand { color: var(--ink); padding: 0 0 18px; }

/* ---------- calendario ---------- */
.cal { display: grid; grid-template-columns: 52px repeat(7, minmax(110px, 1fr)); border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); overflow: auto; max-height: calc(100vh - 220px); }
.cal .hd { position: sticky; top: 0; z-index: 3; background: var(--panel); border-bottom: 1px solid var(--line); padding: 8px 6px; text-align: center; font-weight: 600; font-size: 12px; }
.cal .hd.today { color: var(--brand); }
.cal .hd span { display: block; font-size: 18px; color: var(--ink); }
.cal .hd.today span { color: var(--brand); }
.cal .times { position: relative; border-right: 1px solid var(--line); }
.cal .times div { height: var(--h); font-size: 11px; color: var(--mute); text-align: right; padding-right: 6px; transform: translateY(-7px); }
.cal .col { position: relative; border-right: 1px solid var(--line); background-image: linear-gradient(var(--line) 1px, transparent 1px); background-size: 100% var(--h); }
.cal .col.today { background-color: color-mix(in srgb, var(--brand-2) 45%, transparent); }
.cal .ev { position: absolute; left: 3px; right: 3px; border-radius: 7px; padding: 4px 6px; font-size: 11px; line-height: 1.25; overflow: hidden; cursor: pointer; color: #fff; border-left: 3px solid rgba(0,0,0,.25); }
.cal .ev b { display: block; font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cal .ev:hover { filter: brightness(1.08); z-index: 2; }
.agenda { display: none; }
@media (max-width: 860px) { .cal { display: none; } .agenda { display: block; } }
.agenda .day { margin-bottom: 14px; }
.agenda .day h3 { font-size: 13px; color: var(--mute); text-transform: capitalize; }
.agenda .item { display: flex; gap: 10px; align-items: stretch; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 10px; margin-bottom: 6px; cursor: pointer; }
.agenda .item i { width: 4px; border-radius: 4px; flex: none; }

/* ---------- tabulador ---------- */
.persona { display: grid; grid-template-columns: 1.4fr .6fr 1fr auto; gap: 8px; align-items: end; padding: 10px 0; border-bottom: 1px dashed var(--line); }
@media (max-width: 640px) { .persona { grid-template-columns: 1fr 1fr; } }
.total-box { background: var(--brand); color: var(--brand-ink); border-radius: var(--radius); padding: 16px 18px; }
.total-box .v { font-size: 30px; font-weight: 700; }
.lines td { font-size: 13px; }

@media print {
  .side, .mobile-bar, .topbar .actions, .no-print { display: none !important; }
  .layout { display: block; }
  .card { box-shadow: none; }
}
.tab-grid { grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr); align-items: start; }
.emp-grid { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); align-items: start; }
@media (max-width: 1180px) { .tab-grid, .emp-grid { grid-template-columns: 1fr; } }


/* mensajería */
table.msg tr.done td { text-decoration: line-through; text-decoration-color: var(--mute); color: var(--mute); }
table.msg tr.done td a { color: var(--mute); }
table.msg tr.done td .pill, table.msg tr.done td .alert-box { opacity: .55; }
table.msg tr.done .nostrike { display: inline-block; text-decoration: none; color: var(--brand); }
.alert-box { display: flex; flex-direction: column; gap: 2px; border-radius: 6px; padding: 8px 10px; border-left: 4px solid currentColor; min-width: 200px; max-width: 280px; font-size: 12px; line-height: 1.35; }
.alert-box b { font-size: 13px; }
.alert-box span { color: var(--ink); }
.alert-box.bad { background: var(--bad-2); color: var(--bad); }
.alert-box.info { background: var(--info-2); color: var(--info); }

/* filtros de clientes */
table.filtrable th.sortable { cursor: pointer; user-select: none; }
table.filtrable th.sortable:hover, table.filtrable th.sorted { color: var(--ink); }
table.filtrable tr.filters th { padding: 6px 6px 10px; border-bottom: 1px solid var(--line); }
table.filtrable tr.filters select { padding: 5px 8px; font-size: 12px; min-width: 110px; font-weight: 500; }
table.filtrable tr.filters select.on { border-color: var(--brand); background: var(--brand-2); color: var(--brand); }

/* grupos de plan */
#glist { max-height: 300px; overflow: auto; border: 1px solid var(--line); border-radius: 9px; margin-top: 6px; }
.gitem { padding: 8px 10px; border-bottom: 1px solid var(--line); margin: 0; flex-wrap: wrap; }
.gitem:last-child { border-bottom: 0; }
.gitem.dis { opacity: .45; cursor: not-allowed; }
.cal .ev.narrow { padding: 4px; font-size: 10px; }
.cal .ev.narrow b { font-size: 11px; }

/* botón limpiar filtros */
.clear-btn { border: 1.5px solid var(--bad); color: var(--bad); background: var(--bad-2); font-weight: 700; }
.clear-btn:hover { background: var(--bad); color: #fff; }
.clear-btn .n { display: none; border-radius: 99px; font-size: 11px; min-width: 18px; padding: 1px 6px; text-align: center; background: #fff; color: var(--bad); }
.clear-btn.active { background: var(--bad); color: #fff; box-shadow: 0 0 0 3px color-mix(in srgb, var(--bad) 25%, transparent); }
.clear-btn.active .n { display: inline-block; }
.gitem.dis .pill.bad { opacity: 1; }

/* titular del grupo de plan (paga las mensualidades del grupo) */
.pill.titular { background: var(--brand); color: var(--brand-ink); font-weight: 600; }
.titular-box { background: var(--brand-2); border-radius: 10px; padding: 10px 12px; margin-bottom: 10px; }
.titular-box select { max-width: 320px; }

/* buscador de grupos de plan */
.gsearch { padding: 12px 14px; }
.gsearch input[type=search] { flex: 1; max-width: 380px; }
.gmem.hit { background: var(--warn-2); border-radius: 6px; padding-left: 6px !important; padding-right: 6px !important; }
.gmem.hit a { font-weight: 700; }

/* selector de días de la semana (recurrencia de clases) */
.dias-sem { display: flex; gap: 6px; flex-wrap: wrap; }
.dias-sem .dia { margin: 0; cursor: pointer; }
.dias-sem .dia input { position: absolute; opacity: 0; pointer-events: none; }
.dias-sem .dia span { display: grid; place-items: center; min-width: 42px; height: 38px; padding: 0 8px; border-radius: 10px; border: 1.5px solid var(--line); font-weight: 700; color: var(--mute); user-select: none; }
.dias-sem .dia:hover span { border-color: var(--brand); color: var(--ink); }
.dias-sem .dia input:checked + span { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.dias-sem .dia input:focus-visible + span { outline: 2px solid var(--brand); outline-offset: 2px; }

/* alta rápida desde formularios (coach / salón) */
.lbl-add { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.link-btn { background: none; border: 0; padding: 0; color: var(--brand); font-weight: 700; font-size: 12px; cursor: pointer; }
.link-btn:hover { text-decoration: underline; background: none; }

/* opciones al eliminar una clase recurrente */
.opt-list { display: grid; gap: 8px; }
.opt { display: flex; gap: 10px; align-items: flex-start; border: 1.5px solid var(--line); border-radius: 10px; padding: 10px 12px; cursor: pointer; margin: 0; }
.opt:has(input:checked) { border-color: var(--brand); background: var(--brand-2); }
.opt input { margin-top: 3px; width: auto; }
.opt > span { display: grid; gap: 2px; font-weight: 400; }

/* enlace a la app de pádel en el menú */
.nav a.nav-ext { margin-top: 10px; border-top: 1px solid rgba(255,255,255,.08); border-radius: 0 0 9px 9px; padding-top: 12px; }
.nav a.nav-ext .ext { margin-left: auto; opacity: .6; }
