/**
 * Glassy Variations – Custom WooCommerce Variation Dropdowns
 * 
 * Uses the same Liquid Glass styling as glassy-container module.
 * Reuses --se-lg-btn-* and --se-lg-container-* CSS variables.
 * 
 * @version 1.0.2
 */

/* ============================================
   HIDE NATIVE SELECT IMMEDIATELY
   This runs before JS - no flash of default styling
   ============================================ */

html.se-gv-js body.single-product.se-gv-enabled .variations select,
html.se-gv-js body.single-product.se-gv-enabled form.variations_form .variations select,
body.single-product.se-gv-enabled .se-gv-wrapper.se-gv-enhanced select.se-gv-native-select {
    position: absolute !important;
    opacity: 0 !important;
    pointer-events: none !important;
    width: 1px !important;
    height: 1px !important;
    overflow: hidden !important;
    clip: rect(0, 0, 0, 0) !important;
    white-space: nowrap !important;
    border: 0 !important;
    margin: 0 !important;
    padding: 0 !important;
}

/* ============================================
   DROPDOWN WRAPPER
   ============================================ */

/* Global sizing for split label/value UI (consistent across all dropdowns) */
body.single-product.se-gv-enabled {
    --se-gv-label-width: 220px;
    --se-gv-trigger-pad-left: 14px;
    --se-gv-trigger-pad-right: 8px;
    --se-gv-trigger-pad-x: var(--se-gv-trigger-pad-left);
    --se-gv-trigger-col-gap: 8px;
}

.se-gv-wrapper {
    position: relative;
    display: block;
    width: 100% !important;
    max-width: 100% !important;
    box-sizing: border-box;

}

/* Hide the separate WC label cell; label is rendered inside the trigger */
body.single-product.se-gv-enabled form.variations_form .variations th.label,
body.single-product.se-gv-enabled form.variations_form .variations td.label {
    display: none !important;
}

/* ============================================
   DROPDOWN TRIGGER (closed state button)
   Matches .glassy-btn1 / WooCommerce button styling
   ============================================ */

/* Override global `.glassy-btn1` padding specifically for our dropdown trigger */
body.single-product.se-gv-enabled button.se-gv-trigger.glassy-btn1,
body.single-product.se-gv-enabled .se-gv-trigger {
    display: grid;
    grid-template-columns: var(--se-gv-label-width, 220px) 1fr auto;
    align-items: center;
    column-gap: var(--se-gv-trigger-col-gap, 10px);
    width: 100%;
    min-height: 50px;
    padding: 0 var(--se-gv-trigger-pad-right, 4px) 0 var(--se-gv-trigger-pad-left, 14px) !important;
    text-align: left !important;
    
    /* Glass effect - same as glassy buttons */
    background: var(--se-lg-btn-bg) !important;
    background-color: var(--se-lg-btn-bg) !important;
    backdrop-filter: blur(var(--se-lg-btn-blur)) saturate(120%);
    -webkit-backdrop-filter: blur(var(--se-lg-btn-blur)) saturate(120%);
    
    /* Border and shadow */
    border: 1px solid var(--se-lg-btn-border) !important;
    border-radius: var(--se-lg-btn-radius) !important;
    box-shadow: var(--se-lg-btn-shadow);
    
    /* Typography */
    font-family: var(--e-global-typography-text-font-family, 'Poppins', sans-serif);
    font-size: 16px;
    font-weight: 500;
    color: #1C244B;
    
    /* Interaction */
    cursor: pointer;
    user-select: none;
    transition: all 0.2s ease;
    box-sizing: border-box;
    line-height: 1.2;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

/* Right-side icon group: keeps chevron fixed when reset toggles */
.se-gv-trigger__icons {
    display: inline-flex;
    align-items: center;
    justify-content: flex-end;
    gap: 4px;
}

.se-gv-trigger:hover {
    background: var(--se-lg-btn-bg-hover) !important;
    background-color: var(--se-lg-btn-bg-hover) !important;
    box-shadow: var(--se-lg-btn-shadow-hover);
    transform: translateY(-1px);
}

.se-gv-trigger:focus {
    outline: none;
    background: var(--se-lg-btn-bg-hover) !important;
    box-shadow: var(--se-lg-btn-shadow-hover), 0 0 0 3px rgba(55, 145, 197, 0.15);
}

.se-gv-trigger:active {
    transform: translateY(0);
    background: rgba(255, 255, 255, 0.6) !important;
}

/* Open state */
body.single-product.se-gv-enabled .se-gv-wrapper.se-gv-open button.se-gv-trigger.glassy-btn1,
body.single-product.se-gv-enabled .se-gv-wrapper.se-gv-open .se-gv-trigger {
    background: var(--se-lg-btn-bg-hover) !important;
    box-shadow: var(--se-lg-btn-shadow-hover);
    border-radius: var(--se-lg-btn-radius) var(--se-lg-btn-radius) 0 0 !important;
}

/* Trigger label (left segment) */
.se-gv-trigger__label {
    display: flex;
    align-items: center;
    width: 100%;
    font-size: 13px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: #1C244B;
    opacity: 0.95;
    padding-right: 12px;
    border-right: 1px solid rgba(28, 36, 75, 0.14);
    text-align: left !important;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    line-height: 1.2;
}

/* Trigger text (right segment) */
.se-gv-trigger__text {
    display: block;
    width: 100%;
    text-align: left !important;
    color: #1C244B;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    line-height: 1.2;
}

.se-gv-trigger__text.se-gv-placeholder {
    color: #7F7F7F;
    font-weight: 400;
}

/* Trigger arrow */
.se-gv-trigger__arrow {
    flex-shrink: 0;
    width: 20px;
    height: 20px;
    margin-left: 0;
    transition: transform 0.2s ease;
}

.se-gv-trigger__arrow svg {
    width: 20px;
    height: 20px;
    stroke: #1C244B;
    stroke-width: 2;
    fill: none;
}

/* Per-dropdown reset icon (only visible when a value is selected) */
.se-gv-trigger__reset {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 22px;
    height: 22px;
    margin-left: 0;
    border-radius: 999px;
    color: rgba(28, 36, 75, 0.7);
    cursor: pointer;
    user-select: none;
}

.se-gv-trigger__reset svg {
    width: 18px;
    height: 18px;
    stroke: currentColor;
    stroke-width: 2;
    fill: none;
}

.se-gv-trigger__reset:hover {
    background: rgba(0, 0, 0, 0.04);
    color: rgba(28, 36, 75, 0.9);
}

.se-gv-wrapper:not(.se-gv-has-value) .se-gv-trigger__reset {
    display: none;
}

.se-gv-wrapper.se-gv-open .se-gv-trigger__arrow {
    transform: rotate(180deg);
}

/* ============================================
   DROPDOWN LIST (open state panel)
   Uses container-like glass styling
   ============================================ */

.se-gv-dropdown {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    z-index: 99999;
    min-width: 100%;
    
    /* Glass effect - similar to portaled dropdowns */
    background: rgba(255, 255, 255, 0.92) !important;
    background-color: rgba(255, 255, 255, 0.92) !important;
    backdrop-filter: blur(24px) saturate(140%);
    -webkit-backdrop-filter: blur(24px) saturate(140%);
    
    /* Border and shadow */
    border: 1px solid rgba(255, 255, 255, 0.5);
    border-top: none;
    border-top-left-radius: 0;
    border-top-right-radius: 0;
    border-radius: 0 0 var(--se-lg-container-radius) var(--se-lg-container-radius);
    box-shadow: 
        0 8px 32px rgba(0, 0, 0, 0.12),
        inset 0 0 0 1px rgba(255, 255, 255, 0.1);
    
    /* Spacing */
    padding: 4px;
    margin: 0;
    
    /* Animation */
    opacity: 0;
    visibility: hidden;
    transform: translateY(-8px);
    transition: 
        opacity 150ms ease,
        visibility 150ms ease,
        transform 200ms ease;
    
    /* Scrollable if too many options */
    max-height: min(55vh, 320px);
    overflow-y: auto;
    overflow-x: hidden;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
}

.se-gv-wrapper.se-gv-open .se-gv-dropdown {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

/* Drop-up mode (used when there's not enough space below on small viewports) */
.se-gv-wrapper.se-gv-dropup .se-gv-dropdown {
    top: auto;
    bottom: 100%;
    border-top: 1px solid rgba(255, 255, 255, 0.5);
    border-bottom: none;
    border-radius: var(--se-lg-container-radius) var(--se-lg-container-radius) 0 0;
    transform: translateY(8px);
}

body.single-product.se-gv-enabled .se-gv-wrapper.se-gv-dropup.se-gv-open button.se-gv-trigger.glassy-btn1,
body.single-product.se-gv-enabled .se-gv-wrapper.se-gv-dropup.se-gv-open .se-gv-trigger {
    border-radius: 0 0 var(--se-lg-btn-radius) var(--se-lg-btn-radius) !important;
}

/* Top highlight gradient */
.se-gv-dropdown::before {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: inherit;
    pointer-events: none;
    background: linear-gradient(
        180deg,
        rgba(255, 255, 255, 0.25) 0%,
        rgba(255, 255, 255, 0.08) 6%,
        transparent 25%
    );
    z-index: 0;
}

/* ============================================
   SLIDING HIGHLIGHT - DISABLED
   ============================================ */

.se-gv-highlight {
    display: none !important;
}

/* ============================================
   OPTION ITEMS
   ============================================ */

.se-gv-option {
    position: relative;
    z-index: 1;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 12px;
    text-align: left;
    margin: 0;
    border-radius: 8px;
    
    /* Typography */
    font-family: var(--e-global-typography-text-font-family, 'Poppins', sans-serif);
    font-size: 14px;
    font-weight: 400;
    color: #1C244B;
    
    /* Clean background */
    background: transparent !important;
    border: none;
    
    /* Interaction */
    cursor: pointer;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

.se-gv-option:hover {
    background: rgba(0, 0, 0, 0.04) !important;
}

/* Selected option */
.se-gv-option.se-gv-selected {
    font-weight: 600;
    color: var(--e-global-color-accent, #3791C5);
}

.se-gv-option.se-gv-selected::after {
    content: '';
    flex-shrink: 0;
    width: 16px;
    height: 16px;
    margin-left: 12px;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%233791C5' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='20 6 9 17 4 12'%3E%3C/polyline%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: center;
    background-size: contain;
}

/* Disabled option */
.se-gv-option.se-gv-disabled {
    color: #7F7F7F;
    opacity: 0.5;
    cursor: not-allowed;
}

/* Keyboard focus */
.se-gv-option.se-gv-focused {
    outline: none;
}

/* ============================================
   VARIATIONS TABLE OVERRIDES
   ============================================ */

/* Clean up the variations table */
body.single-product.se-gv-enabled form.variations_form .variations {
    border: 0;
    width: 100%;
}

body.single-product.se-gv-enabled form.variations_form .variations tr {
    display: grid;
    grid-template-columns: 1fr;
    align-items: start;
    gap: 2px;
    border: 0;
    padding: 3px 0;
}

/* More vertical space between dropdown rows */
body.single-product.se-gv-enabled form.variations_form .variations tbody tr + tr {
    margin-top: 3px;
}

body.single-product.se-gv-enabled form.variations_form .variations td {
    border: 0;
    background: transparent;
    padding: 0;
}

body.single-product.se-gv-enabled form.variations_form .variations th.label {
    padding: 0;
    width: 100%;
    background: transparent !important;
    border: 0 !important;
}

body.single-product.se-gv-enabled form.variations_form .variations th.label label {
    font-weight: 600;
    font-size: 14px;
    color: #1C244B;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    display: inline-block;
    background: transparent !important;
}

body.single-product.se-gv-enabled form.variations_form .variations td.value {
    position: relative;
    padding: 0;
    width: 100% !important;
    min-width: 0;

    /* Keep the global reset link stable (no centering/jumping) */
    display: flex;
    flex-direction: column;
    align-items: stretch;
}

/* Force full-width dropdown inside the value cell */
.single-product form.variations_form .variations td.value .se-gv-wrapper,
.single-product form.variations_form .variations td.value .se-gv-trigger,
.single-product form.variations_form .variations td.value .se-gv-dropdown {
    width: 100% !important;
    max-width: 100% !important;
}

/* Hide Woo's reset link; we render a stable one ourselves */
body.single-product.se-gv-enabled form.variations_form .reset_variations {
    display: none !important;
}

/* Stable reset-all row under dropdowns */
body.single-product.se-gv-enabled form.variations_form .se-gv-reset-all-wrap {
    display: block;
    margin-top: 12px;
    margin-bottom: 18px;
    min-height: 24px; /* reserve space consistently */
}

body.single-product.se-gv-enabled form.variations_form .se-gv-reset-all {
    display: inline-flex;
    align-items: center;
    justify-content: flex-start;
    padding: 0;
    border: 0;
    background: transparent;
    font-weight: 600;
    font-size: 13px;
    line-height: 1.2;
    color: #1C244B;
    opacity: 0.85;
    cursor: pointer;
}

body.single-product.se-gv-enabled form.variations_form .se-gv-reset-all:hover {
    opacity: 1;
    text-decoration: underline;
}

body.single-product.se-gv-enabled form.variations_form:not(.se-gv-any-selected) .se-gv-reset-all {
    visibility: hidden;
    pointer-events: none;
}

/* Extra separation between dropdowns/reset and add-to-cart */
body.single-product.se-gv-enabled form.cart .woocommerce-variation-add-to-cart,
body.single-product.se-gv-enabled form.cart .variations_button {
    margin-top: 8px;
}

/* Keep qty + add-to-cart button on the same line (all breakpoints) */
body.single-product.se-gv-enabled form.cart .woocommerce-variation-add-to-cart,
body.single-product.se-gv-enabled form.cart .variations_button {
    display: flex !important;
    flex-wrap: nowrap !important;
    align-items: stretch;
    gap: 10px;
}

body.single-product.se-gv-enabled form.cart .woocommerce-variation-add-to-cart .quantity,
body.single-product.se-gv-enabled form.cart .variations_button .quantity {
    flex: 0 0 auto;
    margin: 0 !important;
}

body.single-product.se-gv-enabled form.cart .woocommerce-variation-add-to-cart .quantity .qty,
body.single-product.se-gv-enabled form.cart .variations_button .quantity .qty {
    width: clamp(64px, 18vw, 92px);
    min-width: 64px;
    box-sizing: border-box;
}

body.single-product.se-gv-enabled form.cart .woocommerce-variation-add-to-cart .single_add_to_cart_button,
body.single-product.se-gv-enabled form.cart .variations_button .single_add_to_cart_button,
body.single-product.se-gv-enabled form.cart .woocommerce-variation-add-to-cart .se-gv-add-btn,
body.single-product.se-gv-enabled form.cart .variations_button .se-gv-add-btn {
    flex: 1 1 auto;
    min-width: 0;
}

/* (hover handled on .se-gv-reset-all) */

/* ============================================
   SCROLLBAR STYLING
   ============================================ */

.se-gv-dropdown::-webkit-scrollbar {
    width: 6px;
}

.se-gv-dropdown::-webkit-scrollbar-track {
    background: transparent;
    margin: 6px 0;
}

.se-gv-dropdown::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.15);
    border-radius: 3px;
}

.se-gv-dropdown::-webkit-scrollbar-thumb:hover {
    background: rgba(0, 0, 0, 0.25);
}

/* ============================================
   RESPONSIVE ADJUSTMENTS
   ============================================ */

@media (max-width: 1024px) {
    body.single-product.se-gv-enabled {
        --se-gv-label-width: 170px;
    }
}

@media (max-width: 880px) {
    body.single-product.se-gv-enabled {
        --se-gv-label-width: 150px;
        --se-gv-trigger-pad-right: 6px;
        --se-gv-trigger-col-gap: 6px;
    }
}

@media (max-width: 768px) {
    body.single-product.se-gv-enabled {
        --se-gv-label-width: 140px;
        --se-gv-trigger-pad-right: 6px;
        --se-gv-trigger-col-gap: 6px;
    }

    body.single-product.se-gv-enabled form.variations_form .variations tr {
        grid-template-columns: 1fr;
        gap: 4px;
    }
    
    body.single-product.se-gv-enabled form.variations_form .variations td.label label {
        font-size: 13px;
    }
    
    .se-gv-trigger {
        min-height: 46px;
        font-size: 14px;
    }
    
    .se-gv-option {
        padding: 10px 12px;
    }
    
    .se-gv-dropdown {
        max-height: min(55vh, 300px);
    }
}

/* Very small phones: stack label above value for readability */
@media (max-width: 480px) {
    body.single-product.se-gv-enabled {
        --se-gv-label-width: 0px;
        --se-gv-trigger-pad-left: 12px;
        --se-gv-trigger-pad-right: 10px;
        --se-gv-trigger-col-gap: 0px;
    }

    body.single-product.se-gv-enabled button.se-gv-trigger.glassy-btn1,
    body.single-product.se-gv-enabled .se-gv-trigger {
        grid-template-columns: 1fr auto;
        grid-template-rows: auto auto;
        row-gap: 4px;
        min-height: 56px;
        padding-top: 10px !important;
        padding-bottom: 10px !important;
    }

    .se-gv-trigger__label {
        grid-column: 1;
        grid-row: 1;
        border-right: 0;
        padding-right: 0;
        opacity: 0.85;
        font-size: 12px;
    }

    .se-gv-trigger__text {
        grid-column: 1;
        grid-row: 2;
        font-size: 15px;
    }

    .se-gv-trigger__icons {
        grid-column: 2;
        grid-row: 1 / span 2;
        align-self: center;
    }

    .se-gv-option {
        padding-left: 12px;
    }
}
