* { box-sizing: border-box; margin: 0; padding: 0; }
:root {
  --bg: #0f1115;
  --panel: #161a21;
  --panel-2: #1d222b;
  --border: #2a303b;
  --text: #e6e9ef;
  --muted: #8b93a3;
  --accent: #4f9e6f;
  --accent-2: #67b98a;
  --user-bubble: #24406b;
  --error: #c05a5a;
}
html, body { height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.55 -apple-system, "Segoe UI", Roboto, Ubuntu, sans-serif;
}
.hidden { display: none !important; }

/* ---------- login ---------- */
.login {
  height: 100vh; display: flex; align-items: center; justify-content: center;
}
.login-card {
  background: var(--panel); border: 1px solid var(--border); border-radius: 14px;
  padding: 36px 32px; width: 320px; display: flex; flex-direction: column; gap: 14px;
}
.login-card h1 { font-size: 20px; text-align: center; }
.login-card .tagline {
  color: var(--muted); font-size: 12.5px; text-align: center;
  margin: -6px 0 8px; line-height: 1.4;
}
.login-card input {
  background: var(--panel-2); border: 1px solid var(--border); color: var(--text);
  border-radius: 8px; padding: 10px 12px; font-size: 15px;
}
.login-card button {
  background: var(--accent); border: 0; color: #fff; border-radius: 8px;
  padding: 10px; font-size: 15px; cursor: pointer;
}
.login-card button:hover { background: var(--accent-2); }
.login-error { color: var(--error); font-size: 13px; text-align: center; min-height: 18px; }

/* ---------- layout ---------- */
.app { display: flex; height: 100vh; }
.sidebar {
  width: 264px; min-width: 264px; background: var(--panel);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
}
.sidebar-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 14px 10px;
}
.brand { font-weight: 600; letter-spacing: .3px; }
.sidebar-head button {
  background: var(--accent); color: #fff; border: 0; border-radius: 8px;
  padding: 6px 12px; cursor: pointer; font-size: 13px;
}
.sidebar-head button:hover { background: var(--accent-2); }
.session-list { flex: 1; overflow-y: auto; padding: 6px 8px; }
.session-item {
  display: flex; align-items: center; gap: 8px;
  padding: 9px 10px; border-radius: 8px; cursor: pointer;
  color: var(--muted); font-size: 13.5px; margin-bottom: 2px;
  border: 1px solid transparent;
}
.session-item:hover { background: var(--panel-2); color: var(--text); }
.session-item.active { background: var(--panel-2); color: var(--text); border-color: var(--border); }
.session-item .title {
  flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.session-item .dot {
  width: 7px; height: 7px; border-radius: 50%; background: var(--accent);
  flex: none; animation: pulse 1.2s infinite; display: none;
}
.session-item.running .dot { display: block; }
.session-item .del {
  background: none; border: 0; color: var(--muted); cursor: pointer;
  font-size: 14px; padding: 0 2px; visibility: hidden;
}
.session-item:hover .del { visibility: visible; }
.session-item .del:hover { color: var(--error); }
@keyframes pulse { 50% { opacity: .3; } }
.sidebar-foot { padding: 10px 14px; border-top: 1px solid var(--border); }
.ghost {
  background: none; border: 1px solid var(--border); color: var(--muted);
  border-radius: 8px; padding: 6px 12px; cursor: pointer; font-size: 13px;
}
.ghost:hover { color: var(--text); }

/* ---------- chat ---------- */
.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.chat { flex: 1; overflow-y: auto; padding: 24px 0; }
.empty-hint { text-align: center; color: var(--muted); margin-top: 18vh; }
.empty-hint h2 { font-weight: 500; margin-bottom: 8px; color: var(--text); }
.messages { max-width: 820px; margin: 0 auto; padding: 0 20px; }
.msg { margin-bottom: 18px; display: flex; }
.msg.user { justify-content: flex-end; }
.msg .bubble {
  max-width: 88%; padding: 10px 14px; border-radius: 12px;
  word-wrap: break-word; overflow-wrap: break-word;
}
.msg.user .bubble { background: var(--user-bubble); white-space: pre-wrap; }
.msg.assistant .bubble { background: var(--panel); border: 1px solid var(--border); max-width: 100%; flex: 1; }
.msg .bubble p { margin: 0 0 10px; }
.msg .bubble p:last-child { margin-bottom: 0; }
.msg .bubble h1, .msg .bubble h2, .msg .bubble h3 { margin: 14px 0 8px; font-size: 1.05em; }
.msg .bubble ul, .msg .bubble ol { margin: 0 0 10px 22px; }
.msg .bubble li { margin-bottom: 3px; }
.msg .bubble blockquote {
  border-left: 3px solid var(--border); padding-left: 10px; color: var(--muted); margin: 0 0 10px;
}
.msg .bubble code {
  background: #10131a; border: 1px solid var(--border); border-radius: 4px;
  padding: 1px 5px; font: 13px/1.5 "SF Mono", Menlo, Consolas, monospace;
}
.msg .bubble pre {
  background: #10131a; border: 1px solid var(--border); border-radius: 8px;
  padding: 12px; overflow-x: auto; margin: 0 0 10px;
}
.msg .bubble pre code { background: none; border: 0; padding: 0; }
.msg .bubble a { color: var(--accent-2); }
.tool-chip {
  display: inline-block; background: var(--panel-2); border: 1px solid var(--border);
  color: var(--muted); border-radius: 20px; padding: 2px 12px; font-size: 12.5px;
  margin: 4px 0 10px;
}
.error-chip { color: var(--error); border-color: var(--error); }
.typing { color: var(--muted); font-size: 13px; padding-left: 4px; }
.typing::after { content: '▍'; animation: pulse 1s infinite; }

/* ---------- composer ---------- */
.composer {
  display: flex; gap: 10px; padding: 14px 20px 18px;
  max-width: 860px; margin: 0 auto; width: 100%;
}
.composer textarea {
  flex: 1; resize: none; background: var(--panel); color: var(--text);
  border: 1px solid var(--border); border-radius: 10px; padding: 11px 14px;
  font: inherit; max-height: 200px; outline: none;
}
.composer textarea:focus { border-color: var(--accent); }
.composer button {
  background: var(--accent); color: #fff; border: 0; border-radius: 10px;
  padding: 0 20px; cursor: pointer; font-size: 14.5px;
}
.composer button:hover { background: var(--accent-2); }
.composer button:disabled { opacity: .5; cursor: default; }
.composer .stop { background: var(--error); }

/* ---------- right sidebar ---------- */
.rightbar {
  width: 250px; min-width: 250px; background: var(--panel);
  border-left: 1px solid var(--border);
  display: flex; flex-direction: column;
}
.rightbar-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 14px 6px; font-weight: 600; letter-spacing: .3px;
}
.ghost.sm { padding: 2px 8px; font-size: 13px; }
.rightbar-legend {
  display: flex; gap: 10px; padding: 0 14px 8px;
  color: var(--muted); font-size: 11.5px;
  border-bottom: 1px solid var(--border);
}
.domain-list { flex: 1; overflow-y: auto; padding: 6px 8px; }
.domains-loading { color: var(--muted); font-size: 13px; padding: 10px; }
.domain-item {
  display: flex; align-items: center; gap: 6px;
  padding: 5px 8px; border-radius: 6px; cursor: pointer;
  font-size: 12.5px; color: var(--text);
}
.domain-item:hover { background: var(--panel-2); }
.domain-item .dname {
  flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.domain-item .src { font-size: 11px; width: 15px; text-align: center; }
.domain-item .src.off { opacity: .12; filter: grayscale(1); }
.rightbar-foot {
  padding: 8px 14px; border-top: 1px solid var(--border);
  color: var(--muted); font-size: 11.5px;
}

@media (max-width: 1050px) {
  .rightbar { display: none; }
}
@media (max-width: 700px) {
  .sidebar { position: absolute; z-index: 10; height: 100%; transform: translateX(-100%); transition: transform .2s; }
  .sidebar.open { transform: none; }
}
