/* =========================================================================
   ONLINE SUPPORT CHAT WIDGET (Matching Reference Screenshot Design)
   Shop: Arian Cable (کابل آرین)
   ========================================================================= */

:root {
  --support-red: #C5161D;
  --support-red-dark: #9E1016;
  --support-red-glow: rgba(197, 22, 29, 0.35);
  --support-bg: #F8FAFC;
}

/* 1. Floating Trigger Button (Positioned with generous 32px gap above Scroll-to-Top Button) */
.support-chat-trigger {
  position: fixed;
  bottom: 106px;
  left: 24px;
  width: 50px;
  height: 50px;
  border-radius: 50%;
  background: var(--support-red);
  color: #FFFFFF;
  border: 2px solid #FFFFFF;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 6px 20px var(--support-red-glow), 0 2px 6px rgba(0, 0, 0, 0.2);
  z-index: 9998;
  transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  outline: none;
}

.support-chat-trigger:hover {
  transform: translateY(-3px) scale(1.08);
  background: var(--support-red-dark);
  box-shadow: 0 10px 26px var(--support-red-glow);
}

.support-chat-trigger .chat-trigger-icon {
  width: 24px;
  height: 24px;
  fill: currentColor;
}

/* Unread Badge on Trigger */
.support-trigger-badge {
  position: absolute;
  top: -3px;
  right: -3px;
  background: #EAB308;
  color: #111827;
  font-size: 0.72rem;
  font-weight: 900;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid #FFFFFF;
  box-shadow: 0 2px 6px rgba(0,0,0,0.25);
  animation: supportBadgePulse 2s infinite;
}

@keyframes supportBadgePulse {
  0% { transform: scale(1); }
  50% { transform: scale(1.18); }
  100% { transform: scale(1); }
}

/* 2. Idle Preview Tooltip Card (Matching Reference Screenshot 2) */
.support-chat-preview-card {
  position: fixed;
  bottom: 170px;
  left: 24px;
  width: 280px;
  background: #FFFFFF;
  border-radius: 14px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.16), 0 2px 8px rgba(0,0,0,0.06);
  border: 1px solid #E2E8F0;
  z-index: 9998;
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  animation: supportPreviewPop 0.4s cubic-bezier(0.16, 1, 0.3, 1);
  cursor: pointer;
  transition: transform 0.2s, box-shadow 0.2s;
}

.support-chat-preview-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 14px 36px rgba(0, 0, 0, 0.2);
}

@keyframes supportPreviewPop {
  0% { opacity: 0; transform: translateY(12px) scale(0.95); }
  100% { opacity: 1; transform: translateY(0) scale(1); }
}

.support-preview-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.support-preview-user {
  display: flex;
  align-items: center;
  gap: 10px;
}

.support-avatar-circle {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: 1.5px solid #E2E8F0;
  background: #FFFFFF;
  object-fit: cover;
  flex-shrink: 0;
}

.support-preview-title {
  font-size: 0.88rem;
  font-weight: 800;
  color: #1E293B;
  margin: 0;
  line-height: 1.25;
}

.support-preview-close {
  background: transparent;
  border: none;
  color: #94A3B8;
  font-size: 1.2rem;
  line-height: 1;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 4px;
  transition: color 0.2s;
}

.support-preview-close:hover {
  color: #EF4444;
  background: #FEF2F2;
}

.support-preview-text {
  font-size: 0.82rem;
  color: #475569;
  line-height: 1.55;
  margin: 0;
}

/* 3. Full Chat Window (Matching Reference Screenshot 1) */
.support-chat-window {
  position: fixed;
  bottom: 106px;
  left: 24px;
  width: 370px;
  max-width: calc(100vw - 32px);
  height: 530px;
  max-height: calc(100vh - 120px);
  background: #FFFFFF;
  border-radius: 18px;
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.28), 0 0 1px rgba(0,0,0,0.15);
  border: 1px solid #E2E8F0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: 10000;
  opacity: 0;
  transform: translateY(20px) scale(0.96);
  pointer-events: none;
  transition: opacity 0.3s cubic-bezier(0.16, 1, 0.3, 1), transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.support-chat-window.is-open {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}

/* Chat Header */
.support-chat-header {
  background: var(--support-red);
  color: #FFFFFF;
  padding: 14px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-shadow: 0 2px 10px rgba(197, 22, 29, 0.25);
  flex-shrink: 0;
}

.support-header-profile {
  display: flex;
  align-items: center;
  gap: 12px;
}

.support-header-avatar {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: 2px solid #FFFFFF;
  background: #FFFFFF;
  object-fit: cover;
}

.support-header-info h4 {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 800;
  color: #FFFFFF;
  line-height: 1.3;
}

.support-header-info p {
  margin: 2px 0 0;
  font-size: 0.75rem;
  color: rgba(255, 255, 255, 0.85);
}

.support-chat-close-btn {
  background: rgba(255, 255, 255, 0.15);
  border: none;
  color: #FFFFFF;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.2s;
}

.support-chat-close-btn:hover {
  background: rgba(255, 255, 255, 0.3);
}

/* Chat Body (Scrollable Stream) */
.support-chat-body {
  flex: 1;
  background: #F8FAFC;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

/* Pre-Chat Form Card (Matching Reference Screenshot 1) */
.support-form-card {
  background: #FFFFFF;
  border: 1px solid #E2E8F0;
  border-radius: 14px;
  padding: 16px;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.05);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.support-form-desc {
  font-size: 0.84rem;
  color: #475569;
  line-height: 1.5;
  margin: 0;
  font-weight: 600;
}

.support-input-field {
  width: 100%;
  padding: 10px 14px;
  border: 1.5px solid #E2E8F0;
  border-radius: 8px;
  font-family: inherit;
  font-size: 0.88rem;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
  box-sizing: border-box;
  background: #FFFFFF;
}

.support-input-field:focus {
  border-color: var(--support-red);
  box-shadow: 0 0 0 3px rgba(197, 22, 29, 0.12);
}

.support-start-btn {
  background: var(--support-red);
  color: #FFFFFF;
  border: none;
  padding: 10px 20px;
  border-radius: 8px;
  font-family: inherit;
  font-size: 0.92rem;
  font-weight: 800;
  cursor: pointer;
  transition: all 0.2s;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  box-shadow: 0 2px 8px var(--support-red-glow);
}

.support-start-btn:hover {
  background: var(--support-red-dark);
}

/* Chat Message Bubbles */
.chat-bubble-row {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  width: 100%;
}

.chat-bubble-row.from-support {
  flex-direction: row;
}

.chat-bubble-row.from-customer {
  flex-direction: row-reverse;
}

.chat-bubble-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 1.5px solid #E2E8F0;
  flex-shrink: 0;
  object-fit: cover;
}

.chat-bubble-content {
  max-width: 80%;
  padding: 10px 14px;
  border-radius: 14px;
  font-size: 0.85rem;
  line-height: 1.55;
  word-break: break-word;
  position: relative;
}

.from-support .chat-bubble-content {
  background: #FFFFFF;
  color: #1E293B;
  border: 1px solid #E2E8F0;
  border-top-right-radius: 4px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.04);
}

.from-customer .chat-bubble-content {
  background: var(--support-red);
  color: #FFFFFF;
  border-top-left-radius: 4px;
  box-shadow: 0 2px 8px var(--support-red-glow);
}

.chat-bubble-time {
  display: block;
  font-size: 0.68rem;
  margin-top: 4px;
  text-align: left;
  opacity: 0.75;
}

/* Chat Footer Input Area */
.support-chat-footer {
  background: #FFFFFF;
  border-top: 1px solid #E2E8F0;
  padding: 10px 14px;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.support-chat-input {
  flex: 1;
  padding: 9px 14px;
  border: 1.5px solid #E2E8F0;
  border-radius: 20px;
  font-family: inherit;
  font-size: 0.86rem;
  outline: none;
  background: #F8FAFC;
  transition: all 0.2s;
  box-sizing: border-box;
}

.support-chat-input:focus {
  background: #FFFFFF;
  border-color: var(--support-red);
  box-shadow: 0 0 0 3px rgba(197, 22, 29, 0.1);
}

.support-send-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--support-red);
  color: #FFFFFF;
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s;
  flex-shrink: 0;
}

.support-send-btn:hover {
  background: var(--support-red-dark);
  transform: scale(1.08);
}

.support-send-btn svg {
  transform: scaleX(-1);
}

/* =========================================================================
   MOBILE & TABLET RESPONSIVENESS
   ========================================================================= */
@media (max-width: 768px) {
  .support-chat-trigger {
    bottom: calc(130px + env(safe-area-inset-bottom, 0px)) !important;
    left: 12px !important;
    width: 44px !important;
    height: 44px !important;
  }

  .support-chat-preview-card {
    left: 12px !important;
    bottom: calc(186px + env(safe-area-inset-bottom, 0px)) !important;
    width: calc(100vw - 28px) !important;
    max-width: 310px !important;
  }

  .support-chat-window {
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    width: 100% !important;
    max-width: 100vw !important;
    height: 85vh !important;
    max-height: 85vh !important;
    border-radius: 20px 20px 0 0 !important;
    border: none !important;
    box-shadow: 0 -8px 36px rgba(0, 0, 0, 0.35) !important;
  }

  .support-input-field,
  .support-chat-input {
    font-size: 16px !important; /* Prevents auto-zoom in iOS Safari */
  }
}


/* Attachment Button */
.support-attach-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: #F1F5F9;
  color: #475569;
  border: 1px solid #CBD5E1;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s;
  flex-shrink: 0;
}

.support-attach-btn:hover {
  background: #E2E8F0;
  color: var(--support-red);
  border-color: var(--support-red);
  transform: scale(1.05);
}

.support-attach-btn svg {
  width: 19px;
  height: 19px;
  fill: currentColor;
}

/* Chat Image Thumbnail */
.chat-bubble-img-wrap {
  margin-top: 6px;
  border-radius: 10px;
  overflow: hidden;
  max-width: 230px;
  border: 1px solid rgba(0,0,0,0.1);
  cursor: pointer;
  transition: transform 0.2s, box-shadow 0.2s;
}

.chat-bubble-img-wrap:hover {
  transform: scale(1.02);
  box-shadow: 0 4px 14px rgba(0,0,0,0.18);
}

.chat-bubble-img {
  width: 100%;
  max-height: 200px;
  object-fit: cover;
  display: block;
}

/* Virtual Agent Badge in Bubble */
.chat-agent-badge {
  display: inline-block;
  font-size: 0.68rem;
  font-weight: 800;
  color: var(--support-red);
  background: rgba(197, 22, 29, 0.08);
  padding: 1px 6px;
  border-radius: 4px;
  margin-bottom: 4px;
}

/* Lightbox Modal for Chat Images */
.chat-lightbox {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.88);
  z-index: 99999;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  cursor: zoom-out;
  backdrop-filter: blur(4px);
  animation: supportPreviewPop 0.2s ease-out;
}

.chat-lightbox-img {
  max-width: 90vw;
  max-height: 90vh;
  border-radius: 8px;
  box-shadow: 0 10px 40px rgba(0,0,0,0.5);
  cursor: default;
}

.chat-lightbox-close {
  position: absolute;
  top: 20px;
  right: 20px;
  background: rgba(255, 255, 255, 0.2);
  color: #FFFFFF;
  border: none;
  font-size: 24px;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
}

.chat-lightbox-close:hover {
  background: var(--support-red);
}
