:root {
  --bg: #f4f6fb; --panel: #fff; --ink: #0f172a; --muted: #64748b; --line: #e2e8f0;
  --accent: #4f46e5; --accent-soft: #eef2ff; --good: #15803d; --bad: #b91c1c; --ai: #f8fafc;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { font: 15px/1.55 Inter, -apple-system, "Segoe UI", Helvetica, Arial, sans-serif; color: var(--ink); background: var(--bg); -webkit-font-smoothing: antialiased; }
button { font: inherit; cursor: pointer; }
input, textarea { font: inherit; }
a { color: var(--accent); }

/* ---- login / waiting ---- */
.center { min-height: 100%; display: flex; align-items: center; justify-content: center; padding: 24px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 30px 34px; width: 440px; max-width: 100%; box-shadow: 0 1px 2px rgba(15,23,42,.06), 0 8px 24px rgba(15,23,42,.06); }
.card h1 { font-size: 20px; margin: 0 0 12px; }
.card p { margin: 8px 0; color: var(--muted); }
.card label { display: block; margin-top: 14px; font-weight: 600; font-size: 13px; }
.card input { width: 100%; padding: 10px 12px; border: 1px solid #cbd5e1; border-radius: 8px; margin-top: 4px; font-size: 16px; } .card input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(79,70,229,.15); }
.btn { background: var(--accent); color: #fff; border: 0; border-radius: 8px; padding: 10px 18px; font-weight: 600; } .btn:hover { background: #4338ca; }
.btn:disabled { opacity: .5; cursor: default; }
.btn.secondary { background: #fff; color: var(--ink); border: 1px solid var(--line); }
.error { color: var(--bad); margin-top: 12px; }
.hidden { display: none !important; }

/* ---- workspace ---- */
.ws { display: grid; grid-template-rows: 48px 1fr; height: 100vh; }
.topbar { display: flex; align-items: center; justify-content: space-between; padding: 0 20px; background: var(--panel); border-bottom: 1px solid var(--line); }
.topbar .title { font-weight: 600; }
.status { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 13px; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--good); display: inline-block; }
.dot.off { background: #9aa0a6; }
.identity { font-weight: 600; }
.panes { display: grid; grid-template-columns: 45% 55%; min-height: 0; }
.pane { min-height: 0; display: flex; flex-direction: column; background: var(--panel); }
.pane.materials { border-right: 1px solid var(--line); }
.tabs { display: flex; gap: 2px; padding: 8px 12px 0; border-bottom: 1px solid var(--line); overflow-x: auto; flex-wrap: wrap; }
.tabs button { background: none; border: 0; border-bottom: 2px solid transparent; padding: 6px 10px; color: var(--muted); font-weight: 600; font-size: 13px; white-space: nowrap; }
.tabs button.active { color: var(--ink); border-bottom-color: var(--accent); }
.doc { overflow: auto; padding: 16px 22px 40px; }
.doc h2 { font-size: 17px; margin: 0 0 12px; }
.doc h3 { font-size: 15px; margin: 16px 0 6px; }
.doc table { border-collapse: collapse; margin: 10px 0; width: 100%; font-size: 14px; }
.doc th, .doc td { border: 1px solid var(--line); padding: 5px 8px; text-align: left; vertical-align: top; }
.doc th { background: var(--bg); }
.doc p { margin: 8px 0; }
.doc ul, .doc ol { margin: 6px 0 6px 22px; padding: 0; }
.doc code { background: var(--bg); padding: 1px 4px; border-radius: 3px; font-size: 13px; }

.chat { display: flex; flex-direction: column; min-height: 0; }
.messages { flex: 1; overflow: auto; padding: 16px 20px; display: flex; flex-direction: column; gap: 12px; }
.msg { max-width: 85%; padding: 10px 14px; border-radius: 10px; position: relative; white-space: pre-wrap; word-wrap: break-word; }
.msg.user { align-self: flex-end; background: var(--accent-soft); border: 1px solid #c7d2fe; }
.msg.assistant { align-self: flex-start; background: var(--ai); border: 1px solid var(--line); white-space: normal; }
.msg.assistant .md p { margin: 6px 0; }
.msg.assistant .md p:first-child { margin-top: 0; }
.msg.assistant .md p:last-child { margin-bottom: 0; }
.msg.assistant .md ul, .msg.assistant .md ol { margin: 6px 0 6px 20px; padding: 0; }
.msg.assistant .md table { border-collapse: collapse; margin: 8px 0; font-size: 14px; }
.msg.assistant .md th, .msg.assistant .md td { border: 1px solid var(--line); padding: 4px 8px; }
.msg.assistant .md code { background: #fff; padding: 1px 4px; border-radius: 3px; font-size: 13px; }
.msg.assistant .md h1, .msg.assistant .md h2, .msg.assistant .md h3 { font-size: 15px; margin: 10px 0 4px; }
.msg.error { align-self: stretch; max-width: none; background: #fff4f2; border: 1px solid #f1b5ad; color: var(--bad); text-align: center; }
.msg .copy { position: absolute; right: 8px; bottom: -22px; background: none; border: 0; color: var(--muted); font-size: 12px; padding: 2px 6px; }
.msg .copy:hover { color: var(--ink); }
.msg.assistant { margin-bottom: 14px; }
.typing { color: var(--muted); font-size: 13px; padding: 0 20px 6px; min-height: 22px; }
.empty { margin: auto; max-width: 420px; text-align: center; color: var(--muted); }
.empty h3 { color: var(--ink); margin-bottom: 6px; }
.composer { display: flex; gap: 10px; padding: 12px 20px 6px; border-top: 1px solid var(--line); }
.composer textarea { flex: 1; resize: none; height: 72px; padding: 10px 12px; border: 1px solid #cbd5e1; border-radius: 10px; }
.composer textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(79,70,229,.15); }
.composer .btn { align-self: stretch; width: 84px; }
.hint { color: var(--muted); font-size: 12px; padding: 0 20px 10px; }
.closed { padding: 16px 20px; border-top: 1px solid var(--line); background: var(--bg); color: var(--muted); }
.closed strong { color: var(--ink); }
.cursor::after { content: "▍"; color: var(--muted); animation: blink 1s steps(2) infinite; }
@keyframes blink { 50% { opacity: 0; } }
@media (max-width: 1000px) { .panes { grid-template-columns: 1fr; grid-template-rows: 45% 55%; } .pane.materials { border-right: 0; border-bottom: 1px solid var(--line); } }

/* waiting for the first token */
.thinking { display: inline-flex; align-items: center; gap: 10px; color: var(--muted); font-size: 14px; }
.thinking .secs { font-variant-numeric: tabular-nums; }
.dots { display: inline-flex; gap: 4px; }
.dots i { width: 6px; height: 6px; border-radius: 50%; background: var(--accent); opacity: .3; animation: think 1.2s infinite ease-in-out; }
.dots i:nth-child(2) { animation-delay: .15s; }
.dots i:nth-child(3) { animation-delay: .3s; }
@keyframes think { 0%, 80%, 100% { opacity: .25; transform: translateY(0); } 40% { opacity: 1; transform: translateY(-3px); } }
.msg.pending .copy { display: none; }
