/* ===== PIRO Chatbot Widget Styles =====
   All values reference existing CSS vars from styles.css.
   Z-index: 3000 (above header 1000, drawer 2000, profile-menu 2500).
   RTL panel — direction:rtl hard-coded regardless of document direction.
======================================== */

/* ── Floating button ───────────────────────────────────────────── */
#piro-chat-btn {
  position: fixed;
  bottom: 24px;
  left: 24px;          /* RTL: left side of viewport */
  width: 54px;
  height: 54px;
  border-radius: 50%;
  background: var(--burgundy);
  color: #fff;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 3000;
  box-shadow: 0 4px 20px rgba(139, 38, 53, 0.38);
  transition: background 0.22s, transform 0.22s, box-shadow 0.22s;
}
#piro-chat-btn:hover {
  background: var(--burgundy-dark);
  transform: translateY(-2px);
  box-shadow: 0 8px 28px rgba(139, 38, 53, 0.48);
}
#piro-chat-btn:focus-visible {
  outline: 2px solid var(--burgundy);
  outline-offset: 3px;
}
/* Pulse on first load (runs 3 times, starts after 1.5s) */
#piro-chat-btn:not(.active) {
  animation: piroBtnPulse 2.4s ease-in-out 1.5s 3;
}
@keyframes piroBtnPulse {
  0%, 100% { box-shadow: 0 4px 20px rgba(139, 38, 53, 0.38); }
  50%       { box-shadow: 0 4px 28px rgba(139, 38, 53, 0.6), 0 0 0 8px rgba(139, 38, 53, 0.1); }
}

/* Icon swap: chat icon ↔ × when open */
#piro-chat-btn .icon-chat  { display: block; }
#piro-chat-btn .icon-close { display: none;  }
#piro-chat-btn.active .icon-chat  { display: none;  }
#piro-chat-btn.active .icon-close { display: block; }

/* ── Chat panel ────────────────────────────────────────────────── */
#piro-chat-panel {
  position: fixed;
  bottom: 90px;
  left: 24px;
  width: 380px;
  height: 500px;
  z-index: 3000;
  background: var(--bg);
  border: 1px solid var(--line);
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.14);
  display: flex;
  flex-direction: column;
  direction: rtl;          /* always RTL regardless of document lang */
  font-family: var(--font-fa), sans-serif;
  font-size: 14px;
  line-height: 1.6;
  /* Hidden state */
  opacity: 0;
  visibility: hidden;
  transform: translateY(16px);
  transition: opacity 0.32s var(--ease), transform 0.32s var(--ease), visibility 0.32s;
  border-radius: 4px;
  overflow: hidden;
}
#piro-chat-panel.open {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

/* ── Header ────────────────────────────────────────────────────── */
.piro-chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  background: var(--burgundy);
  color: #fff;
  flex-shrink: 0;
}
.piro-chat-header-info {
  display: flex;
  align-items: center;
  gap: 10px;
}
.piro-chat-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.22);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 600;
  font-family: var(--font-lat), sans-serif;
  letter-spacing: 0.5px;
  flex-shrink: 0;
}
.piro-chat-name {
  font-size: 14px;
  font-weight: 600;
  color: #fff;
}
.piro-chat-status {
  font-size: 12px;
  color: rgba(255, 255, 255, 0.75);
  display: flex;
  align-items: center;
  gap: 5px;
}
.piro-chat-status::before {
  content: '';
  display: inline-block;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #4ade80;
}
.piro-chat-close {
  background: none;
  border: none;
  color: rgba(255, 255, 255, 0.8);
  cursor: pointer;
  padding: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  transition: color 0.2s, background 0.2s;
}
.piro-chat-close:hover { color: #fff; background: rgba(255,255,255,0.12); }

/* ── Messages area ─────────────────────────────────────────────── */
.piro-chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 14px 14px 8px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  scroll-behavior: smooth;
}
.piro-chat-messages::-webkit-scrollbar { width: 4px; }
.piro-chat-messages::-webkit-scrollbar-track { background: transparent; }
.piro-chat-messages::-webkit-scrollbar-thumb { background: var(--line); border-radius: 2px; }
.piro-chat-messages::-webkit-scrollbar-thumb:hover { background: var(--grey); }

/* ── Message bubbles ───────────────────────────────────────────── */
.piro-msg {
  max-width: 82%;
  padding: 9px 13px;
  border-radius: 18px;
  font-size: 13.5px;
  line-height: 1.65;
  word-break: break-word;
  white-space: pre-wrap;
  animation: piroMsgIn 0.22s ease forwards;
}
@keyframes piroMsgIn {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* Bot: left-aligned (RTL end = left) */
.piro-msg--assistant {
  align-self: flex-end;
  background: var(--bg-warm);
  color: var(--ink);
  border-bottom-left-radius: 4px;
}
/* User: right-aligned (RTL start = right) */
.piro-msg--user {
  align-self: flex-start;
  background: var(--burgundy);
  color: #fff;
  border-bottom-right-radius: 4px;
}

/* ── Typing indicator ──────────────────────────────────────────── */
.piro-typing {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 12px 16px;
  background: var(--bg-warm);
  border-radius: 18px;
  border-bottom-left-radius: 4px;
  align-self: flex-end;
}
.piro-typing span {
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--grey);
  animation: piroTypingDot 1.2s ease-in-out infinite;
}
.piro-typing span:nth-child(2) { animation-delay: 0.2s; }
.piro-typing span:nth-child(3) { animation-delay: 0.4s; }
@keyframes piroTypingDot {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
  30%            { transform: translateY(-5px); opacity: 1; }
}

/* ── Quick reply buttons ───────────────────────────────────────── */
.piro-quick-replies {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  padding: 8px 14px 10px;
  border-top: 1px solid var(--line);
  background: var(--bg);
  flex-shrink: 0;
}
.piro-qr-btn {
  background: none;
  border: 1px solid var(--burgundy);
  color: var(--burgundy);
  border-radius: 20px;
  padding: 5px 12px;
  font-size: 12px;
  font-family: var(--font-fa), sans-serif;
  cursor: pointer;
  transition: background 0.18s, color 0.18s;
  white-space: nowrap;
  line-height: 1.5;
}
.piro-qr-btn:hover {
  background: var(--burgundy);
  color: #fff;
}

/* ── Input footer ──────────────────────────────────────────────── */
.piro-chat-footer {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 10px 12px 12px;
  border-top: 1px solid var(--line);
  background: var(--bg);
  flex-shrink: 0;
}
#piro-input {
  flex: 1;
  resize: none;
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 8px 14px;
  font-family: var(--font-fa), sans-serif;
  font-size: 13px;
  color: var(--ink);
  background: var(--bg-soft);
  outline: none;
  transition: border-color 0.2s;
  max-height: 120px;
  overflow-y: auto;
  line-height: 1.5;
  direction: rtl;
}
#piro-input:focus { border-color: var(--burgundy); }
#piro-input::placeholder { color: var(--grey); }

#piro-send {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--burgundy);
  color: #fff;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.18s, transform 0.18s;
}
#piro-send:hover:not(:disabled) { background: var(--burgundy-dark); transform: scale(1.05); }
#piro-send:disabled { opacity: 0.5; cursor: not-allowed; }

/* ── Mobile: full-screen panel ─────────────────────────────────── */
@media (max-width: 600px) {
  #piro-chat-panel {
    inset: 0;
    width: 100%;
    height: 100%;
    bottom: auto;
    left: auto;
    border-radius: 0;
    border: none;
  }
  #piro-chat-btn {
    bottom: 16px;
    left: 16px;
  }
}

/* ── Reduced motion ─────────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  #piro-chat-btn,
  #piro-chat-panel,
  .piro-msg,
  .piro-typing span {
    animation: none !important;
    transition: none !important;
  }
}
