:root {
  --bg: #ffffff;
  --sidebar: #f9f9f9;
  --hover: #ececec;
  --active: #e3e3e3;
  --text: #0d0d0d;
  --muted: #5d5d5d;
  --faint: #8f8f8f;
  --border: #e5e5e5;
  --bubble: #e9f1fe;
  --bubble-text: #0b2a55;
  --accent: #2f6fde;
  --danger: #d0342c;
  --code-bg: #f6f6f6;
  --shadow: 0 4px 24px rgba(0,0,0,.08), 0 1px 3px rgba(0,0,0,.06);
  --composer: #ffffff;
  --brand-blue: #2563eb;
  --radius: 26px;
  font-synthesis: none;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #212121; --sidebar: #171717; --hover: #2a2a2a; --active: #333;
    --text: #ececec; --muted: #b4b4b4; --faint: #8a8a8a; --border: #383838;
    --bubble: #303030; --bubble-text: #ececec; --code-bg: #2b2b2b; --composer: #303030;
    --shadow: 0 4px 24px rgba(0,0,0,.35);
    --brand-blue: #60a5fa;
  }
}

/* ---------- Marke: vault – immer klein, immer fett, das v blau ---------- */
.vb { font-weight: 700; white-space: nowrap; }
.vb-v { color: var(--brand-blue); }
.bubble .vb-v { color: var(--brand-blue); }

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: ui-sans-serif, -apple-system, "Segoe UI", system-ui, Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 15px; line-height: 1.6; color: var(--text); background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; padding: 0; }
input, textarea { font: inherit; color: inherit; }
svg { display: block; flex: none; }
[hidden] { display: none !important; }

/* ---------- Login ---------- */
#login { min-height: 100%; display: grid; place-items: center; padding: 24px; }
.login-card { width: 100%; max-width: 360px; text-align: center; }
.login-card h1 { font-size: 28px; font-weight: 600; margin: 0 0 6px; }
.login-card p { color: var(--muted); margin: 0 0 24px; }
.login-card input {
  width: 100%; padding: 13px 16px; border: 1px solid var(--border); border-radius: 999px;
  background: var(--bg); outline: none; margin-bottom: 12px;
}
.login-card input:focus { border-color: var(--accent); }
.btn-primary {
  width: 100%; padding: 13px 16px; border-radius: 999px; background: var(--text); color: var(--bg); font-weight: 500;
}
.btn-primary:disabled { opacity: .5; cursor: default; }
.login-msg { margin-top: 16px; font-size: 14px; color: var(--muted); }
.login-msg a { color: var(--accent); word-break: break-all; }

/* ---------- Grundlayout ---------- */
#app { display: flex; height: 100%; overflow: hidden; }
#sidebar {
  width: 260px; flex: none; background: var(--sidebar); display: flex; flex-direction: column;
  border-right: 1px solid var(--border); transition: margin-left .2s ease;
}
#app.sb-closed #sidebar { margin-left: -260px; }
main { flex: 1; min-width: 0; display: flex; flex-direction: column; position: relative; }

.sb-head { display: flex; align-items: center; gap: 4px; padding: 10px 10px 6px 14px; }
.brand { font-weight: 600; font-size: 17px; flex: 1; display: flex; align-items: center; gap: 8px; }
.brand-mark {
  width: 22px; height: 22px; border-radius: 7px; background: #0d0d0d; color: #60a5fa;
  display: grid; place-items: center; font-size: 15px; font-weight: 700; line-height: 1; padding-bottom: 2px;
}
@media (prefers-color-scheme: dark) { .brand-mark { background: #ececec; color: #2563eb; } }
.icon-btn { width: 36px; height: 36px; border-radius: 9px; display: grid; place-items: center; color: var(--muted); }
.icon-btn:hover { background: var(--hover); color: var(--text); }

.sb-scroll { flex: 1; overflow-y: auto; padding: 4px 8px 12px; }
.sb-item {
  display: flex; align-items: center; gap: 10px; width: 100%; padding: 7px 10px; border-radius: 9px;
  text-align: left; font-size: 14px; color: var(--text); position: relative; min-height: 36px;
}
.sb-item:hover, .sb-item.menu-open { background: var(--hover); }
.sb-item.active { background: var(--active); }
.sb-item .label { flex: 1; min-width: 0; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.sb-item .more {
  opacity: 0; width: 26px; height: 26px; border-radius: 6px; display: grid; place-items: center; color: var(--muted);
}
.sb-item:hover .more, .sb-item.active .more, .sb-item.menu-open .more { opacity: 1; }
.sb-item .more:hover { color: var(--text); }
@media (hover: none) { .sb-item .more { opacity: 1; } }
.sb-section { margin-top: 18px; }
.sb-section-title { font-size: 13px; color: var(--faint); padding: 4px 10px 6px; }
.sb-show-more { font-size: 13px; color: var(--faint); padding: 6px 10px; }
.sb-show-more:hover { color: var(--text); }
.sb-sub { padding-left: 34px; font-size: 13.5px; color: var(--muted); }

.sb-foot { padding: 8px; border-top: 1px solid var(--border); }
.avatar {
  width: 28px; height: 28px; border-radius: 50%; background: #e8a33d; color: #fff; display: grid; place-items: center;
  font-size: 12px; font-weight: 600; flex: none;
}

/* ---------- Kopfzeile ---------- */
.topbar { height: 52px; display: flex; align-items: center; gap: 6px; padding: 0 10px; flex: none; }
.topbar .title { font-size: 15px; font-weight: 500; flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; padding-left: 6px; }
.topbar .model-chip { font-size: 13px; color: var(--muted); padding: 4px 10px; border-radius: 8px; }
#open-sidebar { display: none; }
#app.sb-closed #open-sidebar { display: grid; }

/* ---------- Verlauf ---------- */
#scroller { flex: 1; overflow-y: auto; overflow-anchor: none; }
.thread { max-width: 768px; margin: 0 auto; padding: 20px 24px 40px; }
.msg { margin: 0 0 28px; }
.msg-time { text-align: center; color: var(--faint); font-size: 12.5px; margin: 6px 0 20px; }
.msg.user { display: flex; flex-direction: column; align-items: flex-end; }
.bubble {
  background: var(--bubble); color: var(--bubble-text); padding: 10px 18px; border-radius: 22px; max-width: 75%;
  white-space: pre-wrap; word-wrap: break-word;
}
.attachments { display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-end; margin-bottom: 8px; max-width: 75%; }
.att-thumb { width: 120px; height: 120px; object-fit: cover; border-radius: 14px; border: 1px solid var(--border); cursor: zoom-in; }
.att-file {
  display: flex; align-items: center; gap: 10px; padding: 8px 12px; border: 1px solid var(--border); border-radius: 14px;
  font-size: 13px; max-width: 260px; background: var(--bg);
}
.att-file .ficon { width: 32px; height: 32px; border-radius: 8px; background: #f0563a; color: #fff; display: grid; place-items: center; font-size: 10px; font-weight: 700; flex: none; }
.att-file .fname { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.att-file .fsub { color: var(--faint); font-size: 12px; }

.msg.assistant .content { word-wrap: break-word; }
.msg-actions { display: flex; gap: 2px; margin-top: 6px; margin-left: -6px; opacity: 0; transition: opacity .15s; }
.msg.assistant:hover .msg-actions, .msg.assistant.last .msg-actions { opacity: 1; }
.msg-actions .icon-btn { width: 30px; height: 30px; border-radius: 7px; }

/* Markdown */
.md > :first-child { margin-top: 0; }
.md > :last-child { margin-bottom: 0; }
.md p { margin: 0 0 14px; }
.md h1, .md h2, .md h3, .md h4 { line-height: 1.3; margin: 24px 0 10px; font-weight: 600; }
.md h1 { font-size: 22px; } .md h2 { font-size: 19px; } .md h3 { font-size: 17px; } .md h4 { font-size: 15px; }
.md ul, .md ol { margin: 0 0 14px; padding-left: 24px; }
.md li { margin: 3px 0; }
.md li > p { margin: 0; }
.md a { color: var(--accent); text-decoration: underline; text-underline-offset: 2px; }
.md strong { font-weight: 600; }
.md blockquote { margin: 0 0 14px; padding-left: 14px; border-left: 3px solid var(--border); color: var(--muted); }
.md hr { border: 0; border-top: 1px solid var(--border); margin: 22px 0; }
.md code { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: 13.5px; background: var(--code-bg); padding: 2px 5px; border-radius: 5px; }
.md table { border-collapse: collapse; margin: 0 0 16px; font-size: 14px; display: block; overflow-x: auto; }
.md th, .md td { border-bottom: 1px solid var(--border); padding: 7px 12px; text-align: left; vertical-align: top; }
.md th { font-weight: 600; }
.md img { max-width: 100%; border-radius: 10px; }
.codeblock { margin: 0 0 16px; border-radius: 12px; background: var(--code-bg); overflow: hidden; }
.codeblock-head { display: flex; justify-content: space-between; align-items: center; padding: 6px 12px; font-size: 12px; color: var(--muted); }
.codeblock-head button { display: flex; gap: 5px; align-items: center; font-size: 12px; color: var(--muted); }
.codeblock-head button:hover { color: var(--text); }
.codeblock pre { margin: 0; padding: 4px 16px 14px; overflow-x: auto; }
.codeblock pre code { background: none; padding: 0; font-size: 13px; line-height: 1.55; }

/* Nachdenken */
.reasoning { margin-bottom: 12px; }
.reasoning-toggle { display: inline-flex; align-items: center; gap: 4px; color: var(--muted); font-size: 14px; }
.reasoning-toggle:hover { color: var(--text); }
.reasoning-toggle svg { transition: transform .15s; }
.reasoning.open .reasoning-toggle svg { transform: rotate(90deg); }
.reasoning-body {
  display: none; margin-top: 8px; padding-left: 14px; border-left: 2px solid var(--border); color: var(--muted);
  font-size: 13.5px; white-space: pre-wrap; max-height: 320px; overflow-y: auto;
}
.reasoning.open .reasoning-body { display: block; }
.shimmer {
  background: linear-gradient(90deg, var(--faint) 0%, var(--text) 50%, var(--faint) 100%);
  background-size: 200% 100%; -webkit-background-clip: text; background-clip: text; color: transparent;
  animation: shimmer 1.6s linear infinite;
}
@keyframes shimmer { from { background-position: 100% 0; } to { background-position: -100% 0; } }
.cursor-dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; background: var(--text); animation: pulse 1s ease-in-out infinite; vertical-align: middle; }
@keyframes pulse { 0%,100% { transform: scale(.7); opacity: .6; } 50% { transform: scale(1); opacity: 1; } }

/* Bilder */
.gen-image { margin: 4px 0 14px; position: relative; display: inline-block; max-width: 100%; }
.gen-image img { display: block; max-width: min(100%, 520px); max-height: 560px; border-radius: 16px; cursor: zoom-in; }
.gen-image .img-actions { position: absolute; top: 10px; right: 10px; display: flex; gap: 6px; opacity: 0; transition: opacity .15s; }
.gen-image:hover .img-actions { opacity: 1; }
.gen-image .img-actions a { width: 32px; height: 32px; border-radius: 50%; background: rgba(0,0,0,.55); color: #fff; display: grid; place-items: center; }
.img-placeholder {
  width: min(100%, 420px); aspect-ratio: 1; border-radius: 16px; margin: 4px 0 14px; display: grid; place-items: center;
  background: linear-gradient(110deg, var(--code-bg) 30%, var(--hover) 50%, var(--code-bg) 70%); background-size: 200% 100%;
  animation: shimmer 1.6s linear infinite; color: var(--muted); font-size: 14px;
}
.img-placeholder.landscape { aspect-ratio: 16/9; } .img-placeholder.portrait { aspect-ratio: 9/16; width: min(100%, 300px); }
.notice { font-size: 13px; color: var(--faint); margin: 0 0 10px; }
.error-box { border: 1px solid color-mix(in srgb, var(--danger) 40%, transparent); color: var(--danger); background: color-mix(in srgb, var(--danger) 7%, transparent); border-radius: 12px; padding: 10px 14px; font-size: 14px; margin: 6px 0 10px; }
.memory-note { font-size: 13px; color: var(--muted); display: inline-flex; gap: 6px; align-items: center; margin: 0 0 10px; }

/* ---------- Eingabe ---------- */
.composer-wrap { flex: none; padding: 0 16px 14px; }
.composer {
  max-width: 768px; margin: 0 auto; background: var(--composer); border-radius: var(--radius);
  box-shadow: var(--shadow); border: 1px solid var(--border); padding: 8px 10px;
}
.composer-files { display: flex; gap: 8px; flex-wrap: wrap; padding: 4px 4px 8px; }
.chip { position: relative; }
.chip img { width: 56px; height: 56px; object-fit: cover; border-radius: 12px; display: block; }
.chip .att-file { max-width: 220px; }
.chip .x {
  position: absolute; top: -6px; right: -6px; width: 20px; height: 20px; border-radius: 50%; background: var(--text); color: var(--bg);
  display: grid; place-items: center; font-size: 12px;
}
.chip.uploading { opacity: .5; }
.composer-row { display: flex; align-items: flex-end; gap: 6px; }
.composer textarea {
  flex: 1; border: 0; outline: none; resize: none; background: transparent; max-height: 240px; min-height: 24px;
  padding: 7px 4px; line-height: 1.5; font-size: 15.5px;
}
.composer textarea::placeholder { color: var(--faint); }
.input-wrap { flex: 1; position: relative; display: flex; min-width: 0; }
.input-ph {
  position: absolute; left: 4px; top: 7px; right: 4px; pointer-events: none; color: var(--faint);
  font-size: 15.5px; line-height: 1.5; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.send-btn { width: 36px; height: 36px; border-radius: 50%; background: var(--text); color: var(--bg); display: grid; place-items: center; }
.send-btn:disabled { opacity: .25; cursor: default; }
.composer .model-label { font-size: 13px; color: var(--muted); padding: 0 8px; align-self: center; white-space: nowrap; }
.disclaimer { text-align: center; font-size: 12px; color: var(--faint); padding-top: 8px; }

/* Startseite */
main.home #scroller { display: none; }
main.home .composer-wrap { flex: 1; display: flex; flex-direction: column; justify-content: center; padding-bottom: 18vh; }
.home-title { text-align: center; font-size: 28px; font-weight: 500; margin: 0 0 26px; }
main:not(.home) .home-title { display: none; }

/* ---------- Projektseite ---------- */
.project-page { max-width: 768px; margin: 0 auto; padding: 30px 24px 40px; }
.project-head { display: flex; align-items: center; gap: 12px; margin-bottom: 22px; }
.project-head h1 { font-size: 26px; font-weight: 600; margin: 0; flex: 1; outline: none; border-radius: 6px; }
.project-head h1:focus { background: var(--hover); }
.tabs { display: flex; gap: 6px; border-bottom: 1px solid var(--border); margin: 24px 0 8px; }
.tab { padding: 8px 12px; font-size: 14px; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tab.active { color: var(--text); border-color: var(--text); }
.list-row { display: flex; align-items: center; gap: 12px; padding: 12px 8px; border-bottom: 1px solid var(--border); border-radius: 8px; }
.list-row:hover { background: var(--sidebar); }
.list-row .grow { flex: 1; min-width: 0; }
.list-row .t { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list-row .s { font-size: 12.5px; color: var(--faint); }
.btn { display: inline-flex; align-items: center; gap: 6px; padding: 7px 14px; border: 1px solid var(--border); border-radius: 999px; font-size: 14px; }
.btn:hover { background: var(--hover); }
.btn-danger { color: var(--danger); }
.meter { height: 6px; border-radius: 3px; background: var(--hover); overflow: hidden; margin: 6px 0 2px; }
.meter > div { height: 100%; background: var(--accent); }
.empty { color: var(--faint); font-size: 14px; padding: 18px 8px; }
.drop-hint { border: 2px dashed var(--border); border-radius: 14px; padding: 18px; text-align: center; color: var(--faint); font-size: 14px; margin-top: 12px; }

/* ---------- Menüs, Dialoge ---------- */
.menu {
  position: fixed; z-index: 50; min-width: 200px; background: var(--bg); border: 1px solid var(--border); border-radius: 14px;
  box-shadow: var(--shadow); padding: 6px;
}
.menu button { display: flex; align-items: center; gap: 10px; width: 100%; padding: 8px 10px; border-radius: 8px; font-size: 14px; text-align: left; }
.menu button:hover { background: var(--hover); }
.menu button.danger { color: var(--danger); }
.menu hr { border: 0; border-top: 1px solid var(--border); margin: 5px 4px; }
.menu .menu-label { font-size: 12px; color: var(--faint); padding: 6px 10px 2px; }

.overlay { position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 60; display: grid; place-items: start center; padding: 10vh 16px 16px; }
.dialog { width: 100%; max-width: 560px; background: var(--bg); border-radius: 18px; box-shadow: var(--shadow); overflow: hidden; display: flex; flex-direction: column; max-height: 76vh; }
.dialog-head { display: flex; align-items: center; gap: 10px; padding: 14px 16px; border-bottom: 1px solid var(--border); }
.dialog-head h2 { font-size: 17px; margin: 0; flex: 1; font-weight: 600; }
.dialog-head input { flex: 1; border: 0; outline: none; background: transparent; font-size: 16px; }
.dialog-body { overflow-y: auto; padding: 8px; }
.dialog-body.pad { padding: 16px; }
.dialog-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 16px; border-top: 1px solid var(--border); }
.dialog textarea, .dialog .field { width: 100%; border: 1px solid var(--border); border-radius: 12px; padding: 10px 12px; outline: none; background: var(--bg); }
.dialog textarea { min-height: 220px; resize: vertical; }
.dialog textarea:focus, .dialog .field:focus { border-color: var(--accent); }
.result { display: block; width: 100%; text-align: left; padding: 10px 12px; border-radius: 10px; }
.result:hover, .result.sel { background: var(--hover); }
.result .t { font-size: 14px; font-weight: 500; }
.result .s { font-size: 13px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.result mark { background: #fff1a8; color: inherit; border-radius: 3px; padding: 0 1px; }
.mem-row { display: flex; gap: 10px; align-items: flex-start; padding: 10px 8px; border-bottom: 1px solid var(--border); font-size: 14px; }
.mem-row .grow { flex: 1; }
.mem-row .src { font-size: 12px; color: var(--faint); }

.lightbox { position: fixed; inset: 0; z-index: 70; background: rgba(0,0,0,.85); display: grid; place-items: center; padding: 24px; cursor: zoom-out; }
.lightbox img { max-width: 100%; max-height: 100%; border-radius: 8px; }
.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 10px 18px; border-radius: 12px; font-size: 14px; z-index: 80; box-shadow: var(--shadow); }
.drop-overlay { position: fixed; inset: 0; z-index: 65; background: color-mix(in srgb, var(--accent) 12%, transparent); border: 3px dashed var(--accent); display: grid; place-items: center; font-size: 18px; color: var(--accent); pointer-events: none; }

/* ---------- Mobil ---------- */
@media (max-width: 800px) {
  #sidebar { position: fixed; inset: 0 auto 0 0; z-index: 40; width: 280px; box-shadow: var(--shadow); }
  #app.sb-closed #sidebar { margin-left: -290px; }
  #app:not(.sb-closed)::after { content: ""; position: fixed; inset: 0; background: rgba(0,0,0,.3); z-index: 30; }
  #open-sidebar { display: grid !important; }
  .thread { padding: 12px 14px 30px; }
  .bubble, .attachments { max-width: 88%; }
  .composer-wrap { padding: 0 10px 10px; }
  .home-title { font-size: 24px; }
}
