/* ============================================================
   TOKENS(唯一的设计值来源)
   primitive → semantic 两层。断点(@media 里唯一允许的字面量):
   compact = 900px(单列,侧栏移到搜索上方)  narrow = 560px(手机,控件纵向堆叠)
   方向:白底 + 深青灰,检索工具感;路径等宽。
   ============================================================ */
:root {
  /* primitive · 颜色 */
  --p-teal-900: #12292e;
  --p-teal-700: #2b4a52;
  --p-teal-600: #0f6b6e;
  --p-teal-500: #4d6a72;
  --p-teal-300: #b3c6cb;
  --p-teal-200: #d2dfe2;
  --p-teal-100: #e6eff1;
  --p-teal-50: #f3f7f8;
  --p-white: #ffffff;
  --p-aqua-100: #d3ecec;
  --p-yellow-200: #ffe58f;
  --p-amber-700: #7a4f0c;
  --p-amber-100: #f8ead0;
  --p-red-700: #9b2f2f;
  --p-red-100: #f6dcdc;
  --p-focus: #1d6fd1;
  /* primitive · 尺寸 */
  --p-s1: 4px; --p-s2: 8px; --p-s3: 12px; --p-s4: 16px; --p-s5: 20px; --p-s6: 24px; --p-s8: 32px; --p-s10: 40px; --p-s12: 48px;
  --p-t-sm: 16px; --p-t-base: 17px; --p-t-lg: 20px; --p-t-xl: 24px; --p-t-2xl: 30px;
  --p-r-sm: 4px; --p-r-md: 8px; --p-r-lg: 10px;
  --p-border: 1px; --p-border-thick: 2px; --p-focus-w: 3px;
  --p-shadow: 0 6px 22px rgba(18, 41, 46, 0.1);
  --p-motion: 140ms; --p-ease: ease-out;
  --p-sidebar: 400px; --p-content: 1440px; --p-control: 44px; --p-textarea: 120px; --p-list: 70vh; --p-progress: 12px;

  /* semantic · 角色 */
  --bg: var(--p-teal-50);
  --surface: var(--p-white);
  --surface-muted: var(--p-teal-100);
  --line: var(--p-teal-200);
  --line-strong: var(--p-teal-300);
  --ink: var(--p-teal-900);
  --ink-2: var(--p-teal-700);
  --ink-muted: var(--p-teal-500);
  --action: var(--p-teal-600);
  --action-ink: var(--p-white);
  --action-soft: var(--p-aqua-100);
  --focus: var(--p-focus);
  --mark-bg: var(--p-yellow-200);
  --mark-ink: var(--p-teal-900);
  --warn: var(--p-amber-700); --warn-bg: var(--p-amber-100);
  --danger: var(--p-red-700); --danger-bg: var(--p-red-100);
  --s1: var(--p-s1); --s2: var(--p-s2); --s3: var(--p-s3); --s4: var(--p-s4); --s5: var(--p-s5); --s6: var(--p-s6); --s8: var(--p-s8); --s10: var(--p-s10); --s12: var(--p-s12);
  --t-sm: var(--p-t-sm); --t-base: var(--p-t-base); --t-lg: var(--p-t-lg); --t-xl: var(--p-t-xl); --t-2xl: var(--p-t-2xl);
  --r-sm: var(--p-r-sm); --r-md: var(--p-r-md); --r-lg: var(--p-r-lg);
  --border: var(--p-border); --border-thick: var(--p-border-thick); --focus-w: var(--p-focus-w);
  --shadow: var(--p-shadow);
  --motion: var(--p-motion); --ease: var(--p-ease);
  --sidebar-w: var(--p-sidebar); --content-w: var(--p-content); --control-h: var(--p-control); --textarea-h: var(--p-textarea); --list-h: var(--p-list); --progress-h: var(--p-progress);
  --font: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", system-ui, sans-serif;
  --font-path: ui-monospace, "SF Mono", Menlo, Consolas, "PingFang SC", "Microsoft YaHei", monospace;
  --leading: 1.6; --weight-regular: 400; --weight-medium: 600; --weight-bold: 700;
}

/* ============================================================ BASE */
* { box-sizing: border-box; }
html { font-size: var(--t-base); }
body { margin: 0; background: var(--bg); color: var(--ink); font-family: var(--font); font-size: var(--t-base); line-height: var(--leading); }
h1, h2, h3, p, dl, dd, ol { margin: 0; }
h1 { font-size: var(--t-2xl); font-weight: var(--weight-bold); }
h2 { font-size: var(--t-xl); font-weight: var(--weight-medium); margin-bottom: var(--s3); }
button, input, select, textarea { font: inherit; color: inherit; }
button, .file-btn { cursor: pointer; min-height: var(--control-h); padding: var(--s2) var(--s4); border: var(--border) solid var(--line-strong); border-radius: var(--r-sm); background: var(--surface); transition: background var(--motion) var(--ease), border-color var(--motion) var(--ease); }
button:hover:not(:disabled), .file-btn:hover { background: var(--surface-muted); }
button:disabled { cursor: not-allowed; color: var(--ink-muted); background: var(--surface-muted); border-color: var(--line); }
button.primary { background: var(--action); color: var(--action-ink); border-color: var(--action); }
button.primary:hover:not(:disabled) { background: var(--ink-2); border-color: var(--ink-2); }
button.primary:disabled { background: var(--surface-muted); color: var(--ink-muted); border-color: var(--line); }
button.danger { color: var(--danger); border-color: var(--danger); }
button.danger:hover:not(:disabled) { background: var(--danger-bg); }
button.link { border: 0; background: transparent; color: var(--action); text-decoration: underline; padding: var(--s1) 0; min-height: auto; justify-self: start; }
button:focus-visible, input:focus-visible, textarea:focus-visible, summary:focus-visible, .dropzone:focus-visible, .file-btn:focus-within { outline: var(--focus-w) solid var(--focus); outline-offset: var(--s1); }
input[type="text"], input[type="search"], textarea { width: 100%; min-height: var(--control-h); padding: var(--s2) var(--s3); border: var(--border) solid var(--line-strong); border-radius: var(--r-sm); background: var(--surface); }
input:disabled { background: var(--surface-muted); }
textarea { min-height: var(--textarea-h); resize: vertical; }
label { display: grid; gap: var(--s1); font-size: var(--t-sm); color: var(--ink-2); }
[hidden] { display: none !important; }
.muted { color: var(--ink-muted); font-size: var(--t-sm); }
.sr-input { position: absolute; width: var(--border); height: var(--border); opacity: 0; overflow: hidden; }
.file-btn { position: relative; display: inline-flex; align-items: center; color: var(--ink); font-size: var(--t-base); }
progress { width: 100%; height: var(--progress-h); accent-color: var(--action); }

/* ============================================================ 布局 */
.app { max-width: var(--content-w); margin: 0 auto; padding: var(--s6) var(--s6) var(--s12); }
.topbar { display: flex; flex-wrap: wrap; align-items: end; justify-content: space-between; gap: var(--s4); margin-bottom: var(--s5); border-bottom: var(--border-thick) solid var(--action); padding-bottom: var(--s4); }
.title-block { display: grid; gap: var(--s1); }
.eyebrow { font-size: var(--t-sm); color: var(--action); font-weight: var(--weight-medium); }
.workspace { display: grid; grid-template-columns: var(--sidebar-w) minmax(0, 1fr); gap: var(--s5); align-items: start; }
.side, .main { display: grid; gap: var(--s4); min-width: 0; }
.panel { background: var(--surface); border: var(--border) solid var(--line); border-radius: var(--r-lg); padding: var(--s5); min-width: 0; }
.stack { display: grid; gap: var(--s3); }
.row { display: flex; flex-wrap: wrap; gap: var(--s2); align-items: center; }
.row.between { justify-content: space-between; }

/* ============================================================ 警告与确认 */
.warnings { display: grid; gap: var(--s2); margin-bottom: var(--s4); }
.warnings:empty { display: none; }
.warning { background: var(--warn-bg); color: var(--warn); border: var(--border) solid var(--warn); border-left: var(--s2) solid var(--warn); border-radius: var(--r-md); padding: var(--s3) var(--s4); font-weight: var(--weight-medium); overflow-wrap: anywhere; }
.confirm { background: var(--danger-bg); border: var(--border) solid var(--danger); border-radius: var(--r-md); padding: var(--s3) var(--s4); display: grid; gap: var(--s2); margin-bottom: var(--s4); }
.toast { position: fixed; left: 50%; bottom: var(--s6); transform: translateX(-50%); background: var(--ink); color: var(--surface); padding: var(--s3) var(--s5); border-radius: var(--r-md); box-shadow: var(--shadow); max-width: calc(100% - var(--s8)); }

/* ============================================================ 笔记库 */
.dropzone { border: var(--border-thick) dashed var(--line-strong); border-radius: var(--r-md); padding: var(--s4); text-align: center; color: var(--ink-muted); cursor: pointer; }
.dropzone.over { border-color: var(--action); background: var(--action-soft); color: var(--ink); }
.dropzone.disabled { cursor: not-allowed; }
.summary { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--s2); }
.summary div { background: var(--surface-muted); border-radius: var(--r-md); padding: var(--s2) var(--s3); }
.summary dt { font-size: var(--t-sm); color: var(--ink-muted); }
.summary dd { font-size: var(--t-lg); font-weight: var(--weight-bold); font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }

/* ============================================================ 搜索与结果 */
.search-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: var(--s2); }
.result-bar { margin: var(--s3) 0; }
.results { display: grid; gap: var(--s3); margin-bottom: var(--s3); }
.hit { border: var(--border) solid var(--line); border-left: var(--focus-w) solid var(--action); border-radius: var(--r-md); padding: var(--s3) var(--s4); display: grid; gap: var(--s2); min-width: 0; }
.hit-head { display: flex; flex-wrap: wrap; gap: var(--s2); align-items: center; }
.rank-box { margin: var(--s2) 0; }
.rank-box summary { cursor: pointer; min-height: var(--control-h); display: flex; align-items: center; }
.path { font-family: var(--font-path); font-size: var(--t-sm); color: var(--ink-2); overflow-wrap: anywhere; }
.badge { display: inline-block; font-size: var(--t-sm); line-height: 1.3; padding: var(--s1) var(--s2); border-radius: var(--r-sm); background: var(--surface-muted); color: var(--ink-2); font-weight: var(--weight-medium); white-space: nowrap; }
.badge.accent { background: var(--action-soft); color: var(--action); }
.snippet, .ctx-text { overflow-wrap: anywhere; white-space: pre-wrap; }
mark { background: var(--mark-bg); color: var(--mark-ink); padding: 0; border-radius: var(--r-sm); }
.ctx { display: grid; gap: var(--s2); border-top: var(--border) solid var(--line); padding-top: var(--s3); }
.ctx-para { display: grid; gap: var(--s1); padding: var(--s2) var(--s3); border-radius: var(--r-md); color: var(--ink-muted); }
.ctx-para.current { background: var(--surface-muted); color: var(--ink); }
.ctx-label { font-size: var(--t-sm); font-weight: var(--weight-medium); color: var(--ink-muted); }

/* ============================================================ 工具 */
.chips { list-style: none; padding: 0; display: flex; flex-wrap: wrap; gap: var(--s2); margin-top: var(--s3); }
.chip { min-height: auto; padding: var(--s1) var(--s3); background: var(--action-soft); border-color: var(--action-soft); color: var(--ink); }
.chip-count { color: var(--action); font-weight: var(--weight-bold); font-variant-numeric: tabular-nums; }
.stop-box { margin-top: var(--s3); display: grid; gap: var(--s2); }
.stop-box summary { cursor: pointer; font-weight: var(--weight-medium); margin-bottom: var(--s2); }
.stop-box label, .stop-box .row { margin-bottom: var(--s2); }
.recent { list-style: none; padding: 0; display: grid; gap: var(--s2); max-height: var(--list-h); overflow-y: auto; }
.recent-item { display: grid; gap: 0; border-bottom: var(--border) solid var(--line); padding-bottom: var(--s2); }
.recent-item .date { font-size: var(--t-sm); color: var(--ink-muted); font-variant-numeric: tabular-nums; }
.footer { margin-top: var(--s8); }

/* ============================================================ 响应式(断点见 TOKENS 注释) */
@media (max-width: 900px) {
  .workspace { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 560px) {
  .app { padding: var(--s4) var(--s4) var(--s10); }
  .search-row { grid-template-columns: minmax(0, 1fr); }
  h1 { font-size: var(--t-xl); }
  .panel { padding: var(--s4); }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
