/* ═══════════════════════════════════════════════════════════════════════════════
 * visual-prefs.css — Visual Preference Bar styling (Phase 2 polish)
 *
 * Visual Empathy Blueprint v2 §2.2. Glassmorphism to match the launch-site
 * aesthetic. All colors via CSS vars (theme-aware). Hover/focus/reduced-motion/
 * high-contrast handled here (not inline) so media queries + [data-*] work.
 *
 * Z-index layering (verified against funnel.css):
 *   vp-backdrop  = 10099   (above funnel modal 9600, gear 9700, header-Clio 10001/10002)
 *   vp-panel     = 10100
 *   vp-trigger   = 10090
 * ═══════════════════════════════════════════════════════════════════════════════ */

/* ─── Trigger button — floating bottom-left ─── */
.vp-trigger {
    position: fixed;
    left: 16px;
    bottom: calc(16px + env(safe-area-inset-bottom));
    width: 48px;
    height: 48px;
    border-radius: 50%;
    border: 1px solid var(--border-hi);
    background: var(--glass);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    color: var(--text);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10090;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
    transition: transform 0.2s ease, box-shadow 0.2s ease, border-color 0.2s ease;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
}

.vp-trigger:hover {
    transform: translateY(-2px);
    border-color: var(--teal);
    box-shadow: 0 6px 24px rgba(45, 212, 191, 0.3);
}

.vp-trigger:focus-visible {
    outline: 2px solid var(--teal);
    outline-offset: 2px;
}

.vp-trigger[aria-expanded="true"] {
    border-color: var(--teal);
    background: rgba(45, 212, 191, 0.12);
}

/* ─── Backdrop ─── */
.vp-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(2px);
    -webkit-backdrop-filter: blur(2px);
    z-index: 10099;
    visibility: hidden;
    opacity: 0;
    transition: opacity 0.2s ease, visibility 0s 0.2s;
}

.vp-backdrop.vp-open {
    visibility: visible;
    opacity: 1;
    transition: opacity 0.2s ease, visibility 0s;
}

/* ─── Panel — bottom sheet ─── */
.vp-panel {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    max-width: 520px;
    margin: 0 auto;
    background: var(--bg2);
    color: var(--text);
    border: 1px solid var(--border-hi);
    border-bottom: none;
    border-radius: 20px 20px 0 0;
    padding: 0 20px calc(24px + env(safe-area-inset-bottom));
    z-index: 10100;
    box-shadow: 0 -8px 40px rgba(0, 0, 0, 0.4);
    max-height: 80vh;
    overflow-y: auto;
    font-family: var(--font);
    visibility: hidden;
    transform: translateY(100%);
    transition: transform 0.25s cubic-bezier(0.16, 1, 0.3, 1),
                visibility 0s 0.25s;
}

.vp-panel.vp-open {
    visibility: visible;
    transform: translateY(0);
    transition: transform 0.25s cubic-bezier(0.16, 1, 0.3, 1), visibility 0s;
}

/* Drag handle (bottom-sheet convention) */
.vp-handle {
    width: 36px;
    height: 4px;
    border-radius: 2px;
    background: var(--text-dim);
    margin: 8px auto 0;
    opacity: 0.5;
}

/* ─── Header ─── */
.vp-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 0 12px;
    position: sticky;
    top: 0;
    background: var(--bg2);
    z-index: 1;
}

.vp-title {
    font-size: 1.1rem;
    font-weight: 600;
    margin: 0;
}

.vp-close {
    background: none;
    border: 1px solid var(--border);
    color: var(--text-muted);
    cursor: pointer;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
    -webkit-tap-highlight-color: transparent;
}

.vp-close:hover {
    background: var(--glass);
    color: var(--text);
    border-color: var(--border-hi);
}

.vp-close:focus-visible {
    outline: 2px solid var(--teal);
    outline-offset: 2px;
}

/* ─── Row ─── */
.vp-row {
    margin-bottom: 18px;
}

.vp-row-label {
    font-size: 0.85rem;
    font-weight: 600;
    margin-bottom: 8px;
    color: var(--text-muted);
}

/* ─── Segmented control ─── */
.vp-seg {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}

.vp-seg-btn {
    flex: 1 1 auto;
    min-width: 64px;
    min-height: 44px;
    padding: 8px 12px;
    border-radius: 10px;
    border: 1px solid var(--border);
    background: var(--bg3);
    color: var(--text-muted);
    cursor: pointer;
    font-family: var(--font);
    font-size: 0.85rem;
    font-weight: 500;
    transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
    -webkit-tap-highlight-color: transparent;
}

.vp-seg-btn:hover {
    border-color: var(--border-hi);
    color: var(--text);
}

.vp-seg-btn:focus-visible {
    outline: 2px solid var(--teal);
    outline-offset: 2px;
}

.vp-seg-btn[aria-pressed="true"] {
    background: linear-gradient(135deg, var(--cyan), var(--teal));
    color: #06101a;
    border-color: transparent;
    font-weight: 700;
    box-shadow: 0 2px 8px rgba(45, 212, 191, 0.3);
}

/* ─── Toggle switch ─── */
.vp-toggle {
    width: 44px;
    height: 26px;
    border-radius: 13px;
    border: 1px solid var(--border-hi);
    background: var(--bg3);
    cursor: pointer;
    padding: 2px;
    display: flex;
    align-items: center;
    transition: background 0.15s ease, border-color 0.15s ease;
    -webkit-tap-highlight-color: transparent;
    flex-shrink: 0;
}

.vp-toggle:focus-visible {
    outline: 2px solid var(--teal);
    outline-offset: 2px;
}

.vp-toggle[aria-checked="true"] {
    background: rgba(45, 212, 191, 0.25);
    border-color: var(--teal);
}

.vp-toggle-knob {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--text-muted);
    transition: transform 0.15s ease, background 0.15s ease;
}

.vp-toggle[aria-checked="true"] .vp-toggle-knob {
    transform: translateX(18px);
    background: var(--teal);
}

/* ─── Footer note ─── */
.vp-note {
    font-size: 0.8rem;
    color: var(--text-dim);
    margin-top: 16px;
    line-height: 1.5;
}

/* ═══════════════════════════════════════════════════════════════════════════════
 *  High-contrast adjustments — strengthen borders + text under [data-contrast="high"]
 * ═══════════════════════════════════════════════════════════════════════════════ */
:root[data-contrast="high"] .vp-trigger,
:root[data-contrast="high"] .vp-panel,
:root[data-contrast="high"] .vp-close,
:root[data-contrast="high"] .vp-seg-btn {
    border-color: var(--text-muted);
}

:root[data-contrast="high"] .vp-seg-btn[aria-pressed="true"] {
    color: #000;
    border: 2px solid var(--text);
    box-shadow: none;
}

:root[data-contrast="high"] .vp-toggle {
    border-color: var(--text);
}

:root[data-contrast="high"] .vp-toggle[aria-checked="true"] {
    border-width: 2px;
}

/* ═══════════════════════════════════════════════════════════════════════════════
 *  Reduced motion — suppress all panel animations (user toggle + OS)
 *  The global [data-motion="reduce"] + @media rules in variables.css already
 *  neutralize transition-duration, but the slide-up transform needs explicit reset
 *  so the panel appears instantly for reduced-motion users.
 * ═══════════════════════════════════════════════════════════════════════════════ */
:root[data-motion="reduce"] .vp-panel {
    transform: none;
    transition: none;
}

:root[data-motion="reduce"] .vp-panel.vp-open {
    transform: none;
}

@media (prefers-reduced-motion: reduce) {
    .vp-panel {
        transform: none;
        transition: none;
    }
    .vp-panel.vp-open {
        transform: none;
    }
}

/* ═══════════════════════════════════════════════════════════════════════════════
 *  Mobile adjustments
 *  - ≤768px: the mobile sticky CTA bar is ~72px tall at bottom:0 (z-index 700).
 *    Raise the trigger ABOVE it so they don't overlap.
 *  - ≤480px: tighter padding, full-width panel.
 * ═══════════════════════════════════════════════════════════════════════════════ */
@media (max-width: 768px) {
    .vp-trigger {
        /* Sit above the 72px sticky CTA bar + a 12px gap + safe-area */
        bottom: calc(84px + env(safe-area-inset-bottom));
    }
}

@media (max-width: 480px) {
    .vp-trigger {
        left: 12px;
        bottom: calc(84px + env(safe-area-inset-bottom));
    }
    .vp-panel {
        max-width: 100%;
        border-radius: 16px 16px 0 0;
        padding: 0 16px calc(20px + env(safe-area-inset-bottom));
    }
    .vp-seg-btn {
        min-width: 56px;
        padding: 8px 8px;
        font-size: 0.8rem;
    }
}

/* ═══════════════════════════════════════════════════════════════════════════════
 *  Desktop (>1024px) — could move trigger to header pill (future enhancement).
 *  For now, the floating icon works on all breakpoints.
 * ═══════════════════════════════════════════════════════════════════════════════ */
