:root {
  --bg: #07090e;
  --panel: #10141c;
  --ink: #dce8f4;
  --muted: #8aa0b5;
  --line: #1c2a3a;
  --accent: #d7c4a3;
  --user: #16283a;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 17px/1.45 system-ui, sans-serif;
}
button, textarea, input { font: inherit; color: inherit; }
button { cursor: pointer; }
.login {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: 24px;
}
.login form, .history, .top, .composer {
  border: 1px solid var(--line);
  background: #10141ccc;
}
.login form {
  width: min(420px, 100%);
  border-radius: 16px;
  padding: 22px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.login h1, .top h1 { margin: 0; letter-spacing: 0.08em; font-weight: 600; }
.login p, .top p { margin: 0; color: var(--muted); }
label { display: flex; flex-direction: column; gap: 4px; color: var(--muted); font-size: 13px; }
input, textarea {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #07090e;
  padding: 10px 12px;
  min-height: 44px;
}
.login button, .new-chat, .history-btn, #sign-out, #send, .chat-row, .delete {
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #10141c;
}
.login button, #send { background: var(--accent); color: #1a140c; border: 0; }
.error { color: #e07a72; min-height: 1.2em; }
.desk {
  height: 100%;
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
}
.login[hidden],
.desk[hidden] {
  display: none;
}
.history {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 12px;
  border-right: 1px solid var(--line);
  min-height: 0;
}
.history nav { overflow: auto; display: flex; flex-direction: column; gap: 8px; }
.history h2 {
  margin: 8px 4px 0;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.chat-row, .chat-row.on { text-align: left; padding: 10px 12px; white-space: normal; }
.chat-row.on { border-color: var(--accent); color: var(--accent); }
main {
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
}
.top, .composer {
  display: flex;
  gap: 10px;
  align-items: center;
  padding: 10px 12px;
}
.top { justify-content: space-between; }
.history-btn { display: none; }
.thread {
  overflow: auto;
  padding: 18px 12px 8px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.bubble {
  width: min(720px, 100%);
  margin: 0 auto;
  white-space: pre-wrap;
  padding: 12px 14px;
  border-radius: 14px;
  border: 1px solid var(--line);
}
.bubble.user { background: var(--user); }
.bubble.assistant { background: #10141c; }
.empty, .status {
  width: min(720px, 100%);
  margin: 8px auto;
  color: var(--muted);
  text-align: center;
}
.composer { align-items: flex-end; }
.composer textarea { flex: 1; resize: none; max-height: 160px; }
.row-actions { width: min(720px, 100%); margin: 0 auto; display: flex; justify-content: flex-end; }
.scrim {
  display: none;
  border: 0;
  background: #0008;
}
@media (max-width: 720px) {
  .desk { grid-template-columns: 1fr; }
  .history-btn { display: inline-flex; align-items: center; }
  .history {
    display: none;
    position: fixed;
    z-index: 3;
    inset: 0 auto 0 0;
    width: min(320px, 88vw);
    background: var(--bg);
  }
  body.history-open .history { display: flex; }
  body.history-open .scrim { display: block; position: fixed; inset: 0; z-index: 2; }
  .top p { display: none; }
  .composer { padding-bottom: calc(10px + env(safe-area-inset-bottom)); }
}
