/* ==========================================================================
   SISTEMA UNIFICADO DE NOTIFICACIONES - SERVISORT
   Estilos completos para PWA, sesiones, errores y alertas
   ========================================================================== */

/* Variables CSS para notificaciones */
:root {
  /* Colores principales */
  --notification-success: #10b981;
  --notification-warning: #f59e0b;
  --notification-error: #ef4444;
  --notification-info: #3b82f6;
  --notification-primary: #6366f1;
  
  /* Colores de fondo */
  --notification-bg-light: #ffffff;
  --notification-bg-dark: #1f2937;
  --notification-bg-overlay: rgba(0, 0, 0, 0.5);
  
  /* Colores de texto */
  --notification-text-primary: #1f2937;
  --notification-text-secondary: #6b7280;
  --notification-text-light: #ffffff;
  
  /* Espaciado */
  --notification-padding: 16px;
  --notification-margin: 12px;
  --notification-gap: 12px;
  
  /* Bordes y sombras */
  --notification-radius: 8px;
  --notification-border-width: 1px;
  --notification-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
  --notification-shadow-hover: 0 8px 25px rgba(0, 0, 0, 0.15);
  
  /* Transiciones */
  --notification-transition: all 0.3s ease;
  --notification-duration: 5000ms;
  
  /* Z-index */
--notification-z-index: 10002;
--notification-overlay-z-index: 10001;
}

/* ==========================================================================
   ANIMACIONES GLOBALES
   ========================================================================== */

@keyframes slideInDown {
  from {
    transform: translateY(-100%);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

@keyframes slideInRight {
  from {
    transform: translateX(100%);
    opacity: 0;
  }
  to {
    transform: translateX(0);
    opacity: 1;
  }
}

@keyframes slideInUp {
  from {
    transform: translateY(100%);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

@keyframes pulse {
  0%, 100% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.05);
  }
}

@keyframes shake {
  0%, 100% {
    transform: translateX(0);
  }
  25% {
    transform: translateX(-5px);
  }
  75% {
    transform: translateX(5px);
  }
}

/* ==========================================================================
   CONTENEDOR BASE DE NOTIFICACIONES
   ========================================================================== */

/* Prevenir acumulación de notificaciones en el footer */
.notification-container,
.js-notification-container {
  position: fixed !important;
  top: 20px !important;
  right: 20px !important;
  z-index: 10002 !important;
  bottom: auto !important;
  left: auto !important;
  transform: none !important;
}

/* Asegurar que las notificaciones error-toast también se posicionen correctamente */
.error-toast {
  position: fixed !important;
  top: 20px !important;
  left: 50% !important;
  transform: translateX(-50%) !important;
  z-index: 10001 !important;
  bottom: auto !important;
}

/* Evitar superposición de múltiples notificaciones */
.error-toast:nth-of-type(1) { top: 20px !important; }
.error-toast:nth-of-type(2) { top: 80px !important; }
.error-toast:nth-of-type(3) { top: 140px !important; }
.error-toast:nth-of-type(4) { top: 200px !important; }
.error-toast:nth-of-type(5) { top: 260px !important; }

.notification-container {
  position: fixed !important;
  top: var(--notification-margin) !important;
  right: var(--notification-margin) !important;
  z-index: var(--notification-z-index) !important;
  max-width: 400px;
  width: calc(100% - 24px);
  pointer-events: none;
  /* Asegurar que no se posicione en el footer */
  bottom: auto !important;
  left: auto !important;
}

.notification-container > * {
  pointer-events: auto;
  margin-bottom: var(--notification-margin);
  position: relative !important;
  /* Evitar que se acumulen en el footer */
  bottom: auto !important;
}

/* ==========================================================================
   NOTIFICACIÓN BASE
   ========================================================================== */

.notification {
  background: var(--notification-bg-light);
  border-radius: var(--notification-radius);
  box-shadow: var(--notification-shadow);
  padding: var(--notification-padding);
  border-left: 4px solid var(--notification-primary);
  animation: slideInRight 0.5s ease-out;
  transition: var(--notification-transition);
  position: relative;
  overflow: hidden;
}

.notification:hover {
  transform: translateY(-2px);
  box-shadow: var(--notification-shadow-hover);
}

.notification::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 2px;
  background: linear-gradient(90deg, transparent, var(--notification-primary), transparent);
  animation: progress var(--notification-duration) linear;
}

@keyframes progress {
  from {
    transform: translateX(-100%);
  }
  to {
    transform: translateX(100%);
  }
}

/* ==========================================================================
   VARIANTES DE NOTIFICACIONES
   ========================================================================== */

/* Éxito */
.notification.success {
  border-left-color: var(--notification-success);
  background: linear-gradient(135deg, #ecfdf5 0%, #d1fae5 100%);
}

.notification.success::before {
  background: linear-gradient(90deg, transparent, var(--notification-success), transparent);
}

/* Advertencia */
.notification.warning {
  border-left-color: var(--notification-warning);
  background: linear-gradient(135deg, #fffbeb 0%, #fef3c7 100%);
}

.notification.warning::before {
  background: linear-gradient(90deg, transparent, var(--notification-warning), transparent);
}

/* Error */
.notification.error {
  border-left-color: var(--notification-error);
  background: linear-gradient(135deg, #fef2f2 0%, #fecaca 100%);
  animation: slideInDown 0.3s ease-out, shake 0.5s ease-in-out 0.3s;
}

.notification.error::before {
  background: linear-gradient(90deg, transparent, var(--notification-error), transparent);
}

/* Información */
.notification.info {
  border-left-color: var(--notification-info);
  background: linear-gradient(135deg, #eff6ff 0%, #dbeafe 100%);
}

.notification.info::before {
  background: linear-gradient(90deg, transparent, var(--notification-info), transparent);
}

/* ==========================================================================
   ESTRUCTURA INTERNA DE NOTIFICACIONES
   ========================================================================== */

.notification-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.notification-title {
  font-weight: 600;
  color: var(--notification-text-primary);
  font-size: 14px;
  margin: 0;
  display: flex;
  align-items: center;
  gap: 8px;
}

.notification-icon {
  font-size: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
}

.notification-close {
  background: none;
  border: none;
  color: var(--notification-text-secondary);
  cursor: pointer;
  font-size: 16px;
  padding: 4px;
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  transition: var(--notification-transition);
}

.notification-close:hover {
  background: rgba(0, 0, 0, 0.1);
  color: var(--notification-text-primary);
}

.notification-body {
  color: var(--notification-text-secondary);
  font-size: 13px;
  line-height: 1.5;
  margin: 0;
}

.notification-actions {
  margin-top: 12px;
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

/* ==========================================================================
   BOTONES DE NOTIFICACIONES
   ========================================================================== */

.notification-btn {
  padding: 6px 12px;
  border: none;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: var(--notification-transition);
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.notification-btn.primary {
  background: var(--notification-primary);
  color: var(--notification-text-light);
}

.notification-btn.primary:hover {
  background: #5b21b6;
}

.notification-btn.secondary {
  background: transparent;
  color: var(--notification-text-secondary);
  border: 1px solid var(--notification-text-secondary);
}

.notification-btn.secondary:hover {
  background: var(--notification-text-secondary);
  color: var(--notification-text-light);
}

/* ==========================================================================
   NOTIFICACIONES PWA ESPECÍFICAS
   ========================================================================== */

.pwa-notification {
  background: var(--notification-bg-light);
  border-left: 4px solid var(--notification-primary);
  padding: var(--notification-padding);
  border-radius: var(--notification-radius);
  box-shadow: var(--notification-shadow);
  animation: slideInRight 0.5s ease-out;
  transition: var(--notification-transition);
}

.pwa-install-prompt {
  background: linear-gradient(135deg, #f0f9ff 0%, #e0f2fe 100%);
  border-left-color: var(--notification-info);
}

.pwa-update-available {
  background: linear-gradient(135deg, #fffbeb 0%, #fef3c7 100%);
  border-left-color: var(--notification-warning);
}

.pwa-offline-ready {
  background: linear-gradient(135deg, #ecfdf5 0%, #d1fae5 100%);
  border-left-color: var(--notification-success);
}

/* ==========================================================================
   NOTIFICACIONES DE SESIÓN
   ========================================================================== */

.session-notification {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: var(--notification-z-index);
  animation: slideInDown 0.3s ease-out;
}

.session-conflict-message,
.session-expired-message {
  background: var(--notification-bg-light);
  border-bottom: 3px solid var(--notification-warning);
  padding: var(--notification-padding);
  box-shadow: var(--notification-shadow);
}

.session-alert {
  max-width: 1200px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: var(--notification-gap);
  padding: var(--notification-padding);
  background: linear-gradient(135deg, #fffbeb 0%, #fef3c7 100%);
  border-radius: var(--notification-radius);
  transition: var(--notification-transition);
}

.session-expired-message .session-alert {
  background: linear-gradient(135deg, #eff6ff 0%, #dbeafe 100%);
  border-left-color: var(--notification-info);
}

.session-icon {
  font-size: 24px;
  animation: pulse 2s infinite;
  color: var(--notification-warning);
}

.session-content {
  flex: 1;
}

.session-title {
  font-size: 16px;
  font-weight: 600;
  margin: 0 0 4px 0;
  color: var(--notification-text-primary);
}

.session-message {
  margin: 0;
  line-height: 1.5;
  color: var(--notification-text-secondary);
  font-size: 14px;
}

.session-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

/* ==========================================================================
   TOAST NOTIFICATIONS (MÓVIL)
   ========================================================================== */

.toast-container {
  position: fixed;
  top: var(--notification-margin);
  left: var(--notification-margin);
  right: var(--notification-margin);
  z-index: var(--notification-z-index);
  pointer-events: none;
}

.toast {
  background: var(--notification-bg-light);
  color: var(--notification-text-primary);
  border-radius: var(--notification-radius);
  padding: var(--notification-padding);
  margin-bottom: var(--notification-margin);
  box-shadow: var(--notification-shadow);
  animation: slideInDown 0.3s ease-out;
  transition: var(--notification-transition);
  pointer-events: auto;
  display: flex;
  align-items: center;
  gap: var(--notification-gap);
}

.toast.show {
  animation: slideInDown 0.3s ease-out;
}

.toast.hide {
  animation: slideInUp 0.3s ease-out reverse;
}

/* Variantes de toast */
.toast.error {
  background: var(--notification-error);
  color: var(--notification-text-light);
}

.toast.success {
  background: var(--notification-success);
  color: var(--notification-text-light);
}

.toast.warning {
  background: var(--notification-warning);
  color: var(--notification-text-light);
}

.toast.info {
  background: var(--notification-info);
  color: var(--notification-text-light);
}

.toast-content {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 8px;
}

.toast-icon {
  font-size: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.toast-text {
  font-size: 14px;
  font-weight: 500;
  line-height: 1.4;
}

.toast-close {
  background: none;
  border: none;
  color: inherit;
  font-size: 18px;
  cursor: pointer;
  padding: 4px;
  border-radius: 4px;
  transition: var(--notification-transition);
  opacity: 0.8;
}

.toast-close:hover {
  opacity: 1;
  background: rgba(255, 255, 255, 0.2);
}

/* ==========================================================================
   OVERLAY DE CONEXIÓN/OFFLINE
   ========================================================================== */

.offline-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--notification-bg-overlay);
  z-index: var(--notification-overlay-z-index);
  display: flex;
  align-items: center;
  justify-content: center;
  animation: fadeIn 0.3s ease-out;
}

.offline-message {
  background: var(--notification-bg-light);
  padding: 32px;
  border-radius: var(--notification-radius);
  text-align: center;
  max-width: 400px;
  margin: var(--notification-margin);
  box-shadow: var(--notification-shadow);
  animation: slideInUp 0.5s ease-out;
}

.offline-message h3 {
  margin: 0 0 16px 0;
  color: var(--notification-text-primary);
  font-size: 20px;
  font-weight: 600;
}

.offline-message p {
  margin: 0 0 24px 0;
  color: var(--notification-text-secondary);
  line-height: 1.5;
}

.offline-message .notification-btn {
  padding: 12px 24px;
  font-size: 14px;
}

/* ==========================================================================
   INDICADORES DE ESTADO
   ========================================================================== */

.status-indicator {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 8px;
  border-radius: 12px;
  font-size: 12px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.status-indicator.online {
  background: rgba(16, 185, 129, 0.1);
  color: var(--notification-success);
}

.status-indicator.offline {
  background: rgba(239, 68, 68, 0.1);
  color: var(--notification-error);
}

.status-indicator.syncing {
  background: rgba(245, 158, 11, 0.1);
  color: var(--notification-warning);
}

.status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  animation: pulse 2s infinite;
}

/* ==========================================================================
   TEMA OSCURO
   ========================================================================== */

[data-theme="dark"] {
  --notification-bg-light: #1f2937;
  --notification-text-primary: #f9fafb;
  --notification-text-secondary: #d1d5db;
}

[data-theme="dark"] .notification {
  background: var(--notification-bg-dark);
  border-color: rgba(255, 255, 255, 0.1);
}

[data-theme="dark"] .notification.success {
  background: linear-gradient(135deg, #064e3b 0%, #065f46 100%);
}

[data-theme="dark"] .notification.warning {
  background: linear-gradient(135deg, #78350f 0%, #92400e 100%);
}

[data-theme="dark"] .notification.error {
  background: linear-gradient(135deg, #7f1d1d 0%, #991b1b 100%);
}

[data-theme="dark"] .notification.info {
  background: linear-gradient(135deg, #1e3a8a 0%, #1e40af 100%);
}

[data-theme="dark"] .notification-close:hover {
  background: rgba(255, 255, 255, 0.1);
}

[data-theme="dark"] .offline-message {
  background: var(--notification-bg-dark);
}

/* ==========================================================================
   RESPONSIVE DESIGN
   ========================================================================== */

@media (max-width: 768px) {
  .notification-container {
    top: 10px;
    right: 10px;
    left: 10px;
    max-width: none;
    width: auto;
  }
  
  .notification {
    padding: 12px;
  }
  
  .notification-title {
    font-size: 13px;
  }
  
  .notification-body {
    font-size: 12px;
  }
  
  .toast-container {
    top: 10px;
    left: 10px;
    right: 10px;
  }
  
  .session-alert {
    flex-direction: column;
    text-align: center;
    gap: 12px;
  }
  
  .session-actions {
    justify-content: center;
    width: 100%;
  }
  
  .offline-message {
    margin: 20px;
    padding: 24px;
  }
}

@media (max-width: 480px) {
  .notification {
    padding: 10px;
  }
  
  .notification-title {
    font-size: 12px;
  }
  
  .notification-body {
    font-size: 11px;
  }
  
  .notification-btn {
    padding: 4px 8px;
    font-size: 11px;
  }
  
  .toast {
    padding: 10px;
  }
  
  .toast-text {
    font-size: 12px;
  }
}

/* ==========================================================================
   UTILIDADES Y HELPERS
   ========================================================================== */

.notification-hidden {
  display: none !important;
}

.notification-visible {
  display: block !important;
}

.notification-fade-out {
  animation: fadeOut 0.3s ease-out forwards;
}

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

/* Clases de utilidad para JavaScript */
.js-notification-container {
  /* Contenedor manejado por JavaScript */
  position: relative;
}

.js-notification-item {
  /* Elemento individual manejado por JavaScript */
  display: block;
}

.js-notification-auto-hide {
  /* Se oculta automáticamente después del tiempo especificado */
  transition: opacity 0.3s ease;
}

.js-notification-persistent {
  /* Requiere acción del usuario para cerrarse */
  position: sticky;
}

/* ==========================================================================
   ACCESIBILIDAD
   ========================================================================== */

@media (prefers-reduced-motion: reduce) {
  .notification,
  .toast,
  .session-alert,
  .offline-message {
    animation: none;
  }
  
  .status-dot {
    animation: none;
  }
  
  .session-icon {
    animation: none;
  }
}

/* Focus visible para navegación por teclado */
.notification-close:focus-visible,
.notification-btn:focus-visible,
.toast-close:focus-visible {
  outline: 2px solid var(--notification-primary);
  outline-offset: 2px;
}

/* Alto contraste */
@media (prefers-contrast: high) {
  .notification {
    border-width: 2px;
  }
  
  .notification-close,
  .toast-close {
    border: 1px solid currentColor;
  }
}