/**
 * Gravity Forms Product Selector - Styles
 *
 * @package GF_Product_Selector
 */

/* ============================================
   Custom Properties
   ============================================ */

.gf-product-selector-wrapper {
    --gfps-border-color: #c4c4c4;
    --gfps-border-radius: 4px;
    --gfps-focus-color: #0073aa;
    --gfps-bg-color: #fff;
    --gfps-text-color: #1e1e1e;
    --gfps-text-muted: #6c757d;
    --gfps-hover-bg: #f5f5f5;
    --gfps-selected-bg: #e8f4fc;
    --gfps-shadow: 0 4px 12px rgba(0, 0, 0, 0.12);
    --gfps-transition: 150ms ease;
}

/* ============================================
   Wrapper
   ============================================ */

.gf-product-selector-wrapper {
    position: relative;
    width: 100%;
}

/* ============================================
   Dropdown
   ============================================ */

.gf-product-selector-dropdown {
    position: relative;
    width: 100%;
}

/* ============================================
   Selected Tags (Multi-select)
   ============================================ */

.gf-product-selector-selected-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 8px;
}

.gf-product-selector-selected-tags:empty {
    display: none;
    margin-bottom: 0;
}

.gf-product-selector-tag {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 8px;
    background: var(--gfps-selected-bg);
    border: 1px solid var(--gfps-focus-color);
    border-radius: var(--gfps-border-radius);
    font-size: 13px;
    line-height: 1.4;
    color: var(--gfps-text-color);
}

.gf-product-selector-tag-text {
    max-width: 200px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.gf-product-selector-tag-remove {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 18px;
    height: 18px;
    padding: 0;
    background: transparent;
    border: none;
    border-radius: 50%;
    color: var(--gfps-text-muted);
    font-size: 16px;
    font-weight: bold;
    line-height: 1;
    cursor: pointer;
    transition: background-color var(--gfps-transition),
                color var(--gfps-transition);
}

.gf-product-selector-tag-remove:hover {
    background: rgba(0, 0, 0, 0.1);
    color: #d63638;
}

.gf-product-selector-tag-remove:focus {
    outline: none;
    background: rgba(0, 0, 0, 0.1);
    box-shadow: 0 0 0 2px rgba(0, 115, 170, 0.3);
}

/* ============================================
   Trigger Button
   ============================================ */

.gf-product-selector-trigger {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    min-height: 42px;
    padding: 10px 14px;
    background: var(--gfps-bg-color);
    border: 1px solid var(--gfps-border-color);
    border-radius: var(--gfps-border-radius);
    color: var(--gfps-text-color);
    font-size: inherit;
    font-family: inherit;
    text-align: left;
    cursor: pointer;
    transition: border-color var(--gfps-transition),
                box-shadow var(--gfps-transition);
}

.gf-product-selector-trigger:hover {
    border-color: #8c8c8c;
}

.gf-product-selector-trigger:focus {
    outline: none;
    border-color: var(--gfps-focus-color);
    box-shadow: 0 0 0 2px rgba(0, 115, 170, 0.2);
}

.gf-product-selector-trigger:disabled {
    background: #f7f7f7;
    cursor: not-allowed;
    opacity: 0.7;
}

.gf-product-selector-trigger[aria-invalid="true"] {
    border-color: #d63638;
}

/* Label */
.gf-product-selector-label {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: var(--gfps-text-muted);
}

.gf-product-selector-label.has-value {
    color: var(--gfps-text-color);
}

/* Arrow */
.gf-product-selector-arrow {
    flex-shrink: 0;
    width: 0;
    height: 0;
    margin-left: 10px;
    border-left: 5px solid transparent;
    border-right: 5px solid transparent;
    border-top: 5px solid var(--gfps-text-muted);
    transition: transform var(--gfps-transition);
}

.gf-product-selector-wrapper.is-open .gf-product-selector-arrow {
    transform: rotate(180deg);
}

/* ============================================
   Panel
   ============================================ */

.gf-product-selector-panel {
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    right: 0;
    z-index: 9999;
    display: none;
    flex-direction: column;
    max-height: 360px;
    background: var(--gfps-bg-color);
    border: 1px solid var(--gfps-border-color);
    border-radius: var(--gfps-border-radius);
    box-shadow: var(--gfps-shadow);
    overflow: hidden;
}

.gf-product-selector-wrapper.is-open .gf-product-selector-panel {
    display: flex;
}

/* ============================================
   Search Input
   ============================================ */

.gf-product-selector-search-wrapper {
    padding: 10px;
    border-bottom: 1px solid var(--gfps-border-color);
}

.gf-product-selector-search {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid var(--gfps-border-color);
    border-radius: var(--gfps-border-radius);
    font-size: 14px;
    font-family: inherit;
    transition: border-color var(--gfps-transition),
                box-shadow var(--gfps-transition);
}

.gf-product-selector-search:focus {
    outline: none;
    border-color: var(--gfps-focus-color);
    box-shadow: 0 0 0 2px rgba(0, 115, 170, 0.2);
}

.gf-product-selector-search::placeholder {
    color: var(--gfps-text-muted);
}

/* ============================================
   Product List
   ============================================ */

.gf-product-selector-list {
    flex: 1;
    overflow-y: auto;
    max-height: 240px;
}

/* Scrollbar styling */
.gf-product-selector-list::-webkit-scrollbar {
    width: 8px;
}

.gf-product-selector-list::-webkit-scrollbar-track {
    background: #f0f0f0;
}

.gf-product-selector-list::-webkit-scrollbar-thumb {
    background: #c4c4c4;
    border-radius: 4px;
}

.gf-product-selector-list::-webkit-scrollbar-thumb:hover {
    background: #a0a0a0;
}

/* ============================================
   Product Option
   ============================================ */

.gf-product-selector-option {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    cursor: pointer;
    transition: background-color var(--gfps-transition);
    border-bottom: 1px solid #f0f0f0;
}

.gf-product-selector-option:last-child {
    border-bottom: none;
}

.gf-product-selector-option:hover {
    background: var(--gfps-hover-bg);
}

.gf-product-selector-option:focus {
    outline: none;
    background: var(--gfps-hover-bg);
    box-shadow: inset 0 0 0 2px rgba(0, 115, 170, 0.3);
}

.gf-product-selector-option.is-selected {
    background: var(--gfps-selected-bg);
}

.gf-product-selector-option.is-selected:hover {
    background: #d4e9f5;
}

/* Checkbox indicator */
.gf-product-selector-checkbox {
    flex-shrink: 0;
    width: 18px;
    height: 18px;
    border: 2px solid var(--gfps-border-color);
    border-radius: 3px;
    background: var(--gfps-bg-color);
    transition: background-color var(--gfps-transition),
                border-color var(--gfps-transition);
}

.gf-product-selector-option:hover .gf-product-selector-checkbox {
    border-color: var(--gfps-focus-color);
}

.gf-product-selector-option.is-selected .gf-product-selector-checkbox {
    background: var(--gfps-focus-color);
    border-color: var(--gfps-focus-color);
}

.gf-product-selector-option.is-selected .gf-product-selector-checkbox::after {
    content: '';
    display: block;
    width: 5px;
    height: 9px;
    margin: 1px auto 0;
    border: solid #fff;
    border-width: 0 2px 2px 0;
    transform: rotate(45deg);
}

/* Title */
.gf-product-selector-option-title {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-weight: 500;
    color: var(--gfps-text-color);
}

/* Price */
.gf-product-selector-option-price {
    flex-shrink: 0;
    margin-left: 12px;
    padding: 3px 8px;
    background: #f0f0f0;
    border-radius: 3px;
    font-size: 13px;
    font-weight: 600;
    color: var(--gfps-text-color);
}

/* ============================================
   Loading State
   ============================================ */

.gf-product-selector-loading {
    display: none;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 20px;
    color: var(--gfps-text-muted);
    font-size: 14px;
}

.gf-product-selector-loading[aria-hidden="false"] {
    display: flex;
}

/* Spinner */
.gf-product-selector-spinner {
    width: 18px;
    height: 18px;
    border: 2px solid #f0f0f0;
    border-top-color: var(--gfps-focus-color);
    border-radius: 50%;
    animation: gfps-spin 0.8s linear infinite;
}

@keyframes gfps-spin {
    to {
        transform: rotate(360deg);
    }
}

/* ============================================
   Load More Button
   ============================================ */

.gf-product-selector-load-more {
    display: none;
    width: 100%;
    padding: 10px 14px;
    background: #f5f5f5;
    border: none;
    border-top: 1px solid var(--gfps-border-color);
    color: var(--gfps-focus-color);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: background-color var(--gfps-transition);
}

.gf-product-selector-load-more[aria-hidden="false"] {
    display: block;
}

.gf-product-selector-load-more:hover {
    background: #ebebeb;
}

.gf-product-selector-load-more:focus {
    outline: none;
    background: #ebebeb;
    box-shadow: inset 0 0 0 2px rgba(0, 115, 170, 0.3);
}

/* ============================================
   No Results
   ============================================ */

.gf-product-selector-no-results {
    display: none;
    padding: 30px 20px;
    text-align: center;
    color: var(--gfps-text-muted);
    font-size: 14px;
}

.gf-product-selector-no-results[aria-hidden="false"] {
    display: block;
}

/* ============================================
   Size Variants (GF Field Sizes)
   ============================================ */

.gfield--size-small .gf-product-selector-trigger {
    min-height: 36px;
    padding: 6px 10px;
    font-size: 13px;
}

.gfield--size-large .gf-product-selector-trigger {
    min-height: 48px;
    padding: 12px 16px;
    font-size: 16px;
}

/* ============================================
   Form Editor Specific
   ============================================ */

.gform_wrapper .gf-product-selector-wrapper {
    max-width: 100%;
}

#gform_fields .gf-product-selector-wrapper .gf-product-selector-trigger {
    pointer-events: none;
}

/* ============================================
   Dark Mode / Theme Compatibility
   ============================================ */

@media (prefers-color-scheme: dark) {
    .gf-product-selector-wrapper {
        --gfps-border-color: #3c3c3c;
        --gfps-bg-color: #1e1e1e;
        --gfps-text-color: #e0e0e0;
        --gfps-text-muted: #9c9c9c;
        --gfps-hover-bg: #2a2a2a;
        --gfps-selected-bg: #1a3a4a;
    }

    .gf-product-selector-option-price {
        background: #2a2a2a;
    }

    .gf-product-selector-load-more {
        background: #2a2a2a;
    }

    .gf-product-selector-load-more:hover {
        background: #353535;
    }

    .gf-product-selector-list::-webkit-scrollbar-track {
        background: #2a2a2a;
    }

    .gf-product-selector-list::-webkit-scrollbar-thumb {
        background: #4a4a4a;
    }

    .gf-product-selector-tag {
        background: #1a3a4a;
        border-color: #0073aa;
    }

    .gf-product-selector-tag-remove:hover {
        background: rgba(255, 255, 255, 0.1);
    }

    .gf-product-selector-checkbox {
        background: #2a2a2a;
    }
}

/* ============================================
   Responsive Adjustments
   ============================================ */

@media screen and (max-width: 480px) {
    .gf-product-selector-panel {
        max-height: 300px;
    }

    .gf-product-selector-list {
        max-height: 200px;
    }

    .gf-product-selector-option {
        flex-wrap: wrap;
    }

    .gf-product-selector-option-title {
        flex: 1 1 calc(100% - 28px);
        order: 1;
    }

    .gf-product-selector-option-price {
        order: 2;
        margin-left: 28px;
        margin-top: 4px;
    }

    .gf-product-selector-checkbox {
        order: 0;
    }

    .gf-product-selector-tag-text {
        max-width: 150px;
    }
}

/* ============================================
   Reduced Motion
   ============================================ */

@media (prefers-reduced-motion: reduce) {
    .gf-product-selector-trigger,
    .gf-product-selector-arrow,
    .gf-product-selector-option,
    .gf-product-selector-search,
    .gf-product-selector-load-more {
        transition: none;
    }

    .gf-product-selector-spinner {
        animation: none;
        border-top-color: var(--gfps-focus-color);
        opacity: 0.7;
    }
}

/* ============================================
   Screen Reader Only
   ============================================ */

.gf-product-selector-sr-live {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* ============================================
   Print Styles
   ============================================ */

@media print {
    .gf-product-selector-panel {
        display: none !important;
    }

    .gf-product-selector-arrow {
        display: none;
    }
}

