:root {
  color-scheme: light;
  --bg: #f5f7fb;
  --panel: #ffffff;
  --text: #172033;
  --muted: #667085;
  --line: #d9e0ea;
  --brand: #dc2626;
  --brand-dark: #b91c1c;
  --gold: #f59e0b;
  --ok: #067647;
  --warn: #b54708;
  --danger: #b42318;
  --shadow: 0 14px 36px rgba(15, 23, 42, .08);
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  background: radial-gradient(circle at top left, #fff1f2 0, transparent 260px), var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", sans-serif;
  line-height: 1.6;
}
a { color: inherit; text-decoration: none; }
img { max-width: 100%; display: block; }
.container { width: min(1160px, calc(100% - 32px)); margin: 0 auto; }
.page-shell { padding: 28px 0 52px; }
.mono { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; }
.muted { color: var(--muted); }
.center { text-align: center; }
.narrow, .narrow-page { max-width: 760px; margin-left: auto; margin-right: auto; }

.site-header {
  position: sticky;
  top: 0;
  z-index: 50;
  background: rgba(255,255,255,.92);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid rgba(217,224,234,.8);
}
.header-inner { min-height: 64px; display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.brand { font-weight: 900; font-size: 21px; color: var(--brand); letter-spacing: .02em; }
.site-nav { display: flex; gap: 18px; color: #344054; font-size: 14px; flex-wrap: wrap; justify-content: flex-end; }
.site-nav a:hover { color: var(--brand); }

.hero {
  display: grid;
  grid-template-columns: minmax(0, 1.5fr) 360px;
  gap: 22px;
  align-items: stretch;
  padding: 34px;
  border-radius: 18px;
  background: linear-gradient(135deg, #7f1d1d 0%, #991b1b 45%, #111827 100%);
  color: #fff;
  box-shadow: var(--shadow);
}
.eyebrow {
  display: inline-flex;
  align-items: center;
  color: #fef3c7;
  font-size: 13px;
  font-weight: 800;
  letter-spacing: .04em;
  margin-bottom: 8px;
}
.hero h1 { margin: 0 0 12px; font-size: clamp(32px, 6vw, 56px); line-height: 1.05; }
.hero p { margin: 0; max-width: 720px; color: #fee2e2; font-size: 17px; }
.hero-actions { display: flex; gap: 12px; flex-wrap: wrap; margin-top: 22px; }
.hero-panel {
  display: grid;
  gap: 12px;
  align-content: center;
  padding: 18px;
  border-radius: 14px;
  background: rgba(255,255,255,.1);
  border: 1px solid rgba(255,255,255,.2);
}
.flow-step { display: flex; align-items: center; gap: 12px; padding: 12px; border-radius: 10px; background: rgba(255,255,255,.12); }
.flow-step b { width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; background: #fff; color: var(--brand); }

.notice-bar, .panel, .product-card, .order-card, .help-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: 0 2px 8px rgba(15,23,42,.04);
}
.notice-bar { display: flex; gap: 14px; align-items: center; margin: 18px 0 28px; padding: 14px 16px; }
.notice-bar strong { color: var(--brand); white-space: nowrap; }
.section-head, .admin-head, .order-title {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 18px;
}
.section-head h2, .admin-head h1 { margin: 0; }
.section-head p { margin: 4px 0 0; color: var(--muted); }
.category-tabs, .admin-actions, .order-actions { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.category-tabs button, .link-button {
  border: 1px solid var(--line);
  background: #fff;
  color: #344054;
  border-radius: 999px;
  padding: 8px 12px;
  cursor: pointer;
}
.category-tabs button.active { background: var(--brand); color: #fff; border-color: var(--brand); }

.products-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 18px; }
.product-card { overflow: hidden; cursor: pointer; transition: transform .18s, box-shadow .18s; }
.product-card:hover { transform: translateY(-3px); box-shadow: var(--shadow); }
.product-media {
  position: relative;
  min-height: 260px;
  aspect-ratio: 4 / 3;
  padding: 18px;
  background: linear-gradient(180deg, #ffffff 0%, #f8fafc 100%);
  display: grid;
  place-items: center;
  overflow: hidden;
}
.product-media img {
  position: absolute;
  inset: 18px;
  width: calc(100% - 36px);
  height: calc(100% - 36px);
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}
.product-placeholder, .detail-placeholder {
  width: 82px;
  height: 82px;
  border-radius: 18px;
  display: grid;
  place-items: center;
  background: #fee2e2;
  color: var(--brand);
  font-size: 42px;
  font-weight: 900;
}
.badge { display: inline-flex; border-radius: 999px; background: #fff7ed; color: #9a3412; padding: 4px 9px; font-size: 12px; font-weight: 700; }
.product-media .badge { position: absolute; z-index: 1; top: 10px; left: 10px; background: rgba(255,255,255,.92); }
.product-body { padding: 16px; }
.product-body h3 { margin: 0 0 7px; font-size: 18px; }
.product-body p { min-height: 46px; margin: 0 0 14px; color: var(--muted); font-size: 14px; }
.product-meta { display: flex; align-items: end; justify-content: space-between; gap: 10px; }
.price { color: var(--brand); font-size: 24px; font-weight: 900; }
.old-price { color: #98a2b3; text-decoration: line-through; margin-left: 6px; font-size: 13px; }
.rebate-tag {
  display: inline-flex;
  margin-top: 6px;
  border-radius: 999px;
  background: #ecfdf3;
  color: #067647;
  padding: 3px 8px;
  font-size: 12px;
  font-weight: 800;
}
.stock { color: var(--muted); font-size: 13px; white-space: nowrap; }
.empty-state { grid-column: 1 / -1; text-align: center; padding: 46px 18px; background: #fff; border: 1px dashed #cbd5e1; border-radius: 12px; }

.modal[hidden] { display: none; }
.modal { position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; padding: 18px; }
.modal-mask { position: absolute; inset: 0; background: rgba(15,23,42,.54); }
.modal-card { position: relative; z-index: 1; width: min(900px, 100%); max-height: 90vh; overflow: auto; background: #fff; border-radius: 16px; box-shadow: 0 24px 60px rgba(15,23,42,.24); }
.modal-close { position: absolute; top: 12px; right: 16px; border: 0; background: transparent; font-size: 28px; cursor: pointer; color: #667085; }
.modal-body { padding: 26px; }
.product-detail { display: grid; grid-template-columns: 330px minmax(0, 1fr); gap: 24px; }
.detail-media {
  position: relative;
  min-height: 280px;
  aspect-ratio: 1 / 1;
  padding: 18px;
  border-radius: 12px;
  background: linear-gradient(180deg, #ffffff 0%, #f8fafc 100%);
  display: grid;
  place-items: center;
  overflow: hidden;
}
.detail-media img {
  position: absolute;
  inset: 18px;
  width: calc(100% - 36px);
  height: calc(100% - 36px);
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}
.detail-copy h2 { margin: 8px 0 8px; font-size: 28px; line-height: 1.2; }
.detail-price strong { color: var(--brand); font-size: 34px; margin-right: 10px; }
.detail-price span { color: #98a2b3; text-decoration: line-through; }
.detail-stats { display: flex; gap: 12px; flex-wrap: wrap; margin: 14px 0; color: var(--muted); }
.pay-note { padding: 12px; border-radius: 8px; background: #fffbeb; color: #92400e; font-size: 14px; }
.wallet-use {
  padding: 12px;
  border: 1px solid #bbf7d0;
  border-radius: 10px;
  background: #f0fdf4;
}
.check-row {
  display: flex;
  grid-template-columns: none;
  align-items: center;
  gap: 10px;
  margin: 0;
}
.check-row input { width: auto; }
.check-row em { color: var(--ok); font-style: normal; font-weight: 900; }
.mini-note { color: var(--muted); font-size: 13px; margin: 0; }

.btn {
  border: 1px solid var(--line);
  border-radius: 8px;
  min-height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 9px 14px;
  background: #fff;
  color: var(--text);
  font-weight: 800;
  cursor: pointer;
  text-decoration: none;
}
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-dark); }
.btn.ghost { background: #fff7ed; border-color: #fed7aa; color: #9a3412; }
.btn.danger, .btn.small.danger { background: #fff1f2; color: var(--danger); border-color: #fecdd3; }
.btn.small { min-height: 32px; padding: 6px 10px; font-size: 13px; }
.btn.full { width: 100%; }

.stack-form { display: grid; gap: 14px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
label { display: grid; gap: 7px; font-weight: 800; color: #344054; }
input, textarea, select {
  width: 100%;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  padding: 10px 12px;
  font: inherit;
  background: #fff;
}
textarea { resize: vertical; }
input:focus, textarea:focus, select:focus { outline: 3px solid rgba(220,38,38,.14); border-color: var(--brand); }

.recent-orders { margin: 24px 0; }
.order-list { display: grid; gap: 10px; }
.recent-order-card { display: grid; gap: 3px; padding: 12px; border: 1px solid var(--line); border-radius: 10px; background: #fff; }
.recent-order-card span { color: var(--muted); font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 13px; }
.recent-order-card em { color: var(--brand); font-style: normal; font-size: 13px; font-weight: 800; }

.order-page, .query-layout, .admin-grid.two { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 18px; align-items: start; }
.order-card, .help-card, .panel { padding: 22px; }
.order-title h1 { margin: 0 0 4px; }
.status-pill { display: inline-flex; border-radius: 999px; padding: 7px 12px; font-weight: 900; font-size: 13px; }
.status-pill.pending { background: #fef3c7; color: #92400e; }
.status-pill.paid { background: #d1fae5; color: #065f46; }
.status-pill.error, .status-pill.payment_error { background: #fee2e2; color: #991b1b; }
.order-summary { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin: 18px 0; }
.order-summary div { padding: 12px; border-radius: 10px; background: #f8fafc; }
.order-summary span { display: block; color: var(--muted); font-size: 13px; }
.payment-box, .delivery-box { border-top: 1px solid var(--line); padding-top: 18px; }
.qr-wrap { display: inline-grid; gap: 8px; justify-items: center; padding: 14px; border: 1px solid var(--line); border-radius: 12px; background: #fff; }
.qr-wrap img { width: 220px; height: 220px; object-fit: contain; }
.delivery-download {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin: 14px 0;
  padding: 16px;
  border: 1px solid #bbf7d0;
  border-radius: 10px;
  background: #f0fdf4;
}
.delivery-download strong { display: block; color: #166534; font-size: 18px; }
.delivery-download span { display: block; color: var(--muted); font-size: 13px; }
.delivery-plain {
  margin-top: 12px;
  padding: 12px;
  border: 1px dashed var(--line);
  border-radius: 10px;
  background: #f8fafc;
}
.delivery-plain summary { cursor: pointer; font-weight: 900; color: #344054; }
.delivered-list { display: grid; gap: 12px; margin: 14px 0; }
.delivered-list.compact { margin: 8px 0; }
.delivered-item { padding: 12px; border: 1px solid #bbf7d0; border-radius: 10px; background: #f0fdf4; }
.delivered-item label { color: #166534; font-size: 13px; }
pre { white-space: pre-wrap; word-break: break-word; margin: 6px 0 0; font-family: ui-monospace, SFMono-Regular, Consolas, monospace; }

.alert { padding: 12px 14px; border-radius: 10px; margin: 14px 0; }
.alert.error { background: #fef2f2; border: 1px solid #fecaca; color: var(--danger); }
.alert.warn { background: #fffbeb; border: 1px solid #fde68a; color: var(--warn); }
.alert.success { background: #f0fdf4; border: 1px solid #bbf7d0; color: var(--ok); }
.loading { padding: 32px; text-align: center; color: var(--muted); }

.admin-page { display: grid; gap: 18px; }
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 12px; }
.stat-card { padding: 16px; border-radius: 12px; background: #fff; border: 1px solid var(--line); }
.stat-card b { display: block; font-size: 28px; color: var(--brand); }
.stat-card span { color: var(--muted); font-size: 13px; }
.admin-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.admin-table th, .admin-table td { border-bottom: 1px solid var(--line); padding: 10px 8px; text-align: left; vertical-align: top; }
.admin-table th { background: #f8fafc; color: #344054; }
.table-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.table-actions form { display: inline; }
.login-card { width: min(420px, calc(100% - 32px)); margin: 9vh auto; padding: 28px; border: 1px solid var(--line); border-radius: 16px; background: #fff; box-shadow: var(--shadow); }
.login-card h1 { margin: 0 0 6px; }
.invite-page { display: grid; gap: 18px; }
.invite-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; align-items: start; }
.wallet-card {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  align-items: center;
}
.wallet-card .copy-row { grid-column: 1 / -1; }
.invite-code, .wallet-balance {
  display: block;
  color: var(--brand);
  font-size: 26px;
  line-height: 1.2;
  word-break: break-all;
}
.copy-row { display: grid; grid-template-columns: minmax(0, 1fr) auto auto; gap: 10px; align-items: center; }
.ledger-list { display: grid; gap: 10px; }
.ledger-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(180px, .7fr);
  gap: 12px;
  align-items: center;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
}
.ledger-item span { display: block; color: var(--muted); font-size: 13px; }
.ledger-item .earn { color: var(--ok); font-weight: 900; }
.ledger-item .spend { color: var(--danger); font-weight: 900; }
.site-footer { background: #111827; color: #d1d5db; padding: 26px 0; }
.footer-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.footer-grid p { margin: 5px 0 0; color: #9ca3af; }

@media (max-width: 820px) {
  .site-nav { gap: 10px; font-size: 13px; }
  .hero, .product-detail, .order-page, .query-layout, .admin-grid.two, .footer-grid, .invite-grid, .wallet-card, .copy-row, .ledger-item { grid-template-columns: 1fr; }
  .hero { padding: 24px; }
  .section-head, .admin-head, .order-title { display: grid; }
  .order-summary, .form-grid { grid-template-columns: 1fr; }
  .delivery-download { display: grid; }
  .modal-body { padding: 18px; }
  .product-media { min-height: 240px; }
  .detail-media { min-height: 260px; }
  .admin-table { display: block; overflow-x: auto; white-space: nowrap; }
}
