/* ==========================================================================
   共用样式（前台和后台都加载）：基础、表单、按钮、表格、提示、徽章。
   颜色、字体、圆角、间距全部来自 tokens.css（设计系统，见 design/DESIGN.md）。
   前台另外加载 components.css（设计系统的组件）和 site.css（把现有页面结构接到组件上）。
   这里的旧变量名（--text、--muted、--radius 等）只是指向 tokens 的别名，后台沿用。
   手机优先：先写 375px 的样式，再用 min-width 往大屏幕加。
   ========================================================================== */

:root {
  /* 旧名字 -> tokens.css。深色模式由 tokens.css 统一切换，这里不再写第二份。 */
  --text: var(--ink);
  --muted: var(--ink-2);
  --radius: var(--r-md);
  --radius-sm: var(--r-sm);
  --shadow: var(--shadow-1);
  --font: var(--font-sans);
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --leading: var(--lh-body);

  --success-bg: var(--ok-bg);  --success-text: var(--ok-ink);
  --error-bg: var(--err-bg);   --error-text: var(--err-ink);
  --info-text: var(--info-ink);
  --success-line: color-mix(in srgb, var(--ok-ink) 40%, transparent);
  --error-line: color-mix(in srgb, var(--err-ink) 40%, transparent);
  --info-line: color-mix(in srgb, var(--info-ink) 40%, transparent);

  --danger: #a82b20;  --danger-hover: #8f2218;  --on-danger: #ffffff;

  --container: 1120px;
  --header-h: 60px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) { --danger: #ffb4aa; --danger-hover: #ffcfc8; --on-danger: #43211e; }
}
:root[data-theme="dark"] { --danger: #ffb4aa; --danger-hover: #ffcfc8; --on-danger: #43211e; }

/* 中文：行距 1.8，不加字距。 */
html[lang="zh"] { --leading: var(--lh-cjk); }
html[lang="zh"] :is(.table th, .nav-group-title) { letter-spacing: normal; text-transform: none; }

/* ---------- 基础 ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  line-height: var(--leading);
  color: var(--text);
  background: var(--bg);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  overflow-wrap: anywhere;          /* 长邮箱、长单词不撑破布局 */
}
img, svg { max-width: 100%; height: auto; }
a { color: var(--link); text-underline-offset: 3px; }
a:hover { text-decoration-thickness: 2px; }
h1, h2, h3 { font-family: var(--font-display); line-height: 1.25; margin: 0 0 0.6em; text-wrap: balance; }
h1 { font-size: var(--fs-xl); }
h2 { font-size: var(--fs-md); }
h3 { font-size: 1.05rem; }
:lang(zh) :is(h1, h2, h3) { line-height: 1.35; }
p { margin: 0 0 1em; }
code, pre { font-family: var(--font-mono); font-size: 0.92em; }
pre { overflow: auto; background: var(--surface-2); padding: 0.75rem; border-radius: var(--radius-sm); }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; border-radius: var(--r-sm); }

.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); border: 0; }
.skip-link { position: absolute; left: -999px; top: 0.5rem; background: var(--ink); color: var(--bg); padding: 0.5rem 1rem; z-index: 100; border-radius: var(--r-sm); }
.skip-link:focus { left: 0.5rem; }
.muted { color: var(--muted); }
.nowrap { white-space: nowrap; }
.center { text-align: center; }
.inline { display: inline; margin: 0; }
.empty { color: var(--muted); text-align: center; padding: 2rem 1rem; }

/* ---------- 布局 ---------- */
.container { width: min(var(--container), 100% - 2rem); margin-inline: auto; }
.main { flex: 1; padding-block: 1.5rem 3rem; }
.narrow { max-width: 440px; margin-inline: auto; }
.stack { display: grid; gap: 1rem; }
.grid { display: grid; gap: 1rem; }
.grid.two { grid-template-columns: 1fr; }
@media (min-width: 900px) { .grid.two { grid-template-columns: 1fr 1fr; } }

/* ---------- 品牌、汉堡按钮、语言切换（后台侧栏和顶栏也用） ---------- */
.admin-sidebar .brand { font: 700 1.1rem/1.2 var(--font-display); color: var(--text); text-decoration: none; }
.nav-toggle {
  display: inline-flex; align-items: center; justify-content: center;
  width: 44px; height: 44px; border: 1px solid var(--line-strong); border-radius: var(--r-md);
  background: transparent; color: var(--text); cursor: pointer;
}
.burger, .burger::before, .burger::after {
  display: block; width: 18px; height: 2px; background: currentColor; border-radius: 2px; position: relative;
}
.burger::before, .burger::after { content: ""; position: absolute; left: 0; }
.burger::before { top: -6px; }
.burger::after { top: 6px; }

.lang-switch { display: inline-flex; border: 1px solid var(--line-strong); border-radius: var(--r-pill); overflow: hidden; flex: none; }
.lang-switch a { min-width: var(--tap); min-height: 40px; display: grid; place-items: center; padding: 0 var(--s-3); font-size: var(--fs-sm); font-weight: 600; color: var(--ink-2); text-decoration: none; white-space: nowrap; }
.lang-switch a:hover { background: var(--surface-2); }
.lang-switch a[aria-current="true"] { background: var(--ink); color: var(--bg); }
.lang-switch a:focus-visible { outline-offset: -3px; }

/* ---------- 按钮 ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.4rem;
  min-height: var(--tap); padding: 0.55rem 1.25rem;
  font: inherit; font-size: var(--fs-sm); font-weight: 600; line-height: 1.2;
  color: var(--on-primary); background: var(--primary);
  border: 2px solid transparent; border-radius: var(--r-pill);
  text-decoration: none; cursor: pointer;
}
.btn:hover { background: var(--primary-hover); }
.btn-ghost { background: transparent; color: var(--primary); border-color: var(--line-strong); }
.btn-ghost:hover { border-color: var(--primary); background: var(--surface); }
.btn-danger { background: var(--danger); color: var(--on-danger); }
.btn-danger:hover { background: var(--danger-hover); }
.btn-small { min-height: 36px; padding: 0.3rem 0.9rem; font-size: var(--fs-xs); }
.btn-block { width: 100%; }
.btn[disabled], .btn[aria-disabled="true"] { opacity: .5; cursor: not-allowed; pointer-events: none; }
.link-button { background: none; border: 0; padding: 0; font: inherit; color: var(--link); cursor: pointer; text-decoration: underline; text-underline-offset: 3px; }
.actions { display: flex; gap: 0.75rem; flex-wrap: wrap; }

/* ---------- 表单 ---------- */
label { display: grid; gap: 0.35rem; font-weight: 600; font-size: var(--fs-sm); }
label.check { display: flex; align-items: center; gap: 0.5rem; font-weight: 500; }
input, select, textarea {
  font: inherit; font-weight: 400; color: var(--text);
  width: 100%; min-height: var(--tap); padding: 0.6rem 0.9rem;
  background: var(--surface); border: 1px solid var(--line-strong); border-radius: var(--r-md);
  transition: border-color .2s;
}
input:hover:not(:disabled), select:hover:not(:disabled), textarea:hover:not(:disabled) { border-color: var(--ink-3); }
/* 复选框 / 单选框至少 24×24px（WCAG 2.2 目标尺寸）；整行 label 都能点，所以实际可点区域更大。 */
input[type="checkbox"], input[type="radio"] { width: 1.5rem; min-width: 1.5rem; min-height: 0; height: 1.5rem; flex: none; accent-color: var(--primary); }
input[type="file"] { padding: 0.45rem; }
input:disabled { background: var(--surface-2); color: var(--muted); }
textarea { resize: vertical; line-height: var(--leading); min-height: 120px; }
input:focus-visible, select:focus-visible, textarea:focus-visible { outline: 3px solid var(--focus); outline-offset: 1px; border-color: var(--focus); }
.hint { font-weight: 400; color: var(--ink-3); font-size: var(--fs-xs); }
.code-input { font-family: var(--font-mono); letter-spacing: 0.15em; max-width: 14rem; }
html[lang="zh"] .code-input { letter-spacing: normal; }
.row-form { display: flex; gap: 0.5rem; flex-wrap: wrap; align-items: center; margin-bottom: 1rem; }
.row-form input { flex: 1 1 10rem; }
.form-card h1 { font-size: var(--fs-lg); }
.form-links { margin: 1rem 0 0; text-align: center; font-size: var(--fs-sm); }
.divider { display: flex; align-items: center; gap: 0.75rem; color: var(--muted); margin: 1rem 0; font-size: var(--fs-sm); }
.divider::before, .divider::after { content: ""; flex: 1; border-top: 1px solid var(--line); }

/* ---------- 卡片、提示、徽章 ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.25rem; }
.callout { border-color: var(--primary); }

/* 提示条：图标 + 文字，不只靠颜色。前台和后台同一套（对应设计系统的 .flash）。 */
.alert {
  display: flex; align-items: flex-start; gap: 0.75rem;
  padding: 0.75rem 1rem; margin-bottom: 1rem; border-radius: var(--r-md); border: 1px solid;
  font-size: var(--fs-sm); font-weight: 500;
}
.alert::before {
  content: "i"; flex: none; width: 22px; height: 22px; margin-top: 0.15rem; border-radius: 50%;
  border: 2px solid currentColor; display: grid; place-items: center; font-size: 13px; font-weight: 800; line-height: 1;
}
.alert > span { flex: 1; min-width: 0; }
.alert-success { background: var(--success-bg); color: var(--success-text); border-color: var(--success-line); }
.alert-success::before { content: "\2713"; }
.alert-error { background: var(--error-bg); color: var(--error-text); border-color: var(--error-line); }
.alert-error::before { content: "\00d7"; font-size: 18px; }
.alert-info { background: var(--info-bg); color: var(--info-text); border-color: var(--info-line); }
.alert-close { background: none; border: 0; font-size: 1.25rem; line-height: 1; color: inherit; cursor: pointer; min-width: 32px; min-height: 32px; }

.badge { display: inline-block; white-space: nowrap; padding: 0.1rem 0.65rem; border-radius: 999px; font-size: var(--fs-xs); font-weight: 700; background: var(--surface-2); color: var(--ink-2); border: 1px solid var(--line); }
.badge-success { background: var(--success-bg); color: var(--success-text); border-color: var(--success-line); }
.badge-danger { background: var(--error-bg); color: var(--error-text); border-color: var(--error-line); }

/* ---------- 表格 ---------- */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table { width: 100%; border-collapse: collapse; font-size: var(--fs-sm); }
.table th, .table td { text-align: left; padding: 0.65rem 0.75rem; border-bottom: 1px solid var(--line); vertical-align: top; }
.table th { font-size: var(--fs-xs); text-transform: uppercase; letter-spacing: 0.03em; color: var(--ink-2); font-weight: 700; }
.table tr.is-inactive td { opacity: 0.6; }
@media (max-width: 640px) { .hide-sm { display: none; } }

.pagination { display: flex; gap: 1rem; align-items: center; justify-content: center; margin: 1.5rem 0; }
.pagination a { display: inline-flex; align-items: center; min-height: var(--tap); }

/* ---------- 错误页、两步验证 ---------- */
.error-page { padding-top: 3rem; }
.error-code { font: 600 3.5rem/1 var(--font-display); color: var(--line-strong); margin: 0; }
.debug { text-align: left; font-size: 0.8rem; max-height: 50vh; }

.steps { display: grid; gap: 1.25rem; padding-left: 1.25rem; margin: 0; }
.qr { background: #fff; display: inline-block; padding: 0.5rem; border-radius: var(--radius-sm); margin: 0.75rem 0; }
.qr svg { display: block; width: 200px; height: 200px; }
.secret { font-size: 1.05rem; letter-spacing: 0.08em; word-break: break-all; }
.codes { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.5rem; padding: 0; list-style: none; }
.codes code { display: block; padding: 0.4rem 0.6rem; background: var(--surface-2); border-radius: var(--radius-sm); text-align: center; font-size: 1rem; }
.only-mobile { display: block; }
@media (min-width: 900px) { .only-mobile { display: none; } }

/* 蜜罐：人看不见也点不到，机器人会填。不用 display:none（有些机器人专门跳过 display:none 的字段）。 */
.hp { position: absolute; left: -10000px; top: auto; width: 1px; height: 1px; overflow: hidden; }
.consent { align-items: flex-start; font-weight: 400; }
.consent input { margin-top: 0.15rem; flex: none; }
