/* --- 1. Variables & Root Theme --- */
:root {
    --primary-blue: #0056b3;
    --accent-blue: #007bff;
    --dental-dark: #0f172a;
    --soft-blue: #eef4ff;
    --white: #ffffff;
    --error-red: #ef4444;
    --glass-bg: rgba(255, 255, 255, 0.15);
}

* {
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

body, html {
    margin: 0;
    padding: 0;
    font-family: 'Inter', -apple-system, sans-serif;
    background-color: var(--dental-dark);
}

/* --- 2. Master App Container (The Shell) --- */
#main-app-shell {
    position: relative;
    width: 95%;
    max-width: 1400px;
    height: calc(100vh - 40px);
    margin: 20px auto; 
    border-radius: 2.5rem;
    overflow: hidden; 
    background-color: var(--dental-dark);
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
    z-index: 1;
    /* Prevent accidental text selection highlights during interaction */
    user-select: none;
    -webkit-user-select: none;
}

/* Watermark Logo - Global Layer (Fixed Size) */
.app-watermark {
    position: absolute;
    top: 1.5rem;
    left: 1.5rem;
    width: 62px;   /* Desktop size as requested */
    height: auto;
    opacity: 0.4;  
    z-index: 9999; /* Highest priority: above all screens/webcams */
    pointer-events: none; 
    filter: drop-shadow(0 2px 4px rgba(0,0,0,0.1));
    transition: opacity 0.3s ease;
}

/* Allow text selection only in inputs */
input, textarea {
    user-select: text !important;
    -webkit-user-select: text !important;
}

/* --- 3. Background & Video Overlays --- */
#bg-video {
    position: absolute;
    top: 0; left: 0; width: 100%; height: 100%;
    object-fit: cover;
    z-index: 1;
    pointer-events: none;
    filter: saturate(0.7) brightness(0.8);
}

.video-overlay {
    position: absolute;
    inset: 0;
    background: rgba(15, 23, 42, 0.4);
    z-index: 2;
    pointer-events: none;
    transition: background 0.8s ease;
}

/* --- 4. Section Management --- */
section {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    display: none; 
    align-items: center;
    justify-content: center;
    z-index: 10;
    opacity: 0;
    transition: opacity 0.5s ease;
}

section.active {
    display: flex;
    opacity: 1;
}

#screen-1 {
    justify-content: flex-end; /* Desktop Landing card to the right */
}

.glass-container {
    background: var(--glass-bg) !important;
    backdrop-filter: blur(40px) brightness(0.9);
    -webkit-backdrop-filter: blur(40px) brightness(0.9);
}

/* --- 5. The Survey Container (Dual Width Logic) --- */
#survey-container {
    background: white;
    padding: 2.5rem;
    border-radius: 2.5rem;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
    width: 100%;
    max-width: 48rem; /* Default Questionnaire width */
    position: relative;
    min-height: 550px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    transition: max-width 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}

/* Expanded state for Lead Form */
#survey-container.wide-card {
    max-width: 70rem;
}

/* --- 6. Animations --- */
.card-animate { animation: slideUpFade 0.7s cubic-bezier(0.16, 1, 0.3, 1) both; }
.shake { animation: shakeCard 0.4s cubic-bezier(.36,.07,.19,.97) both; }

@keyframes slideUpFade {
    0% { opacity: 0; transform: translateY(40px) scale(0.98); }
    100% { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes shakeCard {
    10%, 90% { transform: translate3d(-2px, 0, 0); }
    20%, 80% { transform: translate3d(4px, 0, 0); }
    30%, 50%, 70% { transform: translate3d(-6px, 0, 0); }
    40%, 60% { transform: translate3d(6px, 0, 0); }
}

@keyframes slideInDown { from { opacity: 0; transform: translateY(-5px); } to { opacity: 1; transform: translateY(0); } }

/* --- 7. Validation & Errors --- */
/* Floating Red Tooltip (Survey Skip Attempt) */
.error-tooltip {
    background: var(--error-red);
    color: white;
    padding: 10px 20px;
    border-radius: 12px;
    font-size: 0.9rem;
    font-weight: 700;
    position: absolute;
    bottom: calc(100% + 15px);
    right: 0;
    box-shadow: 0 10px 15px -3px rgba(239, 68, 68, 0.4);
    z-index: 100;
    white-space: nowrap;
    animation: tooltipBounce 0.3s ease-out;
}

.error-tooltip::after {
    content: '';
    position: absolute;
    top: 100%;
    right: 30px;
    border-width: 8px;
    border-style: solid;
    border-color: var(--error-red) transparent transparent transparent;
}

@keyframes tooltipBounce {
    0% { opacity: 0; transform: translateY(10px); }
    70% { transform: translateY(-2px); }
    100% { opacity: 1; transform: translateY(0); }
}

/* Inline Lead Form Errors */
.field-group { position: relative; width: 100%; margin-bottom: 0.5rem; }
input.invalid { border-color: var(--error-red) !important; background-color: #fff5f5; }
.field-error { 
    color: var(--error-red); 
    font-size: 0.85rem; 
    font-weight: 600; 
    margin-top: 4px; 
    animation: slideInDown 0.2s ease-out; 
}

/* Lead Form Icon Colors */
.field-group i { pointer-events: none; transition: color 0.3s ease; }
.field-group input:focus + i { color: var(--accent-blue); }
input.invalid + i { color: var(--error-red) !important; }

/* --- 8. Option Buttons --- */
.option-btn {
    transition: all 0.2s ease;
    border: 2px solid #f1f5f9;
    text-align: left;
    padding: 1.25rem;
    border-radius: 1rem;
    color: var(--dental-dark);
    background: white;
}

.option-btn:hover {
    border-color: var(--accent-blue) !important;
    background-color: var(--soft-blue) !important;
    color: var(--dental-dark) !important; 
    transform: translateX(5px);
}

/* --- 9. Immersive Result Slider --- */
.slider-container-fullscreen {
    position: absolute;
    inset: 0; 
    width: 100%;
    height: 100%;
    overflow: hidden;
    cursor: ew-resize;
    background: #000;
}

.slider-img {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover; 
    pointer-events: none;
}

#before-img { z-index: 10; clip-path: inset(0 50% 0 0); }

.slider-handle {
    position: absolute;
    top: 0; bottom: 0; left: 50%;
    width: 4px; background: white; z-index: 20; transform: translateX(-50%);
}

.slider-handle::after {
    content: ''; position: absolute; top: 50%; left: 50%;
    transform: translate(-50%, -50%);
    width: 56px; height: 56px;
    background: var(--primary-blue); border: 4px solid white; border-radius: 50%;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m18 8 4 4-4 4'/%3E%3Cpath d='m6 8-4 4 4 4'/%3E%3C/svg%3E");
    background-repeat: no-repeat; background-position: center; background-size: 24px;
    box-shadow: 0 0 30px rgba(0, 0, 0, 0.5);
}

/* --- 10. Webcam & Donut Progress --- */
#screen-3 { background: #000 !important; z-index: 100; }
#webcam-feed { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; z-index: 1; }

.oval-mask {
    position: absolute;
    top: 45%; left: 50%; transform: translate(-50%, -50%);
    width: 400px; height: 540px; 
    border: 4px dashed rgba(255, 255, 255, 0.6);
    border-radius: 50%; pointer-events: none; z-index: 10;
    box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.6); 
}

#progress-donut { stroke-dasharray: 553; stroke-dashoffset: 553; transition: stroke-dashoffset 0.5s ease-out; }

/* --- 11. Responsiveness --- */
@media (max-width: 768px) {
    #main-app-shell { width: 100%; height: 100vh; margin: 0; border-radius: 0; }
    
    .app-watermark {
        top: 1rem;
        left: 1rem;
        width: 48px; /* Mobile size */
        opacity: 0.3;
    }

    /* Target the sections to ensure they align content to the top */
    /* Target the section to stop centering vertically */
    section {
        display: block !important; /* Switch from flex to block for natural flow */
        overflow-y: auto !important;
        -webkit-overflow-scrolling: touch;
        height: 100%;
        padding-top: 1.5rem; /* Safe area at the top */
        padding-bottom: 6rem; /* Space at the bottom so the last card isn't cramped */
    }

    /* Target only the landing screen */
    #screen-1 {
        display: flex !important;
        justify-content: center !important; /* Horizontal Center */
        align-items: center !important;     /* Vertical Center */
        padding: 1.5rem !important;        /* Balanced gutter */
        height: 100% !important;
        width: 100% !important;
        position: absolute
    }

    #screen-5 {
        position:absolute;
    }

    /* Ensure the card inside Screen 1 doesn't align to the top */
    #screen-1 .card-animate {
        margin-top: 0 !important;
        width: 100%;
        max-width: 400px;
    }    

    /* Target the inner flex wrapper on Screen 2 */
    #screen-2 .flex-col {
        display: flex;
        flex-direction: column;
        justify-content: flex-start !important;
        align-items: center !important;
        margin-top: 0;
    }

    /* Ensure the cards don't try to shrink */
    #screen-2 .flex-1 {
        flex: none !important;
        width: 100%;
        max-width: 400px; /* Keep them look like cards, not full-width blocks */
        padding: 20px;
    }

    .glass-container {
        overflow-y: auto;
        display: flex;
        flex-direction: column;
    }

    /* Ensure the Survey Container also starts at the top on mobile */
    #survey-container {
        margin-top: 1rem;
        margin-bottom: 2rem;
        min-height: auto; /* Allow it to shrink/grow based on content */
    }

    /* Navigation Stacking */
    .mobile-nav-footer {
        flex-direction: column-reverse !important; 
        gap: 1.5rem !important;
        align-items: stretch !important;
        margin-top: 2rem;
    }

    .mobile-progress-wrapper { width: 100% !important; margin-bottom: 0.5rem; }
    .mobile-button-group { display: flex; gap: 0.75rem; width: 100%; }
    .mobile-button-group button { flex: 1; padding: 1rem 0; font-size: 1rem; }

    /* Adaptive Face Guide */
    .oval-mask { width: 85vw; height: 58vh; top: 48%; }
}

/* Hide scrollbars for clean look */
#survey-container::-webkit-scrollbar { width: 4px; }
#survey-container::-webkit-scrollbar-thumb {
    background: rgba(0, 86, 179, 0.1);
    border-radius: 10px;
}

/* --- Widget Specific Overrides --- */
body.is-widget #main-app-shell {
    width: 100%;
    max-width: 100%;
    margin: 0;
    height: 800px;
    border-radius: 0; /* Let the Webflow container handle the rounding */
    box-shadow: none;
}

/* Ensure the background video covers the entire iframe area */
body.is-widget #bg-video {
    position: fixed;
}