/**
 * SESSIONVAULT - MODALS & OVERLAYS CSS
 * --------------------------------------------------------
 * 1. Global Modal Overlay & Cards
 * 2. Toast Notifications
 * 3. Full-Screen Gates (Login, Passkey, Onboarding)
 * ========================================================
 */

/* ======================================================== */
/* 1. GLOBAL MODAL OVERLAY & CARDS                          */
/* ======================================================== */
.custom-modal-overlay {
    position: fixed;
    top: 0;
    inset-inline-start: 0;
    width: 100vw;
    height: 100vh;
    /* FIX: Replaced backdrop-filter with a solid opacity to prevent mobile GPU flickering */
    background: rgba(15, 23, 42, 0.75);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s ease;
}

.custom-modal-overlay.active {
    opacity: 1;
    pointer-events: all;
}

/* FIX: Z-INDEX OVERRIDE FOR GLOBAL CONFIRMS (Forces them over Modals, Lock Overlay, and Global Loader) */
#custom-alert-modal,
#custom-confirm-modal,
#custom-prompt-modal {
    z-index: 999999999 !important;
}

#payment-info-modal {
    z-index: 10500 !important;
}

.custom-modal-card {
    background: #ffffff;
    border-radius: 12px;
    max-width: 440px;
    width: 92%;
    padding: 24px;
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1);
    /* Forced GPU hardware acceleration to stop keyboard slide-up flickering */
    transform: scale(0.95) translateZ(0);
    -webkit-transform: scale(0.95) translateZ(0);
    backface-visibility: hidden;
    perspective: 1000;
    transition: transform 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
    max-height: calc(100vh - 40px);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    box-sizing: border-box;
}

@media (max-width: 600px) {
    .custom-modal-card {
        padding: 20px 16px;
        width: 94%;
    }
}

.custom-modal-overlay.active .custom-modal-card {
    transform: scale(1) translateZ(0);
    -webkit-transform: scale(1) translateZ(0);
}

/* ======================================================== */
/* 2. TOAST NOTIFICATIONS                                   */
/* ======================================================== */
.app-toast {
    position: fixed;
    bottom: 30px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(15, 23, 42, 0.95);
    color: #ffffff;
    padding: 12px 24px;
    border-radius: 8px;
    font-size: 0.9rem;
    font-weight: 500;
    z-index: 30000;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.3);
    max-width: 90vw;
    word-break: break-word;
    text-align: center;
}

.app-toast.show {
    opacity: 1;
}

/* ======================================================== */
/* 3. FULL-SCREEN GATES (Login, Passkey, Onboarding)        */
/* ======================================================== */
.onboarding-card {
    background: #ffffff;
    border-radius: 16px;
    max-width: 440px;
    width: 100%;
    padding: 40px;
    box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.1);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
}

#passkey-lock-overlay,
#login-gate-overlay {
    position: fixed;
    top: 0;
    inset-inline-start: 0;
    width: 100vw;
    height: 100%;
    min-height: 100vh;
    display: none;
    align-items: center;
    justify-content: flex-start;
    padding: max(20px, 4vh) 16px 40px 16px;
    z-index: 1000;
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch !important;
    box-sizing: border-box;
}

#passkey-lock-overlay {
    background: #f8fafc;
    z-index: 20000;
}

#login-gate-overlay {
    background: #f8fafc;
    z-index: 1001;
}

#onboarding-overlay {
    position: fixed;
    inset: 0;
    display: none;
    background: rgba(15, 23, 42, 0.95);
    z-index: 9999;
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch !important;
    padding: 40px 16px !important;
}

#onboarding-overlay .onboarding-card {
    max-width: 650px !important;
    width: 100% !important;
    display: block !important;
    margin: 0 auto 150px auto !important;
    height: auto !important;
    max-height: none !important;
}

#onboarding-overlay .onboarding-card h2,
#onboarding-overlay .onboarding-card p {
    text-align: center;
}

/* FORCE TOUR TOOLTIP TO BE RESPONSIVE ON SCALED SCREENS & ENLARGED FONTS */
#tour-tooltip {
    max-width: min(360px, calc(100vw - 32px)) !important;
    box-sizing: border-box !important;
    max-height: calc(100vh - 32px) !important;
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch !important;
    word-break: break-word !important;
    overflow-wrap: break-word !important;
}

@media (max-width: 600px) {
    #tour-tooltip {
        padding: 18px 20px !important;
        width: calc(100vw - 32px) !important;
        max-width: calc(100vw - 32px) !important;
    }
}

/* ======================================================== */
/* 4. UPGRADE PRO MODAL & SUBSCRIPTION PILL                 */
/* ======================================================== */
#upgrade-pro-modal {
    z-index: 10600 !important;
}

.upgrade-modal-close {
    position: absolute;
    top: 14px;
    inset-inline-end: 16px;
    background: none;
    border: none;
    font-size: 1.6rem;
    line-height: 1;
    color: #94a3b8;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 6px;
    transition: color 0.15s ease, background-color 0.15s ease;
}

.upgrade-modal-close:hover {
    color: #0f172a;
    background-color: #f1f5f9;
}

.upgrade-pro-card {
    max-width: 520px;
    width: 100%;
    padding: 28px 24px;
    transition: max-width 0.2s ease;
}

.upgrade-plan-cards-container {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

@media (min-width: 768px) {
    .upgrade-pro-card {
        max-width: 800px !important;
        padding: 32px 36px !important;
    }

    .upgrade-pro-grid {
        display: grid;
        grid-template-columns: 1.15fr 1fr;
        gap: 28px;
        align-items: stretch;
    }
}

@media (max-width: 767px) {
    .upgrade-pro-card {
        max-width: 480px;
        padding: 24px 18px !important;
    }

    .upgrade-pro-grid {
        display: flex;
        flex-direction: column;
        gap: 16px;
    }
}

.upgrade-plan-option {
    user-select: none;
    cursor: pointer;
    border: 2px solid var(--border, #e2e8f0);
    background-color: #ffffff;
    border-radius: 12px;
    padding: 14px;
    position: relative;
    transition: border-color 0.2s ease, background-color 0.2s ease, transform 0.15s ease, box-shadow 0.2s ease;
}

.upgrade-plan-option:hover {
    border-color: #818cf8 !important;
    transform: translateY(-2px);
}

.upgrade-plan-option.selected {
    border-color: #6366f1 !important;
    background-color: #eef2ff !important;
    box-shadow: 0 4px 14px rgba(99, 102, 241, 0.18) !important;
}

.topbar-sub-pill {
    display: inline-flex;
    align-items: center;
    gap: 2px;
    padding: 4px 10px;
    border-radius: 9999px;
    font-size: 0.72rem;
    font-weight: 700;
    line-height: 1;
    cursor: pointer;
    transition: transform 0.15s ease, opacity 0.15s ease;
    white-space: nowrap;
    user-select: none;
}

.topbar-sub-pill:hover {
    transform: scale(1.03);
    opacity: 0.92;
}

.topbar-sub-pill.trial {
    background: #e0e7ff;
    color: #4338ca;
    border: 1px solid #c7d2fe;
}

.topbar-sub-pill.pro {
    background: #dcfce7;
    color: #15803d;
    border: 1px solid #86efac;
    cursor: default;
}

.topbar-sub-pill.pro:hover {
    transform: none;
    opacity: 1;
}

.topbar-sub-pill.read-only {
    background: #fee2e2;
    color: #b91c1c;
    border: 1px solid #fca5a5;
    animation: pulse-soft 2s infinite;
}

@keyframes pulse-soft {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.8; }
}

.topbar-pill-icon {
    display: inline-flex;
    align-items: center;
    font-size: 0.7rem;
    line-height: 1;
    transform: translateY(-2px);
}

.topbar-pill-full {
    display: inline;
}

.topbar-pill-compact {
    display: none;
}
