/* ---------- 设计变量：跟随系统明暗 ---------- */
:root {
  --bg: #f5f6f8;
  --card: #ffffff;
  --text: #1b1f24;
  --muted: #6a7280;
  --border: #e3e6ea;
  --soft: #f0f2f5;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --on-primary: #ffffff;
  --danger: #dc2626;
  --danger-soft: #fef2f2;
  --code-bg: #f7f8fa;
  --backdrop: rgba(15, 23, 42, 0.5);
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 4px 16px rgba(16, 24, 40, 0.08);
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", "Noto Sans Mono CJK SC", monospace;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1116;
    --card: #161a21;
    --text: #e6e8eb;
    --muted: #9aa2ad;
    --border: #262c36;
    --soft: #1c2129;
    --primary: #3b82f6;
    --primary-hover: #60a5fa;
    --danger: #f87171;
    --danger-soft: #2a1618;
    --code-bg: #10141a;
    --backdrop: rgba(0, 0, 0, 0.65);
    --shadow: none;
  }
}

/* ---------- 基础 ---------- */
*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body {
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", "PingFang SC", "Microsoft YaHei", "Noto Sans CJK SC", sans-serif;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3, p { margin: 0; }
h2 { font-size: 18px; font-weight: 600; }
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.spacer { flex: 1; }
.error { color: var(--danger); font-size: 14px; }
.offscreen { position: fixed; left: -9999px; top: 0; opacity: 0; }

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

/* ---------- 按钮 / 输入框 ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 8px 14px; border-radius: 8px; border: 1px solid transparent;
  background: transparent; cursor: pointer; white-space: nowrap;
  transition: background-color 0.15s, border-color 0.15s, color 0.15s;
}
.btn.sm { padding: 5px 10px; font-size: 13px; }
.btn.block { width: 100%; padding: 10px 14px; font-size: 15px; }
.btn.primary { background: var(--primary); color: var(--on-primary); }
.btn.primary:hover { background: var(--primary-hover); }
.btn.ghost { border-color: var(--border); }
.btn.ghost:hover { background: var(--soft); }
.btn.danger { background: var(--danger-soft); color: var(--danger); border-color: transparent; }
.btn.danger:hover { background: var(--danger); color: #fff; }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }

.input, .textarea, .select {
  width: 100%; padding: 9px 12px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--card); color: var(--text);
  outline: none; transition: border-color 0.15s, box-shadow 0.15s;
}
.input:focus, .textarea:focus, .select:focus { border-color: var(--primary); box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 18%, transparent); }
.select.sm { width: auto; padding: 5px 8px; font-size: 13px; }
.textarea { resize: vertical; min-height: 150px; font-family: var(--mono); font-size: 14px; line-height: 1.55; }
.field { display: flex; flex-direction: column; gap: 6px; font-size: 14px; }
.field > span { color: var(--muted); }
.link { border: 0; background: none; color: var(--primary); cursor: pointer; padding: 0; }
.link:hover { text-decoration: underline; }

/* ---------- 登录页 ---------- */
.auth-wrap { min-height: 100%; display: flex; align-items: center; justify-content: center; padding: 24px; }
.auth-card { width: 100%; max-width: 380px; padding: 32px 28px; display: flex; flex-direction: column; gap: 14px; }
.auth-card h1 { font-size: 22px; font-weight: 650; }
.auth-lead { margin-top: -8px; }
.brand { display: inline-flex; align-items: center; gap: 8px; font-weight: 650; font-size: 16px; }
.brand-lg { font-size: 20px; justify-content: center; }

/* ---------- 顶栏 ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 12px; padding: 10px 16px;
  background: var(--card); border-bottom: 1px solid var(--border);
}
.search { flex: 1; max-width: 520px; }
.search input {
  width: 100%; padding: 8px 12px; border-radius: 999px;
  border: 1px solid var(--border); background: var(--soft); color: var(--text); outline: none;
}
.search input:focus { border-color: var(--primary); background: var(--card); }
.nav { display: flex; align-items: center; gap: 6px; margin-left: auto; }
.menu-wrap { position: relative; }
.menu {
  position: absolute; right: 0; top: calc(100% + 6px); min-width: 160px;
  background: var(--card); border: 1px solid var(--border); border-radius: 10px;
  box-shadow: var(--shadow); padding: 6px; display: flex; flex-direction: column; z-index: 30;
}
.menu button { text-align: left; border: 0; background: none; padding: 8px 10px; border-radius: 6px; cursor: pointer; }
.menu button:hover { background: var(--soft); }

/* ---------- 主体布局 ---------- */
.layout {
  display: grid; grid-template-columns: minmax(320px, 420px) minmax(0, 1fr);
  gap: 16px; max-width: 1440px; margin: 0 auto; padding: 16px; align-items: start;
}
.composer { padding: 14px; display: flex; flex-direction: column; gap: 10px; position: sticky; top: 66px; }
.composer[hidden] + .board { grid-column: 1 / -1; } /* 回收站里没有输入框，内容区占满整行 */
.composer-foot { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.lang-pick { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); white-space: nowrap; flex: none; }
.dropzone {
  border: 1px dashed var(--border); border-radius: 10px; padding: 12px;
  text-align: center; font-size: 14px; color: var(--muted); background: var(--soft);
}
.dropzone.dragging { border-color: var(--primary); color: var(--primary); background: var(--card); }
.pick-names { display: block; color: var(--primary); margin-top: 2px; word-break: break-all; }
.progress { height: 6px; border-radius: 999px; background: var(--soft); overflow: hidden; }
.progress > div { height: 100%; width: 0; background: var(--primary); transition: width 0.15s; }

.board { min-width: 0; }
.board-head { display: flex; align-items: center; gap: 10px; padding: 2px 4px 10px; }
.list { display: flex; flex-direction: column; gap: 10px; }
.list-more { display: flex; justify-content: center; align-items: center; gap: 10px; padding: 14px 0 40px; min-height: 30px; }
.empty { padding: 56px 16px; text-align: center; color: var(--muted); }

/* ---------- 剪贴条目 ---------- */
.clip {
  display: flex; gap: 8px; padding: 12px 12px 12px 14px;
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
}
.clip.pinned { border-color: color-mix(in srgb, var(--primary) 45%, var(--border)); }
.clip-main { flex: 1; min-width: 0; cursor: pointer; display: flex; flex-direction: column; gap: 6px; }
.clip-title { display: flex; align-items: center; gap: 6px; font-weight: 600; min-width: 0; }
.clip-title .icon { flex: none; }
.clip-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pin-flag { flex: none; font-size: 13px; }
.clip-preview {
  margin: 0; font-family: var(--mono); font-size: 13px; line-height: 1.5; color: var(--text);
  white-space: pre-wrap; word-break: break-all;
  display: -webkit-box; -webkit-line-clamp: 4; -webkit-box-orient: vertical; overflow: hidden;
}
.thumb { display: block; max-width: 320px; max-height: 120px; border-radius: 8px; border: 1px solid var(--border); }
.clip-meta { display: flex; flex-wrap: wrap; gap: 4px 8px; font-size: 12.5px; color: var(--muted); }
.clip-actions { display: flex; flex-direction: column; justify-content: center; gap: 4px; flex: none; }
.clip-actions .btn { padding: 4px 10px; font-size: 13px; }

/* ---------- 对话框 ---------- */
.dlg {
  border: 0; padding: 0; border-radius: 14px; background: var(--card); color: var(--text);
  box-shadow: var(--shadow); width: min(1100px, 96vw); max-width: none; max-height: 92vh;
}
.dlg-sm { width: min(420px, 94vw); }
.dlg::backdrop { background: var(--backdrop); }
.dlg-view { height: fit-content; } /* 模态 dialog 上下都贴边，auto 会被拉伸；高度随内容，超出 92vh 由 .dlg-body 内部滚动 */
.dlg-inner { display: flex; flex-direction: column; max-height: 92vh; }
.dlg-head {
  display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  padding: 14px 16px; border-bottom: 1px solid var(--border);
}
.dlg-titles { min-width: 0; flex: 1; display: flex; flex-direction: column; gap: 2px; }
.dlg-title { font-size: 16px; word-break: break-all; }
.dlg-tools { display: flex; flex-wrap: wrap; gap: 6px; justify-content: flex-end; }
.dlg-body { padding: 16px; overflow: auto; flex: 1; min-height: 0; }
.dlg-foot { display: flex; align-items: center; gap: 8px; padding: 10px 16px; border-top: 1px solid var(--border); flex-wrap: wrap; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.row-end { display: flex; justify-content: flex-end; gap: 8px; }

pre.code {
  margin: 0; padding: 14px; border-radius: 10px; background: var(--code-bg);
  border: 1px solid var(--border); font-family: var(--mono); font-size: 13.5px; line-height: 1.6;
  white-space: pre; overflow: auto; tab-size: 4;
}
pre.code.wrap { white-space: pre-wrap; word-break: break-all; }
pre.code code.hljs { display: block; padding: 0; background: transparent; overflow: visible; }
.viewer { display: flex; flex-direction: column; gap: 12px; align-items: flex-start; }
.viewer img, .viewer video { max-width: 100%; max-height: 70vh; border-radius: 8px; background: var(--soft); }
.viewer iframe { width: 100%; height: 70vh; border: 1px solid var(--border); border-radius: 8px; background: #fff; }
.viewer audio { width: 100%; }
.file-card {
  display: flex; flex-direction: column; gap: 6px; padding: 18px; width: 100%;
  border: 1px solid var(--border); border-radius: 10px; background: var(--soft);
}
.file-card code { font-family: var(--mono); font-size: 12px; word-break: break-all; color: var(--muted); }
.notice { padding: 18px; border: 1px dashed var(--border); border-radius: 10px; text-align: center; color: var(--muted); }

.table { width: 100%; border-collapse: collapse; font-size: 14px; margin-bottom: 14px; }
.table th, .table td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); }
.table th { color: var(--muted); font-weight: 500; font-size: 13px; }
.row-form { display: grid; grid-template-columns: 1fr 1fr auto; gap: 8px; }

/* ---------- 拖拽遮罩 / 提示 ---------- */
.drop-overlay {
  position: fixed; inset: 0; z-index: 100; background: color-mix(in srgb, var(--primary) 12%, transparent);
  display: flex; align-items: center; justify-content: center; pointer-events: none;
}
.drop-box {
  padding: 28px 40px; border: 2px dashed var(--primary); border-radius: 16px;
  background: var(--card); color: var(--primary); font-size: 18px; font-weight: 600;
}
.toast {
  position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%); z-index: 120;
  padding: 10px 16px; border-radius: 999px; background: var(--text); color: var(--card);
  font-size: 14px; max-width: min(560px, 90vw); overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  box-shadow: var(--shadow);
}
.toast.err { background: var(--danger); color: #fff; }

/* ---------- 窄屏 ---------- */
@media (max-width: 900px) {
  .topbar { flex-wrap: wrap; gap: 8px; }
  .search { order: 3; flex-basis: 100%; max-width: none; }
  .layout { grid-template-columns: 1fr; padding: 12px; }
  .composer { position: static; }
  .textarea { min-height: 110px; }
  .clip-actions { flex-direction: column; }
  .row-form { grid-template-columns: 1fr; }
  .dlg-tools .btn, .dlg-tools .select { padding: 5px 8px; }
}
