:root {
  /* Brunnen Corporate Identity (siehe brunnen.de/styleguide) */
  --brunnen-red:       #b00000;  /* Logo-Rot */
  --brunnen-red-ci:    #c00808;  /* CI-Rot fuer Buttons / Highlights */
  --brunnen-red-dark:  #8a0000;  /* fuer Hover */
  --ci-grau:           #495A6B;  /* Sekundaer-Grau */
  --ci-grau-soft:      #6c7a89;  /* aufgehellt */
  --ink:               #000000;  /* Primaer-Text Schwarz */
  --ink-muted:         #495A6B;  /* Sub-Text = CI-Grau */
  --ink-subtle:        #8a96a3;  /* noch subtiler */
  --bg:                #ffffff;
  --bg-soft:           #f5f5f5;  /* Light-Grau aus dem Styleguide */
  --bg-tint:           #faf7f7;  /* sehr leichter Roststich fuer Highlights */
  --border:            #e2e6ea;
  --border-strong:     #495A6B;
  --radius:            2px;
  --radius-pill:       999px;
  /* Source Sans 3 = freie Naeherung an Argumentum (Brunnens Hausschrift). */
  --font-sans: "Source Sans 3", "Argumentum", "Helvetica Neue", Helvetica, Arial, "Segoe UI", system-ui, sans-serif;
  --font-mono: "ui-monospace", "SF Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0; padding: 0;
  font-family: var(--font-sans);
  font-size: 16px;          /* Brunnen-CI: Body 1rem = 16px */
  line-height: 1.5;          /* Brunnen-CI: Body line-height 1.5 */
  color: var(--ink);
  background: var(--bg);
  height: 100%;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}
body { display: flex; flex-direction: column; min-height: 100vh; }

a { color: inherit; text-decoration: none; }

/* ---------- Brunnen Typo-Skala (aus dem Styleguide) ---------- */
h1, .h1 { font-size: 3rem;   font-weight: 700; line-height: 1.25; letter-spacing: 0.005em; margin: 0 0 2rem; }
h2, .h2 { font-size: 2rem;   font-weight: 700; line-height: 1.25; letter-spacing: 0.005em; margin: 0 0 2rem; }
h3, .h3 { font-size: 1.5rem; font-weight: 700; line-height: 1.25; margin: 0 0 1.5rem; }
h4, .h4 { font-size: 1rem;   font-weight: 700; line-height: 1.5;  margin: 0 0 1rem; }

/* ---------- Top red bar ---------- */
.redbar {
  background: var(--brunnen-red);
  color: #ffffff;
  font-size: 13px;
  font-weight: 500;
  letter-spacing: 0.01em;
  padding: 6px 28px;
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 16px;
  min-height: 28px;
}
.redbar .status-dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: rgba(255,255,255,0.4);
  display: inline-block;
  flex-shrink: 0;
  margin-right: 5px;
}
.redbar .status-dot.ok   { background: #8ee39a; box-shadow: 0 0 6px #8ee39a; }
.redbar .status-dot.err  { background: #ff6b6b; box-shadow: 0 0 6px #ff6b6b; }
.redbar .status-dot.warn { background: #ffd166; box-shadow: 0 0 6px #ffd166; }
.redbar .status {
  color: #ffffff;
  opacity: 0.95;
  display: inline-flex;
  align-items: center;
}

/* Ngrok-Tunnel-Status in der Redbar */
.ngrok-status {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  color: rgba(255,255,255,0.85);
  padding-right: 14px;
  margin-right: 6px;
  border-right: 1px solid rgba(255,255,255,0.25);
}
.ngrok-status:empty { display: none; }
.ngrok-status a.ngrok-url {
  color: rgba(255,255,255,0.9);
  text-decoration: none;
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.01em;
  transition: color 0.12s;
}
.ngrok-status a.ngrok-url:hover {
  color: #ffffff;
  text-decoration: underline;
}
.ngrok-status.ngrok-warn {
  color: #ffd166;
  font-weight: 600;
}

/* ---------- Main header ---------- */
.mainbar {
  background: #ffffff;
  border-bottom: 1px solid var(--border);
  padding: 18px 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 32px;
}

.logo {
  display: inline-flex;
  align-items: center;
  /* Neues Logo ist bereits rot+weiß auf weißem Hintergrund —
     kein farbiger Container mehr nötig. */
  background: transparent;
  line-height: 0;
  flex-shrink: 0;
}
.logo-img {
  display: block;
  height: 36px;
  width: auto;
}

/* BRUNI-Naming neben dem Logo */
.brand-bot {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  padding: 0 0 0 18px;
  margin-left: 4px;
  border-left: 1px solid var(--border);
  line-height: 1.1;
  flex-shrink: 0;
}
.brand-bot-name {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: 0.06em;
  color: var(--brunnen-red);
}
.brand-bot-claim {
  font-size: 11px;
  font-weight: 500;
  color: var(--ci-grau);
  letter-spacing: 0.02em;
  text-transform: none;
  margin-top: 2px;
}
@media (max-width: 900px) {
  .brand-bot-claim { display: none; }
}

.nav {
  display: flex; align-items: center; gap: 36px;
  flex: 1;
  justify-content: center;
  font-weight: 600;
  font-size: 15px;
}
.nav a {
  color: var(--ink);
  padding: 4px 0;
  border-bottom: 2px solid transparent;
  transition: border-color 0.15s;
}
.nav a.active { border-bottom-color: var(--brunnen-red-ci); color: var(--brunnen-red-ci); }
.nav a:hover { border-bottom-color: var(--brunnen-red-ci); }

/* Mode-Tabs: Produkt-Chat / Katalog-Chat */
.mode-tab { cursor: pointer; }

/* Katalog-Auswahl-Leiste (sichtbar nur im Katalog-Modus) */
.catalog-bar {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 24px;
  background: #fafbfc;
  border-bottom: 1px solid var(--border);
  font-size: 12px;
}
.catalog-bar-label {
  color: var(--sub, #6b7280);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-size: 11px;
  flex-shrink: 0;
}
.catalog-pills {
  display: flex; flex-wrap: wrap; gap: 6px;
  flex: 1;
}
.catalog-pill {
  border: 1px solid var(--border);
  background: #fff;
  border-radius: 14px;
  padding: 4px 12px;
  font-size: 12px;
  cursor: pointer;
  color: var(--ink);
  transition: all 0.12s;
  user-select: none;
}
.catalog-pill:hover { border-color: var(--brunnen-red-ci); }
.catalog-pill.active {
  background: var(--brunnen-red-ci);
  border-color: var(--brunnen-red-ci);
  color: #ffffff;
}
.catalog-pill .count {
  opacity: 0.7;
  font-size: 10px;
  margin-left: 4px;
}

.mainbar-actions { display: flex; align-items: center; gap: 14px; }
.btn-ghost {
  border: 1px solid var(--ink);
  background: #ffffff;
  padding: 8px 16px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  color: var(--ink);
  border-radius: var(--radius);
  font-family: inherit;
  letter-spacing: 0.02em;
  transition: all 0.12s;
}
.btn-ghost:hover { background: var(--ink); color: #fff; }

/* Sprach-Umschalter ---------- */
.lang-switch {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2px;
  background: #fff;
}
.lang-btn {
  border: none;
  background: transparent;
  padding: 4px 6px;
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  border-radius: 2px;
  filter: grayscale(0.45);
  opacity: 0.75;
  transition: all 0.12s;
  font-family: "Segoe UI Emoji", "Apple Color Emoji", "Noto Color Emoji", sans-serif;
}
.lang-btn:hover { filter: none; opacity: 1; }
.lang-btn.active {
  filter: none;
  opacity: 1;
  background: var(--brunnen-red-ci);
  box-shadow: inset 0 0 0 1px var(--brunnen-red-ci);
}

/* ---------- Layout ---------- */
.layout {
  flex: 1;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 420px;
  min-height: 0;
  background: var(--bg-soft);
}
@media (max-width: 1100px) {
  .layout { grid-template-columns: 1fr; }
  .article-pane { max-height: 55vh; border-left: none !important; border-top: 1px solid var(--border); }
}

.chat-pane {
  display: flex; flex-direction: column;
  overflow: hidden;
  min-height: 0;
  background: #ffffff;
}
.article-pane {
  border-left: 1px solid var(--border);
  background: var(--bg-soft);
  display: flex; flex-direction: column;
  overflow: hidden;
  min-height: 0;
}

/* ---------- Messages ---------- */
.messages {
  flex: 1;
  overflow-y: auto;
  padding: 36px 32px 24px;
  display: flex; flex-direction: column;
  gap: 26px;
  max-width: 780px;
  width: 100%;
  margin: 0 auto;
}

.msg { display: flex; flex-direction: column; gap: 6px; }
.msg-user { align-items: flex-end; }
.msg-assistant { align-items: stretch; }

.msg-role {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--ink-subtle);
}
.msg-user .msg-role { color: var(--brunnen-red-ci); }
.msg-assistant .msg-role { color: var(--ink); }

.msg-body {
  line-height: 1.65;
  white-space: pre-wrap;
  word-wrap: break-word;
  font-size: 15px;
  color: var(--ink);
  /* Defensiv gegen Browser-Default oder User-Stylesheets, die "justify"
     erzwingen koennten (Lesemodus-Extensions, Firefox-Profile mit
     altem Reader-Stylesheet). Wir wollen IMMER linksbuendig. */
  text-align: left !important;
  hyphens: none;
}
.msg-user .msg-body {
  max-width: 78%;
  padding: 12px 16px;
  background: var(--brunnen-red-ci);
  color: #ffffff;
  border-radius: var(--radius);
  font-weight: 500;
}
.msg-assistant .msg-body {
  padding: 0;
  border-left: 3px solid var(--brunnen-red-ci);
  padding-left: 14px;
}

.msg-body ul { margin: 8px 0; padding-left: 22px; }
.msg-body li { margin: 4px 0; }
.msg-body code {
  background: var(--bg-soft);
  padding: 1px 6px;
  border-radius: 2px;
  font-family: var(--font-mono);
  font-size: 0.88em;
}

.msg-meta {
  font-size: 11px;
  color: var(--ink-subtle);
  font-family: var(--font-mono);
  letter-spacing: 0.02em;
  margin-top: 4px;
  padding-left: 14px;
}

/* ---------- Typing ---------- */
.typing { display: inline-flex; gap: 5px; padding: 6px 0; }
.typing span {
  width: 6px; height: 6px;
  background: var(--brunnen-red-ci);
  opacity: 0.5;
  animation: blink 1.2s infinite ease-in-out;
}
.typing span:nth-child(2) { animation-delay: 0.18s; }
.typing span:nth-child(3) { animation-delay: 0.36s; }
@keyframes blink { 0%,80%,100% { opacity: 0.25; } 40% { opacity: 0.95; } }

/* ---------- Composer ---------- */
.composer-wrap {
  padding: 14px 32px 26px;
  max-width: 780px;
  width: 100%;
  margin: 0 auto;
  border-top: 1px solid var(--border);
  background: #ffffff;
}
.composer {
  display: flex; align-items: flex-end; gap: 0;
  background: #ffffff;
  border: 2px solid var(--ink);
  border-radius: var(--radius);
  transition: border-color 0.15s;
}
.composer:focus-within { border-color: var(--brunnen-red-ci); }
.composer textarea {
  flex: 1;
  resize: none;
  padding: 14px 16px;
  border: none;
  font-family: inherit;
  font-size: 15px;
  background: transparent;
  color: var(--ink);
  outline: none;
  min-height: 24px;
  max-height: 200px;
  line-height: 1.5;
}
.composer textarea::placeholder { color: var(--ink-subtle); }
.composer button {
  padding: 0 22px;
  background: var(--brunnen-red-ci);
  color: #ffffff;
  border: none;
  font-weight: 700;
  font-size: 13px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  cursor: pointer;
  border-radius: 0;
  align-self: stretch;
  display: grid; place-items: center;
  min-width: 100px;
  transition: background 0.12s;
}
.composer button:hover { background: var(--brunnen-red-dark); }
.composer button:disabled { background: #bbb; cursor: not-allowed; }

.composer-hint {
  font-size: 11px;
  color: var(--ink-subtle);
  margin-top: 10px;
  letter-spacing: 0.02em;
}

/* ---------- Article pane ---------- */
.article-empty {
  padding: 40px 30px;
}
.empty-title {
  font-weight: 800;
  font-size: 16px;
  margin-bottom: 10px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--ink);
  border-bottom: 2px solid var(--brunnen-red-ci);
  padding-bottom: 8px;
  display: inline-block;
}
.empty-sub {
  font-size: 13px;
  color: var(--ink-muted);
  line-height: 1.6;
  margin-top: 12px;
}

.article-card {
  overflow-y: auto;
  flex: 1;
}
.article-header {
  padding: 26px 30px 20px;
  border-bottom: 1px solid var(--border);
  background: #ffffff;
  position: sticky; top: 0;
  z-index: 1;
}
.article-title {
  font-weight: 800;
  font-size: 22px;
  line-height: 1.25;
  margin: 0 0 10px;
  letter-spacing: -0.01em;
}
.article-mnr {
  font-family: var(--font-mono);
  font-size: 12px;
  color: #ffffff;
  background: var(--brunnen-red-ci);
  padding: 4px 10px;
  display: inline-block;
  letter-spacing: 0.04em;
  font-weight: 600;
  border-radius: var(--radius);
}
.article-section {
  padding: 20px 30px;
  border-bottom: 1px solid var(--border);
  background: #ffffff;
}
.article-section:nth-of-type(even) { background: var(--bg-soft); }
.article-section:last-child { border-bottom: none; }
.section-label {
  text-transform: uppercase;
  font-size: 10px;
  letter-spacing: 0.12em;
  color: var(--brunnen-red-ci);
  font-weight: 800;
  margin-bottom: 14px;
}
.kv {
  display: grid;
  grid-template-columns: 45% 1fr;
  gap: 10px 16px;
  font-size: 13px;
}
.kv dt {
  color: var(--ink-muted);
  font-weight: 500;
  overflow-wrap: anywhere;
  line-height: 1.5;
}
.kv dd {
  margin: 0;
  overflow-wrap: anywhere;
  line-height: 1.5;
  font-weight: 500;
}
.catalog-chunk {
  font-size: 13px;
  line-height: 1.65;
  padding: 14px 16px;
  background: #ffffff;
  border-left: 3px solid var(--brunnen-red-ci);
  margin-bottom: 10px;
  color: var(--ink);
}
.catalog-chunk:last-child { margin-bottom: 0; }

/* ---------- Artikel-Tabs (Sprung zwischen Artikeln) ---------- */
.article-tabs {
  display: none;
  gap: 6px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  background: #ffffff;
  overflow-x: auto;
  scrollbar-width: thin;
  flex-shrink: 0;
}
.article-tabs.has-tabs {
  display: flex;
}
.article-tab {
  appearance: none;
  border: 1px solid var(--border);
  background: #ffffff;
  color: var(--ink-muted);
  padding: 5px 12px;
  font-size: 12px;
  font-family: inherit;
  font-weight: 500;
  cursor: pointer;
  border-radius: var(--radius-pill);
  white-space: nowrap;
  transition: all 0.12s;
  flex-shrink: 0;
}
.article-tab:hover {
  border-color: var(--ink);
  color: var(--ink);
}
.article-tab.active {
  background: var(--brunnen-red-ci);
  border-color: var(--brunnen-red-ci);
  color: #ffffff;
}

/* ---------- „Weitere Felder" als klappbares <details> ---------- */
.article-more {
  padding: 0;
}
.article-more > summary {
  list-style: none;
  cursor: pointer;
  padding: 20px 30px;
  user-select: none;
  position: relative;
}
.article-more > summary::-webkit-details-marker { display: none; }
.article-more > summary::after {
  content: "▸";
  position: absolute;
  right: 30px;
  top: 18px;
  font-size: 14px;
  color: var(--ink-subtle);
  transition: transform 0.15s;
}
.article-more[open] > summary::after { transform: rotate(90deg); }
.article-more[open] > summary { border-bottom: 1px solid var(--border); }
.article-more > .kv {
  padding: 16px 30px 24px;
  background: var(--bg-soft);
}

/* ---------- Chips: Beispiele + Folgefragen ---------- */
.chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}
.chip {
  appearance: none;
  border: 1px solid var(--border);
  background: #ffffff;
  color: var(--ink);
  padding: 8px 14px;
  font-size: 13px;
  font-family: inherit;
  font-weight: 500;
  cursor: pointer;
  border-radius: var(--radius-pill);
  transition: all 0.12s;
  text-align: left;
  line-height: 1.35;
  max-width: 100%;
}
.chip:hover {
  border-color: var(--brunnen-red-ci);
  color: var(--brunnen-red-ci);
  background: #fff5f5;
}
.chip-followup {
  border-style: dashed;
}
.chip-example {
  background: var(--bg-soft);
}

.msg-examples {
  margin-top: -8px;
}
.msg-examples .chip-row { margin-top: 6px; }
.examples-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--ink-subtle);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-top: 4px;
}

/* ---------- Produktbilder im Artikel-Panel ---------- */
.product-images {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
  gap: 8px;
}
.product-image-link {
  display: block;
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: 2px;
  overflow: hidden;
  aspect-ratio: 1 / 1;
  transition: border-color 0.12s, transform 0.12s;
}
.product-image-link:hover {
  border-color: var(--brunnen-red-ci);
  transform: translateY(-1px);
}
.product-image-link img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
  background: #ffffff;
}
.product-images-loading,
.product-images-empty {
  font-size: 13px;
  color: var(--ink-subtle);
  font-style: italic;
}

/* ---------- Scrollbars ---------- */
.messages::-webkit-scrollbar,
.article-card::-webkit-scrollbar { width: 10px; }
.messages::-webkit-scrollbar-track,
.article-card::-webkit-scrollbar-track { background: transparent; }
.messages::-webkit-scrollbar-thumb,
.article-card::-webkit-scrollbar-thumb {
  background: transparent;
  border-radius: 5px;
}
.messages:hover::-webkit-scrollbar-thumb,
.article-card:hover::-webkit-scrollbar-thumb {
  background: #cfcfcf;
}
