/* Super Intelligence Dog — one stylesheet for every surface.
 *
 * Theme: LIGHT-first, with a persistent dark mode. The theme is resolved
 * once (localStorage override → OS prefers-color-scheme → light) and set as
 * `data-theme` on <html> by /static/theme.js before paint. Public pages read
 * exactly like the rest of the BellerCreatives family (light, Inter), while
 * the dark variant keeps a deep-slate workspace for night work.
 *
 * Modern baseline: system type stack with optional Inter, soft shadows on
 * elevated cards, 12-14px radii, focus-visible rings, motion on interactive
 * elements only (prefers-reduced-motion respected).
 */

:root {
  --bg: #f7f8fa;
  --panel: #ffffff;
  --panel-2: #f0f2f5;
  --line: #e3e6ea;
  --fg: #101828;
  --mut: #5d6b82;
  --acc: #4f46e5;
  --acc-fg: #ffffff;
  --acc-soft: #eef0ff;
  --ok: #16a34a;
  --bad: #dc2626;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 4px 12px rgba(16, 24, 40, .05);
  --shadow-soft: 0 1px 2px rgba(16, 24, 40, .06);
  --radius: 12px;
  color-scheme: light;
}

[data-theme="dark"] {
  --bg: #0c1017;
  --panel: #141a23;
  --panel-2: #0f141b;
  --line: #263140;
  --fg: #e6edf3;
  --mut: #94a3b8;
  --acc: #818cf8;
  --acc-fg: #0c1017;
  --acc-soft: #1c2340;
  --ok: #34d399;
  --bad: #f87171;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 6px 16px rgba(0, 0, 0, .35);
  --shadow-soft: 0 1px 2px rgba(0, 0, 0, .4);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--fg);
  font: 15px/1.6 Inter, system-ui, "Segoe UI", Roboto, -apple-system, sans-serif;
  display: flex; flex-direction: column;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
a { color: var(--acc); }
h1, h2, h3, h4 { letter-spacing: -0.015em; line-height: 1.25; }
code, pre { font-family: ui-monospace, "Cascadia Code", Consolas, monospace; }
.hidden { display: none !important; }
.muted { color: var(--mut); font-size: 13px; }

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}

/* ---- top bar ------------------------------------------------------------ */
.topbar {
  display: flex; align-items: center; gap: 14px; padding: 12px 20px;
  background: color-mix(in srgb, var(--panel) 82%, transparent);
  backdrop-filter: blur(10px) saturate(1.4);
  -webkit-backdrop-filter: blur(10px) saturate(1.4);
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 40;
}
.brand { font-weight: 700; letter-spacing: -0.01em; }
.spacer { flex: 1; }
.stat { font-size: 13px; color: var(--mut); }
.stat b { color: var(--fg); }
.link-btn {
  color: var(--fg); text-decoration: none; font-size: 13px; font-weight: 500;
  padding: 6px 12px; border: 1px solid var(--line); border-radius: 999px;
  background: var(--panel);
  transition: border-color .15s ease, background .15s ease, transform .15s ease;
}
.link-btn:hover { border-color: var(--acc); color: var(--acc); }
.link-btn:active { transform: translateY(1px); }

/* theme toggle (injected by theme.js) */
#theme-toggle {
  width: 34px; height: 34px; padding: 0; display: inline-flex; align-items: center;
  justify-content: center; border: 1px solid var(--line); border-radius: 999px;
  background: var(--panel); color: var(--fg); cursor: pointer; font-size: 15px;
  transition: border-color .15s ease, background .15s ease;
}
#theme-toggle:hover { border-color: var(--acc); }

/* ---- layout ------------------------------------------------------------- */
.layout { flex: 1; display: grid; grid-template-columns: 260px 1fr 320px; min-height: 0; }

.sidebar, .rail {
  background: var(--panel); border-right: 1px solid var(--line);
  padding: 12px; overflow-y: auto; min-height: 0;
}
.rail { border-right: none; border-left: 1px solid var(--line); }

.panel-block { margin-bottom: 16px; }
.lbl {
  display: block; font-size: 11.5px; font-weight: 600; text-transform: uppercase;
  letter-spacing: .06em; color: var(--mut); margin: 8px 0 4px;
}
.row { margin-bottom: 8px; }
.row.between { display: flex; align-items: center; justify-content: space-between; }

input, select, textarea, button {
  font: inherit; color: var(--fg); background: var(--panel-2);
  border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px; width: 100%;
  transition: border-color .15s ease, box-shadow .15s ease;
}
textarea { resize: vertical; min-height: 60px; }
button { cursor: pointer; }
:focus-visible {
  outline: 2px solid var(--acc); outline-offset: 1px; border-radius: 10px;
}
button.mini {
  background: var(--acc); color: var(--acc-fg); border-color: var(--acc);
  font-weight: 600; font-size: 13px; padding: 7px 12px; width: auto;
}
button.mini:hover { filter: brightness(1.08); }
button.link { background: none; border: none; color: var(--mut); width: auto; padding: 0 6px; font-size: 12px; }
button.link:hover { color: var(--bad); }
#send { width: auto; padding: 0 22px; background: var(--acc); color: var(--acc-fg); border-color: var(--acc); font-weight: 600; }
#send:disabled { opacity: .5; }

/* ---- conversation lists -------------------------------------------------- */
.list { display: flex; flex-direction: column; gap: 4px; }
.conv-item, .expert-item {
  padding: 8px 10px; border-radius: 10px; cursor: pointer; border: 1px solid transparent;
  transition: background .12s ease, border-color .12s ease;
}
.conv-item:hover, .expert-item:hover { background: var(--panel-2); }
.conv-item.active, .expert-item.active { background: var(--acc-soft); border-color: var(--acc); }
.conv-title { font-size: 14px; }
.expert-name { font-size: 14px; font-weight: 600; }

.tabs { display: flex; gap: 6px; margin-top: 8px; }
.tab {
  flex: 1; background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px;
  font-size: 13px; padding: 7px; font-weight: 500;
}
.tab.active { background: var(--acc); border-color: var(--acc); color: var(--acc-fg); font-weight: 600; }

/* ---- chat ---------------------------------------------------------------- */
.main { display: flex; flex-direction: column; min-height: 0; }
.messages { flex: 1; overflow-y: auto; padding: 22px; max-width: 900px; width: 100%; margin: 0 auto; }
.empty { color: var(--mut); text-align: center; margin-top: 30vh; }
.empty-note {
  margin: 12px auto 0; max-width: 560px; font-size: 12.5px; line-height: 1.5; opacity: .85;
}
.msg { margin-bottom: 18px; }
.msg-role {
  font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .07em;
  color: var(--mut); margin-bottom: 4px;
}
.msg-body {
  white-space: pre-wrap; background: var(--panel); border: 1px solid var(--line);
  border-radius: 14px; padding: 12px 14px; box-shadow: var(--shadow-soft);
}
.msg.user .msg-body { background: var(--acc-soft); }

/* markdown-rendered assistant bodies switch to block layout */
.msg-body.md { white-space: normal; }
.msg-body.md > :first-child { margin-top: 0; }
.msg-body.md > :last-child { margin-bottom: 0; }
.msg-body.md p { margin: 0 0 8px; }
.msg-body.md h1, .msg-body.md h2, .msg-body.md h3, .msg-body.md h4 {
  margin: 14px 0 6px; font-size: 1.12em;
}
.msg-body.md h1 { font-size: 1.3em; }
.msg-body.md ul, .msg-body.md ol { margin: 0 0 8px; padding-left: 22px; }
.msg-body.md li { margin: 2px 0; }
.msg-body.md hr { border: none; border-top: 1px solid var(--line); margin: 12px 0; }
.msg-body.md .md-quote {
  border-left: 3px solid var(--line); padding: 2px 0 2px 12px;
  color: var(--mut); margin: 0 0 8px;
}
.msg-body.md .md-code {
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 6px;
  padding: 1px 5px; font-size: .88em;
}

/* fenced code blocks: language label + copy affordance */
.codeblock {
  margin: 8px 0; border: 1px solid var(--line); border-radius: 10px;
  overflow: hidden; background: var(--panel-2);
}
.codeblock-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 3px 6px 3px 12px; border-bottom: 1px solid var(--line);
}
.codeblock-lang {
  font-size: 11px; font-weight: 600; text-transform: uppercase;
  letter-spacing: .06em; color: var(--mut);
}
.codeblock pre {
  margin: 0; padding: 10px 12px; overflow-x: auto;
  font-size: 12.5px; line-height: 1.55;
}
.codeblock pre code { white-space: pre; }
.copy-btn {
  width: auto; padding: 2px 10px; font-size: 12px; border-radius: 8px;
  background: var(--panel); border: 1px solid var(--line); color: var(--mut);
  font-weight: 500;
}
.copy-btn:hover { border-color: var(--acc); color: var(--acc); }
.copy-btn.copied { border-color: var(--ok); color: var(--ok); }
.copy-btn.copy-failed { border-color: var(--bad); color: var(--bad); }

/* mid-stream upstream errors surface as a visible error state */
.msg-body.msg-error { border-color: var(--bad); background: color-mix(in srgb, var(--bad) 7%, var(--panel)); }
.msg-error .error-title { color: var(--bad); font-weight: 600; font-size: 13px; margin-bottom: 2px; }
.msg-error .error-detail { font-size: 13px; white-space: pre-wrap; }

.composer {
  display: flex; gap: 8px; padding: 12px 16px; border-top: 1px solid var(--line);
  background: var(--panel); align-items: stretch; flex-wrap: wrap;
}
.composer textarea { height: 48px; min-height: 48px; }
.composer textarea:disabled { opacity: .6; cursor: not-allowed; }

/* BC-151 chat tool surface: attach controls + web-search opt-in above the
   textarea. The composer keeps the textarea+send row on its own line. */
.composer-tools { flex: 1 1 100%; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.composer-tools button { width: auto; }
.composer-row { flex: 1 1 100%; display: flex; gap: 8px; align-items: stretch; }
.composer-row textarea { flex: 1; }
.composer-toggle {
  display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px;
  color: var(--mut); cursor: pointer;
}
.composer-toggle input { width: auto; }
.composer-toggle input:disabled + span { opacity: .6; }
.attach-chips { display: flex; flex-wrap: wrap; gap: 4px; }
.attach-chip {
  display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line);
  border-radius: 999px; padding: 2px 8px; font-size: 11.5px; color: var(--mut);
}
.attach-chip button {
  width: auto; padding: 0; border: none; background: none; color: var(--mut);
  cursor: pointer; font-size: 13px; line-height: 1;
}

.mini-form { margin-top: 10px; display: flex; flex-direction: column; gap: 6px; }
.mem-item {
  display: flex; justify-content: space-between; gap: 6px; font-size: 13px;
  padding: 6px 0; border-bottom: 1px solid var(--line);
}

.footer {
  padding: 10px 16px; border-top: 1px solid var(--line); background: var(--panel);
  font-size: 12px; color: var(--mut); text-align: center;
}
.footer a { color: var(--mut); }
.footer a:hover { color: var(--acc); }

/* ---- toasts -------------------------------------------------------------- */
#toasts { position: fixed; right: 16px; bottom: 60px; display: flex; flex-direction: column; gap: 8px; z-index: 50; }
.toast {
  padding: 10px 14px; border-radius: 12px; background: var(--panel);
  border: 1px solid var(--line); font-size: 13px; box-shadow: var(--shadow);
}
.toast.ok { border-color: var(--ok); }
.toast.bad { border-color: var(--bad); }

/* ---- long-form pages (docs / legal) ------------------------------------- */
.doc-page { max-width: 780px; width: 100%; min-width: 0; margin: 0 auto; padding: 40px 20px 64px; }
.doc-page table { width: 100%; border-collapse: collapse; }
@media (max-width: 700px) {
  .doc-page table { display: block; overflow-x: auto; white-space: nowrap; }
}
.doc-page h1 { font-size: 30px; margin-top: 0; }
.doc-page h2 { margin-top: 30px; font-size: 21px; }
.doc-page h3 { margin-top: 22px; font-size: 17px; }
.doc-page pre {
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 12px;
  padding: 14px; overflow-x: auto; font-size: 12.5px; line-height: 1.55;
  box-shadow: var(--shadow-soft);
}

/* ---- admin console ------------------------------------------------------- */
.admin { max-width: 900px; margin: 0 auto; padding: 28px 20px 60px; }
.admin section {
  background: var(--panel); border: 1px solid var(--line); border-radius: 14px;
  padding: 18px; margin-bottom: 16px; box-shadow: var(--shadow-soft);
}
.admin table { width: 100%; border-collapse: collapse; font-size: 14px; }
.admin th, .admin td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--line); }
.admin .grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }

@media (max-width: 1000px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar, .rail { display: none; }
}
