/* ==========================================================================
   ElektroFix Rhön – Chat-Assistent
   ========================================================================== */

.chat {
  position: fixed;
  right: 24px;
  bottom: calc(24px + env(safe-area-inset-bottom, 0px));
  z-index: 90;
}

.chat-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  height: 56px;
  padding: 0 1.15rem 0 1rem;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 999px;
  background: var(--navy);
  color: var(--yellow);
  font-family: var(--font-display);
  font-size: 0.92rem;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 18px 40px -18px rgba(8, 31, 51, 0.75);
  transition: transform 0.18s ease, box-shadow 0.18s ease, background 0.18s ease;
}

.chat-toggle:hover {
  transform: translateY(-2px);
  background: var(--navy-700);
  box-shadow: 0 22px 46px -18px rgba(8, 31, 51, 0.8);
}

.chat-toggle-icon {
  position: relative;
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
}

.chat-toggle .icon {
  width: 24px;
  height: 24px;
}

.chat-ico-close {
  display: none;
}

.chat.is-open .chat-ico-open {
  display: none;
}

.chat.is-open .chat-ico-close {
  display: block;
}

.chat-toggle-text {
  line-height: 1;
}

/* ---------- Panel ---------- */
.chat-panel {
  position: absolute;
  right: 0;
  bottom: calc(100% + 14px);
  display: flex;
  flex-direction: column;
  width: 372px;
  max-width: calc(100vw - 32px);
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--white);
  box-shadow: 0 34px 80px -30px rgba(8, 31, 51, 0.55);
  animation: chatIn 0.2s cubic-bezier(0.2, 0.7, 0.2, 1);
}

.chat-panel[hidden] {
  display: none;
}

@keyframes chatIn {
  from {
    opacity: 0;
    transform: translateY(10px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.chat-head {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  padding: 0.85rem 0.9rem 0.85rem 1rem;
  background: linear-gradient(135deg, var(--navy) 0%, var(--navy-700) 100%);
  color: var(--white);
}

.chat-avatar {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: var(--yellow);
  color: var(--navy-900);
  flex: none;
}

.chat-avatar .icon {
  width: 20px;
  height: 20px;
}

.chat-title {
  margin: 0;
  font-family: var(--font-display);
  font-size: 0.98rem;
  font-weight: 800;
  line-height: 1.2;
  color: var(--white);
}

.chat-status {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  margin: 0.15rem 0 0;
  font-size: 0.71rem;
  line-height: 1.3;
  color: rgba(255, 255, 255, 0.68);
}

.chat-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #5fd48a;
  box-shadow: 0 0 0 3px rgba(95, 212, 138, 0.16);
  flex: none;
}

.chat-close {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  margin-left: auto;
  padding: 0;
  border: 0;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.1);
  color: var(--white);
  cursor: pointer;
  transition: background 0.15s ease;
}

.chat-close:hover {
  background: rgba(255, 255, 255, 0.2);
}

.chat-close .icon {
  width: 17px;
  height: 17px;
}

/* ---------- Verlauf ---------- */
.chat-log {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  height: 300px;
  padding: 1rem;
  overflow-y: auto;
  overscroll-behavior: contain;
  background: #f7fafc;
  scroll-behavior: smooth;
}

.chat-msg {
  max-width: 87%;
  padding: 0.65rem 0.8rem;
  border-radius: 14px;
  font-size: 0.87rem;
  line-height: 1.55;
  white-space: pre-line;
  overflow-wrap: anywhere;
}

.chat-msg--bot {
  align-self: flex-start;
  border: 1px solid var(--line);
  border-bottom-left-radius: 5px;
  background: var(--white);
  color: var(--ink);
  box-shadow: 0 8px 18px -16px rgba(8, 31, 51, 0.45);
}

.chat-msg--user {
  align-self: flex-end;
  border-bottom-right-radius: 5px;
  background: var(--navy);
  color: var(--white);
}

.chat-msg-link {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  margin-top: 0.5rem;
  padding: 0.4rem 0.65rem;
  border: 1px solid #e2c45c;
  border-radius: 8px;
  background: var(--yellow-soft);
  font-family: var(--font-display);
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--navy-900);
  text-decoration: none;
}

.chat-msg-link:hover {
  background: var(--yellow);
  color: var(--navy-900);
}

.chat-typing {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  align-self: flex-start;
  padding: 0.75rem 0.85rem;
  border: 1px solid var(--line);
  border-radius: 14px;
  border-bottom-left-radius: 5px;
  background: var(--white);
}

.chat-typing span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #a9bac9;
  animation: chatBounce 1.1s ease-in-out infinite;
}

.chat-typing span:nth-child(2) {
  animation-delay: 0.14s;
}

.chat-typing span:nth-child(3) {
  animation-delay: 0.28s;
}

@keyframes chatBounce {
  0%,
  70%,
  100% {
    transform: translateY(0);
    opacity: 0.55;
  }
  35% {
    transform: translateY(-4px);
    opacity: 1;
  }
}

/* ---------- Schnellfragen ---------- */
.chat-quick {
  display: flex;
  gap: 0.4rem;
  padding: 0.1rem 0.75rem 0.65rem;
  overflow-x: auto;
  background: #f7fafc;
  scrollbar-width: none;
}

.chat-quick::-webkit-scrollbar {
  display: none;
}

.chat-chip {
  flex: none;
  padding: 0.38rem 0.65rem;
  border: 1px solid #d5e0e9;
  border-radius: 999px;
  background: var(--white);
  font-size: 0.74rem;
  font-weight: 600;
  color: var(--navy-700);
  cursor: pointer;
  white-space: nowrap;
  transition: border-color 0.15s ease, background 0.15s ease;
}

.chat-chip:hover {
  border-color: var(--yellow);
  background: var(--yellow-soft);
}

/* ---------- Eingabe ---------- */
.chat-form {
  display: flex;
  align-items: flex-end;
  gap: 0.5rem;
  padding: 0.7rem 0.75rem;
  border-top: 1px solid var(--line);
  background: var(--white);
}

.chat-input {
  flex: 1;
  min-height: 42px;
  max-height: 96px;
  padding: 0.68rem 0.8rem;
  border: 1px solid #d5e0e9;
  border-radius: 10px;
  background: #fbfcfe;
  font: inherit;
  font-size: 0.88rem;
  line-height: 1.4;
  color: var(--ink);
  resize: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
}

.chat-input::placeholder {
  color: #9aabb9;
}

.chat-input:focus {
  outline: none;
  border-color: var(--navy-700);
  background: var(--white);
  box-shadow: 0 0 0 4px rgba(246, 196, 0, 0.24);
}

.chat-send {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  padding: 0;
  border: 1px solid var(--yellow);
  border-radius: 10px;
  background: var(--yellow);
  color: var(--navy-900);
  cursor: pointer;
  flex: none;
  transition: background 0.15s ease, transform 0.15s ease;
}

.chat-send .icon {
  width: 18px;
  height: 18px;
}

.chat-send:hover:not(:disabled) {
  background: #ffd21f;
  transform: translateY(-1px);
}

.chat-send:disabled,
.chat-input:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.chat-note {
  margin: 0;
  padding: 0 0.75rem 0.65rem;
  background: var(--white);
  font-size: 0.67rem;
  line-height: 1.4;
  text-align: center;
  color: var(--muted);
}

.chat-note a {
  color: var(--navy-700);
  font-weight: 600;
}

/* ---------- Mobil ---------- */
@media (max-width: 520px) {
  .chat {
    right: 16px;
    bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  }

  .chat-toggle {
    width: 54px;
    height: 54px;
    padding: 0;
    justify-content: center;
  }

  .chat-toggle-text {
    display: none;
  }

  .chat-panel {
    position: fixed;
    right: 12px;
    left: 12px;
    bottom: calc(82px + env(safe-area-inset-bottom, 0px));
    width: auto;
    max-width: none;
    max-height: calc(100vh - 120px);
    max-height: calc(100dvh - 120px);
  }

  .chat-log {
    height: auto;
    flex: 1;
    min-height: 190px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .chat-panel {
    animation: none;
  }

  .chat-log {
    scroll-behavior: auto;
  }
}
