/* ============================================================
   Sistema de diseño — Control de acceso escolar "checkaula"
   Paleta: índigo institucional + acentos de estado.
   Layout: sidebar en escritorio, barra inferior en móvil.
   ============================================================ */

:root {
  /* Base */
  --ink:        #1e2438;   /* texto principal, casi negro azulado */
  --ink-soft:   #5b6478;   /* texto secundario */
  --line:       #e6e9f0;   /* bordes y divisores */
  --bg:         #f5f6fa;   /* fondo de la app */
  --card:       #ffffff;   /* tarjetas */

  /* Marca — pizarra oscura + acento cian */
  --brand:      #0891b2;   /* cian: botones, acentos, foco */
  --brand-700:  #0e7490;
  --brand-50:   #ecfeff;
  --brand-grad: linear-gradient(165deg, #1e293b, #0f172a 70%);
  --accent:     #22d3ee;   /* cian brillante para detalles sobre el sidebar */

  /* Estados */
  --ok:    #16a34a;  --ok-bg:   #dcfce7;
  --warn:  #d97706;  --warn-bg: #fef3c7;
  --bad:   #dc2626;  --bad-bg:  #fee2e2;
  --info:  #0891b2;  --info-bg: #cffafe;

  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 1px 3px rgba(30,36,56,.06), 0 8px 24px -12px rgba(30,36,56,.12);
  --shadow-lg: 0 20px 50px -20px rgba(30,36,56,.35);
  --sidebar-w: 236px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: 'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  line-height: 1.5;
}

/* ---------- Layout con sidebar ---------- */
.app { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w);
  background: var(--brand-grad);
  color: #fff;
  padding: 22px 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  position: fixed;
  top: 0; bottom: 0; left: 0;
  z-index: 40;
}
.sidebar .brand {
  display: flex; align-items: center; gap: 12px;
  padding: 0 8px 20px;
  margin-bottom: 8px;
  border-bottom: 1px solid rgba(255,255,255,.15);
}
.sidebar .brand .logo {
  width: 42px; height: 42px; border-radius: 12px;
  background: var(--brand); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 22px; flex-shrink: 0;
}
.sidebar .brand .name { font-weight: 700; font-size: 16px; line-height: 1.15; }
.sidebar .brand .sub { font-size: 11px; opacity: .8; }

.nav-item {
  display: flex; align-items: center; gap: 12px;
  padding: 11px 14px; border-radius: var(--radius-sm);
  color: rgba(255,255,255,.85); cursor: pointer;
  font-size: 14px; font-weight: 500;
  border: none; background: none; text-align: left; width: 100%;
  transition: background .15s;
}
.nav-item:hover { background: rgba(255,255,255,.12); }
.nav-item.active { background: rgba(34,211,238,.16); color: var(--accent); font-weight: 600; box-shadow: inset 3px 0 0 var(--accent); }
.nav-item .ico { width: 20px; text-align: center; font-size: 16px; }
.sidebar .foot { margin-top: auto; padding-top: 12px; }

/* ---------- Contenido principal ---------- */
.main {
  flex: 1;
  margin-left: var(--sidebar-w);
  min-width: 0;
  display: flex; flex-direction: column;
}
.topbar {
  height: 64px; background: var(--card);
  border-bottom: 1px solid var(--line);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 24px;
  position: sticky; top: 0; z-index: 30;
}
.topbar h1 { font-size: 18px; font-weight: 700; }
.topbar .user { display: flex; align-items: center; gap: 10px; font-size: 14px; color: var(--ink-soft); }
.content { padding: 24px; flex: 1; }

/* ---------- Tarjetas ---------- */
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 22px;
  margin-bottom: 18px;
}
.card h2 { font-size: 16px; font-weight: 700; margin-bottom: 14px; }
.card .card-sub { font-size: 13px; color: var(--ink-soft); margin-top: -8px; margin-bottom: 14px; }

/* KPIs */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px,1fr)); gap: 14px; }
.kpi {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow);
  display: flex; align-items: center; gap: 14px;
}
.kpi .kico {
  width: 46px; height: 46px; border-radius: 12px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center; font-size: 22px;
  background: var(--brand-50); color: var(--brand);
}
.kpi.ok .kico { background: var(--ok-bg); color: var(--ok); }
.kpi.warn .kico { background: var(--warn-bg); color: var(--warn); }
.kpi.bad .kico { background: var(--bad-bg); color: var(--bad); }
.kpi b { font-size: 26px; font-weight: 800; display: block; line-height: 1; }
.kpi span { font-size: 12px; color: var(--ink-soft); }

/* ---------- Formularios ---------- */
label { display: block; font-size: 13px; color: var(--ink-soft); margin: 12px 0 5px; font-weight: 600; }
input, select, textarea {
  width: 100%; padding: 11px 13px; font-size: 15px; font-family: inherit;
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  background: #fff; color: var(--ink); transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--brand);
  box-shadow: 0 0 0 3px var(--brand-50);
}
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

/* ---------- Botones ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 12px 20px; border-radius: var(--radius-sm); border: none;
  font-size: 15px; font-weight: 600; cursor: pointer; font-family: inherit;
  transition: transform .05s, box-shadow .15s, background .15s;
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-700); }
.btn-block { width: 100%; }
.btn-ghost { background: var(--brand-50); color: var(--brand-700); }
.btn-ghost:hover { background: #e0e7ff; }
.btn-sm { padding: 7px 12px; font-size: 13px; border-radius: 8px; }
.btn-danger { background: var(--bad-bg); color: var(--bad); }

/* ---------- Tablas ---------- */
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 11px 10px; border-bottom: 1px solid var(--line); }
th { color: var(--ink-soft); font-size: 12px; font-weight: 600; }
tr:last-child td { border-bottom: none; }

/* ---------- Pills / badges ---------- */
.pill { display: inline-block; padding: 4px 12px; border-radius: 999px; font-size: 12px; font-weight: 700; }
.pill.ok { background: var(--ok-bg); color: var(--ok); }
.pill.warn { background: var(--warn-bg); color: var(--warn); }
.pill.bad { background: var(--bad-bg); color: var(--bad); }
.pill.info { background: var(--info-bg); color: var(--info); }

/* ---------- Mensajes ---------- */
.msg { padding: 11px 14px; border-radius: var(--radius-sm); margin-top: 12px; font-size: 14px; }
.msg.ok { background: var(--ok-bg); color: var(--ok); }
.msg.err { background: var(--bad-bg); color: var(--bad); }

/* ---------- Avatares ---------- */
.avatar {
  border-radius: 50%; flex-shrink: 0; overflow: hidden;
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-weight: 700; background: var(--brand);
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }

/* ---------- Login ---------- */
.login-wrap {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  padding: 20px; background: var(--brand-grad);
}
.login-card {
  background: var(--card); border-radius: 22px; box-shadow: var(--shadow-lg);
  padding: 36px 30px; width: 100%; max-width: 400px;
}
.login-card .brand-lg {
  display: flex; flex-direction: column; align-items: center; gap: 12px; margin-bottom: 22px;
}
.login-card .brand-lg .logo {
  width: 60px; height: 60px; border-radius: 16px; background: var(--brand);
  display: flex; align-items: center; justify-content: center; font-size: 30px; color: #fff;
}
.login-card h2 { text-align: center; font-size: 20px; }

/* ---------- Barra inferior móvil (oculta en desktop) ---------- */
.mobilenav { display: none; }

/* ---------- Botón instalar app ---------- */
.install-banner {
  display: none; align-items: center; gap: 12px;
  background: var(--brand-50); border: 1px solid #c7d2fe;
  border-radius: var(--radius); padding: 12px 16px; margin-bottom: 18px;
}
.install-banner.show { display: flex; }
.install-banner .txt { flex: 1; font-size: 14px; color: var(--brand-700); }

.hidden { display: none !important; }

/* ============================================================
   RESPONSIVE — móvil: sidebar se oculta, aparece barra inferior
   ============================================================ */
@media (max-width: 820px) {
  .sidebar { display: none; }
  .main { margin-left: 0; }
  .content { padding: 16px; padding-bottom: 84px; }
  .topbar { padding: 0 16px; }
  .row { grid-template-columns: 1fr; }

  .mobilenav {
    display: flex;
    position: fixed; bottom: 0; left: 0; right: 0; z-index: 50;
    background: var(--card); border-top: 1px solid var(--line);
    padding: 6px 4px 8px;
    box-shadow: 0 -4px 20px -8px rgba(30,36,56,.15);
  }
  .mobilenav .nav-item {
    flex-direction: column; gap: 3px; padding: 6px 4px;
    color: var(--ink-soft); font-size: 10px; font-weight: 600;
    border-radius: 10px;
  }
  .mobilenav .nav-item .ico { font-size: 20px; width: auto; }
  .mobilenav .nav-item.active { background: var(--brand-50); color: var(--brand-700); }
  .mobilenav .nav-item:hover { background: none; }
}

/* ============================================================
   DataTables — integración con el diseño
   ============================================================ */
.dt-wrap { overflow-x: auto; }
table.dataTable { width: 100% !important; border-collapse: collapse; }
table.dataTable thead th {
  cursor: pointer; user-select: none; position: relative;
  color: var(--ink-soft); font-size: 12px; font-weight: 600;
  padding: 11px 24px 11px 10px; border-bottom: 2px solid var(--line);
}
table.dataTable thead th.sorting:after,
table.dataTable thead th.sorting_asc:after,
table.dataTable thead th.sorting_desc:after {
  position: absolute; right: 8px; opacity: .4; font-size: 11px;
}
table.dataTable thead th.sorting:after { content: '⇅'; }
table.dataTable thead th.sorting_asc:after { content: '↑'; opacity: 1; color: var(--brand); }
table.dataTable thead th.sorting_desc:after { content: '↓'; opacity: 1; color: var(--brand); }
table.dataTable tbody td { padding: 11px 10px; border-bottom: 1px solid var(--line); font-size: 14px; }
table.dataTable tbody tr:hover { background: var(--brand-50); }

/* Controles de DataTables */
.dataTables_wrapper .dataTables_filter input,
.dataTables_wrapper .dataTables_length select {
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  padding: 8px 12px; font-size: 14px; font-family: inherit; margin-left: 8px;
}
.dataTables_wrapper .dataTables_filter input:focus { outline:none; border-color:var(--brand); box-shadow:0 0 0 3px var(--brand-50); }
.dataTables_wrapper .dataTables_filter { margin-bottom: 14px; }
.dataTables_wrapper .dataTables_length { margin-bottom: 14px; font-size: 13px; color: var(--ink-soft); }
.dataTables_wrapper .dataTables_info { font-size: 13px; color: var(--ink-soft); padding-top: 12px; }
.dataTables_wrapper .dataTables_paginate { padding-top: 10px; }
.dataTables_wrapper .dataTables_paginate .paginate_button {
  padding: 6px 12px; margin: 0 2px; border-radius: 8px; cursor: pointer;
  border: 1px solid var(--line); background: #fff; color: var(--ink) !important; font-size: 13px;
}
.dataTables_wrapper .dataTables_paginate .paginate_button.current {
  background: var(--brand); color: #fff !important; border-color: var(--brand);
}
.dataTables_wrapper .dataTables_paginate .paginate_button.disabled { opacity: .4; cursor: default; }

/* Fila de acciones */
.acc-btns { display: flex; gap: 5px; flex-wrap: wrap; }

/* Celda con avatar en tabla */
.cell-persona { display: flex; align-items: center; gap: 10px; }
.cell-persona .avatar { width: 34px; height: 34px; font-size: 13px; }

/* Filtros avanzados */
.filtros { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 16px; align-items: end; }
.filtros > div { flex: 1; min-width: 140px; }
.filtros label { margin: 0 0 5px; }

/* Responsive DataTables: en móvil, tarjetas apiladas */
@media (max-width: 820px) {
  .dt-wrap table.dataTable thead { display: none; }
  .dt-wrap table.dataTable tbody td {
    display: flex; justify-content: space-between; align-items: center;
    padding: 8px 12px; border: none; text-align: right;
  }
  .dt-wrap table.dataTable tbody td:before {
    content: attr(data-label); font-weight: 600; color: var(--ink-soft);
    font-size: 12px; text-align: left; margin-right: 10px;
  }
  .dt-wrap table.dataTable tbody tr {
    display: block; margin-bottom: 12px; border: 1px solid var(--line);
    border-radius: var(--radius); padding: 6px; background: #fff;
  }
  .acc-btns { justify-content: flex-end; }
}

/* ============================================================
   TablaPro — tabla propia con búsqueda, orden, paginación
   ============================================================ */
.tabla-pro { width: 100%; }
.tp-top { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.tp-buscar {
  flex: 1; max-width: 320px; padding: 10px 14px; font-size: 14px;
  border: 1px solid var(--line); border-radius: var(--radius-sm); font-family: inherit;
}
.tp-buscar:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-50); }
.tp-count { font-size: 13px; color: var(--ink-soft); }
.tp-scroll { overflow-x: auto; }
.tp-table { width: 100%; border-collapse: collapse; }
.tp-table thead th {
  text-align: left; padding: 12px 10px; font-size: 12px; font-weight: 600;
  color: var(--ink-soft); border-bottom: 2px solid var(--line); white-space: nowrap;
}
.tp-table thead th.tp-sort { cursor: pointer; user-select: none; }
.tp-table thead th.tp-sort:hover { color: var(--brand); }
.tp-arrow { font-size: 10px; opacity: .6; }
.tp-table tbody td { padding: 11px 10px; border-bottom: 1px solid var(--line); font-size: 14px; vertical-align: middle; }
.tp-table tbody tr:hover { background: var(--brand-50); }
.tp-vacio { text-align: center; color: var(--ink-soft); padding: 30px !important; }
.tp-foot { display: flex; align-items: center; justify-content: space-between; margin-top: 14px; flex-wrap: wrap; gap: 10px; }
.tp-info { font-size: 13px; color: var(--ink-soft); }
.tp-pag { display: flex; gap: 4px; align-items: center; }
.tp-pbtn {
  min-width: 34px; height: 34px; padding: 0 10px; border-radius: 8px; cursor: pointer;
  border: 1px solid var(--line); background: #fff; color: var(--ink); font-size: 13px; font-family: inherit;
}
.tp-pbtn:hover:not([disabled]):not(.active) { background: var(--brand-50); border-color: var(--brand); }
.tp-pbtn.active { background: var(--brand); color: #fff; border-color: var(--brand); }
.tp-pbtn[disabled] { opacity: .4; cursor: default; }
.tp-dots { padding: 0 4px; color: var(--ink-soft); }

/* Celda con avatar */
.cell-persona { display: flex; align-items: center; gap: 10px; }
.acc-btns { display: flex; gap: 5px; flex-wrap: wrap; }

/* Responsive: tarjetas apiladas en móvil */
@media (max-width: 820px) {
  .tp-table thead { display: none; }
  .tp-table tbody tr {
    display: block; margin-bottom: 12px; border: 1px solid var(--line);
    border-radius: var(--radius); padding: 6px 10px; background: #fff;
  }
  .tp-table tbody td {
    display: flex; justify-content: space-between; align-items: center;
    padding: 8px 4px; border: none; text-align: right; gap: 12px;
  }
  .tp-table tbody td:before {
    content: attr(data-label); font-weight: 600; color: var(--ink-soft);
    font-size: 12px; text-align: left;
  }
  .tp-table tbody td:last-child { border-top: 1px solid var(--line); margin-top: 4px; padding-top: 10px; }
  .acc-btns { justify-content: flex-end; }
}

/* ============================================================
   Modal propio (reemplaza prompts feos)
   ============================================================ */
.modal-bg {
  position: fixed; inset: 0; background: rgba(30,36,56,.55);
  display: flex; align-items: center; justify-content: center; padding: 20px; z-index: 100;
}
.modal-bg.hidden { display: none !important; }
.modal-box {
  background: #fff; border-radius: 18px; box-shadow: var(--shadow-lg);
  width: 100%; max-width: 460px; max-height: 90vh; overflow-y: auto;
}
.modal-head { padding: 20px 22px 0; display: flex; align-items: center; justify-content: space-between; }
.modal-head h3 { font-size: 18px; font-weight: 700; }
.modal-x { background: none; border: none; font-size: 22px; cursor: pointer; color: var(--ink-soft); line-height: 1; }
.modal-body { padding: 16px 22px; }
.modal-foot { padding: 0 22px 22px; display: flex; gap: 10px; }
.modal-foot .btn { flex: 1; }

/* ============================================================
   Credencial escolar — gafete vertical
   ============================================================ */
.credencial {
  width: 280px; background: #fff; border-radius: 16px; overflow: hidden;
  box-shadow: 0 8px 30px -12px rgba(30,36,56,.3); border: 1px solid var(--line);
  display: flex; flex-direction: column; align-items: center;
  font-family: 'Inter', system-ui, sans-serif; page-break-inside: avoid;
}
.cred-head {
  width: 100%; background: var(--brand-grad); color: #fff;
  padding: 16px 12px 32px; text-align: center;
}
.cred-logo {
  width: 44px; height: 44px; border-radius: 11px; background: rgba(255,255,255,.18);
  display: flex; align-items: center; justify-content: center; font-size: 22px; margin: 0 auto 8px;
}
.cred-logo-img {
  width: 48px; height: 48px; border-radius: 11px; object-fit: contain;
  background: rgba(255,255,255,.95); padding: 4px; margin: 0 auto 8px; display: block;
}
.cred-escuela { font-size: 15px; font-weight: 700; line-height: 1.25; }
.cred-foto {
  width: 92px; height: 92px; border-radius: 50%; margin: -28px auto 0;
  border: 4px solid #fff; overflow: hidden; background: var(--brand);
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 6px 16px -6px rgba(0,0,0,.3); position: relative; z-index: 2;
}
.cred-foto img { width: 100%; height: 100%; object-fit: cover; }
.cred-ini { color: #fff; font-size: 38px; font-weight: 700; }
.cred-nombre { font-size: 18px; font-weight: 800; color: var(--ink); margin-top: 12px; text-align: center; padding: 0 14px; }
.cred-grupo {
  font-size: 13px; font-weight: 700; color: #fff; background: var(--brand);
  padding: 3px 14px; border-radius: 999px; margin-top: 6px;
}
.cred-qr { margin: 14px 0 10px; display: flex; justify-content: center; }
.cred-qr img, .cred-qr canvas { border-radius: 8px; }
.cred-datos { width: 100%; padding: 0 18px 4px; }
.cred-row { display: flex; justify-content: space-between; font-size: 12px; padding: 4px 0; border-top: 1px solid var(--line); }
.cred-row span { color: var(--ink-soft); }
.cred-row b { color: var(--ink); font-weight: 700; }
.cred-foot {
  width: 100%; background: #f8fafc; color: var(--ink-soft);
  font-size: 9px; text-align: center; padding: 8px; margin-top: 8px;
}
/* Rejilla para impresión masiva */
.cred-grid { display: grid; grid-template-columns: repeat(auto-fill, 280px); gap: 20px; justify-content: center; }




/* Layout de registro: formulario (ancho) + credencial (angosto) en una fila; tabla abajo */
.reg-grid { display: grid; grid-template-columns: 1.7fr 1fr; gap: 18px; align-items: stretch; margin-bottom: 18px; }
.reg-grid > .card { margin-bottom: 0; }
.reg-grid #estCredCard { display: flex; flex-direction: column; }
.reg-grid #estCredBox { flex: 1; align-items: center; }
@media (max-width: 900px) { .reg-grid { grid-template-columns: 1fr; } }

/* ============================================================
   Modal de confirmación profesional
   ============================================================ */
.confirm-box { max-width: 400px; text-align: center; padding: 28px 26px 22px; }
.confirm-ico {
  width: 56px; height: 56px; border-radius: 50%; margin: 0 auto 16px;
  display: flex; align-items: center; justify-content: center; font-size: 28px; font-weight: 700;
}
.confirm-ico.normal { background: var(--brand-50); color: var(--brand); }
.confirm-ico.peligro { background: var(--bad-bg); color: var(--bad); }
.confirm-box h3 { font-size: 19px; font-weight: 700; margin-bottom: 8px; }
.confirm-box p { font-size: 14px; color: var(--ink-soft); line-height: 1.55; margin-bottom: 22px; }
.confirm-btns { display: flex; gap: 10px; }
.confirm-btns .btn { flex: 1; }
.btn-danger-solid { background: var(--bad); color: #fff; }
.btn-danger-solid:hover { background: #b91c1c; }

/* Chips de días laborales */
.dia-chk { display:inline-flex; align-items:center; gap:5px; padding:7px 12px; border:1px solid var(--line);
  border-radius:9px; font-size:13px; font-weight:600; cursor:pointer; background:#fff; }
.dia-chk input { width:auto; margin:0; }
.dia-chk:has(input:checked) { background:var(--brand-50); border-color:var(--brand); color:var(--brand-700); }

/* Previews de activos de la escuela (logo, firma, sello) */
.activo-prev { width:100%; height:120px; border:1px dashed var(--line); border-radius:10px;
  display:flex; align-items:center; justify-content:center; margin-bottom:8px; background:#fafbfc; overflow:hidden; }
.activo-prev img { max-width:100%; max-height:100%; object-fit:contain; }
.activo-vacio { color:var(--ink-soft); font-size:13px; }

/* Impresión: la maneja imprimirCredencial() con ventana nueva.
   Este @media print es solo un respaldo mínimo. */
@media print {
  .modal-bg, .sidebar, .topbar, button { display: none !important; }
}
