/* ========================================
   STEP 4 MOBILE - COMPLETE REDESIGN
   Max width: 576px
   Professional, clean, modern design
   IMPORTANT: This overrides all previous mobile styles
   ======================================== */

/* CRITICAL: Hide mobile sticky bar on desktop */
@media (min-width: 577px) {
    .s4m-sticky-bar,
    .step4-mobile-container {
        display: none !important;
    }
}

@media (max-width: 576px) {

    /* ===== CRITICAL: HIDE DESKTOP LAYOUT ===== */
    .savings-hero-card,
    .solar-configurator-full,
    .hero-card-inner,
    .hero-background-horizontal,
    .hero-grid-sections,
    .solar-panels-showcase,
    .roof-data-fullwidth,
    .energy-analysis-fullwidth,
    .financial-summary-card,
    .panel-config-selector,
    .config-options-grid {
        display: none !important;
        opacity: 0 !important;
        visibility: hidden !important;
        position: absolute !important;
        left: -9999px !important;
    }

    /* RESET parent container to prevent interference */
    .step-4-content {
        padding: 0 !important;
        margin: 0 !important;
        max-width: 100% !important;
        width: 100% !important;
        background: transparent !important;
    }

    #analysis-results-section,
    #analysis-results-content {
        padding: 0 !important;
        margin: 0 !important;
        max-width: 100% !important;
        width: 100% !important;
        background: transparent !important;
    }

    /* RESET: Override any conflicting styles from other CSS files */
    .step-4-content .step4-mobile-container,
    .step4-mobile-container {
        display: block !important;
        box-sizing: border-box !important;
        font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif !important;
        font-size: 16px !important;
        line-height: 1.5 !important;
        color: #1F2937 !important;
    }

    .step4-mobile-container * {
        box-sizing: border-box !important;
    }

    /* Container */
    .step4-mobile-container {
        background: #FFFFFF !important;
        padding: 16px !important;
        padding-bottom: 120px !important; /* Space for sticky bar */
        width: 100% !important;
        max-width: 100% !important;
        margin: 0 !important;
    }

    /* ========================================
       HERO CARD
       ======================================== */

    .s4m-hero-card {
        background: linear-gradient(135deg, #F0F9FF 0%, #DBEAFE 100%);
        border: 1px solid #BFDBFE;
        border-radius: 16px;
        padding: 24px 20px;
        margin-bottom: 20px;
        text-align: center;
    }

    .s4m-hero-badge {
        display: inline-flex;
        align-items: center;
        gap: 6px;
        background: rgba(59, 130, 246, 0.1);
        border: 1px solid rgba(59, 130, 246, 0.2);
        border-radius: 20px;
        padding: 6px 12px;
        font-size: 13px;
        font-weight: 500;
        color: #3B82F6;
        margin-bottom: 16px;
    }

    .s4m-hero-icon {
        width: 16px;
        height: 16px;
        stroke-width: 2.5;
    }

    .s4m-hero-amount {
        font-size: 48px;
        font-weight: 800;
        color: #10B981;
        line-height: 1;
        margin-bottom: 20px;
        letter-spacing: -0.02em;
    }

    .s4m-hero-metrics {
        display: flex;
        flex-direction: column;
        gap: 10px;
        margin-bottom: 20px;
    }

    .s4m-metric {
        display: flex;
        align-items: center;
        justify-content: center;
        gap: 8px;
        font-size: 13px;
        color: #6B7280;
    }

    .s4m-metric-icon {
        width: 16px;
        height: 16px;
        stroke-width: 2;
        color: #9CA3AF;
        flex-shrink: 0;
    }

    .s4m-metric strong {
        color: #1F2937;
        font-weight: 600;
    }

    .s4m-hero-cta {
        display: inline-flex;
        align-items: center;
        gap: 8px;
        background: #3B82F6;
        color: #FFFFFF;
        border: none;
        border-radius: 12px;
        padding: 12px 24px;
        font-size: 15px;
        font-weight: 600;
        cursor: pointer;
        transition: all 0.2s ease;
        min-height: 48px;
    }

    .s4m-hero-cta:active {
        transform: scale(0.98);
        background: #2563EB;
    }

    .s4m-hero-cta svg {
        width: 18px;
        height: 18px;
        stroke-width: 2.5;
    }

    /* ========================================
       ADDRESS BAR
       ======================================== */

    .s4m-address-bar {
        display: flex;
        align-items: center;
        gap: 8px;
        background: #F8FAFC;
        border: 1px solid #E2E8F0;
        border-radius: 12px;
        padding: 12px 14px;
        margin-bottom: 20px;
        font-size: 13px;
        overflow-x: auto;
        scrollbar-width: none;
    }

    .s4m-address-bar::-webkit-scrollbar {
        display: none;
    }

    .s4m-address-icon {
        width: 16px;
        height: 16px;
        color: #3B82F6;
        flex-shrink: 0;
    }

    .s4m-address-text {
        color: #1F2937;
        font-weight: 500;
        white-space: nowrap;
    }

    .s4m-address-divider {
        color: #CBD5E1;
        font-weight: 300;
    }

    .s4m-address-config {
        color: #6B7280;
        white-space: nowrap;
    }

    /* ========================================
       MAP SECTION
       ======================================== */

    .s4m-map-section {
        margin-bottom: 20px;
    }

    .s4m-map-container {
        position: relative;
        width: calc(100% + 32px);
        margin-left: -16px;
        margin-right: -16px;
        height: 300px;
        background: #E5E7EB;
        overflow: hidden;
    }

    .s4m-map {
        width: 100%;
        height: 100%;
    }

    .s4m-map-badge {
        position: absolute;
        top: 16px;
        right: 16px;
        display: flex;
        align-items: center;
        gap: 6px;
        background: rgba(255, 255, 255, 0.95);
        backdrop-filter: blur(8px);
        border: 1px solid rgba(0, 0, 0, 0.1);
        border-radius: 20px;
        padding: 8px 14px;
        font-size: 13px;
        font-weight: 600;
        color: #1F2937;
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    }

    .s4m-map-badge svg {
        width: 16px;
        height: 16px;
        color: #3B82F6;
    }

    .s4m-map-controls {
        display: flex;
        align-items: center;
        gap: 12px;
        margin-top: 12px;
    }

    .s4m-map-control {
        display: flex;
        align-items: center;
        gap: 6px;
        background: #F8FAFC;
        border: 1px solid #E2E8F0;
        border-radius: 10px;
        padding: 8px 12px;
        font-size: 12px;
        font-weight: 500;
        color: #6B7280;
        cursor: pointer;
        transition: all 0.2s ease;
        flex-shrink: 0;
        min-height: 40px;
    }

    .s4m-map-control.active {
        background: #3B82F6;
        border-color: #3B82F6;
        color: #FFFFFF;
    }

    .s4m-map-control svg {
        width: 14px;
        height: 14px;
    }

    .s4m-month-slider {
        flex: 1;
        position: relative;
        min-width: 0;
    }

    #s4m-month-range {
        width: 100%;
        height: 6px;
        border-radius: 3px;
        background: #E2E8F0;
        outline: none;
        appearance: none;
        cursor: pointer;
    }

    #s4m-month-range::-webkit-slider-thumb {
        appearance: none;
        width: 20px;
        height: 20px;
        border-radius: 50%;
        background: #3B82F6;
        cursor: pointer;
        box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
    }

    #s4m-month-range::-moz-range-thumb {
        width: 20px;
        height: 20px;
        border-radius: 50%;
        background: #3B82F6;
        cursor: pointer;
        border: none;
        box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
    }

    .s4m-month-label {
        position: absolute;
        top: -24px;
        left: 50%;
        transform: translateX(-50%);
        font-size: 11px;
        font-weight: 600;
        color: #3B82F6;
        white-space: nowrap;
        pointer-events: none;
    }

    /* ========================================
       COLLAPSIBLE SECTIONS
       ======================================== */

    .s4m-collapsible {
        background: #F8FAFC;
        border: 1px solid #E2E8F0;
        border-radius: 12px;
        margin-bottom: 16px;
        overflow: hidden;
    }

    .s4m-collapsible-header {
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding: 16px;
        cursor: pointer;
        user-select: none;
        list-style: none;
        min-height: 56px;
    }

    .s4m-collapsible-header::-webkit-details-marker {
        display: none;
    }

    .s4m-collapsible-title {
        font-size: 15px;
        font-weight: 600;
        color: #1F2937;
    }

    .s4m-collapsible-icon {
        width: 20px;
        height: 20px;
        color: #6B7280;
        transition: transform 0.2s ease;
        stroke-width: 2.5;
    }

    .s4m-collapsible[open] .s4m-collapsible-icon {
        transform: rotate(180deg);
    }

    .s4m-collapsible-content {
        padding: 0 16px 16px 16px;
    }

    /* ========================================
       DATA GRID (ROOF DETAILS)
       ======================================== */

    .s4m-data-grid {
        display: grid;
        grid-template-columns: repeat(2, 1fr);
        gap: 12px;
    }

    .s4m-data-item {
        background: #FFFFFF;
        border: 1px solid #E2E8F0;
        border-radius: 10px;
        padding: 12px;
    }

    .s4m-data-label {
        font-size: 11px;
        font-weight: 500;
        color: #6B7280;
        margin-bottom: 4px;
        text-transform: uppercase;
        letter-spacing: 0.02em;
    }

    .s4m-data-value {
        font-size: 16px;
        font-weight: 700;
        color: #1F2937;
    }

    /* ========================================
       CONFIGURATION SECTION
       ======================================== */

    .s4m-config-section {
        margin-bottom: 24px;
        scroll-margin-top: 20px;
    }

    .s4m-section-title {
        font-size: 18px;
        font-weight: 700;
        color: #1F2937;
        margin: 0 0 20px 0;
        letter-spacing: -0.01em;
    }

    .s4m-power-slider {
        position: relative;
        margin-bottom: 20px;
    }

    .s4m-slider-labels {
        display: flex;
        justify-content: space-between;
        font-size: 12px;
        font-weight: 500;
        color: #6B7280;
        margin-bottom: 8px;
    }

    #s4m-power-range {
        position: relative;
        width: 100%;
        height: 8px;
        border-radius: 4px;
        background: transparent;
        outline: none;
        appearance: none;
        cursor: pointer;
        z-index: 2;
    }

    #s4m-power-range::-webkit-slider-thumb {
        appearance: none;
        width: 28px;
        height: 28px;
        border-radius: 50%;
        background: #FFFFFF;
        border: 3px solid #3B82F6;
        cursor: pointer;
        box-shadow: 0 2px 8px rgba(59, 130, 246, 0.3);
        transition: transform 0.1s ease;
    }

    #s4m-power-range::-webkit-slider-thumb:active {
        transform: scale(1.1);
    }

    #s4m-power-range::-moz-range-thumb {
        width: 28px;
        height: 28px;
        border-radius: 50%;
        background: #FFFFFF;
        border: 3px solid #3B82F6;
        cursor: pointer;
        box-shadow: 0 2px 8px rgba(59, 130, 246, 0.3);
    }

    .s4m-slider-track {
        position: absolute;
        top: 50%;
        transform: translateY(-50%);
        left: 0;
        right: 0;
        height: 8px;
        background: #E2E8F0;
        border-radius: 4px;
        overflow: hidden;
        pointer-events: none;
        z-index: 1;
    }

    .s4m-slider-fill {
        height: 100%;
        background: linear-gradient(90deg, #3B82F6 0%, #2563EB 100%);
        border-radius: 4px;
        transition: width 0.2s ease;
        width: 50%;
    }

    .s4m-config-card {
        background: #FFFFFF;
        border: 2px solid #3B82F6;
        border-radius: 12px;
        padding: 16px;
    }

    .s4m-config-header {
        display: flex;
        align-items: center;
        justify-content: space-between;
        margin-bottom: 16px;
    }

    .s4m-config-power {
        font-size: 28px;
        font-weight: 800;
        color: #1F2937;
        letter-spacing: -0.02em;
    }

    .s4m-config-badge {
        background: #DBEAFE;
        color: #1E40AF;
        border-radius: 6px;
        padding: 4px 10px;
        font-size: 11px;
        font-weight: 600;
        text-transform: uppercase;
        letter-spacing: 0.02em;
    }

    .s4m-config-details {
        display: flex;
        flex-direction: column;
        gap: 10px;
    }

    .s4m-config-detail {
        display: flex;
        align-items: center;
        gap: 10px;
        font-size: 14px;
        color: #1F2937;
    }

    .s4m-config-detail svg {
        width: 18px;
        height: 18px;
        color: #6B7280;
        flex-shrink: 0;
    }

    /* ========================================
       OPTIONS SECTION
       ======================================== */

    .s4m-options-section {
        margin-bottom: 24px;
    }

    .s4m-option-card {
        background: #FFFFFF;
        border: 1px solid #E2E8F0;
        border-radius: 12px;
        padding: 16px;
        margin-bottom: 12px;
        transition: all 0.2s ease;
    }

    .s4m-option-card:active {
        transform: scale(0.99);
    }

    .s4m-option-header {
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 12px;
    }

    .s4m-option-info {
        display: flex;
        align-items: center;
        gap: 12px;
        flex: 1;
        min-width: 0;
    }

    .s4m-option-icon {
        font-size: 24px;
        flex-shrink: 0;
        width: 32px;
        height: 32px;
        display: flex;
        align-items: center;
        justify-content: center;
    }

    .s4m-option-title {
        font-size: 15px;
        font-weight: 600;
        color: #1F2937;
        margin-bottom: 2px;
    }

    .s4m-option-desc {
        font-size: 12px;
        color: #6B7280;
    }

    /* Custom Toggle Switch */
    .s4m-toggle {
        position: relative;
        display: inline-block;
        width: 48px;
        height: 28px;
        flex-shrink: 0;
        cursor: pointer;
    }

    .s4m-toggle input {
        opacity: 0;
        width: 0;
        height: 0;
    }

    .s4m-toggle-slider {
        position: absolute;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: #E2E8F0;
        border-radius: 28px;
        transition: all 0.3s ease;
    }

    .s4m-toggle-slider::before {
        content: "";
        position: absolute;
        height: 22px;
        width: 22px;
        left: 3px;
        bottom: 3px;
        background: #FFFFFF;
        border-radius: 50%;
        transition: all 0.3s ease;
        box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
    }

    .s4m-toggle input:checked + .s4m-toggle-slider {
        background: #10B981;
    }

    .s4m-toggle input:checked + .s4m-toggle-slider::before {
        transform: translateX(20px);
    }

    .s4m-toggle input:focus + .s4m-toggle-slider {
        box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.2);
    }

    /* ========================================
       ENERGY ANALYSIS
       ======================================== */

    .s4m-input-group {
        margin-bottom: 20px;
    }

    .s4m-input-label {
        display: block;
        font-size: 13px;
        font-weight: 600;
        color: #1F2937;
        margin-bottom: 8px;
    }

    .s4m-input-wrapper {
        position: relative;
    }

    .s4m-input {
        width: 100%;
        background: #FFFFFF;
        border: 1px solid #D1D5DB;
        border-radius: 10px;
        padding: 12px 14px;
        padding-right: 50px;
        font-size: 15px;
        color: #1F2937;
        transition: all 0.2s ease;
    }

    .s4m-input:focus {
        outline: none;
        border-color: #3B82F6;
        box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
    }

    .s4m-input-suffix {
        position: absolute;
        right: 14px;
        top: 50%;
        transform: translateY(-50%);
        font-size: 13px;
        font-weight: 500;
        color: #6B7280;
        pointer-events: none;
    }

    .s4m-energy-breakdown {
        display: flex;
        flex-direction: column;
        gap: 16px;
        margin-bottom: 20px;
    }

    .s4m-energy-item {
        display: flex;
        flex-direction: column;
        gap: 6px;
    }

    .s4m-energy-bar {
        height: 8px;
        background: #E2E8F0;
        border-radius: 4px;
        overflow: hidden;
    }

    .s4m-energy-fill {
        height: 100%;
        border-radius: 4px;
        transition: width 0.3s ease;
    }

    .s4m-energy-fill.s4m-energy-self {
        background: linear-gradient(90deg, #10B981 0%, #059669 100%);
    }

    .s4m-energy-fill.s4m-energy-grid {
        background: linear-gradient(90deg, #3B82F6 0%, #2563EB 100%);
    }

    .s4m-energy-info {
        display: flex;
        justify-content: space-between;
        align-items: center;
    }

    .s4m-energy-label {
        font-size: 13px;
        font-weight: 500;
        color: #1F2937;
    }

    .s4m-energy-value {
        font-size: 12px;
        font-weight: 600;
        color: #6B7280;
    }

    .s4m-impact-card {
        display: flex;
        align-items: flex-start;
        gap: 12px;
        background: linear-gradient(135deg, #ECFDF5 0%, #D1FAE5 100%);
        border: 1px solid #A7F3D0;
        border-radius: 10px;
        padding: 16px;
    }

    .s4m-impact-icon {
        width: 32px;
        height: 32px;
        color: #10B981;
        flex-shrink: 0;
    }

    .s4m-impact-content {
        flex: 1;
    }

    .s4m-impact-title {
        font-size: 13px;
        font-weight: 600;
        color: #065F46;
        margin-bottom: 4px;
    }

    .s4m-impact-value {
        font-size: 16px;
        font-weight: 700;
        color: #047857;
        margin-bottom: 2px;
    }

    .s4m-impact-desc {
        font-size: 12px;
        color: #059669;
    }

    /* ========================================
       STICKY BOTTOM BAR
       ======================================== */

    .s4m-sticky-spacer {
        height: 100px;
    }

    .s4m-sticky-bar {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        background: #FFFFFF;
        border-top: 1px solid #E2E8F0;
        padding: 12px 16px;
        z-index: 1000;
        box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.08);
    }

    .s4m-sticky-content {
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 12px;
        max-width: 576px;
        margin: 0 auto;
    }

    .s4m-sticky-info {
        flex: 1;
        min-width: 0;
        display: flex;
        flex-direction: column;
        gap: 8px;
    }

    /* Hero Section: Annual Savings */
    .s4m-sticky-hero {
        display: flex;
        flex-direction: column;
        gap: 4px;
    }

    .s4m-sticky-badge {
        display: inline-flex;
        align-items: center;
        gap: 4px;
        background: linear-gradient(135deg, #ECFDF5 0%, #D1FAE5 100%);
        border: 1px solid #A7F3D0;
        border-radius: 6px;
        padding: 4px 8px;
        width: fit-content;
        max-width: 100%;
    }

    .s4m-badge-icon {
        width: 14px;
        height: 14px;
        color: #059669;
        flex-shrink: 0;
        stroke-width: 2.5;
    }

    .s4m-sticky-badge span {
        font-size: 10px;
        font-weight: 600;
        color: #059669;
        text-transform: uppercase;
        letter-spacing: 0.03em;
        white-space: nowrap;
    }

    .s4m-sticky-savings {
        font-size: 28px;
        font-weight: 900;
        color: #10B981;
        letter-spacing: -0.03em;
        line-height: 1;
        text-shadow: 0 1px 2px rgba(16, 185, 129, 0.1);
    }

    /* Secondary Section: Investment */
    .s4m-sticky-secondary {
        display: flex;
        align-items: baseline;
        gap: 6px;
        flex-wrap: wrap;
    }

    .s4m-sticky-label {
        font-size: 11px;
        font-weight: 500;
        color: #6B7280;
        letter-spacing: 0.01em;
    }

    .s4m-sticky-price {
        font-size: 14px;
        font-weight: 700;
        color: #1F2937;
        letter-spacing: -0.01em;
    }

    /* CTA Button */
    .s4m-sticky-cta {
        display: flex;
        align-items: center;
        gap: 6px;
        background: linear-gradient(135deg, #3B82F6 0%, #2563EB 100%);
        color: #FFFFFF;
        border: none;
        border-radius: 12px;
        padding: 12px 20px;
        font-size: 14px;
        font-weight: 700;
        cursor: pointer;
        transition: all 0.2s ease;
        white-space: nowrap;
        min-height: 48px;
        box-shadow: 0 4px 12px rgba(59, 130, 246, 0.3);
        flex-shrink: 0;
    }

    .s4m-sticky-cta:active {
        transform: scale(0.98);
        box-shadow: 0 2px 8px rgba(59, 130, 246, 0.4);
    }

    .s4m-sticky-cta svg {
        width: 16px;
        height: 16px;
        stroke-width: 2.5;
        flex-shrink: 0;
    }

    /* Responsive adjustments for smaller screens */
    @media (max-width: 360px) {
        .s4m-sticky-content {
            gap: 10px;
        }

        .s4m-sticky-savings {
            font-size: 24px;
        }

        .s4m-sticky-cta {
            padding: 12px 16px;
            font-size: 13px;
        }

        .s4m-sticky-cta span {
            display: none;
        }

        .s4m-sticky-cta svg {
            width: 20px;
            height: 20px;
        }
    }

    /* ========================================
       HIDE DESKTOP LAYOUT ON MOBILE
       ======================================== */

    /* Hide the desktop solar-configurator-full container */
    .step-4-content .solar-configurator-full,
    .solar-configurator-full {
        display: none !important;
    }

    /* Ensure mobile container is visible */
    .step4-mobile-container {
        display: block !important;
    }

    /* ========================================
       ACCESSIBILITY & ANIMATIONS
       ======================================== */

    @media (prefers-reduced-motion: reduce) {
        * {
            animation-duration: 0.01ms !important;
            transition-duration: 0.01ms !important;
        }
    }

    /* Focus visible styles */
    .s4m-hero-cta:focus-visible,
    .s4m-sticky-cta:focus-visible,
    .s4m-map-control:focus-visible,
    .s4m-toggle input:focus-visible + .s4m-toggle-slider {
        outline: 3px solid #3B82F6;
        outline-offset: 2px;
    }

    /* Safe area for notched devices */
    @supports (padding: max(0px)) {
        .s4m-sticky-bar {
            padding-bottom: max(16px, env(safe-area-inset-bottom));
        }
    }

}
