:root {
  --bg: #eef1f5;
  --surface: #ffffff;
  --header: #1f3a5f;
  --header-text: #ffffff;
  --border: #d4dae2;
  --text: #1c2530;
  --text-muted: #64748b;

  --ai-bubble: #ffffff;
  --ai-border: #d4dae2;
  --user-bubble: #1f3a5f;
  --user-text: #ffffff;

  --accent: #1f3a5f;
  --accent-hover: #274b7a;
  --error: #b3261e;

  --input-bg: #ffffff;

  --radius: 14px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

/* ---- Dunkler Modus ---- */
:root[data-theme="dark"] {
  --bg: #0f151c;
  --surface: #1a222c;
  --header: #14202c;
  --border: #2c3a49;
  --text: #e6ebf1;
  --text-muted: #93a1b1;

  --ai-bubble: #1f2a36;
  --ai-border: #30404f;
  --user-bubble: #2f6fb0;
  --user-text: #ffffff;

  --accent: #3b7cc4;
  --accent-hover: #4d8dd0;

  --input-bg: #121a23;
}

* {
  box-sizing: border-box;
}

html, body {
  height: 100%;
  margin: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.5;
  transition: background-color 0.2s ease, color 0.2s ease;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* ---- Layout ---- */
.app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  max-width: 820px;
  margin: 0 auto;
  background: var(--bg);
}

/* ---- Header ---- */
.app__header {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 20px;
  background: var(--header);
  color: var(--header-text);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.12);
  z-index: 2;
}

.app__title h1 {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 600;
  letter-spacing: 0.2px;
}

.app__title p {
  margin: 2px 0 0;
  font-size: 0.8rem;
  opacity: 0.8;
}

.app__controls {
  display: flex;
  align-items: center;
  gap: 8px;
}

.icon-btn {
  flex: 0 0 auto;
  width: 38px;
  height: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid rgba(255, 255, 255, 0.25);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.12);
  color: var(--header-text);
  font-size: 1.05rem;
  line-height: 1;
  cursor: pointer;
  transition: background 0.15s ease;
}

.icon-btn:hover {
  background: rgba(255, 255, 255, 0.22);
}

.icon-btn:focus {
  outline: none;
  border-color: rgba(255, 255, 255, 0.6);
}

.app__provider,
.app__controls input {
  padding: 9px 12px;
  border: 1px solid rgba(255, 255, 255, 0.25);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.12);
  color: var(--header-text);
  font-size: 0.85rem;
}

.app__provider {
  cursor: pointer;
}

.app__provider option {
  /* Native Options-Popups sind meist hell – feste Farben halten sie lesbar. */
  color: #1c2530;
  background: #ffffff;
}

.app__controls input {
  width: 230px;
  max-width: 38vw;
}

.app__controls input::placeholder {
  color: rgba(255, 255, 255, 0.6);
}

.app__provider:focus,
.app__controls input:focus {
  outline: none;
  border-color: rgba(255, 255, 255, 0.6);
  background: rgba(255, 255, 255, 0.18);
}

/* ---- Setup-Leiste (Szenario + Dokumente) ---- */
.setup {
  flex: 0 0 auto;
  padding: 10px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  transition: background-color 0.2s ease;
}

.setup__row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.setup__label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
}

.setup__scenario {
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--input-bg);
  color: var(--text);
  font-size: 0.85rem;
  cursor: pointer;
}

.setup__scenario option {
  color: #1c2530;
  background: #ffffff;
}

.setup__spacer {
  flex: 1 1 auto;
}

.setup__btn {
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--input-bg);
  color: var(--text);
  font-size: 0.85rem;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.setup__btn:hover {
  border-color: var(--accent);
}

.setup__btn--accent {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.setup__btn--accent:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}

.setup__docs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.setup__docs:empty {
  margin-top: 0;
}

.doc-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 6px 4px 10px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--bg);
  font-size: 0.8rem;
  color: var(--text);
  max-width: 260px;
}

.doc-chip__name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.doc-chip__remove {
  flex: 0 0 auto;
  width: 18px;
  height: 18px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: 50%;
  background: transparent;
  color: var(--text-muted);
  font-size: 0.7rem;
  cursor: pointer;
  line-height: 1;
}

.doc-chip__remove:hover {
  background: var(--error);
  color: #fff;
}

/* ---- Messages ---- */
.messages {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 24px 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  scroll-behavior: smooth;
}

.message {
  max-width: 76%;
  padding: 11px 15px;
  border-radius: var(--radius);
  white-space: pre-wrap;
  word-wrap: break-word;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06);
  animation: pop 0.14s ease-out;
}

@keyframes pop {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

/* KI / Fachleiter – links */
.message--assistant {
  align-self: flex-start;
  background: var(--ai-bubble);
  border: 1px solid var(--ai-border);
  border-bottom-left-radius: 4px;
  color: var(--text);
}

/* Nutzer – rechts */
.message--user {
  align-self: flex-end;
  background: var(--user-bubble);
  color: var(--user-text);
  border-bottom-right-radius: 4px;
}

.message__role {
  display: block;
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  opacity: 0.65;
  margin-bottom: 3px;
}

/* System-/Fehlerhinweis */
.message--system {
  align-self: center;
  max-width: 90%;
  background: transparent;
  border: 1px dashed var(--border);
  color: var(--text-muted);
  font-size: 0.85rem;
  text-align: center;
  box-shadow: none;
}

.message--error {
  align-self: center;
  max-width: 90%;
  background: #fdecea;
  border: 1px solid var(--error);
  color: var(--error);
  font-size: 0.85rem;
  text-align: center;
  box-shadow: none;
}

/* Ladeindikator */
.message--loading {
  color: var(--text-muted);
}

.typing {
  display: inline-flex;
  gap: 4px;
  align-items: center;
}

.typing span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text-muted);
  opacity: 0.5;
  animation: blink 1.2s infinite ease-in-out;
}

.typing span:nth-child(2) { animation-delay: 0.2s; }
.typing span:nth-child(3) { animation-delay: 0.4s; }

@keyframes blink {
  0%, 80%, 100% { opacity: 0.3; transform: scale(0.9); }
  40% { opacity: 1; transform: scale(1); }
}

/* ---- Composer (immer unten fixiert) ---- */
.composer {
  flex: 0 0 auto;
  display: flex;
  gap: 10px;
  align-items: flex-end;
  padding: 14px 20px;
  background: var(--surface);
  border-top: 1px solid var(--border);
  box-shadow: 0 -2px 8px rgba(0, 0, 0, 0.05);
}

.composer__input {
  flex: 1 1 auto;
  resize: none;
  max-height: 160px;
  padding: 11px 14px;
  border: 1px solid var(--border);
  border-radius: 12px;
  font-family: inherit;
  font-size: 0.95rem;
  line-height: 1.4;
  color: var(--text);
  background: var(--input-bg);
}

.composer__input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(31, 58, 95, 0.12);
}

.composer__send {
  flex: 0 0 auto;
  padding: 11px 22px;
  border: none;
  border-radius: 12px;
  background: var(--accent);
  color: #fff;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease;
}

.composer__send:hover:not(:disabled) {
  background: var(--accent-hover);
}

.composer__send:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

@media (max-width: 560px) {
  .app__title p { display: none; }
  .app__controls input { width: 130px; }
  .message { max-width: 86%; }
}
