/* ═══════════════════════════════════════════════════════════
   Live-chat widget (tawk.to-style) — brand-colored,
   dark-mode aware (uses CSS vars from site.css)
   v7 (chat148): direction-aware — the panel dir attribute follows
   the page language (blade prints cfg.dir), bubbles are dir="auto"
   in the JS, logical text-align + mirrored tail corners here.
   ═══════════════════════════════════════════════════════════ */

.chatw-btn {
  position: fixed; bottom: 20px; left: 20px; z-index: 9990;
  width: 58px; height: 58px; border-radius: 50%;
  background: var(--primary); color: #fff; border: none; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.65rem; line-height: 1;
  box-shadow: 0 10px 28px rgba(0,0,0,.28), 0 0 0 0 rgba(168,85,247,.5);
  transition: transform .16s ease, box-shadow .16s ease, background .16s ease;
  animation: chatw-pulse 3s ease-out infinite;
}
.chatw-btn:hover { transform: translateY(-3px) scale(1.04); background: var(--primary-dark); }
.chatw-btn:focus-visible { outline: 3px solid var(--primary-soft); outline-offset: 2px; }
@keyframes chatw-pulse {
  0%   { box-shadow: 0 10px 28px rgba(0,0,0,.28), 0 0 0 0 rgba(0,0,0,.22); }
  70%  { box-shadow: 0 10px 28px rgba(0,0,0,.28), 0 0 0 16px transparent; }
  100% { box-shadow: 0 10px 28px rgba(0,0,0,.28), 0 0 0 0 transparent; }
}

/* online dot on the launcher */
.chatw-btn-dot {
  position: absolute; top: 4px; right: 4px; width: 13px; height: 13px;
  border-radius: 50%; background: #22c55e; border: 2.5px solid var(--surface);
  display: none;
}
.chatw-btn.online .chatw-btn-dot { display: block; }

/* unread badge on the launcher */
.chatw-btn-badge {
  position: absolute; top: -4px; left: -4px; min-width: 21px; height: 21px;
  border-radius: 999px; background: #ef4444; color: #fff;
  font-size: .72rem; font-weight: 800; display: none;
  align-items: center; justify-content: center; padding: 0 5px;
  border: 2px solid var(--surface);
}
.chatw-btn-badge.show { display: flex; }

/* ───────────── panel ───────────── */
.chatw-panel {
  position: fixed; bottom: 92px; left: 20px; z-index: 9990;
  width: min(372px, calc(100vw - 32px));
  height: min(560px, calc(100dvh - 130px));
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 18px; overflow: hidden;
  box-shadow: 0 24px 70px rgba(0,0,0,.3), 0 4px 18px rgba(0,0,0,.14);
  display: none; flex-direction: column;
  transform-origin: bottom left;
}
.chatw-panel.open { display: flex; animation: chatw-pop .22s cubic-bezier(.34,1.4,.5,1); }
@keyframes chatw-pop { from { opacity: 0; transform: scale(.86) translateY(14px); } to { opacity: 1; transform: none; } }

.chatw-head {
  display: flex; align-items: center; gap: .7rem; padding: .85rem 1rem;
  background: linear-gradient(135deg, var(--primary), var(--primary-dark)); color: #fff;
}
.chatw-head-avatar {
  width: 40px; height: 40px; border-radius: 50%; flex-shrink: 0;
  background: rgba(255,255,255,.18); display: flex; align-items: center; justify-content: center;
  font-size: 1.25rem; border: 1.5px solid rgba(255,255,255,.35);
}
.chatw-head-info { flex: 1; min-width: 0; }
.chatw-title { font-weight: 800; font-size: .95rem; }
.chatw-status { display: flex; align-items: center; gap: .35rem; font-size: .74rem; opacity: .95; margin-top: .15rem; }
.chatw-status-dot { width: 8px; height: 8px; border-radius: 50%; background: #9ca3af; flex-shrink: 0; }
.chatw-panel.is-online .chatw-status-dot { background: #4ade80; box-shadow: 0 0 0 3px rgba(74,222,128,.25); }
.chatw-close {
  background: rgba(255,255,255,.14); border: none; color: #fff; width: 30px; height: 30px;
  border-radius: 9px; cursor: pointer; font-size: 1.15rem; line-height: 1;
  display: flex; align-items: center; justify-content: center; transition: background .15s;
}
.chatw-close:hover { background: rgba(255,255,255,.3); }

/* offline note strip */
.chatw-note {
  display: none; align-items: flex-start; gap: .45rem;
  background: var(--warn-soft); color: var(--warn);
  font-size: .74rem; font-weight: 600; line-height: 1.7;
  padding: .5rem .85rem; border-bottom: 1px solid var(--border);
}
.chatw-panel.is-offline .chatw-note { display: flex; }
.chatw-note i { font-size: .95rem; flex-shrink: 0; margin-top: .1rem; }

/* messages area */
.chatw-msgs {
  flex: 1; overflow-y: auto; padding: 1rem .9rem;
  display: flex; flex-direction: column; gap: .55rem;
  background: var(--surface-3);
  scrollbar-width: thin; scrollbar-color: var(--border) transparent;
}
.chatw-msgs::-webkit-scrollbar { width: 6px; }
.chatw-msgs::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

.chatw-day {
  align-self: center; font-size: .68rem; color: var(--muted);
  background: var(--surface-2); border-radius: 999px; padding: .15rem .7rem;
}

.chatw-bubble {
  max-width: 80%; padding: .45rem .75rem; border-radius: 14px;
  font-size: .85rem; line-height: 1.7; word-break: break-word;
  position: relative; white-space: pre-wrap;
}
.chatw-bubble .chatw-time { display: block; font-size: .62rem; opacity: .75; margin-top: .2rem; text-align: end; }
/* ✓ / ✓✓ delivery-seen mark under the customer's latest message */
.chatw-seen {
  display: block; font-size: .6rem; text-align: end; margin-top: .1rem;
  opacity: .78; letter-spacing: .2px;
}
.chatw-bubble.from-user .chatw-seen.is-seen { color: #d1fae5; opacity: 1; }
/* customer's own messages — left side (Goftino/tawk style in RTL) */
.chatw-bubble.from-user {
  align-self: flex-end; background: var(--primary); color: #fff;
  border-bottom-left-radius: 5px;
}
/* support messages — right side */
.chatw-bubble.from-admin, .chatw-bubble.from-support {
  align-self: flex-start; background: var(--surface); color: var(--text);
  border: 1px solid var(--border); border-bottom-right-radius: 5px;
  box-shadow: 0 1px 2px rgba(0,0,0,.05);
}
/* chat148 — mirrored bubble tails in LTR panels (user sits right,
   support sits left — the flex-start/flex-end sides flip with dir) */
.chatw-panel[dir="ltr"] .chatw-bubble.from-user {
  border-bottom-left-radius: 14px; border-bottom-right-radius: 5px;
}
.chatw-panel[dir="ltr"] .chatw-bubble.from-admin,
.chatw-panel[dir="ltr"] .chatw-bubble.from-support {
  border-bottom-right-radius: 14px; border-bottom-left-radius: 5px;
}
.chatw-panel[dir="ltr"] .chatw-hello {
  border-bottom-right-radius: 14px; border-bottom-left-radius: 5px;
}
.chatw-bubble.from-system {
  align-self: center; background: transparent; border: 1px dashed var(--border);
  color: var(--muted); font-size: .72rem; text-align: center; border-radius: 10px;
}
.chatw-hello {
  align-self: flex-start; background: var(--surface); color: var(--text);
  border: 1px solid var(--border); border-bottom-right-radius: 5px;
  display: flex; gap: .55rem; align-items: flex-start; padding: .55rem .85rem;
  font-size: .85rem; line-height: 1.8;
}
.chatw-hello .chatw-mini-avatar {
  width: 26px; height: 26px; border-radius: 50%; flex-shrink: 0; margin-top: .15rem;
  background: var(--primary); color: #fff; display: flex; align-items: center; justify-content: center;
  font-size: .8rem;
}

/* typing indicator (support is writing) */
.chatw-typing-row {
  display: none; align-items: center; gap: .5rem;
  padding: .4rem .95rem .5rem; background: var(--surface);
  border-top: 1px dashed var(--border);
  font-size: .74rem; font-weight: 600; color: var(--muted);
}
.chatw-panel.support-typing .chatw-typing-row { display: flex; }
.chatw-typing-dots { display: inline-flex; align-items: center; }
.chatw-typing-dots span {
  width: 6px; height: 6px; margin: 0 1.5px; border-radius: 50%;
  background: var(--primary); display: inline-block; animation: chatw-blink 1.2s infinite;
}
.chatw-typing-dots span:nth-child(2) { animation-delay: .18s; }
.chatw-typing-dots span:nth-child(3) { animation-delay: .36s; }
@keyframes chatw-blink { 0%, 80%, 100% { opacity: .25; } 40% { opacity: 1; } }

/* footer / composer */
.chatw-foot { padding: .65rem .8rem .75rem; border-top: 1px solid var(--border); background: var(--surface); }
.chatw-guest { display: none; gap: .45rem; margin-bottom: .5rem; }
.chatw-guest.show { display: flex; }
.chatw-guest input {
  flex: 1; min-width: 0; border: 1px solid var(--border); border-radius: 10px;
  background: var(--surface-2); color: var(--text); padding: .45rem .7rem; font: inherit; font-size: .8rem;
}
.chatw-guest input:focus { outline: 2px solid var(--primary-soft); border-color: var(--primary); }
.chatw-input-row { display: flex; align-items: flex-end; gap: .5rem; }
.chatw-input-row textarea {
  flex: 1; resize: none; border: 1px solid var(--border); border-radius: 12px;
  background: var(--surface-2); color: var(--text); padding: .55rem .8rem;
  font: inherit; font-size: .85rem; line-height: 1.7; max-height: 110px;
}
.chatw-input-row textarea:focus { outline: 2px solid var(--primary-soft); border-color: var(--primary); }
.chatw-send {
  width: 42px; height: 42px; border-radius: 12px; border: none; flex-shrink: 0;
  background: var(--primary); color: #fff; font-size: 1.15rem; cursor: pointer;
  display: flex; align-items: center; justify-content: center; transition: background .15s, transform .12s;
}
.chatw-send:hover { background: var(--primary-dark); transform: translateY(-1px); }
.chatw-send:disabled { opacity: .55; cursor: default; transform: none; }
.chatw-send i { transform: scaleX(-1); } /* flip for RTL */
.chatw-panel[dir="ltr"] .chatw-send i { transform: none; } /* chat148 — native glyph in LTR panels */
.chatw-err { color: var(--err); font-size: .72rem; font-weight: 600; margin-top: .35rem; display: none; }
.chatw-err.show { display: block; }

@media (max-width: 480px) {
  .chatw-btn { bottom: 14px; left: 14px; width: 54px; height: 54px; font-size: 1.5rem; }
  .chatw-panel { bottom: 82px; left: 14px; height: min(520px, calc(100dvh - 110px)); border-radius: 16px; }
}

/* ── chat44: image messages (messenger-style) ─────────────────── */
.chatw-bubble.has-img { padding: .3rem; max-width: 78%; }
.chatw-bubble.has-img .chatw-img {
  display: block; max-width: 220px; width: 100%; border-radius: 10px; cursor: zoom-in;
}
.chatw-bubble.has-img .chatw-caption {
  display: block; padding: .3rem .5rem 0; white-space: pre-wrap; word-break: break-word;
}
.chatw-bubble.has-img .chatw-time { padding: .15rem .5rem 0; }
/* attach (📎) button in the composer row */
.chatw-attach {
  width: 42px; height: 42px; border-radius: 12px; border: 1px solid var(--border); flex-shrink: 0;
  background: var(--surface-2); color: var(--text); font-size: 1.15rem; cursor: pointer;
  display: flex; align-items: center; justify-content: center; transition: border-color .15s, color .15s;
}
.chatw-attach:hover { border-color: var(--primary); color: var(--primary); }
/* pending image preview chip above the composer */
.chatw-pending-img {
  position: relative; width: 92px; height: 74px; margin-bottom: .5rem;
  border: 1px solid var(--border); border-radius: 10px; overflow: hidden; background: var(--surface-2);
}
.chatw-pending-img img { width: 100%; height: 100%; object-fit: cover; }
.chatw-pending-x {
  position: absolute; top: 2px; left: 2px; width: 20px; height: 20px; border: none; border-radius: 50%;
  background: rgba(0,0,0,.62); color: #fff; font-size: .8rem; line-height: 1; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}

/* ── chat45: unread notifications (toast + launcher flash) ────── */
.chatw-toast {
  position: fixed; bottom: 92px; left: 20px; z-index: 9991;
  width: min(320px, calc(100vw - 32px));
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 14px; box-shadow: 0 18px 50px rgba(0,0,0,.28), 0 3px 12px rgba(0,0,0,.12);
  display: flex; gap: .6rem; align-items: flex-start; padding: .7rem .85rem;
  cursor: pointer;  /* chat148 — direction set via dir attribute from cfg (was hardcoded rtl) */
  animation: chatw-toast-in .28s cubic-bezier(.34,1.4,.5,1);
}
@keyframes chatw-toast-in { from { opacity: 0; transform: translateY(12px) scale(.95); } to { opacity: 1; transform: none; } }
.chatw-toast.out { transition: opacity .25s, transform .25s; opacity: 0; transform: translateY(10px); }
.chatw-toast-avatar {
  width: 34px; height: 34px; border-radius: 50%; flex-shrink: 0;
  background: var(--primary); color: #fff; display: flex; align-items: center; justify-content: center;
  font-size: 1.05rem;
}
.chatw-toast-body { flex: 1; min-width: 0; }
.chatw-toast-title { font-weight: 800; font-size: .8rem; color: var(--text); }
.chatw-toast-text {
  font-size: .76rem; color: var(--muted); line-height: 1.6; margin-top: .1rem;
  overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
}
.chatw-toast-x {
  background: transparent; border: none; color: var(--muted); font-size: 1.05rem;
  cursor: pointer; padding: 0 0 0 .3rem; line-height: 1; flex-shrink: 0;
}
.chatw-toast-x:hover { color: var(--text); }
/* launcher attention flash when a message arrives while closed */
.chatw-btn.flash { animation: chatw-flash 1.1s ease-in-out 3; }
@keyframes chatw-flash {
  0%, 100% { box-shadow: 0 10px 28px rgba(0,0,0,.28), 0 0 0 0 rgba(168,85,247,.55); }
  50%      { box-shadow: 0 10px 28px rgba(0,0,0,.28), 0 0 0 14px rgba(168,85,247,0); }
}
@media (max-width: 480px) {
  .chatw-toast { bottom: 82px; left: 14px; width: min(300px, calc(100vw - 28px)); }
}

/* ── chat146 — auto-linkified URLs inside bubbles / welcome / captions ── */
/* anchors carry dir="ltr" in the markup; CSS isolates + wraps long URLs   */
.chatw-bubble a.chat-link,
.chatw-hello a.chat-link,
.chatw-caption a.chat-link {
  color: inherit; text-decoration: underline; text-decoration-thickness: 1px;
  text-underline-offset: 3px; word-break: break-all; overflow-wrap: anywhere;
  direction: ltr; unicode-bidi: isolate;
}
.chatw-bubble a.chat-link:hover,
.chatw-hello a.chat-link:hover,
.chatw-caption a.chat-link:hover { text-decoration-thickness: 2px; opacity: .92; }
