:root {
  --bg: #f4f5f7; --panel: #fff; --text: #1d2329; --muted: #667781; --border: #e2e5e9;
  --accent: #00a884; --accent-text: #fff; --bubble-in: #fff; --bubble-out: #d9fdd3; --danger: #c62828;
  --chat-bg: #efeae2;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b141a; --panel: #111b21; --text: #e9edef; --muted: #8696a0; --border: #222d34;
    --accent: #00a884; --bubble-in: #202c33; --bubble-out: #005c4b; --danger: #ef5350; --chat-bg: #0b141a;
  }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body { font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--text); }
button { background: var(--accent); color: var(--accent-text); border: 0; border-radius: 6px; padding: .55rem 1rem; cursor: pointer; font: inherit; }
button:disabled { opacity: .6; cursor: progress; }
button.ghost { background: transparent; color: var(--text); border: 1px solid var(--border); }
button.danger { color: var(--danger); }
input, select, textarea { font: inherit; color: inherit; background: var(--bg); border: 1px solid var(--border); border-radius: 6px; padding: .45rem .6rem; width: 100%; }
label { display: grid; gap: .25rem; color: var(--muted); font-size: 12px; }
.muted { color: var(--muted); }
code { font-size: 11px; }

.topbar { display: flex; align-items: center; gap: 1rem; padding: .6rem 1rem; background: var(--panel); border-bottom: 1px solid var(--border); height: 52px; }
.topbar form { margin-left: auto; }

.layout { display: grid; grid-template-columns: 300px 1fr 380px; height: calc(100vh - 52px); }
.sidebar, .llm { background: var(--panel); overflow: auto; }
.sidebar { border-right: 1px solid var(--border); padding: .75rem; }
.llm { border-left: 1px solid var(--border); padding: 1rem; display: flex; flex-direction: column; gap: .75rem; }
.llm h3, .llm h4 { margin: 0; }
.row { display: grid; grid-template-columns: 1fr 1.6fr; gap: .5rem; }

.chat-list { list-style: none; margin: .75rem 0 0; padding: 0; }
.chat-list li { padding: .6rem; border-radius: 8px; cursor: pointer; display: grid; gap: .1rem; }
.chat-list li:hover, .chat-list li.active { background: var(--bg); }
.chat-list .name { font-weight: 600; display: flex; justify-content: space-between; gap: .5rem; }
.chat-list .preview { color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 13px; }

.conversation { display: flex; flex-direction: column; min-width: 0; background: var(--chat-bg); }
.conversation > div:not(.empty) { display: flex; flex-direction: column; height: 100%; }
.conv-header { display: flex; justify-content: space-between; align-items: center; padding: .6rem 1rem; background: var(--panel); border-bottom: 1px solid var(--border); }
.conv-header h2 { margin: 0; font-size: 16px; }
.messages { flex: 1; overflow: auto; padding: .75rem 6%; display: flex; flex-direction: column; gap: 2px; }
.msg { align-self: flex-start; width: fit-content; max-width: min(65%, 560px); padding: 3px 8px; border-radius: 6px;
       background: var(--bubble-in); font-size: 13.5px; line-height: 1.35; overflow-wrap: anywhere; }
.msg.out { align-self: flex-end; background: var(--bubble-out); }
.msg .author { font-size: 11.5px; font-weight: 600; color: var(--accent); }
.msg .body { white-space: pre-wrap; }
.msg .time { float: right; margin: 4px 0 -2px 8px; font-size: 10.5px; color: var(--muted); }
.empty { margin: auto; text-align: center; padding: 2rem; }

.output { min-height: 3rem; padding: .75rem; border: 1px solid var(--border); border-radius: 8px; background: var(--bg); overflow-wrap: anywhere; }
.output:empty { display: none; }
.md h1, .md h2, .md h3 { font-size: 15px; margin: .6rem 0 .3rem; }
.md p { margin: .35rem 0; }
.md ul, .md ol { padding-left: 1.2rem; margin: .3rem 0; }
.history { list-style: none; padding: 0; margin: 0; display: grid; gap: .4rem; }
.history details { border: 1px solid var(--border); border-radius: 8px; padding: .4rem .6rem; }
.history summary { cursor: pointer; font-size: 13px; }

.login { display: grid; place-items: center; }
.card { background: var(--panel); padding: 2rem; border-radius: 12px; border: 1px solid var(--border); display: grid; gap: 1rem; width: min(360px, calc(100vw - 32px)); }
.card h1 { margin: 0; font-size: 20px; }
.error { color: var(--danger); margin: 0; }

@media (max-width: 1100px) {
  .layout { grid-template-columns: 1fr; height: auto; }
  .sidebar { max-height: 40vh; }
  .messages { max-height: 70vh; }
}
