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

:root {
  --blue-50: #F0F4FA;
  --blue-100: #D6E2F5;
  --blue-200: #A8C4E8;
  --blue-400: #5B8FD0;
  --blue-500: #4A7FC7;
  --blue-600: #3D6BA8;
  --orange-50: #FFF5EE;
  --orange-100: #FFE4CC;
  --orange-400: #FFA05C;
  --orange-500: #F08C4A;
  --neutral-50: #FAFAFA;
  --neutral-100: #F5F5F5;
  --neutral-200: #EEEEEE;
  --neutral-300: #E0E0E0;
  --neutral-400: #BDBDBD;
  --neutral-500: #9E9E9E;
  --neutral-600: #757575;
  --neutral-700: #616161;
  --neutral-800: #424242;
  --neutral-900: #212121;
  --success: #66BB6A;
  --success-bg: #E8F5E9;
  --error: #EF5350;
  --error-bg: #FFEBEE;
  --background: #F8F9FC;
  --surface: #FFFFFF;
  --radius: 14px;
  --radius-lg: 18px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'Segoe UI', Roboto, sans-serif;
  background: var(--background);
  color: var(--neutral-900);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* Transiciones suaves entre páginas
   ----------------------------------------------------------------
   Usamos la View Transitions API: al navegar, los navegadores
   compatibles (Chrome/Edge y Safari recientes) hacen un fundido entre
   la página saliente y la entrante. El menú lateral (root) hace un
   cross-fade entre contenidos idénticos, por lo que se percibe fijo;
   solo el contenido principal (page-main) se desliza suavemente. */
@view-transition {
  navigation: auto;
}

::view-transition-old(root),
::view-transition-new(root) {
  animation-duration: 0.32s;
  animation-timing-function: ease;
}

::view-transition-old(page-main) {
  animation: pageFadeOut 0.22s ease both;
}

::view-transition-new(page-main) {
  animation: pageFadeIn 0.34s ease both;
}

@keyframes pageFadeIn {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0); }
}

@keyframes pageFadeOut {
  from { opacity: 1; transform: translateY(0); }
  to   { opacity: 0; transform: translateY(-6px); }
}

/* Fallback para navegadores sin View Transitions: el contenido
   principal aparece con un fundido suave en cada carga de página. */
@supports not (view-transition-name: none) {
  .main {
    animation: pageFadeIn 0.34s ease both;
  }
}

/* Accesibilidad: sin animaciones si el usuario lo prefiere. */
@media (prefers-reduced-motion: reduce) {
  ::view-transition-old(root),
  ::view-transition-new(root),
  ::view-transition-old(page-main),
  ::view-transition-new(page-main),
  .main {
    animation: none !important;
  }
}

/* Sidebar */
.layout {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: 260px;
  background: var(--surface);
  border-right: 1px solid var(--neutral-200);
  padding: 28px 0;
  position: fixed;
  height: 100vh;
  display: flex;
  flex-direction: column;
}

.sidebar-logo {
  padding: 0 24px 28px;
  border-bottom: 1px solid var(--neutral-100);
  margin-bottom: 16px;
}

.sidebar-logo-img {
  display: block;
  width: 120px;
  height: auto;
  margin-bottom: 6px;
}

.sidebar-logo span {
  display: block;
  font-size: 12px;
  color: var(--neutral-500);
  font-weight: 400;
}

.sidebar-nav {
  flex: 1;
  padding: 0 12px;
}

.nav-item {
  position: relative;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 16px;
  border-radius: 10px;
  color: var(--neutral-600);
  text-decoration: none;
  font-size: 14px;
  font-weight: 500;
  transition: all 0.15s ease;
  cursor: pointer;
  margin-bottom: 2px;
}

.nav-item:hover {
  background: var(--neutral-50);
  color: var(--neutral-900);
}

.nav-item.active {
  background: var(--blue-50);
  color: var(--blue-600);
  font-weight: 600;
}

/* Barra de acento a la izquierda del enlace activo */
.nav-item.active::before {
  content: '';
  position: absolute;
  left: -12px;
  top: 50%;
  transform: translateY(-50%);
  width: 4px;
  height: 24px;
  border-radius: 0 4px 4px 0;
  background: var(--blue-500);
}

.nav-item svg {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
}

/* Acciones del pie (Ayuda / Cerrar sesión): se ven como nav-item pero son
   botones, así que reseteamos los estilos por defecto del <button>. */
.nav-action {
  width: 100%;
  background: none;
  border: none;
  font-family: inherit;
  text-align: left;
}

.nav-action-danger:hover {
  background: var(--error-bg);
  color: var(--error);
}

.sidebar-footer {
  padding: 16px 12px 8px;
  border-top: 1px solid var(--neutral-100);
}

.db-status {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--neutral-500);
  padding: 4px 16px 12px;
}

.sidebar-actions {
  display: flex;
  flex-direction: column;
}

.db-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--success);
}

.db-dot.disconnected {
  background: var(--error);
}

/* Main Content */
.main {
  flex: 1;
  margin-left: 260px;
  padding: 32px 40px;
  max-width: 1200px;
  /* Nombre propio para la View Transition: hace que solo el contenido
     principal se anime y el menú lateral quede fijo entre páginas. */
  view-transition-name: page-main;
}

.page-header {
  margin-bottom: 28px;
}

.page-header h2 {
  font-size: 26px;
  font-weight: 700;
  color: var(--neutral-900);
  letter-spacing: -0.4px;
}

.page-header p {
  font-size: 14px;
  color: var(--neutral-500);
  margin-top: 4px;
}

.page-header-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
}

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

.last-refresh {
  font-size: 12px;
  color: var(--neutral-400);
  white-space: nowrap;
}

.btn-refresh .refresh-icon {
  transition: transform 0.4s ease;
}

.btn-refresh.spinning .refresh-icon {
  animation: spin 0.5s linear;
}

/* Stat Cards */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-bottom: 28px;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--neutral-200);
  border-radius: var(--radius);
  padding: 20px;
  transition: border-color 0.15s;
}

.stat-card:hover {
  border-color: var(--neutral-300);
}

.stat-label {
  font-size: 12px;
  color: var(--neutral-500);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-weight: 600;
  margin-bottom: 8px;
}

.stat-value {
  font-size: 28px;
  font-weight: 700;
  color: var(--neutral-900);
  letter-spacing: -0.5px;
}

.stat-card.blue .stat-value { color: var(--blue-500); }
.stat-card.orange .stat-value { color: var(--orange-500); }

/* Toolbar */
.toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}

.search-box {
  flex: 1;
  min-width: 240px;
  position: relative;
}

.search-box svg {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  width: 18px;
  height: 18px;
  color: var(--neutral-400);
}

.search-box input {
  width: 100%;
  padding: 10px 14px 10px 40px;
  border: 1px solid var(--neutral-200);
  border-radius: 10px;
  font-size: 14px;
  background: var(--surface);
  color: var(--neutral-900);
  outline: none;
  transition: border-color 0.15s;
}

.search-box input:focus {
  border-color: var(--blue-400);
}

.search-box input::placeholder {
  color: var(--neutral-400);
}

.date-input {
  padding: 10px 14px;
  border: 1px solid var(--neutral-200);
  border-radius: 10px;
  font-size: 13px;
  background: var(--surface);
  color: var(--neutral-700);
  outline: none;
  cursor: pointer;
  transition: border-color 0.15s;
}

.date-input:focus {
  border-color: var(--blue-400);
}

.btn {
  padding: 10px 20px;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 600;
  border: none;
  cursor: pointer;
  transition: all 0.15s;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.btn-primary {
  background: var(--blue-500);
  color: white;
}

.btn-primary:hover {
  background: var(--blue-600);
}

.btn-ghost {
  background: transparent;
  color: var(--neutral-600);
  border: 1px solid var(--neutral-200);
}

.btn-ghost:hover {
  background: var(--neutral-50);
}

/* Table */
.table-container {
  background: var(--surface);
  border: 1px solid var(--neutral-200);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

table {
  width: 100%;
  border-collapse: collapse;
}

thead th {
  text-align: left;
  padding: 14px 20px;
  font-size: 12px;
  font-weight: 600;
  color: var(--neutral-500);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  background: var(--neutral-50);
  border-bottom: 1px solid var(--neutral-200);
}

tbody td {
  padding: 14px 20px;
  font-size: 14px;
  color: var(--neutral-800);
  border-bottom: 1px solid var(--neutral-100);
}

tbody tr:last-child td {
  border-bottom: none;
}

tbody tr:hover {
  background: var(--neutral-50);
}

.tag-id {
  font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
  font-size: 13px;
  font-weight: 600;
  color: var(--blue-600);
}

.tech-badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 6px;
  font-size: 11px;
  font-weight: 600;
  background: var(--blue-50);
  color: var(--blue-600);
}

.payload-text {
  font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
  font-size: 12px;
  color: var(--neutral-600);
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.timestamp {
  font-size: 13px;
  color: var(--neutral-500);
  white-space: nowrap;
}

/* Usuario asociado a la lectura NFC (resuelto por tagId) */
.record-user {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.record-user-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--neutral-800);
}

.record-user-grade {
  font-size: 12px;
  color: var(--neutral-500);
}

.record-user-none {
  font-size: 13px;
  color: var(--neutral-400);
  font-style: italic;
}

.record-user-unassigned {
  display: flex;
  align-items: center;
  gap: 10px;
}

.btn-assign {
  padding: 4px 12px;
  border: 1px solid var(--blue-200, #BBDEFB);
  border-radius: 8px;
  background: var(--blue-50, #E3F2FD);
  color: var(--blue-600);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}

.btn-assign:hover {
  background: var(--blue-100, #BBDEFB);
}

/* Pagination */
.pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-top: 1px solid var(--neutral-100);
  background: var(--neutral-50);
}

.pagination-info {
  font-size: 13px;
  color: var(--neutral-500);
}

.pagination-buttons {
  display: flex;
  gap: 6px;
}

.page-btn {
  padding: 6px 12px;
  border: 1px solid var(--neutral-200);
  border-radius: 8px;
  background: var(--surface);
  font-size: 13px;
  color: var(--neutral-700);
  cursor: pointer;
  transition: all 0.15s;
}

.page-btn:hover:not(:disabled) {
  background: var(--neutral-50);
  border-color: var(--neutral-300);
}

.page-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.page-btn.active {
  background: var(--blue-500);
  color: white;
  border-color: var(--blue-500);
}

/* Empty State */
.empty-state {
  text-align: center;
  padding: 60px 20px;
}

.empty-state svg {
  width: 64px;
  height: 64px;
  color: var(--neutral-300);
  margin-bottom: 16px;
}

.empty-state h3 {
  font-size: 16px;
  color: var(--neutral-600);
  margin-bottom: 4px;
}

.empty-state p {
  font-size: 14px;
  color: var(--neutral-400);
}

/* Loading */
.loading {
  text-align: center;
  padding: 40px;
  color: var(--neutral-500);
  font-size: 14px;
}

.spinner {
  display: inline-block;
  width: 24px;
  height: 24px;
  border: 3px solid var(--neutral-200);
  border-top-color: var(--blue-500);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
  margin-bottom: 8px;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* Estudiantes: grupos por aula / seccion */
.aula-group {
  margin-bottom: 32px;
}

.aula-header {
  display: flex;
  align-items: baseline;
  gap: 12px;
  margin-bottom: 14px;
}

.aula-header h3 {
  font-size: 18px;
  font-weight: 700;
  color: var(--neutral-900);
  letter-spacing: -0.3px;
}

.aula-count {
  font-size: 13px;
  color: var(--neutral-500);
}

.section-block {
  margin-bottom: 18px;
}

.section-title {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
}

.section-badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 6px;
  font-size: 11px;
  font-weight: 600;
  background: var(--orange-50);
  color: var(--orange-500);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.section-count {
  font-size: 12px;
  color: var(--neutral-400);
  font-weight: 600;
}

.student-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 12px;
}

.student-card {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--surface);
  border: 1px solid var(--neutral-200);
  border-radius: var(--radius);
  padding: 12px 14px;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.student-card:hover {
  border-color: var(--blue-200);
  box-shadow: 0 2px 8px rgba(0,0,0,0.04);
}

.student-info {
  min-width: 0;
  flex: 1;
}

/* Botón de editar dentro de la tarjeta de estudiante. Discreto por defecto,
   se resalta al pasar el cursor por la tarjeta. */
.student-edit {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--neutral-400);
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.15s, background 0.15s, color 0.15s;
}

.student-card:hover .student-edit {
  opacity: 1;
}

.student-edit:hover {
  background: var(--blue-50);
  color: var(--blue-600);
}

.student-edit svg {
  width: 16px;
  height: 16px;
}

.student-name {
  font-size: 14px;
  font-weight: 600;
  color: var(--neutral-900);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.student-tag {
  margin-top: 2px;
}

/* Avatar */
.avatar {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  flex-shrink: 0;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--blue-50);
  color: var(--blue-400);
}

.avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.avatar svg {
  width: 26px;
  height: 26px;
}

.avatar-initials {
  background: var(--blue-100);
  color: var(--blue-600);
  font-size: 15px;
  font-weight: 700;
}

.avatar-lg {
  width: 88px;
  height: 88px;
}

.avatar-lg svg {
  width: 44px;
  height: 44px;
}

/* Modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(33, 33, 33, 0.45);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 100;
}

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

/* El modal de confirmación se apila por encima del modal de asignar. */
.modal-overlay-top {
  z-index: 110;
}

.modal-sm {
  max-width: 400px;
}

.confirm-message {
  font-size: 14px;
  line-height: 1.5;
  color: var(--neutral-700);
  margin: 0 0 20px;
}

.modal {
  background: var(--surface);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 440px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0,0,0,0.2);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px;
  border-bottom: 1px solid var(--neutral-100);
}

.modal-header h3 {
  font-size: 18px;
  font-weight: 700;
  color: var(--neutral-900);
}

.modal-close {
  background: none;
  border: none;
  font-size: 26px;
  line-height: 1;
  color: var(--neutral-400);
  cursor: pointer;
  padding: 0 4px;
}

.modal-close:hover {
  color: var(--neutral-700);
}

.modal-body {
  padding: 24px;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 24px;
}

/* Form */
.form-field {
  margin-bottom: 16px;
}

.form-field label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--neutral-700);
  margin-bottom: 6px;
}

.form-field input,
.form-field select {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--neutral-200);
  border-radius: 10px;
  font-size: 14px;
  background: var(--surface);
  color: var(--neutral-900);
  outline: none;
  transition: border-color 0.15s;
}

.form-field input:focus,
.form-field select:focus {
  border-color: var(--blue-400);
  box-shadow: 0 0 0 3px var(--blue-50);
}

/* Inputs deshabilitados (ej. Tag ID sin el check marcado). */
.form-field input:disabled {
  background: var(--neutral-100);
  color: var(--neutral-400);
  cursor: not-allowed;
}

/* Select con estilo propio: quita la apariencia nativa del navegador y
   dibuja una flecha (chevron) acorde a la línea gráfica del proyecto. */
.form-field select {
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
  padding-right: 38px;
  cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%233D6BA8' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
}

.form-field select:hover {
  border-color: var(--blue-200);
}

/* Casilla "Asignar Tag ID ahora": etiqueta + checkbox en línea. */
.check-option {
  display: flex !important;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  font-weight: 600;
  color: var(--neutral-700);
  cursor: pointer;
  user-select: none;
  margin-bottom: 8px !important;
}

.check-option input[type="checkbox"] {
  width: 17px;
  height: 17px;
  margin: 0;
  accent-color: var(--blue-500);
  cursor: pointer;
}

.form-row {
  display: flex;
  gap: 12px;
}

.form-row .form-field {
  flex: 1;
}

.form-field-sm {
  flex: 0 0 90px !important;
}

.field-hint {
  font-size: 12px;
  color: var(--neutral-400);
  margin-top: 6px;
}

/* Select personalizado (dropdown con la línea gráfica del proyecto) */
.custom-select {
  position: relative;
}

.custom-select-trigger {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--neutral-200);
  border-radius: 10px;
  background: var(--surface);
  color: var(--neutral-900);
  font-size: 14px;
  text-align: left;
  cursor: pointer;
  transition: border-color 0.15s;
}

.custom-select-trigger:hover {
  border-color: var(--neutral-300);
}

.custom-select.open .custom-select-trigger {
  border-color: var(--blue-400);
}

.custom-select-value {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.custom-select-value.placeholder {
  color: var(--neutral-400);
}

.custom-select-arrow {
  flex-shrink: 0;
  color: var(--neutral-500);
  transition: transform 0.15s;
}

.custom-select.open .custom-select-arrow {
  transform: rotate(180deg);
}

.custom-select-panel {
  list-style: none;
  margin: 6px 0 0;
  padding: 6px;
  max-height: 240px;
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--neutral-200);
  border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.08);
}

.custom-select-option {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 14px;
  color: var(--neutral-800);
  cursor: pointer;
  transition: background 0.12s, color 0.12s;
}

.custom-select-option + .custom-select-option {
  margin-top: 2px;
}

.custom-select-option:hover {
  background: var(--blue-50);
}

.custom-select-option.selected {
  background: var(--blue-500);
  color: #fff;
}

.custom-select-option .opt-text {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.opt-sub {
  color: var(--neutral-500);
  font-weight: 400;
}

.opt-badge {
  flex-shrink: 0;
  font-size: 11px;
  font-weight: 600;
  color: var(--orange-500);
  background: var(--orange-50);
  padding: 2px 8px;
  border-radius: 999px;
}

.custom-select-option.selected .opt-sub {
  color: rgba(255, 255, 255, 0.85);
}

.custom-select-option.selected .opt-badge {
  color: #fff;
  background: rgba(255, 255, 255, 0.22);
}

/* Bloque de motivo de sustitución dentro del modal de asignación */
.replace-reason {
  background: var(--neutral-50);
  border: 1px solid var(--neutral-200);
  border-radius: 10px;
  padding: 12px 14px;
}

.radio-option {
  display: flex !important;
  align-items: center;
  gap: 10px;
  font-size: 14px;
  font-weight: 500;
  color: var(--neutral-800);
  margin-bottom: 0;
  margin-top: 8px;
  cursor: pointer;
}

.radio-option input[type="radio"] {
  width: auto;
  margin: 0;
  accent-color: var(--blue-500);
  cursor: pointer;
}

.photo-field {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 20px;
}

.photo-actions {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
}

.btn-sm {
  padding: 7px 14px;
  font-size: 12px;
}

.btn-link {
  background: none;
  border: none;
  color: var(--error);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  padding: 0;
}

.form-error {
  background: var(--error-bg);
  color: var(--error);
  font-size: 13px;
  padding: 10px 12px;
  border-radius: 10px;
  margin-bottom: 16px;
}

/* Acordeón de hijos en la tabla de padres */
.cell-parent {
  display: flex;
  align-items: center;
  gap: 8px;
}

.row-chevron {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  flex-shrink: 0;
  padding: 0;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--neutral-500);
  cursor: pointer;
}

.row-chevron:hover {
  background: var(--neutral-100);
  color: var(--neutral-900);
}

.row-chevron svg {
  width: 18px;
  height: 18px;
  transition: transform 0.15s ease;
}

.row-chevron.open svg {
  transform: rotate(90deg);
}

/* Hueco para alinear los padres sin hijos con los que sí tienen chevron */
.row-chevron-spacer {
  display: inline-block;
  width: 22px;
  flex-shrink: 0;
}

/* Filas de hijos anidadas (acordeón) */
.child-row > td {
  background: var(--neutral-50);
}

.cell-child {
  display: flex;
  align-items: center;
  gap: 10px;
  padding-left: 30px;
}

.child-arrow {
  color: var(--neutral-400);
  font-size: 16px;
  line-height: 1;
}

.grade-tag {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 6px;
  background: var(--neutral-100);
  color: var(--neutral-700);
  font-size: 12px;
  font-weight: 600;
}

td .muted {
  color: var(--neutral-400);
  font-size: 13px;
}

/* Lista de estudiantes vinculados en el modal de editar padre */
.linked-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.linked-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  border: 1px solid var(--neutral-200);
  border-radius: 10px;
  font-size: 14px;
  color: var(--neutral-900);
}

/* Placeholder de módulos en construcción */
.placeholder-card {
  background: var(--surface);
  border: 1px dashed var(--neutral-300);
  border-radius: var(--radius-lg);
  padding: 64px 24px;
  text-align: center;
}

.placeholder-card svg {
  width: 56px;
  height: 56px;
  color: var(--blue-200);
  margin-bottom: 16px;
}

.placeholder-card h3 {
  font-size: 18px;
  font-weight: 700;
  color: var(--neutral-700);
  margin-bottom: 4px;
}

.placeholder-card p {
  font-size: 14px;
  color: var(--neutral-500);
}

/* Vista de Usuarios: KPIs de 3 columnas */
.stats-grid-3 {
  grid-template-columns: repeat(3, 1fr);
}

/* Panel con pestañas + tabla */
.panel {
  background: var(--surface);
  border: 1px solid var(--neutral-200);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 20px 24px 16px;
  flex-wrap: wrap;
}

.panel-header h3 {
  font-size: 18px;
  font-weight: 700;
  color: var(--neutral-900);
}

/* Pestañas */
.tabs {
  display: flex;
  gap: 4px;
  padding: 0 24px;
  border-bottom: 1px solid var(--neutral-200);
}

.tab {
  background: none;
  border: none;
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  color: var(--neutral-500);
  padding: 10px 16px;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  transition: color 0.15s, border-color 0.15s;
}

.tab:hover {
  color: var(--neutral-800);
}

.tab.active {
  color: var(--blue-600);
  border-bottom-color: var(--blue-500);
}

.panel-toolbar {
  padding: 16px 24px;
}

/* Tabla dentro del panel */
.table-scroll {
  overflow-x: auto;
}

.table-footer {
  padding: 14px 24px;
  font-size: 13px;
  color: var(--neutral-500);
  border-top: 1px solid var(--neutral-100);
  background: var(--neutral-50);
}

.td-right {
  text-align: right;
}

/* Celda de usuario (avatar + nombre) */
.cell-user {
  display: flex;
  align-items: center;
  gap: 10px;
}

.cell-user-name {
  font-weight: 600;
  color: var(--neutral-900);
}

.avatar-sm {
  width: 36px;
  height: 36px;
}

.avatar-sm svg {
  width: 20px;
  height: 20px;
}

.avatar-sm.avatar-initials {
  font-size: 13px;
}

/* Acciones por fila */
.row-actions {
  display: flex;
  gap: 6px;
  justify-content: flex-end;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--neutral-400);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.icon-btn:hover {
  background: var(--blue-50);
  color: var(--blue-600);
}

.icon-btn svg {
  width: 16px;
  height: 16px;
}

/* Responsive */
@media (max-width: 1024px) {
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .stats-grid-3 { grid-template-columns: repeat(3, 1fr); }
}

@media (max-width: 768px) {
  .sidebar { display: none; }
  .main { margin-left: 0; padding: 20px; }
  .stats-grid { grid-template-columns: 1fr 1fr; }
  .toolbar { flex-direction: column; }
  .search-box { min-width: 100%; }
}

/* ============================================================
   Pantalla de carga (logo ON animado)
   ============================================================ */
.app-loader {
  position: fixed;
  inset: 0;
  z-index: 2147483647; /* máximo z-index posible: siempre por delante de todo */
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: #ffffff;
  opacity: 1;
  transition: opacity 0.4s ease;
}

.app-loader.is-hidden {
  opacity: 0;
  pointer-events: none;
}

.app-loader-logo {
  width: 240px;
  height: 120px;
}

.app-loader-logo svg {
  width: 100%;
  height: 100%;
}

.loader-path-bg {
  stroke: #F47B20;
  stroke-width: 16;
  stroke-linecap: round;
  fill: none;
}

.loader-path-anim {
  stroke: #1B478D;
  stroke-width: 16.5; /* Ligeramente más grueso para cubrir el naranja */
  stroke-linecap: round;
  stroke-linejoin: round;
  fill: none;
  stroke-dasharray: 200;
}

.loader-anim-o {
  animation: loader-draw-O 5s cubic-bezier(0.4, 0, 0.2, 1) infinite;
}

.loader-anim-n {
  animation: loader-draw-N 5s cubic-bezier(0.4, 0, 0.2, 1) infinite;
}

@keyframes loader-draw-O {
  0%   { stroke-dashoffset: 200; }
  30%, 50%  { stroke-dashoffset: 0; }
  80%, 100% { stroke-dashoffset: -200; }
}

@keyframes loader-draw-N {
  0%, 40%   { stroke-dashoffset: 200; }
  70%, 85%  { stroke-dashoffset: 0; }
  100%      { stroke-dashoffset: -200; }
}

@media (prefers-reduced-motion: reduce) {
  .loader-path-anim {
    animation: none;
    stroke-dashoffset: 0;
  }
}

/* ============================================================
   Control de Asistencia
   ============================================================ */
/* Variantes de KPI para presentes / ausentes */
.stat-card.green .stat-value { color: var(--success); }
.stat-card.red .stat-value { color: var(--error); }

/* Barra de filtros avanzados (búsqueda + selects) */
.filters-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 24px;
  flex-wrap: wrap;
  border-bottom: 1px solid var(--neutral-100);
}

.filter-select {
  padding: 10px 14px;
  border: 1px solid var(--neutral-200);
  border-radius: 10px;
  font-size: 13px;
  font-family: inherit;
  background: var(--surface);
  color: var(--neutral-700);
  outline: none;
  cursor: pointer;
  transition: border-color 0.15s;
}

.filter-select:focus {
  border-color: var(--blue-400);
}

/* Permite usar .muted fuera de las celdas de tabla (ej: etiqueta de fecha) */
.muted {
  color: var(--neutral-400);
  font-size: 13px;
}

/* Badge de estado de asistencia */
.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}

.badge-success {
  background: var(--success-bg);
  color: #2E7D32;
}

.badge-error {
  background: var(--error-bg);
  color: #C62828;
}

.badge-neutral {
  background: var(--neutral-100);
  color: var(--neutral-600);
}

/* Etiqueta del origen del registro (NFC / Docente) */
.source-tag {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 6px;
  background: var(--blue-50);
  color: var(--blue-600);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.02em;
}

/* ------------------------------------------------------------
   Planilla mensual de asistencia (matriz tipo Excel)
   ------------------------------------------------------------ */
.att-table {
  border-collapse: separate;
  border-spacing: 0;
  min-width: 100%;
}

/* Encabezados de la planilla: centrados y compactos. */
.att-table thead th {
  text-align: center;
  padding: 10px 8px;
  white-space: nowrap;
}

/* Cabecera de grupo de semana. */
.att-table thead th.att-week {
  background: var(--blue-50);
  color: var(--blue-600);
  border-bottom: 1px solid var(--neutral-200);
  border-left: 1px solid var(--neutral-200);
}

/* Etiqueta de día (L M M J V). */
.att-table thead th.att-dow {
  background: var(--neutral-50);
  width: 34px;
  color: var(--neutral-600);
}

/* Primera columna (nombre): fija al hacer scroll horizontal. */
.att-table th.att-name,
.att-table td.att-name {
  position: sticky;
  left: 0;
  z-index: 2;
  text-align: left;
  min-width: 220px;
  background: var(--surface);
  border-right: 1px solid var(--neutral-200);
}
.att-table thead th.att-name {
  z-index: 3;
  background: var(--neutral-50);
}
.att-table tbody tr:hover td.att-name {
  background: var(--neutral-50);
}

/* Celdas de día. */
.att-table td.att-day {
  text-align: center;
  padding: 8px 6px;
}

/* Check por día: verde lleno (asistió) o vacío con borde rojo (faltó). */
.att-check {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border-radius: 6px;
  vertical-align: middle;
}
.att-check.present {
  background: var(--success);
  color: #fff;
  box-shadow: 0 1px 2px rgba(102, 187, 106, 0.4);
}
.att-check.present svg {
  width: 15px;
  height: 15px;
}
.att-check.absent {
  border: 1.5px solid var(--neutral-300);
  background: var(--neutral-100);
  color: var(--neutral-400);
}
.att-check.absent svg {
  width: 14px;
  height: 14px;
}

/* Columna de total de asistencias. */
.att-table th.att-total,
.att-table td.att-total {
  text-align: center;
  font-weight: 700;
  color: var(--neutral-900);
  border-left: 1px solid var(--neutral-200);
  min-width: 96px;
}

/* Columna de porcentaje con barra de progreso. */
.att-table th.att-pct,
.att-table td.att-pct {
  min-width: 160px;
  border-left: 1px solid var(--neutral-200);
}
.pct-bar {
  position: relative;
  height: 26px;
  border-radius: 8px;
  background: var(--neutral-100);
  overflow: hidden;
}
.pct-fill {
  position: absolute;
  inset: 0 auto 0 0;
  border-radius: 8px;
  transition: width 0.3s ease;
}
.pct-fill.pct-high { background: linear-gradient(90deg, var(--success), #43A047); }
.pct-fill.pct-mid  { background: linear-gradient(90deg, var(--orange-400), var(--orange-500)); }
.pct-fill.pct-low  { background: linear-gradient(90deg, #EF9A9A, var(--error)); }
.pct-text {
  position: relative;
  z-index: 1;
  display: block;
  text-align: center;
  line-height: 26px;
  font-size: 13px;
  font-weight: 700;
  color: var(--neutral-900);
}

@media (max-width: 768px) {
  .filters-bar { flex-direction: column; align-items: stretch; }
  .filter-select { width: 100%; }
}

/* ============================================================
   Comunicados
   ------------------------------------------------------------
   Vista de emisión y gestión de avisos para la comunidad
   escolar. Dos columnas: a la izquierda el compositor (panel
   "Emitir Comunicado" + canales de envío) y a la derecha el
   historial de envíos con su resumen de rendimiento.
   ============================================================ */
.com-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  gap: 24px;
  align-items: start;
}

.com-main {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

/* Cabecera del panel del compositor: título a la izquierda y las
   acciones (Guardar borrador / Enviar) a la derecha. */
.com-compose-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  padding: 20px 24px;
  border-bottom: 1px solid var(--neutral-100);
}

.com-compose-title {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 18px;
  font-weight: 700;
  color: var(--neutral-900);
}

.com-compose-title svg {
  width: 22px;
  height: 22px;
  color: var(--blue-500);
}

.com-compose-actions {
  display: flex;
  gap: 10px;
}

.com-body {
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 22px;
}

/* Etiqueta de sección dentro del compositor (DESTINATARIOS, etc.) */
.com-section-label {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--neutral-500);
  margin-bottom: 12px;
}

/* Tarjetas de destinatarios (seleccionables) */
.recipient-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}

.recipient-card {
  position: relative;
  border: 1px solid var(--neutral-200);
  border-radius: var(--radius);
  padding: 16px;
  cursor: pointer;
  background: var(--surface);
  transition: border-color 0.15s, background 0.15s, box-shadow 0.15s;
}

.recipient-card:hover {
  border-color: var(--blue-200);
}

.recipient-card.selected {
  border-color: var(--blue-400);
  background: var(--blue-50);
  box-shadow: 0 0 0 3px var(--blue-50);
}

.recipient-card input[type="checkbox"] {
  position: absolute;
  top: 14px;
  right: 14px;
  width: 17px;
  height: 17px;
  margin: 0;
  accent-color: var(--blue-500);
  cursor: pointer;
}

.recipient-name {
  font-size: 14px;
  font-weight: 600;
  color: var(--neutral-900);
  padding-right: 24px;
}

.recipient-meta {
  margin-top: 6px;
  font-size: 12px;
  color: var(--neutral-500);
}

/* Selección manual de grados (chips), visible solo si está activa esa tarjeta */
.grados-picker {
  margin-top: 14px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.grado-chip {
  border: 1px solid var(--neutral-200);
  border-radius: 999px;
  padding: 6px 14px;
  font-size: 13px;
  font-weight: 500;
  color: var(--neutral-700);
  background: var(--surface);
  cursor: pointer;
  transition: all 0.12s;
}

.grado-chip:hover {
  border-color: var(--blue-200);
}

.grado-chip.selected {
  background: var(--blue-500);
  border-color: var(--blue-500);
  color: #fff;
}

/* Campos del compositor */
.com-field label {
  display: block;
  font-size: 14px;
  font-weight: 600;
  color: var(--neutral-800);
  margin-bottom: 8px;
}

.com-field input[type="text"] {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--neutral-200);
  border-radius: 10px;
  font-size: 14px;
  font-family: inherit;
  background: var(--surface);
  color: var(--neutral-900);
  outline: none;
  transition: border-color 0.15s;
}

.com-field input[type="text"]:focus {
  border-color: var(--blue-400);
  box-shadow: 0 0 0 3px var(--blue-50);
}

/* Editor de mensaje: barra de herramientas + área editable */
.editor {
  border: 1px solid var(--neutral-200);
  border-radius: 10px;
  overflow: hidden;
  transition: border-color 0.15s;
}

.editor.focused {
  border-color: var(--blue-400);
  box-shadow: 0 0 0 3px var(--blue-50);
}

.editor-toolbar {
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 8px 10px;
  background: var(--neutral-50);
  border-bottom: 1px solid var(--neutral-200);
}

.editor-tool {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--neutral-600);
  cursor: pointer;
  font-size: 15px;
  transition: background 0.12s, color 0.12s;
}

.editor-tool:hover {
  background: var(--blue-50);
  color: var(--blue-600);
}

.editor-tool svg {
  width: 18px;
  height: 18px;
}

.editor-divider {
  width: 1px;
  height: 20px;
  background: var(--neutral-200);
  margin: 0 6px;
}

.editor-area {
  min-height: 180px;
  padding: 14px;
  font-size: 14px;
  line-height: 1.6;
  color: var(--neutral-900);
  outline: none;
  overflow-y: auto;
}

.editor-area:empty::before {
  content: attr(data-placeholder);
  color: var(--neutral-400);
}

/* Canales de envío (Correo / Push) con interruptor */
.channels-row {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 16px;
}

.channel-card {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 16px;
  border: 1px solid var(--neutral-200);
  border-radius: var(--radius);
  background: var(--surface);
}

.channel-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 42px;
  height: 42px;
  border-radius: 10px;
  background: var(--blue-50);
  color: var(--blue-500);
  flex-shrink: 0;
}

.channel-icon svg { width: 22px; height: 22px; }

.channel-text { flex: 1; min-width: 0; }

.channel-name {
  font-size: 14px;
  font-weight: 600;
  color: var(--neutral-900);
}

.channel-desc {
  font-size: 12px;
  color: var(--neutral-500);
  margin-top: 2px;
}

/* Interruptor (switch) reutilizable */
.switch {
  position: relative;
  display: inline-block;
  width: 42px;
  height: 24px;
  flex-shrink: 0;
}

.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.switch-slider {
  position: absolute;
  inset: 0;
  background: var(--neutral-300);
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.2s;
}

.switch-slider::before {
  content: '';
  position: absolute;
  width: 18px;
  height: 18px;
  left: 3px;
  top: 3px;
  background: #fff;
  border-radius: 50%;
  transition: transform 0.2s;
  box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}

.switch input:checked + .switch-slider {
  background: var(--blue-500);
}

.switch input:checked + .switch-slider::before {
  transform: translateX(18px);
}

/* Columna derecha: historial de envíos */
.com-side {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.history-list {
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-height: 560px;
  overflow-y: auto;
}

.history-card {
  border: 1px solid var(--neutral-200);
  border-radius: var(--radius);
  padding: 14px;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.history-card:hover {
  border-color: var(--blue-200);
  box-shadow: 0 2px 8px rgba(0,0,0,0.04);
}

.history-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
}

.history-time {
  font-size: 12px;
  color: var(--neutral-400);
  white-space: nowrap;
}

/* Variantes de estado del comunicado */
.badge-draft {
  background: var(--orange-50);
  color: var(--orange-500);
}

.history-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--neutral-900);
  margin-bottom: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.history-metrics {
  display: flex;
  gap: 18px;
}

.metric { min-width: 0; }

.metric-label {
  font-size: 11px;
  color: var(--neutral-400);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-weight: 600;
}

.metric-value {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 4px;
  font-size: 13px;
  font-weight: 600;
  color: var(--neutral-700);
}

.metric-rate { color: var(--success); }

.metric-bar {
  flex: 1;
  height: 4px;
  border-radius: 999px;
  background: var(--neutral-200);
  overflow: hidden;
  min-width: 48px;
}

.metric-bar > span {
  display: block;
  height: 100%;
  border-radius: 999px;
  background: var(--success);
}

/* Resumen de rendimiento mensual */
.perf-card {
  background: var(--surface);
  border: 1px solid var(--neutral-200);
  border-radius: var(--radius-lg);
  padding: 20px;
}

.perf-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 18px;
}

.perf-head h3 {
  font-size: 15px;
  font-weight: 700;
  color: var(--neutral-900);
}

.perf-trend {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  font-size: 13px;
  font-weight: 700;
  color: var(--success);
}

.perf-row {
  margin-bottom: 16px;
}

.perf-row:last-child { margin-bottom: 0; }

.perf-row-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 13px;
  margin-bottom: 6px;
}

.perf-row-label { color: var(--neutral-500); }

.perf-row-value {
  font-weight: 700;
  color: var(--neutral-900);
}

.perf-bar {
  height: 6px;
  border-radius: 999px;
  background: var(--neutral-100);
  overflow: hidden;
}

.perf-bar > span {
  display: block;
  height: 100%;
  border-radius: 999px;
  background: var(--blue-500);
}

/* Enlace discreto en cabeceras (ej: "Ver todos") */
.link-action {
  background: none;
  border: none;
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  color: var(--blue-600);
  cursor: pointer;
  padding: 0;
}

.link-action:hover { text-decoration: underline; }

/* Toast de confirmación (envío / borrador guardado) */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 18px;
  background: var(--neutral-900);
  color: #fff;
  border-radius: 12px;
  font-size: 14px;
  font-weight: 500;
  box-shadow: 0 10px 30px rgba(0,0,0,0.25);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s, transform 0.25s;
  z-index: 200;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.toast svg {
  width: 18px;
  height: 18px;
  color: var(--success);
}

@media (max-width: 1024px) {
  .com-layout { grid-template-columns: 1fr; }
  .recipient-grid { grid-template-columns: 1fr; }
}

@media (max-width: 768px) {
  .channels-row { grid-template-columns: 1fr; }
}
