/**
 * Respond - AP - B2B Wholesale
 *
 * Loaded only on the pages listed in RESPOND_AP_B2B_STYLE_PAGE_IDS
 * (see respond-ap-b2b-wholesale.php). Add trade-only rules here rather than
 * to the theme stylesheet, so they stay scoped to the trade pages.
 */

.registration-form h2 {
    display: none;
}

/**
 * Register button, matched to the site's primary add to cart button.
 *
 * Declarations mirror the shared rule in child-theme.css that styles
 * a.wp-block-button__link.add_to_cart_button, the proceed to checkout link and
 * the place order button. That rule sets background twice (#000 then #5b201a),
 * so #5b201a is the value that actually applies; only that one is repeated here.
 *
 * Those are all <a> elements, whereas this is a real <button>, so the border,
 * radius and cursor resets below are needed to make the two look identical.
 *
 * The selector is deliberately element-qualified: WooCommerce's own
 * "button.button" rules would otherwise outrank a single class on its own.
 */
form.woocommerce-form-register button.woocommerce-form-register__submit {
    color: #fff;
    background: #5b201a;
    font-size: 1.1rem;
    font-family: "Poppins", sans-serif;
    text-transform: uppercase;
    text-decoration: none;
    text-align: center;
    padding: 25px 50px;
    min-width: 210px;
    outline: 1px solid #ffffff;
    outline-offset: -6px;
    border: 0;
    border-radius: 0;
    cursor: pointer;
}

form.woocommerce-form-register button.woocommerce-form-register__submit:hover,
form.woocommerce-form-register button.woocommerce-form-register__submit:focus {
    color: #fff;
    background: #000;
}

/**
 * All fields in the registration form, given one consistent appearance.
 *
 * Only the WooCommerce email field carries Bootstrap's .form-control, so it
 * alone was picking up a height and a border. The trade fields injected by the
 * B2B plugin have no such class and fall back to browser defaults, which is why
 * they disagreed. Everything is stated explicitly here instead.
 *
 * The :not() exclusions keep the newsletter checkbox and the hidden inputs out
 * of it, and they also lift the specificity above WooCommerce's own
 * ".woocommerce form .form-row input.input-text" rules, which woocommerce.css
 * loads on this page and which would otherwise win on the border and font size.
 *
 * The third selector looks redundant against the second, and for matching it is,
 * but each selector in a list carries its own specificity. The long form is what
 * lets the selects outrank WooCommerce's own ".woocommerce form .form-row select"
 * rule, which the short form loses to.
 */
.registration-form input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]):not([type="submit"]),
.registration-form select,
.registration-form .woocommerce form .form-row select {
    border: 1px solid #000;
    border-radius: 0 !important;
    font-size: 16px;
    line-height: 1.2rem;
    background: rgb(248, 248, 248);
    height: calc(2em + 0.75rem + 2px);
    box-sizing: border-box;
    padding: 10px 10px 7px;
}

/**
 * Placeholders.
 *
 * font-size carries !important here, and it is not belt-and-braces. Around
 * line 19101 of the child theme's child-theme.css sit five rules whose
 * selector list ends in a bare, unscoped placeholder selector:
 *
 *     #ajaxsearchlite1 .probox .proinput input,
 *     div.asl_w .probox .proinput input,
 *     ::placeholder { font-family: "Halant", serif !important;
 *                     font-size: 14px !important; }
 *
 * That third selector was meant to be the ajax search input's own placeholder,
 * but as written it matches every placeholder on the site, and !important beats
 * any specificity a normal declaration can reach. Until that rule is scoped
 * properly, !important is the only way to set a placeholder size here.
 *
 * Note the same rule also forces "Halant", serif on placeholders site-wide,
 * which is left alone deliberately: changing the typeface is a design call.
 *
 * Each vendor prefix needs its own rule: browsers discard an entire selector
 * list if any single selector in it is one they do not recognise, so combining
 * these would silently kill the whole block.
 *
 * Selects are left out, as a <select> has no placeholder. The B2B plugin does
 * put a placeholder attribute on its selects, but browsers ignore it.
 */
.registration-form input::placeholder {
    font-size: 16px !important;
    line-height: 1.2rem;
    opacity: 1;
}

.registration-form input::-webkit-input-placeholder {
    font-size: 16px !important;
    line-height: 1.2rem;
}

.registration-form input::-moz-placeholder {
    font-size: 16px !important;
    line-height: 1.2rem;
    opacity: 1;
}

/**
 * Two column field layout.
 *
 * Grid goes on the form itself because the field wrappers are not a consistent
 * element: the WooCommerce rows are <p class="form-row">, while the trade
 * fields are each wrapped in their own <div class="b2bking_custom_registration_
 * container"> by B2BKing. WooCommerce's own form-row-first / form-row-last
 * float classes cannot cope with that mix, and the B2B plugin puts
 * form-row-wide on everything regardless. Grid on the parent treats both
 * wrapper types identically, so the mix stops mattering.
 *
 * Single column below the breakpoint, which is why this is all inside the
 * media query rather than being undone at small sizes.
 *
 * Field widths are already handled: B2BKing sets
 * .b2bking_custom_registration_field { width: 100% } in its own stylesheet.
 *
 * B2BKing also prints a "User Type" row (p.b2bking_registration_roles_dropdown_
 * section) as a direct child of the form. It needs no rule here: with the
 * registration role set on the shortcode, B2BKing gives it a class that it
 * hides with display: none !important, and a display: none element takes no
 * grid cell.
 */
@media (min-width: 768px) {
    .registration-form form.woocommerce-form-register {
        display: grid;
        grid-template-columns: 1fr 1fr;
        column-gap: 20px;
        align-items: end;
    }

    /* Neither of these is a field, and both would otherwise claim a grid cell
       and push every field after them into the wrong column. div.clear is a
       float clearer with nothing to clear once this is a grid, and
       wc-order-attribution-inputs holds only hidden inputs but, being a custom
       element, still defaults to display: inline and so still takes a cell. */
    .registration-form form.woocommerce-form-register > div.clear,
    .registration-form form.woocommerce-form-register > wc-order-attribution-inputs {
        display: none;
    }

    /**
     * Rows that run the full width rather than sitting in one column.
     *
     * p:first-child is the email address row, and the :has() alongside it says
     * so explicitly in case the field order ever changes.
     *
     * p:not([class]) is the "A password will be sent to your email address."
     * note. WooCommerce outputs it with no class or id of any kind, and it is
     * the only classless <p> in the form, so that is the one reliable hook on it.
     *
     * p:last-child is the row holding the Register button.
     */
    .registration-form form.woocommerce-form-register > p:first-child,
    .registration-form form.woocommerce-form-register > p:has(#reg_email),
    .registration-form form.woocommerce-form-register > p:not([class]),
    .registration-form form.woocommerce-form-register > p.statement,
    .registration-form form.woocommerce-form-register > a.legal,
    .registration-form form.woocommerce-form-register > p.mailchimp-newsletter,
    .registration-form form.woocommerce-form-register > p:last-child {
        grid-column: 1 / -1;
    }
}

/**
 * Country and State row.
 *
 * A note on the markup, because it is not what it looks like: B2BKing prints a
 * <p> inside a <p> here, which is invalid, so the browser auto-closes the outer
 * one the moment the inner opens. In the real DOM
 * p.b2bking_country_or_state therefore holds only the "Country and State" label,
 * and p.b2bking_country_field_selector and p#billing_state_field are its
 * siblings, not its children. That is why all three are addressed separately
 * below rather than through one descendant selector.
 *
 * Hiding the country selector is safe: the <p> wraps a hidden input carrying
 * the country value (GB), and CSS display has no bearing on whether a field is
 * submitted. Only the disabled attribute would drop it from the POST.
 */
.registration-form .b2bking_country_field_selector {
    display: none;
}

/**
 * Both wrappers need to beat two layers of existing rules:
 *
 *   .woocommerce form .form-row  { padding: 3px; margin: 0 0 6px }  (0,2,2)
 *   .mb-3, .my-3 { margin-bottom: 1rem !important }
 *
 * The selectors below are scoped through .woocommerce form to reach (0,3,2)
 * and (1,2,2), which clears the first. The second is !important, so setting the
 * margin needs !important too: both these <p> elements carry Bootstrap's mb-3.
 *
 * The two are separate rules because they want different spacing. The label
 * wrapper is collapsed to nothing, while the State / County field keeps the
 * padding and bottom margin every other form row has, so it sits in line with
 * the fields around it.
 */
.registration-form .woocommerce form p.b2bking_country_or_state {
    padding: 0;
    margin: 0 !important;
    width: 100%;
}

.registration-form .woocommerce form p#billing_state_field {
    padding: 3px;
    margin: 0 0 6px !important;
    width: 100%;
}


/**
 * Section headings and their notes, plus one forced row break.
 *
 * Both are injected by respond-ap-b2b-wholesale.php as real elements, siblings
 * of the field containers, so each is a grid item in its own right and can span
 * both columns. Heading styling is deliberately left to the theme's own h3
 * rule, so they match section headings elsewhere on the site.
 *
 * The reference block layout is handled inside the media query below.
 */
.registration-form .field-group-heading {
    border: 0;
    margin-top: 20px;
}

.registration-form .field-group-note {
    margin-bottom: 15px;
}

/**
 * Labels that stay visible sit directly above a select, so their inherited
 * bottom margin (label { margin-bottom: 0.5rem } in child-theme.css around
 * line 245) only opens a gap between the two.
 */
.registration-form form.woocommerce-form-register p:has(select) label {
    margin-bottom: 0;
}

@media (min-width: 768px) {
    .registration-form form.woocommerce-form-register > .field-group-heading,
    .registration-form form.woocommerce-form-register > .field-group-note {
        grid-column: 1 / -1;
    }

    /*
     * Field containers that run the full width instead of pairing up.
     *
     * The class is added by respond-ap-b2b-wholesale.php to the fields named
     * in RESPOND_AP_B2B_FULL_WIDTH_FIELDS, which are:
     *
     *   Entity Type, the only select among the trade fields
     *   Reference 1 Name
     *   Reference 2 Name
     *
     * The reference Names being full width leaves each reference's Address and
     * Phone to pair up on the row beneath it:
     *
     *     Reference 1 Name
     *     Reference 1 Address   |  Reference 1 Phone Number
     *     Reference 2 Name
     *     Reference 2 Address   |  Reference 2 Phone Number
     *
     * That also replaced an earlier grid-column-start on Reference 2 Name,
     * which existed to stop it pairing alongside Reference 1 Phone Number and
     * is redundant now: a full width item always begins a new row.
     *
     * Note that a full width field shifts the pairing of everything after it by
     * one, since the columns simply fill in document order.
     */
    .registration-form form.woocommerce-form-register > div.field-full-width {
        grid-column: 1 / -1;
    }
}

/**
 * Trade statements and the terms link.
 *
 * a.legal is an <a>, so margin-bottom on it would be ignored while it is still
 * inline. inline-block fixes that below the two column breakpoint; above it the
 * link is a grid item and gets blockified anyway, so the margin applies there
 * either way.
 */
.registration-form p.statement {
    font-size: 0.9rem;
}

/**
 * "A password will be sent to your email address."
 *
 * WooCommerce prints that note with no class or id, and it is the only classless
 * <p> in the form, so :not([class]) is the one reliable hook on it. The same
 * selector is used in the grid block above to make it span both columns.
 */
.registration-form form.woocommerce-form-register > p:not([class]) {
    font-size: 0.9rem;
}

.registration-form a.legal {
    display: inline-block;
    font-size: 0.9rem;
    margin-bottom: 30px;
}

/**
 * Checkbox labels: separate the label text from the box itself.
 *
 * Left unscoped from .registration-form on purpose. This stylesheet only loads
 * on the two trade pages already, and page 38732 does not necessarily carry
 * that wrapper class, so scoping it would stop the rule applying there.
 */
.woocommerce-form__label-for-checkbox span {
    padding-left: 5px;
}

/**
 * Field labels: hidden, except on selects and checkboxes.
 *
 * Written as one exclusion rather than a blanket hide plus two re-enabling
 * rules, so the labels that stay visible keep whatever display value they
 * already had. WooCommerce leaves them inline and relies on the 100% wide input
 * wrapping onto the next line, so re-declaring display: block on the ones we
 * keep would quietly change how they sit.
 *
 * :has(select) covers the select case: the label and the select are siblings
 * inside the same <p>, and CSS has no previous-sibling selector, so the test
 * has to be made from their shared parent.
 *
 * These are hidden visually but left in the accessibility tree, using the same
 * clip technique as the theme's own .screen-reader-text (child-theme.css around
 * line 10528) with clip-path added, since clip is deprecated. display: none
 * would have dropped them from the tree entirely, leaving screen reader users
 * on a trade application form with nothing but placeholder text, which is not a
 * reliable accessible name.
 *
 * That only works because each label is tied to its field. B2BKing prints a
 * matching "for" on every label it renders, as WooCommerce does on its own, so
 * the association is already there to preserve. A label without one would
 * announce nothing however it was hidden.
 */
.registration-form form.woocommerce-form-register p:not(:has(select)) label:not(.woocommerce-form__label-for-checkbox) {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    clip-path: inset(50%);
    white-space: nowrap;
    border: 0;
}

/**
 * Mailchimp's own opt-in checkbox.
 *
 * Hidden because the trade form carries its own marketing checkbox, worded as
 * an opt out, and that one is the control. Mailchimp's box would be a second
 * control saying the opposite thing.
 *
 * Safe to hide: respond-ap-b2b-wholesale.php sets the POST value this box would
 * have carried, so what it renders as no longer decides anything. It is left
 * unticked, so even if that bridge were removed this box would post nothing
 * rather than silently subscribing people.
 */
.registration-form .mailchimp-newsletter {
    display: none;
}
