:root {
  --bg: #0a0c10;
  --bg2: #11151c;
  --bg3: #1a2030;
  --border: #2a3348;
  --text: #edf2f7;
  --muted: #8b97ad;
  --accent: #6ea8ff;
  --accent2: #5eead4;
  --danger: #fb7185;
  --ok: #34d399;
  --warn: #fbbf24;
  --radius: 14px;
  --sidebar: 280px;
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font-family: var(--font); }
button, input, textarea, select {
  font: inherit; color: inherit; background: var(--bg3); border: 1px solid var(--border);
  border-radius: 12px; padding: 0.7rem 0.9rem;
}
textarea { resize: none; }
.btn { cursor: pointer; background: #1e2738; border: 1px solid var(--border); }
.btn.primary { background: linear-gradient(180deg,#5b9cff,#3b82f6); border-color:#3b82f6; color:#fff; font-weight:600; }
.btn.danger { background:#7f1d1d; border-color:#991b1b; }
.btn.ghost { background: transparent; }
.btn.block { width: 100%; }
.btn.tiny { padding: 0.25rem 0.55rem; font-size: 0.8rem; }
.btn.icon { padding: 0.45rem 0.65rem; }
.btn.send { width: 44px; height: 44px; border-radius: 50%; padding: 0; font-size: 1.2rem; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.hidden { display: none !important; }
.spacer { flex: 1; }
.error { color: var(--danger); min-height: 1.2em; font-size: 0.9rem; }
.pill { font-size: 0.75rem; padding: 0.2rem 0.55rem; border-radius: 999px; border: 1px solid var(--border); color: var(--muted); }
.pill.ok { color: var(--ok); border-color: #065f46; }
.pill.bad { color: var(--danger); border-color: #7f1d1d; }
.pill.warn { color: var(--warn); border-color: #854d0e; }

.login-view {
  min-height: 100%; display: grid; place-items: center; padding: 1.5rem;
  background: radial-gradient(900px 500px at 50% -20%, #1e3a5f55, transparent), var(--bg);
}
.login-card {
  width: min(400px,100%); background: var(--bg2); border: 1px solid var(--border);
  border-radius: 20px; padding: 1.75rem; box-shadow: 0 24px 80px #000a;
}
.logo { font-size: 1.6rem; font-weight: 750; }
.logo span { color: var(--accent2); }
.login-card p { color: var(--muted); margin: 0.35rem 0 1.25rem; }
.login-card form { display: grid; gap: 0.65rem; }
.login-card label { font-size: 0.85rem; color: var(--muted); }

.app { display: grid; grid-template-columns: var(--sidebar) 1fr; height: 100%; }
.sidebar {
  background: var(--bg2); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; min-height: 0; z-index: 30;
}
.sidebar-top { padding: 0.85rem; }
.convo-list { flex: 1; overflow: auto; padding: 0 0.6rem 0.6rem; display: flex; flex-direction: column; gap: 0.3rem; }
.convo {
  text-align: left; padding: 0.7rem 0.75rem; border-radius: 12px; border: 1px solid transparent;
  background: transparent; cursor: pointer; width: 100%;
}
.convo:hover { background: var(--bg3); }
.convo.active { background: #243149; border-color: var(--border); }
.convo .t { font-weight: 600; font-size: 0.92rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.convo .m { color: var(--muted); font-size: 0.75rem; margin-top: 0.2rem; }
.convo-actions { display: flex; gap: 0.25rem; margin-top: 0.35rem; }
.sidebar-foot { padding: 0.75rem; border-top: 1px solid var(--border); display: grid; gap: 0.35rem; }
.agent-pills { display: flex; flex-wrap: wrap; gap: 0.3rem; margin-bottom: 0.35rem; }

.main { display: grid; grid-template-rows: auto auto 1fr auto auto auto; min-width: 0; min-height: 0; }
.chat-top {
  display: flex; align-items: center; gap: 0.5rem; padding: 0.65rem 1rem;
  border-bottom: 1px solid var(--border); background: #0d1118cc; backdrop-filter: blur(8px);
}
.chat-title-wrap { display: flex; align-items: center; gap: 0.4rem; min-width: 0; }
.chat-title-wrap h1 { margin: 0; font-size: 1rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#btn-menu { display: none; }

.banner {
  margin: 0.75rem 1rem 0; padding: 0.85rem 1rem; border-radius: 12px;
  background: #3b2f14; border: 1px solid #854d0e; color: #fde68a;
}
.banner button { margin-left: 0.5rem; }

.messages { overflow: auto; padding: 1rem 1rem 0.5rem; display: flex; flex-direction: column; gap: 1rem; }
.msg { max-width: min(820px, 100%); }
.msg.user { align-self: flex-end; }
.msg.assistant { align-self: flex-start; width: 100%; }
.bubble {
  padding: 0.85rem 1rem; border-radius: 16px; line-height: 1.5;
  background: var(--bg3); border: 1px solid var(--border);
}
.msg.user .bubble { background: #1e3a5f; border-color: #2a4a73; }
.msg .meta { font-size: 0.7rem; color: var(--muted); margin: 0.35rem 0.25rem; }
.bubble pre {
  background: #0b1220; border-radius: 10px; padding: 0.75rem; overflow: auto;
  border: 1px solid var(--border); font-family: var(--mono); font-size: 0.85rem;
}
.bubble code { font-family: var(--mono); font-size: 0.9em; }
.bubble p { margin: 0.4rem 0; }
.bubble p:first-child { margin-top: 0; }
.bubble p:last-child { margin-bottom: 0; }

.steps { margin: 0 1rem; border: 1px solid var(--border); border-radius: 12px; background: var(--bg2); }
.steps summary { cursor: pointer; padding: 0.65rem 0.85rem; color: var(--muted); font-size: 0.9rem; }
.steps-body { padding: 0 0.85rem 0.85rem; display: grid; gap: 0.4rem; }
.step { font-size: 0.82rem; padding: 0.45rem 0.55rem; background: var(--bg3); border-radius: 8px; color: var(--muted); }

.composer {
  margin: 0.5rem 1rem 0; display: grid; grid-template-columns: 1fr auto; gap: 0.5rem;
  align-items: end; background: var(--bg2); border: 1px solid var(--border); border-radius: 18px; padding: 0.55rem;
}
.composer textarea {
  border: none; background: transparent; max-height: 160px; min-height: 44px; padding: 0.55rem 0.65rem;
}
.hint { margin: 0.35rem 1rem 0.75rem; color: var(--muted); font-size: 0.75rem; text-align: center; }

.backdrop { position: fixed; inset: 0; background: #000a; z-index: 25; }
.modal { position: fixed; inset: 0; background: #000a; display: grid; place-items: center; z-index: 40; padding: 1rem; }
.modal-card {
  width: min(720px, 100%); max-height: min(86vh, 900px); overflow: auto;
  background: var(--bg2); border: 1px solid var(--border); border-radius: 18px;
}
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 1rem 1.1rem; border-bottom: 1px solid var(--border); }
.modal-head h2 { margin: 0; font-size: 1.05rem; }
.modal-body { padding: 1.1rem; }
.connect-card { border: 1px solid var(--border); border-radius: 14px; padding: 1rem; margin-bottom: 1rem; background: var(--bg3); }
.connect-card h3 { margin: 0 0 0.35rem; }
.connect-status { margin: 0.35rem 0 0.75rem; }
.big-code {
  font-family: var(--mono); font-size: 1.4rem; letter-spacing: 0.08em; font-weight: 700;
  background: #0b1220; border: 1px dashed var(--accent); border-radius: 12px; padding: 0.85rem; text-align: center; margin: 0.5rem 0;
}
.big-link { word-break: break-all; font-size: 0.9rem; }
.files .row { display: flex; gap: 0.5rem; padding: 0.45rem 0.2rem; border-bottom: 1px solid #1b2433; cursor: pointer; font-family: var(--mono); font-size: 0.85rem; }
.file-view { background: #0b1220; border: 1px solid var(--border); border-radius: 10px; padding: 0.75rem; overflow: auto; max-height: 40vh; white-space: pre-wrap; font-family: var(--mono); font-size: 0.8rem; }
.term-wrap { height: 320px; background: #000; border-radius: 10px; border: 1px solid var(--border); overflow: hidden; }

@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; inset: 0 auto 0 0; width: min(86vw, var(--sidebar));
    transform: translateX(-105%); transition: transform .2s ease; box-shadow: 8px 0 40px #0008;
  }
  .sidebar.open { transform: translateX(0); }
  #btn-menu { display: inline-flex; }
}
