/**
 * The shared size panel and the button that opens it.
 *
 * Loaded after main.css and product-card.css. The panel is opened by the card's own
 * add-to-cart button, which product-card.css already styles as the navy button on the
 * card floor; nothing here restyles it, because opening the panel must not change how
 * the button looks.
 *
 * The panel opens inside the card that owns the button, not over the viewport. The
 * presentation below is written for the viewport, and the IN CARD section at the end
 * of the file restyles it once the script has moved it into a card. That order is what
 * keeps a panel the script never moved (no JavaScript, or a page without WCBlocks) from
 * looking broken.
 *
 * The palette is neutral grey plus black. The only accent colours left are the two
 * status message colours, which report the outcome of a request.
 */

/* -------------------------------------------------------------------- MODAL */

/*
 * The page is not locked while the panel is open. The panel lives inside a card, so
 * scrolling the grid past it is exactly what a customer expects.
 */

.wcb-sizes-modal[hidden] {
    display: none !important;
}

.wcb-sizes-modal {
    position: fixed;
    inset: 0;
    z-index: 999999;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
}

.wcb-sizes-modal__backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.55);
}

.wcb-sizes-modal__panel {
    position: relative;
    width: 100%;
    max-width: 420px;
    max-height: calc(100vh - 32px);
    overflow-y: auto;
    padding: 24px 22px 22px;
    border-radius: 12px;
    background: #ffffff;
    box-shadow: 0 18px 48px rgba(0, 0, 0, 0.22);
    text-align: left;
}

.wcb-sizes-modal__panel:focus {
    outline: none;
}

/* Visually hidden text, so the modal does not depend on the theme defining it. */
.wcb-sizes-modal__sr {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    padding: 0;
    overflow: hidden;
    clip: rect(0 0 0 0);
    clip-path: inset(50%);
    white-space: nowrap;
    border: 0;
}

/* -------------------------------------------------------------- CLOSE BUTTON */

/*
 * A neutral, borderless square. It keeps the top-right corner of the panel and stays
 * comfortably above the 32px minimum tap target.
 *
 * Every control rule in this file is scoped under .wcb-sizes-modal on purpose. Hello
 * Elementor's reset.css styles every button through a single-attribute selector and is
 * printed after this file, so a lone class would lose the tie and the close button
 * would render with the theme's crimson border and crimson glyph. Two classes win
 * outright, and the extra class costs nothing: the panel root is always an ancestor.
 */
.wcb-sizes-modal .wcb-sizes-modal__close {
    position: absolute;
    top: 8px;
    right: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    padding: 0;
    border: 0;
    border-radius: 6px;
    background: #f5f5f5;
    color: #555555;
    font-family: inherit;
    font-size: 20px;
    line-height: 1;
    cursor: pointer;
    box-sizing: border-box;
    transition: background-color 0.15s ease, color 0.15s ease;
}

/*
 * The theme paints its crimson fill on :focus as well as on :hover, and a mouse click
 * leaves the button focused, so both states are restated at the same raised specificity.
 */
.wcb-sizes-modal .wcb-sizes-modal__close:hover,
.wcb-sizes-modal .wcb-sizes-modal__close:focus {
    background: #e2e2e2;
    color: #111111;
}

.wcb-sizes-modal .wcb-sizes-modal__close:focus-visible {
    outline: 2px solid #111111;
    outline-offset: 2px;
    color: #111111;
}

/* --------------------------------------------------------- TITLE AND STATUS */

.wcb-sizes-modal__title {
    margin: 0 44px 4px 0;
    font-size: 17px;
    font-weight: 600;
    line-height: 1.35;
    color: #111111;
}

.wcb-sizes-modal__subtitle {
    margin: 0 0 16px;
    font-size: 13px;
    color: #6b6b70;
}

.wcb-sizes-modal__status {
    margin: 0 0 12px;
    font-size: 13px;
    line-height: 1.4;
    color: #6b6b70;
}

.wcb-sizes-modal__status:empty {
    display: none;
}

/*
 * The load state is driven by data-wcb-sizes-state and the add state by
 * data-wcb-add-state, so the script never has to toggle individual nodes.
 *
 * A failed load leaves nothing to choose, so the chips go away. A failed add does not:
 * the panel keeps the list and the selection so the customer can retry.
 */
.wcb-sizes-modal__panel[data-wcb-sizes-state="loading"] .wcb-sizes-modal__chips,
.wcb-sizes-modal__panel[data-wcb-sizes-state="error"] .wcb-sizes-modal__chips {
    display: none;
}

.wcb-sizes-modal__panel[data-wcb-sizes-state="error"] .wcb-sizes-modal__status,
.wcb-sizes-modal__panel[data-wcb-add-state="error"] .wcb-sizes-modal__status {
    color: #b32d2e;
}

.wcb-sizes-modal__panel[data-wcb-add-state="success"] .wcb-sizes-modal__status {
    color: #1a7f37;
}

/* -------------------------------------------------------------------- CHIPS */

/*
 * Every chip is the same box no matter how many sizes a product has. The row height is
 * fixed and `align-content: start` stops the grid from stretching its rows to fill the
 * panel, which is what made a 6-size product show two enormous chips.
 */
.wcb-sizes-modal .wcb-sizes-modal__chips {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(64px, 1fr));
    grid-auto-rows: 46px;
    align-content: start;
    gap: 8px;
}

/*
 * The chip box is border-box, so the 2px border of the selected state cannot grow it:
 * the selected rule only takes 1px back off the padding, which keeps the size name in
 * exactly the same place.
 *
 * Scoped under the modal root: the theme's button reset is printed after this file and
 * ties a lone class on specificity, so the chip used to render with the theme's crimson
 * border, crimson text and 1rem padding. See the CLOSE BUTTON section for the full note.
 */
.wcb-sizes-modal .wcb-sizes-modal__chip {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    height: 46px;
    padding: 8px 6px;
    border: 1px solid #111111;
    border-radius: 6px;
    background: #f5f5f5;
    color: #333333;
    font-family: inherit;
    font-size: 14px;
    font-weight: 500;
    line-height: 1.2;
    cursor: pointer;
    box-sizing: border-box;
    transition: border-color 0.15s ease, background-color 0.15s ease, color 0.15s ease;
}

/*
 * A click leaves the chip focused, and the theme paints crimson on :focus too. This
 * rule restates the resting palette so a focused chip is indistinguishable from an
 * unfocused one; the keyboard ring is left to :focus-visible below.
 */
.wcb-sizes-modal .wcb-sizes-modal__chip:focus:not([disabled]):not(.is-selected) {
    border-color: #111111;
    background: #f5f5f5;
    color: #333333;
}

/* In stock and unselected: the chip fills solid black under the pointer. */
.wcb-sizes-modal .wcb-sizes-modal__chip:hover:not([disabled]):not(.is-selected) {
    border-color: #111111;
    background: #111111;
    color: #ffffff;
}

/*
 * The chosen size: solid black fill with white text, matching the hover preview, so
 * picking a size visibly "sticks" instead of only thickening the border. The 2px
 * border (compensated in the padding) keeps the box exactly the same size.
 */
.wcb-sizes-modal .wcb-sizes-modal__chip.is-selected {
    border: 2px solid #111111;
    padding: 7px 5px;
    background: #111111;
    color: #ffffff;
    font-weight: 600;
}

/*
 * A selected chip holds its black fill under the pointer and on focus, so it never
 * falls back to the light resting look once the pointer leaves or the chip is focused.
 */
.wcb-sizes-modal .wcb-sizes-modal__chip.is-selected:hover,
.wcb-sizes-modal .wcb-sizes-modal__chip.is-selected:focus {
    border-color: #111111;
    background: #111111;
    color: #ffffff;
}

.wcb-sizes-modal .wcb-sizes-modal__chip:focus-visible {
    outline: 2px solid #111111;
    outline-offset: 2px;
}

/* A chip shows the size name only; no price is rendered next to it. */

/* Out of stock: still visible and disabled, struck through and muted. */
.wcb-sizes-modal .wcb-sizes-modal__chip[disabled] {
    cursor: not-allowed;
    border-color: #eeeeee;
    background: #fafafa;
    color: #b5b5b5;
}

/*
 * The theme's button:hover is not guarded by :disabled, so an out-of-stock chip would
 * still take the crimson fill under the pointer. Every interaction state is restated
 * here at a specificity the theme cannot reach, so a disabled chip never reacts.
 */
.wcb-sizes-modal .wcb-sizes-modal__chip[disabled]:hover,
.wcb-sizes-modal .wcb-sizes-modal__chip[disabled]:focus,
.wcb-sizes-modal .wcb-sizes-modal__chip[disabled]:focus-visible {
    border-color: #eeeeee;
    background: #fafafa;
    color: #b5b5b5;
    outline: none;
}

.wcb-sizes-modal .wcb-sizes-modal__chip[disabled] .wcb-sizes-modal__chip-name {
    text-decoration: line-through;
}

/* ----------------------------------------------------------- CONFIRM BUTTON */

/*
 * The add happens here, not on the chip. The button is always in the layout so the
 * panel keeps its height, and only its visibility changes: the panel must not jump
 * when a size is picked. It is disabled until something is selected, which also keeps
 * it out of the tab order while it is invisible.
 */
.wcb-sizes-modal .wcb-sizes-modal__confirm {
    display: block;
    width: 100%;
    min-height: 44px;
    margin: 16px 0 0;
    padding: 10px 14px;
    border: 0;
    border-radius: 8px;
    background: #111111;
    color: #ffffff;
    font-family: inherit;
    font-size: 12px;
    font-weight: 700;
    line-height: 1.2;
    letter-spacing: 0.04em;
    text-align: center;
    text-transform: uppercase;
    cursor: pointer;
    visibility: hidden;
    box-sizing: border-box;
    transition: background-color 0.2s ease;
}

.wcb-sizes-modal__panel[data-wcb-add-state="selected"] .wcb-sizes-modal__confirm,
.wcb-sizes-modal__panel[data-wcb-add-state="adding"] .wcb-sizes-modal__confirm,
.wcb-sizes-modal__panel[data-wcb-add-state="success"] .wcb-sizes-modal__confirm,
.wcb-sizes-modal__panel[data-wcb-add-state="error"] .wcb-sizes-modal__confirm {
    visibility: visible;
}

/*
 * :focus is restated next to :hover because the theme paints its crimson fill on focus
 * as well, and a click leaves the button focused. The dark fill and the white label are
 * re-declared so neither can be taken over by the theme.
 */
.wcb-sizes-modal .wcb-sizes-modal__confirm:hover:not([disabled]),
.wcb-sizes-modal .wcb-sizes-modal__confirm:focus:not([disabled]) {
    background: #000000;
    color: #ffffff;
}

.wcb-sizes-modal .wcb-sizes-modal__confirm:focus-visible {
    outline: 2px solid #111111;
    outline-offset: 2px;
}

/* The request is in flight: no second submission, and it is obvious why. */
.wcb-sizes-modal .wcb-sizes-modal__confirm[disabled] {
    background: #9a9aa1;
    color: #ffffff;
    cursor: progress;
}

.wcb-sizes-modal .wcb-sizes-modal__panel[data-wcb-add-state="idle"] .wcb-sizes-modal__confirm[disabled] {
    cursor: default;
}

/* ----------------------------------------------------------------- RESPONSIVE */

@media (max-width: 480px) {
    .wcb-sizes-modal {
        align-items: flex-end;
        padding: 0;
    }

    .wcb-sizes-modal__panel {
        max-width: none;
        max-height: 80vh;
        padding: 20px 16px 18px;
        border-radius: 14px 14px 0 0;
    }

    .wcb-sizes-modal .wcb-sizes-modal__chips {
        grid-template-columns: repeat(auto-fill, minmax(58px, 1fr));
    }
}

/*
 * Scoped like the rest: the theme sets transition: all .3s on every button, so an
 * unscoped transition: none would tie and lose to the later theme stylesheet.
 */
@media (prefers-reduced-motion: reduce) {
    .wcb-sizes-modal .wcb-sizes-modal__chip,
    .wcb-sizes-modal .wcb-sizes-modal__close,
    .wcb-sizes-modal .wcb-sizes-modal__confirm {
        transition: none;
    }
}

/* ------------------------------------------------------------------ IN CARD */

/*
 * The panel is not a viewport overlay any more. The script moves this whole element
 * into the card that opened the button, and these rules make it cover the card
 * surface. They are declared last and scoped to a card, so they win over the viewport
 * presentation above without that presentation having to know about them.
 *
 * The offsets mirror the card surface drawn by product-card.css: it is inset from li
 * by --wcb-card-gutter, and both boxes are positioned against the same padding box.
 * Nothing can therefore spill outside the card.
 */
.wcb-products>li .wcb-sizes-modal {
    position: absolute;
    inset: 0 var(--wcb-card-gutter, 12px);
    z-index: 20;
    padding: 0;
    align-items: stretch;
}

/* Covers the card behind the panel, so the card reads as replaced, not overlaid. */
.wcb-products>li .wcb-sizes-modal__backdrop {
    background: rgba(255, 255, 255, 0.92);
}

/*
 * The panel fills the layer above and is itself absolutely positioned, so its box is
 * exactly the card surface: the top and bottom insets define the height, and it can
 * neither stretch past the card nor be pushed out of it by its own content.
 */
.wcb-products>li .wcb-sizes-modal__panel {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    width: auto;
    height: auto;
    max-width: none;
    max-height: none;
    padding: 18px 16px 16px;
    border: 1px solid var(--wcb-card-border, #e8e8ec);
    border-radius: var(--wcb-card-radius, 10px);
    box-shadow: none;
    box-sizing: border-box;
}

/* The card is much narrower than the viewport, so the panel content gets tighter. */
.wcb-products>li .wcb-sizes-modal__title,
.wcb-products>li .wcb-sizes-modal__subtitle,
.wcb-products>li .wcb-sizes-modal__status {
    flex: 0 0 auto;
}

.wcb-products>li .wcb-sizes-modal__title {
    margin: 0 38px 4px 0;
    font-size: 14px;
}

.wcb-products>li .wcb-sizes-modal__subtitle {
    margin-bottom: 10px;
    font-size: 12px;
}

.wcb-products>li .wcb-sizes-modal__status {
    font-size: 12px;
}

.wcb-products>li .wcb-sizes-modal__close {
    top: 4px;
    right: 4px;
    width: 32px;
    height: 32px;
    font-size: 18px;
}

/*
 * The chip grid takes the room left between the heading and the confirm button and
 * scrolls on its own, so a long size list can never push the button out of the card.
 */
.wcb-products>li .wcb-sizes-modal__chips {
    flex: 1 1 auto;
    min-height: 0;
    grid-template-columns: repeat(auto-fill, minmax(52px, 1fr));
    grid-auto-rows: 46px;
    align-content: start;
    gap: 6px;
    overflow-y: auto;
}

.wcb-products>li .wcb-sizes-modal__chip {
    height: 46px;
    padding: 6px 4px;
    font-size: 13px;
}

.wcb-products>li .wcb-sizes-modal__chip.is-selected {
    padding: 5px 3px;
}

/* The confirm button sits on the card floor, under a chip grid that scrolls. */
.wcb-products>li .wcb-sizes-modal__confirm {
    flex: 0 0 auto;
    min-height: 40px;
    margin-top: 10px;
    padding: 8px 10px;
}
