/*
 * Mw Attribute Drawer
 *
 * @author    Felipe Maya <maya@mayaweb.es>
 * @copyright 2026 Felipe Maya
 * @license   Commercial
 */
/* Mw Attribute Drawer CSS */

/* Variables */
:root {
    --mw-drawer-width: 400px;
    --mw-drawer-bg: #ffffff;
    --mw-drawer-overlay: rgba(0, 0, 0, 0.5);
    --mw-primary-color: #000000;
    --mw-border-color: #e0e0e0;
    --mw-selected-border: #000000;
}

/* 1. Trigger Buttons */
/* Main Wrapper - Hidden by default to prevent FOUC/Flicker */
.mw-attribute-triggers {
    display: none !important;
    /* Hidden until JS moves it */
    margin-top: 1rem;
    margin-bottom: 1rem;
}

/* Visible state - applied by JS after correct positioning */
.mw-attribute-triggers.mw-ready {
    display: flex !important;
    /* Use flex when ready */
    flex-direction: column;
    gap: 15px;
    animation: mwFadeIn 0.2s ease-in-out;
}

@keyframes mwFadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

.mw-drawer-trigger {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px 20px;
    border: 1px solid var(--mw-border-color);
    background: #fff;
    cursor: pointer;
    transition: all 0.2s ease;
    border-radius: 4px;
}

.mw-drawer-trigger:hover {
    border-color: var(--mw-primary-color);
}

.mw-trigger-label {
    font-weight: 600;
    font-size: 14px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.mw-trigger-value {
    color: #666;
    font-size: 14px;
    display: flex;
    align-items: center;
    gap: 10px;
}

.mw-trigger-preview-color {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    border: 1px solid #ddd;
    display: inline-block;
}

.mw-trigger-text {
    line-height: 20px;
}

/* 2. Drawer (Modal) */
#mw-attribute-drawer {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100vh;
    z-index: 99999;
    visibility: hidden;
    pointer-events: none;
    /* Let clicks pass through when closed */
    transition: visibility 0.3s;
}

#mw-attribute-drawer.is-open {
    visibility: visible;
}

.mw-drawer-open-body {
    overflow: hidden;
}

/* Overlay */
.mw-drawer-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--mw-drawer-overlay);
    opacity: 0;
    transition: opacity 0.3s;
    backdrop-filter: blur(2px);
    pointer-events: auto;
    /* Block clicks when open */
    cursor: pointer;
}

#mw-attribute-drawer.is-open .mw-drawer-overlay {
    opacity: 1;
}

/* Sidebar */
.mw-drawer-container {
    position: absolute;
    top: 0;
    right: -100%;
    /* Start off-screen */
    width: var(--mw-drawer-width);
    max-width: 85%;
    height: 100%;
    background: var(--mw-drawer-bg);
    box-shadow: -5px 0 15px rgba(0, 0, 0, 0.1);
    display: flex;
    flex-direction: column;
    z-index: 10000;
    pointer-events: auto;
    transition: right 0.3s ease;
    /* Only the sidebar slides */
}

#mw-attribute-drawer.is-open .mw-drawer-container {
    right: 0;
}

/* Custom Tabs Container */
.mw-custom-tab-triggers {
    display: flex;
    flex-direction: column;
    gap: 15px;
    margin-top: 15px;
}

/* Allow Custom Triggers to be visible immediately as they are injected separately */
.mw-custom-tab-triggers.mw-ready {
    animation: mwFadeIn 0.2s ease-in-out;
}

/* Header */
.mw-drawer-header {
    padding: 20px;
    border-bottom: 1px solid var(--mw-border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.mw-drawer-title {
    font-weight: 700;
    font-size: 16px;
    margin: 0;
    text-transform: uppercase;
}

.mw-drawer-close {
    background: none;
    border: none;
    font-size: 28px;
    cursor: pointer;
    line-height: 1;
    padding: 0 10px;
    color: #000;
}

/* Content Area */
.mw-drawer-body {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
}

/* GRID LAYOUTS */
/* Default Grid (for Colors/Textures) */
.mw-attribute-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 15px;
}

@media (min-width: 768px) {
    .mw-attribute-grid {
        grid-template-columns: repeat(3, 1fr);
    }
}

/* Groups that are NOT color/radio (Text Only) - List View (1 column) */
.mw-group-type-select .mw-attribute-grid {
    grid-template-columns: 1fr;
    gap: 10px;
}

/* Attribute Option Card */
.mw-attribute-option {
    border: 1px solid var(--mw-border-color);
    cursor: pointer;
    transition: border-color 0.2s;
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    overflow: hidden;
    border-radius: 4px;
    background: #fff;
}

/* Layout for List View items (Text only) */
.mw-group-type-select .mw-attribute-option {
    flex-direction: row;
    /* Horizontal layout */
    justify-content: space-between;
    align-items: center;
    padding: 15px;
    min-height: auto;
}

.mw-attribute-option:hover {
    border-color: #999;
}

.mw-attribute-option.selected {
    border: 2px solid var(--mw-selected-border);
}

/* Check Icon */
.mw-attribute-option.selected::after {
    content: '✔';
    position: absolute;
    top: 5px;
    right: 5px;
    background: #000;
    color: #fff;
    border-radius: 50%;
    width: 20px;
    height: 20px;
    font-size: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 5;
}

/* For List View, check icon position update */
.mw-group-type-select .mw-attribute-option.selected::after {
    top: 50%;
    transform: translateY(-50%);
    right: 15px;
}

/* Media (Images/Colors) */
.mw-option-media {
    width: 100%;
    height: 120px;
    /* Taller for better visibility */
    display: flex;
    position: relative;
    padding: 0;
    /* Remove padding */
    margin: 0;
}

.mw-option-media img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    /* Fill the box */
    display: block;
}

/* Color Fill */
.mw-option-color-fill {
    width: 100%;
    height: 100%;
    display: block;
    min-height: 100px;
    /* Ensure it has height */
}

/* Text Handling */
.mw-option-name {
    font-size: 13px;
    font-weight: 600;
    padding: 10px;
    width: 100%;
}

.mw-group-type-select .mw-option-name {
    padding: 0;
    text-align: left;
    font-size: 14px;
    flex: 1;
}

.mw-option-price {
    font-size: 12px;
    color: #888;
    padding-bottom: 10px;
}

.mw-group-type-select .mw-option-price {
    padding: 0;
    margin-left: auto;
    /* Push to right */
    margin-right: 30px;
    /* Space for checkmark */
}

/* Hiding Native Variants - Aggressive */
.product-variants,
#product-variants {
    display: none !important;
    opacity: 0 !important;
    visibility: hidden !important;
    height: 0 !important;
    overflow: hidden !important;
    pointer-events: none !important;
}

/* Ensure our triggers are visible */
.mw-attribute-triggers {
    display: flex !important;
    visibility: visible !important;
    opacity: 1 !important;
}

/* =========================================
   MOBILE BOTTOM SHEET (< 768px)
   ========================================= */
@media (max-width: 768px) {
    .mw-drawer-container {
        top: auto;
        bottom: 0;
        right: 0;
        left: 0;
        /* Span full width */
        width: 100%;
        max-width: 100%;
        height: auto;
        max-height: 85vh;
        /* Allow scrolling within sheet, don't cover header */
        border-radius: 20px 20px 0 0;
        /* Rounded top corners */
        transform: translateY(100%);
        /* Start hidden below screen */
        transition: transform 0.3s cubic-bezier(0.1, 0.7, 0.1, 1);
        /* Smooth spring-like eased slide */
    }

    #mw-attribute-drawer.is-open .mw-drawer-container {
        right: 0;
        /* Keep anchored */
        transform: translateY(0);
        /* Slide up */
    }

    /* Optional: Center title on mobile for better aesthetics */
    .mw-drawer-header {
        justify-content: center;
        position: relative;
    }

    .mw-drawer-title {
        text-align: center;
    }

    .mw-drawer-close {
        position: absolute;
        right: 20px;
        top: 50%;
        transform: translateY(-50%);
        padding: 0;
    }
}