/* ================= floating chat widget ================= */
/* Kept in its own file (not styles.css) so the chatbot can be
   iterated on independently, per project convention. */

#chatWidget{ position:fixed; bottom:24px; right:24px; z-index:500; }
html[dir="rtl"] #chatWidget{ right:auto; left:24px; }

.chat-toggle{
  width:60px; height:60px; border-radius:50%; border:none; cursor:none;
  background:linear-gradient(135deg,var(--blue),var(--cyan));
  display:flex; align-items:center; justify-content:center; font-size:24px;
  box-shadow:0 10px 30px rgba(61,90,254,0.45), 0 0 0 1px rgba(255,255,255,0.08);
  position:relative;
}
@media (max-width:860px){ .chat-toggle{ cursor:pointer; } }
.chat-toggle .badge{ position:absolute; top:-2px; right:-2px; width:14px; height:14px; border-radius:50%; background:#34D399; border:2px solid var(--void); }
.chat-toggle .badge.unread{ background:#F87171; }
.chat-toggle .chat-toggle-icon{ width:30px; height:30px; border-radius:8px; object-fit:cover; }

.chat-panel{
  position:absolute; bottom:76px; right:0; width:360px; max-width:88vw;
  background:var(--panel); border:1px solid var(--line); border-radius:16px;
  box-shadow:0 30px 80px rgba(0,0,0,0.45); overflow:hidden;
  display:flex; flex-direction:column; opacity:0; transform:translateY(16px) scale(0.97);
  pointer-events:none; transition:opacity .22s ease, transform .22s ease;
  backdrop-filter:blur(20px);
}
html[dir="rtl"] .chat-panel{ right:auto; left:0; }
#chatWidget.open .chat-panel{ opacity:1; transform:translateY(0) scale(1); pointer-events:auto; }

@media (prefers-reduced-motion: reduce){
  .chat-panel{ transition:opacity .01s linear; transform:none; }
  #chatWidget.open .chat-panel{ transform:none; }
  .chat-typing span, .chat-toggle .badge{ animation:none !important; }
}

.chat-panel-head{ padding:14px 16px; border-bottom:1px solid var(--line); display:flex; align-items:center; gap:10px; }
.chat-panel-head .avatar{ width:30px; height:30px; border-radius:9px; object-fit:cover; flex-shrink:0; background:var(--deep); }
.chat-panel-head .name{ font-size:13.5px; font-weight:600; }
.chat-panel-head .status{ font-size:10.5px; color:var(--cyan); display:flex; align-items:center; gap:5px; }
.chat-panel-head .status.human{ color:#F59E0B; }
.chat-panel-head .status .pulse-dot{ width:5px; height:5px; border-radius:50%; background:currentColor; box-shadow:0 0 6px currentColor; animation:pulse 1.6s infinite; }
.chat-close{ margin-left:auto; background:none; border:none; color:var(--mist); font-size:16px; cursor:none; width:26px; height:26px; }
.chat-menu-wrap{ position:relative; }
.chat-menu-btn{
  background:none; border:none; color:var(--mist); cursor:none;
  width:28px; height:28px; padding:0; opacity:.8; border-radius:8px;
  display:flex; align-items:center; justify-content:center;
  transition:color .18s ease, opacity .18s ease, background .18s ease;
}
.chat-menu-btn svg{ width:17px; height:17px; }
.chat-menu-btn:hover, .chat-menu-btn[aria-expanded="true"]{ color:var(--cyan); opacity:1; background:rgba(34,211,238,0.08); }

.chat-menu-dropdown{
  position:absolute; top:calc(100% + 8px); right:0; min-width:172px; z-index:20;
  background:var(--panel); border:1px solid var(--line); border-radius:12px;
  box-shadow:0 16px 40px rgba(0,0,0,0.45); padding:6px; overflow:hidden;
  animation:historyFadeIn .16s ease;
}
html[dir="rtl"] .chat-menu-dropdown{ right:auto; left:0; }
.chat-menu-item{
  display:flex; align-items:center; gap:9px; width:100%; text-align:left;
  background:none; border:none; color:var(--white); font-size:12.5px; font-weight:500;
  padding:9px 10px; border-radius:8px; cursor:pointer; transition:background .15s;
}
html[dir="rtl"] .chat-menu-item{ text-align:right; }
.chat-menu-item svg{ width:15px; height:15px; color:var(--cyan); flex-shrink:0; }
.chat-menu-item:hover{ background:rgba(34,211,238,0.08); }
@media (max-width:860px){ .chat-menu-btn{ cursor:pointer; } .chat-menu-item{ cursor:pointer; } }

/* Bulletproof "hide this view" toggle for swapping live chat <-> history -
   uses a dedicated class instead of the [hidden] attribute, since
   [hidden]'s default display:none is easily beaten by any class selector
   of equal specificity that sets its own `display` (e.g. .chat-panel-body
   sets display:flex, which otherwise silently wins and leaves the panel
   visible even while "hidden"). */
.chat-view-hidden{ display:none !important; }
.chat-close:focus-visible, .chat-toggle:focus-visible, .chat-send-btn:focus-visible, .chat-panel-input input:focus-visible, .quick-action:focus-visible, .chat-menu-btn:focus-visible{
  outline:2px solid var(--cyan); outline-offset:2px;
}
@media (max-width:860px){ .chat-close{ cursor:pointer; } .chat-menu-btn{ cursor:pointer; } }
html[dir="rtl"] .chat-close{ margin-left:0; margin-right:auto; }

/* System banner, e.g. "An agent has joined the conversation" */
.chat-system-banner{ text-align:center; font-size:11px; color:var(--mist-dim); font-style:italic; padding:4px 0; }

.chat-panel-body{ padding:16px; display:flex; flex-direction:column; gap:12px; max-height:400px; overflow-y:auto; scroll-behavior:smooth; }
.chat-panel-body .bubble{ max-width:86%; font-size:13px; line-height:1.5; padding:9px 12px; border-radius:14px; }
.chat-panel-body .bubble.bot,
.chat-panel-body .bubble.admin{ align-self:flex-start; background:var(--deep); border:1px solid var(--line); border-bottom-left-radius:4px; }
html[dir="rtl"] .chat-panel-body .bubble.bot, html[dir="rtl"] .chat-panel-body .bubble.admin{ border-bottom-left-radius:14px; border-bottom-right-radius:4px; }
.chat-panel-body .bubble.admin{ border-color:rgba(245,158,11,0.4); }
.chat-panel-body .bubble.user{ align-self:flex-end; background:linear-gradient(135deg,var(--blue),var(--cyan)); color:#05060B; border-bottom-right-radius:4px; }
html[dir="rtl"] .chat-panel-body .bubble.user{ align-self:flex-start; border-bottom-right-radius:14px; border-bottom-left-radius:4px; }
.chat-panel-body .bubble .sender-label{ display:block; font-size:9.5px; text-transform:uppercase; letter-spacing:.04em; opacity:.6; margin-bottom:2px; }

.chat-panel-body .bubble .action-btn{
  display:inline-block; margin-top:8px; font-size:11.5px; font-weight:600; color:var(--cyan);
  border:1px solid rgba(34,211,238,0.35); border-radius:100px; padding:5px 12px; cursor:none;
}
@media (max-width:860px){ .chat-panel-body .bubble .action-btn{ cursor:pointer; } }
.chat-panel-body .bubble .action-btn:hover{ background:rgba(34,211,238,0.08); }

/* Name / email-or-phone form shown before "Speak with the team" fires */
.chat-human-form-wrap{ display:flex; flex-direction:column; gap:8px; max-width:92%; }
.chat-human-form{ display:flex; flex-direction:column; gap:8px; margin-top:4px; }
.chat-human-form input{
  background:var(--panel); border:1px solid var(--line); border-radius:8px;
  padding:8px 10px; color:var(--white); font-size:12.5px; outline:none;
}
.chat-human-form input:focus{ border-color:var(--cyan); }
.chat-human-form-error{ font-size:11px; color:#F87171; min-height:14px; }
.chat-human-form-btns{ display:flex; gap:8px; }
.chat-human-form-btns button[type="submit"]{
  flex:1; background:linear-gradient(135deg,var(--blue),var(--cyan)); color:#05060B;
  border:none; border-radius:100px; padding:8px 14px; font-size:12px; font-weight:600; cursor:pointer;
}
.chat-human-form-skip{
  background:none; border:1px solid var(--line); color:var(--mist); border-radius:100px;
  padding:8px 14px; font-size:12px; cursor:pointer;
}

/* "Your past conversations" panel - replaces the live chat body while open */
.chat-history-view{
  padding:16px; display:flex; flex-direction:column; gap:8px; max-height:400px; overflow-y:auto;
  animation:historyFadeIn .2s ease;
}
@keyframes historyFadeIn{ from{ opacity:0; transform:translateY(6px); } to{ opacity:1; transform:translateY(0); } }
.chat-history-title{
  font-size:12.5px; font-weight:600; color:var(--white); margin-bottom:6px;
  display:flex; align-items:center; gap:7px; justify-content:space-between;
}
.chat-history-title::before{
  content:''; width:6px; height:6px; border-radius:50%;
  background:linear-gradient(135deg,var(--blue),var(--cyan)); flex-shrink:0;
}
.chat-history-title-text{ display:flex; align-items:center; gap:7px; }
.chat-history-new-btn{
  display:flex; align-items:center; gap:5px; background:none; border:1px solid rgba(34,211,238,0.35);
  color:var(--cyan); font-size:11px; font-weight:600; border-radius:100px; padding:5px 11px; cursor:pointer;
  transition:background .15s;
}
.chat-history-new-btn:hover{ background:rgba(34,211,238,0.08); }
.chat-history-new-btn svg{ width:11px; height:11px; }
.chat-history-empty{ font-size:12px; color:var(--mist-dim); text-align:center; padding:28px 12px; line-height:1.6; }
.chat-history-item{
  display:flex; align-items:center; gap:10px; text-align:left; background:var(--deep);
  border:1px solid var(--line); border-radius:12px; padding:10px 12px; cursor:pointer;
  transition:border-color .15s, background .15s, transform .15s;
}
.chat-history-item:hover{ border-color:var(--cyan); background:rgba(34,211,238,0.05); transform:translateX(2px); }
html[dir="rtl"] .chat-history-item{ text-align:right; }
html[dir="rtl"] .chat-history-item:hover{ transform:translateX(-2px); }
.chat-history-item-status{ width:8px; height:8px; border-radius:50%; flex-shrink:0; background:#34D399; }
.chat-history-item-status.pending_human{ background:#F59E0B; }
.chat-history-item-status.human{ background:#F59E0B; }
.chat-history-item-status.closed{ background:var(--mist-dim); }
.chat-history-item-text{ display:flex; flex-direction:column; gap:2px; min-width:0; flex:1; }
.chat-history-item-date{ font-size:10.5px; color:var(--cyan); font-weight:600; }
.chat-history-item-preview{ font-size:12px; color:var(--mist); overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
.chat-history-back{
  align-self:flex-start; display:flex; align-items:center; gap:6px; background:none; border:none; color:var(--cyan);
  font-size:12px; font-weight:600; cursor:pointer; padding:8px 2px; margin-top:4px;
}
.chat-history-back:hover{ opacity:.8; }
.chat-history-back-top{ margin-top:0; margin-bottom:4px; }
@media (max-width:860px){ .chat-history-item, .chat-history-back{ cursor:pointer; } }

.chat-quick-actions{ display:flex; flex-wrap:wrap; gap:8px; padding:0 16px 14px; }
.quick-action{
  font-size:12px; font-weight:600; color:var(--white); background:var(--deep);
  border:1px solid var(--line); border-radius:100px; padding:7px 13px; cursor:pointer;
  transition:border-color .15s, background .15s;
}
.quick-action:hover{ border-color:var(--cyan); background:rgba(34,211,238,0.08); }

.chat-typing{ display:flex; gap:4px; padding:10px 14px; align-self:flex-start; }
.chat-typing span{ width:6px; height:6px; border-radius:50%; background:var(--mist-dim); animation:typingBounce 1s infinite; }
.chat-typing span:nth-child(2){ animation-delay:.15s; }
.chat-typing span:nth-child(3){ animation-delay:.3s; }
@keyframes typingBounce{ 0%,60%,100%{ transform:translateY(0); opacity:.4; } 30%{ transform:translateY(-4px); opacity:1; } }

.chat-panel-input{ padding:12px; border-top:1px solid var(--line); display:flex; gap:8px; padding-bottom:calc(12px + env(safe-area-inset-bottom)); }
.chat-panel-input input{
  flex:1; background:var(--deep); border:1px solid var(--line); border-radius:9px;
  padding:11px 12px; color:var(--white); font-size:13px; outline:none;
}
.chat-panel-input input:focus{ border-color:var(--cyan); }
.chat-send-btn{
  width:38px; height:38px; border-radius:9px; border:none; flex-shrink:0;
  background:linear-gradient(135deg,var(--blue),var(--cyan)); color:#05060B; font-size:14px; cursor:none;
}
.chat-send-btn:disabled{ opacity:.5; cursor:not-allowed; }
@media (max-width:860px){ .chat-send-btn{ cursor:pointer; } }

@media (max-width:480px){
  #chatWidget{ bottom:16px; right:16px; }
  html[dir="rtl"] #chatWidget{ left:16px; right:auto; }

  /* Full-screen mobile mode: covers the viewport, respects notches/home
     indicator, and locks background scroll (toggled via body.chat-open
     in chat.js) while keeping the input above the on-screen keyboard. */
  .chat-panel{
    position:fixed; inset:0; width:100%; max-width:none; height:100%;
    max-height:none; border-radius:0; bottom:auto; right:auto;
    padding-top:env(safe-area-inset-top);
  }
  .chat-panel-head{ position:sticky; top:0; background:var(--panel); z-index:1; }
  .chat-panel-body{ max-height:none; flex:1; }
  .chat-close{ width:34px; height:34px; font-size:18px; }
  .chat-menu-btn{ width:36px; height:36px; }
  .chat-menu-btn svg{ width:19px; height:19px; }
  .chat-history-view{ max-height:none; flex:1; }
  .quick-action, .chat-send-btn, .chat-toggle{ min-height:44px; } /* large touch targets */
}
html.chat-open{ overflow:hidden; } /* prevent background scroll under the full-screen widget */