/* ============ Chat Widget ============ */
.chat-fab {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 60px; height: 60px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--primary), #e0c078);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 8px 30px rgba(201,169,97,.5), 0 0 0 0 rgba(201,169,97,.6);
  z-index: 9990;
  transition: transform .25s, box-shadow .25s;
  animation: chatPulse 2.4s ease-out 3s infinite;
}
[dir="rtl"] .chat-fab { right: auto; left: 24px; }
.chat-fab:hover { transform: scale(1.08); }
.chat-fab:active { transform: scale(.95); }
.chat-fab-icon { font-size: 26px; line-height: 1; }
.chat-fab-badge {
  position: absolute;
  top: -4px; right: -4px;
  background: #ef4444;
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  min-width: 20px; height: 20px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 5px;
  border: 2px solid #fff;
  animation: chatBadgePop .3s ease-out;
}
@keyframes chatPulse {
  0%   { box-shadow: 0 8px 30px rgba(201,169,97,.5), 0 0 0 0 rgba(201,169,97,.6); }
  70%  { box-shadow: 0 8px 30px rgba(201,169,97,.5), 0 0 0 18px rgba(201,169,97,0); }
  100% { box-shadow: 0 8px 30px rgba(201,169,97,.5), 0 0 0 0 rgba(201,169,97,0); }
}
@keyframes chatBadgePop {
  from { transform: scale(0); }
  to   { transform: scale(1); }
}

.chat-window {
  position: fixed;
  bottom: 96px;
  right: 24px;
  width: 380px;
  max-width: calc(100vw - 32px);
  height: 560px;
  max-height: calc(100vh - 140px);
  background: #fff;
  border-radius: 20px;
  box-shadow: 0 20px 70px rgba(0,0,0,.18), 0 4px 20px rgba(0,0,0,.08);
  display: none;
  flex-direction: column;
  z-index: 9991;
  overflow: hidden;
  animation: chatWindowIn .3s cubic-bezier(.4,0,.2,1);
}
[dir="rtl"] .chat-window { right: auto; left: 24px; }
.chat-window.open { display: flex; }
@keyframes chatWindowIn {
  from { opacity: 0; transform: translateY(20px) scale(.96); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

.chat-header {
  background: linear-gradient(135deg, var(--secondary), #2d3348);
  color: #fff;
  padding: 14px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.chat-header-info { display: flex; align-items: center; gap: 12px; }
.chat-avatar {
  width: 42px; height: 42px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--primary), #e0c078);
  display: flex; align-items: center; justify-content: center;
  overflow: hidden;
  font-size: 20px;
  flex-shrink: 0;
}
.chat-avatar img { width: 100%; height: 100%; object-fit: cover; }
.chat-header-name { font-weight: 700; font-size: 14px; }
.chat-header-status {
  font-size: 11.5px;
  opacity: .85;
  display: flex;
  align-items: center;
  gap: 5px;
  margin-top: 2px;
}
.chat-status-dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: #9ca3af;
}
.chat-status-dot.online {
  background: #22c55e;
  box-shadow: 0 0 0 3px rgba(34,197,94,.25);
  animation: statusPulse 2s infinite;
}
@keyframes statusPulse {
  0%, 100% { box-shadow: 0 0 0 3px rgba(34,197,94,.25); }
  50%      { box-shadow: 0 0 0 6px rgba(34,197,94,.08); }
}
.chat-close {
  width: 30px; height: 30px;
  background: rgba(255,255,255,.12);
  border: none;
  border-radius: 8px;
  color: #fff;
  font-size: 14px;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: background .2s;
}
.chat-close:hover { background: rgba(255,255,255,.25); }

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  background: #f8fafc;
  display: flex;
  flex-direction: column;
  gap: 10px;
  scroll-behavior: smooth;
}
.chat-messages::-webkit-scrollbar { width: 6px; }
.chat-messages::-webkit-scrollbar-thumb { background: #d1d5db; border-radius: 3px; }

.chat-loading { text-align: center; color: #9ca3af; font-size: 13px; padding: 20px; }

.chat-bubble {
  max-width: 78%;
  padding: 10px 14px;
  border-radius: 18px;
  font-size: 14px;
  line-height: 1.5;
  word-wrap: break-word;
  animation: bubbleIn .25s ease-out;
  position: relative;
}
@keyframes bubbleIn {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}
.chat-bubble.customer {
  align-self: flex-end;
  background: linear-gradient(135deg, var(--primary), #d4b374);
  color: #fff;
  border-bottom-right-radius: 6px;
}
[dir="rtl"] .chat-bubble.customer { border-bottom-right-radius: 18px; border-bottom-left-radius: 6px; }
.chat-bubble.admin {
  align-self: flex-start;
  background: #fff;
  color: var(--text);
  border: 1px solid #e5e9f0;
  border-bottom-left-radius: 6px;
}
[dir="rtl"] .chat-bubble.admin { border-bottom-left-radius: 18px; border-bottom-right-radius: 6px; }
.chat-time {
  display: block;
  font-size: 10px;
  opacity: .7;
  margin-top: 4px;
}
.chat-bubble.admin .chat-time { color: #9ca3af; }

.chat-date-sep {
  text-align: center;
  font-size: 11px;
  color: #9ca3af;
  margin: 8px 0;
  position: relative;
}
.chat-date-sep::before,
.chat-date-sep::after {
  content: '';
  position: absolute;
  top: 50%;
  width: 30%;
  height: 1px;
  background: #e5e9f0;
}
.chat-date-sep::before { left: 0; }
.chat-date-sep::after { right: 0; }

.chat-input-form {
  display: flex;
  gap: 8px;
  padding: 12px 14px;
  background: #fff;
  border-top: 1px solid #f0f2f5;
}
.chat-input-form input {
  flex: 1;
  padding: 11px 16px;
  border: 1px solid #e5e9f0;
  border-radius: 24px;
  font-size: 14px;
  font-family: inherit;
  background: #f8fafc;
  outline: none;
  transition: border-color .2s, background .2s;
}
.chat-input-form input:focus {
  border-color: var(--primary);
  background: #fff;
}
.chat-send-btn {
  width: 42px; height: 42px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--primary), #d4b374);
  color: #fff;
  border: none;
  font-size: 16px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform .15s, box-shadow .15s;
  flex-shrink: 0;
}
.chat-send-btn:hover { transform: scale(1.05); box-shadow: 0 4px 14px rgba(201,169,97,.4); }
.chat-send-btn:active { transform: scale(.94); }
.chat-send-btn:disabled { opacity: .5; cursor: not-allowed; transform: none; }

.chat-typing {
  align-self: flex-start;
  display: flex;
  gap: 4px;
  padding: 12px 16px;
  background: #fff;
  border: 1px solid #e5e9f0;
  border-radius: 18px;
  border-bottom-left-radius: 6px;
}
.chat-typing span {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: #9ca3af;
  animation: typingDot 1.4s infinite;
}
.chat-typing span:nth-child(2) { animation-delay: .2s; }
.chat-typing span:nth-child(3) { animation-delay: .4s; }
@keyframes typingDot {
  0%, 60%, 100% { transform: translateY(0); opacity: .4; }
  30% { transform: translateY(-5px); opacity: 1; }
}

/* Mobile */
@media (max-width: 900px) {
  .chat-fab {
    bottom: calc(66px + 18px + env(safe-area-inset-bottom, 0px));
    right: 18px;
    width: 54px; height: 54px;
  }
  [dir="rtl"] .chat-fab { left: 18px; right: auto; }
  .chat-fab-icon { font-size: 22px; }

  .chat-window {
    bottom: calc(66px + 84px + env(safe-area-inset-bottom, 0px));
    right: 12px; left: 12px;
    width: auto;
    max-width: none;
    height: calc(100vh - 66px - 100px - env(safe-area-inset-bottom, 0px));
    max-height: 620px;
    border-radius: 18px;
  }
  [dir="rtl"] .chat-window { right: 12px; left: 12px; }
}