/* barista Web-Demo — Chat-UI. Kein Build-Schritt, same-origin, CSP-konform
   (kein Inline-CSS/JS; alle Styles hier). Warm, kaffeehaus-inspiriert, dezent. */

:root {
  color-scheme: light dark;

  --bg: #f3ece2;
  --surface: #fffdfa;
  --surface-2: #efe5d8;
  --text: #2a201a;
  --text-muted: #6f6055;
  --border: #e2d5c5;
  --accent: #6f4526; /* Espresso */
  --accent-strong: #5a3620;
  --user-bubble: #6f4526;
  --user-ink: #fbf3ea;
  --assistant-bubble: #fffdfa;
  --focus: #a8663a;
  --shadow: 0 1px 2px rgba(60, 40, 25, 0.08), 0 3px 10px rgba(60, 40, 25, 0.06);

  /* Guardrail-/Safety-Blöcke — je Marker klar unterscheidbar */
  --escalate-bg: #fadedb;
  --escalate-border: #c0392b;
  --escalate-ink: #7a231a;
  --health-bg: #fbeecb;
  --health-border: #d8a63a;
  --health-ink: #6b4a08;
  --slate-bg: #e9e2d9;
  --slate-border: #b3a595;
  --slate-ink: #4a3f34;
  --info-bg: #e3edf0;
  --info-border: #4f8592;
  --info-ink: #274e56;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1b1410;
    --surface: #241b15;
    --surface-2: #2c211a;
    --text: #f2e9df;
    --text-muted: #b9a692;
    --border: #3a2c22;
    --accent: #c98a5c;
    --accent-strong: #d79a63;
    --user-bubble: #8a5a34;
    --user-ink: #fbf3ea;
    --assistant-bubble: #2c211a;
    --focus: #d79a63;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 3px 10px rgba(0, 0, 0, 0.25);

    --escalate-bg: #3a1c18;
    --escalate-border: #d15b4c;
    --escalate-ink: #f3b3a9;
    --health-bg: #382c13;
    --health-border: #b9862f;
    --health-ink: #f2d488;
    --slate-bg: #2a2620;
    --slate-border: #5a5145;
    --slate-ink: #cdbfae;
    --info-bg: #1d2a2d;
    --info-border: #4f8592;
    --info-ink: #a9d4dc;
  }
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Ubuntu, sans-serif;
  line-height: 1.55;
  -webkit-text-size-adjust: 100%;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  border: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
}

/* ── Layout: Kopf · Chat (scrollt) · Fuß ──────────────────────────────── */

.app {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  max-width: 48rem;
  margin: 0 auto;
}

.site-header {
  padding: 1rem 1rem 0.75rem;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.site-header__inner {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.35rem 0.75rem;
}

.site-title {
  margin: 0;
  font-size: 1.4rem;
  letter-spacing: 0.01em;
  color: var(--accent);
}

.site-title__mark {
  color: var(--accent);
}

.site-sub {
  margin: 0;
  color: var(--text-muted);
  font-size: 0.95rem;
}

/* „Neue Sitzung" — dezenter Escape-Hatch rechts im Kopf (Sticky-Reparatur verlassen) */
.new-session {
  margin-left: auto;
  align-self: center;
  flex: none;
  padding: 0.25rem 0.7rem;
  font: inherit;
  font-size: 0.76rem;
  line-height: 1.2;
  color: var(--text-muted);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  cursor: pointer;
  transition:
    color 0.12s ease,
    border-color 0.12s ease;
}

.new-session:hover {
  color: var(--text);
  border-color: var(--accent);
}

.tiers {
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin: 0.35rem 0 0;
  padding: 0;
  width: 100%;
}

.tier {
  font-size: 0.72rem;
  letter-spacing: 0.02em;
  color: var(--text-muted);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.12rem 0.6rem;
}

.chat {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding: 0.75rem 0.75rem 0;
}

/* ── Hinweis-/Fehlerbanner ────────────────────────────────────────────── */

.notice {
  margin: 0 0 0.6rem;
  padding: 0.7rem 0.85rem;
  border-radius: 0.6rem;
  border: 1px solid var(--escalate-border);
  background: var(--escalate-bg);
  color: var(--escalate-ink);
  font-size: 0.92rem;
}

.notice[hidden] {
  display: none;
}

.notice--info {
  border-color: var(--info-border);
  background: var(--info-bg);
  color: var(--info-ink);
}

/* ── Nachrichtenverlauf ───────────────────────────────────────────────── */

.messages {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
  padding: 0.25rem 0.15rem 0.75rem;
}

.msg {
  display: flex;
}

.msg--user {
  justify-content: flex-end;
}

.msg--assistant {
  justify-content: flex-start;
}

.bubble {
  max-width: 85%;
  padding: 0.6rem 0.8rem;
  border-radius: 1rem;
  box-shadow: var(--shadow);
  overflow-wrap: anywhere;
}

.msg--user .bubble {
  background: var(--user-bubble);
  color: var(--user-ink);
  border-bottom-right-radius: 0.3rem;
}

.msg--assistant .bubble {
  background: var(--assistant-bubble);
  color: var(--text);
  border: 1px solid var(--border);
  border-bottom-left-radius: 0.3rem;
}

.bubble__text {
  margin: 0;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

/* Guardrail-Badge (Label über dem Antworttext) */
.badge {
  display: inline-block;
  margin: 0 0 0.4rem;
  padding: 0.1rem 0.55rem;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  border: 1px solid currentColor;
}

/* Abgesetzte Guardrail-/Safety-Blöcke: eigene Farbe + Rahmen je Marker */
.bubble--escalate {
  background: var(--escalate-bg) !important;
  border: 1px solid var(--escalate-border) !important;
  color: var(--escalate-ink) !important;
}
.bubble--escalate .badge {
  color: var(--escalate-ink);
}

.bubble--health {
  background: var(--health-bg) !important;
  border: 1px solid var(--health-border) !important;
  color: var(--health-ink) !important;
}
.bubble--health .badge {
  color: var(--health-ink);
}

.bubble--keine-quelle {
  background: var(--slate-bg) !important;
  border: 1px solid var(--slate-border) !important;
  color: var(--slate-ink) !important;
}
.bubble--keine-quelle .badge {
  color: var(--slate-ink);
}

.bubble--kategorie {
  background: var(--info-bg) !important;
  border: 1px solid var(--info-border) !important;
  color: var(--info-ink) !important;
}
.bubble--kategorie .badge {
  color: var(--info-ink);
}

/* Quellenliste unter der Antwort */
.quellen {
  margin: 0.6rem 0 0;
  padding: 0.5rem 0 0;
  border-top: 1px solid var(--border);
  list-style: none;
  font-size: 0.85rem;
}

.quellen__title {
  margin: 0 0 0.25rem;
  font-size: 0.75rem;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.quellen li {
  margin: 0.15rem 0;
  display: flex;
  gap: 0.4rem;
}

.quellen__nr {
  flex: none;
  font-variant-numeric: tabular-nums;
  color: var(--accent);
  font-weight: 600;
}

/* Ladeanimation (CSS-only, drei Punkte) */
.dots {
  display: inline-flex;
  gap: 0.28rem;
  align-items: center;
  padding: 0.2rem 0.1rem;
}

.dots span {
  width: 0.5rem;
  height: 0.5rem;
  border-radius: 50%;
  background: var(--text-muted);
  animation: dot-bounce 1.2s infinite ease-in-out both;
}

.dots span:nth-child(2) {
  animation-delay: 0.16s;
}

.dots span:nth-child(3) {
  animation-delay: 0.32s;
}

@keyframes dot-bounce {
  0%,
  70%,
  100% {
    transform: translateY(0);
    opacity: 0.5;
  }
  35% {
    transform: translateY(-0.28rem);
    opacity: 1;
  }
}

@media (prefers-reduced-motion: reduce) {
  .dots span {
    animation: dot-fade 1.2s infinite ease-in-out both;
  }
  @keyframes dot-fade {
    0%,
    100% {
      opacity: 0.35;
    }
    50% {
      opacity: 1;
    }
  }
}

/* ── Eingabe ──────────────────────────────────────────────────────────── */

.composer {
  display: flex;
  gap: 0.5rem;
  align-items: flex-end;
  padding-top: 0.5rem;
  border-top: 1px solid var(--border);
}

.composer__input {
  flex: 1;
  resize: vertical;
  min-height: 2.6rem;
  max-height: 40vh;
  padding: 0.55rem 0.7rem;
  border-radius: 0.7rem;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  line-height: 1.4;
}

.composer__input::placeholder {
  color: var(--text-muted);
}

.composer__send {
  flex: none;
  padding: 0.6rem 1.1rem;
  min-height: 2.6rem;
  border: 1px solid var(--accent);
  border-radius: 0.7rem;
  background: var(--accent);
  color: var(--user-ink);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.12s ease;
}

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

.composer__send:disabled,
.composer__input:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

.composer__hint {
  margin: 0.35rem 0.1rem 0.75rem;
  font-size: 0.78rem;
  color: var(--text-muted);
}

/* ── Fuß / Disclaimer ─────────────────────────────────────────────────── */

.disclaimer {
  padding: 0.7rem 1rem 1rem;
  border-top: 1px solid var(--border);
  background: var(--surface);
}

.disclaimer p {
  margin: 0;
  font-size: 0.78rem;
  color: var(--text-muted);
  line-height: 1.45;
}

@media (max-width: 400px) {
  .bubble {
    max-width: 92%;
  }
  .site-title {
    font-size: 1.25rem;
  }
}
