/* ===================================================================
   OPTIMISTIC UI - Phase 4 Pattern 2
   Toast notifications, pending states, and visual feedback
   =================================================================== */

/* ===== TOAST CONTAINER ===== */
.toast-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 10000;
    display: flex;
    flex-direction: column;
    gap: 12px;
    pointer-events: none;
}

/* ===== TOAST NOTIFICATIONS ===== */
.toast {
    background: #ffffff;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15), 0 0 1px rgba(0, 0, 0, 0.1);
    padding: 16px;
    min-width: 320px;
    max-width: 400px;
    opacity: 0;
    transform: translateX(400px);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    pointer-events: all;
    position: relative;
    overflow: hidden;
}

.toast-show {
    opacity: 1;
    transform: translateX(0);
}

.toast-hide {
    opacity: 0;
    transform: translateX(400px);
}

/* ===== TOAST TYPES ===== */
.toast-success {
    border-left: 4px solid #10b981;
}

.toast-error {
    border-left: 4px solid #ef4444;
}

.toast-warning {
    border-left: 4px solid #f59e0b;
}

.toast-info {
    border-left: 4px solid #3b82f6;
}

/* ===== TOAST CONTENT ===== */
.toast-content {
    display: flex;
    align-items: center;
    gap: 12px;
}

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

.toast-success .toast-icon {
    color: #10b981;
}

.toast-error .toast-icon {
    color: #ef4444;
}

.toast-warning .toast-icon {
    color: #f59e0b;
}

.toast-info .toast-icon {
    color: #3b82f6;
}

.toast-message {
    flex: 1;
    font-size: 14px;
    font-weight: 500;
    color: #1f2937;
    line-height: 1.4;
}

/* ===== TOAST BUTTONS ===== */
.toast-undo-btn {
    flex-shrink: 0;
    background: transparent;
    border: 1px solid #d1d5db;
    border-radius: 4px;
    padding: 4px 12px;
    font-size: 13px;
    font-weight: 600;
    color: #374151;
    cursor: pointer;
    transition: all 0.2s;
}

.toast-undo-btn:hover {
    background: #f3f4f6;
    border-color: #9ca3af;
}

.toast-undo-btn:active {
    transform: scale(0.95);
}

.toast-close-btn {
    flex-shrink: 0;
    background: transparent;
    border: none;
    padding: 0;
    width: 20px;
    height: 20px;
    font-size: 20px;
    line-height: 1;
    color: #9ca3af;
    cursor: pointer;
    transition: color 0.2s;
}

.toast-close-btn:hover {
    color: #374151;
}

/* ===== TOAST COUNTDOWN ===== */
.toast-countdown {
    position: absolute;
    bottom: 0;
    left: 0;
    height: 3px;
    background: linear-gradient(90deg, #10b981 0%, #3b82f6 100%);
    width: 100%;
    border-radius: 0 0 8px 8px;
}

.toast-error .toast-countdown {
    background: linear-gradient(90deg, #ef4444 0%, #dc2626 100%);
}

/* ===== OPTIMISTIC PENDING STATE ===== */
.optimistic-pending {
    position: relative;
    opacity: 0.7;
    pointer-events: none;
}

.optimistic-pending::after {
    content: '';
    position: absolute;
    top: 8px;
    right: 8px;
    width: 16px;
    height: 16px;
    border: 2px solid #e5e7eb;
    border-top-color: #3b82f6;
    border-radius: 50%;
    animation: optimistic-spin 0.8s linear infinite;
}

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

/* ===== OPTIMISTIC SUCCESS ANIMATION ===== */
@keyframes optimistic-success {
    0% {
        transform: scale(1);
        box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.4);
    }
    50% {
        transform: scale(1.02);
        box-shadow: 0 0 0 10px rgba(16, 185, 129, 0);
    }
    100% {
        transform: scale(1);
        box-shadow: 0 0 0 0 rgba(16, 185, 129, 0);
    }
}

/* ===== OPTIMISTIC ERROR ANIMATION ===== */
@keyframes optimistic-error {
    0%, 100% {
        transform: translateX(0);
    }
    10%, 30%, 50%, 70%, 90% {
        transform: translateX(-10px);
    }
    20%, 40%, 60%, 80% {
        transform: translateX(10px);
    }
}

.optimistic-error {
    animation: optimistic-error 0.5s ease-out;
    border-color: #ef4444 !important;
    background: #fef2f2 !important;
}

/* ===== PULSE ANIMATION (for pending badges) ===== */
@keyframes optimistic-pulse {
    0%, 100% {
        opacity: 1;
    }
    50% {
        opacity: 0.5;
    }
}

.badge-pending {
    animation: optimistic-pulse 1.5s ease-in-out infinite;
}

/* ===== RESPONSIVE DESIGN ===== */
@media (max-width: 768px) {
    .toast-container {
        top: 10px;
        right: 10px;
        left: 10px;
    }

    .toast {
        min-width: auto;
        max-width: none;
        width: 100%;
    }

    .toast-content {
        flex-wrap: wrap;
    }

    .toast-undo-btn {
        order: 3;
        width: 100%;
        margin-top: 8px;
    }
}

/* ===== DARK MODE SUPPORT ===== */
[data-theme="dark"] .toast {
    background: #1f2937;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3), 0 0 1px rgba(255, 255, 255, 0.1);
}

[data-theme="dark"] .toast-message {
    color: #f3f4f6;
}

[data-theme="dark"] .toast-undo-btn {
    border-color: #4b5563;
    color: #e5e7eb;
}

[data-theme="dark"] .toast-undo-btn:hover {
    background: #374151;
    border-color: #6b7280;
}

[data-theme="dark"] .toast-close-btn {
    color: #9ca3af;
}

[data-theme="dark"] .toast-close-btn:hover {
    color: #f3f4f6;
}

/* ===== ACCESSIBILITY ===== */
.toast[role="alert"] {
    /* Ensures screen readers announce toasts */
}

.toast-undo-btn:focus,
.toast-close-btn:focus {
    outline: 2px solid #3b82f6;
    outline-offset: 2px;
}

/* Reduce motion for users with motion sensitivity */
@media (prefers-reduced-motion: reduce) {
    .toast {
        transition: opacity 0.2s;
        transform: none;
    }

    .toast-show {
        transform: none;
    }

    .toast-hide {
        transform: none;
    }

    .optimistic-pending::after {
        animation: none;
        border-top-color: #3b82f6;
    }

    @keyframes optimistic-spin {
        /* Disable spin for reduced motion */
    }
}

/* ===== STATUS INDICATORS ===== */
.status-pending {
    background: #fef3c7;
    color: #92400e;
    position: relative;
}

.status-pending::before {
    content: '';
    display: inline-block;
    width: 8px;
    height: 8px;
    margin-right: 6px;
    border-radius: 50%;
    background: #f59e0b;
    animation: optimistic-pulse 1.5s ease-in-out infinite;
}

/* ===== UNDO HINT ===== */
.undo-hint {
    font-size: 12px;
    color: #6b7280;
    margin-top: 4px;
}

/* ===== SMOOTH TRANSITIONS ===== */
.optimistic-transition {
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ===== LOADING SPINNER ===== */
.optimistic-spinner {
    display: inline-block;
    width: 14px;
    height: 14px;
    border: 2px solid #e5e7eb;
    border-top-color: #3b82f6;
    border-radius: 50%;
    animation: optimistic-spin 0.8s linear infinite;
    margin-right: 8px;
    vertical-align: middle;
}
