/**
 * WebChat AI - Frontend Widget Styles
 * Sleek, modern floating chat interface inspired by Tidio & Lyro AI.
 */

:root {
  --wcai-theme-color: #4F46E5;
  --wcai-theme-hover: #4338CA;
  --wcai-font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --wcai-bg-light: #F8FAFC;
  --wcai-text-main: #0F172A;
  --wcai-text-muted: #64748B;
  --wcai-border: #E2E8F0;
  --wcai-shadow-bubble: 0 4px 14px rgba(0, 0, 0, 0.16);
  --wcai-shadow-drawer: 0 12px 36px rgba(15, 23, 42, 0.16), 0 4px 12px rgba(15, 23, 42, 0.08);
  --wcai-radius-lg: 18px;
  --wcai-radius-md: 12px;
  --wcai-radius-sm: 8px;
  --wcai-zindex: 999999;
}

/* Root Container */
.wcai-widget-container {
  position: fixed;
  z-index: var(--wcai-zindex);
  font-family: var(--wcai-font-sans);
  line-height: 1.5;
  color: var(--wcai-text-main);
  box-sizing: border-box;
}.wcai-widget-container *,
.wcai-widget-container *::before,
.wcai-widget-container *::after {
  box-sizing: border-box;
}

/* Positions */
.wcai-position-bottom-right {
  bottom: 24px;
  right: 24px;
}

.wcai-position-bottom-left {
  bottom: 24px;
  left: 24px;
}

@media (max-width: 480px) {
  .wcai-position-bottom-right,
  .wcai-position-bottom-left {
    bottom: calc(16px + env(safe-area-inset-bottom, 0px));
    right: calc(16px + env(safe-area-inset-right, 0px));
    left: auto;
  }
}

/* Floating Launcher Button */
.wcai-launcher-btn {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: var(--wcai-theme-color);
  color: #FFFFFF;
  border: none;
  cursor: pointer;
  box-shadow: var(--wcai-shadow-bubble);
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  transition: transform 0.25s cubic-bezier(0.34, 1.56, 0.64, 1), background-color 0.2s ease, box-shadow 0.2s ease;
  outline: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.wcai-launcher-btn:focus-visible,
.wcai-action-btn:focus-visible,
.wcai-send-btn:focus-visible,
.wcai-chip-btn:focus-visible,
.wcai-lead-submit:focus-visible {
  outline: 3px solid rgba(79, 70, 229, 0.45);
  outline-offset: 2px;
}

.wcai-launcher-btn:hover {
  transform: scale(1.08);
  box-shadow: 0 6px 20px rgba(79, 70, 229, 0.4);
}

.wcai-launcher-btn:active {
  transform: scale(0.95);
}

.wcai-launcher-icon-chat,
.wcai-launcher-icon-close {
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity 0.2s ease, transform 0.25s ease;
}

.wcai-launcher-icon-close {
  position: absolute;
  opacity: 0;
  transform: rotate(-90deg) scale(0.5);
}

.wcai-widget-container.wcai-open .wcai-launcher-icon-chat {
  opacity: 0;
  transform: rotate(90deg) scale(0.5);
}

.wcai-widget-container.wcai-open .wcai-launcher-icon-close {
  opacity: 1;
  transform: rotate(0) scale(1);
}

/* Notification Ping Dot */
.wcai-ping-indicator {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 14px;
  height: 14px;
  background-color: #10B981;
  border: 2px solid #FFFFFF;
  border-radius: 50%;
  animation: wcai-pulse 2s infinite;
}

@keyframes wcai-pulse {
  0% { box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.7); }
  70% { box-shadow: 0 0 0 8px rgba(16, 185, 129, 0); }
  100% { box-shadow: 0 0 0 0 rgba(16, 185, 129, 0); }
}

.wcai-widget-container.wcai-open .wcai-ping-indicator {
  display: none;
}

/* Chat Drawer Window */
.wcai-drawer-window {
  position: absolute;
  bottom: 76px;
  width: 390px;
  max-width: calc(100vw - 32px);
  height: 610px;
  max-height: calc(100vh - 110px);
  background: #FFFFFF;
  border-radius: var(--wcai-radius-lg);
  box-shadow: var(--wcai-shadow-drawer);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  opacity: 0;
  pointer-events: none;
  transform: translateY(20px) scale(0.95);
  transform-origin: bottom right;
  transition: opacity 0.28s cubic-bezier(0.16, 1, 0.3, 1), transform 0.28s cubic-bezier(0.16, 1, 0.3, 1);
  border: 1px solid var(--wcai-border);
}

.wcai-position-bottom-right .wcai-drawer-window {
  right: 0;
  transform-origin: bottom right;
}

.wcai-position-bottom-left .wcai-drawer-window {
  left: 0;
  transform-origin: bottom left;
}

.wcai-widget-container.wcai-open .wcai-drawer-window {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0) scale(1);
}

/* Header Bar */
.wcai-header-bar {
  background: var(--wcai-theme-color);
  color: #FFFFFF;
  padding: 16px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.wcai-header-info {
  display: flex;
  align-items: center;
  gap: 12px;
}

.wcai-avatar-wrap {
  position: relative;
  width: 42px;
  height: 42px;
  flex-shrink: 0;
}

.wcai-avatar-img {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  object-fit: cover;
  background: rgba(255, 255, 255, 0.2);
  display: block;
}

.wcai-online-dot {
  position: absolute;
  bottom: 0;
  right: 0;
  width: 11px;
  height: 11px;
  background: #10B981;
  border: 2px solid #FFFFFF;
  border-radius: 50%;
}

.wcai-header-text {
  display: flex;
  flex-direction: column;
}

.wcai-header-title {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
  color: #FFFFFF;
  line-height: 1.2;
}

.wcai-header-status {
  margin: 3px 0 0 0;
  font-size: 12px;
  color: rgba(255, 255, 255, 0.85);
  display: flex;
  align-items: center;
  gap: 6px;
}

.wcai-status-pulse {
  width: 6px;
  height: 6px;
  background: #34D399;
  border-radius: 50%;
}

.wcai-header-actions {
  display: flex;
  align-items: center;
  gap: 4px;
}

.wcai-action-btn {
  background: transparent;
  border: none;
  color: rgba(255, 255, 255, 0.8);
  width: 32px;
  height: 32px;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s ease, color 0.15s ease;
  outline: none;
}

.wcai-action-btn:hover {
  background: rgba(255, 255, 255, 0.2);
  color: #FFFFFF;
}

/* Messages Wrap */
.wcai-messages-wrap {
  flex: 1;
  padding: 16px;
  overflow-y: auto;
  background: var(--wcai-bg-light);
  display: flex;
  flex-direction: column;
  gap: 14px;
  scroll-behavior: smooth;
}

.wcai-messages-wrap::-webkit-scrollbar {
  width: 6px;
}

.wcai-messages-wrap::-webkit-scrollbar-thumb {
  background: #CBD5E1;
  border-radius: 3px;
}

.wcai-messages-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* Message Rows */
.wcai-message-row {
  display: flex;
  gap: 8px;
  max-width: 88%;
  align-items: flex-end;
}

.wcai-message-row.wcai-user {
  align-self: flex-end;
  flex-direction: row-reverse;
}

.wcai-message-row.wcai-assistant {
  align-self: flex-start;
}

.wcai-msg-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  flex-shrink: 0;
  margin-bottom: 2px;
}

.wcai-bubble-wrap {
  display: flex;
  flex-direction: column;
}

.wcai-message-row.wcai-user .wcai-bubble-wrap {
  align-items: flex-end;
}

.wcai-message-bubble {
  padding: 11px 15px;
  border-radius: 16px;
  font-size: 14px;
  line-height: 1.5;
  word-break: break-word;
}

.wcai-message-row.wcai-user .wcai-message-bubble {
  background: var(--wcai-theme-color) !important;
  color: #FFFFFF !important;
  border-bottom-right-radius: 4px;
}

.wcai-message-row.wcai-user .wcai-message-bubble,
.wcai-message-row.wcai-user .wcai-message-bubble *,
.wcai-message-row.wcai-user .wcai-message-bubble p,
.wcai-message-row.wcai-user .wcai-message-bubble span,
.wcai-message-row.wcai-user .wcai-message-bubble div,
.wcai-message-row.wcai-user .wcai-message-bubble li,
.wcai-message-row.wcai-user .wcai-message-bubble strong,
.wcai-message-row.wcai-user .wcai-message-bubble em {
  color: #FFFFFF !important;
}

.wcai-message-row.wcai-assistant .wcai-message-bubble {
  background: #FFFFFF !important;
  color: #0F172A !important;
  border: 1px solid var(--wcai-border);
  border-bottom-left-radius: 4px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
}

.wcai-message-row.wcai-assistant .wcai-message-bubble.wcai-is-error {
  background: #FEF2F2 !important;
  border-color: #FECACA !important;
}

.wcai-message-row.wcai-assistant .wcai-message-bubble.wcai-is-error,
.wcai-message-row.wcai-assistant .wcai-message-bubble.wcai-is-error * {
  color: #991B1B !important;
}

/* Force dark readable text on all assistant child elements regardless of theme */
.wcai-message-row.wcai-assistant .wcai-message-bubble,
.wcai-message-row.wcai-assistant .wcai-message-bubble *,
.wcai-message-row.wcai-assistant .wcai-message-bubble p,
.wcai-message-row.wcai-assistant .wcai-message-bubble span,
.wcai-message-row.wcai-assistant .wcai-message-bubble div,
.wcai-message-row.wcai-assistant .wcai-message-bubble li,
.wcai-message-row.wcai-assistant .wcai-message-bubble strong,
.wcai-message-row.wcai-assistant .wcai-message-bubble em {
  color: #0F172A !important;
}

.wcai-message-bubble p {
  margin: 0 0 8px 0 !important;
  line-height: 1.5 !important;
}

.wcai-message-bubble p:last-child {
  margin-bottom: 0 !important;
}

.wcai-message-bubble ul,
.wcai-message-bubble ol {
  margin: 6px 0 !important;
  padding-left: 18px !important;
}

.wcai-message-bubble li {
  margin-bottom: 4px !important;
}

.wcai-message-row.wcai-assistant .wcai-message-bubble a {
  color: var(--wcai-theme-color) !important;
  text-decoration: underline !important;
  font-weight: 500 !important;
}

.wcai-message-row.wcai-user .wcai-message-bubble a {
  color: #FFFFFF !important;
  text-decoration: underline !important;
}

.wcai-timestamp {
  font-size: 10.5px;
  color: var(--wcai-text-muted);
  margin-top: 4px;
  padding: 0 4px;
}

/* Citations & Sources Box */
.wcai-sources-box {
  margin-top: 10px;
  padding-top: 8px;
  border-top: 1px dashed var(--wcai-border);
}

.wcai-sources-title {
  font-size: 11px;
  font-weight: 600;
  color: var(--wcai-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.4px;
  margin-bottom: 5px;
}

.wcai-sources-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.wcai-source-link {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: #EEF2FF;
  color: var(--wcai-theme-color) !important;
  font-size: 11.5px;
  padding: 3px 8px;
  border-radius: 12px;
  text-decoration: none !important;
  border: 1px solid rgba(79, 70, 229, 0.15);
  transition: background 0.15s ease;
}

.wcai-source-link:hover {
  background: #E0E7FF;
}

/* Quick Suggestion Chips */
.wcai-suggestions-chips {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 4px;
}

.wcai-chip-btn {
  background: #FFFFFF !important;
  border: 1px solid var(--wcai-border) !important;
  color: #0F172A !important;
  padding: 8px 12px;
  border-radius: var(--wcai-radius-md);
  font-size: 12.5px;
  text-align: left;
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease, transform 0.15s ease;
  outline: none;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
}

.wcai-chip-btn:hover {
  border-color: var(--wcai-theme-color) !important;
  background: #F5F3FF !important;
  color: var(--wcai-theme-color) !important;
  transform: translateX(3px);
}

/* Follow-up suggestions rendered after each answer */
.wcai-followup-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--wcai-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.4px;
  margin: 4px 0 2px 2px;
}

.wcai-followup-chips {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.wcai-chip-followup {
  background: #EEF2FF !important;
  border-color: rgba(79, 70, 229, 0.2) !important;
  color: var(--wcai-theme-color) !important;
  font-weight: 500;
}

.wcai-chip-retry {
  align-self: flex-start;
  background: #FEF2F2 !important;
  border-color: #FECACA !important;
  color: #B91C1C !important;
  font-weight: 600;
}

/* Animated Typing Bubble */
.wcai-typing-bubble {
  align-self: flex-start;
  display: flex;
  align-items: center;
  gap: 4px;
  background: #FFFFFF;
  border: 1px solid var(--wcai-border);
  padding: 10px 14px;
  border-radius: 16px;
  border-bottom-left-radius: 4px;
  width: fit-content;
}

.wcai-dot {
  width: 6px;
  height: 6px;
  background: #94A3B8;
  border-radius: 50%;
  animation: wcai-bounce 1.4s infinite ease-in-out both;
}

.wcai-dot:nth-child(1) { animation-delay: -0.32s; }
.wcai-dot:nth-child(2) { animation-delay: -0.16s; }

@keyframes wcai-bounce {
  0%, 80%, 100% { transform: scale(0); }
  40% { transform: scale(1); }
}

/* Lead Capture Card */
.wcai-lead-view {
  flex: 1;
  padding: 24px 20px;
  background: #FFFFFF;
  display: flex;
  align-items: center;
  justify-content: center;
}

.wcai-lead-card {
  width: 100%;
  text-align: center;
}

.wcai-lead-icon {
  width: 54px;
  height: 54px;
  margin: 0 auto 12px;
  background: #EEF2FF;
  color: var(--wcai-theme-color);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.wcai-lead-title {
  margin: 0 0 6px 0;
  font-size: 18px;
  font-weight: 700;
  color: var(--wcai-text-main);
}

.wcai-lead-desc {
  margin: 0 0 18px 0;
  font-size: 13px;
  color: var(--wcai-text-muted);
}

.wcai-form-group {
  margin-bottom: 12px;
  text-align: left;
}

.wcai-form-group label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--wcai-text-main);
  margin-bottom: 4px;
}

.wcai-form-group input {
  width: 100%;
  padding: 10px 12px;
  font-size: 13.5px;
  border: 1px solid var(--wcai-border);
  border-radius: var(--wcai-radius-sm);
  outline: none;
  transition: border-color 0.15s ease;
}

.wcai-form-group input:focus {
  border-color: var(--wcai-theme-color);
}

.wcai-lead-submit {
  width: 100%;
  margin-top: 8px;
  background: var(--wcai-theme-color);
  color: #FFFFFF;
  border: none;
  padding: 11px;
  border-radius: var(--wcai-radius-sm);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: background 0.15s ease;
}

.wcai-lead-submit:hover {
  background: var(--wcai-theme-hover);
}

/* Footer & Input Bar */
.wcai-footer-bar {
  background: #FFFFFF;
  border-top: 1px solid var(--wcai-border);
  padding: 10px 12px 6px;
}

.wcai-input-form {
  margin: 0;
}

.wcai-input-wrap {
  display: flex;
  align-items: flex-end;
  background: var(--wcai-bg-light);
  border: 1px solid var(--wcai-border);
  border-radius: 20px;
  padding: 6px 8px 6px 14px;
  gap: 6px;
  transition: border-color 0.15s ease;
}

.wcai-input-wrap:focus-within {
  border-color: var(--wcai-theme-color);
  background: #FFFFFF;
}

.wcai-input-wrap textarea {
  flex: 1;
  background: transparent !important;
  border: none !important;
  outline: none !important;
  font-family: inherit !important;
  font-size: 14px !important;
  color: #0F172A !important;
  resize: none !important;
  max-height: 100px;
  line-height: 1.4 !important;
  padding: 4px 0 !important;
  display: block;
}

.wcai-input-wrap textarea::placeholder {
  color: #94A3B8 !important;
  opacity: 1 !important;
}

.wcai-send-btn {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--wcai-theme-color);
  color: #FFFFFF;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: transform 0.15s ease, opacity 0.15s ease;
  outline: none;
}

.wcai-send-btn:hover {
  transform: scale(1.05);
}

.wcai-send-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  transform: none;
}

/* Branding Badge */
.wcai-branding-row {
  text-align: center;
  padding-top: 6px;
  font-size: 11px;
}

.wcai-branding-row a {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  color: var(--wcai-text-muted);
  text-decoration: none;
  transition: color 0.15s ease;
}

.wcai-branding-row a:hover {
  color: var(--wcai-theme-color);
}

/* Responsive Mobile Rules */
@media (max-width: 480px) {
  .wcai-widget-container.wcai-position-bottom-right,
  .wcai-widget-container.wcai-position-bottom-left {
    bottom: 16px;
    right: 16px;
    left: auto;
  }

  .wcai-drawer-window {
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    right: 0;
    width: 100vw;
    height: 100vh;
    max-width: 100vw;
    max-height: 100vh;
    border-radius: 0;
    border: none;
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }

  .wcai-widget-container.wcai-open .wcai-launcher-btn {
    display: none;
  }
}

/* Prevent iOS zoom by keeping inputs >= 16px */
.wcai-form-group input,
.wcai-input-wrap textarea {
  font-size: 16px;
}

@media (min-width: 481px) {
  .wcai-form-group input,
  .wcai-input-wrap textarea {
    font-size: 14px;
  }
}

/* Respect reduced-motion preferences */
@media (prefers-reduced-motion: reduce) {
  .wcai-launcher-btn,
  .wcai-drawer-window,
  .wcai-launcher-icon-chat,
  .wcai-launcher-icon-close,
  .wcai-ping-indicator,
  .wcai-dot {
    animation: none !important;
    transition: none !important;
  }
}
