/*
 * monoSmartUpsell, structure only (Settings > General > Appearance > Style source > "Structure only").
 *
 * Layout, the carousel's mechanics and the hidden states, all inside :where() so the specificity is zero and any rule of the theme wins.
 * No colours, fonts, borders, radii or shadows: the theme styles the buttons, the links, the text and the product cards. The accent colour
 * setting is not used with this file (the plugin writes no colour rule when "Structure only" is chosen).
 *
 * The same markup, the same classes, the same data-msu-* hooks and the same custom properties as smart-upsell.css (the plugin's own
 * design): --msu-cols (the grid's columns) and --msu-vis-d / --msu-vis-t / --msu-vis-m (cards visible at once in a slider, per box width).
 * It repeats the layout rules of smart-upsell.css on purpose: change both together. tests/StyleSourceTest.php fails if this file carries a
 * colour, a font, a border or a shadow.
 */

:where(.msu-box) { box-sizing: border-box; max-width: 100%; margin: 10px 0 0; }
:where(.msu-box *, .msu-box *::before, .msu-box *::after) { box-sizing: border-box; }
:where(.msu-box__title) { margin: 0 0 8px; }

:where(.msu-list) { display: grid; gap: 8px; margin: 0; padding: 0; list-style: none; }

/* A line: thumbnail, name and price, and the button. On a phone the button gets its own full-width row, 44px tall. */
:where(.msu-item) { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 10px; margin: 0; padding: 0; list-style: none; }
:where(.msu-item__thumb) { display: block; flex: 0 0 48px; width: 48px; height: 48px; overflow: hidden; }
:where(.msu-item__img) { display: block; width: 100%; height: 100%; margin: 0; object-fit: cover; }
:where(.msu-item__body) { display: flex; flex: 1 1 140px; flex-direction: column; gap: 2px; min-width: 0; }
:where(.msu-item__name) { overflow-wrap: anywhere; }

:where(.msu-add) {
  display: inline-flex; align-items: center; justify-content: center; flex: 1 1 100%;
  min-height: 44px; margin: 0; padding: 0 16px; cursor: pointer;
}
:where(.msu-add.is-busy) { opacity: .6; pointer-events: none; cursor: progress; }
:where(.msu-item.is-added .msu-add) { opacity: .55; pointer-events: none; }

:where(.msu-box__status) { margin: 8px 0 0; }
:where(.msu-box__status[hidden]) { display: none; }

/* Cards: a swipeable row (no arrows) on a phone, a grid from 640px. */
:where(.msu-box--cards .msu-list) { display: flex; gap: 10px; overflow-x: auto; padding-bottom: 4px; scroll-snap-type: x mandatory; -webkit-overflow-scrolling: touch; }
:where(.msu-box--cards .msu-item) { flex: 0 0 150px; flex-direction: column; align-items: stretch; gap: 6px; scroll-snap-align: start; }
:where(.msu-box--cards .msu-item__thumb) { flex: none; width: 100%; height: auto; aspect-ratio: 1; }
:where(.msu-box--cards .msu-item__body) { flex: 1 1 auto; }
:where(.msu-box--cards .msu-add) { flex: 0 0 auto; width: 100%; }

/* The heading row: the title, and the carousel's arrows at its end. */
:where(.msu-box__head) { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin: 0 0 8px; }
:where(.msu-box__head .msu-box__title) { margin: 0; }
:where(.msu-nav) { display: inline-flex; gap: 6px; }
:where(.msu-nav[hidden]) { display: none; }
:where(.msu-nav__btn) { display: inline-flex; align-items: center; justify-content: center; width: 36px; height: 36px; margin: 0; padding: 0; cursor: pointer; }
:where(.msu-nav__btn:disabled) { opacity: .35; cursor: default; }

:where(.msu-track) { min-width: 0; }

/* The variation picker. Hidden until the script runs (the page gets .msu-js): without it the item shows its "Choose options" link. */
:where(.msu-picker) { display: none; flex: 1 1 100%; min-width: 0; }
:where(.msu-js .msu-picker) { display: grid; gap: 6px; }
:where(.msu-js .msu-add--nojs) { display: none; }
:where(.msu-picker__field) { display: grid; gap: 2px; margin: 0; }
:where(.msu-picker__select) { box-sizing: border-box; width: 100%; max-width: 100%; min-height: 40px; margin: 0; }
:where(.msu-picker__note) { margin: 0; }
:where(.msu-picker__note[hidden]) { display: none; }
:where(.msu-picker .msu-add) { width: 100%; }
:where(.msu-add:disabled) { opacity: .45; cursor: not-allowed; }

/*
 * Compact: one row per suggestion. Chosen by the owner, or automatically (layout "auto") when the box is narrower than 420px: by a
 * container query where the browser has them, by .is-narrow (set by the script's width observer) where it does not. The two blocks below
 * are the same rules; tests/CarouselTest.php fails if they drift apart.
 */
:where(.msu-blocks-slot) { align-self: stretch; width: 100%; min-width: 0; }
:where(.msu-blocks-slot--pending) { margin: 10px 0 0; }
:where(.msu-skeleton) { display: block; box-sizing: border-box; height: 74px; }

:where(.msu-box--auto) { container-type: inline-size; width: 100%; }

/* compact:begin */
:where(.msu-box--compact .msu-list, .msu-box--auto.is-narrow .msu-list) { gap: 6px; }
:where(.msu-box--compact .msu-item, .msu-box--auto.is-narrow .msu-item) { flex-wrap: wrap; gap: 4px 10px; }
:where(.msu-box--compact .msu-item__thumb, .msu-box--auto.is-narrow .msu-item__thumb) { flex: 0 0 40px; width: 40px; height: 40px; }
:where(.msu-box--compact .msu-item__body, .msu-box--auto.is-narrow .msu-item__body) { flex: 1 1 0; min-width: 0; }
:where(.msu-box--compact .msu-add, .msu-box--auto.is-narrow .msu-add) { flex: 0 0 auto; padding: 0 12px; }
:where(.msu-box--compact .msu-picker, .msu-box--auto.is-narrow .msu-picker) { flex: 1 1 100%; }
/* compact:end */

@container (width < 420px) {
  /* container-compact:begin */
  :where(.msu-box--auto .msu-list) { gap: 6px; }
  :where(.msu-box--auto .msu-item) { flex-wrap: wrap; gap: 4px 10px; }
  :where(.msu-box--auto .msu-item__thumb) { flex: 0 0 40px; width: 40px; height: 40px; }
  :where(.msu-box--auto .msu-item__body) { flex: 1 1 0; min-width: 0; }
  :where(.msu-box--auto .msu-add) { flex: 0 0 auto; padding: 0 12px; }
  :where(.msu-box--auto .msu-picker) { flex: 1 1 100%; }
  /* container-compact:end */
}

/*
 * Carousel: one horizontal row, the title above with the arrows at its end. A mouse drags it, a finger scrolls it natively with snap, the
 * arrow keys move one card. The script (smart-upsell.js) draws the arrows only when the row overflows.
 *
 * How many cards show at once ("Visible at once" in the settings): --msu-vis-d (a box 640px wide or more), --msu-vis-t (420 to 639px) and
 * --msu-vis-m (under 420px), each 1 to 6, printed on the box by the server. A card is (100% minus a peek) divided by that many, the peek
 * being the next card showing at the edge: max(10%, 32% - 10% * N). Same formula as smart-upsell.css.
 */
:where(.msu-box--carousel) { container-type: inline-size; width: 100%; }
:where(.msu-box--carousel .msu-track) {
  overflow-x: auto; overscroll-behavior-x: contain; scroll-snap-type: x mandatory; touch-action: pan-x pan-y;
  scrollbar-width: none; -ms-overflow-style: none; cursor: grab; -webkit-user-select: none; user-select: none;
}
:where(.msu-box--carousel .msu-track::-webkit-scrollbar) { display: none; }
:where(.msu-box--carousel .msu-track.is-dragging) { cursor: grabbing; scroll-snap-type: none; scroll-behavior: auto; }
:where(.msu-box--carousel .msu-track img, .msu-box--carousel .msu-track a) { -webkit-user-drag: none; }
:where(.msu-box--carousel .msu-track img) { pointer-events: none; }
:where(.msu-box--carousel .msu-list) { display: flex; gap: 10px; padding-bottom: 2px; }
:where(.msu-box--carousel .msu-item) {
  flex: 0 0 calc((100% - max(10%, 32% - 10% * var(--msu-vis-d, 2))) / var(--msu-vis-d, 2)); flex-direction: column; flex-wrap: nowrap; align-items: stretch; gap: 6px;
  scroll-snap-align: start;
}
:where(.msu-box--carousel .msu-item__thumb) { flex: none; width: 100%; height: auto; aspect-ratio: 1; }
:where(.msu-box--carousel .msu-item__body) { flex: 1 1 auto; }
:where(.msu-box--carousel .msu-add) { flex: 0 0 auto; width: 100%; gap: 6px; }
@container (width < 640px) {
  :where(.msu-box--carousel .msu-item) { flex-basis: calc((100% - max(10%, 32% - 10% * var(--msu-vis-t, 2))) / var(--msu-vis-t, 2)); }
}
@container (width < 420px) {
  :where(.msu-box--carousel .msu-item) { flex-basis: calc((100% - max(10%, 32% - 10% * var(--msu-vis-m, 1))) / var(--msu-vis-m, 1)); }
}
/*
 * A drawer box whose Visible-at-once value the admin changed carries data-msu-vis="set" (server-side; 0.7.5). Only then, this width rule
 * outranks a card width a theme or plugin sets from outside (monoCheckout's drawer does: `.woocommerce .mc-item__after .msu-box .msu-item`,
 * four classes). Five here (box, carousel, attribute, list, item), no !important, same formula as above. A box without the attribute is
 * untouched, so an outside width stays in charge until a value is changed. With no outside rule it draws exactly what the rules above draw.
 * Same rule as smart-upsell.css.
 */
.msu-box.msu-box--carousel[data-msu-vis="set"] .msu-list .msu-item { flex-basis: calc((100% - max(10%, 32% - 10% * var(--msu-vis-d, 2))) / var(--msu-vis-d, 2)); }
@container (width < 640px) {
  .msu-box.msu-box--carousel[data-msu-vis="set"] .msu-list .msu-item { flex-basis: calc((100% - max(10%, 32% - 10% * var(--msu-vis-t, 2))) / var(--msu-vis-t, 2)); }
}
@container (width < 420px) {
  .msu-box.msu-box--carousel[data-msu-vis="set"] .msu-list .msu-item { flex-basis: calc((100% - max(10%, 32% - 10% * var(--msu-vis-m, 1))) / var(--msu-vis-m, 1)); }
}
@media (prefers-reduced-motion: no-preference) {
  :where(.msu-box--carousel .msu-track) { scroll-behavior: smooth; }
}

/*
 * The theme's product card (Product card > "The theme's product card"). The li is the plugin's and sits in the layout like any card; the
 * slot holds the theme's markup. Only the card root's layout is reset (its Bootstrap column width, margins, float): `!important` on exactly
 * those five properties, on the slot's direct child only, because a theme's `.col-10` or `.product` rule is as specific as ours and may
 * load later. Everything inside the card keeps the theme's own CSS. Same rule as smart-upsell.css.
 */
:where(.msu-item--theme) { display: block; padding: 0; }
:where(.msu-theme-slot) { min-width: 0; }
.msu-theme-slot > * { width: 100% !important; max-width: none !important; flex: none !important; margin: 0 !important; float: none !important; }
:where(.msu-item--theme.is-added .add_to_cart_button) { opacity: .55; pointer-events: none; }
:where(.msu-item--theme .add_to_cart_button.is-busy) { opacity: .6; pointer-events: none; cursor: progress; }

/*
 * The whole-cart block (templates/cart-block.php). A slider is the carousel above (class msu-box--carousel). A grid: two columns in a narrow
 * box, --msu-cols columns (the Display setting) from 640px wide; in the drawer and the mini-cart the setting (1 to 3) is used as it is.
 */
:where(.msu-cart) { margin: 16px 0; }
:where(.msu-cart__title) { margin: 0; }
:where(.msu-box--grid) { container-type: inline-size; width: 100%; }
:where(.msu-box--grid .msu-list) { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
@container (width >= 640px) {
  :where(.msu-box--grid .msu-list) { grid-template-columns: repeat(var(--msu-cols, 4), minmax(0, 1fr)); }
}
:where(.msu-box--drawer.msu-box--grid .msu-list, .msu-box--minicart.msu-box--grid .msu-list) { grid-template-columns: repeat(var(--msu-cols, 2), minmax(0, 1fr)); gap: 8px; }
:where(.msu-box--grid .msu-item) { flex-direction: column; flex-wrap: nowrap; align-items: stretch; gap: 6px; }
:where(.msu-box--grid .msu-item__thumb) { flex: none; width: 100%; height: auto; aspect-ratio: 1; }
:where(.msu-box--grid .msu-item__body) { flex: 1 1 auto; }
:where(.msu-box--grid .msu-add) { flex: 0 0 auto; width: 100%; }
:where(.msu-item__rating) { display: block; line-height: 1; }
:where(.msu-item__rating .star-rating) { float: none; margin: 2px 0; }

/* WooCommerce's classic mini-cart widget: the per-line box under a line's quantity, the whole-cart block under the buttons. */
:where(.woocommerce-mini-cart .msu-box) { clear: both; margin: 8px 0 0; }
:where(.widget_shopping_cart_content .msu-cart) { margin: 12px 0 0; }
/* The Mini-Cart block (unverified in a browser): the block sits inside the drawer's scrolling content. */
:where(.wc-block-mini-cart__template-part .msu-cart) { margin: 12px 16px; }

@media (min-width: 480px) {
  :where(.msu-add) { flex: 0 0 auto; }
}

@media (min-width: 640px) {
  :where(.msu-box--cards .msu-list) { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); overflow: visible; }
  :where(.msu-box--cards .msu-item) { flex: initial; }
}

/* In a classic cart table the box fills the product-name cell; on a wide screen it does not stretch across a long cell. */
@media (min-width: 768px) {
  :where(.woocommerce-cart-form__cart-item .msu-box) { max-width: 30rem; }
}

/* Cart block: the box sits at the foot of the product cell. */
:where(.wc-block-cart-item__wrap .msu-box) { margin-top: 12px; }

/* monoCheckout drawer: the box is a full-width row under the line. */
:where(.mc-drawer .msu-box) { margin: 0; }

@media print { :where(.msu-box) { display: none; } }
