/*
 * components/modal.css — SfxModal canonical chrome.
 *
 * One source of truth for every modal in the app. Visual language is
 * aligned with the polished `.sfx-tab-info-card` (from layout.css) —
 * deep-violet gradient card, hairline primary border, pop-in animation,
 * themed close button. Other surfaces (`.sfx-modal`, `.room-modal`,
 * `.session-overlay`, etc.) remain for now so existing markup still
 * works, but any NEW modal goes through the .sfx-m-* classes below.
 *
 * Covers:
 *   - .sfx-m-overlay            — backdrop / full-viewport container
 *   - .sfx-m-backdrop-{dim,blur,none}
 *   - .sfx-m-card               — glass gradient card (the actual modal)
 *   - .sfx-m-size-{sm,md,lg,full}
 *   - .sfx-m-head / .sfx-m-title / .sfx-m-close
 *   - .sfx-m-body / .sfx-m-message
 *   - .sfx-m-actions + .sfx-btn / .sfx-btn-{primary,ghost,danger,secondary}
 *   - @keyframes sfxModalPop + sfxModalFade + closing states
 */

@layer components {
    .sfx-m-overlay {
        position: fixed;
        inset: 0;
        display: flex;
        align-items: center;
        justify-content: center;
        padding: 20px;
        animation: sfxModalFade 0.18s ease;
    }
    .sfx-m-overlay.sfx-m-backdrop-dim {
        background: rgba(0, 0, 0, 0.75);
    }
    .sfx-m-overlay.sfx-m-backdrop-blur {
        background: rgba(0, 0, 0, 0.75);
        backdrop-filter: blur(6px);
        -webkit-backdrop-filter: blur(6px);
    }
    .sfx-m-overlay.sfx-m-backdrop-none {
        background: transparent;
        pointer-events: none;
    }
    .sfx-m-overlay.sfx-m-backdrop-none .sfx-m-card {
        pointer-events: auto;
    }
    .sfx-m-overlay.sfx-m-closing {
        animation: sfxModalFadeOut 0.18s ease forwards;
    }

    @keyframes sfxModalFade {
        from { opacity: 0; }
        to { opacity: 1; }
    }
    @keyframes sfxModalFadeOut {
        from { opacity: 1; }
        to { opacity: 0; }
    }

    .sfx-m-card {
        position: relative;
        width: 100%;
        max-width: 440px;
        max-height: 86vh;
        max-height: 86dvh;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        padding: 24px 26px 22px;
        background: linear-gradient(160deg,
            rgba(20, 14, 38, 0.97),
            rgba(12, 8, 24, 0.98));
        border: 1px solid rgba(var(--primary-rgb), 0.35);
        border-radius: 16px;
        box-shadow:
            0 20px 60px rgba(0, 0, 0, 0.5),
            0 0 32px rgba(var(--primary-rgb), 0.15);
        color: var(--text-primary);
        animation: sfxModalPop 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
    }
    .sfx-m-overlay.sfx-m-closing .sfx-m-card {
        animation: sfxModalPopOut 0.18s ease forwards;
    }

    @keyframes sfxModalPop {
        from { transform: scale(0.9); opacity: 0; }
        to { transform: scale(1); opacity: 1; }
    }
    @keyframes sfxModalPopOut {
        from { transform: scale(1); opacity: 1; }
        to { transform: scale(0.95); opacity: 0; }
    }

    .sfx-m-size-sm { max-width: 360px; }
    .sfx-m-size-md { max-width: 440px; }
    .sfx-m-size-lg { max-width: 640px; }
    .sfx-m-size-full {
        max-width: min(92vw, 1200px);
        width: min(92vw, 1200px);
        max-height: 92dvh;
    }

    /* Wave 16 — modal titles are centered by default app-wide. Close
     * button floats absolutely top-right so the title can occupy the
     * full head row width without competing for space. The previous
     * `space-between` head + flex close was retired here; any modal
     * that genuinely wants a left-aligned title can opt-in via
     * `sfx-m-card-titled-left` (no current consumer). */
    .sfx-m-head {
        display: flex;
        align-items: center;
        justify-content: center;
        gap: 12px;
        margin-bottom: 14px;
    }
    .sfx-m-title {
        font-size: 1.25rem;
        font-weight: 700;
        margin: 0;
        text-align: center;
        flex: 0 0 auto;
        background: linear-gradient(135deg, var(--primary), var(--secondary));
        background-clip: text;
        -webkit-background-clip: text;
        color: var(--primary);
        -webkit-text-fill-color: transparent;
        letter-spacing: -0.01em;
        /* Wave 17 follow-up — give floating tittles (the dot of
         * lowercase i, j) and accent marks room. Without explicit
         * line-height the browser default plus -webkit-text-fill-color:
         * transparent could clip the small disconnected glyph. */
        line-height: 1.4;
        padding: 2px 0;
    }
    /* Default close placement is absolute top-right — won't fight the
     * centered title for space and matches the room-modal convention. */
    .sfx-m-close {
        position: absolute;
        top: 12px;
        right: 12px;
    }

    /* Wave 13 / Wave 16 — the `.sfx-m-card-centered` class is the
     * `confirm() / alert()` layout: title-centering is now the default
     * (above), but this class additionally centers the BODY content
     * (icon stacked above message, vertically aligned). Kept as a
     * separate class because regular modals (settings panels, lists)
     * still want left-aligned body content. */
    .sfx-m-card-centered .sfx-m-body {
        text-align: center;
        display: flex;
        flex-direction: column;
        align-items: center;
        gap: 10px;
    }
    /* Escape hatch — opt back into the old left-aligned title layout
     * if a future modal needs it. Currently unused. */
    .sfx-m-card-titled-left .sfx-m-head {
        justify-content: space-between;
    }
    .sfx-m-card-titled-left .sfx-m-title {
        text-align: left;
    }
    .sfx-m-card-titled-left .sfx-m-close {
        position: static;
    }

    .sfx-m-icon {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        width: 48px;
        height: 48px;
        margin: 4px auto 8px;
        /* No circular bg / border — SOTA confirm dialogs (Apple HIG,
           Material) show the icon directly. The circle frame felt
           extraneous and competed with the icon's own shape. */
        background: transparent;
        border: 0;
        animation: sfxIconPop 0.36s cubic-bezier(0.34, 1.56, 0.64, 1) 0.05s both;
    }
    .sfx-m-icon .sfx-icon {
        width: 40px;
        height: 40px;
        color: var(--primary);
    }
    .sfx-m-icon .sfx-icon-destructive {
        color: #ef4444;
        filter: drop-shadow(0 0 8px rgba(239, 68, 68, 0.45));
    }
    @keyframes sfxIconPop {
        0% { transform: scale(0.4); opacity: 0; }
        60%  { transform: scale(1.1); opacity: 1; }
        100%   { transform: scale(1); }
    }
    html[data-motion="off"] .sfx-m-icon { animation: none; }
    .sfx-m-close {
        width: 32px;
        height: 32px;
        min-width: 32px;
        min-height: 32px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        background: rgba(255, 255, 255, 0.06);
        border: 1px solid rgba(255, 255, 255, 0.08);
        border-radius: 50%;
        color: rgba(255, 255, 255, 0.7);
        cursor: pointer;
        padding: 0;
        transition: background 0.18s ease, color 0.18s ease, transform 0.18s ease, border-color 0.18s ease;
        flex-shrink: 0;
    }
    .sfx-m-close:hover,
    .sfx-m-close:focus-visible {
        background: rgba(var(--secondary-rgb), 0.2);
        color: var(--secondary);
        border-color: rgba(var(--secondary-rgb), 0.4);
        transform: rotate(90deg);
    }
    /* Legacy alias — `.sfx-m-close` is already absolute by default.
     * Kept as a no-op so any historical markup still positions correctly. */
    .sfx-m-close-float {
        position: absolute;
        top: 12px;
        right: 12px;
    }

    .sfx-m-body {
        color: var(--text-secondary);
        font-size: 0.92rem;
        line-height: 1.55;
    }
    .sfx-m-body > :first-child { margin-top: 0; }
    .sfx-m-body > :last-child { margin-bottom: 0; }

    .sfx-m-message {
        margin: 4px 0 0;
        color: var(--text-secondary);
        font-size: 0.95rem;
        line-height: 1.55;
    }

    .sfx-m-actions {
        display: flex;
        gap: 12px;
        justify-content: stretch;
        margin-top: 22px;
    }
    .sfx-m-actions .sfx-btn {
        flex: 1 1 0;
        min-width: 0;  /* let flex shrink past content size */
    }
    /* Centered confirm/alert layout: equal-width buttons span full row. */
    .sfx-m-card-centered .sfx-m-actions {
        justify-content: stretch;
    }

    /* Shared button kit — used by SfxModal actions and SfxBanner actions.
     * Matches the visual language of the existing .sfx-btn-primary /
     * .sfx-btn-secondary in gallery.css, but re-declared here at layer
     * specificity so it survives future dedup passes. */
    .sfx-btn {
        padding: 10px 20px;
        border: none;
        border-radius: 10px;
        font-family: inherit;
        font-weight: 600;
        font-size: 0.9rem;
        cursor: pointer;
        min-height: 40px;
        min-width: 90px;
        transition: transform 0.16s ease, box-shadow 0.16s ease, filter 0.16s ease, background 0.16s ease;
        line-height: 1.2;
    }
    .sfx-btn:active { transform: translateY(0); }
    .sfx-btn:hover { transform: translateY(-1px); }
    .sfx-btn-primary {
        background: linear-gradient(135deg, var(--primary), var(--primary-light));
        color: #fff;
        box-shadow: 0 4px 14px rgba(var(--primary-rgb), 0.35);
    }
    .sfx-btn-primary:hover {
        box-shadow: 0 6px 18px rgba(var(--primary-rgb), 0.5);
    }
    .sfx-btn-secondary {
        background: linear-gradient(135deg, var(--secondary-dark, var(--secondary)), var(--secondary));
        color: #fff;
        box-shadow: 0 4px 14px rgba(var(--secondary-rgb), 0.35);
    }
    .sfx-btn-secondary:hover {
        box-shadow: 0 6px 18px rgba(var(--secondary-rgb), 0.5);
    }
    .sfx-btn-ghost {
        background: rgba(255, 255, 255, 0.05);
        color: var(--text-primary);
        border: 1px solid rgba(255, 255, 255, 0.1);
    }
    .sfx-btn-ghost:hover {
        background: rgba(255, 255, 255, 0.09);
        border-color: rgba(255, 255, 255, 0.18);
    }
    .sfx-btn-danger {
        background: linear-gradient(135deg, #ef4444, #dc2626);
        color: #fff;
        box-shadow: 0 4px 14px rgba(239, 68, 68, 0.3);
    }
    .sfx-btn-danger:hover {
        box-shadow: 0 6px 18px rgba(239, 68, 68, 0.45);
    }

    /* Mobile: full-height overlay so dynamic viewport changes don't clip,
     * and a bit more breathing room around the card. */
    @media (max-width: 600px) {
        .sfx-m-overlay {
            padding: 16px;
        }
        .sfx-m-card {
            padding: 20px 18px 18px;
            max-height: 90dvh;
        }
        .sfx-m-size-lg,
        .sfx-m-size-full {
            width: 100%;
            max-width: 100%;
        }
        .sfx-m-title {
            font-size: 1rem;
        }
        .sfx-m-actions {
            gap: 8px;
            flex-direction: column-reverse;
        }
        .sfx-m-actions .sfx-btn {
            width: 100%;
        }
    }

    /* Motion preferences — shorten animations for 'reduced', skip for 'off'. */
    html[data-motion="reduced"] .sfx-m-overlay {
        animation-duration: 0.1s;
    }
    html[data-motion="reduced"] .sfx-m-card {
        animation-duration: 0.12s;
    }
    html[data-motion="off"] .sfx-m-overlay,
    html[data-motion="off"] .sfx-m-card,
    html[data-motion="off"] .sfx-m-overlay.sfx-m-closing,
    html[data-motion="off"] .sfx-m-overlay.sfx-m-closing .sfx-m-card {
        animation: none !important;
    }
    @media (prefers-reduced-motion: reduce) {
        .sfx-m-overlay,
        .sfx-m-card,
        .sfx-m-close {
            animation-duration: 0.01ms !important;
            transition-duration: 0.01ms !important;
        }
    }
}
