/* ========================================
   MOBILE & TABLET HEADER OPTIMIZATION
   Modern, Clean, and User-Friendly Navigation
   ======================================== */

/* ========================================
   BASE HEADER STYLES
   ======================================== */

#mainHeader {
    z-index: 1000;
    transition: all 0.3s ease;
}

/* ========================================
   MOBILE & TABLET OPTIMIZATIONS
   ======================================== */

@media (max-width: 991px) {
    /* Header Container - Transparent with Dark Text */
    #mainHeader {
        padding: 8px 0 !important;
        background: transparent !important;
        backdrop-filter: none;
        box-shadow: none;
        transition: all 0.3s ease;
    }

    #mainHeader .container-fluid {
        padding-left: 15px;
        padding-right: 15px;
    }

    /* Logo Optimization - Standard Size */
    #mainHeader .navbar-brand img {
        height: 40px !important;
        transition: height 0.3s ease;
        filter: brightness(1);
    }

    /* Hamburger Menu Button - Dark */
    .navbar-toggler {
        border: none !important;
        padding: 8px 12px;
        background: rgba(0, 0, 0, 0.7);
        border-radius: 10px;
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
        transition: all 0.3s ease;
    }

    .navbar-toggler:focus {
        box-shadow: 0 0 0 3px rgba(0, 0, 0, 0.3);
        outline: none;
    }

    .navbar-toggler:active {
        transform: scale(0.95);
    }

    .navbar-toggler i {
        color: #fff !important;
        font-size: 20px;
    }

    /* Mobile Menu Dropdown - White with Dark Text */
    .navbar-collapse {
        position: absolute;
        top: 100%;
        left: 0;
        right: 0;
        background: rgba(255, 255, 255, 0.98);
        backdrop-filter: blur(10px);
        border-radius: 0 0 20px 20px;
        box-shadow: 0 8px 30px rgba(0, 0, 0, 0.12);
        margin-top: 10px;
        padding: 20px !important;
        max-height: calc(100vh - 80px);
        overflow-y: auto;
        overflow-x: hidden;
    }

    .navbar-collapse.show {
        animation: slideDown 0.3s ease-out;
    }

    @keyframes slideDown {
        from {
            opacity: 0;
            transform: translateY(-20px);
        }
        to {
            opacity: 1;
            transform: translateY(0);
        }
    }

    /* Navigation Links - Dark Text */
    .navbar-nav {
        margin: 0 !important;
        padding: 0;
    }

    .nav-item {
        margin-bottom: 5px;
    }

    .nav-link {
        color: #1a1d20 !important;
        padding: 14px 20px !important;
        font-size: 16px;
        font-weight: 600;
        border-radius: 12px;
        transition: all 0.3s ease;
        display: flex;
        align-items: center;
        justify-content: space-between;
    }

    .nav-link::after {
        display: none !important;
    }

    .nav-link:hover,
    .nav-link.active {
        background: linear-gradient(135deg, #007bff 0%, #0056b3 100%);
        color: #fff !important;
        transform: translateX(5px);
    }

    .nav-link.active::before {
        content: '';
        width: 4px;
        height: 100%;
        background: #007bff;
        position: absolute;
        left: 0;
        top: 0;
        border-radius: 0 4px 4px 0;
    }

    /* Right Actions Container - Linear Search */
    .navbar-collapse > div:last-child {
        margin-top: 20px;
        padding-top: 20px;
        border-top: 2px solid #f0f0f0;
        flex-direction: column !important;
        gap: 15px !important;
    }

    /* Linear Search Form in Mobile Menu - Single Line */
    .navbar-collapse form.d-none {
        display: flex !important;
        width: 100%;
        margin: 0 !important;
    }

    .navbar-collapse .input-group {
        width: 100% !important;
        display: flex !important;
        flex-wrap: nowrap !important;
        align-items: center !important;
    }

    .navbar-collapse .input-group .form-control {
        flex: 1 1 auto !important;
        min-width: 0 !important;
        width: 100% !important;
        border-radius: 25px 0 0 25px !important;
        border: 2px solid #e9ecef !important;
        background: #f8f9fa !important;
        color: #1a1d20 !important;
        padding: 8px 14px !important;
        font-size: 14px !important;
        height: 40px !important;
        line-height: 1.5 !important;
    }

    .navbar-collapse .input-group .form-control::placeholder {
        color: #6c757d !important;
    }

    .navbar-collapse .input-group .btn {
        flex: 0 0 40px !important;
        width: 40px !important;
        min-width: 40px !important;
        max-width: 40px !important;
        border-radius: 0 25px 25px 0 !important;
        border: 2px solid #e9ecef !important;
        border-left: none !important;
        background: #007bff !important;
        color: #fff !important;
        padding: 0 !important;
        height: 40px !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
        transition: all 0.3s ease;
    }

    .navbar-collapse .input-group .btn:hover {
        background: #0056b3 !important;
    }
    
    .navbar-collapse .input-group .btn i {
        font-size: 14px !important;
        margin: 0 !important;
    }

    /* Hide search icon button for mobile */
    .btn-link.d-xl-none {
        display: none !important;
    }

    /* Get Quote Button - White Background */
    .btn-quote {
        width: 100% !important;
        padding: 16px 24px !important;
        font-size: 16px;
        font-weight: 700;
        border-radius: 50px;
        background: #ffffff !important;
        color: #1a1d20 !important;
        border: 2px solid #e9ecef !important;
        box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
        transition: all 0.3s ease;
        display: flex !important;
        align-items: center;
        justify-content: center;
        gap: 10px;
        margin-top: 10px;
    }

    .btn-quote:hover {
        transform: translateY(-3px);
        box-shadow: 0 8px 25px rgba(0, 0, 0, 0.15);
        background: #f8f9fa !important;
    }

    .btn-quote:active {
        transform: translateY(-1px) scale(0.98);
    }

    /* Scrolled State - White Background */
    #mainHeader.scrolled {
        background: #ffffff !important;
        backdrop-filter: blur(10px);
        box-shadow: 0 2px 15px rgba(0, 0, 0, 0.1);
        padding: 6px 0 !important;
    }

    #mainHeader.scrolled .navbar-brand img {
        height: 36px !important;
    }

    /* Keep hamburger dark when scrolled */
    #mainHeader.scrolled .navbar-toggler {
        background: rgba(0, 0, 0, 0.8);
    }
}

/* ========================================
   TABLET SPECIFIC (768px - 991px)
   ======================================== */

@media (min-width: 768px) and (max-width: 991px) {
    #mainHeader .container-fluid {
        padding-left: 30px;
        padding-right: 30px;
    }

    .navbar-collapse {
        padding: 25px !important;
    }

    .nav-link {
        font-size: 17px;
        padding: 16px 24px !important;
    }

    .btn-quote {
        padding: 18px 32px !important;
        font-size: 17px;
    }
}

/* ========================================
   SMALL MOBILE (< 576px)
   ======================================== */

@media (max-width: 576px) {
    #mainHeader .container-fluid {
        padding-left: 15px;
        padding-right: 15px;
    }

    #mainHeader .navbar-brand img {
        height: 36px !important;
    }
    
    #mainHeader.scrolled .navbar-brand img {
        height: 32px !important;
    }

    .navbar-toggler {
        padding: 6px 10px;
    }

    .navbar-toggler i {
        font-size: 18px;
    }

    .navbar-collapse {
        padding: 15px !important;
        border-radius: 0 0 15px 15px;
    }

    .nav-link {
        padding: 12px 16px !important;
        font-size: 15px;
    }

    .btn-quote {
        padding: 14px 20px !important;
        font-size: 15px;
    }
    
    /* Ensure search stays on single line on small screens */
    .navbar-collapse .input-group .form-control {
        padding: 8px 12px !important;
        font-size: 13px !important;
        height: 38px !important;
    }
    
    .navbar-collapse .input-group .btn {
        flex: 0 0 38px !important;
        width: 38px !important;
        min-width: 38px !important;
        max-width: 38px !important;
        padding: 0 !important;
        height: 38px !important;
    }
    
    .navbar-collapse .input-group .btn i {
        font-size: 13px !important;
    }
}

/* ========================================
   SMOOTH SCROLLBAR FOR MOBILE MENU
   ======================================== */

@media (max-width: 991px) {
    .navbar-collapse::-webkit-scrollbar {
        width: 6px;
    }

    .navbar-collapse::-webkit-scrollbar-track {
        background: #f1f1f1;
        border-radius: 10px;
    }

    .navbar-collapse::-webkit-scrollbar-thumb {
        background: #007bff;
        border-radius: 10px;
    }

    .navbar-collapse::-webkit-scrollbar-thumb:hover {
        background: #0056b3;
    }
}

/* ========================================
   ACCESSIBILITY IMPROVEMENTS
   ======================================== */

@media (max-width: 991px) {
    /* Focus states */
    .nav-link:focus,
    .btn-quote:focus,
    .navbar-toggler:focus {
        outline: 3px solid rgba(0, 123, 255, 0.5);
        outline-offset: 2px;
    }

    /* Tap highlight */
    .nav-link,
    .btn-quote,
    .navbar-toggler {
        -webkit-tap-highlight-color: rgba(0, 123, 255, 0.2);
    }

    /* Minimum touch target */
    .nav-link,
    .btn-quote,
    .navbar-toggler {
        min-height: 44px;
        min-width: 44px;
    }
}

/* ========================================
   ANIMATION ENHANCEMENTS
   ======================================== */

@media (max-width: 991px) {
    /* Stagger animation for menu items */
    .navbar-collapse.show .nav-item {
        animation: fadeInLeft 0.3s ease-out backwards;
    }

    .navbar-collapse.show .nav-item:nth-child(1) { animation-delay: 0.05s; }
    .navbar-collapse.show .nav-item:nth-child(2) { animation-delay: 0.1s; }
    .navbar-collapse.show .nav-item:nth-child(3) { animation-delay: 0.15s; }
    .navbar-collapse.show .nav-item:nth-child(4) { animation-delay: 0.2s; }
    .navbar-collapse.show .nav-item:nth-child(5) { animation-delay: 0.25s; }
    .navbar-collapse.show .nav-item:nth-child(6) { animation-delay: 0.3s; }

    @keyframes fadeInLeft {
        from {
            opacity: 0;
            transform: translateX(-20px);
        }
        to {
            opacity: 1;
            transform: translateX(0);
        }
    }

    /* Button animations */
    .navbar-collapse.show .btn-quote {
        animation: fadeInUp 0.4s ease-out 0.35s backwards;
    }

    @keyframes fadeInUp {
        from {
            opacity: 0;
            transform: translateY(20px);
        }
        to {
            opacity: 1;
            transform: translateY(0);
        }
    }
}

/* ========================================
   PREVENT BODY SCROLL WHEN MENU OPEN
   ======================================== */

@media (max-width: 991px) {
    /* Prevent auto-scroll when menu opens */
    .navbar-collapse.collapsing,
    .navbar-collapse.show {
        position: absolute !important;
    }
    
    body.menu-open {
        overflow: hidden;
    }

    body.menu-open #mainHeader {
        position: fixed;
        width: 100%;
    }
}

/* ========================================
   LIGHT MODE OVERRIDE (Optional)
   For pages with light backgrounds
   ======================================== */

@media (max-width: 991px) {
    /* Add .light-header class to header for light mode */
    #mainHeader.light-header {
        background: rgba(255, 255, 255, 0.95) !important;
        backdrop-filter: blur(10px);
    }

    #mainHeader.light-header .navbar-toggler {
        background: linear-gradient(135deg, #007bff 0%, #0056b3 100%);
    }

    #mainHeader.light-header .navbar-collapse {
        background: rgba(255, 255, 255, 0.98);
    }

    #mainHeader.light-header .nav-link {
        color: #1a1d20 !important;
    }

    #mainHeader.light-header .nav-link:hover,
    #mainHeader.light-header .nav-link.active {
        background: linear-gradient(135deg, #007bff 0%, #0056b3 100%);
        color: #fff !important;
    }

    #mainHeader.light-header .btn-link {
        background: #f8f9fa;
        color: #1a1d20 !important;
    }

    #mainHeader.light-header .navbar-collapse > div:last-child {
        border-top-color: #f0f0f0;
    }
}

/* ========================================
   PERFORMANCE OPTIMIZATIONS
   ======================================== */

@media (max-width: 991px) {
    /* GPU acceleration */
    #mainHeader,
    .navbar-collapse,
    .nav-link,
    .btn-quote {
        transform: translateZ(0);
        backface-visibility: hidden;
        will-change: transform;
    }

    /* Smooth transitions */
    * {
        -webkit-font-smoothing: antialiased;
        -moz-osx-font-smoothing: grayscale;
    }
}

/* ========================================
   LANDSCAPE MODE ADJUSTMENTS
   ======================================== */

@media (max-width: 991px) and (orientation: landscape) {
    .navbar-collapse {
        max-height: calc(100vh - 60px);
    }

    .nav-link {
        padding: 10px 16px !important;
    }
}
