/**
 * BookitEazy — Apple-Style Compact Floating Alert / Toast System
 * Fixes Bootstrap 4 `.toast { flex-basis: 350px; }` vertical stretching bug.
 * Supports smooth jQuery fadeIn/fadeOut auto-dismissal and manual close.
 * Fully responsive on mobile with notch / safe-area awareness.
 */

/* ─────────────────────────────────────────────────────────────
   1. TOAST CONTAINER (Top-Center Viewport Fixed)
───────────────────────────────────────────────────────────── */
#toast-container {
    position: fixed !important;
    z-index: 9999999 !important;
    pointer-events: none !important;
    font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, Helvetica, Arial, sans-serif !important;
    -webkit-font-smoothing: antialiased !important;
    -moz-osx-font-smoothing: grayscale !important;
    width: auto !important;
    height: auto !important;
    min-height: 0 !important;
    max-height: none !important;
    padding: 0 !important;
    margin: 0 !important;
    border: none !important;
    background: transparent !important;
}

#toast-container * {
    box-sizing: border-box !important;
}

/* Primary Top-Center Positioning */
.toast-top-center,
#toast-container.toast-top-center {
    top: 20px !important;
    left: 50% !important;
    right: auto !important;
    bottom: auto !important;
    transform: translateX(-50%) !important;
    width: auto !important;
    max-width: min(90vw, 440px) !important;
    height: auto !important;
    min-height: 0 !important;
    max-height: none !important;
    display: flex !important;
    flex-direction: column !important;
    align-items: center !important;
}

/* Fallback alignments */
.toast-top-right, #toast-container.toast-top-right { top: 20px !important; right: 20px !important; left: auto !important; }
.toast-top-left, #toast-container.toast-top-left { top: 20px !important; left: 20px !important; right: auto !important; }
.toast-bottom-center, #toast-container.toast-bottom-center { bottom: 20px !important; left: 50% !important; transform: translateX(-50%) !important; }
.toast-bottom-right, #toast-container.toast-bottom-right { bottom: 20px !important; right: 20px !important; }
.toast-bottom-left, #toast-container.toast-bottom-left { bottom: 20px !important; left: 20px !important; }

/* ─────────────────────────────────────────────────────────────
   2. APPLE-STYLE COMPACT CARD (Content Height, Auto-Dismiss Friendly)
───────────────────────────────────────────────────────────── */
#toast-container > div,
#toast-container .toast,
.toast#toast-container > div {
    position: relative;
    pointer-events: auto;
    overflow: hidden;
    
    /* CRITICAL: Neutralize Bootstrap 4's flex-basis: 350px */
    flex: 0 0 auto !important;
    flex-grow: 0 !important;
    flex-shrink: 0 !important;
    flex-basis: auto !important;
    -ms-flex-preferred-size: auto !important;
    -ms-flex: 0 0 auto !important;
    
    /* Strict Content-Driven Dimensions */
    height: auto !important;
    min-height: 0 !important;
    max-height: none !important;
    width: auto !important;
    min-width: 260px !important;
    max-width: min(90vw, 420px) !important;
    
    /* Horizontal Layout: [ICON] [MESSAGE] [CLOSE] */
    display: inline-flex;
    flex-direction: row;
    align-items: center;
    justify-content: flex-start;
    
    margin: 0 0 8px 0 !important;
    padding: 10px 14px 10px 14px !important;
    border-radius: 16px !important;
    
    /* Apple-inspired Dark Glass Surface */
    background: rgba(22, 22, 26, 0.94) !important;
    backdrop-filter: blur(24px) saturate(180%);
    -webkit-backdrop-filter: blur(24px) saturate(180%);
    background-image: none !important;
    background-repeat: no-repeat !important;
    
    border: 1px solid rgba(255, 255, 255, 0.14) !important;
    box-shadow: 
        0 8px 24px -4px rgba(0, 0, 0, 0.45),
        0 2px 6px -1px rgba(0, 0, 0, 0.25),
        0 0 0 1px rgba(255, 255, 255, 0.05) !important;
    
    opacity: 0.96;
    cursor: default;
    
    transition: box-shadow 0.2s ease;
    animation: appleToastSlide 0.22s cubic-bezier(0.16, 1, 0.3, 1);
}

#toast-container > div:hover,
#toast-container .toast:hover {
    opacity: 1;
    box-shadow: 
        0 12px 30px -4px rgba(0, 0, 0, 0.55),
        0 4px 8px -2px rgba(0, 0, 0, 0.3),
        0 0 0 1px rgba(255, 255, 255, 0.1) !important;
}

/* ─────────────────────────────────────────────────────────────
   3. ISOLATED SINGLE ICON (Flex Item 1 - Left)
───────────────────────────────────────────────────────────── */
#toast-container > div::before,
#toast-container .toast::before {
    content: '' !important;
    order: 1 !important;
    position: static !important; /* Normal flex flow */
    width: 20px !important;
    height: 20px !important;
    min-width: 20px !important;
    min-height: 20px !important;
    max-width: 20px !important;
    max-height: 20px !important;
    margin: 0 10px 0 0 !important;
    padding: 0 !important;
    flex-shrink: 0 !important;
    background-repeat: no-repeat !important;
    background-position: center !important;
    background-size: 20px 20px !important;
    pointer-events: none !important;
}

/* ERROR: Subtle Red Accent & Vector Circle-X */
#toast-container > .toast-error,
#toast-container .toast.toast-error {
    border: 1px solid rgba(239, 68, 68, 0.35) !important;
}
#toast-container > .toast-error::before,
#toast-container .toast.toast-error::before {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='20' height='20' viewBox='0 0 24 24' fill='none' stroke='%23ef4444' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='12' cy='12' r='10'/%3E%3Cline x1='15' y1='9' x2='9' y2='15'/%3E%3Cline x1='9' y1='9' x2='15' y2='15'/%3E%3C/svg%3E") !important;
}

/* SUCCESS: Subtle Green Accent & Vector Circle-Check */
#toast-container > .toast-success,
#toast-container .toast.toast-success {
    border: 1px solid rgba(34, 197, 94, 0.35) !important;
}
#toast-container > .toast-success::before,
#toast-container .toast.toast-success::before {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='20' height='20' viewBox='0 0 24 24' fill='none' stroke='%2322c55e' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='12' cy='12' r='10'/%3E%3Cpolyline points='9 12 11 14 15 10'/%3E%3C/svg%3E") !important;
}

/* WARNING: Subtle Amber Accent & Vector Alert Triangle */
#toast-container > .toast-warning,
#toast-container .toast.toast-warning {
    border: 1px solid rgba(245, 158, 11, 0.35) !important;
}
#toast-container > .toast-warning::before,
#toast-container .toast.toast-warning::before {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='20' height='20' viewBox='0 0 24 24' fill='none' stroke='%23f59e0b' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M10.29 3.86L1.82 18a2 2 0 0 0 1.71 3h16.94a2 2 0 0 0 1.71-3L13.71 3.86a2 2 0 0 0-3.42 0z'/%3E%3Cline x1='12' y1='9' x2='12' y2='13'/%3E%3Cline x1='12' y1='17' x2='12.01' y2='17'/%3E%3C/svg%3E") !important;
}

/* INFO: Subtle Blue Accent & Vector Info Circle */
#toast-container > .toast-info,
#toast-container .toast.toast-info {
    border: 1px solid rgba(59, 130, 246, 0.35) !important;
}
#toast-container > .toast-info::before,
#toast-container .toast.toast-info::before {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='20' height='20' viewBox='0 0 24 24' fill='none' stroke='%233b82f6' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='12' cy='12' r='10'/%3E%3Cline x1='12' y1='16' x2='12' y2='12'/%3E%3Cline x1='12' y1='8' x2='12.01' y2='8'/%3E%3C/svg%3E") !important;
}

/* ─────────────────────────────────────────────────────────────
   4. MESSAGE CONTENT (Flex Item 2 - Center)
───────────────────────────────────────────────────────────── */
#toast-container .toast-message {
    order: 2 !important;
    flex: 1 1 auto !important;
    margin: 0 !important;
    padding: 0 !important;
    font-size: 13.5px !important;
    font-weight: 500 !important;
    line-height: 1.4 !important;
    letter-spacing: -0.01em !important;
    color: #f4f4f5 !important;
    word-break: break-word !important;
    height: auto !important;
    min-height: 0 !important;
    max-height: none !important;
    direction: ltr !important;
}

#toast-container .toast-title {
    order: 2 !important;
    font-size: 13.5px !important;
    font-weight: 600 !important;
    color: #ffffff !important;
    margin: 0 6px 0 0 !important;
    line-height: 1.4 !important;
    height: auto !important;
    min-height: 0 !important;
}

#toast-container .toast-message ul {
    margin: 4px 0 0 0 !important;
    padding-left: 16px !important;
}

#toast-container .toast-message a {
    color: #ffffff !important;
    text-decoration: underline !important;
}

/* ─────────────────────────────────────────────────────────────
   5. CLOSE BUTTON (Flex Item 3 - Right)
───────────────────────────────────────────────────────────── */
#toast-container .toast-close-button {
    order: 3 !important;
    position: static !important; /* Normal flex flow */
    width: 20px !important;
    height: 20px !important;
    min-width: 20px !important;
    min-height: 20px !important;
    max-width: 20px !important;
    max-height: 20px !important;
    margin: 0 0 0 10px !important;
    padding: 0 !important;
    flex-shrink: 0 !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    background: transparent !important;
    border: none !important;
    border-radius: 50% !important;
    color: rgba(255, 255, 255, 0.4) !important;
    font-size: 16px !important;
    line-height: 1 !important;
    cursor: pointer !important;
    outline: none !important;
    transition: color 0.15s ease, background 0.15s ease !important;
}

#toast-container .toast-close-button:hover,
#toast-container .toast-close-button:focus-visible {
    color: #ffffff !important;
    background: rgba(255, 255, 255, 0.12) !important;
}

/* ─────────────────────────────────────────────────────────────
   6. SUBTLE PROGRESS INDICATOR
───────────────────────────────────────────────────────────── */
#toast-container .toast-progress {
    position: absolute !important;
    left: 0 !important;
    bottom: 0 !important;
    height: 2px !important;
    opacity: 0.65 !important;
    border-radius: 0 0 16px 16px !important;
}

#toast-container > .toast-error .toast-progress,
#toast-container .toast.toast-error .toast-progress { background: #ef4444 !important; }
#toast-container > .toast-success .toast-progress,
#toast-container .toast.toast-success .toast-progress { background: #22c55e !important; }
#toast-container > .toast-warning .toast-progress,
#toast-container .toast.toast-warning .toast-progress { background: #f59e0b !important; }
#toast-container > .toast-info .toast-progress,
#toast-container .toast.toast-info .toast-progress { background: #3b82f6 !important; }

/* ─────────────────────────────────────────────────────────────
   7. APPLE SUBTLE ENTRANCE & REDUCED MOTION
───────────────────────────────────────────────────────────── */
@keyframes appleToastSlide {
    0% {
        transform: translateY(-8px) scale(0.98);
    }
    100% {
        transform: translateY(0) scale(1);
    }
}

@media (prefers-reduced-motion: reduce) {
    #toast-container > div,
    #toast-container .toast {
        animation: none !important;
        transition: none !important;
    }
}

/* ─────────────────────────────────────────────────────────────
   8. MOBILE RESPONSIVE (iOS / Android Notch & Dynamic Island Safe)
───────────────────────────────────────────────────────────── */
@media (max-width: 576px) {
    .toast-top-center,
    #toast-container.toast-top-center {
        top: calc(env(safe-area-inset-top, 0px) + 12px) !important;
        left: 50% !important;
        right: auto !important;
        bottom: auto !important;
        transform: translateX(-50%) !important;
        width: max-content !important;
        max-width: calc(100vw - 24px) !important;
        margin: 0 !important;
        padding: 0 !important;
    }

    #toast-container > div,
    #toast-container .toast {
        width: auto !important;
        max-width: calc(100vw - 24px) !important;
        min-width: 0 !important;
        padding: 9px 12px !important;
        border-radius: 14px !important;
        box-shadow: 
            0 6px 20px -2px rgba(0, 0, 0, 0.5),
            0 2px 6px -1px rgba(0, 0, 0, 0.3) !important;
    }

    #toast-container .toast-message {
        font-size: 13px !important;
        line-height: 1.35 !important;
        word-break: break-word !important;
    }

    #toast-container > div::before,
    #toast-container .toast::before {
        width: 18px !important;
        height: 18px !important;
        min-width: 18px !important;
        min-height: 18px !important;
        max-width: 18px !important;
        max-height: 18px !important;
        background-size: 18px 18px !important;
        margin-right: 8px !important;
    }

    #toast-container .toast-close-button {
        width: 24px !important;
        height: 24px !important;
        min-width: 24px !important;
        min-height: 24px !important;
        max-width: 24px !important;
        max-height: 24px !important;
        margin-left: 8px !important;
        font-size: 17px !important;
    }
}
