/*
 * Quantity calculator (Tts\Ui\QuantityCalculator, quantity-calculator.js):
 * the order form. How to calculate (m², tiles, width × length) as a segmented
 * choice, the field(s) with their unit inside, the result - tiles or packs and
 * the price - and the order button under it, full width. The fields are the
 * design's (form.css): 48px, 16px text so iOS does not zoom.
 *
 * input.-qualified: base.css and Foundation style inputs at (0,1,1)
 * (Decision 5).
 */

.quantity-calculator {
    display: grid;
    gap: var(--shop-space-3);
    margin: 0;
}

.quantity-calculator__fieldset {
    display: grid;
    gap: var(--shop-space-3);
    min-width: 0;
    margin: 0;
    padding: 0;
    border: 0;
}

.quantity-calculator__legend {
    margin: 0 0 var(--shop-space-3);
    padding: 0;
    color: var(--shop-ink);
    font-size: var(--shop-text-base);
    font-weight: var(--shop-weight-bold);
    line-height: var(--shop-leading-snug);
}

.quantity-calculator__modes {
    display: grid;
    grid-auto-columns: minmax(0, 1fr);
    grid-auto-flow: column;
    padding: 3px;
    border-radius: var(--shop-radius-md);
    background: var(--shop-surface-subtle);
}

.quantity-calculator__modes[hidden] {
    display: none;
}

.quantity-calculator__mode {
    display: grid;
    margin: 0;
    cursor: pointer;
}

/* The radio stays in the page (keyboard, screen readers), under its label. */
.quantity-calculator__mode input {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: 0;
    opacity: 0;
}

.quantity-calculator__mode span {
    display: grid;
    place-items: center;
    min-height: 40px;
    padding: 0 var(--shop-space-2);
    border: 1px solid transparent;
    border-radius: calc(var(--shop-radius-md) - 2px);
    color: var(--shop-text);
    font-size: var(--shop-text-md);
    font-weight: var(--shop-weight-semibold);
    line-height: var(--shop-leading-tight);
    text-align: center;
}

.quantity-calculator__mode input:checked + span {
    /* The border carries the state: the pill's white on the track's near-white
       is 1.12:1, well under the 3:1 a control's state needs. */
    border: 1px solid var(--shop-ink);
    background: var(--shop-surface);
    box-shadow: var(--shop-shadow-card);
    color: var(--shop-ink);
}

.quantity-calculator__mode input:focus-visible + span {
    outline: 2px solid var(--shop-accent);
    outline-offset: 1px;
}

.quantity-calculator__panel {
    display: grid;
    gap: var(--shop-space-1);
}

.quantity-calculator__panel[hidden] {
    display: none;
}

.quantity-calculator__panel--dimensions {
    grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
    align-items: end;
    gap: var(--shop-space-2);
}

.quantity-calculator__panel--dimensions > div {
    display: grid;
    /* minmax(0, 1fr): the field follows the column, not its own content width,
       which overflowed the panel (and the phone) once this mode was chosen. */
    grid-template-columns: minmax(0, 1fr);
    gap: var(--shop-space-1);
}

.quantity-calculator__times {
    display: grid;
    place-items: center;
    height: 48px;
    color: var(--shop-text-soft);
}

.quantity-calculator__label {
    margin: 0;
    color: var(--shop-text);
    font-size: var(--shop-text-md);
    line-height: var(--shop-leading-snug);
}

.quantity-calculator__control {
    display: flex;
    align-items: center;
    min-height: 48px;
    border: 1px solid var(--shop-border-input);
    border-radius: var(--shop-radius-md);
    background: var(--shop-surface);
}

.quantity-calculator__control:focus-within {
    border-color: var(--shop-accent);
    outline: 2px solid var(--shop-accent);
    outline-offset: 0;
}

.quantity-calculator__control:has([aria-invalid="true"]),
.quantity-calculator__control:has([aria-invalid="true"]):focus-within {
    border-color: var(--shop-warning-text);
    outline-color: var(--shop-warning-text);
}

input.quantity-calculator__input,
input.quantity-calculator__input:focus {
    flex: 1;
    min-width: 0;
    height: 46px;
    margin: 0;
    padding: 0 var(--shop-space-3);
    border: 0;
    outline: none;
    background: none;
    box-shadow: none;
    color: var(--shop-ink);
    font-family: var(--shop-font);
    font-size: var(--shop-text-base);
    font-variant-numeric: tabular-nums;
    appearance: textfield;
}

.quantity-calculator__input::-webkit-inner-spin-button,
.quantity-calculator__input::-webkit-outer-spin-button {
    margin: 0;
    appearance: none;
}

.quantity-calculator__suffix {
    flex: none;
    padding-inline-end: var(--shop-space-3);
    color: var(--shop-text-soft);
    font-size: var(--shop-text-md);
}

/* The result: what will be ordered and its price, on one line when it fits. */
.quantity-calculator__summary {
    /* One line held whether or not there is a result: the order button below it
       must not move while a quantity is being typed. */
    min-height: 2.5rem;
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    justify-content: space-between;
    gap: var(--shop-space-1) var(--shop-space-3);
    margin: 0;
    padding: var(--shop-space-3);
    border-radius: var(--shop-radius-md);
    background: var(--shop-accent-soft);
}

.quantity-calculator__summary:empty {
    background: none;
}

.quantity-calculator__result {
    color: var(--shop-text);
    font-size: var(--shop-text-md);
    line-height: var(--shop-leading-snug);
}

/* A partij's summary has no total beside it (its price is the page's): what the
   lot holds is the bar's one statement, so it carries the weight the total would. */
.quantity-calculator__result--lot {
    color: var(--shop-ink);
    font-weight: var(--shop-weight-semibold);
}

.quantity-calculator__total {
    color: var(--shop-ink);
    font-size: var(--shop-text-xl);
    font-weight: var(--shop-weight-bold);
    line-height: var(--shop-leading-tight);
    font-variant-numeric: tabular-nums;
}

.quantity-calculator__error {
    display: flex;
    align-items: flex-start;
    gap: var(--shop-space-2);
    margin: 0;
    padding: var(--shop-space-3);
    border: 1px solid var(--shop-warning-border);
    border-radius: var(--shop-radius-md);
    background: var(--shop-warning-surface);
    color: var(--shop-warning-text);
    font-size: var(--shop-text-md);
    font-weight: var(--shop-weight-semibold);
    line-height: var(--shop-leading-snug);
}

/* The same mark the notice component uses, so a warning looks like a warning
   wherever it appears. */
.quantity-calculator__error::before {
    content: "!" / "";
    display: grid;
    flex: none;
    place-items: center;
    width: 1.25rem;
    height: 1.25rem;
    margin-block-start: 0.05rem;
    border-radius: 50%;
    background: var(--shop-warning-text);
    color: var(--shop-surface);
    font-size: var(--shop-text-xs);
    font-weight: var(--shop-weight-bold);
    line-height: 1;
}

.quantity-calculator__error[hidden] {
    display: none;
}

button.quantity-calculator__submit {
    width: 100%;
    min-height: 52px;
    font-size: var(--shop-text-base);
}

.quantity-calculator__hints {
    display: grid;
    gap: 2px;
    margin: 0;
    padding: 0;
    color: var(--shop-text-soft);
    font-size: var(--shop-text-sm);
    line-height: var(--shop-leading-snug);
    list-style: none;
}

.quantity-calculator__hints strong {
    color: var(--shop-text);
}

@media (forced-colors: active) {
    /* Only the chosen tab is drawn: a transparent border is repainted as
       CanvasText, which boxed all three. */
    .quantity-calculator__mode span {
        border-color: Canvas;
    }

    .quantity-calculator__mode input:checked + span {
        border-color: CanvasText;
        outline: 2px solid CanvasText;
    }
}
