/**
 * MG Red Shift - one button, one field, one focus ring (Etap 9, mini design system D).
 *
 * Loaded on every page after woocommerce.css and before the page sheets (cart, checkout, order received, account).
 * Page sheets give buttons layout only, never their look. Values come from variables.css.
 * A page sheet MAY set on a mapped button: width, min-width, max-width, margin, order, flex / flex-*, align-self,
 * position. It CANNOT (they lose to the base at (0,4,0) unless the page rule is at least that strong and prints later):
 * display, padding, white-space, overflow-wrap, justify-content, align-items, gap, height, min-height, line-height,
 * text-align, transform, and every colour, border, radius, shadow and font property. Change those here.
 *
 * Specificity, with no important flags: the selector lists sit in :where() (no weight of their own) behind a repeated
 * :root, so every level has one known weight that is independent of the list:
 *   - base (button, field):  :root x4 :where(...)   (0,4,0)  beats Astra's inline button rules, up to (0,3,1)
 *                                                            (.woocommerce .woocommerce-message a.button)
 *   - variants, sizes:       :root x5 :where(...)   (0,5,0)  later in the file
 *   - focus ring:            :root x5 :focus-visible (0,6,0)  beats Astra's focus list, up to (0,5,1)
 *   (the field base adds :not(.qty), so it weighs (0,5,0); field refinements that must beat it, such as the textarea
 *   padding, sit at :root x5 later in the file)
 * Hover adds (0,1,0) to its level. Single exception: WooCommerce's grid sheet sets the product form button's padding
 * at (0,5,2); that rule is repeated below with the same selector.
 *
 * Mapping (Etap 9 plan, Task 1):
 *   primary 48   theme .mgredline-btn(-primary), WooCommerce .button, main add to basket, block cart / checkout buttons,
 *                thank-you "Continue shopping", empty-cart "Back to shop", mini cart checkout, account submit,
 *                the header search and the product search submit (.mgredline-search-form, .woocommerce-product-search)
 *   primary 44   listing cards and recommendation rows, the cart's cross-sell "Add to basket" (block button)
 *   secondary    .mgredline-btn-outline, mini cart "View basket", account buttons, "Register", Customer Reviews
 *                "Add a review" (48);
 *                "Withdraw" order action (EU Order Withdrawal Button, key withdrawal_link: thank-you page and
 *                My account order view) (48);
 *                "Frequently bought together", notice "View basket", coupon "Apply", mini cart suggestion (44)
 *   44 sizes     also My account Orders row actions (padding 0 14px)
 *   icon button  the header search submit (#mgredline-header-search, 48x48, icon only): padding 0
 * Fields: account / order-received / order-pay forms, block text inputs and selects, the coupon field, the checkout
 *   order note (textarea, 100px), the withdrawal form (EU Order Withdrawal Button), the header search and the product
 *   search field (.mgredline-search-form, .woocommerce-product-search).
 *   ghost        .mgredline-btn-secondary, .mgredline-btn-outline-white (dark backgrounds); footer withdrawal (Etap 7)
 *   light        .mgredline-btn-light (white on a dark or red background)
 * Outside the system (own rules): main menu, #mgrs-pbar, .cmplz-*, quantity +/- buttons, header icons.
 */

/* ===================================================================== */
/* Button: base (primary)                                                 */
/* ===================================================================== */

:root:root:root:root :where(
    .mgredline-btn,
    .woocommerce .button,
    .woocommerce-page .button,
    .woocommerce input[type="submit"],
    .woocommerce .single_add_to_cart_button,
    ul.products li.product .button,
    .wc-block-components-button:not(.is-link),
    .wp-block-woocommerce-empty-cart-block .wp-block-button__link,
    .mgredline-thankyou-next-steps__shop,
    .mgredline-sticky-atc__button,
    .woocommerce-account .mgredline-my-account button[type="submit"],
    .cr-reviews-ajax-reviews .cr-nosummary-add,
    .astra-cart-drawer .cart-btn,
    .astra-cart-drawer .button,
    .wp-block-woocommerce-cart-cross-sells-block .wc-block-components-product-button__button,
    .mgredline-search-form button[type="submit"],
    .woocommerce-product-search button[type="submit"]
) {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    box-sizing: border-box;
    min-height: var(--control-height);
    height: auto;
    padding: 0 24px;
    border: 1px solid var(--primary-color);
    border-radius: var(--radius-control);
    background-color: var(--primary-color);
    background-image: none;
    box-shadow: none;
    color: var(--white);
    font-family: var(--font-heading);
    font-size: 16px;
    font-weight: 700;
    line-height: 1.2;
    letter-spacing: 0;
    text-align: center;
    text-decoration: none;
    text-shadow: none;
    text-transform: none;
    white-space: normal;
    overflow-wrap: break-word; /* wrap between words; a single word longer than the button is the only one split */
    cursor: pointer;
    transform: none;
    transition: background-color 0.2s;
}

:root:root:root:root :where(
    .mgredline-btn,
    .woocommerce .button,
    .woocommerce-page .button,
    .woocommerce input[type="submit"],
    .woocommerce .single_add_to_cart_button,
    ul.products li.product .button,
    .wc-block-components-button:not(.is-link),
    .wp-block-woocommerce-empty-cart-block .wp-block-button__link,
    .mgredline-thankyou-next-steps__shop,
    .mgredline-sticky-atc__button,
    .woocommerce-account .mgredline-my-account button[type="submit"],
    .cr-reviews-ajax-reviews .cr-nosummary-add,
    .astra-cart-drawer .cart-btn,
    .astra-cart-drawer .button,
    .wp-block-woocommerce-cart-cross-sells-block .wc-block-components-product-button__button,
    .mgredline-search-form button[type="submit"],
    .woocommerce-product-search button[type="submit"]
):is(:hover, :active) {
    border-color: var(--primary-color-dark);
    background-color: var(--primary-color-dark);
    background-image: none;
    box-shadow: none;
    color: var(--white);
    transform: none;
}

/* No decorative layers (the old shine sweep). */
:root:root:root:root :where(.mgredline-btn, ul.products li.product .button)::before {
    content: none;
}

/* ===================================================================== */
/* Button: variants                                                       */
/* ===================================================================== */

/* secondary: white, 1px dark border, dark text */
:root:root:root:root:root :where(
    .mgredline-btn-outline,
    .astra-cart-drawer .cart-btn.view-cart,
    .astra-cart-drawer .mgredline-mini-cart-upsell__add.button,
    .mgredline-bought-together .mgredline-bought-together__action .button,
    .woocommerce-message .button,
    .woocommerce-info .button,
    .woocommerce-error .button,
    .woocommerce-message .wc-forward,
    .woocommerce-info .wc-forward,
    .woocommerce-error .wc-forward,
    .woocommerce-message .restore-item,
    .wc-block-components-totals-coupon__button,
    .woocommerce-account .mgredline-my-account .button,
    .woocommerce-form-register .woocommerce-form-register__submit,
    .cr-reviews-ajax-reviews .cr-nosummary-add,
    .order-actions-button.withdrawal_link
) {
    border-color: var(--dark-color);
    background-color: var(--white);
    color: var(--dark-color);
}

:root:root:root:root:root :where(
    .mgredline-btn-outline,
    .astra-cart-drawer .cart-btn.view-cart,
    .astra-cart-drawer .mgredline-mini-cart-upsell__add.button,
    .mgredline-bought-together .mgredline-bought-together__action .button,
    .woocommerce-message .button,
    .woocommerce-info .button,
    .woocommerce-error .button,
    .woocommerce-message .wc-forward,
    .woocommerce-info .wc-forward,
    .woocommerce-error .wc-forward,
    .woocommerce-message .restore-item,
    .wc-block-components-totals-coupon__button,
    .woocommerce-account .mgredline-my-account .button,
    .woocommerce-form-register .woocommerce-form-register__submit,
    .cr-reviews-ajax-reviews .cr-nosummary-add,
    .order-actions-button.withdrawal_link
):is(:hover, :active) {
    border-color: var(--dark-color);
    background-color: var(--light-gray);
    color: var(--dark-color);
}

/* primary again where a secondary default above also matches: listing cards (also inside the account), the account
   form's main action (submit, .button.alt), "Pay" and "Order again"; the cart's cross-sell "Add to basket" (a listing
   card button, kept red here so no secondary list can catch it) */
:root:root:root:root:root :where(
    ul.products li.product .button,
    .woocommerce-account .mgredline-my-account button[type="submit"]:not(.woocommerce-form-register__submit),
    .woocommerce-account .mgredline-my-account input[type="submit"],
    .woocommerce-account .mgredline-my-account .button.alt,
    .woocommerce-account .mgredline-my-account .button.pay,
    .woocommerce-account .mgredline-my-account .order-actions-button.order-again,
    .woocommerce-account .mgredline-my-account .mgredline-btn-primary,
    .wp-block-woocommerce-cart-cross-sells-block .wc-block-components-product-button__button
) {
    border-color: var(--primary-color);
    background-color: var(--primary-color);
    color: var(--white);
}

:root:root:root:root:root :where(
    ul.products li.product .button,
    .woocommerce-account .mgredline-my-account button[type="submit"]:not(.woocommerce-form-register__submit),
    .woocommerce-account .mgredline-my-account input[type="submit"],
    .woocommerce-account .mgredline-my-account .button.alt,
    .woocommerce-account .mgredline-my-account .button.pay,
    .woocommerce-account .mgredline-my-account .order-actions-button.order-again,
    .woocommerce-account .mgredline-my-account .mgredline-btn-primary,
    .wp-block-woocommerce-cart-cross-sells-block .wc-block-components-product-button__button
):is(:hover, :active) {
    border-color: var(--primary-color-dark);
    background-color: var(--primary-color-dark);
    color: var(--white);
}

/* ghost: transparent on a dark background, 2px white border, white text */
:root:root:root:root:root :where(.mgredline-btn-secondary, .mgredline-btn-outline-white) {
    border: 2px solid var(--white);
    background-color: transparent;
    color: var(--white);
}

:root:root:root:root:root :where(.mgredline-btn-secondary, .mgredline-btn-outline-white):is(:hover, :active) {
    border-color: var(--white);
    background-color: rgba(255, 255, 255, 0.12);
    color: var(--white);
}

/* light: white button with dark text on a dark or red background */
:root:root:root:root:root :where(.mgredline-btn-light) {
    border-color: var(--white);
    background-color: var(--white);
    color: var(--dark-color);
}

:root:root:root:root:root :where(.mgredline-btn-light):is(:hover, :active) {
    border-color: var(--light-gray);
    background-color: var(--light-gray);
    color: var(--dark-color);
}

/* Withdrawal button (EU Order Withdrawal Button, Etap 7): deliberately not a .button, a calm outline that stands out
   from the footer links. Ghost with a 1px light border on the dark footer; dark outline on light backgrounds. */
:root:root:root:root:root :where(.mgredline-withdrawal-link) {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    box-sizing: border-box;
    min-height: var(--control-height-sm);
    padding: 0 24px;
    border: 1px solid var(--dark-color);
    border-radius: var(--radius-control);
    background-color: transparent;
    background-image: none;
    box-shadow: none;
    color: var(--dark-color);
    font-family: var(--font-heading);
    font-size: 16px;
    font-weight: 700;
    line-height: 1.2;
    letter-spacing: 0;
    text-align: center;
    text-decoration: none;
    text-transform: none;
    transition: background-color 0.2s;
}

:root:root:root:root:root :where(.mgredline-withdrawal-link):is(:hover, :active) {
    background-color: rgba(0, 0, 0, 0.05);
    color: var(--dark-color);
}

:root:root:root:root:root :where(.footer-action-bar .mgredline-withdrawal-link) {
    border-color: rgba(255, 255, 255, 0.7);
    color: var(--white);
}

:root:root:root:root:root :where(.footer-action-bar .mgredline-withdrawal-link):is(:hover, :active) {
    border-color: var(--white);
    background-color: rgba(255, 255, 255, 0.08);
    color: var(--white);
}

/* ===================================================================== */
/* Button: compact size (44px)                                            */
/* ===================================================================== */

:root:root:root:root:root :where(
    ul.products li.product .button,
    .mgredline-sticky-atc__button,
    .mgredline-bought-together .mgredline-bought-together__action .button,
    .woocommerce-message .button,
    .woocommerce-info .button,
    .woocommerce-error .button,
    .woocommerce-message .wc-forward,
    .woocommerce-info .wc-forward,
    .woocommerce-error .wc-forward,
    .woocommerce-message .restore-item,
    .wc-block-components-totals-coupon__button,
    .astra-cart-drawer .mgredline-mini-cart-upsell__add.button,
    .wp-block-woocommerce-cart-cross-sells-block .wc-block-components-product-button__button,
    .woocommerce-account .mgredline-my-account .woocommerce-orders-table__cell-order-actions .button
) {
    min-height: var(--control-height-sm);
}

/* My account Orders: the row actions ("View", "Pay", "Cancel") sit side by side in a narrow cell. */
:root:root:root:root:root :where(.woocommerce-account .mgredline-my-account .woocommerce-orders-table__cell-order-actions .button) {
    padding: 0 14px;
}

/* Listing cards: narrow columns (2 per row on phones), so less side padding; long labels wrap between words. */
:root:root:root:root:root :where(
    ul.products li.product .button,
    .mgredline-bought-together .mgredline-bought-together__action .button,
    .wp-block-woocommerce-cart-cross-sells-block .wc-block-components-product-button__button
) {
    padding: 0 12px;
}

/* 320-360px: a card is ~95px wide; 8px sides leave 77px, enough for the longest word of the 8 translations
   ("Hinzufügen" 76px, "Warenkorb" 73px in Rajdhani 700 16px). */
@media (max-width: 360px) {
    :root:root:root:root:root :where(ul.products li.product .button) {
        padding: 0 8px;
    }
}

/* Below 360px, 4px: "Add to basket" (91px) fits the 119px card at 320 (woocommerce.css widens the button, 2.21.1). */
@media (max-width: 359.98px) {
    :root:root:root:root:root :where(ul.products li.product .button) {
        padding: 0 4px;
    }
}

/* Icon-only square button in the header search panel: the base's 0 24px padding would make it 50px wide inside its
   48px width (components/dynamic.css). The id outweighs the base (0,4,0). Moved from dynamic.css in Etap 13. */
#mgredline-header-search button[type="submit"] {
    padding: 0;
}

/* The main add to basket button: WooCommerce's grid sheet sets padding at (0,5,2). */
.woocommerce-js div.product form.cart .button.single_add_to_cart_button {
    padding: 0 24px;
    max-width: 100%;
}

/* ===================================================================== */
/* Field                                                                  */
/* ===================================================================== */

:root:root:root:root :where(
    :is(.woocommerce-account, .woocommerce-order-received, .woocommerce-order-pay) .woocommerce form :is(.input-text, select, textarea),
    .wc-block-components-text-input input,
    .wc-block-components-totals-coupon__input input,
    .wc-blocks-components-select .wc-blocks-components-select__select,
    .wc-block-checkout__add-note textarea,
    .woocommerce-form.order-withdrawal-request :is(.input-text, select),
    .mgredline-search-form input[type="search"],
    .woocommerce-product-search input[type="search"]
):not(.qty) {
    box-sizing: border-box;
    min-height: var(--control-height);
    padding: 0 16px;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-control);
    background-color: var(--white);
    box-shadow: none;
    color: var(--text-color);
    font-family: var(--font-primary);
    font-size: 16px;
}

/* Textareas: the base field above weighs (0,5,0) with its :not(.qty), so these sit at :root x5. */
/* keep: the checkout note textarea opens only after ticking its checkbox */
:root:root:root:root:root :where(
    :is(.woocommerce-account, .woocommerce-order-received, .woocommerce-order-pay) .woocommerce form textarea,
    .wc-block-checkout__add-note textarea
) {
    padding-top: 12px;
    padding-bottom: 12px;
}

/* Withdrawal form select (EU Order Withdrawal Button): room on the right for its caret (order-withdrawal.css). */
/* keep: the order select shows only to logged-in customers with orders */
:root:root:root:root:root :where(.woocommerce-form.order-withdrawal-request select) {
    padding-right: 40px;
}

/* Checkout "Add a note to your order" (WooCommerce .wc-block-components-textarea): room for a few lines. */
/* keep: the checkout note textarea opens only after ticking its checkbox */
:root:root:root:root:root :where(.wc-block-checkout__add-note textarea) {
    min-height: 100px;
}

:root:root:root:root :where(:is(.woocommerce-account, .woocommerce-order-received, .woocommerce-order-pay) .woocommerce form, .wc-block-components-form, .wc-block-components-totals-coupon, .woocommerce-form.order-withdrawal-request) ::placeholder {
    color: var(--text-muted);
    opacity: 1;
}

/* Error: red border; the message sits under the field, 14px. */
:root:root:root:root:root :where(.woocommerce-invalid .input-text, .woocommerce-invalid select, .wc-block-components-text-input.has-error input, [aria-invalid="true"]) {
    border-color: var(--primary-color-dark);
}

:root:root:root:root :where(.wc-block-components-validation-error, .woocommerce-form-row .woocommerce-error-message, .mgredline-field-error) {
    font-size: 14px;
}

/* Hint under a field (e.g. "For the courier" under the phone, Task 3). */
.mgredline-field-hint {
    display: block;
    margin: 4px 0 0;
    color: var(--text-muted);
    font-size: 14px;
    line-height: 1.4;
}

/* Checkbox and radio: 24px (WCAG 2.5.8); their labels are 44px tall targets. */
:root:root:root:root :where(:is(.woocommerce-account, .woocommerce-order-received, .woocommerce-order-pay) .woocommerce form, .wc-block-components-checkbox, .wc-block-components-radio-control) :where(input[type="checkbox"], input[type="radio"]) {
    width: 24px;
    height: 24px;
    min-width: 24px;
    min-height: 24px;
}

/* Block checkbox and radio border >= 3:1 (WooCommerce draws them in #808285 at 80%, 2.8:1); dark when checked. */
:root:root:root:root :where(.wc-block-components-checkbox, .wc-block-components-radio-control) :where(input[type="checkbox"], input[type="radio"]) {
    border: 1px solid var(--border-strong);
}

:root:root:root:root :where(.wc-block-components-checkbox, .wc-block-components-radio-control) :where(input[type="checkbox"], input[type="radio"]):checked {
    border-color: var(--dark-color);
}

:root:root:root:root :where(:is(.woocommerce-account, .woocommerce-order-received, .woocommerce-order-pay) .woocommerce form .woocommerce-form__label-for-checkbox, .wc-block-components-checkbox label) {
    min-height: var(--control-height-sm);
    display: inline-flex;
    align-items: center;
}

/* ===================================================================== */
/* Focus                                                                  */
/* ===================================================================== */

/* One ring everywhere: 3px brand red, 2px off the element. Never removed without this replacement. No transition:
   a `transition: all` on the element faded the ring in from its dark text colour (2.21.1, UX D1). */
:root:root:root:root:root :focus-visible {
    outline: var(--focus-ring);
    outline-offset: var(--focus-offset);
    transition: none;
}

/* On dark or red backgrounds (header, footer, home hero / CTA, Technology hero and CTA) the ring is white. */
:root:root:root:root:root :is(
    .site-header,
    .site-footer,
    .mgredline-hero,
    .mgredline-cta,
    .mgredline-tech-hero,
    .mgredline-tech-cta,
    .mgredline-dark-surface
) :focus-visible {
    outline: var(--focus-ring-dark);
}

/* ...except inside the white panels that open from the header (mini cart, search panel .mgredline-search-form).
   The mobile menu panel is dark (#1a1a1a) and keeps the white ring. */
:root:root:root:root:root .site-header :is(.astra-cart-drawer, .mgredline-search-form) :focus-visible {
    outline: var(--focus-ring);
}

/* Rings drawn inside the element where a scrolling or clipping parent would cut an outside ring: the account menu
   (a horizontally scrolling tab bar on phones), the show-password toggle inside its field, the product image link. */
:root:root:root:root:root :is(
    .woocommerce-MyAccount-navigation a,
    .password-input .show-password-input,
    .woocommerce-product-gallery__image a
):focus-visible {
    outline-offset: -3px;
}

/* Script focus targets outside the Tab order (tabindex="-1"): a notice focused so screen readers announce it, the mini
   cart title focused when the panel opens. Chrome counts script focus without prior pointer input as :focus-visible
   and would ring the whole box; these are not controls (WCAG 2.4.7 covers keyboard-operable UI), so no ring. Links
   and buttons inside them keep the ring. */
:root:root:root:root:root :is(
    .woocommerce-message,
    .woocommerce-info,
    .woocommerce-error,
    .wc-block-components-notice-banner,
    #mgredline-mini-cart-title
)[tabindex="-1"]:focus {
    outline: none;
}
