:root {
  --ink: #1a1a1a;
  --muted: #6b7280;
  --line: #e5e7eb;
  --bg: #f7f7f5;
  --paper: #ffffff;
  --accent: #8a5a2b;
  --material: #1a1a1a;
  --template: #1f5fa8;
  --retrieval: #1f7a4d;
  --placeholder: #c0392b;
  --req: #c0392b;
  --sug: #d69e2e;
  --opt: #5a8fd0;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, "PingFang SC", "Microsoft YaHei", sans-serif;
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

.hidden { display: none !important; }

/* 默认纯对话；分栏只在又宽又高时启用 */
#app { display: grid; grid-template-columns: 1fr; height: 100dvh; }
#doc-pane { display: none; }

#chat-pane { display: flex; flex-direction: column; min-height: 0; background: var(--bg); }

#chat-head {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 14px; padding-top: calc(12px + env(safe-area-inset-top, 0));
  border-bottom: 1px solid var(--line); background: var(--paper);
}
#chat-head .title { font-weight: 600; margin-right: auto; }

#chat-stream {
  flex: 1; overflow-y: auto; overscroll-behavior: contain;
  padding: 16px 14px calc(16px + env(safe-area-inset-bottom, 0));
  display: flex; flex-direction: column; gap: 14px;
}

/* 手机：输入框字号 ≥16px，否则 iOS 聚焦会放大整页；可点区域 ≥44px */
#composer {
  display: flex; flex-direction: column; gap: 8px;
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom, 0));
  border-top: 1px solid var(--line); background: var(--paper);
}
#composer .row { display: flex; align-items: flex-end; gap: 8px; }
#pending { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  display: flex; align-items: center; gap: 6px;
  background: #fdf6ee; border: 1px solid #e8d5bd; border-radius: 999px;
  padding: 6px 10px; font-size: 13px; color: var(--accent); max-width: 100%;
}
.chip span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip button {
  min-height: 0; padding: 0 4px; border: 0; background: transparent;
  color: var(--accent); font-size: 18px; line-height: 1;
}
label.icon.attached { background: #fdf6ee; border-color: #e8d5bd; }
#composer textarea {
  flex: 1; min-height: 44px; max-height: 120px;
  padding: 11px; border: 1px solid var(--line); border-radius: 10px;
  font: inherit; font-size: 16px; resize: none;
}

button {
  font: inherit; font-size: 16px; min-height: 44px;
  padding: 10px 14px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--paper); color: var(--ink);
  cursor: pointer;
}
button.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
button:disabled { opacity: .5; }
.icon { min-width: 44px; padding: 10px 6px; font-size: 20px; line-height: 1; }
.icon.listening { background: var(--placeholder); color: #fff; border-color: var(--placeholder); }

/* 对话消息 */
.msg { display: flex; flex-direction: column; gap: 8px; max-width: 100%; }
.msg.user { align-items: flex-end; }
.bubble {
  padding: 11px 14px; border-radius: 14px; line-height: 1.7; font-size: 15px;
  white-space: pre-wrap; word-break: break-word;
}
.msg.user .bubble { background: var(--accent); color: #fff; border-bottom-right-radius: 4px; max-width: 85%; }
.msg.assistant .bubble { background: var(--paper); border: 1px solid var(--line); border-bottom-left-radius: 4px; }
.attach {
  font-size: 13px; color: var(--muted);
  background: var(--paper); border: 1px dashed var(--line);
  border-radius: 10px; padding: 8px 12px;
}

/* 卡片 */
.card {
  background: var(--paper); border: 1px solid var(--line);
  border-radius: 12px; padding: 14px; font-size: 15px;
}
.card h4 { margin: 0 0 10px; font-size: 14px; color: var(--accent); font-weight: 600; }
.card .hint { color: var(--muted); font-size: 13px; line-height: 1.6; }
.card .actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }

.oline-acts { display: flex; gap: 2px; flex-shrink: 0; }
.oline-acts button { min-height: 0; min-width: 32px; padding: 2px 6px; font-size: 14px; line-height: 1.4; }
.outline-line { display: flex; align-items: center; gap: 6px; padding: 8px 0; border-bottom: 1px dashed var(--line); min-height: 44px; }
.outline-line .num { color: var(--accent); margin-right: 6px; flex-shrink: 0; }
.outline-line [contenteditable] { flex: 1; }
.outline-line [contenteditable] { outline: none; border-bottom: 1px dotted transparent; }
.outline-line [contenteditable]:focus { border-bottom-color: var(--accent); }

.dline { display: flex; align-items: center; gap: 8px; padding: 8px 0; min-height: 44px; font-size: 14px; cursor: pointer; }
.dot { width: 8px; height: 8px; border-radius: 50%; flex: 0 0 8px; }
.dot.required { background: var(--req); }
.dot.suggested { background: var(--sug); }
.dot.optional { background: var(--opt); }
.dline .answered { color: var(--retrieval); margin-left: auto; font-size: 13px; }

.outline-line .warnline { font-size: 12px; color: var(--placeholder); padding-left: 4px; }
.dgroup { font-size: 13px; color: var(--muted); margin: 10px 0 4px; }

.fact {
  display: flex; gap: 8px; padding: 6px 0;
  border-bottom: 1px dashed var(--line); font-size: 14px; line-height: 1.6;
}
.fact .fid { color: var(--accent); flex: 0 0 36px; font-size: 12px; padding-top: 2px; }
.fact .ftag { flex: 0 0 auto; font-size: 11px; color: var(--muted); padding-top: 2px; }
.fact .ftext { flex: 1; }
.fact.internal .ftext { color: var(--muted); }

.just-changed {
  background: #fff6d8; box-shadow: inset 3px 0 0 var(--accent);
  transition: background .4s ease;
}
#scope-bar, #scope-bar-full {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 12px; background: #fdf6ee; border-bottom: 1px solid #e8d5bd;
  font-size: 13px; color: var(--accent);
}
#scope-bar span, #scope-bar-full span { margin-right: auto; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#scope-bar button, #scope-bar-full button { min-height: 0; padding: 0 8px; border: 0; background: transparent; color: var(--accent); font-size: 18px; }

/* 修改框浮在选中的文字上方，不再是底部固定条 */
#sel-bar, #sel-bar-full {
  position: fixed; z-index: 40;
  display: flex; align-items: center; gap: 6px;
  padding: 8px; border: 1px solid var(--accent); border-radius: 10px;
  background: #fdf6ee; box-shadow: 0 6px 20px rgba(0,0,0,.18);
  max-width: min(560px, calc(100vw - 24px));
}
/* 正在编辑的那一段——原生选区在焦点移开时会消失，所以自己标一个 */
p.editing-target {
  background: #fff6d8; box-shadow: inset 3px 0 0 var(--accent); border-radius: 4px;
}
#sel-bar span, #sel-bar-full span {
  font-size: 12px; color: var(--muted); max-width: 30%;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
#sel-bar input, #sel-bar-full input {
  flex: 1; min-height: 40px; padding: 8px 10px; font: inherit; font-size: 16px;
  border: 1px solid var(--line); border-radius: 8px;
}
#sel-bar button, #sel-bar-full button { min-height: 40px; padding: 6px 12px; }

.point { font-size: 15px; line-height: 1.75; padding: 3px 0 3px 14px; position: relative; }
.point { font-size: 15px; line-height: 1.75; padding: 3px 0 3px 14px; position: relative; }
.point::before { content: "·"; position: absolute; left: 2px; color: var(--accent); font-weight: 700; }
.stitle { font-size: 13px; color: var(--accent); margin-bottom: 4px; }
.stext { font-size: 14px; line-height: 1.7; }
.fact.key { border-bottom-style: solid; }
.fact.key .ftext { font-weight: 500; }
.lstmt { font-size: 16px; font-weight: 600; line-height: 1.7; margin-bottom: 8px; }

.cand {
  border: 1px solid var(--line); border-radius: 10px;
  padding: 10px 12px; margin-bottom: 8px;
}
.cand.chosen { border-color: var(--accent); background: #fdf6ee; }
.cand .stmt { font-size: 15px; font-weight: 600; margin-bottom: 4px; line-height: 1.6; }
.cand .why { font-size: 13px; color: var(--muted); line-height: 1.6; }
.cand .warn { color: var(--placeholder); font-size: 12px; margin-top: 4px; }
.cand .preview { margin-top: 8px; font-size: 13px; color: var(--muted); display: none; }
.cand.open .preview { display: block; }

.qcard .qhead { font-size: 14px; color: var(--accent); margin-bottom: 6px; }
.qcard .qtext { font-size: 16px; font-weight: 600; margin-bottom: 8px; }
.qcard input {
  width: 100%; margin-top: 10px; padding: 11px;
  border: 1px solid var(--line); border-radius: 10px; font: inherit; font-size: 16px;
}

/* 文稿 */
#doc-body, #doc-full-body {
  overflow-y: auto; overscroll-behavior: contain;
  padding: 18px 16px 24px; line-height: 1.95; font-size: 15px;
}
#doc-body { flex: 1; }
.insert-btn {
  display: block; width: 100%;
  min-height: 32px; padding: 4px; margin-bottom: 6px;
  font-size: 12px; color: var(--muted);
  background: transparent; border: 1px dashed var(--line);
  opacity: 0; transition: opacity .15s;
}
.doc-section:hover .insert-btn { opacity: 1; }
.doc-section .insert-btn:focus { opacity: 1; }
@media (hover: none) { .insert-btn { opacity: 1; } }

.doc-section { margin-bottom: 22px; cursor: pointer; border-radius: 8px; padding: 6px 8px; min-height: 44px; }
.doc-section.selected { background: #fdf6ee; outline: 1px solid #e8d5bd; }
.sec-heading { font-size: 15px; margin: 0 0 8px; color: var(--accent); }
.doc-section.parent .sec-heading { font-size: 16px; }
.doc-section p { margin: 0 0 10px; text-align: justify; }

.source-on .src-material { color: var(--material); }
.source-on .src-template { color: var(--template); }
.source-on .src-retrieval { color: var(--retrieval); }
.source-on .src-placeholder { color: var(--placeholder); background: #fdecea; border-radius: 3px; padding: 0 3px; }
.src-ref { font-size: 11px; color: var(--muted); margin-left: 4px; }
#doc-body:not(.source-on) .src-ref,
#doc-full-body:not(.source-on) .src-ref { display: none; }

.pane-head {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 10px 14px; border-bottom: 1px solid var(--line); background: var(--paper);
}
#doc-title, #doc-full-title { font-weight: 600; margin-right: auto; }
.toggle { font-size: 13px; color: var(--muted); margin: 0; display: flex; align-items: center; gap: 4px; }

/* 全屏文稿（窄屏用） */
#doc-full {
  position: fixed; inset: 0; background: var(--paper);
  display: flex; flex-direction: column; z-index: 20;
}
#doc-full .pane-head { padding-top: calc(10px + env(safe-area-inset-top, 0)); }
#doc-full-body { flex: 1; }
#revise-bar {
  display: flex; gap: 8px;
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom, 0));
  border-top: 1px solid var(--line); background: var(--paper);
}
#revise-bar textarea {
  flex: 1; min-height: 44px; padding: 11px;
  border: 1px solid var(--line); border-radius: 10px; font: inherit; font-size: 16px; resize: none;
}

/* 又宽又高：左对话、右文稿 */
@media (min-width: 840px) and (min-height: 600px) {
  #app.split { grid-template-columns: 45% 55%; }
  #app.split #doc-pane {
    display: flex; flex-direction: column; min-height: 0;
    border-left: 1px solid var(--line); background: var(--paper);
  }
  #app.split #chat-stream { padding-bottom: 16px; }
  #app.split #composer { padding-bottom: 10px; }
  #app.split #doc-body { padding-bottom: 24px; }
}
