/* ============================================================
   CART (cart.php) + CHECKOUT (checkout.php) — shared stylesheet
   Mobile-first. Cart contents come from the browser cart (MSCart).
   ============================================================ */

.cart-section { padding: 28px 0 8px; background: var(--primary-tint); }
.cart-layout, .checkout-layout { display: grid; gap: 24px; align-items: start; }
.cart-main, .cart-summary, .co-main, .co-summary { min-width: 0; }

/* ---------- tick animation for changing numbers ---------- */
@keyframes tick { 0% { transform: scale(1); color: inherit; } 35% { transform: scale(1.12); color: var(--primary-dark); } 100% { transform: scale(1); color: inherit; } }
.tick { display: inline-block; animation: tick .45s var(--ease); }
@keyframes rowIn { from { opacity: 0; transform: translateY(18px); } to { opacity: 1; transform: none; } }

/* ---------- cart list ---------- */
.cart-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.cart-head h2 { margin: 0; font-size: 1.3rem; color: var(--brand-navy); }
.cart-head-count { font-weight: 600; color: var(--ink-soft); font-size: 1rem; }
.cart-clear {
  display: inline-flex; align-items: center; gap: 6px; min-height: 44px; padding: 0 12px;
  font-size: .85rem; font-weight: 700; color: var(--ink-soft); background: transparent;
  border: 1.5px solid var(--line); border-radius: var(--radius-s);
  transition: color .2s, border-color .2s, background .2s;
}
.cart-clear:hover { color: var(--accent-strong); border-color: #F5B8BB; background: var(--accent-tint); }
.cart-clear.is-confirm { color: #fff; background: var(--accent-strong); border-color: var(--accent-strong); animation: pop .3s var(--ease); }

.cart-list { background: #fff; border: 1px solid var(--line); border-radius: var(--radius-m); box-shadow: var(--shadow-sm); overflow: hidden; }
.cart-row {
  display: grid; gap: 4px 12px; align-items: center; padding: 14px;
  grid-template-columns: 84px minmax(0, 1fr) auto;
  grid-template-areas: "img info remove" "img qty line";
  border-bottom: 1px solid var(--line-soft); overflow: hidden;
  animation: rowIn .5s var(--ease) both; animation-delay: calc(var(--i, 0) * 70ms);
  transition: background .25s;
}
.cart-row:last-child { border-bottom: 0; }
.cart-row:hover { background: var(--bg-soft); }
.cart-row.is-removing {
  max-height: 0 !important; opacity: 0; transform: translateX(44px);
  padding-block: 0; border-bottom-width: 0; animation: none;
  transition: max-height .38s var(--ease), opacity .28s, transform .38s var(--ease), padding .38s var(--ease);
}
.cart-img { grid-area: img; align-self: start; display: block; width: 84px; aspect-ratio: 1; overflow: hidden; background: var(--bg-soft); border: 1px solid var(--line); border-radius: var(--radius-s); }
.cart-img img { width: 100%; height: 100%; object-fit: cover; transition: transform .5s var(--ease); }
.cart-row:hover .cart-img img { transform: scale(1.08); }
.cart-info { grid-area: info; display: flex; flex-direction: column; gap: 2px; min-width: 0; align-self: start; }
.cart-name { font-family: var(--font-head); font-weight: 700; font-size: .98rem; line-height: 1.3; color: var(--ink); overflow-wrap: anywhere; }
.cart-name:hover { color: var(--primary-dark); }
.cart-code { font-size: .74rem; color: var(--ink-faint); }
.cart-unit { font-size: .85rem; font-weight: 600; color: var(--ink-soft); }

.cart-qty-wrap { grid-area: qty; display: flex; flex-direction: column; align-items: flex-start; gap: 4px; }
.cart-qty { display: inline-flex; height: 44px; overflow: hidden; background: #fff; border: 1.5px solid var(--line); border-radius: var(--radius-s); transition: border-color .2s, box-shadow .2s; }
.cart-qty:focus-within { border-color: var(--primary); box-shadow: 0 0 0 4px rgba(8,152,204,.16); }
.cart-qty button { display: grid; place-items: center; width: 40px; border: 0; background: var(--bg-soft); color: var(--primary-dark); transition: background .2s, color .2s, transform .15s; }
.cart-qty button:hover:not(:disabled) { background: var(--primary-btn); color: #fff; }
.cart-qty button:active:not(:disabled) { transform: scale(.9); }
.cart-qty button:disabled { opacity: .45; cursor: not-allowed; }
.cart-qty input {
  width: 46px; padding: 0; text-align: center; font: inherit; font-weight: 700; color: var(--ink);
  border: 0; border-inline: 1.5px solid var(--line); background: #fff; -moz-appearance: textfield; appearance: textfield;
}
.cart-qty input:focus { outline: none; }
.cart-qty input::-webkit-outer-spin-button, .cart-qty input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.cart-limit { font-size: .72rem; font-weight: 600; color: var(--warn); }

.cart-line { grid-area: line; justify-self: end; font-family: var(--font-head); font-weight: 800; font-size: 1.05rem; color: var(--brand-navy); white-space: nowrap; }
.cart-remove {
  grid-area: remove; justify-self: end; align-self: start; display: grid; place-items: center; width: 44px; height: 44px; margin: -8px -8px 0 0;
  border: 0; border-radius: 50%; background: transparent; color: var(--ink-faint);
  transition: color .2s, background .2s, transform .25s var(--ease);
}
.cart-remove:hover { color: var(--accent-strong); background: var(--accent-tint); transform: rotate(-8deg) scale(1.08); }

.cart-continue { display: inline-flex; align-items: center; gap: 6px; min-height: 44px; margin-top: 14px; font-weight: 700; color: var(--primary-dark); transition: gap .25s var(--ease); }
.cart-continue:hover { gap: 10px; text-decoration: underline; }

/* ---------- summary cards (cart + checkout) ---------- */
.cart-summary, .co-summary {
  padding: 22px 20px; background: #fff; border: 1px solid var(--line); border-radius: var(--radius-l); box-shadow: var(--shadow-md);
  position: relative; overflow: hidden;
}
.cart-summary::before, .co-summary::before { content: ''; position: absolute; left: 0; right: 0; top: 0; height: 5px; background: var(--primary); }
.cart-summary h2, .co-summary h2 { font-size: 1.2rem; margin: 6px 0 16px; color: var(--brand-navy); }
.sum-lines { margin: 0 0 14px; }
.sum-line { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; padding: 10px 0; border-bottom: 1px dashed var(--line); }
.sum-line dt { font-size: .92rem; color: var(--ink-soft); }
.sum-line dd { margin: 0; font-weight: 700; text-align: right; }
.sum-muted { font-weight: 500 !important; font-size: .85rem; color: var(--ink-faint); }
.sum-total { border-bottom: 0; padding-top: 14px; }
.sum-total dt { font-weight: 700; color: var(--ink); }
.sum-total dd { font-family: var(--font-head); font-size: 1.6rem; font-weight: 800; color: var(--brand-navy); }
.sum-note { margin: 0 0 18px; font-size: .8rem; color: var(--ink-soft); }
.cart-summary .btn + .btn { margin-top: 10px; }

/* free-shipping nudge */
.ship-nudge { margin: 0 0 16px; padding: 12px 14px; background: var(--primary-light); border-radius: var(--radius-s); font-size: .85rem; font-weight: 600; color: var(--primary-deep); }
.ship-nudge.is-free { background: var(--ok-tint); color: #11693A; }
.ship-bar { height: 8px; margin-top: 8px; overflow: hidden; background: #fff; border-radius: 999px; }
.ship-bar span { display: block; height: 100%; width: 0; background: var(--primary-btn); border-radius: 999px; transition: width .5s var(--ease); }
.ship-nudge.is-free .ship-bar span { background: var(--ok); }
.sum-perks { display: grid; gap: 10px; margin-top: 20px; padding-top: 16px; border-top: 1px solid var(--line-soft); font-size: .85rem; color: var(--ink-soft); }
.sum-perks li { display: flex; align-items: flex-start; gap: 10px; }
.sum-perks .icon { color: var(--primary); margin-top: 2px; }
.sum-perks a { color: var(--primary-dark); font-weight: 600; text-decoration: underline; text-underline-offset: 3px; }

.cart-empty { margin: 8px 0 24px; padding: 56px 20px; }
.cart-empty .usp-icon { animation: float 5s ease-in-out infinite; }
.cart-empty-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 12px; margin-top: 10px; }

/* ============================================================
   CHECKOUT
   ============================================================ */
.co-main { display: grid; gap: 18px; }
.co-card { padding: 20px 18px; background: #fff; border: 1px solid var(--line); border-radius: var(--radius-m); box-shadow: var(--shadow-sm); }
.co-card h2 { display: flex; align-items: center; gap: 12px; margin: 0 0 18px; font-size: 1.1rem; color: var(--brand-navy); }
.co-num { display: inline-grid; place-items: center; width: 30px; height: 30px; flex-shrink: 0; font-size: .9rem; font-weight: 800; color: #fff; background: var(--primary-btn); border-radius: 50%; }
.co-card .field:last-child { margin-bottom: 0; }
.opt { font-weight: 500; color: var(--ink-faint); }
.field select { appearance: none; -webkit-appearance: none; padding-right: 40px; cursor: pointer;
  background: #fff url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%23056A91' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E") no-repeat right 14px center; }

/* payment method radios */
.pay-group { display: grid; gap: 10px; }
.pay-option { position: relative; display: block; cursor: pointer; }
.pay-option input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.pay-body {
  display: flex; align-items: center; gap: 14px; min-height: 64px; padding: 12px 16px 12px 14px;
  background: #fff; border: 1.5px solid var(--line); border-radius: var(--radius-m);
  transition: border-color .2s, background .2s, box-shadow .25s, transform .25s var(--ease);
}
.pay-option:hover .pay-body { border-color: #A9C7D6; transform: translateY(-2px); }
.pay-icon { display: grid; place-items: center; width: 42px; height: 42px; flex-shrink: 0; color: var(--primary-dark); background: var(--primary-light); border-radius: 12px; transition: background .25s, color .25s; }
.pay-text { display: flex; flex-direction: column; min-width: 0; line-height: 1.3; }
.pay-text strong { font-size: .95rem; color: var(--ink); }
.pay-text span { font-size: .8rem; color: var(--ink-soft); }
.pay-tick { margin-left: auto; display: grid; place-items: center; width: 22px; height: 22px; flex-shrink: 0; border: 2px solid var(--line); border-radius: 50%; color: transparent; transition: background .2s, border-color .2s, color .2s, transform .3s var(--ease); }
.pay-option input:checked ~ .pay-body { border-color: var(--primary); background: var(--primary-tint); box-shadow: 0 0 0 3px rgba(8,152,204,.16); }
.pay-option input:checked ~ .pay-body .pay-icon { background: var(--primary-btn); color: #fff; }
.pay-option input:checked ~ .pay-body .pay-tick { background: var(--primary-btn); border-color: var(--primary-btn); color: #fff; transform: scale(1.1); }
.pay-option input:focus-visible ~ .pay-body { outline: 3px solid var(--primary); outline-offset: 2px; }

.co-terms { margin-bottom: 18px; }
.co-terms a { color: var(--primary-dark); font-weight: 600; text-decoration: underline; text-underline-offset: 3px; }
.co-note { margin: 14px 0 0; font-size: .8rem; text-align: center; color: var(--ink-faint); }

/* unavailable-items notice (409 from api/order.php) */
.co-problems { align-items: flex-start; }
.co-problem-list { margin: 8px 0 12px; padding-left: 18px; list-style: disc; font-weight: 500; }
.co-problem-list li { margin-bottom: 2px; color: var(--ink); }

/* checkout summary list */
.co-items { display: grid; gap: 12px; margin: 0 0 14px; max-height: 340px; overflow-y: auto; padding-right: 2px; }
.co-item { display: grid; grid-template-columns: 56px minmax(0, 1fr) auto; gap: 12px; align-items: center; animation: rowIn .45s var(--ease) both; animation-delay: calc(var(--i, 0) * 60ms); }
.co-thumb { position: relative; width: 56px; aspect-ratio: 1; background: var(--bg-soft); border: 1px solid var(--line); border-radius: var(--radius-s); }
.co-thumb img { width: 100%; height: 100%; object-fit: cover; border-radius: calc(var(--radius-s) - 1px); }
.co-qty { position: absolute; top: -7px; right: -7px; min-width: 20px; height: 20px; padding: 0 5px; display: grid; place-items: center; font-size: .7rem; font-weight: 700; color: #fff; background: var(--brand-navy); border-radius: 999px; border: 2px solid #fff; }
.co-item-name { font-size: .88rem; font-weight: 600; line-height: 1.3; color: var(--ink); overflow-wrap: anywhere; }
.co-item-sub { display: block; font-size: .75rem; font-weight: 500; color: var(--ink-faint); }
.co-item-total { font-weight: 700; font-size: .9rem; color: var(--brand-navy); white-space: nowrap; }
.co-edit { display: inline-flex; align-items: center; min-height: 44px; font-size: .85rem; font-weight: 700; color: var(--primary-dark); text-decoration: underline; text-underline-offset: 3px; }

/* success panel */
.order-success { max-width: 640px; margin: 8px auto 24px; padding: 40px 24px; text-align: center; background: #fff; border: 1px solid var(--line); border-radius: var(--radius-l); box-shadow: var(--shadow-lg); position: relative; overflow: hidden; }
.order-success::before { content: ''; position: absolute; left: 0; right: 0; top: 0; height: 5px; background: var(--ok); }
.order-success.is-shown .success-icon { animation: pop .6s var(--ease) both; }
.order-success.is-shown > *:not(.success-icon) { animation: rise .6s var(--ease) both; }
.order-success.is-shown > h2 { animation-delay: .15s; }
.order-success.is-shown > p { animation-delay: .22s; }
.order-success.is-shown .order-ref { animation-delay: .3s; }
.order-success.is-shown .success-facts { animation-delay: .38s; }
.order-success.is-shown .success-actions { animation-delay: .46s; }
.success-icon { display: inline-grid; place-items: center; width: 84px; height: 84px; margin-bottom: 18px; color: #fff; background: var(--ok); border-radius: 50%; box-shadow: 0 0 0 10px var(--ok-tint); }
.order-success h2 { margin-bottom: 8px; }
.order-success > p { color: var(--ink-soft); }
.order-ref { display: inline-flex; flex-direction: column; gap: 2px; margin: 8px 0 20px; padding: 12px 26px; background: var(--primary-tint); border: 1.5px dashed var(--primary); border-radius: var(--radius-m); }
.order-ref small { font-size: .72rem; font-weight: 700; letter-spacing: .1em; text-transform: uppercase; color: var(--ink-soft); }
.order-ref strong { font-family: var(--font-head); font-size: 1.5rem; letter-spacing: .04em; color: var(--brand-navy); }
.success-facts { display: grid; gap: 8px; margin: 0 auto 22px; max-width: 420px; text-align: left; font-size: .92rem; }
.success-facts div { display: flex; justify-content: space-between; gap: 14px; padding: 8px 0; border-bottom: 1px dashed var(--line); }
.success-facts dt { color: var(--ink-soft); }
.success-facts dd { margin: 0; font-weight: 700; text-align: right; overflow-wrap: anywhere; }
.success-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 12px; }

/* ---------- >= 640px ---------- */
@media (min-width: 640px) {
  .cart-section { padding-top: 40px; }
  .cart-row { padding: 18px 20px; gap: 6px 18px; grid-template-columns: 96px minmax(0, 1fr) auto auto auto; grid-template-areas: "img info qty line remove"; }
  .cart-img { width: 96px; align-self: center; }
  .cart-info { align-self: center; }
  .cart-line { min-width: 90px; font-size: 1.1rem; }
  .cart-remove { align-self: center; margin: 0; }
  .co-card { padding: 26px 26px; }
  .order-success { padding: 52px 40px; }
}

/* ---------- >= 960px ---------- */
@media (min-width: 960px) {
  .cart-layout { grid-template-columns: minmax(0, 1fr) 380px; gap: 32px; }
  .checkout-layout { grid-template-columns: minmax(0, 1fr) 400px; gap: 32px; }
  .cart-summary, .co-summary { position: sticky; top: 150px; }
  /* summary is first in the DOM (shown above the form on mobile) but sits on the right on desktop */
  .co-summary { grid-column: 2; grid-row: 1; }
  .co-main { grid-column: 1; grid-row: 1; }
}

/* fixes */
.co-items { padding: 8px 8px 0 0; }
.field label.check { display: flex; margin-bottom: 0; font-weight: 500; }
