/* Barney Web — light theme matching the barneyai.app palette, laid out like the
   Finley Stetson assistant (navy sidebar + light chat pane, stacked message
   cards with role labels). Self-hosted fonts only (system stack) to keep the
   strict CSP: Georgia for display, system-ui for body. */
:root {
  --navy: #0d1b34;
  --navy-2: #13254a;
  --navy-3: #1b3361;
  --navy-900: #08152c;
  --brand: #2563eb;
  --brand-dark: #1e40af;
  --brand-light: #3b82f6;

  --bg: #eef2f8;
  --panel: #ffffff;
  --panel-2: #f6f8fc;
  --ink: #0f1b30;
  --muted: #5a6b85;
  --line: #e5e9f2;
  --ok: #0f9d6b;
  --danger: #c0362c;

  --sidebar: #0d1b34;
  --sidebar-hover: #13254a;
  --sidebar-active: #2563eb;
  --sidebar-ink: #d5ddee;
  --sidebar-muted: #8595b5;

  --radius: 12px;
  --sidebar-w: 264px;
  --header-h: 58px;
  --serif: Georgia, "Times New Roman", serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

.hidden { display: none !important; }

/* ---- top bar ---- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  height: var(--header-h); padding: 0 20px; flex-shrink: 0;
  background: var(--navy); color: #fff;
  box-shadow: 0 1px 0 rgba(0,0,0,.15); z-index: 10;
}
.brand { display: flex; align-items: center; gap: 10px; font-family: var(--serif); font-size: 20px; }
.brand-badge {
  display: grid; place-items: center; width: 30px; height: 30px; border-radius: 7px;
  background: var(--brand); color: #fff; font-weight: 700; font-size: 16px;
}
.brand-name { font-weight: 600; letter-spacing: .01em; }
.brand-accent { color: #9cc0ff; font-weight: 600; }
.brand span { color: #9cc0ff; }
.userbar { display: flex; align-items: center; gap: 12px; }
.user-email { color: #b9c6de; font-size: 13px; }

.app { flex: 1; min-height: 0; width: 100%; display: flex; flex-direction: column; overflow: hidden; }

/* ---- generic ---- */
.btn {
  font: inherit; font-weight: 600; padding: 10px 16px; border-radius: 9px;
  border: 1px solid transparent; cursor: pointer; background: var(--brand); color: #fff;
  transition: background .15s;
}
.btn:hover { background: var(--brand-dark); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-ghost { background: transparent; border-color: rgba(255,255,255,.35); color: #fff; }
.btn-ghost:hover { background: rgba(255,255,255,.12); }
.btn-danger { background: transparent; border-color: var(--danger); color: var(--danger); }
.btn-danger:hover { background: #fbe9e8; }
.btn-sm { padding: 6px 12px; font-size: 13px; }

input, textarea, select {
  font: inherit; color: var(--ink); background: #fff;
  border: 1px solid var(--line); border-radius: 9px; padding: 11px 12px; width: 100%;
}
input:focus, textarea:focus, select:focus {
  outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px rgba(37,99,235,.15);
}
label { display: block; font-size: 13px; color: var(--muted); margin: 0 0 6px; }

/* ---- auth / centered cards ---- */
.card {
  max-width: 440px; width: 100%; margin: auto; background: var(--panel);
  border: 1px solid var(--line); border-radius: 16px; padding: 30px;
  box-shadow: 0 1px 2px rgba(15,27,48,.05), 0 18px 40px -20px rgba(15,27,48,.25);
  max-height: calc(100% - 40px); overflow-y: auto;
}
.card h1 { font-family: var(--serif); font-size: 24px; color: var(--navy); margin: 0 0 6px; }
.card .sub { color: var(--muted); margin: 0 0 20px; font-size: 14px; }
.field { margin-bottom: 16px; }
.row { display: flex; gap: 10px; align-items: center; }
.msg { font-size: 13px; margin-top: 12px; min-height: 18px; color: var(--muted); }
.msg.err { color: var(--danger); }
.msg.ok { color: var(--ok); }
.mono { font-family: ui-monospace, "Cascadia Code", Consolas, monospace; }

.secret-box {
  background: var(--panel-2); border: 1px dashed #c7d2e6; border-radius: 10px;
  padding: 12px; letter-spacing: 2px; text-align: center; font-size: 16px; margin: 8px 0 4px;
  word-break: break-all; color: var(--navy);
}
.codes { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin: 10px 0; }
.codes span {
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px;
  padding: 8px; text-align: center; letter-spacing: 1px; color: var(--navy);
}
.note { font-size: 12px; color: var(--muted); }
.card a { color: var(--brand); }
.qr-wrap { display: flex; justify-content: center; margin: 6px 0 12px; }
.qr-canvas { background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 10px; max-width: 100%; height: auto; }

/* ---- chat shell ---- */
.chat { flex: 1; min-height: 0; display: grid; grid-template-columns: var(--sidebar-w) 1fr; }

/* sidebar */
.side {
  background: var(--sidebar); color: var(--sidebar-ink);
  display: flex; flex-direction: column; overflow-y: auto; padding: 14px 10px;
  border-right: 1px solid var(--navy-900);
}
.side-top { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; }
/* Reduced "New chat": compact pill, not a full-width primary button. */
.new-chat {
  font: inherit; font-size: 13px; font-weight: 600; cursor: pointer;
  text-align: left; padding: 8px 12px; border-radius: 8px;
  background: var(--brand); color: #fff; border: 1px solid transparent;
  transition: background .15s;
}
.new-chat:hover { background: var(--brand-light); }
/* Admin button, directly under New chat — subtle, sidebar-tinted. */
.side-admin {
  font: inherit; font-size: 13px; font-weight: 600; cursor: pointer;
  display: flex; align-items: center; gap: 8px;
  text-align: left; padding: 8px 12px; border-radius: 8px;
  background: transparent; color: var(--sidebar-ink);
  border: 1px solid rgba(255,255,255,.14); transition: background .15s;
}
.side-admin:hover { background: var(--sidebar-hover); }
.side-admin-ic { opacity: .85; }
.conv-item {
  display: flex; justify-content: space-between; gap: 6px; align-items: center;
  padding: 9px 11px; border-radius: 7px; cursor: pointer; color: var(--sidebar-ink);
  font-size: 13.5px; margin-bottom: 2px;
}
.conv-item:hover { background: var(--sidebar-hover); }
.conv-item.active { background: var(--sidebar-active); color: #fff; }
.conv-item .title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }
.conv-del {
  border: none; background: none; color: var(--sidebar-muted); cursor: pointer;
  font-size: 16px; line-height: 1; padding: 2px 5px; border-radius: 4px; visibility: hidden;
}
.conv-item:hover .conv-del { visibility: visible; }
.conv-del:hover { color: #fff; background: rgba(255,255,255,.12); }
.conv-item.active .conv-del { color: #dbe6ff; visibility: visible; }

/* main pane */
.pane { display: flex; flex-direction: column; background: var(--bg); overflow: hidden; min-width: 0; }
.messages { flex: 1; overflow-y: auto; padding: 26px 22px; display: flex; flex-direction: column; align-items: center; gap: 18px; }
.bubble {
  width: 100%; max-width: 780px; padding: 4px 2px; white-space: normal;
  word-wrap: break-word; overflow-wrap: anywhere; line-height: 1.6;
}
.bubble .who {
  display: block; font-size: 11px; font-weight: 700; letter-spacing: .08em;
  text-transform: uppercase; margin-bottom: 7px;
}
.bubble.assistant .who { color: var(--navy); }
.bubble.user .who { color: var(--brand); }
.bubble .body, .bubble { color: var(--ink); }
.bubble.assistant {
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
  padding: 15px 17px; font-size: 14.5px;
}
.bubble.user {
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 12px;
  padding: 15px 17px; font-size: 14.5px;
}
.bubble .body { white-space: pre-wrap; }        /* streaming text + user messages */
.bubble .body.md { white-space: normal; }       /* rendered Markdown manages its own layout */
.bubble .body.md > :first-child { margin-top: 0; }
.bubble .body.md > :last-child { margin-bottom: 0; }
.bubble .body p { margin: 0 0 10px; }
.bubble .body h1, .bubble .body h2, .bubble .body h3, .bubble .body h4 {
  font-family: var(--serif); color: var(--navy); line-height: 1.25; margin: 15px 0 8px;
}
.bubble .body h1 { font-size: 20px; }
.bubble .body h2 { font-size: 17px; }
.bubble .body h3 { font-size: 15px; }
.bubble .body h4 { font-size: 14px; }
.bubble .body ul, .bubble .body ol { margin: 8px 0; padding-left: 22px; }
.bubble .body li { margin-bottom: 4px; }
.bubble .body li > ul, .bubble .body li > ol { margin: 4px 0; }
.bubble .body a { color: var(--brand); }
.bubble .body code {
  background: #e9eef7; color: var(--navy); padding: 1px 5px; border-radius: 4px;
  font-family: ui-monospace, "Cascadia Code", Consolas, monospace; font-size: .9em;
}
.bubble .body pre {
  background: var(--navy); color: #e8eefb; padding: 13px 15px; border-radius: 10px;
  overflow-x: auto; margin: 10px 0;
}
.bubble .body pre code { background: none; color: inherit; padding: 0; font-size: 13px; }
.bubble .body blockquote {
  margin: 10px 0; padding: 6px 14px; border-left: 3px solid var(--line); color: var(--muted);
}
.bubble .body hr { border: none; border-top: 1px solid var(--line); margin: 14px 0; }
/* ---- composer: ChatGPT-style rounded pill, centered under the messages ---- */
.composer-wrap {
  flex-shrink: 0; background: transparent; padding: 6px 22px 20px;
  display: flex; flex-direction: column; align-items: center; gap: 8px;
}
.composer-wrap > * { width: 100%; max-width: 780px; }
.composer-status { font-size: 12.5px; color: var(--muted); min-height: 0; text-align: center; }
.composer-status:empty { display: none; }
.composer-status.err { color: var(--danger); }

.composer {
  background: #fff; border: 1px solid var(--line); border-radius: 26px;
  padding: 10px 12px 8px; display: flex; flex-direction: column; gap: 4px;
  box-shadow: 0 1px 2px rgba(15,27,48,.05), 0 12px 30px -18px rgba(15,27,48,.35);
}
.composer:focus-within { border-color: #c9d6ee; box-shadow: 0 1px 2px rgba(15,27,48,.06), 0 14px 34px -16px rgba(15,27,48,.4); }
.composer-input {
  border: none; background: transparent; resize: none; width: 100%;
  padding: 6px 8px; min-height: 26px; max-height: 180px; line-height: 1.5;
  color: var(--ink); font: inherit;
}
.composer-input:focus { outline: none; border: none; box-shadow: none; }
.composer-input::placeholder { color: #9aa7bf; }
.composer-tools { display: flex; align-items: flex-end; justify-content: space-between; gap: 8px; }
.tools-right { display: flex; align-items: flex-end; gap: 8px; }
/* Library pill stacked directly above the model pill (owner ask 2026-08-12).
   Right-aligned column; each pill's menu opens upward from its own row. */
.picker-stack { display: flex; flex-direction: column; gap: 6px; align-items: flex-end; }

.file-hidden { display: none; }
.attach-btn {
  flex-shrink: 0; width: 34px; height: 34px; border-radius: 50%; cursor: pointer;
  border: 1px solid var(--line); background: #fff; color: var(--muted);
  font-size: 20px; line-height: 1; display: grid; place-items: center;
}
.attach-btn:hover { background: var(--panel-2); color: var(--navy); }

.send-btn {
  flex-shrink: 0; width: 34px; height: 34px; border-radius: 50%; cursor: pointer;
  border: none; background: var(--navy); color: #fff;
  font-size: 17px; line-height: 1; display: grid; place-items: center;
  transition: background .15s;
}
.send-btn:hover { background: var(--brand); }
.send-btn:disabled { background: #c2cbdd; cursor: not-allowed; }

/* custom model dropdown (bottom-right of the composer) */
.model-picker { position: relative; }
.model-btn {
  display: inline-flex; align-items: center; gap: 5px; cursor: pointer;
  font: inherit; font-size: 13px; font-weight: 600; color: var(--navy);
  background: var(--panel-2); border: 1px solid var(--line);
  border-radius: 999px; padding: 6px 12px;
}
.model-btn:hover { background: #eef2fa; border-color: #d5deee; }
.model-chev { font-size: 10px; color: var(--muted); }
.model-menu {
  position: absolute; bottom: calc(100% + 8px); right: 0; z-index: 30;
  width: 300px; max-width: 78vw; background: #fff; border: 1px solid var(--line);
  border-radius: 14px; padding: 6px; box-shadow: 0 14px 40px -12px rgba(15,27,48,.35);
}
.model-menu-hd {
  font-size: 11px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase;
  color: var(--muted); padding: 8px 10px 6px;
}
.model-opt { padding: 9px 10px; border-radius: 9px; cursor: pointer; }
.model-opt:hover { background: var(--panel-2); }
.model-opt.sel { background: #eef4ff; }
.model-opt-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.model-opt-name { font-size: 14px; font-weight: 600; color: var(--navy); }
.model-opt-tick { color: var(--brand); font-weight: 700; }
.model-opt-desc { font-size: 12.5px; color: var(--muted); margin-top: 2px; line-height: 1.4; }

.attach-chip {
  display: flex; align-items: center; gap: 8px; padding: 7px 12px;
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px;
  font-size: 13px; width: fit-content;
}

/* "thinking" indicator shown in the assistant bubble until the reply arrives */
.thinking { display: inline-flex; align-items: center; gap: 9px; color: var(--muted); font-size: 13.5px; }
.tk-label { font-style: italic; }
.tk-dots { display: inline-flex; gap: 4px; }
.tk-dots .dot { width: 6px; height: 6px; border-radius: 50%; background: var(--brand); display: inline-block; animation: tkpulse 1.2s infinite ease-in-out both; }
.tk-dots .dot:nth-child(2) { animation-delay: .16s; }
.tk-dots .dot:nth-child(3) { animation-delay: .32s; }
@keyframes tkpulse { 0%, 80%, 100% { transform: scale(.5); opacity: .4; } 40% { transform: scale(1); opacity: 1; } }

/* ---- extended thinking: the model's REASONING, not its answer ---------------
   Deliberately unlike a reply bubble: tinted, dashed left rule, smaller italic
   muted text. Its header reuses .tk-label/.tk-dots so the bubble carries ONE
   thinking affordance rather than two. */
.reasoning {
  margin-bottom: 12px; border: 1px solid var(--line); border-left: 3px dashed #b9c6de;
  border-radius: 10px; background: var(--panel-2); overflow: hidden;
}
.rz-head {
  display: flex; align-items: center; gap: 9px; width: 100%; cursor: pointer;
  font: inherit; text-align: left; border: none; background: none;
  padding: 9px 12px; color: var(--muted); font-size: 13px;
}
.rz-head:hover { background: #eef2fa; }
.rz-ic { color: var(--brand); font-size: 12px; }
.rz-chev { margin-left: auto; color: var(--muted); font-size: 11px; }
.rz-text {
  padding: 0 14px 12px 14px; white-space: pre-wrap; font-size: 13px; line-height: 1.55;
  font-style: italic; color: var(--muted); max-height: 260px; overflow-y: auto;
}
.reasoning.collapsed .rz-text { display: none; }
.reasoning.done { background: transparent; }
.attach-chip .chip-nm { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--navy); font-weight: 500; }
.attach-chip .chip-x { border: none; background: none; cursor: pointer; color: var(--muted); font-size: 13px; padding: 0 2px; }
.attach-chip .chip-x:hover { color: var(--danger); }
.chip-meta { color: var(--muted); font-size: 11.5px; white-space: nowrap; }
.doc-chip {
  display: inline-flex; align-items: center; gap: 4px; margin-bottom: 8px; padding: 5px 10px;
  background: #fff; border: 1px solid var(--line); border-radius: 8px; font-size: 12.5px; color: var(--navy);
}
/* "Generated document" panel — shown only when the model creates/modifies a doc */
.gen-doc { margin-top: 12px; padding: 12px 14px; background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px; }
.gen-doc-lbl { font-size: 11px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--navy); margin-bottom: 8px; }
.gen-doc-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.gen-doc-name { font-size: 13.5px; font-weight: 500; color: var(--navy); display: inline-flex; align-items: center; }
.doc-dl {
  display: inline-flex; align-items: center; gap: 2px; background: var(--brand); color: #fff;
  border: none; cursor: pointer; font: inherit; font-size: 13px; font-weight: 600; padding: 7px 16px; border-radius: 8px;
}
.doc-dl:hover { background: var(--brand-dark); }
.empty { text-align: center; margin: auto; max-width: 460px; }
.empty-title { font-family: var(--serif); font-size: 26px; color: var(--navy); margin-bottom: 8px; }
.empty-sub { color: var(--muted); font-size: 14px; line-height: 1.6; }

/* ---- admin panel ---- */
.admin { flex: 1; min-height: 0; overflow-y: auto; display: flex; flex-direction: column; gap: 18px; max-width: 860px; margin: 0 auto; padding: 22px 22px 28px; width: 100%; }
.admin-nav { margin-bottom: 2px; }
.admin-back {
  font: inherit; font-size: 13px; font-weight: 600; cursor: pointer;
  display: inline-flex; align-items: center; gap: 7px;
  padding: 7px 14px; border-radius: 8px;
  background: var(--panel); color: var(--navy); border: 1px solid var(--line);
  transition: background .15s;
}
.admin-back:hover { background: var(--panel-2); }
.admin-section {
  border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--panel); padding: 20px 22px;
  box-shadow: 0 1px 2px rgba(15,27,48,.04);
}
.admin-h2 { font-family: var(--serif); font-size: 18px; color: var(--navy); margin: 0 0 14px; }

.admin-banner {
  border: 1px solid var(--line); border-radius: 10px; padding: 10px 14px;
  font-size: 13px; background: var(--panel-2);
}
.admin-banner.ok { border-color: #a7e0c6; background: #edfaf3; color: #0b7a52; }
.admin-banner.err { border-color: #f0c2bd; background: #fdeeec; color: var(--danger); }

/* billing card */
.billing-card {
  display: flex; gap: 28px; flex-wrap: wrap;
  background: var(--panel-2); border: 1px solid var(--line);
  border-radius: 10px; padding: 18px 20px; margin-bottom: 12px;
}
.billing-card.needs-card { border-color: var(--brand); background: #eef4ff; }
.billing-figure, .billing-status { display: flex; flex-direction: column; gap: 4px; }
.billing-label { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .4px; }
.billing-amount { font-size: 26px; font-weight: 700; color: var(--navy); }
.billing-status-val { font-size: 16px; font-weight: 600; }
.billing-status-val.blocked { color: var(--danger); }
.billing-status-val.active { color: var(--ok); }

/* tables */
.admin-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.admin-table th {
  text-align: left; color: var(--muted); font-weight: 600; font-size: 12px;
  padding: 8px 10px; border-bottom: 1px solid var(--line);
}
.admin-table td { padding: 9px 10px; border-bottom: 1px solid var(--line); }
.admin-table tr:last-child td { border-bottom: none; }

.invite-row { display: flex; gap: 10px; align-items: center; margin-bottom: 14px; }
.invite-row input { flex: 1; }

/* ---- sidebar: Projects section + section headers ---- */
.side-section { margin-bottom: 10px; }
.side-hd {
  display: flex; align-items: center; justify-content: space-between;
  font-size: 11px; font-weight: 700; letter-spacing: .07em; text-transform: uppercase;
  color: var(--sidebar-muted); padding: 4px 8px 6px; margin-top: 4px;
}
.chats-hd { margin-top: 8px; }
/* ---- sidebar Chats | Projects tabs (like the FS assistant) ---- */
.side-tabs {
  display: flex; gap: 4px; margin-bottom: 8px; padding: 3px;
  background: rgba(255,255,255,.06); border-radius: 8px;
}
.side-tab {
  flex: 1; font: inherit; font-size: 12.5px; font-weight: 600; cursor: pointer;
  padding: 6px 0; border: none; border-radius: 6px; background: transparent;
  color: var(--sidebar-muted); transition: background .15s, color .15s;
}
.side-tab:hover { color: #fff; }
.side-tab.active { background: var(--sidebar-active); color: #fff; }
.proj-pane { display: flex; flex-direction: column; gap: 2px; }
.new-proj-row {
  display: flex; align-items: center; gap: 8px; width: 100%;
  font: inherit; font-size: 13.5px; font-weight: 600; cursor: pointer; text-align: left;
  padding: 8px 10px; border-radius: 7px; margin-bottom: 4px;
  border: 1px dashed rgba(255,255,255,.25); background: transparent; color: var(--sidebar-ink);
  transition: background .15s;
}
.new-proj-row:hover { background: var(--sidebar-hover); color: #fff; }
.proj-col { display: flex; flex-direction: column; overflow: hidden; flex: 1; }
.proj-meta { font-size: 11px; color: var(--sidebar-muted); }
.proj-item.active .proj-meta { color: rgba(255,255,255,.75); }
.proj-empty {
  font-size: 12.5px; color: var(--sidebar-muted); padding: 8px 10px; line-height: 1.45;
}
.proj-list { display: flex; flex-direction: column; gap: 2px; }
.proj-item {
  display: flex; align-items: center; gap: 8px; padding: 8px 10px; border-radius: 7px;
  cursor: pointer; color: var(--sidebar-ink); font-size: 13.5px;
}
.proj-item:hover { background: var(--sidebar-hover); }
.proj-item.active { background: var(--sidebar-active); color: #fff; }
.proj-ic { opacity: .9; flex-shrink: 0; }
.proj-nm { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }

/* ---- project banner above the messages (chat scoped to a project) ---- */
.project-banner {
  display: flex; align-items: center; gap: 10px; flex-shrink: 0;
  padding: 9px 22px; background: #eef4ff; border-bottom: 1px solid var(--line);
  font-size: 13px; color: var(--navy);
}
.project-banner .pb-ic { font-size: 14px; }
.project-banner .pb-nm { font-weight: 600; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pb-open {
  font: inherit; font-size: 12.5px; font-weight: 600; cursor: pointer;
  padding: 4px 12px; border-radius: 7px; background: #fff; color: var(--brand);
  border: 1px solid #cddcff;
}
.pb-open:hover { background: var(--brand); color: #fff; border-color: var(--brand); }

/* ---- clickable document chips + generated-doc preview button ---- */
.doc-chip.clickable, .attach-chip .chip-nm.clickable { cursor: pointer; }
.doc-chip.clickable:hover { border-color: var(--brand); color: var(--brand); }
.attach-chip .chip-nm.clickable:hover { color: var(--brand); text-decoration: underline; }
.gen-doc-acts { display: inline-flex; gap: 8px; }
.doc-pv {
  display: inline-flex; align-items: center; gap: 2px; background: #fff; color: var(--navy);
  border: 1px solid var(--line); cursor: pointer; font: inherit; font-size: 13px; font-weight: 600;
  padding: 7px 14px; border-radius: 8px;
}
.doc-pv:hover { background: var(--panel-2); border-color: #cdd8ec; }

/* A turn that produced no document, or an answer the output limit cut short.
   Deliberately as prominent as .gen-doc: the user paid for the turn, so the
   explanation gets the same weight the download link would have had. */
.turn-notice {
  margin-top: 12px; padding: 11px 13px; border-radius: 10px;
  background: #fdf3f2; border: 1px solid #f0cfcb;
}
.turn-notice-tx { display: block; font-size: 13px; line-height: 1.55; color: var(--danger); }

/* ---- overlay (shared by preview + project panel) ---- */
.preview-overlay {
  position: fixed; inset: 0; z-index: 100; background: rgba(8,21,44,.5);
  display: flex; align-items: center; justify-content: center; padding: 24px;
}
.preview-panel, .project-panel {
  background: #fff; border-radius: 16px; width: 100%; max-width: 760px;
  max-height: calc(100vh - 48px); display: flex; flex-direction: column; overflow: hidden;
  box-shadow: 0 24px 60px -18px rgba(8,21,44,.55);
}
.preview-head, .pj-head {
  display: flex; align-items: center; gap: 12px; padding: 14px 20px;
  border-bottom: 1px solid var(--line); flex-shrink: 0; background: var(--panel-2);
}
.pv-title { font-family: var(--serif); font-size: 17px; color: var(--navy); flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pv-close {
  border: none; background: none; cursor: pointer; color: var(--muted);
  font-size: 16px; line-height: 1; padding: 6px 8px; border-radius: 6px; flex-shrink: 0;
}
.pv-close:hover { background: #e7ecf5; color: var(--navy); }

/* preview document body — reads like a page */
.preview-doc { overflow-y: auto; padding: 26px 34px; color: var(--ink); line-height: 1.6; }
.preview-doc h1, .preview-doc h2, .preview-doc h3, .preview-doc h4, .preview-doc h5, .preview-doc h6 {
  font-family: var(--serif); color: var(--navy); line-height: 1.25; margin: 18px 0 8px;
}
.preview-doc h1 { font-size: 22px; } .preview-doc h2 { font-size: 18px; }
.preview-doc h3 { font-size: 16px; } .preview-doc h4 { font-size: 14.5px; }
.preview-doc > :first-child { margin-top: 0; }
.preview-doc p { margin: 0 0 11px; }
.preview-doc ul, .preview-doc ol { margin: 8px 0; padding-left: 24px; }
.preview-doc li { margin-bottom: 5px; }
.preview-doc a { color: var(--brand); }
.preview-doc code {
  background: #e9eef7; color: var(--navy); padding: 1px 5px; border-radius: 4px;
  font-family: ui-monospace, Consolas, monospace; font-size: .9em;
}
.preview-doc pre { background: var(--navy); color: #e8eefb; padding: 13px 15px; border-radius: 10px; overflow-x: auto; margin: 10px 0; }
.preview-doc blockquote { margin: 10px 0; padding: 6px 14px; border-left: 3px solid var(--line); color: var(--muted); }
.preview-pre { white-space: pre-wrap; word-wrap: break-word; font: inherit; margin: 0; }
.pv-table { border-collapse: collapse; width: 100%; margin: 12px 0; font-size: 13.5px; }
.pv-table td { border: 1px solid var(--line); padding: 7px 10px; vertical-align: top; }
.pv-table tr:nth-child(odd) td { background: var(--panel-2); }
/* Markdown pipe tables render with .pv-table too, so a table looks the same
   in the chat bubble, in the preview panel and in the downloaded .docx. */
.pv-table th {
  border: 1px solid var(--line); padding: 7px 10px; text-align: left;
  font-weight: 700; color: var(--navy); background: var(--panel-2);
}

/* ---- project panel ---- */
.pj-badge { font-size: 18px; flex-shrink: 0; }
.pj-name { flex: 1; font-family: var(--serif); font-size: 17px; color: var(--navy); font-weight: 600; border: 1px solid transparent; background: transparent; padding: 6px 8px; }
.pj-name:hover { border-color: var(--line); background: #fff; }
.pj-body { overflow-y: auto; padding: 18px 22px 22px; display: flex; flex-direction: column; gap: 22px; }
.pj-section { display: flex; flex-direction: column; gap: 8px; }
.pj-section-hd { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.pj-label { font-size: 12px; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; color: var(--muted); }
.pj-instr { resize: vertical; min-height: 84px; line-height: 1.5; }
.pj-add, .pj-newchat {
  font: inherit; font-size: 13px; font-weight: 600; cursor: pointer; white-space: nowrap;
  padding: 6px 13px; border-radius: 8px; background: var(--panel-2); color: var(--navy); border: 1px solid var(--line);
}
.pj-add:hover, .pj-newchat:hover { background: #eef2fa; border-color: #cdd8ec; }
.pj-status { font-size: 12.5px; color: var(--muted); }
.pj-status:empty { display: none; }
.pj-files, .pj-chats { display: flex; flex-direction: column; gap: 6px; }
.pj-empty { font-size: 13px; color: var(--muted); padding: 4px 2px; }
.pj-file {
  display: flex; align-items: center; gap: 9px; padding: 8px 12px;
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 9px; font-size: 13.5px;
}
.pj-file-ic { flex-shrink: 0; }
.pj-file-nm { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--navy); }
.pj-file-sz { font-size: 12px; color: var(--muted); flex-shrink: 0; }
.pj-file-acts { display: inline-flex; gap: 6px; flex-shrink: 0; }
.pj-file-act {
  font: inherit; font-size: 12.5px; font-weight: 600; cursor: pointer;
  padding: 4px 10px; border-radius: 7px; background: #fff; color: var(--brand); border: 1px solid #cddcff;
}
.pj-file-act:hover { background: var(--brand); color: #fff; }
.pj-file-act.danger { color: var(--danger); border-color: #f0c2bd; }
.pj-file-act.danger:hover { background: var(--danger); color: #fff; }
.pj-chat {
  padding: 9px 12px; border-radius: 8px; cursor: pointer; font-size: 13.5px; color: var(--navy);
  border: 1px solid var(--line); background: #fff;
}
.pj-chat:hover { background: var(--panel-2); border-color: #cdd8ec; }
.pj-footer { border-top: 1px solid var(--line); padding-top: 16px; }
.pj-delete {
  font: inherit; font-size: 13px; font-weight: 600; cursor: pointer;
  padding: 8px 15px; border-radius: 8px; background: transparent; color: var(--danger); border: 1px solid var(--danger);
}
.pj-delete:hover { background: #fbe9e8; }

/* ---- sidebar Backup button badge (needs_restore) ---- */
.side-dot {
  width: 7px; height: 7px; border-radius: 50%; background: var(--brand-light);
  flex-shrink: 0; margin-left: auto;
  box-shadow: 0 0 0 3px rgba(59,130,246,.22);
}

/* ---- backup and sync panel (shares .preview-overlay with preview/projects) ---- */
.sync-panel {
  background: #fff; border-radius: 16px; width: 100%; max-width: 520px;
  max-height: calc(100vh - 48px); display: flex; flex-direction: column; overflow: hidden;
  box-shadow: 0 24px 60px -18px rgba(8,21,44,.55);
}
.sy-head {
  display: flex; align-items: center; gap: 10px; padding: 14px 20px;
  border-bottom: 1px solid var(--line); flex-shrink: 0; background: var(--panel-2);
}
.sy-head-ic { font-size: 16px; flex-shrink: 0; }
.sy-title { font-family: var(--serif); font-size: 17px; color: var(--navy); flex: 1; }
.sy-body { overflow-y: auto; padding: 18px 22px 22px; display: flex; flex-direction: column; gap: 12px; }

.sy-lead { margin: 0; font-size: 15px; font-weight: 600; color: var(--navy); line-height: 1.5; }
.sy-body-p { margin: 0; font-size: 13.5px; color: var(--ink); line-height: 1.6; }
.sy-note { margin: 0; font-size: 12.5px; color: var(--muted); line-height: 1.55; }
.sy-warn {
  font-size: 13px; line-height: 1.55; color: var(--danger);
  background: #fdeeec; border: 1px solid #f0c2bd; border-radius: 10px; padding: 10px 13px;
}
.sy-err { font-size: 13px; color: var(--danger); line-height: 1.5; }
.sy-err:empty { display: none; }
.sy-feedback { font-size: 12.5px; color: var(--ok); line-height: 1.5; }
.sy-feedback:empty { display: none; }

/* status block when backup is on */
.sy-status {
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px;
  display: flex; flex-direction: column; gap: 4px;
}
.sy-stat { display: flex; align-items: center; gap: 9px; }
.sy-stat-txt { font-size: 14px; font-weight: 600; color: var(--navy); }
.sy-stat-sub { font-size: 12.5px; color: var(--muted); line-height: 1.5; }
.sy-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; background: var(--muted); }
.sy-dot.on { background: var(--ok); }
.sy-dot.warn { background: #d08700; }

/* the one-time recovery code */
.sy-code {
  background: var(--panel-2); border: 1px dashed #c7d2e6; border-radius: 10px;
  padding: 16px 12px; text-align: center; color: var(--navy);
  font-family: ui-monospace, "Cascadia Code", Consolas, monospace;
  font-size: 19px; font-weight: 600; letter-spacing: 2px;
  word-break: break-all; user-select: all;
}
.sy-code-acts { display: flex; gap: 8px; }

/* buttons */
.sy-btn {
  font: inherit; font-size: 13.5px; font-weight: 600; cursor: pointer; white-space: nowrap;
  padding: 9px 16px; border-radius: 8px;
  background: #fff; color: var(--navy); border: 1px solid var(--line);
  transition: background .15s, border-color .15s;
}
.sy-btn:hover { background: var(--panel-2); border-color: #cdd8ec; }
.sy-btn.primary { background: var(--brand); color: #fff; border-color: transparent; }
.sy-btn.primary:hover { background: var(--brand-dark); }
.sy-btn.danger { background: transparent; color: var(--danger); border-color: var(--danger); }
.sy-btn.danger:hover { background: #fbe9e8; }
.sy-btn:disabled { opacity: .5; cursor: not-allowed; }
.sy-btn:disabled:hover { background: #fff; border-color: var(--line); }
.sy-btn.primary:disabled:hover { background: var(--brand); }
.sy-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 4px; }
.sy-row { display: flex; gap: 8px; flex-wrap: wrap; border-top: 1px solid var(--line); padding-top: 14px; }

/* confirm checkbox + code entry */
.sy-check {
  display: flex; align-items: flex-start; gap: 9px; margin: 0;
  font-size: 13.5px; color: var(--ink); line-height: 1.5; cursor: pointer;
}
.sy-cb { width: auto; margin: 2px 0 0; flex-shrink: 0; accent-color: var(--brand); }
.sy-input { letter-spacing: 1px; text-align: center; font-size: 15px; }

/* progress while setup or restore runs */
.sy-busy { display: flex; align-items: center; gap: 10px; font-size: 13.5px; color: var(--muted); padding: 8px 0; }
.sy-spin {
  width: 15px; height: 15px; flex-shrink: 0; border-radius: 50%;
  border: 2px solid var(--line); border-top-color: var(--brand);
  animation: syspin .8s linear infinite;
}
@keyframes syspin { to { transform: rotate(360deg); } }

@media (max-width: 720px) {
  .chat { grid-template-columns: 1fr; }
  .side { grid-row: auto; max-height: 190px; }
  .billing-card { flex-direction: column; gap: 14px; }
  .preview-doc { padding: 20px; }
  .sy-code { font-size: 16px; letter-spacing: 1px; }
}

/* ---------------- Libraries (flag-gated; LIBRARIES_PLAN.md) ---------------- */
.lib-drop {
  border: 2px dashed var(--line);
  border-radius: 12px;
  padding: 26px 18px;
  text-align: center;
  color: var(--muted);
  cursor: pointer;
  font-size: 13.5px;
  transition: border-color .15s, background .15s;
}
.lib-drop:hover, .lib-drop.over { border-color: var(--brand); background: var(--panel-2); }
.lib-drop-ic { font-size: 20px; margin-bottom: 6px; }
.lib-drop-sub { font-size: 11.5px; margin-top: 6px; opacity: .8; }
.lib-doc-st { white-space: nowrap; }

/* Citation chips + hover popover (Libraries retrieval) */
.cite {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  margin: 0 2px;
  border-radius: 8px;
  background: var(--brand);
  color: #fff;
  font-size: 10.5px;
  font-weight: 600;
  line-height: 1;
  vertical-align: baseline;
  cursor: default;
}
.cite:hover, .cite:focus { background: var(--brand-dark); outline: none; }
.cite-pop {
  position: fixed;
  z-index: 200;
  max-width: 420px;
  max-height: 300px;
  overflow-y: auto;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: 0 8px 28px rgba(13, 27, 52, .18);
  padding: 12px 14px;
  font-size: 12.5px;
}
.cite-pop.hidden { display: none; }
.cite-pop-hd { display: flex; gap: 8px; align-items: baseline; margin-bottom: 6px; flex-wrap: wrap; }
.cite-pop-doc { font-weight: 600; color: var(--ink); }
.cite-pop-loc { color: var(--muted); font-size: 11.5px; }
.cite-pop-note { color: var(--muted); font-size: 11px; font-style: italic; margin-bottom: 4px; }
.cite-pop-tx { color: var(--ink); white-space: pre-wrap; line-height: 1.5; }
/* The library pill when at least one library is selected: same "something is
   chosen" tint the selected model row uses, so the two pills read as one
   system. (The old left-anchored .lib-menu override died with the icon
   button; the menu now right-aligns like the model menu.) */
.lib-btn.lib-on { color: var(--brand); background: #eef4ff; border-color: #d5deee; }
