/* Berr Chat – gemeinsame Optik für Website-Widget und Mitarbeiter-App.
   Farben kommen aus den Einstellungen: --bchat-primary, --bchat-header, --bchat-button */

.bchat-root {
  --bchat-primary: #0b5ea8;
  --bchat-header: var(--bchat-primary);
  --bchat-button: var(--bchat-primary);
  --bchat-bg: #ffffff;
  --bchat-surface: #f3f5f8;
  --bchat-text: #1d2430;
  --bchat-muted: #6b7484;
  --bchat-border: #dfe3ea;
  --bchat-radius: 14px;
  --bchat-shadow: 0 12px 40px rgba(16, 24, 40, .18);
  --bchat-font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-family: var(--bchat-font);
  font-size: 15px;
  line-height: 1.45;
  color: var(--bchat-text);
  box-sizing: border-box;
}
.bchat-root *, .bchat-root *::before, .bchat-root *::after { box-sizing: inherit; }
.bchat-root svg { width: 22px; height: 22px; display: block; }
.bchat-root button { font: inherit; cursor: pointer; }
.bchat-root [hidden] { display: none !important; }

/* ---------- Bausteine ---------- */

.bchat-header {
  display: flex; align-items: center; gap: 6px;
  padding: 12px 12px 12px 16px;
  background: var(--bchat-header); color: #fff;
}
.bchat-header__title { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.bchat-header__title strong { font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bchat-header__sub { opacity: .85; font-size: 12px; }

.bchat-icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 36px; height: 36px; border: 0; border-radius: 50%;
  background: transparent; color: inherit; text-decoration: none;
}
.bchat-icon-btn:hover, .bchat-icon-btn:focus-visible { background: rgba(255, 255, 255, .18); outline: none; }
.bchat-icon-btn svg { width: 20px; height: 20px; }

.bchat-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 10px 16px; border: 0; border-radius: 10px;
  background: var(--bchat-button); color: #fff; font-weight: 600;
}
.bchat-btn:hover { filter: brightness(1.08); }
.bchat-btn:disabled { opacity: .6; cursor: default; }
.bchat-btn svg { width: 18px; height: 18px; }
.bchat-btn--ghost { background: transparent; color: var(--bchat-button); border: 1px solid currentColor; }
.bchat-btn--inline { align-self: flex-start; margin: 4px 0 8px; font-size: 14px; padding: 8px 14px; }
.bchat-link { border: 0; background: none; color: var(--bchat-primary); text-decoration: underline; padding: 0; font-size: 13px; }

.bchat-banner {
  padding: 8px 16px; font-size: 13px;
  background: color-mix(in srgb, var(--bchat-primary) 12%, var(--bchat-bg));
  color: var(--bchat-text); border-bottom: 1px solid var(--bchat-border);
}

.bchat-badge {
  display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 11px; font-weight: 600;
  background: var(--bchat-surface); color: var(--bchat-muted);
}
.bchat-badge--warn { background: #fff1d6; color: #8a5a00; }
.bchat-badge--count { background: var(--bchat-primary); color: #fff; }
.bchat-muted { color: var(--bchat-muted); font-size: 13px; }

/* Nachrichten */
.bchat-messages {
  flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 4px;
  background: var(--bchat-surface); overscroll-behavior: contain;
}
.bchat-msg { display: flex; flex-direction: column; max-width: 85%; margin-bottom: 6px; }
.bchat-msg--own { align-self: flex-end; align-items: flex-end; }
.bchat-msg--other { align-self: flex-start; }
.bchat-msg--system { align-self: center; max-width: 95%; text-align: center; font-size: 12px; color: var(--bchat-muted); margin: 6px 0; }
.bchat-bubble {
  padding: 9px 13px; border-radius: 16px; background: var(--bchat-bg);
  border: 1px solid var(--bchat-border); word-wrap: break-word; overflow-wrap: anywhere;
}
.bchat-msg--own .bchat-bubble { background: var(--bchat-primary); color: #fff; border-color: transparent; border-bottom-right-radius: 4px; }
.bchat-msg--other .bchat-bubble { border-bottom-left-radius: 4px; }
.bchat-msg--own .bchat-bubble a { color: #fff; }
.bchat-bubble a { color: var(--bchat-primary); }
.bchat-msg--pending { opacity: .6; }
.bchat-msg--cont { margin-top: -2px; }
.bchat-msg:not(.bchat-msg--cont):not(.bchat-msg--system) { margin-top: 8px; }
.bchat-msg__head {
  display: flex; align-items: center; gap: 6px; margin-bottom: 5px; padding: 0 2px;
  font-size: 12px; color: var(--bchat-muted);
}
.bchat-msg__head span:first-of-type { color: var(--bchat-text); font-weight: 600; }
.bchat-dot { opacity: .6; }

/* Themen-Buttons */
.bchat-chips { display: flex; flex-wrap: wrap; gap: 8px; margin: 6px 0 10px; max-width: 95%; }
.bchat-chip {
  display: inline-flex; align-items: center; padding: 8px 14px; border-radius: 10px;
  border: 2px solid var(--bchat-header); background: var(--bchat-bg); color: var(--bchat-text);
  font: inherit; font-size: 14px; font-weight: 600; text-decoration: none; cursor: pointer; line-height: 1.2;
}
.bchat-chip:hover, .bchat-chip:focus-visible { background: var(--bchat-header); color: #fff; outline: none; }
.bchat-dark .bchat-chip { border-color: color-mix(in srgb, var(--bchat-header) 50%, #fff); }

/* Avatar */
.bchat-avatar {
  flex: none; width: 28px; height: 28px; border-radius: 50%; object-fit: cover;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--bchat-bg); border: 1px solid var(--bchat-border);
}
.bchat-avatar--icon { background: var(--bchat-primary); color: #fff; border-color: transparent; }
.bchat-avatar--icon svg { width: 18px !important; height: 18px !important; }
.bchat-avatar--initial { background: var(--bchat-header); color: #fff; font-size: 13px; font-weight: 700; border-color: transparent; }
.bchat-avatar--header { width: 38px; height: 38px; border: 2px solid rgba(255, 255, 255, .7); margin-right: 4px; }
.bchat-avatar--header.bchat-avatar--icon { background: rgba(255, 255, 255, .18); }
.bchat-avatar--header svg { width: 22px !important; height: 22px !important; }

.bchat-typing { display: inline-flex; gap: 4px; padding: 12px 14px; }
.bchat-typing i { width: 7px; height: 7px; border-radius: 50%; background: var(--bchat-muted); animation: bchat-dot 1.2s infinite ease-in-out; }
.bchat-typing i:nth-child(2) { animation-delay: .15s; }
.bchat-typing i:nth-child(3) { animation-delay: .3s; }
@keyframes bchat-dot { 0%, 80%, 100% { opacity: .3; transform: translateY(0); } 40% { opacity: 1; transform: translateY(-3px); } }

/* Eingabe */
.bchat-composer {
  display: flex; align-items: flex-end; gap: 8px; padding: 10px 12px;
  border-top: 1px solid var(--bchat-border); background: var(--bchat-bg);
}
.bchat-composer textarea {
  flex: 1; resize: none; border: 1px solid var(--bchat-border); border-radius: 12px;
  padding: 9px 12px; font: inherit; font-size: 16px; /* 16px verhindert Zoom auf iOS */
  max-height: 120px; color: var(--bchat-text); background: var(--bchat-bg);
}
.bchat-composer textarea:focus { outline: 2px solid color-mix(in srgb, var(--bchat-primary) 40%, transparent); border-color: var(--bchat-primary); }
.bchat-send {
  flex: none; width: 42px; height: 42px; border: 0; border-radius: 50%;
  background: var(--bchat-button); color: #fff; display: inline-flex; align-items: center; justify-content: center;
}
.bchat-send svg { width: 20px; height: 20px; }
.bchat-composer.is-busy .bchat-send { opacity: .5; pointer-events: none; }
.bchat-composer.is-disabled { opacity: .5; pointer-events: none; }

/* Overlay-Karten (Einwilligung, Formulare) */
.bchat-body { position: relative; flex: 1; display: flex; flex-direction: column; min-height: 0; }
.bchat-overlay {
  position: absolute; inset: 0; background: color-mix(in srgb, var(--bchat-surface) 96%, transparent);
  display: flex; align-items: center; justify-content: center; padding: 16px; overflow-y: auto;
}
.bchat-card {
  position: relative; width: 100%; background: var(--bchat-bg); border-radius: var(--bchat-radius);
  padding: 20px; box-shadow: 0 4px 16px rgba(16, 24, 40, .08); display: flex; flex-direction: column; gap: 10px;
}
.bchat-card h3 { margin: 0; font-size: 17px; }
.bchat-card p { margin: 0; font-size: 14px; color: var(--bchat-muted); }
.bchat-card a { color: var(--bchat-primary); }
.bchat-card label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; font-weight: 600; }
.bchat-card label small { font-weight: 400; color: var(--bchat-muted); }
.bchat-card input, .bchat-card textarea {
  background: var(--bchat-bg); color: var(--bchat-text);
  font: inherit; font-size: 16px; padding: 9px 11px; border: 1px solid var(--bchat-border); border-radius: 10px; font-weight: 400;
}
.bchat-card__close { position: absolute; top: 8px; right: 8px; border: 0; background: none; color: var(--bchat-muted); width: 32px; height: 32px; }
.bchat-card__close svg { width: 18px; height: 18px; margin: auto; }
.bchat-error { color: #b42318 !important; }

/* ---------- Website-Widget ---------- */

.bchat-widget { position: fixed; bottom: 20px; z-index: 2147483000; }
.bchat-pos-right { right: 20px; }
.bchat-pos-left { left: 20px; }

.bchat-launcher {
  width: 60px; height: 60px; border-radius: 50%; border: 0;
  background: var(--bchat-button); color: #fff; box-shadow: var(--bchat-shadow);
  display: flex; align-items: center; justify-content: center; position: relative;
  transition: transform .15s ease;
}
.bchat-launcher:hover { transform: scale(1.06); }
.bchat-launcher svg { width: 28px; height: 28px; }
.bchat-launcher.has-unread::after {
  content: ""; position: absolute; top: 4px; right: 4px; width: 14px; height: 14px;
  border-radius: 50%; background: #e5484d; border: 2px solid #fff;
}
.bchat-widget .bchat-panel {
  position: absolute; bottom: 76px; width: 380px; height: min(620px, calc(100vh - 120px));
  background: var(--bchat-bg); border-radius: var(--bchat-radius); box-shadow: var(--bchat-shadow);
  display: flex; flex-direction: column; overflow: hidden;
  animation: bchat-in .18s ease-out;
}
.bchat-pos-right .bchat-panel { right: 0; }
.bchat-pos-left .bchat-panel { left: 0; }
@keyframes bchat-in { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }

@media (max-width: 480px) {
  .bchat-widget { bottom: 14px; }
  .bchat-pos-right { right: 14px; }
  .bchat-pos-left { left: 14px; }
  .bchat-widget .bchat-panel {
    position: fixed; inset: 0; width: 100%; height: 100%; height: 100dvh; border-radius: 0; bottom: 0;
    padding-bottom: env(safe-area-inset-bottom);
  }
  .bchat-widget.is-open .bchat-launcher { display: none; }
}

/* ---------- Mitarbeiter-App ---------- */

.bchat-agent-body { margin: 0; background: #e9edf2; }
.bchat-app { display: flex; flex-direction: column; height: 100vh; height: 100dvh; background: var(--bchat-bg); }
.bchat-app__header { padding-top: calc(12px + env(safe-area-inset-top)); }
.bchat-switch { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; padding: 0 8px; cursor: pointer; }
.bchat-switch input { width: 18px; height: 18px; accent-color: #34c759; }
.bchat-app.is-offline .bchat-app__header { filter: grayscale(.7); }

.bchat-app__main { flex: 1; display: flex; min-height: 0; }
.bchat-app__list { width: 320px; border-right: 1px solid var(--bchat-border); overflow-y: auto; background: var(--bchat-bg); }
.bchat-app__listhead { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 12px 16px; font-size: 13px; color: var(--bchat-muted); border-bottom: 1px solid var(--bchat-border); }
.bchat-app__list ul { list-style: none; margin: 0; padding: 0; }
.bchat-session { padding: 12px 16px; border-bottom: 1px solid var(--bchat-border); cursor: pointer; }
.bchat-session:hover { background: var(--bchat-surface); }
.bchat-session.is-active { background: color-mix(in srgb, var(--bchat-primary) 14%, var(--bchat-bg)); }
.bchat-session.is-waiting { border-left: 4px solid #f5a524; }
.bchat-session__top { display: flex; align-items: center; gap: 6px; }
.bchat-session__top strong { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bchat-session__preview { font-size: 13px; color: var(--bchat-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 2px; }
.bchat-session__time { font-size: 11px; color: var(--bchat-muted); margin-top: 2px; }

.bchat-app__chat { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.bchat-app__empty { margin: auto; color: var(--bchat-muted); }
.bchat-app__conv { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.bchat-app__info { padding: 10px 16px; border-bottom: 1px solid var(--bchat-border); font-size: 13px; }
.bchat-app__info a { color: var(--bchat-primary); }
.bchat-app__actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; padding: 8px 12px; border-top: 1px solid var(--bchat-border); }
.bchat-app__actions:empty { display: none; }
.bchat-app__actions .bchat-btn { padding: 8px 14px; font-size: 14px; }
.bchat-app .bchat-composer { padding-bottom: calc(10px + env(safe-area-inset-bottom)); }

@media (max-width: 760px) {
  .bchat-app__list { width: 100%; border-right: 0; }
  .bchat-app__chat { display: none; }
  .bchat-app.is-chat-open .bchat-app__list { display: none; }
  .bchat-app.is-chat-open .bchat-app__chat { display: flex; }
  .bchat-switch span { display: none; }
}
@media (min-width: 761px) { .bchat-back { display: none !important; } }

/* ---------- Nachtansicht ---------- */
.bchat-root.bchat-dark {
  --bchat-bg: #1a1f29;
  --bchat-surface: #10141b;
  --bchat-text: #e7eaf0;
  --bchat-muted: #98a1b1;
  --bchat-border: #2c3442;
  --bchat-shadow: 0 12px 40px rgba(0, 0, 0, .55);
  color-scheme: dark;
}
.bchat-dark .bchat-bubble a { color: color-mix(in srgb, var(--bchat-primary) 55%, #fff); }
.bchat-dark .bchat-msg--own .bchat-bubble a { color: #fff; }
.bchat-dark .bchat-badge--warn { background: #4a3500; color: #ffd27a; }
.bchat-dark .bchat-link, .bchat-dark .bchat-card a, .bchat-dark .bchat-app__info a { color: color-mix(in srgb, var(--bchat-primary) 55%, #fff); }
.bchat-dark .bchat-btn--ghost { color: color-mix(in srgb, var(--bchat-button) 55%, #fff); }
.bchat-dark .bchat-launcher.has-unread::after { border-color: var(--bchat-bg); }
.bchat-agent-body:has(.bchat-dark) { background: #10141b; }
