/**
 * HAS AI Sales & Support Chat Drawer Stylesheet
 * Brand: HAS (HEX Automation Services)
 * Responsive Conversational Drawer with Dynamic Viewport, Touch-Friendly Targets, and Mobile Bottom-Sheet
 */

/* -------------------------------------------------------------------------
 * Conversational Drawer Container
 * ------------------------------------------------------------------------- */
.has-chat-drawer {
  position: fixed;
  bottom: 90px;
  right: 24px;
  width: 390px;
  max-width: calc(100vw - 32px);
  height: 580px;
  max-height: calc(100vh - 120px);
  background: var(--has-bg-surface);
  border: 1px solid var(--has-border-medium);
  border-radius: var(--has-radius-lg);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.8), 0 0 40px var(--has-purple-muted);
  display: none;
  flex-direction: column;
  overflow: hidden;
  z-index: 9999;
  backdrop-filter: blur(20px);
  animation: hasDrawerSlideUp 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

.has-chat-drawer.active {
  display: flex;
}

@keyframes hasDrawerSlideUp {
  from {
    opacity: 0;
    transform: translateY(16px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

/* -------------------------------------------------------------------------
 * Header
 * ------------------------------------------------------------------------- */
.has-chat-header {
  padding: 0.85rem 1.15rem;
  background: var(--has-bg-card);
  border-bottom: 1px solid var(--has-border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
  user-select: none;
}

.has-chat-header-brand {
  display: flex;
  align-items: center;
  gap: var(--has-space-3);
}

.has-chat-brand-name {
  font-size: var(--has-text-sm);
  color: var(--has-text-primary);
  font-weight: 700;
  display: block;
}

.has-chat-brand-sub {
  font-size: 10px;
  font-family: var(--has-font-mono);
  color: var(--has-gold-signature);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  display: block;
}

.has-chat-header-actions {
  display: flex;
  align-items: center;
  gap: var(--has-space-2);
}

.has-chat-icon-btn {
  background: transparent;
  border: 1px solid transparent;
  color: var(--has-text-muted);
  width: 32px;
  height: 32px;
  border-radius: var(--has-radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: var(--has-text-sm);
  transition: all var(--has-transition-fast);
}

.has-chat-icon-btn:hover {
  background: rgba(255, 255, 255, 0.08);
  color: var(--has-text-primary);
  border-color: var(--has-border-subtle);
}

/* -------------------------------------------------------------------------
 * Message Stream Area
 * ------------------------------------------------------------------------- */
.has-chat-messages {
  flex: 1;
  padding: 1rem;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  scroll-behavior: smooth;
}

.has-chat-bubble {
  display: flex;
  max-width: 88%;
  word-break: break-word;
  animation: hasMessageFadeIn 0.2s ease-out;
}

@keyframes hasMessageFadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

.has-chat-bubble.user {
  align-self: flex-end;
}

.has-chat-bubble.assistant {
  align-self: flex-start;
}

.has-chat-bubble-content {
  padding: 0.75rem 0.95rem;
  border-radius: var(--has-radius-md);
  font-size: var(--has-text-xs);
  line-height: 1.6;
}

.has-chat-bubble.user .has-chat-bubble-content {
  background: #1e1b4b;
  color: #f8fafc;
  border: 1px solid rgba(139, 92, 246, 0.4);
  border-bottom-right-radius: 2px;
}

.has-chat-bubble.assistant .has-chat-bubble-content {
  background: var(--has-bg-card);
  color: var(--has-text-secondary);
  border: 1px solid var(--has-border-subtle);
  border-bottom-left-radius: 2px;
}

.has-chat-bubble.assistant .has-chat-bubble-content strong {
  color: var(--has-text-primary);
}

.has-chat-inline-code {
  font-family: var(--has-font-mono);
  font-size: 11px;
  background: rgba(0, 0, 0, 0.4);
  padding: 2px 5px;
  border-radius: 3px;
  color: var(--has-gold-signature);
}

.has-chat-bullet {
  margin: 4px 0;
  padding-left: 4px;
}

/* -------------------------------------------------------------------------
 * Quick Action Starter Pills
 * ------------------------------------------------------------------------- */
.has-chat-quick-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 4px;
  margin-bottom: 4px;
}

.has-quick-pill {
  background: var(--has-bg-card);
  border: 1px solid var(--has-border-medium);
  border-radius: var(--has-radius-full);
  color: var(--has-text-secondary);
  font-size: 11px;
  padding: 5px 10px;
  cursor: pointer;
  transition: all var(--has-transition-fast);
  white-space: nowrap;
}

.has-quick-pill:hover {
  border-color: var(--has-cyan);
  color: var(--has-cyan);
  background: rgba(0, 229, 255, 0.05);
}

/* -------------------------------------------------------------------------
 * Visual Quote Card Inside Chat
 * ------------------------------------------------------------------------- */
.has-quote-card {
  margin-top: 10px;
  background: var(--has-bg-surface);
  border: 1px solid rgba(0, 229, 255, 0.4);
  border-radius: var(--has-radius-md);
  padding: 0.85rem;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.4);
}

.has-quote-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
}

.has-quote-tag {
  font-family: var(--has-font-mono);
  font-size: 9px;
  font-weight: 700;
  background: rgba(0, 229, 255, 0.15);
  color: var(--has-cyan);
  padding: 2px 6px;
  border-radius: 3px;
  letter-spacing: 0.05em;
}

.has-quote-id {
  font-family: var(--has-font-mono);
  font-size: 10px;
  color: var(--has-text-muted);
}

.has-quote-title {
  font-size: var(--has-text-sm);
  font-weight: 700;
  color: var(--has-text-primary);
  margin-bottom: 8px;
}

.has-quote-row {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: var(--has-text-secondary);
  padding: 3px 0;
  border-bottom: 1px dashed var(--has-border-subtle);
}

.has-quote-row:last-of-type {
  border-bottom: none;
  margin-bottom: 8px;
}

.has-quote-row strong {
  color: var(--has-text-primary);
  font-family: var(--has-font-mono);
}

.has-quote-card-btn {
  width: 100%;
  padding: 6px 10px;
  font-size: 11px;
  justify-content: center;
}

/* -------------------------------------------------------------------------
 * Typing Animation Indicator
 * ------------------------------------------------------------------------- */
.has-chat-typing-dots {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px 6px;
}

.has-chat-typing-dots span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--has-cyan);
  opacity: 0.4;
  animation: hasTypingDot 1.2s infinite ease-in-out;
}

.has-chat-typing-dots span:nth-child(1) { animation-delay: 0s; }
.has-chat-typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.has-chat-typing-dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes hasTypingDot {
  0%, 80%, 100% { opacity: 0.3; transform: scale(0.8); }
  40% { opacity: 1; transform: scale(1.2); }
}

/* -------------------------------------------------------------------------
 * Footer & Input Form
 * ------------------------------------------------------------------------- */
.has-chat-footer {
  padding: 0.75rem 0.85rem;
  background: var(--has-bg-card);
  border-top: 1px solid var(--has-border-subtle);
  padding-bottom: max(0.75rem, env(safe-area-inset-bottom));
}

.has-chat-input-form {
  display: flex;
  align-items: flex-end;
  gap: 6px;
  background: var(--has-bg-surface);
  border: 1px solid var(--has-border-medium);
  border-radius: var(--has-radius-md);
  padding: 4px 6px 4px 10px;
  transition: all var(--has-transition-fast);
}

.has-chat-input-form:focus-within {
  border-color: var(--has-cyan);
  box-shadow: 0 0 0 2px rgba(0, 229, 255, 0.15);
}

.has-chat-textarea {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--has-text-primary);
  font-family: var(--has-font-sans);
  font-size: 13px;
  resize: none;
  outline: none;
  max-height: 100px;
  line-height: 1.4;
  padding: 6px 0;
}

.has-chat-textarea::placeholder {
  color: var(--has-text-muted);
}

.has-chat-send-btn {
  background: var(--has-cyan);
  border: none;
  color: #000;
  width: 34px;
  height: 34px;
  border-radius: var(--has-radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all var(--has-transition-fast);
  flex-shrink: 0;
}

.has-chat-send-btn:hover:not(:disabled) {
  background: #fff;
  transform: scale(1.05);
}

.has-chat-send-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.has-chat-footer-note {
  font-size: 10px;
  color: var(--has-text-muted);
  text-align: center;
  margin-top: 6px;
}

/* -------------------------------------------------------------------------
 * Mobile Responsive Overrides (< 768px)
 * ------------------------------------------------------------------------- */
@media (max-width: 768px) {
  .has-ai-launcher {
    bottom: 16px;
    right: 16px;
  }

  .has-ai-launcher-btn {
    padding: 0.75rem 1.25rem;
    min-height: 48px; /* Minimum 48px touch target */
    font-size: var(--has-text-sm);
  }

  .has-chat-drawer {
    bottom: 0;
    right: 0;
    left: 0;
    top: 0;
    width: 100vw;
    max-width: 100vw;
    height: 100dvh; /* Dynamic Viewport Height */
    max-height: 100dvh;
    border-radius: 0;
    border: none;
    z-index: 10000;
  }

  .has-chat-header {
    padding: 1rem;
    padding-top: max(1rem, env(safe-area-inset-top));
  }

  .has-chat-icon-btn {
    width: 44px; /* Touch target */
    height: 44px;
    font-size: 18px;
  }

  .has-chat-messages {
    padding: 1rem;
    gap: 1rem;
  }

  .has-chat-bubble {
    max-width: 92%;
  }

  .has-chat-bubble-content {
    font-size: 13px;
  }

  .has-quick-pill {
    padding: 8px 14px;
    font-size: 12px;
    min-height: 38px;
  }

  .has-chat-footer {
    padding: 0.75rem 1rem;
    padding-bottom: max(1rem, env(safe-area-inset-bottom));
  }

  .has-chat-textarea {
    font-size: 14px;
  }

  .has-chat-send-btn {
    width: 44px; /* Touch target */
    height: 44px;
  }
}

/* -------------------------------------------------------------------------
 * Accessibility & Reduced Motion
 * ------------------------------------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
  .has-chat-drawer,
  .has-chat-bubble,
  .has-chat-typing-dots span {
    animation: none !important;
    transition: none !important;
  }
}
