/* Mobile Panel Navigation System */
@media (max-width: 768px) {
    /* Panel Navigation Bar */
    .mobile-nav {
        display: flex;
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        background: var(--color-bg-secondary, #ffffff);
        border-top: 1px solid var(--color-border, #e5e7eb);
        z-index: 1000;
        padding: 8px 0;
        backdrop-filter: blur(20px);
        -webkit-backdrop-filter: blur(20px);
        /* Chrome compatibility fixes */
        box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.1);
        min-height: 60px;
    }
    
    .nav-item {
        flex: 1;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        padding: 6px 4px;
        border: none;
        background: transparent;
        color: var(--color-text-secondary, #6b7280);
        cursor: pointer;
        transition: all 0.2s ease;
        position: relative;
        /* Chrome/Firefox compatibility fixes */
        -webkit-tap-highlight-color: transparent;
        -webkit-touch-callout: none;
        -webkit-user-select: none;
        user-select: none;
        min-height: 50px;
        /* Firefox specific alignment fixes */
        gap: 2px;
    }
    
    .nav-item.active {
        color: var(--color-accent, #3b82f6);
    }
    
    .nav-item.active::before {
        content: '';
        position: absolute;
        top: 0;
        left: 20%;
        right: 20%;
        height: 2px;
        background: var(--color-accent, #3b82f6);
        border-radius: 0 0 2px 2px;
    }
    
    .nav-icon {
        width: 20px;
        height: 20px;
        /* Fix SVG rendering across browsers */
        fill: currentColor;
        stroke: none;
        transition: transform 0.3s cubic-bezier(0.68, -0.55, 0.265, 1.55);
        /* Firefox alignment fix */
        display: block;
        flex-shrink: 0;
        margin: 0 auto;
    }
    
    /* Panel update notification bounce animation */
    .nav-icon.panel-update-bounce {
        animation: panelUpdateBounce 0.3s cubic-bezier(0.68, -0.55, 0.265, 1.55);
    }
    
    @keyframes panelUpdateBounce {
        0% { transform: scale(1); }
        50% { transform: scale(1.15); }
        100% { transform: scale(1); }
    }
    
    .nav-label {
        font-size: 10px;
        font-weight: 500;
        /* Firefox text alignment fix */
        line-height: 1.1;
        text-align: center;
        display: block;
        white-space: nowrap;
        margin: 0;
        padding: 0;
    }
    
    /* Panel System */
    .panel-container {
        display: flex;
        width: 400vw; /* Extended to 4 panels for feedback */
        transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        will-change: transform;
        height: 100%;
    }
    
    .panel {
        width: 100vw;
        /* min-height: calc(100vh - 60px - 60px); /* header height - nav height */
        height: calc(var(--vh, 1vh) * 100 - 60px); /* Full height minus header and nav */
        overflow-y: auto;
        overflow-x: hidden;
        padding-bottom: 80px; /* Space for nav bar */
        -webkit-overflow-scrolling: touch;
        scroll-behavior: smooth;
    }
    
    .panel-container.panel-1 {
        transform: translateX(0);
    }
    
    .panel-container.panel-2 {
        transform: translateX(-100vw);
    }
    
    .panel-container.panel-3 {
        transform: translateX(-200vw);
    }
    
    .panel-container.panel-4 {
        transform: translateX(-300vw);
    }
    
    /* Hide desktop layout */
    .app-container {
        display: block;
        overflow: hidden;
        position: relative;
        height: calc(var(--vh, 1vh) * 100);
    }

    .sidebar,
    .main-panel,
    .insights-panel {
        position: relative;
        grid-area: unset;
        border: none;
        height: auto;
        max-height: none;
        overflow: visible;
    }
    
    /* Hide desktop feedback on mobile */
    .desktop-feedback {
        display: none !important;
    }
    
    /* Panel 1: Input Panel */
    .sidebar {
        padding: 20px;
    }
    
    /* Annual Package styling for Panel 1 */
    #panel1 .salary-control {
        background: transparent;
        border: none;
        box-shadow: none;
        padding: 0;
        margin-bottom: 20px;
    }
    
    #panel1 .ctc-display-container {
        background: var(--color-bg-secondary);
        border: 1px solid var(--color-border);
        border-radius: var(--radius-xl);
        padding: 16px;
        display: flex;
        flex-direction: column;
        align-items: flex-start !important;
        gap: 12px;
    }
    
    #panel1 .ctc-label {
        /* CTC label = Monthly Take-Home label size (same hierarchy) */
        font-size: clamp(13px, 3.5vw, 18px);
        text-align: left !important;
        color: var(--color-text-secondary);
        font-weight: 500;
    }
    
    #panel1 .salary-display {
        /* CTC number = Monthly Take-Home number minus 3px (hero should be 3px bigger) */
        font-size: clamp(25px, 7.2vw, 45px);
        font-weight: 300;
        text-align: right;
        margin-bottom: 0;
    }
    
    #panel1 .salary-slider {
        width: 100%;
        margin-top: 8px;
    }
    
    /* Hide only the separate mobile regime toggle, but keep the content one visible */
    .mobile-regime-toggle {
        display: none !important;
    }
    
    /* Make content area regime toggle visible and responsive for mobile */
    #panel1 .regime-toggle {
        display: flex !important;
        /* Responsive gap and padding for mobile */
        gap: clamp(4px, 1.5vw, 8px) !important;
        padding: clamp(2px, 0.8vw, 4px) !important;
        margin-bottom: clamp(8px, 2vw, 12px);
    }
    
    /* Make regime buttons smaller for mobile to ensure visibility */
    #panel1 .regime-btn {
        /* Responsive padding for mobile */
        padding: clamp(6px, 2vw, 10px) clamp(12px, 4vw, 20px) !important;
        /* Responsive font size */
        font-size: clamp(11px, 3vw, 14px) !important;
        font-weight: 600 !important;
        min-height: 36px;
        min-width: clamp(60px, 18vw, 80px);
    }

    /* Specific fix for iPhone SE and very small screens */
    @media (max-width: 375px) {
        #panel1 .regime-toggle {
            display: flex !important;
            visibility: visible !important;
            opacity: 1 !important;
            position: relative !important;
            z-index: 10 !important;
            margin-bottom: 6px !important;
            gap: 4px !important;
            padding: 2px !important;
        }

        #panel1 .regime-btn {
            padding: 5px 10px !important;
            font-size: 10px !important;
            min-height: 30px !important;
            min-width: 55px !important;
            border-radius: 4px !important;
        }
    }
    
    /* Ensure section titles are visible in Panel 1 */
    #panel1 .section-title {
        display: block !important;
        font-size: 24px;
        font-weight: 600;
        color: var(--color-text-primary);
        margin-bottom: 16px;
    }

    /* Make the sidebar a flex container that fills Panel 1 */
    #panel1 .sidebar {
        display: flex;
        flex-direction: column;
        height: 100%;
        padding: 0; 
    }

    /* This is the new wrapper for your inputs */
    .scrollable-inputs {
        flex: 1 1 auto;
        overflow-y: auto;
        /* Add this line to fix the expanding content issue */
        min-height: 0; 
        /* Responsive padding - much smaller on iPhone SE */
        padding: clamp(12px, 4vw, 20px);
        -webkit-overflow-scrolling: touch;
    }

    /* Extra space saving for iPhone SE */
    @media (max-width: 375px) {
        .scrollable-inputs {
            padding: 10px !important;
        }
    }

    /* Monthly Take-Home Preview in Panel 1 - Responsive with max limits */
    .take-home-preview {
        /* This makes sure the box doesn't get squished */
        flex-shrink: 0; 
        
        /* Smaller margin for narrow screens */
        margin: clamp(6px, 1.5vw, 10px) clamp(12px, 3vw, 20px) clamp(12px, 3vw, 20px) clamp(12px, 3vw, 20px);

        /* These are your existing styles, which are great! */
        background: var(--gradient-accent);
        border-radius: var(--radius-xl);
        /* Much smaller padding for narrow screens */
        padding: clamp(12px, 3vw, 20px);
        text-align: center;
        box-shadow: 0 4px 20px rgba(0, 122, 255, 0.2);
        border-top: none; /* The margin provides enough separation */
        /* Max height to prevent it from getting too large on big phones */
        max-height: clamp(120px, 25vh, 180px);
        display: flex;
        flex-direction: column;
        justify-content: center;
    }    
    .take-home-preview .result-title {
        color: rgba(255, 255, 255, 0.9);
        /* Much smaller font size for narrow screens */
        font-size: clamp(13px, 3.5vw, 18px);
        /* Smaller margin */
        margin-bottom: clamp(3px, 1vw, 6px);
        line-height: 1.2;
    }
    
    .take-home-preview .result-amount {
        color: #fff;
        /* Much smaller font size to fit on narrow screens */
        font-size: clamp(28px, 8vw, 48px);
        font-weight: 300;
        animation: none;
        text-shadow: none;
        line-height: 1.1;
    }
    
    /* But ensure Annual Package and Tax Deductions sections are visible */
    #panel1 .input-section:first-child,
    #panel1 .input-section:nth-child(3) {
        display: block !important;
    }
    
    /* Panel 2: Results Panel */
    .main-panel {
        padding: 20px;
    }
    
    /* Panel 3: Insights Panel */
    .insights-panel {
        padding: 24px; /* Increased padding for better mobile spacing */
    }
    
    /* Mobile-specific insights styling */
    .insights-card {
        padding: 20px; /* Slightly reduced for mobile but still larger than original */
        margin-bottom: 20px;
    }
    
    .insight-title {
        font-size: 17px; /* Slightly smaller on mobile but still larger than original */
    }
    
    .insight-text {
        font-size: 14px; /* Improved mobile text size */
    }
    
    .section-title {
        font-size: 18px; /* Adjusted for mobile */
        margin-bottom: 20px;
    }
    
    /* Mobile Tax Breakdown Styles */
    .tax-breakdown-details {
        position: static; /* Changed from absolute for mobile */
        background: var(--color-bg-tertiary);
        border: 1px solid var(--color-border);
        border-radius: var(--radius-lg);
        margin-top: 12px;
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    }
    
    .tax-breakdown-content {
        padding: 16px; /* Reduced padding for mobile */
        max-height: 300px; /* Smaller max height for mobile */
    }
    
    .breakdown-section-title {
        font-size: 13px; /* Smaller for mobile */
    }
    
    .tax-slab-item,
    .deduction-detail-item {
        font-size: 12px; /* Smaller for mobile */
        padding: 6px 0;
    }
    
    .slab-rate {
        width: 50px; /* Narrower for mobile */
    }
    
    .slab-tax {
        width: 70px; /* Narrower for mobile */
    }
    
    .expand-chevron {
        font-size: 10px; /* Smaller chevron for mobile */
    }
    
    /* Panel 4: Feedback Panel */
    .feedback-panel {
        padding: 20px;
        display: flex;
        flex-direction: column;
        justify-content: center;
        align-items: center;
        text-align: center;
        min-height: 100%;
    }
    
    /* Feedback UI Styling - Steve Jobs approach */
    .feedback-question {
        font-size: 24px;
        font-weight: 600;
        margin-bottom: 40px;
        color: var(--color-text-primary);
        line-height: 1.3;
    }
    
    .feedback-buttons {
        display: flex;
        flex-direction: column;
        gap: 16px;
        width: 100%;
        max-width: 300px;
        margin-bottom: 30px;
    }
    
    .feedback-btn {
        padding: 18px 24px;
        font-size: 18px;
        font-weight: 600;
        border: 2px solid var(--color-border);
        background: var(--color-bg-secondary);
        color: var(--color-text-primary);
        border-radius: var(--radius-lg);
        cursor: pointer;
        transition: all 0.2s ease;
        min-height: 60px;
    }
    
    .feedback-btn:hover,
    .feedback-btn:focus {
        border-color: var(--color-accent);
        background: var(--color-accent);
        transform: translateY(-2px);
    }
    
    .feedback-btn.primary {
        background: var(--color-accent);
        border-color: var(--color-accent);
        color: white;
    }
    
    .feedback-input-container {
        width: 100%;
        max-width: 300px;
        margin-bottom: 20px;
    }
    
    .feedback-input {
        width: 100%;
        padding: 18px;
        font-size: 24px;
        font-weight: 600;
        text-align: center;
        border: 2px solid var(--color-border);
        background: var(--color-bg-secondary);
        color: var(--color-text-primary);
        border-radius: var(--radius-lg);
        outline: none;
        transition: border-color 0.2s ease;
    }
    
    .feedback-input:focus {
        border-color: var(--color-accent);
    }
    
    .feedback-success {
        color: var(--color-success);
        font-size: 20px;
        font-weight: 600;
        opacity: 0;
        transition: opacity 0.3s ease;
    }
    
    .feedback-success.show {
        opacity: 1;
    }
    
    /* Swipe Indicator - REMOVED: overlaps content and is useless */
    
    /* Touch gesture hints */
    .panel::after {
        content: '';
        position: absolute;
        top: 50%;
        right: 10px;
        width: 30px;
        height: 30px;
        background: radial-gradient(circle, rgba(0, 122, 255, 0.1) 0%, transparent 70%);
        border-radius: 50%;
        opacity: 0;
        animation: swipeHint 3s ease-in-out infinite;
        pointer-events: none;
    }
    
    @keyframes swipeHint {
        0%, 100% { opacity: 0; transform: translateX(0); }
        50% { opacity: 1; transform: translateX(-10px); }
    }
    
    /* Disable swipe hint after first interaction */
    body.has-interacted .panel::after {
        display: none;
    }
    
    /* Prevent body scroll when panels are active */
    body.panel-active {
        overflow: hidden;
        position: fixed;
        width: 100%;
    }
    
    /* Smooth iOS-style scrolling */
    .panel {
        -webkit-overflow-scrolling: touch;
        scroll-behavior: smooth;
    }
    
    /* Panel transition states */
    .panel-container.transitioning {
        transition-duration: 0.3s;
    }
    
    .panel-container.swiping {
        transition: none;
    }
}

/* Navigation Tutorial */
.nav-tutorial-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(8px);
    z-index: 3000;
    display: flex;
    align-items: center;
    justify-content: center;
    animation: fadeIn 0.3s ease-out;
}

.nav-tutorial-overlay.fade-out {
    animation: fadeOut 0.3s ease-out;
}

.nav-tutorial-content {
    background: var(--color-bg-secondary);
    border-radius: var(--radius-xl);
    padding: 24px;
    margin: 20px;
    max-width: 320px;
    text-align: center;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
}

.nav-tutorial-text h3 {
    color: var(--color-text-primary);
    font-size: 18px;
    font-weight: 600;
    margin: 0 0 8px 0;
}

.nav-tutorial-text p {
    color: var(--color-text-secondary);
    font-size: 14px;
    line-height: 1.4;
    margin: 0 0 16px 0;
}

.nav-tutorial-demo {
    margin: 16px 0;
}

.swipe-demo-arrow {
    font-size: 24px;
    color: var(--color-accent);
    animation: swipeDemo 2s ease-in-out infinite;
}

@keyframes swipeDemo {
    0%, 100% { transform: translateX(0); opacity: 1; }
    25% { transform: translateX(-8px); opacity: 0.7; }
    75% { transform: translateX(8px); opacity: 0.7; }
}

.nav-tutorial-close {
    background: var(--color-accent);
    color: white;
    border: none;
    border-radius: var(--radius-md);
    padding: 12px 20px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s ease;
}

.nav-tutorial-close:hover {
    background: var(--color-accent-dark);
}

@keyframes fadeIn {
    from { opacity: 0; transform: scale(0.9); }
    to { opacity: 1; transform: scale(1); }
}

@keyframes fadeOut {
    from { opacity: 1; transform: scale(1); }
    to { opacity: 0; transform: scale(0.9); }
}

/* Hide mobile nav on desktop */
@media (min-width: 769px) {
    .mobile-nav,
    .mobile-regime-toggle,
    .take-home-preview,
    .swipe-indicator,
    .nav-tutorial-overlay {
        display: none !important;
    }
    
    .panel-container {
        display: contents !important;
    }
}