:root {
  color-scheme: dark;
  --bg: #0f1012;
  --sidebar: #141518;
  --panel: #1a1c20;
  --panel-2: #22252b;
  --panel-3: #282c33;
  --line: #30343c;
  --line-soft: #24272d;
  --text: #eef1f5;
  --muted: #9aa3af;
  --muted-2: #747d8b;
  --accent: #35d39a;
  --accent-2: #9ae6c8;
  --danger: #ff6b6b;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
button, textarea, select { font: inherit; }
button { color: inherit; }
.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr);
  background: var(--bg);
}
.sidebar {
  min-width: 0;
  border-right: 1px solid var(--line);
  background: var(--sidebar);
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: 18px;
  padding: 18px;
}
.sidebar-head { display: grid; gap: 16px; }
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.mark {
  width: 38px;
  height: 38px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  background: var(--accent);
  color: #07110d;
  font-weight: 850;
}
h1, h2, p { margin: 0; }
h1 { font-size: 18px; line-height: 1.1; }
.brand p, .chat-heading p { color: var(--muted); font-size: 13px; overflow-wrap: anywhere; }
.primary-action, .icon-button, #send {
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--text);
  border-radius: 8px;
  cursor: pointer;
}
.primary-action {
  width: 100%;
  padding: 11px 12px;
  display: flex;
  justify-content: center;
  gap: 8px;
  align-items: center;
  font-weight: 700;
}
.primary-action span { color: var(--accent-2); font-size: 18px; line-height: 1; }
.primary-action:hover, .icon-button:hover { border-color: var(--accent); }
.history-pane { min-height: 0; display: grid; grid-template-rows: auto minmax(0, 1fr); gap: 9px; }
.section-label {
  color: var(--muted-2);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0;
}
.conversation-list {
  min-height: 0;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding-right: 2px;
}
.conversation-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 32px;
  align-items: stretch;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
}
.conversation-item:hover { background: #1a1d22; border-color: var(--line-soft); }
.conversation-item.active { background: #1c2422; border-color: #25483b; }
.conversation-open {
  min-width: 0;
  border: 0;
  background: transparent;
  color: var(--text);
  padding: 10px 8px 10px 10px;
  text-align: left;
  cursor: pointer;
  display: grid;
  gap: 2px;
}
.conversation-title {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 14px;
}
.conversation-meta { color: var(--muted-2); font-size: 12px; }
.conversation-delete {
  border: 0;
  background: transparent;
  color: var(--muted-2);
  cursor: pointer;
  border-radius: 6px;
  margin: 5px 5px 5px 0;
  font-size: 20px;
  line-height: 1;
}
.conversation-delete:hover { color: #ffd4d4; background: #3a2023; }
.settings-pane {
  border-top: 1px solid var(--line-soft);
  padding-top: 14px;
  display: grid;
  gap: 12px;
}
.field { display: grid; gap: 7px; color: var(--muted); font-size: 13px; }
.field small { color: var(--muted-2); line-height: 1.45; }
select {
  width: 100%;
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--text);
  border-radius: 8px;
  padding: 10px 12px;
  outline: none;
}
select:focus, textarea:focus { border-color: var(--accent); }
.chat-shell {
  min-width: 0;
  height: 100vh;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
}
.topbar {
  min-height: 72px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px max(22px, 5vw);
  background: rgba(15, 16, 18, 0.96);
}
.icon-button {
  width: 40px;
  height: 40px;
  display: none;
  place-items: center;
  font-size: 20px;
}
.chat-heading { min-width: 0; display: grid; gap: 3px; }
.chat-heading h2 {
  font-size: 18px;
  line-height: 1.2;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.messages {
  overflow: auto;
  padding: 28px max(22px, 8vw);
  display: flex;
  flex-direction: column;
  gap: 20px;
}
.empty-state {
  margin: auto;
  width: min(720px, 100%);
  text-align: center;
  color: var(--muted);
}
.empty-state h2 {
  color: var(--text);
  font-size: clamp(30px, 5vw, 48px);
  margin: 0 0 10px;
  letter-spacing: 0;
}
.msg {
  display: grid;
  grid-template-columns: 38px minmax(0, 1fr);
  gap: 12px;
  max-width: 980px;
  width: 100%;
}
.msg.user { align-self: end; max-width: 860px; }
.avatar {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  background: var(--panel-2);
  border: 1px solid var(--line);
  color: var(--muted);
  font-weight: 800;
  font-size: 13px;
}
.msg.assistant .avatar { background: #163128; color: #a9f3d0; border-color: #275444; }
.msg.user .avatar { background: #23252b; color: var(--text); }
.message-main { min-width: 0; display: grid; gap: 7px; }
.role { color: var(--muted); font-size: 13px; }
.bubble {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 13px 15px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.msg.user .bubble { background: #20242b; }
.msg.error .bubble, .msg.system .bubble { border-color: #6f3030; color: #ffd7d7; background: #24191b; }
.reasoning-box {
  border: 1px solid #34413d;
  background: #151d1a;
  color: #b8c7c0;
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 13px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.reasoning-box:empty { display: none; }
.reasoning-title { color: #7ee2b8; font-weight: 750; margin-bottom: 4px; }
.composer {
  border-top: 1px solid var(--line);
  padding: 16px max(22px, 8vw) 18px;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  background: rgba(15, 16, 18, 0.96);
}
textarea {
  resize: none;
  max-height: 220px;
  min-height: 48px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--text);
  padding: 12px 14px;
  outline: none;
}
#send {
  min-width: 82px;
  background: var(--accent);
  color: #07110d;
  font-weight: 800;
  border-color: transparent;
  padding: 0 18px;
}
#send:disabled, select:disabled { opacity: .55; cursor: not-allowed; }
.sidebar-backdrop { display: none; }
code, pre { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
@media (max-width: 860px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed;
    z-index: 30;
    inset: 0 auto 0 0;
    width: min(330px, 88vw);
    transform: translateX(-100%);
    transition: transform .18s ease;
    box-shadow: 18px 0 40px rgba(0, 0, 0, .32);
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-backdrop.show {
    display: block;
    position: fixed;
    z-index: 20;
    inset: 0;
    background: rgba(0, 0, 0, .48);
  }
  .chat-shell { height: 100vh; }
  .icon-button { display: grid; }
  .topbar { padding: 12px 16px; }
  .messages { padding: 18px; }
  .msg, .msg.user { max-width: 100%; grid-template-columns: 34px minmax(0, 1fr); gap: 10px; }
  .composer { padding: 12px; grid-template-columns: 1fr; }
  #send { min-height: 44px; width: 100%; }
}

.hidden { display: none !important; }
.auth-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: #0f1012;
}
.auth-card {
  width: min(430px, 100%);
  border: 1px solid var(--line);
  background: var(--sidebar);
  border-radius: 8px;
  padding: 24px;
  display: grid;
  gap: 18px;
  box-shadow: 0 24px 80px rgba(0,0,0,.28);
}
.auth-brand { display: flex; align-items: center; gap: 12px; }
.auth-brand h1 { font-size: 20px; }
.auth-brand p { color: var(--muted); font-size: 13px; }
.auth-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  padding: 4px;
  background: var(--panel);
  border: 1px solid var(--line-soft);
  border-radius: 8px;
}
.auth-tabs button {
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  padding: 9px 10px;
  cursor: pointer;
}
.auth-tabs button.active { background: var(--panel-3); color: var(--text); }
.auth-form { display: grid; gap: 14px; }
input {
  width: 100%;
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--text);
  border-radius: 8px;
  padding: 11px 12px;
  outline: none;
}
input:focus { border-color: var(--accent); }
.auth-error, .error-text { color: #ffb4b4; }
.auth-error { min-height: 20px; font-size: 13px; }
.user-panel {
  border: 1px solid var(--line-soft);
  background: var(--panel);
  border-radius: 8px;
  padding: 10px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
}
.user-panel span {
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.user-panel button {
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--muted);
  border-radius: 7px;
  padding: 6px 9px;
  cursor: pointer;
}
.user-panel button:hover { color: var(--text); border-color: var(--accent); }
.history-empty {
  color: var(--muted-2);
  font-size: 13px;
  padding: 10px;
}