/* Carpart Berater-Chat — FAB unten rechts (Mobile), Vollbild/Bottom-Sheet wenn offen */

.advisor-chat-fab {
  position: fixed;
  right: max(0.85rem, env(safe-area-inset-right));
  bottom: calc(var(--nav-mobile-h, 60px) + env(safe-area-inset-bottom, 0px) + 0.75rem);
  z-index: 105;
  width: 3.35rem;
  height: 3.35rem;
  border: none;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  cursor: pointer;
  background: linear-gradient(180deg, var(--ad-navy-mid, #133456) 0%, var(--ad-navy, #0c2340) 100%);
  color: #fff;
  box-shadow: 0 6px 22px rgba(12, 35, 64, 0.45);
  font-family: inherit;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  transition: transform 0.18s ease, box-shadow 0.18s ease, opacity 0.18s ease;
}

.advisor-chat-fab:hover,
.advisor-chat-fab:focus-visible {
  transform: translateY(-2px);
  box-shadow: 0 8px 26px rgba(12, 35, 64, 0.5);
  outline: none;
}

.advisor-chat-fab__icon {
  width: 1.55rem;
  height: 1.55rem;
  stroke: var(--ad-orange, #f85a00);
}

.advisor-chat-fab__badge {
  position: absolute;
  top: -0.1rem;
  right: -0.05rem;
  min-width: 1.05rem;
  height: 1.05rem;
  padding: 0 0.28rem;
  border-radius: 999px;
  background: var(--ad-orange, #f85a00);
  color: #fff;
  font-size: 0.58rem;
  font-weight: 800;
  line-height: 1.05rem;
  text-align: center;
  border: 2px solid var(--ad-navy, #0c2340);
}

.advisor-chat-fab__badge[hidden] {
  display: none !important;
}

.advisor-chat-panel {
  position: fixed;
  inset: 0;
  z-index: 235;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  pointer-events: none;
  visibility: hidden;
  opacity: 0;
  transition: opacity 0.22s ease, visibility 0.22s ease;
}

.advisor-chat-panel.is-open {
  pointer-events: auto;
  visibility: visible;
  opacity: 1;
}

.advisor-chat-panel__backdrop {
  position: absolute;
  inset: 0;
  border: none;
  padding: 0;
  background: rgba(12, 35, 64, 0.45);
  backdrop-filter: blur(3px);
  cursor: pointer;
}

.advisor-chat-panel__sheet {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  width: 100%;
  max-height: min(92dvh, 920px);
  background: #fff;
  border-radius: 18px 18px 0 0;
  box-shadow: 0 -12px 40px rgba(12, 35, 64, 0.22);
  overflow: hidden;
  transform: translateY(100%);
  transition: transform 0.28s cubic-bezier(0.22, 1, 0.36, 1);
}

.advisor-chat-panel.is-open .advisor-chat-panel__sheet {
  transform: translateY(0);
}

.advisor-chat-panel__head {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.85rem 0.9rem 0.75rem;
  background: linear-gradient(180deg, var(--ad-navy-mid, #133456) 0%, var(--ad-navy, #0c2340) 100%);
  color: #fff;
  flex-shrink: 0;
}

.advisor-chat-panel__avatar {
  width: 2.35rem;
  height: 2.35rem;
  border-radius: 999px;
  display: grid;
  place-items: center;
  background: rgba(255, 255, 255, 0.14);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  flex-shrink: 0;
}

.advisor-chat-panel__meta {
  flex: 1;
  min-width: 0;
}

.advisor-chat-panel__title {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 700;
  line-height: 1.2;
}

.advisor-chat-panel__status {
  margin: 0.12rem 0 0;
  font-size: 0.72rem;
  color: rgba(255, 255, 255, 0.78);
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.advisor-chat-panel__status-dot {
  width: 0.45rem;
  height: 0.45rem;
  border-radius: 999px;
  background: #86efac;
  flex-shrink: 0;
}

.advisor-chat-panel__close {
  width: 2.15rem;
  height: 2.15rem;
  border: none;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  font-size: 1.35rem;
  line-height: 1;
  cursor: pointer;
  flex-shrink: 0;
}

.advisor-chat-panel__body {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: #f8fafc;
}

.advisor-chat-panel__messages {
  flex: 1;
  min-height: 8rem;
  overflow-y: auto;
  padding: 0.85rem 0.85rem 0.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  -webkit-overflow-scrolling: touch;
}

.advisor-chat-msg-wrap {
  display: flex;
  flex-direction: column;
  gap: 0.18rem;
  max-width: 88%;
}

.advisor-chat-msg-wrap--user {
  align-self: flex-end;
  align-items: flex-end;
}

.advisor-chat-msg-wrap--agent {
  align-self: flex-start;
  align-items: flex-start;
}

.advisor-chat-msg-wrap--system {
  align-self: center;
  align-items: center;
  max-width: 95%;
}

.advisor-chat-msg__label {
  font-size: 0.68rem;
  font-weight: 700;
  line-height: 1.1;
}

.advisor-chat-msg__label--user {
  color: rgba(12, 35, 64, 0.72);
  padding: 0 0.15rem;
}

.advisor-chat-msg__label--advisor {
  display: inline-flex;
  align-items: center;
  gap: 0.28rem;
  padding: 0.28rem 0.62rem 0.32rem;
  background: var(--ad-navy, #0c2340);
  color: #fff;
  border-radius: 12px 12px 12px 4px;
  box-shadow: 0 2px 8px rgba(12, 35, 64, 0.18);
  position: relative;
}

.advisor-chat-msg__label--advisor::before {
  content: "";
  width: 0.42rem;
  height: 0.42rem;
  border-radius: 999px;
  background: #22c55e;
  box-shadow: 0 0 0 2px rgba(34, 197, 94, 0.25);
  flex-shrink: 0;
}

.advisor-chat-msg-wrap--agent .advisor-chat-msg--bot,
.advisor-chat-msg-wrap--agent .advisor-chat-msg--agent {
  margin-top: 0.12rem;
}

.advisor-chat-panel__name-row {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.35rem 0.85rem 0;
  background: #f8fafc;
}

.advisor-chat-panel__name-label {
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--ad-navy, #0c2340);
  white-space: nowrap;
}

.advisor-chat-panel__name-input {
  flex: 1;
  min-width: 0;
  border: 1px solid var(--line, #e2e8f0);
  border-radius: 8px;
  padding: 0.42rem 0.55rem;
  font-family: inherit;
  font-size: 16px;
  color: var(--text, #0f172a);
  background: #fff;
}

.advisor-chat-msg {
  max-width: 100%;
  width: fit-content;
  padding: 0.55rem 0.75rem;
  border-radius: 14px;
  font-size: 0.86rem;
  line-height: 1.45;
  word-break: break-word;
  white-space: pre-wrap;
}

.advisor-chat-msg--user {
  background: var(--ad-orange, #f85a00);
  color: #fff;
  border-bottom-right-radius: 4px;
}

.advisor-chat-msg--bot,
.advisor-chat-msg--agent {
  background: #fff;
  color: var(--ad-navy, #0c2340);
  border: 1px solid var(--line, #e2e8f0);
  border-bottom-left-radius: 4px;
}

.advisor-chat-msg--system {
  background: transparent;
  color: var(--muted, #64748b);
  font-size: 0.72rem;
  text-align: center;
  padding: 0.15rem 0.35rem;
  width: auto;
}

.advisor-chat-panel__quick {
  display: flex;
  flex-wrap: nowrap;
  gap: 0.4rem;
  overflow-x: auto;
  padding: 0 0.85rem 0.55rem;
  -webkit-overflow-scrolling: touch;
}

.advisor-chat-panel__quick-btn {
  flex-shrink: 0;
  border: 1px solid var(--line, #e2e8f0);
  border-radius: 999px;
  background: #fff;
  color: var(--ad-navy, #0c2340);
  font-size: 0.72rem;
  font-weight: 600;
  padding: 0.35rem 0.7rem;
  cursor: pointer;
  font-family: inherit;
}

.advisor-chat-panel__composer {
  display: flex;
  align-items: flex-end;
  gap: 0.45rem;
  padding: 0.65rem 0.75rem calc(0.65rem + env(safe-area-inset-bottom, 0px));
  border-top: 1px solid var(--line, #e2e8f0);
  background: #fff;
  flex-shrink: 0;
}

.advisor-chat-panel__input {
  flex: 1;
  min-width: 0;
  min-height: 2.5rem;
  max-height: 6.5rem;
  resize: none;
  border: 1px solid var(--line, #e2e8f0);
  border-radius: 12px;
  padding: 0.55rem 0.7rem;
  font-family: inherit;
  font-size: 16px;
  line-height: 1.35;
  color: var(--text, #0f172a);
  background: #fff;
}

.advisor-chat-panel__send {
  width: 2.5rem;
  height: 2.5rem;
  border: none;
  border-radius: 12px;
  background: var(--ad-orange, #f85a00);
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
}

.advisor-chat-panel__send:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.advisor-chat-panel__send svg {
  width: 1.15rem;
  height: 1.15rem;
}

.advisor-chat-panel__state {
  margin: auto;
  padding: 1rem;
  text-align: center;
  color: var(--muted, #64748b);
  font-size: 0.82rem;
}

body.advisor-chat-open .dock {
  display: none !important;
}

body.advisor-chat-open .advisor-chat-fab {
  opacity: 0;
  pointer-events: none;
  transform: scale(0.85);
}

/* Carpart + WebToApp: Chat immer Vollbild (Handy & Desktop) */
.advisor-chat-panel.is-open {
  justify-content: stretch !important;
  align-items: stretch !important;
  padding: 0 !important;
}

.advisor-chat-panel.is-open .advisor-chat-panel__sheet {
  width: 100% !important;
  max-width: none !important;
  max-height: var(--advisor-chat-vvh, 100dvh) !important;
  height: var(--advisor-chat-vvh, 100dvh) !important;
  min-height: var(--advisor-chat-vvh, 100dvh) !important;
  border-radius: 0 !important;
  transform: none !important;
  opacity: 1 !important;
  box-shadow: none !important;
}

.advisor-chat-panel.is-open .advisor-chat-panel__backdrop {
  display: none !important;
}

.advisor-chat-panel__composer {
  padding-bottom: calc(0.65rem + env(safe-area-inset-bottom, 0px));
}

.advisor-chat-panel__input {
  font-size: 16px; /* iOS: kein Auto-Zoom beim Fokus */
}

.advisor-chat-fab {
  bottom: max(1rem, env(safe-area-inset-bottom, 0px));
}

@media (min-width: 900px) {
  /* altes Karten-Layout bewusst deaktiviert — Vollbild bleibt aktiv */
  .advisor-chat-panel {
    align-items: stretch;
    justify-content: stretch;
    padding: 0;
  }

  body.advisor-chat-open .advisor-chat-fab {
    opacity: 0 !important;
    pointer-events: none !important;
    transform: scale(0.85);
  }
}

.advisor-chat--webtoapp .advisor-chat-fab {
  bottom: max(1rem, env(safe-area-inset-bottom));
}
