/* =================================================================
   UNIFIED TOAST NOTIFICATION SYSTEM
   Presentify - Apple-Inspired Design

   This is the ONLY alert/notification system to use across the app.
   DO NOT use Bootstrap alerts, native alert(), or custom notifications.

   Usage: window.Toast.show('Message', 'success')
   Types: success, error, warning, info
   ================================================================= */

/* ===============================================================
   CSS Custom Properties (uses design-tokens.css)
   =============================================================== */
:root {
    /* Toast Colors */
    --toast-success-bg: rgba(16, 185, 129, 0.95);
    --toast-success-border: rgba(16, 185, 129, 1);
    --toast-success-icon: #10b981;

    --toast-error-bg: rgba(239, 68, 68, 0.95);
    --toast-error-border: rgba(239, 68, 68, 1);
    --toast-error-icon: #ef4444;

    --toast-warning-bg: rgba(245, 158, 11, 0.95);
    --toast-warning-border: rgba(245, 158, 11, 1);
    --toast-warning-icon: #f59e0b;

    --toast-info-bg: rgba(59, 130, 246, 0.95);
    --toast-info-border: rgba(59, 130, 246, 1);
    --toast-info-icon: #3b82f6;

    /* Toast Dimensions */
    --toast-max-width: 420px;
    --toast-min-width: 300px;
    --toast-padding: 16px 20px;
    --toast-gap: 12px;
    --toast-radius: 12px;
    --toast-z-index: 999999;
}

/* Dark mode adjustments */
@media (prefers-color-scheme: dark) {
    :root {
        --toast-success-bg: rgba(16, 185, 129, 0.15);
        --toast-error-bg: rgba(239, 68, 68, 0.15);
        --toast-warning-bg: rgba(245, 158, 11, 0.15);
        --toast-info-bg: rgba(59, 130, 246, 0.15);
    }
}

/* ===============================================================
   Toast Container
   =============================================================== */
.toast-container {
    position: fixed;
    top: 24px;
    left: 50%;
    transform: translateX(-50%);
    z-index: var(--toast-z-index);
    display: flex;
    flex-direction: column;
    gap: var(--toast-gap);
    pointer-events: none;
    max-width: calc(100vw - 32px);
}

/* Alternative positions */
.toast-container.bottom {
    top: auto;
    bottom: 24px;
}

.toast-container.top-right {
    left: auto;
    right: 24px;
    transform: none;
}

.toast-container.top-left {
    left: 24px;
    transform: none;
}

/* Mobile adjustments */
@media (max-width: 640px) {
    .toast-container {
        top: 16px;
        left: 16px;
        right: 16px;
        transform: none;
        max-width: none;
    }

    .toast-container.top-right,
    .toast-container.top-left {
        left: 16px;
        right: 16px;
    }
}

/* ===============================================================
   Toast Element
   =============================================================== */
.toast {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: var(--toast-padding);
    min-width: var(--toast-min-width);
    max-width: var(--toast-max-width);
    width: fit-content;
    margin: 0 auto;

    /* Glass morphism effect */
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid rgba(0, 0, 0, 0.08);
    border-radius: var(--toast-radius);
    box-shadow:
        0 4px 6px -1px rgba(0, 0, 0, 0.1),
        0 2px 4px -1px rgba(0, 0, 0, 0.06),
        0 20px 25px -5px rgba(0, 0, 0, 0.1);

    /* Animation */
    opacity: 0;
    transform: translateY(-20px) scale(0.95);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    pointer-events: auto;

    /* Typography */
    font-family: var(--font-system, -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'Helvetica Neue', sans-serif);
    font-size: 14px;
    line-height: 1.5;
    color: #1f2937;
}

/* Toast visible state */
.toast.show {
    opacity: 1;
    transform: translateY(0) scale(1);
}

/* Toast hiding state */
.toast.hiding {
    opacity: 0;
    transform: translateY(-10px) scale(0.95);
}

/* Dark mode toast */
@media (prefers-color-scheme: dark) {
    .toast {
        background: rgba(31, 41, 55, 0.95);
        border-color: rgba(255, 255, 255, 0.1);
        color: #f3f4f6;
        box-shadow:
            0 4px 6px -1px rgba(0, 0, 0, 0.3),
            0 2px 4px -1px rgba(0, 0, 0, 0.2),
            0 20px 25px -5px rgba(0, 0, 0, 0.4);
    }
}

/* Mobile toast */
@media (max-width: 640px) {
    .toast {
        min-width: 0;
        max-width: none;
        width: 100%;
    }
}

/* ===============================================================
   Toast Icon
   =============================================================== */
.toast-icon {
    flex-shrink: 0;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    margin-top: 1px;
}

.toast-icon svg {
    width: 16px;
    height: 16px;
}

/* ===============================================================
   Toast Content
   =============================================================== */
.toast-content {
    flex: 1;
    min-width: 0;
}

.toast-title {
    font-weight: 600;
    font-size: 15px;
    margin: 0 0 2px 0;
    color: inherit;
}

.toast-message {
    margin: 0;
    font-size: 14px;
    opacity: 0.9;
    word-break: break-word;
}

/* When there's no title */
.toast-content:not(:has(.toast-title)) .toast-message {
    font-weight: 500;
}

/* ===============================================================
   Toast Close Button
   =============================================================== */
.toast-close {
    flex-shrink: 0;
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    color: currentColor;
    opacity: 0.5;
    transition: all 0.2s ease;
    padding: 0;
    margin: -4px -6px -4px 0;
}

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

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

@media (prefers-color-scheme: dark) {
    .toast-close:hover {
        background: rgba(255, 255, 255, 0.1);
    }
}

.toast-close svg {
    width: 14px;
    height: 14px;
}

/* ===============================================================
   Toast Progress Bar
   =============================================================== */
.toast-progress {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: rgba(0, 0, 0, 0.1);
    border-radius: 0 0 var(--toast-radius) var(--toast-radius);
    overflow: hidden;
}

.toast-progress-bar {
    height: 100%;
    background: currentColor;
    opacity: 0.3;
    transform-origin: left;
    animation: toast-progress linear forwards;
}

@keyframes toast-progress {
    from {
        transform: scaleX(1);
    }
    to {
        transform: scaleX(0);
    }
}

@media (prefers-color-scheme: dark) {
    .toast-progress {
        background: rgba(255, 255, 255, 0.1);
    }
}

/* ===============================================================
   Toast Types - Success
   =============================================================== */
.toast.success {
    background: var(--toast-success-bg);
    border-color: var(--toast-success-border);
}

.toast.success .toast-icon {
    background: rgba(16, 185, 129, 0.2);
    color: #059669;
}

@media (prefers-color-scheme: dark) {
    .toast.success {
        background: var(--toast-success-bg);
        border-color: rgba(16, 185, 129, 0.3);
        color: #d1fae5;
    }

    .toast.success .toast-icon {
        background: rgba(16, 185, 129, 0.3);
        color: #34d399;
    }
}

/* ===============================================================
   Toast Types - Error / Danger
   =============================================================== */
.toast.error,
.toast.danger {
    background: var(--toast-error-bg);
    border-color: var(--toast-error-border);
}

.toast.error .toast-icon,
.toast.danger .toast-icon {
    background: rgba(239, 68, 68, 0.2);
    color: #dc2626;
}

@media (prefers-color-scheme: dark) {
    .toast.error,
    .toast.danger {
        background: var(--toast-error-bg);
        border-color: rgba(239, 68, 68, 0.3);
        color: #fee2e2;
    }

    .toast.error .toast-icon,
    .toast.danger .toast-icon {
        background: rgba(239, 68, 68, 0.3);
        color: #f87171;
    }
}

/* ===============================================================
   Toast Types - Warning
   =============================================================== */
.toast.warning {
    background: var(--toast-warning-bg);
    border-color: var(--toast-warning-border);
}

.toast.warning .toast-icon {
    background: rgba(245, 158, 11, 0.2);
    color: #d97706;
}

@media (prefers-color-scheme: dark) {
    .toast.warning {
        background: var(--toast-warning-bg);
        border-color: rgba(245, 158, 11, 0.3);
        color: #fef3c7;
    }

    .toast.warning .toast-icon {
        background: rgba(245, 158, 11, 0.3);
        color: #fbbf24;
    }
}

/* ===============================================================
   Toast Types - Info
   =============================================================== */
.toast.info {
    background: var(--toast-info-bg);
    border-color: var(--toast-info-border);
}

.toast.info .toast-icon {
    background: rgba(59, 130, 246, 0.2);
    color: #2563eb;
}

@media (prefers-color-scheme: dark) {
    .toast.info {
        background: var(--toast-info-bg);
        border-color: rgba(59, 130, 246, 0.3);
        color: #dbeafe;
    }

    .toast.info .toast-icon {
        background: rgba(59, 130, 246, 0.3);
        color: #60a5fa;
    }
}

/* ===============================================================
   Toast Actions (optional buttons)
   =============================================================== */
.toast-actions {
    display: flex;
    gap: 8px;
    margin-top: 12px;
}

.toast-action {
    padding: 6px 12px;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    border: none;
    transition: all 0.2s ease;
    background: rgba(0, 0, 0, 0.1);
    color: inherit;
}

.toast-action:hover {
    background: rgba(0, 0, 0, 0.15);
}

.toast-action.primary {
    background: rgba(0, 0, 0, 0.8);
    color: white;
}

.toast-action.primary:hover {
    background: rgba(0, 0, 0, 0.9);
}

@media (prefers-color-scheme: dark) {
    .toast-action {
        background: rgba(255, 255, 255, 0.1);
    }

    .toast-action:hover {
        background: rgba(255, 255, 255, 0.15);
    }

    .toast-action.primary {
        background: rgba(255, 255, 255, 0.9);
        color: #1f2937;
    }

    .toast-action.primary:hover {
        background: rgba(255, 255, 255, 1);
    }
}

/* ===============================================================
   Animations
   =============================================================== */

/* Entrance from top */
@keyframes toast-slide-in-top {
    from {
        opacity: 0;
        transform: translateY(-20px) scale(0.95);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

/* Exit to top */
@keyframes toast-slide-out-top {
    from {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
    to {
        opacity: 0;
        transform: translateY(-10px) scale(0.95);
    }
}

/* Entrance from bottom */
@keyframes toast-slide-in-bottom {
    from {
        opacity: 0;
        transform: translateY(20px) scale(0.95);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

/* Exit to bottom */
@keyframes toast-slide-out-bottom {
    from {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
    to {
        opacity: 0;
        transform: translateY(10px) scale(0.95);
    }
}

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

    .toast.show {
        transform: none;
    }

    .toast.hiding {
        transform: none;
    }

    .toast-progress-bar {
        animation: none;
    }
}

/* ===============================================================
   Accessibility
   =============================================================== */
.toast[role="alert"] {
    /* Ensure screen readers announce */
}

/* Focus visible for close button */
.toast-close:focus-visible {
    outline: 2px solid currentColor;
    outline-offset: 2px;
    opacity: 1;
}

/* High contrast mode */
@media (prefers-contrast: high) {
    .toast {
        border-width: 2px;
    }

    .toast-icon {
        border: 1px solid currentColor;
    }
}
