/* ================================================================
   CSS PRINCIPAL MODERNO - SISTEMA RAIGA
   ================================================================
   
   Layout Grid modernizado con sidebar oscura + Variables tema
   Responsive design optimizado para dispositivos móviles y desktop
   
   Áreas del layout:
   - Cabecera: Header superior limpio
   - Lateral: Sidebar oscura navegacional (ancho fijo)
   - Principal: Contenido principal (flexible)
   - Auxiliar: Panel contextual (opcional)
   
================================================================ */

/* Zoom global al 80% para la aplicación */
body {
  zoom: 80%;
  /* O alternativamente: */
  /* transform: scale(0.8);
  transform-origin: 0 0; */
}

/* ================================================================
   VARIABLES CSS GLOBALES MODERNIZADAS
================================================================ */
:root {
  /* Paleta de colores moderna */
  --raiga-primary: #2563eb;
  --raiga-primary-dark: #1d4ed8;
  --raiga-primary-light: #3b82f6;
  --raiga-secondary: #64748b;
  --raiga-accent: #0ea5e9;
  
  /* Sidebar moderna (oscura) */
  --sidebar-bg: #1e293b;
  --sidebar-bg-light: #334155;
  --sidebar-text: #cbd5e1;
  --sidebar-text-muted: #94a3b8;
  --sidebar-border: rgba(255, 255, 255, 0.1);
  --sidebar-hover: #334155;
  --sidebar-active: var(--raiga-primary);
  
  /* Fondos principales */
  --bg-primary: #ffffff;
  --bg-secondary: #f8fafc;
  --bg-tertiary: #f1f5f9;
  --bg-card: #ffffff;
  
  /* Header moderno */
  --header-bg: #ffffff;
  --header-border: #e2e8f0;
  --header-shadow: 0 1px 3px 0 rgb(0 0 0 / 0.1);
  
  /* Bordes y líneas suaves */
  --border-light: #e2e8f0;
  --border-medium: #cbd5e1;
  --border-dark: #94a3b8;
  
  /* Texto */
  --text-primary: #1e293b;
  --text-secondary: #64748b;
  --text-muted: #94a3b8;
  --text-white: #ffffff;
  
  /* Títulos */
  --title-primary: #1e293b;
  --title-secondary: var(--raiga-primary);
  --title-tertiary: #0f172a;
  
  /* Estados */
  --success-bg: #22c55e;
  --success-text: #ffffff;
  --success-light: #dcfce7;
  --error-bg: #ef4444;
  --error-text: #ffffff;
  --error-light: #fef2f2;
  --warning-bg: #f59e0b;
  --warning-text: #ffffff;
  --warning-light: #fef3c7;
  --info-bg: var(--raiga-primary);
  --info-text: #ffffff;
  --info-light: #dbeafe;
  
  /* Hover y focus modernos */
  --hover-bg: #f8fafc;
  --hover-border: var(--raiga-primary);
  --focus-ring: var(--raiga-primary);
  --focus-ring-alpha: rgba(37, 99, 235, 0.1);
  
  /* Sombras modernas */
  --shadow-xs: 0 1px 2px 0 rgb(0 0 0 / 0.05);
  --shadow-sm: 0 1px 3px 0 rgb(0 0 0 / 0.1);
  --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1);
  --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1);
  --shadow-xl: 0 20px 25px -5px rgb(0 0 0 / 0.1);
  
  /* Tamaños del layout */
  --ancho-lateral: 280px;
  --ancho-auxiliar: 320px;
  --alto-cabecera: 120px;
  --gap-principal: 32px;
  
  /* Breakpoints responsive */
  --mobile-max: 768px;
  --tablet-max: 1024px;
  --desktop-min: 1025px;
  
  /* Transiciones suaves */
  --transition-fast: 150ms cubic-bezier(0.4, 0, 0.2, 1);
  --transition-normal: 250ms cubic-bezier(0.4, 0, 0.2, 1);
  --transition-slow: 350ms cubic-bezier(0.4, 0, 0.2, 1);
  
  /* Tipografía moderna */
  --font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  --font-mono: 'SF Mono', 'Monaco', 'Consolas', 'Roboto Mono', monospace;
  
  /* Radios de borde modernos */
  --radius-xs: 4px;
  --radius-sm: 6px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --radius-xl: 16px;
  --radius-full: 9999px;
  
  /* Z-index layers */
  --z-dropdown: 1000;
  --z-sticky: 1010;
  --z-fixed: 1020;
  --z-modal-backdrop: 1030;
  --z-modal: 1040;
  --z-popover: 1050;
  --z-tooltip: 1060;
}

/* ================================================================
   RESET Y BASE STYLES MODERNOS
================================================================ */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 16px;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  scroll-behavior: smooth;
}

body {
  font-family: var(--font-family);
  background-color: var(--bg-secondary);
  color: var(--text-primary);
  overflow-x: hidden;
  min-height: 100vh;
}

/* ================================================================
   SOPORTE RTL MEJORADO
================================================================ */
[dir="rtl"] {
  text-align: right;
}

[dir="rtl"] .grid-container {
  grid-template-areas:
    "cabecera cabecera cabecera"
    "auxiliar principal lateral";
  grid-template-columns: var(--ancho-auxiliar) 1fr var(--ancho-lateral);
}

[dir="rtl"] .area-lateral {
  border-left: 1px solid var(--sidebar-border);
  border-right: none;
}

[dir="rtl"] .area-auxiliar {
  border-right: 1px solid var(--border-light);
  border-left: none;
}

/* ================================================================
   LAYOUT GRID MODERNO
================================================================ */
.grid-container {
  display: grid;
  grid-template-areas:
    "cabecera cabecera cabecera"
    "logos logos logos"
    "lateral principal auxiliar";
  grid-template-columns: var(--ancho-lateral) 1fr var(--ancho-auxiliar);
  grid-template-rows: var(--alto-cabecera) auto 1fr;
  min-height: 100vh;
  gap: 0;
  background: var(--bg-secondary);
}

/* ================================================================
   ÁREA CABECERA MODERNA
================================================================ */
.area-cabecera {
  grid-area: cabecera;
  background: var(--header-bg);
  color: var(--text-primary);
  border-bottom: 1px solid var(--header-border);
  box-shadow: var(--header-shadow);
  z-index: var(--z-sticky);
  position: sticky;
  top: 0;
  
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 2.5rem 2.5rem;
}

.cabecera-izquierda {
  display: flex;
  align-items: center;
  gap: 24px;
}

.logo-sistema {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--title-primary);
  text-decoration: none;
  display: flex;
  align-items: center;
  gap: 16px;
}

.icono-logo {
  height: 90px;      /* Altura del logo - aumenta este número */
  width: auto;       /* Mantiene proporción */
  object-fit: contain; /* Evita deformación */
}

.logo-sistema:hover {
  color: var(--raiga-primary);
  transition: var(--transition-fast);
}

.titulo-modulo {
  font-size: 1.125rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-left: 24px;
  position: relative;
}

.titulo-modulo::before {
  content: '›';
  position: absolute;
  left: -16px;
  color: var(--text-muted);
  font-weight: 400;
}

.cabecera-derecha {
  display: flex;
  align-items: center;
  gap: 32px;
}

.info-usuario {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 0.875rem;
  color: var(--text-secondary);
  padding: 8px 16px;
  border-radius: var(--radius-lg);
  background: var(--bg-secondary);
  border: 1px solid var(--border-light);
}

.info-sesion {
  display: flex;
  flex-direction: column;
  text-align: right;
  font-size: 0.75rem;
  line-height: 1.3;
  color: var(--text-muted);
}

/* ================================================================
   BARRA DE LOGOS INSTITUCIONALES
================================================================ */
.barra-logos-institucionales {
  grid-area: logos;  /* ✅ Asigna al área del grid */
  width: 100%;
  background-color: #f8f9fa;
  padding: 10px 20px;
  display: flex;
  justify-content: center;
  align-items: center;
  border-bottom: 1px solid #e0e0e0;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);  /* ✅ Coma corregida */
}

.logos-institucionales {
  max-width: 100%;
  height: auto;
  max-height: 85px;
  object-fit: contain;
}

/* ================================================================
   ÁREA LATERAL MODERNA (SIDEBAR OSCURA)
================================================================ */
.area-lateral {
  grid-area: lateral;
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  border-right: 1px solid var(--sidebar-border);
  overflow-y: auto;
  overflow-x: hidden;
  display: flex;
  flex-direction: column;
}

/* Header del sidebar */
.sidebar-header {
  padding: var(--gap-principal);
  border-bottom: 1px solid var(--sidebar-border);
  flex-shrink: 0;
}

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 12px;
  text-decoration: none;
  color: var(--text-white);
}

.sidebar-logo h1 {
  font-size: 1.5rem;
  font-weight: 700;
  margin: 0;
}

.sidebar-subtitle {
  font-size: 0.875rem;
  color: var(--sidebar-text-muted);
  margin-top: 4px;
}

/* Navegación del sidebar */
.sidebar-nav {
  flex: 1;
  padding: var(--gap-principal);
  overflow-y: auto;
}

.menu-modulos {
  list-style: none;
  margin: 0;
  padding: 0;
}

.nav-section {
  margin-bottom: 32px;
}

.nav-section-title {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  color: var(--sidebar-text-muted);
  margin-bottom: 12px;
  letter-spacing: 0.05em;
  padding: 0 12px;
}

.item-modulo {
  margin-bottom: 4px;
}

.enlace-modulo {
  display: flex;
  align-items: center;
  padding: 12px 16px;
  color: var(--sidebar-text);
  text-decoration: none;
  border-radius: var(--radius-md);
  transition: var(--transition-fast);
  font-weight: 500;
  gap: 12px;
  font-size: 0.875rem;
}

.enlace-modulo:hover {
  background: var(--sidebar-hover);
  color: var(--text-white);
}

.enlace-modulo.activo {
  background: var(--sidebar-active);
  color: var(--text-white);
  box-shadow: var(--shadow-sm);
  font-weight: 600;
}

.icono-modulo {
  width: 20px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.125rem;
  opacity: 0.8;
}

.enlace-modulo.activo .icono-modulo {
  opacity: 1;
}

/* Contador en sidebar */
.contador-modulo {
  margin-left: auto;
  background: var(--sidebar-text-muted);
  color: var(--sidebar-bg);
  font-size: 0.7rem;
  padding: 2px 6px;
  border-radius: var(--radius-full);
  min-width: 18px;
  text-align: center;
  font-weight: 600;
}

.enlace-modulo.activo .contador-modulo {
  background: rgba(255, 255, 255, 0.3);
  color: var(--text-white);
}

/* Footer del sidebar */
.sidebar-footer {
  padding: var(--gap-principal);
  border-top: 1px solid var(--sidebar-border);
  flex-shrink: 0;
}

.connection-status {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px;
  border-radius: var(--radius-md);
  background: rgba(255, 255, 255, 0.05);
  font-size: 0.75rem;
}

.status-indicator {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.status-indicator.connected {
  background: var(--success-bg);
}

.status-indicator.error {
  background: var(--error-bg);
}

.status-indicator.warning {
  background: var(--warning-bg);
}

/* ================================================================
   ÁREA PRINCIPAL MODERNA
================================================================ */
.area-principal {
  grid-area: principal;
  background: var(--bg-primary);
  padding: var(--gap-principal);
  overflow-y: auto;
  min-height: 0;
}

.contenido-principal {
  max-width: 100%;
  height: 100%;
}

/* ================================================================
   ÁREA AUXILIAR MODERNA (OPCIONAL)
================================================================ */
.area-auxiliar {
  grid-area: auxiliar;
  background: var(--bg-secondary);
  border-left: 1px solid var(--border-light);
  padding: var(--gap-principal);
  overflow-y: auto;
}

.panel-auxiliar {
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-lg);
  padding: 20px;
  margin-bottom: 20px;
  box-shadow: var(--shadow-sm);
}

.titulo-panel {
  font-size: 1rem;
  font-weight: 600;
  color: var(--title-primary);
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border-light);
}

/* ================================================================
   COMPONENTES MODERNOS
================================================================ */

/* Botones modernos */
.boton {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 10px 20px;
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  font-size: 0.875rem;
  font-weight: 500;
  line-height: 1.5;
  text-decoration: none;
  cursor: pointer;
  transition: var(--transition-fast);
  gap: 8px;
  white-space: nowrap;
}

.boton:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none !important;
}

.boton-primario {
  background: var(--raiga-primary);
  color: var(--text-white);
  border-color: var(--raiga-primary);
  box-shadow: var(--shadow-sm);
}

.boton-primario:hover:not(:disabled) {
  background: var(--raiga-primary-dark);
  border-color: var(--raiga-primary-dark);
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
}

.boton-secundario {
  background: var(--bg-card);
  color: var(--text-primary);
  border-color: var(--border-medium);
  box-shadow: var(--shadow-xs);
}

.boton-secundario:hover:not(:disabled) {
  background: var(--hover-bg);
  border-color: var(--raiga-primary);
  transform: translateY(-1px);
  box-shadow: var(--shadow-sm);
}

.boton-peligro {
  background: var(--error-bg);
  color: var(--error-text);
  border-color: var(--error-bg);
  box-shadow: var(--shadow-sm);
}

.boton-peligro:hover:not(:disabled) {
  background: #dc2626;
  border-color: #dc2626;
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
}

/* Formularios modernos */
.grupo-campo {
  margin-bottom: 20px;
}

.etiqueta-campo {
  display: block;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-primary);
  margin-bottom: 6px;
}

.campo-entrada {
  width: 100%;
  padding: 12px 16px;
  border: 1px solid var(--border-medium);
  border-radius: var(--radius-md);
  font-size: 0.875rem;
  line-height: 1.5;
  transition: var(--transition-fast);
  background: var(--bg-card);
  color: var(--text-primary);
}

.campo-entrada:focus {
  outline: none;
  border-color: var(--focus-ring);
  box-shadow: 0 0 0 3px var(--focus-ring-alpha);
}

.campo-entrada:disabled {
  background: var(--bg-tertiary);
  color: var(--text-muted);
  cursor: not-allowed;
}

.campo-entrada::placeholder {
  color: var(--text-muted);
}

/* Tarjetas modernas */
.tarjeta {
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-lg);
  padding: 24px;
  box-shadow: var(--shadow-sm);
  transition: var(--transition-fast);
}

.tarjeta:hover {
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
}

.titulo-tarjeta {
  font-size: 1.25rem;
  font-weight: 600;
  color: var(--title-primary);
  margin-bottom: 12px;
}

/* Mensajes modernos */
.mensaje-estado {
  padding: 16px 20px;
  border-radius: var(--radius-md);
  font-size: 0.875rem;
  margin-bottom: 20px;
  display: flex;
  align-items: center;
  gap: 12px;
  border: 1px solid transparent;
  box-shadow: var(--shadow-sm);
}

.mensaje-exito {
  background: var(--success-light);
  color: #065f46;
  border-color: var(--success-bg);
}

.mensaje-error {
  background: var(--error-light);
  color: #991b1b;
  border-color: var(--error-bg);
}

.mensaje-advertencia {
  background: var(--warning-light);
  color: #92400e;
  border-color: var(--warning-bg);
}

.mensaje-info {
  background: var(--info-light);
  color: #1e40af;
  border-color: var(--info-bg);
}

/* ================================================================
   RESPONSIVE DESIGN MODERNO
================================================================ */

/* Tablet */
@media (max-width: 1024px) {
  :root {
    --ancho-lateral: 240px;
    --ancho-auxiliar: 280px;
    --gap-principal: 20px;
  }
  
  .cabecera-derecha .info-sesion {
    display: none;
  }
  
  .titulo-modulo {
    font-size: 1rem;
  }
  
  .logos-institucionales {
    max-height: 50px;
  }
}

/* Mobile */
@media (max-width: 768px) {
  .grid-container {
    grid-template-areas:
      "cabecera"
      "logos"
      "principal";
    grid-template-columns: 1fr;
    grid-template-rows: var(--alto-cabecera) auto 1fr;
  }
  
  .area-lateral,
  .area-auxiliar {
    display: none;
  }
  
  .area-lateral.mobile-open {
    display: flex;
    position: fixed;
    top: var(--alto-cabecera);
    left: 0;
    width: var(--ancho-lateral);
    height: calc(100vh - var(--alto-cabecera));
    z-index: var(--z-modal);
    box-shadow: var(--shadow-xl);
  }
  
  .area-principal {
    padding: 16px;
  }
  
  .cabecera-derecha {
    gap: 12px;
  }
  
  .info-usuario {
    padding: 6px 12px;
    font-size: 0.8rem;
  }
  
  .titulo-modulo {
    display: none;
  }
  
  .logo-sistema {
    font-size: 2.25rem;
  }
  
  .barra-logos-institucionales {
    padding: 8px 10px;
  }
  
  .logos-institucionales {
    max-height: 40px;
  }
}

/* Mobile pequeño */
@media (max-width: 480px) {
  :root {
    --alto-cabecera: 60px;
    --gap-principal: 16px;
  }
  
  .area-cabecera {
    padding: 0 16px;
  }
  
  .logo-sistema {
    font-size: 2.125rem;
  }
  
  .area-principal {
    padding: 12px;
  }
  
  .cabecera-izquierda {
    gap: 8px;
  }
  
  .cabecera-derecha {
    gap: 8px;
  }
  
  .barra-logos-institucionales {
    padding: 6px 8px;
  }
  
  .logos-institucionales {
    max-height: 30px;
  }
}

/* ================================================================
   UTILIDADES MODERNAS
================================================================ */
.oculto {
  display: none !important;
}

.visible {
  display: block !important;
}

.flex {
  display: flex !important;
}

.flex-center {
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
}

.texto-centrado {
  text-align: center !important;
}

.texto-derecha {
  text-align: right !important;
}

.texto-izquierda {
  text-align: left !important;
}

/* Espaciado moderno */
.mt-xs { margin-top: 4px !important; }
.mt-sm { margin-top: 8px !important; }
.mt-md { margin-top: 16px !important; }
.mt-lg { margin-top: 24px !important; }
.mt-xl { margin-top: 32px !important; }

.mb-xs { margin-bottom: 4px !important; }
.mb-sm { margin-bottom: 8px !important; }
.mb-md { margin-bottom: 16px !important; }
.mb-lg { margin-bottom: 24px !important; }
.mb-xl { margin-bottom: 32px !important; }

.p-xs { padding: 4px !important; }
.p-sm { padding: 8px !important; }
.p-md { padding: 16px !important; }
.p-lg { padding: 24px !important; }
.p-xl { padding: 32px !important; }

/* Estados de componentes */
.loading {
  opacity: 0.6;
  pointer-events: none;
  position: relative;
}

.loading::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 20px;
  height: 20px;
  margin: -10px 0 0 -10px;
  border: 2px solid var(--raiga-primary);
  border-radius: 50%;
  border-top-color: transparent;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ================================================================
   ANIMACIONES MODERNAS
================================================================ */
@keyframes slideIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.slide-in {
  animation: slideIn var(--transition-normal) ease-out;
}

.fade-in {
  animation: fadeIn var(--transition-normal) ease-out;
}

/* ================================================================
   ACCESIBILIDAD MEJORADA
================================================================ */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* Focus visible mejorado */
.boton:focus-visible,
.campo-entrada:focus-visible,
.enlace-modulo:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

/* ================================================================
   TEMA OSCURO (PREPARADO)
================================================================ */
@media (prefers-color-scheme: dark) {
  /* Variables para tema oscuro - implementar en el futuro */
  /*
  :root {
    --bg-primary: #0f172a;
    --bg-secondary: #1e293b;
    --text-primary: #f8fafc;
    --sidebar-bg: #020617;
  }
  */
}