/*
 * WooCommerce Mini-Cart block, restyled to the header design.
 *
 * The design's cart item is an icon beside two stacked lines — "Cart (n)" over the subtotal. The
 * block gives a flex row of [icon + absolutely-positioned badge] then the amount, so the button is
 * re-laid-out as a grid: the badge and the amount are pulled into a second column, one per row,
 * and the theme's own cart icon is drawn as the button's ::before.
 *
 * These rules mirror .cart-btn, .cart-btn--topbar and .cart-btn__icon in header.css, including
 * their breakpoints, because header.css belongs to the UI team and nothing here edits it. The two
 * instances are mutually exclusive by width — the pill in .hd-right down to 1640px, the full-height
 * white bar in the top utility bar below that — and that swap now lives here, since the elements it
 * used to act on are gone.
 *
 * The Mini-Cart's own stylesheet is left to WooCommerce to enqueue when the block renders; see the
 * comment in includes/assets.php for why pulling wc-blocks-style into the head breaks the drawer.
 */

.cart-mini .wc-block-mini-cart {
  display: block;
}

.cart-mini .wc-block-mini-cart__button {
  display: grid;
  grid-template-columns: 22px auto;
  grid-template-rows: auto auto;
  align-items: center;
  justify-content: start;
  gap: 0 var(--space-10);
  background-color: var(--secondary);
  color: var(--white);
  padding: 5px var(--space-16);
  border: 0;
  border-radius: var(--radius-md);
  cursor: pointer;
  line-height: 1.2;
  transition: var(--transition);
}

.cart-mini .wc-block-mini-cart__button:hover {
  background-color: var(--primary);
}

/* The theme's cart icon, spanning both rows in the first column. Drawn as a mask so it takes
   currentColor and inverts with the button in the top-bar variant below. */
.cart-mini .wc-block-mini-cart__button::before {
  content: "";
  grid-column: 1;
  grid-row: 1 / 3;
  width: 22px;
  height: 18px;
  flex-shrink: 0;
  background-color: currentColor;
  -webkit-mask-image: url("../images/svg/cart.svg");
  mask-image: url("../images/svg/cart.svg");
  -webkit-mask-size: contain;
  mask-size: contain;
  -webkit-mask-repeat: no-repeat;
  mask-repeat: no-repeat;
  -webkit-mask-position: center;
  mask-position: center;
}

/* Lets the badge escape its wrapper and become a grid item of the button. */
.cart-mini .wc-block-mini-cart__quantity-badge {
  display: contents;
}

.cart-mini .wc-block-mini-cart__icon {
  display: none;
}

/* Out of WooCommerce's floating bubble and back into the text flow as the "Cart (n)" line. */
.cart-mini .wc-block-mini-cart__badge {
  grid-column: 2;
  grid-row: 1;
  position: static;
  display: block;
  left: auto;
  margin: 0;
  padding: 0;
  height: auto;
  min-width: 0;
  border: 0;
  border-radius: 0;
  transform: none;
  font-size: var(--fs-13);
  font-weight: var(--fw-semibold);
  line-height: 1.4;
  white-space: nowrap;
  /* The block binds badge colours as inline styles (data-wp-style--background-color / --color),
       so a class rule cannot win. !important is the only lever short of theming the block. */
  background-color: transparent !important;
  color: inherit !important;
}

.cart-mini .wc-block-mini-cart__badge::before {
  content: "Cart (";
}

.cart-mini .wc-block-mini-cart__badge::after {
  content: ")";
}
.wc-block-components-drawer__screen-overlay--with-slide-in
  .wc-block-components-drawer {
  .wc-block-components-drawer__content {
    margin-top: 0 !important;
  }
}
.cart-mini .wc-block-mini-cart__amount {
  grid-column: 2;
  grid-row: 2;
  font-size: var(--fs-12);
  font-weight: var(--fw-medium);
  line-height: 1.4;
  color: inherit !important;
  text-align: left;
}
.wc-block-components-button,
.wc-block-components-drawer__close-wrapper {
  button.wc-block-components-drawer__close,
  .wc-block-mini-cart__footer
    .wc-block-mini-cart__footer-actions
    .wp-block-woocommerce-mini-cart-checkout-button-block {
    outline: none !important;
    border: none !important;
    box-shadow: none !important;
  }
}
.wc-block-mini-cart__template-part h2.wc-block-mini-cart__title {
  font-size: 24px !important;
  margin: 0 !important;
  mask-image: none !important;
  padding: 20px;
  border-bottom: 1px solid var(--border-color);
  text-transform: capitalize;
}
.wc-block-mini-cart__drawer
  .wp-block-woocommerce-mini-cart-contents
  .wc-block-components-notices {
  margin: 0;
}
.wc-block-components-button.wc-block-mini-cart__shopping-button.wp-block-woocommerce-mini-cart-shopping-button-block {
  padding: var(--space-20) var(--space-30);
  border-radius: var(--radius-md);
  line-height: 1;
  text-transform: capitalize;
}
.wc-block-mini-cart__template-part
  .wc-block-mini-cart__items
  tr:not(:last-child) {
  border-bottom: 1px solid var(--border-color);
}
.wc-block-mini-cart__template-part .wc-block-mini-cart__items tr {
  padding: 20px !important;
}
.wc-block-mini-cart__items {
  padding: 0 !important;
  background-color: var(--bg-alt);
}
.wc-block-mini-cart__footer-actions {
  .wc-block-mini-cart__footer-cart.is-style-outline.wp-block-woocommerce-mini-cart-cart-button-block {
    background: transparent;
    color: var(--secondary);
    &:hover {
      background: var(--secondary);
      color: var(--white);
    }
  }
  .wp-block-woocommerce-mini-cart-checkout-button-block {
    background: var(--secondary);
    color: var(--white);
    &:hover {
      background: var(--primary);
      color: var(--white);
    }
  }
  .wc-block-components-button {
    text-transform: capitalize;
  }
}
.wc-block-mini-cart__template-part
  h2.wc-block-mini-cart__title
  .wp-block-woocommerce-mini-cart-title-items-counter-block {
  font-size: 16px;
}
/* ==========================================================================
   Top utility bar variant — white, full height, square. Mirrors .cart-btn--topbar.
   ========================================================================== */
.cart-mini--topbar {
  display: none;
  height: 100%;
}

/* Full width as well as full height: the design's cart was the anchor itself, so `flex: 1` on it
   stretched the white background across the rest of the bar. Here `flex: 1` lands on the wrapper
   and the block sits inside it, so both inner levels have to be told to fill — otherwise the
   button is only as wide as its text and the dark bar shows through beside it. */
.cart-mini--topbar .wc-block-mini-cart,
.cart-mini--topbar .wc-block-mini-cart__button {
  width: 100%;
  height: 100%;
}

.cart-mini--topbar .wc-block-mini-cart__button {
  background-color: var(--white);
  color: var(--secondary);
  padding: 0 var(--header-padding);
  border-radius: 0;
}

.cart-mini--topbar .wc-block-mini-cart__button:hover {
  background-color: var(--primary);
  color: var(--white);
}

.cart-mini--topbar .wc-block-mini-cart__button::before {
  width: 18px;
  height: 15px;
}

/* ==========================================================================
   Responsive — the same breakpoints header.css used for .cart-btn
   ========================================================================== */
.wc-block-components-quantity-selector
  > .wc-block-components-quantity-selector__button--minus {
  border-right: 1px solid var(--border-color);
}
.wc-block-components-quantity-selector
  > .wc-block-components-quantity-selector__button--plus {
  border-left: 1px solid var(--border-color);
}
.wc-block-mini-cart__template-part
  .wc-block-mini-cart__items
  tr
  td
  a.wc-block-components-product-name,
table.wc-block-cart-items
  .wc-block-cart-items__row
  .wc-block-cart-item__prices {
  color: var(--secondary);
}
.wc-block-mini-cart__template-part .wc-block-components-product-metadata {
  display: none !important;
}
.wc-block-components-button:not(.is-link) {
  border-radius: 10px;
}

@media (max-width: 1639.98px) {
  .hd-right .cart-mini--main {
    display: none;
  }

  .cart-mini--topbar {
    display: block;
  }
}
@media (max-width: 991.98px) {
  .wc-block-mini-cart__drawer
    .wc-block-mini-cart__template-part
    .wc-block-mini-cart__items
    tr {
    padding: 16px 0px !important;
  }
}
/* Icon only: the two text rows collapse away and the grid becomes a single cell. */
@media (max-width: 767.98px) {
  .cart-mini .wc-block-mini-cart__button {
    grid-template-columns: auto;
    grid-template-rows: auto;
    gap: 0;
  }

  .cart-mini .wc-block-mini-cart__button::before {
    grid-column: 1;
    grid-row: 1;
  }

  .cart-mini .wc-block-mini-cart__badge,
  .cart-mini .wc-block-mini-cart__amount {
    display: none;
  }
}

/* Back to one row, side by side — the top bar becomes a two-item strip at this width and the
   cart takes half of it. Mirrors the .cart-btn .cart-text row rules in header.css. */
@media (max-width: 575.98px) {
  .cart-mini--topbar {
    flex: 1;
  }
  .wc-block-components-drawer
    table.wc-block-cart-items
    .wc-block-cart-items__row
    .wc-block-cart-item__wrap {
    align-items: flex-start;
  }
  .cart-mini--topbar .wc-block-mini-cart__button {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 5px;
    padding: 0 10px;
  }

  .cart-mini--topbar .wc-block-mini-cart__badge {
    display: block;
    font-size: 12px;
    margin-right: 5px;
  }

  .cart-mini--topbar .wc-block-mini-cart__amount {
    display: block;
  }
}
