/* Mobile Devices */
@media (max-width: 768px) {
    /* Layout */
    .app-container {
        grid-template-areas:
            "header"
            "sidebar"
            "main"
            "insights";
        grid-template-columns: 1fr;
        grid-template-rows: auto auto auto auto;
        min-height: 100vh;
        overflow-y: auto;
        overflow-x: hidden;
    }
    
    /* Header */
    .header {
        /* Ultra compact padding for mobile */
        padding: clamp(8px, 2.5vw, 12px) clamp(10px, 3vw, 16px);
        display: flex;
        align-items: center;
        justify-content: space-between;
        background: var(--gradient-header);
        backdrop-filter: blur(20px);
        border-bottom: 1px solid var(--color-border);
        /* Much smaller header height */
        min-height: clamp(40px, 10vh, 60px);
        position: relative;
        /* z-index: 10001;  */
    }
    
    .logo-title-container {
        flex: 1 1 auto;
        display: flex;
        align-items: center;
        position: static;
        transform: none;
        width: 100%;
        gap: 10px;
    }
    
    .logo-title-wrapper {
        display: flex;
        flex-direction: column; /* stack title and FY */
        align-items: flex-start;
        position: static;
        transform: none;
        width: 100%;
        /* Smart responsive gap - minimal but not cramped */
        gap: clamp(0px, 0.3vw, 2px);
        /* Optimize available space */
        min-height: 0;
        flex: 1 1 auto;
    }
    
    .logo {
        font-size: 14px;
        font-weight: 500;
        letter-spacing: 0.3px;
    flex: 0 0 auto;
    }
    
    .logo-title-wrapper .site-title {
        display: block;
        width: 100%;
        min-width: 0;
        /* ULTRA aggressive responsive sizing - minimum 9px for iPhone SE */
        font-size: clamp(9px, 3.5vw, 18px);
        /* Always allow wrapping for optimal space usage */
        white-space: normal;
        overflow: visible;
        text-overflow: unset;
        font-weight: 700;
        margin: 0;
        padding: 0;
        line-height: 1.0;
        /* Ensure proper word breaking for optimal layout */
        word-break: keep-all;
        hyphens: none;
    }

    .logo-title-wrapper .fy-line {
        /* ULTRA aggressive responsive sizing for FY line - minimum 8px */
        font-size: clamp(8px, 2.8vw, 14px);
        font-weight: 500;
        color: var(--color-text-secondary);
        margin: 0;
        line-height: 1.0;
    }
    
    .header-controls {
        display: flex;
        align-items: center;
    gap: 10px; /* slightly tighter gap on mobile */
        flex-shrink: 0;
    }
    
    /* Very small screens: optimize for smart two-line layout */
    @media (max-width: 420px) {
        .logo-title-container {
            justify-content: center;
            /* Maximize available space */
            flex: 1 1 auto;
        }

        .logo-title-wrapper {
            align-items: center;
            text-align: center;
            /* Ensure optimal space utilization */
            width: 100%;
            max-width: none;
        }

        /* Much smaller fonts on very small screens to fit in 2 lines */
        .logo-title-wrapper .site-title {
            font-size: clamp(11px, 3.2vw, 14px);
        }

        .logo-title-wrapper .fy-line {
            font-size: clamp(9px, 2.8vw, 12px);
        }
    }

    /* Shrink logo image and tighten spacing on very small screens so title fits */
    @media (max-width: 420px) {
        .logo-image {
            height: 28px !important;
            margin-right: 6px !important;
        }

        .logo-title-container {
            gap: 6px;
        }
    }
    .theme-toggle {
        display: none;
    }
    
    /* Hide regime toggle in header for mobile */
    .regime-toggle {
        display: none;
    }
    
    /* Hide help button in header for mobile - use settings panel instead */
    .help-btn {
        display: none !important;
    }
    
    /* Panels */
    .sidebar {
        height: auto;
        /* Reduced from 65vh to 45vh - keeps essential elements visible */
        max-height: 45vh;
        overflow-y: auto;
        overflow-x: hidden;
        /* Much smaller padding for narrow screens */
        padding: clamp(12px, 3vw, 20px);
        border-bottom: 1px solid var(--color-border);
        border-right: none;
        position: relative;
        scroll-behavior: smooth;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: thin;
        scrollbar-color: rgba(255, 255, 255, 0.2) transparent;
    }
    
    .sidebar::-webkit-scrollbar {
        width: 6px;
    }
    
    .sidebar::-webkit-scrollbar-track {
        background: transparent;
    }
    
    .sidebar::-webkit-scrollbar-thumb {
        background-color: var(--color-border);
        border-radius: 3px;
    }
    
    .sidebar::-webkit-scrollbar-thumb:hover {
        background-color: var(--color-text-secondary);
    }
    
    .sidebar::after {
        content: '';
        position: sticky;
        bottom: 0;
        left: 0;
        right: 0;
        height: 20px;
        background: linear-gradient(to bottom, transparent, var(--color-bg-primary));
        pointer-events: none;
        z-index: 1;
    }

    .panel .sidebar {
        max-height: none;
    }
    
    .main-panel {
        height: auto;
        min-height: auto;
        /* Responsive padding for results panel */
        padding: clamp(20px, 6vw, 30px) clamp(16px, 5vw, 24px);
        overflow: visible;
        border-bottom: 1px solid var(--color-border);
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: flex-start;
    }
    
    .insights-panel {
        max-height: 45vh;
        overflow-y: auto;
        overflow-x: hidden;
        padding: 20px;
        border-left: none;
        border-bottom: none;
        scroll-behavior: smooth;
        -webkit-overflow-scrolling: touch;
    }

    /* Components */
    .salary-control,
    .ctc-display-container,
    .basic-input-container,
    .input-section {
        background: transparent;
        border: none;
        box-shadow: none;
        padding: 0;
        margin-bottom: 2px;
    }
    
    .input-section {
        /* Reduce spacing between sections for mobile to fit more content */
        margin-bottom: clamp(0px, 0.2vw, 2px);
    }
    
    .section-title {
        /* Much smaller font size for narrow screens */
        font-size: clamp(12px, 3.2vw, 16px);
        font-weight: 700;
        color: var(--color-text-primary, #1d1d1f);
        /* Smaller margin */
        margin-bottom: clamp(4px, 1.5vw, 8px);
        letter-spacing: 0.2px;    
    }
    
    .salary-control {
        display: flex;
        align-items: stretch !important;
        flex-direction: column;
        gap: 0;
        width: 100%;
        margin-bottom: 0px;
    }
    .salary-label,
    .deduction-label {
        /* Much smaller font size for labels */
        font-size: clamp(10px, 2.8vw, 13px);
        font-weight: 500;
        color: var(--color-text-secondary, #555);
        /* Minimal margin */
        margin-bottom: clamp(1px, 0.3vw, 2px);
    }

    
    .result-showcase {
        width: 100%;
        max-width: 400px;
        margin: 0 auto;
    }
    
    .salary-display,
    .result-amount {
        /* Much smaller font size for narrow screens */
        font-size: clamp(20px, 6vw, 32px);
        font-weight: 200;
        color: var(--color-text-primary, #1d1d1f);
        /* Smaller margin */
        margin-bottom: clamp(2px, 1vw, 6px);
        letter-spacing: -1px;
        line-height: 1.1;
    }
    
    /* Mobile pillow/bulge gradient effect for CTC input */
    .salary-display {
        background: linear-gradient(to right, transparent 0%, rgba(255, 255, 255, 0.08) 50%, transparent 100%);
        padding: 4px 8px;
        border-radius: 6px;
        cursor: text;
    }
    
    .salary-display:hover {
        background: linear-gradient(to right, transparent 0%, rgba(255, 255, 255, 0.12) 50%, transparent 100%);
    }
    
    .salary-display:focus {
        background: linear-gradient(to right, transparent 0%, rgba(0, 122, 255, 0.15) 50%, transparent 100%);
    }    
    .comparison-chart {
        padding: 20px;
        margin: 25px 0;
    }
    
    .chart-bars {
        height: 110px;
    }
    
    /* Input Layout */
    .input-section .salary-control {
        display: flex;
        align-items: center;
        gap: 10px;
        flex-wrap: nowrap;
    }
    
    .input-section .basic-toggle {
        flex: 0 0 auto;
        margin-bottom: 1px;
    }
    
    .input-section .basic-input-container {
        flex: 1 1 0%;
        min-width: 0;
    }
    
    .input-section .section-title,
    .input-section .basic-toggle {
        display: inline-flex;
        vertical-align: middle;
    }
    
    .input-section .section-title {
        /* Responsive margin */
        margin-right: clamp(8px, 2.5vw, 12px);
        /* Responsive font size */
        font-size: clamp(13px, 4vw, 16px);
    }
    
    /* CTC Display */
    .ctc-display-container {
        background: transparent;
        border: none;
        box-shadow: none;
        padding: 0;
        margin-bottom: 0px;
        backdrop-filter: none;
        transition: none;
        display: flex;
        align-items: center;
        gap: 10px;
    }
    
    /* Slider Adjustments */
    .salary-slider::-webkit-slider-thumb,
    .basic-slider::-webkit-slider-thumb {
        margin-top: -6px;
    }
    
    .salary-slider::-ms-thumb,
    .basic-slider::-ms-thumb {
        margin-top: 0;
    }

    /* --- Input Focus Mode Styles --- */
    .focus-overlay {
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        background: rgba(0, 0, 0, 0.6);
        backdrop-filter: blur(8px);
        -webkit-backdrop-filter: blur(8px);
        z-index: 2000;
        opacity: 0;
        pointer-events: none;
        transition: opacity 0.3s ease;
    }

    .focus-input-container {
        position: fixed;
        top: 40%; /* Position slightly higher than center */
        left: 50%;
        transform: translate(-50%, -50%) scale(0.9);
        z-index: 2001;
        background: var(--color-bg-secondary);
        border-radius: var(--radius-xl);
        padding: 24px;
        width: calc(100% - 40px);
        max-width: 380px;
        box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
        opacity: 0;
        pointer-events: none;
        transition: opacity 0.3s ease, transform 0.3s ease;
    }

    /* State when focus mode is active */
    body.input-focused .focus-overlay,
    body.input-focused .focus-input-container {
        opacity: 1;
        pointer-events: auto;
    }

    body.input-focused .focus-input-container {
        transform: translate(-50%, -50%) scale(1);
    }

    /* Styling for the focused elements */
    #focusInputLabel {
        display: block;
        font-size: 16px;
        font-weight: 500;
        color: var(--color-text-secondary);
        margin-bottom: 12px;
    }

    #focusInputHolder input {
        width: 100%;
        font-size: 28px;
        font-weight: 300;
        padding: 12px;
        border: 1px solid var(--color-border);
        border-radius: var(--radius-md);
        background: var(--color-bg-primary);
        color: var(--color-text-primary);
        text-align: center;
    }

    #focusInputDone {
        width: 100%;
        padding: 14px;
        margin-top: 20px;
        border: none;
        background: var(--color-accent);
        color: white;
        font-size: 18px;
        font-weight: 600;
        border-radius: var(--radius-md);
        cursor: pointer;
        transition: background 0.2s ease;
    }

    #focusInputDone:hover {
        background: #0056b3; /* A slightly darker accent color */
    }    
    
    /* Landscape Orientation */
    @media (orientation: landscape) and (max-height: 600px) {
        .app-container {
            grid-template-areas:
                "header header"
                "sidebar main"
                "sidebar insights";
            grid-template-columns: 320px 1fr;
            grid-template-rows: auto 1fr auto;
        }
        
        .sidebar {
            max-height: calc(100vh - 80px);
            border-right: 1px solid var(--color-border);
            border-bottom: none;
        }
        
        .main-panel {
            min-height: auto;
            border-bottom: none;
        }
        
        .insights-panel {
            border-left: 1px solid var(--color-border);
            max-height: 35vh;
        }
    }
    
    .result-title {
        font-size: 14px;
        font-weight: 500;
        color: var(--color-text-secondary, #555);
        margin-bottom: 6px;
    }
    
    /* iPhone SE and very small screens - ULTRA AGGRESSIVE sizing to force exactly 2 lines */
    @media (max-width: 375px) {
        .logo-title-wrapper .site-title {
            font-size: 9px !important;
            line-height: 0.95 !important;
            letter-spacing: -0.3px !important;
            word-spacing: -1px !important;
        }

        .logo-title-wrapper .fy-line {
            font-size: 8px !important;
            line-height: 0.95 !important;
        }

        .logo-title-wrapper {
            gap: 0px !important;
        }

        .header {
            padding: 8px 12px !important;
            min-height: 44px !important;
        }

        /* Force text to break properly */
        .logo-title-wrapper .site-title {
            max-width: 200px !important;
            white-space: normal !important;
            overflow-wrap: break-word !important;
        }
    }

    /* Very Small Screens - other elements */
    @media (max-width: 375px) {
        .header {
            padding: 10px 12px;
        }
        
        .logo {
            font-size: 12px;
        }
        
        .logo h1 {
            font-size: 12px;
        }
        
        .regime-btn {
            font-size: 11px;
            padding: 8px 12px;
        }
        
        .sidebar {
            height: auto;
            /* Ultra-compact for iPhone SE - reduced from 60vh to 38vh */
            max-height: 38vh;
        }
        
        .result-amount {
            font-size: 48px;
        }
        
        .main-panel {
            padding: 20px 15px;
            min-height: 40vh;
        }
    }
    
    /* Performance Optimizations */
    .regime-btn {
        animation: none;
    }
    
    .regime-btn:active:not(.active) {
        opacity: 0.7;
    }
    
    /* Touch Targets - Optimize for Mobile with responsive sizing */
    .regime-btn {
        /* Responsive padding */
        padding: clamp(8px, 3vw, 12px) clamp(16px, 6vw, 24px) !important;
        min-height: 44px;
        /* Responsive minimum width */
        min-width: clamp(70px, 20vw, 90px);
        /* Responsive font size */
        font-size: clamp(12px, 3.8vw, 16px) !important;
        font-weight: 600 !important;
        display: flex;
        align-items: center;
        justify-content: center;
        position: relative;
    }
    
    /* Responsive regime toggle container - override later styles */
    .regime-toggle {
        /* Responsive gap */
        gap: clamp(6px, 2vw, 10px) !important;
        /* Responsive padding */
        padding: clamp(2px, 1vw, 4px) !important;
    }
    
    /* Better visual feedback for mobile */
    .regime-btn:active {
        transform: scale(0.96);
        transition: transform 0.1s ease;
    }
    
    /* Smooth micro-interactions for mobile */
    .deduction-input {
        transition: all 0.2s ease !important;
    }
    
    .deduction-input:focus {
        transform: scale(1.02);
        z-index: 10;
        position: relative;
    }
    
    .deduction-input:active {
        transform: scale(0.98);
    }
    
    /* Enhanced touch feedback for sliders */
    .salary-slider:active,
    .basic-slider:active {
        filter: brightness(1.1);
    }
    
    /* Smooth panel transitions with haptic-like feedback */
    .panel {
        transition: opacity 0.3s ease;
    }
    
    .panel-container.transitioning .panel {
        will-change: transform;
    }
    
    /* Button press feedback */
    .basic-btn:active {
        transform: scale(0.95);
        transition: transform 0.1s ease;
    }
    
    /* Subtle hover states for touch devices */
    @media (hover: hover) {
        .deduction-input:hover {
            border-color: var(--color-accent);
            box-shadow: 0 0 0 1px rgba(0, 122, 255, 0.1);
        }
        
        .regime-btn:hover:not(.active) {
            background: rgba(0, 122, 255, 0.1);
            color: var(--color-accent);
        }
    }
    
    @media (pointer: coarse) {
        .regime-btn {
            min-width: 88px;
            min-height: 44px;
        }
    }
}

