:root {
  --bg: #fbf6ec;
  --surface: #fffaf1;
  --surface-strong: #fff3df;
  --text: #33251d;
  --muted: #7f6b5b;
  --primary: #a7663f;
  --primary-dark: #7c492d;
  --accent: #d9a46b;
  --border: #eadcc8;
  --danger: #b84b4b;
  --success: #3d8060;
  --radius: 18px;
  --shadow: 0 18px 48px rgba(109, 75, 45, .12);
  --font: "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", system-ui, sans-serif;
  --h1: 30px;
  --h2: 22px;
}

body.theme-dashboard,
.theme-dashboard {
  --bg: #f6f7f6;
  --surface: #ffffff;
  --surface-strong: #eef1f2;
  --text: #1e272b;
  --muted: #5f6b70;
  --primary: #2f4c5a;
  --primary-dark: #1d333d;
  --accent: #7b6755;
  --border: #dfe4e4;
  --radius: 8px;
  --shadow: 0 8px 24px rgba(24, 39, 45, .08);
  --h1: 28px;
  --h2: 20px;
}

body.theme-brand,
.theme-brand {
  --bg: #f9f4ea;
  --surface: #fffbf2;
  --surface-strong: #eef1e4;
  --text: #213629;
  --muted: #66745e;
  --primary: #31543e;
  --primary-dark: #1f3929;
  --accent: #bd7a43;
  --border: #dbe2ce;
  --radius: 14px;
  --shadow: 0 16px 38px rgba(33, 54, 41, .12);
  --h1: 34px;
  --h2: 24px;
}

* { box-sizing: border-box; }
html { font-size: 16px; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  line-height: 1.6;
  letter-spacing: 0;
}
a { color: inherit; }
img { max-width: 100%; display: block; }
h1, h2, h3, p { margin-top: 0; }
h1 { font-size: var(--h1); line-height: 1.2; margin-bottom: 8px; }
h2 { font-size: var(--h2); line-height: 1.3; margin-bottom: 10px; }
h3 { font-size: 18px; margin-bottom: 8px; }

.site-header {
  position: sticky;
  top: 0;
  z-index: 10;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 14px;
  align-items: center;
  padding: 18px clamp(16px, 4vw, 42px);
  background: color-mix(in srgb, var(--surface) 90%, transparent);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(14px);
}
.site-header.storefront {
  background: linear-gradient(135deg, var(--surface), var(--surface-strong));
}
.customer-header {
  padding: 24px clamp(16px, 5vw, 48px);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.site-nav {
  grid-column: 1 / -1;
  display: none;
  gap: 8px;
  flex-wrap: wrap;
}
.site-nav.open { display: flex; }
.header-actions {
  grid-column: 1 / -1;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}
.site-nav a {
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: calc(var(--radius) - 4px);
  background: var(--surface);
  text-decoration: none;
  font-weight: 700;
  font-size: 15px;
}
.site-nav a[aria-current="page"] {
  color: #fff;
  border-color: var(--primary);
  background: var(--primary);
}
.nav-toggle {
  min-height: 42px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text);
  font-weight: 700;
  padding: 0 16px;
}
.page-shell {
  width: min(1160px, 100%);
  margin: 0 auto;
  padding: 18px 16px 48px;
}
.product-admin-shell {
  width: min(1180px, 100%);
}
.settings-shell {
  width: min(1180px, 100%);
}
.settings-layout {
  display: grid;
  gap: 18px;
}
.customer-shell {
  width: min(1040px, 100%);
  margin: 0 auto;
  padding: 16px 14px 36px;
}
.panel,
.hero-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: clamp(18px, 4vw, 30px);
  margin-bottom: 18px;
}
.hero-panel {
  display: grid;
  gap: 18px;
  background:
    linear-gradient(135deg, color-mix(in srgb, var(--surface-strong) 68%, transparent), var(--surface)),
    var(--surface);
}
.theme-brand .hero-panel {
  min-height: 240px;
  align-items: end;
  background:
    linear-gradient(110deg, rgba(33,54,41,.82), rgba(189,122,67,.55)),
    url("https://images.unsplash.com/photo-1509440159596-0249088772ff?auto=format&fit=crop&w=1400&q=80") center/cover;
  color: #fff;
}
.theme-dashboard .hero-panel,
.theme-dashboard .panel { box-shadow: none; }
.eyebrow {
  color: var(--accent);
  font-size: 13px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0;
  margin-bottom: 6px;
}
.lead, .muted { color: var(--muted); }
.section-title {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  align-items: start;
  margin-bottom: 16px;
}
.hero-actions,
.segmented,
.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}
.button,
.segmented button,
button,
input,
select,
textarea {
  font: inherit;
}
.button,
.segmented button,
button {
  min-height: 44px;
  border: 0;
  border-radius: calc(var(--radius) - 4px);
  padding: 10px 16px;
  cursor: pointer;
  font-weight: 800;
}
.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
}
.primary,
.segmented button.active {
  color: #fff;
  background: var(--primary);
}
.secondary,
.segmented button {
  color: var(--primary-dark);
  background: var(--surface-strong);
  border: 1px solid var(--border);
}
.danger { color: #fff; background: var(--danger); }
.text-link {
  color: var(--primary);
  font-weight: 800;
  text-decoration: none;
}
.metric-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}
.metric-card {
  min-height: 108px;
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}
.theme-dashboard .metric-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}
.theme-dashboard .metric-card {
  border-left: 5px solid var(--primary);
}
.metric-card strong {
  display: block;
  font-size: 28px;
  line-height: 1.2;
}
.dashboard-layout,
.order-layout {
  display: grid;
  gap: 18px;
}
.form-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 14px;
}
.product-editor-panel .form-grid {
  max-width: 980px;
  margin: 0 auto;
}
label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-weight: 700;
}
input,
select,
textarea {
  width: 100%;
  min-height: 46px;
  border: 1px solid var(--border);
  border-radius: calc(var(--radius) - 6px);
  background: #fff;
  color: var(--text);
  padding: 10px 12px;
  font-size: 16px;
}
textarea { min-height: 92px; resize: vertical; }
.checkbox {
  display: flex;
  align-items: center;
  gap: 10px;
}
.checkbox input { width: 18px; min-height: 18px; }
.full { grid-column: 1 / -1; }
.hidden { display: none !important; }
.product-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(245px, 1fr));
  gap: 14px;
}
.image-upload-field {
  display: grid;
  gap: 10px;
}
.field-label {
  color: var(--muted);
  font-weight: 700;
}
.image-preview-wrap {
  display: grid;
  place-items: center;
  min-height: 220px;
  overflow: hidden;
  border: 1px dashed var(--border);
  border-radius: 8px;
  background: #fff;
}
.image-preview-wrap img {
  width: 100%;
  max-height: 320px;
  object-fit: contain;
}
.logo-preview-wrap,
.cover-preview-wrap {
  display: grid;
  place-items: center;
  overflow: hidden;
  border: 1px dashed var(--border);
  border-radius: 8px;
  background: #fff;
}
.logo-preview-wrap {
  width: 128px;
  height: 128px;
}
.logo-preview-wrap img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}
.cover-preview-wrap {
  min-height: 220px;
}
.cover-preview-wrap img {
  width: 100%;
  max-height: 360px;
  object-fit: cover;
}
.upload-button {
  position: relative;
  overflow: hidden;
}
.upload-button input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}
.empty-state {
  padding: 26px;
  border: 1px dashed var(--border);
  border-radius: 8px;
  background: var(--surface-strong);
  text-align: center;
}
.product-card,
.order-card,
.preview-card {
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}
.product-card img {
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  background: var(--surface-strong);
}
.theme-dashboard .product-card {
  display: grid;
  grid-template-columns: 96px 1fr;
}
.theme-dashboard .product-card img {
  height: 100%;
  aspect-ratio: auto;
}
.product-body,
.order-card,
.preview-card { padding: 14px; }
.tag {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--surface-strong);
  color: var(--primary-dark);
  font-weight: 800;
  font-size: 13px;
}
.tag.danger { color: #fff; background: var(--danger); }
.tag.success { color: #fff; background: var(--success); }
.card-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}
.order-list,
.product-strip,
.stats-list {
  display: grid;
  gap: 10px;
}
.order-row {
  display: grid;
  gap: 6px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: calc(var(--radius) - 6px);
  background: color-mix(in srgb, var(--surface-strong) 42%, #fff);
}
.order-table {
  display: grid;
  gap: 12px;
}
.order-card-grid {
  display: grid;
  gap: 8px;
}
.inline-controls {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
}
.summary-line,
.stat-line {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}
.shipping-fields {
  padding: 14px;
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  background: var(--surface-strong);
}
.sticky-summary { align-self: start; }
.customer-page {
  background: #f6f7f6;
}
.customer-page .customer-header {
  min-height: 320px;
  display: grid;
  align-items: end;
  background:
    linear-gradient(110deg, rgba(33,54,41,.76), rgba(49,84,62,.48)),
    url("https://images.unsplash.com/photo-1509440159596-0249088772ff?auto=format&fit=crop&w=1400&q=80") center/cover;
  color: #fff;
}
.customer-page .customer-header .lead {
  color: rgba(255,255,255,.9);
}
.brand-logo {
  width: 88px;
  height: 88px;
  margin-bottom: 16px;
  border-radius: 18px;
  object-fit: cover;
  background: rgba(255,255,255,.9);
}
.customer-page .customer-header,
.customer-page .customer-section,
.customer-page .customer-intro,
.customer-page .date-strip article {
  border-radius: 8px;
  box-shadow: none;
}
.customer-intro,
.customer-section {
  padding: clamp(18px, 4vw, 28px);
  margin-bottom: 14px;
  background: var(--surface);
  border: 1px solid var(--border);
}
.customer-intro {
  display: grid;
  gap: 10px;
}
.date-strip {
  display: grid;
  gap: 10px;
  margin-bottom: 14px;
}
.date-strip article {
  padding: 16px;
  background: var(--surface-strong);
  border: 1px solid var(--border);
}
.date-strip span,
.product-meta span {
  display: block;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}
.date-strip strong {
  display: block;
  font-size: 20px;
}
.customer-product-grid {
  display: grid;
  gap: 14px;
}
.customer-product-card {
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
}
.customer-product-card img {
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  background: var(--surface-strong);
}
.product-card-heading {
  display: grid;
  gap: 8px;
}
.product-card-heading strong {
  color: var(--primary-dark);
  font-size: 20px;
}
.product-meta {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 4px 10px;
  margin: 12px 0;
}
.product-controls,
.delivery-options {
  display: grid;
  gap: 10px;
}
.product-controls {
  grid-template-columns: minmax(0, 1fr) 112px;
  align-items: end;
}
.choice-card {
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: center;
  min-height: 68px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
}
.choice-card input {
  width: 20px;
  min-height: 20px;
}
.choice-card small {
  display: block;
  color: var(--muted);
}
.customer-order-layout {
  display: grid;
  gap: 14px;
}
.total-line {
  font-size: 18px;
}
.checkout-button {
  width: 100%;
  min-height: 54px;
  margin-top: 12px;
  font-size: 18px;
}
.consent-line {
  margin-top: 16px;
}
.form-subsection {
  padding-top: 12px;
  border-top: 1px solid var(--border);
}
.settings-form {
  align-self: start;
}
.form-footer {
  display: flex;
  flex-wrap: wrap;
  justify-content: end;
  gap: 10px;
}
.save-status {
  width: 100%;
  margin: 0;
  text-align: right;
}
.store-mode-box {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-strong);
}
.color-preset-group {
  display: grid;
  gap: 8px;
}
.color-presets {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.color-swatch {
  width: 34px;
  height: 34px;
  min-height: 34px;
  border: 2px solid #fff;
  border-radius: 999px;
  background: var(--swatch);
  box-shadow: 0 0 0 1px var(--border);
}
.store-preview-panel {
  align-self: start;
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-strong);
}
.segmented.compact button {
  min-height: 36px;
  padding: 8px 12px;
}
.store-preview-frame {
  display: grid;
  justify-items: center;
  overflow: auto;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
}
.store-preview-frame.mobile-preview .preview-store {
  width: min(320px, 100%);
}
.preview-store {
  width: 100%;
  min-height: 540px;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: var(--preview-radius, 14px);
  background-color: var(--preview-bg, #f9f4ea);
  background-size: cover;
  background-position: center;
  color: #213629;
  font-family: var(--preview-font, var(--font));
}
.preview-hero {
  min-height: 220px;
  display: grid;
  align-content: end;
  padding: 22px;
  color: #fff;
  background: linear-gradient(110deg, rgba(33,54,41,.82), rgba(49,84,62,.58));
  background-size: cover;
  background-position: center;
}
.preview-logo {
  width: 64px;
  height: 64px;
  margin-bottom: 12px;
  border-radius: 16px;
  object-fit: cover;
  background: rgba(255,255,255,.9);
}
.preview-content {
  display: grid;
  gap: 12px;
  padding: 16px;
}
.preview-dates {
  margin-bottom: 0;
}
.preview-product-card {
  display: grid;
  gap: 12px;
  overflow: hidden;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: var(--preview-radius, 14px);
  background: #fff;
}
.preview-product-card img {
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  border-radius: calc(var(--preview-radius, 14px) - 4px);
}
.preview-store .primary {
  background: var(--preview-button, #31543e);
}
dialog {
  width: min(680px, calc(100% - 28px));
  border: 0;
  border-radius: var(--radius);
  padding: 0;
  background: var(--surface);
  color: var(--text);
}
dialog::backdrop { background: rgba(0,0,0,.35); }
.dialog-content { padding: 18px; }
.info-grid,
.theme-preview-grid {
  display: grid;
  gap: 14px;
}
.preview-shot {
  display: grid;
  gap: 8px;
  min-height: 160px;
  padding: 12px;
  border-radius: var(--radius);
  background: var(--surface-strong);
}
.mini-phone {
  width: 112px;
  min-height: 190px;
  border: 7px solid var(--text);
  border-radius: 24px;
  padding: 10px;
  background: var(--surface);
}
.danger-zone { border-color: color-mix(in srgb, var(--danger) 35%, var(--border)); }

@media (min-width: 760px) {
  .site-header { grid-template-columns: auto 1fr auto; }
  .nav-toggle { display: none; }
  .site-nav {
    grid-column: auto;
    display: flex;
    justify-content: center;
  }
  .header-actions {
    grid-column: auto;
    justify-content: end;
  }
  .page-shell { padding: 28px 24px 64px; }
  .customer-shell { padding: 24px 24px 56px; }
  .hero-panel {
    grid-template-columns: 1.4fr auto;
    align-items: center;
  }
  .metric-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .dashboard-layout,
  .order-layout { grid-template-columns: minmax(0, 1.45fr) minmax(300px, .75fr); }
  .form-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .product-editor-panel .form-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .inline-controls { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .theme-preview-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .date-strip { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .customer-product-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .customer-order-layout { grid-template-columns: minmax(0, 1fr) 360px; }
  .product-card-heading { grid-template-columns: 1fr auto; align-items: start; }
  .delivery-options { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .sticky-summary {
    position: sticky;
    top: 116px;
  }
  .theme-dashboard .order-card-grid {
    grid-template-columns: 1.1fr .8fr .8fr .9fr .9fr;
    align-items: center;
  }
}

@media (min-width: 980px) {
  .settings-layout {
    grid-template-columns: minmax(0, 1.05fr) minmax(360px, .95fr);
    align-items: start;
  }
  .store-preview-panel {
    position: sticky;
    top: 116px;
  }
  .preview-product-card {
    grid-template-columns: 140px 1fr;
  }
  .preview-product-card img {
    height: 100%;
    aspect-ratio: auto;
  }
}

@media (max-width: 430px) {
  .metric-grid { grid-template-columns: 1fr; }
  .section-title { display: grid; }
  .button, .segmented button { width: 100%; }
  .site-header { position: static; }
  .customer-header { border-radius: 0; }
  .customer-shell { padding-inline: 10px; }
  .product-controls { grid-template-columns: 1fr 92px; }
  .customer-section,
  .customer-intro { padding: 16px 12px; }
}

@media (max-width: 767px) {
  .product-editor-panel .form-grid { grid-template-columns: 1fr; }
}
