/* ===== SPLASH SCREEN + ONBOARDING + MOBILE CHAT ENHANCEMENT ===== */
/* Version: 2.0.0 — Mobile-first chat experience */

/* ============================= */
/*  SECTION 1: SPLASH SCREEN    */
/* ============================= */
#splashScreen {
    position: fixed;
    inset: 0;
    z-index: 999999;
    background: #0f172a;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    transition: opacity 0.5s ease, visibility 0.5s ease;
}
#splashScreen.fade-out {
    opacity: 0;
    visibility: hidden;
}
.splash-logo {
    width: 96px;
    height: 96px;
    border-radius: 24px;
    box-shadow: 0 16px 48px rgba(0,0,0,0.15);
    animation: splash-breathe 2s ease-in-out infinite;
    margin-bottom: 24px;
}
@media (min-width: 768px) {
    .splash-logo {
        width: 120px;
        height: 120px;
        border-radius: 28px;
    }
}
.splash-title {
    font-size: 28px;
    font-weight: 800;
    color: #ffffff;
    letter-spacing: -0.5px;
    margin-bottom: 4px;
}
.splash-subtitle {
    font-size: 14px;
    color: rgba(148,163,184,0.8);
    font-weight: 400;
}
.splash-loader {
    margin-top: 32px;
    width: 40px;
    height: 40px;
    border: 3px solid rgba(255,255,255,0.1);
    border-top: 3px solid rgba(255,255,255,0.5);
    border-radius: 50%;
    animation: splash-spin 0.8s linear infinite;
}
@keyframes splash-spin {
    to { transform: rotate(360deg); }
}
@keyframes splash-breathe {
    0%, 100% { transform: scale(1); box-shadow: 0 16px 48px rgba(0,0,0,0.15); }
    50% { transform: scale(1.02); box-shadow: 0 20px 56px rgba(0,0,0,0.2); }
}

/* ============================= */
/*  SECTION 2: ONBOARDING       */
/* ============================= */
#onboardingScreen {
    position: fixed;
    inset: 0;
    z-index: 999998;
    background: #ffffff;
    display: flex;
    flex-direction: column;
    align-items: center;
    /* Use safe centering: center when space allows, scroll from top when it doesn't */
    justify-content: safe center;
    padding: 24px;
    transition: opacity 0.4s ease, visibility 0.4s ease;
    overflow-y: auto;
}
/* Fallback for browsers that don't support 'safe center' */
@supports not (justify-content: safe center) {
    #onboardingScreen {
        justify-content: flex-start;
    }
}
#onboardingScreen.hidden {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}

.onboard-card {
    max-width: 420px;
    width: 100%;
    text-align: center;
    animation: onboard-slide-up 0.5s ease;
    /* Ensure logo/bottom link never clip against screen edges */
    margin-top: auto;
    margin-bottom: auto;
    padding-top: 16px;
    padding-bottom: 24px;
    flex-shrink: 0;
}
@keyframes onboard-slide-up {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}

.onboard-logo {
    width: 72px;
    height: 72px;
    border-radius: 20px;
    box-shadow: 0 8px 24px rgba(0,0,0,0.08);
    margin-bottom: 20px;
}
.onboard-title {
    font-size: 24px;
    font-weight: 800;
    color: #0f172a;
    margin-bottom: 6px;
    line-height: 1.2;
}
.onboard-subtitle {
    font-size: 14px;
    color: #64748b;
    margin-bottom: 24px;
    line-height: 1.5;
}
.onboard-features {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-bottom: 24px;
    text-align: left;
}
.onboard-feature {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    background: #ffffff;
    border-radius: 14px;
    border: 1px solid #e2e8f0;
    box-shadow: 0 1px 3px rgba(0,0,0,0.04);
    transition: transform 0.15s, box-shadow 0.15s;
}
.onboard-feature:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(0,0,0,0.06);
}
.onboard-feature-icon {
    width: 38px;
    height: 38px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-size: 15px;
    color: #fff;
}
.onboard-feature-text {
    font-size: 13px;
    font-weight: 600;
    color: #1e293b;
}
.onboard-feature-text small {
    display: block;
    font-size: 11px;
    font-weight: 400;
    color: #94a3b8;
    margin-top: 2px;
}

.onboard-cta-primary {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    padding: 15px 24px;
    background: #1e293b;
    color: #fff;
    font-size: 16px;
    font-weight: 600;
    border: none;
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.15s;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    margin-bottom: 10px;
    gap: 8px;
    letter-spacing: -0.2px;
}
.onboard-cta-primary:hover {
    opacity: 0.9;
}
.onboard-cta-primary:active {
    transform: scale(0.99);
}

.onboard-cta-secondary {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    padding: 13px 24px;
    background: #ffffff;
    color: #475569;
    font-size: 14px;
    font-weight: 600;
    border: 1px solid #e4e4e7;
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.15s;
    margin-bottom: 8px;
}
.onboard-cta-secondary:hover {
    background: #f8fafc;
    border-color: #cbd5e1;
    color: #1e293b;
}

.onboard-skip {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    margin-top: 10px;
    font-size: 13px;
    color: #64748b;
    cursor: pointer;
    background: none;
    border: none;
    font-weight: 500;
    transition: color 0.15s;
    padding: 8px 16px;
}
.onboard-skip:hover {
    color: #1e293b;
}

.onboard-trial-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 7px 16px;
    background: #f4f4f5;
    border: 1px solid #e4e4e7;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 600;
    color: #3f3f46;
    margin-bottom: 18px;
}

.onboard-divider {
    display: flex;
    align-items: center;
    gap: 12px;
    margin: 12px 0;
    color: #cbd5e1;
    font-size: 11px;
    font-weight: 500;
}
.onboard-divider::before,
.onboard-divider::after {
    content: '';
    flex: 1;
    height: 1px;
    background: #e2e8f0;
}

/* ======================================= */
/*  SECTION 3: MOBILE CHAT ENHANCEMENTS   */
/*  Refined for visual harmony & elegance  */
/* ======================================= */

/* --- Mobile header: elegant, airy --- */
@media (max-width: 768px) {
    .chat-header-minimal {
        padding: 10px 14px;
        border-bottom: 1px solid var(--border-light, #e4e4e7);
        background: rgba(255,255,255,0.97);
        -webkit-backdrop-filter: blur(16px);
        backdrop-filter: blur(16px);
    }
    .chat-header-inner {
        gap: 6px;
    }
    /* Sofia avatar — refined circle with subtle shadow */
    .chat-header-inner img.w-8 {
        width: 34px !important;
        height: 34px !important;
        border-radius: 50% !important;
        box-shadow: 0 1px 4px rgba(0,0,0,0.1);
        border: 2px solid #ffffff;
        outline: 1px solid var(--border-light, #e4e4e7);
    }
    /* Header text — clean hierarchy */
    .chat-header-inner h3 {
        font-size: 15px !important;
        font-weight: 700 !important;
        letter-spacing: -0.01em;
        color: var(--text-primary, #1e293b) !important;
    }
    .chat-header-inner p.text-gray-400 {
        font-size: 10px !important;
        color: var(--text-muted, #a1a1aa) !important;
        letter-spacing: 0.01em;
    }
    .chat-header-inner p.text-gray-400 .bg-green-500 {
        width: 5px !important;
        height: 5px !important;
    }
    
    /* Action buttons — labeled layout on mobile */
    .chat-header-actions {
        gap: 1px;
    }
    .chat-header-action-btn {
        border-radius: 10px;
        font-size: 13px;
        background: var(--surface-1, #fafafa);
        border: 1px solid var(--border-light, #e4e4e7);
    }
    .chat-audio-btn {
        border-radius: 10px;
        font-size: 13px;
    }
    .chat-labeled-btn {
        min-width: 32px;
        padding: 4px 3px 2px !important;
    }
    .chat-labeled-btn i {
        font-size: 12px;
    }
    .chat-btn-label {
        font-size: 7px;
    }
    
    /* --- Mobile input area: floating, refined --- */
    .chat-input-wrapper {
        padding: 8px 10px 0;
        padding-bottom: max(8px, env(safe-area-inset-bottom));
        background: transparent;
        position: relative;
    }
    .chat-input-container {
        background: var(--surface-0, #ffffff);
        border-radius: 22px;
        border: 1px solid var(--border-light, #e4e4e7);
        box-shadow: 0 -1px 12px rgba(0,0,0,0.04);
        padding: 4px;
    }
    .chat-input-bar {
        border: none !important;
        box-shadow: none !important;
        background: transparent !important;
        border-radius: 18px;
        padding: 4px 6px 4px 10px;
        gap: 4px;
    }
    .chat-input-bar:focus-within {
        box-shadow: none !important;
        border: 1px solid var(--text-primary, #1e293b) !important;
        background: transparent !important;
    }
    /* + button — subtle, proportional */
    .chat-input-icon-btn {
        width: 34px;
        height: 34px;
        font-size: 14px;
    }
    
    /* Credit bar — clean, spacious, legible */
    .chat-credit-bar {
        margin-top: 6px;
        padding: 2px 10px 4px;
        font-size: 10px;
        gap: 6px;
    }
    
    /* Messages area: breathing room */
    .chat-messages-area {
        padding: 14px 12px 8px;
        scroll-behavior: smooth;
    }
    
    /* Send button: refined */
    .chat-send-btn {
        width: 36px;
        height: 36px;
        border-radius: 50%;
        font-size: 14px;
    }
    
    /* Chat message avatars */
    .chat-msg-avatar { width: 26px; height: 26px; margin-top: 1px; }
    .chat-msg-avatar img { width: 26px; height: 26px; }
    
    /* Tighter message spacing on mobile */
    .chat-msg { margin-bottom: 16px; padding: 0 2px; }
    .chat-msg-name { font-size: 13px; font-weight: 600; }
    .chat-msg-time { font-size: 10px; }
    .chat-msg-assistant .message-content { font-size: 14.5px; line-height: 1.7; color: var(--text-secondary, #3f3f46); }
    .chat-msg-body-user { 
        max-width: 82%;
        font-size: 14.5px;
        padding: 10px 15px;
        border-radius: 18px 18px 4px 18px;
    }
    
    /* Rewards banner — compact, non-intrusive */
    #rewardProgressContainer {
        padding: 6px 12px !important;
        border-bottom: 1px solid var(--border-light, #e4e4e7);
        background: var(--surface-1, #fafafa);
    }
    #rewardProgressContainer .reward-progress-header {
        font-size: 12px !important;
        padding: 4px 0 !important;
    }
}

/* --- Mobile: smooth scroll behavior for messages --- */
@media (max-width: 768px) {
    #chatMessages {
        scroll-behavior: smooth;
        overscroll-behavior: contain;
    }
}

/* --- Explore landing link in chat (visible on mobile) --- */
.chat-explore-btn {
    display: none; /* hidden on desktop */
}
@media (max-width: 768px) {
    .chat-explore-btn {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        gap: 4px;
        padding: 0;
        width: 32px;
        height: 32px;
        font-size: 11px;
        font-weight: 500;
        color: var(--text-muted, #a1a1aa);
        background: var(--surface-1, #fafafa);
        border: 1px solid var(--border-light, #e4e4e7);
        border-radius: 10px;
        cursor: pointer;
        transition: all 0.15s;
        overflow: hidden;
    }
    .chat-explore-btn span {
        display: none;
    }
    .chat-explore-btn:hover {
        background: var(--surface-2, #f4f4f5);
        color: var(--text-secondary, #3f3f46);
    }
    .chat-explore-btn i {
        font-size: 13px;
    }
}

/* ======================================= */
/*  SECTION 4: MOBILE-FIRST ADJUSTMENTS   */
/* ======================================= */

/* Small phones (< 375px) */
@media (max-width: 375px) {
    .splash-logo { width: 72px; height: 72px; border-radius: 18px; }
    .splash-title { font-size: 22px; }
    .splash-subtitle { font-size: 12px; }
    
    .onboard-logo { width: 60px; height: 60px; border-radius: 16px; }
    .onboard-title { font-size: 18px; }
    .onboard-subtitle { font-size: 13px; margin-bottom: 16px; }
    .onboard-features { gap: 8px; margin-bottom: 18px; }
    .onboard-feature { padding: 10px 12px; gap: 10px; }
    .onboard-feature-icon { width: 32px; height: 32px; font-size: 12px; }
    .onboard-feature-text { font-size: 12px; }
    .onboard-feature-text small { font-size: 10px; }
    .onboard-cta-primary { padding: 13px 18px; font-size: 14px; }
    .onboard-cta-secondary { padding: 11px 18px; font-size: 13px; }

    /* Tiny labeled buttons on small phones */
    .chat-labeled-btn {
        min-width: 28px;
        padding: 3px 2px 1px !important;
    }
    .chat-labeled-btn i {
        font-size: 11px;
    }
    .chat-btn-label {
        font-size: 6px;
    }
    .chat-header-actions {
        gap: 0px;
    }
}

/* Medium phones (375px - 640px) */
@media (min-width: 376px) and (max-width: 640px) {
    .splash-logo { width: 84px; height: 84px; border-radius: 22px; }
    .splash-title { font-size: 26px; }
    
    .onboard-title { font-size: 21px; }
    .onboard-feature { padding: 11px 14px; }
    .onboard-cta-primary { padding: 14px 20px; font-size: 15px; }
}

/* Safe area padding for notched phones */
@supports (padding: max(0px)) {
    #splashScreen {
        padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
    }
    #onboardingScreen {
        padding-top: max(24px, env(safe-area-inset-top));
        padding-bottom: max(24px, env(safe-area-inset-bottom));
    }
}

/* ===================================== */
/*  SECTION 5: LANDING BANNER IN CHAT   */
/* ===================================== */
.chat-landing-banner {
    display: none;
}
@media (max-width: 768px) {
    .chat-landing-banner {
        display: block;
        text-align: center;
        padding: 10px 12px;
        background: var(--surface-1, #fafafa);
        border-bottom: 1px solid var(--border-light, #e4e4e7);
    }
    .chat-landing-banner-text {
        font-size: 12px;
        color: var(--text-tertiary, #71717a);
    }
    .chat-landing-banner-text a {
        color: var(--text-primary, #1e293b);
        font-weight: 600;
        text-decoration: none;
    }
    .chat-landing-banner-text a:hover {
        text-decoration: underline;
    }
}

/* ===================================== */
/*  SECTION 6: REDUCED MOTION           */
/* ===================================== */
@media (prefers-reduced-motion: reduce) {
    .splash-logo { animation: none; }
    .splash-loader { animation: none; }
    .onboard-card { animation: none; }
    .onboard-feature { transition: none; }
    #splashScreen { transition: none; }
    #onboardingScreen { transition: none; }
}
