:root {
  --bg: #171717;
  --bg-elevated: #212121;
  --bg-hover: #2a2a2a;
  --border: #333;
  --text: #ececec;
  --muted: #9b9b9b;
  --accent: #10a37f;
  --accent-dim: rgba(16,163,127,0.15);
  --cyan: #58a6ff;
  --purple: #bc8cff;
  --danger: #f85149;
  --font: "Inter", system-ui, sans-serif;
  --mono: "JetBrains Mono", monospace;
  --rail-w: 260px;
  --fusion-w: 320px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: var(--font); background: var(--bg); color: var(--text); min-height: 100vh; font-size: 14px; }
.hidden { display: none !important; }
a { color: var(--cyan); }

.login-screen {
  min-height: 100vh; display: grid; place-items: center;
  background: radial-gradient(circle at 30% 20%, rgba(16,163,127,0.12), transparent 45%), var(--bg);
}
.login-card { text-align: center; padding: 2rem; max-width: 400px; }
.logo-mark { font-size: 2rem; color: var(--accent); }
.login-card h1 { font-size: 1.5rem; margin: 0.75rem 0 0.25rem; font-weight: 600; }
.tagline { color: var(--muted); margin-bottom: 1rem; }
.login-note { font-size: 0.85rem; color: var(--muted); margin-bottom: 1rem; }
.btn-primary, .btn-ghost {
  border: none; border-radius: 8px; padding: 0.65rem 1rem; font-weight: 600; cursor: pointer; width: 100%;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { filter: brightness(1.08); }
.btn-ghost { background: var(--bg-elevated); color: var(--text); border: 1px solid var(--border); margin-top: 0.5rem; }
.beta-link { margin-top: 2.5rem; }
.beta-tester { background: none; border: none; color: var(--muted); font-size: 0.72rem; opacity: 0.5; cursor: pointer; }
.beta-tester:hover { opacity: 0.9; color: var(--accent); }

.modal { position: fixed; inset: 0; background: rgba(0,0,0,0.75); display: grid; place-items: center; z-index: 100; }
.modal-inner { background: var(--bg-elevated); border: 1px solid var(--border); padding: 1.5rem; border-radius: 12px; width: min(360px, 92vw); }
.modal-inner input { width: 100%; padding: 0.6rem; margin: 0.75rem 0; background: var(--bg); border: 1px solid var(--border); color: var(--text); border-radius: 8px; }
.error { color: var(--danger); font-size: 0.85rem; }

.app { display: grid; grid-template-columns: var(--rail-w) 1fr var(--fusion-w); height: 100vh; overflow: hidden; }
.app.fusion-closed { grid-template-columns: var(--rail-w) 1fr 0; }
.app.fusion-closed .fusion-panel { display: none; }

.rail {
  background: var(--bg-elevated); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; overflow: hidden;
}
.rail-top { padding: 0.85rem; border-bottom: 1px solid var(--border); }
.rail-brand { font-weight: 600; margin-bottom: 0.75rem; font-size: 0.95rem; }
.btn-new-thread {
  width: 100%; background: transparent; border: 1px solid var(--border); color: var(--text);
  border-radius: 8px; padding: 0.5rem; cursor: pointer; font-size: 0.85rem;
}
.btn-new-thread:hover { background: var(--bg-hover); }
.rail-section { padding: 0.65rem 0.85rem; border-bottom: 1px solid var(--border); }
.rail-grow { flex: 1; overflow-y: auto; }
.rail-label { font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); margin-bottom: 0.5rem; }
.rail-item {
  display: block; width: 100%; text-align: left; background: none; border: none; color: var(--text);
  padding: 0.45rem 0.5rem; border-radius: 6px; cursor: pointer; font-size: 0.85rem;
}
.rail-item.active, .rail-item:hover { background: var(--bg-hover); }
.thread-list, .model-list-compact { list-style: none; }
.thread-list li, .model-list-compact li {
  padding: 0.4rem 0.5rem; border-radius: 6px; font-size: 0.82rem; color: var(--muted); cursor: pointer;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.thread-list li:hover, .model-list-compact li:hover { background: var(--bg-hover); color: var(--text); }
.model-list-compact li.active { background: var(--accent-dim); color: var(--accent); }
.btn-text { background: none; border: none; color: var(--accent); font-size: 0.8rem; cursor: pointer; margin-top: 0.35rem; }
.rail-footer { margin-top: auto; padding: 0.85rem; border-top: 1px solid var(--border); font-size: 0.8rem; }
.plan-badge { color: var(--accent); font-size: 0.72rem; margin-top: 0.2rem; }

.workspace { display: flex; flex-direction: column; min-width: 0; background: var(--bg); }
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0.65rem 1rem; border-bottom: 1px solid var(--border); gap: 0.75rem;
}
.model-select {
  background: var(--bg-elevated); border: 1px solid var(--border); color: var(--text);
  border-radius: 8px; padding: 0.45rem 0.65rem; min-width: 220px; font-size: 0.85rem;
}
.pill { font-size: 0.72rem; padding: 0.25rem 0.55rem; border-radius: 999px; background: var(--bg-elevated); border: 1px solid var(--border); color: var(--muted); }
.pill.ok { color: var(--accent); border-color: rgba(16,163,127,0.4); }
.btn-icon { background: var(--bg-elevated); border: 1px solid var(--border); color: var(--text); border-radius: 8px; width: 36px; height: 36px; cursor: pointer; }

.chat-area { flex: 1; overflow-y: auto; padding: 1.5rem 1rem; }
.empty-state { max-width: 520px; margin: 4rem auto; text-align: center; color: var(--muted); }
.empty-state h2 { color: var(--text); margin-bottom: 0.75rem; font-weight: 600; }
.empty-state p { margin-bottom: 1.25rem; line-height: 1.55; }
.messages { max-width: 780px; margin: 0 auto; display: flex; flex-direction: column; gap: 1rem; }
.msg { padding: 1rem; border-radius: 12px; line-height: 1.55; white-space: pre-wrap; }
.msg.user { background: var(--bg-elevated); align-self: flex-end; max-width: 85%; }
.msg.assistant { background: transparent; border: 1px solid var(--border); }

.composer {
  display: flex; gap: 0.5rem; padding: 0.85rem 1rem 1rem; border-top: 1px solid var(--border);
  align-items: flex-end;
}
.composer textarea {
  flex: 1; resize: none; min-height: 44px; max-height: 160px; padding: 0.65rem 0.85rem;
  background: var(--bg-elevated); border: 1px solid var(--border); border-radius: 12px;
  color: var(--text); font-family: inherit; font-size: 0.95rem;
}
.composer button {
  width: 44px; height: 44px; border-radius: 10px; border: none; background: var(--accent);
  color: #fff; font-size: 1.1rem; cursor: pointer; flex-shrink: 0;
}
.composer button:disabled { opacity: 0.35; cursor: not-allowed; }

.fusion-panel {
  background: var(--bg-elevated); border-left: 1px solid var(--border);
  overflow-y: auto; display: flex; flex-direction: column;
}
.fusion-head { display: flex; justify-content: space-between; align-items: center; padding: 0.85rem 1rem; border-bottom: 1px solid var(--border); }
.fusion-head h2 { font-size: 0.95rem; font-weight: 600; }
.fusion-form { padding: 1rem; display: flex; flex-direction: column; gap: 0.75rem; }
.fusion-form label { display: flex; flex-direction: column; gap: 0.35rem; font-size: 0.8rem; color: var(--muted); }
.fusion-form input[type=text], .fusion-form textarea, .fusion-form select {
  background: var(--bg); border: 1px solid var(--border); color: var(--text); border-radius: 8px; padding: 0.5rem;
  font-family: inherit;
}
.fusion-form .check { flex-direction: row; align-items: center; gap: 0.5rem; color: var(--text); }
.fusion-status { padding: 0 1rem 1rem; font-size: 0.78rem; color: var(--muted); }
.fusion-status .mono { font-family: var(--mono); margin-top: 0.35rem; font-size: 0.7rem; }
.result-box {
  margin: 0 1rem 1rem; padding: 0.75rem; background: #0d0d0d; border: 1px solid var(--border);
  border-radius: 8px; font-family: var(--mono); font-size: 0.68rem; overflow: auto; max-height: 200px;
}

@media (max-width: 960px) {
  .app { grid-template-columns: 1fr; }
  .rail, .fusion-panel { display: none; }
}
