/* ─────────────────────────────────────────────────────────────────────────
   Herbert Chat-Widget — Floating Button + Panel
   Global auf allen Chapter-Site-Seiten via layout.php eingebunden.
   Namespace: alles unter #herbert-root, damit nichts kollidiert.
   ─────────────────────────────────────────────────────────────────────── */

#herbert-root {
  --hb-brand:      #cf102e;
  --hb-brand-dark: #a80c26;
  --hb-gold:       #f5b800;
  --hb-bg:         #ffffff;
  --hb-body:       #f7f7f8;
  --hb-text:       #111827;
  --hb-text-mute:  #6b7280;
  --hb-border:     #e5e7eb;
  --hb-shadow-lg:  0 22px 60px -12px rgba(0,0,0,.28);
  --hb-shadow-md:  0 10px 28px -6px rgba(0,0,0,.22);
  --hb-radius:     18px;
  --hb-radius-sm:  12px;
  --hb-radius-msg: 16px;

  position: fixed;
  right: 24px; bottom: 24px;
  z-index: 999;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  color: var(--hb-text);
}

/* ── Trigger (Floating Button + Hint-Chip) ────────────────────────────── */

#herbert-root .hb-trigger {
  display: flex; align-items: center;
  background: var(--hb-bg);
  border: 1px solid var(--hb-border);
  border-radius: 999px;
  padding: 4px 14px 4px 4px;
  box-shadow: var(--hb-shadow-md);
  cursor: pointer;
  transition: transform .18s ease, box-shadow .18s ease;
  gap: 10px;
}
#herbert-root .hb-trigger:hover {
  transform: translateY(-2px);
  box-shadow: var(--hb-shadow-lg);
}
#herbert-root .hb-trigger.is-hidden { display: none; }

#herbert-root .hb-avatar {
  width: 42px; height: 42px;
  border-radius: 50%;
  background:
    url('/assets/img/ki-herbert.png') center center / cover no-repeat,
    linear-gradient(135deg, var(--hb-brand) 0%, var(--hb-brand-dark) 100%);
  flex-shrink: 0;
  position: relative;
}
#herbert-root .hb-avatar::after {
  content: '';
  position: absolute;
  right: 1px; bottom: 1px;
  width: 10px; height: 10px;
  background: #16a34a;
  border: 2px solid #fff;
  border-radius: 50%;
}
#herbert-root .hb-trigger-label {
  font-size: 14px; font-weight: 600;
  color: var(--hb-text);
  white-space: nowrap;
}
#herbert-root .hb-trigger-sub {
  font-size: 11px; color: var(--hb-text-mute);
  white-space: nowrap;
}

/* ── Panel ──────────────────────────────────────────────────────────── */

#herbert-root .hb-panel {
  position: absolute;
  right: 0; bottom: 60px;
  width: 380px; height: 560px;
  max-width: calc(100vw - 32px);
  max-height: calc(100vh - 100px);
  background: var(--hb-bg);
  border-radius: var(--hb-radius);
  box-shadow: var(--hb-shadow-lg);
  display: flex; flex-direction: column;
  overflow: hidden;
  transform-origin: bottom right;
  animation: hbIn .22s cubic-bezier(.2,.9,.3,1.2);
}
#herbert-root .hb-panel.is-hidden { display: none; }

@keyframes hbIn {
  from { opacity: 0; transform: translateY(10px) scale(.96); }
  to   { opacity: 1; transform: translateY(0)   scale(1);    }
}

/* ── Panel-Header ───────────────────────────────────────────────────── */

#herbert-root .hb-head {
  display: flex; align-items: center; gap: 12px;
  background: #1f2937;
  color: #fff;
  padding: 14px 16px;
}
#herbert-root .hb-head .hb-avatar {
  width: 38px; height: 38px;
}
#herbert-root .hb-head-text { flex: 1; min-width: 0; }
#herbert-root .hb-head-name { font-weight: 600; font-size: 14px; letter-spacing: -0.01em; }
#herbert-root .hb-head-sub  { font-size: 11px; color: #9ca3af; margin-top: 1px; }
#herbert-root .hb-head-sub .hb-dot {
  display: inline-block; width: 7px; height: 7px; border-radius: 50%;
  background: #16a34a; margin-right: 5px; vertical-align: middle;
}
#herbert-root .hb-close {
  background: transparent; border: none; color: #d1d5db;
  width: 30px; height: 30px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; padding: 0;
}
#herbert-root .hb-close:hover { background: rgba(255,255,255,.10); color: #fff; }
#herbert-root .hb-close svg { width: 16px; height: 16px; }

/* ── Message-Bereich ────────────────────────────────────────────────── */

#herbert-root .hb-body {
  flex: 1; overflow-y: auto;
  padding: 16px 14px;
  background: var(--hb-body);
  display: flex; flex-direction: column; gap: 10px;
  scrollbar-width: thin;
}
#herbert-root .hb-body::-webkit-scrollbar { width: 6px; }
#herbert-root .hb-body::-webkit-scrollbar-thumb { background: #d1d5db; border-radius: 3px; }

#herbert-root .hb-msg {
  display: flex; flex-direction: column;
  max-width: 88%;
  animation: hbMsgIn .18s ease;
}
@keyframes hbMsgIn {
  from { opacity: 0; transform: translateY(4px); }
  to   { opacity: 1; transform: translateY(0);   }
}
#herbert-root .hb-msg-bubble {
  padding: 9px 13px;
  border-radius: var(--hb-radius-msg);
  font-size: 13.5px; line-height: 1.5;
  white-space: pre-wrap;
  word-wrap: break-word;
  overflow-wrap: anywhere;
}
#herbert-root .hb-msg.hb-user {
  align-self: flex-end; align-items: flex-end;
}
#herbert-root .hb-msg.hb-user .hb-msg-bubble {
  background: var(--hb-brand);
  color: #fff;
  border-bottom-right-radius: 4px;
}
#herbert-root .hb-msg.hb-bot {
  align-self: flex-start; align-items: flex-start;
}
#herbert-root .hb-msg.hb-bot .hb-msg-bubble {
  background: #fff;
  color: var(--hb-text);
  border: 1px solid var(--hb-border);
  border-bottom-left-radius: 4px;
}
#herbert-root .hb-msg-bubble a {
  color: inherit; text-decoration: underline;
}

/* Quellen-Chips unter Bot-Antworten */
#herbert-root .hb-sources {
  margin-top: 6px;
  display: flex; flex-wrap: wrap; gap: 5px;
  align-items: center;
  max-width: 100%;
}
#herbert-root .hb-sources-label {
  font-size: 10.5px;
  color: var(--hb-text-mute);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-weight: 600;
  width: 100%;
  margin-bottom: 2px;
}
#herbert-root .hb-source-chip {
  display: inline-flex; align-items: center;
  gap: 5px;
  padding: 4px 10px 4px 8px;
  background: #fff;
  border: 1px solid var(--hb-border);
  border-radius: 12px;
  font-size: 11.5px; line-height: 1.3;
  color: var(--hb-text);
  text-decoration: none;
  max-width: 100%;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  transition: background .15s, border-color .15s;
}
#herbert-root .hb-source-chip:hover {
  background: var(--hb-brand);
  color: #fff;
  border-color: var(--hb-brand);
}
#herbert-root .hb-source-chip::before {
  content: '📄';
  font-size: 10px;
  flex-shrink: 0;
}

#herbert-root .hb-typing {
  align-self: flex-start;
  background: #fff;
  border: 1px solid var(--hb-border);
  border-radius: var(--hb-radius-msg);
  border-bottom-left-radius: 4px;
  padding: 12px 14px;
  display: inline-flex; gap: 4px;
}
#herbert-root .hb-typing span {
  width: 6px; height: 6px; border-radius: 50%;
  background: #9ca3af;
  animation: hbTyping 1.2s infinite ease-in-out;
}
#herbert-root .hb-typing span:nth-child(2) { animation-delay: .15s; }
#herbert-root .hb-typing span:nth-child(3) { animation-delay: .30s; }
@keyframes hbTyping {
  0%,60%,100% { opacity: .35; transform: translateY(0);   }
  30%         { opacity: 1;   transform: translateY(-3px); }
}

#herbert-root .hb-notice {
  align-self: center;
  background: #fef3c7;
  border: 1px solid #fde68a;
  color: #78350f;
  font-size: 12px;
  padding: 8px 12px;
  border-radius: 10px;
  max-width: 92%;
  text-align: center;
}

/* ── Input-Bereich ──────────────────────────────────────────────────── */

#herbert-root .hb-foot {
  padding: 10px 12px 12px;
  border-top: 1px solid var(--hb-border);
  background: #fff;
}
#herbert-root .hb-form {
  display: flex; align-items: flex-end; gap: 8px;
  background: #f3f4f6;
  border: 1.5px solid transparent;
  border-radius: 22px;
  padding: 6px 6px 6px 14px;
  transition: border-color .15s;
}
#herbert-root .hb-form:focus-within {
  border-color: var(--hb-brand);
  background: #fff;
}
#herbert-root .hb-input {
  flex: 1; border: 0; background: transparent;
  resize: none; outline: none;
  font: 400 13.5px/1.5 'Inter', sans-serif;
  color: var(--hb-text);
  max-height: 120px; min-height: 22px;
  padding: 6px 0;
}
#herbert-root .hb-send {
  width: 34px; height: 34px;
  border: none; border-radius: 50%;
  background: var(--hb-brand); color: #fff;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: background .15s, transform .1s;
}
#herbert-root .hb-send:hover:not(:disabled) { background: var(--hb-brand-dark); }
#herbert-root .hb-send:active:not(:disabled) { transform: scale(.94); }
#herbert-root .hb-send:disabled {
  background: #d1d5db; cursor: not-allowed;
}
#herbert-root .hb-send svg { width: 15px; height: 15px; }

#herbert-root .hb-legal {
  font-size: 10.5px; color: var(--hb-text-mute);
  text-align: center;
  margin-top: 6px;
}

/* ── Mobile ─────────────────────────────────────────────────────────── */

@media (max-width: 480px) {
  #herbert-root {
    right: 12px; bottom: 12px;
  }
  #herbert-root .hb-panel {
    width: calc(100vw - 24px);
    height: min(600px, calc(100vh - 80px));
  }
  #herbert-root .hb-trigger-sub { display: none; }
}
