/*
 * Swiftly: styled drop-down for product customizable options (tm-option-select).
 * Markup: Magento_Catalog::product/composite/fieldset/options/view/multiple.phtml (Swiftly).
 * Also styles the text field / text area options (tm-option-input, Magento_Catalog::product/view/options/type/text.phtml)
 * with the same tokens, so all option controls match.
 * Plain CSS linked by those templates the first time an option renders, so every leaf gets it without a Tailwind
 * rebuild or layout change.
 *
 * Leaf themes restyle it with tokens, e.g. on :root or .catalog-product-view:
 *   --tm-option-select-accent         focus ring, selected border, check mark (default: store primary)
 *   --tm-option-select-selected-bg    selected field and selected row background
 *   --tm-option-select-selected-border
 *   --tm-option-select-active-bg      keyboard/hover row highlight
 *   --tm-option-select-text, --tm-option-select-muted, --tm-option-select-border, --tm-option-select-radius
 *   --tm-option-select-size           font size of the field value and the rows (default 0.875rem)
 */

.tm-option-select,
.tm-option-input {
    --tm-option-select-accent: var(--color-primary, #1d4ed8);
    --tm-option-select-text: var(--color-fg, #0f172a);
    --tm-option-select-muted: #64748b;
    --tm-option-select-border: #cbd5e1;
    --tm-option-select-divider: #f1f5f9;
    --tm-option-select-bg: #fff;
    --tm-option-select-selected-bg: color-mix(in srgb, var(--tm-option-select-accent) 8%, #fff);
    --tm-option-select-selected-border: var(--tm-option-select-accent);
    --tm-option-select-active-bg: color-mix(in srgb, var(--tm-option-select-accent) 12%, #fff);
    --tm-option-select-hover-bg: #f8fafc;
    --tm-option-select-error: #b91c1c;
    --tm-option-select-radius: 10px;
}

.tm-option-select {
    position: relative;
    width: 100%;
    min-width: 0;
}

.tm-option-select [x-cloak] {
    display: none !important;
}

/* The native select stays in the form for submit and validation, under the visible control. */
.tm-option-select__native {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    margin: 0;
    padding: 0;
    border: 0;
    opacity: 0;
    pointer-events: none;
    appearance: none;
    -webkit-appearance: none;
}

.tm-option-select__field {
    position: relative;
    width: 100%;
}

.tm-option-select__control {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    width: 100%;
    max-width: 100%;
    min-height: 2.75rem;
    margin: 0;
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--tm-option-select-border);
    border-radius: var(--tm-option-select-radius);
    background: var(--tm-option-select-bg);
    color: var(--tm-option-select-text);
    font: inherit;
    font-size: var(--tm-option-select-size, 0.875rem);
    line-height: 1.25rem;
    text-align: left;
    text-transform: none;
    letter-spacing: normal;
    box-shadow: none;
    cursor: pointer;
    transition: border-color 0.15s ease, box-shadow 0.15s ease, background-color 0.15s ease;
}

.tm-option-select__control:hover {
    border-color: color-mix(in srgb, var(--tm-option-select-accent) 45%, var(--tm-option-select-border));
}

.tm-option-select__control:focus {
    outline: none;
}

.tm-option-select__control:focus-visible,
.tm-option-select__control.is-open {
    border-color: var(--tm-option-select-accent);
    box-shadow: 0 0 0 2px color-mix(in srgb, var(--tm-option-select-accent) 35%, transparent);
}

.tm-option-select__control.is-filled {
    border-color: var(--tm-option-select-selected-border);
    background: var(--tm-option-select-selected-bg);
}

.tm-option-select__control.is-invalid {
    border-color: var(--tm-option-select-error);
    background: var(--tm-option-select-bg);
}

.tm-option-select__control.is-invalid:focus-visible {
    box-shadow: 0 0 0 2px color-mix(in srgb, var(--tm-option-select-error) 30%, transparent);
}

.tm-option-select__check,
.tm-option-select__chevron {
    flex-shrink: 0;
    width: 1rem;
    height: 1rem;
}

.tm-option-select__check {
    color: var(--tm-option-select-accent);
}

.tm-option-select__chevron {
    color: var(--tm-option-select-muted);
    transition: transform 0.15s ease;
}

.tm-option-select__control.is-open .tm-option-select__chevron {
    transform: rotate(180deg);
}

.tm-option-select__value {
    flex: 1 1 auto;
    min-width: 0;
    color: var(--tm-option-select-muted);
    white-space: normal;
    overflow-wrap: anywhere;
}

.tm-option-select__control.is-filled .tm-option-select__value {
    color: var(--tm-option-select-text);
    font-weight: 500;
}

.tm-option-select__price,
.tm-option-select__choice-price {
    flex-shrink: 0;
    white-space: nowrap;
    text-align: right;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    color: var(--tm-option-select-text);
}

/* Floating list */
.tm-option-select__panel {
    position: absolute;
    top: 100%;
    left: 0;
    z-index: 40;
    width: 100%;
    max-height: 18rem;
    margin: 0.25rem 0 0;
    padding: 0.25rem 0;
    overflow-y: auto;
    overscroll-behavior: contain;
    list-style: none;
    border: 1px solid #e2e8f0;
    border-radius: var(--tm-option-select-radius);
    background: var(--tm-option-select-bg);
    box-shadow: 0 10px 15px -3px rgb(15 23 42 / 0.1), 0 4px 6px -4px rgb(15 23 42 / 0.1);
}

.tm-option-select__panel.is-up {
    top: auto;
    bottom: 100%;
    margin: 0 0 0.25rem;
}

.tm-option-select__choice {
    display: flex;
    align-items: flex-start;
    gap: 0.5rem;
    margin: 0;
    padding: 0.5rem 0.75rem;
    border-bottom: 1px solid var(--tm-option-select-divider);
    color: var(--tm-option-select-text);
    font-size: var(--tm-option-select-size, 0.875rem);
    line-height: 1.25rem;
    cursor: pointer;
}

.tm-option-select__choice:last-child {
    border-bottom: 0;
}

.tm-option-select__choice:hover {
    background: var(--tm-option-select-hover-bg);
}

.tm-option-select__choice.is-active {
    background: var(--tm-option-select-active-bg);
}

.tm-option-select__choice.is-selected {
    background: var(--tm-option-select-selected-bg);
}

.tm-option-select__choice-check {
    flex-shrink: 0;
    width: 1rem;
    height: 1rem;
    margin-top: 0.125rem;
    color: var(--tm-option-select-accent);
}

.tm-option-select__choice-check svg {
    display: none;
    width: 1rem;
    height: 1rem;
}

.tm-option-select__choice.is-selected .tm-option-select__choice-check svg {
    display: block;
}

.tm-option-select__choice-title {
    flex: 1 1 auto;
    min-width: 0;
    font-weight: 500;
    white-space: normal;
    overflow-wrap: anywhere;
}

.tm-option-select__choice--placeholder .tm-option-select__choice-title {
    color: var(--tm-option-select-muted);
    font-weight: 400;
}

.tm-option-select__choice-price {
    min-width: 4.5rem;
}

.tm-option-select__error {
    margin: 0.25rem 0 0;
    color: var(--tm-option-select-error);
    font-size: 0.875rem;
}

/*
 * Text field and text area options (Swiftly Magento_Catalog::product/view/options/type/text.phtml): same box as the
 * drop-down control so the two sit together. Filled = not showing its single-space placeholder.
 */
.tm-option-input {
    display: block;
    width: 100%;
    max-width: 100%;
    min-height: 2.75rem;
    margin: 0;
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--tm-option-select-border);
    border-radius: var(--tm-option-select-radius);
    background: var(--tm-option-select-bg);
    color: var(--tm-option-select-text);
    font: inherit;
    font-size: 0.875rem;
    line-height: 1.25rem;
    box-shadow: none;
    outline: none;
    transition: border-color 0.15s ease, box-shadow 0.15s ease, background-color 0.15s ease;
}

.tm-option-input--area {
    min-height: 6rem;
    resize: vertical;
}

.tm-option-input::placeholder {
    color: var(--tm-option-select-muted);
}

.tm-option-input:hover {
    border-color: color-mix(in srgb, var(--tm-option-select-accent) 45%, var(--tm-option-select-border));
}

.tm-option-input:not(:placeholder-shown) {
    border-color: var(--tm-option-select-selected-border);
    background: var(--tm-option-select-selected-bg);
}

.tm-option-input:focus,
.tm-option-input:focus-visible {
    border-color: var(--tm-option-select-accent);
    box-shadow: 0 0 0 2px color-mix(in srgb, var(--tm-option-select-accent) 35%, transparent);
    outline: none;
}

.tm-option-input:user-invalid {
    border-color: var(--tm-option-select-error);
    background: var(--tm-option-select-bg);
}

.tm-option-input:user-invalid:focus {
    box-shadow: 0 0 0 2px color-mix(in srgb, var(--tm-option-select-error) 30%, transparent);
}

/* 16px text on phones so iOS Safari doesn't zoom in when the field is focused. */
@media (max-width: 639px) {
    .tm-option-input {
        font-size: 1rem;
    }
}

@media (prefers-reduced-motion: reduce) {
    .tm-option-input,
    .tm-option-select__control,
    .tm-option-select__chevron {
        transition: none;
    }
}
