:root {
  --bg: #0b0d14;
  --bg2: #11141e;
  --card: #161a27;
  --card2: #1c2132;
  --line: #262c40;
  --text: #e8eaf2;
  --muted: #8d94ab;
  --accent: #7c5cff;
  --accent2: #22d3ee;
  --accent-text: #fff;
  --ok: #22c55e;
  --bad: #ef4444;
  --warn: #f59e0b;
  --user: #24203f;
  --shadow: 0 10px 30px rgba(0, 0, 0, .35);
  --radius: 14px;
  color-scheme: dark;
}
:root[data-theme="light"] {
  --bg: #f5f6fb;
  --bg2: #ffffff;
  --card: #ffffff;
  --card2: #f0f2f8;
  --line: #e1e4ee;
  --text: #171a26;
  --muted: #646b82;
  --user: #ece8ff;
  --shadow: 0 10px 30px rgba(20, 24, 40, .1);
  color-scheme: light;
}
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bg: #f5f6fb; --bg2: #ffffff; --card: #ffffff; --card2: #f0f2f8; --line: #e1e4ee;
    --text: #171a26; --muted: #646b82; --user: #ece8ff; --shadow: 0 10px 30px rgba(20, 24, 40, .1);
    color-scheme: light;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; overflow-x: hidden; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, Inter, sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent2); }
button, input, select, textarea { font: inherit; color: inherit; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.pad { padding: 8px 12px; }
kbd { background: var(--card2); border: 1px solid var(--line); border-radius: 5px; padding: 0 5px; font-size: 12px; }

.app { display: grid; grid-template-columns: 280px minmax(0, 1fr); height: 100dvh; }
.scrim { display: none; }

/* ---------- Seitenleiste */
.side { background: var(--bg2); border-right: 1px solid var(--line); display: flex; flex-direction: column; padding: 14px; gap: 10px; min-height: 0; }
.side-head { display: flex; align-items: center; justify-content: space-between; }
.brand { display: flex; align-items: center; gap: 10px; color: var(--text); text-decoration: none; font-size: 18px; }
.brand img { width: 30px; height: 30px; }
.brand b { background: linear-gradient(90deg, var(--accent), var(--accent2)); -webkit-background-clip: text; background-clip: text; color: transparent; }
.side-title { font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin-top: 6px; }
.chat-list { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 2px; margin: 0 -6px; }
.chat-item { display: flex; align-items: center; gap: 10px; padding: 8px; border-radius: 10px; cursor: pointer; border: 0; background: none; text-align: left; width: 100%; }
.chat-item:hover { background: var(--card2); }
.chat-item.active { background: var(--card2); box-shadow: inset 3px 0 0 var(--accent); }
.chat-item img, .chat-item .ph { width: 36px; height: 36px; border-radius: 8px; object-fit: cover; flex: none; background: var(--card2); display: grid; place-items: center; }
.chat-item .t { overflow: hidden; min-width: 0; }
.chat-item .t b { display: block; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 14px; }
.chat-item .t small { color: var(--muted); font-size: 12px; }
.side-foot { display: flex; flex-direction: column; gap: 2px; border-top: 1px solid var(--line); padding-top: 8px; }
.link-btn { background: none; border: 0; text-align: left; padding: 7px 6px; border-radius: 8px; cursor: pointer; color: var(--muted); }
.link-btn:hover { background: var(--card2); color: var(--text); }
.link-btn.danger:hover { color: var(--bad); }

/* ---------- Kopf */
.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.top { display: flex; align-items: center; gap: 12px; min-width: 0; overflow: hidden; padding: 10px 16px; border-bottom: 1px solid var(--line); background: color-mix(in srgb, var(--bg) 85%, transparent); backdrop-filter: blur(10px); }
.top-right { margin-left: auto; display: flex; align-items: center; gap: 10px; min-width: 0; }
.user { color: var(--muted); font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 160px; }
.chip { font-size: 12px; padding: 3px 10px; border-radius: 99px; background: var(--card2); border: 1px solid var(--line); color: var(--muted); white-space: nowrap; }
.chip:empty { display: none; }
.seg { display: inline-flex; background: var(--card2); border: 1px solid var(--line); border-radius: 99px; padding: 3px; }
.seg button { border: 0; background: none; padding: 5px 14px; border-radius: 99px; cursor: pointer; color: var(--muted); font-size: 14px; }
.seg button[aria-checked="true"] { background: var(--accent); color: var(--accent-text); }
.seg button:disabled { opacity: .4; cursor: not-allowed; }
.seg button[hidden] { display: none; }

/* ---------- Buttons */
.btn { border: 1px solid var(--line); background: var(--card2); padding: 9px 16px; border-radius: 11px; cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; justify-content: center; gap: 8px; }
.btn:hover { border-color: var(--accent); }
.btn.primary { background: linear-gradient(135deg, var(--accent), #5b8cff); border-color: transparent; color: #fff; font-weight: 600; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.primary:disabled { opacity: .5; cursor: progress; }
.btn.big { padding: 13px 22px; font-size: 16px; }
.btn.wide { width: 100%; }
.icon-btn { border: 0; background: none; width: 38px; height: 38px; border-radius: 10px; cursor: pointer; font-size: 18px; flex: none; display: inline-grid; place-items: center; }
.icon-btn:hover { background: var(--card2); }
.only-mobile { display: none; }

/* ---------- Login */
.center { flex: 1; display: grid; place-items: center; padding: 16px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 20px; box-shadow: var(--shadow); }
.login-card { max-width: 420px; padding: 32px 28px; text-align: center; }
.login-card h1 { margin: 8px 0; }
.hero-icon { width: 72px; height: 72px; }

/* ---------- Chat */
.chat { flex: 1; display: flex; flex-direction: column; min-height: 0; position: relative; }
.messages { flex: 1; overflow-y: auto; padding: 20px 16px 10px; display: flex; flex-direction: column; gap: 16px; scroll-behavior: smooth; }
.messages > * { width: 100%; max-width: 820px; margin: 0 auto; }
.hero { text-align: center; margin: auto; padding: 20px 0; }
.hero h1 { margin: 10px 0 4px; font-size: 26px; }
.hero-actions { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; margin: 22px 0 10px; }
.tile { border: 1px solid var(--line); background: var(--card); border-radius: 16px; padding: 18px 20px; min-width: 150px; cursor: pointer; display: flex; flex-direction: column; align-items: center; gap: 6px; transition: transform .15s, border-color .15s; }
.tile span { font-size: 30px; }
.tile:hover { border-color: var(--accent); transform: translateY(-2px); }

.msg { display: flex; flex-direction: column; gap: 6px; }
.msg.user { align-items: flex-end; }
.bubble { padding: 12px 15px; border-radius: var(--radius); max-width: 100%; overflow-wrap: anywhere; }
.msg.user .bubble { background: var(--user); border-bottom-right-radius: 4px; max-width: 85%; white-space: pre-wrap; }
.msg.bot .bubble { background: var(--card); border: 1px solid var(--line); border-bottom-left-radius: 4px; }
.msg-imgs { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.msg-imgs img { max-width: 260px; max-height: 220px; border-radius: 12px; border: 1px solid var(--line); cursor: zoom-in; object-fit: cover; }
.msg-meta { display: flex; gap: 10px; align-items: center; font-size: 12px; color: var(--muted); }
.msg-meta button { background: none; border: 0; color: var(--muted); cursor: pointer; padding: 2px 4px; border-radius: 6px; }
.msg-meta button:hover { color: var(--text); background: var(--card2); }
.badge { padding: 1px 8px; border-radius: 99px; background: var(--card2); border: 1px solid var(--line); }
.badge.claude { color: #d4a373; }
.badge.local { color: var(--accent2); }
.status { color: var(--muted); font-size: 14px; display: flex; align-items: center; gap: 8px; }
.dots::after { content: ''; display: inline-block; width: 1.2em; text-align: left; animation: dots 1.2s steps(4) infinite; }
@keyframes dots { 0% { content: ''; } 25% { content: '.'; } 50% { content: '..'; } 75% { content: '...'; } }
.think { font-size: 13px; color: var(--muted); border-left: 2px solid var(--line); padding-left: 10px; margin-bottom: 6px; }
.think summary { cursor: pointer; }
.think div { white-space: pre-wrap; max-height: 220px; overflow-y: auto; margin-top: 4px; }
.err { color: var(--bad); }
.sources { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-top: 10px; padding-top: 8px; border-top: 1px dashed var(--line); font-size: 12.5px; color: var(--muted); }
.sources a { text-decoration: none; padding: 2px 9px; border-radius: 99px; background: var(--card2); border: 1px solid var(--line); color: var(--text); max-width: 200px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sources a:hover { border-color: var(--accent); }

/* Markdown */
.md > :first-child { margin-top: 0; }
.md > :last-child { margin-bottom: 0; }
.md p { margin: 0 0 .7em; }
.md h1, .md h2, .md h3, .md h4 { margin: 1em 0 .4em; line-height: 1.3; font-size: 1.05em; }
.md h1, .md h2 { font-size: 1.15em; }
.md ul, .md ol { margin: 0 0 .7em; padding-left: 1.4em; }
.md li { margin: .15em 0; }
.md code { background: var(--card2); padding: 1px 5px; border-radius: 5px; font-size: .92em; }
.md pre { background: var(--card2); padding: 12px; border-radius: 10px; overflow-x: auto; }
.md pre code { background: none; padding: 0; }
.md table { border-collapse: collapse; margin: 0 0 .8em; display: block; overflow-x: auto; }
.md th, .md td { border: 1px solid var(--line); padding: 5px 9px; text-align: left; }
.md blockquote { margin: 0 0 .7em; padding-left: 12px; border-left: 3px solid var(--accent); color: var(--muted); }
.md strong { color: var(--text); }
.md .answer { background: color-mix(in srgb, var(--ok) 12%, transparent); border: 1px solid color-mix(in srgb, var(--ok) 35%, transparent); border-radius: 10px; padding: 8px 12px; }

/* ---------- Eingabe */
.composer { border-top: 1px solid var(--line); padding: 10px 16px calc(10px + env(safe-area-inset-bottom)); background: var(--bg); display: flex; flex-direction: column; gap: 8px; }
.composer > * { width: 100%; max-width: 820px; margin: 0 auto; }
.modes { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; }
.mode { border: 1px solid var(--line); background: var(--card); border-radius: 99px; padding: 5px 12px; cursor: pointer; white-space: nowrap; font-size: 14px; }
.mode[aria-pressed="true"] { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 18%, var(--card)); }
.previews { display: flex; gap: 8px; flex-wrap: wrap; }
.previews:empty { display: none; }
.prev { position: relative; }
.prev img { width: 72px; height: 72px; object-fit: cover; border-radius: 10px; border: 1px solid var(--line); display: block; }
.prev button { position: absolute; top: -6px; right: -6px; width: 22px; height: 22px; border-radius: 50%; border: 0; background: var(--bad); color: #fff; cursor: pointer; font-size: 12px; line-height: 1; }
.row { display: flex; align-items: flex-end; gap: 6px; background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 6px; }
.row:focus-within { border-color: var(--accent); }
.row textarea { flex: 1; min-width: 0; border: 0; background: none; resize: none; outline: none; padding: 8px 6px; max-height: 180px; min-height: 38px; line-height: 1.4; overflow-y: hidden; }
.row select { border: 0; background: var(--card2); border-radius: 9px; padding: 8px 6px; cursor: pointer; }
.send { padding: 9px 18px; }
.foot-note { font-size: 11.5px; color: var(--muted); text-align: center; }

.drop { position: absolute; inset: 10px; border: 3px dashed var(--accent); border-radius: 20px; background: color-mix(in srgb, var(--bg) 80%, transparent); display: grid; place-items: center; font-size: 22px; z-index: 5; pointer-events: none; }

/* ---------- Dialoge */
.dlg { border: 1px solid var(--line); background: var(--card); color: var(--text); border-radius: 18px; padding: 0; width: min(560px, calc(100vw - 32px)); box-shadow: var(--shadow); }
.dlg.wide { width: min(720px, calc(100vw - 32px)); }
.dlg::backdrop { background: rgba(0, 0, 0, .55); }
.dlg-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 18px; border-bottom: 1px solid var(--line); margin: 0; }
.dlg-head h2 { margin: 0; font-size: 18px; }
.dlg-body { padding: 16px 18px 20px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 14px; }
.grid2 label { display: flex; flex-direction: column; gap: 4px; font-size: 14px; }
.grid2 input, .grid2 select { background: var(--card2); border: 1px solid var(--line); border-radius: 9px; padding: 8px 10px; }
.grid2 label.check { flex-direction: row; align-items: center; gap: 8px; }
.span2 { grid-column: 1 / -1; }
.admin-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.stats table { width: 100%; border-collapse: collapse; font-size: 13px; }
.stats th, .stats td { border-bottom: 1px solid var(--line); padding: 4px 6px; text-align: right; }
.stats th:first-child, .stats td:first-child { text-align: left; }
.dl-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 12px 0; }
.dl { border: 1px solid var(--line); border-radius: 14px; padding: 14px; text-decoration: none; color: var(--text); display: flex; flex-direction: column; gap: 2px; background: var(--card2); }
.dl:hover { border-color: var(--accent); }
.dl span { font-size: 26px; }
.dl small { color: var(--muted); }
.dl.off { opacity: .45; pointer-events: none; }

.toast { position: fixed; left: 50%; bottom: 100px; transform: translateX(-50%) translateY(20px); background: var(--card2); border: 1px solid var(--line); padding: 10px 16px; border-radius: 12px; box-shadow: var(--shadow); opacity: 0; transition: .2s; pointer-events: none; z-index: 50; max-width: calc(100vw - 32px); }
.toast.show { opacity: 1; transform: translateX(-50%); }

.lightbox { position: fixed; inset: 0; background: rgba(0, 0, 0, .85); display: grid; place-items: center; z-index: 60; cursor: zoom-out; padding: 16px; }
.lightbox img { max-width: 100%; max-height: 100%; border-radius: 10px; }

/* ---------- Handy */
@media (max-width: 820px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .side { position: fixed; inset: 0 auto 0 0; width: min(300px, 85vw); z-index: 30; transform: translateX(-100%); transition: transform .2s; }
  .side.open { transform: none; box-shadow: var(--shadow); }
  .scrim { position: fixed; inset: 0; background: rgba(0, 0, 0, .5); z-index: 25; }
  .scrim.show { display: block; }
  .only-mobile { display: inline-grid; }
  .top { padding: 8px 10px; gap: 6px; }
  .user, .top-right .chip { display: none; }
  .seg button { padding: 5px 10px; }
  .messages { padding: 14px 12px 8px; }
  .composer { padding-left: 10px; padding-right: 10px; }
  .msg.user .bubble { max-width: 92%; }
  .msg-imgs img { max-width: 70vw; }
  .row select { max-width: 78px; padding: 8px 2px; }
  .row .icon-btn { width: 34px; }
  .row .desktop-only { display: none !important; }
  .send { padding: 9px 12px; }
  .hint-paste { display: none; }
  .tile { min-width: 130px; padding: 14px; }
  .grid2, .dl-grid { grid-template-columns: 1fr; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; scroll-behavior: auto !important; } }

/* Bild bearbeiten */
#image-seg { display: none; }
body.mode-bild #image-seg { display: inline-flex; }
body.mode-bild #engine-seg { display: none; }
body.mode-bild #detail { display: none; }
.top .seg { max-width: 100%; overflow-x: auto; scrollbar-width: none; flex-shrink: 1; min-width: 0; }
.top .seg button { white-space: nowrap; }
.admin-h { margin: 14px 0 0; font-size: 15px; display: flex; gap: 10px; align-items: baseline; }
.admin-h a { font-size: 13px; font-weight: 500; color: var(--accent); }
.badge.chatgpt { color: #10a37f; }
.badge.gemini { color: #4f8bf9; }
@media (max-width: 560px) { .top .seg button { padding: 5px 8px; font-size: 13px; } }
.gen { margin-bottom: 10px; }
.gen-view { position: relative; display: inline-block; max-width: 100%; line-height: 0; border-radius: 12px; overflow: hidden; border: 1px solid var(--line); }
.gen-view img { display: block; max-width: min(520px, 100%); max-height: 70vh; width: auto; height: auto; }
.gen-after { cursor: zoom-in; }
.gen-before { position: absolute; inset: 0; }
.gen-before img { width: 100%; height: 100%; max-width: none; max-height: none; object-fit: cover; }
.gen-range { position: absolute; left: 0; right: 0; bottom: 10px; width: calc(100% - 24px); margin: 0 12px; accent-color: var(--accent); }
.gen-tag { position: absolute; top: 8px; padding: 2px 8px; border-radius: 8px; background: rgba(0, 0, 0, .6); color: #fff; font-size: 12px; line-height: 1.6; }
.gen-tag.l { left: 8px; } .gen-tag.r { right: 8px; }
.gen-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.gen-actions .btn { padding: 7px 12px; font-size: 14px; }
.badge.image { background: rgba(236, 72, 153, .15); color: #ec4899; }

/* Test-Knöpfe im Admin */
.test-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding: 8px 10px; border: 1px dashed var(--line); border-radius: 10px; }
.btn.small-btn { padding: 6px 12px; font-size: 13px; }
.test-out { flex-basis: 100%; }
.test-out:empty { display: none; }
.test-out.ok { color: var(--ok); }
.test-out.bad { color: var(--bad); }
.test-img { margin-top: 6px; max-width: 160px; border-radius: 8px; border: 1px solid var(--line); }