/* ===== Floating cluster: Zalo + Phone + Facebook + AI ===== */

.floating-cluster,
#floatingCluster {
  position: fixed;
  right: 12px;
  bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  z-index: 10060;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0;
  font-family: "Inter", system-ui, sans-serif;
  pointer-events: none;
  -webkit-transform: translateZ(0);
  transform: translateZ(0);
}

/* Panel must NOT live inside .floating-cluster (iOS Safari ≤480px overlay bug) */
.floating-cluster .chatbot-panel {
  display: none !important;
  visibility: hidden !important;
  pointer-events: none !important;
}

.floating-cluster__actions {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
  pointer-events: auto;
}

.social-group {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
}

.float-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  border: 1.5px solid rgba(255, 255, 255, 0.2);
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.25);
  transition: transform 0.18s ease, box-shadow 0.18s ease;
  flex-shrink: 0;
  overflow: hidden;
  color: #fff;
}

.float-btn:hover {
  transform: scale(1.1);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.35);
}

.float-btn:active {
  transform: scale(0.96);
}

.float-btn svg {
  width: 20px;
  height: 20px;
  fill: currentColor;
  flex-shrink: 0;
}

.float-btn img {
  display: block;
  width: 24px;
  height: 24px;
  object-fit: contain;
}

.btn-zalo {
  background-color: #0068ff;
}

.btn-zalo img {
  width: 26px;
  height: 26px;
  background: #fff;
  border-radius: 8px;
  padding: 2px;
}

.btn-phone {
  background-color: #25c755;
}

.btn-fb {
  background-color: #1877f2;
  padding: 0;
}

.btn-fb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 50%;
}

.float-divider {
  width: 28px;
  height: 1px;
  background: rgba(0, 0, 0, 0.15);
  align-self: flex-end;
  margin: 2px 6px 2px 0;
}

.dark .float-divider,
:root[data-theme="dark"] .float-divider {
  background: rgba(255, 255, 255, 0.2);
}

.dark .float-btn,
:root[data-theme="dark"] .float-btn {
  border-color: rgba(255, 255, 255, 0.15);
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.5);
}

.chatbot-root {
  position: relative;
  flex-shrink: 0;
  align-self: flex-end;
  z-index: 901;
  pointer-events: auto;
}

#chatbotPanelMount {
  position: relative;
  z-index: 2147483001;
  pointer-events: none;
}

/* Must beat #chatbotPanelMount .chatbot-panel { display:none } (higher specificity) */
#chatbotPanelMount .chatbot-panel.chatbot-panel--visible,
#chatbotPanelMount .chat-widget-container.chatbot-panel--visible {
  display: flex;
  visibility: visible;
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0);
  z-index: 2147483001;
}

.chatbot-toggle {
  position: relative;
  z-index: 3;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-height: 52px;
  padding: 0 16px 0 14px;
  border: none;
  border-radius: 999px;
  background: linear-gradient(135deg, #1a5fb4 0%, #3584e4 100%);
  color: #fff;
  cursor: pointer;
  box-shadow: 0 10px 28px rgba(26, 95, 180, 0.5);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  pointer-events: auto;
  font-size: 0.875rem;
  font-weight: 600;
}

.chatbot-toggle__label {
  white-space: nowrap;
  line-height: 1;
}

.chatbot-root--open .chatbot-toggle {
  width: 56px;
  height: 56px;
  min-height: 0;
  padding: 0;
  border-radius: 50%;
  justify-content: center;
}

.chatbot-root--open .chatbot-toggle__label {
  display: none;
}

.chatbot-toggle__pulse {
  position: absolute;
  inset: -5px;
  border-radius: 999px;
  border: 2px solid rgba(53, 132, 228, 0.55);
  animation: chatbot-pulse 2.4s ease-out infinite;
  pointer-events: none;
}

@keyframes chatbot-pulse {
  0% {
    transform: scale(1);
    opacity: 0.8;
  }
  70% {
    transform: scale(1.18);
    opacity: 0;
  }
  100% {
    transform: scale(1.18);
    opacity: 0;
  }
}

.chatbot-root--open .chatbot-toggle__pulse {
  display: none;
}

.chatbot-toggle:hover {
  transform: scale(1.08);
  box-shadow: 0 12px 32px rgba(26, 95, 180, 0.6);
}

.chatbot-toggle__icon--close {
  display: none;
}

.chatbot-root--open .chatbot-toggle__icon--open {
  display: none;
}

.chatbot-root--open .chatbot-toggle__icon--close {
  display: block;
}

#chatbotPanelMount .chatbot-panel,
#chatbotPanelMount .chat-widget-container,
.chatbot-panel,
.chat-widget-container {
  position: fixed;
  bottom: 90px;
  right: 16px;
  top: auto !important;
  left: auto !important;
  width: 340px;
  max-width: calc(100vw - 32px);
  height: min(480px, calc(100dvh - 180px));
  max-height: calc(100dvh - 180px);
  z-index: 10065;
  display: none;
  visibility: hidden;
  pointer-events: none;
  flex-direction: column;
  background: var(--surface, #fff);
  border: 1px solid var(--border, #e5e7eb);
  border-radius: 16px;
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.18);
  overflow: hidden;
  pointer-events: none;
  opacity: 0;
  transform: translateY(12px);
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.chatbot-panel--visible {
  display: flex;
  pointer-events: auto;
  visibility: visible;
  opacity: 1;
  transform: translateY(0);
  animation: chatbot-slide-up 0.25s ease;
}

@keyframes chatbot-slide-up {
  from {
    opacity: 0;
    transform: translateY(12px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.chatbot-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 14px 16px;
  background: linear-gradient(135deg, #1a5fb4 0%, #3584e4 100%);
  color: #fff;
}

.chatbot-header__info {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.chatbot-header__avatar {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.2);
  font-size: 0.75rem;
  font-weight: 700;
  flex-shrink: 0;
}

.chatbot-header__title {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 600;
  line-height: 1.2;
}

.chatbot-header__status {
  margin: 2px 0 0;
  font-size: 0.75rem;
  opacity: 0.85;
}

.chatbot-header__actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.chatbot-clear {
  flex-shrink: 0;
  padding: 4px 10px;
  border: 1px solid rgba(255, 255, 255, 0.45);
  border-radius: 999px;
  background: transparent;
  color: #fff;
  font-size: 0.72rem;
  cursor: pointer;
  transition: background 0.15s ease;
}

.chatbot-close {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  padding: 0;
  border: none;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.15);
  color: #fff;
  cursor: pointer;
  transition: background 0.15s ease;
}

.chatbot-close:hover {
  background: rgba(255, 255, 255, 0.28);
}

.chatbot-clear:hover {
  background: rgba(255, 255, 255, 0.15);
}

.chatbot-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: var(--bg-alt, #f8fafc);
}

.chatbot-bubble {
  max-width: 85%;
  padding: 10px 14px;
  border-radius: 16px;
  font-size: 0.875rem;
  line-height: 1.5;
  word-wrap: break-word;
  white-space: pre-wrap;
}

.chatbot-bubble--user {
  align-self: flex-end;
  background: #3584e4;
  color: #fff;
  border-bottom-right-radius: 4px;
}

.chatbot-bubble--ai {
  align-self: flex-start;
  background: var(--surface, #fff);
  color: var(--text, #1f2937);
  border: 1px solid var(--border, #e5e7eb);
  border-bottom-left-radius: 4px;
}

.chatbot-bubble--typing {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--text-muted, #6b7280);
}

.chatbot-dots {
  display: inline-flex;
  gap: 3px;
  align-items: center;
}

.chatbot-dots i {
  display: block;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: #9ca3af;
  animation: chatbot-dot 1.2s ease-in-out infinite;
}

.chatbot-dots i:nth-child(2) {
  animation-delay: 0.15s;
}

.chatbot-dots i:nth-child(3) {
  animation-delay: 0.3s;
}

@keyframes chatbot-dot {
  0%, 80%, 100% {
    opacity: 0.3;
    transform: translateY(0);
  }
  40% {
    opacity: 1;
    transform: translateY(-3px);
  }
}

.chatbot-input-form {
  display: flex;
  gap: 8px;
  padding: 12px;
  border-top: 1px solid var(--border, #e5e7eb);
  background: var(--surface, #fff);
}

.chatbot-input {
  flex: 1;
  min-width: 0;
  padding: 10px 14px;
  border: 1px solid var(--border, #e5e7eb);
  border-radius: 999px;
  font-size: 0.875rem;
  font-family: inherit;
  background: var(--bg-alt, #f8fafc);
  color: var(--text, #1f2937);
  outline: none;
  transition: border-color 0.15s ease;
}

.chatbot-input:focus {
  border-color: #3584e4;
}

.chatbot-send {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 50%;
  background: #3584e4;
  color: #fff;
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.15s ease, opacity 0.15s ease;
}

.chatbot-send:hover:not(:disabled) {
  background: #1a5fb4;
}

.chatbot-send:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Listing cards in chat */
.chatbot-listings-container {
  margin: 4px 0 8px 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-self: flex-start;
  max-width: 92%;
}

.chatbot-listings-badge {
  align-self: flex-start;
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 0.6875rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: #9a3412;
  background: #ffedd5;
  border: 1px solid #fdba74;
}

.chatbot-listing-item {
  padding: 10px 12px;
  background: #f0f4f8;
  border: 1px solid var(--border, #e5e7eb);
  border-radius: 10px;
  font-size: 0.8125rem;
}

.chatbot-listing-link {
  color: #0084ff;
  text-decoration: none;
  font-weight: 600;
  line-height: 1.4;
}

.chatbot-listing-link:hover {
  text-decoration: underline;
}

.chatbot-listing-meta {
  margin-top: 6px;
  color: #666;
  font-size: 0.75rem;
}

/* Dark theme */
html.dark .chatbot-panel {
  background: var(--surface, #1e293b);
  border-color: var(--border, #334155);
}

html.dark .chatbot-messages {
  background: var(--bg-alt, #0f172a);
}

html.dark .chatbot-bubble--ai {
  background: var(--surface, #1e293b);
  color: var(--text, #e2e8f0);
  border-color: var(--border, #334155);
}

html.dark .chatbot-input-form {
  background: var(--surface, #1e293b);
  border-color: var(--border, #334155);
}

html.dark .chatbot-input {
  background: var(--bg-alt, #0f172a);
  color: var(--text, #e2e8f0);
  border-color: var(--border, #334155);
}

html.dark .chatbot-listings-badge {
  color: #fdba74;
  background: rgba(154, 52, 18, 0.35);
  border-color: rgba(253, 186, 116, 0.45);
}

html.dark .chatbot-listing-item {
  background: #1e293b;
  border-color: var(--border, #334155);
}

html.dark .chatbot-listing-meta {
  color: #94a3b8;
}

/* Mobile / tablet */
@media (max-width: 768px) {
  .floating-cluster,
  #floatingCluster {
    right: calc(12px + env(safe-area-inset-right, 0px));
    bottom: calc(12px + env(safe-area-inset-bottom, 0px));
    z-index: 10060;
    -webkit-transform: translateZ(0);
    transform: translateZ(0);
  }

  .floating-cluster__actions {
    gap: 10px;
  }

  .float-stack,
  .social-group {
    gap: 10px;
  }

  .float-btn {
    width: 44px;
    height: 44px;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.28);
  }

  .chatbot-toggle__label {
    display: none !important;
  }

  .chatbot-toggle {
    width: 48px;
    height: 48px;
    min-height: 48px;
    padding: 0;
    border-radius: 50%;
    justify-content: center;
    box-shadow: 0 4px 14px rgba(26, 95, 180, 0.45);
  }

  .chatbot-toggle__pulse {
    display: none;
  }

  .chatbot-root--open .chatbot-toggle,
  .floating-cluster--open .chatbot-toggle {
    width: 48px;
    height: 48px;
    min-height: 48px;
  }

  #chatbotPanelMount .chatbot-panel,
  #chatbotPanelMount .chat-widget-container {
    bottom: calc(200px + env(safe-area-inset-bottom, 0px));
    right: 12px;
    width: min(340px, calc(100vw - 24px));
  }
}

@media (max-width: 480px) {
  .floating-cluster,
  #floatingCluster {
    right: calc(10px + env(safe-area-inset-right, 0px));
    bottom: calc(10px + env(safe-area-inset-bottom, 0px));
  }

  .float-btn {
    width: 42px;
    height: 42px;
  }

  .float-btn svg {
    width: 18px;
    height: 18px;
  }

  .float-btn img,
  .btn-zalo img {
    width: 22px;
    height: 22px;
  }

  #chatbotPanelMount .chatbot-panel,
  #chatbotPanelMount .chat-widget-container {
    bottom: 0;
    right: 0;
    left: 0;
    top: auto !important;
    width: 100%;
    max-width: 100%;
    height: min(72dvh, calc(100dvh - 72px));
    max-height: 72dvh;
    border-radius: 16px 16px 0 0;
  }
}
