:root {
  --bg: #f7f7f5; --surface: #fff; --text: #1d1d1b; --muted: #6b6b66; --border: #e3e2dd;
  --accent: #1f5f8b; --accent-text: #fff; --danger: #b3261e; --ok: #2e7d32; --warn: #a15c00;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif; color: var(--text); background: var(--bg);
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #161615; --surface: #1f1f1e; --text: #ecebe6; --muted: #9c9b95; --border: #33332f;
          --accent: #6aa9d6; --accent-text: #0d1b26; --danger: #f2817a; --ok: #7cc47f; --warn: #e3a857; }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); }
a { color: var(--accent); }
h1 { font-size: 1.4rem; margin: 0 0 1rem; }
.muted { color: var(--muted); }
.small { font-size: .85em; }
.error { color: var(--danger); }
.notice { background: var(--surface); border: 1px solid var(--border); border-left: 4px solid var(--accent); padding: .75rem 1rem; border-radius: 6px; }
.topbar { display: flex; gap: 1.5rem; align-items: center; padding: .6rem 1.25rem; background: var(--surface); border-bottom: 1px solid var(--border); }
.topbar nav { display: flex; gap: 1rem; flex: 1; }
.topbar nav a { text-decoration: none; }
.brand { font-weight: 600; }
.page { max-width: 1000px; margin: 1.5rem auto; padding: 0 16px; }
.center { display: grid; place-items: center; min-height: 100vh; padding: 16px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 1rem 1.25rem; margin-bottom: 1.25rem; display: flex; flex-wrap: wrap; gap: .75rem; align-items: end; }
.card.narrow { flex-direction: column; align-items: stretch; width: min(360px, 100%); }
label { display: flex; flex-direction: column; gap: .25rem; font-size: .9rem; }
label.check { flex-direction: row; align-items: center; }
fieldset { border: 0; padding: 0; margin: 0; display: flex; gap: .75rem; flex-wrap: wrap; }
legend { font-size: .9rem; margin-bottom: .25rem; }
input, textarea { font: inherit; padding: .45rem .6rem; border: 1px solid var(--border); border-radius: 6px; background: var(--bg); color: var(--text); }
button, .button { font: inherit; padding: .45rem .9rem; border-radius: 6px; border: 1px solid var(--border); background: var(--surface); color: var(--text); cursor: pointer; text-decoration: none; display: inline-block; }
button.primary, .button.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
button.link { border: 0; background: none; padding: 0; color: var(--accent); }
button.danger { color: var(--danger); }
button:disabled { opacity: .5; cursor: wait; }
form.inline { display: inline-flex; gap: .5rem; align-items: center; margin: 0; }
table { width: 100%; border-collapse: collapse; background: var(--surface); border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
th, td { text-align: left; padding: .55rem .75rem; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-size: .8rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); }
tr.revoked td { opacity: .55; }
.status { font-size: .8rem; padding: .1rem .45rem; border-radius: 999px; border: 1px solid currentColor; }
.status.ready { color: var(--ok); } .status.failed { color: var(--danger); }
.status.pending, .status.processing { color: var(--warn); }
code.secret { display: block; padding: .6rem; background: var(--bg); border-radius: 6px; word-break: break-all; user-select: all; }

.chat-layout { display: grid; grid-template-columns: 260px 1fr; height: calc(100vh - 49px); }
.sidebar { border-right: 1px solid var(--border); padding: 1rem; overflow-y: auto; background: var(--surface); }
.conversations { list-style: none; padding: 0; margin: 1rem 0 0; }
.conversations a { display: block; padding: .4rem .5rem; border-radius: 6px; text-decoration: none; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conversations a.active, .conversations a:hover { background: var(--bg); }
.chat { display: flex; flex-direction: column; min-height: 0; }
.messages { flex: 1; overflow-y: auto; padding: 1.25rem; display: flex; flex-direction: column; gap: 1rem; }
.empty { margin: auto; }
.msg { max-width: 820px; width: 100%; margin: 0 auto; }
.msg .body { white-space: pre-wrap; line-height: 1.5; }
.msg .body.md { white-space: normal; }
.md > :first-child { margin-top: 0; } .md > :last-child { margin-bottom: 0; }
.md p, .md ul, .md ol, .md pre, .md blockquote, .md .table-wrap { margin: 0 0 .75rem; }
.md ul, .md ol { padding-left: 1.5rem; }
.md li > p, .md li > ul, .md li > ol { margin: .15rem 0; }
.md h3, .md h4, .md h5, .md h6 { font-size: 1rem; margin: 1rem 0 .4rem; }
.md h3 { font-size: 1.1rem; }
.md code { font-size: .875em; background: var(--surface); border: 1px solid var(--border); border-radius: 4px; padding: 0 .25rem; }
.md pre { background: var(--surface); border: 1px solid var(--border); border-radius: 6px; padding: .6rem .8rem; overflow-x: auto; }
.md pre code { background: none; border: 0; padding: 0; white-space: pre; }
.md blockquote { border-left: 3px solid var(--border); padding-left: .8rem; color: var(--muted); }
.md hr { border: 0; border-top: 1px solid var(--border); margin: 1rem 0; }
.md .table-wrap { overflow-x: auto; }
.md table { border-collapse: collapse; font-size: .9rem; }
.md th, .md td { border: 1px solid var(--border); padding: .3rem .6rem; text-align: left; vertical-align: top; }
.msg.user .body { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: .6rem .8rem; }
.sources { font-size: .85rem; color: var(--muted); margin: .5rem 0 0; padding-left: 1.5rem; }
.status-line { font-size: .85rem; }
.ask { display: flex; gap: .5rem; padding: .75rem 1.25rem; border-top: 1px solid var(--border); background: var(--surface); }
.ask textarea { flex: 1; resize: vertical; }
@media (max-width: 720px) {
  .chat-layout { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .topbar { flex-wrap: wrap; gap: .5rem 1rem; }
}
h2 { font-size: 1.1rem; margin: 1.5rem 0 .75rem; }
select { font: inherit; padding: .45rem .6rem; border: 1px solid var(--border); border-radius: 6px; background: var(--bg); color: var(--text); }
label.wide { flex-basis: 100%; }
.card.column { flex-direction: column; align-items: stretch; }
.table-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: .4rem 1rem; }
.actions { display: flex; flex-wrap: wrap; gap: .5rem; margin-bottom: 1rem; }
.notice.warn { border-left-color: var(--warn); }
code.sql { white-space: pre-wrap; word-break: break-word; font-size: .85em; }
.sources code.sql { display: block; margin-top: .2rem; }
.card.narrow form { display: flex; flex-direction: column; gap: .75rem; }
.card.narrow .button { text-align: center; }
.card.narrow details summary { cursor: pointer; margin-bottom: .75rem; }
details.inline { display: inline-block; }
details.inline summary.link { cursor: pointer; color: var(--accent); display: inline; }
details.inline[open] form { display: flex; gap: .4rem; margin-top: .4rem; }
p.wide { flex-basis: 100%; margin: 0; font-size: .85rem; }
/* documents: drag-and-drop upload (upload.js) */
.upload { display: flex; gap: .75rem; align-items: center; margin-bottom: 1.25rem; }
.dropzone { position: relative; flex: 1; display: flex; flex-direction: column; align-items: center; gap: .3rem; padding: 1.75rem 1rem; background: var(--surface); border: 2px dashed var(--border); border-radius: 8px; cursor: pointer; text-align: center; }
.dropzone:hover, .dropzone.over, .dropzone:focus-within { border-color: var(--accent); }
.dropzone.over { background: var(--bg); }
.dropzone.busy { cursor: progress; opacity: .7; }
.upload.js .dropzone input { position: absolute; width: 1px; height: 1px; opacity: 0; overflow: hidden; }

.msg.assistant.refused .body { color: var(--muted); font-style: italic; }
