:root {
  color-scheme: dark;
  --bg: #111318;
  --panel: #171a21;
  --panel-2: #1d212a;
  --line: #2a303c;
  --text: #e8ebf2;
  --muted: #8d96a8;
  --accent: #d7a96b;
  --accent-strong: #efc487;
  --danger: #ef8f8f;
  --ok: #7dc9a4;
  --radius: 14px;
  --shadow: 0 18px 60px rgba(0, 0, 0, 0.33);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html, body { min-height: 100%; }
body {
  margin: 0;
  background: radial-gradient(circle at 10% 0%, #1e2330 0, var(--bg) 42%);
  color: var(--text);
}
button, input, textarea { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: 0.5; }

.login-page { display: grid; min-height: 100vh; place-items: center; padding: 24px; }
.login-shell { width: min(100%, 440px); }
.login-card {
  background: linear-gradient(160deg, rgba(29, 33, 42, 0.98), rgba(20, 23, 30, 0.98));
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 36px;
  box-shadow: var(--shadow);
}
.login-card h1 { margin: 6px 0 8px; font-size: 2rem; letter-spacing: -0.04em; }
.login-card form { display: grid; gap: 10px; margin-top: 28px; }
.login-card label { color: var(--muted); font-size: 0.88rem; }
.login-card input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg);
  color: var(--text);
  padding: 12px 14px;
  outline: none;
}
.login-card input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(215, 169, 107, 0.12); }
.login-card button {
  margin-top: 10px;
  border: 0;
  border-radius: 10px;
  background: var(--accent);
  color: #17120c;
  font-weight: 750;
  padding: 12px 16px;
}
.form-error { min-height: 1.4em; margin: 2px 0 0; color: var(--danger); font-size: 0.9rem; }
.muted { color: var(--muted); }
.eyebrow { margin: 0; color: var(--accent); font-size: 0.68rem; font-weight: 750; letter-spacing: 0.18em; }

.app { display: grid; grid-template-columns: 280px minmax(0, 1fr); min-height: 100vh; }
.sidebar {
  position: sticky;
  top: 0;
  display: flex;
  height: 100vh;
  flex-direction: column;
  gap: 18px;
  padding: 22px 16px;
  background: rgba(18, 21, 27, 0.92);
  border-right: 1px solid var(--line);
  backdrop-filter: blur(16px);
}
.brand-row { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; padding: 4px 6px; }
.brand-row h1 { margin: 6px 0 0; font-size: 1.22rem; letter-spacing: -0.035em; }
.sidebar-close, .menu-button { display: none; }
.new-chat {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel-2);
  color: var(--text);
  padding: 11px 12px;
  text-align: left;
}
.new-chat:hover { border-color: var(--accent); }
.conversation-list { display: grid; gap: 5px; overflow-y: auto; padding-right: 2px; }
.conversation-item {
  width: 100%;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: var(--muted);
  padding: 10px 11px;
  text-align: left;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.conversation-item:hover { background: var(--panel); color: var(--text); }
.conversation-item.active { background: var(--panel-2); color: var(--text); box-shadow: inset 2px 0 0 var(--accent); }
.sidebar-footer { display: grid; gap: 12px; margin-top: auto; padding: 8px 6px 2px; }
.connection { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 0.82rem; }
.connection-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--danger); }
.connection-dot.online { background: var(--ok); box-shadow: 0 0 0 4px rgba(125, 201, 164, 0.1); }
.text-button { border: 0; background: transparent; color: var(--muted); padding: 0; text-align: left; }
.text-button:hover { color: var(--text); }

.main { display: grid; grid-template-rows: auto minmax(0, 1fr) auto auto; min-height: 100vh; }
.topbar {
  display: flex;
  align-items: center;
  gap: 14px;
  min-height: 70px;
  padding: 14px clamp(18px, 4vw, 44px);
  border-bottom: 1px solid rgba(42, 48, 60, 0.7);
  background: rgba(17, 19, 24, 0.7);
  backdrop-filter: blur(12px);
}
.topbar h2 { flex: 1; margin: 0; font-size: 0.98rem; font-weight: 650; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.status-pill { border: 1px solid var(--line); border-radius: 999px; color: var(--muted); font-size: 0.75rem; padding: 5px 10px; }
.status-pill.running { border-color: rgba(215, 169, 107, 0.5); color: var(--accent-strong); }
.icon-button { border: 1px solid var(--line); border-radius: 8px; background: var(--panel); color: var(--text); width: 34px; height: 34px; }

.messages { overflow-y: auto; padding: 36px clamp(18px, 5vw, 72px) 20px; scroll-behavior: smooth; }
.empty-state { max-width: 620px; margin: 12vh auto 0; text-align: center; color: var(--muted); }
.empty-state h3 { margin-bottom: 8px; color: var(--text); font-size: 1.35rem; }
.message { width: min(100%, 880px); margin: 0 auto 22px; }
.message.user { display: flex; justify-content: flex-end; }
.message-bubble { border-radius: var(--radius); line-height: 1.65; }
.message.user .message-bubble {
  max-width: min(78%, 680px);
  border: 1px solid #343b48;
  background: #252b36;
  padding: 12px 15px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.message.assistant .message-bubble { padding: 2px 0; overflow-wrap: anywhere; }
.message-label { margin: 0 0 7px; color: var(--muted); font-size: 0.72rem; letter-spacing: 0.08em; text-transform: uppercase; }
.message.assistant .message-label { margin-left: 2px; }
.message p { margin: 0 0 1em; }
.message p:last-child { margin-bottom: 0; }
.message h1, .message h2, .message h3 { margin: 1.2em 0 0.5em; line-height: 1.25; }
.message h1 { font-size: 1.35rem; }
.message h2 { font-size: 1.16rem; }
.message h3 { font-size: 1.02rem; }
.message ul, .message ol { margin: 0.5em 0 1em; padding-left: 1.5em; }
.message li { margin: 0.25em 0; }
.message a { color: var(--accent-strong); }
.message code { border-radius: 5px; background: #202530; color: #f1d4a8; padding: 0.13em 0.35em; font-size: 0.9em; }
.message pre { overflow-x: auto; border: 1px solid var(--line); border-radius: 10px; background: #0b0d11; padding: 14px 16px; margin: 0.8em 0 1em; }
.message pre code { background: transparent; color: #e9edf5; padding: 0; font-size: 0.87rem; line-height: 1.55; }
.cursor::after { content: "▋"; color: var(--accent); animation: blink 1s steps(2, start) infinite; }
@keyframes blink { 50% { opacity: 0; } }

.composer { padding: 0 clamp(18px, 5vw, 72px) 28px; }
.composer textarea {
  display: block;
  width: min(100%, 880px);
  max-height: 220px;
  margin: 0 auto;
  resize: none;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--panel);
  color: var(--text);
  padding: 15px 16px 8px;
  outline: none;
  line-height: 1.5;
}
.composer textarea:focus { border-color: rgba(215, 169, 107, 0.72); box-shadow: 0 0 0 3px rgba(215, 169, 107, 0.1); }
.composer-footer { display: flex; align-items: center; justify-content: space-between; gap: 16px; width: min(100%, 880px); margin: 8px auto 0; }
.composer-hint { color: var(--muted); font-size: 0.76rem; }
.composer-actions { display: flex; gap: 8px; }
.primary-button, .secondary-button { border-radius: 9px; padding: 9px 16px; }
.primary-button { border: 0; background: var(--accent); color: #17120c; font-weight: 750; }
.secondary-button { border: 1px solid var(--line); background: var(--panel); color: var(--text); }
.error-banner {
  width: min(calc(100% - 36px), 880px);
  margin: 0 auto 10px;
  border: 1px solid rgba(239, 143, 143, 0.35);
  border-radius: 10px;
  background: rgba(94, 32, 39, 0.35);
  color: #ffc4c4;
  padding: 9px 12px;
  font-size: 0.84rem;
}

@media (max-width: 760px) {
  .app { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed;
    z-index: 20;
    left: 0;
    width: min(86vw, 320px);
    transform: translateX(-105%);
    transition: transform 180ms ease;
    box-shadow: var(--shadow);
  }
  body.sidebar-open .sidebar { transform: translateX(0); }
  .sidebar-close, .menu-button { display: inline-grid; place-items: center; }
  .topbar { min-height: 62px; }
  .message.user .message-bubble { max-width: 90%; }
  .composer-hint { display: none; }
}
