:root {
  --bg: #212121; --bg2: #2f2f2f; --bg3: #3a3a3a; --fg: #ececec; --muted: #9a9a9a;
  --accent: #10a37f; --accent-fg: #fff; --border: #444; --user-bubble: #303030; --danger: #ef5350;
  --radius: 14px; --max: 820px;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--fg); font: 16px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
.hidden { display: none !important; }
button { font: inherit; cursor: pointer; }
.muted { color: var(--muted); }
.error { color: var(--danger); min-height: 1.4em; font-size: 14px; }

/* Login */
.overlay { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; background: var(--bg); }
.login-card { background: var(--bg2); padding: 36px 32px; border-radius: 18px; width: min(360px, 92vw); display: flex; flex-direction: column; gap: 12px; border: 1px solid var(--border); }
.login-card h1 { margin: 0; font-size: 26px; }
.login-card p { margin: 0 0 6px; color: var(--muted); }
.login-card input { padding: 12px 14px; border-radius: 10px; border: 1px solid var(--border); background: var(--bg); color: var(--fg); font-size: 16px; }
.login-card input:focus { outline: 2px solid var(--accent); border-color: transparent; }
.login-card button { padding: 12px; border-radius: 10px; border: 0; background: var(--accent); color: var(--accent-fg); font-weight: 600; }

/* Layout */
#app { height: 100%; display: flex; flex-direction: column; }
header { display: flex; align-items: center; justify-content: space-between; padding: 10px 16px; border-bottom: 1px solid var(--border); background: var(--bg); }
.brand { font-weight: 600; }
.header-actions { display: flex; gap: 8px; align-items: center; }
select { background: var(--bg2); color: var(--fg); border: 1px solid var(--border); border-radius: 8px; padding: 6px 10px; font: inherit; font-size: 14px; }
.ghost { background: transparent; color: var(--fg); border: 1px solid var(--border); border-radius: 8px; padding: 6px 12px; font-size: 14px; }
.ghost:hover { background: var(--bg2); }

main { flex: 1; overflow-y: auto; padding: 24px 16px; }
.empty { max-width: var(--max); margin: 12vh auto 0; text-align: center; }
.empty h2 { font-size: 28px; margin-bottom: 8px; }
.empty p { color: var(--fg); max-width: 560px; margin: 8px auto; }

/* Messages */
.msg { max-width: var(--max); margin: 0 auto 22px; display: flex; }
.msg.user { justify-content: flex-end; }
.msg .bubble { max-width: 80%; background: var(--user-bubble); border-radius: 20px; padding: 10px 16px; white-space: pre-wrap; word-wrap: break-word; }
.msg.assistant .bubble { max-width: 100%; background: transparent; padding: 0 4px; white-space: normal; }
.msg .images { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 6px; }
.msg .images img { max-width: 240px; max-height: 240px; border-radius: 10px; display: block; }
.msg .files { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 6px; }
.filechip { display: inline-flex; align-items: center; gap: 6px; background: var(--bg3); border: 1px solid var(--border); border-radius: 10px; padding: 6px 10px; font-size: 13px; max-width: 280px; }
.filechip .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.filechip .meta { color: var(--muted); white-space: nowrap; }
.msg.error .bubble { color: var(--danger); border: 1px solid var(--danger); border-radius: 12px; padding: 10px 14px; }
.cursor::after { content: "▍"; animation: blink 1s steps(2) infinite; color: var(--muted); }
@keyframes blink { 50% { opacity: 0; } }
.thinking { font-size: 13px; color: var(--muted); border-left: 2px solid var(--border); padding-left: 10px; margin: 0 0 10px; white-space: pre-wrap; }
details.thinking summary { cursor: pointer; }
.msg-actions { display: flex; gap: 6px; margin-top: 4px; opacity: 0; transition: opacity .15s; }
.msg:hover .msg-actions { opacity: 1; }
.msg-actions button { background: transparent; border: 0; color: var(--muted); font-size: 13px; padding: 2px 6px; border-radius: 6px; }
.msg-actions button:hover { background: var(--bg2); color: var(--fg); }

/* Markdown */
.md > :first-child { margin-top: 0; } .md > :last-child { margin-bottom: 0; }
.md p { margin: 0 0 12px; } .md ul, .md ol { margin: 0 0 12px; padding-left: 24px; } .md li { margin: 3px 0; }
.md h1, .md h2, .md h3, .md h4 { margin: 18px 0 8px; line-height: 1.3; }
.md h1 { font-size: 1.5em; } .md h2 { font-size: 1.3em; } .md h3 { font-size: 1.15em; }
.md blockquote { margin: 0 0 12px; padding: 4px 14px; border-left: 3px solid var(--border); color: var(--muted); }
.md code { background: var(--bg3); padding: 2px 5px; border-radius: 5px; font-size: 0.9em; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.md pre { background: #0d1117; border: 1px solid var(--border); border-radius: 10px; padding: 0; margin: 0 0 14px; overflow: hidden; }
.md pre code { display: block; padding: 14px; overflow-x: auto; background: transparent; font-size: 13.5px; line-height: 1.5; }
.codebar { display: flex; justify-content: space-between; align-items: center; padding: 4px 12px; background: var(--bg3); font-size: 12px; color: var(--muted); font-family: ui-monospace, monospace; }
.codebar button { background: transparent; border: 0; color: var(--muted); font-size: 12px; padding: 2px 6px; border-radius: 5px; }
.codebar button:hover { color: var(--fg); background: var(--bg2); }
.md table { border-collapse: collapse; margin: 0 0 14px; display: block; overflow-x: auto; max-width: 100%; }
.md th, .md td { border: 1px solid var(--border); padding: 6px 10px; text-align: left; vertical-align: top; }
.md th { background: var(--bg2); }
.md img { max-width: 100%; border-radius: 8px; }
.md a { color: #7ab8ff; } .md hr { border: 0; border-top: 1px solid var(--border); margin: 16px 0; }

/* Composer */
footer { padding: 8px 16px 14px; background: var(--bg); }
.composer { max-width: var(--max); margin: 0 auto; background: var(--bg2); border: 1px solid var(--border); border-radius: 24px; padding: 8px 10px 4px; }
.composer.dragover { outline: 2px dashed var(--accent); }
.composer-row { display: flex; align-items: flex-end; gap: 6px; }
textarea { flex: 1; resize: none; background: transparent; color: var(--fg); border: 0; font: inherit; padding: 10px 6px; max-height: 220px; line-height: 1.5; }
textarea:focus { outline: none; }
.icon { width: 40px; height: 40px; border-radius: 50%; border: 0; background: transparent; color: var(--fg); display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0; }
.icon:hover { background: var(--bg3); }
.icon.primary { background: var(--fg); color: var(--bg); }
.icon.primary:hover { background: #fff; }
.icon.primary:disabled { opacity: .35; cursor: default; }
.hint { text-align: center; font-size: 12px; color: var(--muted); padding: 4px 0 2px; }
.attachments { display: flex; flex-wrap: wrap; gap: 8px; padding: 4px 6px 6px; }
.attachments:empty { display: none; }
.att { position: relative; display: inline-flex; align-items: center; gap: 8px; background: var(--bg3); border: 1px solid var(--border); border-radius: 12px; padding: 6px 30px 6px 8px; font-size: 13px; max-width: 300px; }
.att img { width: 44px; height: 44px; object-fit: cover; border-radius: 8px; }
.att .ico { width: 36px; height: 36px; border-radius: 8px; background: #e0583a; display: grid; place-items: center; font-size: 11px; font-weight: 700; color: #fff; flex-shrink: 0; }
.att .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 180px; }
.att .status { color: var(--muted); font-size: 12px; }
.att .status.err { color: var(--danger); }
.att .rm { position: absolute; top: 4px; right: 4px; width: 20px; height: 20px; border-radius: 50%; border: 0; background: var(--bg); color: var(--fg); font-size: 13px; line-height: 1; display: grid; place-items: center; }
.att .rm:hover { background: var(--danger); }
@media (max-width: 600px) { .msg .bubble { max-width: 92%; } .brand { display: none; } }
