:root {
  --bg: #0e0f14; --panel: #15171f; --panel2: #1c1f29; --line: #262a36;
  --text: #e6e8ef; --dim: #8b91a3; --accent: #7ea0ff; --danger: #ff7a7a;
  --radius: 14px; --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Code", Menlo, Consolas, monospace;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font: 16px/1.55 var(--font); }
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
.hidden { display: none !important; }
.link { color: var(--dim); text-decoration: underline; padding: 0; }

/* login */
.login { height: 100%; display: grid; place-items: center; padding: 24px; }
.login-card { width: 100%; max-width: 340px; display: flex; flex-direction: column; gap: 12px; }
.brand { display: flex; align-items: center; gap: 10px; font-size: 22px; font-weight: 600; margin-bottom: 8px; }
.brand img { width: 40px; height: 40px; border-radius: 10px; }
.login input, #search { background: var(--panel); border: 1px solid var(--line); color: var(--text);
  border-radius: 10px; padding: 12px 14px; font: inherit; outline: none; }
.login input:focus, #search:focus { border-color: var(--accent); }
.login button[type=submit] { background: var(--accent); color: #0b0d14; font-weight: 600; border-radius: 10px; padding: 12px; }
.err { color: var(--danger); min-height: 1.4em; font-size: 14px; }

/* layout */
.app { height: 100%; display: flex; }
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; height: 100dvh; }
.top { display: flex; align-items: center; gap: 8px; padding: 8px 10px; padding-top: max(8px, env(safe-area-inset-top));
  border-bottom: 1px solid var(--line); background: var(--bg); }
.icon { width: 40px; height: 40px; border-radius: 10px; font-size: 20px; display: grid; place-items: center; }
.icon:hover { background: var(--panel2); }
#model { flex: 1; min-width: 0; max-width: 260px; margin: 0 auto; background: var(--panel); color: var(--text);
  border: 1px solid var(--line); border-radius: 999px; padding: 8px 14px; font: inherit; font-size: 15px; text-align: center; }

/* drawer */
.drawer { width: 290px; flex: none; background: var(--panel); border-right: 1px solid var(--line);
  display: flex; flex-direction: column; height: 100dvh; }
.drawer-top { padding: 12px; padding-top: max(12px, env(safe-area-inset-top)); display: flex; flex-direction: column; gap: 10px; }
.btn-wide { border: 1px solid var(--line); border-radius: 10px; padding: 10px; text-align: left; }
.btn-wide:hover { background: var(--panel2); }
.thread-list { list-style: none; margin: 0; padding: 0 8px; overflow-y: auto; flex: 1; }
.thread-list li { display: flex; align-items: center; border-radius: 10px; }
.thread-list li.active, .thread-list li:hover { background: var(--panel2); }
.thread-list .t-title { flex: 1; min-width: 0; padding: 10px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; text-align: left; }
.thread-list .t-act { opacity: .55; padding: 6px 8px; font-size: 14px; }
.thread-list .t-act:hover { opacity: 1; }
.drawer-foot { display: flex; justify-content: space-between; align-items: center; padding: 12px 14px;
  padding-bottom: max(12px, env(safe-area-inset-bottom)); border-top: 1px solid var(--line); color: var(--dim); font-size: 13px; }
.scrim { display: none; }
@media (max-width: 820px) {
  .drawer { position: fixed; z-index: 20; left: 0; top: 0; transform: translateX(-100%); transition: transform .2s ease; width: 84vw; max-width: 320px; }
  .app.open .drawer { transform: none; }
  .app.open .scrim { display: block; position: fixed; inset: 0; background: #0008; z-index: 10; }
}
@media (min-width: 821px) { #menu { display: none; } }

/* messages */
.messages { flex: 1; overflow-y: auto; padding: 16px 14px 8px; display: flex; flex-direction: column; gap: 18px; }
.messages > * { width: 100%; max-width: 760px; margin: 0 auto; }
.empty { margin: auto; color: var(--dim); font-size: 22px; text-align: center; }
.msg.user { display: flex; flex-direction: column; align-items: flex-end; }
.msg.user .bubble { background: var(--panel2); border-radius: 18px 18px 4px 18px; padding: 10px 14px; max-width: 85%; white-space: pre-wrap; word-wrap: break-word; }
.msg.assistant .body { word-wrap: break-word; }
.msg .body > :first-child { margin-top: 0; } .msg .body > :last-child { margin-bottom: 0; }
.msg .body p { margin: .55em 0; }
.msg .body a { color: var(--accent); }
.msg .body table { border-collapse: collapse; display: block; overflow-x: auto; margin: .6em 0; font-size: 15px; }
.msg .body th, .msg .body td { border: 1px solid var(--line); padding: 6px 10px; text-align: left; }
.msg .body th { background: var(--panel); }
.msg .body code { font-family: var(--mono); font-size: .9em; background: var(--panel2); padding: .1em .35em; border-radius: 5px; }
.codewrap { position: relative; margin: .6em 0; border: 1px solid var(--line); border-radius: 10px; background: #0a0b10; }
.codehead { display: flex; justify-content: space-between; align-items: center; padding: 4px 6px 4px 12px;
  font: 12px var(--mono); color: var(--dim); border-bottom: 1px solid var(--line); }
.codehead button { font-size: 12px; padding: 4px 8px; border-radius: 6px; color: var(--dim); }
.codehead button:hover { background: var(--panel2); color: var(--text); }
.codewrap pre { margin: 0; padding: 12px; overflow-x: auto; }
.msg .body .codewrap pre code { background: none; padding: 0; font-size: 13.5px; line-height: 1.5; }
.meta { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 10px; margin-top: 6px; color: var(--dim); font-size: 12px; }
.meta button { font-size: 12px; color: var(--dim); padding: 2px 4px; border-radius: 6px; }
.meta button:hover { color: var(--text); background: var(--panel2); }
.meta .stopped { color: #e8b45f; }
.msg.error .body { color: var(--danger); }
.cursor::after { content: "▍"; animation: blink 1s steps(2) infinite; color: var(--dim); }
@keyframes blink { 50% { opacity: 0; } }

/* composer */
.composer { padding: 8px 12px; padding-bottom: max(10px, env(safe-area-inset-bottom)); }
.composer > * { max-width: 760px; margin: 0 auto; }
.composer-row { display: flex; align-items: flex-end; gap: 8px; background: var(--panel); border: 1px solid var(--line);
  border-radius: 24px; padding: 6px 6px 6px 16px; }
.composer-row:focus-within { border-color: #3a4160; }
#input { flex: 1; resize: none; background: none; border: 0; outline: none; color: var(--text); font: inherit;
  max-height: 40vh; padding: 7px 0; }
.send { width: 38px; height: 38px; flex: none; border-radius: 50%; background: var(--text); color: var(--bg); font-size: 20px; font-weight: 700; }
.send:disabled { opacity: .3; }
.send.stop { background: var(--text); font-size: 14px; }
.edit-banner { font-size: 13px; color: var(--accent); padding: 0 8px 6px; }
.msg .body h1 { font-size: 1.3em; margin: .8em 0 .4em; }
.msg .body h2 { font-size: 1.15em; margin: .8em 0 .4em; }
.msg .body h3, .msg .body h4 { font-size: 1.02em; margin: .7em 0 .3em; }
.msg .body ul, .msg .body ol { padding-left: 1.4em; margin: .5em 0; }
.msg .body blockquote { margin: .6em 0; padding-left: 12px; border-left: 3px solid var(--line); color: var(--dim); }
