/* Contemplate — giao diện chat, mobile-first, tông hổ phách ấm, sáng/tối. */
:root {
  --bg: #faf7f2;
  --surface: #ffffff;
  --surface-2: #f3ede3;
  --text: #292019;
  --muted: #8a7a68;
  --border: #e6dccb;
  --accent: #b45309;
  --accent-2: #d97706;
  --bubble-user: #b45309;
  --bubble-user-text: #ffffff;
  --bubble-ai: #ffffff;
  --danger: #b91c1c;
  --shadow: 0 8px 30px rgba(90, 60, 10, .10);
}
html[data-theme="dark"] {
  --bg: #171310;
  --surface: #221c17;
  --surface-2: #2b231c;
  --text: #f0e7da;
  --muted: #a8977f;
  --border: #3d332a;
  --accent: #f59e0b;
  --accent-2: #fbbf24;
  --bubble-user: #b45309;
  --bubble-ai: #221c17;
  --shadow: 0 8px 30px rgba(0, 0, 0, .35);
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}
button { font: inherit; cursor: pointer; }
input, textarea { font: inherit; color: var(--text); }
[hidden] { display: none !important; }

/* ---------- Auth ---------- */
.auth-wrap {
  min-height: 100dvh;
  display: flex; align-items: center; justify-content: center;
  padding: 16px;
}
.auth-card {
  width: 100%; max-width: 400px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  box-shadow: var(--shadow);
  padding: 28px 24px;
  text-align: center;
}
.auth-card .logo { font-size: 44px; }
.auth-card h1 { margin: 8px 0 4px; font-family: Georgia, "Times New Roman", serif; font-size: 30px; }
.tagline { color: var(--muted); margin: 0 0 20px; }
.tabs { display: flex; background: var(--surface-2); border-radius: 12px; padding: 4px; margin-bottom: 18px; }
.tab { flex: 1; border: 0; background: transparent; padding: 9px; border-radius: 9px; color: var(--muted); font-weight: 600; }
.tab.active { background: var(--surface); color: var(--text); box-shadow: 0 1px 4px rgba(0,0,0,.12); }
.auth-card form { text-align: left; display: grid; gap: 12px; }
.auth-card label { display: grid; gap: 6px; font-size: 14px; font-weight: 600; }
.auth-card input {
  padding: 12px; border: 1px solid var(--border); border-radius: 12px;
  background: var(--bg); outline: none;
}
.auth-card input:focus { border-color: var(--accent-2); }
.error { color: var(--danger); margin: 0; font-size: 14px; }
.hint { color: var(--muted); font-size: 13px; margin: 16px 0 0; }

.primary {
  background: var(--accent); color: #fff; border: 0;
  padding: 12px 16px; border-radius: 12px; font-weight: 700;
}
.primary:hover { background: var(--accent-2); }
.primary:disabled { opacity: .55; cursor: wait; }
.primary.block, .ghost.block { width: 100%; }
.ghost {
  background: transparent; color: var(--muted); border: 1px solid var(--border);
  padding: 10px 14px; border-radius: 12px;
}

/* ---------- App layout ---------- */
.app { display: flex; height: 100dvh; }
.sidebar {
  width: 290px; flex: 0 0 290px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  padding: 14px; gap: 12px;
  z-index: 30;
}
.side-head { display: flex; align-items: center; justify-content: space-between; }
.brand { font-family: Georgia, serif; font-weight: 700; font-size: 18px; }
.conv-list { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 4px; }
.conv-item {
  display: flex; align-items: center; gap: 6px;
  padding: 10px 12px; border-radius: 10px; cursor: pointer;
  border: 1px solid transparent;
}
.conv-item:hover { background: var(--surface-2); }
.conv-item.active { background: var(--surface-2); border-color: var(--border); }
.conv-item .t { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 14px; }
.conv-item .del { border: 0; background: transparent; color: var(--muted); padding: 2px 4px; border-radius: 6px; }
.conv-item .del:hover { color: var(--danger); }
.side-foot { border-top: 1px solid var(--border); padding-top: 12px; display: grid; gap: 8px; }
.user-info { font-size: 14px; font-weight: 600; word-break: break-all; }
.quota { font-size: 13px; color: var(--muted); }
.icon-btn {
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  width: 38px; height: 38px; border-radius: 10px; font-size: 17px;
}
.backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 20; }

.chat { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.chat-head {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 14px; border-bottom: 1px solid var(--border);
  background: var(--surface);
}
.chat-title { flex: 1; font-family: Georgia, serif; font-weight: 700; font-size: 18px; }
.only-mobile { display: none; }

.messages { flex: 1; overflow-y: auto; padding: 18px 14px; }
.welcome { max-width: 640px; margin: 8vh auto 0; text-align: center; }
.welcome .logo { font-size: 46px; }
.welcome h2 { font-family: Georgia, serif; margin: 10px 0 6px; }
.welcome p { color: var(--muted); }
.chips { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-top: 16px; }
.chip {
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  border-radius: 999px; padding: 8px 14px; font-size: 14px;
}
.chip:hover { border-color: var(--accent-2); }

.msg { max-width: 780px; margin: 0 auto 14px; display: flex; gap: 10px; }
.msg .avatar { flex: 0 0 32px; width: 32px; height: 32px; border-radius: 50%; display: flex; align-items: center; justify-content: center; background: var(--surface-2); border: 1px solid var(--border); font-size: 16px; }
.msg .bubble {
  padding: 11px 14px; border-radius: 16px; line-height: 1.55;
  white-space: normal; word-break: break-word; max-width: 100%;
}
.msg.user { flex-direction: row-reverse; }
.msg.user .bubble { background: var(--bubble-user); color: var(--bubble-user-text); border-bottom-right-radius: 4px; }
.msg.ai .bubble { background: var(--bubble-ai); border: 1px solid var(--border); border-bottom-left-radius: 4px; }
.msg .bubble p { margin: 0 0 8px; }
.msg .bubble p:last-child { margin-bottom: 0; }
.msg .bubble code { background: var(--surface-2); padding: 1px 5px; border-radius: 6px; font-size: .92em; }
.msg .bubble pre { background: var(--surface-2); padding: 10px; border-radius: 10px; overflow-x: auto; }
.msg .bubble pre code { background: transparent; padding: 0; }
.msg.error .bubble { border-color: var(--danger); color: var(--danger); }
.cursor-blink::after { content: "▍"; animation: blink 1s steps(1) infinite; color: var(--accent-2); }
@keyframes blink { 50% { opacity: 0; } }
.thinking { color: var(--muted); font-style: italic; }

.composer {
  display: flex; gap: 10px; align-items: flex-end;
  padding: 12px 14px; border-top: 1px solid var(--border); background: var(--surface);
}
.composer textarea {
  flex: 1; resize: none; max-height: 140px;
  padding: 12px 14px; border: 1px solid var(--border); border-radius: 16px;
  background: var(--bg); outline: none; line-height: 1.45;
}
.composer textarea:focus { border-color: var(--accent-2); }
.send-btn {
  flex: 0 0 46px; width: 46px; height: 46px; border-radius: 50%;
  border: 0; background: var(--accent); color: #fff; font-size: 18px;
}
.send-btn:disabled { opacity: .5; cursor: wait; }
.foot-note { text-align: center; color: var(--muted); font-size: 12px; margin: 0; padding: 0 12px 10px; background: var(--surface); }

@media (max-width: 760px) {
  .sidebar {
    position: fixed; top: 0; left: 0; bottom: 0;
    transform: translateX(-105%); transition: transform .22s ease;
    box-shadow: var(--shadow);
  }
  .sidebar.open { transform: translateX(0); }
  .only-mobile { display: inline-flex; align-items: center; justify-content: center; }
}
