/* The structure the widgets need, and nothing else.

   In @layer haya-defaults beside pb-behaviors.css, for the reason CMS-L11
   recorded: an unlayered rule beats a layered one whatever the load order, so
   a sheet outside the layers would quietly outrank both the site's tokens and
   the styles an author wrote in the panel.

   That layering is the whole contract here. Nothing in this file decides a
   colour, a font, a spacing or a radius that the theme has an opinion about —
   it decides what is a row and what is a column, what scrolls and what wraps.
   Everything visible is a token the site owns or a declaration the style
   panel can overrule.

   What is left is the data widgets' structure: the shop's, the account
   area's, the credit line and the form. The coded content widgets — tabs,
   accordion, modal and the rest — are gone (CMS-L89); a converted block
   carries the rules it needs in its own scoped CSS, and a store design
   brings its own. */

@layer haya-defaults {

    /* ── add to cart, when the product cannot be bought (CMS-L38-5) ─────── */

    /* The basket form's status line exists to be filled in (CMS-L89 BR-01);
       display below would otherwise beat the hidden attribute. */
    .product-unavailable[hidden] {
        display: none;
    }

    .product-unavailable {
        display: inline-block;
        margin: 0;
        padding: 0.6em 1em;
        border-radius: var(--radius-md, 8px);
        background: color-mix(in srgb, currentColor 8%, transparent);
        font-weight: 600;
    }

    /* The cart menu (CMS-L58). The control's own look travels with the
       storefront component (CartMenu.razor.css); this only keeps the widget
       box from stretching the trigger across a header row. */
    .pb-cart-menu {
        display: inline-flex;
        align-items: center;
    }

    /* The account menu (CMS-L30). Structure only, like every rule in this sheet:
       what it looks like is the theme's and the author's, and pb-design.css puts
       the tokens on it. The sign-out button is a form control talked back into
       sitting in a row of links. */
    .pb-account-menu {
        display: flex;
        align-items: center;
        gap: 16px;
        flex-wrap: wrap;
    }

    .pb-account-menu__out {
        display: flex;
        margin: 0;
    }

    .pb-account-menu__out button {
        padding: 0;
        border: 0;
        background: none;
        font: inherit;
        color: inherit;
        cursor: pointer;
    }

    /* ── The account menu ─────────────────────────────────────────────────
       Inline is a header's row; stacked is a dashboard's sidebar. The rules
       are structure and the colours are tokens, so a shop that picked its
       own palette keeps its sidebar in it. */

    .pb-account-menu__link {
        display: inline-flex;
        align-items: center;
        gap: 8px;
        padding: 6px 8px;
        border: 0;
        border-radius: var(--radius-sm);
        background: none;
        font: inherit;
        color: inherit;
        text-decoration: none;
        cursor: pointer;
    }

        .pb-account-menu__link:hover {
            background: var(--surface-muted, rgba(0, 0, 0, .04));
        }

        /* Where the reader is. A colour alone would leave this invisible to
           anyone who cannot see it, which is why the markup also carries
           aria-current. */
        .pb-account-menu__link--current {
            background: var(--surface-muted, rgba(0, 0, 0, .06));
            font-weight: 600;
            color: var(--color-text-link);
        }

    .pb-account-menu--stacked {
        display: flex;
        flex-direction: column;
        align-items: stretch;
        /* The inline rule above wraps, which is right for a header's row and
           wrong here: a *column* container that wraps lays its items out in
           columns, so instead of an over-wide item shrinking, the container
           grows to fit it. That is what put a long e-mail address 33px
           outside the sidebar. */
        flex-wrap: nowrap;
        gap: 2px;
    }

        .pb-account-menu--stacked .pb-account-menu__link {
            justify-content: flex-start;
            width: 100%;
            padding: 10px 12px;
        }

        .pb-account-menu--stacked .pb-account-menu__out {
            display: block;
        }

    .pb-account-menu__who {
        display: flex;
        align-items: center;
        gap: 10px;
        /* Without this the block is as wide as the longest word in it and
           pushes out of the sidebar: a flex item's default min-width is its
           content, so the ellipsis below never gets a chance to apply. An
           e-mail address as a display name is the ordinary case, not the
           edge one — somebody who has not set a name yet. */
        min-width: 0;
        padding: 4px 4px 12px;
        margin-block-end: 8px;
        border-block-end: 1px solid var(--color-border);
    }

    .pb-account-menu__avatar {
        display: grid;
        /* It is a circle at a fixed size, so it must not be squeezed when the
           name beside it is long. */
        flex: 0 0 auto;
        place-items: center;
        inline-size: 36px;
        block-size: 36px;
        border-radius: 50%;
        background: var(--surface-muted, #eef4ff);
        color: var(--color-text-link);
        font-weight: 600;
    }

    .pb-account-menu__name {
        font-size: 14px;
        font-weight: 600;
        /* A long name shortens rather than pushing the sidebar wider.
           `min-width: 0` on the row above is not enough on its own: a flex
           item's floor is its content, and the name is the item, so the floor
           has to be lifted here too. `flex: 1 1 0` rather than `auto` for the
           same reason — an auto basis is the content's width, which is the
           thing being contained. Measured, not guessed: it was 34px outside
           the sidebar, spilling past its left edge. */
        flex: 1 1 0;
        min-width: 0;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }
}

/* ── site credit (SiteCredit) ───────────────────────────────────────────── */

@layer haya-defaults {
    .pb-site-credit {
        margin: 0;
        font-size: 0.8125rem;
        color: var(--color-text-muted, #6b7280);
    }

    .pb-site-credit a,
    .pb-site-credit-name {
        color: inherit;
        font-weight: 600;
        text-decoration: none;
    }

    .pb-site-credit a:hover {
        text-decoration: underline;
    }

    /* What the storefront draws under a footer that does not carry the
       widget: a page built without the agent, a hidden footer, an old one. */
    .store-fallback-credit {
        padding-block: 12px;
        padding-inline: 16px;
        text-align: center;
    }
}

/* Outside the layers on purpose, and the one rule in this file that is: an
   unlayered !important outranks everything an author can write, because the
   style panel and the agent cannot emit !important at all. Only the
   properties that would make the line vanish are held; how it looks stays
   the author's. */
[data-pb-credit] {
    visibility: visible !important;
    opacity: 1 !important;
    clip-path: none !important;
    content-visibility: visible !important;
}

/* The form widget (CMS-L76-1): a site form from the Forms module. Theme
   tokens only, in the defaults layer, so the style panel and the page's own
   CSS always win. */
@layer haya-defaults {
    .pb-form-body {
        display: grid;
        gap: 1rem;
    }

    .pb-form-field {
        display: grid;
        gap: 0.35rem;
    }

    .pb-form-label {
        font-weight: var(--font-weight-h3, 600);
        color: var(--color-text-dark);
    }

    .pb-form-required {
        color: var(--color-error);
    }

    .pb-form-input {
        width: 100%;
        box-sizing: border-box;
        padding: 0.65rem 0.8rem;
        border: 1px solid var(--color-border);
        border-radius: var(--radius-md);
        background: var(--color-bg-card);
        color: var(--color-text-dark);
        font: inherit;
    }

    .pb-form-input:focus-visible {
        outline: 2px solid var(--color-primary);
        outline-offset: 1px;
    }

    .pb-form-field.is-invalid .pb-form-input {
        border-color: var(--color-error);
    }

    .pb-form-check {
        display: flex;
        align-items: flex-start;
        gap: 0.5rem;
        cursor: pointer;
    }

    .pb-form-help {
        color: var(--color-text-muted);
    }

    .pb-form-error {
        color: var(--color-error);
    }

    .pb-form-error:empty {
        display: none;
    }

    .pb-form-message:empty {
        display: none;
    }

    .pb-form-message--sent {
        padding: 1rem;
        border: 1px solid var(--color-primary);
        border-radius: var(--radius-md);
    }

    .pb-form-message--error,
    .pb-form-message--closed {
        color: var(--color-error);
    }

    .pb-form-captcha-row {
        display: flex;
        align-items: center;
        gap: 0.75rem;
        flex-wrap: wrap;
    }

    .pb-form-captcha-image svg {
        display: block;
        max-width: 100%;
        height: auto;
        border-radius: var(--radius-md);
    }

    .pb-form-captcha-refresh {
        background: none;
        border: 0;
        padding: 0;
        color: var(--color-text-link);
        text-decoration: underline;
        cursor: pointer;
        font: inherit;
    }

    /* Off-screen, not display:none: some bots skip hidden fields. */
    .pb-form-hp {
        position: absolute;
        inset-inline-start: -10000px;
        width: 1px;
        height: 1px;
        overflow: hidden;
    }

    .pb-form-empty {
        padding: 1rem;
        border: 1px dashed var(--color-border);
        border-radius: var(--radius-md);
        color: var(--color-text-muted);
        text-align: center;
    }

    .pb-form-submit {
        justify-self: start;
    }
}
