/*
 * The shop's own components (includes/woocommerce and the woocommerce/ templates): the shop and
 * category page head, the toolbar and colour filter, "Load more", price per m², the quantity buttons,
 * the tiles and area calculator, optional extras, the product page's layout and summary, and the basket,
 * checkout and account page head. Loaded when WooCommerce is active.
 *
 * Restyling of WooCommerce's own markup (product cards, the add to basket form, the gallery, the basket
 * and checkout) belongs in plugins/woocommerce.css, outside any layer.
 */

@layer components {
  /* ---- Shop and category pages: the toolbar and products, close under the hero ---- */
  .shop-archive { padding-block: var(--space-xl) var(--space-section); }

  /* ---- Toolbar above a product list: sorting and the colour filter, boxes in a row ----
     A box's dark edge has 3:1 against the page, to show it's a control. Sorting and the colour filter are
     the same dropdown (.shop-dropdown): a box with a muted label, the
     choice in ink and the select chevron (--field-chevron), which opens a panel joined to its foot. Not a
     select, whose list is the browser's own and can't match. On phones each box is the full width (half
     can't fit "Sort by Price: high to low"). */
  .shop-toolbar {
    --toolbar-width: 15rem; /* fits "Sort by Price: high to low" clear of the chevron */
    display: flex; flex-wrap: wrap; align-items: flex-start; gap: var(--space-2xs); margin-bottom: var(--space-l);
    position: relative; z-index: 5; /* keeps the panels above the product cards */
    @media (width < 40rem) { display: grid; & > * { min-width: 0; } }
  }

  /* ---- Dropdown: sorting (woocommerce/loop/orderby.php) and the colour filter (includes/woocommerce/colour-filter.php) ---- */
  .shop-dropdown { position: relative; }
  .shop-dropdown__toggle {
    display: flex; align-items: center; gap: 0.375em; min-width: var(--toolbar-width); min-height: var(--target-size);
    padding: var(--space-2xs) var(--space-xl) var(--space-2xs) var(--space-xs);
    border: 1px solid var(--color-field-border); background: var(--color-white); color: var(--color-muted); font-size: var(--text-small); line-height: var(--leading-tight);
    list-style: none; cursor: pointer; position: relative;
    &::-webkit-details-marker { display: none; }
    &::after {
      content: ""; position: absolute; right: 0.875rem; top: 50%; width: 0.75rem; height: 0.5rem; translate: 0 -50%;
      background: var(--field-chevron) no-repeat center / contain; transition: rotate var(--transition);
    }
    &:hover { background: var(--color-paper-light); }
    [open] > & { border-color: var(--color-ink); background: var(--color-white); &::after { rotate: 180deg; } }
  }
  .shop-dropdown__label { flex: none; }
  .shop-dropdown__value { overflow: hidden; color: var(--color-ink); text-overflow: ellipsis; white-space: nowrap; }

  /* The panel hangs from the box, sharing its dark edge, at least as wide as the box */
  .shop-dropdown__panel {
    position: absolute; top: calc(100% - 1px); left: 0; z-index: 10;
    width: max-content; min-width: 100%; max-width: calc(100vw - 2 * var(--wrap-gutter)); padding-block: var(--space-3xs);
    border: 1px solid var(--color-ink); background: var(--color-white); box-shadow: var(--shadow-panel);
    @media (width < 40rem) { right: 0; width: auto; max-width: none; max-height: 60vh; overflow-y: auto; } /* the shop's 60 or so colours */
    /* It fades in and drops a little as it opens, like the header's menus (the keyframes are in motion.css) */
    [open] > & { animation: appear var(--duration-s) var(--ease-out); }
  }
  .shop-dropdown__set { min-width: 0; margin: 0; padding: 0; border: 0; }
  .shop-dropdown__list { display: grid; }
  /* Many colours sit in two or three columns (--columns, set by colour-filter.php), in A to Z order down
     each one, so the panel stays short. A short list keeps the plain panel under its box. The wide panel
     lines up with the toolbar's left edge rather than the box's, so it never runs off the screen. */
  .shop-toolbar .shop-dropdown--wide { position: static; }
  .shop-dropdown--wide .shop-dropdown__panel { right: auto; width: min(var(--columns, 3) * 16.5rem, 100%); min-width: 0; } /* 100% here is the toolbar */
  .shop-dropdown--wide .shop-dropdown__list {
    @media (min-width: 40rem) { display: block; columns: 16rem var(--columns, 3); column-gap: 0; & li { break-inside: avoid; } }
  }

  /* A row per choice: the box (a checkbox, or a tick for the chosen order), the name, and a colour's count */
  .shop-dropdown__option {
    display: flex; align-items: center; gap: var(--space-xs); min-height: var(--target-size); padding: var(--space-3xs) var(--space-s);
    color: var(--color-ink); font-size: var(--text-small); line-height: var(--leading-snug); cursor: pointer;
    &:hover, &:has(:focus-visible) { background: var(--color-paper-light); }
    &:has(:focus-visible) { outline: var(--focus-width) solid var(--color-focus); outline-offset: calc(var(--focus-width) * -1); }
  }
  .shop-dropdown__input {
    flex: none; width: 1.125rem; height: 1.125rem; margin: 0; accent-color: var(--color-ink); cursor: pointer;
    &:focus-visible { outline: none; box-shadow: none; } /* the row shows focus */
  }
  .shop-dropdown__input--radio {
    appearance: none; border: 0; background: none;
    &:checked { background: var(--field-tick) no-repeat center / 0.875rem; }
  }
  .shop-dropdown__count { margin-left: auto; padding-left: var(--space-s); color: var(--color-muted); }

  /* "Apply" without the script, and "Clear colours" once a colour is chosen, under a line */
  .shop-dropdown__actions {
    display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-xs) var(--space-s);
    margin-top: var(--space-3xs); padding: var(--space-xs) var(--space-s) var(--space-2xs); border-top: 1px solid var(--color-line);
    &:not(:has(> :not([hidden]))) { display: none; }
  }
  .shop-dropdown__clear { color: var(--color-ink); font-size: var(--text-small); }

  /* While the list is updating */
  [aria-busy="true"] > .product-list { opacity: 0.5; transition: opacity var(--transition); }

  /* ---- The foot of a product list: how many are showing, then "Load more" (assets/scripts/shop.js) ---- */
  .product-list__more { display: flex; flex-direction: column; align-items: center; gap: var(--space-s); margin-top: var(--space-xl); text-align: center; }
  .product-list__count { color: var(--color-muted); font-size: var(--text-small); }
  .product-list--enhanced .woocommerce-pagination { display: none; }
  .product-list__empty { margin-top: var(--space-m); }

  /* ---- Price per m²: under a tile's per-tile price ---- */
  .price-per-m2 { display: block; margin-top: var(--space-3xs); color: var(--color-muted); font-size: var(--text-small); }

  /* ---- Quantity buttons: minus and plus either side of WooCommerce's quantity field (includes/woocommerce/woocommerce.php) ---- */
  .quantity__button {
    display: grid; place-items: center; width: var(--target-size); min-height: var(--target-size); padding: 0;
    border: 1px solid var(--color-field-border); background: var(--color-line); color: var(--color-ink); font-size: var(--text-button); line-height: 1; cursor: pointer;
    &:first-child { border-right: 0; }
    &:last-child { border-left: 0; }
    &:hover { background: var(--color-ink); color: var(--color-white); }
    & .icon { width: 0.75rem; height: 0.75rem; } /* as the accordion's plus and minus */
  }

  /* ---- Tiles and area calculator: beside the quantity field on tile product pages ---- */
  .tile-calculator { display: flex; flex-wrap: wrap; align-items: flex-end; gap: var(--space-2xs) var(--space-s); }
  .tile-calculator__field { flex: 0 1 8rem; min-width: 0; }
  .tile-calculator__label { display: block; margin-bottom: var(--field-gap); color: var(--color-ink); font-size: var(--text-small); line-height: var(--leading-snug); }
  .tile-calculator__input {
    display: block; width: 100%; min-height: var(--target-size); padding: var(--field-padding);
    border: 1px solid var(--color-field-border); background: var(--color-white); color: var(--color-ink); line-height: var(--leading-snug);
    /* Disabled until a variation with a coverage is chosen. Still drawn as a field, so it's clear one is coming. */
    &:disabled { border-color: var(--color-text); background: var(--color-white); opacity: 0.6; cursor: not-allowed; }
  }
  .tile-calculator__total { display: flex; align-items: center; gap: 0.25em; min-height: var(--target-size); margin: 0; }

  /* ---- Optional extras: above the quantity and the add to basket button (includes/woocommerce/extras.php) ----
     A select sits under its label, like the variations. A checkbox's label wraps beside the box,
     not under it, and the price stays on the label's last line. Rows are at least 44px tall to tap. */
  .extras { display: grid; gap: var(--form-gap); }
  .extras__row { display: grid; gap: var(--field-gap); }
  .extras__label { color: var(--color-ink); font-size: var(--text-small); line-height: var(--leading-snug); }
  .extras__set { min-width: 0; margin: 0; padding: 0; border: 0; }
  .extras__legend { margin-bottom: var(--space-3xs); padding: 0; color: var(--color-ink); font-size: var(--text-small); }
  .extras__option {
    display: grid; grid-template-columns: auto minmax(0, 1fr); align-items: start; gap: var(--space-xs);
    padding-block: var(--space-3xs); color: var(--color-ink); font-size: var(--text-small); line-height: var(--leading-snug); cursor: pointer;
    @media (pointer: coarse) { padding-block: max(var(--space-3xs), (var(--target-size) - 1lh) / 2); } /* 44px tall to tap */
    &:hover .extras__text { text-decoration: underline; }
  }
  .extras__input { width: 1.125rem; height: 1.125rem; margin: 0; accent-color: var(--color-ink); cursor: pointer; }
  .extras__text { padding-top: 0.05rem; }
  .extras__price { white-space: nowrap; }
  .extras__hint { margin: 0 0 0 calc(1.125rem + var(--space-xs)); font-size: var(--text-small); line-height: var(--leading-snug); }

  /* ---- Product page: the gallery beside the summary from medium screens ----
     On a laptop (1280x720) the title, price, options and add to basket button fit above the fold. */
  .product-page__main { padding-block: var(--space-xl) var(--space-section); }
  .product-page__inner {
    display: grid; gap: var(--space-l);
    @media (min-width: 48rem) { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--space-xl); align-items: start; }
    @media (min-width: 64rem) { gap: var(--space-2xl); }
  }
  /* The gallery stays in view while a longer summary scrolls past, under the site bar */
  .product-page__gallery {
    min-width: 0;
    @media (min-width: 64rem) { position: sticky; top: calc(var(--header-height) + var(--space-m)); }
  }
  .product-page__summary { min-width: 0; container-type: inline-size; } /* the add to basket form lays out by this width */

  /* The category, a small label in capitals above the title, linking to the category */
  .product-page__category {
    margin-bottom: var(--space-2xs); font-size: var(--text-xsmall); line-height: var(--leading-snug); letter-spacing: var(--tracking-label); text-transform: uppercase;
    & a { color: var(--color-muted); text-decoration: none; &:hover { color: var(--color-ink); text-decoration: underline; } }
  }

  /* Terms, warranty and delivery: small links with an icon, in a row under the form */
  .product-page__policies {
    display: flex; flex-wrap: wrap; gap: var(--space-3xs) var(--space-m); margin-top: var(--space-s); font-size: var(--text-small);
    & a {
      display: inline-flex; align-items: center; gap: var(--space-2xs); min-height: var(--target-size); color: var(--color-muted); text-decoration: none;
      &:hover { color: var(--color-ink); text-decoration: underline; }
    }
    & .icon { width: var(--icon-s); height: var(--icon-s); }
  }
  .product-page__description { margin-block: var(--space-m); }

  /* Specs: a row per spec, the label beside its value, with a line between rows. The features are a list under them. */
  .product-specs { margin-block: var(--space-m); }
  .product-specs__list { border-bottom: 1px solid var(--color-line); font-size: var(--text-small); }
  .product-specs__item {
    display: grid; grid-template-columns: minmax(6rem, 2fr) minmax(0, 5fr); gap: var(--space-s); padding-block: var(--space-2xs); border-top: 1px solid var(--color-line);
    & dt { color: var(--color-muted); }
    & dd { margin: 0; color: var(--color-ink); }
  }
  .product-specs__features {
    margin-top: var(--space-m); padding-left: var(--list-indent); list-style: disc; color: var(--color-muted);
    & li + li { margin-top: var(--space-3xs); }
  }

  /* Downloads: outlined buttons side by side */
  .product-downloads { margin-block: var(--space-m); }
  .product-downloads__list {
    display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 12rem), 1fr)); gap: var(--space-2xs);
    @media (width < 40rem) { grid-template-columns: minmax(0, 1fr); }
  }
  .product-downloads__link { width: 100%; }
  .product-page__summary > :last-child { margin-bottom: 0; }

  /* ---- Basket, checkout and my account: the page heading ---- */
  .shop-page { padding-block: var(--space-xl) var(--space-section); }
  .shop-page__title { margin-bottom: var(--space-l); }
}
