/* ============ 设计令牌与基础组件 ============ */
:root {
  --ink: #0a0b0d;
  --ink-2: #121317;
  --ink-3: #1a1c22;
  --paper: #ffffff;
  --paper-2: #f5f6f8;
  --paper-3: #eceef2;
  --line-dark: rgba(255, 255, 255, 0.1);
  --line-light: #e4e6eb;
  --text-dark: #f2f3f7;
  --text-light: #1c1f26;
  --muted-dark: #9aa1b2;
  --muted-light: #6b7280;
  --blue: #3b82f6;
  --blue-600: #2563eb;
  --violet: #8b5cf6;
  --ok: #22c55e;
  --warn: #f59e0b;
  --danger: #ef4444;
  --r-sm: 8px;
  --r-md: 12px;
  --r-lg: 18px;
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.06);
  --shadow-md: 0 8px 24px rgba(16, 24, 40, 0.12);
  --shadow-lg: 0 24px 60px rgba(0, 0, 0, 0.35);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB",
    "Microsoft YaHei", "Noto Sans SC", sans-serif;
  --mono: ui-monospace, SFMono-Regular, "Cascadia Code", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

a { color: inherit; text-decoration: none; }
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
img { display: block; max-width: 100%; }
:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; }

/* ---- 站点（深色） ---- */
body.site {
  background: var(--ink);
  color: var(--text-dark);
}

/* ---- 应用（浅色，可切深色） ---- */
body.app {
  background: var(--paper-2);
  color: var(--text-light);
}
body.app[data-theme="dark"] {
  background: var(--ink-2);
  color: var(--text-dark);
  --paper: #15171c;
  --paper-2: #101217;
  --paper-3: #1b1e25;
  --line-light: #262a33;
  --text-light: #e9ebf2;
  --muted-light: #98a0b1;
}

/* ---- 组件 ---- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  height: 38px;
  padding: 0 16px;
  border-radius: 10px;
  border: 1px solid transparent;
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
  transition: transform 0.12s ease, background 0.16s ease, border-color 0.16s ease, opacity 0.16s;
}
.btn:active { transform: translateY(1px); }
.btn[disabled] { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--blue); color: #fff; }
.btn-primary:hover { background: var(--blue-600); }
.btn-dark { background: var(--ink-3); color: var(--text-dark); border-color: var(--line-dark); }
.btn-dark:hover { background: #24262e; }
.btn-light { background: var(--paper); color: var(--text-light); border-color: var(--line-light); }
.btn-light:hover { background: var(--paper-3); }
.btn-ghost { background: transparent; border-color: var(--line-light); color: inherit; }
.btn-ghost:hover { background: rgba(127, 127, 127, 0.08); }
.btn-sm { height: 32px; padding: 0 12px; font-size: 13px; border-radius: 9px; }
.btn-lg { height: 44px; padding: 0 22px; font-size: 15px; border-radius: 12px; }
.btn-block { width: 100%; }

.input, .textarea, .select {
  width: 100%;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--line-light);
  background: var(--paper);
  color: inherit;
  font-size: 14px;
  line-height: 1.55;
}
.input:focus, .textarea:focus, .select:focus { border-color: var(--blue); outline: none; }
.textarea { resize: vertical; min-height: 90px; }
.field { margin-bottom: 14px; }
.field > label { display: block; font-size: 12.5px; color: var(--muted-light); margin-bottom: 6px; }

.tag {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11.5px;
  line-height: 1.7;
  background: rgba(59, 130, 246, 0.1);
  color: var(--blue);
  border: 1px solid rgba(59, 130, 246, 0.22);
}
.tag-muted { background: rgba(127, 127, 127, 0.1); color: inherit; border-color: var(--line-light); }
.tag-ok { background: rgba(34, 197, 94, 0.12); color: #15803d; border-color: rgba(34, 197, 94, 0.3); }

.spinner {
  width: 16px; height: 16px;
  border: 2px solid rgba(127, 127, 127, 0.3);
  border-top-color: currentColor;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 64px 20px;
  text-align: center;
  color: var(--muted-light);
  font-size: 14px;
}
.empty-state .big { font-size: 34px; opacity: 0.55; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translate(-50%, 14px);
  padding: 10px 18px;
  border-radius: 11px;
  background: #1b1f27;
  color: #f2f3f7;
  border: 1px solid rgba(255, 255, 255, 0.12);
  box-shadow: var(--shadow-lg);
  font-size: 13.5px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s, transform 0.18s;
  z-index: 200;
  max-width: 90vw;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.err { border-color: rgba(239, 68, 68, 0.55); }

.skeleton {
  border-radius: var(--r-md);
  background: linear-gradient(100deg, var(--paper-3) 30%, var(--paper) 50%, var(--paper-3) 70%);
  background-size: 200% 100%;
  animation: sheen 1.4s infinite;
}
@keyframes sheen { to { background-position: -200% 0; } }

/* 富文本（对话气泡内） */
.rich { white-space: normal; }
.rich .md-p { margin: 0 0 10px; }
.rich .md-p:last-child { margin-bottom: 0; }
.rich .md-h { margin: 14px 0 7px; font-size: 15px; font-weight: 700; }
.rich .md-h:first-child { margin-top: 0; }
.rich .md-list { margin: 0 0 10px; }
.rich .md-li { position: relative; padding-left: 15px; margin-bottom: 4px; }
.rich .md-li::before { content: "·"; position: absolute; left: 3px; color: var(--blue); font-weight: 700; }
.rich .md-li.ordered { padding-left: 21px; }
.rich .md-li.ordered::before {
  content: attr(data-n); left: 0; color: var(--muted-light); font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.rich .code-block {
  margin: 0 0 10px; padding: 12px 14px; border-radius: 10px;
  background: #0d1117; color: #e6edf3; overflow-x: auto;
}
.rich .code-block code { font-family: var(--mono); font-size: 12.8px; line-height: 1.6; white-space: pre; }
.rich .inline-code {
  padding: 1px 5px; border-radius: 5px; background: rgba(127, 127, 127, 0.16);
  font-family: var(--mono); font-size: 0.92em;
}
