/* ==========================================================================
   SHOP LAYER -- ported from _starter 2026-07-15, running on Aurelia's dark
   luxury palette. _starter's shop.css references its light-theme token names
   (--surface/--accent/...); this alias block maps them onto Aurelia's own
   :root palette (style.css) instead of forking 400 lines of rules. Aurelia
   is a DARK theme: "surface" = near-black, accent = gold, text vars
   (--ink/--muted/--line) already share semantics with _starter.
   ========================================================================== */
:root {
  --surface: var(--ivory);
  --surface-alt: var(--stone);
  --surface-card: var(--paper);
  --accent: var(--gold);
  --accent-dark: var(--gold-light); /* accent TEXT on dark needs the lighter gold */
  --radius-md: 6px;
  --radius-sm: 3px;
}
/* _starter's base.css provides these section-background utilities; Aurelia's
   style.css predates them. */
.bg-surface { background: var(--surface); }
.bg-surface-alt { background: var(--surface-alt); }

/* ==========================================================================
   SHOP -- CSS for the e-commerce layer (announcement bar, cart, product
   grid/detail, policy pages). Only linked (see base.html) when has_shop is
   true, so a non-commerce site pays zero cost for this file. Same rule as
   sections.css: everything here reads tokens.css variables, nothing is
   hand-picked in isolation. Organized to roughly match templates/sections/
   render order (announcement -> cart -> grid -> detail -> policy).
   ========================================================================== */

/* ---- Semantic stock-state colors -------------------------------------
   Not brand-personality-derived like tokens.css's palette -- these are
   conventional traffic-light meanings (in stock / low / sold out) that
   should stay recognizable regardless of brand hue. Still built from
   --ink/--surface so they don't clash with a dark vs light brand base. */
:root {
  --stock-ok: #2f7d4f;
  --stock-low: #b8860b;
  --stock-out: #b03a2e;
}

/* ---- Announcement bar -------------------------------------------------- */
.announcement-bar {
  background: var(--ink);
  color: var(--surface);
}
.announcement-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  position: relative;
  padding: 10px 44px;
  text-align: center;
}
.announcement-row p {
  margin: 0;
  font-size: 0.82rem;
  letter-spacing: 0.02em;
  color: inherit;
}
.announcement-dismiss {
  position: absolute;
  right: 16px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: 0;
  color: inherit;
  font-size: 1.1rem;
  line-height: 1;
  cursor: pointer;
  padding: 6px;
  opacity: 0.8;
}
.announcement-dismiss:hover, .announcement-dismiss:focus-visible { opacity: 1; }
.announcement-bar[hidden] { display: none; }

/* ---- Cart toggle (header) ---------------------------------------------- */
.cart-toggle {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: 0;
  padding: 8px;
  margin-left: 6px;
  color: var(--ink);
  cursor: pointer;
}
.cart-badge {
  position: absolute;
  top: 0;
  right: 0;
  min-width: 17px;
  height: 17px;
  padding: 0 4px;
  border-radius: 999px;
  background: var(--accent-dark);
  color: var(--surface);
  font-size: 0.65rem;
  font-weight: 700;
  line-height: 17px;
  text-align: center;
}
/* Add-to-cart feedback: transform-only bump, matches the motion hard rule
   (see SKILL.md "动效词汇表" -- transform/opacity only, never box-shadow).
   Class is toggled briefly by shop.js on a successful add. */
.cart-badge.is-bumped { animation: cart-bump 0.4s ease; }
@keyframes cart-bump {
  0% { transform: scale(1); }
  40% { transform: scale(1.35); }
  100% { transform: scale(1); }
}
@media (prefers-reduced-motion: reduce) {
  .cart-badge.is-bumped { animation: none; }
}

/* ---- Cart drawer (native <dialog>) ------------------------------------- */
.cart-drawer {
  position: fixed;
  inset: 0 0 0 auto;
  margin: 0;
  height: 100vh;
  max-height: 100vh;
  width: min(420px, 100vw);
  border: 0;
  padding: 0;
  background: var(--surface-card);
  color: var(--ink);
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform 0.35s cubic-bezier(.65, 0, .35, 1);
}
.cart-drawer[open] { transform: translateX(0); }
.cart-drawer::backdrop { background: rgba(0, 0, 0, 0.4); }
@media (prefers-reduced-motion: reduce) {
  .cart-drawer { transition: none; }
}
.cart-drawer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 22px 24px;
  border-bottom: 1px solid var(--line);
}
.cart-drawer-head h2 { margin: 0; font-size: 1.2rem; }
.cart-drawer-close {
  background: none;
  border: 0;
  font-size: 1.6rem;
  line-height: 1;
  cursor: pointer;
  color: var(--ink);
  padding: 4px 8px;
}
.cart-items { flex: 1; overflow-y: auto; padding: 12px 24px; }
.cart-empty { color: var(--muted); text-align: center; margin-top: 40px; }
.cart-item {
  display: grid;
  grid-template-columns: 64px 1fr auto;
  gap: 14px;
  padding: 16px 0;
  border-bottom: 1px solid var(--line);
  align-items: start;
}
.cart-item img {
  width: 64px;
  height: 80px;
  object-fit: cover;
  border-radius: var(--radius-sm);
}
.cart-item-title { font-weight: 600; font-size: 0.92rem; margin: 0 0 4px; }
.cart-item-variant { font-size: 0.78rem; color: var(--muted); margin: 0 0 8px; }
.cart-item-qty {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
}
.cart-item-qty button {
  background: none;
  border: 0;
  width: 26px;
  height: 26px;
  cursor: pointer;
  font-size: 0.95rem;
  color: var(--ink);
}
.cart-item-qty span { min-width: 1.2em; text-align: center; font-size: 0.85rem; }
.cart-item-price { font-size: 0.88rem; font-weight: 600; text-align: right; }
.cart-item-remove {
  grid-column: 1 / -1;
  justify-self: start;
  background: none;
  border: 0;
  padding: 0;
  font-size: 0.76rem;
  text-decoration: underline;
  color: var(--muted);
  cursor: pointer;
}
.cart-item-remove:hover, .cart-item-remove:focus-visible { color: var(--ink); }
.cart-drawer-foot { padding: 20px 24px; border-top: 1px solid var(--line); }
.cart-subtotal-row {
  display: flex;
  justify-content: space-between;
  font-weight: 700;
  font-size: 1.05rem;
  margin-bottom: 6px;
}
.cart-note { font-size: 0.76rem; color: var(--muted); margin: 0 0 16px; }
.cart-checkout { width: 100%; justify-content: center; }
.cart-checkout:disabled { opacity: 0.5; cursor: not-allowed; }

/* ---- Shop hero ----------------------------------------------------------*/
.shop-hero { padding-bottom: 56px; }

/* ---- Product filter bar ------------------------------------------------ */
.product-filter-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 40px;
}
.filter-chip {
  background: var(--surface-card);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 9px 18px;
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
  cursor: pointer;
  transition: color 0.2s ease, border-color 0.2s ease, background 0.2s ease;
}
.filter-chip:hover, .filter-chip:focus-visible { border-color: var(--accent-dark); color: var(--ink); }
.filter-chip.is-active { background: var(--ink); border-color: var(--ink); color: var(--surface); }
@media (prefers-reduced-motion: reduce) { .filter-chip { transition: none; } }

/* ---- Product grid / card ------------------------------------------------ */
.product-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 28px;
}
.product-card {
  display: block;
  color: inherit;
}
.product-card-media {
  position: relative;
  aspect-ratio: 4 / 5;
  overflow: hidden;
  background: var(--surface-alt);
  border-radius: var(--radius-md);
}
.product-card-media img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.5s ease;
}
.product-card:hover .product-card-media img,
.product-card:focus-visible .product-card-media img { transform: scale(1.045); }
@media (prefers-reduced-motion: reduce) {
  .product-card-media img { transition: none; }
}
.product-card.is-sold-out .product-card-media img { opacity: 0.55; }
.stock-badge {
  display: inline-block;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 5px 10px;
  border-radius: var(--radius-sm);
}
.product-card-media .stock-badge {
  position: absolute;
  top: 12px;
  left: 12px;
  background: var(--surface-card);
  color: var(--ink);
}
.stock-badge.stock-out { background: var(--stock-out); color: #fff; }
.stock-badge.stock-sale { background: var(--accent); color: var(--ink-deep); }
.stock-badge.stock-ok { background: color-mix(in srgb, var(--stock-ok) 14%, transparent); color: var(--stock-ok); }
.stock-badge.stock-low { background: color-mix(in srgb, var(--stock-low) 16%, transparent); color: var(--stock-low); }
.product-card-body { padding-top: 14px; }
.product-card-category {
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--accent-dark);
}
.product-card-body h3 { margin: 4px 0 6px; font-size: 1.05rem; }
.product-card-price { display: flex; align-items: baseline; gap: 8px; margin: 0; }
.price-compare { text-decoration: line-through; color: var(--muted); font-size: 0.85rem; }
.price-current { font-weight: 700; }
.product-card[data-category][hidden] { display: none; }

/* ---- Product detail ------------------------------------------------------*/
.product-detail-grid {
  display: grid;
  grid-template-columns: 1.1fr 1fr;
  gap: 64px;
  align-items: start;
}
.product-gallery-main {
  display: block;
  width: 100%;
  padding: 0;
  border: 0;
  background: var(--surface-alt);
  border-radius: var(--radius-md);
  aspect-ratio: 4 / 5;
  overflow: hidden;
  cursor: zoom-in;
}
.product-gallery-main img { width: 100%; height: 100%; object-fit: cover; display: block; }
.product-thumbs { display: flex; gap: 10px; margin-top: 12px; }
.product-thumb {
  width: 64px;
  aspect-ratio: 4 / 5;
  padding: 0;
  border: 2px solid transparent;
  border-radius: var(--radius-sm);
  overflow: hidden;
  cursor: pointer;
  background: var(--surface-alt);
}
.product-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.product-thumb.is-active, .product-thumb:hover, .product-thumb:focus-visible { border-color: var(--accent-dark); }

.product-info .product-card-category { display: block; margin-bottom: 6px; }
.product-price-row { display: flex; align-items: baseline; gap: 12px; margin: 10px 0 14px; }
.product-price-row .price-current { font-size: 1.6rem; }
.product-info .stock-badge { margin-bottom: 20px; }
.product-info .stock-badge.stock-ok { background: color-mix(in srgb, var(--stock-ok) 14%, transparent); color: var(--stock-ok); }

.variant-picker { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 22px; }
.variant-chip {
  background: var(--surface-card);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 10px 16px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: border-color 0.2s ease, background 0.2s ease, color 0.2s ease;
}
.variant-chip:hover, .variant-chip:focus-visible { border-color: var(--accent-dark); }
.variant-chip.is-active { background: var(--ink); border-color: var(--ink); color: var(--surface); }
.variant-chip.is-disabled, .variant-chip:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  text-decoration: line-through;
}
@media (prefers-reduced-motion: reduce) { .variant-chip { transition: none; } }

.qty-stepper {
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  margin-bottom: 20px;
}
.qty-stepper button {
  background: none;
  border: 0;
  width: 40px;
  height: 40px;
  font-size: 1.1rem;
  cursor: pointer;
  color: var(--ink);
}
.qty-stepper input {
  width: 44px;
  border: 0;
  border-left: 1px solid var(--line);
  border-right: 1px solid var(--line);
  text-align: center;
  font: inherit;
  font-size: 0.95rem;
  height: 40px;
  -moz-appearance: textfield;
}
.qty-stepper input::-webkit-outer-spin-button,
.qty-stepper input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }

.add-to-cart-btn { display: flex; width: 100%; justify-content: center; margin-bottom: 36px; }
.add-to-cart-btn.is-added { background: var(--stock-ok); border-color: var(--stock-ok); }
/* Click feedback: transform-only, same rule as .cart-badge.is-bumped. */
.add-to-cart-btn.is-bumped { animation: add-to-cart-bump 0.3s ease; }
@keyframes add-to-cart-bump {
  0% { transform: scale(1); }
  50% { transform: scale(0.96); }
  100% { transform: scale(1); }
}
@media (prefers-reduced-motion: reduce) { .add-to-cart-btn.is-bumped { animation: none; } }

.product-desc { max-width: 60ch; margin-bottom: 28px; }
.product-desc p:last-child { margin-bottom: 0; }

.spec-table { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
.spec-table tr { border-top: 1px solid var(--line); }
.spec-table tr:first-child { border-top: 1px solid var(--line); }
.spec-table th, .spec-table td { text-align: left; padding: 10px 0; vertical-align: top; }
.spec-table th { color: var(--muted); font-weight: 500; width: 40%; }
.spec-table td { font-weight: 500; }

@media (max-width: 900px) {
  .product-detail-grid { grid-template-columns: 1fr; gap: 32px; }
}

/* ---- Product lightbox (native <dialog>) --------------------------------- */
.product-lightbox {
  border: 0;
  padding: 0;
  background: transparent;
  max-width: 92vw;
  max-height: 92vh;
}
.product-lightbox::backdrop { background: rgba(0, 0, 0, 0.85); }
.product-lightbox img { display: block; max-width: 92vw; max-height: 88vh; object-fit: contain; }
.product-lightbox-close {
  position: fixed;
  top: 20px;
  right: 24px;
  background: rgba(0, 0, 0, 0.5);
  color: #fff;
  border: 0;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  font-size: 1.4rem;
  line-height: 1;
  cursor: pointer;
}

/* ---- Policy pages --------------------------------------------------------*/
.policy-body { max-width: 72ch; }
.policy-body h2 { margin-top: 2em; }
.policy-body h2:first-child { margin-top: 0; }
.policy-body ul, .policy-body ol { padding-left: 1.3em; }
.policy-body a { text-decoration: underline; }

/* ---- Footer: shop adds a 5th column (Policies) -------------------------- */
.footer-grid { grid-template-columns: 1.6fr 1fr 1fr 1fr 1fr; }
@media (max-width: 1000px) {
  .footer-grid { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 760px) {
  .footer-grid { grid-template-columns: 1fr; }
}

@media (max-width: 640px) {
  .cart-drawer { width: 100vw; }
}

/* ---- Aurelia header integration (appended in the port) ------------------
   Aurelia's .header-row is flex space-between with brand|toggle|nav; the
   ported cart button joins as a 4th child. Switch to flex-start + auto
   margins so desktop reads brand ... nav cart, and mobile reads
   brand ... hamburger cart (the slide-in .nav is position:fixed on mobile,
   so it leaves the flex flow entirely). */
.header-row { justify-content: flex-start; }
.header-row .nav { margin-left: auto; }
.header-row .nav-toggle { margin-left: auto; }
.header-row .cart-toggle { order: 10; margin-left: 18px; color: var(--ink); }

/* Trust line under add-to-cart (shipping/returns reassurance at the buy point) */
.product-trust-line { font-size: 0.82rem; color: var(--muted); margin: -22px 0 30px; }
.product-trust-line a { color: var(--accent-dark); border-bottom: 1px solid currentColor; }
