:root {
  --bg: #f6f5f1;
  --surface: #ffffff;
  --surface-2: #f0efe9;
  --text: #22302a;
  --muted: #6b7570;
  --border: #e2e0d8;
  --primary: #5b7f6e;
  --primary-ink: #ffffff;
  --primary-soft: #e3ece7;
  --accent: #c98b6b;
  --ok: #2f8a57;
  --ok-soft: #e1f2e8;
  --warn: #b7791f;
  --warn-soft: #fbf0db;
  --danger: #c0392b;
  --danger-soft: #fae3e0;
  --wa: #25d366;
  --radius: 12px;
  --shadow: 0 1px 2px rgb(0 0 0 / .05), 0 4px 16px rgb(0 0 0 / .05);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #151a18;
    --surface: #1d2421;
    --surface-2: #242c28;
    --text: #e7ece9;
    --muted: #9aa5a0;
    --border: #323c37;
    --primary: #7fae97;
    --primary-ink: #0f1513;
    --primary-soft: #263a31;
    --ok-soft: #1f3a2b;
    --warn-soft: #3a3020;
    --danger-soft: #3d2320;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3 { line-height: 1.2; margin: 0 0 .5rem; }
h1 { font-size: 1.4rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }
a { color: var(--primary); }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.center { text-align: center; }
[hidden] { display: none !important; }

/* ── Layout ── */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 1rem;
  padding: .6rem 1rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; flex: none; }
/* Logo negro con fondo transparente; en modo oscuro se invierte a blanco. */
.logo { display: block; height: 58px; width: auto; }
.logo-lg { height: auto; width: 100%; max-width: 280px; margin: 0 auto .5rem; }
@media (prefers-color-scheme: dark) {
  .logo { filter: invert(1); }
}
@media (max-width: 760px) { .logo { height: 54px; } .topbar { justify-content: center; } }
.tabs { display: flex; gap: .25rem; margin-left: auto; }
.tabs a {
  display: flex; align-items: center; gap: .35rem;
  padding: .45rem .8rem; border-radius: 999px;
  color: var(--muted); text-decoration: none; font-weight: 550;
}
.tabs a:hover { background: var(--surface-2); }
.tabs a.active { background: var(--primary-soft); color: var(--text); }
.view { max-width: 1100px; margin: 0 auto; padding: 1rem 1rem 6rem; }

@media (max-width: 760px) {
  .tabs {
    position: fixed; left: 0; right: 0; bottom: 0;
    justify-content: space-around; gap: 0;
    padding: .3rem .25rem calc(.3rem + env(safe-area-inset-bottom));
    background: var(--surface); border-top: 1px solid var(--border);
  }
  .tabs a { flex-direction: column; gap: 0; padding: .3rem .5rem; font-size: .72rem; border-radius: 10px; }
  .tabs a .ico { font-size: 1.2rem; }
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  box-shadow: var(--shadow);
}
.stack > * + * { margin-top: 1rem; }
.row { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.grow { flex: 1; min-width: 0; }
.cols { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); align-items: start; }

/* ── Controles ── */
button, .btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .35rem;
  font: inherit; font-weight: 550;
  padding: .5rem .9rem; min-height: 38px;
  border-radius: 10px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text);
  cursor: pointer; text-decoration: none; white-space: nowrap;
}
button:hover, .btn:hover { background: var(--surface-2); }
button:disabled { opacity: .5; cursor: not-allowed; }
.primary { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
.primary:hover { background: var(--primary); filter: brightness(1.07); }
.danger { color: var(--danger); }
.btn.wa, button.wa { background: var(--wa); border-color: var(--wa); color: #08301a; }
.btn.wa:hover { filter: brightness(1.05); background: var(--wa); }
.btn.done { background: var(--ok-soft); border-color: transparent; color: var(--ok); }
.icon-btn { padding: .4rem .6rem; min-width: 38px; }
.link-btn { border: 0; background: none; padding: 0; min-height: 0; color: var(--primary); }

input, select, textarea {
  font: inherit; color: inherit;
  width: 100%; padding: .5rem .65rem; min-height: 38px;
  border: 1px solid var(--border); border-radius: 10px;
  background: var(--surface);
}
textarea { resize: vertical; min-height: 120px; }
input:focus, select:focus, textarea:focus, button:focus-visible, a:focus-visible {
  outline: 2px solid var(--primary); outline-offset: 1px;
}
input[type="checkbox"] { width: auto; min-height: 0; accent-color: var(--primary); }

.form { display: grid; gap: .8rem; }
.form label { display: grid; gap: .25rem; font-size: .88rem; font-weight: 550; }
.form label.check { display: flex; align-items: center; gap: .5rem; font-weight: 500; }
.form .grid-2 { display: grid; gap: .8rem; grid-template-columns: 1fr 1fr; }
@media (max-width: 520px) { .form .grid-2 { grid-template-columns: 1fr; } }
.checks { display: flex; flex-wrap: wrap; gap: .4rem .9rem; }
.checks label { display: flex; align-items: center; gap: .35rem; font-weight: 500; }
.actions { display: flex; justify-content: flex-end; gap: .5rem; flex-wrap: wrap; margin-top: .25rem; }
.error { color: var(--danger); background: var(--danger-soft); padding: .5rem .7rem; border-radius: 8px; margin: 0; }
.hint { font-size: .8rem; color: var(--muted); font-weight: 400; }

.chip {
  display: inline-block; padding: .1rem .55rem; border-radius: 999px;
  font-size: .78rem; font-weight: 550;
  background: var(--surface-2); color: var(--muted);
}
.chip.ok { background: var(--ok-soft); color: var(--ok); }
.chip.warn { background: var(--warn-soft); color: var(--warn); }
.chip.danger { background: var(--danger-soft); color: var(--danger); }
.chip.primary { background: var(--primary-soft); color: var(--text); }

/* ── Modal ── */
dialog {
  width: min(560px, calc(100vw - 2rem));
  max-height: calc(100dvh - 2rem);
  border: 0; border-radius: 16px; padding: 1.25rem;
  background: var(--surface); color: var(--text);
  box-shadow: 0 20px 60px rgb(0 0 0 / .25);
}
dialog::backdrop { background: rgb(15 20 18 / .45); }

/* ── Toasts ── */
#toasts { position: fixed; right: 1rem; bottom: 1rem; z-index: 100; display: grid; gap: .5rem; }
@media (max-width: 760px) { #toasts { left: 1rem; bottom: 5.5rem; } }
.toast {
  padding: .7rem 1rem; border-radius: 10px; max-width: 420px;
  background: var(--text); color: var(--bg); box-shadow: var(--shadow);
  animation: in .2s ease-out;
}
.toast.error { background: var(--danger); color: #fff; }
@keyframes in { from { opacity: 0; transform: translateY(6px); } }

/* ── Agenda ── */
.agenda-toolbar { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; margin-bottom: .75rem; }
.agenda-toolbar input[type="date"] { width: auto; }
.agenda-title { margin: 0 0 .75rem; }

.week { display: grid; grid-template-columns: repeat(7, 1fr); gap: .35rem; margin-bottom: 1rem; }
.week button {
  flex-direction: column; gap: .15rem; padding: .45rem .2rem; min-height: 64px;
  font-weight: 500;
}
.week button .d { font-size: .75rem; color: var(--muted); text-transform: uppercase; }
.week button .n { font-size: 1.1rem; font-weight: 650; }
.week button .bar { width: 70%; height: 4px; border-radius: 2px; background: var(--surface-2); overflow: hidden; }
.week button .bar i { display: block; height: 100%; background: var(--primary); }
.week button.sel { border-color: var(--primary); background: var(--primary-soft); }
.week button.hoy .n { color: var(--accent); }
.week button.cerrado { opacity: .5; }

.grid {
  display: grid;
  grid-template-columns: 64px repeat(var(--camas), minmax(0, 1fr));
  gap: .35rem;
}
.grid .gh { font-size: .8rem; font-weight: 650; color: var(--muted); text-align: center; padding-bottom: .1rem; }
.grid .time { font-weight: 650; font-variant-numeric: tabular-nums; padding-top: .55rem; font-size: .9rem; }
.cell {
  min-height: 54px; padding: .35rem .5rem;
  flex-direction: column; align-items: flex-start; justify-content: center; gap: 0;
  text-align: left; white-space: normal; overflow: hidden;
  font-weight: 500;
}
.cell strong { font-size: .9rem; line-height: 1.2; overflow: hidden; text-overflow: ellipsis; max-width: 100%; white-space: nowrap; }
.cell small { font-size: .74rem; color: var(--muted); }
.cell.libre { border-style: dashed; color: var(--muted); align-items: center; background: transparent; }
.cell.libre:hover { background: var(--primary-soft); color: var(--text); border-style: solid; }
.cell.ocupada { background: var(--primary-soft); border-color: transparent; }
.cell.ocupada.asistio { background: var(--ok-soft); }
.cell.ocupada.ausente { background: var(--danger-soft); }
.cell.pasado.libre { opacity: .35; }
.cell .alerta { color: var(--warn); }
.slot-full .time { color: var(--accent); }

/* ── Listas ── */
.list { list-style: none; margin: 0; padding: 0; }
.list > li { display: flex; gap: .75rem; align-items: center; padding: .7rem 0; border-top: 1px solid var(--border); }
.list > li:first-child { border-top: 0; }
.list .meta { font-size: .85rem; color: var(--muted); }
.avatar {
  flex: none; width: 38px; height: 38px; border-radius: 50%;
  display: grid; place-items: center;
  background: var(--primary-soft); font-weight: 650; font-size: .9rem;
}
.inactive { opacity: .55; }

.preview {
  white-space: pre-wrap; margin: .35rem 0 0; padding: .5rem .7rem;
  background: var(--surface-2); border-radius: 10px; font-size: .88rem;
}
.var-chips { display: flex; flex-wrap: wrap; gap: .3rem; }
.var-chips button { min-height: 28px; padding: .1rem .55rem; font-size: .8rem; border-radius: 999px; }

table { width: 100%; border-collapse: collapse; font-size: .88rem; }
th, td { text-align: left; padding: .5rem .4rem; border-top: 1px solid var(--border); vertical-align: top; }
th { color: var(--muted); font-weight: 600; border-top: 0; }
.truncate { max-width: 360px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.table-wrap { overflow-x: auto; }

.login { max-width: 360px; margin: 12vh auto 0; }
.stat { font-size: 1.6rem; font-weight: 700; }
.obs { background: var(--warn-soft); padding: .5rem .7rem; border-radius: 10px; white-space: pre-wrap; font-size: .9rem; }
.w-auto { width: auto; }
.primary.danger-bg { background: var(--danger); border-color: var(--danger); color: #fff; }

/* Pausas (horarios bloqueados) */
.pausa {
  grid-column: 2 / -1;
  display: flex; align-items: center; justify-content: center;
  min-height: 38px; padding: .35rem .5rem;
  border-radius: 10px; font-size: .85rem; color: var(--muted);
  background: repeating-linear-gradient(135deg, var(--surface-2) 0 8px, transparent 8px 16px);
  border: 1px solid var(--border);
}
.pausa-time { color: var(--muted); font-weight: 500; padding-top: .45rem; }
.pausa-row { display: grid; grid-template-columns: auto auto auto 1fr auto; gap: .4rem; align-items: center; }
.pausa-row input[type="time"] { width: auto; }
@media (max-width: 520px) {
  .pausa-row { grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr) auto; }
  .pausa-row input[type="time"] { width: 100%; min-width: 0; }
  .pausa-row input[type="text"] { grid-column: 1 / 4; grid-row: 2; }
}
/* Los fieldset tienen min-width: min-content por defecto y desbordan en pantallas chicas. */
fieldset { min-width: 0; margin: 0; border: 1px solid var(--border); border-radius: 10px; padding: .6rem .8rem .8rem; }
.cols > * { min-width: 0; }

/* Días con su horario */
.dias-grid { display: grid; grid-template-columns: auto auto auto auto 1fr; gap: .4rem .5rem; align-items: center; }
.dias-grid input[type="time"] { width: auto; min-width: 0; }
.dias-grid .chip { justify-self: start; }
/* La etiqueta oculta debe conservar su celda; si no, la grilla se corre de fila. */
.dias-grid .chip[hidden] { display: inline-block !important; visibility: hidden; }
@media (max-width: 520px) {
  .dias-grid { grid-template-columns: auto minmax(0, 1fr) auto minmax(0, 1fr); }
  .dias-grid input[type="time"] { width: 100%; }
  .dias-grid .chip, .dias-grid .chip[hidden] { display: none !important; }
}

/* Bloqueos por fecha */
.cell.bloqueada {
  display: flex; align-items: center; justify-content: center;
  font-size: .78rem; color: var(--muted); border-radius: 10px; min-height: 54px; padding: .35rem;
  background: repeating-linear-gradient(135deg, var(--danger-soft) 0 8px, transparent 8px 16px);
  border: 1px solid var(--border); text-align: center; overflow: hidden;
}
.bloqueo-banner {
  display: flex; flex-wrap: wrap; gap: .5rem; align-items: center;
  padding: .6rem .8rem; margin: 0 0 .75rem; border-radius: 10px;
  background: var(--danger-soft); color: var(--text);
}
.week sup { font-size: .6rem; margin-left: 1px; }

/* Avisos de falta y reportes */
.avisos { margin-top: .9rem; display: grid; gap: .35rem; }
.avisos .chip { border: 0; cursor: pointer; min-height: 0; padding: .25rem .6rem; font-size: .8rem; }
.aviso-box { padding: .7rem .85rem; border-radius: 10px; background: var(--surface-2); }
.aviso-box > .row, .aviso-box > div, .aviso-box > ul { margin-top: .5rem; }
.aviso-box > :first-child { margin-top: 0; }
.aviso-box.ok { background: var(--ok-soft); }
.aviso-box.warn { background: var(--warn-soft); }
.aviso-box ul { margin: 0; padding-left: 1.1rem; }
.stats { display: grid; gap: .75rem; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); margin: 1rem 0; }
.stat-card { display: grid; gap: .2rem; }
.txt-danger { color: var(--danger); }
.txt-warn { color: var(--warn); }
.txt-ok { color: var(--ok); }
.warn-banner { background: var(--warn-soft); }
table.reporte th, table.reporte td { white-space: nowrap; }
table.reporte .num { text-align: center; }
table.reporte tbody tr { cursor: pointer; }
table.reporte tbody tr:hover { background: var(--surface-2); }
table.reporte tfoot th { border-top: 2px solid var(--border); color: var(--text); }
.view > h1 + .card { margin-bottom: 0; }
@media (max-width: 760px) { .tabs a { padding: .3rem .3rem; font-size: .68rem; } }

/* Pagos */
.periodo { min-width: 9.5rem; text-align: center; }
.seg button { min-height: 32px; padding: .3rem .7rem; font-size: .85rem; }

/* Portal del alumno */
.portal-view { max-width: 680px; padding-bottom: 3rem; }
.portal-view > * + * { margin-top: 1rem; }
.portal .topbar { justify-content: center; }
.novedad + .novedad { border-top: 1px solid var(--border); margin-top: .8rem; padding-top: .8rem; }
.novedad h3 { margin-bottom: .2rem; }
.novedad p { margin: 0 0 .3rem; white-space: pre-wrap; }
.center-row { justify-content: center; }
details summary { cursor: pointer; color: var(--primary); margin-top: .6rem; }

/* Campana de notificaciones */
.campana { position: relative; border: 0; background: none; font-size: 1.25rem; padding: .3rem .5rem; min-height: 0; }
.campana #badge {
  position: absolute; top: -2px; right: -4px; min-width: 18px; height: 18px; padding: 0 4px;
  border-radius: 9px; background: var(--danger); color: #fff; font-size: .7rem; font-weight: 700;
  display: grid; place-items: center;
}
.campana #badge[hidden] { display: none !important; }
@media (max-width: 760px) { .campana { position: absolute; right: .75rem; top: 50%; transform: translateY(-50%); } .topbar { position: sticky; } }
@media (min-width: 761px) { .campana { order: 3; } .tabs { margin-left: auto; } }
.list li.no-leida b::before { content: '● '; color: var(--danger); }

/* Ocupación */
.week button .pct { font-size: .7rem; color: var(--muted); }
.bar.nivel-bajo i, .ocupacion.nivel-bajo .ocupacion-bar i { background: var(--ok); }
.bar.nivel-medio i, .ocupacion.nivel-medio .ocupacion-bar i { background: var(--warn); }
.bar.nivel-alto i, .ocupacion.nivel-alto .ocupacion-bar i { background: var(--danger); }
.ocupacion { display: grid; gap: .35rem; margin: 0 0 .9rem; font-size: .9rem; }
.ocupacion-bar { height: 10px; border-radius: 5px; background: var(--surface-2); overflow: hidden; }
.ocupacion-bar i { display: block; height: 100%; border-radius: 5px; }
.grid .time { display: flex; flex-direction: column; line-height: 1.15; }
.grid .time .ocup { font-size: .68rem; font-weight: 600; color: var(--muted); }
.grid .time.slot-full .ocup { color: var(--danger); }
.chip.ocu-bajo { background: var(--ok-soft); color: var(--ok); }
.chip.ocu-medio { background: var(--warn-soft); color: var(--warn); }
.chip.ocu-alto { background: var(--danger-soft); color: var(--danger); }
table.heatmap { border-collapse: separate; border-spacing: 3px; }
table.heatmap th, table.heatmap td { border: 0; text-align: center; padding: .35rem .5rem; border-radius: 6px; font-size: .82rem; white-space: nowrap; }
table.heatmap tbody th { text-align: right; color: var(--muted); font-weight: 600; }
.hm-0 { background: var(--surface-2); color: var(--muted); }
.hm-1 { background: #dfeee5; color: #2b5c40; }
.hm-2 { background: #a9d3b8; color: #1d4630; }
.hm-3 { background: #f3c98b; color: #6b4310; }
.hm-4 { background: #e58b7d; color: #5c1a10; font-weight: 700; }
@media (prefers-color-scheme: dark) {
  .hm-1 { background: #24402f; color: #b9e2c8; }
  .hm-2 { background: #2f6b47; color: #e3f6ea; }
  .hm-3 { background: #8a5a1c; color: #fbe6c6; }
  .hm-4 { background: #9b3b2c; color: #ffe1db; }
}
.hm-na { color: var(--muted); }
.hm-total { font-weight: 700; }
.hm-leyenda span[class^='hm-'] { padding: .1rem .5rem; border-radius: 6px; }
/* Las 7 pestañas entran siempre, aun en pantallas muy angostas */
@media (max-width: 760px) {
  .tabs a { flex: 1 1 0; min-width: 0; padding: .3rem .1rem; }
  .tabs a span:last-child { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
}
@media (max-width: 400px) { .tabs a { font-size: .62rem; } .tabs a .ico { font-size: 1.1rem; } }

#avisos-card:empty { display: none; }

/* Ficha del alumno */
.link-btn.nombre { font-weight: 650; color: var(--text); text-decoration: underline; text-decoration-color: var(--border); text-underline-offset: 3px; }
.link-btn.nombre:hover { color: var(--primary); }
.meta.horarios { color: var(--text); }
.ficha h3 { margin: .2rem 0 .3rem; }
.ficha section .list li, .ficha details .list li { padding: .45rem 0; }
dialog { overflow-y: auto; }

.turnos-preview b { color: var(--text); }
