/* ==========================================================================
   BILGE – Chat-Assistent (gehört zu js/bilge.js)
   --------------------------------------------------------------------------
   1. Launcher: goldener runder Button unten rechts mit BILGE-Gesicht + Label
   2. Begrüßungs-Sprechblase
   3. Chatfenster: Kopf, Verlauf, Vorschläge, Eingabe
   4. Animationen (Augen blinzeln, Antenne pulsiert)
   5. Handy: Chat im Vollbild
   ========================================================================== */

.bilge {
  --bilge-gold: linear-gradient(135deg, #e9d5a6 0%, #cfae6f 55%, #b08f52 100%);
  position: fixed;
  right: 1rem;
  bottom: 1rem;
  z-index: 65; /* über dem Cookie-Hinweis (60), unter Menüs nicht nötig */
  font-family: var(--font-body);
}

/* 1. Launcher ------------------------------------------------------------- */

.bilge-launcher {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  padding: 0;
  border: 0;
  background: none;
  cursor: pointer;
}

/* Label "BILGE · KI-Chat" links neben dem Button */
.bilge-launcher-label {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  padding: 0.45rem 0.85rem;
  border: 1px solid rgb(207 174 111 / 0.35);
  border-radius: 12px;
  background: rgb(13 21 38 / 0.85);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  color: var(--paper);
  font: 700 0.9rem/1.1 var(--font-display);
  letter-spacing: 0.08em;
  box-shadow: 0 10px 24px -10px rgb(0 0 0 / 0.6);
  transition:
    opacity 0.3s,
    transform 0.3s;
}
.bilge-launcher-label small {
  color: var(--gold);
  font: 500 0.66rem var(--font-mono);
  letter-spacing: 0.06em;
}

/* runder goldener "Orb" mit Gesicht */
.bilge-orb {
  position: relative;
  display: grid;
  place-items: center;
  width: 62px;
  height: 62px;
  border-radius: 50%;
  background: var(--bilge-gold);
  color: #0d1526;
  box-shadow:
    0 14px 30px -10px rgb(207 174 111 / 0.7),
    inset 0 2px 0 rgb(255 255 255 / 0.35);
  transition: transform 0.25s ease;
}
/* leuchtender Ring, der langsam "atmet" */
.bilge-orb::before {
  content: "";
  position: absolute;
  inset: -6px;
  border-radius: 50%;
  border: 2px solid rgb(207 174 111 / 0.5);
  animation: bilge-breathe 2.8s ease-in-out infinite;
}
.bilge-launcher:hover .bilge-orb,
.bilge-launcher:focus-visible .bilge-orb {
  transform: scale(1.07) rotate(-6deg);
}
/* Avatar-Bild füllt den Orb, der goldene Hintergrund wirkt als Ring */
.bilge-face {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: 50%;
  object-fit: cover;
}
.bilge-orb {
  padding: 3px;
}

/* grüner "online"-Punkt */
.bilge-online {
  position: absolute;
  top: 3px;
  right: 3px;
  width: 13px;
  height: 13px;
  border-radius: 50%;
  background: var(--signal);
  border: 2px solid #0d1526;
}

/* geöffnet: Label ausblenden, Orb zeigt dasselbe Gesicht */
.bilge.is-open .bilge-launcher-label {
  opacity: 0;
  transform: translateX(10px);
  pointer-events: none;
}

/* 2. Begrüßungs-Sprechblase ---------------------------------------------- */

.bilge-teaser {
  position: absolute;
  right: 0;
  bottom: 78px;
  width: 250px;
  padding: 0.85rem 2rem 0.85rem 1rem;
  border: 1px solid rgb(207 174 111 / 0.35);
  border-radius: 16px 16px 4px 16px;
  background: var(--panel);
  color: var(--paper);
  font-size: 0.86rem;
  line-height: 1.45;
  box-shadow: 0 18px 40px -14px rgb(0 0 0 / 0.7);
  cursor: pointer;
  animation: bilge-pop 0.45s cubic-bezier(0.2, 0.9, 0.3, 1.3);
}
.bilge-teaser[hidden] {
  display: none;
}
.bilge-teaser p {
  margin: 0;
}
.bilge-teaser-close {
  position: absolute;
  top: 0.3rem;
  right: 0.4rem;
  width: 26px;
  height: 26px;
  border: 0;
  border-radius: 50%;
  background: none;
  color: var(--mist);
  font-size: 1.1rem;
  cursor: pointer;
}
.bilge-teaser-close:hover {
  color: var(--paper);
}

/* 3. Chatfenster ---------------------------------------------------------- */

.bilge-panel {
  position: absolute;
  right: 0;
  bottom: 78px;
  display: flex;
  flex-direction: column;
  width: min(380px, calc(100vw - 2rem));
  height: min(580px, calc(100vh - 140px));
  border: 1px solid rgb(207 174 111 / 0.3);
  border-radius: 20px;
  background: #0f182c;
  box-shadow: 0 30px 70px -20px rgb(0 0 0 / 0.8);
  overflow: hidden;
  animation: bilge-pop 0.35s cubic-bezier(0.2, 0.9, 0.3, 1.15);
  transform-origin: bottom right;
}
.bilge-panel[hidden] {
  display: none;
}

/* Kopfzeile */
.bilge-head {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  padding: 0.85rem 0.8rem 0.85rem 1rem;
  background: linear-gradient(180deg, #18243f, #131d34);
  border-bottom: 1px solid var(--line);
}
.bilge-avatar {
  display: grid;
  place-items: center;
  flex: none;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--bilge-gold);
  color: #0d1526;
}
.bilge-avatar {
  padding: 2px;
}
.bilge-title {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-width: 0;
}
.bilge-title strong {
  font: 700 1.05rem var(--font-display);
  letter-spacing: 0.1em;
  color: var(--paper);
}
.bilge-title span {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  color: var(--mist);
  font-size: 0.74rem;
}
.bilge-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--signal);
}
.bilge-icon-btn {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  padding: 0;
  border: 0;
  border-radius: 10px;
  background: none;
  color: var(--mist);
  cursor: pointer;
}
.bilge-icon-btn:hover {
  background: rgb(255 255 255 / 0.06);
  color: var(--paper);
}
.bilge-icon-btn svg {
  width: 18px;
  height: 18px;
}

/* Verlauf */
.bilge-log {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  padding: 1rem 0.9rem;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-color: var(--line) transparent;
}

.bilge-msg {
  display: flex;
  align-items: flex-end;
  gap: 0.5rem;
  max-width: 88%;
}
.bilge-msg.is-new {
  animation: bilge-in 0.3s ease;
}
.bilge-bot {
  align-self: flex-start;
}
.bilge-user {
  align-self: flex-end;
}

.bilge-mini {
  display: grid;
  place-items: center;
  flex: none;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--bilge-gold);
  color: #0d1526;
}
.bilge-mini {
  padding: 1.5px;
}

.bilge-bubble {
  padding: 0.65rem 0.85rem;
  border-radius: 16px;
  font-size: 0.88rem;
  line-height: 1.5;
  overflow-wrap: break-word;
}
.bilge-bot .bilge-bubble {
  background: #1a2643;
  color: var(--paper);
  border-bottom-left-radius: 4px;
}
.bilge-user .bilge-bubble {
  background: var(--gold);
  color: #0d1526;
  font-weight: 500;
  border-bottom-right-radius: 4px;
}
.bilge-bubble a {
  color: var(--gold-soft);
  text-decoration: underline;
  text-underline-offset: 2px;
}

/* Preisliste in der Antwort */
.bilge-prices {
  display: grid;
  gap: 0.15rem;
  min-width: 220px;
}
.bilge-price-cat {
  margin: 0.5rem 0 0.2rem;
  color: var(--gold);
  font: 700 0.74rem var(--font-body);
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
.bilge-price-cat:first-child {
  margin-top: 0;
}
.bilge-price-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 0.8rem;
  padding: 0.3rem 0;
  border-bottom: 1px dashed rgb(255 255 255 / 0.1);
}
.bilge-price-row b {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  color: var(--gold-soft);
  font-weight: 600;
  white-space: nowrap;
}
.bilge-price-row small {
  color: var(--mist);
  font-size: 0.68rem;
  font-weight: 400;
}
.bilge-small {
  margin: 0.6rem 0 0;
  color: var(--mist);
  font-size: 0.76rem;
}

/* "schreibt …" */
.bilge-typing .bilge-bubble {
  display: flex;
  gap: 4px;
  padding: 0.85rem 0.9rem;
}
.bilge-typing i {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--gold);
  animation: bilge-bounce 1s infinite;
}
.bilge-typing i:nth-child(2) {
  animation-delay: 0.15s;
}
.bilge-typing i:nth-child(3) {
  animation-delay: 0.3s;
}

/* Vorschläge */
.bilge-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  padding-left: 2.1rem;
  animation: bilge-in 0.35s ease 0.1s both;
}
.bilge-chips button {
  padding: 0.42rem 0.75rem;
  border: 1px solid rgb(207 174 111 / 0.45);
  border-radius: 999px;
  background: rgb(207 174 111 / 0.08);
  color: var(--gold-soft);
  font: 500 0.8rem var(--font-body);
  cursor: pointer;
  transition:
    background-color 0.2s,
    color 0.2s;
}
.bilge-chips button:hover {
  background: var(--gold);
  color: #0d1526;
}

/* Eingabe */
.bilge-form {
  display: flex;
  gap: 0.5rem;
  padding: 0.7rem 0.75rem 0.4rem;
  border-top: 1px solid var(--line);
}
.bilge-form input {
  flex: 1;
  min-width: 0;
  padding: 0.7rem 0.9rem;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #0b1222;
  color: var(--paper);
  font: 1rem var(--font-body); /* 16px: verhindert Auto-Zoom auf dem iPhone */
}
.bilge-form input:focus {
  outline: none;
  border-color: var(--gold);
}
.bilge-send {
  display: grid;
  place-items: center;
  flex: none;
  width: 44px;
  border: 0;
  border-radius: 12px;
  background: var(--bilge-gold);
  color: #0d1526;
  cursor: pointer;
}
.bilge-send svg {
  width: 20px;
  height: 20px;
}

.bilge-note {
  margin: 0;
  padding: 0 0.9rem 0.65rem;
  color: rgb(155 167 192 / 0.7);
  font-size: 0.68rem;
  line-height: 1.4;
}

/* 4. Animationen ---------------------------------------------------------- */

@keyframes bilge-breathe {
  0%,
  100% {
    transform: scale(1);
    opacity: 0.7;
  }
  50% {
    transform: scale(1.12);
    opacity: 0;
  }
}
@keyframes bilge-pop {
  from {
    opacity: 0;
    transform: translateY(12px) scale(0.92);
  }
}
@keyframes bilge-in {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
}
@keyframes bilge-bounce {
  0%,
  60%,
  100% {
    transform: translateY(0);
    opacity: 0.4;
  }
  30% {
    transform: translateY(-4px);
    opacity: 1;
  }
}

/* 5. Handy ---------------------------------------------------------------- */

@media (max-width: 560px) {
  /* Label ausblenden – nur der runde Button (spart Platz) */
  .bilge-launcher-label {
    display: none;
  }
  .bilge-orb {
    width: 56px;
    height: 56px;
  }
  /* Sprechblase links neben dem Button statt darüber – so bleibt "Projekt starten" frei.
     Breite: Platz zwischen Cookie-Button (links) und BILGE-Button (rechts) */
  .bilge-teaser {
    right: 66px;
    bottom: 0;
    width: min(250px, calc(100vw - 9.5rem));
    padding: 0.65rem 1.9rem 0.65rem 0.85rem;
    border-radius: 16px 16px 4px 16px;
    font-size: 0.8rem;
    line-height: 1.4;
  }

  /* Chat im Vollbild, passt sich der sichtbaren Höhe an (Tastatur, Safari-Leisten) */
  .bilge-panel {
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100dvh;
    border: 0;
    border-radius: 0;
    padding-top: env(safe-area-inset-top);
    padding-bottom: env(safe-area-inset-bottom);
  }
  /* geöffnet: runden Button verstecken (Schließen geht über das X im Kopf) */
  .bilge.is-open .bilge-launcher {
    display: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  .bilge-orb::before {
    animation: none;
  }
}
