/* responsive.css */

/* Accessibility focus styles */
.primary-navigation a:focus {
    outline: 2px solid #007acc;
    outline-offset: 2px;
}

/* ===========================
    Responsive Navigation Styles
    =========================== */

/* Tablet & Mobile (max-width: 991px) */
@media (max-width: 991px) {
    /* Show hamburger */
    .menu-toggle {
        display: block !important; /* Ensure this is always shown on mobile */
    }

    /* Navigation fixed below header */
    .primary-navigation {
        position: fixed;
        top: 56px; /* Adjust if header height changes */
        left: 0;
        right: 0;
        background: #fff;
        border-top: 1px solid #ddd;
        box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
        max-height: 0; /* Hidden by default */
        overflow: hidden; /* Crucial for max-height transition */
        transition: max-height 0.3s ease-out, opacity 0.3s ease-out, visibility 0.3s ease-out; /* Added opacity and visibility to transition */
        z-index: 10500; /* High z-index to ensure it's on top of page content */
        opacity: 0; /* Start hidden */
        visibility: hidden; /* Start hidden */
        display: block; /* Ensure it's a block element for max-height to work */
    }

    /* When nav is open */
    body.nav-open .primary-navigation {
        max-height: 100vh; /* Sufficiently large to reveal entire menu */
        overflow-y: auto;
        opacity: 1; /* Show */
        visibility: visible; /* Show */
    }

    /* Vertical menu */
    .nav-links {
        flex-direction: column;
        gap: 0;
    }

    /* Menu items border */
    .nav-links > li {
        border-bottom: 1px solid #eee;
    }

    /* --- CRITICAL FIXES FOR MOBILE DROPDOWNS START HERE --- */

    /* Header navigation dropdowns (Services, Core Renovation Services, etc.) */
    .dropdown-menu,
    .submenu-list {
        position: static; /* Important for mobile: makes it flow normally */
        background: none; /* No background for sub-menus on mobile */
        border: none;
        box-shadow: none;
        padding-left: 1em;
        max-height: 0; /* HIDDEN by default using max-height */
        overflow: hidden; /* Crucial for max-height transition */
        opacity: 0; /* Start hidden */
        visibility: hidden; /* Start hidden */
        transition: max-height 0.3s ease-out, opacity 0.3s ease-out, visibility 0.3s ease-out; /* Smooth transition */
        display: block; /* Ensure it's a block element to take max-height */
    }

    /* WHEN THE HEADER DROPDOWN IS OPEN (JS adds the .open class) */
    .dropdown-menu.open,
    .submenu-list.open {
        max-height: 1000px; /* Make it tall enough to show all content */
        overflow: auto; /* Allow scrolling if content is too long */
        opacity: 1; /* Show */
        visibility: visible; /* Show */
    }

    /* --- CRITICAL FIXES FOR MOBILE DROPDOWNS END HERE --- */


    /* Rules for the service section dropdowns on the main page (e.g., Core Renovation Services) */
    .service-card .dropdown-content {
        max-height: 0; /* HIDDEN by default */
        overflow: hidden; /* Crucial for max-height transition */
        transition: max-height 0.3s ease-out;
        padding-left: 1em; /* Add some indentation */
        display: block; /* Ensure it's a block element to take max-height */
    }

    /* WHEN THE SERVICE CARD DROPDOWN IS OPEN */
    .service-card .dropdown-content.open {
        max-height: 1000px; /* Make it tall enough */
        overflow: auto;
    }

    /* Further indentation for submenu links */
    .submenu-list a {
        padding: 0.5em 3em;
    }

    /* Indentation for dropdown links (applies to both header and service-card links) */
    .dropdown-menu a,
    .submenu-list a,
    .service-card .dropdown-content a {
        padding: 0.5em 2em;
    }
    
    /* Custom caret indicator for mobile dropdowns */
    .has-dropdown > a::after,
    .has-submenu > a::after {
        content: '▶';
        float: right;
        font-size: 0.75em;
        transform: rotate(0deg);
        transition: transform 0.3s ease;
        margin-left: 0.5em; /* Added space */
    }

    /* Rotate when open */
    .has-dropdown.open > a::after,
    .has-submenu.open > a::after {
        transform: rotate(90deg);
    }

    /* Scrollbar styling for mobile nav overflow */
    .primary-navigation::-webkit-scrollbar {
        width: 8px;
    }

    .primary-navigation::-webkit-scrollbar-thumb {
        background-color: rgba(0, 0, 0, 0.15);
        border-radius: 4px;
    }
}

/* Desktop-specific overrides (min-width: 992px) */
@media (min-width: 992px) {
    /* Hide hamburger menu on desktop */
    .menu-toggle {
        display: none !important; /* Ensure hidden on desktop */
    }

    /* Nav links displayed horizontally on desktop */
    .primary-navigation {
        position: static; /* Remove fixed positioning */
        max-height: none; /* Ensure full height */
        overflow: visible; /* Ensure content is visible */
        border-top: none;
        box-shadow: none;
        opacity: 1; /* Ensure visible on desktop */
        visibility: visible; /* Ensure visible on desktop */
    }

    .nav-links {
        display: flex;
        flex-direction: row; /* Ensure horizontal */
        gap: 1em;
    }

    .nav-links > li {
        border-bottom: none; /* Remove mobile border */
    }

    /* Reintroduce dropdown arrow for hover */
    .has-dropdown > a::after,
    .has-submenu > a::after {
        content: ' ▼';
        font-size: 0.6em;
        margin-left: 0.25em;
    }

    /* Reset mobile specific dropdown behavior for header navigation */
    .dropdown-menu,
    .submenu-list {
        position: absolute; /* Revert to absolute positioning */
        background: #fff;
        border: 1px solid #ddd;
        box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
        opacity: 0; /* Hidden by default, shown on hover/focus on desktop */
        visibility: hidden; /* Hidden by default, shown on hover/focus on desktop */
        transition: opacity 0.3s ease, visibility 0.3s ease; /* Transition opacity/visibility for desktop */
        z-index: 1000;
        padding: 0.5em 0;
        border-radius: 4px;
        display: block; /* IMPORTANT: Always keep display block for opacity/visibility transitions */
        max-height: none; /* Reset any max-height from mobile */
        overflow: visible; /* Reset any overflow from mobile */
    }

    .dropdown-menu {
        top: 100%;
        left: 0;
    }

    .submenu-list {
        top: 0;
        left: 100%;
    }

    /* Ensure correct padding for desktop */
    .dropdown-menu a,
    .submenu-list a {
        padding: 0.5em 1.5em;
    }

    /* Reset .open classes as they're for mobile JS interaction */
    .dropdown-menu.open,
    .submenu-list.open {
        max-height: none; /* Remove mobile max-height override */
        opacity: 0; /* Ensure these are hidden if accidentally applied */
        visibility: hidden; /* Ensure these are hidden if accidentally applied */
    }

    /* Ensure desktop hover rules correctly show the dropdowns */
    .has-dropdown:hover > .dropdown-menu,
    .has-dropdown > a:focus + .dropdown-menu,
    .has-submenu:hover > ul.submenu-list, /* Corrected selector: should be ul.submenu-list */
    .has-submenu > a:focus + ul.submenu-list { /* Corrected selector: should be ul.submenu-list */
        opacity: 1; /* Show on hover/focus on desktop */
        visibility: visible; /* Show on hover/focus on desktop */
    }

    /* --- FIX FOR SERVICE CARD DROPDOWNS ON DESKTOP --- */
    /* Ensure they are hidden by default on desktop and only revealed by the 'open' class */
    .service-card .dropdown-content {
        max-height: 0; /* Initially hidden with max-height */
        overflow: hidden; /* Important for transition */
        transition: max-height 0.3s ease-out; /* Smooth transition */
        padding-left: 0; /* Remove mobile indentation */
        display: block; /* Ensure it's a block element to take max-height, but content hidden */
    }

    .service-card .dropdown-content.open {
        max-height: 1000px; /* Expands when 'open' class is added */
        overflow: auto; /* Allow scrolling if content is too long */
    }
}
