@font-face { font-family: 'Playfair Display'; src: url('/web/static/fonts/PlayfairDisplay.ttf') format('truetype'); font-weight: 400 900; }
@font-face { font-family: 'Playfair Display'; src: url('/web/static/fonts/PlayfairDisplay-Italic.ttf') format('truetype'); font-style: italic; font-weight: 400 900; }

:root {
  --paper: #121212;
  --ink: #F0F0F0;
  --coral: #C94D42;
  --coral-bright: #FF7A6E;
  --hairline: rgba(240,240,240,0.14);
  --muted: rgba(240,240,240,0.55);
}
@media (prefers-color-scheme: dark) {
  :root { --paper: #121212; --ink: #F0F0F0; --coral: #E0685C; --coral-bright: #FF8F84; --hairline: rgba(240,240,240,0.16); --muted: rgba(240,240,240,0.55); }
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  background: var(--paper);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  display: flex;
  flex-direction: column;
}

/* ---- scrollbars: no track background, indicator darker than the page ---- */
* { scrollbar-width: thin; scrollbar-color: var(--muted) transparent; }
*::-webkit-scrollbar { width: 10px; height: 10px; background: transparent; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-thumb { background: var(--muted); border-radius: 6px; border: 2px solid transparent; background-clip: padding-box; }
*::-webkit-scrollbar-thumb:hover { background: var(--ink); background-clip: padding-box; }
h1, h2, h3, .display { font-family: 'Playfair Display', Georgia, serif; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; letter-spacing: 0.02em; }

.hidden { display: none !important; }

/* ---- login ---- */
#login-screen {
  flex: 1; display: flex; align-items: center; justify-content: center;
}
#login-form {
  display: flex; align-items: stretch; width: min(360px, 84vw);
  background: #0A0A0A; border: none; border-radius: 2px; overflow: hidden;
}
#login-form.shake { animation: login-shake 0.4s ease; }
@keyframes login-shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-6px); }
  40% { transform: translateX(6px); }
  60% { transform: translateX(-4px); }
  80% { transform: translateX(4px); }
}
#login-password {
  flex: 1; min-width: 0;
  background: transparent; border: none; color: var(--ink);
  padding: 0.85rem 1rem; font-size: 1rem; outline: none;
}
#login-submit {
  display: flex; align-items: center; justify-content: center;
  background: transparent; color: var(--coral); border: none;
  padding: 0 0.95rem; cursor: pointer; flex-shrink: 0;
}
#login-submit:hover { color: var(--coral-bright); background: transparent; }
input[type="password"], input[type="text"] {
  background: transparent; border: 1px solid var(--hairline); color: var(--ink);
  padding: 0.75rem 0.9rem; font-size: 1rem; border-radius: 2px;
}
button {
  background: var(--coral); color: #FBFAF6; border: none; padding: 0.75rem 1rem;
  font-size: 0.95rem; border-radius: 2px; cursor: pointer; font-weight: 600;
}
button:hover { background: var(--coral-bright); }
button.secondary { background: transparent; color: var(--ink); border: 1px solid var(--hairline); }

/* ---- app shell ---- */
#app-shell { flex: 1; display: none; flex-direction: column; height: 100vh; }
#app-shell.active { display: flex; }

/* ---- nav: right-side vertical rail ---- */
.body-row { flex: 1; display: flex; overflow: hidden; }
nav.tabs {
  display: flex; flex-direction: column; gap: 0.5rem; width: 150px; flex-shrink: 0;
  padding: 1.25rem 1rem; border-left: 1px solid var(--hairline); order: 2;
}
nav.tabs button {
  background: none; border: none; color: var(--muted); font-family: inherit; font-weight: 600;
  padding: 0.5rem 0.6rem; border-left: 2px solid transparent; border-radius: 0; font-size: 0.9rem; text-align: left;
}
nav.tabs button.active { color: var(--ink); border-left-color: var(--coral); }
nav.tabs button:hover { background: none; color: var(--ink); }

main.view { flex: 1; overflow-y: auto; padding: 1.25rem; order: 1; }
.view-panel { display: none; max-width: 720px; margin: 0 auto; }
.view-panel.active { display: block; }

.section-num { color: var(--coral); font-weight: 700; margin-right: 0.5em; }
.hairline { border: none; border-top: 1px solid var(--hairline); margin: 1.25rem 0; }
.muted { color: var(--muted); font-size: 0.85rem; }

/* ---- chat ---- */
/* NOTE: this must be #chat-panel.active, not #chat-panel — an ID selector
   without .active beats the generic ".view-panel { display: none }" rule on
   specificity alone, which kept chat visible underneath every other tab. */
#chat-panel.active { display: flex; flex-direction: column; height: 100%; max-width: 960px; position: relative; }
/* Drag-a-file-onto-the-window highlight (Q, app msg 3549). position:relative
   above lets this pseudo-element overlay the whole panel without a wrapper. */
#chat-panel.dragover::after {
  content: ''; position: absolute; inset: 0; pointer-events: none; z-index: 5;
  border: 2px dashed var(--coral); border-radius: 8px; background: rgba(255, 111, 97, 0.06);
}

/* ---- terminal ---- */
/* Same specificity note as #chat-panel above: must be .active, not the bare id. */
#terminal-panel.active { display: flex; flex-direction: column; height: 100%; max-width: none; }
.term-topbar { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding-bottom: 0.6rem; flex-shrink: 0; }
#term-status { flex-shrink: 0; padding-bottom: 0.5rem; }
#term-container { flex: 1; min-height: 0; background: var(--paper); border: 1px solid var(--hairline); border-radius: 3px; padding: 0.5rem; overflow: hidden; }
#term-container .xterm { height: 100%; }
#term-container .xterm-viewport { border-radius: 3px; }
.chat-topbar { display: flex; justify-content: space-between; align-items: center; gap: 0.75rem; padding-bottom: 0.6rem; }
.chat-title { font-family: 'Playfair Display', serif; font-size: 1.05rem; font-weight: 700; color: var(--ink); }

/* ---- conversation rail (right nav, permanent list, not a popover) ---- */
.tabs-divider { width: 100%; margin: 0.75rem 0; }
#conv-rail { display: flex; flex-direction: column; gap: 0.1rem; width: 100%; }
.conv-row {
  display: flex; align-items: center; gap: 0.55rem; background: none; border: none; color: var(--muted);
  font-family: inherit; font-weight: 600; font-size: 0.85rem; padding: 0.4rem 0.6rem; border-radius: 0;
  border-left: 2px solid transparent; cursor: pointer; text-align: left; width: 100%;
}
.conv-row:hover { background: none; color: var(--ink); }
.conv-row.active { color: var(--ink); border-left-color: var(--coral); }
.conv-row .conv-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
/* Three states: dark/muted (idle, seen) is the default; solid coral (unread,
   a reply landed you haven't opened) overrides it; working (agent replying
   right now) pulses and takes priority over both -- set by JS as the class
   applied, never combined, so precedence is just "last class wins" in markup. */
/* needs-input is a FOURTH state, above all three: a ringed coral dot, static
   rather than pulsing, so "it wants you" reads as different in kind from "it's
   busy" rather than just a louder version of it. */
.conv-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); flex-shrink: 0; }
.conv-dot.unread { background: var(--coral); }
.conv-dot.working { background: var(--coral); animation: conv-pulse 1.2s ease-in-out infinite; }
.conv-dot.needs-input { background: var(--coral-bright); box-shadow: 0 0 0 3px rgba(224,104,92,0.28); }
@keyframes conv-pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.35; } }
.conv-row.needs-input { color: var(--ink); }
.conv-row.needs-input .conv-name { color: var(--ink); }
/* The reason lives under the row rather than in it — the rail is 150px wide,
   and truncating "Permission prompt: …" into the name line would tell Q there's
   something to do without telling him what. Full text is on the row's title. */
.conv-reason {
  font-size: 0.62rem; text-transform: uppercase; letter-spacing: 0.06em; font-weight: 700;
  color: var(--coral-bright); padding: 0 0.6rem 0.35rem 1.75rem; margin-top: -0.15rem;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.conv-row.conv-new { color: var(--coral); margin-top: 0.4rem; }
.conv-row.conv-new .conv-name { color: var(--coral); }
.conv-plus { font-family: 'Playfair Display', serif; font-size: 1rem; width: 7px; text-align: center; flex-shrink: 0; color: var(--coral); }
button.linklike {
  background: none; border: 1px solid var(--hairline); color: var(--muted); font-family: inherit; font-weight: 600;
  font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.05em; padding: 0.35rem 0.7rem; border-radius: 2px; cursor: pointer;
}
button.linklike:hover { background: none; color: var(--coral); border-color: var(--coral); }
#chat-log { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 0.6rem; padding-bottom: 1rem; }
#load-older, #reading-load-older {
  align-self: center; flex-shrink: 0; margin: 0.35rem 0;
  background: none; border: 1px solid var(--hairline); color: var(--muted); font-family: inherit; font-weight: 600;
  font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.08em; padding: 0.3rem 0.8rem; border-radius: 999px; cursor: pointer;
}
#load-older:hover, #reading-load-older:hover { background: none; color: var(--coral); border-color: var(--coral); }
.msg { max-width: 80%; line-height: 1.4; white-space: pre-wrap; word-wrap: break-word; align-self: flex-start; color: var(--ink); }
.msg.user {
  background: #2A2A2A; border-radius: 10px;
  padding: 0.65rem 0.9rem; text-align: left;
}
.msg.assistant { background: transparent; padding: 0.3rem 0; }
.msg .ts { display: block; font-size: 0.7rem; opacity: 0.6; margin-top: 0.25rem; color: var(--muted); }
/* Working indicator: a pulsing coral dot plus whatever the agent is actually
   doing. Stays deliberately quiet — muted text, one line, no wrap — so a long
   build reads as ambient progress rather than a second message stream. */
#thinking-indicator, #reading-thinking {
  display: flex; align-items: center; gap: 0.5rem; padding: 0.3rem 0.1rem;
  font-style: italic; color: var(--muted); font-size: 0.85rem;
}
#thinking-indicator.hidden, #reading-thinking.hidden { display: none; }
#thinking-indicator .working-dot, #reading-thinking .working-dot {
  width: 6px; height: 6px; border-radius: 50%; background: var(--coral); flex-shrink: 0;
  animation: conv-pulse 1.2s ease-in-out infinite;
}
#thinking-indicator #thinking-text, #reading-thinking #reading-thinking-text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#thinking-indicator.has-note #thinking-text, #reading-thinking.has-note #reading-thinking-text {
  font-style: normal; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.78rem;
}
.msg-attachment { display: block; max-width: 100%; max-height: 16rem; border-radius: 4px; margin-bottom: 0.3rem; }
.msg-file {
  display: inline-block; margin-bottom: 0.3rem; color: var(--coral); text-decoration: none;
  border: 1px solid var(--hairline); border-radius: 4px; padding: 0.4rem 0.7rem; font-size: 0.9rem;
}
.msg-file:hover { border-color: var(--coral); }
#chat-input-row, #reading-chat-input-row { display: flex; padding-top: 0.75rem; }
#chat-compose, #reading-compose {
  display: flex; align-items: stretch; width: 100%;
  background: #0A0A0A; border: none; border-radius: 2px; overflow: hidden;
}
#chat-compose textarea, #reading-compose textarea {
  flex: 1; min-width: 0; resize: none; overflow-y: auto; max-height: 8.5rem; line-height: 1.4;
  background: transparent; border: none; color: var(--ink); outline: none;
  padding: 0.85rem 0.25rem; font-size: 1rem; font-family: inherit;
}
#attach-btn {
  display: flex; align-items: center; justify-content: center;
  background: transparent; border: none; color: var(--muted);
  font-size: 1.05rem; line-height: 1; padding: 0 0.85rem; cursor: pointer; flex-shrink: 0;
}
#attach-btn:hover { color: var(--coral); background: transparent; }
#chat-send, #reading-chat-send {
  display: flex; align-items: center; justify-content: center;
  background: transparent; color: var(--coral); border: none;
  padding: 0 0.95rem; cursor: pointer; flex-shrink: 0;
}
#chat-send:hover, #reading-chat-send:hover { color: var(--coral-bright); background: transparent; }
#chat-send:disabled, #reading-chat-send:disabled { opacity: 0.45; cursor: default; }
#attach-preview { padding-top: 0.6rem; }
.attach-chip {
  display: inline-flex; align-items: center; gap: 0.5rem; border: 1px solid var(--hairline);
  border-radius: 999px; padding: 0.25rem 0.5rem 0.25rem 0.25rem; font-size: 0.8rem; color: var(--muted);
}
.attach-chip img { width: 2rem; height: 2rem; object-fit: cover; border-radius: 999px; }
.attach-chip-remove {
  background: none; border: none; color: var(--muted); cursor: pointer; font-size: 1rem; line-height: 1; padding: 0 0.15rem;
}
.attach-chip-remove:hover { color: var(--coral); }

/* ---- today / tasks ---- */
.counts-row { display: flex; gap: 1.5rem; margin-bottom: 1rem; }
.counts-row .stat { text-align: center; }
.counts-row .stat .n { font-size: 1.6rem; font-family: 'Playfair Display', serif; }
.counts-row .stat .l { font-size: 0.7rem; color: var(--muted); text-transform: uppercase; }

.filter-row { display: flex; gap: 1.25rem; margin-bottom: 1rem; flex-wrap: wrap; }
.filter-btn { background: none; border: none; padding: 0.2rem 0; font-size: 0.75rem; text-transform: uppercase;
  letter-spacing: 0.05em; color: var(--muted); border-bottom: 2px solid transparent; cursor: pointer; }
.filter-btn.active { color: var(--ink); border-bottom-color: var(--coral); font-weight: 600; }
/* Without this the base `button:hover` fills a filter tab solid coral, which
   reads as a pressed primary button rather than a tab. Same quiet hover the
   nav rail uses. */
.filter-btn:hover { background: none; color: var(--ink); }

/* ---- ops dashboard ---- */
#dashboard-panel.active { max-width: 720px; }
#dashboard-home { display: flex; flex-direction: column; gap: 1.75rem; }
.ops-cat { font-size: 0.65rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--coral); font-weight: 700; }
.ops-when { font-size: 0.75rem; color: var(--muted); white-space: nowrap; flex-shrink: 0; }

.digest-card {
  display: block; width: 100%; text-align: left; cursor: pointer;
  background: #0A0A0A; border: none; border-radius: 2px; color: var(--ink);
  padding: 1.1rem 1.15rem; font-family: inherit; font-weight: 400;
}
.digest-card:hover { background: #111; }
.digest-card-top { display: flex; justify-content: space-between; align-items: baseline; gap: 1rem; margin-bottom: 0.45rem; }
.digest-card-title { font-size: 1.35rem; font-family: 'Playfair Display', Georgia, serif; font-weight: 700; margin-bottom: 0.3rem; }
.digest-card-summary { font-size: 0.9rem; color: var(--muted); line-height: 1.4; }
.digest-card-cta { margin-top: 0.85rem; font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--coral); font-weight: 700; }

.dash-section { display: flex; flex-direction: column; gap: 0.55rem; }
.dash-section-title {
  margin: 0; font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.1em;
  color: var(--muted); font-family: inherit; font-weight: 700;
}
.dash-section-list { background: #0A0A0A; border-radius: 2px; overflow: hidden; }
.dash-row {
  display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem;
  padding: 0.85rem 1rem; border-bottom: 1px solid rgba(240,240,240,0.06);
  border-left: 3px solid transparent;
}
.dash-row:last-child { border-bottom: none; }
.dash-row.severity-info { border-left-color: #555; }
.dash-row.severity-warn { border-left-color: #C9A142; }
.dash-row.severity-error { border-left-color: var(--coral); }
.dash-row-main { min-width: 0; }
.dash-row-title { font-size: 0.95rem; font-weight: 600; color: var(--ink); margin-bottom: 0.15rem; }
.dash-row-body { font-size: 0.85rem; color: var(--muted); line-height: 1.35; }
.dash-empty { padding: 0.85rem 1rem; }

/* ---- dashboard tasks: header tools, tappable rows, detail/create sheet ---- */
/* A task row is a <button> so the whole row opens the detail sheet; it keeps the
   .dash-row layout and only resets what the base `button` rule would impose. */
.dash-section-head { display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap; }
.dash-section-tools { display: flex; align-items: center; gap: 1rem; }
.dash-section-tools .linklike { font-size: 0.7rem; padding: 0.25rem 0.6rem; }
button.dash-row-tap {
  width: 100%; text-align: left; font-family: inherit; font-size: inherit; font-weight: 400;
  background: none; color: var(--ink); border-radius: 0; cursor: pointer;
}
button.dash-row-tap:hover { background: #111; }

.task-detail-title { font-family: 'Playfair Display', Georgia, serif; font-size: 1.3rem; font-weight: 700; line-height: 1.25; }
.task-fields { margin-top: 1rem; }
.task-field {
  display: flex; justify-content: space-between; align-items: center; gap: 1rem;
  padding: 0.55rem 0; border-bottom: 1px solid var(--hairline);
}
.task-field-label { font-size: 0.65rem; text-transform: uppercase; letter-spacing: 0.1em; color: var(--muted); font-weight: 700; }
.task-field-value { font-size: 0.9rem; color: var(--ink); font-weight: 600; }
.task-input {
  background: #0A0A0A; border: 1px solid var(--hairline); color: var(--ink);
  padding: 0.4rem 0.55rem; font-size: 0.9rem; font-family: inherit; border-radius: 2px; max-width: 60%;
}
.task-title-input { width: 100%; max-width: none; padding: 0.7rem 0.75rem; font-size: 1rem; }
.task-actions { display: flex; align-items: center; gap: 0.6rem; flex-wrap: wrap; margin-top: 1.1rem; }
.task-actions button { font-size: 0.85rem; padding: 0.55rem 0.9rem; }
.task-actions button:disabled { opacity: 0.5; cursor: default; }
.task-actions button.task-remove { color: var(--coral); border-color: var(--coral); }
.task-foot { display: flex; justify-content: space-between; align-items: baseline; gap: 1rem; margin-top: 0.85rem; flex-wrap: wrap; }
.task-notion-link { font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); text-decoration: none; }
.task-notion-link:hover { color: var(--coral); }
.task-error { color: var(--coral); }

#dashboard-digest { display: flex; flex-direction: column; gap: 1rem; }
#dashboard-digest.hidden { display: none !important; }
.digest-back { align-self: flex-start; background: none; border: none; color: var(--coral); padding: 0; font-size: 0.85rem; font-weight: 600; cursor: pointer; }
.digest-page-header h2 { margin: 0.35rem 0 0.4rem; font-size: 1.75rem; font-family: 'Playfair Display', Georgia, serif; }
.digest-page-header p { margin: 0; }
.digest-block { margin-top: 1.5rem; }
.digest-block h3 {
  margin: 0 0 0.65rem; font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.1em;
  color: var(--muted); font-family: inherit; font-weight: 700;
}
.digest-row {
  display: flex; justify-content: space-between; align-items: baseline; gap: 1rem;
  padding: 0.7rem 0; border-bottom: 1px solid rgba(240,240,240,0.06); font-size: 0.95rem;
}
.digest-row:last-child { border-bottom: none; }

/* ---- reading ---- */
/* Same card surface (#0A0A0A on paper) as digest/activity cards; the head is a
   button so the whole row is the expand target, and the detail block sits
   outside it (a button can't contain the textarea). */
.reading-card { background: #0A0A0A; border-radius: 2px; margin-bottom: 0.5rem; overflow: hidden; }
.reading-card.open { border-left: 3px solid var(--coral); }
.reading-head {
  display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; width: 100%;
  background: none; border: none; border-radius: 0; padding: 0.85rem 1rem;
  font-family: inherit; font-weight: 400; color: var(--ink); text-align: left; cursor: pointer;
}
.reading-head:hover { background: #111; }
.reading-head-main { display: flex; flex-direction: column; gap: 0.15rem; min-width: 0; }
.reading-title { font-size: 0.95rem; font-weight: 600; line-height: 1.3; }
.reading-author { font-size: 0.78rem; color: var(--muted); }
.reading-teaser { font-size: 0.85rem; color: var(--muted); line-height: 1.35; margin-top: 0.2rem; }
.reading-tag {
  font-size: 0.6rem; text-transform: uppercase; letter-spacing: 0.08em; font-weight: 700;
  border: 1px solid var(--hairline); border-radius: 2px; padding: 0.1rem 0.35rem;
  color: var(--muted); white-space: nowrap; flex-shrink: 0;
}
.reading-tag.reading { color: var(--coral); border-color: var(--coral); }
.reading-tag.done { color: var(--ink); border-color: var(--hairline); opacity: 0.7; }
/* Neuroscience-only grouping by last author (Q, app msg 2774). Folders start
   collapsed; the cards inside are the same .reading-card, just indented. */
.reading-folder { margin-bottom: 0.5rem; }
.reading-folder-head {
  display: flex; align-items: center; gap: 0.5rem; width: 100%;
  background: none; border: none; border-bottom: 1px solid var(--hairline); border-radius: 0;
  padding: 0.6rem 0.25rem; font-family: inherit; font-weight: 600; color: var(--ink);
  text-align: left; cursor: pointer; font-size: 0.85rem;
}
.reading-folder-head:hover { background: #111; }
.reading-folder-arrow { color: var(--coral); font-size: 0.75rem; flex-shrink: 0; }
.reading-folder-name { flex: 1; min-width: 0; }
.reading-folder-count { font-size: 0.75rem; }
.reading-folder-items { padding: 0.5rem 0 0 0.5rem; }
.reading-folder.open .reading-folder-head { border-bottom-color: var(--coral); }
.reading-detail { padding: 0 1rem 1rem; display: flex; flex-direction: column; gap: 0.5rem; }
.reading-body { margin: 0; font-size: 0.88rem; line-height: 1.45; color: var(--ink); }
.reading-why { border-left: 2px solid var(--hairline); padding-left: 0.75rem; }
.reading-why .reading-body { color: var(--muted); margin-top: 0.2rem; }
.reading-link { align-self: flex-start; color: var(--coral); font-size: 0.85rem; font-weight: 600; text-decoration: none; }
.reading-link:hover { color: var(--coral-bright); }
.reading-response-label { margin-top: 0.35rem; }
.reading-response {
  width: 100%; resize: vertical; line-height: 1.4; font-family: inherit; font-size: 0.9rem;
  background: var(--paper); border: 1px solid var(--hairline); border-radius: 2px;
  color: var(--ink); padding: 0.6rem 0.7rem; outline: none;
}
.reading-response:focus { border-color: var(--coral); }
.reading-actions { display: flex; align-items: center; gap: 0.75rem; flex-wrap: wrap; }
.reading-actions button { font-size: 0.8rem; padding: 0.45rem 0.8rem; }
.reading-actions button:disabled { opacity: 0.5; cursor: default; }
.reading-error { color: var(--coral); }

/* ---- reading notes (the Notes section under the reading list) ---- */
/* Deliberately a different surface from .reading-card above it: flat, no head
   button, a coral rule down the left — so a wall of notes never reads as more
   reading-list rows. */
#reading-notes-section h3 { font-size: 1.15rem; margin: 0 0 0.75rem; }
#reading-note-form { display: flex; flex-direction: column; gap: 0.5rem; margin-bottom: 1rem; }
#reading-note-text {
  width: 100%; resize: vertical; line-height: 1.4; font-family: inherit; font-size: 0.9rem;
  background: var(--paper); border: 1px solid var(--hairline); border-radius: 2px;
  color: var(--ink); padding: 0.6rem 0.7rem; outline: none;
}
#reading-note-text:focus { border-color: var(--coral); }
#reading-note-form-row { display: flex; align-items: center; gap: 0.75rem; flex-wrap: wrap; }
/* Tag picker for a new note: a chip per tag, any number picked at once. A note
   carries a list of tags now, so a single-choice <select> can't say it. Picked
   chips go coral-on-coral so the pending set reads at a glance before submit. */
#reading-note-tags { display: flex; flex-wrap: wrap; gap: 0.4rem; }
.tag-chip {
  background: none; border: 1px solid var(--hairline); border-radius: 2px;
  color: var(--muted); font-family: inherit; font-size: 0.65rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.08em; padding: 0.25rem 0.45rem; cursor: pointer;
}
.tag-chip:hover { color: var(--ink); background: none; }
.tag-chip.picked { color: var(--coral); border-color: var(--coral); background: rgba(201, 77, 66, 0.1); }
#reading-note-submit { font-size: 0.8rem; padding: 0.45rem 0.8rem; }
#reading-note-submit:disabled { opacity: 0.5; cursor: default; }
.note-card {
  border-left: 2px solid var(--coral); padding: 0.15rem 0 0.15rem 0.75rem; margin-bottom: 0.9rem;
}
.note-meta { display: flex; align-items: center; gap: 0.4rem; margin-bottom: 0.3rem; flex-wrap: wrap; }
.note-date { font-size: 0.7rem; color: var(--muted); margin-left: 0.2rem; }
.reading-tag.untagged { opacity: 0.55; }
/* Delete sits at the far right of the meta row: reachable, but never the thing
   the eye lands on first. */
.note-delete {
  margin-left: auto; background: none; border: none; padding: 0 0.2rem;
  color: var(--muted); font-size: 1rem; line-height: 1; cursor: pointer;
}
.note-delete:hover { color: var(--coral); background: none; }
.note-delete:disabled { opacity: 0.4; cursor: default; }
/* Chat mode replaces the whole list view, so the notes go with it — that hide
   lives in setReadingMode() with the rest of the mode switching, not here. */

/* ---- reading author graph (the third section, under List and Notes) ---- */
/* The canvas is a framed surface, darker than the page, so the graph reads as a
   thing you manipulate rather than more page content. Node and label colors come
   from the same coral/ink pair the rest of the tab uses. */
#reading-graph-section h3 { font-size: 1.15rem; margin: 0 0 0.75rem; }
#reading-graph-wrap { position: relative; }
#reading-graph-svg {
  display: block; width: 100%; height: 420px;
  background: #0A0A0A; border: 1px solid var(--hairline); border-radius: 2px;
  touch-action: none;   /* d3-zoom owns the pinch/drag gestures, not the page */
  cursor: grab;
}
#reading-graph-svg:active { cursor: grabbing; }
/* A phone-width panel can't hold a graph this wide at a readable scale, so give
   it more height to pan around in. */
@media (max-width: 560px) { #reading-graph-svg { height: 60vh; } }
#reading-graph-zoom { position: absolute; top: 0.5rem; right: 0.5rem; display: flex; flex-direction: column; gap: 0.3rem; }
#reading-graph-zoom button {
  background: rgba(18,18,18,0.9); border: 1px solid var(--hairline); color: var(--ink);
  font-family: inherit; font-size: 0.75rem; font-weight: 700; line-height: 1;
  width: 1.9rem; height: 1.6rem; padding: 0; border-radius: 2px; cursor: pointer;
}
#reading-graph-zoom button:hover { background: rgba(18,18,18,0.9); color: var(--coral); border-color: var(--coral); }
#reading-graph-status { position: absolute; top: 0.75rem; left: 0.85rem; font-size: 0.8rem; }
#reading-graph-hint { font-size: 0.72rem; margin: 0.4rem 0 0.9rem; }

.graph-link { stroke: rgba(240,240,240,0.28); }
.graph-link.lit { stroke: var(--coral); }
.graph-link.dim { stroke: rgba(240,240,240,0.08); }
.graph-node { cursor: pointer; outline: none; }
.graph-node circle { fill: var(--coral); fill-opacity: 0.75; stroke: var(--paper); stroke-width: 1.5; }
.graph-node text { fill: var(--ink); font-size: 11px; font-family: inherit; pointer-events: none; }
.graph-node:hover circle, .graph-node:focus circle { fill-opacity: 1; stroke: var(--coral-bright); }
.graph-node.selected circle { fill: var(--coral-bright); fill-opacity: 1; stroke: var(--ink); stroke-width: 2; }
.graph-node.selected text { font-weight: 700; }
.graph-node.dim { opacity: 0.3; }

/* Same flat, coral-ruled surface the notes use, so the detail card belongs to
   this tab rather than looking like a modal bolted on. */
.graph-detail-card { border-left: 2px solid var(--coral); padding: 0.15rem 0 0.15rem 0.75rem; }
.graph-detail-head { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; margin-bottom: 0.6rem; }
.graph-detail-name { font-family: 'Playfair Display', Georgia, serif; font-size: 1.1rem; font-weight: 700; }
.graph-field { margin-bottom: 0.7rem; }
.graph-field .reading-body { margin-top: 0.15rem; }
.graph-list { margin: 0.15rem 0 0; padding-left: 1.1rem; font-size: 0.88rem; line-height: 1.45; }
.graph-list li { margin-bottom: 0.2rem; }
.graph-list a { color: var(--coral); text-decoration: none; word-break: break-all; }
.graph-list a:hover { color: var(--coral-bright); }
.graph-conns { display: flex; flex-wrap: wrap; gap: 0.4rem; margin-top: 0.25rem; }
.graph-conn {
  background: none; border: 1px solid var(--hairline); border-radius: 2px;
  color: var(--ink); font-family: inherit; font-size: 0.78rem; padding: 0.2rem 0.45rem; cursor: pointer;
}
.graph-conn:hover { background: none; color: var(--coral); border-color: var(--coral); }
/* Chat mode replaces the whole list view, so this section hides with it — that
   toggle lives in setReadingMode(), next to the notes one. */

/* ---- reading chat (the "reading" conversation, in the tab it belongs to) ---- */
/* Chat mode turns the panel into a column that owns the full height, so the
   transcript scrolls inside it and the composer stays pinned — the same shape
   #chat-panel.active uses. Same specificity note as #chat-panel: the rule has to
   carry .active, or it beats ".view-panel { display: none }" and shows Reading
   under every other tab. List mode is untouched (plain block flow). */
#reading-panel.active.chat-mode { display: flex; flex-direction: column; height: 100%; }
#reading-panel.chat-mode > h2, #reading-panel.chat-mode > #reading-modes { flex-shrink: 0; }
#reading-chat { flex: 1; min-height: 0; display: flex; flex-direction: column; }
#reading-chat.hidden { display: none !important; }
#reading-chat-log { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 0.6rem; padding-bottom: 1rem; }
#reading-chat-error { color: var(--coral); padding-top: 0.4rem; }

/* ---- system ---- */
#system-status { margin-bottom: 0.75rem; }
#system-extra { line-height: 1.6; margin-bottom: 0.5rem; }
.account-row { display: flex; gap: 0.6rem; margin-bottom: 0.4rem; }
.account-row button.active-account { background: var(--coral); color: #FBFAF6; }
.account-row button.inactive-account { background: transparent; border: 1px solid var(--hairline); color: var(--ink); }
#account-note { margin-bottom: 0; }
#system-stats { gap: 1.5rem; }
.gauge { display: flex; flex-direction: column; align-items: center; gap: 0.15rem; }
.gauge-track { fill: none; stroke: var(--hairline); stroke-width: 6; }
.gauge-fill {
  fill: none; stroke-width: 6; stroke-linecap: round;
  transform-origin: 32px 32px; transform: rotate(-90deg);
  transition: stroke-dashoffset 0.4s ease, stroke 0.4s ease;
}
.gauge-num { font-family: 'Playfair Display', serif; font-size: 0.85rem; fill: var(--ink); }
.gauge .l { font-size: 0.7rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; }
.gauge-sub { font-size: 0.65rem; }
/* ---- activity cards (System tab) ---- */
.activity-card {
  background: #0A0A0A; border-radius: 2px; border-left: 3px solid transparent;
  padding: 0.75rem 0.9rem; margin-bottom: 0.5rem;
}
.activity-card.stuck { border-left-color: var(--coral); }
.activity-head { display: flex; align-items: baseline; gap: 0.5rem; margin-bottom: 0.2rem; }
.activity-title { font-size: 0.95rem; font-weight: 600; color: var(--ink); }
.activity-flag {
  font-size: 0.6rem; text-transform: uppercase; letter-spacing: 0.08em; font-weight: 700;
  color: var(--coral); border: 1px solid var(--coral); border-radius: 2px; padding: 0.05rem 0.3rem;
}
.activity-detail { font-size: 0.85rem; color: var(--muted); line-height: 1.35; margin-bottom: 0.5rem; }
.activity-foot { display: flex; justify-content: space-between; align-items: center; gap: 0.75rem; flex-wrap: wrap; }
.activity-actions { display: flex; gap: 0.4rem; flex-shrink: 0; }
.activity-actions button { font-size: 0.68rem; padding: 0.25rem 0.55rem; }
.activity-actions button:disabled { opacity: 0.5; cursor: default; }

.job-row { display: flex; justify-content: space-between; padding: 0.4rem 0; border-bottom: 1px solid var(--hairline); font-size: 0.85rem; }
.file-row { display: flex; justify-content: space-between; padding: 0.45rem 0; border-bottom: 1px solid var(--hairline); cursor: pointer; font-size: 0.9rem; }
.file-row:hover { color: var(--coral); }
.file-row .size { color: var(--muted); font-size: 0.75rem; }
#files-crumb { margin-bottom: 0.5rem; font-size: 0.85rem; }
#files-crumb button { background: none; border: none; color: var(--coral); padding: 0; font-size: 0.85rem; font-weight: 600; }
#file-preview { white-space: pre-wrap; font-size: 0.8rem; background: rgba(128,128,128,0.08); padding: 0.75rem; border-radius: 3px; max-height: 50vh; overflow: auto; }
#clean-result { margin-top: 0.75rem; font-size: 0.85rem; }

/* ---- links modal ---- */
.modal { position: fixed; inset: 0; background: rgba(22,20,15,0.45); display: flex; align-items: center; justify-content: center; z-index: 50; padding: 1rem; }
.modal.hidden { display: none; }
.modal-card { background: var(--paper); border: 1px solid var(--hairline); border-radius: 4px; width: min(520px, 100%); max-height: 80vh; overflow-y: auto; padding: 1.25rem; }
.modal-header { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 0.75rem; }
.modal-header h2 { margin: 0; font-size: 1.15rem; }
.link-row { display: flex; flex-direction: column; gap: 0.2rem; padding: 0.7rem 0; border-bottom: 1px solid var(--hairline); }
.link-row:last-child { border-bottom: none; }
.link-row a { color: var(--ink); font-weight: 600; text-decoration: none; font-size: 0.95rem; }
.link-row a:hover { color: var(--coral); }
.link-meta { display: flex; gap: 0.6rem; align-items: center; font-size: 0.75rem; color: var(--muted); }
.link-type { text-transform: uppercase; letter-spacing: 0.05em; color: var(--coral); font-size: 0.65rem; font-weight: 700; }
.link-note { font-size: 0.8rem; color: var(--muted); }
.link-folder { margin-bottom: 1rem; }
.link-folder:last-child { margin-bottom: 0; }
.link-folder-title {
  text-transform: uppercase; letter-spacing: 0.05em; font-size: 0.75rem; font-weight: 700;
  color: var(--ink); padding-bottom: 0.4rem; border-bottom: 1px solid var(--hairline); margin-bottom: 0.2rem;
}
.link-remove {
  margin-left: auto; background: none; border: none; color: var(--muted); padding: 0 0.2rem;
  font-size: 0.9rem; cursor: pointer; line-height: 1;
}
.link-remove:hover { background: none; color: var(--coral); }
