/* ============================================================
   讀伴・樹狀閱讀 — 樣式
   視覺語彙：宣紙（偏青的紙灰）、墨青（主幹）、硃砂（硃批/分支）
   ============================================================ */

:root {
  --bg:        #EDEFE9;   /* 宣紙青灰 */
  --paper:     #FCFCFA;   /* 紙面 */
  --paper-2:   #F6F6F1;
  --ink:       #24313B;   /* 墨青 */
  --ink-soft:  #64737D;
  --ink-faint: #9AA6AD;
  --line:      #DBDED3;
  --vermilion: #A63A2B;   /* 硃砂 */
  --verm-wash: #F5E6E1;
  --verm-line: #DCB9B0;
  --jade-wash: #E9F0EC;
  --sand-wash: #F1EEE2;
  --shadow: 0 2px 10px rgba(36,49,59,.07);
  --radius: 12px;
  --serif: "Noto Serif TC", "Songti TC", serif;
  --sans:  "Noto Sans TC", "PingFang TC", sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: var(--sans);
  background: var(--bg);
  color: var(--ink);
  font-size: 15px;
  line-height: 1.7;
}
button { font-family: inherit; cursor: pointer; }
::selection { background: rgba(166,58,43,.22); }

/* ---------- 頂欄 ---------- */
.topbar {
  height: 60px;
  display: flex; align-items: center; gap: 18px;
  padding: 0 18px;
  background: var(--paper);
  border-bottom: 1px solid var(--line);
  position: relative; z-index: 20;
}
.brand { display: flex; align-items: center; gap: 10px; user-select: none; }
.seal {
  width: 38px; height: 38px;
  background: var(--vermilion);
  color: #fff;
  font-family: var(--serif);
  font-size: 13px; font-weight: 700; line-height: 1.15;
  display: flex; align-items: center; justify-content: center;
  text-align: center;
  border-radius: 6px;
  transform: rotate(-3deg);
  box-shadow: inset 0 0 0 2px rgba(255,255,255,.35), 0 1px 3px rgba(166,58,43,.35);
  letter-spacing: 1px;
}
.brand h1 {
  font-family: var(--serif);
  font-size: 19px; font-weight: 700; letter-spacing: 3px;
}
.brand h1 em {
  font-style: normal; font-size: 12px; font-weight: 400;
  color: var(--ink-soft); letter-spacing: 4px; margin-left: 8px;
}
.doc-meta {
  flex: 1; min-width: 0;
  display: flex; align-items: baseline; gap: 10px;
  font-family: var(--serif);
}
.doc-meta .doc-title {
  font-size: 15px; font-weight: 600;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.topbar .actions { display: flex; gap: 8px; }

.btn {
  border: 1px solid var(--line);
  background: var(--paper);
  color: var(--ink);
  border-radius: 8px;
  padding: 6px 13px;
  font-size: 13px;
  transition: all .15s;
}
.btn:hover { border-color: var(--ink-soft); background: var(--paper-2); }
.btn.primary { background: var(--ink); border-color: var(--ink); color: #fff; }
.btn.primary:hover { background: #33434f; }
.btn.verm { background: var(--vermilion); border-color: var(--vermilion); color: #fff; }
.btn.verm:hover { background: #8f2f22; }
.btn.ghost { border-color: transparent; background: transparent; color: var(--ink-soft); }
.btn.ghost:hover { color: var(--ink); background: var(--paper-2); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.small { padding: 3px 9px; font-size: 12px; border-radius: 6px; }

/* ---------- 三欄工作區 ---------- */
.workspace {
  height: calc(100vh - 60px);
  display: grid;
  grid-template-columns: minmax(320px, 5fr) minmax(340px, 5fr) minmax(250px, 3fr);
  gap: 12px;
  padding: 12px;
}
.panel {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  display: flex; flex-direction: column;
  min-height: 0; overflow: hidden;
}
.panel-head {
  padding: 10px 16px;
  border-bottom: 1px solid var(--line);
  display: flex; align-items: center; gap: 8px;
  flex-shrink: 0;
}
.panel-head .eyebrow {
  font-size: 11px; letter-spacing: 3px; color: var(--ink-faint);
  text-transform: uppercase;
}
.panel-head .name { font-family: var(--serif); font-weight: 600; font-size: 14px; }
.panel-head .spacer { flex: 1; }

/* ---------- 讀本 ---------- */
.reader-body {
  flex: 1; overflow-y: auto;
  padding: 26px 30px 60px;
}
.reader-title {
  font-family: var(--serif);
  font-size: 22px; font-weight: 700; letter-spacing: 2px;
  margin-bottom: 4px;
}
.reader-sub { font-size: 12px; color: var(--ink-faint); margin-bottom: 22px; }
.reader-body p.rp {
  font-family: var(--serif);
  font-size: 16.5px; line-height: 2.05;
  text-indent: 2em;
  margin-bottom: 14px;
  color: #2b3944;
}
.reader-body p.rp::before {
  content: attr(data-no);
  float: left; margin-left: -2em;
  font-family: var(--sans);
  font-size: 10px; color: var(--ink-faint);
  transform: translateY(9px);
  text-indent: 0;
}
.reader-hint {
  margin-top: 26px; padding: 10px 14px;
  background: var(--sand-wash);
  border-radius: 8px;
  font-size: 12.5px; color: var(--ink-soft);
}

/* ---------- 對話 ---------- */
.crumbs {
  display: flex; align-items: center; gap: 6px;
  flex-wrap: wrap; min-width: 0;
  font-size: 13px;
}
.crumb {
  border: none; background: none; padding: 2px 4px;
  color: var(--ink-soft); border-radius: 5px;
  max-width: 150px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.crumb:hover { background: var(--paper-2); color: var(--ink); }
.crumb.current { color: var(--ink); font-weight: 600; }
.crumb.branch.current { color: var(--vermilion); }
.crumb-sep { color: var(--ink-faint); }

.branch-banner {
  flex-shrink: 0;
  padding: 9px 16px;
  background: var(--verm-wash);
  border-bottom: 1px solid var(--verm-line);
  display: flex; align-items: center; gap: 10px;
  font-size: 12.5px; color: #7c2c20;
}
.branch-banner .quote {
  flex: 1; min-width: 0;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  font-family: var(--serif);
}
.branch-banner.hidden { display: none; }

.chat-body {
  flex: 1; overflow-y: auto;
  padding: 18px 16px 20px;
  display: flex; flex-direction: column; gap: 14px;
  scroll-behavior: smooth;
}
.msg { display: flex; gap: 9px; max-width: 86%; }
.msg.ai { align-self: flex-start; }
.msg.user { align-self: flex-end; flex-direction: row-reverse; }
.avatar {
  width: 30px; height: 30px; flex-shrink: 0;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-family: var(--serif); font-weight: 700;
  margin-top: 2px;
}
.msg.user .avatar { background: var(--ink); color: #fff; }
.msg.ai .avatar { background: var(--verm-wash); color: var(--vermilion); border: 1px solid var(--verm-line); }
.bubble-wrap { min-width: 0; display: flex; flex-direction: column; }
.msg.user .bubble-wrap { align-items: flex-end; }
.bubble {
  background: var(--paper-2);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 13px;
  font-size: 14.5px;
  white-space: pre-wrap;
  word-break: break-word;
  width: fit-content;
  max-width: 100%;
}
.msg.ai .bubble { background: #FDF9F7; border-color: var(--verm-line); border-top-left-radius: 4px; }
.msg.user .bubble {
  background: var(--ink);
  border-color: var(--ink);
  color: #F2F3EF;
  border-top-right-radius: 4px;
}
.msg.user .bubble .quoteblock {
  background: rgba(255,255,255,.1);
  border-left-color: var(--verm-line);
  color: #EBD9D3;
}
.msg.user .bubble .quoteblock .q-label { color: #C9AFA8; }
.bubble strong { font-weight: 700; color: inherit; }
.bubble em { font-style: normal; border-bottom: 1px solid var(--verm-line); }
.bubble code {
  font-family: ui-monospace, "Courier New", monospace;
  font-size: 13px;
  background: var(--sand-wash);
  border-radius: 4px;
  padding: 1px 5px;
}
.bubble .quoteblock {
  border-left: 3px solid var(--vermilion);
  background: var(--verm-wash);
  padding: 6px 10px;
  margin-bottom: 8px;
  border-radius: 0 6px 6px 0;
  font-family: var(--serif);
  font-size: 13.5px; color: #6d2a1f;
}
.bubble .quoteblock .q-label { font-size: 10.5px; color: #a3695e; font-family: var(--sans); display: block; }
.msg-actions {
  display: flex; gap: 6px; margin-top: 4px;
  opacity: 0; transition: opacity .15s;
}
.msg.user .msg-actions { justify-content: flex-end; }
.msg:hover .msg-actions { opacity: 1; }
.msg-actions button {
  border: none; background: none;
  font-size: 11.5px; color: var(--ink-faint);
  padding: 1px 4px; border-radius: 4px;
}
.msg-actions button:hover { color: var(--vermilion); background: var(--verm-wash); }

/* 分支收束卡片 */
.merge-card {
  border: 1px dashed var(--verm-line);
  background: var(--verm-wash);
  border-radius: 10px;
  padding: 10px 14px;
  font-size: 13.5px;
  color: #6d2a1f;
}
.merge-card .m-head {
  display: flex; align-items: center; gap: 6px;
  font-size: 11.5px; color: var(--vermilion);
  margin-bottom: 4px; font-weight: 600;
}
.merge-card .m-link {
  border: none; background: none; color: var(--vermilion);
  text-decoration: underline; font-size: 11.5px; padding: 0;
}

/* 打字中 */
.typing { display: inline-flex; gap: 4px; padding: 4px 2px; }
.typing i {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--verm-line);
  animation: blink 1.2s infinite;
}
.typing i:nth-child(2) { animation-delay: .2s; }
.typing i:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%,80%,100%{opacity:.25} 40%{opacity:1} }

/* 輸入區 */
.composer {
  flex-shrink: 0;
  border-top: 1px solid var(--line);
  padding: 10px 12px 12px;
  background: var(--paper);
}
.composer .pending-quote {
  display: flex; align-items: center; gap: 8px;
  background: var(--verm-wash);
  border: 1px solid var(--verm-line);
  border-radius: 8px;
  padding: 5px 10px; margin-bottom: 8px;
  font-size: 12.5px; color: #6d2a1f;
  font-family: var(--serif);
}
.composer .pending-quote span { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.composer .pending-quote button { border: none; background: none; color: var(--vermilion); font-size: 14px; }
.composer-row { display: flex; gap: 8px; align-items: flex-end; }
.composer textarea {
  flex: 1;
  resize: none;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--paper-2);
  padding: 9px 12px;
  font-family: inherit; font-size: 14px;
  line-height: 1.6;
  max-height: 140px;
  outline: none;
}
.composer textarea:focus { border-color: var(--ink-soft); background: #fff; }
.composer .hint {
  font-size: 11px; color: var(--ink-faint);
  margin-top: 6px;
}

/* ---------- 樹狀圖 & 筆記 ---------- */
.side-panel { display: flex; flex-direction: column; gap: 0; min-height: 0; background: none; border: none; box-shadow: none; overflow: visible; }
.side-panel > .panel { flex: 1 1 55%; min-height: 0; }
.side-panel > .panel.notes-panel { flex: 1 1 45%; }

.tree-scroll { flex: 1; overflow: auto; padding: 12px 10px; }
#treeSvg { display: block; }
.tree-node { cursor: pointer; }
.tree-node rect {
  fill: var(--paper-2);
  stroke: var(--line); stroke-width: 1.2;
  rx: 9;
  transition: all .15s;
}
.tree-node.branch rect { stroke: var(--verm-line); fill: #FDF8F6; }
.tree-node.current rect { fill: var(--ink); stroke: var(--ink); }
.tree-node.branch.current rect { fill: var(--vermilion); stroke: var(--vermilion); }
.tree-node text { font-size: 12px; fill: var(--ink); font-family: var(--sans); }
.tree-node .t-label { font-family: var(--serif); font-weight: 600; }
.tree-node.current text { fill: #fff; }
.tree-node .t-status { font-size: 9.5px; fill: var(--ink-faint); }
.tree-node.current .t-status { fill: rgba(255,255,255,.75); }
.tree-edge { fill: none; stroke: var(--ink-faint); stroke-width: 1.6; }
.tree-edge.branch { stroke: var(--verm-line); stroke-width: 1.6; stroke-dasharray: none; }
.tree-edge.merged { stroke-dasharray: 4 4; }
.tree-legend {
  padding: 6px 14px 10px;
  font-size: 11px; color: var(--ink-faint);
  display: flex; gap: 12px; flex-shrink: 0;
}
.tree-legend i { display: inline-block; width: 9px; height: 9px; border-radius: 3px; margin-right: 4px; vertical-align: -1px; }
.tree-legend .li-trunk i { background: var(--ink); }
.tree-legend .li-branch i { background: var(--vermilion); }

.notes-area {
  flex: 1; overflow-y: auto;
  padding: 14px;
  display: flex; flex-wrap: wrap; gap: 10px;
  align-content: flex-start;
}
.note-bubble {
  cursor: pointer;
  border: none;
  border-radius: 18px;
  padding: 8px 14px;
  font-size: 12.5px;
  font-family: var(--serif);
  color: var(--ink);
  max-width: 100%;
  text-align: left;
  box-shadow: 0 1px 4px rgba(36,49,59,.08);
  animation: floaty 5s ease-in-out infinite;
  line-height: 1.55;
}
.note-bubble.c0 { background: var(--jade-wash); }
.note-bubble.c1 { background: var(--verm-wash); }
.note-bubble.c2 { background: var(--sand-wash); }
.note-bubble:nth-child(2n) { animation-delay: -2.2s; }
.note-bubble:nth-child(3n) { animation-delay: -3.6s; }
@keyframes floaty {
  0%,100% { transform: translateY(0); }
  50%     { transform: translateY(-4px); }
}
@media (prefers-reduced-motion: reduce) {
  .note-bubble { animation: none; }
}
.note-bubble .n-full { display: none; }
.note-bubble.open { border-radius: 12px; width: 100%; animation: none; }
.note-bubble.open .n-short { display: none; }
.note-bubble.open .n-full { display: block; white-space: pre-wrap; }
.note-bubble .n-tools { display: none; gap: 8px; margin-top: 6px; }
.note-bubble.open .n-tools { display: flex; }
.note-bubble .n-tools button {
  border: none; background: none; font-size: 11px;
  color: var(--vermilion); padding: 0;
}
.notes-empty { font-size: 12px; color: var(--ink-faint); padding: 6px 2px; }

/* ---------- 閱讀前導讀 ---------- */
.panel#panelChat.briefing-mode .chat-body,
.panel#panelChat.briefing-mode .composer,
.panel#panelChat.briefing-mode .branch-banner { display: none !important; }
.briefing { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.briefing-scroll { flex: 1; overflow-y: auto; padding: 22px 24px; }
.brief-greet {
  font-family: var(--serif);
  font-size: 14.5px; line-height: 1.95;
  color: #2b3944;
  margin-bottom: 20px;
}
.brief-label {
  font-family: var(--serif);
  font-size: 14px; font-weight: 600;
  margin: 16px 0 8px;
}
.brief-box {
  background: #FBF2D8;               /* 淡金便箋 */
  border: 1px solid #E8D394;
  border-radius: 12px;
  padding: 13px 16px;
  font-size: 13.5px; line-height: 1.85;
  font-family: var(--serif);
  color: #4a4230;
  min-height: 52px;
}
.brief-loading { color: #A99B72; font-size: 12.5px; font-family: var(--sans); }
.brief-error { color: var(--vermilion); font-size: 12.5px; font-family: var(--sans); }
.brief-map {
  background: var(--paper-2);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px;
  overflow: auto;
  max-height: 340px;
}
.brief-map svg { display: block; margin: 0 auto; }
.mm-center rect { fill: var(--ink); rx: 10; }
.mm-center text { fill: #fff; font-family: var(--serif); font-weight: 700; font-size: 16px; }
.mm-branch rect { rx: 8; }
.mm-branch text { fill: #fff; font-size: 13px; font-family: var(--sans); font-weight: 600; }
.mm-leaf { font-size: 12.5px; fill: var(--ink); font-family: var(--sans); }
.mm-edge { fill: none; stroke-width: 1.6; opacity: .55; }
.brief-foot {
  flex-shrink: 0;
  border-top: 1px solid var(--line);
  padding: 10px 16px;
  display: flex; align-items: center; gap: 10px;
  background: var(--paper);
}
.brief-foot .spacer { flex: 1; }

/* ---------- 人格切換 ---------- */
.persona-row {
  display: flex; align-items: center; gap: 8px;
  margin-bottom: 8px;
}
.persona-label { font-size: 11px; color: var(--ink-faint); letter-spacing: 1px; }
.persona-pills { display: flex; gap: 4px; background: var(--paper-2); border: 1px solid var(--line); border-radius: 8px; padding: 2px; }
.persona-pills button {
  border: none; background: none;
  font-size: 12px; color: var(--ink-soft);
  padding: 3px 11px; border-radius: 6px;
  transition: all .15s;
}
.persona-pills button.on { background: var(--ink); color: #fff; }
.persona-pills button[data-p=critic].on { background: var(--vermilion); }
.persona-pills button[data-p=explorer].on { background: #4A6B5D; }

.send-col { display: flex; flex-direction: column; gap: 5px; align-items: stretch; }

/* ---------- 選項式快速回覆 ---------- */
.quick-opts { display: flex; flex-direction: column; gap: 6px; margin-top: 8px; align-items: flex-start; }
.quick-opts button {
  border: 1px solid var(--verm-line);
  background: var(--paper);
  color: var(--ink);
  border-radius: 10px;
  padding: 7px 13px;
  font-size: 13.5px;
  text-align: left;
  transition: all .15s;
  font-family: var(--serif);
}
.quick-opts button:hover { background: var(--verm-wash); border-color: var(--vermilion); }
.quick-opts button .opt-no { color: var(--vermilion); font-weight: 700; margin-right: 6px; font-family: var(--sans); font-size: 12px; }

/* ---------- 讀本收合與字級 ---------- */
.reader-strip { display: none; }
.workspace.reader-collapsed {
  grid-template-columns: 46px minmax(340px, 7fr) minmax(250px, 3fr);
}
.workspace.reader-collapsed #panelReader .panel-head,
.workspace.reader-collapsed #panelReader .reader-body { display: none; }
.workspace.reader-collapsed #panelReader .reader-strip {
  display: flex; align-items: center; justify-content: center;
  flex: 1;
  border: none; background: var(--paper);
  writing-mode: vertical-rl;
  letter-spacing: 6px;
  font-family: var(--serif); font-size: 13px; font-weight: 600;
  color: var(--ink-soft);
}
.workspace.reader-collapsed #panelReader .reader-strip:hover { color: var(--vermilion); background: var(--paper-2); }
.reader-body { font-size: var(--reader-size, 16.5px); }
.reader-body p.rp { font-size: 1em; }

/* ---------- 螢光筆 ---------- */
.reader-body mark {
  background: linear-gradient(transparent 12%, #F3E19A 12%, #F3E19A 92%, transparent 92%);
  color: inherit;
  cursor: pointer;
  border-radius: 2px;
}
.reader-body mark:hover { background: linear-gradient(transparent 8%, #EDCF6B 8%, #EDCF6B 94%, transparent 94%); }

/* ---------- 右鍵選單 ---------- */
.ctx-menu {
  position: fixed; z-index: 70;
  display: none;
  min-width: 190px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: 0 8px 28px rgba(20,30,38,.22);
  padding: 5px;
  flex-direction: column;
}
.ctx-menu.show { display: flex; }
.ctx-menu button {
  border: none; background: none;
  text-align: left;
  font-size: 13px; color: var(--ink);
  padding: 7px 11px; border-radius: 7px;
}
.ctx-menu button:hover { background: var(--paper-2); }
.ctx-menu button.danger { color: var(--vermilion); }
.ctx-menu button.danger:hover { background: var(--verm-wash); }
.ctx-menu button:disabled { color: var(--ink-faint); cursor: not-allowed; background: none; }
.ctx-menu .ctx-title {
  font-size: 11px; color: var(--ink-faint);
  padding: 5px 11px 3px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 3px;
  font-family: var(--serif);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  max-width: 230px;
}

/* 樹節點拖曳中 */
.tree-node.dragging rect { opacity: .5; stroke-dasharray: 5 4; }
.tree-node.drop-target rect { stroke: var(--vermilion); stroke-width: 2.4; }

/* ---------- 選取浮動工具列 ---------- */
.sel-toolbar {
  position: fixed; z-index: 60;
  display: none;
  background: var(--ink);
  border-radius: 9px;
  padding: 5px;
  gap: 2px;
  box-shadow: 0 4px 16px rgba(20,30,38,.3);
}
.sel-toolbar.show { display: flex; }
.sel-toolbar button {
  border: none; background: none;
  color: #ECEFE9; font-size: 12.5px;
  padding: 5px 10px; border-radius: 6px;
  white-space: nowrap;
}
.sel-toolbar button:hover { background: rgba(255,255,255,.12); }
.sel-toolbar button.verm-act { color: #F3B9AC; }

/* ---------- 遮罩層（上傳/彈窗） ---------- */
.overlay {
  position: fixed; inset: 0; z-index: 80;
  background: rgba(36,49,59,.35);
  backdrop-filter: blur(3px);
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
}
.overlay.hidden { display: none; }
.sheet {
  background: var(--paper);
  border-radius: 16px;
  width: min(660px, 100%);
  max-height: 88vh;
  overflow-y: auto;
  padding: 30px 34px;
  box-shadow: 0 12px 40px rgba(20,30,38,.25);
}
.sheet h2 {
  font-family: var(--serif); font-size: 20px; letter-spacing: 2px;
  margin-bottom: 4px;
}
.sheet .sub { font-size: 13px; color: var(--ink-soft); margin-bottom: 20px; }
.sheet label.f-label { display: block; font-size: 12.5px; color: var(--ink-soft); margin: 14px 0 5px; }
.sheet input[type=text], .sheet textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--paper-2);
  padding: 9px 12px;
  font-family: var(--serif); font-size: 14.5px;
  outline: none;
}
.sheet textarea { min-height: 200px; resize: vertical; line-height: 1.9; }
.sheet input:focus, .sheet textarea:focus { border-color: var(--ink-soft); background: #fff; }
.sheet .row { display: flex; gap: 10px; margin-top: 20px; align-items: center; }
.sheet .row .spacer { flex: 1; }
.saved-docs { margin-top: 10px; display: flex; flex-direction: column; gap: 6px; }
.saved-doc {
  display: flex; align-items: center; gap: 10px;
  border: 1px solid var(--line); border-radius: 9px;
  padding: 8px 12px; background: var(--paper-2);
  font-size: 13.5px;
}
.saved-doc .sd-title { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-family: var(--serif); font-weight: 600; border: none; background: none; text-align: left; cursor: pointer; font-size: 13.5px; }
.saved-doc .sd-title:hover { color: var(--vermilion); }
.saved-doc .sd-del { border: none; background: none; color: var(--ink-faint); font-size: 13px; }
.saved-doc .sd-del:hover { color: var(--vermilion); }

.check-row { display: flex; align-items: center; gap: 8px; font-size: 14px; margin: 8px 0; }
.check-row input { width: 15px; height: 15px; accent-color: var(--vermilion); }

.summary-body {
  font-size: 14px; white-space: pre-wrap;
  background: var(--paper-2); border: 1px solid var(--line);
  border-radius: 10px; padding: 14px 16px;
  max-height: 50vh; overflow-y: auto;
  font-family: var(--serif); line-height: 1.9;
}

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%) translateY(20px);
  background: var(--ink); color: #fff;
  padding: 9px 18px; border-radius: 9px;
  font-size: 13px; opacity: 0; pointer-events: none;
  transition: all .25s; z-index: 100;
  box-shadow: 0 6px 20px rgba(20,30,38,.3);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.err { background: var(--vermilion); }

/* ---------- 行動裝置 ---------- */
.mobile-tabs { display: none; }
@media (max-width: 980px) {
  .workspace {
    grid-template-columns: 1fr !important;   /* 覆蓋讀本收合的欄寬設定 */
    grid-template-rows: 1fr;
    padding: 8px;
  }
  /* 只隱藏工作區的「直屬」面板；側欄內部的對話樹/筆記葉面板不受影響 */
  .workspace > .panel, .workspace > .side-panel { display: none; }
  .workspace[data-view="reader"] > #panelReader { display: flex; }
  .workspace[data-view="chat"]   > #panelChat   { display: flex; }
  .workspace[data-view="tree"]   > #panelSide   { display: flex; }
  .workspace.reader-collapsed #panelReader .reader-strip { display: none; }
  .workspace.reader-collapsed[data-view="reader"] #panelReader .panel-head,
  .workspace.reader-collapsed[data-view="reader"] #panelReader .reader-body { display: block; }
  .workspace.reader-collapsed[data-view="reader"] #panelReader .panel-head { display: flex; }
  .mobile-tabs {
    display: flex; gap: 4px;
  }
  .mobile-tabs button {
    border: 1px solid var(--line); background: var(--paper);
    border-radius: 7px; padding: 5px 10px; font-size: 12.5px; color: var(--ink-soft);
  }
  .mobile-tabs button.on { background: var(--ink); color: #fff; border-color: var(--ink); }
  .brand h1 em { display: none; }
  .topbar .actions .btn.hide-m { display: none; }
  .doc-meta { display: none; }
}

/* 捲軸 */
::-webkit-scrollbar { width: 9px; height: 9px; }
::-webkit-scrollbar-thumb { background: #C9CDC0; border-radius: 5px; border: 2px solid var(--paper); }
::-webkit-scrollbar-track { background: transparent; }

/* ---------- 關於讀伴（導讀時蓋掉右側） ---------- */
.about-panel { display: none; }
.side-panel.about-mode > .panel:not(.about-panel) { display: none; }
.side-panel.about-mode > .about-panel { display: flex; flex: 1; }
.about-body {
  flex: 1; overflow-y: auto;
  padding: 18px 20px 24px;
  font-family: var(--serif);
  font-size: 13.5px; line-height: 2.05;
  color: #2b3944;
}
.about-body p { margin-bottom: 14px; text-indent: 2em; }
@media (max-width: 980px) {
  .workspace[data-view="tree"] #panelSide.about-mode { display: flex; }
}

/* ---------- 側欄拉桿（樹狀圖/筆記 比例調整） ---------- */
.v-splitter {
  flex: 0 0 16px;
  display: flex; align-items: center; justify-content: center;
  cursor: row-resize;
  user-select: none;
  touch-action: none;
  color: var(--ink-faint);
  font-size: 13px;
  border-radius: 6px;
  transition: background .15s, color .15s;
}
.v-splitter span { line-height: 1; pointer-events: none; }
.v-splitter:hover, .v-splitter.dragging { background: var(--verm-wash); color: var(--vermilion); }
.side-panel.about-mode > .v-splitter { display: none; }

/* ---------- 心智圖放大 ---------- */
#briefMapWrap { cursor: zoom-in; }
#briefMapWrap:hover { border-color: var(--ink-soft); }
.map-sheet {
  width: auto;
  min-width: min(560px, 92vw);
  max-width: calc(100vw - 48px);
}
.map-zoom {
  overflow: auto;
  background: var(--paper-2);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px;
  max-height: 72vh;
  max-width: 100%;
}
.map-zoom svg { display: block; margin: 0 auto; }

/* 手機版仍可從頂欄重看導讀 */
@media (max-width: 980px) {
  .topbar .actions #btnBriefing { display: inline-block; padding: 4px 9px; font-size: 12px; }
}

/* ---------- 筆記來源標籤 ---------- */
.note-bubble .n-src {
  display: block;
  margin-top: 6px;
  font-size: 10.5px;
  color: var(--ink-faint);
  font-family: var(--sans);
}
.note-bubble .n-src::before { content: '⌖ '; }

/* ---------- 空分支起點提示 ---------- */
.branch-empty-hint {
  align-self: center;
  max-width: 88%;
  text-align: center;
  background: var(--sand-wash);
  border: 1px dashed var(--line);
  border-radius: 12px;
  padding: 14px 18px;
  font-size: 13px;
  line-height: 1.9;
  color: var(--ink-soft);
  font-family: var(--serif);
  margin-top: 8px;
}
.branch-empty-hint .beh-q { color: var(--vermilion); }

/* ---------- 測試版標籤 ---------- */
.beta-tag {
  display: inline-block;
  font-size: 10.5px;
  color: var(--vermilion);
  border: 1px solid var(--verm-line);
  background: var(--verm-wash);
  border-radius: 20px;
  padding: 1px 8px;
  margin-left: 8px;
  letter-spacing: 1px;
  vertical-align: middle;
  font-family: var(--sans);
  font-weight: 500;
}

/* ---------- 首頁 hero ---------- */
.up-hero { text-align: center; padding: 4px 0 6px; }
.seal-lg {
  width: 56px; height: 56px;
  font-size: 19px;
  margin: 0 auto 12px;
  display: flex;
}
.up-hero h2 { font-size: 22px; letter-spacing: 3px; margin-bottom: 12px; }
.up-intro {
  font-family: var(--serif);
  font-size: 14px; line-height: 2;
  color: #2b3944;
  max-width: 30em;
  margin: 0 auto 4px;
  text-align: left;
}
.up-intro-cta {
  font-family: var(--serif);
  font-size: 14px; color: var(--vermilion);
  margin-bottom: 6px;
}
.up-cta { justify-content: center; margin-top: 14px !important; }
.up-big { padding: 10px 20px; font-size: 14.5px; }
.up-status { text-align: center; min-height: 18px; margin-top: 6px; }
.up-status span { font-size: 12px; color: var(--ink-soft); }

/* ---------- 閱讀門檻提示 ---------- */
.brief-gate-hint {
  font-size: 12px;
  color: var(--vermilion);
  font-family: var(--serif);
}

/* ---------- 樹狀圖右鍵提示 ---------- */
.tree-legend .li-hint { color: var(--ink-faint); }

/* ---------- 讀本上方操作導引 ---------- */
.reader-guide {
  background: var(--sand-wash);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 7px 12px;
  font-size: 11.5px;
  color: var(--ink-soft);
  margin-bottom: 16px;
  line-height: 1.8;
}

/* ---------- 觸控裝置：選取操作列固定於底部（避開系統選單） ---------- */
.sel-toolbar.docked {
  left: 10px !important;
  right: 10px;
  top: auto !important;
  bottom: calc(12px + env(safe-area-inset-bottom, 0px));
  justify-content: space-around;
  padding: 7px 6px;
  border-radius: 14px;
  box-shadow: 0 8px 30px rgba(20,30,38,.45);
  animation: dockUp .18s ease-out;
}
.sel-toolbar.docked button {
  flex: 1;
  text-align: center;
  font-size: 13.5px;
  padding: 9px 6px;
}
@keyframes dockUp {
  from { transform: translateY(14px); opacity: 0; }
  to   { transform: translateY(0);    opacity: 1; }
}

/* ---------- 簡要查詢浮動視窗 ---------- */
.lookup-panel {
  position: fixed;
  right: 16px;
  bottom: 16px;
  width: min(360px, calc(100vw - 24px));
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: 0 12px 40px rgba(20,30,38,.25);
  z-index: 75;
  display: none;
  flex-direction: column;
  overflow: hidden;
}
.lookup-panel.open { display: flex; animation: dockUp .18s ease-out; }
.lk-head {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 14px;
  background: var(--ink);
  color: #F2F3EF;
}
.lk-title { font-family: var(--serif); font-size: 14px; font-weight: 600; letter-spacing: 1px; }
.lk-head .spacer { flex: 1; }
.lk-close { border: none; background: none; color: #C9CDC0; font-size: 14px; cursor: pointer; padding: 2px 4px; }
.lk-close:hover { color: #fff; }
.lk-note {
  padding: 8px 14px;
  background: var(--sand-wash);
  border-bottom: 1px solid var(--line);
  font-size: 11.5px; color: var(--ink-soft);
  line-height: 1.7;
}
.lk-body { max-height: 40vh; overflow-y: auto; }
.lk-answer {
  padding: 12px 14px 4px;
  font-size: 13.5px; line-height: 1.9;
  font-family: var(--serif);
  white-space: pre-wrap;
  word-break: break-word;
}
.lk-tools { display: flex; gap: 8px; padding: 8px 14px 12px; }
.lk-input-row {
  display: flex; gap: 8px;
  padding: 10px 12px;
  border-top: 1px solid var(--line);
  background: var(--paper);
}
.lk-input-row input {
  flex: 1;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--paper-2);
  padding: 8px 11px;
  font-family: inherit; font-size: 13.5px;
  outline: none;
}
.lk-input-row input:focus { border-color: var(--ink-soft); background: #fff; }
@media (max-width: 980px) {
  .lookup-panel { right: 8px; bottom: 8px; left: 8px; width: auto; }
}

/* ---------- 麵包屑改名快捷 ---------- */
.crumb-rename {
  border: none; background: none;
  color: var(--ink-faint);
  font-size: 12px;
  padding: 2px 5px;
  border-radius: 5px;
  cursor: pointer;
  line-height: 1;
}
.crumb-rename:hover { color: var(--vermilion); background: var(--verm-wash); }

/* 查詢鈕與送出鈕同欄 */
.send-col #btnLookup { white-space: nowrap; font-size: 12px; padding: 4px 8px; }


/* ---------- 訊息:頭像欄、編號、by 人格 ---------- */
.avatar-col { display: flex; flex-direction: column; align-items: center; gap: 2px; flex-shrink: 0; }
.msg-seq {
  font-size: 10.5px;
  color: var(--ink-faint);
  font-variant-numeric: tabular-nums;
  line-height: 1;
}
.msg-actions .ma-spacer { flex: 1; }
.by-persona {
  font-size: 10.5px;
  letter-spacing: .5px;
  white-space: nowrap;
  opacity: .85;
}
.by-persona.p-guide    { color: #56707f; }
.by-persona.p-critic   { color: var(--vermilion); }
.by-persona.p-explorer { color: #3d6657; }
.msg.ai .msg-actions { opacity: 1; }
.msg.ai .msg-actions button { opacity: 0; transition: opacity .15s; }
.msg.ai:hover .msg-actions button { opacity: 1; }

/* ---------- 首頁暱稱 ---------- */
.nick-input {
  width: 100%;
  border: 1px solid var(--verm-line) !important;
  border-radius: 10px;
  background: #FDF9F7 !important;
  padding: 10px 14px !important;
  font-family: var(--serif) !important;
  font-size: 14px !important;
  margin-top: 16px;
  text-align: center;
}
.nick-input:focus { border-color: var(--vermilion) !important; background: #fff !important; }

/* ---------- composer 緊湊排版 ---------- */
.persona-row { margin-bottom: 6px; }
.persona-row .spacer { flex: 1; }
.persona-row #btnLookup { padding: 3px 10px; font-size: 12px; }
.composer-row { align-items: stretch; }
.composer-row #btnSend { padding: 6px 18px; align-self: stretch; }
.composer { padding: 8px 12px 10px; }

/* ---------- 筆記標題 ---------- */
.n-title {
  font-weight: 700;
  font-size: 13px;
  margin-bottom: 3px;
  color: var(--ink);
}

/* ---------- 底部單位 banner ---------- */
.site-banner {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  background: rgba(252,252,250,.97);
  border-top: 1px solid var(--line);
  z-index: 40;
  transition: transform .22s ease;
  backdrop-filter: blur(4px);
}
.site-banner.collapsed { transform: translateY(100%); }
.sb-toggle {
  position: absolute;
  right: 14px; top: -22px;
  width: 30px; height: 22px;
  border: 1px solid var(--line);
  border-bottom: none;
  border-radius: 7px 7px 0 0;
  background: rgba(252,252,250,.97);
  color: var(--ink-soft);
  font-size: 11px;
  line-height: 1;
  cursor: pointer;
  transition: transform .22s ease, color .15s;
}
.site-banner.collapsed .sb-toggle { transform: rotate(180deg) translateY(-1px); }
.sb-toggle:hover { color: var(--vermilion); }
.sb-inner {
  max-width: 1180px;
  margin: 0 auto;
  padding: 7px 18px;
  display: flex; align-items: center; gap: 18px;
  flex-wrap: wrap;
}
.sb-links { display: flex; flex-direction: column; gap: 1px; font-size: 11.5px; }
.sb-links a { color: var(--ink-soft); text-decoration: none; }
.sb-links a:hover { color: var(--vermilion); text-decoration: underline; }
.sb-logos { display: flex; align-items: center; gap: 12px; margin-left: auto; }
.sb-logos img { height: 26px; width: auto; display: block; }
.sb-logos img.sb-hai { height: 30px; }
.sb-org { display: flex; flex-direction: column; gap: 1px; font-size: 10.5px; color: var(--ink-soft); line-height: 1.5; }
@media (max-width: 980px) {
  .sb-inner { padding: 6px 12px; gap: 10px; }
  .sb-org { display: none; }
  .sb-links { font-size: 10.5px; }
  .sb-logos img { height: 20px; }
  .sb-logos img.sb-hai { height: 24px; }
  .lookup-panel { bottom: 62px; }
}
