/**
 * Product Category Sliding Menu Styles
 * Version: 2.0.0
 */

:root {
    --pcsm-animation-duration: 0.3s;
}

/* Container Styles */
.pcsm-menu-container {
    position: relative;
    max-width: 100%;
    background: var(--pcsm-menu-bg, #ffffff);
    border: 1px solid #e1e5e9;
    border-radius: 8px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    overflow: hidden;
    font-family: inherit;
}

.pcsm-menu-wrapper {
    position: relative;
    overflow: hidden;
    width: 100%;
    background: inherit;
}

/* Panel System - Each level is a separate panel */
.pcsm-panel {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    z-index: 1;
    transition: transform var(--pcsm-animation-duration) cubic-bezier(0.4, 0, 0.2, 1);
    background: var(--pcsm-panel-bg, var(--pcsm-menu-bg, #ffffff));
}

.pcsm-panel.pcsm-main {
    position: relative;
    transform: translateX(0);
}

.pcsm-panel.pcsm-sub {
    transform: translateX(100%);
}

.pcsm-panel.pcsm-active {
    transform: translateX(0);
    z-index: 2;
}

.pcsm-panel.pcsm-shifted-left {
    transform: translateX(-100%);
}

/* Menu Lists - Ensure consistent styling for all panels */
.pcsm-panel .pcsm-menu {
    list-style: none;
    margin: 0;
    padding: 0;
    background: var(--pcsm-panel-bg, var(--pcsm-menu-bg, #ffffff));
}

/* Menu Item Styles - Apply to all menu items in all panels */
.pcsm-panel .pcsm-menu-item {
    position: relative;
    border-bottom: 1px solid #f0f0f0;
    transition: background-color 0.2s ease;
    background: var(--pcsm-panel-bg, var(--pcsm-menu-bg, #ffffff));
}

.pcsm-panel .pcsm-menu-item:last-child {
    border-bottom: none;
}

.pcsm-panel .pcsm-menu-item:hover {
    background-color: #f8f9fa;
}

/* Category Link Styles - Apply to all panels */
.pcsm-panel .pcsm-category-link {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px 50px;
    text-decoration: none;
    color: #333333;
    font-size: 14px;
    font-weight: 500;
    transition: all 0.2s ease;
    cursor: pointer;
    position: relative;
}

.pcsm-panel .pcsm-category-link:hover {
    color: #007cba;
    text-decoration: none;
}

.pcsm-panel .pcsm-category-link:focus-visible {
    outline: 2px solid #007cba;
    outline-offset: -2px;
}

/* Category Name - Apply to all panels */
.pcsm-panel .pcsm-category-name {
    text-align: center;
}

/* For items without toggle buttons, use equal padding for perfect centering */
.pcsm-panel .pcsm-menu-item:not(.pcsm-has-children) .pcsm-category-link {
    padding: 16px 20px;
}

/* Product Count - Apply to all panels (now inline with category name) */
.pcsm-panel .pcsm-category-count {
    color: #666666;
    font-size: 12px;
    font-weight: 400;
    margin-left: 4px;
    display: inline;
}

/* Toggle Button - Apply to all panels */
.pcsm-panel .pcsm-toggle-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    color: #666666;
    transition: color 0.2s ease, transform var(--pcsm-animation-duration) ease;
    position: absolute;
    right: 20px;
    top: 50%;
    transform: translateY(-50%);
}

.pcsm-panel .pcsm-has-children .pcsm-category-link:hover .pcsm-toggle-btn {
    color: #007cba;
    transform: translateY(-50%) scale(1.1);
}

/* Arrow Icon - Apply to all panels */
.pcsm-panel .pcsm-arrow {
    display: block;
    width: 6px;
    height: 6px;
    border: 2px solid currentColor;
    border-left: none;
    border-bottom: none;
    transform: rotate(45deg);
    transition: transform var(--pcsm-animation-duration) ease;
}

/* Back Button */
.pcsm-back-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px 20px;
    background: #f8f9fa;
    border: none;
    border-bottom: 1px solid #e1e5e9;
    width: 100%;
    text-align: center;
    color: #007cba;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: background-color 0.2s ease;
}

.pcsm-back-btn:hover {
    background-color: #e9ecef;
}

.pcsm-back-arrow {
    display: inline-block;
    width: 6px;
    height: 6px;
    border: 2px solid currentColor;
    border-right: none;
    border-bottom: none;
    transform: rotate(315deg);
    margin-right: 8px;
    vertical-align: middle;
}

.pcsm-back-text {
    display: inline-block;
    vertical-align: middle;
}

/* Sub-panel header: compact back + title */
.pcsm-panel-header {
    display: flex;
    align-items: center;
    background: #f8f9fa;
    border-bottom: 1px solid #e1e5e9;
    padding: 0;
}

.pcsm-panel .pcsm-panel-header:hover {
    background-color: #f8f9fa;
}

.pcsm-header-back-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 48px;
    min-height: 48px;
    background: none;
    border: none;
    border-right: 1px solid #e1e5e9;
    color: #007cba;
    cursor: pointer;
    transition: background-color 0.2s ease;
    flex-shrink: 0;
}

.pcsm-header-back-btn:hover {
    background-color: #e9ecef;
}

.pcsm-panel-title {
    flex: 1;
    padding: 12px 16px;
    font-weight: 600;
    font-size: 14px;
    color: #333333;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.pcsm-back-item-bottom {
    border-top: 1px solid #e1e5e9;
    border-bottom: none !important;
}

.pcsm-menu-item.pcsm-loading-item {
    border-bottom: none;
}

.pcsm-menu-item.pcsm-loading-item .pcsm-loading-content {
    width: 100%;
}

.pcsm-menu-item.pcsm-error-item {
    border-bottom: none;
}

.pcsm-menu-item.pcsm-error-item .pcsm-error-content {
    width: 100%;
}

/* Loading States for AJAX */
.pcsm-loading-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px 20px;
    text-align: center;
}

.pcsm-loading-spinner-large {
    display: inline-block;
    width: 32px;
    height: 32px;
    border: 3px solid #f3f3f3;
    border-top: 3px solid #007cba;
    border-radius: 50%;
    animation: pcsm-spin 1s linear infinite;
    margin-bottom: 16px;
}

.pcsm-loading-text {
    color: #666666;
    font-family: inherit;
    font-size: inherit;
    font-weight: inherit;
}

/* Error States for AJAX */
.pcsm-error-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px 20px;
    text-align: center;
}

.pcsm-error-text {
    color: #d32f2f;
    font-size: 14px;
    font-weight: 500;
    margin-bottom: 20px;
}

.pcsm-error-content .pcsm-back-btn {
    background: #f44336;
    color: white;
    border: none;
    border-radius: 4px;
    padding: 10px 16px;
    width: auto;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: background-color 0.2s ease;
}

.pcsm-error-content .pcsm-back-btn:hover {
    background: #d32f2f;
}

@keyframes pcsm-spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Responsive Design */

/* Tablets in portrait / narrow sidebars */
@media (max-width: 1024px) {
    .pcsm-panel .pcsm-category-link {
        padding: 15px 44px;
    }

    .pcsm-panel .pcsm-menu-item:not(.pcsm-has-children) .pcsm-category-link {
        padding: 15px 18px;
    }
}

@media (max-width: 768px) {
    .pcsm-menu-container {
        border-radius: 6px;
    }
    
    .pcsm-panel .pcsm-category-link {
        padding: 14px 16px;
        font-size: 13px;
    }
    
    .pcsm-panel .pcsm-back-btn {
        padding: 14px 16px;
        font-size: 13px;
    }

    .pcsm-panel-title {
        font-size: 13px;
        padding: 10px 14px;
    }

    .pcsm-header-back-btn {
        width: 44px;
        min-height: 44px;
    }
}

/* Small phones -- larger touch targets */
@media (max-width: 480px) {
    .pcsm-menu-container {
        border-radius: 4px;
    }

    .pcsm-panel .pcsm-category-link {
        padding: 16px 14px;
        font-size: 14px;
        min-height: 48px;
    }

    .pcsm-panel .pcsm-menu-item:not(.pcsm-has-children) .pcsm-category-link {
        padding: 16px 14px;
    }

    .pcsm-panel .pcsm-back-btn {
        padding: 16px 14px;
        font-size: 14px;
        min-height: 48px;
    }

    .pcsm-header-back-btn {
        width: 48px;
        min-height: 48px;
    }

    .pcsm-panel .pcsm-toggle-btn {
        right: 14px;
    }
}

/* Dark theme: follows system preference (optional .dark-theme still narrows if you add the class) */
@media (prefers-color-scheme: dark) {
    .pcsm-menu-container,
    .pcsm-menu-container.dark-theme {
        --pcsm-menu-bg: #1e1e1e;
        --pcsm-panel-bg: #1e1e1e;
        background: #1e1e1e;
        border-color: #404040;
    }
    
    .pcsm-panel .pcsm-menu-item {
        border-bottom-color: #404040;
    }
    
    .pcsm-panel .pcsm-menu-item:hover {
        background-color: #2a2a2a;
    }
    
    .pcsm-panel .pcsm-category-link {
        color: #ffffff;
    }
    
    .pcsm-panel .pcsm-category-link:hover {
        color: #4fc3f7;
    }
    
    .pcsm-panel .pcsm-category-count {
        color: #cccccc;
    }
    
    .pcsm-panel .pcsm-toggle-btn {
        color: #cccccc;
    }
    
    .pcsm-panel .pcsm-has-children .pcsm-category-link:hover .pcsm-toggle-btn {
        color: #4fc3f7;
    }
    
    .pcsm-panel .pcsm-back-btn {
        background: #2a2a2a;
        border-bottom-color: #404040;
        color: #4fc3f7;
    }
    
    .pcsm-panel .pcsm-back-btn:hover {
        background-color: #353535;
    }

    .pcsm-panel .pcsm-panel-header,
    .pcsm-panel .pcsm-panel-header:hover {
        background: #2a2a2a;
        border-bottom-color: #404040;
    }

    .pcsm-panel .pcsm-header-back-btn {
        color: #4fc3f7;
        border-right-color: #404040;
    }

    .pcsm-panel .pcsm-header-back-btn:hover {
        background-color: #353535;
    }

    .pcsm-panel .pcsm-panel-title {
        color: #ffffff;
    }

    .pcsm-panel .pcsm-back-item-bottom {
        border-top-color: #404040;
    }
    
    .pcsm-panel .pcsm-submenu {
        background: #1e1e1e !important;
    }
}

/* Animation Classes */
.pcsm-menu-container.pcsm-animating {
    pointer-events: none;
}

.pcsm-menu-container.pcsm-animating * {
    pointer-events: none;
}

/* Loading State */
.pcsm-loading {
    padding: 20px;
    text-align: center;
    color: #666666;
    font-style: italic;
}

/* Error State */
.pcsm-error {
    padding: 20px;
    text-align: center;
    color: #d32f2f;
    background-color: #ffebee;
    border: 1px solid #ffcdd2;
    border-radius: 4px;
}

/* Custom Themes */
.pcsm-menu-container.minimal {
    border: none;
    box-shadow: none;
    border-radius: 0;
}

.pcsm-menu-container.rounded {
    border-radius: 16px;
}

.pcsm-menu-container.shadow-lg {
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.15);
}

/* Accessibility Improvements */
.pcsm-category-link:focus-visible {
    outline: 2px solid #007cba;
    outline-offset: -2px;
}

.pcsm-back-btn:focus-visible {
    outline: 2px solid #007cba;
    outline-offset: -2px;
}

.pcsm-header-back-btn:focus-visible {
    outline: 2px solid #007cba;
    outline-offset: -2px;
}

/* Custom Links and Separator */
.pcsm-menu-item.pcsm-custom-link .pcsm-category-link {
    color: #007cba;
    font-weight: 600;
}

.pcsm-menu-item.pcsm-custom-link:hover .pcsm-category-link {
    color: #00547a;
}

.pcsm-menu-item.pcsm-separator {
    height: 1px;
    background-color: #e1e5e9;
    padding: 0;
    margin: 8px 15px;
    border-bottom: none;
}

.pcsm-menu-item.pcsm-separator:hover {
    background-color: #e1e5e9;
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    .pcsm-menu-container {
        border: 2px solid #000000;
    }
    
    .pcsm-panel .pcsm-menu-item {
        border-bottom: 1px solid #000000;
    }
    
    .pcsm-panel .pcsm-category-link {
        color: #000000;
    }
    
    .pcsm-panel .pcsm-category-link:hover {
        background-color: #000000;
        color: #ffffff;
    }
    
    .pcsm-panel .pcsm-menu-item.pcsm-separator {
        background-color: #000000;
    }

    .pcsm-panel-header {
        border-bottom-color: #000000;
    }

    .pcsm-header-back-btn {
        border-right-color: #000000;
    }

    .pcsm-panel-title {
        color: #000000;
    }

    .pcsm-back-item-bottom {
        border-top-color: #000000;
    }
}

@media (prefers-reduced-motion: reduce) {
    :root {
        --pcsm-animation-duration: 0s;
    }

    .pcsm-panel {
        transition: none;
    }

    .pcsm-loading-spinner-large {
        animation: none;
    }

    .pcsm-panel .pcsm-menu-item {
        transition: none;
    }

    .pcsm-panel .pcsm-category-link {
        transition: none;
    }

    .pcsm-panel .pcsm-toggle-btn {
        transition: none;
    }

    .pcsm-panel .pcsm-arrow {
        transition: none;
    }

    .pcsm-back-btn {
        transition: none;
    }

    .pcsm-header-back-btn {
        transition: none;
    }
}