/* CSS Custom Properties for Design System */
:root {
    --mg-black: #000000;
    --mg-white: #ffffff;
    --mg-gray-bg: #f9f9f9;
    --mg-gray-border: #e5e5e5;
    --mg-text-dark: #1d1d1f;
    --mg-text-muted: #86868b;
    --mg-orange: #ff9f00;
    --mg-blue-electric: #00b0f0;
    --mg-green-hybrid: #00c853;
    --mg-red-gasoline: #e53935;
    --mg-font-family: 'Outfit', 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    --mg-transition-speed: 0.3s;
}

/* Base resets inside our header to prevent theme interference */
.mg-custom-header * {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: var(--mg-font-family);
    -webkit-font-smoothing: antialiased;
}

.mg-custom-header {
    background-color: var(--mg-black);
    width: 100%;
    position: relative;
    z-index: 99999;
}

/* Header Container */
.mg-header-container {
    max-width: 1400px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 40px;
    height: 90px;
}

/* Logo */
.mg-logo-wrapper {
    display: flex;
    align-items: center;
}

.mg-logo-wrapper a {
    display: flex;
    align-items: center;
}

.mg-logo {
    height: 48px;
    width: auto;
    object-fit: contain;
    margin: 0 !important;
    display: block !important;
}

/* Navigation Links */
.mg-main-nav {
    display: flex !important;
    height: 100% !important;
    margin: 0 !important;
    padding: 0 !important;
}

.mg-menu-list {
    display: flex !important;
    list-style: none !important;
    align-items: center !important;
    height: 100% !important;
    margin: 0 !important;
    padding: 0 !important;
    line-height: normal !important;
}

.mg-menu-item {
    height: 100% !important;
    display: flex !important;
    align-items: center !important;
    margin: 0 !important;
    padding: 0 !important;
    line-height: normal !important;
}

.mg-menu-link {
    color: var(--mg-white);
    text-decoration: none !important;
    font-size: 15px;
    font-weight: 500;
    padding: 0 20px !important;
    height: 100% !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    margin: 0 !important;
    line-height: 1 !important;
    transition: color var(--mg-transition-speed) ease;
}

.mg-menu-link:hover {
    color: var(--mg-text-muted);
}

.mg-arrow-down {
    display: inline-block !important;
    width: 0;
    height: 0;
    margin-left: 6px !important;
    margin-top: 2px !important; /* Compensate visually for uppercase font baseline offset */
    vertical-align: middle !important;
    border-top: 4px solid var(--mg-white);
    border-right: 4px solid transparent;
    border-left: 4px solid transparent;
    transition: transform var(--mg-transition-speed) ease;
}

.mg-menu-item:hover .mg-arrow-down,
.mg-menu-item.open .mg-arrow-down {
    transform: rotate(180deg);
}

/* ==========================================================================
   Submenús Convencionales (Dropdowns)
   ========================================================================== */
.mg-has-megamenu {
    position: static !important;
}

.mg-has-dropdown {
    position: relative !important;
}

.mg-dropdown-menu {
    display: none !important; /* Oculto por defecto */
    position: absolute !important;
    top: 100% !important;
    left: 0 !important;
    background-color: var(--mg-black) !important; /* Fondo negro a juego con la cabecera */
    border: 1px solid rgba(255, 255, 255, 0.15) !important;
    min-width: 180px !important;
    list-style: none !important;
    padding: 8px 0 !important;
    margin: 0 !important;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5) !important;
    border-radius: 4px !important;
    z-index: 100000 !important;
    flex-direction: column !important;
}

/* Mostrar dropdown al hacer hover sobre el item padre */
.mg-has-dropdown:hover .mg-dropdown-menu {
    display: flex !important;
}

.mg-dropdown-item {
    width: 100% !important;
    display: block !important;
    padding: 0 !important;
    margin: 0 !important;
}

.mg-dropdown-item a {
    display: block !important;
    padding: 10px 18px !important;
    color: var(--mg-white) !important;
    text-decoration: none !important;
    font-size: 13px !important;
    font-weight: 500 !important;
    transition: all 0.2s ease !important;
    white-space: nowrap !important;
    text-align: left !important;
    line-height: 1.2 !important;
}

.mg-dropdown-item a:hover {
    background-color: rgba(255, 255, 255, 0.08) !important;
    color: var(--mg-white) !important;
    padding-left: 22px !important; /* Desplazamiento sutil interactivo */
}

/* Header Buttons (Right) */
.mg-header-buttons {
    display: flex !important;
    align-items: center !important;
    gap: 12px !important;
    margin: 0 !important;
    padding: 0 !important;
}

.mg-btn {
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    padding: 10px 24px !important;
    border-radius: 30px !important;
    font-size: 14px;
    font-weight: 600;
    text-decoration: none !important;
    cursor: pointer !important;
    margin: 0 !important;
    line-height: 1 !important;
    transition: all var(--mg-transition-speed) ease;
}

.mg-btn-outline {
    background-color: transparent;
    color: var(--mg-white);
    border: 1px solid var(--mg-white);
}

.mg-btn-outline:hover {
    background-color: var(--mg-white);
    color: var(--mg-black);
}

.mg-btn-solid {
    background-color: var(--mg-white);
    color: var(--mg-black);
    border: 1px solid var(--mg-white);
}

.mg-btn-solid:hover {
    background-color: transparent;
    color: var(--mg-white);
}

/* Megamenú Panel Dropdown */
.mg-megamenu-panel {
    position: absolute;
    top: 100%;
    left: 0;
    width: 100%;
    background-color: var(--mg-white);
    box-shadow: 0 10px 30px rgba(0,0,0,0.15);
    border-top: 1px solid #222;
    opacity: 0;
    visibility: hidden;
    transform: translateY(15px);
    transition: opacity 0.25s ease, transform 0.25s ease, visibility 0.25s;
    pointer-events: none;
}

/* Show megamenu when active class is added by JS */
.mg-megamenu-panel.active {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
    pointer-events: auto;
}

.mg-megamenu-container {
    width: 100%;
    display: flex;
    flex-direction: column;
}

/* Filters Top Bar (Black background) */
.mg-megamenu-filters {
    background-color: var(--mg-black);
    padding: 15px 40px;
    display: flex;
    justify-content: flex-start;
}

.mg-filters-wrapper {
    max-width: 1400px;
    width: 100%;
    margin: 0 auto;
    display: flex;
    gap: 15px;
    flex-wrap: wrap;
}

.mg-filter-btn {
    background: transparent;
    border: none;
    color: var(--mg-white);
    font-size: 14px;
    font-weight: 500;
    padding: 8px 20px;
    border-radius: 20px;
    cursor: pointer;
    transition: all var(--mg-transition-speed) ease;
}

.mg-filter-btn:hover {
    color: var(--mg-text-muted);
}

.mg-filter-btn.active {
    background-color: var(--mg-white);
    color: var(--mg-black);
}

/* Megamenu Main Content (White background) */
.mg-megamenu-content {
    background-color: var(--mg-white);
    display: flex;
    max-width: 1400px;
    width: 100%;
    margin: 0 auto;
    min-height: 520px;
}

/* Left Column: Grid */
.mg-megamenu-grid-col {
    width: 70%;
    padding: 40px;
    border-right: 1px solid var(--mg-gray-border);
}

.mg-vehicles-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 30px 24px;
    max-height: 580px;
    overflow-y: auto;
    padding-right: 10px;
}

/* Custom Scrollbar for Grid */
.mg-vehicles-grid::-webkit-scrollbar {
    width: 4px;
}
.mg-vehicles-grid::-webkit-scrollbar-track {
    background: var(--mg-white);
}
.mg-vehicles-grid::-webkit-scrollbar-thumb {
    background: #ccc;
    border-radius: 4px;
}

/* Vehicle Cards */
.mg-vehicle-card {
    position: relative;
    display: flex;
    flex-direction: column;
    padding: 16px;
    border-radius: 12px;
    transition: all 0.25s ease;
    cursor: pointer;
    background: var(--mg-white);
}

.mg-vehicle-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 4px 15px rgba(0,0,0,0.05);
}

.mg-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
    min-height: 24px;
}

/* Fuel Tag styling */
.mg-fuel-tag {
    display: inline-flex;
    align-items: center;
    font-size: 11px;
    font-weight: 500;
    color: var(--mg-blue-electric);
    text-transform: capitalize;
}

.mg-fuel-icon {
    width: 12px;
    height: 12px;
    margin-left: 4px;
    object-fit: contain;
}

.mg-badge-new {
    background-color: var(--mg-orange);
    color: var(--mg-white);
    font-size: 10px;
    font-weight: bold;
    padding: 3px 8px;
    border-radius: 4px;
    text-transform: uppercase;
}

/* Image Container */
.mg-card-image-wrapper {
    width: 100%;
    height: 110px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 12px;
}

.mg-card-image {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    transition: transform 0.3s ease;
}

.mg-vehicle-card:hover .mg-card-image {
    transform: scale(1.05);
}

/* Card Body */
.mg-card-title {
    font-size: 15px;
    font-weight: 700;
    color: var(--mg-text-dark);
    margin-bottom: 6px;
    text-transform: uppercase;
}

.mg-card-price {
    font-size: 14px;
    color: var(--mg-text-muted);
    margin-bottom: 15px;
}

/* Card Footer Action Buttons */
.mg-card-actions {
    display: flex;
    gap: 8px;
    margin-top: auto;
}

.mg-card-btn {
    flex: 1;
    padding: 8px 12px;
    border-radius: 20px;
    border: 1px solid var(--mg-black);
    background-color: var(--mg-white);
    color: var(--mg-black);
    font-size: 12px;
    font-weight: 600;
    text-decoration: none;
    text-align: center;
    cursor: pointer;
    transition: all 0.25s ease;
}

.mg-card-btn:hover {
    background-color: var(--mg-black);
    color: var(--mg-white);
}

/* Right Column: Featured Panel */
.mg-megamenu-featured-col {
    width: 30%;
    padding: 40px;
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    align-items: center;
    background-color: var(--mg-white);
}

.mg-featured-container {
    width: 100%;
    max-width: 300px;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    opacity: 1;
    transition: opacity 0.2s ease-in-out;
}

.mg-featured-container.fade-out {
    opacity: 0;
}

.mg-featured-image-wrapper {
    width: 100%;
    height: 180px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 25px;
}

.mg-featured-image {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
}

.mg-featured-title {
    font-size: 20px;
    font-weight: 700;
    color: var(--mg-text-dark);
    margin-bottom: 10px;
    text-transform: uppercase;
}

.mg-featured-price {
    font-size: 18px;
    color: var(--mg-text-muted);
    margin-bottom: 30px;
}

.mg-featured-actions {
    display: flex;
    gap: 12px;
    width: 100%;
    justify-content: center;
}

.mg-featured-actions .mg-card-btn {
    padding: 10px 24px;
    font-size: 13px;
    flex: 0 1 auto;
    min-width: 120px;
}

/* Desktop Defaults for Mobile-Only Elements */
.mg-chevron-right,
.mg-mobile-nav-header,
.mg-mobile-drawer-buttons {
    display: none !important;
}

/* Mobile Toggle Styles */
.mg-mobile-toggle {
    display: none;
    flex-direction: column;
    justify-content: space-between;
    width: 24px;
    height: 18px;
    background: transparent;
    border: none;
    cursor: pointer;
    z-index: 100000;
}

.mg-mobile-toggle span {
    display: block;
    width: 100%;
    height: 2px;
    background-color: var(--mg-white);
    transition: all 0.3s ease;
}

/* ==========================================================================
   Full-Screen Mobile Menu Overlay (@media (max-width: 1024px))
   ========================================================================== */
body.mg-menu-open {
    overflow: hidden !important;
    position: fixed !important;
    width: 100% !important;
    height: 100% !important;
}

@media (max-width: 1024px) {
    /* Header Base Alignment & Dimensions */
    .mg-custom-header {
        position: relative !important;
        z-index: 99999999 !important;
        background-color: #000000 !important;
    }

    .mg-header-container {
        padding: 0 20px !important;
        height: 80px !important;
        background-color: #000000 !important;
        border-bottom: 1px solid rgba(255, 255, 255, 0.08) !important;
        display: flex !important;
        align-items: center !important;
        justify-content: space-between !important;
    }

    .mg-logo-wrapper {
        display: flex !important;
        align-items: center !important;
        margin-right: auto !important;
    }

    .mg-logo {
        height: 53px !important;
        width: auto !important;
    }

    /* Mobile toggle hamburger */
    .mg-mobile-toggle {
        display: flex !important;
        flex-direction: column !important;
        justify-content: space-between !important;
        width: 24px !important;
        height: 18px !important;
        background: transparent !important;
        border: none !important;
        cursor: pointer !important;
        z-index: 1000001 !important;
        padding: 0 !important;
        margin-left: auto !important;
    }

    .mg-mobile-toggle span {
        display: block !important;
        width: 100% !important;
        height: 2px !important;
        background-color: var(--mg-white) !important;
        border-radius: 2px !important;
        transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1) !important;
    }

    /* Hide top header buttons on mobile (they move into the drawer) */
    .mg-header-buttons > .mg-btn {
        display: none !important;
    }

    /* Full-Screen Mobile Navigation Overlay (Pitch Black #000000) */
    .mg-main-nav {
        position: fixed !important;
        top: 0 !important;
        left: -100% !important;
        width: 100vw !important;
        height: 100vh !important;
        background-color: #000000 !important;
        flex-direction: column !important;
        align-items: flex-start !important;
        padding: 0 !important;
        margin: 0 !important;
        transition: left 0.35s cubic-bezier(0.4, 0, 0.2, 1) !important;
        overflow-y: auto !important;
        z-index: 99999999 !important;
    }

    .mg-main-nav.active {
        left: 0 !important;
    }

    /* Top Bar inside Mobile Full Screen Overlay */
    .mg-mobile-nav-header {
        display: flex !important;
        align-items: center !important;
        justify-content: space-between !important;
        width: 100% !important;
        height: 80px !important;
        padding: 0 24px !important;
        background-color: #000000 !important;
        border-bottom: 1px solid rgba(255, 255, 255, 0.1) !important;
        flex-shrink: 0 !important;
    }

    .mg-mobile-logo {
        height: 53px !important;
        width: auto !important;
    }

    .mg-mobile-close-btn {
        background: transparent !important;
        border: none !important;
        cursor: pointer !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
        padding: 4px !important;
        color: #ffffff !important;
    }

    /* Mobile Menu List */
    .mg-menu-list {
        flex-direction: column !important;
        align-items: flex-start !important;
        width: 100% !important;
        height: auto !important;
        padding: 10px 0 !important;
        margin: 0 !important;
    }

    .mg-menu-item {
        width: 100% !important;
        height: auto !important;
        flex-direction: column !important;
        align-items: flex-start !important;
        padding: 20px 0px !important;
    }

    /* Menu Link Row: Generous vertical padding & Text on left, > chevron icon on right */
    .mg-menu-link {
        display: flex !important;
        align-items: center !important;
        justify-content: space-between !important;
        width: 100% !important;
        padding: 22px 24px !important;
        color: #ffffff !important;
        font-size: 18px !important;
        font-weight: 500 !important;
        text-decoration: none !important;
        border: none !important;
        background: transparent !important;
        line-height: 1.2 !important;
    }

    .mg-arrow-down {
        display: none !important;
    }

    .mg-chevron-right {
        display: flex !important;
        align-items: center !important;
        color: #ffffff !important;
        opacity: 0.9 !important;
        transition: transform 0.25s ease !important;
    }

    .mg-menu-item.open > .mg-menu-link .mg-chevron-right {
        transform: rotate(90deg) !important;
    }

    /* Conventional Dropdown Menu Accordion inside Mobile Drawer (List format matching image) */
    .mg-has-dropdown {
        position: relative !important;
        width: 100% !important;
        z-index: 2000 !important;
    }

    .mg-dropdown-menu {
        position: static !important;
        width: 100% !important;
        display: none; /* Toggled by JS slideToggle */
        background-color: #000000 !important;
        box-shadow: none !important;
        border: none !important;
        padding: 0 !important;
        margin: 0 !important;
        border-radius: 0 !important;
        flex-direction: column !important;
    }

    .mg-dropdown-item {
        width: 100% !important;
        display: block !important;
        margin: 0 !important;
        padding: 0 !important;
        border-top: 1px solid rgba(255, 255, 255, 0.15) !important;
    }

    .mg-dropdown-item:last-child {
        border-bottom: 1px solid rgba(255, 255, 255, 0.15) !important;
    }

    .mg-dropdown-item a {
        display: block !important;
        padding: 18px 24px !important;
        color: #ffffff !important;
        font-size: 15px !important;
        font-weight: 700 !important;
        text-transform: uppercase !important;
        text-decoration: none !important;
        background-color: #000000 !important;
        letter-spacing: 0.5px !important;
        line-height: 1.2 !important;
        transition: background-color 0.2s ease !important;
    }

    .mg-dropdown-item a:hover {
        background-color: rgba(255, 255, 255, 0.08) !important;
    }

    /* Mobile Megamenu Panel Accordion */
    .mg-megamenu-panel {
        position: static !important;
        width: 100% !important;
        opacity: 1 !important;
        visibility: visible !important;
        transform: none !important;
        box-shadow: none !important;
        border-top: 1px solid rgba(255, 255, 255, 0.08) !important;
        display: none; /* Toggled via JS slideToggle */
        pointer-events: auto !important;
        background-color: #0a0a0a !important;
    }

    /* Category filter horizontal scroll pills on mobile */
    .mg-megamenu-filters {
        padding: 12px 16px !important;
        background-color: #121212 !important;
        border-bottom: 1px solid rgba(255, 255, 255, 0.08) !important;
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch !important;
    }

    .mg-filters-wrapper {
        display: flex !important;
        gap: 8px !important;
        flex-wrap: nowrap !important;
        width: max-content !important;
    }

    .mg-filter-btn {
        flex: 0 0 auto !important;
        padding: 8px 18px !important;
        font-size: 13px !important;
        font-weight: 500 !important;
        border-radius: 20px !important;
        white-space: nowrap !important;
        background: rgba(255, 255, 255, 0.08) !important;
        color: #ffffff !important;
        border: 1px solid rgba(255, 255, 255, 0.15) !important;
    }

    .mg-filter-btn.active {
        background-color: #ffffff !important;
        color: #000000 !important;
        border-color: #ffffff !important;
    }

    .mg-megamenu-content {
        flex-direction: column !important;
        min-height: auto !important;
        background-color: #0a0a0a !important;
    }

    .mg-megamenu-grid-col {
        width: 100% !important;
        padding: 12px !important;
        border: none !important;
    }

    /* FORCED 2 Vehicles Side-by-Side per row on Mobile */
    .mg-vehicles-grid {
        display: grid !important;
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 10px !important;
        max-height: none !important;
        overflow: visible !important;
        padding: 4px !important;
        box-sizing: border-box !important;
    }

    /* Compact Vehicle Cards for Mobile 2-column view */
    .mg-vehicle-card {
        padding: 10px 8px !important;
        border-radius: 10px !important;
        background: #ffffff !important;
        box-shadow: 0 4px 12px rgba(0,0,0,0.3) !important;
        display: flex !important;
        flex-direction: column !important;
        box-sizing: border-box !important;
    }

    .mg-card-header {
        margin-bottom: 4px !important;
        min-height: 18px !important;
    }

    .mg-fuel-tag {
        font-size: 10px !important;
        font-weight: 600 !important;
    }

    .mg-fuel-icon {
        width: 10px !important;
        height: 10px !important;
    }

    .mg-badge-new {
        font-size: 9px !important;
        padding: 2px 5px !important;
        border-radius: 3px !important;
    }

    .mg-card-image-wrapper {
        height: 75px !important;
        margin-bottom: 6px !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
    }

    .mg-card-image {
        max-width: 100% !important;
        max-height: 100% !important;
        object-fit: contain !important;
    }

    .mg-card-title {
        font-size: 13px !important;
        font-weight: 700 !important;
        color: #111111 !important;
        margin-bottom: 3px !important;
        line-height: 1.2 !important;
        text-transform: uppercase !important;
    }

    .mg-card-price {
        font-size: 11px !important;
        color: #666666 !important;
        margin-bottom: 8px !important;
        line-height: 1.2 !important;
    }

    .mg-card-actions {
        gap: 4px !important;
        margin-top: auto !important;
        display: flex !important;
    }

    .mg-card-btn {
        padding: 6px 2px !important;
        font-size: 11px !important;
        border-radius: 16px !important;
        text-align: center !important;
        flex: 1 !important;
    }

    /* Hide right featured preview column on mobile to save vertical space */
    .mg-megamenu-featured-col {
        display: none !important;
    }

    /* Mobile CTA buttons block at bottom of overlay */
    .mg-mobile-drawer-buttons {
        display: flex !important;
        flex-direction: column !important;
        gap: 10px !important;
        width: 100% !important;
        padding: 20px !important;
        margin-top: 10px !important;
    }

    .mg-mobile-drawer-buttons .mg-btn {
        width: 100% !important;
        text-align: center !important;
        height: 48px !important;
    }
}

/* --- Divi Theme Builder Overflow & Full-Width Header Patch --- */
div[class*="_tb_header"],
div[class*="_tb_header"] .et_pb_row,
div[class*="_tb_header"] .et_pb_column,
div[class*="_tb_header"] .et_pb_module,
div[class*="_tb_header"] .et_pb_code,
.et_pb_section_header .et_pb_row {
    overflow: visible !important;
    width: 100% !important;
    max-width: 100% !important;
    padding-left: 0 !important;
    padding-right: 0 !important;
    margin-left: 0 !important;
    margin-right: 0 !important;
}

.mg-custom-header {
    width: 100% !important;
    max-width: 100% !important;
    z-index: 9999999 !important;
}

.mg-megamenu-panel {
    z-index: 99999999 !important;
}
