/* ============================================
   Homepage AI chat widget -- floating icon + panel.
   Reuses main.css's existing design tokens, not a new palette.
   ============================================ */

.chat-widget {
  position: fixed;
  right: var(--space-md);
  bottom: var(--space-md);
  z-index: 200;
  font-family: var(--font-body);
}

.chat-widget-toggle {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: none;
  background: linear-gradient(160deg, var(--accent-cyan), var(--accent-blue));
  color: var(--bg-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 8px 24px rgba(34, 211, 238, 0.35);
  transition: transform 0.2s ease;
}

.chat-widget-toggle:hover {
  transform: scale(1.05);
}

.chat-widget-toggle svg {
  width: 24px;
  height: 24px;
  position: absolute;
  transition: opacity 0.15s ease, transform 0.15s ease;
}

.chat-widget-toggle .chat-widget-icon-close {
  opacity: 0;
  transform: scale(0.7);
}

.chat-widget-toggle.is-open .chat-widget-icon-open {
  opacity: 0;
  transform: scale(0.7);
}

.chat-widget-toggle.is-open .chat-widget-icon-close {
  opacity: 1;
  transform: scale(1);
}

.chat-widget-panel {
  position: absolute;
  right: 0;
  bottom: calc(56px + var(--space-sm));
  width: min(360px, calc(100vw - 2 * var(--space-md)));
  height: min(520px, calc(100vh - 140px));
  background: var(--bg-panel);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* The [hidden] attribute (toggled by chat-widget.js's panel.hidden =
   true/false) only takes effect via a same-or-higher-specificity rule --
   the browser's own [hidden] { display: none } lives in the user-agent
   stylesheet, which loses to any author rule of equal specificity, so
   .chat-widget-panel's unconditional `display: flex` above was silently
   overriding it and leaving the panel permanently visible regardless of
   open/closed state. This compound selector has higher specificity than
   .chat-widget-panel alone, so it wins correctly when hidden is set. */
.chat-widget-panel[hidden] {
  display: none;
}

.chat-widget-header {
  padding: var(--space-sm) var(--space-md);
  background: linear-gradient(160deg, var(--bg-panel-hover), var(--bg-primary));
  border-bottom: 1px solid var(--border-subtle);
  font-family: var(--font-display);
  font-weight: 600;
  color: var(--text-primary);
  font-size: 0.95rem;
}

.chat-widget-messages {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-sm) var(--space-md);
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.chat-widget-message {
  max-width: 85%;
  padding: 0.6rem 0.85rem;
  border-radius: var(--radius-md);
  font-size: 0.88rem;
  line-height: 1.45;
  white-space: pre-wrap;
  word-break: break-word;
}

.chat-widget-message-assistant {
  align-self: flex-start;
  background: var(--bg-panel-hover);
  border: 1px solid var(--border-subtle);
  color: var(--text-primary);
  border-bottom-left-radius: 4px;
}

.chat-widget-message-user {
  align-self: flex-end;
  background: linear-gradient(160deg, var(--accent-cyan), var(--accent-blue));
  color: var(--bg-primary);
  border-bottom-right-radius: 4px;
}

.chat-widget-handoff-link {
  align-self: flex-start;
  color: var(--accent-cyan);
  font-size: 0.82rem;
  border-bottom: 1px solid rgba(34, 211, 238, 0.3);
  padding-bottom: 2px;
}

.chat-widget-typing {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 0.7rem 0.9rem;
}

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

.chat-widget-typing span:nth-child(2) { animation-delay: 0.15s; }
.chat-widget-typing span:nth-child(3) { animation-delay: 0.3s; }

@keyframes chat-widget-typing-bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.5; }
  30% { transform: translateY(-4px); opacity: 1; }
}

.chat-widget-form {
  display: flex;
  gap: 0.5rem;
  padding: var(--space-sm);
  border-top: 1px solid var(--border-subtle);
  background: var(--bg-panel);
}

.chat-widget-input {
  flex: 1;
  min-width: 0;
  padding: 0.6rem 0.8rem;
  background: var(--bg-primary);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-family: var(--font-body);
  font-size: 0.88rem;
}

.chat-widget-input:focus {
  outline: none;
  border-color: var(--accent-cyan);
}

.chat-widget-input:disabled {
  opacity: 0.6;
}

.chat-widget-send {
  width: 38px;
  height: 38px;
  flex-shrink: 0;
  border: none;
  border-radius: var(--radius-sm);
  background: var(--accent-cyan);
  color: var(--bg-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.chat-widget-send svg {
  width: 18px;
  height: 18px;
}

.chat-widget-send:hover {
  background: var(--accent-blue);
}

@media (max-width: 480px) {
  .chat-widget {
    right: var(--space-sm);
    bottom: var(--space-sm);
  }
  .chat-widget-panel {
    width: calc(100vw - 2 * var(--space-sm));
    height: min(480px, calc(100vh - 120px));
  }
}

/* ============================================
   Support email button -- sits beside the chat toggle, same fixed
   bottom-right cluster.
   ============================================ */

.support-email-fab {
  position: fixed;
  right: calc(var(--space-md) + 56px + 0.6rem);
  bottom: var(--space-md);
  z-index: 199;
  height: 56px;
  padding: 0 1.1rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  border-radius: 999px;
  background: var(--bg-panel);
  border: 1px solid var(--border-subtle);
  color: var(--text-primary);
  font-family: var(--font-body);
  font-size: 0.85rem;
  font-weight: 600;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
  transition: border-color 0.2s ease, transform 0.2s ease;
  white-space: nowrap;
}

.support-email-fab:hover {
  border-color: var(--accent-cyan);
  transform: translateY(-2px);
}

.support-email-fab svg {
  width: 20px;
  height: 20px;
  color: var(--accent-cyan);
  flex-shrink: 0;
}

@media (max-width: 480px) {
  .support-email-fab {
    right: calc(var(--space-sm) + 56px + 0.5rem);
    bottom: var(--space-sm);
    width: 56px;
    height: 56px;
    padding: 0;
    justify-content: center;
  }
  .support-email-fab span {
    display: none;
  }
}
