/**
 * DeWonder Mobile Menu - Frontend Styles
 * All classes use dwmm- prefix to avoid conflicts
 */

/* Container - just holds the hamburger, minimal layout impact */
.dwmm-container {
    position: relative;
    box-sizing: border-box;
    display: inline-block; /* Don't take full width, minimize layout impact */
}

/* Backdrop when menu is open */
.dwmm-container::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
    z-index: 99998;
    pointer-events: none;
}

.dwmm-container.menu-open::before {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
}

/* Toggle Button - with !important to override theme conflicts */
.dwmm-container .dwmm-toggle {
    position: relative;
    z-index: 100000; /* Above the menu content (99999) */
    display: flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    padding: 0;
    margin: 0;
    background: transparent !important;
    background-color: transparent !important;
    border: none !important;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    box-sizing: border-box;
}

/* Reposition toggle as close button when menu is open */
.dwmm-container.menu-open .dwmm-toggle {
    position: fixed;
    top: 10px;
    left: 10px;
    margin: 0;
}

.dwmm-toggle:focus {
    outline: none;
}

/* 3-line Hamburger Icon */
.dwmm-icon-menu {
    display: block;
    width: 24px;
    height: 2px;
    background: #000;  /* Middle line */
    position: relative;
    transition: background 0.3s ease;
}

.dwmm-icon-menu::before,
.dwmm-icon-menu::after {
    content: '';
    display: block;
    width: 24px;
    height: 2px;
    background: #000;
    position: absolute;
    left: 0;
    transition: transform 0.3s ease, top 0.3s ease, bottom 0.3s ease;
}

.dwmm-icon-menu::before {
    top: -8px;  /* Top line */
}

.dwmm-icon-menu::after {
    bottom: -8px;  /* Bottom line */
}

/* X Icon state when menu is open */
.dwmm-toggle[aria-expanded="true"] .dwmm-icon-menu {
    background: transparent;  /* Hide middle line */
}

.dwmm-toggle[aria-expanded="true"] .dwmm-icon-menu::before {
    top: 0;  /* Move to center */
    transform: rotate(45deg);
}

.dwmm-toggle[aria-expanded="true"] .dwmm-icon-menu::after {
    bottom: 0;  /* Move to center */
    transform: rotate(-45deg);
}

/* Content wrapper - fixed overlay, slides from left */
.dwmm-content {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    width: 100% !important;
    max-width: 400px !important;
    height: 100vh !important;
    display: flex !important;
    gap: 0;
    background: #fff;
    z-index: 99999 !important;
    box-shadow: 2px 0 10px rgba(0, 0, 0, 0.1);
    transform: translateX(0);
    transition: transform 0.3s ease, visibility 0.3s ease;
    overflow: hidden;
}

/* Hidden state - completely remove from layout to prevent content push */
.dwmm-content.dwmm-hidden {
    display: none !important;
}

/* Left navigation column */
.dwmm-nav {
    width: 130px;
    flex-shrink: 0;
    background: #f8f8f8;
    overflow-y: auto;
    border-right: 1px solid #e1e1e1;
    height: 100%;
    padding-top: 60px; /* Space for close button */
}

/* Navigation item - container only, no padding here */
.dwmm-nav-item {
    font-size: 13px;
    font-weight: 500;
    text-transform: uppercase;
    cursor: pointer;
    border-bottom: 1px solid #e1e1e1;
    color: #000;
    transition: color 0.2s ease;
    position: relative;
    -webkit-tap-highlight-color: transparent;
}

/* Navigation header - THIS gets the padding, contains text + arrow */
.dwmm-nav-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 5px;
    padding: 12px 10px; /* Padding moved here from .dwmm-nav-item */
    transition: background-color 0.2s ease;
}

.dwmm-nav-item:hover .dwmm-nav-header {
    background-color: #f0f0f0;
}

.dwmm-nav-item.active {
    color: #000; /* Keep font black when active */
    font-weight: 600;
}

.dwmm-nav-item.active .dwmm-nav-header {
    background-color: #fff;
    border-left: 4px solid #000; /* Black line on left side */
    padding-left: 6px; /* Adjust padding to compensate for border */
}

/* Navigation text */
.dwmm-nav-text {
    display: block;
    flex: 1;
}

/* Navigation arrow for parent items - container with proper dimensions for rotation */
.dwmm-nav-arrow {
    flex-shrink: 0;
    width: 8px;
    height: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s ease;
}

/* Triangle shape via ::before - rotates around container center */
.dwmm-nav-arrow::before {
    content: '';
    display: block;
    width: 0;
    height: 0;
    border-left: 4px solid transparent;
    border-right: 4px solid transparent;
    border-top: 5px solid #666;
}

.dwmm-nav-parent.expanded .dwmm-nav-arrow {
    transform: rotate(180deg);
}

/* Navigation children container - appears below parent in nav column */
.dwmm-nav-children {
    display: none;
    padding-left: 5px;
    padding-bottom: 8px;
    background: transparent;
}

.dwmm-nav-parent.expanded .dwmm-nav-children {
    display: block !important;
}

/* Child items styling */
.dwmm-nav-child {
    padding: 8px 10px;
    font-size: 13px;
    font-weight: 400;
    text-transform: capitalize;
    color: #555;
    cursor: pointer;
    transition: color 0.2s ease, background-color 0.2s ease;
    border-left: 2px solid transparent;
}

.dwmm-nav-child:hover {
    color: #000;
    background-color: rgba(0, 0, 0, 0.05);
}

.dwmm-nav-child.active {
    color: #000;
    font-weight: 500;
    border-left-color: #000;
}

/* Hidden state for menu grid (legacy, kept for backwards compatibility) */
.dwmm-grid.dwmm-hidden {
    max-height: 0;
    overflow: hidden;
    opacity: 0;
    visibility: hidden;
}

/* Grid layout using flexbox */
.dwmm-grid {
    flex: 1;
    display: flex;
    flex-wrap: wrap;
    align-content: flex-start;
    gap: var(--dwmm-gap, 10px);
    margin: 0;
    padding: 60px 10px 10px 10px; /* Top padding for close button */
    list-style: none;
    overflow-y: auto;
    scroll-behavior: smooth;
    height: 100%;
}

/* Individual item - base styles */
.dwmm-item {
    box-sizing: border-box;
}

/* Width-specific calculations for proper gap handling */
/* 1/2 width (2 items/row): subtract gap/2 */
.dwmm-item[style*="--dwmm-width: 50%"] {
    flex: 0 0 calc(50% - var(--dwmm-gap, 10px) / 2);
    max-width: calc(50% - var(--dwmm-gap, 10px) / 2);
}

/* 1/3 width (3 items/row): subtract gap*2/3 */
.dwmm-item[style*="--dwmm-width: 33.33%"] {
    flex: 0 0 calc(33.33% - var(--dwmm-gap, 10px) * 2 / 3);
    max-width: calc(33.33% - var(--dwmm-gap, 10px) * 2 / 3);
}

/* 1/4 width (4 items/row): subtract gap*3/4 */
.dwmm-item[style*="--dwmm-width: 25%"] {
    flex: 0 0 calc(25% - var(--dwmm-gap, 10px) * 3 / 4);
    max-width: calc(25% - var(--dwmm-gap, 10px) * 3 / 4);
}

/* 2/3 width: subtract gap/3 */
.dwmm-item[style*="--dwmm-width: 66.66%"] {
    flex: 0 0 calc(66.66% - var(--dwmm-gap, 10px) / 3);
    max-width: calc(66.66% - var(--dwmm-gap, 10px) / 3);
}

/* 3/4 width: subtract gap/4 */
.dwmm-item[style*="--dwmm-width: 75%"] {
    flex: 0 0 calc(75% - var(--dwmm-gap, 10px) / 4);
    max-width: calc(75% - var(--dwmm-gap, 10px) / 4);
}

/* 100% width: no gap subtraction */
.dwmm-item[style*="--dwmm-width: 100%"] {
    flex: 0 0 100%;
    max-width: 100%;
}

/* Link wrapper */
.dwmm-link {
    display: block;
    text-decoration: none;
    color: inherit;
    transition: opacity 0.3s ease;
}

.dwmm-link:hover {
    opacity: 0.9;
}

.dwmm-link:focus {
    outline: 2px solid #000;
    outline-offset: 2px;
}

/* Image wrapper with aspect ratio */
.dwmm-image-wrapper {
    position: relative;
    width: 100%;
    aspect-ratio: var(--dwmm-aspect-ratio, 1);
    overflow: hidden;
    background-color: #f5f5f5;
}

/* Fallback for browsers that don't support aspect-ratio */
@supports not (aspect-ratio: 1) {
    .dwmm-image-wrapper {
        height: 0;
        padding-bottom: calc(100% / var(--dwmm-aspect-ratio, 1));
    }

    .dwmm-image-wrapper .dwmm-image {
        position: absolute;
        top: 0;
        left: 0;
    }
}

/* Image */
.dwmm-image {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    transition: transform 0.3s ease;
}

.dwmm-link:hover .dwmm-image {
    transform: scale(1.02);
}

/* Title section */
.dwmm-title {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 0;
    font-size: 14px;
    font-weight: 500;
    color: #000;
    line-height: 1.4;
}

/* Title text */
.dwmm-title-text {
    flex: 1;
}

/* Arrow */
.dwmm-arrow {
    flex-shrink: 0;
    margin-left: 8px;
    font-size: 14px;
    transition: transform 0.3s ease;
}

.dwmm-link:hover .dwmm-arrow {
    transform: translateX(3px);
}

/* Section header (full-width text divider in grid) */
.dwmm-section-header {
    flex: 0 0 100%;
    width: 100%;
    font-size: 14px;
    font-weight: 600;
    color: #333;
    padding: 15px 0 8px 0;
    margin: 0;
    box-sizing: border-box;
}

.dwmm-section-header:first-child {
    padding-top: 5px;
}

/* Section header link */
.dwmm-section-link {
    display: flex;
    align-items: center;
    text-decoration: none;
    color: inherit;
    transition: opacity 0.2s ease;
}

.dwmm-section-link:hover {
    opacity: 0.7;
}

.dwmm-section-text {
    flex: 1;
}

.dwmm-section-arrow {
    margin-left: 5px;
    transition: transform 0.2s ease;
}

.dwmm-section-link:hover .dwmm-section-arrow {
    transform: translateX(3px);
}

/* Responsive breakpoints - removed min 50% constraint to respect user-set widths */

@media screen and (max-width: 480px) {
    .dwmm-nav {
        width: 110px;
    }

    .dwmm-nav-item {
        font-size: 12px;
    }

    .dwmm-nav-header {
        padding: 10px 8px;
    }

    .dwmm-nav-item.active .dwmm-nav-header {
        padding-left: 4px; /* Adjust for border on small screens */
    }

    .dwmm-nav-child {
        padding: 6px 8px;
        font-size: 12px;
    }

    .dwmm-grid {
        gap: calc(var(--dwmm-gap, 10px) * 0.8);
        padding: 60px 8px 8px 8px; /* Top padding for close button */
    }

    .dwmm-title {
        padding: 10px 0;
        font-size: 13px;
    }
}

/* Print styles */
@media print {
    .dwmm-container {
        page-break-inside: avoid;
    }

    .dwmm-link:hover .dwmm-image {
        transform: none;
    }
}
