/* ==========================================================================
   Custom UI — Sistema de Diseño Unificado SAGE (Nivel Superior)
   Tokens, Componentes Nativos, Segmented Control & Icon Sprite
   ========================================================================== */

:root {
  /* 1. Fondos y Superficies (Slate / Azul suave - Sin blancos ni grises planos) */
  --bg-main: #f0f4f8;          /* Fondo base azul suave */
  --bg-surface: #ffffff;       /* Fondo de tarjetas y contenedores */
  --bg-subtle: #f1f5f9;        /* Fondos secundarios, hovers de filas y pill bars */
  --border-color: #cbd5e1;     /* Borde azul-gris definido */
  --border-light: #e2e8f0;     /* Borde sutil interno */

  /* 2. Paleta de Azules */
  --primary-50:  #eff6ff;
  --primary-100: #dbeafe;      /* Halos de foco, fondos de badges */
  --primary-200: #bfdbfe;
  --primary-500: #3b82f6;      /* Azul vibrante */
  --primary-600: #2563eb;      /* Azul principal */
  --primary-700: #1d4ed8;
  --primary-800: #1e40af;      /* Hover de botones */
  --primary-900: #1e3a8a;      /* Azul institucional SAGE */

  /* 3. Estados y Alertas */
  --danger-color: #dc2626;
  --danger-hover: #b91c1c;
  --danger-bg: #fee2e2;
  --danger-border: #fecaca;

  --success-color: #15803d;
  --success-bg: #dcfce7;
  --success-border: #bbf7d0;

  --warning-color: #b45309;
  --warning-bg: #fef3c7;
  --warning-border: #fde68a;

  /* 4. Texto */
  --text-primary: #0f172a;     /* Slate muy oscuro para alto contraste */
  --text-secondary: #475569;   /* Slate medio para etiquetas y subtítulos */
  --text-muted: #64748b;       /* Slate suave para placeholders y metadata */

  /* 5. Geometría y Sombras */
  --border-radius-sm: 4px;
  --border-radius-md: 6px;
  --border-radius-lg: 10px;
  --border-radius-xl: 12px;

  --shadow-sm: 0 1px 3px rgba(15, 23, 42, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(15, 23, 42, 0.07), 0 2px 4px -1px rgba(15, 23, 42, 0.04);
  --shadow-lg: 0 10px 15px -3px rgba(15, 23, 42, 0.08);

  /* 6. Fuentes y Transiciones */
  --font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --transition-fast: 0.15s ease-in-out;
  --transition-normal: 0.25s ease;
}

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

body {
  font-family: var(--font-family);
  background-color: var(--bg-main);
  color: var(--text-primary);
  line-height: 1.5;
  min-height: 100vh;
  padding: 24px 16px;
}

/* ==========================================================================
   Iconografía Centralizada (SVG Sprite)
   ========================================================================== */
.icon {
  width: 1.1em;
  height: 1.1em;
  display: inline-block;
  vertical-align: -0.2em;
  stroke: currentColor;
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex-shrink: 0;
}

/* ==========================================================================
   Contenedor Principal y Tarjetas
   ========================================================================== */
.container {
  max-width: 1280px;
  margin: 0 auto;
  padding: 0 16px;
  box-sizing: border-box;
}

/* Encabezados Institucionales Responsive */
.app-header,
.portal-header {
  background: var(--bg-surface);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
  padding: 16px 22px;
  border-radius: var(--border-radius-lg);
  margin-bottom: 20px;
  box-shadow: var(--shadow-sm);
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 16px;
  box-sizing: border-box;
  width: 100%;
}

.header-brand,
.portal-brand {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}

.header-logo,
.portal-logo {
  height: 38px;
  width: auto;
  max-width: 280px;
  object-fit: contain;
}

.header-title-block,
.portal-title-block {
  border-left: 1px solid var(--border-color);
  padding-left: 16px;
}

.header-title-block h1,
.portal-title-block h1 {
  font-size: 1.25rem;
  font-weight: 800;
  color: var(--primary-900);
  margin: 0;
  line-height: 1.2;
}

.header-title-block p,
.portal-title-block p {
  font-size: 0.82rem;
  color: var(--text-secondary);
  margin: 3px 0 0 0;
}

.header-actions,
.portal-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.portal-badge-pub {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--primary-50);
  color: var(--primary-800);
  border: 1px solid var(--primary-200);
  padding: 6px 14px;
  border-radius: 9999px;
  font-size: 0.82rem;
  font-weight: 700;
  letter-spacing: 0.02em;
}

@media (max-width: 820px) {
  .app-header,
  .portal-header {
    padding: 14px 16px;
    flex-direction: column;
    align-items: stretch;
    gap: 14px;
  }

  .header-brand,
  .portal-brand {
    flex-direction: column;
    align-items: flex-start;
    gap: 10px;
    width: 100%;
  }

  .header-logo,
  .portal-logo {
    height: 32px;
    max-width: 220px;
  }

  .header-title-block,
  .portal-title-block {
    border-left: none;
    border-top: 1px solid var(--border-color);
    padding-left: 0;
    padding-top: 8px;
    width: 100%;
  }

  .header-title-block h1,
  .portal-title-block h1 {
    font-size: 1.15rem;
  }

  .header-actions,
  .portal-actions {
    width: 100%;
    flex-direction: column;
    align-items: stretch;
  }

  .header-actions .btn,
  .header-actions .badge-status,
  .portal-actions .portal-badge-pub {
    width: 100%;
    justify-content: center;
    text-align: center;
    box-sizing: border-box;
  }
}

.card {
  background-color: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius-xl);
  box-shadow: var(--shadow-md);
  padding: 24px;
  margin-bottom: 24px;
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border-light);
  flex-wrap: wrap;
  gap: 12px;
}

.card-header h2 {
  font-size: 1.35rem;
  font-weight: 700;
  color: var(--primary-900);
  display: flex;
  align-items: center;
  gap: 10px;
}

.card-header p {
  color: var(--text-secondary);
  font-size: 0.9rem;
}

/* ==========================================================================
   Segmented Control / Pill Tabs (Navegación entre submódulos)
   ========================================================================== */
.subtabs-container {
  display: inline-flex;
  align-items: center;
  background-color: var(--bg-subtle);
  padding: 5px;
  border-radius: var(--border-radius-lg);
  border: 1px solid var(--border-color);
  margin-bottom: 24px;
  gap: 6px;
  user-select: none;
}

.subtab-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: transparent;
  border: none;
  border-radius: 7px;
  padding: 10px 22px;
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--text-secondary);
  cursor: pointer;
  outline: none;
  transition: all 0.18s cubic-bezier(0.4, 0, 0.2, 1);
  white-space: nowrap;
}

.subtab-btn:hover {
  color: var(--text-primary);
  background-color: rgba(255, 255, 255, 0.65);
}

.subtab-btn.active {
  background-color: #ffffff;
  color: var(--primary-900);
  font-weight: 600;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08), 0 1px 2px rgba(0, 0, 0, 0.04);
}

.subtab-btn.active .icon {
  stroke: var(--primary-600);
}

@media (max-width: 768px) {
  .subtabs-container {
    display: flex;
    flex-direction: column;
    width: 100%;
    box-sizing: border-box;
    padding: 6px;
    gap: 6px;
  }

  .subtab-btn {
    width: 100%;
    justify-content: center;
    padding: 11px 16px;
    box-sizing: border-box;
    white-space: normal;
    text-align: center;
    font-size: 0.88rem;
  }
}

/* ==========================================================================
   Tablas y Filtros
   ========================================================================== */
.table-container {
  overflow-x: auto;
  border: 1px solid var(--border-light);
  border-radius: var(--border-radius-lg);
  background: #ffffff;
  position: relative;
  min-height: 200px;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
  text-align: left;
}

thead {
  background-color: var(--bg-subtle);
  border-bottom: 2px solid var(--border-color);
}

th {
  padding: 12px 14px;
  font-weight: 600;
  color: var(--text-secondary);
  white-space: nowrap;
}

td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border-light);
  color: var(--text-primary);
  vertical-align: middle;
}

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

.table-filter-row th {
  padding: 6px 10px;
  background-color: #f8fafc;
}

.col-filter-input {
  width: 100%;
  padding: 6px 10px;
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius-sm);
  font-size: 0.8rem;
  outline: none;
  background-color: #ffffff;
}

.col-filter-input:focus {
  border-color: var(--primary-500);
  box-shadow: 0 0 0 2px var(--primary-100);
}

.col-filter-wrapper {
  position: relative;
  display: flex;
  align-items: center;
  width: 100%;
}

.col-filter-wrapper .icon {
  position: absolute;
  left: 7px;
  width: 0.85em;
  height: 0.85em;
  color: var(--text-muted);
  pointer-events: none;
  transition: color var(--transition-fast);
}

.col-filter-wrapper:focus-within .icon {
  color: var(--primary-600);
}

.col-filter-wrapper .col-filter-input {
  padding-left: 24px;
}

/* ==========================================================================
   Badges Semánticos con Punto Indicador
   ========================================================================== */
.badge-status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 12px;
  font-size: 0.78rem;
  font-weight: 600;
  line-height: 1.2;
  white-space: nowrap;
}

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

.badge-status-active::before {
  content: '';
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background-color: #16a34a;
  flex-shrink: 0;
}

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

.badge-status-inactive::before {
  content: '';
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background-color: #dc2626;
  flex-shrink: 0;
}

/* ==========================================================================
   Botones y Acciones
   ========================================================================== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 9px 18px;
  font-size: 0.875rem;
  font-weight: 600;
  font-family: inherit;
  border-radius: var(--border-radius-md);
  border: 1px solid transparent;
  cursor: pointer;
  transition: all var(--transition-fast);
  text-decoration: none;
}

.btn-primary {
  background-color: var(--primary-600);
  color: #ffffff;
}

.btn-primary:hover {
  background-color: var(--primary-700);
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
}

.btn-secondary {
  background-color: var(--bg-surface);
  color: var(--text-secondary);
  border-color: var(--border-color);
}

.btn-secondary:hover {
  background-color: var(--bg-subtle);
  color: var(--text-primary);
}

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

.btn-success:hover {
  background-color: #166534;
}

.action-btn {
  background: transparent;
  border: none;
  cursor: pointer;
  font-size: 0.85rem;
  padding: 6px 10px;
  border-radius: var(--border-radius-md);
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-weight: 500;
  transition: all var(--transition-fast);
}

.btn-action-toggle-on {
  color: var(--success-color);
  background-color: var(--success-bg);
  border: 1.5px solid var(--success-border);
}

.btn-action-toggle-on:hover {
  background-color: #bbf7d0;
}

.btn-action-toggle-off {
  color: var(--danger-color);
  background-color: var(--danger-bg);
  border: 1.5px solid var(--danger-border);
}

.btn-action-toggle-off:hover {
  background-color: #fecaca;
}

/* ==========================================================================
   Formularios y Preinscripción
   ========================================================================== */
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 20px;
  margin-bottom: 24px;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.form-label {
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  color: var(--text-secondary);
}

.form-input, .form-select {
  width: 100%;
  box-sizing: border-box;
  padding: 10px 14px;
  border: 1.5px solid var(--border-color);
  border-radius: var(--border-radius-md);
  font-size: 0.95rem;
  font-family: inherit;
  color: var(--text-primary);
  background-color: #ffffff;
  outline: none;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
  line-height: 1.5;
}

.form-select {
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
  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='%23475569' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
  background-size: 16px 16px;
  padding-right: 42px;
  cursor: pointer;
  text-overflow: ellipsis;
}

.form-input:focus, .form-select:focus {
  border-color: var(--primary-600);
  box-shadow: 0 0 0 3px var(--primary-100);
}

.form-input::placeholder {
  color: var(--text-muted);
}

.form-input-lg {
  padding: 12px 18px;
  font-size: 1.05rem;
  height: 48px;
  border-radius: 8px;
}

/* Carreras Slots (Máximo 3) */
.carreras-slot-container {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin: 16px 0 24px 0;
}

.carrera-slot {
  display: flex;
  align-items: center;
  gap: 14px;
  background-color: var(--bg-subtle);
  border: 1.5px dashed var(--border-color);
  border-radius: var(--border-radius-lg);
  padding: 12px 18px;
  transition: all var(--transition-fast);
}

.carrera-slot.selected {
  background-color: #ffffff;
  border-style: solid;
  border-color: var(--primary-200);
  box-shadow: var(--shadow-sm);
}

.slot-priority-badge {
  background-color: var(--primary-100);
  color: var(--primary-800);
  font-weight: 700;
  font-size: 0.8rem;
  padding: 4px 10px;
  border-radius: 6px;
  white-space: nowrap;
}

.slot-content {
  flex: 1;
}

/* Modal y Popovers */
.modal-overlay {
  position: fixed;
  inset: 0;
  background-color: rgba(15, 23, 42, 0.5);
  backdrop-filter: blur(2px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 999;
  padding: 20px;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.2s ease;
}

.modal-overlay.active {
  opacity: 1;
  visibility: visible;
}

.modal-card {
  background: #ffffff;
  border-radius: var(--border-radius-xl);
  box-shadow: var(--shadow-lg);
  max-width: 580px;
  width: 100%;
  padding: 32px;
  border: 1px solid var(--border-color);
  transform: translateY(10px);
  transition: transform 0.2s ease;
}

.modal-overlay.active .modal-card {
  transform: translateY(0);
}

.code-input-container {
  display: flex;
  justify-content: center;
  margin: 24px 0;
}

.code-input {
  font-size: 2rem;
  letter-spacing: 8px;
  text-align: center;
  width: 240px;
  padding: 10px;
  border: 2px solid var(--primary-500);
  border-radius: 8px;
  font-weight: 700;
  color: var(--primary-800);
  outline: none;
}

.code-input:focus {
  box-shadow: 0 0 0 4px var(--primary-100);
}

/* Loading Overlay */
.table-loading-overlay {
  position: absolute;
  inset: 0;
  background: rgba(255, 255, 255, 0.75);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 10;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s ease;
}

.table-loading-overlay.active {
  opacity: 1;
  pointer-events: auto;
}

.spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--border-light);
  border-top-color: var(--primary-600);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

/* Paginación */
.pagination-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 16px;
  padding-top: 6px;
  font-size: 0.85rem;
  color: var(--text-secondary);
}

.pagination-info {
  color: var(--text-secondary);
  font-weight: 500;
  white-space: nowrap;
}

.pagination-controls {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: nowrap;
}

.pagination-controls .btn {
  height: 32px;
  padding: 0 12px;
  font-size: 0.82rem;
  white-space: nowrap;
  line-height: 1;
  display: inline-flex;
  align-items: center;
}

.pagination-controls select {
  height: 32px;
  padding: 0 8px;
  font-size: 0.82rem;
  border-radius: var(--border-radius-sm);
  border: 1px solid var(--border-color);
  background: var(--bg-surface);
  color: var(--text-primary);
}

.page-current-indicator,
#page-current,
#preinscriptos-page-current {
  font-weight: 600;
  padding: 0 10px;
  white-space: nowrap;
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  color: var(--text-primary);
  line-height: 1;
}

@media (max-width: 768px) {
  .pagination-bar {
    flex-direction: column;
    align-items: center;
    text-align: center;
    gap: 12px;
  }

  .pagination-info {
    white-space: normal;
  }

  .pagination-controls {
    flex-wrap: wrap;
    justify-content: center;
  }
}

/* ==========================================================================
   Toast Notifications (Custom UI Native Toast)
   ========================================================================== */
.toast-container {
  position: fixed;
  top: 24px;
  right: 24px;
  z-index: 10000;
  display: flex;
  flex-direction: column;
  gap: 12px;
  pointer-events: none;
  max-width: calc(100vw - 32px);
}

.toast {
  pointer-events: auto;
  min-width: 300px;
  max-width: 440px;
  padding: 12px 16px;
  background-color: var(--bg-surface);
  border-radius: var(--border-radius-md);
  box-shadow: var(--shadow-lg);
  display: flex;
  align-items: flex-start;
  gap: 12px;
  font-size: 0.9rem;
  line-height: 1.4;
  color: var(--text-primary);
  border: 1px solid var(--border-color);
  animation: toastSlideIn 0.25s cubic-bezier(0.16, 1, 0.3, 1);
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.toast.toast-hiding {
  opacity: 0;
  transform: translateY(-8px) scale(0.96);
}

.toast-icon {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
  margin-top: 2px;
}

.toast-content {
  flex: 1;
}

.toast-close {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-muted);
  font-size: 1.2rem;
  line-height: 1;
  padding: 0 4px;
  border-radius: 4px;
  transition: color var(--transition-fast);
}

.toast-close:hover {
  color: var(--text-primary);
}

.toast-success {
  border-left: 4px solid var(--success-color);
}
.toast-success .toast-icon {
  color: var(--success-color);
}

.toast-error {
  border-left: 4px solid var(--danger-color);
}
.toast-error .toast-icon {
  color: var(--danger-color);
}

.toast-warning {
  border-left: 4px solid var(--warning-color);
}
.toast-warning .toast-icon {
  color: var(--warning-color);
}

.toast-info {
  border-left: 4px solid var(--primary-600);
}
.toast-info .toast-icon {
  color: var(--primary-600);
}

@keyframes toastSlideIn {
  from {
    opacity: 0;
    transform: translateY(-12px) scale(0.95);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

/* ==========================================================================
   Searchable Combobox / Autocomplete Dropdown
   ========================================================================== */
.autocomplete-wrapper {
  position: relative;
  width: 100%;
}

.autocomplete-dropdown {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  z-index: 1000;
  background-color: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius-md);
  box-shadow: 0 10px 25px -5px rgba(15, 23, 42, 0.15), 0 8px 10px -6px rgba(15, 23, 42, 0.1);
  max-height: 320px;
  overflow-y: auto;
}

.autocomplete-item {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border-light);
  cursor: pointer;
  transition: background var(--transition-fast);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.autocomplete-item:last-child {
  border-bottom: none;
}

.autocomplete-item:hover,
.autocomplete-item.active {
  background-color: var(--primary-50);
}

.autocomplete-item.disabled {
  opacity: 0.55;
  cursor: not-allowed;
  background-color: var(--bg-subtle);
}

.autocomplete-item-title {
  font-weight: 700;
  color: var(--primary-950);
  font-size: 0.9rem;
  line-height: 1.3;
}

.autocomplete-item-meta {
  font-size: 0.78rem;
  color: var(--text-secondary);
  margin-top: 2px;
}

.autocomplete-item-action {
  font-size: 0.75rem;
  font-weight: 700;
  padding: 3px 10px;
  border-radius: 9999px;
  background: var(--primary-100);
  color: var(--primary-800);
  white-space: nowrap;
  flex-shrink: 0;
}

.autocomplete-item.disabled .autocomplete-item-action {
  background: var(--border-light);
  color: var(--text-muted);
}


