/* ══════════════════════════════════════════════════════════════════════
   EasyToolio — Comparison Tools Responsive & Mobile Optimization
   ══════════════════════════════════════════════════════════════════════ */

/* --- 0. Root Viewport Confinement & Universal Box Sizing --- */
html,
body.is-tool-page {
    max-width: 100vw !important;
    overflow-x: clip !important;
    overflow-y: visible !important;
    width: 100% !important;
    box-sizing: border-box !important;
}

*, *::before, *::after {
    box-sizing: border-box;
}

/* Floating Header Mobile Boundaries */
@media (max-width: 640px) {
    #floatingHeader {
        padding-left: 0.85rem !important;
        padding-right: 0.85rem !important;
        max-width: calc(100vw - 1.5rem) !important;
    }
}

/* Tool Header & H1 Typography Scaling on Mobile */
@media (max-width: 639px) {
    body.is-tool-page header {
        max-width: 100% !important;
        overflow: hidden !important;
        padding-left: 1rem !important;
        padding-right: 1rem !important;
    }

    body.is-tool-page h1 {
        font-size: 1.35rem !important;
        line-height: 1.25 !important;
        word-break: break-word !important;
        overflow-wrap: break-word !important;
        hyphens: auto;
    }

    body.is-tool-page header nav ol {
        flex-wrap: wrap !important;
        word-break: break-word !important;
    }
}

/* --- 1. Ergonomic Mobile Sliders & Touch Targets --- */
@media (max-width: 768px) {
    input[type="range"] {
        height: 7px !important;
        margin: 10px 0 !important;
        touch-action: pan-x !important;
        -webkit-tap-highlight-color: transparent;
    }

    input[type="range"]::-webkit-slider-thumb {
        width: 24px !important;
        height: 24px !important;
        border-radius: 50% !important;
        cursor: grab !important;
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.45) !important;
    }

    input[type="range"]::-moz-range-thumb {
        width: 24px !important;
        height: 24px !important;
        border-radius: 50% !important;
        cursor: grab !important;
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.45) !important;
    }

    /* Prevent iOS Safari 16px auto-zoom on input focus */
    input[type="number"],
    input[type="text"],
    select {
        font-size: 16px !important;
    }
}

/* --- 2. Responsive Chart Canvas (Eliminate Horizontal Scroll traps) --- */
@media (max-width: 1024px) {
    /* Override forced 700px desktop min-width */
    .overflow-x-auto > div[class*="min-w-[700px]"],
    div[class*="min-w-[700px]"] {
        min-width: 100% !important;
        width: 100% !important;
    }

    .overflow-x-auto:has(canvas):not(.cso-chart-scroll-wrap) {
        overflow-x: hidden !important;
    }

    #comparisonChart,
    canvas[id*="Chart"]:not(#offerComparisonChart) {
        max-width: 100% !important;
        width: 100% !important;
    }
}

/* --- 3. Mobile Freeze-Column Comparison Matrix Tables --- */
@media (max-width: 768px) {
    .overflow-x-auto:has(table),
    div.overflow-x-auto {
        -webkit-overflow-scrolling: touch;
        scroll-behavior: smooth;
        position: relative;
        max-width: 100% !important;
        width: 100% !important;
    }

    /* Sticky first column so feature/year parameter remains visible */
    table[class*="min-w-"] th:first-child,
    table[class*="min-w-"] td:first-child,
    table th:first-child.sticky-mobile,
    table td:first-child.sticky-mobile,
    .compare-table th:first-child,
    .compare-table td:first-child {
        position: sticky !important;
        left: 0 !important;
        z-index: 10 !important;
        background-color: #121214 !important;
        box-shadow: 3px 0 8px -2px rgba(0, 0, 0, 0.4) !important;
    }

    html:not(.dark) table[class*="min-w-"] th:first-child,
    html:not(.dark) table[class*="min-w-"] td:first-child,
    html:not(.dark) table th:first-child.sticky-mobile,
    html:not(.dark) table td:first-child.sticky-mobile,
    html:not(.dark) .compare-table th:first-child,
    html:not(.dark) .compare-table td:first-child {
        background-color: #f5f5f7 !important;
        box-shadow: 3px 0 8px -2px rgba(0, 0, 0, 0.08) !important;
    }
}

/* --- 4. Mobile Sticky Bottom Summary Pill Bar --- */
@media (max-width: 640px) {
    .sticky-summary-bar {
        top: auto !important;
        bottom: 14px !important;
        padding-left: 10px !important;
        padding-right: 10px !important;
        transform: translateY(40px) !important;
    }

    .sticky-summary-bar.visible {
        transform: translateY(0) !important;
    }

    .sticky-summary-pill {
        border-radius: 20px !important;
        padding: 8px 12px !important;
        box-shadow: 0 12px 36px rgba(0, 0, 0, 0.55) !important;
        background: rgba(18, 18, 22, 0.88) !important;
        backdrop-filter: blur(20px) !important;
        -webkit-backdrop-filter: blur(20px) !important;
        border: 1px solid rgba(255, 255, 255, 0.12) !important;
    }

    html:not(.dark) .sticky-summary-pill {
        background: rgba(255, 255, 255, 0.92) !important;
        border-color: rgba(0, 0, 0, 0.1) !important;
        box-shadow: 0 12px 36px rgba(0, 0, 0, 0.12) !important;
    }
}

/* --- 5. Mobile Quick Preset Chips --- */
.mobile-preset-chips {
    display: flex;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scroll-snap-type: x mandatory;
    scrollbar-width: none;
    gap: 6px;
    padding-bottom: 2px;
}

.mobile-preset-chips::-webkit-scrollbar {
    display: none;
}

.mobile-preset-chips > button {
    scroll-snap-align: start;
    flex-shrink: 0;
}

/* --- 6. Mobile Card Layout & Padding Refinements --- */
.apple-glass,
.apple-card {
    max-width: 100% !important;
    box-sizing: border-box !important;
}

@media (max-width: 640px) {
    .apple-glass {
        border-radius: 1.25rem !important;
    }

    .apple-glass.rounded-3xl,
    div.rounded-3xl.apple-glass {
        padding: 1.15rem !important;
        border-radius: 1.25rem !important;
    }

    .apple-card {
        border-radius: 1rem !important;
    }

    /* Outer Compare Page Content Padding */
    .is-tool-page div[class*="max-w-7xl"] {
        padding-left: 0.85rem !important;
        padding-right: 0.85rem !important;
        width: 100% !important;
        max-width: 100% !important;
        min-width: 0 !important;
    }

    /* Stack difference analysis cleanly */
    #difference-analysis-callout {
        flex-direction: column !important;
        text-align: center !important;
    }
}

/* --- 7. Top Quick Redirection Navigation Toolbar (SIP Tool Standard) --- */
.compare-top-nav-bar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    margin-bottom: 1.25rem;
    width: 100%;
    max-width: 100%;
}

.compare-top-nav-wrap {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    padding: 3px 2px;
    max-width: 100%;
    min-width: 0;
}

.compare-top-nav-wrap::-webkit-scrollbar {
    display: none;
}

@media (max-width: 640px) {
    .compare-top-nav-bar {
        display: flex !important;
        flex-direction: column !important;
        align-items: stretch !important;
        width: 100% !important;
        max-width: 100% !important;
        gap: 0.5rem !important;
        min-width: 0 !important;
    }

    .compare-top-nav-wrap {
        width: 100% !important;
        max-width: 100% !important;
        overflow-x: auto !important;
        display: flex !important;
        flex-wrap: nowrap !important;
        min-width: 0 !important;
        padding-bottom: 4px !important;
        -webkit-overflow-scrolling: touch !important;
    }
}

.compare-nav-pill {
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    padding: 0.375rem 0.75rem;
    border-radius: 0.5rem;
    font-size: 11px;
    font-weight: 600;
    line-height: 1.25rem;
    transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
    white-space: nowrap;
    flex-shrink: 0;
    border: 1px solid rgba(255, 255, 255, 0.1);
    background: rgba(24, 24, 27, 0.6);
    color: #a1a1aa;
    text-decoration: none;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
}

.compare-nav-pill:hover {
    background: rgba(39, 39, 42, 0.9);
    color: #ffffff;
    border-color: rgba(255, 255, 255, 0.25);
    transform: scale(1.02);
}

.compare-nav-pill:active {
    transform: scale(0.95);
}

.compare-nav-pill i.fa-arrow-right {
    font-size: 8px;
    opacity: 0.4;
    transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

.compare-nav-pill:hover i.fa-arrow-right {
    opacity: 1;
    transform: translateX(2px);
}

html:not(.dark) .compare-nav-pill {
    background: #f4f4f5;
    border-color: #e4e4e7;
    color: #52525b;
}

html:not(.dark) .compare-nav-pill:hover {
    background: #e4e4e7;
    color: #18181b;
    border-color: #d4d4d8;
    transform: scale(1.02);
}

/* Primary Highlight Pill (Emerald) */
.compare-nav-pill.primary {
    background: rgba(16, 185, 129, 0.12);
    border-color: rgba(16, 185, 129, 0.28);
    color: #34d399;
}

html:not(.dark) .compare-nav-pill.primary {
    background: rgba(16, 185, 129, 0.1);
    border-color: rgba(16, 185, 129, 0.25);
    color: #059669;
}

.compare-nav-pill.primary:hover {
    background: rgba(16, 185, 129, 0.22);
    color: #6ee7b7;
    border-color: rgba(16, 185, 129, 0.45);
}

html:not(.dark) .compare-nav-pill.primary:hover {
    background: rgba(16, 185, 129, 0.16);
    color: #047857;
}

/* Secondary Amber/Indigo Highlight Pills */
.compare-nav-pill.amber {
    background: rgba(245, 158, 11, 0.1);
    border-color: rgba(245, 158, 11, 0.25);
    color: #fbbf24;
}

html:not(.dark) .compare-nav-pill.amber {
    background: rgba(245, 158, 11, 0.1);
    border-color: rgba(245, 158, 11, 0.25);
    color: #d97706;
}

.compare-nav-pill.amber:hover {
    background: rgba(245, 158, 11, 0.2);
    color: #fde68a;
    border-color: rgba(245, 158, 11, 0.4);
}

.compare-nav-pill.indigo {
    background: rgba(99, 102, 241, 0.1);
    border-color: rgba(99, 102, 241, 0.25);
    color: #818cf8;
}

html:not(.dark) .compare-nav-pill.indigo {
    background: rgba(99, 102, 241, 0.1);
    border-color: rgba(99, 102, 241, 0.25);
    color: #4f46e5;
}

.compare-nav-pill.indigo:hover {
    background: rgba(99, 102, 241, 0.2);
    color: #c7d2fe;
    border-color: rgba(99, 102, 241, 0.4);
}

/* --- 8. Scenario Card Headers & Mobile Flow --- */
.scenario-header-wrap {
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    margin-bottom: 0.75rem;
    padding-bottom: 0.65rem;
    border-bottom: 1px solid rgba(0, 0, 0, 0.06);
}

html.dark .scenario-header-wrap {
    border-bottom-color: rgba(255, 255, 255, 0.06);
}

.scenario-badge-pill {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.2rem 0.55rem;
    border-radius: 6px;
    font-size: 10px;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    white-space: nowrap;
    flex-shrink: 0;
}

.scenario-horizon-pill {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.15rem 0.6rem;
    border-radius: 9999px;
    font-size: 10px;
    font-weight: 600;
    background-color: #f4f4f5;
    color: #52525b;
    border: 1px solid rgba(0, 0, 0, 0.06);
    white-space: nowrap;
    flex-shrink: 0;
}

html.dark .scenario-horizon-pill {
    background-color: rgba(255, 255, 255, 0.06);
    color: #a1a1aa;
    border-color: rgba(255, 255, 255, 0.08);
}

/* --- 9. Sticky Sidebars & Mobile Layout Isolation --- */
/* Mobile & Tablet (< 1024px): strict container clipping to eliminate horizontal overflow */
@media (max-width: 1023px) {
    .is-tool-page .tool-content-container,
    body:has(.compare-top-nav-bar) .tool-content-container,
    .tool-content-container {
        overflow-x: hidden !important;
        max-width: 100% !important;
        width: 100% !important;
        min-width: 0 !important;
    }

    #calculator-section,
    div[id*="calculator-section"] {
        width: 100% !important;
        max-width: 100% !important;
        min-width: 0 !important;
        overflow-x: hidden !important;
    }

    #calculator-section > div,
    div[id*="calculator-section"] > div {
        width: 100% !important;
        max-width: 100% !important;
        min-width: 0 !important;
    }
}

/* Desktop (>= 1024px): enable overflow-x: visible to allow sticky sidebars */
@media (min-width: 1024px) {
    .is-tool-page .tool-content-container,
    body:has(.compare-top-nav-bar) .tool-content-container,
    .tool-content-container {
        overflow-x: visible !important;
    }

    #calculator-section > .lg\:sticky,
    #calculator-section .lg\:sticky {
        position: sticky !important;
        top: 6rem !important;
        align-self: flex-start !important;
        z-index: 20 !important;
    }
}

/* --- 10. Aligned Full-Width FAQs (SIP Tool Standard) --- */
.tool-guide .faq-section-wrapper {
    width: 100% !important;
    max-width: 100% !important;
}

.tool-guide div[class*="max-w-4xl"] {
    max-width: 100% !important;
}
