/* ==========================================================================
   SERVICE RECOMMENDATION QUIZ - STRUCTURAL CSS (quiz.css)
   Version: 0.2.0
   Order: Variables -> Modal Shell -> Quiz Wrapper -> Progress -> Steps -> Chips -> Buttons
   ========================================================================== */

/* --- 1. Default Fallback Variables --- */
:root {
    --sqe-modal-background: #ffffff; /* Default white */
    --sqe-pill-incomplete: #e9ecef;  /* Default Bootstrap gray-200 */
    --sqe-pill-current: #0d6efd;     /* Default Bootstrap primary */
    --sqe-pill-completed: #198754;   /* Default Bootstrap success */
    --sqe-er: #dc3545;               /* Default Bootstrap danger */
}

/* --- 2. Modal Shell & Backdrop (modal-wrapper.php) --- */

/* Apply frosted glass blur directly to the fixed modal container */
.sqe-blur-modal {
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    background-color: rgba(0, 0, 0, 0.7);
}

/* Hide Bootstrap's default solid backdrop overlay so custom blur shows */
.modal-backdrop.show {
    opacity: 0 !important;
}

/* Fix z-index stacking if the ER modal triggers while inside the main modal */
#sqe-er-modal {
    z-index: 1060;
}

/* Ensure the quiz container respects the modal bounds */
#sqeQuizModal .sqe-quiz-wrapper {
    min-height: 500px;
    padding: 1rem;
}

/* Ensure the close button breaks out of the modal body stacking context */
#sqeQuizModal .btn-close {
    position: absolute;
    top: 1rem;
    right: 1rem;
    z-index: 1050 !important; /* Higher than any modal body content */
    pointer-events: auto !important;
}

/* --- 3. Core Quiz Layout & Dynamic Height (quiz-template.php) --- */

.sqe-quiz-wrapper {
    max-width: 800px;
    margin: 0 auto;
    position: relative;
    display: flex;
    flex-direction: column;
}

/* Enforce the minimum height lock ONLY on tablet/desktop */
@media (min-width: 768px) {
    .sqe-quiz-wrapper {
        min-height: 450px;
    }
}

#sqe-quiz-container {
    display: flex;
    flex-direction: column;
    flex-grow: 1;
    width: 100%;
    /* Remove any min-height: 100% or similar that was forcing it open */
}

#sqe-content-wrapper {
    position: relative;
    width: 100%;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    flex-grow: 1;
    /* Remove padding-bottom: 1rem; to let it hug the buttons */
}

/* Ensure the step container stretches as well */
#sqe-step-container {
    position: relative;
    width: 100%;
    display: flex; /* Pass the flex context down to the steps */
    flex-direction: column;
    flex-grow: 1; /* Stretch to fill the remaining space below the progress bar */
}

/* --- 4. Progress Tracker --- */

/* Base container positioning */
#sqe-progress-container {
    margin-top: 0;
    margin-bottom: 2rem !important;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
}

/* High-specificity override to defeat theme margin collapse */
.modal-body #sqe-progress-container,
.modal-body div#sqe-progress-container {
    margin-bottom: 2rem !important;
}

/* High-specificity override for text spacing */
.modal-body #sqe-progress-text,
.modal-body div#sqe-progress-text {
    margin-bottom: 1rem !important;
}

/* Pills container footprint lock */
#sqe-progress-pills {
    min-height: 6px; /* Ensures vertical slot holds even when empty on Step 0 */
    width: 100%;
}

/* Individual Pill structural sizing and transitions */
.sqe-progress-pill {
    height: 2px;
    width: 2rem;
    border-radius: 10px;
    transition: background-color 0.3s ease-in-out;
}

@media(min-width: 768px) {
    .sqe-progress-pill {
        width: 16%;
    }
}

/* High-specificity override for pill border-radius */
.modal-body .sqe-progress-pill {
    border-radius: 10px !important;
}

/* Apply variable colors */
.sqe-pill-incomplete { background-color: var(--sqe-pill-incomplete); }
.sqe-pill-current    { background-color: var(--sqe-pill-current); }
.sqe-pill-completed  { background-color: var(--sqe-pill-completed); }


/* Protect the mt-auto wrapper for mobile responsive anchoring */
/* Mobile: Ensure standard spacing beneath content */
.modal-body #sqe-quiz-container .mt-4,
.modal-body div#sqe-quiz-container .mt-4 {
    margin-top: 1.5rem !important;
}

/* Desktop: Push buttons flush to the bottom of the grid cell */
@media (min-width: 768px) {
    .modal-body #sqe-quiz-container .mt-md-auto,
    .modal-body div#sqe-quiz-container .mt-md-auto {
        margin-top: auto !important;
    }
}

/* Protect the intro text bottom margin (mb-5) from being stripped */
.modal-body #sqe-quiz-container .sqe-intro-text,
.modal-body div#sqe-quiz-container .sqe-intro-text {
    margin-bottom: 3rem !important;
}

/* Restore Start Over Button spacing */
.modal-body .sqe-reset-container,
.modal-body div.sqe-reset-container {
    margin-top: 1rem !important; /* Adjust spacing above "Start Quiz Again" */
    display: flex !important;
    justify-content: flex-end !important;
}

/* Protect the mt-auto wrapper inside the results screen */
.modal-body #step-results .mt-4,
.modal-body div#step-results .mt-4 {
    margin-top: 1.5rem !important; /* Enforce mobile margin */
}

@media (min-width: 768px) {
    .modal-body #step-results .mt-md-auto,
    .modal-body div#step-results .mt-md-auto {
        margin-top: auto !important; /* Enforce desktop bottom anchor */
    }
}

/* --- 5. Step Containers & Animations --- */

/* 1. Base Step Container */
#sqe-step-container {
    display: grid;
    grid-template-areas: "stack";
    width: 100%;
    flex-grow: 1;
}

/* 2. Base Step Rule */
.sqe-step {
    grid-area: stack;
    width: 100%;
    margin: 0 !important;

    /* Change to display: none so inactive steps DO NOT force grid height */
    display: none !important;
    flex-direction: column;
}

/* 3. The Active Step */
.sqe-step.active {
    display: flex !important; /* Only the active step dictates height */
    z-index: 2;
}

/* 4. The Animating Out Step */
.sqe-step.animating-out {
    display: flex !important; /* Keep visible ONLY while sliding out */
    z-index: 1;
}

/* --- 6. Choice Chips & Inputs --- */

/* Ensure the wrapper respects Flexbox child stretching */
.sqe-choice-chip {
    display: block;
    cursor: pointer;
}

.cursor-pointer {
    cursor: pointer;
}

/* Core pill/card structure */
.sqe-chip-label {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    padding: 0.5rem 1rem;
    min-height: 44px; /* WCAG touch target */
    cursor: pointer;
    transition: all 0.2s ease;
    text-align: center;
    user-select: none;
    background-color: transparent;
    border: 2px solid transparent;
    border-radius: 0;
}

/* Visual Interaction States (Consider moving these to theme.css for strict separation) */
.sqe-choice-chip:hover .sqe-chip-label {
    background-color: #e9ecef;
    border-color: #adb5bd !important;
}

.sqe-input:checked ~ .sqe-chip-label {
    background-color: #e0f2fe;
    border-color: #0d6efd !important;
    color: #0a58ca;
    font-weight: 600;
}

.sqe-input:focus-visible ~ .sqe-chip-label {
    outline: 3px solid #0d6efd;
    outline-offset: 2px;
}


/* --- 7. Action Buttons & Bottom Layout --- */

/* Action row flex container */
.sqe-action-row {
    display: flex;
    flex-wrap: nowrap;
    justify-content: flex-end; /* Aligns to the right */
    align-items: center;
    gap: 0.5rem;
    width: 100%;
    margin-top: auto !important; /* Pushes the row to the absolute bottom */
    padding-top: 1.5rem; /* Breathing room between content and buttons */
}

/* High-specificity override against theme margins */
.modal-body .sqe-action-row,
.modal-body div.sqe-action-row {
    margin-top: auto !important;
}

/* Force standard button sizing against aggressive theme overrides */
.sqe-action-row .btn,
.sqe-back-btn,
.sqe-next-btn {
    min-width: 6.25rem !important;
    width: auto !important;
}

/* Step 0 Specific Action Buttons */
.sqe-patient-type-btn {
    min-width: 12rem;
    width: 100%;
}

@media (min-width: 768px) {
    .sqe-patient-type-btn {
        width: auto;
    }
}

/* Results Screen Reset Link */
.sqe-reset-container {
    display: flex;
    justify-content: flex-end;
    width: 100%;
    margin-top: 0.5rem;
}

/* Emergency State Override for Result Title */
#sqe-result-title.sqe-er-title {
    color: var(--sqe-er) !important;
    background-color: transparent !important;
    border-color: var(--sqe-er) !important;
}