/* Knowledge base, reader and chat. Uses the same tokens as the field guide. */
[hidden] { display: none !important; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.btn { height: 40px; padding: 0 16px; border-radius: var(--radius-button); border: 1px solid var(--ink); background: var(--ink); color: var(--canvas); font: inherit; font-weight: 500; cursor: pointer; }
.btn:disabled { opacity: 0.5; cursor: default; }
.btn:focus-visible, .icon-btn:focus-visible, .ref-open:focus-visible { outline: none; box-shadow: var(--focus-ring); }
.icon-btn { width: 36px; height: 36px; display: grid; place-items: center; border: 1px solid var(--line); border-radius: var(--radius-button); background: var(--card); color: var(--ink); cursor: pointer; flex-shrink: 0; }
.icon-btn svg { width: 18px; height: 18px; }

.topic .refs-btn { justify-self: start; display: inline-flex; align-items: center; gap: 6px; height: 28px; padding: 0 10px; border-radius: var(--radius-pill); border: 1px solid var(--line); background: var(--soft); color: var(--ink); font-family: var(--mono); font-size: 0.6875rem; letter-spacing: var(--tracking-label); text-transform: uppercase; cursor: pointer; }
.topic .refs-btn:hover { border-color: var(--line-strong); }

.lib-count { margin-bottom: 12px; }
.lib-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 12px; }
.ref { display: grid; gap: 8px; align-content: start; padding: 18px; }
.ref h3 { font-size: 1rem; letter-spacing: -0.015em; line-height: 1.3; }
.ref .by { font-size: 0.8125rem; color: var(--muted); }
.ref p.sum { font-size: 0.8125rem; color: var(--muted); line-height: 1.5; display: -webkit-box; -webkit-line-clamp: 4; -webkit-box-orient: vertical; overflow: hidden; }
.ref .acts { display: flex; flex-wrap: wrap; gap: 8px 14px; align-items: center; padding-top: 8px; border-top: var(--hairline); font-size: 0.8125rem; }
.ref .acts a { color: var(--ink); }
.ref-open { border: none; background: none; padding: 0; font: inherit; color: var(--ink); text-decoration: underline; cursor: pointer; }
.tag.full { background: var(--lime); }
.tag.queued { background: var(--soft); border: 1px dashed var(--line-strong); }
.tag.sum { background: var(--saffron); }
.band.lime .tag.full { background: var(--card); }

dialog.reader { width: min(820px, calc(100vw - 24px)); max-height: calc(100dvh - 24px); padding: 0; border: var(--hairline); border-radius: var(--radius-nav); background: var(--card); color: var(--ink); overflow: hidden; }
dialog.reader[open] { display: grid; grid-template-rows: auto minmax(0, 1fr); }
dialog.reader::backdrop { background: color-mix(in srgb, #000 45%, transparent); }
.reader-head { display: flex; gap: 16px; justify-content: space-between; align-items: start; padding: 20px 20px 16px; border-bottom: var(--hairline); }
.reader-head h2 { font-size: 1.375rem; margin-top: 6px; }
.reader-meta { font-size: 0.8125rem; color: var(--muted); margin-top: 6px; }
.reader-body { overflow-y: auto; padding: 8px 20px 28px; }

.prose { font-size: 0.9375rem; line-height: 1.65; }
.prose h2 { font-size: 1.125rem; margin: 24px 0 8px; }
.prose h3 { font-size: 1rem; margin: 20px 0 6px; }
.prose h4, .prose h5 { font-size: 0.9375rem; margin: 16px 0 6px; }
.prose p, .prose ul, .prose ol, .prose blockquote, .prose pre, .prose table { margin: 0 0 12px; }
.prose ul, .prose ol { padding-left: 22px; }
.prose li { margin: 3px 0; }
.prose blockquote { padding: 8px 14px; border-left: 3px solid var(--line-strong); background: var(--soft); border-radius: 4px; color: var(--muted); font-size: 0.8125rem; }
.prose code { font-size: 0.8125rem; background: var(--soft); padding: 1px 4px; border-radius: 4px; overflow-wrap: anywhere; }
.prose pre code { background: none; padding: 0; overflow-wrap: normal; }
.prose a { color: var(--ink); }
.prose table { display: block; overflow-x: auto; min-width: 0; font-size: 0.8125rem; }
.prose img { display: none; }

.chat { display: grid; gap: 0; padding: 0; overflow: hidden; }
.chat-log { display: grid; gap: 16px; align-content: start; padding: 20px; min-height: 220px; max-height: min(60vh, 640px); overflow-y: auto; }
.chat-empty p { color: var(--muted); font-size: 0.875rem; margin-bottom: 10px; }
.chat-empty .chip { text-transform: none; letter-spacing: 0; font-family: var(--sans); font-size: 0.8125rem; height: auto; padding: 6px 12px; white-space: normal; text-align: left; }
.msg { display: grid; gap: 6px; max-width: 46rem; }
.msg.user { justify-self: end; background: var(--soft); padding: 10px 14px; border-radius: var(--radius-card); }
.msg.user p { white-space: pre-wrap; }
.msg .who { font-family: var(--mono); font-size: var(--text-label); letter-spacing: var(--tracking-label); text-transform: uppercase; color: var(--muted); }
.msg .cites { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 4px; }
.msg .cites button { border: 1px solid var(--line); background: var(--card); color: var(--ink); border-radius: var(--radius-pill); font-size: 0.75rem; padding: 3px 10px; cursor: pointer; text-align: left; }
.msg .cites button:hover { border-color: var(--line-strong); }
.msg.error p { color: #B42318; }
.chat-form, .chat-gate { display: grid; gap: 8px; padding: 14px 20px 18px; border-top: var(--hairline); background: var(--card); }
.chat-form textarea, .chat-gate input { width: 100%; padding: 10px 12px; border: var(--hairline); border-radius: var(--radius-button); background: var(--canvas); color: var(--ink); font: inherit; resize: vertical; }
.chat-form textarea:focus, .chat-gate input:focus { outline: none; box-shadow: var(--focus-ring); }
.chat-row { display: flex; gap: 10px; align-items: center; justify-content: space-between; }
.chat-gate .chat-row { justify-content: stretch; }
.chat-note { font-size: 0.8125rem; color: var(--muted); }
.cursor::after { content: "▍"; animation: blink 1s steps(1) infinite; margin-left: 1px; }
@keyframes blink { 50% { opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .cursor::after { animation: none; } }
