:root {
  --bg: #f6f6f4; --panel: #ffffff; --text: #1d1f23; --muted: #6b6f76; --line: #e3e3df;
  --accent: #c2572e; --accent-text: #ffffff; --user: #ece9e3; --code: #f0efeb; --err: #b3261e;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #14161a; --panel: #1c1f24; --text: #e8e8e6; --muted: #9aa0a8; --line: #2c3037;
          --accent: #e07a4f; --accent-text: #14161a; --user: #2a2e35; --code: #23262c; --err: #f28b82; }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; }
[hidden] { display: none !important; }
button { font: inherit; color: inherit; cursor: pointer; border: 0; }
.screen { height: 100dvh; }
.brand { font-weight: 650; font-size: 17px; }
.muted { color: var(--muted); }
.err { color: var(--err); min-height: 1.5em; font-size: 14px; }

/* вход */
#login { display: grid; place-items: center; padding: 16px; }
.login-card { width: 100%; max-width: 340px; display: grid; gap: 12px; background: var(--panel);
  padding: 24px; border-radius: 16px; border: 1px solid var(--line); }
.login-card input { font: inherit; padding: 12px 14px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--bg); color: var(--text); }
.login-card button, #send { background: var(--accent); color: var(--accent-text); border-radius: 10px;
  padding: 12px; font-weight: 600; }

/* каркас */
#app { display: flex; }
#drawer { width: 280px; flex: none; background: var(--panel); border-right: 1px solid var(--line);
  display: flex; flex-direction: column; padding: 12px; gap: 8px; padding-top: max(12px, env(safe-area-inset-top)); }
.drawer-head { display: flex; justify-content: space-between; align-items: center; padding: 4px 4px 8px; }
#chat-list { flex: 1; overflow-y: auto; display: grid; align-content: start; gap: 2px; }
#chat-list button { text-align: left; background: none; padding: 9px 10px; border-radius: 8px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#chat-list button.active, #chat-list button:hover { background: var(--user); }
.ghost { background: none; border-radius: 8px; padding: 6px 10px; color: var(--muted); }
.ghost:hover { background: var(--user); color: var(--text); }
.icon { font-size: 18px; line-height: 1; padding: 8px 10px; }
.small { font-size: 13px; }
main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
header { display: flex; align-items: center; gap: 8px; padding: 8px 12px; border-bottom: 1px solid var(--line);
  padding-top: max(8px, env(safe-area-inset-top)); }
#title { flex: 1; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#menu, #new-chat-2 { display: none; }
#scrim { display: none; }

/* сообщения */
#messages { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 14px; }
.msg { max-width: 820px; width: 100%; margin: 0 auto; }
.msg.user .bubble { margin-left: auto; width: fit-content; max-width: 85%; background: var(--user);
  padding: 10px 14px; border-radius: 16px 16px 4px 16px; white-space: pre-wrap; overflow-wrap: anywhere; }
.msg.assistant .bubble { overflow-wrap: anywhere; }
.msg .files { display: flex; flex-wrap: wrap; gap: 6px; justify-content: flex-end; margin-bottom: 6px; }
.status { color: var(--muted); font-size: 13px; display: flex; gap: 8px; align-items: center; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); animation: pulse 1s infinite alternate; }
@keyframes pulse { from { opacity: .3 } to { opacity: 1 } }
.bubble table { border-collapse: collapse; display: block; overflow-x: auto; max-width: 100%; font-size: 14px; margin: 8px 0; }
.bubble th, .bubble td { border: 1px solid var(--line); padding: 6px 8px; text-align: left; vertical-align: top; }
.bubble th { background: var(--code); }
.bubble code { background: var(--code); padding: 1px 5px; border-radius: 4px; font-size: 13px; }
.bubble pre { background: var(--code); padding: 10px; border-radius: 8px; overflow-x: auto; }
.bubble pre code { padding: 0; }
.bubble blockquote { margin: 8px 0; padding-left: 12px; border-left: 3px solid var(--line); color: var(--muted); }
.bubble p:first-child { margin-top: 0; } .bubble p:last-child { margin-bottom: 0; }
.err-msg { color: var(--err); }
.empty { margin: auto; text-align: center; display: grid; gap: 16px; max-width: 520px; }
.hints { display: grid; gap: 8px; }
.hint { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 10px 14px; text-align: left; }

/* ввод */
footer { padding: 8px 12px; padding-bottom: max(10px, env(safe-area-inset-bottom)); border-top: 1px solid var(--line); }
#chips { display: flex; flex-wrap: wrap; gap: 6px; max-width: 820px; margin: 0 auto; }
#chips:not(:empty) { margin-bottom: 8px; }
.chip { display: inline-flex; align-items: center; gap: 6px; background: var(--user); border-radius: 999px;
  padding: 4px 10px; font-size: 13px; max-width: 100%; }
.chip span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 220px; }
.chip button { background: none; padding: 0 2px; color: var(--muted); }
.chip.loading { opacity: .6; }
#composer { display: flex; gap: 8px; align-items: flex-end; max-width: 820px; margin: 0 auto; }
#input { flex: 1; resize: none; font: inherit; color: var(--text); background: var(--panel); border: 1px solid var(--line);
  border-radius: 14px; padding: 10px 14px; max-height: 40dvh; font-size: 16px; }
#send { width: 44px; height: 44px; padding: 0; font-size: 20px; flex: none; }
#send:disabled { opacity: .4; cursor: default; }
.attach { cursor: pointer; height: 44px; display: grid; place-items: center; }
#drop { position: fixed; inset: 0; background: color-mix(in srgb, var(--bg) 85%, transparent); display: grid;
  place-items: center; font-size: 20px; border: 3px dashed var(--accent); z-index: 10; }

@media (max-width: 760px) {
  #drawer { position: fixed; inset: 0 auto 0 0; z-index: 5; transform: translateX(-100%); transition: transform .2s; }
  #app.drawer-open #drawer { transform: none; }
  #app.drawer-open #scrim { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 4; }
  #menu, #new-chat-2 { display: block; }
  #messages { padding: 12px; }
}
