/**
 * Toast Notifications Component - v2.0
 * =====================================
 * Sistema unificado de notificaciones toast profesional
 *
 * Metodología: BEM (Block Element Modifier)
 * Mobile-First: Sí
 * Dependencias: Alpine.js store 'notifications'
 *
 * @author SuiteEducation Team
 * @since 2025-01-25
 */

/* ============================================
   VARIABLES CSS
   ============================================ */
:root {
    /* Colores de notificaciones */
    --toast-success-bg: linear-gradient(135deg, #10b981 0%, #059669 100%);
    --toast-success-text: #ffffff;
    --toast-success-icon: #ffffff;

    --toast-error-bg: linear-gradient(135deg, #ef4444 0%, #dc2626 100%);
    --toast-error-text: #ffffff;
    --toast-error-icon: #ffffff;

    --toast-warning-bg: linear-gradient(135deg, #f59e0b 0%, #d97706 100%);
    --toast-warning-text: #ffffff;
    --toast-warning-icon: #ffffff;

    --toast-info-bg: linear-gradient(135deg, #3b82f6 0%, #2563eb 100%);
    --toast-info-text: #ffffff;
    --toast-info-icon: #ffffff;

    /* Sombras */
    --toast-shadow: 0 10px 40px rgba(0, 0, 0, 0.15), 0 4px 12px rgba(0, 0, 0, 0.1);
    --toast-shadow-hover: 0 15px 50px rgba(0, 0, 0, 0.2), 0 6px 16px rgba(0, 0, 0, 0.12);

    /* Timing */
    --toast-transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

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

.toast-notifications {
    position: fixed;
    top: 100px;
    right: 24px;
    z-index: 99999;
    display: flex;
    flex-direction: column;
    gap: 12px;
    max-width: 420px;
    pointer-events: none;
}

.toast-notifications > * {
    pointer-events: auto;
}

/* ============================================
   TOAST INDIVIDUAL (BEM Block)
   ============================================ */

.toast {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 16px 20px;
    border-radius: 12px;
    box-shadow: var(--toast-shadow);
    cursor: pointer;
    min-width: 320px;
    max-width: 100%;
    animation: toast-enter 0.4s cubic-bezier(0.21, 1.02, 0.73, 1) forwards;
    transform-origin: top right;
    backdrop-filter: blur(8px);
    transition: var(--toast-transition);
}

.toast:hover {
    transform: translateX(-4px) scale(1.02);
    box-shadow: var(--toast-shadow-hover);
}

/* ============================================
   ICONO DEL TOAST (BEM Element)
   ============================================ */

.toast__icon {
    flex-shrink: 0;
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.25);
    font-size: 14px;
}

.toast__icon svg {
    width: 16px;
    height: 16px;
    stroke: currentColor;
    stroke-width: 2.5;
    fill: none;
}

/* ============================================
   CONTENIDO DEL TOAST (BEM Element)
   ============================================ */

.toast__content {
    flex: 1;
    min-width: 0;
}

.toast__title {
    font-weight: 600;
    font-size: 14px;
    margin-bottom: 2px;
    line-height: 1.3;
}

.toast__message {
    font-weight: 400;
    font-size: 14px;
    line-height: 1.5;
    opacity: 0.95;
    word-wrap: break-word;
}

/* ============================================
   BOTÓN CERRAR (BEM Element)
   ============================================ */

.toast__close {
    flex-shrink: 0;
    background: rgba(255, 255, 255, 0.2);
    border: none;
    cursor: pointer;
    font-size: 18px;
    line-height: 1;
    padding: 0;
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    color: inherit;
    opacity: 0.7;
    transition: var(--toast-transition);
}

.toast__close:hover {
    opacity: 1;
    background: rgba(255, 255, 255, 0.35);
    transform: scale(1.1);
}

.toast__close:focus {
    outline: 2px solid rgba(255, 255, 255, 0.5);
    outline-offset: 2px;
}

/* ============================================
   BARRA DE PROGRESO (BEM Element)
   ============================================ */

.toast__progress {
    position: absolute;
    bottom: 0;
    left: 0;
    height: 3px;
    background: rgba(255, 255, 255, 0.4);
    border-radius: 0 0 12px 12px;
    animation: toast-progress linear forwards;
}

/* ============================================
   MODIFICADORES DE TIPO (BEM Modifiers)
   ============================================ */

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

.toast--success .toast__icon {
    background: rgba(255, 255, 255, 0.3);
}

.toast--error {
    background: var(--toast-error-bg);
    color: var(--toast-error-text);
}

.toast--error .toast__icon {
    background: rgba(255, 255, 255, 0.3);
}

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

.toast--warning .toast__icon {
    background: rgba(255, 255, 255, 0.3);
}

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

.toast--info .toast__icon {
    background: rgba(255, 255, 255, 0.3);
}

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

@keyframes toast-enter {
    0% {
        opacity: 0;
        transform: translateX(100%) scale(0.9);
    }
    100% {
        opacity: 1;
        transform: translateX(0) scale(1);
    }
}

@keyframes toast-exit {
    0% {
        opacity: 1;
        transform: translateX(0) scale(1);
    }
    100% {
        opacity: 0;
        transform: translateX(100%) scale(0.9);
    }
}

@keyframes toast-progress {
    from {
        width: 100%;
    }
    to {
        width: 0%;
    }
}

.toast--leaving {
    animation: toast-exit 0.3s cubic-bezier(0.4, 0, 1, 1) forwards;
}

/* Efecto shimmer sutil */
.toast::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(
        90deg,
        transparent,
        rgba(255, 255, 255, 0.1),
        transparent
    );
    animation: toast-shimmer 3s ease-in-out infinite;
    pointer-events: none;
    border-radius: 12px;
}

@keyframes toast-shimmer {
    0% {
        left: -100%;
    }
    50%, 100% {
        left: 100%;
    }
}

/* ============================================
   RESPONSIVE - MOBILE FIRST
   ============================================ */

/* Móvil (por defecto) */
@media (max-width: 639px) {
    .toast-notifications {
        top: auto;
        bottom: 20px;
        right: 12px;
        left: 12px;
        max-width: none;
    }

    .toast {
        min-width: auto;
        padding: 14px 16px;
        gap: 12px;
    }

    .toast__icon {
        width: 24px;
        height: 24px;
    }

    .toast__icon svg {
        width: 14px;
        height: 14px;
    }

    .toast__message {
        font-size: 13px;
    }

    .toast__close {
        width: 24px;
        height: 24px;
        font-size: 16px;
    }
}

/* Tablet y superior */
@media (min-width: 640px) {
    .toast-notifications {
        right: 24px;
        left: auto;
        max-width: 420px;
    }

    .toast {
        min-width: 320px;
    }
}

/* Desktop grande */
@media (min-width: 1280px) {
    .toast-notifications {
        max-width: 480px;
        right: 32px;
    }

    .toast {
        padding: 18px 22px;
    }
}

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

/* Reducir movimiento para usuarios con preferencias de accesibilidad */
@media (prefers-reduced-motion: reduce) {
    .toast {
        animation: none;
        opacity: 1;
        transform: none;
    }

    .toast--leaving {
        animation: none;
        opacity: 0;
    }

    .toast::before {
        animation: none;
    }

    .toast__progress {
        animation: none;
        width: 0;
    }
}

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

    .toast__close {
        border: 1px solid currentColor;
    }
}

/* ============================================
   TEMA OSCURO (opcional, respeta sistema)
   ============================================ */

@media (prefers-color-scheme: dark) {
    :root {
        --toast-shadow: 0 10px 40px rgba(0, 0, 0, 0.4), 0 4px 12px rgba(0, 0, 0, 0.3);
        --toast-shadow-hover: 0 15px 50px rgba(0, 0, 0, 0.5), 0 6px 16px rgba(0, 0, 0, 0.35);
    }
}

/* ============================================
   ESTADOS ADICIONALES
   ============================================ */

.toast:active {
    transform: scale(0.98);
}

.toast:focus-within {
    outline: 2px solid rgba(255, 255, 255, 0.6);
    outline-offset: 2px;
}

/* Para usuarios de teclado */
.toast__close:focus-visible {
    outline: 2px solid rgba(255, 255, 255, 0.8);
    outline-offset: 2px;
    border-radius: 8px;
}

/* ============================================
   UTILIDADES
   ============================================ */

/* Toast con posición sticky (no se mueve con scroll) */
.toast--sticky {
    position: relative;
}

/* Toast sin auto-dismiss (requiere clic para cerrar) */
.toast--persistent .toast__progress {
    display: none;
}
