/* AFB Brain — core layout, sidebar, thread, composer.
   Palette + structure held faithful to ui_previews/chosen_design.html.
   Component-level styles (working blocks, citations, brief, unlock, toasts)
   live in components.css. */

:root {
  --bg: #ffffff;
  --bg-soft: #f7f7f8;
  --surface: #ffffff;
  --ink: #1a1a1e;
  --ink-2: #55555e;
  --ink-3: #8e8e98;
  --line: #e6e6ea;
  --line-soft: #efeff2;
  --accent: #0d7d5f;
  --accent-soft: rgba(13,125,95,.08);
  --user-bubble: #f1f1f3;
  --code-bg: #f7f7f8;
  --sidebar-bg: #171719;
  --sidebar-ink: #d4d4d8;
  --sidebar-ink-dim: #85858d;
  --sidebar-hover: rgba(255,255,255,.06);
  --sidebar-active: rgba(255,255,255,.10);
  --shadow-composer: 0 0 0 1px var(--line), 0 2px 12px rgba(0,0,0,.05);
  --shadow-composer-focus: 0 0 0 1px #c9c9cf, 0 4px 20px rgba(0,0,0,.08);
}
[data-theme="dark"] {
  --bg: #1e1e21;
  --bg-soft: #232327;
  --surface: #26262a;
  --ink: #ececef;
  --ink-2: #a8a8b0;
  --ink-3: #6f6f78;
  --line: #37373c;
  --line-soft: #2d2d32;
  --accent: #3dbf97;
  --accent-soft: rgba(61,191,151,.10);
  --user-bubble: #2e2e33;
  --code-bg: #232327;
  --sidebar-bg: #141416;
  --sidebar-ink: #d4d4d8;
  --sidebar-ink-dim: #7c7c84;
  --sidebar-hover: rgba(255,255,255,.05);
  --sidebar-active: rgba(255,255,255,.09);
  --shadow-composer: 0 0 0 1px var(--line), 0 2px 12px rgba(0,0,0,.25);
  --shadow-composer-focus: 0 0 0 1px #4a4a52, 0 4px 20px rgba(0,0,0,.35);
}

* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { height: 100%; }
body {
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 15px;
  line-height: 1.65;
  color: var(--ink);
  background: var(--bg);
  display: flex;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
button:disabled { cursor: default; }
svg { display: block; flex: none; }

/* ---------- Sidebar ---------- */
.sidebar {
  width: 244px;
  flex: none;
  background: var(--sidebar-bg);
  color: var(--sidebar-ink);
  display: flex;
  flex-direction: column;
  padding: 10px 8px;
  font-size: 13.5px;
}
.brand {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 8px 10px 14px;
  font-weight: 550;
  font-size: 14px;
  letter-spacing: .01em;
  color: #fff;
}
.brand-mark {
  width: 22px; height: 22px;
  border-radius: 6px;
  background: linear-gradient(140deg, #12a37f, #0b6b52);
  display: grid; place-items: center;
  font-size: 11px; font-weight: 600; color: #fff;
  letter-spacing: 0;
  flex: none;
}
.new-chat {
  display: flex; align-items: center; gap: 9px;
  width: 100%;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid rgba(255,255,255,.12);
  color: #fff;
  font-weight: 500;
  font-size: 13.5px;
  transition: background .12s ease;
}
.new-chat:hover { background: var(--sidebar-hover); }

.history { flex: 1; overflow-y: auto; margin-top: 18px; scrollbar-width: thin; scrollbar-color: rgba(255,255,255,.15) transparent; }
.day-label {
  font-size: 11px;
  font-weight: 550;
  letter-spacing: .05em;
  text-transform: uppercase;
  color: var(--sidebar-ink-dim);
  padding: 6px 10px 4px;
}
.day-label + .day-label, .convo + .day-label { margin-top: 16px; }
.convo {
  display: block;
  width: 100%;
  text-align: left;
  padding: 7px 10px;
  border-radius: 8px;
  color: var(--sidebar-ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: background .12s ease;
}
.convo:hover { background: var(--sidebar-hover); }
.convo.active { background: var(--sidebar-active); color: #fff; }
.history-empty { padding: 10px; color: var(--sidebar-ink-dim); font-size: 12.5px; line-height: 1.5; }

.sidebar-foot {
  border-top: 1px solid rgba(255,255,255,.08);
  margin-top: 10px;
  padding-top: 10px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.foot-row {
  display: flex; align-items: center; gap: 10px;
  width: 100%;
  padding: 7px 10px;
  border-radius: 8px;
  color: var(--sidebar-ink);
  transition: background .12s ease;
  text-align: left;
}
.foot-row:not(:disabled):hover { background: var(--sidebar-hover); }
.foot-row:disabled { opacity: .55; }
.avatar {
  width: 24px; height: 24px;
  border-radius: 50%;
  background: #b45309;
  color: #fff;
  display: grid; place-items: center;
  font-size: 10.5px; font-weight: 600;
  flex: none;
}
.foot-row .sub { margin-left: auto; font-size: 11px; color: var(--sidebar-ink-dim); }

/* ---------- Main ---------- */
.main { flex: 1; display: flex; flex-direction: column; min-width: 0; position: relative; }

.topbar {
  height: 52px;
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  font-size: 13.5px;
  color: var(--ink-2);
}
.topbar .model {
  display: flex; align-items: center; gap: 6px;
  font-weight: 500; color: var(--ink);
  padding: 5px 10px; border-radius: 8px;
}
.topbar .model .ver { font-weight: 400; color: var(--ink-3); }
.mode-tag {
  font-family: "JetBrains Mono", monospace;
  font-size: 10.5px;
  font-weight: 500;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--accent);
  background: var(--accent-soft);
  border-radius: 5px;
  padding: 1px 6px;
}
.theme-toggle {
  width: 32px; height: 32px;
  border-radius: 8px;
  display: grid; place-items: center;
  color: var(--ink-2);
  transition: background .12s ease;
}
.theme-toggle:hover { background: var(--bg-soft); }
.theme-toggle .moon { display: none; }
[data-theme="dark"] .theme-toggle .sun { display: none; }
[data-theme="dark"] .theme-toggle .moon { display: block; }

/* ---------- Thread ---------- */
.thread {
  flex: 1;
  overflow-y: auto;
  padding: 8px 24px 40px;
}
.col { max-width: 720px; margin: 0 auto; }

.msg { padding: 14px 0; }
.msg + .msg { margin-top: 4px; }

.msg-user { display: flex; justify-content: flex-end; }
.msg-user .bubble {
  background: var(--user-bubble);
  border-radius: 18px;
  padding: 9px 16px;
  max-width: 78%;
  font-size: 15px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.msg-ai { position: relative; }
.msg-ai .body p { margin: 0 0 12px; }
.msg-ai .body p:last-child { margin-bottom: 0; }
.msg-ai .body strong { font-weight: 550; }
.msg-ai .body code {
  font-family: "JetBrains Mono", monospace;
  font-size: 13px;
  background: var(--code-bg);
  border: 1px solid var(--line-soft);
  border-radius: 5px;
  padding: 1px 5px;
}
.cursor::after {
  content: "";
  display: inline-block;
  width: 7px; height: 15px;
  margin-left: 1px;
  vertical-align: -2px;
  background: var(--ink-3);
  border-radius: 1px;
  animation: blink 1s step-end infinite;
}
@keyframes blink { 50% { opacity: 0; } }

/* ---------- Composer ---------- */
.composer-zone {
  flex: none;
  padding: 0 24px 14px;
  background: linear-gradient(to bottom, transparent, var(--bg) 32%);
}
.composer {
  max-width: 720px;
  margin: 0 auto;
  display: flex;
  align-items: flex-end;
  gap: 4px;
  background: var(--surface);
  border-radius: 26px;
  padding: 7px 8px 7px 14px;
  box-shadow: var(--shadow-composer);
  transition: box-shadow .15s ease;
}
.composer:focus-within { box-shadow: var(--shadow-composer-focus); }
.composer textarea {
  flex: 1;
  border: 0;
  outline: 0;
  resize: none;
  background: transparent;
  color: var(--ink);
  font: inherit;
  font-size: 15px;
  line-height: 1.5;
  padding: 7px 4px;
  max-height: 160px;
}
.composer textarea::placeholder { color: var(--ink-3); }
.icon-btn {
  width: 34px; height: 34px;
  flex: none;
  border-radius: 50%;
  display: grid; place-items: center;
  color: var(--ink-3);
  transition: background .12s ease, color .12s ease;
}
.icon-btn:not(:disabled):hover { background: var(--bg-soft); color: var(--ink); }
.icon-btn:disabled { opacity: .4; }
.send-btn {
  width: 34px; height: 34px;
  flex: none;
  border-radius: 50%;
  display: grid; place-items: center;
  background: var(--ink);
  color: var(--bg);
  transition: opacity .12s ease, transform .12s ease;
}
.send-btn:hover { opacity: .85; }
.send-btn:active { transform: scale(.94); }
.send-btn:disabled { opacity: .3; }
.microcopy {
  max-width: 720px;
  margin: 9px auto 0;
  text-align: center;
  font-size: 11.5px;
  color: var(--ink-3);
}

/* Scrollbars */
.thread { scrollbar-width: thin; scrollbar-color: var(--line) transparent; }
.thread::-webkit-scrollbar, .history::-webkit-scrollbar { width: 6px; }
.thread::-webkit-scrollbar-thumb { background: var(--line); border-radius: 3px; }
.history::-webkit-scrollbar-thumb { background: rgba(255,255,255,.15); border-radius: 3px; }

@media (max-width: 860px) {
  .sidebar { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .001ms !important; transition-duration: .001ms !important; }
}
