/* Flexa Extra — storefront field styling. Plain CSS, no build step.
 * Swatch size/shape and button colors are driven by CSS custom properties
 * emitted on .flexa-extra-fields by ProductRenderer; each var has a sane
 * fallback so the file also works standalone. */

.flexa-extra-fields {
    margin: 1.25em 0;
    display: flex;
    flex-direction: column;
    gap: 1em;
}

/* Reveal once the storefront script has computed initial visibility/totals,
 * so no field flashes before conditional logic runs. Absent JS, it stays
 * visible (progressive enhancement). */
.flexa-extra-fields.is-ready {
    animation: flexa-extra-fade-in 0.18s ease-out;
}

@keyframes flexa-extra-fade-in {
    from { opacity: 0; transform: translateY(4px); }
    to   { opacity: 1; transform: none; }
}

.flexa-extra-set {
    display: flex;
    flex-direction: column;
    gap: 1em;
}

.flexa-extra-field {
    display: flex;
    flex-direction: column;
    gap: 0.4em;
}

.flexa-extra-field[hidden] {
    display: none;
}

.flexa-extra-field__label {
    font-weight: 600;
    font-size: 0.95em;
    line-height: 1.3;
}

.flexa-extra-required {
    color: #e2401c;
    border: 0;
    text-decoration: none;
}

.flexa-extra-tooltip {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.1em;
    height: 1.1em;
    border-radius: 50%;
    background: #e5e7eb;
    color: #374151;
    font-size: 0.72em;
    cursor: help;
}

/* Style setting: hide the tooltip markers site-wide. */
.flexa-extra-fields--no-tooltips .flexa-extra-tooltip {
    display: none;
}

.flexa-extra-control {
    width: 100%;
    max-width: 100%;
    padding: 0.55em 0.7em;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    background: #fff;
    font: inherit;
    line-height: 1.3;
}

.flexa-extra-control:focus {
    outline: none;
    border-color: #4f46e5;
    box-shadow: 0 0 0 1px #4f46e5;
}

textarea.flexa-extra-control {
    resize: vertical;
    min-height: 3em;
}

/* Keyboard focus ring on the visible choice surfaces (inputs are visually
 * hidden). :focus-within tracks the hidden input's focus. Checkbox/radio show
 * the ring on their own control (see below), not the whole row. */
.flexa-extra-button:focus-within,
.flexa-extra-swatch:focus-within,
.flexa-extra-colorpicker:focus-within {
    outline: 2px solid #4f46e5;
    outline-offset: 2px;
    border-radius: 6px;
}

/* Price badge */
.flexa-extra-price {
    color: #6b7280;
    font-size: 0.85em;
    white-space: nowrap;
}

.flexa-extra-field__label .flexa-extra-price {
    margin-left: 0.35em;
    font-weight: 500;
}

.flexa-extra-stock--out {
    color: #b91c1c;
    font-size: 0.8em;
    white-space: nowrap;
}

/* "Choose N to M options" helper under a multi-select group. */
.flexa-extra-select-hint {
    display: block;
    margin-top: 0.35em;
    color: #6b7280;
    font-size: 0.8em;
}

/* Sold-out options stay visible but read-only. */
.flexa-extra-choice.is-out-of-stock,
.flexa-extra-button.is-out-of-stock,
.flexa-extra-swatch.is-out-of-stock {
    opacity: 0.5;
    cursor: not-allowed;
}

.is-out-of-stock .flexa-extra-choice__label,
.is-out-of-stock .flexa-extra-button__label,
.is-out-of-stock .flexa-extra-swatch__label {
    text-decoration: line-through;
}

/* Choice groups render as a fieldset; strip the UA chrome. */
.flexa-extra-choices {
    display: flex;
    flex-direction: column;
    gap: 0.45em;
    border: 0;
    margin: 0;
    padding: 0;
    min-width: 0;
}

.flexa-extra-choice {
    display: flex;
    align-items: center;
    gap: 0.55em;
    cursor: pointer;
    font-size: 0.95em;
}

/* Hide the native checkbox/radio but keep it focusable and in the a11y tree;
 * the custom control below mirrors its state via the adjacent-sibling selector
 * (input:checked + .control), so no :has() is needed for wide browser support. */
.flexa-extra-choice input[type="checkbox"],
.flexa-extra-choice input[type="radio"] {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    padding: 0;
    border: 0;
    overflow: hidden;
    clip: rect(0 0 0 0);
    clip-path: inset(50%);
    white-space: nowrap;
}

.flexa-extra-choice__control {
    flex: none;
    box-sizing: border-box;
    width: 1.15em;
    height: 1.15em;
    border: 2px solid #c4c8d0;
    background: #fff;
    transition: border-color 0.12s, background 0.12s, box-shadow 0.12s;
    position: relative;
}

/* Square for checkboxes, circle for radios. */
.flexa-extra-choice input[type="checkbox"] + .flexa-extra-choice__control {
    border-radius: 4px;
}

.flexa-extra-choice input[type="radio"] + .flexa-extra-choice__control {
    border-radius: 50%;
}

.flexa-extra-choice:hover input:not(:disabled) + .flexa-extra-choice__control {
    border-color: #4f46e5;
}

/* Checked state: filled control. */
.flexa-extra-choice input:checked + .flexa-extra-choice__control {
    border-color: #4f46e5;
    background: #4f46e5;
}

/* Checkbox tick, drawn with a rotated border; scales/fades in when checked. */
.flexa-extra-choice input[type="checkbox"] + .flexa-extra-choice__control::after {
    content: "";
    position: absolute;
    left: 50%;
    top: 45%;
    width: 0.28em;
    height: 0.55em;
    border: solid #fff;
    border-width: 0 0.14em 0.14em 0;
    transform: translate(-50%, -50%) rotate(45deg) scale(0);
    transition: transform 0.14s ease;
}

.flexa-extra-choice input[type="checkbox"]:checked + .flexa-extra-choice__control::after {
    transform: translate(-50%, -50%) rotate(45deg) scale(1);
}

/* Radio dot. */
.flexa-extra-choice input[type="radio"] + .flexa-extra-choice__control::after {
    content: "";
    position: absolute;
    left: 50%;
    top: 50%;
    width: 0.5em;
    height: 0.5em;
    border-radius: 50%;
    background: #fff;
    transform: translate(-50%, -50%) scale(0);
    transition: transform 0.14s ease;
}

.flexa-extra-choice input[type="radio"]:checked + .flexa-extra-choice__control::after {
    transform: translate(-50%, -50%) scale(1);
}

/* Keyboard focus ring on the control itself. */
.flexa-extra-choice input:focus-visible + .flexa-extra-choice__control {
    outline: 2px solid #4f46e5;
    outline-offset: 2px;
}

.flexa-extra-choice input:disabled + .flexa-extra-choice__control {
    border-color: #e5e7eb;
    background: #f3f4f6;
}

.flexa-extra-choice__label {
    flex: 1 1 auto;
}

/* Color picker: a themeable swatch + hex label; the native <input type=color>
 * sits on top as an invisible, click/keyboard target that opens the OS picker. */
.flexa-extra-colorpicker {
    position: relative;
    display: inline-flex;
    align-items: center;
    gap: 0.55em;
    padding: 0.3em 0.7em 0.3em 0.4em;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    background: #fff;
    cursor: pointer;
    line-height: 1.3;
}

.flexa-extra-colorpicker input[type="color"] {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    margin: 0;
    padding: 0;
    border: 0;
    opacity: 0;
    cursor: pointer;
}

.flexa-extra-colorpicker__swatch {
    flex: none;
    width: 1.5em;
    height: 1.5em;
    border-radius: 5px;
    border: 1px solid rgba(0, 0, 0, 0.16);
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.35);
    background: #000;
}

.flexa-extra-colorpicker__value {
    font-size: 0.9em;
    font-variant-numeric: tabular-nums;
    letter-spacing: 0.02em;
    color: #4b5563;
}

/* Buttons */
.flexa-extra-choices--button {
    flex-direction: row;
    flex-wrap: wrap;
}

.flexa-extra-button {
    display: inline-flex;
    align-items: center;
    gap: 0.4em;
    padding: 0.5em 0.9em;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    background: var(--fxe-btn-bg, transparent);
    color: var(--fxe-btn-text, inherit);
    cursor: pointer;
    transition: border-color 0.12s, background 0.12s, color 0.12s;
    user-select: none;
}

.flexa-extra-button input {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.flexa-extra-button:has(input:checked) {
    border-color: var(--fxe-btn-active-bg, #4f46e5);
    background: var(--fxe-btn-active-bg, #eef2ff);
    color: var(--fxe-btn-active-text, inherit);
}

/* Swatches — size/shape from style settings. */
.flexa-extra-choices--swatch {
    flex-direction: row;
    flex-wrap: wrap;
    gap: 0.6em;
}

.flexa-extra-swatch {
    display: inline-flex;
    flex-direction: column;
    align-items: center;
    gap: 0.3em;
    cursor: pointer;
    font-size: 0.8em;
}

.flexa-extra-swatch input {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.flexa-extra-swatch__chip {
    width: var(--fxe-swatch-size, 36px);
    height: var(--fxe-swatch-size, 36px);
    border-radius: var(--fxe-swatch-radius, 6px);
    border: 2px solid #e5e7eb;
    background-size: cover;
    background-position: center;
    transition: border-color 0.12s, box-shadow 0.12s;
}

.flexa-extra-swatch:has(input:checked) .flexa-extra-swatch__chip {
    border-color: #4f46e5;
    box-shadow: 0 0 0 1px #4f46e5;
}

.flexa-extra-swatch__label {
    color: #4b5563;
}

/* Heading / description */
.flexa-extra-heading__title {
    font-weight: 700;
    font-size: 1.05em;
}

.flexa-extra-heading__desc {
    color: #6b7280;
    font-size: 0.9em;
}

/* Totals */
.flexa-extra-totals {
    margin-top: 0.5em;
    padding-top: 0.75em;
    border-top: 1px solid #e5e7eb;
    display: flex;
    flex-direction: column;
    gap: 0.25em;
}

.flexa-extra-totals[hidden] {
    display: none;
}

.flexa-extra-totals__row {
    display: flex;
    justify-content: space-between;
    gap: 1em;
}

.flexa-extra-totals__total {
    font-weight: 700;
    font-size: 1.05em;
}

.flexa-extra-totals__value {
    white-space: nowrap;
}

/* Itemized price breakdown */
.flexa-extra-breakdown {
    display: flex;
    flex-direction: column;
    gap: 0.15em;
    margin-bottom: 0.35em;
    padding-bottom: 0.35em;
    border-bottom: 1px dashed #e5e7eb;
    font-size: 0.9em;
    color: #6b7280;
}

.flexa-extra-breakdown[hidden] {
    display: none;
}

.flexa-extra-breakdown__row {
    display: flex;
    justify-content: space-between;
    gap: 1em;
}

.flexa-extra-breakdown__label {
    overflow-wrap: anywhere;
}

.flexa-extra-breakdown__amount {
    white-space: nowrap;
}

/* Responsive — stack swatches/buttons tighter on narrow viewports. */
@media (max-width: 480px) {
    .flexa-extra-choices--button,
    .flexa-extra-choices--swatch {
        gap: 0.4em;
    }

    .flexa-extra-button {
        flex: 1 1 auto;
        justify-content: center;
    }
}

/* Respect users who prefer reduced motion. */
@media (prefers-reduced-motion: reduce) {
    .flexa-extra-fields.is-ready {
        animation: none;
    }

    .flexa-extra-button,
    .flexa-extra-swatch__chip,
    .flexa-extra-control,
    .flexa-extra-choice__control,
    .flexa-extra-choice__control::after {
        transition: none;
    }
}

/* ==========================================================================
 * Cart & checkout — extra-option line items
 * Styles the option meta both in the classic cart (<dl class="variation">),
 * the block cart/checkout (.wc-block-components-product-details) and order
 * emails/received pages (.wc-item-meta). Values are emitted by CartHandler.
 * ========================================================================== */

/* --- Classic cart / checkout: turn the stacked <dl> into tidy label rows --- */
.woocommerce dl.variation,
.wc-item-meta {
    margin: 0.5em 0 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 0.3em;
    font-size: 0.875em;
    line-height: 1.45;
    list-style: none;
}

.woocommerce dl.variation dt,
.wc-item-meta .wc-item-meta-label {
    display: inline;
    float: none;
    clear: none;
    margin: 0 0.35em 0 0;
    padding: 0;
    font-weight: 600;
    color: #6b7280;
}

.woocommerce dl.variation dd,
.wc-item-meta li {
    display: block;
    margin: 0;
    padding: 0;
    color: inherit;
}

.woocommerce dl.variation dd p {
    display: inline;
    margin: 0;
}

.wc-item-meta li > * { display: inline; }

/* --- Block cart / checkout --- */
.wc-block-components-product-details {
    margin: 0.4em 0 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 0.3em;
    font-size: 0.875em;
    line-height: 1.45;
}

.wc-block-components-product-details__item {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 0.35em;
    margin: 0;
}

.wc-block-components-product-details__name {
    font-weight: 600;
    color: #6b7280;
}

/* --- Shared: the value payload (chip + text + fee pill) --- */
.flexa-extra-cart-item {
    display: inline-flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.45em;
    vertical-align: middle;
}

.flexa-extra-cart-text {
    font-weight: 500;
}

.flexa-extra-cart-swatch {
    display: inline-block;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    border: 1px solid rgba(0, 0, 0, 0.16);
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.35), 0 1px 2px rgba(0, 0, 0, 0.12);
    background-color: #e5e7eb;
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    flex: none;
    vertical-align: middle;
}

.flexa-extra-cart-fee {
    display: inline-block;
    padding: 0.05em 0.55em;
    border-radius: 999px;
    background: #eef2ff;
    color: #4f46e5;
    font-size: 0.82em;
    font-weight: 600;
    line-height: 1.5;
    white-space: nowrap;
}

/* wc_price() wraps the amount in its own span — inherit the pill colour. */
.flexa-extra-cart-fee .woocommerce-Price-amount,
.flexa-extra-cart-fee bdi {
    color: inherit;
}

/* --- Edit options in cart (classic cart line link) --- */
.flexa-extra-edit {
    margin-top: 0.35em;
}

.flexa-extra-edit-link {
    font-size: 0.82em;
    text-decoration: underline;
}

/* --- Date picker (progressive enhancement of <input type=date>) --- */
.flexa-extra-datepicker {
    position: relative;
}

.flexa-extra-datepicker__trigger {
    display: flex;
    align-items: center;
    gap: 0.5em;
    text-align: left;
    cursor: pointer;
}

.flexa-extra-datepicker__value {
    flex: 1 1 auto;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.flexa-extra-datepicker__icon {
    flex: none;
    display: inline-flex;
    align-items: center;
    color: #6b7280;
}

.flexa-extra-datepicker__trigger.is-placeholder {
    color: #6b7280;
}

.flexa-extra-datepicker__popup {
    position: absolute;
    z-index: 50;
    top: calc(100% + 4px);
    left: 0;
    width: 17.5em;
    max-width: 92vw;
    padding: 0.6em;
    border: 1px solid #d1d5db;
    border-radius: 8px;
    background: #fff;
    box-shadow: 0 6px 24px rgba(0, 0, 0, 0.14);
    box-sizing: border-box;
}

.flexa-extra-datepicker__popup[hidden] {
    display: none;
}

.flexa-extra-datepicker__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.4em;
    margin-bottom: 0.5em;
}

.flexa-extra-datepicker__title {
    font-weight: 600;
    font-size: 0.95em;
    text-transform: capitalize;
}

.flexa-extra-datepicker__nav {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2em;
    height: 2em;
    padding: 0;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    background: #fff;
    font: inherit;
    font-size: 1.05em;
    line-height: 1;
    cursor: pointer;
}

.flexa-extra-datepicker__nav:hover {
    background: #f3f4f6;
}

.flexa-extra-datepicker__weekdays,
.flexa-extra-datepicker__grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 2px;
}

.flexa-extra-datepicker__weekday {
    text-align: center;
    font-size: 0.72em;
    font-weight: 600;
    color: #6b7280;
    padding: 0.25em 0;
    text-transform: capitalize;
}

.flexa-extra-datepicker__day {
    display: flex;
    align-items: center;
    justify-content: center;
    aspect-ratio: 1 / 1;
    min-height: 2em;
    padding: 0;
    border: 0;
    border-radius: 6px;
    background: transparent;
    font: inherit;
    font-size: 0.9em;
    color: inherit;
    cursor: pointer;
}

.flexa-extra-datepicker__day.is-empty {
    cursor: default;
}

.flexa-extra-datepicker__day:not(.is-empty):not(:disabled):hover {
    background: #eef2ff;
}

.flexa-extra-datepicker__day.is-today {
    box-shadow: inset 0 0 0 1px #4f46e5;
}

.flexa-extra-datepicker__day.is-selected {
    background: #4f46e5;
    color: #fff;
}

.flexa-extra-datepicker__day:disabled {
    color: #cbd5e1;
    cursor: not-allowed;
    text-decoration: line-through;
}

.flexa-extra-datepicker__day:focus-visible,
.flexa-extra-datepicker__nav:focus-visible,
.flexa-extra-datepicker__clear:focus-visible {
    outline: 2px solid #4f46e5;
    outline-offset: 1px;
}

.flexa-extra-datepicker__footer {
    display: flex;
    justify-content: flex-end;
    margin-top: 0.5em;
}

.flexa-extra-datepicker__clear {
    padding: 0.3em 0.7em;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    background: #fff;
    font: inherit;
    font-size: 0.85em;
    cursor: pointer;
}

.flexa-extra-datepicker__clear:hover {
    background: #f3f4f6;
}

/* Comfortable touch targets on small screens. */
@media (max-width: 480px) {
    .flexa-extra-datepicker__day {
        min-height: 2.4em;
    }
}
