:root {
  --bg: #ffffff;
  --bg-soft: #f6f6f4;
  --bg-sunk: #efeeea;
  --fg: #1d1c1a;
  --fg-dim: #6b6862;
  --line: #e2e0da;
  --accent: #c96442;
  --accent-fg: #ffffff;
  --error: #b4392a;
  --radius: 12px;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  --sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1b1b19;
    --bg-soft: #232320;
    --bg-sunk: #2b2a27;
    --fg: #eceae4;
    --fg-dim: #9b978f;
    --line: #35342f;
    --accent: #d97757;
    --error: #e07a6a;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0; height: 100%;
  background: var(--bg); color: var(--fg);
  font-family: var(--sans); font-size: 15px; line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }

button { font: inherit; cursor: pointer; border: none; background: none; color: inherit; }
input, textarea, select { font: inherit; color: inherit; }

/* ---------------------------------------------------------------- Anmeldung */

.gate {
  min-height: 100%;
  display: grid; place-items: center;
  padding: 24px;
  background: var(--bg-soft);
}

.gate-card {
  width: 100%; max-width: 380px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 32px 28px;
}

.gate-card h1 { margin: 0; font-size: 24px; letter-spacing: -0.02em; }
.gate-sub { margin: 4px 0 24px; color: var(--fg-dim); font-size: 14px; }

.tabs { display: flex; gap: 4px; margin-bottom: 20px; background: var(--bg-sunk); padding: 3px; border-radius: 10px; }
.tab {
  flex: 1; padding: 7px; border-radius: 8px;
  font-size: 14px; color: var(--fg-dim);
}
.tab.active { background: var(--bg); color: var(--fg); font-weight: 500; }

.pane { display: flex; flex-direction: column; gap: 14px; }

label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--fg-dim); }

input, textarea {
  padding: 10px 12px;
  border: 1px solid var(--line); border-radius: 9px;
  background: var(--bg); font-size: 15px;
}
input:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }

.pane button[type=submit], .primary {
  background: var(--accent); color: var(--accent-fg);
  padding: 10px; border-radius: 9px; font-weight: 500;
}
.pane button[type=submit]:hover, .primary:hover { filter: brightness(1.07); }
.pane button[type=submit]:disabled { opacity: 0.5; cursor: default; }

.ghost {
  border: 1px solid var(--line); border-radius: 9px;
  padding: 8px; font-size: 13px; color: var(--fg-dim);
}
.ghost:hover { background: var(--bg-sunk); color: var(--fg); }

.link { color: var(--fg-dim); font-size: 13px; text-decoration: underline; padding: 0; }
.link:hover { color: var(--fg); }

.error { color: var(--error); font-size: 13px; margin: 12px 0 0; min-height: 1em; }

/* ---------------------------------------------------------------- Gerüst */

.shell { display: flex; height: 100%; }

#sidebar {
  width: 260px; flex-shrink: 0;
  display: flex; flex-direction: column;
  background: var(--bg-soft);
  border-right: 1px solid var(--line);
}

.side-head { padding: 14px; }
.side-head button { width: 100%; }

#conv-list { flex: 1; overflow-y: auto; padding: 0 8px; }

.conv {
  display: flex; align-items: center; gap: 6px;
  padding: 8px 10px; border-radius: 8px;
  font-size: 14px; color: var(--fg-dim);
  cursor: pointer;
}
.conv:hover { background: var(--bg-sunk); color: var(--fg); }
.conv.active { background: var(--bg-sunk); color: var(--fg); font-weight: 500; }
.conv span { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv .del { opacity: 0; font-size: 15px; line-height: 1; padding: 0 4px; }
.conv:hover .del { opacity: 0.5; }
.conv .del:hover { opacity: 1; color: var(--error); }

.side-foot { padding: 14px; border-top: 1px solid var(--line); display: flex; flex-direction: column; gap: 12px; }

.budget { font-size: 12px; color: var(--fg-dim); display: flex; flex-direction: column; gap: 4px; }
.budget-row { display: flex; justify-content: space-between; }
.bar { height: 4px; background: var(--bg-sunk); border-radius: 2px; overflow: hidden; margin-bottom: 4px; }
.bar i { display: block; height: 100%; width: 0; background: var(--accent); transition: width 0.3s; }
.bar i.warn { background: var(--error); }

.who { display: flex; justify-content: space-between; align-items: center; font-size: 13px; color: var(--fg-dim); }

main { flex: 1; display: flex; flex-direction: column; min-width: 0; }

header {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 20px; border-bottom: 1px solid var(--line);
  font-size: 13px; color: var(--fg-dim);
}
header select {
  padding: 5px 8px; border: 1px solid var(--line); border-radius: 8px;
  background: var(--bg); font-size: 13px;
}
#conv-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.icon { display: none; font-size: 18px; }

/* ---------------------------------------------------------------- Verlauf */

#thread { flex: 1; overflow-y: auto; padding: 28px 20px 12px; scroll-behavior: smooth; }

.empty { max-width: 680px; margin: 14vh auto; text-align: center; color: var(--fg-dim); }
.empty h2 { color: var(--fg); font-weight: 500; font-size: 22px; margin: 0 0 8px; }
.empty p { margin: 0; font-size: 14px; }

.msg { max-width: 720px; margin: 0 auto 24px; }
.msg.user .bubble {
  background: var(--bg-sunk); border-radius: var(--radius);
  padding: 12px 16px; margin-left: auto; max-width: 85%; width: fit-content;
  white-space: pre-wrap; overflow-wrap: anywhere;
}
.msg.assistant .bubble { overflow-wrap: anywhere; }
.msg.assistant .bubble > *:first-child { margin-top: 0; }
.msg.assistant .bubble > *:last-child { margin-bottom: 0; }

.bubble h1, .bubble h2, .bubble h3 { font-size: 1.05em; margin: 1.2em 0 0.4em; }
.bubble p { margin: 0 0 0.9em; }
.bubble ul, .bubble ol { margin: 0 0 0.9em; padding-left: 1.4em; }
.bubble li { margin-bottom: 0.25em; }
.bubble code {
  font-family: var(--mono); font-size: 0.88em;
  background: var(--bg-sunk); padding: 1px 5px; border-radius: 5px;
}
.bubble pre {
  background: var(--bg-sunk); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 14px;
  overflow-x: auto; margin: 0 0 0.9em;
}
.bubble pre code { background: none; padding: 0; font-size: 13px; line-height: 1.5; }
.bubble blockquote {
  border-left: 3px solid var(--line); margin: 0 0 0.9em; padding-left: 12px; color: var(--fg-dim);
}

.cursor::after {
  content: "▍"; color: var(--accent);
  animation: blink 1s steps(2) infinite;
}
@keyframes blink { 50% { opacity: 0; } }

/* ---------------------------------------------------------------- Eingabe */

#composer {
  max-width: 720px; width: 100%; margin: 0 auto;
  padding: 0 20px 8px;
  display: flex; gap: 8px; align-items: flex-end;
}
#input {
  flex: 1; resize: none; max-height: 220px;
  border-radius: var(--radius); padding: 12px 14px;
  background: var(--bg-soft);
}
#send {
  width: 40px; height: 40px; flex-shrink: 0;
  border-radius: 50%; background: var(--accent); color: var(--accent-fg);
  font-size: 17px; line-height: 1;
}
#send:disabled { opacity: 0.35; cursor: default; }

#chat-error { max-width: 720px; margin: 0 auto 10px; padding: 0 20px; width: 100%; }

/* ---------------------------------------------------------------- Fenster */

.modal {
  position: fixed; inset: 0; z-index: 20;
  background: rgba(0, 0, 0, 0.45);
  display: grid; place-items: center; padding: 20px;
}
.modal-card {
  background: var(--bg); border-radius: 16px; padding: 26px;
  width: 100%; max-width: 420px;
  display: flex; flex-direction: column; gap: 12px;
}
.modal-card h3 { margin: 0; font-size: 17px; }
.modal-card p { margin: 0; font-size: 13px; color: var(--fg-dim); }
.modal-card textarea { resize: vertical; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; }
.modal-actions button { padding: 8px 16px; }

/* ---------------------------------------------------------------- Schmal */

@media (max-width: 760px) {
  #sidebar {
    position: fixed; z-index: 10; inset: 0 auto 0 0;
    transform: translateX(-100%); transition: transform 0.2s;
    box-shadow: 0 0 40px rgba(0, 0, 0, 0.25);
  }
  #sidebar.open { transform: none; }
  .icon { display: block; }
  #thread { padding: 20px 12px 8px; }
  #composer { padding: 0 12px 8px; }
}
