/* ============================================================
   AJ Chat Widget - chat.css
   Deep navy theme · No shadows · Reduced hover contrast
   ============================================================ */

/* ── Widget root ───────────────────────────────────────────── */
.cw {
  --cw-accent:      #3D7AE8;
  --cw-accent-dark: #2D69D4;
  --cw-bg:          #0B1422;
  --cw-surface:     #111C2D;
  --cw-border:      rgba(255,255,255,.06);
  --cw-text:        rgba(255,255,255,.92);
  --cw-text-2:      rgba(255,255,255,.55);
  --cw-text-3:      rgba(255,255,255,.34);
  --cw-radius:      14px;
  --cw-font:        'Inter', 'Segoe UI', system-ui, sans-serif;

  position: fixed;
  bottom: 22px;
  right: 22px;
  z-index: 9500;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 12px;
  font-family: var(--cw-font);
}

/* ── Trigger button ─────────────────────────────────────────── */
.cw__trigger {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: var(--cw-accent);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  transition: background 0.18s ease-out;
  flex-shrink: 0;
}
.cw__trigger:hover { background: var(--cw-accent-dark); }
.cw__trigger:active { opacity: .92; }

.cw__trigger-avatar {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  object-fit: cover;
  display: block;
}
.cw__trigger-icon {
  width: 24px;
  height: 24px;
  color: #fff;
  transition: opacity 0.18s ease, transform 0.18s ease;
  position: absolute;
}
.cw__trigger-icon--close {
  opacity: 0;
  transform: rotate(-90deg) scale(.7);
}

/* When panel is open, swap icons */
.cw[data-state="open"] .cw__trigger-icon--chat,
.cw[data-state="open"] .cw__trigger-avatar { opacity: 0; }
.cw[data-state="open"] .cw__trigger-icon--close {
  opacity: 1;
  transform: rotate(0) scale(1);
}

/* Unread badge */
.cw__unread-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  min-width: 18px;
  height: 18px;
  background: #EF4444;
  color: #fff;
  font-size: .68rem;
  font-weight: 700;
  border-radius: 10px;
  padding: 0 5px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid var(--cw-bg);
  animation: cw-pulse 2s ease infinite;
}
@keyframes cw-pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.12); }
}

/* ── Panel ──────────────────────────────────────────────────── */
.cw__panel {
  width: 348px;
  max-height: min(560px, calc(100vh - 110px));
  background: var(--cw-bg);
  border: 1px solid var(--cw-border);
  border-radius: var(--cw-radius);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transform-origin: bottom right;
  animation: cw-open 0.22s cubic-bezier(.16,1,.3,1);
}
/* Once a conversation has started, lock the panel to a consistent
   tall height so it doesn't look short with few messages and doesn't
   jump/resize as the exchange grows. */
.cw__panel--tall {
  height: min(560px, calc(100vh - 110px));
}
.cw__panel[hidden],
.cw__view[hidden],
.cw__end-chat[hidden],
.cw__unread-badge[hidden] {
  display: none !important;
}
@keyframes cw-open {
  from { opacity: 0; transform: scale(.9); }
  to   { opacity: 1; transform: scale(1); }
}

/* ── Header ─────────────────────────────────────────────────── */
.cw__header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
  background: var(--cw-surface);
  border-bottom: 1px solid var(--cw-border);
  flex-shrink: 0;
}
.cw__header-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--cw-accent);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  position: relative;
  color: #fff;
  overflow: hidden;
}
.cw__header-avatar img { width: 100%; height: 100%; object-fit: cover; border-radius: 50%; }
.cw__online-dot {
  position: absolute;
  bottom: 0;
  right: 0;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #10B981;
  border: 2px solid var(--cw-surface);
}
.cw__online-dot.offline { background: #6B7280; }
.cw__header-info { flex: 1; min-width: 0; }
.cw__name {
  display: block;
  font-size: .88rem;
  font-weight: 600;
  color: var(--cw-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.cw__status {
  display: block;
  font-size: .72rem;
  color: var(--cw-text-2);
  margin-top: 1px;
}
.cw__close {
  width: 30px;
  height: 30px;
  border: none;
  background: transparent;
  color: var(--cw-text-2);
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, color 0.15s;
  flex-shrink: 0;
}
.cw__close svg { width: 16px; height: 16px; }
.cw__close:hover { background: rgba(255,255,255,.06); color: var(--cw-text); }
.cw__end-chat {
  border: 1px solid rgba(239,68,68,.35);
  background: rgba(239,68,68,.1);
  color: #FCA5A5;
  border-radius: 999px;
  padding: 6px 10px;
  font-size: .72rem;
  font-weight: 700;
  cursor: pointer;
  transition: background .15s, color .15s, border-color .15s;
  white-space: nowrap;
}
.cw__end-chat:hover {
  background: rgba(239,68,68,.18);
  border-color: rgba(239,68,68,.55);
  color: #fff;
}

/* ── Views ──────────────────────────────────────────────────── */
.cw__view {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-height: 0;
  background:
    radial-gradient(circle at 18px 18px, rgba(61,122,232,.16) 0 1px, transparent 1.5px),
    linear-gradient(135deg, rgba(255,255,255,.03) 0 1px, transparent 1px);
  background-size: 28px 28px, 74px 74px;
}
.cw__view--center {
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 32px 24px;
  gap: 8px;
}

/* Launcher / knowledge base */
.cw__launcher {
  padding: 4px 18px 18px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.cw__launcher-label {
  margin: 0 0 2px;
  font-size: .72rem;
  font-weight: 800;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--cw-text-3);
}
.cw__quick-question {
  width: 100%;
  border: 1px solid var(--cw-border);
  background: var(--cw-surface);
  color: var(--cw-text-2);
  border-radius: 12px;
  padding: 12px 13px;
  text-align: left;
  font: inherit;
  font-size: .84rem;
  line-height: 1.4;
  cursor: pointer;
  transition: border-color .15s, color .15s, background .15s;
}
.cw__quick-question:hover {
  border-color: rgba(61,122,232,.44);
  color: var(--cw-text);
  background: rgba(61,122,232,.09);
}
.cw__launcher-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 8px;
}
.cw__secondary-btn,
.cw__back-btn {
  background: transparent;
  color: var(--cw-text-2);
  border: 1px solid var(--cw-border);
  border-radius: 8px;
  padding: 10px 14px;
  font-size: .875rem;
  font-weight: 700;
  cursor: pointer;
  font-family: var(--cw-font);
  transition: border-color .15s, color .15s, background .15s;
}
.cw__secondary-btn:hover,
.cw__back-btn:hover {
  background: rgba(255,255,255,.045);
  border-color: rgba(255,255,255,.16);
  color: var(--cw-text);
}
.cw__kb-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--cw-border);
  color: var(--cw-text);
}
.cw__back-btn {
  width: auto;
  padding: 7px 10px;
  font-size: .76rem;
}
.cw__kb-list {
  flex: 1;
  overflow-y: auto;
  padding: 12px 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.cw__kb-article {
  border: 1px solid var(--cw-border);
  border-radius: 12px;
  background: var(--cw-surface);
  padding: 12px;
}
.cw__kb-article small {
  display: block;
  color: var(--cw-accent);
  font-size: .68rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: .07em;
  margin-bottom: 6px;
}
.cw__kb-article strong {
  display: block;
  color: var(--cw-text);
  font-size: .88rem;
  margin-bottom: 6px;
}
.cw__kb-article p,
.cw__kb-empty {
  margin: 0;
  color: var(--cw-text-2);
  font-size: .82rem;
  line-height: 1.55;
}

.cw__kb-faq-head {
  margin: 14px 0 6px;
  font-size: .72rem; font-weight: 700; letter-spacing: .04em;
  text-transform: uppercase; color: var(--cw-text-2);
}
.cw__kb-faq {
  border: 1px solid var(--cw-border);
  border-radius: 10px;
  padding: 8px 12px;
  margin-bottom: 6px;
  background: var(--cw-bg-2, rgba(255,255,255,.03));
}
.cw__kb-faq summary {
  cursor: pointer; font-size: .82rem; font-weight: 600;
  color: var(--cw-text); list-style: none;
}
.cw__kb-faq summary::-webkit-details-marker { display: none; }
.cw__kb-faq summary::before { content: '+ '; color: var(--cw-accent, #3D7AE8); }
.cw__kb-faq[open] summary::before { content: '– '; }
.cw__kb-faq p {
  margin: 8px 0 2px; font-size: .8rem; line-height: 1.55;
  color: var(--cw-text-2);
}
.cw__rating { margin-top: 14px; }
.cw__rating-q { font-size: .85rem; color: var(--cw-text-2); margin: 0 0 6px; }
.cw__rating-stars { display: inline-flex; gap: 4px; }
.cw__star {
  background: none; border: none; cursor: pointer;
  font-size: 1.5rem; line-height: 1; color: var(--cw-border);
  padding: 2px; transition: color .12s, transform .12s;
}
.cw__star:hover:not(:disabled) { transform: scale(1.15); }
.cw__star.is-on { color: #f5b301; }
.cw__star:disabled { cursor: default; }
.cw__rating-thanks { margin: 8px 0 0; font-size: .82rem; color: var(--cw-accent, #3D7AE8); }

.cw__kb-viewall {
  display: block; margin: 12px 0 4px; text-align: center;
  font-size: .82rem; font-weight: 700;
  color: var(--cw-accent, #3D7AE8); text-decoration: none;
}
.cw__kb-viewall:hover { text-decoration: underline; }

/* Gate / offline form */
.cw__welcome-block {
  padding: 22px 18px 10px;
  flex-shrink: 0;
}
.cw__welcome-text {
  font-size: .9rem;
  color: var(--cw-text);
  line-height: 1.55;
  margin: 0;
}
.cw__offline-icon {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  background: rgba(255,255,255,.05);
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 12px;
  color: var(--cw-text-2);
}
.cw__offline-icon svg { width: 20px; height: 20px; }

/* Form */
.cw__form {
  padding: 12px 18px 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex-shrink: 0;
}
.cw__field { display: flex; flex-direction: column; }
.cw__hp { position: absolute; left: -9999px; width: 1px; height: 1px; opacity: 0; }
.cw__puzzle-label {
  color: var(--cw-text-2);
  font-size: .76rem;
  font-weight: 700;
  margin-bottom: 6px;
}
.cw__input {
  background: var(--cw-surface);
  border: 1px solid var(--cw-border);
  border-radius: 8px;
  padding: 9px 12px;
  font-size: .875rem;
  color: var(--cw-text);
  font-family: var(--cw-font);
  outline: none;
  transition: border-color 0.15s;
}
.cw__input::placeholder { color: var(--cw-text-3); }
.cw__input:focus { border-color: rgba(61,122,232,.5); }
.cw__error {
  font-size: .78rem;
  color: #EF4444;
  padding: 4px 0;
}
.cw__start-btn {
  background: var(--cw-accent);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 10px 18px;
  font-size: .875rem;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-family: var(--cw-font);
  transition: background 0.15s;
  margin-top: 4px;
}
.cw__launcher-actions .cw__start-btn,
.cw__launcher-actions .cw__secondary-btn {
  min-height: 42px;
  margin-top: 0;
}
.cw__start-btn svg { width: 16px; height: 16px; flex-shrink: 0; }
.cw__start-btn:hover { background: var(--cw-accent-dark); }
.cw__start-btn:disabled { opacity: .55; cursor: default; }

/* ── Message log ────────────────────────────────────────────── */
.cw__messages {
  flex: 1;
  overflow-y: auto;
  padding: 14px 14px 6px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  scrollbar-width: thin;
  scrollbar-color: var(--scrollbar-thumb) var(--scrollbar-track);
  min-height: 0;
}
.cw__messages::-webkit-scrollbar { width: .55rem; }
.cw__messages::-webkit-scrollbar-track { background: var(--scrollbar-track); border-radius: 1.25rem; }
.cw__messages::-webkit-scrollbar-thumb { background: var(--scrollbar-thumb); border-radius: .625rem; }
.cw__messages::-webkit-scrollbar-thumb:hover { background: var(--scrollbar-thumb-hover); }

/* Message bubbles */
.cw__msg {
  display: flex;
  flex-direction: column;
  max-width: 82%;
  animation: cw-msg-in 0.18s ease-out;
}
@keyframes cw-msg-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}
.cw__msg--in  { align-self: flex-start; align-items: flex-start; }
.cw__msg--out { align-self: flex-end;   align-items: flex-end; }
.cw__msg--system { align-self: center; max-width: 90%; }

.cw__msg-body {
  padding: 9px 13px;
  border-radius: 14px;
  font-size: .875rem;
  line-height: 1.5;
  word-break: break-word;
  margin: 0;
}
.cw__msg-body a {
  color: inherit;
  text-decoration: underline;
  text-underline-offset: 2px;
}
.cw__msg--in  .cw__msg-body { background: var(--cw-surface); color: var(--cw-text); border-bottom-left-radius: 4px; }
.cw__msg--out .cw__msg-body { background: var(--cw-accent);  color: #fff; border-bottom-right-radius: 4px; }
.cw__msg--system .cw__msg-body {
  background: rgba(255,255,255,.04);
  color: var(--cw-text-2);
  font-size: .78rem;
  text-align: center;
  border-radius: 8px;
  padding: 6px 12px;
}
.cw__msg-time {
  font-size: .66rem;
  color: var(--cw-text-3);
  margin-top: 2px;
  padding: 0 4px;
}
.cw__msg-edited {
  margin-left: 4px;
}
.cw__msg-actions {
  display: flex;
  gap: 6px;
  margin-top: 4px;
  opacity: .72;
}
.cw__msg:hover .cw__msg-actions,
.cw__msg:focus-within .cw__msg-actions {
  opacity: 1;
}
.cw__msg-action {
  border: 1px solid var(--cw-border);
  background: var(--cw-surface);
  color: var(--cw-text-2);
  border-radius: 999px;
  padding: 2px 8px;
  font: inherit;
  font-size: .66rem;
  cursor: pointer;
}
.cw__msg-action:hover {
  color: var(--cw-text);
  background: rgba(255,255,255,.06);
}
.cw__og-preview {
  display: flex;
  align-items: center;
  gap: 9px;
  width: 100%;
  margin-top: 0;
  padding: 9px;
  border: 1px solid var(--cw-border);
  border-top: 0;
  border-radius: 0 0 14px 14px;
  background: var(--cw-surface);
  color: var(--cw-text);
  text-decoration: none;
}
.cw__og-preview-img {
  width: 54px;
  height: 54px;
  border-radius: 8px;
  object-fit: cover;
  flex-shrink: 0;
  background: rgba(255,255,255,.08);
}
.cw__og-preview-meta {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.cw__og-preview-title {
  font-size: .76rem;
  font-weight: 700;
  color: var(--cw-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.cw__og-preview-desc {
  font-size: .7rem;
  color: var(--cw-text-2);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.cw__og-preview-host {
  font-size: .66rem;
  color: var(--cw-accent);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.cw__msg:has(.cw__og-preview) .cw__msg-body {
  border-bottom-left-radius: 0;
  border-bottom-right-radius: 0;
}

/* Typing indicator */
.cw__typing-indicator {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 6px 18px 2px;
  flex-shrink: 0;
}
/* Only show the animated dots when JS explicitly reveals them
   (i.e. an admin is actually typing). Without this the display:flex
   above overrides the [hidden] attribute and the dots show from the
   moment the chat opens. */
.cw__typing-indicator[hidden] { display: none !important; }
.cw__typing-indicator span {
  width: 6px;
  height: 6px;
  background: var(--cw-text-2);
  border-radius: 50%;
  display: block;
  animation: cw-dot 1.3s ease infinite;
}
.cw__typing-indicator span:nth-child(2) { animation-delay: .15s; }
.cw__typing-indicator span:nth-child(3) { animation-delay: .30s; }
@keyframes cw-dot {
  0%, 80%, 100% { transform: scale(.7); opacity: .4; }
  40% { transform: scale(1); opacity: 1; }
}

/* ── Compose bar ────────────────────────────────────────────── */
.cw__compose {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 10px 12px;
  border-top: 1px solid var(--cw-border);
  flex-shrink: 0;
}
.cw__textarea {
  flex: 1;
  background: var(--cw-surface);
  border: 1px solid var(--cw-border);
  border-radius: 10px;
  padding: 9px 12px;
  font-size: .875rem;
  color: var(--cw-text);
  font-family: var(--cw-font);
  resize: none;
  outline: none;
  transition: border-color 0.15s;
  max-height: 120px;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--scrollbar-thumb) var(--scrollbar-track);
  line-height: 1.4;
}
.cw__textarea::-webkit-scrollbar { width: .55rem; }
.cw__textarea::-webkit-scrollbar-track { background: var(--scrollbar-track); border-radius: 1.25rem; }
.cw__textarea::-webkit-scrollbar-thumb { background: var(--scrollbar-thumb); border-radius: .625rem; }
.cw__textarea::-webkit-scrollbar-thumb:hover { background: var(--scrollbar-thumb-hover); }
.cw__textarea--offline { max-height: unset; }
.cw__textarea::placeholder { color: var(--cw-text-3); }
.cw__textarea:focus { border-color: rgba(61,122,232,.4); }
.cw__send-btn {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: var(--cw-accent);
  border: none;
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.15s;
}
.cw__send-btn svg { width: 18px; height: 18px; }
.cw__send-btn:hover { background: var(--cw-accent-dark); }
.cw__send-btn:disabled { opacity: .45; cursor: default; }

/* ── Success state ──────────────────────────────────────────── */
.cw__success-icon {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: rgba(16,185,129,.12);
  color: #10B981;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 12px;
}
.cw__success-icon svg { width: 24px; height: 24px; }
.cw__success-title { font-size: 1rem; font-weight: 600; color: var(--cw-text); margin: 0; }
.cw__success-sub   { font-size: .83rem; color: var(--cw-text-2); margin: 4px 0 0; }

/* ── Footer ─────────────────────────────────────────────────── */
.cw__footer {
  padding: 8px 16px;
  border-top: 1px solid var(--cw-border);
  font-size: .68rem;
  color: var(--cw-text-3);
  text-align: center;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.cw__footer strong { color: var(--cw-text-2); }
.cw__whatsapp-link {
  color: #25D366;
  font-weight: 700;
  text-decoration: none;
}
.cw__whatsapp-link:hover { color: #6EE7A8; }

/* ── Light mode overrides ───────────────────────────────────── */
html:not(.dark) .cw {
  --cw-bg:      #FFFFFF;
  --cw-surface: #F5F7FC;
  --cw-border:  rgba(15,27,56,.08);
  --cw-text:    rgba(9,14,28,.90);
  --cw-text-2:  rgba(9,14,28,.56);
  --cw-text-3:  rgba(9,14,28,.34);
}

/* ── Mobile ─────────────────────────────────────────────────── */
@media (max-width: 480px) {
  .cw {
    bottom: 16px;
    right: 16px;
  }
  .cw__panel {
    width: calc(100vw - 32px);
    max-height: calc(100vh - 100px);
    border-radius: 18px;
  }
}
