:root {
  --cobaem-green-900: #1e3a8a;
  --cobaem-green-800: #1e40af;
  --cobaem-green-700: #1d4ed8;
  --cobaem-green-600: #2563eb;
  --cobaem-green-500: #3b82f6;
  --cobaem-green-100: #dbeafe;
  --cobaem-green-50: #eff6ff;
  --cobaem-gold: #0284c7;
  --cobaem-gold-light: #e0f2fe;
  --blue-600: #0284c7;
  --blue-100: #e0f2fe;
  --blue-50: #f0f9ff;
  --red-600: #dc2626;
  --red-100: #fee2e2;
  --slate-900: #0f172a;
  --slate-800: #1e293b;
  --slate-700: #334155;
  --slate-600: #475569;
  --slate-500: #64748b;
  --slate-300: #cbd5e1;
  --slate-200: #e2e8f0;
  --slate-100: #f1f5f9;
  --slate-50: #f8fafc;
  --radius-lg: 16px;
  --radius-md: 12px;
  --radius-sm: 8px;
  --shadow-sm: 0 1px 3px rgba(15, 23, 42, 0.08);
  --shadow-md: 0 4px 12px rgba(15, 23, 42, 0.1);
  --shadow-lg: 0 12px 28px rgba(15, 23, 42, 0.16);
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background-color: var(--slate-100);
  color: var(--slate-900);
  line-height: 1.45;
  padding-bottom: 84px;
  -webkit-font-smoothing: antialiased;
}

/* Header Institucional en Tonos Azules */
.app-header {
  background: linear-gradient(135deg, #0f172a 0%, #1e3a8a 50%, #1d4ed8 100%);
  color: #ffffff;
  padding: 14px 20px;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow-md);
}

.header-inner {
  max-width: 1240px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-logo {
  width: 44px;
  height: 44px;
  border-radius: 10px;
  background: rgba(59, 130, 246, 0.25);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 1.1rem;
  border: 2px solid rgba(147, 197, 253, 0.5);
  flex-shrink: 0;
}

.brand-title h1 {
  font-size: 1.15rem;
  font-weight: 800;
  letter-spacing: -0.01em;
}

.brand-title p {
  font-size: 0.8rem;
  opacity: 0.9;
}

.header-meta {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.clock-pill {
  background: rgba(0, 0, 0, 0.28);
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 6px;
}

.sync-badge {
  font-size: 0.75rem;
  padding: 5px 10px;
  border-radius: 999px;
  font-weight: 600;
  background: rgba(255, 255, 255, 0.18);
  cursor: pointer;
}

.sync-badge.online {
  background: #38bdf8;
  color: #082f49;
}

/* Botón de Administrador en el Header */
.admin-pill {
  background: rgba(255, 255, 255, 0.16);
  color: #ffffff;
  border: 1.5px solid rgba(255, 255, 255, 0.35);
  padding: 6px 13px;
  border-radius: 999px;
  font-size: 0.82rem;
  font-weight: 700;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: all 0.2s;
}

.admin-pill:hover {
  background: rgba(255, 255, 255, 0.28);
}

.admin-pill.active-admin {
  background: #22c55e;
  color: #052e16;
  border-color: #86efac;
  box-shadow: 0 0 12px rgba(34, 197, 94, 0.45);
}

.tab-lock-icon {
  font-size: 0.78rem;
  opacity: 0.75;
}

/* Navegación Principal */
.nav-tabs {
  background: #ffffff;
  border-bottom: 1px solid var(--slate-200);
  position: sticky;
  top: 72px;
  z-index: 90;
}

.nav-tabs-inner {
  max-width: 1240px;
  margin: 0 auto;
  display: flex;
  overflow-x: auto;
}

.nav-tab {
  flex: 1;
  min-width: 135px;
  padding: 13px 14px;
  border: none;
  background: transparent;
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--slate-600);
  cursor: pointer;
  border-bottom: 3px solid transparent;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  white-space: nowrap;
}

.nav-tab:hover {
  color: var(--cobaem-green-700);
  background: var(--slate-50);
}

.nav-tab.active {
  color: var(--cobaem-green-800);
  border-bottom-color: var(--cobaem-green-600);
  background: var(--cobaem-green-50);
}

/* Contenedor principal */
.main-container {
  max-width: 1240px;
  margin: 20px auto;
  padding: 0 16px;
}

.tab-panel {
  display: none;
}

.tab-panel.active {
  display: block;
}

/* Tarjetas y contenedores */
.card {
  background: #ffffff;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--slate-200);
  padding: 20px;
  margin-bottom: 20px;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.card-title {
  font-size: 1.1rem;
  font-weight: 800;
  color: var(--slate-800);
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Layout de Escáner */
.scanner-grid {
  display: grid;
  grid-template-columns: 1.1fr 0.9fr;
  gap: 20px;
}

@media (max-width: 900px) {
  .scanner-grid {
    grid-template-columns: 1fr;
  }
}

/* Selector de Modo (Automático / Entrada / Salida) */
.mode-selector {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  background: var(--slate-100);
  padding: 6px;
  border-radius: var(--radius-md);
  margin-bottom: 16px;
}

.mode-btn {
  padding: 10px 8px;
  border: 2px solid transparent;
  border-radius: var(--radius-sm);
  background: transparent;
  font-weight: 700;
  font-size: 0.85rem;
  color: var(--slate-600);
  cursor: pointer;
  transition: all 0.15s;
  text-align: center;
}

.mode-btn.active[data-mode="AUTO"] {
  background: #ffffff;
  color: #1e40af;
  border-color: #2563eb;
  box-shadow: var(--shadow-sm);
}

.mode-btn.active[data-mode="ENTRADA"] {
  background: #2563eb;
  color: #ffffff;
  box-shadow: var(--shadow-sm);
}

.mode-btn.active[data-mode="SALIDA"] {
  background: #0284c7;
  color: #ffffff;
  box-shadow: var(--shadow-sm);
}

/* Visor de Cámara */
.camera-box {
  position: relative;
  width: 100%;
  max-width: 480px;
  margin: 0 auto 16px;
  aspect-ratio: 4 / 3;
  background: #0f172a;
  border-radius: var(--radius-lg);
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 3px solid var(--slate-300);
}

.camera-box.scanning {
  border-color: #3b82f6;
}

#scannerVideo {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: none;
}

#html5QrReader {
  width: 100%;
}

.scan-overlay {
  position: absolute;
  inset: 0;
  pointer-events: none;
  display: flex;
  align-items: center;
  justify-content: center;
}

.scan-frame {
  width: 210px;
  height: 210px;
  border: 3px solid rgba(59, 130, 246, 0.95);
  border-radius: 20px;
  box-shadow: 0 0 0 9999px rgba(15, 23, 42, 0.38);
  position: relative;
}

.scan-line {
  position: absolute;
  left: 10px;
  right: 10px;
  height: 3px;
  background: #38bdf8;
  box-shadow: 0 0 12px #38bdf8;
  animation: scanMove 2.2s infinite ease-in-out;
}

@keyframes scanMove {
  0%, 100% { top: 14px; }
  50% { top: calc(100% - 17px); }
}

.camera-placeholder {
  color: #ffffff;
  text-align: center;
  padding: 24px;
}

.camera-placeholder p {
  font-size: 0.9rem;
  opacity: 0.85;
  margin-top: 8px;
}

.camera-controls {
  display: flex;
  gap: 10px;
  justify-content: center;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

/* Botones Generales */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  font-weight: 700;
  font-size: 0.9rem;
  border: none;
  cursor: pointer;
  transition: all 0.15s;
  text-decoration: none;
}

.btn-primary {
  background: #1d4ed8;
  color: #ffffff;
}
.btn-primary:hover {
  background: #1e40af;
}

.btn-secondary {
  background: var(--slate-200);
  color: var(--slate-800);
}
.btn-secondary:hover {
  background: var(--slate-300);
}

.btn-blue {
  background: #0284c7;
  color: #ffffff;
}
.btn-blue:hover {
  background: #0369a1;
}

.btn-danger {
  background: var(--red-100);
  color: var(--red-600);
}
.btn-danger:hover {
  background: #fecaca;
}

.btn-sm {
  padding: 6px 11px;
  font-size: 0.8rem;
}

.btn-lg {
  padding: 13px 22px;
  font-size: 1rem;
}

/* Resultado de Escaneo (Confirmación Visual en Tonos Azules) */
.scan-result-banner {
  border-radius: var(--radius-lg);
  padding: 20px;
  margin-bottom: 18px;
  border: 2px solid var(--slate-200);
  background: var(--slate-50);
  transition: all 0.25s;
}

.scan-result-banner.entrada {
  background: #eff6ff;
  border-color: #2563eb;
  box-shadow: 0 8px 24px rgba(37, 99, 235, 0.22);
}

.scan-result-banner.salida {
  background: #f0f9ff;
  border-color: #0284c7;
  box-shadow: 0 8px 24px rgba(2, 132, 199, 0.22);
}

.scan-result-banner.warn {
  background: #fffbeb;
  border-color: #f59e0b;
}

.scan-result-banner.error {
  background: #fef2f2;
  border-color: #ef4444;
}

.result-badge {
  display: inline-block;
  padding: 5px 14px;
  border-radius: 999px;
  font-weight: 800;
  font-size: 0.85rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  margin-bottom: 8px;
}

.entrada .result-badge {
  background: #1d4ed8;
  color: #ffffff;
}

.salida .result-badge {
  background: #0284c7;
  color: #ffffff;
}

.warn .result-badge {
  background: #d97706;
  color: #ffffff;
}

.error .result-badge {
  background: #dc2626;
  color: #ffffff;
}

.result-student-name {
  font-size: 1.35rem;
  font-weight: 900;
  color: var(--slate-900);
  margin-bottom: 6px;
}

.result-details {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  font-size: 0.92rem;
  color: var(--slate-700);
  font-weight: 600;
}

/* Buscador Manual con Autocompletado */
.manual-search-wrap {
  position: relative;
}

.input-field, .select-field {
  width: 100%;
  padding: 11px 14px;
  border: 1.5px solid var(--slate-300);
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
  color: var(--slate-900);
  background: #ffffff;
  transition: border-color 0.15s;
}

.input-field:focus, .select-field:focus {
  outline: none;
  border-color: #2563eb;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

.autocomplete-list {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: #ffffff;
  border: 1px solid var(--slate-300);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg);
  max-height: 260px;
  overflow-y: auto;
  z-index: 50;
  margin-top: 4px;
  display: none;
}

.autocomplete-item {
  padding: 10px 14px;
  border-bottom: 1px solid var(--slate-100);
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

.autocomplete-item:hover {
  background: #eff6ff;
}

/* Tarjetas KPI Estadísticas */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 14px;
  margin-bottom: 20px;
}

.kpi-card {
  background: #ffffff;
  border-radius: var(--radius-md);
  padding: 16px;
  border: 1px solid var(--slate-200);
  box-shadow: var(--shadow-sm);
}

.kpi-label {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--slate-500);
  text-transform: uppercase;
}

.kpi-value {
  font-size: 1.9rem;
  font-weight: 900;
  margin-top: 4px;
  color: var(--slate-900);
}

.kpi-sub {
  font-size: 0.78rem;
  color: var(--slate-500);
  margin-top: 2px;
}

/* Resumen por Grupos */
.groups-summary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(165px, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}

.group-chip-card {
  background: var(--slate-50);
  border: 1px solid var(--slate-200);
  border-radius: var(--radius-sm);
  padding: 12px;
  cursor: pointer;
  transition: all 0.15s;
}

.group-chip-card:hover {
  border-color: #2563eb;
  background: #eff6ff;
}

.group-chip-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-weight: 800;
  font-size: 0.95rem;
  margin-bottom: 6px;
}

.progress-bar {
  height: 7px;
  background: var(--slate-200);
  border-radius: 999px;
  overflow: hidden;
  margin-bottom: 6px;
}

.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, #1d4ed8, #38bdf8);
  border-radius: 999px;
}

/* Tablas */
.table-responsive {
  overflow-x: auto;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
}

.data-table th, .data-table td {
  padding: 10px 12px;
  text-align: left;
  border-bottom: 1px solid var(--slate-200);
}

.data-table th {
  background: var(--slate-50);
  font-weight: 800;
  color: var(--slate-600);
  text-transform: uppercase;
  font-size: 0.76rem;
  letter-spacing: 0.03em;
}

.data-table tr:hover td {
  background: var(--slate-50);
}

/* Pills de estado en tonos azules */
.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 0.76rem;
  font-weight: 800;
}

.status-pill.dentro {
  background: #dbeafe;
  color: #1e40af;
}

.status-pill.salio {
  background: #e0f2fe;
  color: #0369a1;
}

.status-pill.falta {
  background: var(--slate-200);
  color: var(--slate-600);
}

/* Grid de Credenciales / Gafetes QR */
.filters-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
  margin-bottom: 18px;
}

.badges-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 18px;
}

.id-badge-card {
  background: #ffffff;
  border: 2px solid #1e3a8a;
  border-radius: 14px;
  overflow: hidden;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.id-badge-top {
  background: linear-gradient(135deg, #0f172a, #1e3a8a, #1d4ed8);
  color: #ffffff;
  padding: 10px 12px;
  text-align: center;
  border-bottom: 3px solid #38bdf8;
}

.id-badge-top h4 {
  font-size: 0.82rem;
  font-weight: 900;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}

.id-badge-top p {
  font-size: 0.7rem;
  opacity: 0.92;
}

.id-badge-body {
  padding: 14px 12px;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.id-badge-qr {
  background: #ffffff;
  padding: 6px;
  border: 1px solid var(--slate-200);
  border-radius: 10px;
  display: inline-block;
}

.id-badge-name {
  font-size: 0.92rem;
  font-weight: 800;
  color: var(--slate-900);
  line-height: 1.25;
  min-height: 2.4em;
  display: flex;
  align-items: center;
  justify-content: center;
}

.id-badge-meta {
  width: 100%;
  display: flex;
  justify-content: space-around;
  background: #eff6ff;
  padding: 6px 8px;
  border-radius: 8px;
  font-size: 0.78rem;
  border: 1px solid #bfdbfe;
}

.id-badge-actions {
  padding: 10px 12px;
  background: var(--slate-50);
  border-top: 1px solid var(--slate-200);
  display: flex;
  gap: 8px;
  justify-content: center;
}

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.65);
  z-index: 200;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.modal-backdrop.open {
  display: flex;
}

.modal-content {
  background: #ffffff;
  border-radius: var(--radius-lg);
  max-width: 480px;
  width: 100%;
  padding: 24px;
  box-shadow: var(--shadow-lg);
  text-align: center;
}

.admin-modal-box {
  max-width: 420px;
}

.admin-modal-header {
  margin-bottom: 18px;
}

.admin-lock-badge {
  width: 56px;
  height: 56px;
  border-radius: 16px;
  background: #eff6ff;
  border: 2px solid #bfdbfe;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1.65rem;
  margin-bottom: 10px;
}

.admin-modal-header h3 {
  font-size: 1.2rem;
  font-weight: 800;
  color: var(--slate-900);
  margin-bottom: 6px;
}

.admin-modal-header p {
  font-size: 0.85rem;
  color: var(--slate-600);
}

.password-input-wrap {
  position: relative;
  display: flex;
  align-items: center;
}

.password-input-wrap .input-field {
  padding-right: 44px;
}

.btn-eye {
  position: absolute;
  right: 8px;
  background: transparent;
  border: none;
  font-size: 1.1rem;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 6px;
  color: var(--slate-600);
}

.btn-eye:hover {
  background: var(--slate-100);
}

.admin-login-error {
  background: #fef2f2;
  border: 1px solid #fecaca;
  color: #dc2626;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  font-size: 0.84rem;
  font-weight: 600;
  text-align: left;
}

/* ==================== PORTAL DE PADRES DE FAMILIA ==================== */
.parent-login-card {
  max-width: 560px;
  margin: 10px auto 24px;
  border-top: 5px solid #1d4ed8;
}

.parent-hero-header {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 20px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--slate-200);
}

.parent-hero-icon {
  width: 56px;
  height: 56px;
  border-radius: 14px;
  background: #eff6ff;
  border: 2px solid #bfdbfe;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.8rem;
  flex-shrink: 0;
}

.parent-hero-header h2 {
  font-size: 1.2rem;
  font-weight: 900;
  color: var(--slate-900);
}

.parent-hero-header p {
  font-size: 0.83rem;
  color: var(--slate-600);
  margin-top: 2px;
}

.parent-form-grid {
  display: flex;
  flex-direction: column;
  gap: 15px;
}

.parent-student-header-card {
  border-left: 5px solid #1d4ed8;
}

.parent-times-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 14px;
  margin-top: 16px;
}

.parent-time-box {
  background: rgba(255, 255, 255, 0.85);
  border: 1.5px solid var(--slate-200);
  border-radius: var(--radius-md);
  padding: 14px 16px;
}

.parent-time-label {
  font-size: 0.76rem;
  font-weight: 800;
  color: var(--slate-600);
  letter-spacing: 0.03em;
}

.parent-time-value {
  font-size: 1.75rem;
  font-weight: 900;
  color: var(--slate-900);
  margin-top: 4px;
  font-variant-numeric: tabular-nums;
}

/* Modo Público (Solo Portal Padres — sin acceso a pestañas administrativas ni escáner) */
body.public-parent-mode .nav-tabs,
body.public-parent-mode .admin-only,
body.public-parent-mode .tab-panel:not(#panel-padres) {
  display: none !important;
}

body.public-parent-mode #panel-padres {
  display: block !important;
}

/* Formato de Impresión para Hojas de Credenciales QR */
@media print {
  body {
    background: #ffffff;
    padding: 0;
  }
  .app-header,
  .nav-tabs,
  .no-print,
  .id-badge-actions {
    display: none !important;
  }
  .main-container {
    max-width: 100%;
    margin: 0;
    padding: 0;
  }
  .card {
    border: none;
    box-shadow: none;
    padding: 0;
    margin: 0;
  }
  .badges-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
  }
  .id-badge-card {
    break-inside: avoid;
    page-break-inside: avoid;
    border: 1.5px solid #1e3a8a;
  }
}
