/* ── Buy box ────────────────────────────────────────────────
   Figma: Section: Format & Quantity 3033:85513 (and its states
   3033:85895, 3033:86100; collection 3033:86305). A white card
   on desktop and tablet; on mobile it sits on the grey.
   ─────────────────────────────────────────────────────────── */

.product-buy {
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 24px;
    border-radius: 12px;
    background: var(--color-white);
    box-shadow: 0 0 12px rgb(0 0 0 / 0.12);
}

/* The breadcrumb, title and short description (styled in product-hero.css) */
.product-buy__head {
    margin-bottom: 12px;
}

.product-buy__panel {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.product-buy__panel[hidden] {
    display: none;
}

/* Delivery | Collection */
.product-buy__modes {
    display: flex;
    gap: 4px;
    padding: 6px;
    border-radius: 99px;
    background: var(--color-grey);
}

.product-buy__mode {
    flex: 1;
    padding: 10px 16px;
    border: 0;
    border-radius: 99px;
    background: none;
    color: var(--color-text);
    font: inherit;
    font-weight: 700;
    line-height: 20.8px;
    cursor: pointer;
    transition: background var(--transition), color var(--transition);
}

.product-buy__mode.is-active {
    background: var(--color-primary);
    color: var(--color-white);
}

.product-buy__group {
    display: flex;
    flex-direction: column;
    gap: 8px;
    min-width: 0;
    margin: 0;
    padding: 0;
    border: 0;
}

.product-buy__label {
    padding: 0;
    font-family: var(--font-heading);
    font-weight: 500;
    line-height: 20px;
}

/* Bulk bag / Loose load */
.product-buy__types {
    display: flex;
    gap: 16px;
}

.product-buy__type {
    display: flex;
    flex: 1;
    flex-direction: column;
    align-items: flex-start;
    gap: 4px;
    min-width: 0;
    padding: 20px;
    border: 1px solid var(--color-border);
    border-radius: 8px;
    background: var(--color-white);
    color: var(--color-text);
    font: inherit;
    text-align: left;
    cursor: pointer;
    transition: border-color var(--transition), box-shadow var(--transition);
}

.product-buy__type:hover {
    border-color: var(--color-primary);
}

/* Doesn't fit on the lorry: greyed, kept in view; its tip says why */
.product-buy__type[aria-disabled="true"] {
    position: relative;
    background: var(--color-grey-light);
    color: var(--color-text-muted);
    cursor: not-allowed;
}

.product-buy__type[aria-disabled="true"]:hover {
    border-color: var(--color-border);
}

/* Chosen: a 2px Mid Green edge, drawn inside so nothing moves */
.product-buy__type.is-active {
    border-color: var(--color-primary);
    box-shadow: inset 0 0 0 1px var(--color-primary);
}

.product-buy__type-name {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 0;
    font-family: var(--font-heading);
    font-size: 20px;
    font-weight: 600;
    line-height: 25px;
}

.product-buy__type-how {
    font-family: var(--font-heading);
    font-weight: 500;
    line-height: 20px;
    color: var(--color-text-muted);
}

.product-buy__type-what {
    line-height: 20.8px;
}

.product-buy__type-note {
    font-family: var(--font-heading);
    font-size: 12px;
    line-height: 16px;
    color: var(--color-text-muted);
}

/* Quantity and Location */
.product-buy__row-head {
    display: flex;
    justify-content: space-between;
    gap: 16px;
}

.product-buy__calculator {
    font-family: var(--font-heading);
    font-weight: 500;
    line-height: 20px;
    color: var(--color-primary);
    white-space: nowrap;
}

.product-buy__fields {
    display: flex;
    gap: 16px;
}

.product-buy__fields > [hidden] {
    display: none;
}

/* − 1 + */
.product-buy__stepper {
    display: flex;
    flex: none;
    align-items: center;
    gap: 4px;
    height: 45px;
    padding: 4px;
    border: 1px solid var(--color-border);
    border-radius: 4px;
    background: var(--color-white);
    box-shadow: 0 0 12px rgb(0 0 0 / 0.12);
}

.product-buy__stepper button {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    padding: 0;
    border: 0;
    border-radius: 4px;
    background: none;
    color: var(--color-text);
    font-family: var(--font-heading);
    font-size: 16px;
    font-weight: 500;
    cursor: pointer;
}

.product-buy__stepper button:hover:not(:disabled) {
    background: var(--color-grey-hover);
}

.product-buy__stepper button:disabled,
.product-buy__stepper button[aria-disabled="true"] {
    opacity: 0.35;
    cursor: default;
}

.product-buy__stepper input {
    width: 32px;
    padding: 0;
    border: 0;
    background: none;
    color: var(--color-text);
    font-family: var(--font-heading);
    font-size: 16px;
    font-weight: 500;
    text-align: center;
    outline: none;
    appearance: textfield;
}

.product-buy__stepper input::-webkit-inner-spin-button,
.product-buy__stepper input::-webkit-outer-spin-button {
    margin: 0;
    appearance: none;
}

/* Tonnes, and the collection depot */
.product-buy__select,
.product-buy__location {
    position: relative;
    display: flex;
    flex: 1;
    min-width: 0;
}

.product-buy__select {
    flex: 0 1 170px;
}

.product-buy__fields--collection .product-buy__select:last-child {
    flex: 1;
}

.product-buy__select select,
.product-buy__location input {
    width: 100%;
    min-width: 0;
    height: 45px;
    padding: 10px 36px 10px 12px;
    border: 1px solid var(--color-border);
    border-radius: 4px;
    background: var(--color-white);
    box-shadow: 0 0 12px rgb(0 0 0 / 0.12);
    color: var(--color-text);
    font-family: var(--font-heading);
    font-size: 16px;
    font-weight: 500;
    line-height: 20px;
    appearance: none;
}

.product-buy__select select {
    cursor: pointer;
}

.product-buy__location input::placeholder {
    color: rgb(5 5 2 / 0.5);
}

.product-buy__select select:focus-visible,
.product-buy__location input:focus-visible {
    outline: 2px solid var(--color-primary);
    outline-offset: -2px;
}

.product-buy__chevron {
    position: absolute;
    top: 50%;
    right: 12px;
    width: 14px;
    height: 14px;
    translate: 0 -50%;
    pointer-events: none;
}

/* The arrow opens every location */
.product-buy__all {
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    width: 40px;
    padding: 0;
    border: 0;
    background: none;
    color: var(--color-text);
    cursor: pointer;
}

.product-buy__all:disabled {
    cursor: not-allowed;
}

/* Waiting for a format: greyed, and a tip on hover saying why */
.product-buy__stepper:has(input:disabled),
.product-buy__location:has(input:disabled) input {
    background: var(--color-grey-light);
    color: var(--color-text-muted);
    cursor: not-allowed;
}

.product-buy__stepper input:disabled {
    cursor: not-allowed;
}

.product-buy__tip {
    position: relative;
}

.product-buy__tip--full {
    display: flex;
    flex-direction: column;
}

.product-buy__tip[data-tip]:not([data-tip=""]):is(:hover, .is-tipping)::after,
.product-buy__type[aria-disabled="true"][data-tip]:not([data-tip=""]):is(:hover, .is-tipping)::after {
    content: attr(data-tip);
    position: absolute;
    bottom: calc(100% + 8px);
    left: 50%;
    z-index: 40;
    width: max-content;
    max-width: 260px;
    padding: 8px 12px;
    border-radius: 6px;
    background: var(--color-secondary);
    color: var(--color-white);
    font-family: var(--font-heading);
    font-size: 14px;
    font-weight: 500;
    line-height: 18px;
    text-align: center;
    pointer-events: none;
    translate: -50% 0;
}

/* A tap on a waiting control reaches its wrapper (disabled controls take
   no taps), which shows the tip for a moment — the touch-screen way. */
.product-buy__tip :disabled {
    pointer-events: none;
}

/* The tip only shows while the thing under it is waiting */
.product-buy__tip:not(:has(input:disabled, [data-buy-add]:disabled))::after {
    display: none;
}

/* The basket's location, fixed for the order (Figma 3342:96480) */
.product-buy__place-button {
    display: flex;
    flex: 1;
    align-items: center;
    gap: 8px;
    min-width: 0;
    height: 45px;
    padding: 10px 12px;
    border: 1px solid var(--color-border);
    border-radius: 4px;
    background: var(--color-white);
    box-shadow: 0 0 12px rgb(0 0 0 / 0.12);
    color: var(--color-text-muted);
    font: inherit;
    text-align: left;
    cursor: pointer;
}

.product-buy__place-button[hidden] {
    display: none;
}

.product-buy__place-button > span:first-child {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    font-family: var(--font-heading);
    font-weight: 500;
    line-height: 20px;
    white-space: nowrap;
    text-overflow: ellipsis;
}

.product-buy__edit {
    display: flex;
    align-items: center;
    font-size: 14px;
    line-height: 20.8px;
}

.product-buy__place-button:hover .product-buy__edit {
    color: var(--color-text);
}

/* "Delivery location applies to your whole order." (Figma 3342:96501) */
.product-buy__note {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-top: 4px;
    padding: 4px 12px;
    border-radius: 4px;
    background: var(--color-info);
    font-size: 14px;
    line-height: 20.8px;
}

.product-buy__note[hidden] {
    display: none;
}

.product-buy__note svg {
    flex: none;
}

/* The pop-up to change the order's location (Figma 3342:96612) */
.product-buy__dialog {
    width: min(349px, calc(100vw - 32px));
    margin: auto; /* centred: the reset takes a dialog's own margin away */
    padding: 44px 24px 24px;
    border: 0;
    border-radius: 12px;
    background: var(--color-white);
    box-shadow: 0 0 12px rgb(0 0 0 / 0.12);
    color: var(--color-text);
    overflow: visible;
}

.product-buy__dialog[open] {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.product-buy__dialog::backdrop {
    background: rgb(5 5 2 / 0.5);
}

.product-buy__dialog p {
    line-height: 20.8px;
}

.product-buy__dialog-title {
    font-family: var(--font-heading);
    font-size: 20px;
    font-weight: 600;
    line-height: 25px;
}

.product-buy__dialog .product-buy__location input {
    border-color: var(--color-primary);
}

.product-buy__close {
    position: absolute;
    top: 20px;
    right: 20px;
    display: flex;
    width: 24px;
    height: 24px;
    padding: 0;
    border: 0;
    background: none;
    color: var(--color-text);
    cursor: pointer;
}

/* The matching locations under the field */
.product-buy__places {
    position: absolute;
    top: calc(100% + 4px);
    right: 0;
    left: 0;
    z-index: 30;
    max-height: min(420px, 60vh); /* about eight places at a time, never more than most of the screen */
    margin: 0;
    padding: 6px;
    overflow-y: auto;
    border: 1px solid var(--color-border);
    border-radius: 8px;
    background: var(--color-white);
    box-shadow: 0 6px 12px rgb(0 0 0 / 0.12);
    list-style: none;
}

.product-buy__places[hidden] {
    display: none;
}

/* On the page, the list runs the full width of the row (the amount and the
   location), under it. The location box isn't what it's placed against, so
   its arrow sits over the field's end in the flow instead. */
.product-buy__fields {
    position: relative;
}

.product-buy__fields .product-buy__location {
    position: static;
}

.product-buy__fields .product-buy__all {
    position: relative;
    flex: none;
    margin-left: -40px;
}

/* A group per postcode district; its label sticks to the top of the list
   while its places scroll by, then the next group's label pushes it off. */
.product-buy__place-group ul {
    margin: 0;
    padding: 0;
    list-style: none;
}

/* Grouped: no top padding, so the first label sits flush with the top */
.product-buy__places:has(.product-buy__place-group) {
    padding-top: 0;
}

.product-buy__place-label {
    position: sticky;
    top: 0;
    z-index: 1;
    margin: 0 -6px;
    padding: 8px 16px 6px;
    border-bottom: 1px solid var(--color-border);
    background: var(--color-grey-light);
    color: var(--color-text-muted);
    font-family: var(--font-heading);
    font-size: 12px;
    font-weight: 600;
    line-height: 16px;
    letter-spacing: 0.04em;
}

.product-buy__place {
    display: flex;
    justify-content: space-between;
    scroll-margin-top: 32px; /* arrow keys keep it clear of the sticky label */
    gap: 12px;
    padding: 12px 10px;
    border-radius: 4px;
    line-height: 20.8px;
    cursor: pointer;
}

.product-buy__place span {
    color: var(--color-text-muted);
}

.product-buy__place:hover,
.product-buy__place[aria-selected="true"] {
    background: var(--color-grey-hover);
}

.product-buy__place--empty {
    color: var(--color-text-muted);
    cursor: default;
}

.product-buy__place--empty:hover {
    background: none;
}

.product-buy__hint {
    font-size: 14px;
    line-height: 20.8px;
    color: var(--color-text-muted);
}

.product-buy__hint[hidden] {
    display: none;
}

/* Tablet and mobile have no hover: their tips come from a tap (product-buy.js) */
@media (max-width: 1024px) {
    .product-buy__tip[data-tip]:hover:not(.is-tipping)::after,
    .product-buy__type[data-tip]:hover:not(.is-tipping)::after {
        display: none;
    }

    /* The quantity sits at the left edge of the screen: its tip starts at
       its left edge rather than centring over it, so it isn't cut off. */
    .product-buy__tip[data-buy-qty-for][data-tip]:not([data-tip=""]):is(:hover, .is-tipping)::after {
        left: 0;
        max-width: min(260px, calc(100vw - 2 * var(--pad-x)));
        translate: none;
    }
}


/* Price, button, trade prompt */
.product-buy__result {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.product-buy__price {
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin-bottom: 8px;
}

.product-buy__price[hidden] {
    display: none;
}

.product-buy__price strong {
    font-family: var(--font-heading);
    font-size: 32px;
    font-weight: 600;
    line-height: 34px;
}

/* A trade price: the usual price struck through beside it */
.product-buy__amounts {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 10px;
}

.product-buy__was {
    font-family: var(--font-heading);
    font-size: 20px;
    font-weight: 500;
    line-height: 25px;
    color: var(--color-text-muted);
}

.product-buy__was[hidden] {
    display: none;
}

.product-buy__price > span:not(.product-buy__amounts),
.product-buy__price-label {
    font-family: var(--font-heading);
    font-size: 12px;
    line-height: 16px;
    color: var(--color-text-muted);
}

.product-buy__price.is-updating strong {
    opacity: 0.4;
}

/* Errors and the lorry limit: red text (Figma 3336:95834) */
.product-buy__errors,
.product-buy__limit a {
    color: inherit;
    font-weight: 700;
    white-space: nowrap;
}

.product-buy__limit {
    font-size: 14px;
    line-height: 20.8px;
    color: var(--color-error);
}

.product-buy__errors[hidden],
.product-buy__limit[hidden] {
    display: none;
}

.product-buy__added {
    font-family: var(--font-heading);
    font-weight: 500;
    line-height: 20px;
    text-align: center;
    color: var(--color-primary);
}

.product-buy__added[hidden] {
    display: none;
}

.product-buy__trade {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    font-family: var(--font-heading);
    font-weight: 500;
    line-height: 20px;
    text-align: center;
}

.product-buy__trade svg {
    flex: none;
}

.product-buy__trade a {
    color: inherit;
    text-decoration: underline;
}

.product-buy__small {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 4px 8px;
    font-family: var(--font-heading);
    font-size: 12px;
    line-height: 16px;
    text-align: center;
    color: var(--color-text-muted);
}

/* Split load available (i) in the small line; its tooltip opens above it,
   lined up with its right end (the hero's styles do the rest). The line sits
   at the box's right edge: centred, the tip hung off the screen, and the
   page scrolled sideways (hidden, it still takes up room). */
.product-buy__split {
    align-self: auto;
}

.product-buy__split .product-hero__split-trigger {
    gap: 4px;
    color: inherit;
    font-size: inherit;
    line-height: inherit;
}

.product-buy__split .product-hero__split-tip {
    top: auto;
    right: 0;
    bottom: calc(100% + 8px);
    left: auto;
    text-align: left;
}

/* Collection */
.product-buy__intro {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-top: 12px;
}

.product-buy__heading {
    font-family: var(--font-heading);
    font-size: 28px;
    font-weight: 600;
    line-height: 36px;
}

.product-buy__intro p {
    line-height: 20.8px;
}

.product-buy__intro a {
    color: inherit;
    font-weight: 700;
    text-decoration: none;
}

.product-buy__buttons {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.product-buy__lead {
    line-height: 20.8px;
}

/* ── Mobile: on the grey, no card ───────────────────────────── */
@media (max-width: 767px) {
    .product-buy {
        padding: 0;
        border-radius: 0;
        background: none;
        box-shadow: none;
    }

    .product-buy__modes {
        background: var(--color-white);
    }

    .product-buy__types {
        gap: 12px;
    }

    .product-buy__type {
        padding: 16px;
    }

    .product-buy__type-name {
        gap: 6px;
        font-size: 16px;
        line-height: 20px;
    }

    .product-buy__fields--collection {
        flex-direction: column;
        gap: 12px;
    }

    .product-buy__select,
    .product-buy__fields--collection .product-buy__select:last-child {
        flex: 1;
    }

    .product-buy__fields:not(.product-buy__fields--collection) .product-buy__select {
        flex: 0 0 130px;
    }

    .product-buy__trade {
        justify-content: flex-start;
        text-align: left;
    }

    .product-buy__collect-note {
        text-align: center;
    }

    /* The line wraps to the left edge here: the tip starts there too */
    .product-buy__split .product-hero__split-tip {
        right: auto;
        left: 0;
    }
}
