:root { --bg:#f6f7f9; --panel:#fff; --ink:#1b1f24; --mute:#6b7280; --line:#e3e6ea; --accent:#2457c5; --user:#e8eefc; --tool:#f1f3f5; --err:#b42318; }
@media (prefers-color-scheme: dark) {
  :root { --bg:#0f1115; --panel:#171a20; --ink:#e6e8eb; --mute:#9aa3ad; --line:#2a2f37; --accent:#6c9bff; --user:#1f2a44; --tool:#1d2129; --err:#ff8a80; }
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { display: flex; font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--ink); }
button { font: inherit; cursor: pointer; border: 1px solid var(--line); background: var(--panel); color: var(--ink); border-radius: 8px; padding: 6px 12px; }
button:hover { border-color: var(--accent); }
button.link { border: none; background: none; color: var(--mute); padding: 0; text-decoration: underline; }
#side { width: 260px; flex: none; display: flex; flex-direction: column; background: var(--panel); border-right: 1px solid var(--line); }
.side-head, .side-foot { display: flex; align-items: center; justify-content: space-between; padding: 12px 14px; border-bottom: 1px solid var(--line); font-weight: 600; }
.side-foot { border-bottom: none; border-top: 1px solid var(--line); font-weight: 400; color: var(--mute); font-size: 13px; }
.scope { padding: 0 14px 10px; font-size: 12px; color: var(--mute); }
.scope.warn { color: #b7791f; }
#convs { list-style: none; margin: 0; padding: 6px; overflow-y: auto; flex: 1; }
#convs li { padding: 8px 10px; border-radius: 8px; cursor: pointer; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: flex; gap: 6px; }
#convs li span { flex: 1; overflow: hidden; text-overflow: ellipsis; }
#convs li.on { background: var(--user); }
#convs li button { visibility: hidden; border: none; background: none; padding: 0 4px; color: var(--mute); }
#convs li:hover button { visibility: visible; }
#main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
#messages { flex: 1; overflow-y: auto; padding: 24px 16px; }
.msg { max-width: 860px; margin: 0 auto 18px; }
.msg.user .bubble { background: var(--user); border-radius: 12px; padding: 10px 14px; display: inline-block; white-space: pre-wrap; }
.msg.user { text-align: right; }
.msg.assistant .bubble { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 12px 16px; }
.msg .meta { color: var(--mute); font-size: 12px; margin-top: 4px; }
.msg .err { color: var(--err); font-size: 13px; margin-top: 6px; }
.tools { margin: 6px 0; font-size: 13px; color: var(--mute); }
.tools > details { background: var(--tool); border-radius: 8px; padding: 4px 10px; margin: 3px 0; }
.tools > details > details { margin: 2px 0 2px 12px; padding: 2px 8px; border-left: 2px solid var(--line); }
.tools summary { cursor: pointer; list-style: none; }
.tools summary::before { content: "▸ "; }
.tools details[open] summary::before { content: "▾ "; }
.tools pre { margin: 6px 0 2px; white-space: pre-wrap; word-break: break-all; font-size: 12px; }
.tools .pending::after { content: " …"; }
.tools .bad { color: var(--err); }
.bubble p { margin: 0 0 10px; } .bubble p:last-child { margin-bottom: 0; }
.bubble pre { background: var(--tool); padding: 10px 12px; border-radius: 8px; overflow-x: auto; font-size: 13px; }
.bubble code { background: var(--tool); padding: 1px 4px; border-radius: 4px; font-size: 13px; }
.bubble pre code { background: none; padding: 0; }
.bubble table { border-collapse: collapse; margin: 8px 0; font-size: 14px; }
.bubble th, .bubble td { border: 1px solid var(--line); padding: 4px 10px; text-align: left; }
.bubble th { background: var(--tool); }
.bubble ul, .bubble ol { margin: 4px 0 10px; padding-left: 22px; }
.bubble h1, .bubble h2, .bubble h3 { font-size: 15px; margin: 12px 0 6px; }
.cursor::after { content: "▍"; color: var(--accent); animation: blink 1s step-end infinite; }
@keyframes blink { 50% { opacity: 0; } }
#compose { display: flex; gap: 10px; padding: 12px 16px 16px; border-top: 1px solid var(--line); background: var(--panel); max-width: 892px; width: 100%; margin: 0 auto; align-items: flex-end; }
#text { flex: 1; resize: none; font: inherit; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); color: var(--ink); }
.compose-buttons { display: flex; gap: 6px; }
#send { background: var(--accent); color: #fff; border-color: var(--accent); }
body.login { align-items: center; justify-content: center; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 28px; width: 340px; display: flex; flex-direction: column; gap: 12px; }
.card h1 { font-size: 18px; margin: 0 0 6px; }
.card label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--mute); }
.card input { font: inherit; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); color: var(--ink); }
.err { color: var(--err); font-size: 13px; margin: 0; }
.empty { color: var(--mute); text-align: center; margin-top: 20vh; }
@media (max-width: 720px) { #side { display: none; } }
.notice { max-width: 892px; width: 100%; margin: 0 auto; padding: 8px 16px; font-size: 13px; color: var(--mute); background: var(--tool); border-top: 1px solid var(--line); }
.notice a { color: var(--accent); }
/* 1.1.0: conversation bar, user actions, paused answers, system lines, admin page */
.convbar { display: flex; gap: 6px; justify-content: flex-end; padding: 8px 16px 0; max-width: 892px; width: 100%; margin: 0 auto; }
.convbar button { font-size: 12px; padding: 4px 10px; color: var(--mute); }
.msg.user .uactions { font-size: 12px; margin-top: 2px; visibility: hidden; }
.msg.user:hover .uactions { visibility: visible; }
.msg.user .uactions .link { text-decoration: none; margin-left: 8px; color: var(--mute); }
.msg .paused { margin-top: 8px; font-size: 13px; color: #b7791f; }
.msg .paused button { margin-left: 6px; border-color: #b7791f; }
.msg .sys { color: var(--mute); font-size: 13px; text-align: center; padding: 6px 0; border-top: 1px dashed var(--line); border-bottom: 1px dashed var(--line); }
.notice.warn { color: #b7791f; }
.notice.bad { color: var(--err); }
#send:disabled { opacity: .5; cursor: not-allowed; }
#admin { padding: 4px 8px; }
body.admin { display: block; overflow: auto; }
.page { max-width: 1000px; margin: 0 auto; padding: 24px 20px 60px; }
.admin-head { display: flex; align-items: baseline; justify-content: space-between; gap: 16px; }
.admin-head h1 { font-size: 20px; margin: 0; }
.page section { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 18px 20px; margin: 18px 0; }
.page h2 { font-size: 16px; margin: 0 0 12px; }
.page h3 { font-size: 14px; margin: 14px 0 6px; }
.grid { border-collapse: collapse; width: 100%; font-size: 14px; margin-bottom: 12px; }
.grid th, .grid td { border-bottom: 1px solid var(--line); padding: 6px 8px; text-align: left; vertical-align: middle; }
.grid td.q { max-width: 360px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.grid input[type=text], .grid input:not([type]) { width: 100%; }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin: 8px 0; }
.row input { flex: 1; min-width: 140px; }
.page input:not([type=checkbox]), .page select, .page textarea { font: inherit; padding: 6px 8px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); color: var(--ink); }
.page textarea { width: 100%; font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 12px; }
.help { color: var(--mute); font-size: 13px; }
.field { display: grid; grid-template-columns: 280px 220px 1fr; gap: 12px; align-items: center; padding: 6px 0; border-bottom: 1px solid var(--line); }
.field .label em { color: #b7791f; font-style: normal; font-size: 12px; }
.field .help { font-size: 12px; }
.status { font-size: 14px; }
.status.ok { color: #2f855a; } .status.warn { color: #b7791f; } .status.bad { color: var(--err); }
.flash { position: sticky; top: 8px; background: var(--user); border: 1px solid var(--line); border-radius: 8px; padding: 8px 12px; margin: 0 0 12px; }
.flash.bad { color: var(--err); }
button.danger { border-color: var(--err); color: var(--err); }
button.secondary { color: var(--mute); }
.console { background: var(--tool); padding: 10px 12px; border-radius: 8px; max-height: 420px; overflow: auto; font-size: 12px; white-space: pre-wrap; }
.notes { font-size: 14px; } .notes table { border-collapse: collapse; } .notes th, .notes td { border: 1px solid var(--line); padding: 3px 8px; }
#draftText { background: var(--tool); padding: 10px 12px; border-radius: 8px; font-size: 12px; white-space: pre-wrap; max-height: 360px; overflow: auto; }
@media (max-width: 720px) { .field { grid-template-columns: 1fr; } }

/* documentation page */
body.docs .page { max-width: 860px; }
body.docs p, body.docs li { line-height: 1.55; font-size: 15px; }
body.docs ol, body.docs ul { padding-left: 22px; margin: 10px 0; }
body.docs li { margin: 5px 0; }
body.docs code { background: var(--tool); padding: 1px 5px; border-radius: 5px; font-size: 13px; }
.flow { display: grid; grid-template-columns: 1fr 28px 1fr 28px 1fr; align-items: stretch; gap: 6px; margin: 6px 0; }
.flow .node { border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; background: var(--bg); display: flex; flex-direction: column; gap: 3px; font-size: 14px; }
.flow .node span { color: var(--mute); font-size: 12.5px; line-height: 1.35; }
.flow .node.ghost, .flow .arrow.ghost { border: 0; background: none; visibility: hidden; }
.flow .node.down { border: 0; background: none; color: var(--mute); font-size: 12.5px; text-align: center; padding: 0; justify-content: center; }
.flow .arrow { display: flex; align-items: center; justify-content: center; color: var(--mute); font-size: 18px; }
@media (max-width: 640px) { .flow { grid-template-columns: 1fr; } .flow .arrow { transform: rotate(90deg); } .flow .ghost { display: none; } }
.grid tbody th[colspan] { text-align: left; padding-top: 1.1em; font-size: .78em; letter-spacing: .06em; text-transform: uppercase; opacity: .7; border-bottom-width: 2px; }

.sources { border: 1px solid var(--line); border-left: 4px solid var(--accent); border-radius: 10px; margin-top: 10px; padding: 12px 16px; background: var(--panel); font-size: 14px; }
.sources-head { font-weight: 600; margin-bottom: 8px; }
.sources-foot { color: var(--mute); font-size: 12px; margin-top: 8px; }
.src { padding: 10px 0; border-top: 1px solid var(--line); }
.src-title { font-weight: 600; margin-bottom: 6px; }
.crumbs { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; margin: 4px 0; }
.lead { color: var(--mute); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; margin-right: 6px; }
.crumb { background: var(--user); border-radius: 6px; padding: 2px 8px; }
.crumb:last-of-type { outline: 1px solid var(--accent); }
.sep { color: var(--mute); }
.src-enter { border-collapse: collapse; margin: 8px 0 4px; font-size: 13px; }
.src-enter th, .src-enter td { border: 1px solid var(--line); padding: 3px 10px; text-align: left; }
.src-enter th { background: var(--tool); font-weight: 500; color: var(--mute); }
.src-shows { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; margin-top: 6px; }
.pill { border: 1px solid var(--line); border-radius: 999px; padding: 1px 9px; font-size: 13px; display: inline-block; margin: 1px 0; white-space: nowrap; }
.src-note, .src-none { color: var(--mute); font-size: 13px; margin-top: 6px; }
.src-ns ul { margin: 4px 0 0; padding-left: 18px; }

.sources-group { color: var(--mute); font-size: 12px; text-transform: uppercase; letter-spacing: .06em; margin-top: 12px; padding-top: 8px; border-top: 2px solid var(--line); }
.sources-group + .src { border-top: none; }
.src-row { display: flex; gap: 6px; margin-top: 6px; align-items: baseline; }
.src-row .lead { flex: none; width: 86px; }
.src-row ul { margin: 0; padding-left: 18px; }
body.login form[hidden] { display: none; }
