/* ==========================================================
   NeuralPress — Smart Support Chat Widget
   Author: Ali Feizbakhsh Haghighi | Tarh Rayan
   © 2025 — All rights reserved
   ========================================================== */

/* ── Widget wrapper — always fixed to viewport ── */
#np-chat {
  --npc: #6366f1;           /* overridden by inline style */
  position: fixed !important;
  z-index: 999999 !important;
  bottom: 24px;
  right:  24px;
  left:   auto;
  top:    auto;
  font-family: 'Vazirmatn', 'Plus Jakarta Sans', system-ui, sans-serif;
}
#np-chat * { box-sizing: border-box; margin: 0; padding: 0; }

/* RTL default */
html[dir="rtl"] #np-chat { right: auto; left: 24px; }

/* Position variants via data-pos attribute */
#np-chat[data-pos="bottom-left"]  { right: auto !important; left: 24px !important; }
#np-chat[data-pos="top-right"]    { bottom: auto !important; top: 24px !important; }
#np-chat[data-pos="top-left"]     { bottom: auto !important; top: 24px !important;
                                     right: auto !important; left: 24px !important; }

/* ── Trigger button ── */
#np-chat-btn {
  width: 54px; height: 54px;
  border-radius: 50%;
  background: var(--npc);
  border: none;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 4px 18px rgba(0,0,0,.32);
  transition: transform .2s ease, box-shadow .2s ease;
  position: relative;
}
#np-chat-btn:hover { transform: scale(1.1); box-shadow: 0 6px 24px rgba(0,0,0,.42); }
#np-chat-btn:active { transform: scale(.95); }
.np-btn-icon { display: flex; align-items: center; justify-content: center; }
.np-btn-icon svg, .np-btn-icon img { display: block; }

/* Unread badge */
#np-unread {
  position: absolute; top: -3px; right: -3px;
  width: 18px; height: 18px; border-radius: 50%;
  background: #ef4444; color: #fff; font-size: 10px; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  border: 2px solid #fff; pointer-events: none;
  animation: npPop .3s ease;
}
@keyframes npPop { from { transform: scale(0); } to { transform: scale(1); } }

/* ── Chat panel ── */
#np-chat-panel {
  display: none;
  position: absolute;
  bottom: 64px; right: 0;
  width: 336px; max-width: 94vw;
  background: #13131f;
  color: #e8e8f0;
  border: 1px solid rgba(255,255,255,.08);
  border-radius: 18px;
  overflow: hidden;
  box-shadow: 0 18px 52px rgba(0,0,0,.56);
  flex-direction: column;
}
/* Panel position adjustments */
#np-chat[data-pos="bottom-left"]  #np-chat-panel { right: auto; left: 0; }
#np-chat[data-pos="top-right"]    #np-chat-panel { bottom: auto; top: 64px; }
#np-chat[data-pos="top-left"]     #np-chat-panel { bottom: auto; top: 64px; right: auto; left: 0; }
html[dir="rtl"]                   #np-chat-panel { right: auto; left: 0; }

/* ── Header ── */
#np-chat-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 13px 15px;
  background: var(--npc);
  flex-shrink: 0;
}
#np-chat-info { display: flex; align-items: center; gap: 10px; }
#np-chat-logo {
  width: 34px; height: 34px; border-radius: 50%;
  background: rgba(255,255,255,.18);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0; overflow: hidden;
}
#np-chat-name  { font-size: 13px; font-weight: 700; color: #fff; }
#np-chat-status {
  font-size: 11px; color: rgba(255,255,255,.75);
  display: flex; align-items: center; gap: 4px; margin-top: 2px;
}
.np-dot {
  width: 7px; height: 7px; border-radius: 50%; background: #4ade80; flex-shrink: 0;
  animation: npPulse 2s ease-in-out infinite;
}
@keyframes npPulse { 0%,100%{opacity:1} 50%{opacity:.5} }
#np-chat-close {
  background: none; border: none; color: rgba(255,255,255,.7);
  font-size: 16px; cursor: pointer; padding: 3px 7px;
  border-radius: 4px; line-height: 1;
}
#np-chat-close:hover { background: rgba(255,255,255,.12); color: #fff; }

/* ── Messages ── */
#np-chat-msgs {
  flex: 1; overflow-y: auto; padding: 14px 12px;
  display: flex; flex-direction: column; gap: 10px;
  min-height: 220px; max-height: 320px;
  background: #0a0a14;
}
#np-chat-msgs::-webkit-scrollbar { width: 3px; }
#np-chat-msgs::-webkit-scrollbar-thumb { background: rgba(255,255,255,.1); border-radius: 2px; }
.np-msg { display: flex; }
.np-msg-user { justify-content: flex-end; }
.np-msg-bot  { justify-content: flex-start; }
.np-bubble {
  max-width: 80%; padding: 10px 13px; border-radius: 15px;
  font-size: 13px; line-height: 1.65; word-break: break-word;
}
.np-msg-user .np-bubble {
  background: var(--npc); color: #fff;
  border-bottom-right-radius: 4px;
}
.np-msg-bot  .np-bubble {
  background: #1d1d30; color: #d4d4ec;
  border: 1px solid rgba(255,255,255,.06);
  border-bottom-left-radius: 4px;
}
.np-msg-err .np-bubble { background: rgba(239,68,68,.15); color: #fca5a5; }

/* RTL message swap */
html[dir="rtl"] .np-msg-user { justify-content: flex-start; }
html[dir="rtl"] .np-msg-user .np-bubble { border-radius: 15px; border-bottom-left-radius: 4px; }
html[dir="rtl"] .np-msg-bot  { justify-content: flex-end; }
html[dir="rtl"] .np-msg-bot  .np-bubble { border-radius: 15px; border-bottom-right-radius: 4px; }

/* ── Typing dots ── */
.np-typing { display: flex !important; gap: 5px; align-items: center; padding: 11px 14px !important; }
.np-typing span {
  width: 7px; height: 7px; background: rgba(255,255,255,.35);
  border-radius: 50%; animation: npBounce 1.1s ease-in-out infinite;
}
.np-typing span:nth-child(2) { animation-delay: .17s; }
.np-typing span:nth-child(3) { animation-delay: .34s; }
@keyframes npBounce { 0%,60%,100%{transform:translateY(0)} 30%{transform:translateY(-6px)} }

/* ── Sources (offline mode) ── */
#np-chat-srcs {
  padding: 8px 12px;
  background: #0a0a14;
  border-top: 1px solid rgba(255,255,255,.04);
  flex-shrink: 0;
}
.np-src-lbl { font-size: 11px; color: rgba(255,255,255,.35); margin-bottom: 4px; }
.np-src-a {
  display: block; font-size: 12px; color: #818cf8;
  text-decoration: none; padding: 3px 0;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  border-bottom: 1px solid rgba(255,255,255,.04);
}
.np-src-a:last-child { border-bottom: none; }
.np-src-a:hover { color: #a5b4fc; text-decoration: underline; }

/* ── Input bar ── */
#np-chat-bar {
  display: flex; gap: 7px; padding: 10px 11px;
  background: #13131f;
  border-top: 1px solid rgba(255,255,255,.06);
  flex-shrink: 0;
}
#np-chat-in {
  flex: 1; padding: 9px 12px;
  background: #0a0a14;
  border: 1px solid rgba(255,255,255,.1);
  border-radius: 10px; color: #e8e8f0;
  font-size: 13px; font-family: inherit; outline: none;
  transition: border-color .2s;
}
#np-chat-in::placeholder { color: rgba(255,255,255,.28); }
#np-chat-in:focus { border-color: var(--npc); }
#np-chat-in:disabled { opacity: .45; }
#np-chat-send {
  width: 38px; height: 38px; border-radius: 10px; border: none;
  background: var(--npc); color: #fff; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0; transition: filter .2s, transform .15s;
}
#np-chat-send:hover  { filter: brightness(1.15); }
#np-chat-send:active { transform: scale(.92); }

/* ── Mobile Responsive (v3.3.3) ────────────────────────── */
@media (max-width: 600px) {

  /* Button stays in corner, closer to edge */
  #np-chat {
    bottom: 16px !important;
    right:  16px !important;
    left:   auto !important;
    top:    auto !important;
  }
  html[dir="rtl"] #np-chat {
    right: auto  !important;
    left:  16px  !important;
  }

  /* Panel: full-width strip above the button */
  #np-chat-panel {
    position:   fixed       !important;
    bottom:     84px        !important;  /* clear the 54px button + 16px gap + 14px margin */
    right:      10px        !important;
    left:       10px        !important;
    width:      auto        !important;
    max-width:  none        !important;
    max-height: calc(100dvh - 120px) !important; /* don't overflow viewport */
    border-radius: 16px     !important;
    overflow:   hidden      !important;
  }
  /* RTL: same insets */
  html[dir="rtl"] #np-chat-panel {
    right: 10px !important;
    left:  10px !important;
  }

  /* Messages: shrink to give room to header + input bar */
  #np-chat-msgs {
    min-height: 120px                    !important;
    max-height: calc(100dvh - 230px)     !important;
    overflow-y: auto                     !important;
  }

  /* Bubbles: use more width */
  .np-bubble { max-width: 88%; }

  /* Input: 16px prevents iOS Safari auto-zoom on focus */
  #np-chat-in {
    font-size: 16px !important;
    padding: 10px 12px !important;
  }

  /* Slightly larger send button for thumbs */
  #np-chat-send { width: 42px !important; height: 42px !important; }

  /* Tighter header */
  #np-chat-head { padding: 10px 13px !important; }
}

/* Landscape phone: reduce heights */
@media (max-height: 500px) and (max-width: 768px) {
  #np-chat-panel { max-height: 70vh   !important; }
  #np-chat-msgs  { max-height: 35vh   !important; min-height: 60px !important; }
}
