:root {
  --bg: #f1f5f9;
  --panel: #ffffff;
  --ink: #0f172a;
  --muted: #64748b;
  --line: #e2e8f0;
  --brand: #2563eb;
  --brand-ink: #ffffff;
  --oscuro: #0f172a;
  --ambar: #fbbf24;
  --ambar-oscuro: #b45309;
  --ok: #15803d;
  --error: #b91c1c;
  --radio: 10px;
  --alto-cab: 56px;
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  color: var(--ink);
  -webkit-text-size-adjust: 100%;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); font-size: 15px; line-height: 1.4; overscroll-behavior-y: none; }
h1, h2, h3, h4 { margin: 0; line-height: 1.2; }
h1 { font-size: 24px; }
h3 { font-size: 16px; margin-bottom: 10px; }
h4 { font-size: 13px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; margin: 0 0 6px; }
a { color: var(--brand); }
.muted { color: var(--muted); }
.pequena { font-size: 13px; }
.grande { font-size: 17px; }
.espacio { flex: 1; }
.error-texto { color: var(--error); }
[hidden] { display: none !important; }
.solo-print { display: none !important; }

/* ---------- botones y formularios ---------- */
.btn {
  font: inherit; font-weight: 600; cursor: pointer; min-height: 40px; padding: 8px 14px; border-radius: 8px;
  border: 1px solid #cbd5e1; background: #fff; color: var(--ink); display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  touch-action: manipulation;
}
.btn:hover { background: #f8fafc; }
.btn:disabled { opacity: .55; cursor: default; }
.btn.primario { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn.primario:hover { background: #1d4ed8; }
.btn.peligro { background: var(--error); border-color: var(--error); color: #fff; }
.btn.peligro-suave { color: var(--error); border-color: #fecaca; background: #fff5f5; }
.btn.examen-btn { background: var(--ambar); border-color: #f59e0b; color: #451a03; }
.btn.pequeno { min-height: 32px; padding: 4px 10px; font-size: 13px; }
.btn.grande { min-height: 50px; font-size: 17px; }
.btn.icono { width: 40px; padding: 0; font-size: 22px; }
.btn.enlace { border: 0; background: none; color: var(--brand); padding-left: 0; }
.icon-btn { border: 0; background: none; font-size: 18px; cursor: pointer; color: var(--muted); min-width: 36px; min-height: 36px; border-radius: 8px; }
.icon-btn:hover { background: #f1f5f9; }

input, select, textarea {
  font: inherit; min-height: 42px; padding: 8px 10px; border: 1px solid #cbd5e1; border-radius: 8px; background: #fff; color: var(--ink); width: 100%;
}
input[type='color'] { padding: 2px; width: 56px; cursor: pointer; }
input[type='checkbox'] { width: 20px; min-height: 20px; height: 20px; }
input:focus-visible, select:focus-visible, .btn:focus-visible, .card:focus-visible, .fila-click:focus-visible { outline: 3px solid #93c5fd; outline-offset: 1px; }
.form { display: grid; gap: 14px; }
.fila { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }
.campo { display: grid; gap: 4px; }
.campo-et { font-size: 13px; font-weight: 600; color: #334155; }
.ayuda { color: var(--muted); }
.check { display: flex; align-items: center; gap: 10px; font-weight: 600; cursor: pointer; }
.acciones { display: flex; gap: 10px; flex-wrap: wrap; justify-content: flex-end; align-items: center; }
.acciones.dividido { justify-content: flex-start; padding-top: 6px; border-top: 1px solid var(--line); }
.acciones-fila { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.color-input { width: 44px; min-height: 34px; }

/* ---------- cabecera y navegación ---------- */
.cabecera {
  position: sticky; top: 0; z-index: 30; height: var(--alto-cab); background: var(--oscuro); color: #fff;
  display: flex; align-items: center; gap: 18px; padding: 0 16px;
}
.marca { display: flex; align-items: center; gap: 10px; white-space: nowrap; }
.marca img { border-radius: 7px; }
.nav { display: flex; gap: 4px; flex: 1; overflow-x: auto; }
.nav a { color: #cbd5e1; text-decoration: none; padding: 8px 12px; border-radius: 8px; font-weight: 600; white-space: nowrap; }
.nav a:hover { background: #1e293b; color: #fff; }
.nav a.activo { background: #1e293b; color: #fff; box-shadow: inset 0 -3px 0 var(--brand); }
.usuario { display: flex; align-items: center; gap: 8px; font-weight: 600; }
.usuario .btn { background: transparent; color: #e2e8f0; border-color: #475569; }
.punto { display: inline-block; width: 12px; height: 12px; border-radius: 50%; margin-right: 6px; vertical-align: -1px; flex: none; }
.punto.examen { background: var(--ambar); margin-right: 4px; }
.vista { padding: 16px; max-width: 1400px; margin: 0 auto; }
.cargando { padding: 24px; }
.vacio { padding: 32px 16px; text-align: center; color: var(--muted); }

.banner-zona { position: sticky; top: var(--alto-cab); z-index: 25; }
.banner { display: flex; align-items: center; gap: 12px; padding: 8px 16px; font-weight: 600; font-size: 14px; }
.banner.aviso { background: #fef3c7; color: #78350f; }
.banner.info { background: #dbeafe; color: #1e3a8a; }
.banner.error { background: #fee2e2; color: #7f1d1d; }

/* ---------- login ---------- */
.login { min-height: 100dvh; display: grid; place-items: center; padding: 16px; background: linear-gradient(160deg, #0f172a, #1e3a8a); }
.login-caja { width: min(380px, 100%); background: #fff; padding: 28px; border-radius: 16px; box-shadow: 0 20px 50px -20px #000a; text-align: center; }
.login-caja .campo { text-align: left; }
.login-logo { margin: 0 auto; border-radius: 16px; }
.login-caja.ancha { width: min(460px, 100%); display: grid; gap: 12px; }
.login-caja .volver { justify-self: start; min-height: 32px; }
.ae-lista { display: grid; gap: 10px; text-align: left; }
.ae-card {
  display: flex; align-items: center; gap: 14px; width: 100%; padding: 12px 14px; font: inherit; text-align: left; cursor: pointer;
  background: #fff; border: 1px solid #cbd5e1; border-radius: 12px; color: var(--ink); min-height: 64px; touch-action: manipulation;
}
.ae-card:hover { border-color: var(--brand); background: #f8fbff; }
.ae-card:focus-visible { outline: 3px solid #93c5fd; outline-offset: 1px; }
.ae-inicial { flex: none; width: 40px; height: 40px; border-radius: 10px; background: var(--oscuro); color: #fff; display: grid; place-items: center; font-weight: 800; font-size: 18px; }
.ae-texto { display: grid; flex: 1; min-width: 0; }
.ae-texto strong { font-size: 16px; }
.ae-texto small { color: var(--muted); }
.ae-ultima { font-size: 11px; font-weight: 700; color: #1d4ed8; background: #dbeafe; padding: 2px 8px; border-radius: 999px; white-space: nowrap; }
.ae-flecha { color: var(--muted); font-size: 24px; }

/* ---------- páginas genéricas ---------- */
.pagina { display: grid; gap: 16px; }
.pagina-cab { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.pagina-cab input[type='search'] { width: 240px; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radio); padding: 16px; }
.tabla-wrap { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radio); overflow-x: auto; }
.tabla { width: 100%; border-collapse: collapse; }
.tabla th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); padding: 10px 12px; border-bottom: 1px solid var(--line); background: #f8fafc; white-space: nowrap; }
.tabla td { padding: 10px 12px; border-bottom: 1px solid #f1f5f9; vertical-align: middle; }
.tabla tr:last-child td { border-bottom: 0; }
.tabla .num { text-align: right; font-variant-numeric: tabular-nums; }
.tabla.compacta td, .tabla.compacta th { padding: 6px 10px; font-size: 13px; }
.fila-click { cursor: pointer; }
.fila-click:hover { background: #f8fafc; }
.tachada td { color: var(--muted); text-decoration: line-through; }
.tachada td:last-child, .tachada td:nth-last-child(2) { text-decoration: none; }
.lista-simple { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; }
.lista-simple li { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.lista-simple li:last-child { border: 0; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radio); padding: 14px; display: grid; gap: 2px; }
.stat strong { font-size: 24px; font-variant-numeric: tabular-nums; }
.stat span { color: var(--muted); font-size: 13px; }
.resumenes { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 16px; }
.cabecera-impresion { display: grid; gap: 2px; margin-bottom: 12px; padding-bottom: 8px; border-bottom: 2px solid #000; }

.insignia { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 700; background: #e2e8f0; color: #334155; white-space: nowrap; }
.insignia.pendiente { background: #dbeafe; color: #1e40af; }
.insignia.completada, .insignia.apto { background: #dcfce7; color: #166534; }
.insignia.cancelada { background: #e2e8f0; color: #475569; }
.insignia.no_apto { background: #fee2e2; color: #991b1b; }
.aviso { padding: 10px 12px; border-radius: 8px; font-size: 14px; }
.aviso.error { background: #fee2e2; color: #7f1d1d; }
.aviso.info { background: #dbeafe; color: #1e3a8a; }
.firmas-chip { display: inline-flex; gap: 3px; }
.firmas-chip span { display: inline-grid; place-items: center; width: 20px; height: 20px; border-radius: 50%; background: #e2e8f0; color: #94a3b8; font-size: 11px; font-weight: 700; }
.firmas-chip span.on { background: #16a34a; color: #fff; }

/* ---------- calendario ---------- */
.cal { display: grid; gap: 10px; }
.cal-barra { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; }
.cal-nav, .cal-acciones { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.cal-titulo { font-size: 20px; margin-left: 6px; text-transform: capitalize; }
.saltar { width: 150px; }
.pagina-cab input[type='month'] { width: 190px; }
.leyenda { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.chip-prof, .chip-leyenda { display: inline-flex; align-items: center; gap: 2px; padding: 4px 12px 4px 10px; border-radius: 999px; background: #fff; border: 1px solid var(--line); font: inherit; font-weight: 600; font-size: 13px; }
.chip-prof { cursor: pointer; }
.chip-prof.off { opacity: .45; text-decoration: line-through; }
.cal-scroll { background: #fff; border: 1px solid var(--line); border-radius: var(--radio); overflow: auto; height: calc(100dvh - 220px); min-height: 420px; }
.cal-grid { display: grid; grid-template-columns: 52px repeat(7, minmax(100px, 1fr)); min-width: 752px; }
.cal-esquina, .cal-cab { position: sticky; top: 0; z-index: 4; background: #f8fafc; border-bottom: 1px solid var(--line); }
.cal-esquina { left: 0; z-index: 6; }
.cal-cab { display: flex; align-items: baseline; justify-content: center; gap: 6px; padding: 8px 4px; border-left: 1px solid var(--line); }
.cab-dia { text-transform: capitalize; color: var(--muted); font-weight: 600; }
.cab-num { font-size: 20px; font-weight: 700; }
.cab-n { font-size: 11px; color: var(--muted); }
.cal-cab.hoy .cab-num { background: var(--brand); color: #fff; border-radius: 999px; min-width: 32px; text-align: center; padding: 1px 6px; }
.cal-horas { position: sticky; left: 0; z-index: 3; background: #fff; }
.cal-hora span { display: block; text-align: right; padding: 2px 6px 0 0; font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums; }
.cal-dia {
  position: relative; border-left: 1px solid var(--line); cursor: cell;
  background-image: repeating-linear-gradient(to bottom, transparent 0, transparent calc(var(--hora) / 2 - 1px), #f1f5f9 calc(var(--hora) / 2 - 1px), #f1f5f9 calc(var(--hora) / 2), transparent calc(var(--hora) / 2), transparent calc(var(--hora) - 1px), var(--line) calc(var(--hora) - 1px), var(--line) var(--hora));
}
.cal-dia.hoy { background-color: #f5f9ff; }
.ahora { position: absolute; left: 0; right: 0; height: 0; border-top: 2px solid #ef4444; z-index: 2; pointer-events: none; }
.ahora::before { content: ''; position: absolute; left: -4px; top: -5px; width: 8px; height: 8px; border-radius: 50%; background: #ef4444; }

/* Tarjetas: "imanes" de colores por profesor */
.card {
  position: absolute; z-index: 1; overflow: hidden; text-align: left; font: inherit; cursor: pointer; border: 0;
  background: var(--color, #64748b); color: #fff; border-radius: 8px; padding: 4px 8px 3px; display: flex; flex-direction: column; gap: 0;
  box-shadow: 0 1px 2px #0003, 0 6px 12px -8px #0006; transition: transform .12s, box-shadow .12s;
}
.card:hover { transform: translateY(-1px) rotate(-.4deg); box-shadow: 0 2px 4px #0003, 0 10px 18px -8px #0008; z-index: 5; }
.card-hora { font-size: 11px; opacity: .85; font-variant-numeric: tabular-nums; line-height: 1.2; }
.card-nombre { font-weight: 700; font-size: 13px; line-height: 1.2; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card-meta { font-size: 11px; opacity: .9; line-height: 1.25; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card.compacta .card-hora { display: none; }
.card-sello { position: absolute; top: 3px; right: 5px; width: 18px; height: 18px; display: grid; place-items: center; border-radius: 50%; background: #fff; color: var(--color, #16a34a); font-size: 12px; font-weight: 800; }
.card-sello.cola { color: #b45309; background: #fef3c7; }
.card-sello.aviso { background: #fef2f2; color: #dc2626; }
.card.completada { filter: saturate(.85); }
.card.cancelada { opacity: .5; background-image: repeating-linear-gradient(135deg, transparent 0 6px, #ffffff33 6px 12px); }
.card.cancelada .card-nombre { text-decoration: line-through; }
.card.sin-cerrar { outline: 2px dashed #ef4444; outline-offset: -2px; }
.card.examen { background: var(--ambar); color: #451a03; border-left: 5px solid var(--ambar-oscuro); box-shadow: 0 1px 2px #0003, 0 0 0 1px #f59e0b; }
.card.examen .card-hora { font-weight: 800; letter-spacing: .03em; opacity: 1; }
.card.examen.apto { background: #bbf7d0; border-left-color: #15803d; color: #052e16; }
.card.examen.no_apto { background: #fecaca; border-left-color: #b91c1c; color: #450a0a; }

/* ---------- diálogos ---------- */
.modal { border: 0; border-radius: 16px; padding: 0; width: min(520px, calc(100vw - 24px)); max-height: calc(100dvh - 24px); box-shadow: 0 30px 70px -20px #000a; color: var(--ink); overflow: hidden; }
.modal.ancho { width: min(820px, calc(100vw - 24px)); }
.modal.estrecho { width: min(420px, calc(100vw - 24px)); }
.modal::backdrop { background: #0f172a99; }
.modal[open] { display: flex; flex-direction: column; }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 12px 12px 12px 18px; border-bottom: 1px solid var(--line); }
.modal-head h2 { font-size: 18px; }
.modal-body { padding: 16px 18px 18px; overflow: auto; display: grid; gap: 14px; align-content: start; }
.clase-cabecera { border-left: 5px solid #94a3b8; padding-left: 12px; display: grid; gap: 2px; }
.clase-cabecera.examen { border-color: var(--ambar-oscuro); }
.datos { display: grid; grid-template-columns: max-content 1fr; gap: 6px 18px; margin: 0; }
.dato { display: contents; }
.dato dt { color: var(--muted); }
.dato dd { margin: 0; font-weight: 600; }
.galeria-firmas { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 12px; }
.galeria-firmas figure { margin: 0; border: 1px solid var(--line); border-radius: 10px; padding: 8px; background: #fff; }
.galeria-firmas img { display: block; width: 100%; height: 90px; object-fit: contain; }
.galeria-firmas figcaption { font-size: 13px; font-weight: 600; display: grid; }
.galeria-firmas small { color: var(--muted); font-weight: 400; }

.selector-alumno { position: relative; }
.sugerencias { position: absolute; left: 0; right: 0; top: calc(100% + 4px); z-index: 10; background: #fff; border: 1px solid #cbd5e1; border-radius: 8px; box-shadow: 0 12px 24px -12px #0006; overflow: hidden; }
.sug { display: flex; justify-content: space-between; gap: 8px; width: 100%; padding: 11px 12px; border: 0; border-bottom: 1px solid var(--line); background: #fff; font: inherit; text-align: left; cursor: pointer; }
.sug:last-child { border-bottom: 0; }
.sug:hover, .sug:focus-visible { background: #eff6ff; }
.sug small { color: var(--muted); }
.sug.nuevo { color: var(--brand); font-weight: 700; }
.alumno-elegido { display: flex; align-items: center; gap: 10px; padding: 6px 6px 6px 12px; border: 1px solid #bfdbfe; background: #eff6ff; border-radius: 8px; min-height: 44px; }
.alumno-elegido small { color: var(--muted); }
.alumno-elegido .nuevo-tag { color: var(--brand); font-weight: 700; }
.alumno-elegido .icon-btn { margin-left: auto; }

/* ---------- firma táctil ---------- */
.pads { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.firma-pad { display: grid; gap: 6px; }
.firma-cabecera { display: flex; justify-content: space-between; align-items: center; gap: 8px; font-size: 14px; }
.firma-zona { position: relative; border: 2px dashed #94a3b8; border-radius: 12px; background: #fff; overflow: hidden; }
.firma-canvas { position: absolute; inset: 0; touch-action: none; cursor: crosshair; -webkit-user-select: none; user-select: none; }
.firma-linea { position: absolute; left: 6%; right: 6%; bottom: 28%; border-bottom: 1px solid #cbd5e1; pointer-events: none; }
.firma-linea span { position: absolute; left: 0; top: 4px; font-size: 12px; color: #94a3b8; }
.firma-linea.oculta span { display: none; }
.bloque-director { display: grid; gap: 10px; }

.toasts { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); z-index: 1000; display: grid; gap: 8px; width: min(440px, calc(100vw - 24px)); }
.toast { padding: 12px 16px; border-radius: 10px; background: #14532d; color: #fff; font-weight: 600; box-shadow: 0 10px 24px -8px #0008; }
.toast.error { background: #7f1d1d; }
.toast.aviso { background: #78350f; }
dialog[open] ~ .toasts { z-index: 2000; }

/* ---------- tablet vertical y móvil: navegación inferior ---------- */
@media (max-width: 900px) {
  .cabecera { padding: 0 10px; gap: 8px; justify-content: space-between; }
  .marca strong { max-width: 45vw; overflow: hidden; text-overflow: ellipsis; }
  .nav { position: fixed; left: 0; right: 0; bottom: 0; z-index: 40; flex: none; background: var(--oscuro); padding: 6px 6px calc(6px + env(safe-area-inset-bottom)); justify-content: space-around; border-top: 1px solid #1e293b; }
  .nav a { flex: 1; text-align: center; padding: 10px 2px; font-size: 13px; }
  .vista { padding: 12px 12px 84px; }
  .toasts { bottom: 84px; }
}

/* ---------- móvil ---------- */
@media (max-width: 760px) {
  body { font-size: 16px; }
  .usuario-nombre { display: none; }
  .cal-grid { grid-template-columns: 46px repeat(7, minmax(128px, 1fr)); min-width: 940px; }
  .cal-scroll { height: calc(100dvh - 300px); }
  .cal-titulo { font-size: 17px; }
  .pads { grid-template-columns: 1fr; }
  .oculta-movil { display: none; }
  .pagina-cab input[type='search'] { width: 100%; }
  .modal { width: 100vw !important; max-height: 96dvh; margin: auto 0 0; border-radius: 16px 16px 0 0; }
  .modal-body { padding-bottom: calc(18px + env(safe-area-inset-bottom)); }
}

/* ---------- impresión (ficha del alumno y parte mensual) ---------- */
@media print {
  body { background: #fff; font-size: 11pt; }
  .no-print, .cabecera, .banner-zona, .toasts, .btn { display: none !important; }
  .solo-print { display: grid !important; }
  .vista { padding: 0; max-width: none; }
  .panel, .stat, .tabla-wrap { border-color: #999; box-shadow: none; }
  .tabla-wrap { overflow: visible; }
  .tabla th { background: #eee !important; color: #000; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .insignia { border: 1px solid #999; background: none !important; color: #000 !important; }
  .fila-click { cursor: auto; }
  .firma-director { display: flex !important; justify-content: space-between; margin-top: 60px; }
  .firma-director span { border-top: 1px solid #000; padding-top: 4px; width: 40%; text-align: center; }
  .firmas-chip span { border: 1px solid #999; background: none !important; color: #000 !important; }
  .firmas-chip span.on { font-weight: 900; }
  .punto { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  @page { margin: 14mm; }
}
