/* ===== Base ===== */
:root {
  --blue: #0b57d0;
  --blue-dark: #083b8c;
  --yellow: #ffc220;
  --bg: #f6f7f9;
  --text: #0f172a;
  --muted: #475569;
  --card: #ffffff;
  --line: #e5e7eb;
  --shadow: 0 10px 30px rgba(15, 23, 42, 0.08);
  --radius: 16px;
  --radius-sm: 12px;
  --max: 1100px;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
  color: var(--text);
  background: var(--bg);
}

a { color: inherit; text-decoration: none; }
a:hover { text-decoration: underline; }

img { max-width: 100%; height: auto; }

.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
  white-space: nowrap; border: 0;
}

.skip-link {
  position: absolute;
  left: 12px;
  top: 12px;
  padding: 10px 12px;
  border-radius: 10px;
  background: #fff;
  border: 1px solid var(--line);
  transform: translateY(-200%);
  transition: transform 120ms ease;
  z-index: 9999;
}
.skip-link:focus { transform: translateY(0); }

/* ===== Header ===== */
.site-header {
  position: sticky;
  top: 0;
  z-index: 50;
  background: linear-gradient(180deg, var(--blue) 0%, var(--blue-dark) 100%);
  color: #fff;
  box-shadow: 0 10px 25px rgba(2, 6, 23, 0.25);
}

.header-inner {
  max-width: var(--max);
  margin: 0 auto;
  padding: 14px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.brand { display: grid; gap: 2px; }
.brand-logo {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-weight: 800;
  letter-spacing: 0.2px;
}
.brand-dot {
  width: 12px;
  height: 12px;
  border-radius: 999px;
  background: var(--yellow);
  box-shadow: 0 0 0 4px rgba(255, 194, 32, 0.22);
}
.brand-name { font-size: 18px; }
.brand-subtitle {
  margin: 0;
  font-size: 12px;
  color: rgba(255,255,255,0.85);
}

/* ===== Nav ===== */
.site-nav {
  border-top: 1px solid rgba(255,255,255,0.18);
  background: rgba(255,255,255,0.06);
  backdrop-filter: blur(8px);
}
.nav-list {
  max-width: var(--max);
  margin: 0 auto;
  padding: 8px 12px;
  list-style: none;
  display: flex;
  gap: 10px;
  overflow-x: auto;
}
.nav-link {
  display: inline-flex;
  align-items: center;
  padding: 8px 12px;
  border-radius: 999px;
  font-weight: 650;
  font-size: 14px;
  white-space: nowrap;
  color: rgba(255,255,255,0.92);
  border: 1px solid rgba(255,255,255,0.16);
  background: rgba(255,255,255,0.04);
}
.nav-link:hover { text-decoration: none; border-color: rgba(255,255,255,0.3); }
.nav-link.is-active {
  background: var(--yellow);
  border-color: rgba(255, 194, 32, 0.95);
  color: #111827;
}

/* ===== Page layout ===== */
.page {
  max-width: var(--max);
  margin: 0 auto;
  padding: 18px 14px 42px;
}

.section { margin-top: 18px; }
.section-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 6px;
}
.section-title { margin: 0; font-size: 22px; letter-spacing: -0.2px; }
.section-link {
  font-size: 14px;
  color: var(--muted);
}
.section-link:hover { color: var(--text); }

/* ===== Breadcrumb ===== */
.breadcrumb {
  margin-top: 6px;
}
.breadcrumb-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
  color: var(--muted);
  font-size: 13px;
}
.breadcrumb-item::after {
  content: "›";
  margin-left: 6px;
  color: #94a3b8;
}
.breadcrumb-item:last-child::after { content: ""; }
.breadcrumb a { color: var(--muted); }
.breadcrumb a:hover { color: var(--text); }

/* ===== Hero ===== */
.hero {
  margin-top: 12px;
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--line);
  background: radial-gradient(1200px 600px at 10% 0%, rgba(11,87,208,0.18), transparent 60%),
              radial-gradient(900px 520px at 80% 10%, rgba(255,194,32,0.22), transparent 55%),
              #fff;
  box-shadow: var(--shadow);
}
.hero-inner { padding: 18px; display: grid; gap: 10px; }
.hero-title { margin: 0; font-size: 28px; letter-spacing: -0.6px; }
.hero-subtitle { margin: 0; color: var(--muted); max-width: 60ch; }

.search {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  margin-top: 6px;
}
.search input {
  width: 100%;
  padding: 12px 12px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: #fff;
  font-size: 14px;
}

/* ===== Buttons ===== */
.btn {
  border: 1px solid transparent;
  border-radius: 12px;
  padding: 12px 14px;
  font-weight: 700;
  font-size: 14px;
  cursor: pointer;
  transition: transform 120ms ease, box-shadow 120ms ease, border-color 120ms ease, background 120ms ease;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}
.btn:active { transform: translateY(1px); }

.btn-primary {
  background: var(--yellow);
  color: #111827;
  border-color: rgba(255,194,32,0.9);
}
.btn-primary:hover { box-shadow: 0 10px 22px rgba(255, 194, 32, 0.25); }

.btn-secondary {
  background: var(--blue);
  color: #fff;
  border-color: rgba(255,255,255,0.2);
}
.btn-secondary:hover { background: #0a4fc0; }

.btn-ghost {
  background: #fff;
  color: var(--text);
  border-color: var(--line);
}
.btn-ghost:hover { box-shadow: 0 12px 26px rgba(15, 23, 42, 0.08); }

.btn-small { padding: 10px 12px; border-radius: 10px; font-size: 13px; }

/* ===== Product list (tableless) ===== */
.product-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  padding: 6px;
}

@media (max-width: 980px) {
  .product-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 520px) {
  .product-grid { grid-template-columns: 1fr; }
}

.product-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
  display: grid;
  grid-template-rows: auto 1fr;
  transition: transform 120ms ease, box-shadow 120ms ease;
}
.product-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 14px 36px rgba(15, 23, 42, 0.12);
}

/* 主页商品卡片的图片区：保持不变 */
.product-media {
  display: block;
  background: #f2f4f7;
}
.product-thumb {
  width: 100%;
  height: 170px;
  object-fit: cover;
  display: block;
}

.product-body { padding: 12px 12px 14px; display: grid; gap: 8px; }
.product-name { margin: 0; font-size: 16px; letter-spacing: -0.2px; }
.product-name a:hover { text-decoration: underline; }
.product-desc { margin: 0; color: var(--muted); font-size: 13px; }

.product-buy {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-top: 4px;
}
.product-price { margin: 0; }
.price { font-weight: 900; letter-spacing: -0.2px; }

/* ===== Info card ===== */
.info-card {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px 14px;
  margin: 6px;
}
.info-title { margin: 0; font-weight: 900; }
.info-text { margin: 6px 0 0; color: var(--muted); }

/* ===== Footer ===== */
.site-footer {
  margin-top: 26px;
  border-top: 1px solid var(--line);
  background: #fff;
}
.footer-inner {
  max-width: var(--max);
  margin: 0 auto;
  padding: 18px 14px;
}
.footer-title { margin: 0; font-weight: 900; }
.footer-text { margin: 6px 0 0; color: var(--muted); }

/* ===== Cart (hover + click toggle) ===== */
.cart-wrap { position: relative; }

.cart-toggle {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.cart-button {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 999px;
  border: 1px solid rgba(255,255,255,0.22);
  background: rgba(255,255,255,0.08);
  cursor: pointer;
  user-select: none;
}
.cart-button:hover { border-color: rgba(255,255,255,0.36); }
.cart-icon { font-size: 18px; }
.cart-text { font-weight: 800; }
.cart-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 22px;
  height: 22px;
  padding: 0 7px;
  border-radius: 999px;
  background: var(--yellow);
  color: #111827;
  font-weight: 900;
  font-size: 12px;
}

.cart-panel {
  position: fixed;
  right: 14px;
  top: 86px;
  width: min(380px, calc(100vw - 28px));
  max-height: calc(100vh - 110px);
  overflow: auto;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 24px 60px rgba(2, 6, 23, 0.25);
  display: none;
  z-index: 200;
}

.cart-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 12px;
  border-bottom: 1px solid var(--line);
}
.cart-title { margin: 0; font-size: 16px; }
.cart-close {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: 10px;
  border: 1px solid var(--line);
  cursor: pointer;
}
.cart-close:hover { background: #f6f7f9; }

.cart-items {
  list-style: none;
  margin: 0;
  padding: 10px 12px;
  display: grid;
  gap: 10px;
}
.cart-item {
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 10px 10px;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  background: #fff;
}
.cart-item-meta {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  min-width: 0;
}
.cart-item-thumb {
  width: 48px;
  height: 48px;
  object-fit: cover;
  border-radius: 8px;
  flex-shrink: 0;
}
.cart-item-meta > div { min-width: 0; flex: 1; }
.cart-item-name { margin: 0; font-weight: 900; font-size: 14px; line-height: 1.3; }
.cart-item-price { margin: 4px 0 0; color: var(--muted); font-size: 13px; }

.cart-qty {
  display: grid;
  gap: 6px;
  font-size: 12px;
  color: var(--muted);
}
.cart-qty input {
  width: 74px;
  padding: 10px 10px;
  border-radius: 12px;
  border: 1px solid var(--line);
  font-weight: 700;
  color: var(--text);
}

.cart-foot {
  padding: 12px 12px 14px;
  border-top: 1px solid var(--line);
  display: grid;
  gap: 10px;
}
.cart-summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: var(--muted);
}
.cart-summary strong { color: var(--text); font-size: 16px; }
/* show on hover (desktop) */
.cart-wrap:hover .cart-panel { display: block; }
/* show on click toggle (mobile or any) */
.cart-toggle:checked ~ .cart-panel { display: block; }

/* On very small screens: prefer click (disable hover-open) */
@media (max-width: 520px) {
  .cart-wrap:hover .cart-panel { display: none; }
  .cart-panel { right: 10px; }
}

/* ===== Product details layout ===== */
/* 静态 product.html：多段详情用 URL hash + :target 切换；勿用内联 style 覆盖（CSP style-src 'self' 会拦截） */
.product-detail { display: none; }
.product-detail:target { display: block; }
/* 动态 EJS 商品页：单页无 hash，用修饰类强制显示（双类优先级高于单独 .product-detail） */
.product-detail.product-detail--page {
  display: block;
}

.product-layout {
  display: grid;
  grid-template-columns: 1.15fr 0.85fr;
  gap: 16px;
  padding: 6px;
}

@media (max-width: 920px) {
  .product-layout { grid-template-columns: 1fr; }
}

.product-info {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px 14px;
  display: grid;
  gap: 10px;
  height: fit-content;
}

.pill {
  margin: 0;
  width: fit-content;
  padding: 6px 10px;
  border-radius: 999px;
  background: rgba(11,87,208,0.08);
  color: var(--blue);
  border: 1px solid rgba(11,87,208,0.18);
  font-weight: 800;
  font-size: 12px;
}

.product-title { margin: 0; font-size: 24px; letter-spacing: -0.5px; }
.product-price-lg { margin: 0; font-size: 22px; font-weight: 950; }
.product-description {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin: 0;
}
.product-desc-heading {
  margin: 0;
  font-size: 14px;
  font-weight: 800;
  letter-spacing: 0.02em;
  color: var(--text, #111);
}
.product-longdesc { margin: 0; color: var(--muted); line-height: 1.55; }

.product-actions { display: flex; gap: 10px; flex-wrap: wrap; }

.mini-links {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  font-size: 13px;
  color: var(--muted);
}
.mini-links a {
  padding: 6px 10px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: #fff;
}
.mini-links a:hover { color: var(--text); text-decoration: none; }

/* ===== Extension: Pure CSS gallery ===== */
.product-gallery {
display: grid;
gap: 12px;
}

/* Hide radio but keep state */
.media-radio {
position: absolute;
opacity: 0;
pointer-events: none;
}

/* Main image stage */
.media-stage {
position: relative;
border-radius: var(--radius);
overflow: hidden;
background: #fff;
border: 1px solid var(--line);
box-shadow: var(--shadow);
aspect-ratio: 4 / 3;
}

/* Frames stack on top of each other */
.media-frame {
position: absolute;
inset: 0;
margin: 0;
opacity: 0;
transform: scale(1.01);
transition: opacity 180ms ease, transform 180ms ease;
display: grid;
place-items: center;
}

.media-frame img {
width: 100%;
height: 100%;
object-fit: contain;
display: block;
}

/* ===== Gallery: generic rules (works with dynamic ids) ===== */
.product-gallery input:nth-of-type(1):checked ~ .media-stage .media-frame-1,
.product-gallery input:nth-of-type(2):checked ~ .media-stage .media-frame-2,
.product-gallery input:nth-of-type(3):checked ~ .media-stage .media-frame-3,
.product-gallery input:nth-of-type(4):checked ~ .media-stage .media-frame-4 {
opacity: 1;
transform: scale(1);
}

.media-thumbs {
display: grid;
grid-template-columns: repeat(4, minmax(0, 1fr));
gap: 10px;
}

.media-thumb {
border-radius: 12px;
overflow: hidden;
border: 1px solid var(--line);
background: #fff;
cursor: pointer;
user-select: none;
transition: transform 120ms ease, border-color 120ms ease, box-shadow 120ms ease;
}

.media-thumb img {
width: 100%;
height: 72px;
object-fit: cover;
display: block;
}

.media-thumb:hover {
transform: translateY(-1px);
border-color: #cbd5e1;
}

/* Highlight selected thumbnail */
.product-gallery input:nth-of-type(1):checked ~ .media-thumbs label:nth-child(1),
.product-gallery input:nth-of-type(2):checked ~ .media-thumbs label:nth-child(2),
.product-gallery input:nth-of-type(3):checked ~ .media-thumbs label:nth-child(3),
.product-gallery input:nth-of-type(4):checked ~ .media-thumbs label:nth-child(4) {
border-color: #2563eb;
box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.18);
}

@media (max-width: 520px) {
.media-thumb img { height: 56px; }
}

/* ===== Admin: product image drop zone (requirement 4) ===== */
.admin-dropzone {
  margin-top: 10px;
  padding: 20px 16px;
  border: 2px dashed var(--line);
  border-radius: var(--radius-sm);
  background: #fafbfc;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease;
}

.admin-dropzone:hover {
  border-color: #cbd5e1;
  background: #fff;
}

.admin-dropzone.is-dragover {
  border-color: var(--blue);
  background: #eef4ff;
}

.admin-dropzone:focus {
  outline: 2px solid var(--blue);
  outline-offset: 2px;
}

.admin-dropzone-title {
  margin: 0;
  font-weight: 600;
  font-size: 1.05rem;
}

.admin-image-error {
  margin-top: 10px;
  color: #b00020;
  font-size: 0.95rem;
}

.admin-image-preview-wrap {
  margin-top: 14px;
}

.admin-image-preview-wrap--empty .admin-image-preview-img[hidden] {
  display: none;
}

.admin-image-preview-img {
  display: block;
  max-width: 220px;
  max-height: 220px;
  width: auto;
  height: auto;
  object-fit: contain;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  background: #fff;
}