/* ── Voltaic consumer chat — dark, modern, minimal ───────────────────────── */

/* The `hidden` attribute must always win over explicit display rules below. */
[hidden] { display: none !important; }

:root {
  --bg:          #f6f8fb;
  --bg-elev:     #ffffff;
  --bg-elev-2:   #eef1f5;
  --border:      #dde2e9;
  --border-soft: #e8ecf1;
  --fg:          #121722;
  --fg-muted:    #58606d;
  --fg-dim:      #8b93a1;
  --accent:      #2f6fed;
  --accent-2:    #1457d6;
  --accent-soft: rgba(47, 111, 237, 0.10);
  --user-bub:    #e8f0ff;
  --err:         #d92d20;
  --ok:          #1a8a44;
  --radius:      16px;
  --maxw:        760px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background:
    radial-gradient(1200px 600px at 50% -10%, rgba(47,111,237,0.07), transparent 60%),
    var(--bg);
  color: var(--fg);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
}

/* ── Top bar ─────────────────────────────────────────────────────────────── */
.topbar {
  flex: 0 0 auto;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  border-bottom: 1px solid var(--border-soft);
  background: rgba(255, 255, 255, 0.75);
  backdrop-filter: blur(10px);
  position: sticky;
  top: 0;
  z-index: 10;
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand-logo { height: 22px; width: auto; display: block; }
.bolt { width: 20px; height: 20px; fill: var(--accent); filter: drop-shadow(0 0 6px rgba(112,184,255,0.5)); }
.brand-name { font-weight: 600; font-size: 16px; letter-spacing: 0.2px; }
.status-dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--fg-dim); margin-left: 4px;
}
.status-dot[data-state="ok"]   { background: var(--ok);  box-shadow: 0 0 6px var(--ok); }
.status-dot[data-state="warn"] { background: #d29922; }
.status-dot[data-state="err"]  { background: var(--err); }

.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 36px; height: 36px;
  border: none; background: transparent; color: var(--fg-muted);
  border-radius: 10px; cursor: pointer; transition: background 0.15s, color 0.15s;
}
.icon-btn:hover { background: var(--bg-elev-2); color: var(--fg); }

/* ── Chat transcript ─────────────────────────────────────────────────────── */
.chat {
  flex: 1 1 auto;
  overflow-y: auto;
  scroll-behavior: smooth;
  padding: 24px 16px 8px;
}
.chat::-webkit-scrollbar { width: 10px; }
.chat::-webkit-scrollbar-thumb { background: var(--border); border-radius: 6px; }

.msg {
  max-width: var(--maxw);
  margin: 0 auto 18px;
  display: flex;
  gap: 12px;
}
.msg.user { justify-content: flex-end; }
.msg .avatar {
  flex: 0 0 auto;
  width: 28px; height: 28px; border-radius: 8px;
  display: grid; place-items: center;
  font-size: 12px; font-weight: 700;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #ffffff;
  margin-top: 2px;
}
.msg.user .avatar { display: none; }
.msg .body { min-width: 0; max-width: 100%; }
.msg.user .body { max-width: 80%; }

.bubble {
  font-size: 15px;
  line-height: 1.65;
  white-space: pre-wrap;
  word-wrap: break-word;
}
.msg.user .bubble {
  background: var(--user-bub);
  padding: 11px 15px;
  border-radius: 18px 18px 4px 18px;
}
.msg.assistant .bubble { padding-top: 2px; }
.msg.system .bubble { color: var(--fg-muted); font-size: 13.5px; }

/* thinking dots */
.thinking { display: inline-flex; gap: 5px; padding: 8px 2px; }
.thinking span {
  width: 7px; height: 7px; border-radius: 50%; background: var(--fg-dim);
  animation: blink 1.3s infinite both;
}
.thinking span:nth-child(2) { animation-delay: 0.2s; }
.thinking span:nth-child(3) { animation-delay: 0.4s; }
@keyframes blink { 0%, 80%, 100% { opacity: 0.25; } 40% { opacity: 1; } }

/* subtle "why" affordance under an answer */
.why {
  margin-top: 8px;
  font-size: 12.5px;
  color: var(--fg-dim);
}
.why .why-toggle {
  background: none; border: none; color: var(--fg-dim);
  cursor: pointer; padding: 0; font: inherit; display: inline-flex; gap: 6px; align-items: center;
}
.why .why-toggle:hover { color: var(--accent); }
.why-chip {
  display: inline-block; padding: 1px 8px; border-radius: 999px;
  background: var(--accent-soft); color: var(--accent); font-size: 11px;
}
.why-body {
  margin-top: 8px; padding: 10px 12px;
  background: var(--bg-elev); border: 1px solid var(--border-soft);
  border-radius: 10px; color: var(--fg-muted); font-size: 12.5px; line-height: 1.5;
}
.why-body ul { margin: 6px 0 0; padding-left: 18px; }

/* ── Welcome ─────────────────────────────────────────────────────────────── */
.welcome {
  max-width: 640px;
  margin: 8vh auto 0;
  text-align: center;
}
.welcome-bolt {
  width: 56px; height: 56px; margin: 0 auto 18px;
  border-radius: 16px; display: grid; place-items: center;
  background: var(--accent-soft);
}
.welcome-bolt svg { width: 28px; height: 28px; fill: var(--accent); }
.welcome h1 { font-size: 30px; font-weight: 650; margin: 0 0 8px; letter-spacing: -0.5px; }
.welcome-sub { color: var(--fg-muted); font-size: 15px; margin: 0 0 28px; }
.examples {
  display: grid; grid-template-columns: 1fr 1fr; gap: 10px;
  max-width: 540px; margin: 0 auto;
}
.chip {
  text-align: left;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  color: var(--fg);
  border-radius: 12px;
  padding: 13px 15px;
  font-size: 14px;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s, transform 0.1s;
}
.chip:hover { border-color: var(--accent); background: var(--bg-elev-2); transform: translateY(-1px); }

/* ── Composer ────────────────────────────────────────────────────────────── */
.composer {
  flex: 0 0 auto;
  padding: 10px 16px 16px;
  background: linear-gradient(to top, var(--bg) 70%, transparent);
}
.composer-inner {
  max-width: var(--maxw);
  margin: 0 auto;
  display: flex;
  align-items: flex-end;
  gap: 8px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 26px;
  padding: 7px 7px 7px 18px;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.composer-inner:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
#prompt {
  flex: 1 1 auto;
  border: none; outline: none; resize: none;
  background: transparent; color: var(--fg);
  font: inherit; font-size: 15px; line-height: 1.5;
  max-height: 200px; padding: 8px 0;
}
#prompt::placeholder { color: var(--fg-dim); }
.send {
  flex: 0 0 auto;
  width: 38px; height: 38px; border-radius: 50%;
  border: none; cursor: pointer;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #ffffff;
  display: grid; place-items: center;
  transition: opacity 0.15s, transform 0.1s;
}
.send:hover { transform: scale(1.05); }
.send:disabled { opacity: 0.4; cursor: default; transform: none; }
.hint {
  max-width: var(--maxw);
  margin: 8px auto 0;
  text-align: center;
  color: var(--fg-dim);
  font-size: 11.5px;
}
.hint kbd {
  background: var(--bg-elev-2); border: 1px solid var(--border);
  border-radius: 4px; padding: 0 5px; font-size: 11px;
}

/* ── Tools slide-over ────────────────────────────────────────────────────── */
.scrim {
  position: fixed; inset: 0; z-index: 40;
  background: rgba(0, 0, 0, 0.5);
}
.tools {
  position: fixed; top: 0; right: 0; bottom: 0; z-index: 41;
  width: min(380px, 92vw);
  background: var(--bg-elev);
  border-left: 1px solid var(--border);
  padding: 0 18px 24px;
  overflow-y: auto;
  box-shadow: -20px 0 60px rgba(0, 0, 0, 0.45);
}
.tools-head {
  position: sticky; top: 0; background: var(--bg-elev);
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 0; margin-bottom: 4px;
  border-bottom: 1px solid var(--border-soft);
}
.tools-head h3 { margin: 0; font-size: 16px; }
.tools-section { padding: 18px 0; border-bottom: 1px solid var(--border-soft); }
.tools-section:last-child { border-bottom: none; }
.tools-section h4 { margin: 0 0 4px; font-size: 14px; }
.tools-help { margin: 0 0 12px; font-size: 12.5px; color: var(--fg-muted); line-height: 1.45; }
.tools textarea {
  width: 100%; background: var(--bg); border: 1px solid var(--border);
  border-radius: 10px; color: var(--fg); padding: 10px 12px; font: inherit;
  font-size: 14px; resize: vertical; margin-bottom: 10px;
}
.teach-result { margin-top: 10px; font-size: 12.5px; color: var(--fg-muted); }
.teach-result.ok { color: var(--ok); }
.teach-result.err { color: var(--err); }

/* Text inputs inside Tools fields (topic name, etc.) */
.field input[type="text"] {
  width: 100%; background: var(--bg); border: 1px solid var(--border);
  border-radius: 10px; color: var(--fg); padding: 9px 12px; font: inherit;
  font-size: 14px;
}

/* Read-a-document progress */
.read-progress { margin-top: 10px; }
.read-bar {
  height: 8px; border-radius: 5px; background: var(--bg-elev-2);
  overflow: hidden; margin-bottom: 8px;
}
.read-bar i {
  display: block; height: 100%; width: 0%;
  background: linear-gradient(90deg, var(--accent-2, var(--accent)), var(--accent));
  border-radius: 5px; transition: width 0.4s ease;
}
.read-status { font-size: 12.5px; color: var(--fg-muted); line-height: 1.45; }

.read-concepts-wrap {
  margin-top: 10px;
}
.read-concepts-label {
  display: block;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .05em;
  text-transform: uppercase;
  color: var(--fg-muted);
  margin-bottom: 6px;
}
.read-concepts {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}
.concept-chip {
  display: inline-flex;
  align-items: center;
  padding: 2px 9px;
  border-radius: 99px;
  font-size: 12px;
  background: color-mix(in srgb, var(--accent) 12%, transparent);
  color: var(--accent);
  border: 1px solid color-mix(in srgb, var(--accent) 28%, transparent);
  animation: chipIn .22s ease both;
}
@keyframes chipIn {
  from { opacity: 0; transform: scale(.78); }
  to   { opacity: 1; transform: scale(1); }
}

.field { display: block; margin-bottom: 14px; font-size: 13px; color: var(--fg-muted); }
.field span { display: flex; justify-content: space-between; margin-bottom: 6px; }
.field em { color: var(--accent); font-style: normal; }
.field input[type="range"] { width: 100%; accent-color: var(--accent); }
.checkbox { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--fg-muted); margin-bottom: 14px; }
.checkbox input { accent-color: var(--accent); }

.primary, .ghost {
  border-radius: 10px; padding: 10px 16px; font-size: 14px; font: inherit;
  cursor: pointer; transition: filter 0.15s, background 0.15s, border-color 0.15s;
}
.primary {
  border: none;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #ffffff; font-weight: 600;
}
.primary:hover { filter: brightness(1.08); }
.primary:disabled { opacity: 0.5; cursor: default; }
.ghost {
  background: var(--bg-elev-2); border: 1px solid var(--border); color: var(--fg);
}
.ghost:hover { border-color: var(--accent); }
.block { display: block; width: 100%; }

/* ── Investor Lab overlay ────────────────────────────────────────────────── */
.lab-overlay {
  position: fixed; inset: 0; z-index: 50;
  display: flex; align-items: center; justify-content: center;
  background: rgba(0, 0, 0, 0.6); padding: 24px;
}
.lab-modal {
  width: min(820px, 100%); max-height: 88vh; overflow: auto;
  background: var(--bg-elev); border: 1px solid var(--border);
  border-radius: 16px; box-shadow: 0 24px 70px rgba(0, 0, 0, 0.5);
}
.lab-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 14px; border-bottom: 1px solid var(--border-soft);
  position: sticky; top: 0; background: var(--bg-elev);
}
.lab-tabs { display: flex; gap: 6px; }
.lab-tab {
  border: 1px solid var(--border); background: var(--bg); color: var(--fg-muted);
  border-radius: 9px; padding: 8px 13px; font-size: 13px; cursor: pointer; font: inherit;
}
.lab-tab.active { color: var(--fg); border-color: var(--accent); background: var(--accent-soft); }
.lab-panel { padding: 16px; }
.lab-hint { color: var(--fg-muted); font-size: 13px; margin: 0 0 12px; line-height: 1.5; }
.lab-row { display: flex; gap: 8px; align-items: center; margin-bottom: 12px; }
.lab-row input[type="text"], .lab-row textarea {
  flex: 1; background: var(--bg); border: 1px solid var(--border);
  border-radius: 10px; color: var(--fg); padding: 10px 12px; font: inherit; resize: vertical;
}
.lab-status { font-size: 12px; color: var(--fg-muted); }
.ab-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.ab-col { border: 1px solid var(--border); border-radius: 12px; padding: 13px; background: var(--bg); }
.ab-col.voltaic { border-color: var(--accent); }
.ab-col-head { font-size: 12px; font-weight: 600; color: var(--fg-muted); margin-bottom: 8px; }
.ab-col.voltaic .ab-col-head { color: var(--accent); }
.ab-answer { font-size: 14px; line-height: 1.55; white-space: pre-wrap; min-height: 48px; }
.ab-memory { margin-top: 10px; padding-top: 8px; border-top: 1px dashed var(--border); font-size: 11px; color: var(--fg-dim); }
#forget-canvas { width: 100%; max-width: 720px; border: 1px solid var(--border-soft); border-radius: 12px; background: var(--bg); }

/* ── Brain pill (top bar) ────────────────────────────────────────────────── */
.brain-pill {
  display: flex; align-items: center; gap: 10px;
  background: var(--bg-elev); border: 1px solid var(--border);
  border-radius: 999px; padding: 5px 14px 5px 6px; cursor: pointer;
  color: var(--fg); font: inherit; transition: border-color 0.15s, background 0.15s;
}
.brain-pill:hover { border-color: var(--accent); background: var(--bg-elev-2); }
.brain-orb {
  width: 30px; height: 30px; border-radius: 50%;
  display: grid; place-items: center; color: var(--accent);
  background: radial-gradient(circle at 50% 40%, rgba(112,184,255,0.35), rgba(112,184,255,0.05));
  box-shadow: 0 0 0 0 rgba(112,184,255,0.55);
}
.brain-orb svg { width: 18px; height: 18px; }
.brain-orb.spike { animation: orbSpike 0.6s ease-out; }
@keyframes orbSpike {
  0%   { box-shadow: 0 0 0 0 rgba(112,184,255,0.6); transform: scale(1); color: #cfe6ff; }
  40%  { box-shadow: 0 0 0 10px rgba(112,184,255,0); transform: scale(1.18); }
  100% { box-shadow: 0 0 0 0 rgba(112,184,255,0); transform: scale(1); }
}
.brain-meta { display: flex; flex-direction: column; gap: 2px; line-height: 1; min-width: 84px; }
.brain-level { font-size: 12px; font-weight: 700; color: var(--accent); }
.brain-xp { height: 4px; border-radius: 2px; background: var(--bg-elev-2); overflow: hidden; }
.brain-xp i { display: block; height: 100%; width: 0%; background: linear-gradient(90deg, var(--accent-2), var(--accent)); transition: width 0.5s ease; }
.brain-count { font-size: 10.5px; color: var(--fg-dim); }

/* Level-up + memory toast */
.brain-toast {
  position: fixed; top: 64px; left: 50%; transform: translateX(-50%) translateY(-8px);
  background: var(--bg-elev); border: 1px solid var(--accent); color: var(--fg);
  border-radius: 999px; padding: 8px 16px; font-size: 13px; font-weight: 600;
  z-index: 60; opacity: 0; pointer-events: none;
  box-shadow: 0 8px 30px rgba(0,0,0,0.4), 0 0 20px var(--accent-soft);
  transition: opacity 0.3s, transform 0.3s;
}
.brain-toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.brain-toast.levelup { border-color: #e0a800; color: #8a6300; box-shadow: 0 8px 30px rgba(0,0,0,0.15), 0 0 24px rgba(224,168,0,0.30); }

/* ── Brain overlay ───────────────────────────────────────────────────────── */
.brain-overlay {
  position: fixed; inset: 0; z-index: 50;
  display: flex; align-items: center; justify-content: center;
  background: rgba(0,0,0,0.72); padding: 20px;
  backdrop-filter: blur(4px);
}
.brain-modal {
  width: min(1060px, 100%);
  max-height: calc(100vh - 40px);
  display: flex; flex-direction: column;
  background: #0d1120;
  border: 1px solid rgba(77,166,255,0.18);
  border-radius: 18px; overflow: hidden;
  box-shadow: 0 30px 90px rgba(0,0,0,0.7), 0 0 0 1px rgba(255,255,255,0.04);
}
.brain-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 1px solid rgba(255,255,255,0.07);
  background: rgba(255,255,255,0.03);
  flex-shrink: 0;
}
.brain-head .icon-btn { color: rgba(255,255,255,0.55); }
.brain-head .icon-btn:hover { color: #fff; background: rgba(255,255,255,0.1); }
.brain-title-name { font-size: 15px; font-weight: 650; display: block; color: #ddeeff; }
.brain-title-sub  { font-size: 11.5px; color: rgba(160,190,230,0.6); }

/* Body: canvas left, sidebar right */
.brain-body {
  display: flex; flex: 1; min-height: 0;
}
#brain-canvas {
  flex: 1; min-width: 0; display: block;
  height: 520px;
  background: #050810;
}
.brain-sidebar {
  width: 230px; flex-shrink: 0;
  background: rgba(255,255,255,0.025);
  border-left: 1px solid rgba(255,255,255,0.06);
  display: flex; flex-direction: column;
  overflow-y: auto; padding: 16px 14px;
  gap: 16px;
}

/* Sidebar stats row */
.bs-stats {
  display: flex; gap: 0; border-radius: 10px;
  background: rgba(255,255,255,0.04);
  border: 1px solid rgba(255,255,255,0.07);
  overflow: hidden;
}
.bs-stat {
  flex: 1; display: flex; flex-direction: column; align-items: center;
  padding: 10px 4px;
  border-right: 1px solid rgba(255,255,255,0.06);
}
.bs-stat:last-child { border-right: none; }
.bs-num { font-size: 18px; font-weight: 700; color: #70b8ff; line-height: 1; }
.bs-lbl { font-size: 10px; color: rgba(160,190,230,0.5); text-transform: uppercase; letter-spacing: 0.06em; margin-top: 3px; }

/* XP bar */
.bs-xp-wrap { display: flex; flex-direction: column; gap: 5px; }
.bs-xp-lbl  { font-size: 11px; color: rgba(160,190,230,0.5); }
.xp-track   { height: 7px; border-radius: 4px; background: rgba(255,255,255,0.08); overflow: hidden; }
.xp-bar     { height: 100%; width: 0%; background: linear-gradient(90deg, #3b7eff, #70b8ff); transition: width 0.6s ease; }

/* Domain / concepts sections */
.bs-legend { display: flex; flex-direction: column; gap: 8px; }
.bs-section-title {
  font-size: 10.5px; font-weight: 600; letter-spacing: 0.07em;
  text-transform: uppercase; color: rgba(160,190,230,0.4);
}
.bs-domains { display: flex; flex-direction: column; gap: 5px; }
.bs-domain-row {
  display: flex; align-items: center; gap: 7px;
  font-size: 12px; color: rgba(200,220,255,0.75);
}
.bs-dot {
  width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0;
  box-shadow: 0 0 6px currentColor;
}
.bs-domain-name { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bs-domain-count {
  font-size: 11px; color: rgba(160,190,230,0.4);
  background: rgba(255,255,255,0.06); border-radius: 8px; padding: 1px 6px;
}
.bs-concepts { display: flex; flex-wrap: wrap; gap: 5px; }
.bs-concept-chip {
  font-size: 11px; padding: 2px 8px; border-radius: 99px;
  background: color-mix(in srgb, var(--chip-col, #4da6ff) 14%, transparent);
  color: var(--chip-col, #4da6ff);
  border: 1px solid color-mix(in srgb, var(--chip-col, #4da6ff) 30%, transparent);
  white-space: nowrap;
}
.bs-empty { font-size: 11.5px; color: rgba(160,190,230,0.3); font-style: italic; }

/* Legend hints */
.bs-hint-block { gap: 7px !important; }
.bs-hint {
  display: flex; align-items: center; gap: 7px;
  font-size: 11px; color: rgba(160,190,230,0.4);
}
.bs-hint-dot {
  width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0;
}
.bs-hint-dot.protect { border: 2px solid rgba(255,255,255,0.55); background: transparent; }
.bs-hint-dot.spike   { background: #ddeeff; box-shadow: 0 0 6px #70b8ff; }
.bs-hint-dot.cluster { background: linear-gradient(135deg, #4da6ff 0%, #4ade80 50%, #c084fc 100%); }

/* Old stat classes kept for any lingering refs */
.stat-num { font-size: 20px; font-weight: 700; color: var(--accent); line-height: 1; }
.stat-lbl { font-size: 11px; color: var(--fg-dim); text-transform: uppercase; letter-spacing: 0.04em; }

/* ── Responsive ──────────────────────────────────────────────────────────── */
@media (max-width: 640px) {
  .examples { grid-template-columns: 1fr; }
  .ab-cols { grid-template-columns: 1fr; }
  .welcome { margin-top: 6vh; }
  .welcome h1 { font-size: 25px; }
  .brain-body { flex-direction: column; }
  .brain-sidebar { width: auto; border-left: none; border-top: 1px solid rgba(255,255,255,0.06); }
  #brain-canvas { height: 300px; }
}
