:root {
    /* ── Type scale (base font-size 18px set in base.html) ── */
    --fs-xs:   0.75rem;    /* 13.5px — tiny labels         */
    --fs-sm:   0.875rem;   /* 15.75px — captions           */
    --fs-base: 1rem;       /* 18px — body text             */
    --fs-md:   1.125rem;   /* 20.25px — medium body        */
    --fs-lg:   1.25rem;    /* 22.5px — subheadings         */
    --fs-xl:   1.5rem;     /* 27px — headings              */
    --fs-2xl:  1.875rem;   /* 33.75px — large headings     */

    --bg-pure-white: #ffffff;
    --bg-soft-white: #f7fafc;
    --text-charcoal: #1a202c;
    --text-slate: #4a5568;
    --border-light: #e2e8f0;
    --accent-blue: #3b82f6;
    --accent-emerald: #10b981;
    --accent-emerald-dk: #059669;
    --brand-navy: #1A2B3C;
    --amber-bg: #fef3c7;
    --amber-border: #fde68a;
    --amber-accent: #d97706;
    --amber-text: #78350f;
    --bg-warm-peach: #FFF0E0;
    --emerald-input-bg: #f0fdf4;
    --emerald-input-bd: #15803d;
    --emerald-input-focus: #dcfce7;
    --sky-accent: #0284c7;
    --sky-bg: #eff6ff;
    --sky-border: #bfdbfe;
    --success-green: #28a745;
    --sidebar-width: 310px;
    --radius-sm: 4px;
    --radius-md: 10px;
    --radius-lg: 14px;
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.1);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
}

body {
    margin: 0;
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    color: var(--text-charcoal);
    background-color: var(--bg-soft-white);
}

/* ── Global Responsive Wrapper ── */
.main-app-wrapper { box-sizing: border-box; }

@media (max-width: 1024px) {
    .main-app-wrapper {
        padding-left: 20px !important;
        padding-right: 20px !important;
    }
}
@media (max-width: 768px) {
    .main-app-wrapper {
        max-width: 960px;
        margin-left: auto !important;
        margin-right: auto !important;
        padding-left: 16px !important;
        padding-right: 16px !important;
    }
}

/* ── Scenario Feedback Zone — Step 3 selection confirmation ── */
.scenario-feedback-zone {
    display: block !important;
    position: relative !important;
    width: 100%;
    min-height: max-content;
    margin-top: 16px;
    clear: both;
}

/* ── Large financial display figures — fluid type ── */
.large-financial-display,
#projToday, #projIncrease, #projFuture, #projWindfall {
    font-size: clamp(1.1rem, 2.2vw, 1.8rem);
    line-height: 1.2;
    word-break: keep-all;
}

/* ── Universal Sticky Navigation Footer ── */
/*
 * Layout: 3-column CSS Grid.
 *   Column 1 (1fr) — Back button, pinned to the left rail.
 *   Column 2 (auto) — Contact info, self-centered.
 *   Column 3 (1fr) — Next button, pinned to the LEFT EDGE of its column.
 *
 * Because columns 1 and 3 are equal 1fr fractions, the left edge of column 3
 * is always at (footer_inner_width + contact_width) / 2 — a value that depends
 * only on viewport width, never on the button's own text length.
 * justify-content: space-between is intentionally removed: it was the cause of
 * the right button drifting left whenever the label text grew longer.
 */
.step-navigation-footer {
    position: fixed;
    bottom: 0;
    left: var(--sidebar-width, 0px);
    width: calc(100% - var(--sidebar-width, 0px));
    background-color: #f1f5f9;
    border-top: 1px solid #dee2e6;
    padding: 15px 40px 15px 50px;
    padding-bottom: calc(15px + env(safe-area-inset-bottom));
    z-index: 1050;
    box-shadow: 0 -2px 8px rgba(0, 0, 0, 0.04);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

/* Both nav buttons grouped together on the right */
.footer-nav-group {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 48px;
}

.footer-nav-placeholder {
    display: inline-block;
}

.footer-spacer {
    height: 80px;
    width: 100%;
}

/* ── Footer nav links (Back / Next) — Bootstrap-safe custom class ── */
.footer-nav-link {
    font-family: inherit;
    font-size: 1.15rem;
    font-weight: 600;
    color: #111827;
    text-decoration: none;
    background: none;
    border: none;
    padding: 0;
    cursor: pointer;
    display: inline-block;
    white-space: nowrap;
    transition: opacity 0.2s;
}
.footer-nav-back {
    flex-shrink: 0;
}
.footer-nav-link:hover {
    opacity: 0.6;
    background: none;
    color: #111827;
    text-decoration: none;
}

/* ── Footer contact block ── */
.footer-contact {
    text-align: left;
    font-size: 1.15rem;
    font-weight: 600;
    color: #111827;
}

.footer-contact-label {
    font-size: 1.15rem;
    font-weight: 600;
    color: #111827;
}

.footer-contact-link {
    display: inline;
    margin-left: 6px;
    padding: 0;
    color: #111827;
    background: none;
    text-decoration: none;
    font-weight: 600;
    font-size: 1.15rem;
    transition: opacity 0.2s;
}

.footer-contact-link:hover {
    background: none;
    opacity: 0.6;
    text-decoration: underline;
}

/* ── Prevent iOS Auto-Zoom on Form Fields ── */
input, select, textarea, .form-control, .form-select {
    font-size: 16px !important;
}

/* ── Canonical Dollar-Amount Input ── */
.dollar-input {
    font-size: 1.4rem !important;
    font-weight: 800 !important;
    color: var(--text-charcoal) !important;
    background: #ffffff !important;
    border: 1px solid #000000 !important;
    border-radius: var(--radius-md) !important;
    text-align: left !important;
    width: 100% !important;
    padding: 8px 12px !important;
    box-sizing: border-box !important;
}
.dollar-input:focus {
    outline: none !important;
    background: #ffffff !important;
    border-color: #000000 !important;
    box-shadow: none !important;
}

/* ── Global Select Dropdown ── */
select {
    background-color: #e8f5e9 !important;
    border: 1px solid #000000 !important;
}
select:focus {
    outline: none;
    box-shadow: none;
}

/* ── Progress Bar ── */
.progress-bar-wrap {
    height: 70px;
    border-radius: 99px;
    overflow: hidden;
    background: var(--border-light);
    margin-bottom: 16px;
    display: flex;
    align-items: stretch;
}

.progress-bar-fill {
    height: 100%;
    min-height: 100%;
    background: linear-gradient(90deg, var(--accent-emerald), var(--accent-blue));
    border-radius: 99px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-size: 1rem;
    font-weight: 800;
    letter-spacing: 0.5px;
    text-transform: uppercase;
    transition: width 0.5s ease;
    white-space: nowrap;
    overflow: hidden;
}

/* ── Sidebar Utility ── */
.nav-section-label {
    padding: 10px 20px 6px;
    font-size: 0.95rem;
    font-weight: 800;
    color: var(--text-slate);
    text-transform: uppercase;
    letter-spacing: 1.5px;
    border-bottom: 1px solid var(--border-light);
    background: var(--bg-soft-white);
    margin-top: 4px;
}

.save-msg-indicator {
    display: none;
}

.reset-form {
    margin: 0;
    padding: 0;
}

.sidebar-action-group {
    padding: 12px 14px;
}

.main-content--landing {
    margin-left: 0;
    padding: 0;
}

/* ── Introduction / Landing Page ── */
.intro-container {
    background-color: var(--bg-pure-white);
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 40px 24px;
}

.intro-card {
    max-width: 900px;
    width: 100%;
    background: var(--bg-pure-white);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    padding: 60px;
}

.intro-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 32px;
    margin-bottom: 48px;
}

.path-card {
    background: #ffffff;
    border: 1px solid var(--border-light);
    border-radius: var(--radius-md);
    padding: 32px;
    box-shadow: var(--shadow-sm);
    display: flex;
    flex-direction: column;
    transition: transform 0.2s, box-shadow 0.2s;
}

.path-card:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-md);
}

.path-card.recommended {
    border: 2px solid var(--accent-emerald);
    position: relative;
}

.badge-recommended {
    position: absolute;
    top: -12px;
    right: 20px;
    background: var(--accent-emerald);
    color: white;
    font-size: 0.7rem;
    font-weight: 800;
    padding: 4px 12px;
    border-radius: 20px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* ── Registration UI ── */
.reg-type-container {
    margin-bottom: 20px;
    display: flex;
    gap: 10px;
}

.reg-type-btn {
    padding: 12px;
    border: 2px solid #ddd;
    border-radius: 8px;
    text-align: center;
    font-size: 0.9rem;
    font-weight: 700;
    color: #666;
    transition: all 0.2s;
}

.reg-type-btn.active {
    border-color: #2e7d32;
    background: #e8f5e9;
    color: #1b5e20;
}

.disclosure-box {
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    padding: 20px;
    margin-bottom: 25px;
}

/* ── Step-Level Responsive Utilities ── */

/*
 * .vid-trigger  — add this class to every step's video walkthrough button.
 *   On desktop: keeps the existing inline absolute-position style unchanged.
 *   On ≤768px : becomes a right-floated circular icon; text hidden via font-size:0
 *   so the button stays usable without overlapping page headings.
 *
 * .rf-step-page — add to the outer wrapper div of each step template.
 *   Replaces the 56px top padding (needed only when the button was absolute)
 *   with 16px on portrait, since the button is now in-flow.
 *
 * .rf-table-wrap — wrap any wide table; enables horizontal scroll on mobile.
 *
 * .rf-windfall-box — Step 5 promo box; converts from absolute to in-flow on mobile.
 *
 * .rf-report-header — Step 11 two-column header; stacks on mobile.
 */

.rf-table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    width: 100%;
}

@media (max-width: 768px) {
    /* Video button: float right, collapse to icon only */
    .vid-trigger {
        position: static !important;
        float: right !important;
        font-size: 0 !important;
        padding: 10px !important;
        border-radius: 50% !important;
        width: 40px !important;
        height: 40px !important;
        justify-content: center !important;
        margin: 0 0 10px 10px !important;
        white-space: nowrap !important;
        flex-shrink: 0 !important;
    }

    /* Step outer container: cut wasted top padding */
    .rf-step-page { padding-top: 16px !important; }

    /* Step 5 windfall box: already in-flow; on mobile expand to full width */
    .rf-windfall-box {
        width: 100% !important;
        max-width: 100% !important;
        margin-left: 0 !important;
        margin-bottom: 20px;
        box-sizing: border-box !important;
    }

    /* Step 11 report header: two-column → single column */
    .rf-report-header {
        flex-direction: column !important;
        align-items: flex-start !important;
    }
    .rf-report-right {
        align-items: flex-start !important;
        flex-direction: row !important;
        flex-wrap: wrap !important;
    }

    /* Step 10 strategy header: side-by-side → stacked */
    .rf-strategy-grid {
        flex-direction: column !important;
    }
}

/* ── Hamburger Menu Button (tablet/phone only) ── */
.hamburger-btn {
    display: none;
    position: fixed;
    top: 10px;
    left: 10px;
    z-index: 1100;
    background: var(--brand-navy);
    color: #fff;
    border: none;
    border-radius: 8px;
    width: 44px;
    height: 44px;
    font-size: 1.5rem;
    cursor: pointer;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.28);
    padding: 0;
    line-height: 1;
}

.sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    z-index: 1040;
}

/* ── Laptop / narrower desktop (≤1100px) — narrow sidebar ── */
@media (max-width: 1100px) {
    :root { --sidebar-width: 250px; }
    .sidebar h2 { font-size: 0.76rem; }
    .sidebar a.nav-link, .sidebar button.nav-link { font-size: 0.78rem; padding: 10px 14px; }
}

/* ── Confirm rail: move to bottom-right at ≤1260px ─────────────────────────────
 * The Step 3 layout has a 493px left column. With a 310px sidebar and padding,
 * content extends to ~835px from the left edge. The button (152px wide at
 * right:200px) starts at viewport−352px — it overlaps that column below ~1190px.
 * Raising the threshold to 1260px gives a safe 60px gap before the rule fires.
 * ─────────────────────────────────────────────────────────────────────────────── */
@media (max-width: 1260px) {
    .confirm-rail-btn {
        right: 14px;
        bottom: calc(84px + env(safe-area-inset-bottom));
        top: auto;
        transform: none;
        width: 128px;
        font-size: 0.77rem;
        padding: 10px 12px;
    }
}

/* ── iPad landscape / small laptop (≤1024px) — video button + overflow guards ── */
@media (max-width: 1024px) {
    .footer-nav-group { gap: 24px; }

    /*
     * Video trigger: integrate into document flow as a full-width block row.
     * Strips the absolute/fixed anchoring so it physically occupies its own
     * vertical slice and pushes all content below it cleanly downward.
     */
    .vid-trigger {
        position: relative !important;
        top: auto !important;
        right: auto !important;
        left: auto !important;
        bottom: auto !important;
        float: none !important;
        display: flex !important;
        align-items: center !important;
        gap: 8px !important;
        width: 100% !important;
        box-sizing: border-box !important;
        font-size: 0.88rem !important;
        font-weight: 700 !important;
        padding: 10px 16px !important;
        border-radius: 6px !important;
        height: auto !important;
        justify-content: flex-start !important;
        margin: 0 0 20px 0 !important;
        white-space: normal !important;
        flex-shrink: 1 !important;
        z-index: 1 !important;
    }

    /* Step 1: stack the two-column form into single column on tablets */
    #s1-outer {
        flex-direction: column !important;
        gap: 16px !important;
    }
    #s1-left {
        flex: 1 1 auto !important;
        width: 100% !important;
        max-width: 100% !important;
    }

    /* Prevent confirm-state buttons from stretching to container width on tablets */
    .btn-state-green, .btn-confirm.btn-clicked {
        max-width: 100% !important;
        width: auto !important;
        height: auto !important;
        display: inline-block !important;
    }

    /* Step page: the 56px top padding existed only for the absolute-position button.
       With the button now an in-flow row, drop to normal top padding. */
    .rf-step-page { padding-top: 20px !important; }

    /* Force any inline white-space:nowrap on paragraphs to wrap so text never
       causes horizontal scrolling on 768–1024px content areas. */
    .rf-step-page p { white-space: normal !important; }

    /* Prevent wide elements from causing horizontal scroll on the
       whole page; let them scroll within their own container instead. */
    .section-card,
    .bucket-card { overflow-x: auto; -webkit-overflow-scrolling: touch; max-width: 100%; }

    /* Mobile Table Cards: eliminate horizontal swiping on data tables */
    .rf-mobile-table {
        display: block !important;
        width: 100% !important;
        overflow-x: hidden !important;
        border: none !important;
    }
    .rf-mobile-table thead, .rf-mobile-table tbody, .rf-mobile-table th, .rf-mobile-table td, .rf-mobile-table tr {
        display: block;
    }
    .rf-mobile-table thead tr {
        position: absolute;
        top: -9999px;
        left: -9999px;
    }
    .rf-mobile-table tr {
        border: 1px solid #ccc;
        border-radius: 8px;
        margin-bottom: 16px;
        padding: 12px;
        background-color: #fff;
        box-shadow: 0 2px 4px rgba(0,0,0,0.05);
    }
    .rf-mobile-table td {
        border: none !important;
        border-bottom: 1px solid #eee !important;
        position: relative;
        padding-left: 55% !important;
        text-align: right !important;
        min-height: 24px;
        background-color: transparent !important;
    }
    .rf-mobile-table td:last-child {
        border-bottom: 0 !important;
    }
    .rf-mobile-table td::before {
        content: attr(data-label);
        position: absolute;
        left: 6px;
        width: 50%;
        padding-right: 10px;
        white-space: normal;
        text-align: left;
        font-weight: bold;
        color: #555;
    }
}

/* ── iPad landscape narrower / large tablet (≤900px) — compress sidebar ── */
@media (max-width: 900px) {
    :root { --sidebar-width: 210px; }
    html { font-size: 16px; }
    .main-content { padding: 20px 14px; }
    .sidebar h2 { font-size: 0.70rem; letter-spacing: 0.8px; }
    .sidebar a.nav-link, .sidebar button.nav-link { font-size: 0.73rem; padding: 9px 12px; }
    .sidebar-action-btn { font-size: 0.76rem; padding: 9px 10px; }
    .footer-nav-group { gap: 16px; }
    /* Confirm rail: compact bottom-right positioning inherited from ≤1100px rule above.
       No longer hidden here — the button must remain accessible so Step 6 users can
       confirm their entries and proceed to Step 7. */
    .section-card, .bucket-card { overflow-x: auto; -webkit-overflow-scrolling: touch; }
}

/* ── iPad portrait and below (≤768px) — collapse sidebar, show hamburger ── */
@media (max-width: 768px) {
    :root { --sidebar-width: 0px; }
    html { font-size: 15px; }

    .sidebar {
        width: 280px !important;
        transform: translateX(-280px);
        transition: transform 0.28s ease;
        box-shadow: none;
    }

    body.sidebar-open .sidebar {
        transform: translateX(0);
        box-shadow: 4px 0 24px rgba(0, 0, 0, 0.2);
    }

    body.sidebar-open .sidebar-backdrop {
        display: block;
    }

    .hamburger-btn { display: flex; }

    .main-content { padding: 64px 16px 16px !important; }

    .step-navigation-footer { padding: 12px 16px; }
    .footer-nav-group { margin-right: 0; }
    .footer-nav-back { min-width: 80px; }

    .progress-bar-wrap { height: 50px; }
    .progress-bar-fill { font-size: 0.82rem; }

    .intro-card { padding: 24px 16px; }
    .intro-grid { grid-template-columns: 1fr; gap: 16px; }
}

/* ── Phone (≤480px) ── */
@media (max-width: 480px) {
    .footer-contact { display: none; }
    .step-navigation-footer { justify-content: flex-end; padding: 10px 16px; }
    .intro-card { padding: 16px 12px; }
}

/* ── Shared Button Classes ── */

/* Sidebar utility buttons (My Scenarios, Save, etc.) */
.sidebar-action-btn {
    width: 100%;
    background: var(--bg-soft-white);
    color: var(--text-charcoal);
    border: 1px solid var(--border-light);
    padding: 12px;
    border-radius: var(--radius-md);
    font-family: inherit;
    font-weight: 700;
    font-size: 0.85rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: all 0.2s;
    text-decoration: none;
    margin-bottom: 8px;
    box-sizing: border-box;
    box-shadow: var(--shadow-sm);
}
.sidebar-action-btn:hover {
    background: #e2e8f0;
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

/* Primary action / confirm button */
.confirm-btn {
    background: var(--accent-blue);
    color: white;
    padding: 16px 32px;
    border: none;
    border-radius: var(--radius-md);
    cursor: pointer;
    font-weight: 700;
    font-size: 1rem;
    transition: all 0.2s;
    box-shadow: var(--shadow-sm);
}
.confirm-btn:hover {
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

/* Secondary / back button */
.back-btn {
    background: var(--bg-soft-white);
    color: var(--text-slate);
    padding: 16px 32px;
    border: 1px solid var(--border-light);
    border-radius: var(--radius-md);
    font-weight: 700;
    cursor: pointer;
    transition: background 0.2s;
}
.back-btn:hover { background: var(--border-light); }

/* Download / CTA hero button (emerald) */
.btn-download-hero {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    background: var(--accent-emerald);
    color: #fff;
    font-weight: 700;
    font-size: 0.82rem;
    padding: 10px 20px;
    border-radius: var(--radius-md);
    text-decoration: none;
    transition: all 0.2s;
    white-space: nowrap;
    letter-spacing: 0.2px;
}
.btn-download-hero:hover { background: #059669; color: #fff; transform: translateY(-1px); }

/* Soft-green modal trigger button */
.btn-example-modal {
    display: inline-block;
    margin-top: 16px;
    background: #ECFDF5;
    color: #065F46;
    border: 1px solid #A7F3D0;
    padding: 12px 24px;
    border-radius: var(--radius-md);
    font-size: 1rem;
    font-weight: 700;
    cursor: pointer;
    text-decoration: none;
    transition: all 0.2s;
}
.btn-example-modal:hover { background: #DCFCE7; transform: translateY(-1px); }

/* ── Unified confirm button (Steps 1–6, floating right side, horizontal text) ── */
.confirm-rail-btn {
    position: fixed;
    right: 200px;
    top: calc(50% + 48px);
    transform: translateY(-50%);
    z-index: 998;
    border: none;
    border-radius: 8px;
    padding: 14px 18px;
    width: 152px;
    font-size: 0.82rem;
    font-weight: 800;
    letter-spacing: 0.2px;
    cursor: pointer;
    white-space: normal;
    text-align: center;
    line-height: 1.4;
    font-family: inherit;
    transition: background 0.25s, color 0.25s, box-shadow 0.25s;
    box-shadow: 0 4px 16px rgba(0,0,0,0.20);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    border: 1px solid rgba(255, 255, 255, 0.15);
}
.confirm-rail-btn.state-hidden    { display: none; }
.confirm-rail-btn.state-initial   { background: rgba(100, 116, 139, 0.95); color: #fff; }
.confirm-rail-btn.state-confirmed { background: rgba(22, 163, 74, 0.95); color: #fff; }
.confirm-rail-btn.state-dirty {
    background: rgba(249, 115, 22, 0.95);
    color: #fff;
    animation: pulse-confirm-rail 2s ease-in-out infinite;
}
.confirm-rail-btn.state-saving {
    background: rgba(71, 85, 105, 0.95);
    color: #fff;
    cursor: wait;
    opacity: 0.85;
}
@keyframes pulse-confirm-rail {
    0%, 100% { box-shadow: 0 4px 16px rgba(249,115,22,0.65); }
    50%       { box-shadow: 0 6px 28px rgba(249,115,22,0.15); }
}


/* ═══════════════════════════════════════════════════════════════════════════
   BRANCH-TT  —  iPad & iPhone Optimised Presentation Layer
   Device detection via django-user-agents sets .device-mobile / .device-tablet
   on <body>.  CSS media-query breakpoints remain the primary responsive
   mechanism; these rules layer server-confirmed intent on top.
   ═══════════════════════════════════════════════════════════════════════════ */

/* ── 1. iOS SAFE-AREA & SCROLL FOUNDATIONS ──────────────────────────────── */

/* Honour iPhone notch / Dynamic Island / home-indicator on all sides */
.device-mobile .step-navigation-footer,
.device-tablet .step-navigation-footer {
    padding-bottom: max(12px, env(safe-area-inset-bottom));
    padding-left:   max(16px, env(safe-area-inset-left));
    padding-right:  max(16px, env(safe-area-inset-right));
}

.device-mobile .main-content {
    padding-top:    max(64px, calc(52px + env(safe-area-inset-top))) !important;
    padding-left:   max(14px, env(safe-area-inset-left)) !important;
    padding-right:  max(14px, env(safe-area-inset-right)) !important;
    padding-bottom: max(80px, calc(60px + env(safe-area-inset-bottom))) !important;
}

/* Prevent elastic bounce from revealing grey behind header on iOS */
html { background: var(--bg-pure-white, #fff); }


/* ── 2. PREVENT iOS SAFARI AUTO-ZOOM ON INPUT FOCUS ─────────────────────── */
/*
 * iOS Safari zooms the viewport whenever a focused input has font-size < 16px.
 * Force 16px on every input/select/textarea on touch devices.
 * 'touch-action: manipulation' removes the 300ms tap delay on older WebKit.
 */
@media (max-width: 1024px) {
    input[type="text"],
    input[type="email"],
    input[type="password"],
    input[type="number"],
    input[type="tel"],
    input[type="search"],
    input[type="url"],
    input[type="date"],
    input[type="month"],
    select,
    textarea {
        font-size: 16px !important;
        touch-action: manipulation;
    }
}


/* ── 3. MINIMUM 44px TOUCH TARGETS (Apple HIG) ──────────────────────────── */

@media (max-width: 1024px) {
    /* Nav links */
    .sidebar a.nav-link,
    .sidebar button.nav-link {
        min-height: 44px;
        padding-top: 12px;
        padding-bottom: 12px;
    }

    /* Step navigation footer buttons */
    .footer-nav-back,
    .footer-nav-next,
    .footer-nav-group a,
    .footer-nav-group button {
        min-height: 44px;
        padding-top:    10px;
        padding-bottom: 10px;
    }

    /* Sidebar action buttons (Save, My Scenarios, etc.) */
    .sidebar-action-btn { min-height: 44px; }

    /* Confirm / back buttons in step content */
    .confirm-btn,
    .back-btn,
    .btn-download-hero,
    .btn-example-modal,
    .btn-register,
    .btn-verify {
        min-height: 44px;
        padding-top:    12px;
        padding-bottom: 12px;
    }

    /* Hamburger already 44×44 in existing CSS; keep it */
}


/* ── 4. TABLET LAYOUT (769px – 1024px) ──────────────────────────────────── */

@media (min-width: 769px) and (max-width: 1024px) {
    :root { --sidebar-width: 220px; }

    .main-content { padding: 24px 20px; }

    /* Section cards — give a bit more room to breathe */
    .section-card  { padding: 20px 18px; }
    .bucket-card   { padding: 20px 18px; }

    /* Tables: horizontal scroll inside card, not full-page scroll */
    .rf-table-wrap,
    .section-card table,
    .bucket-card  table { overflow-x: auto; -webkit-overflow-scrolling: touch; display: block; }

    /* Confirm rail: bottom-right, clear the footer */
    .confirm-rail-btn {
        right: 14px;
        bottom: calc(80px + env(safe-area-inset-bottom));
        top: auto;
        transform: none;
        width: 120px;
        font-size: 0.75rem;
        padding: 10px 12px;
    }

    /* Two-column grid inputs → keep 2-col on tablet but reduce gap */
    .field-row { gap: 10px; }

    /* Landing hero CTAs — keep 3-col but tighter */
    .hero-ctas { gap: 16px; }
}


/* ── 5. PHONE LAYOUT (≤480px) — full single-column ──────────────────────── */

@media (max-width: 480px) {
    /* Typography scale */
    h1 { font-size: 1.35rem !important; }
    h2 { font-size: 1.15rem !important; }
    h3 { font-size: 1.00rem !important; }

    /* Section cards — tight padding, full-width */
    .section-card,
    .bucket-card,
    .input-well {
        padding: 14px 12px !important;
        border-radius: 8px;
    }

    /* Two-column field rows → stack vertically */
    .field-row {
        flex-direction: column !important;
        gap: 10px !important;
    }

    /* Option cards on register page → stack */
    .option-cards {
        grid-template-columns: 1fr !important;
        gap: 10px;
    }

    /* Registration card — remove excess horizontal padding */
    .reg-body { padding: 20px 16px 24px !important; }

    /* Hero CTAs on landing → single column */
    .hero-ctas {
        grid-template-columns: 1fr !important;
        max-width: 100%;
    }

    /* Wide number tables — always scroll, never reflow */
    table { display: block; overflow-x: auto; -webkit-overflow-scrolling: touch; }

    /* Step intro card */
    .intro-card { padding: 16px 12px !important; }

    /* Confirm rail */
    .confirm-rail-btn {
        right: 10px;
        bottom: calc(72px + env(safe-area-inset-bottom));
        top: auto;
        transform: none;
        width: 110px;
        font-size: 0.72rem;
        padding: 9px 10px;
    }

    /* OTP digit boxes — slightly smaller on very narrow screens */
    .otp-digit {
        width: 40px !important;
        height: 52px !important;
        font-size: 1.6rem !important;
    }

    /* Footer nav: only Back + Next visible, hide labels */
    .footer-nav-group { gap: 8px; }
}


/* ── 6. SERVER-CONFIRMED MOBILE CLASS (.device-mobile) ──────────────────── */
/*
 * These rules fire when django-user-agents confirms a phone UA.
 * They work alongside, not instead of, the media-query rules above —
 * a phone UA always accompanies a narrow viewport in normal usage.
 */

.device-mobile .landing-container { padding: 24px 14px; }

/* Collapse the access-grid on the landing page to single column */
.device-mobile .access-grid--three,
.device-mobile .hero-ctas { grid-template-columns: 1fr !important; }

/* Section heading sizes */
.device-mobile .section-title { font-size: 1.6rem; }

/* Privacy grid: single column */
.device-mobile .privacy-grid { grid-template-columns: 1fr; gap: 24px; }

/* Prep content */
.device-mobile .prep-content { padding: 24px 16px !important; }

/* Modal box */
.device-mobile .modal-box { padding: 24px 18px; }

/* Step page top padding when the video button is in-flow */
.device-mobile .rf-step-page { padding-top: 12px !important; }

/* All financial tables must scroll, never overflow the page */
.device-mobile table,
.device-mobile .rf-table-wrap { display: block; overflow-x: auto; -webkit-overflow-scrolling: touch; }

/* Sidebar open: lock body scroll so background doesn't drift */
.device-mobile body.sidebar-open { overflow: hidden; }


/* ── 7. SERVER-CONFIRMED TABLET CLASS (.device-tablet) ──────────────────── */

.device-tablet .access-grid--three { grid-template-columns: repeat(3, 1fr); }

/* iPad portrait: two-column hero */
@media (max-width: 820px) {
    .device-tablet .hero-ctas { grid-template-columns: 1fr 1fr !important; }
}

/* Allow full-width content on iPad portrait */
.device-tablet .main-content { padding: 20px 18px; }

/* Tables inside cards scroll rather than force page scroll */
.device-tablet .rf-table-wrap,
.device-tablet table { overflow-x: auto; -webkit-overflow-scrolling: touch; }


/* ── 8. FORM UX POLISH (ALL TOUCH DEVICES) ─────────────────────────────── */

@media (max-width: 1024px) {
    /* Larger tap area on radio/checkbox labels */
    label { min-height: 24px; }

    /* Remove inner outline tap flash on iOS */
    input, select, textarea, button { -webkit-tap-highlight-color: rgba(0,0,0,0.08); }

    /* Prevent double-tap zoom on buttons */
    button, a { touch-action: manipulation; }

    /* Select dropdowns: show chevron clearly on iOS */
    select { -webkit-appearance: none; appearance: none;
             background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%236b7280' stroke-width='1.8' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
             background-repeat: no-repeat;
             background-position: right 12px center;
             padding-right: 36px !important; }

    /* Increase line-height in paragraphs for easier reading on glass */
    p, li { line-height: 1.65; }

    /* Progress bar: taller for fat-finger tapping */
    .progress-bar-wrap { height: 56px; }
}


/* ── 9. SCROLL PERFORMANCE ──────────────────────────────────────────────── */

/* Momentum scrolling for sidebars and modals on iOS */
.sidebar,
.modal-box,
.otp-card,
.reg-card { -webkit-overflow-scrolling: touch; }

/* Contain scroll on the modal overlay so the page behind doesn't drift */
.modal-overlay { overscroll-behavior: contain; }


/* ── 10. STEP-PAGE TABLE RESPONSIVENESS ─────────────────────────────────── */

/*
 * Steps 8–11 produce wide financial projection tables.
 * Ensure they always scroll horizontally inside their card,
 * never force the whole page to widen.
 */
.section-card table,
.bucket-card  table,
.rf-table-wrap table {
    min-width: 540px;    /* let narrow tables expand to minimum readable width */
    border-collapse: collapse;
}

@media (max-width: 1024px) {
    .section-card,
    .bucket-card {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    /* Sticky first column on wide projection tables so the year/label stays visible while scrolling */
    .rf-table-wrap table td:first-child,
    .rf-table-wrap table th:first-child {
        position: sticky;
        left: 0;
        background: var(--bg-pure-white, #fff);
        z-index: 2;
        box-shadow: 2px 0 4px rgba(0,0,0,0.06);
    }
}
