/* TB-Concierge */
/* FAB: viewport-fixed unten rechts. Auf Mobile + Desktop gleich.
   Historie: am 2026-05-05 wurde der FAB auf position:absolute umgebaut
   ("erst sichtbar wenn User zum Footer scrollt"), aber das hat den
   Use-Case "schnell Concierge oeffnen waehrend man irgendwo auf der Seite
   ist" kaputtgemacht. 2026-05-07: zurueck auf fixed.
   Auf der Kontakt-Page (markiert via .tb-pg--kontakt) raus, damit der
   Bottom-Bereich nicht ueberladen wird. */
body:has(.tb-pg--kontakt) #tb-concierge-fab { display: none; }
#tb-concierge-fab {
  position: fixed;
  right: 1rem;
  bottom: 1rem;
  width: 44px; height: 44px;          /* gleich hoch wie Feedback-FAB */
  border-radius: 50%;
  border: none;
  background: var(--tb-primary-700, #1919C8);
  color: #fff;
  font-size: 1.25rem;
  cursor: pointer;
  z-index: 30;
  box-shadow: 0 4px 14px rgba(25,25,200,0.30);
  transition: transform 200ms cubic-bezier(.34,1.16,.64,1);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
#tb-concierge-fab:hover { transform: translateY(-2px) scale(1.04); }
#tb-concierge-fab:focus-visible { outline: 2px solid var(--tb-accent-cyan, #22D3EE); outline-offset: 3px; }

#tb-concierge-panel {
  position: fixed;
  right: 1rem; bottom: 5rem;
  width: min(380px, calc(100vw - 2rem));
  height: min(560px, 78vh);
  background: var(--tb-bg-card, #fff);
  border: 1px solid var(--tb-line, #E7E7F2);
  border-radius: var(--radius-lg, 12px);
  box-shadow: 0 24px 60px rgba(0,0,0,0.18);
  display: flex; flex-direction: column;
  z-index: 8400;
  overflow: hidden;
  animation: tbconc-in 250ms cubic-bezier(.34,1.16,.64,1) both;
}
#tb-concierge-panel[hidden] { display: none; }
/* Wenn Butler-Panel offen ist, Concierge nach links versetzen */
:where(html:has(#tb-butler-panel:not([hidden]))) #tb-concierge-panel {
  right: calc(min(360px, calc(100vw - 2rem)) + 2rem);
}
@keyframes tbconc-in {
  from { opacity: 0; transform: translateY(10px) scale(.98); }
  to   { opacity: 1; transform: none; }
}

.tb-conc-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: .75rem 1rem;
  border-bottom: 1px solid var(--tb-line);
  background: linear-gradient(180deg, var(--tb-primary-50) 0%, transparent 100%);
}
.tb-conc-head h2 { margin: 0; font-size: 1rem; font-family: Geist, Inter, sans-serif; }
.tb-conc-head button {
  background: none; border: none; cursor: pointer; font-size: 1.1rem; color: var(--tb-ink-700);
}

.tb-conc-body {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  display: flex; flex-direction: column; gap: .75rem;
}
.tb-conc-msg {
  margin: 0; padding: .65rem .9rem;
  border-radius: 16px;
  max-width: 86%;
  line-height: 1.5;
  font-size: .95rem;
  white-space: pre-wrap;
}
.tb-conc-bot { background: var(--tb-primary-50); color: var(--tb-ink-900); border-bottom-left-radius: 4px; align-self: flex-start; }
.tb-conc-user { background: var(--tb-primary-700); color: #fff; border-bottom-right-radius: 4px; align-self: flex-end; }

.tb-conc-sources {
  display: flex; flex-wrap: wrap; gap: .35rem;
  margin-top: .35rem;
}
.tb-conc-sources a {
  font-size: .75rem;
  background: #fff;
  border: 1px solid var(--tb-line);
  padding: .15rem .55rem;
  border-radius: var(--radius-pill);
  color: var(--tb-primary-700);
  text-decoration: none;
}

.tb-conc-form {
  display: flex; gap: .5rem;
  padding: .75rem;
  /* Mehr Platz oben fuer den absoluten Counter (kein Layout-Shift) */
  padding-top: 1.4rem;
  border-top: 1px solid var(--tb-line);
  background: var(--tb-bg);
  align-items: center;
  position: relative;       /* Anker fuer absoluten Counter */
}
.tb-conc-counter {
  /* Position absolute oben rechts im Form, kein CLS, kein Reflow */
  position: absolute;
  top: 4px;
  right: .75rem;
  font-size: 0.7rem;
  color: var(--tb-ink-500, #6B7280);
  margin: 0;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  pointer-events: none;     /* Klicks gehen durch zum Form */
  transition: opacity 0.15s ease, color 0.15s ease;
}
.tb-conc-counter[hidden] { display: none; }
.tb-conc-counter.is-warning  { color: #d97706; }
.tb-conc-counter.is-critical { color: #c00; font-weight: 600; }

/* Regenerate-Button neben generierten Bildern */
.tb-conc-regen {
  display: inline-block;
  margin: .25rem 0 0 0;
  padding: .25rem .55rem;
  font-size: .72rem;
  border: 1px solid var(--tb-line, #d4d4e3);
  border-radius: 999px;
  background: #fff;
  color: var(--tb-ink-700, #374151);
  cursor: pointer;
}
.tb-conc-regen:hover {
  background: var(--tb-line, #d4d4e3);
  color: var(--tb-primary-700, #1919C8);
}
.tb-conc-regen:disabled { opacity: .55; cursor: wait; }
.tb-conc-form input[type=text] {
  flex: 1 1 0;
  /* min-width:0 verhindert dass der Input seine intrinsische Breite haelt
     (Default = auto = Inhaltsbreite) und damit den Send-Button rausschiebt
     wenn Mic-Button daneben ist. */
  min-width: 0;
  padding: .6rem .75rem;
  border: 1px solid var(--tb-line);
  border-radius: var(--radius-md);
  background: #fff;
  font: inherit;
  color: var(--tb-ink-900);
}
/* Send-Button darf nicht schrumpfen, sonst schluckt er Buchstaben */
.tb-conc-form .tb-btn { flex-shrink: 0; }
.tb-conc-form input[type=text]:focus {
  outline: 2px solid var(--tb-primary-500);
  outline-offset: 1px;
  border-color: var(--tb-primary-500);
}

/* ── Sims-Style-Loading: Progress-Bar + rotierender Status-Text ─────
   Aktiviert beim Senden, ersetzt das fruehere 3-Punkte-Typing-Indikator.
   Fuellt sich asymptotisch auf 95% ueber ~2 Min, bei Antwort kurz auf 100%
   und fade-out. */
.tb-conc-loading {
  align-self: stretch;
  padding: .65rem .9rem;
  background: var(--tb-primary-50);
  border: 1px solid color-mix(in srgb, var(--tb-primary-500) 20%, transparent);
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  gap: .5rem;
  transition: opacity 250ms ease, transform 250ms ease;
}
.tb-conc-loading.is-done {
  opacity: 0;
  transform: translateY(-2px);
}
/* Wake-up-Modus: warmerer Ton (Sonnenaufgang-Anmutung) statt Standard-Blau,
   damit der User visuell merkt "hier passiert Cold-Start, dauert laenger". */
.tb-conc-loading.is-wakeup {
  background: color-mix(in srgb, #fef3c7 60%, var(--tb-primary-50) 40%);
  border-color: color-mix(in srgb, #d4a017 35%, transparent);
}
.tb-conc-loading.is-wakeup .tb-conc-loading-fill {
  background-image: linear-gradient(90deg,
    transparent 0%,
    rgba(255,255,255,0.45) 50%,
    transparent 100%
  ), linear-gradient(90deg,
    #d4a017 0%,
    color-mix(in srgb, #d4a017 70%, var(--tb-accent-cyan, #18C6E6) 30%) 100%);
}
.tb-conc-loading.is-wakeup .tb-conc-loading-status::after {
  background: #d4a017;
}
.tb-conc-loading-bar {
  position: relative;
  height: 6px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--tb-primary-500) 12%, transparent);
  overflow: hidden;
}
.tb-conc-loading-fill {
  position: absolute;
  top: 0; left: 0; bottom: 0;
  width: 0%;
  background: linear-gradient(90deg,
    var(--tb-primary-500) 0%,
    color-mix(in srgb, var(--tb-primary-500) 70%, var(--tb-accent-cyan, #18C6E6) 30%) 100%);
  border-radius: 999px;
  transition: width 350ms ease-out;
  /* Sanftes Shimmer-Overlay damit der User sieht: ja, das lebt */
  background-image: linear-gradient(90deg,
    transparent 0%,
    rgba(255,255,255,0.35) 50%,
    transparent 100%
  ), linear-gradient(90deg,
    var(--tb-primary-500) 0%,
    color-mix(in srgb, var(--tb-primary-500) 70%, var(--tb-accent-cyan, #18C6E6) 30%) 100%);
  background-size: 80px 100%, 100% 100%;
  background-repeat: no-repeat, no-repeat;
  background-position: -80px 0, 0 0;
  animation: tbconc-shimmer 1.4s linear infinite;
}
@keyframes tbconc-shimmer {
  0%   { background-position: -80px 0, 0 0; }
  100% { background-position: 120% 0, 0 0; }
}
.tb-conc-loading-status {
  font-size: .82rem;
  color: var(--tb-ink-700, #374151);
  font-style: italic;
  min-height: 1.2em;
  transition: opacity 220ms ease;
  /* Kleines Zucker-Detail: Cursor-Blink-Glyph hinter dem Status-Text */
  position: relative;
}
.tb-conc-loading-status::after {
  content: '';
  display: inline-block;
  width: 4px;
  height: 0.9em;
  margin-left: 4px;
  background: var(--tb-primary-500);
  vertical-align: -2px;
  animation: tbconc-cursor 1s steps(2) infinite;
  border-radius: 1px;
}
@keyframes tbconc-cursor {
  0%, 100% { opacity: 0; }
  50%      { opacity: 1; }
}

@media (prefers-reduced-motion: reduce) {
  #tb-concierge-panel { animation: none; }
  .tb-conc-loading-fill { animation: none; background-image: none; background: var(--tb-primary-500); }
  .tb-conc-loading-status::after { animation: none; opacity: .5; }
}

@media (max-width: 480px) {
  #tb-concierge-panel { right: .5rem; left: .5rem; width: auto; bottom: 4.5rem; }
}

/* Markdown-Rendering im Bot-Bubble (Concierge gibt strukturierte Antworten) */
.tb-conc-bot p { margin: 0 0 .55em; }
.tb-conc-bot p:last-child { margin-bottom: 0; }
.tb-conc-bot ul,
.tb-conc-bot ol {
  margin: .35em 0 .65em;
  padding-left: 1.4em;
}
.tb-conc-bot li { margin-bottom: .15em; }
.tb-conc-bot h2,
.tb-conc-bot h3,
.tb-conc-bot h4 {
  margin: .85em 0 .35em;
  font-size: 1em;
  font-weight: 700;
  letter-spacing: -0.005em;
}
.tb-conc-bot h2:first-child,
.tb-conc-bot h3:first-child,
.tb-conc-bot h4:first-child { margin-top: 0; }
.tb-conc-bot h2 { font-size: 1.05em; }
.tb-conc-bot h3 { font-size: 1em; }
.tb-conc-bot strong { font-weight: 700; }
.tb-conc-bot em { font-style: italic; }
.tb-conc-bot code {
  background: rgba(0,0,0,0.06);
  padding: 1px 6px;
  border-radius: 4px;
  font-family: ui-monospace, "SF Mono", Monaco, monospace;
  font-size: 0.92em;
}
.tb-conc-bot a {
  color: var(--tb-primary-600, #1919C8);
  text-decoration: underline;
  text-underline-offset: 2px;
  text-decoration-thickness: 1px;
}
.tb-conc-bot a:hover { text-decoration-thickness: 2px; }

/* Mode-Toggle (Lokal/Cloud) im Concierge-Form */
.tb-conc-mode {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  margin-top: .6rem;
  padding: 5px 12px 5px 8px;
  background: rgba(0,0,0,0.04);
  border: 1px solid rgba(0,0,0,0.08);
  border-radius: 999px;
  font-size: 12px;
}
.tb-conc-mode__lab {
  font-weight: 700;
  color: var(--tb-ink-500, #5b5b78);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  font-size: 10.5px;
}
.tb-conc-mode label {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 999px;
  transition: background .15s ease;
}
.tb-conc-mode label:hover { background: rgba(0,0,0,0.04); }
.tb-conc-mode input { margin: 0; }

/* Meta-Pill nach jeder Bot-Antwort */
.tb-conc-meta {
  display: inline-block;
  margin-top: .35rem;
  padding: 2px 9px;
  border-radius: 999px;
  font-weight: 600;
  font-size: 11px;
  font-feature-settings: "tnum";
  align-self: flex-start;
}
.tb-conc-meta--local {
  background: rgba(22, 163, 74, 0.10);
  color: #15803d;
}
.tb-conc-meta--cloud {
  background: rgba(194,146,46, 0.12);
  color: #C2922E;
}

/* Generierte Bilder im Chat (vom [image:...]-Tag, fal.ai) */
.tb-conc-msg img.tb-md-img {
  display: block;
  max-width: 100%;
  height: auto;
  margin: 0.5rem 0;
  border-radius: 8px;
  border: 1px solid var(--tb-line, #E7E7F2);
  background: #fff;
  /* 128x128 wirken minimal, aber wir lassen sie Original-Groesse + responsive */
  image-rendering: auto;
}

/* Zitate hochgestellt: kompakte Ziffer ohne Klammer-Roh-Text. */
.tb-conc-cite {
    display: inline-block;
    margin: 0 .15em 0 .1em;
    font-size: .75em;
    line-height: 1;
    color: #C2922E;
    background: #FBF4E6;
    border-radius: 6px;
    padding: .1em .35em;
    vertical-align: super;
}
.tb-conc-cite a {
    color: inherit;
    text-decoration: none;
}
.tb-conc-cite:hover { background: #FBF4E6; }
