:root {
  --bg: #0b0b12;
  --bg-2: #10101a;
  --panel: #14141f;
  --panel-2: #1a1a28;
  --line: #262636;
  --text: #ececf4;
  --muted: #9a9ab0;
  --accent: #8b7cf6;
  --accent-2: #22d3ee;
  --good: #34d399;
  --warn: #fbbf24;
  --bad: #f87171;
  --radius: 14px;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: radial-gradient(1200px 700px at 80% -10%, rgba(139,124,246,.14), transparent 60%),
              radial-gradient(900px 600px at -10% 110%, rgba(34,211,238,.10), transparent 55%),
              var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}
#app { display: grid; grid-template-columns: 290px 1fr; height: 100vh; }

/* ---------- Sidebar ---------- */
#sidebar {
  background: linear-gradient(180deg, var(--panel) 0%, var(--bg-2) 100%);
  border-right: 1px solid var(--line);
  display: flex; flex-direction: column;
  padding: 16px 12px;
  gap: 12px;
  min-height: 0;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 6px; }
.brand-mark {
  width: 36px; height: 36px; border-radius: 10px; display: grid; place-items: center;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  font-size: 18px;
}
.brand-name { font-weight: 700; letter-spacing: .2px; }
.brand-sub { font-size: 11px; color: var(--muted); letter-spacing: .8px; text-transform: uppercase; }
.new-chat-btn {
  border: 1px solid var(--line); background: var(--panel-2); color: var(--text);
  border-radius: 10px; padding: 10px 12px; font-weight: 600; cursor: pointer; font-size: 14px;
  transition: border-color .15s, background .15s;
}
.new-chat-btn:hover { border-color: var(--accent); background: #20203a; }
.agent-search input {
  width: 100%; background: var(--bg-2); border: 1px solid var(--line); color: var(--text);
  border-radius: 10px; padding: 8px 12px; font-size: 13px; outline: none;
}
.agent-search input:focus { border-color: var(--accent); }
#agent-list { overflow-y: auto; flex: 1; display: flex; flex-direction: column; gap: 4px; scrollbar-width: thin; scrollbar-color: var(--line) transparent; }
.agent-item {
  display: flex; gap: 10px; align-items: flex-start;
  padding: 9px 10px; border-radius: 10px; cursor: pointer; border: 1px solid transparent;
  transition: background .12s, border-color .12s;
}
.agent-item:hover { background: var(--panel-2); }
.agent-item.active { background: #20203a; border-color: var(--accent); }
.agent-item .a-emoji { font-size: 18px; margin-top: 1px; }
.agent-item .a-name { font-size: 13.5px; font-weight: 600; }
.agent-item .a-tag { font-size: 11.5px; color: var(--muted); line-height: 1.35; margin-top: 2px; }
.sidebar-foot { border-top: 1px solid var(--line); padding-top: 10px; display: flex; flex-direction: column; gap: 8px; }
.usage-line { font-size: 12px; color: var(--muted); }
.foot-links { display: flex; gap: 14px; }
.foot-links a { color: var(--muted); font-size: 12px; text-decoration: none; }
.foot-links a:hover { color: var(--text); }

/* ---------- Main ---------- */
#main { display: grid; grid-template-rows: auto 1fr auto; min-width: 0; min-height: 0; }
#topbar {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 20px; border-bottom: 1px solid var(--line);
  background: rgba(11,11,18,.7); backdrop-filter: blur(8px);
}
.agent-head { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 0; }
.agent-emoji { font-size: 22px; }
.agent-name { font-weight: 700; font-size: 15px; }
.agent-tagline { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.badge {
  font-size: 11px; color: var(--accent-2); border: 1px solid rgba(34,211,238,.35);
  padding: 4px 10px; border-radius: 999px; white-space: nowrap;
}
.icon-btn {
  background: none; border: 1px solid var(--line); color: var(--text);
  border-radius: 8px; width: 34px; height: 34px; cursor: pointer; font-size: 15px;
}

/* ---------- Chat ---------- */
#chat { overflow-y: auto; padding: 24px 20px; scrollbar-width: thin; scrollbar-color: var(--line) transparent; }
.welcome { max-width: 760px; margin: 6vh auto 0; text-align: center; }
.welcome h1 { font-size: clamp(28px, 4.5vw, 42px); margin: 0 0 12px; line-height: 1.15; }
.grad { background: linear-gradient(90deg, var(--accent), var(--accent-2)); -webkit-background-clip: text; background-clip: text; color: transparent; }
.lede { color: var(--muted); font-size: 15px; margin: 0 0 28px; }
.starter-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 10px; text-align: left; }
.starter {
  border: 1px solid var(--line); background: var(--panel); border-radius: var(--radius);
  padding: 14px; cursor: pointer; transition: border-color .15s, transform .1s;
  font-size: 13px; color: var(--text);
}
.starter:hover { border-color: var(--accent); transform: translateY(-1px); }
.starter .s-emoji { font-size: 17px; display: block; margin-bottom: 6px; }
.starter .s-text { color: var(--muted); }

#messages { max-width: 780px; margin: 0 auto; display: flex; flex-direction: column; gap: 18px; }
.msg { display: flex; gap: 12px; }
.msg .avatar {
  width: 32px; height: 32px; border-radius: 9px; display: grid; place-items: center;
  font-size: 16px; flex-shrink: 0; background: var(--panel-2); border: 1px solid var(--line);
}
.msg.user .avatar { background: linear-gradient(135deg, var(--accent), var(--accent-2)); border: none; }
.msg .bubble { min-width: 0; font-size: 14.5px; line-height: 1.65; }
.msg.user .bubble { color: var(--text); }
.msg.agent .bubble {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 14px 16px;
}
.msg .bubble p { margin: 0 0 10px; }
.msg .bubble p:last-child { margin-bottom: 0; }
.msg .bubble h1, .msg .bubble h2, .msg .bubble h3 { font-size: 15px; margin: 14px 0 8px; }
.msg .bubble ul, .msg .bubble ol { margin: 8px 0; padding-left: 22px; }
.msg .bubble li { margin: 4px 0; }
.msg .bubble code {
  background: var(--bg-2); border: 1px solid var(--line); border-radius: 5px;
  padding: 1px 5px; font-size: 13px; font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}
.msg .bubble pre {
  background: var(--bg-2); border: 1px solid var(--line); border-radius: 10px;
  padding: 12px 14px; overflow-x: auto; margin: 10px 0;
}
.msg .bubble pre code { background: none; border: none; padding: 0; font-size: 12.5px; line-height: 1.55; }
.msg .bubble table { border-collapse: collapse; margin: 10px 0; font-size: 13px; width: 100%; }
.msg .bubble th, .msg .bubble td { border: 1px solid var(--line); padding: 6px 10px; text-align: left; }
.msg .bubble th { background: var(--bg-2); }
.msg .bubble a { color: var(--accent-2); }
.msg-meta { font-size: 11px; color: var(--muted); margin-top: 8px; }
.copy-btn {
  background: none; border: 1px solid var(--line); color: var(--muted);
  font-size: 11px; border-radius: 6px; padding: 3px 8px; cursor: pointer; margin-left: 8px;
}
.copy-btn:hover { color: var(--text); border-color: var(--accent); }
.typing { display: inline-flex; gap: 4px; padding: 6px 0; }
.typing span { width: 6px; height: 6px; border-radius: 50%; background: var(--accent); animation: blink 1.2s infinite; }
.typing span:nth-child(2) { animation-delay: .2s; }
.typing span:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 80%, 100% { opacity: .25; } 40% { opacity: 1; } }

/* ---------- Composer ---------- */
#composer { padding: 14px 20px 16px; border-top: 1px solid var(--line); background: rgba(11,11,18,.75); backdrop-filter: blur(8px); }
.composer-inner, .composer-row, .composer-foot { max-width: 780px; margin: 0 auto; }
.audit-bar { display: flex; gap: 8px; max-width: 780px; margin: 0 auto 10px; }
.audit-bar.hidden { display: none; }
.audit-bar input {
  flex: 1; background: var(--panel); border: 1px solid var(--line); color: var(--text);
  border-radius: 10px; padding: 9px 12px; font-size: 13px; outline: none;
}
.audit-bar input:focus { border-color: var(--accent); }
.audit-run {
  background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #fff;
  border: none; border-radius: 10px; padding: 9px 18px; font-weight: 700; cursor: pointer; font-size: 13px;
}
.audit-run:disabled { opacity: .6; cursor: wait; }
.composer-row { display: flex; gap: 10px; align-items: flex-end; }
#input {
  flex: 1; resize: none; background: var(--panel); border: 1px solid var(--line); color: var(--text);
  border-radius: 12px; padding: 12px 14px; font-size: 14.5px; font-family: inherit; outline: none;
  max-height: 180px; line-height: 1.5;
}
#input:focus { border-color: var(--accent); }
#send {
  width: 44px; height: 44px; border-radius: 12px; border: none; cursor: pointer;
  background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #fff; font-size: 16px;
}
#send:disabled { opacity: .5; cursor: wait; }
.composer-foot { display: flex; justify-content: space-between; align-items: center; margin-top: 8px; font-size: 11.5px; color: var(--muted); }
.agent-chip { color: var(--accent); font-weight: 600; }

/* ---------- Errors ---------- */
.error-bubble {
  border: 1px solid rgba(248,113,113,.4); background: rgba(248,113,113,.08);
  color: #fca5a5; border-radius: var(--radius); padding: 12px 16px; font-size: 13.5px;
  max-width: 780px; margin: 0 auto;
}

.mobile-only { display: none; }

@media (max-width: 860px) {
  #app { grid-template-columns: 1fr; }
  #sidebar {
    position: fixed; inset: 0 30% 0 0; min-width: 260px; z-index: 50;
    transform: translateX(-105%); transition: transform .2s ease;
    box-shadow: 20px 0 60px rgba(0,0,0,.5);
  }
  #sidebar.open { transform: translateX(0); }
  .mobile-only { display: grid; place-items: center; }
  .badge { display: none; }
  #chat { padding: 16px 14px; }
}
