/* ========================================
   HydraClean Chatbot Widget
   ======================================== */

/* Trigger Button */
.chatbot-trigger {
  position: fixed;
  bottom: 24px;
  left: 20px;
  z-index: 1100;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: var(--accent);
  color: var(--bg-primary);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 16px rgba(26, 60, 150, 0.3);
  transition: transform var(--transition-fast), box-shadow var(--transition-fast);
  font-family: inherit;
}

.chatbot-trigger:hover,
.chatbot-trigger:focus-visible {
  transform: scale(1.08);
  box-shadow: 0 6px 24px rgba(26, 60, 150, 0.45);
}

.chatbot-trigger svg {
  width: 24px;
  height: 24px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
}

.chatbot-trigger[aria-expanded="true"] {
  display: none;
}

/* Chat Panel */
.chatbot-panel {
  position: fixed;
  bottom: 84px;
  left: 20px;
  z-index: 1500;
  width: 380px;
  height: 520px;
  max-height: calc(100vh - 120px);
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: 0 8px 32px rgba(19, 31, 60, 0.22);
  display: none;
  flex-direction: column;
  overflow: hidden;
  font-family: inherit;
  touch-action: none;
}

.chatbot-panel.chatbot-open {
  display: flex;
  animation: chatbot-slideUp 0.3s ease forwards;
}

@keyframes chatbot-slideUp {
  from {
    opacity: 0;
    transform: translateY(16px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Header */
.chatbot-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  border-top: 3px solid var(--accent);
  flex-shrink: 0;
}

.chatbot-header__title {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 0.95rem;
  color: var(--text-primary);
}

.chatbot-header__dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--success, #34C759);
  flex-shrink: 0;
}

.chatbot-header__close {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--transition-fast), color var(--transition-fast);
}

.chatbot-header__close:hover,
.chatbot-header__close:focus-visible {
  background: var(--bg-tertiary);
  color: var(--text-primary);
}

/* Messages Area */
.chatbot-messages {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  touch-action: pan-y;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  scroll-behavior: smooth;
}

.chatbot-messages::-webkit-scrollbar {
  width: 4px;
}

.chatbot-messages::-webkit-scrollbar-track {
  background: transparent;
}

.chatbot-messages::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 4px;
}

/* Message Bubbles */
.chatbot-msg {
  max-width: 88%;
  padding: 10px 14px;
  border-radius: 12px;
  font-size: 0.875rem;
  line-height: 1.55;
  color: var(--text-primary);
  animation: chatbot-fadeIn 0.25s ease;
}

@keyframes chatbot-fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

.chatbot-msg--bot {
  align-self: flex-start;
  background: var(--bg-tertiary);
  border-bottom-left-radius: 4px;
}

.chatbot-msg--user {
  align-self: flex-end;
  background: var(--accent);
  color: var(--bg-primary);
  border-bottom-right-radius: 4px;
  font-weight: 500;
}

/* Quick Reply Buttons */
.chatbot-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 0 16px 12px;
  flex-shrink: 0;
  max-height: 180px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-y;
  overscroll-behavior: contain;
}

.chatbot-btn {
  padding: 8px 14px;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: var(--bg-tertiary);
  color: var(--text-primary);
  font-size: 0.8125rem;
  font-family: inherit;
  cursor: pointer;
  transition: border-color var(--transition-fast), background var(--transition-fast);
  line-height: 1.3;
  text-align: left;
}

.chatbot-btn:hover,
.chatbot-btn:focus-visible {
  border-color: var(--accent);
  background: var(--accent-muted);
}

.chatbot-btn--link {
  text-decoration: none;
  display: inline-block;
}

.chatbot-btn--call {
  border-color: var(--accent);
  background: var(--accent-muted);
  font-weight: 600;
}

.chatbot-btn--call:hover,
.chatbot-btn--call:focus-visible {
  background: var(--accent);
  color: var(--bg-primary);
}

/* Text Input Area */
.chatbot-input {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.chatbot-input__field {
  flex: 1;
  padding: 8px 12px;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: var(--bg-tertiary);
  color: var(--text-primary);
  font-size: 0.8125rem;
  font-family: inherit;
  outline: none;
  transition: border-color var(--transition-fast);
}

.chatbot-input__field::placeholder {
  color: var(--text-muted);
}

.chatbot-input__field:focus {
  border-color: var(--accent);
}

.chatbot-input__send {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: none;
  background: var(--accent);
  color: var(--bg-primary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: transform var(--transition-fast);
}

.chatbot-input__send:hover {
  transform: scale(1.08);
}

.chatbot-input__send svg {
  width: 16px;
  height: 16px;
}

/* Disclaimer Footer */
.chatbot-disclaimer {
  padding: 6px 12px;
  text-align: center;
  font-size: 0.6875rem;
  color: var(--text-muted);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
  line-height: 1.4;
}

/* Typing Indicator */
.chatbot-typing {
  display: flex;
  gap: 4px;
  padding: 10px 14px;
  align-self: flex-start;
  background: var(--bg-tertiary);
  border-radius: 12px;
  border-bottom-left-radius: 4px;
  max-width: 60px;
}

.chatbot-typing span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-muted);
  animation: chatbot-dot 1.2s infinite ease-in-out;
}

.chatbot-typing span:nth-child(2) { animation-delay: 0.2s; }
.chatbot-typing span:nth-child(3) { animation-delay: 0.4s; }

@keyframes chatbot-dot {
  0%, 60%, 100% { opacity: 0.3; transform: scale(0.8); }
  30% { opacity: 1; transform: scale(1); }
}

/* Mobile Responsive */
@media (max-width: 767px) {
  .chatbot-trigger {
    bottom: 56px;
    left: 8px;
    width: 40px;
    height: 40px;
    box-shadow: 0 2px 8px rgba(26, 60, 150, 0.2);
    opacity: 0;
    animation: chatbot-triggerFadeIn 0.3s ease 3s forwards;
  }

  .chatbot-trigger svg {
    width: 20px;
    height: 20px;
  }

  .chatbot-panel {
    left: 8px;
    right: 8px;
    bottom: 56px;
    width: auto;
    height: auto;
    max-height: 70vh;
  }
}

@keyframes chatbot-triggerFadeIn {
  from { opacity: 0; transform: scale(0.8); }
  to { opacity: 1; transform: scale(1); }
}

/* Accessibility: reduced motion */
@media (prefers-reduced-motion: reduce) {
  .chatbot-panel.chatbot-open {
    animation: none;
  }
  .chatbot-msg {
    animation: none;
  }
  .chatbot-typing span {
    animation: none;
    opacity: 0.5;
  }
}

/* Focus visible ring */
.chatbot-trigger:focus-visible,
.chatbot-header__close:focus-visible,
.chatbot-btn:focus-visible,
.chatbot-input__send:focus-visible,
.chatbot-input__field:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
