:root {
  --bg: #10131a;
  --surface: #171b24;
  --surface-2: #1d2230;
  --border: #262b38;
  --text: #e7e9ee;
  --text-muted: #8b93a7;
  --accent: #e8a33d;
  --accent-dim: #b9822f;
  --teal: #4fd1c5;
  --danger: #e0685f;
  --radius: 10px;
  --font-mono: 'IBM Plex Mono', ui-monospace, monospace;
  --font-body: 'Inter', system-ui, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
}

button, input, textarea, select {
  font-family: inherit;
  color: inherit;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.hidden { display: none !important; }

/* ===== Brand ===== */
.brand { display: flex; align-items: baseline; gap: 8px; }
.brand-mark {
  font-family: var(--font-mono);
  color: var(--accent);
  font-size: 1.1em;
}
.brand-mark.small { font-size: 1em; }
.brand-name {
  font-family: var(--font-mono);
  font-weight: 600;
  letter-spacing: 0.06em;
  font-size: 1.4rem;
}
.brand-name.small { font-size: 1rem; }
.brand-name em { font-style: normal; color: var(--accent); }
.brand-sub {
  color: var(--text-muted);
  font-size: 0.85rem;
  margin: 4px 0 24px;
  font-family: var(--font-mono);
}

/* ===== Auth screen ===== */
.auth-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background:
    radial-gradient(circle at 20% 15%, rgba(232, 163, 61, 0.07), transparent 40%),
    radial-gradient(circle at 80% 85%, rgba(79, 209, 197, 0.06), transparent 40%),
    var(--bg);
}

.auth-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px;
}

.tabs {
  display: flex;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  margin-bottom: 20px;
}
.tab-btn {
  flex: 1;
  padding: 9px 0;
  background: transparent;
  border: none;
  cursor: pointer;
  color: var(--text-muted);
  font-size: 0.9rem;
  transition: background 0.15s, color 0.15s;
}
.tab-btn.active { background: var(--surface-2); color: var(--text); }

.auth-form { display: none; flex-direction: column; gap: 14px; }
.auth-form.active { display: flex; }

.auth-form label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.auth-form input {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 0.95rem;
}
.auth-form input:focus { border-color: var(--accent-dim); }

.btn-primary {
  margin-top: 6px;
  background: var(--accent);
  color: #1a1305;
  border: none;
  border-radius: 8px;
  padding: 11px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}
.btn-primary:hover { background: #f0af4d; }

.form-error {
  min-height: 1.1em;
  color: var(--danger);
  font-size: 0.82rem;
  margin: 0;
}

/* ===== App screen ===== */
.app-screen {
  height: 100vh;
  display: grid;
  grid-template-columns: 260px 1fr;
}

.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 16px 12px;
}
.sidebar-top { display: flex; align-items: baseline; gap: 8px; padding: 4px 8px 18px; }

.btn-new-chat {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 10px;
  cursor: pointer;
  font-size: 0.88rem;
  margin-bottom: 12px;
  transition: border-color 0.15s;
}
.btn-new-chat:hover { border-color: var(--accent-dim); }

.conversation-list {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.conv-item {
  padding: 9px 10px;
  border-radius: 8px;
  font-size: 0.85rem;
  color: var(--text-muted);
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 6px;
}
.conv-item:hover { background: var(--surface-2); }
.conv-item.active { background: var(--surface-2); color: var(--text); }
.conv-item .del-btn {
  opacity: 0;
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 0.9rem;
}
.conv-item:hover .del-btn { opacity: 1; }
.conv-item .del-btn:hover { color: var(--danger); }

.sidebar-bottom {
  border-top: 1px solid var(--border);
  padding-top: 12px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.82rem;
}
.username-label { color: var(--text-muted); font-family: var(--font-mono); }
.btn-ghost {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-muted);
  border-radius: 6px;
  padding: 5px 10px;
  cursor: pointer;
  font-size: 0.78rem;
}
.btn-ghost:hover { color: var(--text); border-color: var(--accent-dim); }

/* ===== Chat pane ===== */
.chat-pane { display: flex; flex-direction: column; height: 100vh; min-width: 0; }

.chat-header {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
}

.model-select {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 7px 10px;
  font-family: var(--font-mono);
  font-size: 0.8rem;
}

.conv-title {
  color: var(--text-muted);
  font-size: 0.85rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 24px 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.empty-state {
  margin: auto;
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: 0.9rem;
}

.msg {
  max-width: 720px;
  width: 100%;
  margin: 0 auto;
  padding: 10px 20px;
  display: flex;
  gap: 14px;
}
.msg-role {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  color: var(--text-muted);
  width: 60px;
  flex-shrink: 0;
  padding-top: 3px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.msg.user .msg-role { color: var(--accent); }
.msg.assistant .msg-role { color: var(--teal); }
.msg-content {
  white-space: pre-wrap;
  line-height: 1.55;
  font-size: 0.95rem;
}

.composer {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  margin: 0 auto 22px;
  width: 100%;
  max-width: 720px;
  padding: 10px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
}
.composer-prompt {
  font-family: var(--font-mono);
  color: var(--accent);
  padding-bottom: 9px;
}
.composer textarea {
  flex: 1;
  background: transparent;
  border: none;
  resize: none;
  max-height: 200px;
  padding: 8px 0;
  font-size: 0.95rem;
  line-height: 1.4;
}
.composer textarea:focus { outline: none; }

.btn-send {
  background: var(--accent);
  color: #1a1305;
  border: none;
  border-radius: 8px;
  padding: 9px 16px;
  font-weight: 600;
  font-size: 0.85rem;
  cursor: pointer;
}
.btn-send:hover { background: #f0af4d; }
.btn-send:disabled { opacity: 0.5; cursor: default; }

@media (max-width: 720px) {
  .app-screen { grid-template-columns: 1fr; }
  .sidebar { position: fixed; inset: 0 30% 0 0; z-index: 10; transform: translateX(-100%); transition: transform 0.2s; }
  .sidebar.open { transform: translateX(0); }
}
