/* 颜色变量（浅色 / 深色）、基础样式、通用控件、弹窗 */
:root {
  --bg: #f8f7f4;
  --panel: #ffffff;
  --sidebar: #f2f1ed;
  --text: #1c1b19;
  --muted: #66645f;
  --faint: #9b9993;
  --border: #e7e5e0;
  --hover: rgba(0, 0, 0, 0.045);
  --active: rgba(0, 0, 0, 0.075);
  --accent: #c2410c;
  --accent-2: #ea7a3c;
  --accent-text: #ffffff;
  --accent-soft: #fcefe6;
  --danger: #c0262d;
  --ok: #15803d;
  --user-bubble: #efede8;
  --code-bg: #f4f3f0;
  --glass: rgba(248, 247, 244, 0.78);
  --shadow: 0 12px 40px rgba(0, 0, 0, 0.14);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.04), 0 6px 20px rgba(0, 0, 0, 0.06);
  --radius: 14px;
  --hl-comment: #8c8a83;
  --hl-string: #0f7b3d;
  --hl-number: #b4560a;
  --hl-keyword: #a626a4;
  --hl-func: #2860c8;
  --hl-type: #b07800;
  --hl-attr: #9a4a00;
  --hl-var: #c2410c;
  --hl-meta: #0e7c86;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  color-scheme: light;
}
/* 深色：跟随系统时按系统设置；用户在「外观」里选了深色 / 浅色时以选的为准（两处内容要保持一致） */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #151517;
    --panel: #1f1f22;
    --sidebar: #19191b;
    --text: #ededeb;
    --muted: #a3a29d;
    --faint: #767570;
    --border: #2c2c30;
    --hover: rgba(255, 255, 255, 0.055);
    --active: rgba(255, 255, 255, 0.09);
    --accent: #f0864a;
    --accent-2: #f5a66f;
    --accent-text: #1a0d05;
    --accent-soft: #33221a;
    --danger: #f2686e;
    --ok: #4ade80;
    --user-bubble: #2a2a2e;
    --code-bg: #111113;
    --glass: rgba(21, 21, 23, 0.78);
    --shadow: 0 12px 40px rgba(0, 0, 0, 0.55);
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3), 0 6px 20px rgba(0, 0, 0, 0.25);
    --hl-comment: #7d7c77;
    --hl-string: #98c379;
    --hl-number: #e5a15b;
    --hl-keyword: #d68ee6;
    --hl-func: #6fb3f2;
    --hl-type: #e5c07b;
    --hl-attr: #f0a66e;
    --hl-var: #f0864a;
    --hl-meta: #56c8d0;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #151517;
  --panel: #1f1f22;
  --sidebar: #19191b;
  --text: #ededeb;
  --muted: #a3a29d;
  --faint: #767570;
  --border: #2c2c30;
  --hover: rgba(255, 255, 255, 0.055);
  --active: rgba(255, 255, 255, 0.09);
  --accent: #f0864a;
  --accent-2: #f5a66f;
  --accent-text: #1a0d05;
  --accent-soft: #33221a;
  --danger: #f2686e;
  --ok: #4ade80;
  --user-bubble: #2a2a2e;
  --code-bg: #111113;
  --glass: rgba(21, 21, 23, 0.78);
  --shadow: 0 12px 40px rgba(0, 0, 0, 0.55);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3), 0 6px 20px rgba(0, 0, 0, 0.25);
  --hl-comment: #7d7c77;
  --hl-string: #98c379;
  --hl-number: #e5a15b;
  --hl-keyword: #d68ee6;
  --hl-func: #6fb3f2;
  --hl-type: #e5c07b;
  --hl-attr: #f0a66e;
  --hl-var: #f0864a;
  --hl-meta: #56c8d0;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.6 var(--font);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--accent); }
svg { flex-shrink: 0; }
#app { height: 100dvh; }

/* ---------- 通用控件 ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 36px; padding: 0 14px; border-radius: 9px;
  border: 1px solid var(--border); background: var(--panel); white-space: nowrap;
}
.btn:hover { background: var(--hover); }
a.btn { text-decoration: none; color: var(--text); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }
.btn.primary:hover { filter: brightness(1.05); }
.btn.danger { color: var(--danger); }
.btn.sm { min-height: 30px; padding: 0 10px; font-size: 13px; }
.icon-btn {
  display: inline-grid; place-items: center; width: 36px; height: 36px;
  border: 0; background: transparent; border-radius: 9px; color: var(--muted);
}
.icon-btn:hover { background: var(--hover); color: var(--text); }
.input, select.input, textarea.input {
  width: 100%; min-height: 38px; padding: 8px 11px; border-radius: 9px;
  border: 1px solid var(--border); background: var(--panel); outline: none;
}
.input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
textarea.input { resize: vertical; min-height: 80px; line-height: 1.5; }
label.field { display: grid; gap: 6px; font-size: 13px; color: var(--muted); }
label.field > span:first-child { font-weight: 600; color: var(--text); }
.hint { font-size: 12px; color: var(--faint); }
.row { display: flex; gap: 10px; align-items: center; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.spacer { flex: 1; }

.switch { position: relative; display: inline-block; vertical-align: middle; width: 38px; height: 22px; flex-shrink: 0; }
.switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.switch i { position: absolute; inset: 0; background: var(--border); border-radius: 99px; transition: .2s; cursor: pointer; }
.switch i::after { content: ""; position: absolute; width: 16px; height: 16px; left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: .2s; }
.switch input:checked + i { background: var(--ok); }
.switch input:checked + i::after { transform: translateX(16px); }

.avatar {
  display: inline-grid; place-items: center; width: 26px; height: 26px; border-radius: 8px;
  font-size: 13px; font-weight: 700; color: #fff; flex-shrink: 0; line-height: 1;
}

#toast {
  position: fixed; left: 50%; bottom: calc(96px + env(safe-area-inset-bottom)); transform: translateX(-50%) translateY(20px);
  background: var(--text); color: var(--bg); padding: 9px 18px; border-radius: 99px; font-size: 14px; box-shadow: var(--shadow);
  opacity: 0; pointer-events: none; transition: .2s; z-index: 100; max-width: calc(100vw - 32px);
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
#toast.error { background: var(--danger); color: #fff; }

/* 弹窗 */
.modal-bg {
  position: fixed; inset: 0; background: rgba(0, 0, 0, 0.4); z-index: 50; display: grid; place-items: center; padding: 16px;
  animation: fade .15s;
}
@keyframes fade { from { opacity: 0; } }
.modal {
  background: var(--panel); border-radius: 16px; width: min(520px, 100%); max-height: calc(100dvh - 32px);
  display: flex; flex-direction: column; box-shadow: var(--shadow); border: 1px solid var(--border);
}
.modal-head { display: flex; align-items: center; padding: 14px 14px 10px 20px; }
.modal-head h3 { margin: 0; font-size: 17px; flex: 1; }
.modal-body { padding: 4px 20px 16px; overflow-y: auto; display: grid; grid-template-columns: minmax(0, 1fr); gap: 14px; }
.modal-body .row > .input { flex: 1; min-width: 0; }
.modal-foot { display: flex; gap: 8px; padding: 12px 20px 16px; border-top: 1px solid var(--border); flex-wrap: wrap; }
.pick-list { border: 1px solid var(--border); border-radius: 10px; max-height: 46vh; overflow-y: auto; }
.pick-list label { display: flex; align-items: center; gap: 10px; padding: 8px 12px; border-bottom: 1px solid var(--border); font-size: 14px; cursor: pointer; }
.pick-list label:last-child { border-bottom: 0; }
.pick-list label.added { color: var(--faint); }
.pick-list .mono { font-family: var(--mono); font-size: 13px; word-break: break-all; }
.overlay { display: none; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
