/* Building Chat Bot — bubble e pannello conversazione. */
#building-chat.bchat {
  --bchat-accent: #e8842b;
  --bchat-bg: #16233a;
  --bchat-bg-light: #1c2c46;
  --bchat-text: #cdd7e2;
  --bchat-muted: #9fb0c4;
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 99998;
  font-family: 'Manrope', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
}

/* Launcher */
#building-chat .bchat__launcher {
  width: 58px;
  height: 58px;
  border-radius: 50%;
  border: none;
  background: var(--bchat-accent);
  color: #16233a;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
  transition: transform 0.2s ease, box-shadow 0.2s ease, background 0.2s ease;
  position: relative;
}
#building-chat .bchat__launcher:hover {
  transform: translateY(-3px);
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.4);
  filter: brightness(1.05);
}
#building-chat .bchat__launcher svg {
  width: 28px;
  height: 28px;
}
#building-chat .bchat__close { display: none; }
#building-chat.bchat--open .bchat__launcher { transform: rotate(90deg); }
#building-chat.bchat--open .bchat__ic { display: none; }
#building-chat.bchat--open .bchat__close { display: block; }

/* Pannello */
#building-chat .bchat__panel {
  position: absolute;
  right: 0;
  bottom: 74px;
  width: 360px;
  max-width: calc(100vw - 32px);
  height: 520px;
  max-height: calc(100vh - 110px);
  max-height: calc(100svh - 110px);
  max-height: calc(100dvh - 110px);
  background: var(--bchat-bg);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 16px;
  overflow: hidden;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.45);
  display: none;
  flex-direction: column;
}
#building-chat.bchat--open .bchat__panel { display: flex; }

/* Header */
#building-chat .bchat__head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 18px;
  background: var(--bchat-bg-light);
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}
#building-chat .bchat__avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--bchat-accent);
  color: #16233a;
  font-weight: 800;
  font-size: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
}
#building-chat .bchat__avatar--img {
  background: #fff;
  padding: 4px;
  object-fit: contain;
}
#building-chat .bchat__headtxt { display: flex; flex-direction: column; line-height: 1.2; }
#building-chat .bchat__title { color: #fff; font-weight: 700; font-size: 15px; }
#building-chat .bchat__subtitle { color: var(--bchat-muted); font-size: 12px; margin-top: 2px; }

/* Body messaggi */
#building-chat .bchat__body {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  scrollbar-width: thin;
  scrollbar-color: rgba(255,255,255,0.2) transparent;
}
#building-chat .bchat__body::-webkit-scrollbar { width: 6px; }
#building-chat .bchat__body::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.2); border-radius: 3px; }

#building-chat .bchat__msg {
  max-width: 82%;
  padding: 10px 14px;
  border-radius: 14px;
  font-size: 14px;
  line-height: 1.55;
  white-space: pre-wrap;
  word-wrap: break-word;
}
#building-chat .bchat__msg--bot {
  align-self: flex-start;
  background: var(--bchat-bg-light);
  color: var(--bchat-text);
  border-bottom-left-radius: 4px;
}
#building-chat .bchat__msg--user {
  align-self: flex-end;
  background: var(--bchat-accent);
  color: #16233a;
  border-bottom-right-radius: 4px;
}
#building-chat .bchat__msg a {
  color: var(--bchat-accent);
  text-decoration: underline;
  font-weight: 700;
  word-break: break-all;
}
#building-chat .bchat__msg a:hover { text-decoration: none; }
#building-chat .bchat__msg--user a { color: #16233a; }
#building-chat .bchat__typing {
  align-self: flex-start;
  display: inline-flex;
  gap: 5px;
  padding: 12px 16px;
  background: var(--bchat-bg-light);
  border-radius: 14px;
  border-bottom-left-radius: 4px;
}
#building-chat .bchat__typing i {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--bchat-muted);
  animation: bchat-blink 1.2s infinite;
}
#building-chat .bchat__typing i:nth-child(2) { animation-delay: 0.2s; }
#building-chat .bchat__typing i:nth-child(3) { animation-delay: 0.4s; }
@keyframes bchat-blink { 0%, 80%, 100% { opacity: 0.3; } 40% { opacity: 1; } }

/* Form */
#building-chat .bchat__form {
  display: flex;
  gap: 8px;
  padding: 12px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  background: var(--bchat-bg-light);
}
#building-chat .bchat__input {
  flex: 1;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 24px;
  color: #fff;
  font-family: inherit;
  font-size: 16px; /* >=16px: evita lo zoom automatico di iOS quando si scrive */
  padding: 10px 16px;
  outline: none;
  min-width: 0;
}
#building-chat .bchat__input::placeholder { color: var(--bchat-muted); }
#building-chat .bchat__input:focus { border-color: var(--bchat-accent); }
#building-chat .bchat__send {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: none;
  background: var(--bchat-accent);
  color: #16233a;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  padding: 0 !important;
  transition: filter 0.2s ease;
}
#building-chat .bchat__send:hover { filter: brightness(1.08); }
#building-chat .bchat__send svg { width: 22px !important; height: 22px !important; max-width: 22px !important; flex: 0 0 auto !important; }
#building-chat .bchat__send:disabled { opacity: 0.5; cursor: default; }

/* Mobile */
@media (max-width: 480px) {
  #building-chat.bchat { right: 16px; bottom: 16px; }
  #building-chat .bchat__panel {
    right: -8px;
    bottom: 70px;
    top: auto;
    width: calc(100vw - 16px);
    height: calc(100svh - 100px);
    height: calc(100dvh - 100px);
    max-height: calc(100svh - 100px);
    max-height: calc(100dvh - 100px);
    border-radius: 16px;
  }
}
