@import url('https://fonts.googleapis.com/css2?family=Poppins:ital,wght@0,100;0,200;0,300;0,400;0,500;0,600;0,700;0,800;0,900;1,100;1,200;1,300;1,400;1,500;1,600;1,700;1,800;1,900&display=swap');

/* =========================================================
   Global Variables and Resets
   ========================================================= */
:root {
    --primary-green: #bbd551;
    --primary-dark: #1c3433;
    --bg-color: #f4f1eb;
    --text-main: #111827;
    --text-muted: #4B5563;
    --card-bg: #FFFFFF;
    --border-light: #E5E7EB;
}

/* =========================================================
   Generic Helpers
   ========================================================= */
.capitalize {
    text-transform: capitalize;
}

body {
    margin: 0;
    padding: 0;
    font-family: 'Poppins', system-ui, -apple-system, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-main);
    line-height: 1.5;
}

/* =========================================================
   Header Styling
   ========================================================= */
header {
    background-color: var(--card-bg);
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 5%;
    border-bottom: 1px solid var(--border-light);
}

header img {
    width: 258px;
}

header a {
    text-decoration: none;
}

header a:first-child {
    display: flex;
    flex-direction: column;
    justify-content: center;
}

header a[href^="tel"] {
    background-color: var(--primary-dark);
    color: #ffffff;
    padding: 10px 30px;
    border-radius: 40px;
    display: flex;
    flex-direction: column;
    align-items: center;
    line-height: 1.2;
}

header a[href^="tel"] span:first-child {
    color: var(--primary-green);
    font-size: 1.2rem;
    font-weight: 400;
    margin-bottom: 5px;
}

header a[href^="tel"] span:last-child {
    font-size: 1.2rem;
    font-weight: 700;
}

/* =========================================================
   Main Container Layout
   ========================================================= */
form {
    max-width: 900px;
    margin: 0 auto;
    padding: 20px 20px 40px 20px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;

    /* Forces main to exactly fill the remaining screen real estate */
    min-height: calc(100vh - 96px);
    width: 100%;
    box-sizing: border-box;
}

/* Hero Section, Loaders, Datetime, Terms alignment */
#hero,
[role="status"],
#terms h2 + p {
    text-align: center;
    width: 100%;
}

#hero h1,
[role="status"] h2,
#datetime h2,
#terms h2,
#address h2 {
    font-size: 2.7rem;
    font-weight: 600;
    margin: 0 0 10px 0;
    color: var(--text-main);
    line-height: 1.2;
}

#hero p,
[role="status"] p,
#datetime h2 + p,
#terms h2 + p {
    font-size: 1.2rem;
    font-weight: 500;
    color: var(--text-muted);
    margin: 0;
}

/* =========================================================
   Base Card Styling (For all form/interaction sections)
   ========================================================= */
form > section:not(#hero):not(:last-of-type):not([role="status"]):not(#datetime):not(#terms):not(#appointment-success):not(#appointment-error):not(#lead-success):not(#address) {
    background-color: var(--card-bg);
    width: 100%;
    max-width: 800px;
    padding: 15px 20px 20px 20px;
    box-sizing: border-box;
    position: relative;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.03);
    border-top: 10px solid var(--border-light);
}

/* Progress bar pseudo-element (adjustable width) */
form > section:not(#hero):not(:last-of-type):not([role="status"]):not(#datetime):not(#terms):not(#appointment-success):not(#appointment-error):not(#lead-success):not(#address)::before {
    content: '';
    position: absolute;
    top: -10px;
    left: 0;
    height: 10px;
    background-color: var(--primary-dark);
}

/* =========================================================
   Fieldsets, Labels, and Form Elements
   ========================================================= */
fieldset {
    border: none;
    padding: 0;
    margin: 0;
}

legend, h2 {
    font-size: 1.5rem;
    font-weight: 500;
    text-align: center;
    width: 100%;
    margin-bottom: 25px;
    color: var(--text-main);
}

/* Radio Button Options (Pills) */
label:has(input[type="radio"]) {
    display: block;
    background-color: var(--primary-green);
    color: var(--text-main);
    font-weight: bold;
    padding: 15px;
    border-radius: 6px;
    text-align: center;
    cursor: pointer;
    margin-bottom: 12px;
    transition: opacity 0.2s;
    font-size: 1.2rem;
}

label:has(input[type="radio"]):hover {
    opacity: 0.9;
}

label:has(input[type="radio"]:checked) {
    background-color: var(--primary-dark);
    color: var(--primary-green);
}

input[type="radio"] {
    display: none;
}

/* Trust / Lock text */
fieldset + p,
p[aria-hidden="true"] {
    text-align: center;
    font-weight: bolder;
    font-size: 1.1rem;
    margin: 0.8rem 0 0 0;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 5px;
}

fieldset + p::before,
p[aria-hidden="true"]::before {
    content: url("https://cdn.garage.com/hf/lock.svg");
}

/* Bottom Dark Call Box */
section > a[href^="tel"] {
    display: block;
    background-color: var(--primary-dark);
    color: #ffffff;
    text-decoration: none;
    text-align: center;
    padding: 10px;
    margin-top: 15px;
}

section > a[href^="tel"] span {
    display: block;
}

section > a[href^="tel"] span:first-child {
    font-size: 1.3rem;
    margin-bottom: 5px;
    font-weight: 700;
}

section > a[href^="tel"] span:last-child {
    font-size: 1.2rem;
    font-weight: 400;
}

/* Text Inputs and Selects */
div:has(> input[type="text"]),
div:has(> input[type="email"]),
div:has(> input[type="tel"]),
div:has(> select) {
    margin-bottom: 15px;
    text-align: left;
}

label[for]:not(.action-btn) {
    display: block;
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-bottom: 5px;
}

input[type="text"],
input[type="email"],
input[type="tel"],
select {
    width: 100%;
    padding: 14px;
    border: 1px solid var(--border-light);
    border-radius: 6px;
    font-size: 1.2rem;
    box-sizing: border-box;
    background-color: #FAFAFA;
}

input:focus, select:focus {
    outline: 2px solid var(--primary-green);
    border-color: transparent;
}

/* =========================================================
   Form Validation & Button Reactivity
   ========================================================= */

/* 1. Real-time visual feedback for valid inputs */
input[type="text"]:not(:placeholder-shown):valid,
input[type="email"]:not(:placeholder-shown):valid,
input[type="tel"]:not(:placeholder-shown):valid,
select:not(:has(option[disabled]:checked)):not(:has(option[value=""]:checked)) {
    border-color: var(--primary-green);
    background-color: #FAFAFA;
}

/* 2. Strict validation for the Zip Code pattern (\d{5}) */
#zip-code:not(:placeholder-shown):valid {
    border-color: var(--primary-green);
    background-color: #f0fce0;
}

/* 3. Visual feedback for invalid inputs */
input[type="text"]:not(:placeholder-shown):invalid,
input[type="email"]:not(:placeholder-shown):invalid,
input[type="tel"]:not(:placeholder-shown):invalid,
input[type="text"]:user-invalid,
input[type="email"]:user-invalid,
input[type="tel"]:user-invalid,
select:invalid,
#zip-code:not(:placeholder-shown):invalid,
#zip-code:user-invalid {
    border-color: #EF4444;
    background-color: #FAFAFA;
    outline-color: #EF4444;
}

input[type="text"]:not(:placeholder-shown):invalid:focus,
input[type="email"]:not(:placeholder-shown):invalid:focus,
input[type="tel"]:not(:placeholder-shown):invalid:focus,
input[type="text"]:user-invalid:focus,
input[type="email"]:user-invalid:focus,
input[type="tel"]:user-invalid:focus,
select:invalid:focus,
#zip-code:not(:placeholder-shown):invalid:focus,
#zip-code:user-invalid:focus {
    outline: 2px solid #EF4444;
    border-color: #EF4444;
}

/* 4. Base Error Message Styling */
div:has(> input:not(:placeholder-shown):invalid)::after,
div:has(> input:user-invalid)::after,
div:has(> select:invalid)::after {
    display: block;
    color: #DC2626;
    padding: 8px 14px;
    font-size: 0.85rem;
    font-weight: 500;
    text-align: left;
    line-height: 1.4;
    box-sizing: border-box;
    width: 100%;
}

/* 5. Field Specific Error Messages */
div:has(> [name="zip"]:not(:placeholder-shown):invalid)::after,
div:has(> [name="zip"]:user-invalid)::after,
div:has(> #zip-code:not(:placeholder-shown):invalid)::after,
div:has(> #zip-code:user-invalid)::after {
    content: '✕ Please enter a 5-digit zip code';
}

div:has(> [name="firstName"]:not(:placeholder-shown):invalid)::after,
div:has(> [name="firstName"]:user-invalid)::after,
div:has(> #firstName:not(:placeholder-shown):invalid)::after,
div:has(> #firstName:user-invalid)::after {
    content: '✕ Please enter a valid first name';
}

div:has(> [name="lastName"]:not(:placeholder-shown):invalid)::after,
div:has(> [name="lastName"]:user-invalid)::after,
div:has(> #lastName:not(:placeholder-shown):invalid)::after,
div:has(> #lastName:user-invalid)::after {
    content: '✕ Please enter a valid last name';
}

div:has(> [name="email"]:not(:placeholder-shown):invalid)::after,
div:has(> [name="email"]:user-invalid)::after,
div:has(> #email:not(:placeholder-shown):invalid)::after,
div:has(> #email:user-invalid)::after {
    content: '✕ Please enter a valid email';
}

div:has(> [name="phone"]:not(:placeholder-shown):invalid)::after,
div:has(> [name="phone"]:user-invalid)::after,
div:has(> #phone:not(:placeholder-shown):invalid)::after,
div:has(> #phone:user-invalid)::after {
    content: '✕ Please enter a valid phone';
}

div:has(> [name="addressLine1"]:not(:placeholder-shown):invalid)::after,
div:has(> [name="addressLine1"]:user-invalid)::after,
div:has(> #addressLine1:not(:placeholder-shown):invalid)::after,
div:has(> #addressLine1:user-invalid)::after {
    content: '✕ Please enter a valid street address';
}

div:has(> [name="addressLine2"]:not(:placeholder-shown):invalid)::after,
div:has(> [name="addressLine2"]:user-invalid)::after,
div:has(> [name="addresLine2"]:not(:placeholder-shown):invalid)::after,
div:has(> [name="addresLine2"]:user-invalid)::after,
div:has(> #addressLine2:not(:placeholder-shown):invalid)::after,
div:has(> #addressLine2:user-invalid)::after {
    content: '✕ Please enter a valid street address';
}

div:has(> [name="city"]:not(:placeholder-shown):invalid)::after,
div:has(> [name="city"]:user-invalid)::after,
div:has(> #city:not(:placeholder-shown):invalid)::after,
div:has(> #city:user-invalid)::after {
    content: '✕ Please enter a valid city';
}

/* 6. Conditionally disable Action Buttons if forms are empty or invalid */
#contact:has(:invalid) > .action-btn,
#address:has(:invalid) > .action-btn {
    opacity: 0.5;
    pointer-events: none; /* Prevents clicking */
    cursor: not-allowed;
}

/* =========================================================
   Zip Code Verification Animations (Spinner -> Morph Check)
   ========================================================= */
#zip fieldset div {
    position: relative;
}

/* The Spinner (Spins faster at 1.2s, then hides at 2s) */
#zip fieldset div:has(#zip-code:not(:placeholder-shown):valid)::before {
    content: '';
    position: absolute;
    right: 15px;
    bottom: 13px;
    width: 22px;
    height: 22px;
    box-sizing: border-box;
    border: 3px solid var(--border-light);
    border-top-color: var(--primary-green);
    border-radius: 50%;
    animation:
            zip-spin 0.6s linear infinite,
            hide-loader-screen 0s 2s forwards;
    z-index: 2;
}

/* The Morph Checkmark (Uses borders to match the spinner box shape and rotates in) */
#zip fieldset div:has(#zip-code:not(:placeholder-shown):valid)::after {
    content: '';
    position: absolute;
    right: 21px;
    bottom: 17px;
    width: 7px;
    height: 15px;
    border: solid var(--primary-green);
    border-width: 0 3px 3px 0;
    opacity: 0;
    transform: rotate(0deg) scale(0.5);
    animation: zip-morph-check 0.3s 2s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
    z-index: 2;
}

@keyframes zip-spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

@keyframes zip-morph-check {
    0% {
        opacity: 0;
        transform: rotate(0deg) scale(0.5);
    }
    100% {
        opacity: 1;
        transform: rotate(45deg) scale(1);
    }
}

/* =========================================================
   Buttons & Checkbox Hacks
   ========================================================= */
button[type="button"],
.action-btn {
    width: 100%;
    background-color: var(--primary-green);
    color: var(--text-main);
    border: none;
    font-size: 1.2rem;
    border-radius: 6px;
    cursor: pointer;
    margin-top: 15px;
    transition: opacity 0.2s ease;
    display: block;
    font-weight: bold;
    padding: 15px;
    text-align: center;
    font-family: 'Poppins', system-ui, -apple-system, sans-serif;
    text-decoration: none;
    box-sizing: border-box;
}

button:hover,
.action-btn:hover {
    opacity: 0.9;
}

/* Hide the actual checkbox from view for SPA state triggers */
.state-trigger {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

/* Small Disclaimer Text */
small {
    display: block;
    font-size: 0.75rem;
    color: #888;
    line-height: 1.4;
    text-align: justify;
    margin-top: 20px;
}

/* =========================================================
   Specific styling for Form / Contact Section
   ========================================================= */
#contact {
    text-align: center;
}

#contact > p:first-of-type {
    font-size: 1.5rem;
    margin-bottom: 5px;
    font-weight: 500;
    color: var(--text-main);
    margin-top: 10px;
}

#contact > p:nth-of-type(2),
#contact h2 {
    font-weight: 500;
    font-size: 1.2rem;
    color: var(--text-muted);
    margin-top: 0;
}

#contact h2 {
    margin-top: 5px;
}

#contact > p:nth-of-type(2) {
    margin-bottom: 5px;
}

#contact legend,
#contact label:not(.action-btn) {
    display: none;
}

#contact small {
    padding: 15px;
    background-color: #FAFAFA;
    font-family: 'Poppins', system-ui, -apple-system, sans-serif;
    font-weight: 300;
    border-radius: 5px;
    color: var(--text-main);
    font-size: 1.1rem;
    font-style: italic;
    text-align: start;
}

/* =========================================================
   Loaders Specifics
   ========================================================= */
[role="status"] ul {
    list-style: none;
    padding: 0;
    margin: 30px auto;
    max-width: 500px;
    display: flex;
    flex-direction: column;
    gap: 30px;
}

[role="status"] li {
    display: flex;
    align-items: center;
    text-align: left;
    color: var(--text-muted);
    font-size: 1rem;
    line-height: 1.3;
    position: relative;
    opacity: 0;
}

/* Base style for the icon pseudo-element */
[role="status"] li::before {
    content: '';
    display: inline-block;
    width: 32px;
    height: 32px;
    margin-right: 20px;
    flex-shrink: 0;
    background-color: var(--primary-green);
    -webkit-mask-size: contain;
    mask-size: contain;
    -webkit-mask-repeat: no-repeat;
    mask-repeat: no-repeat;
    -webkit-mask-position: center;
    mask-position: center;
    opacity: 0;
    transform: scale(0.5);
}

/* Availability loader icons */
#loading-availability li:nth-child(1)::before { -webkit-mask-image: url('../images/house-garage.svg'); mask-image: url('../images/house-garage.svg'); }
#loading-availability li:nth-child(2)::before { -webkit-mask-image: url('../images/app-window-badge.svg'); mask-image: url('../images/app-window-badge.svg'); }
#loading-availability li:nth-child(3)::before { -webkit-mask-image: url('../images/check-shield.svg'); mask-image: url('../images/check-shield.svg'); }
#loading-availability li:nth-child(4)::before { -webkit-mask-image: url('../images/calendar-clock.svg'); mask-image: url('../images/calendar-clock.svg'); }
#loading-availability li:nth-child(5)::before { -webkit-mask-image: url('../images/calendar-check.svg'); mask-image: url('../images/calendar-check.svg'); }

/* Appointment booking icons */
#booking-appointment li:nth-child(1)::before { -webkit-mask-image: url('../images/cog-desktop.svg'); mask-image: url('../images/cog-desktop.svg'); }
#booking-appointment li:nth-child(2)::before { -webkit-mask-image: url('../images/calendar-clock.svg'); mask-image: url('../images/calendar-clock.svg'); }
#booking-appointment li:nth-child(3)::before { -webkit-mask-image: url('../images/data-transfer-circle.svg'); mask-image: url('../images/data-transfer-circle.svg'); }
#booking-appointment li:nth-child(4)::before { -webkit-mask-image: url('../images/calendar-check.svg'); mask-image: url('../images/calendar-check.svg'); }

/* Loader Sequence Animations */
[role="status"] li::after {
    content: '';
    position: absolute;
    left: 0;
    top: 50%;
    margin-top: -16px;
    width: 32px;
    height: 32px;
    box-sizing: border-box;
    border: 3px solid transparent;
    border-top-color: var(--primary-green);
    border-radius: 50%;
    opacity: 0;
}

@keyframes reveal-step {
    0% { opacity: 0; transform: translateY(10px); }
    100% { opacity: 1; transform: translateY(0); }
}

@keyframes spin-spinner {
    0% { opacity: 1; transform: rotate(0deg); }
    99% { opacity: 1; transform: rotate(720deg); }
    100% { opacity: 0; transform: rotate(720deg); }
}

@keyframes pop-icon {
    0% { opacity: 0; transform: scale(0.5); }
    100% { opacity: 1; transform: scale(1); }
}

[role="status"] li:nth-child(1) { animation: reveal-step 0.4s 0s forwards; }
[role="status"] li:nth-child(1)::after { animation: spin-spinner 2s 0s linear forwards; }
[role="status"] li:nth-child(1)::before { animation: pop-icon 0.4s 2s forwards; }

[role="status"] li:nth-child(2) { animation: reveal-step 0.4s 2s forwards; }
[role="status"] li:nth-child(2)::after { animation: spin-spinner 2s 2s linear forwards; }
[role="status"] li:nth-child(2)::before { animation: pop-icon 0.4s 4s forwards; }

[role="status"] li:nth-child(3) { animation: reveal-step 0.4s 4s forwards; }
[role="status"] li:nth-child(3)::after { animation: spin-spinner 2s 4s linear forwards; }
[role="status"] li:nth-child(3)::before { animation: pop-icon 0.4s 6s forwards; }

[role="status"] li:nth-child(4) { animation: reveal-step 0.4s 6s forwards; }
[role="status"] li:nth-child(4)::after { animation: spin-spinner 2s 6s linear forwards; }
[role="status"] li:nth-child(4)::before { animation: pop-icon 0.4s 8s forwards; }

[role="status"] li:nth-child(5) { animation: reveal-step 0.4s 8s forwards; }
[role="status"] li:nth-child(5)::after { animation: spin-spinner 2s 8s linear forwards; }
[role="status"] li:nth-child(5)::before { animation: pop-icon 0.4s 10s forwards; }

/* =========================================================
   Datetime Section
   ========================================================= */
#datetime {
    max-width: 800px;
    width: 100%;
    margin: 0 auto;
    text-align: center;
    padding-bottom: 40px; /* Gives breathing room before the footer docks */
}

/* Service / Area Indicator (Pill) */
#datetime > p:nth-of-type(2) {
    display: inline-flex;
    align-items: center;
    border: 1px solid var(--primary-green);
    color: #2e6126;
    padding: 4px 10px;
    border-radius: 30px;
    font-size: 0.9rem;
    font-weight: 500;
    margin-bottom: 25px;
    background-color: #f0fce0;
}

#datetime > p:nth-of-type(2)::before {
    content: '';
    display: inline-block;
    width: 14px;
    height: 14px;
    margin-right: 6px;
    background-color: #2e6126;
    -webkit-mask-image: url('../images/pin.svg');
    mask-image: url('../images/pin.svg');
    -webkit-mask-size: contain;
    mask-size: contain;
    -webkit-mask-repeat: no-repeat;
    mask-repeat: no-repeat;
    -webkit-mask-position: center;
    mask-position: center;
}

#datetime > p:nth-of-type(2) [aria-hidden] {
    margin-left: 5px;
    margin-right: 5px;
}

#datetime > fieldset > legend {
    display: none;
}

/* Promoted Slot Styling (The first option) */
#datetime > fieldset > label {
    display: block;
    text-align: left;
    background-color: var(--card-bg);
    border: 2px solid var(--border-light);
    border-radius: 8px;
    padding: 18px 60px 18px 85px;
    position: relative;
    color: var(--text-main);
    cursor: pointer;
    min-height: 85px;
    box-sizing: border-box;
    transition: all 0.2s ease;
    margin: 0 auto 30px auto;
    max-width: 600px;
}

#datetime > fieldset > label:has(input[type="radio"]:checked) {
    border: 2px solid var(--primary-green);
    box-shadow: 0px 4px 10px rgba(0, 0, 0, 0.05);
}

#datetime > fieldset > label::before {
    content: '';
    position: absolute;
    left: 20px;
    top: 50%;
    transform: translateY(-50%);
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background-color: #9CA3AF;
    transition: background-color 0.2s ease;
}

#datetime > fieldset > label > span:first-of-type::before {
    content: '';
    position: absolute;
    left: 34px;
    top: 50%;
    transform: translateY(-50%);
    width: 20px;
    height: 20px;
    background-color: #FFFFFF;
    -webkit-mask-image: url('../images/bolt.svg');
    mask-image: url('../images/bolt.svg');
    -webkit-mask-size: contain;
    mask-size: contain;
    -webkit-mask-repeat: no-repeat;
    mask-repeat: no-repeat;
    -webkit-mask-position: center;
    mask-position: center;
    z-index: 1;
    transition: background-color 0.2s ease;
}

#datetime > fieldset > label:has(input[type="radio"]:checked)::before {
    background-color: var(--primary-dark);
}
#datetime > fieldset > label:has(input[type="radio"]:checked) > span:first-of-type::before {
    background-color: var(--primary-green);
}

#datetime > fieldset > label:has(input[type="radio"]:checked)::after {
    content: '';
    position: absolute;
    right: 20px;
    top: 50%;
    transform: translateY(-50%);
    width: 28px;
    height: 28px;
    background-color: var(--primary-green);
    -webkit-mask-image: url('../images/check-hollow.svg');
    mask-image: url('../images/check-hollow.svg');
    -webkit-mask-size: contain;
    mask-size: contain;
    -webkit-mask-repeat: no-repeat;
    mask-repeat: no-repeat;
    -webkit-mask-position: center;
    mask-position: center;
}

#datetime > fieldset > label > span:first-of-type {
    font-size: 0.9rem;
    text-transform: uppercase;
    font-weight: 500;
    color: #9CA3AF;
    display: block;
    transition: color 0.2s ease;
}

#datetime > fieldset > label:has(input[type="radio"]:checked) > span:first-of-type {
    color: #748a1a;
}

#datetime > fieldset > label {
    font-size: 1.25rem;
    font-weight: 500;
    color: var(--text-main);
}

#datetime > fieldset > label time:first-of-type::after {
    content: ' · ';
}

/* "OR PICK A TIME" Separator */
#datetime > fieldset > p {
    text-align: center;
    text-transform: uppercase;
    font-size: 1.1rem;
    color: #9CA3AF;
    margin: 40px auto 30px auto;
    position: relative;
    font-weight: 500;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 15px;
    max-width: 800px;
}

#datetime > fieldset > p::before,
#datetime > fieldset > p::after {
    content: '';
    flex: 1;
    height: 1px;
    background: var(--border-light);
}

/* Regular Slot Grid Layout */
#datetime fieldset fieldset {
    margin-bottom: 30px;
    display: grid;
    /* 1 Column: Default (Up to 350px) */
    grid-template-columns: 1fr;
    gap: 12px;
}

/* 2 Columns: 351px to 520px */
@media (min-width: 351px) {
    #datetime fieldset fieldset {
        grid-template-columns: repeat(2, 1fr);
    }
}

/* 3 Columns: 521px to 600px */
@media (min-width: 521px) {
    #datetime fieldset fieldset {
        grid-template-columns: repeat(3, 1fr);
    }
}

/* 4 Columns: 601px and larger */
@media (min-width: 601px) {
    #datetime fieldset fieldset {
        grid-template-columns: repeat(4, 1fr);
    }
}

#datetime fieldset fieldset legend {
    font-size: 1.15rem;
    font-weight: 700;
    color: var(--text-main);
    text-align: center;
    margin-bottom: 20px;
    grid-column: 1 / -1;
}

#datetime fieldset fieldset div {
    display: block;
}

#datetime fieldset fieldset label {
    background-color: var(--card-bg);
    color: var(--text-main);
    border: 1px solid var(--border-light);
    font-weight: 600;
    margin-bottom: 0;
    padding: 18px 10px;
    border-radius: 8px;
    font-size: 1rem;
    transition: all 0.2s ease;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    box-sizing: border-box;
}

#datetime fieldset fieldset label:hover {
    border-color: #A0AAB5;
}

#datetime fieldset fieldset label:has(input[type="radio"]:checked) {
    background-color: var(--primary-dark);
    border-color: var(--primary-dark);
    color: var(--primary-green);
}

#datetime fieldset fieldset label span {
    display: inline;
}

/* Datetime Sticky Bottom Section */
#datetime footer {
    position: sticky;
    bottom: 0;
    width: 100vw;
    margin-left: calc(50% - 50vw - 10px);
    background-color: var(--card-bg);
    padding: 20px 20px 30px 20px;
    box-sizing: border-box;
    box-shadow: 0 -4px 15px rgba(0, 0, 0, 0.05);
    z-index: 100;
}

#datetime footer p {
    display: flex;
    align-items: flex-start;
    justify-content: center;
    text-align: left;
    font-size: 1rem;
    color: var(--text-main);
    max-width: 400px;
    margin: 0 auto 10px auto;
    line-height: 1.3;
    font-weight: 400;
}

#datetime footer p::before {
    content: '';
    display: inline-block;
    width: 1rem;
    height: 1rem;
    margin-right: 12px;
    margin-top: 2px;
    flex-shrink: 0;
    background-color: #748a1a;
    -webkit-mask-image: url('../images/shield-check.svg');
    mask-image: url('../images/shield-check.svg');
    -webkit-mask-size: contain;
    mask-size: contain;
    -webkit-mask-repeat: no-repeat;
    mask-repeat: no-repeat;
    -webkit-mask-position: center;
    mask-position: center;
}

#datetime footer .action-btn {
    max-width: 400px;
    margin: 0 auto;
}

/* =========================================================
   Address Section specifics
   ========================================================= */
#address {
    width: 100%;
    max-width: 800px;
    margin: 0 auto;
    text-align: center;
}

#address legend,
#address label:not(.action-btn) {
    display: none;
}

/* Set up the Grid for the background breakout */
#address > * {
    grid-column: 1;
    z-index: 1;
}

/* Explicit row placement for the elements */
#address > h2 { grid-row: 1; margin-bottom: 20px; font-size: 2.7rem; }
#address > p:first-of-type { grid-row: 2; margin: 30px 20px 20px 20px; font-size: 1.5rem; color: var(--text-main); }
#address > fieldset { grid-row: 3; margin: 0 20px; }
#address > .state-trigger { grid-row: 4; }
#address > .action-btn { grid-row: 5; margin: 15px 20px 20px 20px; width: auto; }
#address > p[aria-hidden="true"] { grid-row: 6; margin-bottom: 30px; }

/* The White Card Background */
#address::before {
    content: '';
    grid-column: 1;
    grid-row: 2 / 7; /* Spans from the paragraph down past the lock text */
    background-color: var(--card-bg);
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.03);
    border-radius: 6px;
    z-index: 0;
}

/* Responsive adjustments for mobile padding inside the card */
@media (max-width: 600px) {
    #address > p:first-of-type,
    #address > fieldset,
    #address > .action-btn {
        margin-left: 15px;
        margin-right: 15px;
    }
}

/* =========================================================
   Terms & Confirmation Section
   ========================================================= */
#terms > * {
    grid-column: 1;
    z-index: 1;
}

#terms > h2 { grid-row: 1; margin-bottom: 10px; }
#terms > h2 + p { grid-row: 2; margin-bottom: 30px; }
#terms > p:nth-of-type(2) { grid-row: 3; }
#terms > figure { grid-row: 4; }
#terms > p:nth-of-type(3) { grid-row: 5; }
#terms > .action-btn { grid-row: 6; }
#terms > p:nth-of-type(4) { grid-row: 7; }
#terms > p:nth-of-type(5) { grid-row: 8; }
#terms > p:nth-of-type(6) { grid-row: 9; }

#terms::before {
    content: '';
    grid-column: 1;
    grid-row: 3 / 10;
    background-color: var(--card-bg);
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.03);
    border-radius: 4px;
    z-index: 0;
}

#terms > p:nth-of-type(2) {
    margin: 20px 20px 30px 20px;
    background-color: #F3F4F6;
    padding: 1em;
    text-align: center;
    font-size: 1.1rem;
    color: var(--text-main);
}

#terms figure {
    margin: 0 20px 30px 20px;
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100px;
}

#terms figure figcaption {
    display: none;
}

#terms figure img {
    max-width: 100%;
    max-height: 100%;
}

#terms > p:nth-of-type(3) {
    margin: 0 20px 20px 20px;
    text-align: center;
    font-size: 1.2rem;
    color: var(--text-main);
}

#terms > p:nth-of-type(3) strong:first-child {
    font-weight: 500;
}

#terms > p:nth-of-type(3) strong:last-child {
    display: block;
    width: fit-content;
    margin: 15px auto 0 auto;
    position: relative;
    font-size: 1.6rem;
    font-weight: 700;
    color: var(--text-main);
}

#terms > p:nth-of-type(3) strong:last-child::after {
    content: '';
    position: absolute;
    left: calc(100% + 10px);
    top: 15px;
    width: 32px;
    height: 32px;
    background-color: #292929;
    -webkit-mask-image: url('../images/confirm-arrow.svg');
    mask-image: url('../images/confirm-arrow.svg');
    -webkit-mask-size: contain;
    mask-size: contain;
    -webkit-mask-repeat: no-repeat;
    mask-repeat: no-repeat;
    -webkit-mask-position: center;
    mask-position: center;
}

#terms > button,
#terms > .action-btn {
    margin: 0 20px 30px 20px;
    width: auto;
}

#terms > p:nth-of-type(4),
#terms > p:nth-of-type(5),
#terms > p:nth-of-type(6) {
    margin: 0 20px 20px 20px;
    text-align: left;
    font-size: 1.1rem;
    color: var(--text-main);
}

#terms > p:nth-of-type(6) {
    margin-bottom: 20px;
}

#terms > p:nth-of-type(6) small {
    background-color: transparent;
    padding: 0;
    font-size: 1.1rem;
    color: var(--text-main);
    margin-top: 0;
}

@media (max-width: 600px) {
    #terms > p:nth-of-type(2),
    #terms figure,
    #terms > p:nth-of-type(3),
    #terms > button,
    #terms > p:nth-of-type(4),
    #terms > p:nth-of-type(5),
    #terms > p:nth-of-type(6) {
        margin-left: 20px;
        margin-right: 20px;
    }
}

/* =========================================================
   Final Outcome Screens (Success / Error / Lead)
   ========================================================= */
#appointment-success,
#appointment-error,
#lead-success {
    text-align: center;
    width: 100%;
    max-width: 800px;
    margin: 0 auto;
}

#appointment-success > p:first-of-type,
#lead-success > p:first-of-type {
    font-size: 2.2rem;
    font-weight: 700;
    color: var(--text-main);
    margin: 0 0 5px 0;
}

#appointment-success h2,
#appointment-error h2,
#lead-success h2 {
    font-size: 2.2rem;
    font-weight: 700;
    color: var(--text-main);
    margin: 0 0 30px 0;
}

#appointment-error h2 + p {
    font-size: 1.2rem;
    font-weight: 500;
    color: var(--text-muted);
    margin: 0;
}

#appointment-success h3:first-of-type,
#appointment-error h3:first-of-type,
#lead-success h3:first-of-type {
    font-size: 1.5rem;
    font-weight: 600;
    margin-bottom: 15px;
    color: var(--text-main);
}

#appointment-success > p:has(> a[href^="tel"]),
#appointment-error > p:has(> a[href^="tel"]),
#lead-success > p:has(> a[href^="tel"]) {
    margin: 0 auto 40px auto;
    max-width: 450px;
}

#appointment-success a[href^="tel"],
#appointment-error a[href^="tel"],
#lead-success a[href^="tel"] {
    display: block;
    background-color: var(--primary-green);
    color: var(--text-main);
    font-size: 1.5rem;
    font-weight: 600;
    text-decoration: none;
    padding: 15px;
}

#appointment-success h3:nth-of-type(2),
#appointment-error h3:nth-of-type(2),
#lead-success h3:nth-of-type(2) {
    font-size: 1.3rem;
    font-weight: 400;
    margin-bottom: 20px;
    color: var(--text-main);
}

#appointment-success ol,
#appointment-error ol,
#lead-success ol {
    list-style: none;
    padding: 0;
    margin: 0 0 40px 0;
    counter-reset: steps-counter;
}

#appointment-success li,
#appointment-error li,
#lead-success li {
    margin-bottom: 25px;
    text-align: center;
}

#appointment-success li strong,
#appointment-error li strong,
#lead-success li strong {
    display: block;
    font-size: 1.2rem;
    font-weight: 600;
    margin-bottom: 5px;
    color: var(--text-main);
}

#appointment-success li strong::before,
#appointment-error li strong::before,
#lead-success li strong::before {
    counter-increment: steps-counter;
    content: counter(steps-counter) ". ";
}

#appointment-success li p,
#appointment-error li p,
#lead-success li p {
    font-size: 1.1rem;
    color: var(--text-main);
    margin: 0;
    line-height: 1.4;
}

#appointment-success small,
#appointment-error small,
#lead-success small {
    display: block;
    text-align: center;
    font-size: 0.8rem;
    color: #9CA3AF;
    background: none;
    padding: 0;
    font-style: normal;
    margin-top: 40px;
}

/* =========================================================
   How It Works Section
   ========================================================= */
form > section:last-of-type {
    width: 100%;
    max-width: 800px;
    margin-top: 20px;
    text-align: center;
}

form > section:last-of-type h2 {
    font-size: 1.5rem;
    margin-bottom: 30px;
}

form > section:last-of-type ol {
    display: flex;
    flex-direction: row;
    justify-content: space-between;
    gap: 30px;
    list-style: none;
    padding: 0;
    margin: 0;
}

form > section:last-of-type li {
    flex: 1;
    font-size: 0.95rem;
    position: relative;
    padding-left: 28px;
    text-align: left;
    color: var(--text-main);
}

form > section:last-of-type li::before {
    content: '✓';
    position: absolute;
    left: 0;
    top: 2px;
    background-color: var(--primary-dark);
    color: #fff;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    font-size: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* =========================================================
   Footer Styling
   ========================================================= */
footer {
    border-top: 1px solid #E0E0E0;
    padding: 25px 5%;
}

footer nav ul {
    display: flex;
    justify-content: space-between;
    list-style: none;
    padding: 0;
    margin: 0;
    max-width: 1000px;
    margin: 0 auto;
}

footer nav a {
    color: #777;
    text-decoration: none;
    font-size: 0.85rem;
}

footer nav a:hover {
    text-decoration: underline;
}

footer small {
    text-align: center;
}

/* =========================================================
   Responsive Adjustments (Mobile)
   ========================================================= */
@media (max-width: 768px) {
    form > section:last-of-type ol {
        flex-direction: column;
        gap: 15px;
    }
    footer nav ul {
        flex-direction: column;
        align-items: center;
        gap: 10px;
    }
    header {
        flex-direction: column;
        gap: 15px;
    }

    /* Typography Scaling for small screens */
    #hero h1,
    [role="status"] h2,
    #datetime h2,
    #terms h2,
    #address h2 {
        font-size: 1.8rem;
    }

    #hero p,
    [role="status"] p,
    #datetime h2 + p,
    #terms h2 + p {
        font-size: 1rem;
    }

    legend, h2 {
        font-size: 1.3rem;
    }

    /* Header scaling (Keep on single row) */
    header {
        flex-direction: row;
        padding: 10px 15px;
        gap: 10px;
    }

    header img {
        width: 140px; /* Shrink logo to leave space for the button */
    }

    header a[href^="tel"] {
        padding: 6px 15px;
        text-align: center;
    }

    header a[href^="tel"] span:first-child {
        font-size: 0.7rem; /* Shrink the "Call for Immediate Service" text */
        margin-bottom: 2px;
    }

    header a[href^="tel"] span:last-child {
        font-size: 0.9rem; /* Phone number perfectly legible at .9rem */
    }
}

/* =========================================================
   Section Progress Bars
   ========================================================= */
#service::before { width: 14.28%; }
#homeowner::before { width: 28.57%; }
#homeAge::before { width: 42.86%; }
#timeframe::before { width: 50%; }
#garageSize::before { width: 57.14%; }
#flooring::before { width: 71.43%; }
#zip::before { width: 85.71%; }
#contact::before { width: 96.43%; }


/* =========================================================
   Pure CSS Screen Navigation & Transitions
   ========================================================= */

@keyframes slide-in-step {
    0% {
        opacity: 0;
        transform: translateX(30px);
    }
    100% {
        opacity: 1;
        transform: translateX(0);
    }
}

/* 1. Hide all main sections by default, apply entrance animation */
form > section {
    display: none;
    animation: slide-in-step 0.4s cubic-bezier(0.25, 1, 0.5, 1) forwards;
}

/* 2. Base elements (Hero & How It Works) visible until the loader triggers */
body:not([data-lead-submitted="true"]) form > #hero,
body:not([data-lead-submitted="true"]) form > section:last-of-type {
    display: block;
}

/*
   3. Form Flow Logic (Radio Buttons & Zip Code)
*/
/* Step 1: Service */
form:not(:has(#service input:checked)) > #service { display: block; }

/* PATH A: REPAIR */
form:has(#service input[value="REPAIR"]:checked):not(:has(#timeframe input:checked)) > #timeframe { display: block; }

/* PATH B: REPLACEMENT */
form:has(#service input[value="REPLACEMENT"]:checked):not(:has(#homeowner input:checked)) > #homeowner { display: block; }
form:has(#homeowner input:checked):not(:has(#homeAge input:checked)) > #homeAge { display: block; }
form:has(#homeAge input:checked):not(:has(#garageSize input:checked)) > #garageSize { display: block; }
form:has(#garageSize input:checked):not(:has(#flooring input:checked)) > #flooring { display: block; }

/* CONVERGENCE: ZIP CODE */
body:not([data-lead-submitted="true"]) form:has(#timeframe input:checked) > #zip,
body:not([data-lead-submitted="true"]) form:has(#flooring input:checked) > #zip {
    display: block;
}

/* 1. When valid, start a 2.5-second timer to hide the #zip screen */
body:not([data-lead-submitted="true"]) form:has(#zip-code:not(:placeholder-shown):valid) > #zip {
    animation: hide-loader-screen 0s 2.5s forwards;
}

/* 2. Step: Contact (Hold hidden for 2.5s during the verify animation, then slide in) */
body:not([data-lead-submitted="true"]) form:has(#zip-code:not(:placeholder-shown):valid) > #contact {
    display: block;
    animation:
            hold-hidden 2.5s,
            slide-in-step 0.4s 2.5s cubic-bezier(0.25, 1, 0.5, 1) forwards;
}

/* Step: Contact (Hidden once availability check starts) */
body:not([data-lead-submitted="true"]) form:has(#zip-code:not(:placeholder-shown):valid) > #contact {
    display: block;
}

/*
   4. Post-Contact Forward-Only Flow
*/
/* Step: Address */
form:has(#trigger-address:checked):not(:has(#trigger-terms:checked)) > #address {
    display: grid;
}

/* Step: Terms (Must be declared as grid) */
form:has(#trigger-terms:checked):not(:has(#confirm-appointment:checked)) > #terms {
    display: grid;
}

/* =========================================================
   Auto-Navigate After Loaders (Conditional CSS Handoff)
   ========================================================= */

@keyframes hide-loader-screen {
    to {
        position: absolute;
        opacity: 0;
        visibility: hidden;
        pointer-events: none;
        z-index: -100;
        top: -9999px;
    }
}

@keyframes hold-hidden {
    0%, 100% {
        position: absolute;
        opacity: 0;
        visibility: hidden;
        pointer-events: none;
        z-index: -100;
        top: -9999px;
    }
}

/* ---------------------------------------------------------
   Handoff 1: Availability Loader -> Datetime Picker
   --------------------------------------------------------- */

/* 1. Start the 11s transition timers immediately */
body[data-lead-submitted="true"] form:not(:has(#trigger-address:checked)) > #loading-availability {
    display: block;
    animation:
            slide-in-step 0.4s cubic-bezier(0.25, 1, 0.5, 1) forwards,
            hide-loader-screen 0s 11s forwards;
}

body[data-lead-submitted="true"] form:not(:has(#trigger-address:checked)) > #datetime {
    display: block;
    animation:
            hold-hidden 11s,
            slide-in-step 0.4s 11s cubic-bezier(0.25, 1, 0.5, 1) forwards;
}

/* 2. HALT AUTO-ADVANCE: If the nested fieldsets are missing, lock the loader ON and the datetime screen OFF */
body[data-lead-submitted="true"] form:not(:has(#trigger-address:checked)):not(:has(#datetime > fieldset fieldset)) > #loading-availability {
    opacity: 1 !important;
    visibility: visible !important;
    pointer-events: auto !important;
    position: relative !important;
    top: 0 !important;
    z-index: 1 !important;
}

body[data-lead-submitted="true"] form:not(:has(#trigger-address:checked)):not(:has(#datetime > fieldset fieldset)) > #datetime {
    opacity: 0 !important;
    visibility: hidden !important;
    pointer-events: none !important;
    position: absolute !important;
    top: -9999px !important;
    z-index: -100 !important;
}

/* ---------------------------------------------------------
   Handoff 2: Booking Loader -> Success Screen (JS Handled)
   --------------------------------------------------------- */
/* Reforms indefinite until your JS handles it */
form:has(#confirm-appointment:checked) > #booking-appointment {
    display: block;
    animation: slide-in-step 0.4s cubic-bezier(0.25, 1, 0.5, 1) forwards;
}

/* Infinite loader indicator after loader lists */
[role="status"]::after {
    margin-top: 60px;
    margin-left: auto;
    margin-right: auto;
    display: block;
    content: '';
    height: 4px;
    width: 130px;
    --c:no-repeat linear-gradient(var(--primary-green) 0 0);
    background: var(--c),var(--c),var(--border-light);
    background-size: 60% 100%;
    opacity: 0;
}

/* Only trigger the infinite progress bar if the fieldsets haven't loaded yet */
form:not(:has(#datetime > fieldset fieldset)) > #loading-availability::after {
    animation:
            reveal-step 0.5s 10.5s forwards,
            l16 3s 10.5s infinite;
}

#booking-appointment::after {
    animation:
            reveal-step 0.5s 8.5s forwards,
            l16 3s 8.5s infinite;
}

@keyframes l16 {
    0%   {background-position: -150% 0, -150% 0}
    66%  {background-position: 250% 0, -150% 0}
    100% {background-position: 250% 0, 250% 0}
}

/* =========================================================
   Final Outcome Screens (Data-Result Overrides)
   ========================================================= */

/* 1. When a final result is set, instantly hide all other sections and kill running loader animations */
body[data-result] form > section {
    display: none !important;
    animation: none !important;
}

/* 2. Map the specific results to their respective screens and trigger the slide-in */
body[data-result="lead"] form > #lead-success,
body[data-result="panic"] form > #lead-success,
body[data-result="booking"] form > #appointment-success,
body[data-result="error"] form > #appointment-error {
    display: block !important;
    animation: slide-in-step 0.4s cubic-bezier(0.25, 1, 0.5, 1) forwards !important;
}
