:root {
  --bg: #0f1115; --panel: #161a22; --panel-2: #1d222c; --border: #2a303c;
  --text: #e6e9ef; --muted: #8b93a3; --accent: #4f8cff; --accent-2: #7fb0ff;
  --user: #233049; --danger: #ff6b6b; --ok: #4cd4a0;
  --radius: 12px; --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
@media (prefers-color-scheme: light) {
  :root { --bg: #f5f6f8; --panel: #ffffff; --panel-2: #f0f2f5; --border: #dde1e7; --text: #1b1f27; --muted: #6a7282; --user: #e6eefc; }
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { font-family: var(--font); background: var(--bg); color: var(--text); display: grid; grid-template-columns: 340px 1fr; height: 100vh; }
h1, h2, h3 { margin: 0; font-weight: 600; }
h1 { font-size: 18px; } h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
p { margin: 0; }
.muted { color: var(--muted); font-size: 12px; }
button, label.ghost { font: inherit; border: 1px solid var(--border); background: var(--panel-2); color: var(--text); padding: 8px 14px; border-radius: 8px; cursor: pointer; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
button.primary:disabled { opacity: .5; cursor: progress; }
.ghost, label.ghost { background: transparent; }
.small { padding: 5px 10px; font-size: 12px; }
textarea { width: 100%; font: inherit; color: var(--text); background: var(--panel-2); border: 1px solid var(--border); border-radius: 8px; padding: 10px; resize: vertical; }
textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.row { display: flex; align-items: center; gap: 10px; margin-top: 8px; }

/* Sidebar */
#sidebar { background: var(--panel); border-right: 1px solid var(--border); padding: 18px; overflow-y: auto; display: flex; flex-direction: column; gap: 18px; }
.brand { display: flex; align-items: center; gap: 12px; }
.logo { width: 40px; height: 40px; border-radius: 10px; background: linear-gradient(135deg, var(--accent), #8b5cf6); color: #fff; display: grid; place-items: center; font-weight: 800; font-size: 20px; }
.panel { display: flex; flex-direction: column; gap: 10px; }
.panel-head { display: flex; justify-content: space-between; align-items: baseline; }
details summary { cursor: pointer; list-style: none; } details summary::-webkit-details-marker { display: none; }
details summary h2::after { content: " ▸"; } details[open] summary h2::after { content: " ▾"; }
details > :not(summary) { margin-top: 10px; }
.dropzone { border: 1.5px dashed var(--border); border-radius: var(--radius); padding: 18px 14px; text-align: center; display: flex; flex-direction: column; gap: 4px; cursor: pointer; font-size: 13px; transition: border-color .15s, background .15s; }
.dropzone:hover, .dropzone.over { border-color: var(--accent); background: var(--panel-2); }
.doc-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.doc-list li { display: flex; align-items: center; gap: 8px; background: var(--panel-2); border: 1px solid var(--border); border-radius: 8px; padding: 7px 10px; font-size: 13px; }
.doc-list .kind { font-size: 10px; text-transform: uppercase; color: var(--accent-2); border: 1px solid var(--border); padding: 1px 5px; border-radius: 4px; }
.doc-list .name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.doc-list .del { background: none; border: none; color: var(--muted); padding: 2px 6px; font-size: 14px; } .doc-list .del:hover { color: var(--danger); }

/* Main */
#main { display: flex; flex-direction: column; min-width: 0; }
.thread { flex: 1; overflow-y: auto; padding: 28px clamp(16px, 6vw, 80px); display: flex; flex-direction: column; gap: 22px; }
.empty { margin: auto; max-width: 520px; text-align: center; color: var(--muted); display: flex; flex-direction: column; gap: 10px; }
.empty h2 { text-transform: none; letter-spacing: 0; font-size: 22px; color: var(--text); }
.msg { max-width: 860px; }
.msg.user { align-self: flex-end; background: var(--user); border-radius: var(--radius); padding: 12px 14px; }
.msg.user .charts { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 8px; }
.msg.user .charts img { max-height: 160px; max-width: 320px; border-radius: 8px; border: 1px solid var(--border); }
.msg.assistant { align-self: stretch; }
.msg.assistant .who { font-size: 12px; color: var(--accent-2); font-weight: 600; margin-bottom: 6px; }
.msg.assistant .body { line-height: 1.55; font-size: 15px; }
.body h1, .body h2, .body h3 { margin: 18px 0 8px; text-transform: none; letter-spacing: 0; color: var(--text); }
.body h1 { font-size: 20px; } .body h2 { font-size: 17px; } .body h3 { font-size: 15px; }
.body p, .body ul, .body ol { margin: 8px 0; } .body li { margin: 3px 0; }
.body code { background: var(--panel-2); padding: 1px 5px; border-radius: 4px; font-size: 13px; }
.body table { border-collapse: collapse; margin: 10px 0; } .body td, .body th { border: 1px solid var(--border); padding: 5px 9px; font-size: 14px; }
.cite { display: inline-block; font-size: 11px; vertical-align: super; line-height: 1; color: var(--accent-2); background: var(--panel-2); border: 1px solid var(--border); border-radius: 4px; padding: 1px 4px; margin-left: 2px; cursor: help; }
.sources { margin-top: 14px; border-top: 1px solid var(--border); padding-top: 10px; font-size: 13px; }
.sources summary { cursor: pointer; color: var(--muted); }
.sources ol { margin: 8px 0 0; padding-left: 22px; } .sources li { margin: 6px 0; }
.sources .src-title { font-weight: 600; } .sources q { color: var(--muted); display: block; margin-top: 2px; }
.thinking { font-size: 12px; color: var(--muted); border-left: 2px solid var(--border); padding-left: 10px; margin-bottom: 10px; max-height: 140px; overflow-y: auto; white-space: pre-wrap; }
.meta { font-size: 11px; color: var(--muted); margin-top: 8px; }
.error { color: var(--danger); font-size: 14px; }
.cursor::after { content: "▍"; animation: blink 1s steps(1) infinite; color: var(--accent); }
@keyframes blink { 50% { opacity: 0; } }

/* Composer */
.composer { padding: 12px clamp(16px, 6vw, 80px) 20px; border-top: 1px solid var(--border); background: var(--panel); }
.composer-box { border: 1.5px solid var(--border); border-radius: var(--radius); background: var(--panel-2); padding: 8px; transition: border-color .15s; }
.composer-box.over { border-color: var(--accent); }
.composer-box textarea { border: none; background: transparent; padding: 6px 8px; resize: none; }
.composer-box textarea:focus { outline: none; }
.composer-actions { display: flex; gap: 8px; align-items: center; justify-content: flex-end; padding: 4px; }
.composer-actions label { margin-right: auto; }
.previews { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 8px; }
.previews .thumb { position: relative; }
.previews img { height: 72px; border-radius: 8px; border: 1px solid var(--border); display: block; }
.previews .x { position: absolute; top: -6px; right: -6px; width: 20px; height: 20px; border-radius: 50%; background: var(--danger); color: #fff; border: none; font-size: 12px; line-height: 1; padding: 0; }

@media (max-width: 900px) {
  body { grid-template-columns: 1fr; grid-template-rows: auto 1fr; height: auto; min-height: 100vh; }
  #sidebar { border-right: none; border-bottom: 1px solid var(--border); }
  .thread, .composer { padding-left: 16px; padding-right: 16px; }
}

/* Frank's mind */
.doc-list.compact li { padding: 4px 8px; font-size: 12px; }
.small-summary { font-size: 12px; cursor: pointer; }
.activity { font-size: 12px; color: var(--muted); display: flex; flex-direction: column; gap: 3px; margin-bottom: 8px; }
.activity .act { display: flex; gap: 6px; align-items: baseline; }
.activity .act .q { color: var(--text); opacity: .8; }
.activity .act.running::before { content: "◌"; animation: spin 1s linear infinite; display: inline-block; }
.activity .act.done::before { content: "✓"; color: var(--ok); }
@keyframes spin { to { transform: rotate(360deg); } }
.sources .src-where { color: var(--accent-2); font-size: 12px; margin-left: 4px; }
select.small { font: inherit; font-size: 12px; color: var(--text); background: var(--panel-2); border: 1px solid var(--border); border-radius: 8px; padding: 6px 8px; }
.sources .kind { font-size: 10px; text-transform: uppercase; color: var(--accent-2); border: 1px solid var(--border); padding: 1px 5px; border-radius: 4px; }
