/* =========================================================================
   Chat-Oberfläche – Dark Mode mit Fell-Hintergrund, Akzentfarbe Gelb
   ========================================================================= */

:root {
  --accent: #fde352;
  --accent-hover: #fff08a;
  --accent-text: #141414;

  --text: #f3f1eb;
  --text-soft: #c9c5bb;
  --text-faint: #8f8b83;

  --rail-bg: rgba(0, 0, 0, .62);
  --glass: rgba(24, 24, 23, .80);
  --glass-strong: rgba(18, 18, 17, .90);
  --bubble: rgba(52, 52, 49, .82);
  --hover: rgba(255, 255, 255, .08);
  --border: rgba(255, 255, 255, .10);
  --border-strong: rgba(255, 255, 255, .20);
  --code-bg: rgba(8, 8, 8, .78);
  --inline-code: rgba(255, 255, 255, .11);
  --danger: #ff9d94;
  --danger-bg: rgba(110, 28, 22, .55);
  --shadow: 0 2px 6px rgba(0, 0, 0, .35), 0 10px 30px rgba(0, 0, 0, .35);

  --font-ui: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-serif: "Iowan Old Style", "Charter", "Bitstream Charter", "Sitka Text", Cambria, Georgia, serif;
  --font-mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, "Liberation Mono", monospace;

  --rail-w: 88px;
  --thread-w: 46rem;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: #0b0b0b;
  color: var(--text);
  font: 15px/1.5 var(--font-ui);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
/* Fell-Hintergrund als fixierte Ebene (funktioniert auch auf iOS) */
body::before {
  content: ""; position: fixed; inset: 0; z-index: -1;
  background:
    linear-gradient(180deg, rgba(0, 0, 0, .25) 0%, rgba(0, 0, 0, .45) 100%),
    url("fur.jpg") center / cover no-repeat;
}
::selection { background: var(--accent); color: var(--accent-text); }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
* { scrollbar-width: thin; scrollbar-color: rgba(255, 255, 255, .22) transparent; }

/* ---------- Layout ---------------------------------------------------- */
.app { display: flex; height: 100dvh; overflow: hidden; }

.rail {
  flex: 0 0 var(--rail-w); width: var(--rail-w);
  display: flex; flex-direction: column; align-items: center; justify-content: space-between;
  padding: 18px 10px 14px;
  background: var(--rail-bg);
  border-right: 1px solid var(--border);
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
}
.rail-logo { display: block; width: 62px; border-radius: 6px; }
.rail-logo img { display: block; width: 100%; height: auto; }
.rail-logout { margin: 0; }
.rail-logout button {
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  width: 68px; padding: 8px 4px; border: 0; border-radius: 10px;
  background: transparent; color: var(--text-soft); font-size: 11px;
}
.rail-logout button:hover { background: var(--hover); color: var(--accent); }

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

.topbar {
  display: flex; align-items: center; gap: 8px;
  height: 54px; padding: 0 14px 0 20px; flex-shrink: 0;
}
.chat-title {
  flex: 1; min-width: 0;
  font-size: 14px; font-weight: 500; color: var(--text-soft);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.topbar-new {
  display: inline-flex; align-items: center; gap: 7px; flex-shrink: 0;
  height: 34px; padding: 0 13px; border-radius: 10px;
  border: 1px solid var(--border-strong); background: rgba(0, 0, 0, .35);
  color: var(--text); font-size: 13.5px; font-weight: 500;
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
  transition: border-color .15s ease, color .15s ease;
}
.topbar-new:hover { border-color: var(--accent); color: var(--accent); }
.main.is-empty .topbar-new { visibility: hidden; }

.scroller {
  flex: 1; overflow-y: auto; overflow-x: hidden; overscroll-behavior: contain;
}
.thread { max-width: var(--thread-w); margin: 0 auto; padding: 8px 20px 40px; }

/* ---------- Begrüßungs-Zustand (leerer Chat) --------------------------- */
.welcome { display: none; }
.main.is-empty .thread { display: none; }
.main.is-empty .welcome {
  display: flex; justify-content: center; align-items: flex-end;
  height: 100%; padding: 0 20px 28px;
}
.main.is-empty .scroller { flex: 1 1 40%; }
.main.is-empty .composer-wrap { flex: 1 1 60%; }
.main.is-empty .disclaimer { visibility: hidden; }
.greeting {
  margin: 0; font-family: var(--font-serif); font-weight: 400;
  font-size: clamp(28px, 4.4vw, 42px); letter-spacing: -.015em; text-align: center;
  text-shadow: 0 2px 18px rgba(0, 0, 0, .6);
}

/* ---------- Nachrichten ------------------------------------------------ */
.msg { margin: 18px 0; }
.msg-user { display: flex; flex-direction: column; align-items: flex-end; }
.msg-user .bubble {
  max-width: min(85%, 38rem);
  background: var(--bubble); border: 1px solid var(--border);
  padding: 10px 16px; border-radius: 16px;
  white-space: pre-wrap; overflow-wrap: anywhere;
  font-size: 15.5px; line-height: 1.55;
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
}
.msg-user .msg-actions { margin-top: 2px; min-height: 26px; }
.msg-user + .msg-assistant { margin-top: 6px; }

.msg-assistant .content {
  font-family: var(--font-serif);
  font-size: 16.5px; line-height: 1.68;
  overflow-wrap: anywhere;
  text-shadow: 0 1px 3px rgba(0, 0, 0, .55);
}

.msg-actions {
  display: flex; gap: 2px; margin-top: 6px; min-height: 30px;
  opacity: 0; transition: opacity .15s ease;
}
.msg:hover .msg-actions, .msg:focus-within .msg-actions, .msg.last .msg-actions { opacity: 1; }
.msg-actions button {
  display: inline-flex; align-items: center; gap: 5px;
  height: 28px; padding: 0 7px; border: 0; border-radius: 7px;
  background: transparent; color: var(--text-faint); font-size: 12.5px;
}
.msg-actions button:hover { background: var(--hover); color: var(--accent); }
.msg-actions .model-tag { margin-left: auto; font-size: 12px; color: var(--text-faint); align-self: center; padding-right: 4px; }

/* Bearbeiten einer Nutzernachricht */
.edit-box {
  width: min(100%, 38rem); background: var(--glass-strong); border: 1px solid var(--border-strong);
  border-radius: 16px; padding: 10px 12px; box-shadow: var(--shadow);
}
.edit-box textarea {
  width: 100%; border: 0; outline: 0; resize: none; background: transparent;
  font-size: 15.5px; line-height: 1.55; max-height: 50vh;
}
.edit-box .edit-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 6px; }
.btn {
  border-radius: 9px; padding: 6px 14px; font-size: 14px; font-weight: 500;
  border: 1px solid var(--border-strong); background: transparent;
}
.btn:hover { background: var(--hover); }
.btn-primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.btn-primary:hover { background: var(--accent-hover); }

/* Ladeanzeige */
.thinking { display: inline-flex; gap: 5px; padding: 10px 0 4px; }
.thinking i {
  width: 7px; height: 7px; border-radius: 50%; background: var(--accent);
  animation: pulse 1.2s infinite ease-in-out;
}
.thinking i:nth-child(2) { animation-delay: .15s; }
.thinking i:nth-child(3) { animation-delay: .3s; }
@keyframes pulse { 0%, 80%, 100% { opacity: .25; transform: scale(.8); } 40% { opacity: 1; transform: scale(1); } }

.streaming .content > :last-child::after {
  content: ""; display: inline-block; width: .55em; height: .55em; margin-left: 4px;
  border-radius: 50%; background: var(--accent); vertical-align: middle;
  animation: pulse 1s infinite ease-in-out;
}

.note {
  margin-top: 10px; padding: 9px 12px; border-radius: 10px; font-size: 14px; font-family: var(--font-ui);
  background: var(--glass); color: var(--text-soft); border: 1px solid var(--border);
}
.note.error { background: var(--danger-bg); color: var(--danger); border-color: rgba(255, 120, 110, .25); }
.note button {
  margin-left: 8px; border: 0; background: none; padding: 0; font-size: inherit;
  color: var(--accent); text-decoration: underline; text-underline-offset: 2px;
}

/* ---------- Markdown --------------------------------------------------- */
.content > :first-child { margin-top: 0; }
.content > :last-child { margin-bottom: 0; }
.content p { margin: 0 0 .85em; }
.content h1, .content h2, .content h3, .content h4 {
  font-family: var(--font-serif); line-height: 1.3; margin: 1.3em 0 .5em; font-weight: 600;
}
.content h1 { font-size: 1.45em; }
.content h2 { font-size: 1.25em; }
.content h3 { font-size: 1.1em; }
.content h4 { font-size: 1em; }
.content ul, .content ol { margin: 0 0 .85em; padding-left: 1.6em; }
.content li { margin: .25em 0; }
.content li > p { margin: 0 0 .4em; }
.content li::marker { color: var(--accent); }
.content a { color: var(--accent); text-underline-offset: 2px; }
.content a:hover { color: var(--accent-hover); }
.content blockquote {
  margin: 0 0 .85em; padding: 2px 0 2px 16px; border-left: 3px solid var(--accent); color: var(--text-soft);
}
.content hr { border: 0; border-top: 1px solid var(--border-strong); margin: 1.5em 0; }
.content strong { font-weight: 650; }
.content :not(pre) > code {
  font-family: var(--font-mono); font-size: .84em; text-shadow: none;
  background: var(--inline-code); padding: .12em .38em; border-radius: 5px;
}
.content table {
  border-collapse: collapse; margin: 0 0 1em; font-family: var(--font-ui); font-size: 14px;
  display: block; overflow-x: auto; max-width: 100%; text-shadow: none;
}
.content th, .content td { border: 1px solid var(--border-strong); padding: 7px 11px; text-align: left; vertical-align: top; background: rgba(0, 0, 0, .45); }
.content th { background: rgba(0, 0, 0, .7); font-weight: 600; }

.codeblock {
  margin: 0 0 1em; border: 1px solid var(--border); border-radius: 12px; overflow: hidden;
  background: var(--code-bg); font-family: var(--font-ui); text-shadow: none;
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
}
.codeblock-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 5px 6px 5px 14px; font-size: 12.5px; color: var(--text-faint);
  border-bottom: 1px solid var(--border);
}
.codeblock-head button {
  display: inline-flex; align-items: center; gap: 5px; height: 26px; padding: 0 8px;
  border: 0; border-radius: 6px; background: transparent; color: var(--text-faint); font-size: 12.5px;
}
.codeblock-head button:hover { background: var(--hover); color: var(--accent); }
.codeblock pre { margin: 0; padding: 14px 16px; overflow-x: auto; line-height: 1.55; }
.codeblock pre code, .codeblock pre code.hljs {
  display: block; font-family: var(--font-mono); font-size: 13.5px; line-height: 1.55;
  background: transparent !important; padding: 0 !important; overflow: visible;
}

/* ---------- Eingabefeld ------------------------------------------------ */
.composer-wrap { padding: 0 16px 6px; flex-shrink: 0; }
.composer {
  max-width: var(--thread-w); margin: 0 auto;
  background: var(--glass); border: 1px solid var(--border-strong);
  border-radius: 20px; padding: 12px 12px 10px 16px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  transition: border-color .15s ease;
}
.composer:focus-within { border-color: rgba(253, 227, 82, .55); }
.composer textarea {
  display: block; width: 100%; border: 0; outline: 0; resize: none; background: transparent;
  font-size: 16px; line-height: 1.5; max-height: 40vh; min-height: 26px; padding: 2px 0 0;
  caret-color: var(--accent);
}
.composer textarea::placeholder { color: var(--text-faint); }
.composer-bar { display: flex; align-items: center; justify-content: flex-end; gap: 8px; margin-top: 10px; }

.model-select { position: relative; display: inline-flex; align-items: center; color: var(--text-soft); }
.model-select select {
  appearance: none; -webkit-appearance: none; border: 0; background: transparent;
  padding: 5px 24px 5px 9px; border-radius: 8px; font-size: 13.5px; color: inherit; cursor: pointer;
}
.model-select select:hover { background: var(--hover); color: var(--text); }
.model-select svg { position: absolute; right: 8px; pointer-events: none; }
.model-select select option { color: var(--text); background: #1b1b1a; }

.send {
  display: grid; place-items: center; width: 34px; height: 34px; flex-shrink: 0;
  border: 0; border-radius: 10px; background: var(--accent); color: var(--accent-text);
  transition: background .15s ease, opacity .15s ease;
}
.send:hover:not(:disabled) { background: var(--accent-hover); }
.send:disabled { background: rgba(255, 255, 255, .12); color: var(--text-faint); cursor: default; }
.send .i-stop { display: none; }
.send.is-stop { background: var(--text); color: #111; }
.send.is-stop .i-send { display: none; }
.send.is-stop .i-stop { display: block; }

.disclaimer {
  margin: 8px 0 2px; text-align: center; font-size: 12px; color: var(--text-faint);
  text-shadow: 0 1px 3px rgba(0, 0, 0, .8);
}

/* ---------- Toast ------------------------------------------------------ */
.toast {
  position: fixed; left: 50%; bottom: 96px; transform: translateX(-50%) translateY(10px);
  background: var(--accent); color: var(--accent-text); padding: 8px 14px; border-radius: 10px;
  font-size: 13.5px; font-weight: 500; opacity: 0; pointer-events: none; transition: all .2s ease; z-index: 100;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------- Mobil: Navigation wird zur Kopfleiste ---------------------- */
@media (max-width: 720px) {
  .app { flex-direction: column; }
  .rail {
    flex: 0 0 auto; width: auto; flex-direction: row;
    padding: 8px 10px 8px 14px; border-right: 0; border-bottom: 1px solid var(--border);
  }
  .rail-logo { width: 40px; }
  .rail-logout button { flex-direction: row; width: auto; padding: 8px 10px; font-size: 13px; gap: 6px; }
  .topbar { height: 48px; padding: 0 10px 0 14px; }
  .thread { padding: 4px 14px 30px; }
  .composer-wrap { padding: 0 10px 4px; }
  .msg-actions { opacity: 1; }
  .msg-assistant .content { font-size: 16px; }
}

/* ---------- Login ------------------------------------------------------ */
.login-page { display: grid; place-items: center; min-height: 100dvh; padding: 20px; }
.login-card {
  width: 100%; max-width: 380px; text-align: center;
  background: rgba(0, 0, 0, .55); border: 1px solid var(--border);
  border-radius: 20px; padding: 34px 28px 30px;
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  box-shadow: var(--shadow);
}
.login-logo { display: block; width: 132px; height: auto; margin: 0 auto 22px; }
.login-sub { color: var(--text-soft); margin: 0 0 20px; }
.login-card input {
  width: 100%; padding: 12px 14px; border-radius: 12px; border: 1px solid var(--border-strong);
  background: rgba(0, 0, 0, .5); font-size: 16px; outline: none; caret-color: var(--accent);
}
.login-card input::placeholder { color: var(--text-faint); }
.login-card input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(253, 227, 82, .2); }
.login-card button {
  width: 100%; margin-top: 12px; padding: 11px; border-radius: 12px; border: 0;
  background: var(--accent); color: var(--accent-text); font-weight: 650; font-size: 15px;
}
.login-card button:hover { background: var(--accent-hover); }
.login-error { color: var(--danger); background: var(--danger-bg); border-radius: 10px; padding: 8px 12px; margin: 12px 0 0; font-size: 14px; }

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
