/* Customer chat widget (includes/chat-widget.php). */
/* ═══════════════════════════════════════════════
    Support chat widget  v2
   ═══════════════════════════════════════════════ */
:root {
  --chat-blue: var(--blue, #2563eb);
  --chat-blue-light: var(--blue-light, #60a5fa);
  --chat-bg: #0a0f1a;
  --chat-bg-raised: #0e1422;
  --chat-bg-hover: #141c2e;
  --chat-border: rgba(255,255,255,0.08);
  --chat-text: #e1e7f5;
  --chat-text-sub: #8896b3;
  --chat-text-muted: #4b5b78;
  --chat-radius: 16px;
}
[data-theme="light"] {
  --chat-bg: #ffffff;
  --chat-bg-raised: #f7f9fd;
  --chat-bg-hover: #eef2fb;
  --chat-border: rgba(0,0,0,0.08);
  --chat-text: #0f172a;
  --chat-text-sub: #5b6b8a;
  --chat-text-muted: #94a3b8;
}

#chat-launcher {
  position: fixed;

  bottom: calc(33px + var(--nb-bottom-inset, 0px));
  z-index: 480;
  width: 58px; height: 58px;
  border-radius: 50%;
  background: linear-gradient(145deg, var(--chat-blue), var(--blue-dark, #1e40af));
  box-shadow: 0 6px 22px rgb(var(--blue-rgb, 37 99 235) / 0.45);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; border: none;

  transition: bottom .22s cubic-bezier(.2,.8,.3,1), transform .2s ease;
}
#chat-launcher:hover { transform: scale(1.07); }
#chat-launcher svg { width: 28px; height: 28px; }
#chat-launcher .chat-launcher-badge {
  position: absolute; top: -4px;
  background: #ef4444; color: #fff; font-size: .6rem; font-weight: 800;
  min-width: 18px; height: 18px; border-radius: 99px;
  display: none; align-items: center; justify-content: center; padding: 0 4px;
  border: 2px solid var(--chat-bg);
}
#chat-launcher .chat-launcher-badge.show { display: flex; }

@keyframes chatNudge {
  0%, 100% { transform: translateY(0) rotate(0); }
  15%      { transform: translateY(-7px) rotate(-8deg); }
  30%      { transform: translateY(0)    rotate(7deg); }
  45%      { transform: translateY(-4px) rotate(-5deg); }
  60%      { transform: translateY(0)    rotate(0); }
}
#chat-launcher.chat-nudge { animation: chatNudge 1.1s ease-in-out 1; }
@media (prefers-reduced-motion: reduce) {
  #chat-launcher.chat-nudge { animation: none; }
}

@media (max-width: 680px) {

  #chat-launcher {
    bottom: max(85px, calc(var(--nb-bottom-inset, 0px) + 12px));
    width: 52px; height: 52px;
  }
}

#chat-peek-bubble {
  position: fixed;
  bottom: calc(33px + var(--nb-bottom-inset, 0px));
  transition: bottom .22s cubic-bezier(.2,.8,.3,1);
  z-index: 479;
  max-width: 260px;
  background: var(--chat-bg-raised);
  border: 1px solid var(--chat-blue-light);
  border-radius: 14px;
  box-shadow: 0 10px 30px rgba(0,0,0,.35), 0 0 0 1px rgb(var(--blue-rgb, 37 99 235) / .15);
  padding: 12px 34px 12px 14px;
  display: none;
  cursor: pointer;
  animation: chatPeekIn .28s cubic-bezier(.34,1.56,.64,1);
}
#chat-peek-bubble.show { display: block; }
#chat-peek-bubble .chat-peek-sender {
  font-size: .68rem; font-weight: 800; color: var(--chat-blue-light);
  margin-bottom: 3px; display: flex; align-items: center; gap: 5px;
}
#chat-peek-bubble .chat-peek-sender::before {
  content: ''; width: 7px; height: 7px; border-radius: 50%;
  background: #4ade80; flex-shrink: 0;
  box-shadow: 0 0 0 3px rgba(74,222,128,.2);
}
#chat-peek-bubble .chat-peek-text {
  font-size: .76rem; line-height: 1.4; color: var(--chat-text);
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical;
  overflow: hidden;
}
#chat-peek-bubble .chat-peek-close {
  position: absolute; top: 8px; right: 8px;
  width: 20px; height: 20px; border-radius: 50%;
  background: var(--chat-bg-hover); border: none; color: var(--chat-text-muted);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; font-size: .7rem; line-height: 1;
  transition: background .15s, color .15s;
}
#chat-peek-bubble .chat-peek-close:hover { background: var(--chat-blue); color: #fff; }
@keyframes chatPeekIn {
  from { opacity: 0; transform: translateY(8px) scale(.96); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}
@media (max-width: 680px) {
  #chat-peek-bubble { bottom: 85px; max-width: 210px; }
}

#chat-guest-modal-overlay {
  position: fixed; inset: 0; z-index: 999999;
  background: rgba(0,0,0,.6); backdrop-filter: blur(3px);
  display: none; align-items: center; justify-content: center;
  padding: 1rem;
}
#chat-guest-modal-overlay.show { display: flex; }
#chat-guest-modal {
  background: var(--chat-bg-raised);
  border: 1px solid var(--chat-border);
  border-radius: 16px;
  width: 100%; max-width: 340px;
  padding: 1.5rem;
  position: relative;
  box-shadow: 0 20px 60px rgba(0,0,0,.4);
  animation: chatGuestModalIn .25s ease;
}
#chat-guest-modal::before {
  content: ''; position: absolute; top: 0; left: 0; right: 0; height: 3px;
  background: linear-gradient(90deg, var(--chat-blue), var(--chat-blue-light));
  border-radius: 16px 16px 0 0;
}
#chat-guest-modal h3 {
  font-size: 1rem; font-weight: 800; color: var(--chat-text); margin: 0 0 .3rem;
}
#chat-guest-modal p {
  font-size: .78rem; color: var(--chat-text-sub); margin: 0 0 1rem; line-height: 1.5;
}
#chat-guest-name-input {
  width: 100%; box-sizing: border-box;
  background: var(--chat-bg-hover); border: 1px solid var(--chat-border);
  border-radius: 10px; padding: .65rem .85rem;
  font-size: .85rem; color: var(--chat-text);
  outline: none; transition: border-color .15s;
}
#chat-guest-name-input:focus { border-color: var(--chat-blue); }
#chat-guest-modal-continue {
  width: 100%; margin-top: .9rem;
  background: var(--chat-blue); color: #fff; border: none;
  border-radius: 10px; padding: .68rem; font-size: .85rem; font-weight: 700;
  cursor: pointer; transition: background .15s, opacity .15s;
}
#chat-guest-modal-continue:disabled {
  opacity: .45; cursor: not-allowed;
}
#chat-guest-modal-continue:not(:disabled):hover { background: var(--chat-blue-light); }
@keyframes chatGuestModalIn {
  from { opacity: 0; transform: scale(.94) translateY(8px); }
  to   { opacity: 1; transform: scale(1) translateY(0); }
}

#chat-panel {
  position: fixed;
  bottom: calc(120px + var(--nb-bottom-inset, 0px));
  z-index: 490;
  width: 380px;
  max-width: 100vw;
  height: 600px;
  max-height: 78vh;
  background: var(--chat-bg);
  border: 1px solid var(--chat-border);
  border-radius: var(--chat-radius);
  box-shadow: 0 20px 60px rgba(0,0,0,0.45);
  display: none;
  flex-direction: column;
  overflow: hidden;
  box-sizing: border-box;
  font-family: inherit;
  opacity: 0; transform: translateY(16px) scale(.98);
  transition: opacity .22s ease, transform .22s ease;
}
#chat-panel.open { display: flex; }
#chat-panel.show { opacity: 1; transform: translateY(0) scale(1); }

@media (max-width: 680px) {
  #chat-panel {
    inset: 0 !important;
    bottom: 0 !important; right: 0 !important; left: 0 !important; top: 0 !important;
    width: 100%; height: 100%; max-height: 100%;
    border-radius: 0; z-index: 700;
  }
  /* Keyboard up (round 68): fitted to what is still visible, so the
     header does not slide off the top. Set by assets/js/chat-widget.js. */
  #chat-panel.kb-open {
    top: var(--chat-vv-top, 0px) !important; bottom: auto !important;
    height: var(--chat-vv-h, 100%) !important; max-height: none;
  }
  /* The Home / Messages / Track / Help tabs are not needed while typing;
     their room goes to the conversation. */
  #chat-panel.kb-open .chat-bottomnav { display: none; }
}

#chat-panel.open { z-index: 9999; }

@media (min-width: 681px) {
  #chat-panel.open {
    bottom: 120px;
    max-height: min(78vh, calc(100vh - 140px));
  }
}

.chat-view { display: none; flex: 1; flex-direction: column; overflow: hidden; height: 100%; }
.chat-view.active { display: flex; }

/* Header (shared across views except chat thread) */
.chat-header {
  background: linear-gradient(160deg, var(--chat-blue), var(--blue-dark, #1d4ed8));
  padding: 18px 18px 16px;
  flex-shrink: 0;
  position: relative;
}
.chat-header-top {
  display: flex; justify-content: space-between; align-items: center; margin-bottom: 4px;
}
.chat-header-logo-row {
  display: flex; align-items: center; gap: 8px; margin-bottom: 10px;
}
.chat-header-logo {
  width: 32px; height: 32px; border-radius: 8px;
  object-fit: contain; background: rgba(255,255,255,.12);
  padding: 3px; flex-shrink: 0;
}
.chat-header-title { color: #fff; font-size: .8rem; font-weight: 700; }
.chat-close-btn {
  background: rgba(255,255,255,0.15); border: none; color: #fff;
  width: 26px; height: 26px; border-radius: 50%; cursor: pointer;
  display: flex; align-items: center; justify-content: center; font-size: .75rem;
}
.chat-close-btn:hover { background: rgba(255,255,255,0.25); }
.chat-header-greeting { color: #fff; font-size: 1.05rem; font-weight: 800; margin: 4px 0 4px; line-height: 1.3; }
.chat-header-sub { color: rgba(255,255,255,0.82); font-size: .74rem; }

/* Home view */
.chat-sla-note { display:flex; gap:8px; align-items:flex-start; font-size:12px; line-height:1.55;
  padding:9px 11px; margin-bottom:12px; border-radius:9px;
  background:rgb(var(--blue-rgb) / .09); border:1px solid rgb(var(--blue-rgb) / .22); color:var(--chat-text,#333); }
.chat-sla-note svg { color:var(--chat-blue-light); }
.chat-sla-note a { color:var(--chat-blue-light); font-weight:700; text-decoration:none; }
.chat-home-body { flex: 1; overflow-y: auto; padding: 14px 16px; background: var(--chat-bg); }
.chat-bot-card {
  background: var(--chat-bg-raised); border: 1px solid var(--chat-border);
  border-radius: 12px; padding: 12px; display: flex; gap: 10px; align-items: center;
  margin-bottom: 14px; cursor: pointer; transition: background .15s;
}
.chat-bot-card:hover { background: var(--chat-bg-hover); }
.chat-bot-avatar {
  width: 38px; height: 38px; border-radius: 50%;
  background: linear-gradient(145deg, var(--chat-blue), var(--blue-dark, #1e40af));
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.chat-bot-avatar svg { width: 20px; height: 20px; }
.chat-bot-card-name { font-size: .8rem; font-weight: 700; color: var(--chat-text); }
.chat-bot-card-sub { font-size: .68rem; color: var(--chat-text-sub); }

.chat-section-label {
  font-size: .62rem; font-weight: 700; text-transform: uppercase; letter-spacing: 1px;
  color: var(--chat-text-muted); margin: 0 0 8px;
}
.chat-quick-card {
  display: flex; align-items: center; gap: 10px;
  background: var(--chat-bg-raised); border: 1px solid var(--chat-border);
  border-radius: 10px; padding: 11px 12px; margin-bottom: 8px; cursor: pointer;
  transition: background .15s;
}
.chat-quick-card:hover { background: var(--chat-bg-hover); }
.chat-quick-card-icon {
  width: 30px; height: 30px; border-radius: 8px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center; font-size: .85rem;
}
.chat-quick-card-text { flex: 1; }
.chat-quick-card-title { font-size: .76rem; font-weight: 600; color: var(--chat-text); }
.chat-quick-card-desc { font-size: .65rem; color: var(--chat-text-sub); }
.chat-quick-card svg.chevron { width: 12px; height: 12px; color: var(--chat-text-muted); flex-shrink: 0; }

.chat-cta-btn {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  background: #22c55e; color: #fff; border: none; border-radius: 10px;
  padding: 12px; font-size: .8rem; font-weight: 700; cursor: pointer; width: 100%;
  margin-top: 6px; transition: background .15s;
}
.chat-cta-btn:hover { background: #16a34a; }
.chat-cta-btn svg { width: 15px; height: 15px; }

/* Chat thread view */
.chat-chat-header {
  background: linear-gradient(160deg, var(--chat-blue), var(--blue-dark, #1d4ed8));
  padding: 13px 16px; display: flex; align-items: center; gap: 10px; flex-shrink: 0;
}
.chat-chat-header-back { background: rgba(255,255,255,0.15); border: none; color: #fff; width: 28px; height: 28px; border-radius: 50%; cursor: pointer; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.chat-chat-header-back:hover { background: rgba(255,255,255,0.25); }
.chat-chat-header-avatar { width: 30px; height: 30px; border-radius: 50%; background: rgba(255,255,255,0.18); display: flex; align-items: center; justify-content: center; flex-shrink: 0; overflow: hidden; }
.chat-chat-header-avatar img { width: 100%; height: 100%; object-fit: contain; }
.chat-chat-header-avatar svg { width: 16px; height: 16px; }
.chat-chat-header-info { flex: 1; min-width: 0; }
.chat-chat-header-name { color: #fff; font-size: .78rem; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-chat-header-status { color: rgba(255,255,255,0.78); font-size: .64rem; display: flex; align-items: center; gap: 4px; }
.chat-chat-header-status .dot { width: 6px; height: 6px; border-radius: 50%; background: #4ade80; }
.chat-chat-header-rating { margin-top: 2px; font-size: .72rem; display: flex; align-items: baseline; gap: .3rem; }
.chat-chat-header-rating .num { color: #fff; font-weight: 700; }
.chat-chat-header-rating .stars { color: #fde68a; letter-spacing: 1px; font-size: .8rem; }
.chat-chat-header-close { background: rgba(255,255,255,0.15); border: none; color: #fff; width: 26px; height: 26px; border-radius: 50%; cursor: pointer; display: none; align-items: center; justify-content: center; flex-shrink: 0; }
/* Find private info (round 98b) */
.chat-sens-btn { background: rgba(255,255,255,0.15); border: none; color: #fff; width: 28px; height: 28px; border-radius: 50%; cursor: pointer;
  display: flex; align-items: center; justify-content: center; flex-shrink: 0; transition: background .15s; }
.chat-sens-btn:hover { background: rgba(255,255,255,0.28); }
.chat-sens-bar { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; margin: 0 12px 8px; padding: 9px 11px; border-radius: 12px;
  font-size: .72rem; line-height: 1.45; color: var(--chat-text); background: rgba(239,68,68,.1); border: 1px solid rgba(239,68,68,.35); }
.chat-sens-bar[hidden] { display: none; }
.chat-sens-bar.is-calm { background: var(--chat-bg-raised); border-color: var(--chat-border); }
.chat-sens-bar .csb-t { flex: 1 1 180px; }
.chat-sens-bar .csb-acts { display: flex; gap: 6px; margin-left: auto; }
.chat-sens-bar button { border: 1px solid var(--chat-border); background: var(--chat-bg-raised); color: var(--chat-text); font: 600 .7rem/1 inherit;
  padding: 8px 11px; min-height: 32px; border-radius: 999px; cursor: pointer; }
.chat-sens-bar button.csb-del { background: #dc2626; border-color: #dc2626; color: #fff; }
.chat-sens-bar button:disabled { opacity: .6; cursor: default; }
/* AI / Team switch in the chat header (round 98) */
.chat-mode { margin-left: auto; display: inline-flex; flex-shrink: 0; padding: 2px; border-radius: 999px; background: rgba(255,255,255,0.15); }
.chat-mode-btn { border: 0; background: transparent; color: rgba(255,255,255,.85); font: 600 .68rem/1 inherit; padding: 6px 10px; min-height: 26px; border-radius: 999px; cursor: pointer; transition: background .15s, color .15s; }
.chat-mode-btn:hover:not(:disabled):not(.on) { background: rgba(255,255,255,.18); color: #fff; }
.chat-mode-btn.on { background: #fff; color: var(--chat-blue, #2563eb); cursor: default; }
.chat-mode-btn:disabled:not(.on) { opacity: .5; cursor: not-allowed; }
.chat-chat-header-new { background: rgba(255,255,255,0.15); border: none; color: #fff; width: 26px; height: 26px; border-radius: 50%; cursor: pointer; display: flex; align-items: center; justify-content: center; flex-shrink: 0; transition: background .15s; }
.chat-chat-header-new:hover { background: rgba(255,255,255,0.25); }
.chat-chat-header-switch-ai { background: rgba(255,255,255,0.15); border: none; color: #fff; width: 26px; height: 26px; border-radius: 50%; cursor: pointer; display: flex; align-items: center; justify-content: center; flex-shrink: 0; margin-left: auto; transition: background .15s, color .15s; }
.chat-chat-header-switch-ai:hover:not(:disabled) { background: rgb(var(--blue-rgb) / .35); color: var(--blue-light); }
.chat-chat-header-switch-ai:disabled { opacity: .5; cursor: default; }
.chat-chat-header-flag { background: rgba(255,255,255,0.15); border: none; color: #fff; width: 26px; height: 26px; border-radius: 50%; cursor: pointer; display: flex; align-items: center; justify-content: center; flex-shrink: 0; margin-left: auto; transition: background .15s, color .15s; }
.chat-chat-header-flag:hover:not(:disabled) { background: rgba(245,158,11,.35); color: #fde68a; }
.chat-chat-header-flag.flagged { background: rgba(74,222,128,.28); color: #bbf7d0; cursor: default; }
.chat-chat-header-flag:disabled { cursor: default; }
@media (max-width: 680px) { .chat-chat-header-close { display: flex; } }

/* Messages, clean label-above-bubble style, no avatar circles */
.chat-messages {
  flex: 1; overflow-y: auto; padding: 16px 14px; background: var(--chat-bg);
  display: flex; flex-direction: column; gap: 10px;
}
.chat-msg-row { display: flex; flex-direction: column; gap: 3px; max-width: 86%; animation: chatMsgIn .25s ease; }
.chat-msg-row.from-visitor { align-self: flex-end; }
.chat-msg-row.from-ai, .chat-msg-row.from-admin { align-self: flex-start; }
.chat-msg-row.grouped { margin-top: -6px; }
.chat-msg-meta {
  font-size: .58rem; font-weight: 700; color: var(--chat-text-muted);
  text-transform: uppercase; letter-spacing: .06em; padding: 0 3px;
}
.chat-msg-row.from-visitor .chat-msg-meta { text-align: right; }
.chat-bubble {
  padding: 9px 13px; border-radius: 12px; font-size: .8rem; line-height: 1.6;
  white-space: pre-wrap; word-wrap: break-word; position: relative;
}

.chat-upload-overlay {
  position: absolute; inset: 0; border-radius: 10px; z-index: 2;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 6px; background: rgba(5,8,20,.55); color: #fff;
}
.chat-upload-spinner {
  width: 22px; height: 22px; border-radius: 50%;
  border: 2.5px solid rgba(255,255,255,.35); border-top-color: #fff;
  animation: chatUploadSpin .8s linear infinite;
}
@keyframes chatUploadSpin { to { transform: rotate(360deg); } }
.chat-upload-pct { font-size: .68rem; font-weight: 700; }
.chat-msg-row.from-ai .chat-bubble, .chat-msg-row.from-admin .chat-bubble {
  background: var(--chat-bg-raised); color: var(--chat-text); border: 1px solid var(--chat-border);
  border-bottom-left-radius: 4px;
}
.chat-msg-row.from-visitor .chat-bubble {
  background: linear-gradient(135deg, rgb(var(--blue-rgb, 37 99 235) / .28), rgb(var(--blue-rgb, 37 99 235) / .16));
  color: #fff; border: 1px solid rgb(var(--blue-rgb, 37 99 235) / .3);
  border-bottom-right-radius: 4px;
}
[data-theme="light"] .chat-msg-row.from-visitor .chat-bubble {
  background: linear-gradient(135deg, rgb(var(--blue-rgb, 37 99 235) / .95), rgb(var(--blue-rgb, 37 99 235) / .85));
  border-color: rgb(var(--blue-rgb, 37 99 235) / .4);
}

.chat-msg-row:has(.cf-table-wrap, .cf-codeblock, .cf-callout) { max-width: 94%; }
.chat-msg-row:is(.from-ai, .from-admin) .chat-bubble :is(.cf-link, .cf-ref) { color: var(--chat-blue-light); }
[data-theme="light"] .chat-msg-row:is(.from-ai, .from-admin) .chat-bubble :is(.cf-link, .cf-ref) { color: var(--chat-blue); }
.chat-msg-row.from-system { align-self: center; max-width: 95%; }
.chat-msg-row.from-system .chat-bubble {
  background: var(--chat-bg-hover); color: var(--chat-text-sub); font-size: .72rem;
  font-style: italic; text-align: center; border-radius: 10px; border: 1px solid var(--chat-border);
}

/* Edited tag, small, muted, WhatsApp-style, sits right after the bubble timestamp */
.chat-msg-edited-tag { text-transform: none; letter-spacing: 0; font-weight: 500; opacity: .8; }

/* In-bubble timestamp, bottom-right, "Jul 14, 7:45 AM" style, matches admin panel */
.chat-msg-bubble-stamp {
  display: block; margin-top: 4px; font-size: .62rem; opacity: .7; text-align: right;
  line-height: 1.3;
}
.chat-msg-row.from-visitor .chat-msg-bubble-stamp { color: rgba(255,255,255,.75); }

/* Action row (copy / edit), sits BELOW the bubble, hidden until
   the row is hovered/focused so the chat doesn't look cluttered by default. */
.chat-msg-actions {
  display: flex; gap: 4px; margin-top: 3px; opacity: 0;
  transition: opacity .15s ease; pointer-events: none;
}
.chat-msg-row.from-visitor .chat-msg-actions { justify-content: flex-end; }
.chat-msg-row:hover .chat-msg-actions,
.chat-msg-row:focus-within .chat-msg-actions { opacity: 1; pointer-events: auto; }
.chat-msg-action-btn {
  width: 22px; height: 22px; display: flex; align-items: center; justify-content: center;
  background: var(--chat-bg-hover); border: 1px solid var(--chat-border); border-radius: 50%;
  color: var(--chat-text-sub); font-size: .62rem; cursor: pointer; padding: 0;
  transition: background .15s, color .15s;
}
.chat-msg-action-btn:hover { background: var(--chat-bg-active, var(--chat-bg-hover)); color: var(--chat-text); }
.chat-msg-action-btn.copied { color: #22c55e; border-color: #22c55e; }
.chat-msg-action-btn:disabled { opacity: .5; cursor: default; }
/* Round 98: the action row takes no room. With a mouse it floats over the
   bubble's lower edge; on a phone it is hidden until the message is tapped. */
@media (hover: hover) {
  .chat-msg-actions { position: absolute; bottom: -10px; left: 8px; margin: 0; z-index: 2; }
  .chat-msg-row.from-visitor .chat-msg-actions { left: auto; right: 8px; }
}
@media (hover: none) {
  .chat-msg-actions { display: none; }
  .chat-msg-row.chat-acts-open .chat-msg-actions { display: flex; opacity: 1; pointer-events: auto; }
  .chat-msg-row.chat-acts-open .chat-msg-action-btn { width: 30px; height: 30px; font-size: .7rem; }
}

/* Swipe-to-reply, the fixed reply-arrow icon revealed as the bubble is
   dragged right, and the quoted-message strip shown inside a reply. */
.chat-msg-row { position: relative; touch-action: pan-y; }
.nb-swipe-reply-icon {
  position: absolute; left: 6px; top: 50%; transform: translateY(-50%);
  width: 26px; height: 26px; border-radius: 50%; background: var(--chat-bg-hover);
  color: var(--chat-accent, var(--chat-blue)); display: flex; align-items: center; justify-content: center;
  font-size: .7rem; opacity: 0; pointer-events: none;
}
.chat-bubble { will-change: transform; }
.chat-reply-quote {
  display: flex; flex-direction: column; gap: 1px; margin-bottom: 5px; padding: 4px 8px;
  background: rgba(255,255,255,.1);
  border-radius: 6px; cursor: pointer; font-size: .7rem; line-height: 1.35;
}
[data-theme="light"] .chat-reply-quote { background: rgba(0,0,0,.05); }
.chat-reply-quote-who { font-weight: 700; opacity: .85; }
.chat-reply-quote-snip { opacity: .75; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 220px; }
@keyframes chatFlash { 0%, 100% { filter: none; } 35% { filter: brightness(1.35); } }

.chat-bubble.chat-flash,
.chat-msg-row.chat-flash .chat-bubble { animation: chatFlash .9s ease; }

/* The "replying to" bar above the composer, same shape as the attach
   preview strip right below it, so the two read as one family. */
.chat-reply-preview {
  display: none; align-items: center; gap: 8px; padding: 7px 12px;
  border-top: 1px solid var(--chat-border); background: var(--chat-bg-hover);
}
.chat-reply-preview > i { color: var(--chat-accent, var(--chat-blue)); font-size: .75rem; flex-shrink: 0; }
.chat-reply-preview-info { flex: 1; min-width: 0; }
.chat-reply-preview-who { font-size: .68rem; font-weight: 700; color: var(--chat-accent, var(--chat-blue)); }
.chat-reply-preview-snip { font-size: .72rem; opacity: .75; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-reply-preview-remove {
  background: none; border: none; color: var(--chat-text-sub); cursor: pointer; padding: 4px; flex-shrink: 0;
}

.chat-msg-edit-wrap { margin: 4px 0; display: flex; flex-direction: column; gap: 6px; }
.chat-msg-edit-input {
  width: 100%; min-height: 52px; resize: vertical; border-radius: 8px;
  border: 1px solid rgba(255,255,255,.35); background: rgba(0,0,0,.15); color: #fff;
  font-size: .8rem; font-family: inherit; padding: 6px 8px; line-height: 1.5;
}
[data-theme="light"] .chat-msg-edit-input { border-color: rgba(255,255,255,.55); }
.chat-msg-row.from-ai .chat-msg-edit-input, .chat-msg-row.from-admin .chat-msg-edit-input {
  background: var(--chat-bg); color: var(--chat-text); border-color: var(--chat-border);
}
.chat-msg-edit-actions { display: flex; justify-content: flex-end; gap: 6px; }
.chat-msg-edit-save, .chat-msg-edit-cancel {
  font-size: .65rem; font-weight: 700; padding: 4px 10px; border-radius: 6px; cursor: pointer;
  border: 1px solid transparent;
}
.chat-msg-edit-save { background: #fff; color: var(--blue-dark, #1d4ed8); }
.chat-msg-edit-save:disabled, .chat-msg-edit-cancel:disabled { opacity: .6; cursor: default; }
.chat-msg-edit-cancel { background: transparent; color: inherit; border-color: rgba(255,255,255,.4); }

/* Typing + entrance animation */
.chat-typing-dots { display: inline-flex; gap: 3px; padding: 4px 2px; }
.chat-typing-dots span {
  width: 6px; height: 6px; border-radius: 50%; background: var(--chat-text-muted);
  animation: chatTyping 1.2s infinite ease-in-out;
}
.chat-typing-dots span:nth-child(2) { animation-delay: .15s; }
.chat-typing-dots span:nth-child(3) { animation-delay: .3s; }
@keyframes chatTyping { 0%, 60%, 100% { opacity: .3; transform: translateY(0); } 30% { opacity: 1; transform: translateY(-3px); } }
@keyframes chatMsgIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); } }

.chat-seen-dot { align-self: flex-end; display: block; width: 16px; height: 16px; margin: 1px 2px 0 0; border-radius: 50%; overflow: hidden; background: #fff; box-shadow: 0 0 0 1.5px var(--nw-bg, #0b1220); animation: chatSeenIn .3s cubic-bezier(.2,.9,.3,1.3) both; }
.chat-seen-dot img { width: 100%; height: 100%; object-fit: cover; display: block; }
/* Sent while a reply is still coming: it waits its turn. */
.chat-msg-row.chat-queued .chat-bubble { opacity: .6; }
.chat-msg-row.chat-queued::after { content: 'Sends after the reply'; align-self: flex-end; font-size: 11px; color: var(--chat-text-sub); }
@keyframes chatSeenIn { from { transform: scale(.3); opacity: 0; } to { transform: none; opacity: 1; } }
.chat-seen-row {
  text-align: right; padding: 3px 16px; font-size: .6rem; color: var(--chat-text-muted);
  background: var(--chat-bg); flex-shrink: 0; border-top: 1px solid transparent;
}

/* Inline "talk to a human" handoff bubble, appears in-thread the moment
   status flips to needs_human, distinct from the always-visible footer link */
.chat-inline-handoff {
  display: flex; justify-content: center; padding: 4px 14px 10px; flex-shrink: 0; background: var(--chat-bg);
}
.chat-inline-handoff button {
  display: flex; align-items: center; gap: 6px;
  background: var(--chat-bg-raised); border: 1px solid var(--chat-blue-light);
  color: var(--chat-blue-light); font-family: inherit; font-size: .74rem; font-weight: 700;
  padding: 8px 16px; border-radius: 999px; cursor: pointer; transition: background .15s;
}
.chat-inline-handoff button:hover { background: var(--chat-bg-hover); }
[data-theme="light"] .chat-inline-handoff button { color: var(--chat-blue); border-color: var(--chat-blue); }

.chat-feedback-wrap { align-self: center; margin: 2px 0 8px; }

.chat-feedback-chip {
  display: flex; align-items: center; gap: 6px; background: var(--chat-bg-raised);
  border: 1px solid var(--chat-border); border-radius: 999px; padding: 5px 12px;
  font-size: .7rem; font-weight: 600; color: var(--chat-text-sub); cursor: pointer;
  transition: background .15s, border-color .15s;
}
.chat-feedback-chip:hover { background: var(--chat-bg-hover); }
.chat-feedback-chip.rated { color: var(--chat-text); border-color: #f59e0b; }
.chat-feedback-chip-stars { color: #f59e0b; letter-spacing: 1px; font-size: .75rem; }
/* Not rated yet: the stars themselves (round 98) */
.chat-rate-ask {
  display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 8px 14px 6px;
  background: rgba(245,158,11,.08); border: 1px solid rgba(245,158,11,.35); border-radius: 14px;
}
.chat-rate-ask-t { font-size: .74rem; font-weight: 700; color: var(--chat-text); }
.chat-rate-ask-stars { display: flex; gap: 2px; }
.chat-rate-ask-stars button {
  background: none; border: 0; padding: 4px; min-width: 32px; min-height: 32px; cursor: pointer;
  font-size: 1.45rem; line-height: 1; color: rgba(245,158,11,.45); transition: color .12s, transform .12s;
}
.chat-rate-ask-stars:hover button { color: #f59e0b; }
.chat-rate-ask-stars button:hover ~ button { color: rgba(245,158,11,.45); }
.chat-rate-ask-stars button:hover { transform: scale(1.12); }
.chat-rate-ask.nudge { animation: chatRateNudge 1.2s ease 2; }
@keyframes chatRateNudge { 50% { box-shadow: 0 0 0 6px rgba(245,158,11,.18); border-color: #f59e0b; } }
@media (prefers-reduced-motion: reduce) { .chat-rate-ask.nudge { animation: none; } }

.chat-feedback-card {
  width: 260px; max-width: calc(100vw - 48px); margin: 0 auto;
  background: var(--chat-bg-raised); border: 1px solid var(--chat-border); border-radius: 14px;
  padding: 14px; display: flex; flex-direction: column; gap: 10px;
}
.chat-feedback-title { font-size: .82rem; font-weight: 700; color: var(--chat-text); text-align: center; }
.chat-feedback-stars { display: flex; justify-content: center; gap: 6px; }
.chat-feedback-star {
  background: none; border: none; cursor: pointer; padding: 2px; font-size: 1.3rem;
  color: var(--chat-border); transition: color .15s, transform .1s;
}
.chat-feedback-star:hover { transform: scale(1.12); }
.chat-feedback-star.selected { color: #f59e0b; }
.chat-feedback-comment {
  width: 100%; min-height: 52px; resize: vertical; border-radius: 8px;
  border: 1px solid var(--chat-border); background: var(--chat-bg); color: var(--chat-text);
  font-size: .78rem; font-family: inherit; padding: 8px 10px; line-height: 1.5;
}
.chat-feedback-actions { display: flex; justify-content: flex-end; gap: 8px; }
.chat-feedback-dismiss, .chat-feedback-submit, .chat-feedback-collapse {
  font-size: .72rem; font-weight: 700; padding: 6px 14px; border-radius: 999px; cursor: pointer; border: 1px solid transparent;
}
.chat-feedback-dismiss { background: transparent; color: var(--chat-text-sub); border-color: var(--chat-border); }
.chat-feedback-dismiss:hover { background: var(--chat-bg-hover); }
.chat-feedback-submit { background: var(--chat-blue); color: #fff; }
.chat-feedback-submit:disabled { opacity: .5; cursor: default; }
.chat-feedback-submit:not(:disabled):hover { background: var(--chat-blue-light); }
.chat-feedback-readonly-stars { text-align: center; color: #f59e0b; font-size: 1.1rem; letter-spacing: 2px; }
.chat-feedback-readonly-comment { font-size: .78rem; color: var(--chat-text-sub); font-style: italic; text-align: center; line-height: 1.4; }
.chat-feedback-collapse { align-self: center; background: transparent; color: var(--chat-text-sub); border-color: var(--chat-border); }
.chat-feedback-collapse:hover { background: var(--chat-bg-hover); }

.chat-composer {
  display: flex; align-items: flex-end; gap: 6px; padding: 10px 12px;
  border-top: 1px solid var(--chat-border); background: var(--chat-bg); flex-shrink: 0;
  padding-bottom: max(10px, env(safe-area-inset-bottom));
  max-width: 100%; box-sizing: border-box; overflow: hidden;
}

.chat-composer textarea {
  flex: 1; min-width: 0; background: var(--chat-bg-raised); border: 1px solid var(--chat-border);
  border-radius: 19px; padding: 9px 16px; font-size: .8rem; line-height: 1.4; color: var(--chat-text);
  outline: none; font-family: inherit; box-sizing: border-box; display: block;
  resize: none; min-height: 38px; max-height: 118px; overflow-y: auto; field-sizing: content;
}
.chat-composer textarea:focus { border-color: var(--chat-blue); }
.chat-send-btn, .chat-attach-btn, .chat-voice-btn {
  width: 38px; height: 38px; border-radius: 50%; border: none;
  cursor: pointer; flex-shrink: 0; display: flex; align-items: center; justify-content: center;
  transition: background .15s;
}
.chat-send-btn { background: var(--chat-blue); color: #fff; }
.chat-send-btn:hover { background: var(--blue-dark, #1d4ed8); }
.chat-send-btn svg { width: 16px; height: 16px; }
.chat-attach-btn, .chat-voice-btn {
  background: var(--chat-bg-raised); color: var(--chat-text-sub); border: 1px solid var(--chat-border);
}
.chat-attach-btn:hover, .chat-voice-btn:hover { background: var(--chat-bg-hover); color: var(--chat-text); }
.chat-attach-btn svg, .chat-voice-btn svg { width: 16px; height: 16px; }
.chat-voice-btn.recording { background: #ef4444; border-color: #ef4444; color: #fff; animation: chatPulseRec 1.2s infinite; }
@keyframes chatPulseRec { 0%,100% { box-shadow: 0 0 0 0 rgba(239,68,68,.5); } 50% { box-shadow: 0 0 0 6px rgba(239,68,68,0); } }

/* Attachment preview strip above the composer (before sending) */
.chat-attach-preview {
  display: none; align-items: center; gap: 10px; padding: 8px 14px;
  border-top: 1px solid var(--chat-border); background: var(--chat-bg-raised); flex-shrink: 0;
  max-width: 100%; box-sizing: border-box;
}
.chat-attach-preview.show { display: flex; }
.chat-attach-preview-thumb {
  width: 40px; height: 40px; border-radius: 8px; object-fit: cover; background: var(--chat-bg-hover); flex-shrink: 0;
}
.chat-attach-preview-icon {
  width: 40px; height: 40px; border-radius: 8px; background: var(--chat-bg-hover); flex-shrink: 0;
  display: flex; align-items: center; justify-content: center; color: var(--chat-text-sub); font-size: 1.1rem;
}
.chat-attach-preview-info { flex: 1; min-width: 0; }
.chat-attach-preview-name { font-size: .74rem; color: var(--chat-text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-attach-preview-size { font-size: .64rem; color: var(--chat-text-muted); }
.chat-attach-preview-remove {
  width: 26px; height: 26px; border-radius: 50%; border: none; background: transparent;
  color: var(--chat-text-sub); cursor: pointer; flex-shrink: 0; display: flex; align-items: center; justify-content: center;
}
.chat-attach-preview-remove:hover { background: var(--chat-bg-hover); color: #ef4444; }

/* Attachment content rendered inside message bubbles */
.chat-msg-attachment-img {
  max-width: 100%; max-height: 220px; border-radius: 10px; display: block; cursor: pointer; margin-bottom: 4px;
}
.chat-msg-attachment-video {
  max-width: 100%; max-height: 220px; border-radius: 10px; display: block; margin-bottom: 4px;
}
.chat-msg-attachment-audio { width: 220px; max-width: 100%; display: block; margin-bottom: 4px; height: 34px; }
.chat-msg-caption { margin-top: 2px; }

/* Full-size image lightbox (attachment click-to-zoom) */
.chat-lightbox {
  position: fixed; inset: 0; z-index: 900; background: rgba(0,0,0,.85);
  display: none; align-items: center; justify-content: center; padding: 30px;
  cursor: zoom-out;
}
.chat-lightbox.show { display: flex; }
.chat-lightbox img { max-width: 100%; max-height: 100%; border-radius: 6px; }

/* Talk-to-human link, hidden by default; JS shows after threshold */
.chat-talk-human-link {
  text-align: center; padding: 8px; font-size: .68rem; color: var(--chat-text-muted);
  border-top: 1px solid var(--chat-border); flex-shrink: 0; background: var(--chat-bg);
  display: none;
}
.chat-talk-human-link button {
  background: none; border: none; color: var(--chat-blue-light); font-weight: 600; cursor: pointer;
  font-size: .68rem; font-family: inherit; text-decoration: underline;
}

/* Help view */
.chat-help-body { flex: 1; overflow-y: auto; padding: 14px 16px; background: var(--chat-bg); }
.chat-faq-item {
  background: var(--chat-bg-raised); border: 1px solid var(--chat-border); border-radius: 10px;
  margin-bottom: 8px; overflow: hidden;
}
.chat-faq-q {
  padding: 11px 13px; font-size: .76rem; font-weight: 600; color: var(--chat-text);
  cursor: pointer; display: flex; justify-content: space-between; align-items: center; gap: 8px;
}
.chat-faq-q svg { width: 12px; height: 12px; color: var(--chat-text-muted); flex-shrink: 0; transition: transform .2s; }
.chat-faq-item.open .chat-faq-q svg { transform: rotate(180deg); }
.chat-faq-a { padding: 0 13px; font-size: .72rem; color: var(--chat-text-sub); line-height: 1.6; max-height: 0; overflow: hidden; transition: max-height .2s ease, padding .2s ease; }
.chat-faq-item.open .chat-faq-a { padding: 0 13px 12px; max-height: 300px; }

/* Track Order view */
.chat-track-body { flex: 1; overflow-y: auto; padding: 14px 16px; background: var(--chat-bg); }
.chat-track-input-row { display: flex; gap: 8px; margin-bottom: 14px; }
.chat-track-input-row input {
  flex: 1; background: var(--chat-bg-raised); border: 1px solid var(--chat-border);
  border-radius: 8px; padding: 9px 12px; font-size: .78rem; color: var(--chat-text); outline: none; font-family: inherit;
}
.chat-track-input-row input:focus { border-color: var(--chat-blue); }
.chat-track-input-row button {
  background: var(--chat-blue); color: #fff; border: none; border-radius: 8px; padding: 9px 16px;
  font-size: .76rem; font-weight: 700; cursor: pointer; flex-shrink: 0;
}
.chat-track-result { background: var(--chat-bg-raised); border: 1px solid var(--chat-border); border-radius: 10px; padding: 14px; display: none; }
.chat-track-result.show { display: block; }
.chat-track-row { display: flex; justify-content: space-between; padding: 6px 0; font-size: .74rem; border-bottom: 1px solid var(--chat-border); }
.chat-track-row:last-child { border-bottom: none; }
.chat-track-row .lbl { color: var(--chat-text-muted); }
.chat-track-row .val { color: var(--chat-text); font-weight: 600; }
.chat-track-empty, .chat-track-error { text-align: center; padding: 30px 10px; color: var(--chat-text-muted); font-size: .76rem; }
.chat-status-pill { font-size: .62rem; font-weight: 700; padding: 2px 9px; border-radius: 99px; text-transform: uppercase; letter-spacing: .3px; }
.chat-status-pill.pending  { background: rgba(245,158,11,.15); color: #f59e0b; }
.chat-status-pill.completed{ background: rgba(34,197,94,.15);  color: #22c55e; }
.chat-status-pill.failed   { background: rgba(239,68,68,.15);  color: #ef4444; }
.chat-status-pill.refunded { background: rgb(var(--blue-rgb, 37 99 235) / .15); color: var(--blue-light); }

/* Chats list view */
.chat-tickets-body { flex: 1; overflow-y: auto; padding: 10px 12px; background: var(--chat-bg); }
.chat-ticket-item {
  display: flex; gap: 10px; align-items: center; padding: 11px 10px; border-radius: 10px;
  cursor: pointer; transition: background .15s; margin-bottom: 4px;
}
.chat-ticket-item:hover { background: var(--chat-bg-hover); }
.chat-ticket-avatar { width: 34px; height: 34px; border-radius: 50%; background: var(--chat-bg-hover); display: flex; align-items: center; justify-content: center; flex-shrink: 0; color: var(--chat-blue-light); }
.chat-ticket-avatar svg { width: 17px; height: 17px; }
.chat-ticket-text { flex: 1; min-width: 0; }
.chat-ticket-title { font-size: .76rem; font-weight: 700; color: var(--chat-text); display: flex; align-items: center; gap: 4px; }
.chat-ticket-preview { font-size: .68rem; color: var(--chat-text-sub); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-ticket-meta { text-align: right; flex-shrink: 0; }
.chat-ticket-time { font-size: .6rem; color: var(--chat-text-muted); }

/* Chats tab header with + button */
.chat-tickets-header-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px 4px; flex-shrink: 0;
  border-bottom: 1px solid var(--chat-border);
  background: var(--chat-bg);
}
.chat-tickets-header-row .chat-tickets-title {
  font-size: .78rem; font-weight: 700; color: var(--chat-text);
}
.chat-new-chat-icon-btn {
  width: 30px; height: 30px; border-radius: 50%;
  background: var(--chat-bg-raised); border: 1px solid var(--chat-border);
  color: var(--chat-blue-light); cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: background .15s;
}
.chat-new-chat-icon-btn:hover { background: var(--chat-bg-hover); }
.chat-new-chat-icon-btn svg { width: 14px; height: 14px; }

/* Bottom nav */
.chat-bottomnav {
  display: flex; flex-shrink: 0; border-top: 1px solid var(--chat-border);
  background: var(--chat-bg-raised);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
.chat-nav-item {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 3px;
  padding: 9px 4px 8px; cursor: pointer; color: var(--chat-text-muted); background: none; border: none;
  font-family: inherit;
}
.chat-nav-item svg { width: 18px; height: 18px; }
.chat-nav-item span { font-size: .58rem; font-weight: 600; }
.chat-nav-item.active { color: var(--chat-blue-light); }

.chat-empty-state { display: flex; flex-direction: column; align-items: center; justify-content: center; flex: 1; padding: 30px; text-align: center; color: var(--chat-text-muted); gap: 8px; }
.chat-empty-state svg { width: 40px; height: 40px; opacity: .5; }
.chat-empty-state p { font-size: .76rem; }
