/* ===================================================================
 * SISTEMA DE DISEÑO UNIFICADO - PLATAFORMA EDUCACIONAL
 * Archivo: /assets/style.css
 * =================================================================== */

/* ===================================================================
 * 1. VARIABLES GLOBALES
 * =================================================================== */
:root {
  /* Colores principales */
  --azul-primary: #26416e;
  --azul-hover: #1c3254;
  --azul-light: #e8eef7;
  --azul-lighter: #d4e2f4;
  
  /* Grises */
  --gris-fondo: #f4f6fa;
  --gris-hover: #e2ebf7;
  --gris-light: #f1f3f4;
  --gris-lighter: #f8f9fb;
  --gris-text: #333333;
  --gris-border: #cccccc;
  --gris-table: #eeeeee;
  --gris-muted: #6b7280;
  
  /* Estados */
  --success-color: #10b981;
  --success-bg: #ecfdf5;
  --warning-color: #f59e0b;
  --warning-bg: #fef3c7;
  --danger-color: #ef4444;
  --danger-bg: #fef2f2;
  --info-color: #3b82f6;
  --info-bg: #eff6ff;
  
  /* Espaciado */
  --spacing-xs: 4px;
  --spacing-sm: 8px;
  --spacing-md: 12px;
  --spacing-lg: 16px;
  --spacing-xl: 20px;
  --spacing-2xl: 24px;
  --spacing-3xl: 30px;
  
  /* Layout */
  --navbar-height: 56px;
  --sidebar-collapsed: 80px;
  --sidebar-expanded: 240px;
  --container-max: 1200px;
  --form-max: 900px;
  --page-max: 720px;
  
  /* Animaciones */
  --transition-fast: 0.15s ease;
  --transition-normal: 0.25s ease;
  --transition-slow: 0.3s ease;
  
  /* Sombras */
  --shadow-sm: 0 2px 4px rgba(0, 0, 0, 0.06);
  --shadow-md: 0 3px 8px rgba(0, 0, 0, 0.08);
  --shadow-lg: 0 4px 12px rgba(0, 0, 0, 0.12);
  
  /* Border radius */
  --radius-sm: 4px;
  --radius-md: 6px;
  --radius-lg: 8px;
  --radius-xl: 10px;
  --radius-2xl: 12px;

  /* Tipografía */
  --font-family-base: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  --font-size-base: 14px;
  --font-weight-base: 400;
}

/* Base tipográfica en html: los rem escalan con --font-size-base (personalización org/inst). */
html {
  font-family: var(--font-family-base);
  font-size: var(--font-size-base);
}

/* ===================================================================
 * 2. RESET Y BASE
 * =================================================================== */
* {
  box-sizing: border-box;
}

body {
  margin: 0;
  padding: 0;
  font-family: var(--font-family-base);
  font-size: 1rem;
  font-weight: var(--font-weight-base);
  color: var(--gris-text);
  background: var(--gris-fondo);
  line-height: 1.6;
}

h1, h2, h3, h4, h5, h6 {
  font-family: var(--font-family-base);
}

/* ===================================================================
 * 3. LAYOUT PRINCIPAL
 * =================================================================== */
.contenido {
  margin-top: var(--navbar-height);
  padding: var(--spacing-lg);
  transition: margin-left var(--transition-fast);
  min-height: calc(100vh - var(--navbar-height));
}

@media (min-width: 768px) {
  body:not(.sidebar-expanded) .contenido,
  html:not(.sidebar-expanded) .contenido {
    margin-left: 0;
  }
  
  body.sidebar-expanded .contenido,
  html.sidebar-expanded .contenido {
    margin-left: var(--sidebar-expanded);
  }
}

/* ===================================================================
 * 4. COMPONENTES DE PÁGINA
 * =================================================================== */

/* Page Container */
.page-container {
  padding: var(--spacing-lg);
  max-width: var(--container-max);
  margin: 0 auto;
}

/* Page Header */
.page-header {
  display: flex;
  flex-direction: column;
  gap: var(--spacing-md);
  margin-bottom: var(--spacing-3xl);
  padding: var(--spacing-xl) 0;
  border-bottom: 2px solid var(--gris-hover);
}

.page-title {
  font-family: var(--font-family-base);
  font-size: var(--font-size-title, clamp(1.5rem, 4vw, 2.2rem));
  color: var(--azul-primary);
  margin: 0;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: var(--spacing-md);
}

.page-title .material-icons {
  font-size: 1.2em;
}

.page-subtitle {
  color: var(--gris-text);
  font-size: 1.1rem;
  margin: 0;
}

/* Breadcrumb de módulo */
.module-breadcrumb {
  display: flex;
  align-items: center;
  gap: var(--spacing-sm);
  margin-bottom: var(--spacing-2xl);
  font-size: 0.95rem;
  color: #4a5568;
}

.module-breadcrumb .material-icons {
  font-size: 18px;
}

.module-breadcrumb-link,
.module-breadcrumb-current {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.module-breadcrumb-link {
  color: var(--azul-primary);
  font-weight: 500;
  text-decoration: none;
}

.module-breadcrumb-link:hover {
  text-decoration: underline;
}

.module-breadcrumb-current {
  color: #2d3748;
  font-weight: 600;
}

.module-breadcrumb-separator {
  font-size: 18px;
  color: #a0aec0;
}

/* ===================================================================
 * 5. CARD DE FILTROS UNIFICADA
 * =================================================================== */
.filters-card {
  background: white;
  border-radius: var(--radius-2xl);
  box-shadow: var(--shadow-md);
  padding: var(--spacing-3xl);
  margin-bottom: var(--spacing-3xl);
  border: 1px solid #e5e7eb;
  animation: slideUp 0.4s ease-out;
}

.card-title {
  font-weight: 600;
  color: var(--azul-primary);
  font-size: 1.1rem;
  margin: 0 0 var(--spacing-2xl);
  display: flex;
  align-items: center;
  gap: var(--spacing-sm);
}

.card-title .material-icons {
  font-size: 20px;
}

.filters-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--spacing-3xl);
  margin-bottom: var(--spacing-3xl);
  padding: 0 var(--spacing-md);
}

.filter-group {
  display: flex;
  flex-direction: column;
  gap: var(--spacing-md);
}

.filter-label {
  font-weight: 600;
  color: var(--azul-primary);
  font-size: 1rem;
  margin-bottom: var(--spacing-sm);
}

.filter-select,
.filter-input {
  padding: var(--spacing-lg) var(--spacing-xl);
  border: 2px solid var(--gris-border);
  border-radius: var(--radius-lg);
  font-family: var(--font-family-base);
  font-size: var(--font-size-base);
  transition: all var(--transition-fast);
  background: var(--gris-lighter);
  color: var(--gris-text);
  cursor: pointer;
  min-height: 48px;
}

.filter-select:focus,
.filter-input:focus {
  outline: none;
  border-color: var(--azul-primary);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--azul-primary) 10%, transparent);
  background: white;
}

.filter-select:hover,
.filter-input:hover {
  border-color: var(--azul-hover);
  background: white;
}

/* Sección de búsqueda y acciones */
.search-actions-section {
  border-top: 1px solid var(--gris-border);
  padding-top: var(--spacing-3xl);
  display: grid;
  grid-template-columns: 1fr auto;
  gap: var(--spacing-3xl);
  align-items: end;
  margin-top: var(--spacing-lg);
}

.search-container {
  position: relative;
}

.search-input {
  width: 100%;
  padding: var(--spacing-lg) var(--spacing-xl) var(--spacing-lg) 3.5rem;
  border: 2px solid var(--gris-border);
  border-radius: var(--radius-lg);
  font-family: var(--font-family-base);
  font-size: var(--font-size-base);
  transition: all var(--transition-fast);
  background: var(--gris-lighter);
  min-height: 48px;
}

.search-input:focus {
  outline: none;
  border-color: var(--azul-primary);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--azul-primary) 10%, transparent);
  background: white;
}

.search-input:hover {
  border-color: var(--azul-hover);
  background: white;
}

.search-input::placeholder {
  color: var(--gris-muted);
  font-style: italic;
}

.search-icon {
  position: absolute;
  left: var(--spacing-lg);
  top: 50%;
  transform: translateY(-50%);
  color: #6b7280;
  pointer-events: none;
  font-size: 22px;
}

.actions-buttons {
  display: flex;
  gap: var(--spacing-lg);
  align-items: center;
  flex-wrap: wrap;
}

/* ===================================================================
 * 6. SISTEMA DE BOTONES
 * =================================================================== */
.btn {
  display: inline-flex;
  align-items: center;
  gap: var(--spacing-md);
  padding: var(--spacing-lg) var(--spacing-2xl);
  border: none;
  border-radius: var(--radius-lg);
  font-family: var(--font-family-base);
  font-weight: 600;
  text-decoration: none;
  transition: all var(--transition-fast);
  cursor: pointer;
  font-size: var(--font-size-base);
  white-space: nowrap;
  min-height: 48px;
  justify-content: center;
}

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

.btn-primary:hover {
  background: var(--azul-hover);
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.btn-success {
  background: var(--success-color);
  color: white;
}

.btn-success:hover {
  background: var(--success-color);
  filter: brightness(0.85);
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.btn-warning {
  background: var(--warning-color);
  color: white;
}

.btn-warning:hover {
  background: var(--warning-color);
  filter: brightness(0.85);
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.btn-danger {
  background: var(--danger-color);
  color: white;
}

.btn-danger:hover {
  background: var(--danger-color);
  filter: brightness(0.85);
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.btn-info {
  background: var(--info-color);
  color: white;
}

.btn-info:hover {
  background: var(--info-color);
  filter: brightness(0.85);
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.btn-secondary {
  background: var(--gris-light);
  color: var(--azul-primary);
  border: 2px solid var(--gris-border);
}

.btn-secondary:hover {
  background: var(--gris-hover);
  border-color: var(--azul-primary);
}

/* Botones de icono */
.btn-icon {
  width: 40px;
  height: 40px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
}

.btn-icon:hover {
  transform: scale(1.1);
}

/* File input personalizado */
.file-input-wrapper {
  position: relative;
  overflow: hidden;
  display: inline-block;
}

.file-input-wrapper input[type=file] {
  position: absolute;
  left: -9999px;
}

/* ===================================================================
 * 7. ALERTAS Y MENSAJES
 * =================================================================== */
.alert {
  padding: var(--spacing-lg);
  border-radius: var(--radius-lg);
  margin-bottom: var(--spacing-xl);
  display: flex;
  align-items: center;
  gap: var(--spacing-md);
  font-weight: 500;
  animation: slideIn 0.3s ease-out;
}

.alert-success {
  background: var(--success-bg);
  color: var(--success-color);
  border: 1px solid var(--success-color);
}

.alert-warning {
  background: var(--warning-bg);
  color: var(--warning-color);
  border: 1px solid var(--warning-color);
}

.alert-danger {
  background: var(--danger-bg);
  color: var(--danger-color);
  border: 1px solid var(--danger-color);
}

.alert-info {
  background: var(--info-bg);
  color: var(--info-color);
  border: 1px solid var(--info-color);
}

.alert .material-icons {
  font-size: 24px;
}

/* ===================================================================
 * 8. SISTEMA DE TABLAS
 * =================================================================== */
.table-wrapper {
  background: white;
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-md);
  overflow: hidden;
  margin-bottom: var(--spacing-3xl);
}

.table-container {
  overflow-x: auto;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 700px;
}

.data-table thead {
  background: var(--azul-primary);
  position: sticky;
  top: 0;
  z-index: 10;
}

.data-table th {
  color: white;
  padding: var(--spacing-lg);
  text-align: left;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
  transition: background-color var(--transition-fast);
}

.data-table th:hover {
  background: var(--azul-hover);
}

.data-table th .sort-icon {
  margin-left: var(--spacing-sm);
  font-size: 14px;
  opacity: 0.7;
}

.data-table td {
  padding: var(--spacing-lg);
  border-bottom: 1px solid var(--gris-table);
  vertical-align: middle;
}

.data-table tbody tr {
  transition: background-color var(--transition-fast);
}

.data-table tbody tr:hover {
  background: var(--gris-hover);
}

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

.data-table .numeric {
  text-align: center;
}

/* Acciones de tabla */
.table-actions {
  display: flex;
  gap: var(--spacing-sm);
  justify-content: center;
}

/* ===================================================================
 * 9. STATUS BADGES
 * =================================================================== */
.status-badge {
  display: inline-flex;
  align-items: center;
  gap: var(--spacing-xs);
  padding: var(--spacing-xs) var(--spacing-md);
  border-radius: 20px;
  font-size: 0.8rem;
  font-weight: 600;
  white-space: nowrap;
}

.status-activo,
.status-vigente {
  background: var(--success-bg);
  color: var(--success-color);
}

.status-inactivo,
.status-finiquitado {
  background: var(--danger-bg);
  color: var(--danger-color);
}

.status-solicitud {
  background: var(--warning-bg);
  color: var(--warning-color);
}

.status-historico {
  background: var(--gris-fondo);
  color: var(--gris-muted);
}

/* ===================================================================
 * 10. TOGGLE SWITCHES
 * =================================================================== */
.status-toggle {
  position: relative;
  display: inline-block;
  width: 60px;
  height: 34px;
}

.status-toggle input {
  opacity: 0;
  width: 0;
  height: 0;
}

.slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: var(--gris-border);
  transition: 0.4s;
  border-radius: 34px;
}

.slider:before {
  position: absolute;
  content: "";
  height: 26px;
  width: 26px;
  left: 4px;
  bottom: 4px;
  background-color: white;
  transition: 0.4s;
  border-radius: 50%;
}

input:checked + .slider {
  background-color: var(--success-color);
}

input:checked + .slider:before {
  transform: translateX(26px);
}

/* ===================================================================
 * 11. CÓDIGOS Y ELEMENTOS ESPECIALES
 * =================================================================== */
.code-display {
  background: var(--gris-fondo);
  color: var(--gris-text);
  padding: var(--spacing-xs) var(--spacing-sm);
  border-radius: var(--radius-sm);
  font-family: 'Courier New', monospace;
  font-size: 0.9em;
}

/* ===================================================================
 * 12. PAGINACIÓN
 * =================================================================== */
.pagination-wrapper {
  background: white;
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-md);
  padding: var(--spacing-xl);
  text-align: center;
  margin-bottom: var(--spacing-3xl);
}

.pagination {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: var(--spacing-md);
  flex-wrap: wrap;
}

.pagination-info {
  font-weight: 600;
  color: var(--azul-primary);
  margin: 0 var(--spacing-lg);
  font-size: var(--font-size-base);
}

/* ===================================================================
 * 13. VISTA MÓVIL - CARDS
 * =================================================================== */
@media (max-width: 1024px) {
  .table-container {
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .data-table {
    min-width: 700px;
    width: max-content;
  }

  .mobile-cards {
    display: block;
  }
}

@media (min-width: 1025px) {
  .mobile-cards {
    display: none;
  }
}

.mobile-card {
  background: white;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  margin-bottom: var(--spacing-lg);
  overflow: hidden;
  border: 2px solid transparent;
  transition: all var(--transition-fast);
}

.mobile-card:hover {
  border-color: var(--azul-primary);
  box-shadow: var(--shadow-md);
}

.card-header {
  background: var(--gris-fondo);
  padding: var(--spacing-lg);
  border-bottom: 1px solid var(--gris-border);
}

.card-title-mobile {
  font-weight: 600;
  color: var(--azul-primary);
  margin: 0 0 var(--spacing-sm);
  font-size: 1.1rem;
}

.card-subtitle {
  color: var(--gris-text);
  font-size: 0.9rem;
  margin: 0;
}

.card-body {
  padding: var(--spacing-lg);
}

.card-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: var(--spacing-sm) 0;
  border-bottom: 1px solid var(--gris-fondo);
}

.card-row:last-child {
  border-bottom: none;
  padding-bottom: 0;
}

.card-label {
  font-weight: 600;
  color: var(--gris-text);
  font-size: 0.9rem;
}

.card-value {
  text-align: right;
}

.card-actions {
  padding: var(--spacing-lg);
  background: var(--gris-fondo);
  border-top: 1px solid var(--gris-border);
}

.card-actions .table-actions {
  justify-content: center;
}

/* ===================================================================
 * 14. COMPONENTES ESPECÍFICOS
 * =================================================================== */

/* Navegación entre registros */
.navigation-bar {
  display: flex;
  justify-content: center;
  gap: var(--spacing-lg);
  margin-bottom: var(--spacing-3xl);
  padding: var(--spacing-xl) 0;
}

.nav-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: var(--azul-primary);
  color: white;
  text-decoration: none;
  transition: all var(--transition-fast);
  box-shadow: var(--shadow-md);
}

.nav-btn:hover {
  background: var(--azul-hover);
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg);
}

.nav-btn .material-icons {
  font-size: 24px;
}

/* Headers expandibles */
.expandable-header {
  background: var(--azul-light) !important;
  cursor: pointer;
  transition: all var(--transition-fast);
  user-select: none;
}

.expandable-header:hover {
  background: var(--azul-lighter) !important;
}

.expandable-header td {
  font-weight: 600;
  color: var(--azul-primary);
  padding: var(--spacing-lg) var(--spacing-xl);
}

.expand-icon {
  transition: transform var(--transition-slow);
  margin-right: var(--spacing-sm);
}

.expandable-header.expanded .expand-icon {
  transform: rotate(90deg);
}

/* ===================================================================
 * 15. ESTADOS Y ANIMACIONES
 * =================================================================== */
.hidden {
  display: none !important;
}

.loading {
  opacity: 0.6;
  pointer-events: none;
}

.fade-in {
  animation: fadeIn 0.3s ease-in;
}

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

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

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

/* ===================================================================
 * 16. ESTADOS VACÍOS
 * =================================================================== */
.empty-state {
  text-align: center;
  padding: var(--spacing-3xl);
  color: var(--gris-text);
}

.empty-state .material-icons-outlined {
  font-size: 64px;
  color: var(--gris-border);
  margin-bottom: var(--spacing-xl);
}

.empty-state h3 {
  color: var(--azul-primary);
  margin-bottom: var(--spacing-md);
}

/* ===================================================================
 * 17. FOOTER
 * =================================================================== */
.page-footer {
  text-align: center;
  padding: var(--spacing-3xl) 0;
  border-top: 2px solid var(--gris-hover);
  margin-top: var(--spacing-3xl);
}

.back-link {
  display: inline-flex;
  align-items: center;
  gap: var(--spacing-sm);
  color: var(--azul-primary);
  text-decoration: none;
  font-weight: 600;
  padding: var(--spacing-md) var(--spacing-xl);
  border-radius: var(--radius-lg);
  transition: all var(--transition-fast);
  border: 2px solid var(--gris-border);
}

.back-link:hover {
  background: var(--gris-hover);
  border-color: var(--azul-primary);
  transform: translateY(-2px);
}

/* ===================================================================
 * 18. RESPONSIVIDAD GENERAL
 * =================================================================== */
@media (max-width: 768px) {
  .page-container {
    padding: var(--spacing-md);
  }

  .filters-grid {
    grid-template-columns: 1fr;
    gap: var(--spacing-lg);
    padding: 0;
  }

  .search-actions-section {
    grid-template-columns: 1fr;
    gap: var(--spacing-lg);
  }

  .actions-buttons {
    justify-content: center;
  }

  .filters-card {
    padding: var(--spacing-xl);
    margin: 0 -var(--spacing-md) var(--spacing-3xl);
    border-radius: 0;
  }

  .btn {
    font-size: 0.8rem;
    padding: var(--spacing-sm) var(--spacing-md);
  }

  .btn .material-icons {
    font-size: 18px;
  }

  .mobile-card {
    margin: 0 -var(--spacing-md) var(--spacing-lg);
    border-radius: 0;
  }

  .pagination {
    flex-direction: column;
    gap: var(--spacing-lg);
  }

  .pagination-info {
    margin: 0;
  }
}

@media (max-width: 480px) {
  .actions-buttons {
    flex-direction: column;
    align-items: stretch;
  }

  .btn {
    justify-content: center;
  }

  .filters-card {
    padding: var(--spacing-lg);
  }

  .nav-btn {
    width: 40px;
    height: 40px;
  }

  .nav-btn .material-icons {
    font-size: 20px;
  }
}

/* ===================================================================
 * 19. ACCESIBILIDAD
 * =================================================================== */
.btn:focus-visible,
.filter-select:focus-visible,
.search-input:focus-visible {
  outline: 2px solid var(--azul-primary);
  outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
  .btn,
  .nav-btn,
  .filter-select,
  .search-input,
  .mobile-card {
    transition: none;
  }
  
  .fade-in,
  .filters-card {
    animation: none;
  }
}

/* ===================================================================
 * 20. DARK MODE SUPPORT (OPCIONAL)
 * =================================================================== */
@media (prefers-color-scheme: dark) {
  :root {
    --gris-fondo: #1a1a1a;
    --gris-text: #e0e0e0;
    --gris-border: #333;
  }
}

/* ═══════════════════════════════════════════════════════════
   LAYOUT PRINCIPAL - Compatible con navbar superior
   ═══════════════════════════════════════════════════════════ */

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

body {
    font-family: var(--font-family-base);
    font-size: 1rem;
    font-weight: var(--font-weight-base);
    background-color: var(--gris-fondo);
    color: var(--gris-text);
}

/* ═══════════════════════════════════════════════════════════
   NAVBAR SUPERIOR (mantenemos tu estilo existente)
   ═══════════════════════════════════════════════════════════ */
.navbar {
    display: flex;
    align-items: center;
    gap: 1rem;
    background: var(--azul-primary);
    padding: 0 .75rem;
    color: #fff;
    font-family: var(--font-family-base);
    font-size: 1rem;
    font-weight: var(--font-weight-base);
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    z-index: 1001 !important;
    height: var(--navbar-height) !important;
    width: 100% !important;
}

.navbar ul {
    list-style: none;
    margin: 0;
    margin-left: auto;
    padding: 0;
    display: flex;
    align-items: center;
    gap: 1rem;
}

.nav-logo-item {
    display: flex;
    align-items: center;
    margin-left: auto;
    /* Flex: sin esto la imagen mantiene su ancho intrínseco (cientos de px) en móvil */
    min-width: 0;
    flex-shrink: 1;
    max-width: min(140px, 42vw);
}

.nav-inst-logo {
    display: block;
    width: auto;
    height: auto;
    max-height: 36px;
    max-width: 100%;
    min-width: 0;
    object-fit: contain;
    border-radius: 4px;
    background: rgba(255,255,255,.12);
    padding: 2px 6px;
    box-sizing: border-box;
}

.navbar a {
    color: #fff;
    text-decoration: none;
    display: flex;
    align-items: center;
    gap: .25rem;
    font-size: 1.0625rem;
}

.navbar .material-icons {
    font-size: 1.429rem;
}

.navbar a:hover {
    background: rgba(255,255,255,.15);
    color: #fff;
}

/* ═══════════════════════════════════════════════════════════
   BOTÓN HAMBURGUESA
   ═══════════════════════════════════════════════════════════ */
#hamburger {
    cursor: pointer;
    display: flex;
    align-items: center;
    margin-right: .5rem;
}

#hamburger .material-icons {
    font-size: 2rem;
    line-height: 1;
    color: #fff;
}

/* --- Navbar User Dropdown --- */
.user-menu {
    position: relative;
}
.user-menu .submenu {
    display: none;
    position: absolute;
    top: 100%;
    right: 0;
    min-width: 160px;
    background: var(--azul-hover);
    padding: .25rem 0;
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-lg);
    z-index: 2000;
}
.user-menu.open .submenu {
    display: block;
}
.submenu a {
    display: block;
    padding: .5rem 1rem;
    font-size: 0.95rem;
    color: #fff;
    text-decoration: none;
    white-space: nowrap;
}

.submenu a .material-icons {
    font-size: 1em;
    vertical-align: middle;
    margin-right: 4px;
}
.submenu a:hover {
    background: rgba(255,255,255,.12);
}

/* --- Navbar always single line --- */
.navbar {
    flex-wrap: nowrap;
    overflow: visible;
}
.navbar ul {
    flex-wrap: nowrap;
}

/* ═══════════════════════════════════════════════════════════
   SELECTOR CONTEXTO GLOBAL (navbar)
   ═══════════════════════════════════════════════════════════ */
#navCtxSelector {
    display: flex;
    align-items: center;
    gap: .35rem;
    cursor: pointer;
    color: #fff;
    font-size: .9rem;
    font-weight: 500;
    padding: .3rem .65rem;
    border-radius: var(--radius-sm, 6px);
    background: rgba(255,255,255,.1);
    white-space: nowrap;
    max-width: 340px;
    transition: background .15s;
    user-select: none;
    flex-shrink: 1;
    min-width: 0;
}
#navCtxSelector:hover {
    background: rgba(255,255,255,.22);
}
#navCtxSelector .ctx-inst-name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    min-width: 0;
}
#navCtxSelector .ctx-separator {
    opacity: .5;
    flex-shrink: 0;
}
#navCtxSelector .ctx-anio {
    flex-shrink: 0;
    font-variant-numeric: tabular-nums;
}
#navCtxSelector .ctx-arrow {
    font-size: 1.15rem;
    flex-shrink: 0;
    opacity: .7;
    transition: transform .2s;
}
#navCtxSelector:hover .ctx-arrow {
    opacity: 1;
}

/* ─── Modal contexto ─── */
.ctx-modal-overlay {
    position: fixed;
    inset: 0;
    z-index: 10000;
    background: rgba(0,0,0,.45);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}
.ctx-modal {
    background: #fff;
    border-radius: var(--radius-lg, 12px);
    width: 100%;
    max-width: 460px;
    box-shadow: 0 20px 60px rgba(0,0,0,.25);
    overflow: hidden;
    animation: ctxModalIn .2s ease-out;
}
@keyframes ctxModalIn {
    from { opacity: 0; transform: translateY(-12px) scale(.97); }
    to   { opacity: 1; transform: translateY(0) scale(1); }
}
.ctx-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1.25rem;
    border-bottom: 1px solid #e5e7eb;
}
.ctx-modal-header h3 {
    margin: 0;
    font-size: 1.1rem;
    font-weight: 600;
    color: #1f2937;
}
.ctx-modal-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    line-height: 1;
    cursor: pointer;
    color: #9ca3af;
    padding: 0;
    transition: color .15s;
}
.ctx-modal-close:hover {
    color: #374151;
}
.ctx-modal-body {
    padding: 1.25rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}
.ctx-field label {
    display: block;
    font-size: .85rem;
    font-weight: 600;
    color: #374151;
    margin-bottom: .35rem;
}
.ctx-field select {
    width: 100%;
    padding: .55rem .75rem;
    font-size: .95rem;
    border: 1px solid #d1d5db;
    border-radius: var(--radius-sm, 6px);
    background: #fff;
    color: #1f2937;
    transition: border-color .15s, box-shadow .15s;
    appearance: auto;
}
.ctx-field select:focus {
    outline: none;
    border-color: var(--azul-primary, #2563eb);
    box-shadow: 0 0 0 3px rgba(37,99,235,.15);
}
.ctx-inst-list {
    max-height: 220px;
    overflow-y: auto;
    border: 1px solid #e5e7eb;
    border-radius: var(--radius-sm, 6px);
    background: #fff;
}
.ctx-inst-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: .6rem .85rem;
    font-size: .9rem;
    color: #374151;
    cursor: pointer;
    border-bottom: 1px solid #f3f4f6;
    transition: background .1s;
}
.ctx-inst-item:last-child { border-bottom: none; }
.ctx-inst-item:hover { background: #f0f9ff; }
.ctx-inst-item.active {
    background: var(--azul-light, #e0f7fa);
    color: var(--azul-primary, #0e7490);
    font-weight: 600;
}
.ctx-inst-item.active .material-icons { opacity: 1 !important; color: var(--azul-primary, #0e7490); }
.ctx-anio-bar {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}
.ctx-anio-chip {
    padding: .45rem .9rem;
    font-size: .9rem;
    font-weight: 500;
    border: 1px solid #d1d5db;
    border-radius: var(--radius-sm, 6px);
    background: #fff;
    color: #374151;
    cursor: pointer;
    transition: all .12s;
    line-height: 1.2;
}
.ctx-anio-chip:hover { background: #f0f9ff; border-color: var(--azul-primary, #0e7490); color: var(--azul-primary, #0e7490); }
.ctx-anio-chip.active {
    background: var(--azul-primary, #0e7490);
    color: #fff;
    border-color: var(--azul-primary, #0e7490);
}
.ctx-anio-chip.active:hover { filter: brightness(1.1); }
.ctx-anio-more { color: #9ca3af; letter-spacing: 2px; font-weight: 700; }
.ctx-anio-expanded {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    margin-top: 8px;
    max-height: 140px;
    overflow-y: auto;
    padding: 8px;
    background: #f9fafb;
    border: 1px solid #e5e7eb;
    border-radius: var(--radius-sm, 6px);
}
.ctx-field-readonly .ctx-readonly-value {
    display: block;
    padding: .55rem .75rem;
    font-size: .95rem;
    color: #6b7280;
    background: #f9fafb;
    border: 1px solid #e5e7eb;
    border-radius: var(--radius-sm, 6px);
}
.ctx-modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: .5rem;
    padding: .85rem 1.25rem;
    border-top: 1px solid #e5e7eb;
    background: #f9fafb;
}
.ctx-btn {
    padding: .5rem 1.15rem;
    font-size: .9rem;
    font-weight: 500;
    border-radius: var(--radius-sm, 6px);
    border: 1px solid transparent;
    cursor: pointer;
    transition: background .15s, box-shadow .15s;
}
.ctx-btn-secondary {
    background: #fff;
    color: #374151;
    border-color: #d1d5db;
}
.ctx-btn-secondary:hover {
    background: #f3f4f6;
}
.ctx-btn-primary {
    background: var(--azul-primary, #2563eb);
    color: #fff;
}
.ctx-btn-primary:hover {
    filter: brightness(1.08);
}
.ctx-btn-primary:disabled {
    opacity: .6;
    cursor: wait;
}

/* ─── Responsive contexto ─── */
@media (max-width: 768px) {
    #navCtxSelector {
        max-width: 180px;
        font-size: .82rem;
        padding: .25rem .5rem;
    }
    .ctx-modal {
        max-width: 95vw;
    }
}
@media (max-width: 480px) {
    #navCtxSelector .ctx-inst-name {
        max-width: 90px;
    }
}

/* ═══════════════════════════════════════════════════════════
   SIDEBAR - Compatible con tu sistema expandible
   ═══════════════════════════════════════════════════════════ */
#sidebar {
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    width: 80px; /* colapsado - aumentado para iconos completos */
    background: #fff;
    font-family: var(--font-family-base);
    font-size: 1rem;
    padding-top: var(--navbar-height) !important; /* deja espacio al navbar - forzado */
    overflow: hidden; /* Sin scroll en el contenedor principal */
    transition: width .25s ease;
    z-index: 1000;
    border-top-right-radius: 12px;
    border-bottom-right-radius: 12px;
    box-shadow: 2px 0 6px rgba(0, 0, 0, 0.08);
    display: flex;
    flex-direction: column;
}

/* Sidebar colapsado - completamente oculto */
body:not(.sidebar-expanded) #sidebar,
html:not(.sidebar-expanded) #sidebar {
    transform: translateX(-100%);
    width: 240px;
}

/* Sidebar expandido */
body.sidebar-expanded #sidebar,
html.sidebar-expanded #sidebar {
    transform: translateX(0);
    width: 240px;
}

/* Forzar posicionamiento correcto del sidebar debajo del navbar */
.sidebar, #sidebar {
    top: 0 !important;
    padding-top: var(--navbar-height) !important;
    z-index: 1000 !important;
    height: 100vh !important;
}

/* Header del sidebar */
.sidebar-header {
    padding: 25px 20px;
    text-align: center;
    border-bottom: 1px solid rgba(38, 65, 110, 0.1);
    background: rgba(38, 65, 110, 0.05);
    margin-top: calc(-1 * var(--navbar-height)); /* Compensa el padding-top del #sidebar */
    padding-top: calc(25px + var(--navbar-height));
}

.sidebar-header h2 {
    font-size: 1.4rem;
    font-weight: 600;
    color: var(--azul-primary);
    margin: 0;
    white-space: nowrap;
    overflow: hidden;
}

/* Ya no es necesario ocultar el texto - el sidebar completo desaparece */

/* Buscador del sidebar */
.sidebar-search {
    padding: 16px 12px 0;
    flex-shrink: 0;
}

.sidebar-search-label {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.sidebar-search-input-wrap {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 0 12px;
    min-height: 42px;
    border: 1px solid rgba(38, 65, 110, 0.14);
    border-radius: 12px;
    background: #f7f9fc;
    transition: border-color 0.18s ease, box-shadow 0.18s ease, background-color 0.18s ease;
}

.sidebar-search-input-wrap .material-icons {
    font-size: 20px;
    color: var(--gris-muted);
    flex-shrink: 0;
}

.sidebar-search-input-wrap:focus-within {
    border-color: rgba(38, 65, 110, 0.35);
    box-shadow: 0 0 0 3px rgba(38, 65, 110, 0.08);
    background: #fff;
}

.sidebar-search-input {
    width: 100%;
    border: 0;
    outline: 0;
    background: transparent;
    color: var(--gris-text);
    font: inherit;
    padding: 10px 0;
}

.sidebar-search-input::placeholder {
    color: var(--gris-muted);
}

/* ═══════════════════════════════════════════════════════════
   NAVEGACIÓN DEL SIDEBAR
   ═══════════════════════════════════════════════════════════ */
#sidebar .navlist,
.sidebar-menu {
    margin: 0;
    padding: 12px 0 20px;
    list-style: none;
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    min-height: 0;
    max-height: calc(100vh - var(--navbar-height) - 92px); /* Altura máxima calculada */
}

#sidebar .navlist li,
.sidebar-menu li {
    margin: 4px 8px;
}

#sidebar .navlist li > a,
.sidebar-menu a {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    padding: 10px 14px;
    border-radius: var(--radius-lg);
    background: transparent;
    color: var(--gris-text);
    text-decoration: none;
    transition: all 0.18s ease;
    white-space: nowrap;
    overflow: hidden;
    font-family: inherit;
    font-size: 0.9rem;
    font-weight: var(--font-weight-base);
}

#sidebar .navlist li > a .material-icons,
.sidebar-menu a i {
    font-size: 1.714em;
    line-height: 1;
    margin-right: 12px;
    width: 24px;
    text-align: center;
    flex-shrink: 0;
    color: var(--gris-muted);
}

#sidebar .navlist li > a .text,
.sidebar-menu a .text {
    font: inherit;
}

#sidebar .navlist li > a:hover,
#sidebar .navlist li > a.active,
.sidebar-menu a:hover,
.sidebar-menu a.active {
    background: var(--azul-light);
    color: var(--azul-primary);
}

#sidebar .navlist li > a:hover .material-icons,
#sidebar .navlist li > a.active .material-icons,
.sidebar-menu a:hover i,
.sidebar-menu a.active i {
    color: var(--azul-primary);
}

/* Ya no es necesario ocultar el texto - el sidebar completo desaparece */

/* ═══════════════════════════════════════════════════════════
   SIDEBAR FOOTER
   ═══════════════════════════════════════════════════════════ */
.sidebar-footer {
    position: relative;
    width: 100%;
    padding: 20px 0;
    border-top: 1px solid rgba(38, 65, 110, 0.1);
    flex-shrink: 0;
}

.logout-link {
    display: flex !important;
    align-items: center;
    color: var(--danger-color) !important;
    text-decoration: none;
    padding: 10px 14px;
    margin: 0 8px;
    border-radius: var(--radius-lg);
    transition: all 0.18s ease;
    font-size: 0.95em;
    gap: 12px;
    white-space: nowrap;
    overflow: hidden;
}

.logout-link:hover {
    background-color: var(--danger-bg);
    color: var(--danger-color) !important;
}

.logout-link i {
    font-size: 1.714em;
    width: 24px;
    text-align: center;
    flex-shrink: 0;
}

/* Ya no es necesario ocultar el texto - el sidebar completo desaparece */

/* ═══════════════════════════════════════════════════════════
   CONTENIDO PRINCIPAL - Compatible con tu sistema
   ═══════════════════════════════════════════════════════════ */
.contenido {
    margin-top: var(--navbar-height);
    padding: 30px;
    transition: margin-left .15s ease;
    min-height: calc(100vh - var(--navbar-height));
    background-color: white;
}

/* Ajuste del contenido según estado del sidebar */
body:not(.sidebar-expanded) .contenido,
html:not(.sidebar-expanded) .contenido {
    margin-left: 0;  /* sidebar oculto completamente */
}

body.sidebar-expanded .contenido,
html.sidebar-expanded .contenido {
    margin-left: 240px; /* sidebar expandido  */
}

/* ═══════════════════════════════════════════════════════════
   HEADERS DE CONTENIDO
   ═══════════════════════════════════════════════════════════ */
.content-header {
    margin-bottom: 30px;
    padding-bottom: 20px;
    border-bottom: 2px solid var(--gris-hover, #e2ebf7);
}

.content-header h1 {
    font-family: var(--font-family-base);
    color: var(--azul-primary);
    font-size: var(--font-size-title, 2.2rem);
    font-weight: 600;
    margin-bottom: 10px;
}

.content-header p {
    color: var(--gris-muted);
    font-size: 1.1rem;
}

/* ═══════════════════════════════════════════════════════════
   RESPONSIVE DESIGN
   ═══════════════════════════════════════════════════════════ */

/* Botón toggle para móviles (si lo necesitas) */
.menu-toggle {
    display: none;
    position: fixed;
    top: 70px; /* Debajo del navbar */
    left: 20px;
    z-index: 1001;
    background: var(--azul-primary);
    color: white;
    border: none;
    padding: 12px 15px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 1.2rem;
    box-shadow: 0 2px 10px rgba(0,0,0,0.2);
}

@media (max-width: 768px) {
    /* En móviles, el sidebar se comporta igual: oculto o expandido */
    body:not(.sidebar-expanded) .contenido {
        margin-left: 0;
    }
    
    body:not(.sidebar-expanded) #sidebar {
        transform: translateX(-100%);
        width: 240px;
    }

    body.sidebar-expanded #sidebar {
        transform: translateX(0);
        width: 240px;
    }
    
    body.sidebar-expanded .contenido {
        margin-left: 0; /* En móviles el contenido no se desplaza */
    }

    .contenido {
        padding: 20px 15px;
    }

    .menu-toggle {
        display: block;
    }

    .content-header h1 {
        font-size: 1.8rem;
    }
    
    /* Navbar ajustes móviles */
    .navbar {
        padding: 10px 15px;
    }
    
    .navbar ul {
        gap: 15px;
    }

    .nav-logo-item {
        max-width: min(120px, 38vw);
    }

    .nav-inst-logo {
        max-height: 32px;
        padding: 1px 4px;
    }
}

/* ═══════════════════════════════════════════════════════════
   SCROLLBAR PERSONALIZADO
   ═══════════════════════════════════════════════════════════ */
#sidebar::-webkit-scrollbar {
    width: 6px;
}

#sidebar::-webkit-scrollbar-track {
    background: rgba(38, 65, 110, 0.05);
}

#sidebar::-webkit-scrollbar-thumb {
    background: rgba(38, 65, 110, 0.2);
    border-radius: 3px;
}

#sidebar::-webkit-scrollbar-thumb:hover {
    background: rgba(38, 65, 110, 0.4);
}

/* Scrollbar para Firefox */
#sidebar {
    scrollbar-width: thin;
    scrollbar-color: rgba(38, 65, 110, 0.2) rgba(38, 65, 110, 0.05);
}

/* Asegurar que el scroll funcione */
#sidebar .navlist {
    max-height: calc(100vh - var(--navbar-height) - 92px); /* 100vh - navbar - buscador */
    overflow-y: auto;
    overflow-x: hidden;
}

/* Scrollbar personalizado para el navlist */
#sidebar .navlist::-webkit-scrollbar {
    width: 6px;
}

#sidebar .navlist::-webkit-scrollbar-track {
    background: rgba(38, 65, 110, 0.05);
}

#sidebar .navlist::-webkit-scrollbar-thumb {
    background: rgba(38, 65, 110, 0.2);
    border-radius: 3px;
}

#sidebar .navlist::-webkit-scrollbar-thumb:hover {
    background: rgba(38, 65, 110, 0.4);
}

/* Forzar scroll si hay muchos elementos */
#sidebar .navlist:has(li:nth-child(15)) {
    overflow-y: scroll;
}

/* ═══════════════════════════════════════════════════════════
   CLASES UTILITARIAS PARA COMPATIBILIDAD
   ═══════════════════════════════════════════════════════════ */

/* Para mantener compatibilidad con tu código existente */
.main-container {
    /* No necesario en tu sistema, pero por si lo usas */
    position: relative;
}

.main-content {
    margin-top: var(--navbar-height);
    padding: 30px;
    transition: margin-left .15s ease;
    min-height: calc(100vh - var(--navbar-height));
    background-color: white;
}

/* Estados del sidebar */
.sidebar.open {
    /* Para compatibilidad con sistemas que usen esta clase */
    width: 240px;
}

/* ═══════════════════════════════════════════════════════════
   VARIABLES CSS (si no las tienes definidas)
   ═══════════════════════════════════════════════════════════ */
:root {
    --azul: var(--azul-primary);
}

/* Colores para celdas de la tabla de datos SIMCE */
.celda-verde-suave {
  background: var(--success-bg) !important;
}
.celda-rojo-suave {
  background: var(--danger-bg) !important;
}
.celda-flex {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

/* Medallas para puntajes destacados */
.medalla {
  font-size: 1.2em;
  vertical-align: middle;
}
.medalla-oro { color: #FFD700; }
.medalla-plata { color: #C0C0C0; }
.medalla-bronce { color: #CD7F32; }
.medalla-azul { color: #60a5fa; }

/* ===================================================================
 * ESTILOS PARA BÚSQUEDA DE USUARIOS EN ENCUESTAS
 * =================================================================== */

.usuarios-autocomplete {
    position: relative;
    margin-bottom: 20px;
}

.usuarios-resultados {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: white;
    border: 1px solid var(--gris-border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    max-height: 300px;
    overflow-y: auto;
    z-index: 1000;
    margin-top: 2px;
}

.usuario-resultado {
    padding: 12px 16px;
    border-bottom: 1px solid var(--gris-table);
    cursor: pointer;
    transition: background-color 0.2s ease;
}

.usuario-resultado:hover {
    background-color: var(--gris-fondo);
}

.usuario-resultado:last-child {
    border-bottom: none;
}

.usuario-nombre-resultado {
    font-weight: 600;
    color: var(--gris-text);
    margin-bottom: 4px;
}

.usuario-detalles {
    font-size: 0.9em;
    color: var(--gris-muted);
    line-height: 1.4;
}

.usuario-estado {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 0.75em;
    font-weight: 600;
    text-transform: uppercase;
    margin-left: 8px;
}

.usuario-estado.activo {
    background-color: var(--success-bg);
    color: var(--success-color);
}

.usuario-estado.inactivo {
    background-color: var(--danger-bg);
    color: var(--danger-color);
}

.usuarios-seleccionados {
    margin-top: 20px;
}

.usuarios-lista {
    max-height: 300px;
    overflow-y: auto;
    border: 1px solid var(--gris-border);
    border-radius: var(--radius-md);
    padding: 8px;
    background: var(--gris-fondo);
}

.usuario-seleccionado {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 12px;
    background: white;
    border: 1px solid var(--gris-border);
    border-radius: var(--radius-sm);
    margin-bottom: 8px;
}

.usuario-seleccionado:last-child {
    margin-bottom: 0;
}

.usuario-info {
    flex: 1;
}

.usuario-nombre {
    display: block;
    font-weight: 600;
    color: var(--gris-text);
    margin-bottom: 2px;
}

.usuario-detalles {
    font-size: 0.85em;
    color: var(--gris-muted);
}

.usuario-remove {
    background: var(--danger-color);
    color: white;
    border: none;
    border-radius: 50%;
    width: 24px;
    height: 24px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    font-weight: bold;
    transition: background-color 0.2s ease;
}

.usuario-remove:hover {
    background: var(--danger-color);
    filter: brightness(0.85);
}

/* Estilos para mensajes de error en la búsqueda */
.usuario-resultado[style*="color: #dc3545"] {
    background-color: var(--danger-bg);
    border-left: 4px solid var(--danger-color);
    font-weight: 500;
}

/* Responsive para móviles */
@media (max-width: 768px) {
    .usuarios-resultados {
        position: fixed;
        top: 50%;
        left: 20px;
        right: 20px;
        max-height: 60vh;
        transform: translateY(-50%);
    }
    
    .usuario-resultado {
        padding: 16px;
    }
    
    .usuario-seleccionado {
        flex-direction: column;
        align-items: flex-start;
        gap: 8px;
    }
    
    .usuario-remove {
        align-self: flex-end;
    }
}
