/* ---------- Tokens ---------- */
:root {
  --bg: #f5f6f3;
  --surface: #ffffff;
  --surface-2: #f9faf8;
  --surface-3: #f1f3ef;
  --border: #e3e7e1;
  --border-strong: #cdd5cc;
  --text: #1d2521;
  --text-2: #4a5650;
  --text-3: #7b867f;
  --accent: #235b49;
  --accent-hover: #1b4a3b;
  --accent-soft: #e7f0eb;
  --accent-text: #1d4d3e;
  --warn: #8a5a00;
  --warn-soft: #fdf4de;
  --warn-line: #f0dca9;
  --danger: #b0372b;
  --danger-hover: #952d23;
  --danger-soft: #fdecea;
  --danger-line: #f3c4be;
  --info: #2c5b86;
  --info-soft: #e9f1f9;
  --success: #1f6b4b;
  --success-soft: #e3f2ea;
  /* Chart series (js/charts.js reads these; the fallbacks there are the same values). */
  --chart-1: #235b49;
  --chart-2: #5f9e86;
  --chart-3: #c48a2c;
  --chart-4: #7a6fbf;
  --chart-5: #b9c6bd;
  /* 数据's sources (spec 2026-10-20-analytics-origins §9): one hue a button, in the buttons' order (validated as adjacent pairs), and
     one colour each for new and old buyers on every card, and the grey of a row the pick leaves out. */
  --origin-xhs: #e34948;
  --origin-douyin: #1baf7a;
  --origin-tencent: #2a78d6;
  --origin-share: #eda100;
  --origin-mp: #008300;
  --origin-search: #e87ba4;
  --origin-frequent: #6250d6;
  --origin-other: #eb6834;
  --origin-new: #235b49;
  --origin-old: #c48a2c;
  --origin-dim: #e6ebe7;
  --radius-sm: 6px;
  --radius: 8px;
  --radius-lg: 12px;
  --shadow-sm: 0 1px 2px rgb(22 40 32 / 0.05);
  --shadow: 0 1px 2px rgb(22 40 32 / 0.05), 0 2px 8px rgb(22 40 32 / 0.04);
  --shadow-lg: 0 12px 32px rgb(22 40 32 / 0.16), 0 2px 6px rgb(22 40 32 / 0.08);
  --sidebar: 232px;
  --topbar: 56px;
  --focus: 0 0 0 3px rgb(35 91 73 / 0.28);
  --z-sticky: 10;
  --z-topbar: 20;
  --z-toast: 40;
  /* Control sizes (spec 2026-10-06 §2.2): a button, input and select of one size line up in a row. */
  --surface-glass: rgb(255 255 255 / 0.94);
  --control-h: 32px;
  --control-h-sm: 28px;
  --control-h-lg: 40px;
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 24px;
  --space-6: 32px;
  --fs-xs: 12px;
  --fs-sm: 13px;
  --fs: 14px;
  --fs-md: 15px;
  --fs-lg: 17px;
  --fs-xl: 22px;
  --mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, monospace;

  font-family:
    -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB",
    "Microsoft YaHei", "Segoe UI", sans-serif;
  font-size: 14px;
  line-height: 1.55;
  color: var(--text);
  background: var(--bg);
  font-synthesis: none;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
/* Touch screens (phones, tablets): larger controls, the same in every row. */
@media (pointer: coarse) {
  :root {
    --control-h: 40px;
    --control-h-sm: 36px;
    --control-h-lg: 44px;
  }
}
*,
*::before,
*::after {
  box-sizing: border-box;
}
html {
  scroll-behavior: smooth;
  scroll-padding-top: calc(var(--topbar) + 72px);
}
body {
  margin: 0;
  min-height: 100dvh;
  background: var(--bg);
}
[hidden] {
  display: none !important;
}
h1,
h2,
h3 {
  margin: 0;
  color: var(--text);
  text-wrap: balance;
}
h1 {
  font-size: 22px;
  font-weight: 600;
  letter-spacing: -0.01em;
  line-height: 1.3;
}
h2 {
  font-size: 15px;
  font-weight: 600;
  line-height: 1.4;
}
h3 {
  font-size: 14px;
  font-weight: 600;
}
p {
  margin: 0;
}
a {
  color: var(--accent);
}
code,
.mono {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--text-2);
  font-variant-numeric: tabular-nums;
}
code {
  overflow-wrap: anywhere;
}
.muted {
  color: var(--text-3);
  font-size: 13px;
}
small {
  color: var(--text-3);
  font-size: 12px;
}
.num,
.stat-value,
td {
  font-variant-numeric: tabular-nums;
}
.visually-hidden {
  position: absolute !important;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
}
.skip-link {
  position: absolute;
  left: 12px;
  top: -48px;
  z-index: var(--z-toast);
  background: var(--accent);
  color: #fff;
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  transition: top 0.15s;
}
.skip-link:focus {
  top: 12px;
}

/* ---------- Busy state ---------- */
body[aria-busy="true"]::before {
  content: "";
  position: fixed;
  inset: 0 0 auto 0;
  height: 2px;
  z-index: var(--z-toast);
  background: linear-gradient(90deg, transparent, var(--accent), transparent);
  background-size: 40% 100%;
  background-repeat: no-repeat;
  animation: busy 1s ease-in-out infinite;
}
body[aria-busy="true"] {
  cursor: progress;
}
body[aria-busy="true"] #content {
  opacity: 0.72;
  transition: opacity 0.2s 0.15s;
}
@keyframes busy {
  from {
    background-position: -40% 0;
  }
  to {
    background-position: 140% 0;
  }
}

/* ---------- Controls ---------- */
button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
}
.btn,
button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: var(--control-h);
  padding: 0 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--accent);
  background: var(--accent);
  color: #fff;
  font-weight: 500;
  font-size: 14px;
  line-height: 1.2;
  white-space: nowrap;
  cursor: pointer;
  transition:
    background-color 0.15s,
    border-color 0.15s,
    color 0.15s,
    box-shadow 0.15s,
    transform 0.05s;
}
button:hover:not(:disabled) {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}
button:active:not(:disabled) {
  transform: translateY(1px);
}
button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
summary:focus-visible,
a:focus-visible,
.thumb-upload:focus-within {
  outline: none;
  box-shadow: var(--focus);
}
button:disabled {
  cursor: not-allowed;
  background: var(--surface-3);
  border-color: var(--border);
  color: var(--text-3);
}
.btn.secondary,
button.secondary {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border-strong);
  box-shadow: var(--shadow-sm);
}
.btn.secondary:hover:not(:disabled),
button.secondary:hover:not(:disabled) {
  background: var(--surface-2);
  border-color: #b5c0b4;
}
/* button:disabled above loses to .btn.secondary: a disabled secondary button still has to look it. */
.btn.secondary:disabled,
button.secondary:disabled {
  background: var(--surface-3);
  border-color: var(--border);
  color: var(--text-3);
  box-shadow: none;
}
.btn.ghost {
  background: transparent;
  border-color: transparent;
  color: var(--text-2);
  box-shadow: none;
}
.btn.ghost:hover:not(:disabled) {
  background: var(--surface-3);
  border-color: transparent;
  color: var(--text);
}
.btn.danger,
button.danger {
  color: #fff;
  background: var(--danger);
  border-color: var(--danger);
}
.btn.danger:hover:not(:disabled),
button.danger:hover:not(:disabled) {
  color: #fff;
  background: var(--danger-hover);
  border-color: var(--danger-hover);
}
.btn.warn {
  background: var(--warn-soft);
  border-color: var(--warn-line);
  color: var(--warn);
}
.btn.warn:hover:not(:disabled) {
  background: #fbecc4;
  border-color: #e7c979;
}
.btn.sm {
  min-height: var(--control-h-sm);
  padding: 0 10px;
  font-size: 13px;
}
.btn.block {
  width: 100%;
  min-height: var(--control-h-lg);
}
/* A square button with only an icon: its aria-label and title say what it does. */
.btn.icon {
  width: var(--control-h);
  padding: 0;
}
.btn.icon.sm {
  width: var(--control-h-sm);
}
/* Inputs and selects beside small buttons. */
input.sm,
select.sm,
.field.sm input,
.field.sm select {
  min-height: var(--control-h-sm);
  height: var(--control-h-sm);
  padding-block: 0;
  font-size: var(--fs-sm);
}
.btn svg,
button svg {
  width: 16px;
  height: 16px;
  flex: none;
}

input,
select,
textarea {
  width: 100%;
  min-height: var(--control-h);
  padding: 5px 10px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  transition:
    border-color 0.15s,
    box-shadow 0.15s;
}
/* One-line fields are exactly a control tall, whatever their font and line height (:where keeps this rule as weak as a
   plain `input`, so .sm and page rules still win). */
input:where(:not([type="checkbox"]):not([type="radio"]):not([type="file"])),
select {
  height: var(--control-h);
  padding-block: 0;
}
input:hover,
select:hover,
textarea:hover {
  border-color: #b5c0b4;
}
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  border-color: var(--accent);
}
input::placeholder,
textarea::placeholder {
  color: #a4ada7;
}
textarea {
  min-height: 96px;
  resize: vertical;
  line-height: 1.6;
}
input[type="number"] {
  font-variant-numeric: tabular-nums;
}
input[type="checkbox"],
input[type="radio"] {
  width: 16px;
  height: 16px;
  min-height: 0;
  margin: 0;
  padding: 0;
  accent-color: var(--accent);
  flex: none;
}
input[type="file"] {
  font-size: 13px;
  padding: 6px;
}
.field {
  display: grid;
  gap: 6px;
  font-size: 13px;
}
.field > span:first-child,
.field-label {
  color: var(--text-2);
  font-weight: 500;
}
.field .hint {
  color: var(--text-3);
  font-size: 12px;
  font-weight: 400;
}
.check {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text);
  cursor: pointer;
  white-space: nowrap;
}
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 16px;
}
.form-grid .span-all {
  grid-column: 1 / -1;
}
.form-stack {
  display: grid;
  gap: 14px;
}
/* Form fields as wide as what they hold (spec 2026-10-06 §2.4): a single-column form's fields stop at 640px, numbers
   and short choices narrower; a phone keeps them full width (pages.css). */
.form-stack > .field,
.form-stack > form > .field {
  max-width: 640px;
}
.form-stack .field > input[type="number"] {
  max-width: 12em;
}
.form-stack .field > select {
  max-width: 24em;
}
/* A form's submit row inside a card: the end of the form, not a grey bar. */
.form-stack .card-foot {
  padding: 0;
  border-top: 0;
  background: none;
  justify-content: flex-start;
}
.form-actions {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}

/* Toggle switch */
input.switch {
  appearance: none;
  -webkit-appearance: none;
  width: 34px;
  height: 20px;
  border-radius: 999px;
  background: #cfd6cf;
  border: none;
  position: relative;
  cursor: pointer;
  transition: background-color 0.15s;
}
input.switch::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 2px rgb(0 0 0 / 0.2);
  transition: transform 0.15s;
}
input.switch:checked {
  background: var(--accent);
}
input.switch:checked::after {
  transform: translateX(14px);
}
input.switch:focus-visible {
  box-shadow: var(--focus);
}
/* A switch the operator may not turn (a board successor): its label's title says why. */
.check.locked,
input.switch:disabled {
  cursor: not-allowed;
}
input.switch:disabled {
  opacity: 0.55;
}

/* ---------- Pills ---------- */
.pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  height: 22px;
  padding: 0 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 500;
  white-space: nowrap;
  background: var(--surface-3);
  color: var(--text-2);
  line-height: 1;
}
.pill::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  opacity: 0.8;
}
.pill.plain::before {
  display: none;
}
.pill.warn {
  background: var(--warn-soft);
  color: var(--warn);
}
.pill.danger {
  background: var(--danger-soft);
  color: var(--danger);
}
.pill.info {
  background: var(--info-soft);
  color: var(--info);
}
.pill.success {
  background: var(--success-soft);
  color: var(--success);
}
.pill.accent {
  background: var(--accent-soft);
  color: var(--accent-text);
}
.pill.gold {
  background: #fbefd2;
  color: #7a4f00;
}

