/* ===== Variables y base ===== */
:root {
  --bg: #faf7f0;
  --surface: #ffffff;
  --ink: #1c1c1c;
  --ink-soft: #5c5c56;
  --accent: #0f766e;
  --accent-soft: #d5efe8;
  --accent-dark: #0c5f59;
  --line: #e7e2d8;
  --danger: #b3402a;
  --danger-soft: #f8e3dd;
  --warn: #a16207;
  --warn-soft: #fdf0d2;
  --ok: #15803d;
  --ok-soft: #ddf2e2;
  --radius: 14px;
  --sidebar-w: 260px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 16px;
}

button { font: inherit; cursor: pointer; }
input, select, textarea { font: inherit; }

/* ===== Estructura ===== */
#app { min-height: 100dvh; }

.topbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; gap: 12px;
  padding: 12px 16px;
  padding-top: calc(12px + env(safe-area-inset-top));
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}
.topbar h1 { font-size: 1.15rem; font-weight: 700; flex: 1; }

.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 40px; height: 40px; border: none; border-radius: 12px;
  background: transparent; color: var(--ink);
}
.icon-btn:hover { background: var(--accent-soft); }
.icon-btn svg { width: 24px; height: 24px; }

.scrim {
  position: fixed; inset: 0; z-index: 40;
  background: rgba(0,0,0,.35);
  opacity: 0; pointer-events: none; transition: opacity .2s;
}
.scrim.visible { opacity: 1; pointer-events: auto; }

.sidebar {
  position: fixed; top: 0; left: 0; bottom: 0; z-index: 50;
  width: var(--sidebar-w);
  background: var(--bg);
  border-right: 1px solid var(--line);
  display: flex; flex-direction: column;
  transform: translateX(-100%);
  transition: transform .22s ease;
  padding-top: env(safe-area-inset-top);
}
.sidebar.open { transform: translateX(0); }

.sidebar-header {
  display: flex; align-items: center; gap: 12px;
  padding: 18px 16px 14px;
}
.logo {
  width: 42px; height: 42px; border-radius: 12px;
  object-fit: cover; display: block;
}
.app-name { font-weight: 700; }
.teacher-name { font-size: .8rem; color: var(--ink-soft); }

.nav-list { list-style: none; overflow-y: auto; flex: 1; padding: 6px 10px; }
.nav-list li { margin-bottom: 2px; }
.nav-link {
  display: flex; align-items: center; gap: 14px;
  width: 100%; padding: 12px 14px;
  border: none; border-radius: var(--radius);
  background: transparent; color: var(--ink);
  font-size: 1rem; text-align: left;
}
.nav-link svg { width: 22px; height: 22px; flex-shrink: 0; }
.nav-link:hover { background: #f0ece2; }
.nav-link.active { background: var(--accent-soft); font-weight: 700; }
.nav-link .nav-badge {
  margin-left: auto; background: var(--danger); color: #fff;
  font-size: .72rem; font-weight: 700;
  border-radius: 999px; padding: 2px 8px;
}

.sidebar-footer { padding: 12px 16px; font-size: .75rem; color: var(--ink-soft); }

.main {
  padding: 16px;
  padding-bottom: calc(24px + env(safe-area-inset-bottom));
  max-width: 900px;
}

/* Escritorio: menú fijo visible */
@media (min-width: 900px) {
  .sidebar { transform: none; }
  .scrim { display: none; }
  .topbar { margin-left: var(--sidebar-w); }
  .main { margin-left: var(--sidebar-w); padding: 24px 32px; }
  #btn-menu { display: none; }
}

/* ===== Componentes ===== */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
}
.card h3 { font-size: 1rem; margin-bottom: 8px; }
.card .muted { color: var(--ink-soft); font-size: .85rem; }

.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.row .spacer { flex: 1; }

.btn {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 10px 16px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--surface); color: var(--ink); font-weight: 600;
}
.btn:hover { background: #f4f1e9; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-dark); }
.btn.danger { background: var(--danger-soft); border-color: var(--danger-soft); color: var(--danger); }
.btn.small { padding: 6px 10px; font-size: .85rem; border-radius: 10px; }

.field { margin-bottom: 12px; }
.field label { display: block; font-size: .85rem; font-weight: 600; margin-bottom: 4px; }
.field input, .field select, .field textarea {
  width: 100%; padding: 10px 12px;
  border: 1px solid var(--line); border-radius: 10px;
  background: var(--surface);
}
.field input:focus, .field select:focus, .field textarea:focus {
  outline: 2px solid var(--accent); outline-offset: 1px; border-color: transparent;
}

.list-item {
  display: flex; align-items: center; gap: 12px;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 14px; margin-bottom: 10px;
}
.list-item .grow { flex: 1; min-width: 0; }
.list-item .title { font-weight: 700; }
.list-item .sub { font-size: .82rem; color: var(--ink-soft); }
.list-item.clickable { cursor: pointer; }
.list-item.clickable:hover { border-color: var(--accent); }

.avatar {
  width: 40px; height: 40px; border-radius: 50%; flex-shrink: 0;
  background: var(--accent-soft); color: var(--accent);
  display: flex; align-items: center; justify-content: center; font-weight: 700;
}

.pill {
  display: inline-block; padding: 3px 10px; border-radius: 999px;
  font-size: .75rem; font-weight: 700;
}
.pill.ok { background: var(--ok-soft); color: var(--ok); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.pill.danger { background: var(--danger-soft); color: var(--danger); }
.pill.neutral { background: #eee9df; color: var(--ink-soft); }

.badge {
  background: var(--danger); color: #fff; font-size: .72rem; font-weight: 700;
  border-radius: 999px; padding: 2px 8px;
}
.hidden { display: none !important; }

.empty {
  text-align: center; color: var(--ink-soft);
  padding: 40px 16px; font-size: .95rem;
}
.empty svg { width: 48px; height: 48px; margin-bottom: 10px; opacity: .4; }

.section-title {
  font-size: .8rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: .05em; color: var(--ink-soft); margin: 18px 0 8px;
}

/* Tarjetas resumen del inicio */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; margin-bottom: 12px; }
.stat-card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 14px;
}
.stat-card .num { font-size: 1.7rem; font-weight: 800; color: var(--accent); }
.stat-card .lbl { font-size: .8rem; color: var(--ink-soft); }

/* Próximo evento destacado (Inicio) */
.event-hero {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  cursor: pointer;
}
.event-hero:hover { background: var(--accent-dark); }
.event-hero .when {
  font-size: .75rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: .06em;
  color: rgba(255,255,255,.9);
}
.event-hero h3 { font-size: 1.2rem; margin: 4px 0 2px; }
.event-hero .sub-inv { font-size: .88rem; color: rgba(255,255,255,.88); text-transform: capitalize; }

/* Asistencia */
.att-row {
  display: flex; align-items: center; gap: 10px;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 10px 12px; margin-bottom: 8px;
}
.att-row .name { flex: 1; font-weight: 600; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.att-btns { display: flex; gap: 6px; }
.att-btn {
  width: 38px; height: 38px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--surface);
  font-weight: 700; font-size: .85rem; color: var(--ink-soft);
}
.att-btn.sel-P { background: var(--ok-soft); border-color: var(--ok); color: var(--ok); }
.att-btn.sel-A { background: var(--danger-soft); border-color: var(--danger); color: var(--danger); }
.att-btn.sel-T { background: var(--warn-soft); border-color: var(--warn); color: var(--warn); }
.att-btn.sel-J { background: #e3e7fb; border-color: #4356c0; color: #4356c0; }

/* Planilla de notas */
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
table.grid { border-collapse: collapse; width: 100%; min-width: 480px; }
table.grid th, table.grid td { border-bottom: 1px solid var(--line); padding: 8px 10px; text-align: left; font-size: .88rem; }
table.grid th { background: #f6f3ea; font-size: .78rem; text-transform: uppercase; letter-spacing: .03em; position: sticky; top: 0; }
table.grid td.num, table.grid th.num { text-align: center; }
table.grid input.nota {
  width: 56px; padding: 6px; text-align: center;
  border: 1px solid var(--line); border-radius: 8px;
}
table.grid input.nota:focus { outline: 2px solid var(--accent); }
td.avg { font-weight: 700; text-align: center; }

/* Calendario */
.cal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.cal-head .month { font-weight: 700; font-size: 1.05rem; text-transform: capitalize; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.cal-dow { text-align: center; font-size: .7rem; font-weight: 700; color: var(--ink-soft); padding: 4px 0; text-transform: uppercase; }
.cal-day {
  aspect-ratio: 1; border-radius: 10px; border: 1px solid transparent;
  background: var(--surface); border-color: var(--line);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  font-size: .85rem; cursor: pointer; position: relative;
}
.cal-day.other { opacity: .35; }
.cal-day.today { border-color: var(--accent); font-weight: 800; color: var(--accent); }
.cal-day.selected { background: var(--accent-soft); }
.cal-day .dot { width: 6px; height: 6px; border-radius: 50%; background: var(--accent); position: absolute; bottom: 6px; }
.cal-day.feriado { background: var(--danger-soft); color: var(--danger); font-weight: 700; }
.cal-day.feriado.selected { outline: 2px solid var(--danger); }

/* Selector de colores (Configuración) */
.swatch {
  width: 34px; height: 34px; border-radius: 50%;
  border: 2px solid transparent; padding: 0;
}
.swatch.sel { border-color: var(--ink); box-shadow: 0 0 0 2px #fff inset; }
input[type="color"] { width: 42px; height: 34px; border: 1px solid var(--line); border-radius: 10px; padding: 2px; background: var(--surface); cursor: pointer; }

/* Estadísticas: barras */
.bar-row { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.bar-row .bar-label { width: 130px; font-size: .82rem; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-track { flex: 1; height: 18px; background: #efebe1; border-radius: 999px; overflow: hidden; }
.bar-fill { height: 100%; background: var(--accent); border-radius: 999px; }
.bar-fill.warn { background: var(--warn); }
.bar-fill.danger { background: var(--danger); }
.bar-row .bar-val { width: 48px; text-align: right; font-size: .82rem; font-weight: 700; }

/* Modal */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(0,0,0,.4);
  display: flex; align-items: flex-end; justify-content: center;
}
.modal {
  background: var(--bg); width: 100%; max-width: 520px;
  border-radius: 20px 20px 0 0;
  padding: 20px 18px calc(20px + env(safe-area-inset-bottom));
  max-height: 88dvh; overflow-y: auto;
}
@media (min-width: 700px) {
  .modal-backdrop { align-items: center; }
  .modal { border-radius: 20px; }
}
.modal h2 { font-size: 1.1rem; margin-bottom: 14px; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 16px; }

/* Toast */
.toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom));
  transform: translateX(-50%); z-index: 200;
  background: var(--ink); color: #fff;
  padding: 10px 18px; border-radius: 999px; font-size: .9rem;
  box-shadow: 0 4px 14px rgba(0,0,0,.25);
}

/* ===== Pantalla de acceso (login) ===== */
.auth-overlay {
  position: fixed; inset: 0; z-index: 500;
  background: var(--bg);
  display: flex; align-items: center; justify-content: center;
  padding: 20px; overflow-y: auto;
}
.auth-card {
  width: 100%; max-width: 380px;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 20px; padding: 28px 24px;
  text-align: center;
}
.auth-logo { width: 84px; height: 84px; border-radius: 20px; margin-bottom: 10px; }
.auth-card h1 { font-size: 1.3rem; margin-bottom: 2px; }
.auth-sub { color: var(--ink-soft); font-size: .9rem; margin-bottom: 18px; }
.auth-card .field { text-align: left; }
.auth-main { width: 100%; justify-content: center; margin-top: 6px; }
.auth-link {
  display: block; width: 100%; margin-top: 12px;
  background: none; border: none; color: var(--accent);
  font-size: .9rem; text-align: center;
}
.auth-link:hover { text-decoration: underline; }
.auth-error {
  background: var(--danger-soft); color: var(--danger);
  border-radius: 10px; padding: 10px 12px; font-size: .85rem;
  margin-bottom: 10px; text-align: left;
}
.auth-info {
  background: var(--ok-soft); color: var(--ok);
  border-radius: 10px; padding: 10px 12px; font-size: .85rem;
  margin-bottom: 10px; text-align: left;
}
.auth-brand { margin-top: 18px; font-size: .72rem; color: var(--ink-soft); }
.auth-user { padding: 10px 16px; border-top: 1px solid var(--line); }
.auth-user-mail {
  font-size: .8rem; font-weight: 600; margin-bottom: 6px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.sync-estado { font-size: .72rem; color: var(--ink-soft); margin-bottom: 6px; min-height: 1em; }

/* ===== Informe / impresión PDF ===== */
.report-sheet {
  background: #fff; border: 1px solid var(--line); border-radius: var(--radius);
  padding: 24px; margin-top: 12px;
}
.report-sheet h2 { font-size: 1.2rem; }
.report-sheet .rep-head { border-bottom: 2px solid var(--accent); padding-bottom: 10px; margin-bottom: 14px; }
.report-sheet .rep-inst { color: var(--ink-soft); font-size: .85rem; }
.report-sheet table { width: 100%; border-collapse: collapse; margin: 8px 0 16px; }
.report-sheet th, .report-sheet td { border: 1px solid #ddd; padding: 6px 10px; font-size: .85rem; text-align: left; }
.report-sheet th { background: #f2efe7; }
.rep-brand { margin-top: 18px; font-size: .72rem; color: var(--ink-soft); text-align: right; }

/* Planilla mensual de asistencia (estilo registro impreso) */
table.mini-grid { border-collapse: collapse; width: 100%; }
table.mini-grid th, table.mini-grid td {
  border: 1px solid #bbb; padding: 2px 3px;
  font-size: .68rem; text-align: center; line-height: 1.3;
}
table.mini-grid th { background: #f2efe7; font-weight: 700; }
table.mini-grid .mg-nombre { text-align: left; white-space: nowrap; padding: 2px 6px; min-width: 130px; }
table.mini-grid .mg-num { width: 24px; color: var(--ink-soft); }
table.mini-grid .mg-sem { border-left: 2px solid #666; }
table.mini-grid .mg-fer { background: #e4e0d6; }
table.mini-grid .mg-a { color: var(--danger); font-weight: 700; }
table.mini-grid .mg-tot { border-left: 2px solid #666; font-weight: 700; width: 40px; }
table.mini-grid tr:nth-child(even) td { background: #f7f4ec; }
table.mini-grid tr:nth-child(even) td.mg-fer { background: #e4e0d6; }

.page-break { height: 0; }

@media print {
  .page-break { break-after: page; }
  .table-wrap { border: none; overflow: visible; }
  table.mini-grid { min-width: 0; }
}

@media print {
  .topbar, .sidebar, .scrim, .no-print, .toast { display: none !important; }
  .main { margin: 0 !important; padding: 0 !important; max-width: none; }
  .report-sheet { border: none; padding: 0; }
  body { background: #fff; }
}
