:root {
  color-scheme: light;
  --bg: #faf9f6; --side: #f1efe9; --surface: #ffffff; --ink: #1c1b18; --muted: #6f6c64;
  --line: #e2dfd6; --accent: #c2410c; --accent-ink: #ffffff; --user: #efece4;
  --code: #f4f2ec; --err: #b42318; --radius: 14px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #1d1c1a; --side: #161514; --surface: #262522; --ink: #ecebe6; --muted: #a09d94;
    --line: #3a3834; --accent: #ea7a45; --accent-ink: #1a0f08; --user: #2f2d29;
    --code: #151413; --err: #ff8a80;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #1d1c1a; --side: #161514; --surface: #262522; --ink: #ecebe6; --muted: #a09d94;
  --line: #3a3834; --accent: #ea7a45; --accent-ink: #1a0f08; --user: #2f2d29;
  --code: #151413; --err: #ff8a80;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--ink); font: 16px/1.6 var(--font); -webkit-font-smoothing: antialiased; }
[hidden] { display: none !important; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
.muted { color: var(--muted); }
.err { color: var(--err); min-height: 1.4em; margin: 0; font-size: 14px; }

.primary { background: var(--accent); color: var(--accent-ink); border: 0; border-radius: 10px; padding: 10px 16px; font-weight: 600; }
.primary:disabled { opacity: .5; cursor: default; }
.ghost { background: transparent; border: 1px solid var(--line); border-radius: 10px; padding: 9px 14px; }
.ghost:hover { background: var(--surface); }
.wide { width: 100%; }
.icon-btn { background: transparent; border: 0; border-radius: 8px; width: 38px; height: 38px; font-size: 18px; display: grid; place-items: center; flex: none; }
.icon-btn:hover { background: var(--user); }
.logo { color: var(--accent); font-size: 28px; line-height: 1; }
.logo.big { font-size: 44px; }

/* ---------- Anmeldung ---------- */
#auth { min-height: 100%; display: grid; place-items: center; padding: 16px; }
.auth-card { width: 100%; max-width: 380px; background: var(--surface); border: 1px solid var(--line); border-radius: 18px; padding: 28px; display: grid; gap: 14px; }
.auth-card h1 { margin: 0; font-size: 22px; }
.auth-card p { margin: 0; }
.auth-card label { display: grid; gap: 6px; font-size: 14px; color: var(--muted); }
.auth-card input { padding: 11px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); color: var(--ink); font-size: 16px; }
.auth-card input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

/* ---------- Layout ---------- */
#app { display: flex; height: 100%; }
#side { width: 260px; flex: none; background: var(--side); border-right: 1px solid var(--line); display: flex; flex-direction: column; }
.side-top, .side-bottom { padding: 12px; }
#chatList { flex: 1; overflow-y: auto; padding: 0 8px; }
.chat-item { display: flex; align-items: center; gap: 4px; border-radius: 8px; }
.chat-item a { flex: 1; min-width: 0; padding: 8px 10px; color: var(--ink); text-decoration: none; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 14px; }
.chat-item:hover, .chat-item.active { background: var(--user); }
.chat-item .del { opacity: 0; background: none; border: 0; color: var(--muted); padding: 4px 8px; font-size: 14px; }
.chat-item:hover .del, .chat-item.active .del { opacity: 1; }
.chat-group { font-size: 12px; color: var(--muted); padding: 12px 10px 4px; }

main { flex: 1; min-width: 0; display: flex; flex-direction: column; height: 100%; }
header { display: flex; align-items: center; gap: 8px; padding: 10px 16px; border-bottom: 1px solid var(--line); }
header select { background: transparent; border: 1px solid var(--line); border-radius: 8px; padding: 6px 8px; max-width: 46%; font-size: 14px; }
#menu { display: none; }
.toggle { border: 1px solid var(--line); background: transparent; border-radius: 8px; padding: 5px 10px; font-size: 14px; color: var(--muted); white-space: nowrap; }
.toggle[aria-pressed="true"] { border-color: var(--accent); color: var(--accent); }

.tools { display: grid; gap: 4px; margin-bottom: 10px; font-size: 13px; color: var(--muted); }
.tools details { border: 1px solid var(--line); border-radius: 10px; }
.tools summary { padding: 5px 12px; cursor: pointer; list-style: none; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tools summary::-webkit-details-marker { display: none; }
.tools .running summary::after { content: " …"; }
.tools ol { margin: 0; padding: 0 14px 8px 32px; }
.tools li { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tools a { color: var(--accent); text-decoration: none; }
.tools .err { color: var(--err); padding: 0 12px 8px; }

#scroll { flex: 1; overflow-y: auto; position: relative; }
#messages { max-width: 780px; margin: 0 auto; padding: 24px 16px 8px; }
#empty { position: absolute; inset: 0; display: grid; place-content: center; text-align: center; padding: 16px; gap: 6px; }
#empty h2 { margin: 8px 0 0; font-size: 26px; font-weight: 600; }
#empty p { max-width: 460px; margin: 0 auto; }

/* ---------- Nachrichten ---------- */
.msg { margin-bottom: 28px; }
.msg.user { display: flex; flex-direction: column; align-items: flex-end; }
.msg.user .bubble { background: var(--user); border-radius: 18px; padding: 10px 16px; max-width: 85%; white-space: pre-wrap; word-wrap: break-word; }
.attachments { display: flex; flex-wrap: wrap; gap: 6px; justify-content: flex-end; margin-bottom: 6px; max-width: 85%; }
.attachments img { height: 90px; border-radius: 10px; border: 1px solid var(--line); }
.chip { display: inline-flex; align-items: center; gap: 6px; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 6px 10px; font-size: 13px; max-width: 260px; }
.chip span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chip button { background: none; border: 0; color: var(--muted); padding: 0 2px; }
.chip.busy { opacity: .6; }

.msg.assistant .content { word-wrap: break-word; }
.content > :first-child { margin-top: 0; }
.content > :last-child { margin-bottom: 0; }
.content p, .content ul, .content ol { margin: 0 0 12px; }
.content h1, .content h2, .content h3 { line-height: 1.3; margin: 20px 0 10px; }
.content h1 { font-size: 22px; } .content h2 { font-size: 19px; } .content h3 { font-size: 17px; }
.content code { font-family: var(--mono); font-size: 14px; background: var(--code); border-radius: 5px; padding: 1px 5px; }
.content pre { position: relative; background: var(--code); border: 1px solid var(--line); border-radius: 10px; padding: 14px; overflow-x: auto; margin: 0 0 14px; }
.content pre code { background: none; padding: 0; font-size: 13.5px; line-height: 1.5; }
.content pre code.hljs { background: none; padding: 0; }
.content pre .copy { position: absolute; top: 6px; right: 6px; font-size: 12px; background: var(--surface); border: 1px solid var(--line); border-radius: 6px; padding: 2px 8px; opacity: 0; }
.content pre:hover .copy { opacity: 1; }
.content table { border-collapse: collapse; margin: 0 0 14px; display: block; overflow-x: auto; }
.content th, .content td { border: 1px solid var(--line); padding: 6px 10px; text-align: left; font-size: 14px; }
.content th { background: var(--code); }
.content blockquote { margin: 0 0 12px; padding-left: 14px; border-left: 3px solid var(--line); color: var(--muted); }
.content a { color: var(--accent); }

details.thinking { margin-bottom: 10px; border: 1px solid var(--line); border-radius: 10px; font-size: 14px; }
details.thinking summary { padding: 6px 12px; color: var(--muted); cursor: pointer; list-style: none; }
details.thinking summary::before { content: "▸ "; }
details.thinking[open] summary::before { content: "▾ "; }
details.thinking .t { padding: 0 12px 10px; color: var(--muted); white-space: pre-wrap; max-height: 320px; overflow-y: auto; }

.meta { display: flex; gap: 12px; align-items: center; margin-top: 8px; font-size: 12px; color: var(--muted); }
.meta button { background: none; border: 0; color: var(--muted); padding: 2px 4px; border-radius: 6px; font-size: 12px; }
.meta button:hover { background: var(--user); color: var(--ink); }
.cursor::after { content: "▋"; animation: blink 1s steps(2) infinite; color: var(--accent); margin-left: 2px; }
@keyframes blink { 50% { opacity: 0; } }
.error-box { border: 1px solid var(--err); color: var(--err); border-radius: 10px; padding: 10px 14px; font-size: 14px; }

/* ---------- Eingabe ---------- */
#composer { max-width: 780px; width: 100%; margin: 0 auto; padding: 8px 16px 12px; }
#files { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 6px; }
#files:empty { display: none; }
.box { display: flex; align-items: flex-end; gap: 6px; background: var(--surface); border: 1px solid var(--line); border-radius: 20px; padding: 8px; box-shadow: 0 2px 10px rgba(0,0,0,.04); }
.box:focus-within { border-color: var(--accent); }
#input { flex: 1; border: 0; background: transparent; resize: none; padding: 8px 4px; max-height: 240px; outline: none; font-size: 16px; line-height: 1.5; }
.send { width: 38px; height: 38px; border-radius: 12px; border: 0; background: var(--accent); color: var(--accent-ink); font-size: 18px; font-weight: 700; flex: none; }
.send:disabled { opacity: .4; cursor: default; }
.send.stop { font-size: 14px; }
.foot { text-align: center; font-size: 12px; margin: 8px 0 0; }

#drop { position: fixed; inset: 0; background: rgba(0,0,0,.35); display: grid; place-items: center; z-index: 50; pointer-events: none; }
#drop div { background: var(--surface); border: 2px dashed var(--accent); border-radius: 18px; padding: 40px 60px; font-size: 18px; }
#toast { position: fixed; bottom: 100px; left: 50%; transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 10px; font-size: 14px; z-index: 60; max-width: calc(100% - 32px); }

/* ---------- Handy ---------- */
@media (max-width: 760px) {
  #menu { display: grid; }
  #side { position: fixed; inset: 0 auto 0 0; z-index: 40; transform: translateX(-100%); transition: transform .2s; }
  #side.open { transform: none; }
  #scrim { position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 30; }
  header { padding: 8px 12px; }
  header select { max-width: 40%; }
  .msg.user .bubble, .attachments { max-width: 92%; }
  .foot { display: none; }
  #composer { padding-bottom: max(12px, env(safe-area-inset-bottom)); }
}
@media (max-width: 760px) {
  header { gap: 6px; }
  header select { max-width: 34%; min-width: 0; }
  .toggle { padding: 5px 8px; }
}
