/* ==========================================================================
   Universal Multilingual Support Chat Widget Styles
   Supports 24+ languages, RTL (Arabic, Hebrew), Mobile & Desktop
   ========================================================================== */

:root {
  --sw-primary: #111d5e;
  --sw-primary-hover: #0c1445;
  --sw-primary-text: #ffffff;
  --sw-accent: #2563eb;
  --sw-bg: #ffffff;
  --sw-chat-bg: #f8fafc;
  --sw-text-main: #0f172a;
  --sw-text-muted: #64748b;
  --sw-border: #e2e8f0;
  --sw-bubble-user: #111d5e;
  --sw-bubble-user-text: #ffffff;
  --sw-bubble-support: #ffffff;
  --sw-bubble-support-text: #0f172a;
  --sw-radius-win: 18px;
  --sw-radius-bubble: 16px;
  --sw-shadow: 0 12px 36px rgba(0, 0, 0, 0.18), 0 4px 12px rgba(0, 0, 0, 0.08);
  --sw-z-index: 2147483640;
}

/* Launcher Button */
.sw-launcher {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: var(--sw-primary);
  color: var(--sw-primary-text);
  border: none;
  cursor: pointer;
  box-shadow: 0 6px 20px rgba(17, 29, 94, 0.35);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2147483645;
  transition: transform 0.25s cubic-bezier(0.16, 1, 0.3, 1), background-color 0.2s ease, box-shadow 0.25s ease;
  outline: none;
  padding: 0;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.sw-launcher:hover {
  background: var(--sw-primary-hover);
  transform: scale(1.06);
  box-shadow: 0 8px 24px rgba(17, 29, 94, 0.45);
}

.sw-launcher:active {
  transform: scale(0.95);
}

.sw-launcher__icon {
  width: 28px;
  height: 28px;
  fill: currentColor;
  transition: transform 0.25s ease, opacity 0.2s ease;
}

.sw-launcher__icon--close {
  display: none;
}

.sw-launcher.is-active .sw-launcher__icon--chat {
  display: none;
}

.sw-launcher.is-active .sw-launcher__icon--close {
  display: block;
}

/* Badge for unread operator messages: plain circular indicator dot (not a number) */
.sw-badge {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 14px;
  height: 14px;
  min-width: 14px;
  border-radius: 50%;
  background: #ef4444;
  border: 2.5px solid #ffffff;
  box-shadow: 0 2px 6px rgba(239, 68, 68, 0.6);
  animation: sw-pulse 2s infinite;
  display: none;
  padding: 0;
  margin: 0;
  box-sizing: border-box;
}

@keyframes sw-pulse {
  0% { transform: scale(1); }
  50% { transform: scale(1.15); }
  100% { transform: scale(1); }
}

/* Chat Window */
.sw-window {
  position: fixed;
  bottom: 96px;
  right: 24px;
  width: 380px;
  height: 540px;
  max-width: calc(100vw - 32px);
  max-height: calc(100vh - 120px);
  background: var(--sw-bg);
  border-radius: var(--sw-radius-win);
  box-shadow: var(--sw-shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: 2147483646;
  opacity: 0;
  visibility: hidden;
  transform: translateY(16px) scale(0.96);
  transition: opacity 0.25s cubic-bezier(0.16, 1, 0.3, 1), transform 0.25s cubic-bezier(0.16, 1, 0.3, 1), visibility 0.25s;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  box-sizing: border-box;
}

.sw-window * {
  box-sizing: border-box;
}

.sw-window.is-open {
  opacity: 1;
  visibility: visible;
  transform: translateY(0) scale(1);
}

/* Chat Header */
.sw-header {
  background: var(--sw-primary);
  color: #ffffff;
  padding: 16px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}

.sw-header__info {
  display: flex;
  align-items: center;
  gap: 12px;
}

.sw-header__avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.15);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #ffffff;
  position: relative;
  flex-shrink: 0;
}

.sw-header__avatar-img {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  object-fit: cover;
  display: block;
}

.sw-header__avatar-icon {
  width: 22px;
  height: 22px;
  fill: currentColor;
}

.sw-header__status-dot {
  position: absolute;
  bottom: 0;
  right: 0;
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: #10b981;
  border: 2px solid var(--sw-primary);
}

.sw-header__text {
  display: flex;
  flex-direction: column;
}

.sw-header__title {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
  line-height: 1.25;
  color: #ffffff;
}

.sw-header__subtitle {
  margin: 2px 0 0;
  font-size: 12px;
  color: rgba(255, 255, 255, 0.8);
  display: flex;
  align-items: center;
  gap: 4px;
}

.sw-header__close {
  background: transparent;
  border: none;
  color: rgba(255, 255, 255, 0.75);
  cursor: pointer;
  padding: 6px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.15s ease, background-color 0.15s ease;
}

.sw-header__close:hover {
  color: #ffffff;
  background: rgba(255, 255, 255, 0.15);
}

.sw-header__close-icon {
  width: 20px;
  height: 20px;
  fill: currentColor;
}

/* Chat Messages Container */
.sw-body {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  background: var(--sw-chat-bg);
  display: flex;
  flex-direction: column;
  gap: 12px;
  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch;
}

.sw-body::-webkit-scrollbar {
  width: 5px;
}

.sw-body::-webkit-scrollbar-thumb {
  background: rgba(0, 0, 0, 0.12);
  border-radius: 4px;
}

/* Welcome Box */
.sw-welcome {
  background: #ffffff;
  border: 1px solid var(--sw-border);
  border-radius: 12px;
  padding: 14px;
  text-align: center;
  margin-bottom: 8px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
}

.sw-welcome__icon {
  width: 32px;
  height: 32px;
  fill: var(--sw-primary);
  margin: 0 auto 6px;
  display: block;
}

.sw-welcome__title {
  font-size: 13px;
  font-weight: 600;
  color: var(--sw-text-main);
  margin: 0 0 4px;
}

.sw-welcome__desc {
  font-size: 12px;
  color: var(--sw-text-muted);
  margin: 0;
  line-height: 1.4;
}

/* Date Separator */
.sw-date-divider {
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 8px 0;
}

.sw-date-divider__text {
  font-size: 11px;
  font-weight: 500;
  color: var(--sw-text-muted);
  background: rgba(0, 0, 0, 0.05);
  padding: 2px 10px;
  border-radius: 10px;
}

/* Chat Messages List */
#sw-messages-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: 100%;
}

/* Message Rows & Bubbles */
.sw-message {
  display: flex;
  flex-direction: column;
  max-width: 85%;
  animation: sw-fade-in 0.2s ease-out;
}

@keyframes sw-fade-in {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Customer / Visitor: Blue bubble on the RIGHT */
.sw-message--customer {
  align-self: flex-end;
  align-items: flex-end;
  margin-left: auto;
}

/* Operator / Support: White bubble on the LEFT */
.sw-message--support {
  align-self: flex-start;
  align-items: flex-start;
  margin-right: auto;
}

.sw-message__row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  width: 100%;
}

.sw-message__avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
  margin-bottom: 2px;
  border: 1px solid rgba(0, 0, 0, 0.08);
}

.sw-message__content {
  display: flex;
  flex-direction: column;
}

.sw-message__bubble {
  padding: 10px 14px;
  font-size: 13.5px;
  line-height: 1.45;
  word-break: break-word;
  white-space: pre-wrap;
}

.sw-message--customer .sw-message__bubble {
  background: var(--sw-bubble-user);
  color: var(--sw-bubble-user-text);
  border-radius: 16px 16px 4px 16px;
  box-shadow: 0 2px 6px rgba(17, 29, 94, 0.15);
}

.sw-message--support .sw-message__bubble {
  background: var(--sw-bubble-support);
  color: var(--sw-bubble-support-text);
  border: 1px solid var(--sw-border);
  border-radius: 16px 16px 16px 4px;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.04);
}

.sw-message__time {
  font-size: 10.5px;
  color: var(--sw-text-muted);
  margin-top: 3px;
  padding: 0 2px;
}

/* Chat Footer / Input */
.sw-footer {
  padding: 10px 14px;
  background: #ffffff;
  border-top: 1px solid var(--sw-border);
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex-shrink: 0;
}

.sw-footer__input-row {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
}

.sw-attach-btn {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: transparent;
  color: var(--sw-text-muted);
  border: 1px solid var(--sw-border);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all 0.15s ease;
  padding: 0;
  outline: none;
}

.sw-attach-btn:hover {
  background: #f1f5f9;
  color: var(--sw-primary);
  border-color: #cbd5e1;
}

.sw-attach-btn__icon {
  width: 20px;
  height: 20px;
}

.sw-attach-preview {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: #f1f5f9;
  border: 1px solid var(--sw-border);
  border-radius: 8px;
  padding: 6px 12px;
  font-size: 12px;
  color: var(--sw-text-main);
  gap: 8px;
  width: 100%;
  box-sizing: border-box;
}

.sw-attach-preview__name {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
}

.sw-attach-preview__remove {
  background: none;
  border: none;
  color: #94a3b8;
  cursor: pointer;
  font-size: 16px;
  line-height: 1;
  padding: 0 4px;
}

.sw-attach-preview__remove:hover {
  color: #ef4444;
}

/* Attachments in messages */
.sw-message__attachment {
  margin-top: 6px;
  border-radius: 8px;
  overflow: hidden;
}

.sw-message__thumb {
  max-width: 220px;
  max-height: 220px;
  border-radius: 8px;
  cursor: pointer;
  display: block;
  object-fit: cover;
  transition: transform 0.15s ease;
  border: 1px solid rgba(0, 0, 0, 0.08);
}

.sw-message__thumb:hover {
  transform: scale(1.02);
}

.sw-message__doc {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  background: rgba(0, 0, 0, 0.06);
  border-radius: 8px;
  text-decoration: none;
  color: inherit;
  font-size: 12.5px;
  transition: background 0.15s ease;
  word-break: break-all;
}

.sw-message--customer .sw-message__doc {
  background: rgba(255, 255, 255, 0.2);
  color: #ffffff;
}

.sw-message__doc:hover {
  background: rgba(0, 0, 0, 0.1);
}

.sw-message--customer .sw-message__doc:hover {
  background: rgba(255, 255, 255, 0.3);
}

.sw-message__doc-icon {
  font-size: 20px;
  flex-shrink: 0;
}

.sw-message__doc-info {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  flex: 1;
}

.sw-message__doc-name {
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sw-message__doc-size {
  font-size: 11px;
  opacity: 0.75;
}

.sw-message__doc-download {
  font-size: 14px;
  flex-shrink: 0;
}

/* Lightbox Modal */
.sw-lightbox {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  z-index: calc(var(--sw-z-index) + 10);
  display: flex;
  align-items: center;
  justify-content: center;
}

.sw-lightbox__backdrop {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.85);
  cursor: pointer;
}

.sw-lightbox__content {
  position: relative;
  max-width: 90vw;
  max-height: 90vh;
  display: flex;
  align-items: center;
  justify-content: center;
}

.sw-lightbox__img {
  max-width: 90vw;
  max-height: 90vh;
  border-radius: 8px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
  object-fit: contain;
}

.sw-lightbox__close {
  position: absolute;
  top: -40px;
  right: 0;
  background: transparent;
  border: none;
  color: #ffffff;
  font-size: 32px;
  cursor: pointer;
  line-height: 1;
  padding: 4px;
}

.sw-input {
  flex: 1;
  border: 1px solid var(--sw-border);
  border-radius: 20px;
  padding: 9px 14px;
  font-size: 13.5px;
  font-family: inherit;
  color: var(--sw-text-main);
  background: #ffffff;
  outline: none;
  resize: none;
  max-height: 80px;
  line-height: 1.35;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.sw-input:focus {
  border-color: var(--sw-primary);
  box-shadow: 0 0 0 3px rgba(17, 29, 94, 0.12);
}

.sw-send {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: var(--sw-primary);
  color: #ffffff;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background-color 0.15s ease, transform 0.15s ease;
  padding: 0;
  outline: none;
}

.sw-send:disabled {
  background: #cbd5e1;
  cursor: not-allowed;
  transform: none;
}

.sw-send:not(:disabled):hover {
  background: var(--sw-primary-hover);
  transform: scale(1.05);
}

.sw-send:not(:disabled):active {
  transform: scale(0.95);
}

.sw-send__icon {
  width: 17px;
  height: 17px;
  fill: currentColor;
  transform: translateX(1px);
}


/* Partial Message Preview Toast */
.sw-preview-toast {
  position: fixed;
  bottom: 96px;
  right: 24px;
  width: 320px;
  max-width: calc(100vw - 32px);
  background: #ffffff;
  border: 1px solid var(--sw-border);
  border-radius: 16px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.16);
  padding: 12px 14px;
  z-index: 2147483647;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 8px;
  animation: sw-toast-in 0.25s cubic-bezier(0.16, 1, 0.3, 1);
  transition: opacity 0.2s ease, transform 0.2s ease;
}

/* Chat bubble pointer tail pointing down to launcher button */
.sw-preview-toast::after {
  content: "";
  position: absolute;
  bottom: -7px;
  right: 24px;
  width: 12px;
  height: 12px;
  background: #ffffff;
  border-right: 1px solid var(--sw-border);
  border-bottom: 1px solid var(--sw-border);
  transform: rotate(45deg);
}

@keyframes sw-toast-in {
  from { opacity: 0; transform: translateY(12px) scale(0.96); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.sw-preview-toast__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.sw-preview-toast__author {
  display: flex;
  align-items: center;
  gap: 8px;
}

.sw-preview-toast__avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  object-fit: cover;
  border: 1px solid rgba(0, 0, 0, 0.08);
}

.sw-preview-toast__name {
  font-size: 13.5px;
  font-weight: 600;
  color: var(--sw-text-main);
}

.sw-preview-toast__badge {
  font-size: 11px;
  color: #10b981;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 4px;
}

.sw-preview-toast__badge::before {
  content: "";
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #10b981;
}

.sw-preview-toast__close {
  background: none;
  border: none;
  color: var(--sw-text-muted);
  font-size: 16px;
  line-height: 1;
  padding: 4px;
  cursor: pointer;
  border-radius: 4px;
  transition: color 0.15s;
}

.sw-preview-toast__close:hover {
  color: var(--sw-text-main);
}

.sw-preview-toast__body {
  font-size: 13px;
  line-height: 1.4;
  color: var(--sw-text-main);
  background: var(--sw-bubble-support);
  padding: 8px 10px;
  border-radius: 10px;
  border: 1px solid var(--sw-border);
  word-break: break-word;
  max-height: 80px;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
}


/* ==========================================================================
   RTL (Right-to-Left) Styles for Arabic, Hebrew
   ========================================================================== */
.sw-rtl,
[dir="rtl"] .sw-window,
html[dir="rtl"] .sw-window {
  direction: rtl;
  text-align: right;
}

.sw-rtl .sw-header__status-dot,
[dir="rtl"] .sw-header__status-dot,
html[dir="rtl"] .sw-header__status-dot {
  right: auto;
  left: 0;
}

.sw-rtl .sw-preview-toast,
[dir="rtl"] .sw-preview-toast,
html[dir="rtl"] .sw-preview-toast {
  right: auto;
  left: 24px;
}

.sw-rtl .sw-message--customer,
[dir="rtl"] .sw-message--customer,
html[dir="rtl"] .sw-message--customer {
  align-self: flex-start;
  align-items: flex-start;
  margin-right: auto;
  margin-left: 0;
}

.sw-rtl .sw-message--customer .sw-message__bubble,
[dir="rtl"] .sw-message--customer .sw-message__bubble,
html[dir="rtl"] .sw-message--customer .sw-message__bubble {
  border-radius: 16px 16px 16px 4px;
}

.sw-rtl .sw-message--support,
[dir="rtl"] .sw-message--support,
html[dir="rtl"] .sw-message--support {
  align-self: flex-end;
  align-items: flex-end;
  margin-left: auto;
  margin-right: 0;
}

.sw-rtl .sw-message--support .sw-message__bubble,
[dir="rtl"] .sw-message--support .sw-message__bubble,
html[dir="rtl"] .sw-message--support .sw-message__bubble {
  border-radius: 16px 16px 4px 16px;
}

.sw-rtl .sw-send__icon,
[dir="rtl"] .sw-send__icon,
html[dir="rtl"] .sw-send__icon {
  transform: scaleX(-1) translateX(1px);
}

/* ==========================================================================
   Mobile Fullscreen / Drawer Responsiveness
   ========================================================================== */
html.sw-no-scroll,
body.sw-no-scroll {
  overflow: hidden !important;
  overscroll-behavior: none !important;
}

@media (max-width: 768px) {
  .sw-window {
    position: fixed !important;
    top: var(--sw-vv-top, 0px) !important;
    left: var(--sw-vv-left, 0px) !important;
    right: auto !important;
    bottom: auto !important;
    width: var(--sw-vv-width, 100%) !important;
    max-width: 100% !important;
    height: var(--sw-vv-height, 100dvh) !important;
    max-height: var(--sw-vv-height, 100dvh) !important;
    border-radius: 0 !important;
    margin: 0 !important;
    box-shadow: none !important;
    z-index: 2147483646 !important;
    overflow: hidden !important;
    box-sizing: border-box !important;
  }

  .sw-header {
    flex-shrink: 0;
    padding: 12px 14px;
    padding-top: max(12px, env(safe-area-inset-top));
  }

  .sw-header__close {
    min-width: 42px;
    min-height: 42px;
    display: flex;
    align-items: center;
    justify-content: center;
  }

  .sw-footer {
    flex-shrink: 0;
    padding: 10px 12px;
    padding-bottom: var(--sw-footer-pb, max(12px, env(safe-area-inset-bottom))) !important;
    box-sizing: border-box !important;
  }

  .sw-input {
    font-size: 16px !important; /* Prevents iOS auto-zoom on input focus */
  }

  .sw-launcher {
    bottom: 18px;
    right: 18px;
    width: 54px;
    height: 54px;
  }

  .sw-launcher__icon {
    width: 24px;
    height: 24px;
  }
}

