/* AI Chat Widget (customer) */

/*
  This widget is embedded in multiple layouts.
  Do not assume Tailwind/utility CSS exists on the host page.
*/

#ai-chat-widget {
  position: fixed;
  left: 1.5rem;
  bottom: 1.5rem;
  z-index: 2147483647;
  pointer-events: auto;
}

/* The JS toggles this class; define it here to avoid relying on framework CSS. */
#ai-chat-widget .hidden { display: none !important; }

#ai-chat-widget {
  font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, "Apple Color Emoji", "Segoe UI Emoji";
}

#ai-chat-invite {
  position: absolute;
  left: 0;
  bottom: 4rem;
  width: 260px;
}

@media (min-width: 640px) {
  #ai-chat-invite { width: 320px; }
}

#ai-chat-open {
  position: relative;
  width: 80px;
  height: 80px;
  border-radius: 999px;
  border: 0;
  background: linear-gradient(135deg, #10b981 0%, #059669 100%);
  color: #fff;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 20px 40px rgba(5, 150, 105, 0.4), 0 0 30px rgba(16, 185, 129, 0.3);
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  animation: chat-button-glow 2s ease-in-out infinite;
}

/* Ensure open button stays at the bottom-left corner */
#ai-chat-open { position: fixed; left: 1.5rem; bottom: 1.5rem; z-index: 2147483647; }

@media (max-width: 640px) {
  #ai-chat-open { left: 1rem; bottom: 1rem; }
}

#ai-chat-open:hover {
  background: linear-gradient(135deg, #059669 0%, #047857 100%);
  transform: scale(1.1);
  box-shadow: 0 25px 50px rgba(5, 150, 105, 0.5), 0 0 40px rgba(16, 185, 129, 0.5);
}

#ai-chat-open:focus { outline: none; }
#ai-chat-open:focus-visible {
  box-shadow: 0 0 0 4px rgba(16,185,129,0.4), 0 20px 40px rgba(5, 150, 105, 0.4);
}

#ai-chat-open span {
  font-size: 2.5rem;
  animation: emoji-bounce 3s ease-in-out infinite;
}

@keyframes chat-button-glow {
  0%, 100% {
    box-shadow: 0 20px 40px rgba(5, 150, 105, 0.4), 0 0 30px rgba(16, 185, 129, 0.3);
  }
  50% {
    box-shadow: 0 20px 40px rgba(5, 150, 105, 0.6), 0 0 45px rgba(16, 185, 129, 0.6);
  }
}

@keyframes emoji-bounce {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-4px); }
}

#ai-chat-panel {
  width: 20rem;
  background: #fff;
  border-radius: 1rem;
  border: 1px solid rgba(229,231,235,1);
  overflow: hidden;
  max-height: 85vh;
  box-shadow: 0 24px 60px rgba(0,0,0,0.22);
}

/* Host pages may override display; keep panel as flex container. */
#ai-chat-panel { display: flex; flex-direction: column; }

/* Open button icon container (supports logo image + fallback emoji). */
#aiChatOpenIcon { display: inline-flex; align-items: center; justify-content: center; }
#aiChatOpenIcon img { width: 40px; height: 40px; object-fit: contain; display: block; }

/* Panel floats above the button */
#ai-chat-panel {
  position: fixed;
  left: 1.5rem;
  bottom: calc(1.5rem + 80px + 0.75rem);
  z-index: 2147483646;
}

@media (max-width: 640px) {
  #ai-chat-panel {
    left: 1rem;
    bottom: calc(1rem + 80px + 0.75rem);
  }
}

/* Close button in header */
#ai-chat-widget .ai-chat-close {
  width: 30px;
  height: 30px;
  border-radius: 999px;
  border: 1px solid rgba(255,255,255,0.22);
  background: rgba(255,255,255,0.12);
  color: #fff;
  cursor: pointer;
  line-height: 28px;
  font-weight: 900;
}
#ai-chat-widget .ai-chat-close:hover { background: rgba(255,255,255,0.18); }

@media (min-width: 640px) {
  #ai-chat-panel { width: 24rem; }
}

/* Internal layout (do not rely on Tailwind utility classes) */
#ai-chat-panel { display: flex; flex-direction: column; }
#ai-chat-step-email { display: block; }
#ai-chat-step-chat { display: flex; flex-direction: column; min-height: 0; }

#aiChatMessages {
  flex: 1 1 auto;
  min-height: 200px;
  overflow-y: auto;
  background: #f9fafb;
  resize: vertical;
}

.ai-chat-footer {
  flex: 0 0 auto;
  border-top: 1px solid rgba(229,231,235,1);
  background: #fff;
  padding: 0.75rem;
}

/* Footer layout fallback (quando Tailwind não existe na página) */
#ai-chat-widget .ai-chat-emoji {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-bottom: 0.5rem;
}

#ai-chat-widget .ai-chat-emoji button {
  padding: 0.35rem 0.5rem;
  border: 1px solid #e5e7eb;
  border-radius: 0.5rem;
  background: #fff;
  cursor: pointer;
}

#ai-chat-widget .ai-chat-actions {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  flex-wrap: wrap;
}

#ai-chat-widget #aiChatFile {
  flex: 1 1 12rem;
  min-width: 10rem;
}

#ai-chat-widget #aiChatSend {
  flex: 0 0 auto;
}

/* Evita que o textarea cresça e empurre o botão para fora do painel */
#ai-chat-widget .ai-chat-textarea {
  max-height: 300px;
}

/* Ticket form: scrollable area so the full form is usable on mobile */
#aiChatTicketBox {
  margin-top: 0.5rem;
  padding-top: 0.75rem;
  border-top: 1px solid rgba(229,231,235,1);
}

#aiChatTicketForm {
  max-height: 34vh;
  overflow-y: auto;
  padding-right: 0.25rem;
}

@media (max-width: 640px) {
  #aiChatTicketForm { max-height: 42dvh; }
}

/* Subtle pulse to grab attention */
@keyframes aiChatPulse {
  0% { box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.55); }
  70% { box-shadow: 0 0 0 14px rgba(16, 185, 129, 0); }
  100% { box-shadow: 0 0 0 0 rgba(16, 185, 129, 0); }
}
.ai-chat-pulse { animation: aiChatPulse 2.2s infinite; }

/* Invite entrance animation */
@keyframes aiChatInviteIn {
  from { transform: translateY(6px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}
.ai-chat-invite-in { animation: aiChatInviteIn 220ms ease-out; }

/* Scoped button system (fallback if layout doesn't have .btn) */
#ai-chat-widget .btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.65rem 0.9rem;
  border-radius: 0.75rem;
  font-weight: 700;
  font-size: 0.875rem;
  line-height: 1.25rem;
  box-shadow: 0 1px 2px rgba(0,0,0,0.06);
  transition: transform 200ms ease, box-shadow 200ms ease, background-color 200ms ease, border-color 200ms ease, opacity 200ms ease;
  transform: translateZ(0);
  user-select: none;
}
#ai-chat-widget .btn:hover { box-shadow: 0 10px 24px rgba(0,0,0,0.10); transform: scale(1.01); }
#ai-chat-widget .btn:active { transform: scale(0.99); }
#ai-chat-widget .btn:disabled,
#ai-chat-widget .btn[aria-disabled="true"] {
  opacity: 0.55;
  cursor: not-allowed;
  pointer-events: none;
  transform: none;
}

#ai-chat-widget .btn-primary {
  color: #fff;
  background: linear-gradient(135deg, #059669 0%, #16a34a 60%, #34d399 100%);
}
#ai-chat-widget .btn-primary:hover { filter: brightness(0.97); }

#ai-chat-widget .btn-secondary {
  color: #111827;
  background: #ffffff;
  border: 1px solid #e5e7eb;
}
#ai-chat-widget .btn-secondary:hover { background: #f9fafb; border-color: #d1d5db; }

#ai-chat-widget .ai-chat-input,
#ai-chat-widget .ai-chat-select,
#ai-chat-widget .ai-chat-textarea {
  width: 100%;
  border: 1px solid #e5e7eb;
  border-radius: 0.75rem;
  padding: 0.6rem 0.75rem;
  font-size: 0.875rem;
  outline: none;
  color: #111827;
  background-color: #ffffff;
}
#ai-chat-widget .ai-chat-input::placeholder,
#ai-chat-widget .ai-chat-textarea::placeholder {
  color: #9ca3af;
}
#ai-chat-widget .ai-chat-textarea { resize: vertical; }
#ai-chat-widget .ai-chat-input:focus,
#ai-chat-widget .ai-chat-select:focus,
#ai-chat-widget .ai-chat-textarea:focus {
  border-color: rgba(16,185,129,0.55);
  box-shadow: 0 0 0 3px rgba(16,185,129,0.20);
}

#ai-chat-unread {
  position: absolute;
  top: -6px;
  right: -6px;
  min-width: 18px;
  height: 18px;
  padding: 0 6px;
  border-radius: 999px;
  background: #ef4444;
  color: #fff;
  font-size: 12px;
  line-height: 18px;
  font-weight: 800;
  border: 2px solid rgba(255,255,255,0.95);
  box-shadow: 0 6px 18px rgba(0,0,0,0.18);
}

/* Attachments: image preview */
#ai-chat-widget .ai-chat-attachment-thumb {
  display: inline-block;
  max-width: 220px;
  border-radius: 14px;
  border: 1px solid rgba(229,231,235,1);
  box-shadow: 0 10px 26px rgba(0,0,0,0.14);
  cursor: zoom-in;
}

/* Image modal / lightbox (scoped to widget) */
#ai-chat-widget .ai-chat-img-modal {
  position: fixed;
  inset: 0;
  z-index: 2147483646;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 14px;
}
#ai-chat-widget .ai-chat-img-modal.hidden { display: none !important; }
#ai-chat-widget .ai-chat-img-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.78);
}
#ai-chat-widget .ai-chat-img-modal-body {
  position: relative;
  width: min(980px, 96vw);
  max-height: 92vh;
  background: rgba(17,24,39,0.95);
  border: 1px solid rgba(255,255,255,0.10);
  border-radius: 18px;
  overflow: hidden;
  box-shadow: 0 30px 90px rgba(0,0,0,0.55);
  padding: 14px;
}
#ai-chat-widget .ai-chat-img-modal-close {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 40px;
  height: 40px;
  border-radius: 999px;
  border: 1px solid rgba(255,255,255,0.18);
  background: rgba(255,255,255,0.08);
  color: #fff;
  cursor: pointer;
}
#ai-chat-widget .ai-chat-img-modal-close:hover { background: rgba(255,255,255,0.14); }
#ai-chat-widget .ai-chat-img-modal-download {
  display: inline-block;
  margin: 6px 0 10px;
  color: rgba(167,243,208,1);
  text-decoration: underline;
  font-weight: 700;
  font-size: 13px;
}
#ai-chat-widget .ai-chat-img-modal-img {
  display: block;
  width: 100%;
  height: auto;
  max-height: calc(92vh - 90px);
  object-fit: contain;
  border-radius: 12px;
  background: rgba(0,0,0,0.25);
}
#ai-chat-widget .ai-chat-img-modal-caption {
  margin-top: 8px;
  color: rgba(229,231,235,0.9);
  font-size: 12px;
  word-break: break-word;
}

/* Mobile: panel becomes wide and height-aware */
@media (max-width: 640px) {
  #ai-chat-widget { left: 1rem !important; bottom: 1rem !important; }
  #ai-chat-panel {
    position: fixed !important;
    left: 1rem !important;
    right: 1rem !important;
    bottom: 5rem !important;
    width: auto !important;
    max-height: calc(100dvh - 7.5rem) !important;
  }
  #aiChatMessages { max-height: none !important; }
}
