/*
 * VitaminC購物網 storefront styles: DESIGN.md "Back of the Bottle" (瓶身背面).
 * CSP style-src 'self': no inline styles anywhere, everything lives in this file.
 * Breakpoints (information architecture §7): phone ≤767px, tablet 768–1023px, desktop ≥1024px.
 * Touch targets are 44×44px for every pointer type (IA §7), not only coarse pointers.
 */

/* ---------- Fonts: Latin subsets self-hosted (OFL, see /fonts); Chinese uses system fonts (Alec 2026-11-28). ---------- */
@font-face {
  font-family: "Barlow Condensed";
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url("../fonts/barlow-condensed-700.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

@font-face {
  font-family: "Barlow Condensed";
  font-style: normal;
  font-weight: 800;
  font-display: swap;
  src: url("../fonts/barlow-condensed-800.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

@font-face {
  font-family: "Public Sans";
  font-style: normal;
  font-weight: 400 700;
  font-display: swap;
  src: url("../fonts/public-sans-variable.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

/* ---------- Tokens (DESIGN.md colors, typography, spacing) ---------- */
:root {
  --bg: #eef2f4;
  --surface: #ffffff;
  --text: #111417;
  --text-muted: #4a5560;
  --rule: #111417;
  --hairline: #c9d1d6;
  --primary: #1f3fbf;
  --on-primary: #ffffff;
  --primary-hover: #18329a;
  --info-bg: #e4e9fa;
  --warning: #8a5a00;
  --warning-bg: #fbf0d9;
  --error: #b3261e;
  --error-bg: #fbe4e2;
  --success: #1e6b3a;
  --success-bg: #e3f1e8;

  --font-cjk: "PingFang TC", "Noto Sans CJK TC", "Noto Sans TC", "Microsoft JhengHei", sans-serif;
  --font-body: "Public Sans", var(--font-cjk);
  --font-display: "Barlow Condensed", "Arial Narrow", "Roboto Condensed", var(--font-cjk);

  --space-xs: 4px;
  --space-sm: 8px;
  --space-md: 12px;
  --space-base: 16px;
  --space-lg: 24px;
  --space-xl: 32px;
  --space-2xl: 48px;

  --radius-sm: 2px;
  --radius-md: 4px;
  --target: 44px;

  /* Modern Web Guidance "dark-mode": color-scheme on :root themes the canvas, scrollbars and controls. */
  color-scheme: light dark;
  accent-color: var(--primary);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121418;
    --surface: #1c1f25;
    --text: #e8eaee;
    --text-muted: #9aa1ae;
    --rule: #e8eaee;
    --hairline: #343a44;
    --primary: #8fb0ff;
    --on-primary: #0b1433;
    --primary-hover: #b4caff;
    --info-bg: #1c1f25;
    --warning: #f0c46a;
    --warning-bg: #1c1f25;
    --error: #ff9a90;
    --error-bg: #1c1f25;
    --success: #7ed3a0;
    --success-bg: #1c1f25;
  }
}

/* ---------- Base ---------- */
*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: var(--font-body);
  font-size: 1rem;
  line-height: 1.6;
  color: var(--text);
  background: var(--bg);
  overflow-wrap: break-word;
}

h1,
h2,
h3 {
  text-wrap: balance;
}

p,
li {
  text-wrap: pretty;
}

img {
  max-inline-size: 100%;
  block-size: auto;
}

a {
  color: var(--primary);
  text-underline-offset: 0.2em;
}

a:hover {
  color: var(--primary-hover);
}

:focus-visible {
  outline: 3px solid var(--primary);
  outline-offset: 2px;
}

/* The hidden attribute wins over component display rules (the show-password button is hidden until JS runs). */
[hidden] {
  display: none !important;
}

.visually-hidden {
  position: absolute;
  inline-size: 1px;
  block-size: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

.skip-link {
  position: absolute;
  inset-inline-start: var(--space-base);
  inset-block-start: -100px;
  z-index: 10;
  display: inline-flex;
  align-items: center;
  min-block-size: var(--target);
  padding-inline: var(--space-base);
  background: var(--primary);
  color: var(--on-primary);
  font-weight: 700;
}

.skip-link:focus {
  inset-block-start: var(--space-sm);
  color: var(--on-primary);
}

.numeric {
  font-variant-numeric: tabular-nums;
}

/* ---------- Page frame: max 1180px, gutters at least 16px ---------- */
.site-header-inner,
.site-main,
.site-footer-inner {
  max-inline-size: 1180px;
  margin-inline: auto;
  padding-inline: var(--space-base);
}

.site-header {
  background: var(--surface);
  border-block-end: 4px solid var(--rule);
}

.site-header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-base);
  min-block-size: 56px;
}

.site-header-link {
  display: inline-flex;
  align-items: center;
  min-block-size: var(--target);
  font-weight: 700;
}

.site-header-nav {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  column-gap: var(--space-base);
}

.site-header-form {
  margin: 0;
}

.site-header-user {
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

/* The logout button looks like the header links next to it (it must be a POST, ADR-004). */
.site-header-button {
  display: inline-flex;
  align-items: center;
  min-block-size: var(--target);
  padding: 0;
  border: 0;
  background: none;
  color: var(--primary);
  font: inherit;
  font-weight: 700;
  text-decoration: underline;
  text-underline-offset: 0.2em;
  cursor: pointer;
}

.site-header-button:hover {
  color: var(--primary-hover);
}

.site-logo {
  display: inline-flex;
  align-items: baseline;
  gap: var(--space-xs);
  min-block-size: var(--target);
  padding-block: var(--space-xs);
  color: var(--text);
  text-decoration: none;
}

.site-logo:hover {
  color: var(--text);
}

.site-logo-mark {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 1.75rem;
  line-height: 1.2;
  letter-spacing: 0.02em;
  font-size-adjust: from-font;
}

.site-logo-text {
  font-family: var(--font-cjk);
  font-weight: 700;
  white-space: nowrap;
}

/* The logo keeps its width; the links wrap under each other on narrow phones instead. */
.site-logo {
  flex: none;
}

.site-main {
  padding-block: var(--space-base) var(--space-2xl);
}

.site-footer {
  border-block-start: 4px solid var(--rule);
  color: var(--text-muted);
}

.site-footer-inner {
  padding-block: var(--space-lg);
}

.site-footer p {
  margin: 0;
}

/* ---------- Type roles ---------- */
.page-title {
  margin: var(--space-lg) 0 var(--space-sm);
  font-family: var(--font-cjk);
  font-weight: 900;
  font-size: 1.75rem;
  line-height: 1.2;
}

.page-title-text {
  display: block;
}

.lede {
  max-inline-size: 40em;
  margin: 0 0 var(--space-base);
  color: var(--text-muted);
}

/* English brand names exactly as on the US label; uppercase only visually. */
.brand {
  display: block;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.0625rem;
  line-height: 1.2;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text);
  font-size-adjust: from-font;
}

.brand:empty {
  display: none;
}

.brand-large {
  font-size: 1.375rem;
}

a.brand {
  display: inline-flex;
  align-items: center;
  min-block-size: var(--target);
  text-decoration: none;
}

a.brand:hover {
  color: var(--primary);
  text-decoration: underline;
}

/* ---------- Breadcrumbs (Modern Web Guidance "breadcrumbs") ---------- */
.breadcrumbs ol {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0 var(--space-sm);
  margin: 0;
  padding: 0;
  list-style: none;
}

.breadcrumbs li {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
}

/* The empty alt keeps the divider out of the accessibility tree. */
.breadcrumbs li + li::before {
  content: "/" / "";
  color: var(--text-muted);
}

.breadcrumbs a {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-block-size: var(--target);
  min-inline-size: var(--target);
}

.breadcrumbs a[aria-current="page"] {
  color: var(--text);
  font-weight: 700;
  text-decoration: none;
}

/* ---------- Panels: white label on the grey ground, ruled not shadowed ---------- */
.panel {
  container: panel / inline-size;
  margin-block: var(--space-lg);
  padding: var(--space-md);
  background: var(--surface);
  border: 2px solid var(--rule);
}

@media (min-width: 768px) {
  .panel {
    padding: var(--space-base);
  }
}

.panel-title {
  margin: 0;
  padding-block-end: var(--space-sm);
  border-block-end: 6px solid var(--rule);
  font-family: var(--font-cjk);
  font-weight: 900;
  font-size: 1.25rem;
  line-height: 1.3;
}

.empty-state {
  margin: var(--space-base) 0 0;
  padding: var(--space-md) var(--space-base);
  background: var(--info-bg);
  border: 1px solid var(--hairline);
  border-radius: var(--radius-sm);
}

/* The way out of an empty list is navigation, not a word in a sentence: 44px like other links (IA §7). */
.empty-state a {
  display: inline-flex;
  align-items: center;
  min-block-size: var(--target);
  min-inline-size: var(--target);
}

.list-count {
  margin: var(--space-sm) 0 0;
  color: var(--text-muted);
  font-size: 0.875rem;
}

/* ---------- Link tiles (categories, brands, groups) ---------- */
.link-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  column-gap: var(--space-lg);
  margin: 0;
  padding: 0;
  list-style: none;
}

@container panel (inline-size > 34rem) {
  .link-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@container panel (inline-size > 54rem) {
  .link-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

.link-tile {
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-block-size: var(--target);
  block-size: 100%;
  padding: var(--space-md) var(--space-xs);
  border-block-end: 1px solid var(--hairline);
  color: var(--text);
  text-decoration: none;
}

.link-tile:hover {
  color: var(--primary);
}

.link-tile:hover .link-tile-title {
  text-decoration: underline;
}

.link-tile-title {
  font-weight: 700;
}

.link-tile-note {
  color: var(--text-muted);
  font-size: 0.875rem;
}

.two-paths {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  column-gap: var(--space-lg);
}

@media (min-width: 1024px) {
  .two-paths {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

/* ---------- Product list: one product per row, price on the right ---------- */
.product-list {
  container: products / inline-size;
  margin: var(--space-sm) 0 0;
  padding: 0;
  list-style: none;
}

/* Narrow lists (phones): the price sits under the names, still right-aligned, so long names keep the width. */
.product-row {
  position: relative;
  display: grid;
  grid-template-columns: 64px minmax(0, 1fr);
  grid-template-areas:
    "thumb text"
    "thumb price";
  align-items: center;
  gap: var(--space-xs) var(--space-base);
  padding-block: var(--space-md);
  border-block-start: 1px solid var(--rule);
}

.product-row:first-child {
  border-block-start: 0;
}

.product-row:not(:has(.product-thumb)) {
  grid-template-columns: minmax(0, 1fr);
  grid-template-areas:
    "text"
    "price";
}

@container products (inline-size > 30rem) {
  .product-row {
    grid-template-columns: 64px minmax(0, 1fr) auto;
    grid-template-areas: "thumb text price";
    column-gap: var(--space-base);
  }

  .product-row:not(:has(.product-thumb)) {
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas: "text price";
  }
}

.product-row .price {
  grid-area: price;
  flex-direction: row;
  align-items: baseline;
  justify-content: flex-end;
  gap: var(--space-sm);
}

@container products (inline-size > 30rem) {
  .product-row .price {
    flex-direction: column;
    align-items: flex-end;
    gap: 0;
  }
}

.product-thumb {
  grid-area: thumb;
  align-self: start;
  display: block;
  inline-size: 64px;
  block-size: 64px;
  object-fit: contain;
  background: #ffffff;
}

.product-row-text {
  grid-area: text;
  display: flex;
  flex-direction: column;
  min-inline-size: 0;
}

/* The name link covers the whole row, so the tap target is the row (IA §7). */
.product-row-link {
  color: var(--text);
  font-weight: 700;
  text-decoration: none;
}

.product-row-link::after {
  content: "";
  position: absolute;
  inset: 0;
}

.product-row-link:hover {
  color: var(--primary);
  text-decoration: underline;
}

.product-row-link:focus-visible {
  outline: none;
}

.product-row-link:focus-visible::after {
  outline: 3px solid var(--primary);
  outline-offset: 2px;
}

.product-row-english {
  color: var(--text-muted);
  font-size: 0.875rem;
}

.price {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  text-align: end;
  white-space: nowrap;
}

.price-now {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 1.5rem;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
  font-size-adjust: from-font;
}

.price-was {
  color: var(--text-muted);
  font-size: 0.875rem;
  font-variant-numeric: tabular-nums;
}

/* ---------- Product page ---------- */
.product {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: var(--space-lg);
  margin-block-start: var(--space-base);
}

@media (min-width: 768px) {
  .product:has(.product-media) {
    grid-template-columns: minmax(0, 5fr) minmax(0, 7fr);
    gap: var(--space-xl);
  }
}

.product-media {
  align-self: start;
  padding: var(--space-base);
  background: #ffffff;
  border: 2px solid var(--rule);
}

.product-photo {
  display: block;
  margin-inline: auto;
  object-fit: contain;
}

.product-brand {
  margin: 0;
}

.product-title {
  margin-block-start: 0;
}

.product-english {
  margin: 0 0 var(--space-base);
  color: var(--text-muted);
}

/* 代購資訊 facts panel: the signature component (DESIGN.md Components). */
.facts-panel {
  margin-block: var(--space-lg);
  padding: var(--space-sm) var(--space-base) var(--space-base);
  background: var(--surface);
  border: 2px solid var(--rule);
}

.facts-title {
  margin: 0;
  padding-block-end: var(--space-xs);
  border-block-end: 8px solid var(--rule);
  font-family: var(--font-cjk);
  font-weight: 900;
  font-size: 1.5rem;
  line-height: 1.3;
}

.facts {
  margin: 0;
}

.facts-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--space-base);
  padding-block: var(--space-sm);
  border-block-start: 1px solid var(--rule);
}

.facts-row:first-child {
  border-block-start: 0;
}

.facts-row-section {
  border-block-start-width: 4px;
}

.facts dt {
  font-family: var(--font-cjk);
  font-weight: 700;
}

.facts dd {
  margin: 0;
  text-align: end;
}

.facts-price {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 2rem;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  font-size-adjust: from-font;
}

.facts-note {
  margin: var(--space-sm) 0 0;
  color: var(--text-muted);
  font-size: 0.875rem;
}

/* Parcel trail on the product page is a promise: every station is an empty square. */
.parcel-trail-title {
  margin: 0 0 var(--space-sm);
  font-family: var(--font-cjk);
  font-weight: 700;
  font-size: 1rem;
}

.parcel-trail ol {
  margin: 0 0 0 7px;
  padding: 0;
  list-style: none;
  border-inline-start: 2px solid var(--hairline);
}

.parcel-trail li {
  position: relative;
  padding-block: var(--space-xs);
  padding-inline-start: var(--space-lg);
}

.parcel-trail li::before {
  content: "";
  position: absolute;
  inset-inline-start: -8px;
  inset-block-start: 0.75em;
  inline-size: 14px;
  block-size: 14px;
  background: var(--surface);
  border: 2px solid var(--rule);
}

/* Sanitised description HTML (paragraphs, bold, lists, tables, images, site links). */
.rich-text {
  max-inline-size: 46em;
}

.rich-text table {
  display: block;
  max-inline-size: 100%;
  overflow-x: auto;
  border-collapse: collapse;
}

.rich-text th,
.rich-text td {
  padding: var(--space-xs) var(--space-sm);
  border: 1px solid var(--hairline);
  text-align: start;
}

/* ---------- Status tag and notices (always a text label, never colour alone) ---------- */
.status-tag {
  display: inline-block;
  inline-size: fit-content;
  margin-block: var(--space-xs);
  padding: 0 var(--space-sm);
  border: 1px solid var(--warning);
  border-radius: var(--radius-sm);
  background: var(--warning-bg);
  color: var(--warning);
  font-family: var(--font-cjk);
  font-weight: 700;
  font-size: 0.875rem;
  line-height: 1.6;
}

.status-tag.status-ok {
  border-color: var(--success);
  background: var(--success-bg);
  color: var(--success);
}

.facts dd .status-tag {
  margin-inline: var(--space-sm);
}

.field select {
  inline-size: 100%;
  min-block-size: 48px;
  padding: var(--space-sm) var(--space-md);
  border: 2px solid var(--text-muted);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: max(1rem, 1em);
}

.field select:focus-visible {
  border-color: var(--primary);
}

.field select[aria-invalid="true"] {
  border-color: var(--error);
}

.field-legend {
  margin-block-end: var(--space-sm);
  font-family: var(--font-cjk);
  font-weight: 700;
}

.notice {
  margin: var(--space-md) 0 0;
  padding: var(--space-md) var(--space-base);
  border-radius: var(--radius-sm);
}

.notice strong {
  margin-inline-end: var(--space-sm);
}

.notice-warning {
  border: 1px solid var(--warning);
  background: var(--warning-bg);
  color: var(--text);
}

.notice-warning strong {
  color: var(--warning);
}

/* ---------- Search form (Modern Web Guidance "forms") ---------- */
.search-form {
  display: block;
  margin-block: var(--space-base) var(--space-lg);
  max-inline-size: 40rem;
}

.search-form label {
  display: block;
  margin-block-end: var(--space-xs);
  font-family: var(--font-cjk);
  font-weight: 700;
}

.search-form-row {
  display: flex;
  gap: var(--space-sm);
}

.search-form input {
  flex: 1 1 auto;
  min-inline-size: 0;
  min-block-size: 48px;
  padding: var(--space-sm) var(--space-md);
  border: 2px solid var(--text-muted);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: max(1rem, 1em);
}

.search-form input:focus-visible {
  border-color: var(--primary);
}

.form-hint {
  margin: var(--space-xs) 0 0;
  color: var(--text-muted);
  font-size: 0.875rem;
}

.pager {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: var(--space-base);
  margin-block-start: var(--space-base);
}

.pager [rel="next"] {
  margin-inline-start: auto;
}

/* ---------- Forms (Modern Web Guidance "forms", "autofill-sign-in-form"; DESIGN.md input) ---------- */
.auth-panel {
  max-inline-size: 32rem;
}

.form {
  margin-block-start: var(--space-base);
}

/* Groups a whole form so it can be disabled at once (sign-in while the password key is missing). */
.form-fieldset {
  margin: 0;
  padding: 0;
  border: 0;
  min-inline-size: 0;
}

.field {
  display: flex;
  flex-direction: column;
  gap: var(--space-xs);
  margin-block-end: var(--space-lg);
}

.field label {
  font-family: var(--font-cjk);
  font-weight: 700;
}

.field input {
  inline-size: 100%;
  min-block-size: 48px;
  padding: var(--space-sm) var(--space-md);
  border: 2px solid var(--text-muted);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: max(1rem, 1em);
}

.field input:focus-visible {
  border-color: var(--primary);
}

.field input[aria-invalid="true"] {
  border-color: var(--error);
}

.field .form-hint {
  margin: 0;
}

.password-row {
  display: flex;
  gap: var(--space-sm);
}

.password-row input {
  flex: 1 1 auto;
  min-inline-size: 0;
}

.password-toggle {
  flex: none;
  padding-inline: var(--space-base);
  background: var(--surface);
  cursor: pointer;
}

.field-check {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  min-block-size: var(--target);
  margin-block-end: var(--space-base);
}

.field-check input {
  flex: none;
  inline-size: 1.25rem;
  block-size: 1.25rem;
  margin: 0;
}

/* Taller label so the whole row is a 44px target (IA section 7). */
.field-check label {
  padding-block: var(--space-sm);
  cursor: pointer;
}

.choice-list {
  margin: 0 0 var(--space-base);
  padding: 0;
  border: 0;
}

.choice-list .field-check {
  margin: 0;
  padding-inline: var(--space-sm);
  border-block-end: 1px solid var(--hairline);
}

.form-submit {
  inline-size: 100%;
}

.form + .form-hint {
  margin-block-start: var(--space-md);
}

@media (min-width: 768px) {
  .form-submit {
    inline-size: auto;
  }
}

.notice-error {
  border: 1px solid var(--error);
  background: var(--error-bg);
  color: var(--text);
}

.notice-error strong {
  color: var(--error);
}

.error-summary ul {
  margin: var(--space-sm) 0 0;
  padding-inline-start: var(--space-lg);
}

.error-summary a {
  display: inline-block;
  padding-block: var(--space-xs);
  color: var(--text);
}

/* Honeypot for robots (security design 7.4): never shown, never focused. */
.hp-field {
  position: absolute;
  inset-inline-start: -10000px;
  inline-size: 1px;
  block-size: 1px;
  overflow: hidden;
}

.notice-success {
  border: 1px solid var(--success);
  background: var(--success-bg);
  color: var(--text);
}

.notice-success strong {
  color: var(--success);
}

.notice-info {
  border: 1px solid var(--hairline);
  background: var(--info-bg);
  color: var(--text);
}

.notice + .form,
.notice + .button-row {
  margin-block-start: var(--space-base);
}

/* Field error under its input (DESIGN.md input: reason and how to fix). */
.field-error {
  margin: 0;
  color: var(--error);
  font-weight: 700;
}

.field-check + .consent-links {
  margin: calc(-1 * var(--space-sm)) 0 var(--space-base);
  padding-inline-start: calc(1.25rem + var(--space-sm));
}

.consent-links a {
  display: inline-flex;
  align-items: center;
  min-block-size: var(--target);
  padding-inline: var(--space-xs);
}

.field-check + .field-error {
  margin: calc(-1 * var(--space-sm)) 0 var(--space-base);
}

.field-check input[aria-invalid="true"] {
  outline: 2px solid var(--error);
  outline-offset: 2px;
}

.button-row {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-sm);
}

/* ---------- Back-office tables (DESIGN.md: 4px rule under the header, hairlines between rows;
   Modern Web Guidance "responsive-table": scroll region, row headers, stacked when narrow) ---------- */
.table-wrapper {
  container-type: inline-size;
  overflow: auto;
  max-inline-size: 100%;
  margin-block: var(--space-base);
  background: var(--surface);
  border: 2px solid var(--rule);
}

.admin-table {
  inline-size: 100%;
  border-collapse: separate;
  border-spacing: 0;
}

.admin-table caption {
  padding: var(--space-md) var(--space-base);
  font-family: var(--font-cjk);
  font-weight: 900;
  text-align: start;
}

.admin-table th,
.admin-table td {
  padding: var(--space-sm) var(--space-base);
  border-block-end: 1px solid var(--hairline);
  text-align: start;
  vertical-align: middle;
}

.admin-table thead th {
  border-block-end: 4px solid var(--rule);
  font-family: var(--font-cjk);
  font-size: 0.875rem;
  white-space: nowrap;
}

.admin-table tbody th {
  font-weight: 700;
}

.row-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-sm);
}

.row-actions form {
  margin: 0;
}

.row-actions a {
  display: inline-flex;
  align-items: center;
  min-block-size: var(--target);
}

.row-actions .button-secondary {
  min-block-size: var(--target);
  padding-inline: var(--space-md);
  background: var(--surface);
  cursor: pointer;
}

@container (inline-size < 40rem) {
  .staff-table,
  .staff-table thead,
  .staff-table tbody,
  .staff-table tr,
  .staff-table th,
  .staff-table td {
    display: block;
  }

  .staff-table thead {
    display: none;
  }

  /* Display changes on table parts drop their table roles; the caption needs a full-width block. */
  .staff-table caption {
    display: block;
    border-block-end: 4px solid var(--rule);
  }

  .staff-table td.row-actions {
    display: flex;
  }

  .staff-table tr {
    border-block-end: 2px solid var(--rule);
  }

  .staff-table tbody th {
    border-block-end: 1px solid var(--hairline);
  }

  .staff-table td:nth-child(2)::before {
    content: "名稱：";
    font-weight: 700;
  }

  .staff-table td:nth-child(3)::before {
    content: "狀態：";
    font-weight: 700;
  }

  .staff-table td:nth-child(4)::before {
    content: "密碼最後變更：";
    font-weight: 700;
  }
}

.temporary-password {
  font-family: Consolas, "Courier New", monospace;
  font-size: 1.25rem;
  letter-spacing: 0.08em;
  user-select: all;
}

/* ---------- Back-office product pages (slice 09A-1; Modern Web Guidance "forms": single column,
   labels above controls, fieldsets with legends; "responsive-table" for the list) ---------- */
.filter-form {
  display: grid;
  gap: 0 var(--space-base);
  align-items: end;
  margin-block: var(--space-base);
}

.filter-form .field {
  margin-block-end: var(--space-base);
}

.filter-form input,
.filter-form select {
  inline-size: 100%;
}

.filter-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-base);
  margin-block-end: var(--space-base);
}

.filter-actions a {
  display: inline-flex;
  align-items: center;
  min-block-size: var(--target);
}

@media (min-width: 768px) {
  .filter-form {
    grid-template-columns: minmax(12rem, 2fr) minmax(10rem, 1fr) minmax(8rem, 1fr) auto;
  }
}

.result-count {
  margin: 0;
  color: var(--text-muted);
}

.product-table th a {
  display: inline-flex;
  align-items: center;
  min-block-size: var(--target);
  font-weight: 700;
}

.product-english {
  display: block;
  color: var(--text-muted);
  font-weight: 400;
  font-size: 0.875rem;
}

@container (inline-size < 40rem) {
  .product-table,
  .product-table thead,
  .product-table tbody,
  .product-table tr,
  .product-table th,
  .product-table td,
  .product-table caption {
    display: block;
  }

  .product-table thead {
    display: none;
  }

  .product-table caption {
    border-block-end: 4px solid var(--rule);
  }

  .product-table tr {
    border-block-end: 2px solid var(--rule);
  }

  .product-table td:nth-child(2)::before {
    content: "ID：";
    font-weight: 700;
  }

  .product-table td:nth-child(3)::before {
    content: "品牌：";
    font-weight: 700;
  }

  .product-table td:nth-child(4)::before {
    content: "狀態：";
    font-weight: 700;
  }

  .product-table td:nth-child(5)::before {
    content: "售價：";
    font-weight: 700;
  }
}

/* Slice 09A-2: page actions above the list, and the sort page (plan P10). */
.page-actions {
  margin-block: var(--space-base);
}

.page-actions .button-secondary {
  min-block-size: var(--target);
  background: var(--surface);
}

@media (min-width: 768px) {
  .order-brand-form {
    grid-template-columns: minmax(12rem, 24rem) auto;
  }
}

.order-table .row-actions {
  flex-wrap: nowrap;
}

.row-actions .button-secondary:disabled {
  border-color: var(--hairline);
  color: var(--text-muted);
  cursor: not-allowed;
}

.row-actions .button-secondary:disabled:hover {
  background: var(--surface);
  color: var(--text-muted);
}

/* The product just moved: a thick rule on the leading edge, not color alone (DESIGN.md). */
.order-table tr.is-moved > * {
  background: var(--info-bg);
}

.order-table tr.is-moved > :first-child {
  box-shadow: inset 4px 0 0 var(--primary);
}

.order-table tr.is-moved th a::after {
  content: "（剛移動）";
  font-weight: 400;
}

/* Only the row's name link (09A-4 rows also link their product count). */
.order-table tr.is-moved th .product-english a::after {
  content: none;
}

@container (inline-size < 40rem) {
  .order-table,
  .order-table thead,
  .order-table tbody,
  .order-table tr,
  .order-table th,
  .order-table td,
  .order-table caption {
    display: block;
  }

  .order-table thead {
    display: none;
  }

  .order-table caption {
    border-block-end: 4px solid var(--rule);
  }

  .order-table tr {
    border-block-end: 2px solid var(--rule);
  }

  .order-table td,
  .order-table th {
    border-block-end: 0;
  }

  .order-table td.order-position::before {
    content: "位置：";
    font-weight: 700;
  }

  .order-table td:nth-child(3)::before {
    content: "狀態：";
    font-weight: 700;
  }

  .order-table .row-actions .button-secondary {
    flex: 1;
  }
}

.product-form {
  max-inline-size: 48rem;
}

/* Slice 09A-4: tables that stack when narrow, each cell labelled by its data-label (groups, a group's products). */
.stack-table th a {
  display: inline-flex;
  align-items: center;
  min-block-size: var(--target);
  font-weight: 700;
}

@container (inline-size < 40rem) {
  .stack-table,
  .stack-table thead,
  .stack-table tbody,
  .stack-table tr,
  .stack-table th,
  .stack-table td,
  .stack-table caption {
    display: block;
  }

  .stack-table thead {
    display: none;
  }

  .stack-table caption {
    border-block-end: 4px solid var(--rule);
  }

  .stack-table tr {
    border-block-end: 2px solid var(--rule);
  }

  .stack-table td {
    border-block-end: 0;
  }

  .stack-table td[data-label]::before {
    content: attr(data-label) "：";
    font-weight: 700;
  }
}

/* A category's brands, a group's products to add: checkbox lists in columns on wide screens. */
@media (min-width: 768px) {
  .link-choices {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(16rem, 1fr));
    column-gap: var(--space-base);
  }
}

/* A section ruled by its heading instead of boxed (DESIGN.md: no card in a card). */
.ruled-section {
  margin-block: var(--space-lg);
}

.field-check.is-checkbox-cell {
  margin: 0;
}

/* A group of fields with a visible legend (no styling-only fieldsets). */
.form-group {
  margin: 0 0 var(--space-lg);
  padding: var(--space-md) var(--space-md) 0;
  border: 2px solid var(--rule);
  background: var(--surface);
  min-inline-size: 0;
}

.form-group > legend {
  padding-inline: var(--space-sm);
  font-family: var(--font-cjk);
  font-weight: 900;
  font-size: 1.125rem;
}

.field-row {
  display: grid;
  gap: 0 var(--space-base);
}

@media (min-width: 768px) {
  .form-group {
    padding: var(--space-base) var(--space-base) 0;
  }

  .field-row {
    grid-template-columns: repeat(auto-fit, minmax(11rem, 1fr));
  }
}

.field textarea {
  inline-size: 100%;
  padding: var(--space-sm) var(--space-md);
  border: 2px solid var(--text-muted);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: max(1rem, 1em);
  line-height: 1.5;
  resize: vertical;
}

.field textarea:focus-visible {
  border-color: var(--primary);
}

.field textarea[aria-invalid="true"] {
  border-color: var(--error);
}

.description-preview {
  margin-block-end: var(--space-lg);
  padding: var(--space-md);
  border: 2px dashed var(--rule);
}

.description-preview .panel-title {
  margin-block-end: var(--space-md);
  font-size: 1rem;
}

.form-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-base);
}

.form-actions a {
  display: inline-flex;
  align-items: center;
  min-block-size: var(--target);
}

.form-actions .button-secondary {
  min-block-size: var(--target);
  padding-inline: var(--space-base);
  background: var(--surface);
  cursor: pointer;
}

.conflict .table-wrapper {
  margin-block-end: 0;
}

.conflict-table td {
  overflow-wrap: anywhere;
}

.history-list {
  margin: var(--space-md) 0 0;
  padding: 0;
  list-style: none;
}

.history-list > li {
  padding-block: var(--space-sm);
  border-block-end: 1px solid var(--hairline);
}

.history-list p {
  margin: 0;
}

.history-list ul {
  margin: var(--space-xs) 0 0;
  padding-inline-start: var(--space-lg);
}

/* Product and brand picture (slice 09A-3): the current picture at a modest size, then its own upload form. */
.picture-current {
  margin-block: var(--space-md);
}

.picture-current img {
  display: block;
  inline-size: auto;
  max-inline-size: min(100%, 15rem);
  block-size: auto;
  border: 1px solid var(--hairline);
  background: var(--surface);
}

.picture-current p {
  margin: var(--space-xs) 0 0;
  overflow-wrap: anywhere;
}

/* The native file button styled like a secondary button (DESIGN.md: 2px black border, 4px radius). */
.field input[type="file"] {
  padding-block: var(--space-xs);
  cursor: pointer;
}

.field input[type="file"]::file-selector-button {
  min-block-size: 36px;
  margin-inline-end: var(--space-md);
  padding-inline: var(--space-md);
  border: 2px solid var(--rule);
  border-radius: var(--radius-md);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}

/* ---------- Buttons ---------- */
.button-primary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-block-size: 48px;
  min-inline-size: var(--target);
  padding-inline: var(--space-lg);
  border: 0;
  border-radius: var(--radius-md);
  background: var(--primary);
  color: var(--on-primary);
  font-family: var(--font-cjk);
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
}

.button-primary:hover {
  background: var(--primary-hover);
}

/* Link-styled primary buttons keep the button colours (a:hover would turn the text blue on blue). */
a.button-primary,
a.button-primary:hover {
  color: var(--on-primary);
  text-decoration: none;
}

.button-primary:disabled {
  background: var(--hairline);
  color: var(--text-muted);
  cursor: progress;
}

.button-primary:active {
  transform: translateY(1px);
}

.button-secondary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-block-size: 48px;
  padding-inline: var(--space-lg);
  border: 2px solid var(--text);
  border-radius: var(--radius-md);
  color: var(--text);
  font-family: var(--font-cjk);
  font-weight: 700;
  text-decoration: none;
}

.button-secondary:hover {
  background: var(--text);
  color: var(--surface);
}

.button-secondary:active {
  transform: translateY(1px);
}

.error-code {
  font-family: Consolas, monospace;
  letter-spacing: 0.05em;
}

@media (forced-colors: active) {
  .breadcrumbs a[aria-current="page"] {
    text-decoration: underline;
  }
}
