/* Libra JA — design tokens shared with marco.vectram (warm paper, forest
   green accent, Inter UI type) plus reader/tree/chat components specific
   to this app. See /root/vectram/marco/app/static/style.css for the
   sibling app this palette originates from. */

:root {
  --bg: #FAFAF7;
  --panel-bg: #FFFFFF;
  --ink: #1A1D1A;
  --ink-soft: #55594F;
  --label: #8A8A82;
  --line: #E7E7E0;
  --green: #1E4D36;
  --green-hover: #173D2B;
  --green-tint: #EEF3EF;
  --red: #B23A2F;
  --red-tint: #FBEAE8;
  --amber: #9C6B22;
  --amber-tint: #FBF1E1;
  --radius: 8px;
  --icon-rail-w: 76px;
  --lib-sidebar-w: 300px;

  /* Knowledge-taxonomy cluster colors (categorical, not decorative — one
     per cluster A-E so the graphical breakdown reads at a glance). */
  --cluster-a: var(--green);
  --cluster-b: var(--amber);
  --cluster-c: #6B4C7A;
  --cluster-d: #35618C;
  --cluster-e: #8A8A82;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: 'Inter', 'Noto Sans JP', system-ui, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}
button { font-family: inherit; cursor: pointer; }
input, textarea { font-family: inherit; }
a { color: var(--green); }

/* ---------- Shell ---------- */
.shell { display: flex; height: 100vh; width: 100vw; }

.icon-rail {
  width: var(--icon-rail-w);
  flex-shrink: 0;
  height: 100%;
  background: var(--panel-bg);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 16px 6px;
  gap: 6px;
}
.brand-mark {
  font-family: 'Fraunces', 'Noto Serif JP', serif;
  font-weight: 600;
  font-size: 20px;
  color: var(--green);
  margin-bottom: 10px;
  line-height: 1;
}
.icon-rail-btn {
  width: 100%;
  min-height: 56px;
  padding: 8px 4px 7px;
  border-radius: 10px;
  background: none;
  border: none;
  color: var(--ink-soft);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 5px;
}
.icon-rail-label { font-size: 10.5px; font-weight: 600; line-height: 1.15; text-align: center; }
.icon-rail-btn:hover { background: var(--bg); color: var(--ink); }
.icon-rail-btn.active { background: var(--green-tint); color: var(--green); }
.icon-rail-btn:focus-visible { outline: 2px solid var(--green); outline-offset: -2px; }

.main-area { flex: 1 1 auto; min-width: 0; height: 100%; display: flex; }
.tab-view { display: none; flex: 1 1 auto; min-width: 0; height: 100%; }
.tab-view.active { display: flex; }

/* ================= Ask Vectram ================= */
.ask-view { flex-direction: column; align-items: center; }
.ask-inner {
  width: 100%;
  max-width: 760px;
  height: 100%;
  display: flex;
  flex-direction: column;
  padding: 0 20px;
}
.ask-header { padding: 22px 4px 12px; border-bottom: 1px solid var(--line); }
.ask-header h1 {
  font-family: 'Fraunces', 'Noto Serif JP', serif;
  font-size: 22px;
  font-weight: 600;
  margin: 0 0 4px;
}
.ask-header p { color: var(--ink-soft); font-size: 13px; margin: 0; }

.ask-thread { flex: 1 1 auto; overflow-y: auto; padding: 18px 4px 8px; display: flex; flex-direction: column; gap: 16px; }
.ask-empty { color: var(--label); font-size: 13px; text-align: center; margin-top: 40px; }
.ask-msg { max-width: 92%; }
.ask-msg.user { align-self: flex-end; }
.ask-msg.assistant { align-self: flex-start; }
.ask-bubble {
  padding: 11px 14px;
  border-radius: 14px;
  font-size: 14px;
  line-height: 1.65;
  white-space: pre-wrap;
}
.ask-msg.user .ask-bubble { background: var(--green); color: #fff; border-bottom-right-radius: 4px; }
.ask-msg.assistant .ask-bubble { background: var(--panel-bg); border: 1px solid var(--line); border-bottom-left-radius: 4px; }
.ask-msg.assistant.pending .ask-bubble { color: var(--label); }
.ask-sources { margin-top: 8px; display: flex; flex-direction: column; gap: 6px; }
.ask-source-label { font-size: 10.5px; letter-spacing: .04em; text-transform: uppercase; color: var(--label); font-weight: 600; margin-bottom: 2px; }
.ask-source-card {
  display: block;
  width: 100%;
  text-align: left;
  background: var(--panel-bg);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 12.5px;
  color: var(--ink-soft);
}
.ask-source-card:hover { border-color: var(--green); color: var(--ink); }
.ask-source-card .src-title { font-weight: 600; color: var(--green); display: block; margin-bottom: 2px; font-size: 12px; }

.ask-composer {
  display: flex;
  gap: 8px;
  padding: 14px 4px 20px;
  border-top: 1px solid var(--line);
}
.ask-composer input {
  flex: 1 1 auto;
  border: 1px solid var(--line);
  border-radius: 22px;
  padding: 10px 16px;
  font-size: 14px;
  background: var(--panel-bg);
}
.ask-composer input:focus { outline: none; border-color: var(--green); }
.ask-send {
  width: 42px; height: 42px; border-radius: 50%;
  background: var(--green); color: #fff; border: none;
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.ask-send:hover { background: var(--green-hover); }
.ask-send:disabled { background: var(--line); color: var(--label); }

/* ================= Library ================= */
.library-list {
  width: var(--lib-sidebar-w);
  flex-shrink: 0;
  height: 100%;
  overflow-y: auto;
  background: var(--panel-bg);
  border-right: 1px solid var(--line);
  padding: 18px 14px;
}
.panel-heading { font-size: 11px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--label); display: block; margin-bottom: 12px; }
.book-card {
  display: block;
  width: 100%;
  text-align: left;
  padding: 12px 12px;
  border-radius: 10px;
  border: 1px solid transparent;
  background: none;
  margin-bottom: 6px;
}
.book-card:hover { background: var(--bg); }
.book-card.active { background: var(--green-tint); border-color: var(--green); }
.book-title { font-family: 'Fraunces', 'Noto Serif JP', serif; font-size: 15px; font-weight: 600; line-height: 1.4; display: block; margin-bottom: 2px; }
.book-author { font-size: 11.5px; color: var(--ink-soft); display: block; margin-bottom: 4px; }
.book-meta { font-size: 11.5px; color: var(--label); }
.book-tags { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 8px; }
.book-tag-chip {
  font-size: 10px; color: var(--ink-soft); background: var(--bg);
  border: 1px solid var(--line); border-radius: 10px; padding: 2px 7px;
}

.reader-pane { flex: 1 1 auto; min-width: 0; height: 100%; display: flex; flex-direction: column; background: var(--bg); }
.reader-placeholder { flex: 1; display: flex; align-items: center; justify-content: center; color: var(--label); font-size: 14px; }
.reader-toolbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 20px; border-bottom: 1px solid var(--line); background: var(--panel-bg);
  flex-shrink: 0;
}
.reader-toolbar .rt-title { font-size: 13px; font-weight: 600; color: var(--ink-soft); }
.rt-font-controls { display: flex; align-items: center; gap: 4px; }
.rt-font-btn {
  width: 28px; height: 28px; border-radius: 6px; border: 1px solid var(--line);
  background: var(--panel-bg); color: var(--ink-soft); font-size: 13px; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
}
.rt-font-btn:hover { border-color: var(--green); color: var(--green); }

.rt-page-nav { display: flex; align-items: center; gap: 10px; }
.rt-page-btn {
  width: 28px; height: 28px; border-radius: 6px; border: 1px solid var(--line);
  background: var(--panel-bg); color: var(--ink-soft);
  display: flex; align-items: center; justify-content: center;
}
.rt-page-btn:hover:not(:disabled) { border-color: var(--green); color: var(--green); }
.rt-page-btn:disabled { opacity: 0.35; cursor: default; }
.rt-page-indicator { font-size: 11.5px; color: var(--label); font-variant-numeric: tabular-nums; min-width: 4.5em; text-align: center; }

/* Kindle-style pagination: .reader-viewport is a fixed-size clipped
   window (overflow:hidden); .reader-page is the same centered/padded
   reading column as before, but laid out as CSS multi-column content
   (column-width forced larger than the column itself so exactly one
   "page" fills the viewport) and slid via transform: translateX per
   page instead of the whole thing scrolling vertically. */
.reader-viewport {
  flex: 1 1 auto;
  position: relative;
  overflow: hidden;
  max-width: 34em;
  width: 100%;
  margin: 0 auto;
}
.reader-page {
  height: 100%;
  padding: 48px 28px 56px;
  box-sizing: border-box;
  font-family: 'Noto Serif JP', 'Iowan Old Style', serif;
  font-size: var(--reader-size, 17px);
  line-height: 1.95;
  color: var(--ink);
  column-width: 999px;
  column-gap: 56px;
  column-fill: auto;
  transition: transform 0.32s cubic-bezier(.4, 0, .2, 1);
}
.reader-page h1.reader-title {
  font-size: 1.5em;
  font-weight: 700;
  line-height: 1.5;
  margin: 0 0 6px;
}
.reader-author {
  font-family: 'Inter', 'Noto Sans JP', sans-serif;
  font-size: 0.62em;
  color: var(--ink-soft);
  margin-bottom: 0.3em;
}
.reader-source {
  font-family: 'Inter', sans-serif;
  font-size: 0.55em;
  color: var(--label);
  margin-bottom: 2.2em;
  word-break: break-all;
}
.reader-page p, .reader-page blockquote { margin: 0 0 1.1em; break-inside: avoid; }
.reader-page blockquote { margin-left: 1.4em; padding-left: 1em; border-left: 3px solid var(--line); color: var(--ink-soft); }
.reader-page b { font-weight: 700; }
.reader-page i { font-style: italic; }

/* ---- Knowledge/insight breakdown: sans-serif tool UI, not reading
   content, so it deliberately breaks from the serif reading type.
   Collapsed by default; the stacked summary bar in the header is always
   visible so the graphical read is there even without expanding. ---- */
.reader-knowledge {
  font-family: 'Inter', 'Noto Sans JP', sans-serif;
  margin: 0 0 2.4em;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel-bg);
  overflow: hidden;
}
.rk-toggle {
  width: 100%; display: flex; flex-direction: column; gap: 8px;
  padding: 11px 14px; background: none; border: none; cursor: pointer;
}
.rk-toggle-row { width: 100%; display: flex; align-items: center; justify-content: space-between; }
.rk-toggle-label { font-size: 12px; font-weight: 700; letter-spacing: .03em; color: var(--ink-soft); }
.rk-chevron { color: var(--label); transition: transform 0.12s ease; flex-shrink: 0; }
.reader-knowledge.open .rk-toggle-row { }
.reader-knowledge.open .rk-toggle { border-bottom: 1px solid var(--line); }
.reader-knowledge.open .rk-chevron { transform: rotate(90deg); }

/* Always-visible stacked bar: relative share of each dimension present,
   colored by cluster -- the "at a glance" graphical view. */
.rk-summary-bar {
  width: 100%; height: 8px; border-radius: 4px; overflow: hidden;
  display: flex; background: var(--bg);
}
.rk-summary-seg { height: 100%; }

.rk-body { display: none; padding: 14px; }
.reader-knowledge.open .rk-body { display: flex; flex-direction: column; gap: 14px; }
.rk-cluster-label {
  display: block; font-size: 10.5px; font-weight: 700; letter-spacing: .06em;
  text-transform: uppercase; color: var(--label); margin-bottom: 7px;
}
.rk-tags { display: flex; flex-direction: column; gap: 6px; }
.rk-tag { border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.rk-tag-chip {
  width: 100%; display: flex; flex-direction: column; gap: 6px;
  padding: 8px 10px; background: none; border: none; cursor: pointer; text-align: left;
}
.rk-tag-chip:hover { background: var(--bg); }
.rk-tag-chip-row { width: 100%; display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.rk-tag-label { font-size: 12.5px; color: var(--ink); }
.rk-tag-count { font-size: 10.5px; color: var(--label); flex-shrink: 0; font-variant-numeric: tabular-nums; }
.rk-tag-bar { width: 100%; height: 5px; border-radius: 3px; background: var(--bg); overflow: hidden; }
.rk-tag-bar-fill { height: 100%; border-radius: 3px; }
.rk-tag-items { display: none; list-style: none; margin: 0; padding: 0 10px 9px; }
.rk-tag.open .rk-tag-items { display: block; }
.rk-tag-items li {
  font-size: 11.5px; color: var(--ink-soft); padding: 5px 6px; border-radius: 6px; cursor: pointer;
}
.rk-tag-items li:hover { background: var(--green-tint); color: var(--green); }

mark.hl {
  background: var(--amber-tint);
  color: inherit;
  border-bottom: 2px solid var(--amber);
  padding: 0 1px;
  border-radius: 2px;
  cursor: pointer;
}
mark.hl.flash { animation: hl-flash 1.6s ease; }
@keyframes hl-flash {
  0% { background: #ffe4a1; }
  100% { background: var(--amber-tint); }
}
p.flash-target, blockquote.flash-target { animation: p-flash 1.6s ease; border-radius: 4px; }
@keyframes p-flash {
  0% { background: var(--green-tint); }
  100% { background: transparent; }
}

.hl-popup {
  position: fixed;
  z-index: 50;
  transform: translate(-50%, -100%);
  background: var(--ink);
  color: #fff;
  padding: 6px 12px;
  border-radius: 20px;
  font-size: 12.5px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 6px;
  box-shadow: 0 6px 18px rgba(0,0,0,0.22);
}
.hl-popup:hover { background: #000; }
.hl-popup::after {
  content: "";
  position: absolute; left: 50%; bottom: -5px; transform: translateX(-50%);
  border: 5px solid transparent; border-top-color: var(--ink);
}

.hl-remove-tip {
  position: fixed; z-index: 50; transform: translate(-50%, -100%);
  background: var(--red); color: #fff; padding: 5px 10px; border-radius: 16px;
  font-size: 11.5px; font-weight: 600;
}

/* ================= Brain =================
   Bubble/pill tree diagram (D3), not an indented list: mirrors marco's
   Brain canvas exactly (see /root/vectram/marco app.js renderBrainCanvas /
   style.css .tree-node-pill). Panning/zooming happens via the SVG's own
   d3.zoom transform, so overflow stays hidden (a scrollbar would double
   up on that). */
.brain-view { flex-direction: column; padding: 24px 28px 20px; }
.brain-header { margin: 0 0 14px; flex-shrink: 0; }
.brain-header h1 { font-family: 'Fraunces', 'Noto Serif JP', serif; font-size: 21px; margin: 0; }

.brain-main { flex: 1 1 auto; display: flex; gap: 14px; min-height: 0; }
.brain-tree-viz { flex: 1 1 auto; overflow: hidden; display: flex; min-height: 0; }

.brain-content-panel {
  width: 340px; flex-shrink: 0; overflow-y: auto;
  border: 1px solid var(--line); border-radius: 8px; background: var(--panel-bg);
  padding: 18px;
  font-family: 'Inter', 'Noto Sans JP', sans-serif;
}
.bcp-placeholder { color: var(--label); font-size: 12.5px; line-height: 1.7; }
.bcp-loading { color: var(--label); font-size: 12.5px; }
.bcp-eyebrow { font-size: 10.5px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--label); margin: 0 0 6px; }
.bcp-title { font-family: 'Fraunces', 'Noto Serif JP', serif; font-size: 16px; font-weight: 600; color: var(--ink); margin: 0 0 4px; line-height: 1.4; }
.bcp-meta { font-size: 11px; color: var(--label); margin: 0 0 14px; }
.bcp-excerpt {
  font-family: 'Noto Serif JP', serif; font-size: 13.5px; line-height: 1.85; color: var(--ink-soft);
  margin: 0 0 16px; max-height: 340px; overflow-y: auto; padding-right: 4px;
}
.bcp-excerpt p, .bcp-excerpt blockquote { margin: 0 0 0.9em; }
.bcp-quote {
  font-family: 'Noto Serif JP', serif; font-size: 14px; font-style: italic; color: var(--ink);
  border-left: 3px solid var(--amber); padding-left: 12px; margin: 0 0 16px; line-height: 1.8;
}
.bcp-open-btn {
  display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 600;
  color: #fff; background: var(--green); border: none; border-radius: 7px; padding: 8px 13px; cursor: pointer;
}
.bcp-open-btn:hover { background: var(--green-hover); }
.bcp-child-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.bcp-child-list li {
  font-size: 12.5px; color: var(--ink-soft); padding: 8px 9px; border-radius: 6px; cursor: pointer;
  border: 1px solid var(--line);
}
.bcp-child-list li:hover { background: var(--green-tint); color: var(--green); border-color: var(--green); }

.tree-node-g.selected .tree-node-pill { fill: var(--green); stroke: var(--green); }
.tree-node-g.selected .tree-node-label { fill: #fff; font-weight: 600; }
.brain-tree-svg-wrap {
  flex: 1;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-bg);
}
.brain-tree-svg-wrap svg { display: block; cursor: grab; }

.tree-link { fill: none; stroke: var(--line); stroke-width: 1.5px; }

.tree-node-pill { fill: var(--panel-bg); stroke: var(--green); stroke-width: 1.5px; }
.tree-node-pill.root { fill: var(--green-tint); }
.tree-node-g { cursor: pointer; }
.tree-node-g:hover .tree-node-pill { stroke: var(--green-hover); }
.tree-node-g:hover .tree-node-label { fill: var(--green); }

.tree-node-g.kind-category .tree-node-pill { fill: var(--green-tint); stroke: var(--green); }
.tree-node-g.kind-category .tree-node-label { font-weight: 700; letter-spacing: 0.04em; }
.tree-node-g.kind-essay .tree-node-label { font-weight: 600; }
.tree-node-g.kind-highlight_book .tree-node-pill { stroke: var(--amber); }
.tree-node-g.kind-highlight_book .tree-node-label { font-weight: 600; }
.tree-node-g.kind-highlight_group .tree-node-pill { fill: var(--amber-tint); stroke: var(--amber); }
.tree-node-g.kind-highlight_group .tree-node-label { fill: var(--amber); }
.tree-node-g.kind-highlight .tree-node-pill { stroke-dasharray: 3 2; }
.tree-node-g.kind-highlight .tree-node-label { font-style: italic; }
.tree-node-g.kind-highlight:hover .tree-node-pill { stroke: var(--amber); }

.tree-node-label { font-size: 11px; fill: var(--ink); font-family: 'Inter', 'Noto Sans JP', system-ui, sans-serif; }

.tree-empty { color: var(--label); font-size: 12px; padding: 4px 6px 4px 8px; }
.tree-loading { color: var(--label); font-size: 12px; padding: 4px 6px 4px 8px; }

/* ================= Scrollbars (subtle) ================= */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--line); border-radius: 6px; }
::-webkit-scrollbar-thumb:hover { background: #d3d3c8; }

/* ================= Responsive ================= */
@media (max-width: 860px) {
  :root { --lib-sidebar-w: 240px; }
}
@media (max-width: 640px) {
  .icon-rail { width: 60px; }
  .icon-rail-label { font-size: 9px; }
  .library-list { width: 200px; padding: 12px 8px; }
  .reader-page { padding: 32px 16px 70px; font-size: 15.5px; }
  .ask-header h1 { font-size: 18px; }
}
