/* Dynamic Theme v1 component overrides; rules are scoped to a published Theme.
 * Legacy storefronts never receive these declarations.
 * All values originate from server-validated token variables / fixed variants.
 */
html[data-shop-theme="custom"] {
    font-family: var(--ac-theme-font);
    font-size: var(--ac-theme-font-size);
}
html[data-shop-theme="custom"] body {
    font-family: var(--ac-theme-font);
    background: var(--ac-background);
    color: var(--ac-ink);
    font-weight: var(--ac-theme-body-weight);
}
html[data-shop-theme="custom"] :is(h1,h2,h3,h4,h5,h6) {
    font-family: var(--ac-theme-font);
    font-weight: var(--ac-theme-heading-weight);
}
html[data-shop-theme="custom"] :is(.kb-shell,.kb-page,.kb-page--wide) {
    width: min(var(--ac-container-width), calc(100% - 48px));
    max-width: var(--ac-container-width);
}

/* 1174 / Header, footer and homepage: keep the existing DOM and selectors. */
html[data-shop-theme="custom"] body.site-body--auth,
html[data-shop-theme="custom"] .site-page,
html[data-shop-theme="custom"] .auth-page {
    background: var(--ac-background);
}
html[data-shop-theme="custom"] a:hover,
html[data-shop-theme="custom"] .kb-section-kicker,
html[data-shop-theme="custom"] .catalog-breadcrumb a {
    color: var(--ac-primary);
}
html[data-shop-theme="custom"] :is(a,button,input,select,textarea,[tabindex]):focus-visible {
    outline: 3px solid color-mix(in srgb, var(--ac-primary) 45%, transparent);
    outline-offset: 2px;
}
html[data-shop-theme="custom"] :is(.kb-header,.kb-topbar,.kb-nav-wrap,.kb-footer,.kb-benefits) {
    background: var(--ac-surface);
    border-color: var(--ac-border);
}
html[data-shop-theme="custom"] .kb-topbar {
    color: var(--ac-muted);
}
html[data-shop-theme="custom"] .kb-topbar :is(a,span,button[data-chat-widget-launcher]) {
    color: var(--ac-muted);
}
html[data-shop-theme="custom"] .kb-topbar__divider {
    background: var(--ac-border);
}
html[data-shop-theme="custom"] .kb-brand__mark {
    color: var(--ac-primary);
    background: color-mix(in srgb, var(--ac-primary) 9%, var(--ac-surface));
    box-shadow: inset 0 0 0 1px var(--ac-border);
    border-radius: var(--ac-radius);
}
html[data-shop-theme="custom"] .kb-brand__text strong,
html[data-shop-theme="custom"] .kb-nav__support strong {
    color: var(--ac-primary);
}
html[data-shop-theme="custom"] .kb-search {
    background: var(--ac-surface);
    border-color: var(--ac-border);
    border-radius: var(--ac-radius);
}
html[data-shop-theme="custom"] .kb-search:focus-within {
    border-color: var(--ac-primary);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--ac-primary) 12%, transparent);
}
html[data-shop-theme="custom"] .kb-search :is(input,.kb-search__category) {
    color: var(--ac-ink);
}
html[data-shop-theme="custom"] .kb-action,
html[data-shop-theme="custom"] .kb-user-menu__trigger,
html[data-shop-theme="custom"] .kb-search button {
    color: var(--ac-primary);
}
html[data-shop-theme="custom"] .kb-nav__links a,
html[data-shop-theme="custom"] .kb-nav__links .preview-menu__trigger {
    color: var(--ac-ink);
}
html[data-shop-theme="custom"] .kb-nav__links :is(a,.preview-menu__trigger):hover,
html[data-shop-theme="custom"] .kb-nav__links a.is-active {
    color: var(--ac-primary);
}
html[data-shop-theme="custom"] .kb-category-menu__trigger {
    color: var(--ac-on-primary);
    background: var(--ac-primary);
    border-radius: var(--ac-radius);
}
html[data-shop-theme="custom"] .kb-category-menu__trigger:hover {
    background: var(--ac-primary-dark);
    color: var(--ac-on-primary);
}
html[data-shop-theme="custom"] :is(.kb-category-menu__panel,.preview-menu__children,.kb-user-menu__panel) {
    color: var(--ac-ink);
    background: var(--ac-surface);
    border-color: var(--ac-border);
}
html[data-shop-theme="custom"] :is(.preview-menu__children > .preview-menu__item,.preview-menu__children .preview-menu__trigger) {
    background: color-mix(in srgb, var(--ac-primary) 5%, var(--ac-surface));
}
html[data-shop-theme="custom"] .storefront-shell {
    gap: var(--ac-theme-section-gap);
}
html[data-shop-theme="custom"] .storefront-hero {
    background: var(--ac-surface);
    border-color: var(--ac-border);
    border-radius: var(--ac-radius);
}
html[data-shop-theme="custom"] .storefront-banner-link {
    background: color-mix(in srgb, var(--ac-secondary) 20%, var(--ac-background));
}
html[data-shop-theme="custom"] .storefront-carousel__indicators [data-bs-target] {
    background: var(--ac-secondary);
}
html[data-shop-theme="custom"] .storefront-carousel__indicators .active {
    background: var(--ac-primary);
}
html[data-shop-theme="custom"] :is(.storefront-promo-card,.preview-design-card,.preview-banner-swiper,.preview-design-block) {
    background-color: var(--ac-surface);
    border-color: var(--ac-border);
    border-radius: var(--ac-radius);
}
html[data-shop-theme="custom"] .storefront-promo-card--ai,
html[data-shop-theme="custom"] .kb-benefits__grid div {
    background: color-mix(in srgb, var(--ac-primary) 7%, var(--ac-surface));
}
html[data-shop-theme="custom"] .kb-footer-promo {
    color: var(--ac-ink);
    background: linear-gradient(115deg,
        color-mix(in srgb, var(--ac-secondary) 23%, var(--ac-surface)),
        color-mix(in srgb, var(--ac-primary) 13%, var(--ac-background)));
    border: 1px solid var(--ac-border);
    border-radius: var(--ac-radius);
}
html[data-shop-theme="custom"] .kb-footer-promo p,
html[data-shop-theme="custom"] .kb-footer__grid :is(p,small) {
    color: var(--ac-muted);
}
html[data-shop-theme="custom"] .kb-benefits__icon {
    color: var(--ac-primary);
    background: color-mix(in srgb, var(--ac-primary) 13%, var(--ac-surface));
}
html[data-shop-theme="custom"] .kb-footer__grid h3,
html[data-shop-theme="custom"] .kb-footer__brand strong {
    color: var(--ac-ink);
}
html[data-shop-theme="custom"] .kb-footer__bottom {
    border-color: var(--ac-border);
    background: var(--ac-background);
    color: var(--ac-muted);
}

/* 1174 / Shared cards, catalog and product detail. Ranking / availability
 * colours are intentionally not replaced with the merchant's primary. */
html[data-shop-theme="custom"] :is(
    .kb-card,.dashboard-panel,.summary-card,.mini-card,.status-card,.coupon-panel,
    .my-coupon-card,.product-gallery-card,.product-purchase-card,
    .product-description-card,.favorite-card,.shop-card,.store-card,
    .shop-section-card,.checkout-shop-block,.invoice-card,.profile-address-card,
    .product-detail-sidebar__card,.cart-item,.cart-sidebar-card,.checkout-summary-card,
    .preview-design-card,.auth-card,.order-panel,.order-row) {
    background-color: var(--ac-surface);
    border-color: var(--ac-border);
    border-radius: var(--ac-radius);
    color: var(--ac-ink);
}
html[data-shop-theme="custom"] :is(.catalog-card,.catalog-shell--product-index .catalog-card) {
    background: var(--ac-surface);
    border-radius: var(--ac-radius);
    color: var(--ac-ink);
    overflow: hidden;
}
html[data-shop-theme="custom"] .catalog-card__image,
html[data-shop-theme="custom"] .favorite-card__image {
    background: var(--ac-surface);
    border-radius: var(--ac-radius) var(--ac-radius) 0 0;
}
html[data-shop-theme="custom"] .catalog-card__brand,
html[data-shop-theme="custom"] .catalog-card__shipping svg,
html[data-shop-theme="custom"] .catalog-card__price strong,
html[data-shop-theme="custom"] .catalog-shell--product-index .catalog-card__price strong,
html[data-shop-theme="custom"] :is(.product-detail-panel,.product-purchase-card) a:not(.catalog-primary-button) {
    color: var(--ac-primary);
}
html[data-shop-theme="custom"] .catalog-card__badge:not(.catalog-card__rank):not(.catalog-card__badge--sale) {
    color: var(--ac-on-primary);
    background: var(--ac-primary);
    border-radius: var(--ac-radius);
}
html[data-shop-theme="custom"] .product-category-badges :is(span,a) {
    color: var(--ac-muted);
    background: var(--ac-background);
    border-color: var(--ac-border);
    border-radius: calc(var(--ac-radius) / 2);
}
html[data-shop-theme="custom"] .catalog-card__title,
html[data-shop-theme="custom"] .catalog-card__title a,
html[data-shop-theme="custom"] .product-detail-sidebar__card h3 {
    color: var(--ac-ink);
}
html[data-shop-theme="custom"][data-theme-card="flat"] .catalog-card {
    border: 1px solid transparent;
    box-shadow: none;
    background: transparent;
}
html[data-shop-theme="custom"][data-theme-card="bordered"] .catalog-card {
    border: 1px solid var(--ac-border);
    box-shadow: none;
}
html[data-shop-theme="custom"][data-theme-card="elevated"] .catalog-card {
    border: 1px solid var(--ac-border);
    box-shadow: 0 14px 34px color-mix(in srgb, var(--ac-ink) 11%, transparent);
}
html[data-shop-theme="custom"] .catalog-card:is(:hover,:focus-within) {
    border-color: var(--ac-secondary);
    box-shadow: 0 14px 32px color-mix(in srgb, var(--ac-ink) 12%, transparent);
}

/* Theme v1 button variants; text is readable even if primary is light,
 * because only the on_primary/primary and text/surface pairs are validated. */
html[data-shop-theme="custom"] :is(
    .catalog-primary-button,.kb-action--primary,.kb-action--register,.auth-submit,.checkout-submit,
    .primary-link,.status-card__link--primary,.home-hero__button,.member-cta__primary,
    .checkout-secondary--primary) {
    background: var(--ac-primary);
    color: var(--ac-on-primary);
    border: 1px solid var(--ac-primary);
    border-radius: var(--ac-radius);
}
html[data-shop-theme="custom"] :is(
    .catalog-primary-button,.kb-action--primary,.kb-action--register,.auth-submit,.checkout-submit,
    .primary-link,.status-card__link--primary,.home-hero__button,.member-cta__primary,
    .checkout-secondary--primary):hover:not(:disabled) {
    background: var(--ac-primary-dark);
    border-color: var(--ac-primary-dark);
    color: var(--ac-on-primary);
}
html[data-shop-theme="custom"][data-theme-button="outline"] :is(
    .catalog-primary-button,.kb-action--primary,.kb-action--register,.auth-submit,.checkout-submit,
    .primary-link,.status-card__link--primary,.home-hero__button,.member-cta__primary,
    .checkout-secondary--primary) {
    background: var(--ac-surface);
    color: var(--ac-ink);
    border-color: var(--ac-primary);
}
html[data-shop-theme="custom"][data-theme-button="outline"] :is(
    .catalog-primary-button,.kb-action--primary,.kb-action--register,.auth-submit,.checkout-submit,
    .primary-link,.status-card__link--primary,.home-hero__button,.member-cta__primary,
    .checkout-secondary--primary):hover:not(:disabled) {
    background: var(--ac-primary);
    color: var(--ac-on-primary);
}
html[data-shop-theme="custom"][data-theme-button="soft"] :is(
    .catalog-primary-button,.kb-action--primary,.kb-action--register,.auth-submit,.checkout-submit,
    .primary-link,.status-card__link--primary,.home-hero__button,.member-cta__primary,
    .checkout-secondary--primary) {
    background: color-mix(in srgb, var(--ac-primary) 16%, var(--ac-surface));
    border-color: color-mix(in srgb, var(--ac-primary) 38%, var(--ac-surface));
    color: var(--ac-ink);
}
html[data-shop-theme="custom"][data-theme-button="soft"] :is(
    .catalog-primary-button,.kb-action--primary,.kb-action--register,.auth-submit,.checkout-submit,
    .primary-link,.status-card__link--primary,.home-hero__button,.member-cta__primary,
    .checkout-secondary--primary):hover:not(:disabled) {
    background: color-mix(in srgb, var(--ac-primary) 25%, var(--ac-surface));
    color: var(--ac-ink);
}
/* Original catalog card has a higher-specificity green button rule. */
html[data-shop-theme="custom"] .catalog-card__actions .catalog-primary-button {
    border-color: var(--ac-primary);
    color: var(--ac-on-primary);
    background: var(--ac-primary);
    border-radius: var(--ac-radius);
}
html[data-shop-theme="custom"][data-theme-button="outline"] .catalog-card__actions .catalog-primary-button {
    background: var(--ac-surface);
    color: var(--ac-ink);
}
html[data-shop-theme="custom"][data-theme-button="soft"] .catalog-card__actions .catalog-primary-button {
    background: color-mix(in srgb, var(--ac-primary) 16%, var(--ac-surface));
    color: var(--ac-ink);
}
html[data-shop-theme="custom"] :is(.catalog-secondary-button,.catalog-tab,.catalog-chip,.order-filter-chip,.pagination a) {
    color: var(--ac-ink);
    background: var(--ac-surface);
    border-color: var(--ac-border);
    border-radius: var(--ac-radius);
}
html[data-shop-theme="custom"] :is(.catalog-tab,.catalog-chip,.order-filter-chip).is-active,
html[data-shop-theme="custom"] .order-filter-chip[aria-pressed="true"] {
    color: var(--ac-on-primary);
    background: var(--ac-primary);
    border-color: var(--ac-primary);
}

/* Cart, checkout, membership and order surfaces: visuals only. */
html[data-shop-theme="custom"] :is(.cart-shell,.checkout-page,.favorite-shell,.order-shell) {
    color: var(--ac-ink);
    gap: var(--ac-theme-section-gap);
}
html[data-shop-theme="custom"] :is(.cart-item,.checkout-shop-block,.checkout-summary-card,.order-row) {
    border-color: var(--ac-border);
    background: var(--ac-surface);
    border-radius: var(--ac-radius);
}
html[data-shop-theme="custom"] :is(.cart-summary-row,.checkout-shop-header,.checkout-item-table td,.checkout-item-table th) {
    border-color: var(--ac-border);
}
html[data-shop-theme="custom"] .checkout-item-table th,
html[data-shop-theme="custom"] .order-detail-page .invoice-table thead {
    color: var(--ac-ink);
    background: color-mix(in srgb, var(--ac-primary) 5%, var(--ac-surface));
}
html[data-shop-theme="custom"] .checkout-page :is(.checkout-field-label,.checkout-shop-title,.checkout-section-title) {
    color: var(--ac-ink);
}
html[data-shop-theme="custom"] :is(.checkout-input,.checkout-select,.form-control,.form-select,.auth-form__input,.auth-field input,.auth-field select,.cart-qty input,textarea) {
    color: var(--ac-ink);
    background: var(--ac-surface);
    border-color: var(--ac-border);
    border-radius: var(--ac-radius);
}
html[data-shop-theme="custom"] :is(.checkout-input,.checkout-select,.form-control,.form-select,.auth-form__input,textarea):focus {
    border-color: var(--ac-primary);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--ac-primary) 12%, transparent);
}
html[data-shop-theme="custom"] .checkout-save-address-option {
    background: color-mix(in srgb, var(--ac-primary) 5%, var(--ac-surface));
    border-color: var(--ac-border);
}
html[data-shop-theme="custom"] :is(.cart-summary-row:last-child strong,.order-money,.invoice-summary-box strong,.invoice-card__total strong) {
    color: var(--ac-primary);
}
html[data-shop-theme="custom"] .auth-card {
    border-color: var(--ac-border);
    box-shadow: var(--ac-shadow);
}
html[data-shop-theme="custom"] .auth-copy {
    background: color-mix(in srgb, var(--ac-secondary) 18%, var(--ac-background));
    color: var(--ac-ink);
}
html[data-shop-theme="custom"] .auth-form {
    background: var(--ac-surface);
}
html[data-shop-theme="custom"] :is(.auth-links a,.auth-tabline .is-active) {
    color: var(--ac-primary);
}

/* Chat page and AI advisor Widget. Keep the connection-state colours semantic. */
html[data-shop-theme="custom"] {
    --chat-bg: var(--ac-background);
    --chat-panel: var(--ac-surface);
    --chat-card: var(--ac-surface);
    --chat-border: var(--ac-border);
    --chat-text: var(--ac-ink);
    --chat-muted: var(--ac-muted);
    --chat-accent: var(--ac-primary);
    --chat-accent-deep: var(--ac-primary-dark);
    --chat-user: color-mix(in srgb, var(--ac-secondary) 20%, var(--ac-surface));
}
html[data-shop-theme="custom"] :is(.chat-sidebar,.chat-panel,.product-chat-widget) {
    background: var(--ac-surface);
    border-color: var(--ac-border);
    border-radius: var(--ac-radius);
}
html[data-shop-theme="custom"] .chat-thread {
    background: var(--ac-background);
}
html[data-shop-theme="custom"] :is(.chat-sidebar h1,.chat-panel h2,.message-bubble,.chat-widget-body) {
    color: var(--ac-ink);
}
html[data-shop-theme="custom"] :is(.prompt-chip,.chat-prompt) {
    color: var(--ac-ink);
    border-color: var(--ac-border);
    background: var(--ac-surface);
    border-radius: var(--ac-radius);
}
html[data-shop-theme="custom"] :is(.prompt-chip,.chat-prompt):hover {
    border-color: var(--ac-primary);
    background: color-mix(in srgb, var(--ac-primary) 9%, var(--ac-surface));
}
html[data-shop-theme="custom"] .chat-widget-header {
    background: var(--ac-primary);
    color: var(--ac-on-primary);
}
html[data-shop-theme="custom"] .chat-widget-header :is(strong,.chat-widget-status,.chat-widget-icon-button) {
    color: var(--ac-on-primary);
}
html[data-shop-theme="custom"] .chat-composer-field {
    border-color: var(--ac-border);
    background: var(--ac-surface);
}
html[data-shop-theme="custom"] .chat-composer-field:focus-within {
    border-color: var(--ac-primary);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--ac-primary) 14%, transparent);
}
/* The enclosing field owns the focus ring, including keyboard focus. */
html[data-shop-theme="custom"] .chat-composer-field textarea,
html[data-shop-theme="custom"] .chat-composer-field textarea:is(:focus,:focus-visible) {
    border: 0;
    border-radius: 0;
    outline: 0;
    box-shadow: none;
    background: transparent;
}
html[data-shop-theme="custom"] :is(.chat-launcher,.chat-composer-send,#sendButton) {
    background: var(--ac-primary);
    color: var(--ac-on-primary);
}
html[data-shop-theme="custom"] :is(.chat-launcher,.chat-composer-send,#sendButton):hover:not(:disabled) {
    background: var(--ac-primary-dark);
    color: var(--ac-on-primary);
}

@media (max-width: 767px) {
    html[data-shop-theme="custom"] :is(.kb-shell,.kb-page) {
        max-width: 100%;
    }
    html[data-shop-theme="custom"] .kb-footer-promo {
        padding: 20px;
    }
}

/* Private Theme preview chrome, deliberately independent of merchant tokens
 * to remain legible even with an unusual merchant colour palette. */
.theme-preview-banner {
    position: relative;
    z-index: 50;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
    padding: 10px 24px;
    background: #172936;
    color: #fff;
    font: 600 13px/1.6 system-ui, sans-serif;
}
.theme-preview-banner nav { display: flex; gap: 10px; flex-wrap: wrap; }
.theme-preview-banner a {
    color: #fff;
    padding: 4px 9px;
    border: 1px solid #8296a3;
    border-radius: 5px;
    text-decoration: none;
}
.theme-preview-banner a:hover, .theme-preview-banner a:focus-visible { background: #344f61; color: #fff; }
.is-theme-preview [inert] { cursor: default; }
.theme-preview-sample { display: grid; gap: 24px; min-height: 50vh; }
.theme-preview-sample__intro p { color: var(--ac-muted, #667); }
.theme-preview-product-grid { display: grid; grid-template-columns: repeat(3,minmax(0,1fr)); gap: 20px; }
.theme-preview-product-detail { display: grid; grid-template-columns: minmax(0,1fr) minmax(0,1fr); gap: 24px; }
.theme-preview-product-detail :is(.product-gallery-card,.product-purchase-card) { padding: 24px; }
.theme-preview-product-detail img { max-width: 100%; }
.theme-preview-product-detail .catalog-primary-button { display: inline-block; }
.theme-preview-cart-layout { min-height: 280px; }
.theme-preview-cart-layout .cart-item { display: flex; gap: 20px; padding: 16px; }
.theme-preview-cart-layout .cart-item__image { width: 100px; min-width: 100px; }
.theme-preview-cart-layout .cart-item__image img { width: 100%; }
@media (max-width: 767px) {
    .theme-preview-banner { padding: 10px 14px; }
    .theme-preview-product-grid { grid-template-columns: repeat(2,minmax(0,1fr)); }
    .theme-preview-product-detail, .theme-preview-cart-layout { grid-template-columns: 1fr; }
}
@media (max-width: 480px) {
    .theme-preview-product-grid { grid-template-columns: 1fr; }
}
