/* ==========================================================================
   Cart, checkout, order received (Woo cart.php, form-checkout.php, thankyou.php)
   ========================================================================== */
@layer pages {
  /* ------------------------------------------------------------------------
     Hero + checkout steps
     ------------------------------------------------------------------------ */
  .page-hero--cart { padding-block-end: var(--space-5); }

  .cart-hero {
    display: flex;
    flex-wrap: wrap;
    align-items: end;
    justify-content: space-between;
    gap: var(--space-4) var(--space-6);
    margin-block-start: var(--space-4);
  }

  .cart-hero .page-title:focus { outline: none; }

  .checkout-steps {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    margin: 0;
    padding: 0;
    list-style: none;
    font-size: var(--fs-sm);
    color: var(--text-muted);
  }

  .checkout-steps__item { display: flex; align-items: center; gap: var(--space-2); }

  .checkout-steps__item + .checkout-steps__item::before {
    content: "";
    width: clamp(12px, 3vw, 32px);
    height: 1px;
    background: var(--border-strong);
  }

  .checkout-steps__num {
    display: grid;
    place-items: center;
    flex-shrink: 0;
    width: 28px;
    height: 28px;
    border: 1px solid var(--border-strong);
    border-radius: 50%;
    background: var(--surface);
    font-size: var(--fs-xs);
    font-weight: var(--fw-medium);
    font-variant-numeric: tabular-nums;
  }

  .checkout-steps__num .icon { --icon-size: 14px; display: none; }

  .checkout-steps__item[aria-current="step"] { color: var(--text); font-weight: var(--fw-medium); }
  .checkout-steps__item[aria-current="step"] .checkout-steps__num { border-color: var(--ink); background: var(--ink); color: var(--paper); }

  .checkout-steps__item.is-done { color: var(--text-soft); }
  .checkout-steps__item.is-done .checkout-steps__num { border-color: var(--success); background: var(--success); color: var(--paper); }
  .checkout-steps__item.is-done .checkout-steps__num > span { display: none; }
  .checkout-steps__item.is-done .checkout-steps__num .icon { display: block; }

  /* Narrow screens: only the current step keeps its label on screen */
  @media (max-width: 559px) {
    .checkout-steps__item:not([aria-current="step"]) .checkout-steps__label {
      position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap;
    }
  }

  /* ------------------------------------------------------------------------
     Small shared bits
     ------------------------------------------------------------------------ */
  .link-arrow--back .icon { margin-inline: 0 0.1em; }
  .link-arrow--back:hover .icon { translate: -4px 0; }

  .link-sm { font-size: var(--fs-sm); }

  .link-btn {
    display: inline-flex;
    align-items: center;
    min-height: 44px;
    padding: 0;
    border: 0;
    background: none;
    color: var(--text-soft);
    font: inherit;
    font-size: var(--fs-xs);
    text-decoration: underline;
    text-underline-offset: 0.2em;
    cursor: pointer;
  }

  .link-btn:hover { color: var(--text); }

  .coupon-tag {
    display: inline-block;
    margin-inline-start: 0.35em;
    padding: 0.1em 0.55em;
    border-radius: var(--radius-pill);
    background: var(--coral-50);
    color: var(--coral-800);
    font-size: var(--fs-xs);
    font-weight: var(--fw-medium);
    letter-spacing: 0.04em;
  }

  /* ------------------------------------------------------------------------
     Cart layout
     ------------------------------------------------------------------------ */
  .cart-layout { display: grid; gap: var(--space-6); align-items: start; }

  .cart-main { container-type: inline-size; display: grid; gap: var(--space-5); min-width: 0; }

  .free-shipping--page { border-radius: var(--radius-md); }

  @media (min-width: 1024px) {
    .cart-layout { grid-template-columns: minmax(0, 1fr) 380px; gap: var(--space-8); }
    .cart-collaterals { position: sticky; top: calc(var(--header-h-compact) + var(--nav-h) + var(--space-5)); }
  }

  /* Cart table (shop_table cart) */
  .cart-table { width: 100%; border-collapse: collapse; }

  .cart-table thead th {
    padding: 0 var(--space-3) var(--space-3) 0;
    border-block-end: 1px solid var(--border-strong);
    color: var(--text-muted);
    font-size: var(--fs-xs);
    font-weight: var(--fw-medium);
    text-align: start;
  }

  .cart-table td {
    padding: var(--space-4) var(--space-3) var(--space-4) 0;
    border-block-end: 1px solid var(--border);
    vertical-align: middle;
  }

  .cart-table :is(th, td):last-child { padding-inline-end: 0; }
  .cart-table .product-thumbnail { width: calc(96px + var(--space-4)); }
  .cart-table .product-thumbnail a { display: block; width: 96px; aspect-ratio: 4 / 5; overflow: hidden; border-radius: var(--radius-sm); background: var(--surface-3); }
  .cart-table .product-thumbnail img { width: 100%; height: 100%; object-fit: cover; }
  .cart-table td.product-name { display: grid; gap: 4px; min-width: 0; }
  .cart-table :is(th, td):is(.product-subtotal) { text-align: end; }
  .cart-table td.product-subtotal { font-weight: var(--fw-medium); white-space: nowrap; }
  .cart-table td.product-price { white-space: nowrap; }
  .cart-table .product-remove { width: 48px; text-align: end; }
  .cart-table .remove { width: 44px; height: 44px; color: var(--text-muted); }
  .cart-table .remove:hover { color: var(--coral-700); }
  .cart-table .price { display: inline-flex; flex-wrap: wrap; align-items: baseline; gap: 0 0.4em; }

  .cart-row__name { color: var(--text); font-weight: var(--fw-medium); line-height: 1.35; text-decoration: none; }
  .cart-row__name:hover { text-decoration: underline; color: var(--text); }
  .cart-row__unit { display: none; font-size: var(--fs-xs); color: var(--text-muted); }
  .cart-row__unit small { font-size: inherit; }

  .cart_item { transition: opacity var(--dur) var(--ease-out); }
  .cart_item.is-removing { opacity: 0; }

  /* td.product-name is a grid; keep the table cell box for the row */
  @container (min-width: 600px) {
    .cart-table td.product-name { display: table-cell; }
    .cart-table td.product-name > * + * { margin-block-start: 4px; }
    .cart-table td.product-name .cart-row__name { display: block; }
  }

  /* Narrow: each row becomes a card (Woo shop_table_responsive) */
  @container (max-width: 599px) {
    .cart-table, .cart-table tbody { display: block; }
    .cart-table thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }

    .cart-table tr.cart_item {
      display: grid;
      grid-template-columns: 80px minmax(0, 1fr) 44px;
      grid-template-areas: "thumb name remove" "thumb foot foot";
      gap: var(--space-2) var(--space-3);
      padding-block: var(--space-4);
      border-block-end: 1px solid var(--border);
    }

    .cart-table tr.cart_item td { padding: 0; border: 0; }
    .cart-table td.product-thumbnail { grid-area: thumb; align-self: start; width: auto; }
    .cart-table td.product-thumbnail a { width: 80px; }
    .cart-table td.product-name { grid-area: name; }
    .cart-table td.product-price { display: none; }
    /* quantity and line total share the bottom line */
    .cart-table td.product-quantity { grid-area: foot; justify-self: start; align-self: end; }
    .cart-table td.product-subtotal { grid-area: foot; justify-self: end; align-self: center; }
    .cart-table td.product-subtotal .price { flex-direction: column; align-items: flex-end; }
    .cart-table td.product-remove { grid-area: remove; align-self: start; width: auto; margin-block-start: -10px; margin-inline-end: -10px; }
    .cart-row__unit { display: inline-flex; }
  }

  /* Coupon + continue shopping */
  .cart-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: end;
    justify-content: space-between;
    gap: var(--space-4) var(--space-6);
  }

  .coupon { display: grid; gap: var(--space-2); flex: 1 1 280px; max-width: 440px; }
  .coupon__row { display: flex; gap: var(--space-2); }
  .coupon__row .input { flex: 1; min-width: 0; text-transform: uppercase; }
  .coupon__row .input::placeholder { text-transform: none; }
  .cart-actions .link-arrow { min-height: 44px; }

  /* ------------------------------------------------------------------------
     Totals (cart_totals + checkout review)
     ------------------------------------------------------------------------ */
  .cart_totals {
    container-type: inline-size;
    display: grid;
    gap: var(--space-5);
    padding: clamp(var(--space-5), 4vw, var(--space-6));
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    background: var(--surface);
  }

  .cart-totals__title,
  .checkout-card__title {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    font-family: var(--font-serif);
    font-size: var(--fs-xl);
    font-weight: var(--fw-regular);
    line-height: var(--lh-snug);
  }

  /* Rows are flex lines (keeps table semantics for screen readers);
     shipping choices drop under their label at every width */
  .totals-table { display: block; width: 100%; font-size: var(--fs-sm); }
  .totals-table tbody { display: block; }

  .totals-table tr {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    justify-content: space-between;
    gap: var(--space-1) var(--space-3);
    padding-block: var(--space-3);
    border-block-end: 1px solid var(--border);
  }

  .totals-table tr[hidden] { display: none; }
  .totals-table tr:last-child { border-block-end: 0; }
  .totals-table :is(th, td) { display: block; padding: 0; }
  .totals-table th { color: var(--text-soft); font-weight: var(--fw-regular); text-align: start; }
  .totals-table td { margin-inline-start: auto; text-align: end; }
  .totals-table .cart-discount td { color: var(--success); }
  .totals-table .cart-discount .link-btn { min-height: 24px; margin-inline-start: var(--space-2); }

  .totals-table .shipping td { flex-basis: 100%; text-align: start; }

  .totals-table tr.order-total { padding-block-start: var(--space-4); }
  .order-total th { color: var(--text); font-weight: var(--fw-medium); }
  .order-total strong { font-size: var(--fs-xl); font-weight: var(--fw-semibold); }
  .includes_tax { display: block; color: var(--text-muted); font-size: var(--fs-xs); }

  .shipping-methods { display: grid; margin: 0; padding: 0; list-style: none; }

  .ship-option { display: flex; width: 100%; }
  .ship-option__text { display: grid; gap: 2px; flex: 1; min-width: 0; }
  .ship-option__label { color: var(--text); }
  .ship-option__note { color: var(--text-muted); font-size: var(--fs-xs); }
  .ship-option__price { flex-shrink: 0; font-weight: var(--fw-medium); color: var(--text); }

  .wc-proceed-to-checkout .btn .icon { margin-inline-start: var(--space-1); }

  .trust-mini { display: grid; gap: var(--space-3); margin: 0; padding: 0; list-style: none; font-size: var(--fs-xs); color: var(--text-soft); }
  .trust-mini li { display: flex; align-items: flex-start; gap: var(--space-2); }
  .trust-mini .icon { --icon-size: 1.1rem; flex-shrink: 0; color: var(--text-muted); }

  /* Empty cart */
  .cart-empty-state {
    display: grid;
    justify-items: center;
    gap: var(--space-4);
    max-width: 52ch;
    margin-inline: auto;
    padding-block: var(--space-8);
    text-align: center;
  }

  .cart-empty-state[hidden] { display: none; }
  .cart-empty-state:focus { outline: none; }
  .cart-empty-state h2 { font-size: var(--fs-2xl); font-weight: var(--fw-light); }
  .cart-empty-state p { color: var(--text-soft); }

  .cart-empty-state__icon {
    display: grid;
    place-items: center;
    width: 88px;
    height: 88px;
    border-radius: 50%;
    background: var(--surface-2);
    color: var(--text-muted);
  }

  .return-to-shop { display: flex; flex-wrap: wrap; justify-content: center; gap: var(--space-3); }

  /* ------------------------------------------------------------------------
     Checkout
     ------------------------------------------------------------------------ */
  .checkout-back { margin-block-end: var(--space-5); min-height: 44px; }

  .checkout-layout { display: grid; gap: var(--space-5); align-items: start; }
  .checkout-main { display: grid; gap: var(--space-5); min-width: 0; }

  @media (min-width: 1024px) {
    .checkout-layout { grid-template-columns: minmax(0, 1fr) minmax(360px, 420px); gap: var(--space-7); }
  }

  fieldset.checkout-card { min-width: 0; margin: 0; }

  /* legend inside the card padding */
  .checkout-card > legend { float: inline-start; width: 100%; margin-block-end: var(--space-5); padding: 0; }
  .checkout-card > legend + * { clear: both; }

  .checkout-card__num {
    display: grid;
    place-items: center;
    flex-shrink: 0;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    background: var(--surface-2);
    font-family: var(--font-sans);
    font-size: var(--fs-sm);
    font-weight: var(--fw-medium);
  }

  .form-note .icon { vertical-align: -0.2em; margin-inline-end: 0.25em; }

  /* Receipt / invoice as two choice cards */
  .choice-row .check {
    padding-inline: var(--space-4);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-md);
    align-items: center;
  }

  .choice-row .check:has(input:checked) { border-color: var(--ink); background: var(--surface-2); }

  .invoice-fields { padding-block-start: var(--space-2); }
  .invoice-fields[hidden] { display: none; }

  /* Order review */
  .review-card { display: grid; gap: var(--space-5); }
  .review-card__head { display: flex; align-items: baseline; justify-content: space-between; gap: var(--space-3); }

  .review-items { display: grid; gap: var(--space-4); margin: 0; padding: 0; list-style: none; }

  .review-item { display: grid; grid-template-columns: 56px minmax(0, 1fr) auto; gap: var(--space-3); align-items: center; font-size: var(--fs-sm); }

  .review-item__media { position: relative; width: 56px; aspect-ratio: 4 / 5; border-radius: var(--radius-sm); background: var(--surface-3); }
  .review-item__media img { width: 100%; height: 100%; object-fit: cover; border-radius: inherit; }

  .review-item__qty {
    position: absolute;
    inset-block-start: -8px;
    inset-inline-end: -8px;
    display: grid;
    place-items: center;
    min-width: 22px;
    height: 22px;
    padding-inline: 5px;
    border-radius: var(--radius-pill);
    background: var(--ink);
    color: var(--paper);
    font-size: var(--fs-2xs);
    font-weight: var(--fw-semibold);
  }

  .review-item__info { display: grid; gap: 2px; min-width: 0; }
  .review-item__name { line-height: 1.35; }
  .review-item__meta { color: var(--text-muted); font-size: var(--fs-xs); }
  .review-item__price { font-weight: var(--fw-medium); white-space: nowrap; }

  #order_review { display: grid; gap: var(--space-5); }

  /* Payment methods */
  .woocommerce-checkout-payment { display: grid; gap: var(--space-5); padding-block-start: var(--space-5); border-block-start: 1px solid var(--border); }
  .payment-fieldset { min-width: 0; margin: 0; padding: 0; border: 0; }
  .payment-fieldset > legend { margin-block-end: var(--space-4); padding: 0; }

  .wc_payment_methods { display: grid; gap: var(--space-2); margin: 0; padding: 0; list-style: none; }

  .wc_payment_method {
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-md);
    transition: border-color var(--dur-fast), background-color var(--dur-fast);
  }

  .wc_payment_method:has(input:checked) { border-color: var(--ink); background: var(--surface-2); }

  .payment-option {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    min-height: 52px;
    padding-inline: var(--space-4);
    font-size: var(--fs-sm);
    font-weight: var(--fw-medium);
    cursor: pointer;
  }

  .payment-option input {
    appearance: none;
    flex-shrink: 0;
    display: grid;
    place-items: center;
    width: 20px;
    height: 20px;
    margin: 0;
    border: 1.5px solid var(--border-strong);
    border-radius: 50%;
    background: var(--surface);
    cursor: pointer;
  }

  .payment-option input::after { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--paper); scale: 0; transition: scale var(--dur-fast) var(--ease-out); }
  .payment-option input:checked { border-color: var(--ink); background: var(--ink); }
  .payment-option input:checked::after { scale: 1; }
  .payment-option input:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

  .payment-option__icon { --icon-size: 1.25rem; margin-inline-start: auto; color: var(--text-muted); }

  .payment_box { padding: 0 var(--space-4) var(--space-4) calc(var(--space-4) + 20px + var(--space-3)); color: var(--text-soft); font-size: var(--fs-sm); }
  .payment_box[hidden] { display: none; }

  .place-order { display: grid; gap: var(--space-4); }

  #place_order { justify-content: center; flex-wrap: wrap; }
  .place-order__total::before { content: "·"; margin-inline: 0.5em; }

  .secure-note { display: flex; align-items: center; justify-content: center; gap: var(--space-2); color: var(--text-muted); font-size: var(--fs-xs); }

  /* ------------------------------------------------------------------------
     Order received
     ------------------------------------------------------------------------ */
  .order-received { display: grid; gap: var(--space-6); max-width: 980px; margin-inline: auto; }
  .order-received:focus { outline: none; }

  .order-received__head { display: grid; justify-items: center; gap: var(--space-3); text-align: center; }
  .order-received__head p { color: var(--text-soft); }

  .woocommerce-thankyou-order-received {
    font-family: var(--font-serif);
    font-size: var(--fs-2xl);
    font-weight: var(--fw-light);
    line-height: var(--lh-tight);
    text-wrap: balance;
    color: var(--text) !important;
  }

  .woocommerce-order-overview {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 180px), 1fr));
    margin: 0;
    padding: 0;
    list-style: none;
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    background: var(--surface);
    overflow: hidden;
  }

  .woocommerce-order-overview li {
    display: grid;
    gap: 2px;
    padding: var(--space-4) var(--space-5);
    color: var(--text-muted);
    font-size: var(--fs-xs);
    box-shadow: -1px -1px 0 var(--border); /* inner dividers whichever way it wraps */
  }

  .woocommerce-order-overview strong { color: var(--text); font-size: var(--fs-base); font-weight: var(--fw-medium); }

  .order-received__grid { display: grid; gap: var(--space-5); align-items: start; }
  .order-received__grid .form-card { display: grid; gap: var(--space-4); }
  .order-next p { color: var(--text-soft); }

  @media (min-width: 900px) {
    .order-received__grid { grid-template-columns: 1fr 1.2fr; }
  }

  .bank-details { display: grid; grid-template-columns: auto 1fr; gap: var(--space-2) var(--space-4); margin: 0; font-size: var(--fs-sm); }
  .bank-details dt { color: var(--text-muted); }
  .bank-details dd { margin: 0; overflow-wrap: anywhere; }

  .order-received__actions { display: flex; flex-wrap: wrap; justify-content: center; gap: var(--space-3); }
  .order-received > .form-note { text-align: center; }
}
