:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --ink: #1c2530;
  --ink-soft: #5b6672;
  --line: #e4e7ec;
  --accent: #297eb5;
  --accent-soft: #e9f2f8;
  --chip: #f0f2f5;
  --warn: #b4690e;
  --err: #b4232a;
  --radius: 14px;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body { font-family: var(--sans); color: var(--ink); background: var(--bg); font-size: 15px; line-height: 1.55; }
a { color: var(--accent); }
button { font: inherit; }
.err { color: var(--err); font-size: 13px; margin: 8px 0 0; }
.muted { color: var(--ink-soft); }

/* ---------- brand ---------- */
.brand-logo { height: 30px; width: auto; display: block; }
.login-card .brand-logo { height: 46px; margin-bottom: 12px; }

/* ---------- top bar ---------- */
header.top {
  display: flex; align-items: center; gap: 14px;
  padding: 12px 20px; background: var(--panel); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 20;
}
header.top h1 { font-size: 15px; margin: 0; font-weight: 650; }
header.top .sub { color: var(--ink-soft); font-size: 12.5px; }
header.top .spacer { margin-left: auto; }
header.top .who { font-size: 12.5px; color: var(--ink-soft); }
.btn {
  border: 1px solid var(--line); background: var(--chip); color: var(--ink);
  padding: 6px 12px; border-radius: 9px; cursor: pointer;
}
.btn:hover { border-color: #d3d7de; }
.btn:disabled { opacity: .5; cursor: default; }
.btn:disabled:hover { border-color: var(--line); }
.btn.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn.sm { padding: 4px 9px; font-size: 12px; border-radius: 7px; }
.btn.danger { color: var(--err); }

/* ---------- portal layout ---------- */
.wrap { display: grid; grid-template-columns: 240px minmax(0,1fr) 320px; gap: 16px; padding: 16px; height: calc(100vh - 49px); }
@media (max-width: 1100px) { .wrap { grid-template-columns: 210px 1fr; } .rail-right { display: none; } }
.col { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); display: flex; flex-direction: column; min-height: 0; overflow: hidden; }
.col > h2 { font-size: 12px; letter-spacing: .04em; text-transform: uppercase; color: var(--ink-soft); margin: 0; padding: 13px 14px; border-bottom: 1px solid var(--line); }
.col .body { padding: 12px 14px; overflow-y: auto; flex: 1; min-height: 0; }
.col .foot { border-top: 1px solid var(--line); padding: 12px 14px; }

/* ---------- client list ---------- */
.client { display: flex; align-items: center; gap: 8px; padding: 8px 9px; border-radius: 9px; cursor: pointer; }
.client:hover { background: var(--chip); }
.client.active { background: var(--accent-soft); }
.client .name { font-size: 13.5px; font-weight: 550; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.client .type { font-size: 11px; color: var(--ink-soft); background: var(--chip); border-radius: 999px; padding: 1px 7px; }
.client.active .type { background: #fff; }
input, select, textarea {
  font: inherit; width: 100%; padding: 8px 10px; border: 1px solid var(--line);
  border-radius: 9px; background: #fff; color: var(--ink);
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
label { font-size: 12px; color: var(--ink-soft); display: block; margin: 8px 0 3px; }
.field-row { display: flex; gap: 8px; }
.field-row > * { flex: 1; }

/* ---------- chat ---------- */
.chat-head { display: flex; align-items: center; gap: 10px; padding: 11px 14px; border-bottom: 1px solid var(--line); }
.chat-head .title { font-weight: 600; font-size: 14px; }

.thread { flex: 1; overflow-y: auto; padding: 18px; display: flex; flex-direction: column; gap: 16px; }
.msg.flash .bubble { animation: msgflash 1.6s ease; border-radius: 8px; }
@keyframes msgflash { 0%, 30% { box-shadow: 0 0 0 3px var(--accent-soft); background: var(--accent-soft); } 100% { box-shadow: none; background: transparent; } }
.msg { display: flex; gap: 10px; }
.msg .who { width: 28px; height: 28px; border-radius: 8px; flex: none; display: grid; place-items: center; font-size: 11px; font-weight: 700; }
.msg.user .who { background: var(--chip); color: var(--ink-soft); }
.msg.assistant .who { background: var(--accent); color: #fff; }
.msg .bubble { min-width: 0; flex: 1; }
.msg .bubble h2 { font-size: 15px; margin: 14px 0 5px; }
.msg .bubble h3 { font-size: 13.5px; margin: 12px 0 4px; }
.msg .bubble p { margin: 7px 0; }
.msg .bubble ul, .msg .bubble ol { margin: 7px 0; padding-left: 20px; }
.msg .bubble li { margin: 3px 0; }
.msg .bubble hr { border: none; border-top: 1px solid var(--line); margin: 12px 0; }
.msg .bubble code { font-family: var(--mono); font-size: 12.5px; background: var(--chip); padding: 1px 5px; border-radius: 5px; }
.empty-chat { margin: auto; text-align: center; color: var(--ink-soft); max-width: 320px; }
.empty-chat.no-sessions p { margin: 4px 0; }
.empty-chat.no-sessions button { margin-top: 12px; }

.meta { margin-top: 9px; display: flex; gap: 12px; flex-wrap: wrap; font-size: 11px; color: var(--ink-soft); }
.meta b { color: var(--ink); font-weight: 600; }
details.sources { margin-top: 9px; border: 1px solid var(--line); border-radius: 10px; background: #fbfcfd; }
details.sources > summary { cursor: pointer; padding: 8px 11px; font-size: 12px; color: var(--accent); font-weight: 600; list-style: none; }
details.sources > summary::-webkit-details-marker { display: none; }
details.sources > summary::before { content: "▸ "; }
details.sources[open] > summary::before { content: "▾ "; }
.src { border-top: 1px solid var(--line); padding: 9px 11px; }
.src .name { font-size: 11.5px; font-weight: 600; margin-bottom: 2px; }
.src .snip { font-size: 11px; color: var(--ink-soft); white-space: pre-wrap; max-height: 70px; overflow: hidden; }

.composer { border-top: 1px solid var(--line); padding: 12px 14px; display: flex; gap: 9px; align-items: flex-end; }
.composer textarea { resize: none; min-height: 42px; max-height: 130px; }
.thinking { display: flex; align-items: center; gap: 7px; color: var(--ink-soft); font-size: 13px; }
.thinking .d { width: 6px; height: 6px; border-radius: 50%; background: var(--ink-soft); animation: blink 1s infinite; }
.thinking .d:nth-child(2) { animation-delay: .15s; } .thinking .d:nth-child(3) { animation-delay: .3s; }
@keyframes blink { 0%,60%,100% { opacity: .25; } 30% { opacity: 1; } }

/* ---------- right rail ---------- */
.rail-right .body { display: flex; flex-direction: column; gap: 14px; }
.card { border: 1px solid var(--line); border-radius: 11px; padding: 12px; }
.card h3 { margin: 0 0 7px; font-size: 11.5px; letter-spacing: .03em; text-transform: uppercase; color: var(--ink-soft); }
.card-head-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.card-head-row h3 { margin: 0; }
.card .out { font-size: 12.5px; white-space: pre-wrap; max-height: 260px; overflow-y: auto; }
.card .out h2 { font-size: 13.5px; margin: 10px 0 4px; }
.card .out ul { margin: 5px 0; padding-left: 18px; }
.pill-row { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 6px; }
.pill { font-size: 11px; padding: 3px 8px; border-radius: 999px; background: var(--chip); color: var(--ink-soft); }
.pill.done { background: var(--accent-soft); color: var(--accent); }

label.inline { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--ink-soft); margin: 0; flex: none; }
label.inline input { width: 54px; padding: 5px 7px; }

.feedback { margin-top: 8px; font-size: 12px; padding: 6px 9px; border-radius: 8px; }
.feedback.ok { background: var(--accent-soft); color: var(--accent); }
.feedback.bad { background: #fbeaea; color: var(--err); }

/* the Prep button is shaped like a session row (see .sess-stack / .sess-list) */
#prepBtn { text-align: center; white-space: nowrap; font-size: 12px; padding: 7px 9px; border-radius: 7px; }

/* prep ran but history it should have seen is still un-summarised */
.warnbox { margin: 0 0 10px; padding: 8px 11px; border-radius: 8px; background: #fdf4e3; border: 1px solid #f0dcae; color: #8a5b12; font-size: 12.5px; line-height: 1.45; }
.warnbox div + div { margin-top: 4px; }

/* session rows and the Prep button stack in one column, 4px apart, so Prep
   always sits directly under the newest session row */
.sess-stack { display: flex; flex-direction: column; gap: 4px; margin-top: 10px; }
.sess-list { display: flex; flex-direction: column; gap: 4px; }
.sess-list:empty { display: none; }
.sess-row { display: flex; align-items: center; gap: 10px; font-size: 12px; padding: 7px 9px; border-radius: 7px; cursor: pointer; border: 1px solid transparent; }
.sess-row:hover { background: var(--chip); }
.sess-row.sel { background: var(--accent-soft); border-color: #d4e5f0; }
.sess-row .sn { font-weight: 700; width: 22px; flex: none; }
.sess-row .tags { flex: 1; min-width: 0; color: var(--ink-soft); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; padding-right: 4px; }
.sess-row .mark { font-size: 13px; color: var(--accent); flex: none; margin-left: 2px; }

.past-notes { display: flex; flex-direction: column; gap: 6px; margin-bottom: 9px; max-height: 180px; overflow-y: auto; }
.note-item { font-size: 12px; background: var(--chip); border-radius: 8px; padding: 7px 9px; }
.note-item .text { white-space: pre-wrap; }
.note-item .meta { font-size: 10.5px; color: var(--ink-soft); margin-top: 3px; }

/* modal */
.modal { position: fixed; inset: 0; background: rgba(20,30,40,.32); display: grid; place-items: center; z-index: 50; padding: 20px; }
.modal-card { background: var(--panel); border-radius: var(--radius); border: 1px solid var(--line); width: 440px; max-width: 100%; max-height: 90vh; overflow-y: auto; padding: 18px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.modal-head h3 { margin: 0; font-size: 15px; }
.modal-foot { display: flex; align-items: center; margin-top: 16px; }
.pf-stats { display: flex; gap: 14px; margin-top: 12px; font-size: 11.5px; color: var(--ink-soft); }
.pf-stats b { color: var(--ink); font-weight: 600; }

.chat-head .title { cursor: default; }

.progress { margin-top: 8px; }
.progress .track { height: 6px; border-radius: 999px; background: var(--chip); overflow: hidden; }
.progress .fill { height: 100%; width: 0; background: var(--accent); border-radius: 999px; transition: width .3s ease; }
.progress .fill.err { background: var(--err); }
.progress .ptext { display: block; font-size: 11px; color: var(--ink-soft); margin-top: 4px; }

/* ---------- login ---------- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login-card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 26px; width: 340px; }
.login-card h1 { font-size: 17px; margin: 0 0 3px; }
.login-card .sub { color: var(--ink-soft); font-size: 12.5px; margin-bottom: 16px; }
.login-card button { width: 100%; margin-top: 14px; }

/* ---------- admin ---------- */
.admin-wrap { max-width: 820px; margin: 22px auto; padding: 0 20px; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); }
th { font-size: 11px; text-transform: uppercase; letter-spacing: .03em; color: var(--ink-soft); }
.tag { font-size: 11px; padding: 2px 7px; border-radius: 999px; background: var(--chip); }
.tag.admin { background: var(--accent-soft); color: var(--accent); }
.tag.off { background: #fbeaea; color: var(--err); }
