/* ============================================================
   RESOLUTION ADVERTISING — AI CHAT WIDGET
   Premium floating chat with RAG-powered responses
   ============================================================ */

/* ─── CSS Variables ────────────────────────────────────────── */
.chat-widget {
  --cw-orange:     #FF6000;
  --cw-orange-d:   #e05500;
  --cw-orange-l:   #FF8C40;
  --cw-black:      #0a0a0a;
  --cw-dark:       #111111;
  --cw-surface:    #1a1a1a;
  --cw-border:     rgba(255,255,255,0.08);
  --cw-text:       #f0f0f0;
  --cw-muted:      rgba(255,255,255,0.5);
  --cw-user-bg:    var(--cw-orange);
  --cw-user-text:  #fff;
  --cw-bot-bg:     #222222;
  --cw-bot-text:   #f0f0f0;
  --cw-radius:     20px;
  --cw-w:          380px;
  --cw-h:          560px;
  --ease:          cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

/* ─── Trigger Button — aligned with WA button same column ──── */
.chat-trigger {
  position: fixed;
  /* Stacked directly above WA: WA-bottom + WA-size + gap */
  bottom: var(--fb-chat-bottom, 5.625rem);
  right:  var(--fb-x, 1.5rem);
  z-index: 1000;
  /* Same size as WA button */
  width:  var(--fb-size, 3.25rem);
  height: var(--fb-size, 3.25rem);
  border-radius: 50%;
  background: linear-gradient(135deg, #6B5BFF 0%, #5040E8 100%);
  color: #fff;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow:
    0 6px 28px rgba(91, 75, 255, 0.55),
    0 2px 8px  rgba(91, 75, 255, 0.3);
  transition: all 0.3s var(--ease);
  outline: none;
  overflow: hidden;
}

/* Animated shimmer ring */
.chat-trigger::before {
  content: '';
  position: absolute;
  inset: -3px;
  border-radius: 50%;
  background: conic-gradient(
    from 0deg,
    transparent 0%,
    rgba(255,255,255,0.35) 30%,
    transparent 60%
  );
  animation: triggerSpin 3s linear infinite;
  opacity: 0;
  transition: opacity 0.3s;
}

.chat-trigger:hover::before { opacity: 1; }

@keyframes triggerSpin {
  to { transform: rotate(360deg); }
}

.chat-trigger:hover {
  background: linear-gradient(135deg, #7B6BFF 0%, #6050F8 100%);
  transform: scale(1.1);
  box-shadow:
    0 10px 36px rgba(91, 75, 255, 0.65),
    0 3px 12px  rgba(91, 75, 255, 0.4);
}

/* ── Logo inner content (sparkle + Ai) — fixed direction ── */
.chat-trigger-logo {
  display: flex;
  align-items: center;
  flex-direction: row !important; /* ALWAYS: sparkle LEFT, Ai RIGHT — ignore RTL */
  gap: 4px;
  transition: all 0.3s var(--ease);
  position: relative;
  z-index: 1;
  unicode-bidi: plaintext;
}

.chat-trigger-logo .spark-icon {
  width: 1.2rem;
  height: 1.2rem;
  flex-shrink: 0;
  display: block;
  overflow: visible;
  filter: drop-shadow(0 0 3px rgba(255,255,255,0.5));
}

.chat-trigger-logo .ai-text {
  font-size: 0.95rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  color: #fff;
  line-height: 1;
  font-family: 'Manrope', 'Outfit', sans-serif;
  font-style: normal;
  direction: ltr; /* always LTR — "Ai" is Latin */
  unicode-bidi: embed;
}

/* Close X (shown when open) */
.chat-trigger-close {
  display: none;
  position: relative;
  z-index: 1;
}

.chat-trigger-close svg {
  width: 1.3rem;
  height: 1.3rem;
}

.chat-trigger.open .chat-trigger-logo { display: none; }
.chat-trigger.open .chat-trigger-close { display: flex; }

/* Hide one icon at a time — legacy selectors kept for compatibility */
.chat-trigger .icon-chat  { display: none; }
.chat-trigger .icon-close { display: none; }

/* Notification dot */
.chat-trigger .notif-dot {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: #22c55e;
  border: 2px solid #fff;
  animation: notifPulse 2s ease-in-out infinite;
}

@keyframes notifPulse {
  0%, 100% { transform: scale(1); }
  50%       { transform: scale(1.2); }
}

.chat-trigger.open .notif-dot { display: none; }

/* ─── Chat Panel ───────────────────────────────────────────── */
.chat-widget {
  position: fixed;
  bottom: calc(var(--fb-chat-bottom, 5.625rem) + var(--fb-size, 3.25rem) + 0.75rem);
  right: var(--fb-x, 1.5rem);

  z-index: 1002;

  width: var(--cw-w);
  max-width: calc(100vw - 3rem);

  /* Fit between navbar top and floating buttons bottom:
     viewport - 5rem navbar gap - button stack height (~10rem) */
  max-height: calc(100vh - 15rem);
  min-height: 300px;

  background: var(--cw-dark);
  border-radius: var(--cw-radius);
  box-shadow:
    0 24px 80px rgba(0,0,0,0.65),
    0 0 0 1px var(--cw-border);
  display: flex;
  flex-direction: column;
  overflow: hidden;

  /* Hidden state */
  opacity: 0;
  transform: translateY(16px) scale(0.97);
  pointer-events: none;
  transition: opacity 0.3s var(--ease),
              transform 0.3s var(--ease);
  transform-origin: bottom right;
}

.chat-widget.open {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: all;
}

/* ─── Drag Handle (mobile bottom sheet) ───────────────────── */
.cw-drag-handle {
  display: none;
  align-items: center;
  justify-content: center;
  padding: 0.6rem 0 0.2rem;
  background: var(--cw-black);
  cursor: grab;
  flex-shrink: 0;
}

.cw-drag-pill {
  width: 2.5rem;
  height: 4px;
  border-radius: 99px;
  background: rgba(255,255,255,0.2);
}

@media (max-width: 480px) {
  .cw-drag-handle { display: flex; }
}

/* ─── Header ───────────────────────────────────────────────── */
.cw-header {
  display: flex;
  align-items: center;
  gap: 0.875rem;
  padding: 1.125rem 1.25rem;
  background: linear-gradient(135deg, #120f2e 0%, #0e0c1e 100%);
  border-bottom: 1px solid rgba(107, 91, 255, 0.2);
  flex-shrink: 0;
  position: relative;
  overflow: hidden;
}

/* subtle purple glow top-left */
.cw-header::before {
  content: '';
  position: absolute;
  top: -20px;
  left: -20px;
  width: 80px;
  height: 80px;
  border-radius: 50%;
  background: rgba(107, 91, 255, 0.25);
  filter: blur(20px);
  pointer-events: none;
}

.cw-avatar {
  width: 2.5rem;
  height: 2.5rem;
  border-radius: 50%;
  background: linear-gradient(135deg, #6B5BFF, #5040E8);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  position: relative;
  box-shadow: 0 2px 12px rgba(107, 91, 255, 0.5);
}

.cw-avatar svg { width: 1.25rem; height: 1.25rem; color: #fff; }

.cw-avatar-status {
  position: absolute;
  bottom: 1px;
  right: 1px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #22c55e;
  border: 2px solid var(--cw-black);
}

.cw-info { flex: 1; min-width: 0; }

.cw-name {
  display: block;
  font-size: 0.9rem;
  font-weight: 700;
  color: #fff;
  line-height: 1.2;
}

.cw-status {
  display: block;
  font-size: 0.72rem;
  color: #22c55e;
  margin-top: 1px;
}

.cw-close {
  width: 2rem;
  height: 2rem;
  border-radius: 50%;
  background: rgba(255,255,255,0.07);
  color: var(--cw-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  border: none;
  transition: all 0.2s;
  flex-shrink: 0;
}

.cw-close svg { width: 1rem; height: 1rem; }
.cw-close:hover { background: rgba(255,255,255,0.14); color: #fff; }

/* ─── Messages Area ────────────────────────────────────────── */
.cw-messages {
  flex: 1;
  overflow-y: auto;
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.875rem;
  min-height: 200px;
  max-height: 420px;
  scroll-behavior: smooth;
}

/* Scrollbar */
.cw-messages::-webkit-scrollbar { width: 4px; }
.cw-messages::-webkit-scrollbar-track { background: transparent; }
.cw-messages::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 4px; }
.cw-messages::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.2); }

/* Welcome message */
.cw-welcome {
  text-align: center;
  padding: 1rem 0;
}

.cw-welcome-icon {
  width: 3.5rem;
  height: 3.5rem;
  border-radius: 50%;
  background: linear-gradient(135deg, #6B5BFF 0%, #5040E8 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 0.875rem;
  box-shadow: 0 4px 20px rgba(107, 91, 255, 0.5);
  animation: welcomeIconPulse 3s ease-in-out infinite;
}

@keyframes welcomeIconPulse {
  0%, 100% { box-shadow: 0 4px 20px rgba(107, 91, 255, 0.5); }
  50%       { box-shadow: 0 6px 28px rgba(107, 91, 255, 0.75); }
}

.cw-welcome-icon svg { width: 1.75rem; height: 1.75rem; color: #fff; }

.cw-welcome h4 {
  font-size: 1rem;
  font-weight: 700;
  color: #fff;
  margin-bottom: 0.375rem;
}

.cw-welcome p {
  font-size: 0.8rem;
  color: var(--cw-muted);
  line-height: 1.6;
  max-width: 260px;
  margin: 0 auto 1.25rem;
}

/* Quick suggestions */
.cw-suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  justify-content: center;
  margin-top: 0.5rem;
}

.cw-suggestion {
  padding: 0.375rem 0.875rem;
  background: var(--cw-surface);
  border: 1px solid var(--cw-border);
  border-radius: 999px;
  font-size: 0.75rem;
  color: rgba(255,255,255,0.75);
  cursor: pointer;
  transition: all 0.2s;
  font-family: inherit;
}

.cw-suggestion:hover {
  background: linear-gradient(135deg, #6B5BFF, #5040E8);
  border-color: #6B5BFF;
  color: #fff;
}

/* ─── Message Row ──────────────────────────────────────────── */
.cw-msg {
  display: flex;
  align-items: flex-end;
  gap: 0.5rem;
  animation: msgIn 0.28s var(--ease) both;
  width: 100%;
}

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

/* User messages: avatar RIGHT, bubble LEFT */
.cw-msg.user {
  flex-direction: row-reverse;
}

/* ─── Avatar ───────────────────────────────────────────────── */
.cw-msg-avatar {
  width: 1.75rem;
  height: 1.75rem;
  min-width: 1.75rem; /* never shrink */
  border-radius: 50%;
  background: linear-gradient(135deg, #6B5BFF, #5040E8);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  box-shadow: 0 1px 6px rgba(107, 91, 255, 0.35);
  align-self: flex-end; /* stick to bottom of message */
}

.cw-msg-avatar svg { width: 0.8rem; height: 0.8rem; }

.cw-msg.user .cw-msg-avatar {
  background: rgba(255,255,255,0.1);
  box-shadow: none;
}

/* ─── Body (bubble + timestamp) ────────────────────────────── */
.cw-msg-body {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  max-width: calc(100% - 2.25rem); /* full width minus avatar+gap */
  min-width: 0;
}

/* ─── Bubble ───────────────────────────────────────────────── */
.cw-bubble {
  display: inline-block; /* shrink-wrap to content */
  max-width: 100%;
  padding: 0.6rem 0.9rem;
  border-radius: 14px;
  font-size: 0.875rem;
  line-height: 1.55;
  /* CRITICAL: overflow-wrap only breaks long URLs, never short words */
  overflow-wrap: break-word;
  word-break: normal;
  white-space: pre-wrap; /* preserve intentional newlines */
}

.cw-msg.bot  .cw-bubble {
  background: var(--cw-bot-bg);
  color: var(--cw-bot-text);
  border-bottom-left-radius: 4px;
  align-self: flex-start;
}

.cw-msg.user .cw-bubble {
  background: var(--cw-user-bg);
  color: #fff;
  border-bottom-right-radius: 4px;
  align-self: flex-end;
}

/* ─── Timestamp ─────────────────────────────────────────────── */
.cw-msg-time {
  display: block;
  font-size: 0.62rem;
  color: var(--cw-muted);
  padding: 0 0.25rem;
  text-align: right;
}

.cw-msg.bot .cw-msg-time { text-align: left; }

/* ─── Typing Indicator ─────────────────────────────────────── */
.cw-typing {
  display: flex;
  gap: 0.625rem;
  align-items: flex-end;
  animation: msgIn 0.3s var(--ease) both;
}

.cw-typing-bubble {
  background: var(--cw-bot-bg);
  border-radius: 16px;
  border-bottom-left-radius: 4px;
  padding: 0.75rem 1rem;
  display: flex;
  gap: 5px;
  align-items: center;
}

.cw-typing-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #6B5BFF;
  animation: typingBounce 1.2s ease-in-out infinite;
}

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

@keyframes typingBounce {
  0%, 60%, 100% { transform: translateY(0);    opacity: 0.4; }
  30%           { transform: translateY(-6px); opacity: 1;   }
}

/* ─── Input Area ───────────────────────────────────────────── */
.cw-input-area {
  padding: 1rem;
  border-top: 1px solid var(--cw-border);
  background: var(--cw-black);
  flex-shrink: 0;
}

.cw-input-row {
  display: flex;
  align-items: flex-end;
  gap: 0.625rem;
  background: var(--cw-surface);
  border: 1px solid var(--cw-border);
  border-radius: 14px;
  padding: 0.5rem 0.5rem 0.5rem 1rem;
  transition: border-color 0.2s;
}

.cw-input-row:focus-within {
  border-color: #6B5BFF;
  box-shadow: 0 0 0 3px rgba(107, 91, 255, 0.15);
}

.cw-input {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  resize: none;
  font-size: 0.875rem;
  color: var(--cw-text);
  font-family: inherit;
  line-height: 1.5;
  max-height: 100px;
  min-height: 1.5rem;
  overflow-y: auto;
}

.cw-input::placeholder { color: var(--cw-muted); }

.cw-send {
  width: 2.25rem;
  height: 2.25rem;
  border-radius: 10px;
  background: linear-gradient(135deg, #6B5BFF, #5040E8);
  color: #fff;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all 0.2s;
}

.cw-send svg { width: 1.1rem; height: 1.1rem; }
.cw-send:hover { background: linear-gradient(135deg, #7B6BFF, #6050F8); transform: scale(1.05); }
.cw-send:hover { background: var(--cw-orange-d); transform: scale(1.05); }
.cw-send:disabled { background: #333; cursor: not-allowed; transform: none; }

/* ─── Footer branding ──────────────────────────────────────── */
.cw-footer {
  text-align: center;
  padding: 0.5rem 1rem 0.75rem;
  background: var(--cw-black);
}

.cw-footer span {
  font-size: 0.62rem;
  color: rgba(255,255,255,0.2);
  letter-spacing: 0.05em;
}

.cw-footer strong { color: #6B5BFF; font-weight: 700; }

/* ─── Mobile Backdrop ──────────────────────────────────────── */
.cw-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  z-index: 1000;
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
  opacity: 0;
  transition: opacity 0.3s ease;
  pointer-events: none;
}

@media (max-width: 480px) {
  .cw-backdrop {
    display: block;
  }
  .cw-backdrop.cw-backdrop-visible {
    opacity: 1;
    pointer-events: all;
  }
}

/* ─── RTL support ──────────────────────────────────────────── */

/* Buttons: stack vertically on the LEFT in RTL (same x = 2rem from left) */
[dir="rtl"] .chat-trigger {
  right: auto;
  left: 2rem;       /* same column as WA button */
  bottom: 6.5rem;   /* stacked above WA */
}

[dir="rtl"] .chat-widget {
  right: auto;
  left: 2rem;
  transform-origin: bottom left;
}

[dir="rtl"] .chat-widget.open {
  transform: translateY(0) scale(1);
}

/* Logo always LTR: sparkle left, Ai right — override RTL flex */
[dir="rtl"] .chat-trigger-logo {
  flex-direction: row !important;
}

/* RTL message direction:
   LTR user: [body-LEFT] [avatar-RIGHT]  (row-reverse)
   RTL user: [avatar-LEFT] [body-RIGHT]  (row = natural RTL)
*/
[dir="rtl"] .cw-msg.user { flex-direction: row; }
[dir="rtl"] .cw-msg.bot  { flex-direction: row-reverse; }

/* RTL bubble radius */
[dir="rtl"] .cw-msg.user .cw-bubble {
  border-bottom-right-radius: 14px;
  border-bottom-left-radius:  4px;
  align-self: flex-start;
}
[dir="rtl"] .cw-msg.bot .cw-bubble {
  border-bottom-left-radius:  14px;
  border-bottom-right-radius: 4px;
  align-self: flex-end;
}
[dir="rtl"] .cw-msg.user .cw-msg-time { text-align: left; }
[dir="rtl"] .cw-msg.bot  .cw-msg-time { text-align: right; }

/* Input area */
[dir="rtl"] .cw-input-row { flex-direction: row-reverse; }
[dir="rtl"] .cw-input { text-align: right; direction: rtl; }
[dir="rtl"] .cw-input::placeholder { text-align: right; }
[dir="rtl"] .cw-suggestions { flex-direction: row-reverse; flex-wrap: wrap; }

/* Header */
[dir="rtl"] .cw-header { direction: rtl; }
[dir="rtl"] .cw-info   { text-align: right; }

/* ─── Tablet 481–768px ─────────────────────────────────────── */
@media (max-width: 768px) {
  .chat-widget {
    --cw-w: 340px;
    max-width: calc(100vw - 2rem);
  }
  .cw-messages { max-height: 340px; }
}

/* ─── Mobile ≤480px: full-screen bottom sheet ──────────────── */
@media (max-width: 480px) {

  /* ── Panel: full width, slides up from bottom ── */
  .chat-widget {
    bottom:     0 !important;
    right:      0 !important;
    left:       0 !important;
    width:      100vw !important;
    max-width:  100vw !important;
    max-height: 92vh;
    border-radius: 20px 20px 0 0;
    transform-origin: bottom center;
    transform: translateY(100%);
    transition: transform 0.4s cubic-bezier(0.32, 0.72, 0, 1);
    z-index: 1001;  /* above the trigger button */
  }

  .chat-widget.open {
    transform: translateY(0);
    opacity: 1;
  }

  /* ── Hide the floating trigger when chat is open ──
     (header's × button handles closing on mobile)   */
  .chat-trigger.open {
    opacity: 0 !important;
    pointer-events: none !important;
    transform: scale(0) !important;
  }

  /* ── Messages area ── */
  .cw-messages {
    max-height: calc(92vh - 160px); /* panel height - header - input */
    min-height: 200px;
  }

  /* ── Header compact ── */
  .cw-header { padding: 0.875rem 1rem; }
  .cw-avatar { width: 2.125rem; height: 2.125rem; }
  .cw-name   { font-size: 0.85rem; }
  .cw-status { font-size: 0.65rem; }

  /* ── Bubbles compact ── */
  .cw-bubble {
    padding:   0.55rem 0.8rem;
    font-size: 0.845rem;
    line-height: 1.5;
  }

  .cw-msg-avatar {
    width:     1.5rem;
    height:    1.5rem;
    min-width: 1.5rem;
  }
  .cw-msg-avatar svg { width: 0.72rem; height: 0.72rem; }

  /* ── Input area ── */
  .cw-input-area { padding: 0.75rem; }
  .cw-input-row  { padding: 0.4rem 0.4rem 0.4rem 0.875rem; }
  .cw-input      { font-size: 0.875rem; }
  .cw-send       { width: 2rem; height: 2rem; border-radius: 8px; }
  .cw-send svg   { width: 1rem; height: 1rem; }

  /* ── Suggestions ── */
  .cw-suggestions { gap: 0.375rem; padding: 0 0.25rem; }
  .cw-suggestion  { font-size: 0.72rem; padding: 0.35rem 0.75rem; }

  /* ── Welcome screen compact ── */
  .cw-welcome { padding: 0.5rem 0; }
  .cw-welcome-icon { width: 2.75rem; height: 2.75rem; margin-bottom: 0.75rem; }
  .cw-welcome h4   { font-size: 0.9rem; }
  .cw-welcome p    { font-size: 0.775rem; margin-bottom: 1rem; }

  /* ── Footer ── */
  .cw-footer { padding: 0.375rem; }
  .cw-footer span { font-size: 0.58rem; }

  /* ── Messages padding ── */
  .cw-messages { padding: 1rem; gap: 0.75rem; }
}
