

#tm-support-widget {
  position: fixed;
  bottom: 20px;
  inset-inline-end: 20px;
  z-index: 9999;
  font-family: 'Cairo', 'Tajawal', system-ui, sans-serif;
  direction: rtl;
}

.tm-sw-launcher {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--brand-primary, var(--brand-primary,#6366f1)), var(--brand-secondary, var(--brand-accent,#8b5cf6)));
  color: white;
  border: none;
  cursor: pointer;
  display: grid;
  place-items: center;
  font-size: 26px;
  box-shadow: 0 8px 28px rgba(var(--brand-primary-rgb,99,102,241),  0.45), 0 0 0 0 rgba(var(--brand-primary-rgb,99,102,241),  0.5);
  transition: transform 0.25s ease, box-shadow 0.25s;
  animation: tm-sw-pulse 2.4s infinite;
  position: relative;
}
.tm-sw-launcher:hover { transform: scale(1.08); }
.tm-sw-launcher.hide { transform: scale(0); opacity: 0; pointer-events: none; }

@keyframes tm-sw-pulse {
  0%   { box-shadow: 0 8px 28px rgba(var(--brand-primary-rgb,99,102,241),  0.45), 0 0 0 0 rgba(var(--brand-primary-rgb,99,102,241),  0.5); }
  70%  { box-shadow: 0 8px 28px rgba(var(--brand-primary-rgb,99,102,241),  0.45), 0 0 0 20px rgba(var(--brand-primary-rgb,99,102,241),  0); }
  100% { box-shadow: 0 8px 28px rgba(var(--brand-primary-rgb,99,102,241),  0.45), 0 0 0 0 rgba(var(--brand-primary-rgb,99,102,241),  0); }
}

.tm-sw-badge {
  position: absolute;
  top: -4px;
  inset-inline-start: -4px;
  background: #ef4444;
  color: white;
  font-size: 11px;
  font-weight: 800;
  padding: 2px 7px;
  border-radius: 999px;
  min-width: 22px;
  text-align: center;
  border: 2px solid white;
  box-shadow: 0 2px 6px rgba(0,0,0,0.2);
  animation: tm-sw-bounce 1s infinite;
}
@keyframes tm-sw-bounce {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-3px); }
}

.tm-sw-window {
  position: absolute;
  bottom: 80px;
  inset-inline-end: 0;
  width: 380px;
  max-width: calc(100vw - 30px);
  height: 580px;
  max-height: calc(100vh - 110px);
  background: #ffffff;
  border-radius: 18px;
  box-shadow: 0 24px 60px rgba(15, 23, 42, 0.25);
  display: none;
  flex-direction: column;
  overflow: hidden;
  transform-origin: bottom right;
  animation: tm-sw-open 0.3s ease;
  color: #1f2937;
}
html[dir="ltr"] .tm-sw-window { transform-origin: bottom left; }
.tm-sw-window.open { display: flex; }
@keyframes tm-sw-open {
  from { transform: scale(0.85) translateY(20px); opacity: 0; }
  to { transform: scale(1) translateY(0); opacity: 1; }
}

.tm-sw-head {
  background: linear-gradient(135deg, var(--brand-primary, var(--brand-primary,#6366f1)), var(--brand-secondary, var(--brand-accent,#8b5cf6)));
  color: white;
  padding: 16px 18px;
  display: flex;
  align-items: center;
  gap: 12px;
  position: relative;
  overflow: hidden;
}
.tm-sw-head::before {
  content: '';
  position: absolute;
  top: -40px; right: -40px;
  width: 120px; height: 120px;
  background: rgba(255,255,255,0.1);
  border-radius: 50%;
}
.tm-sw-avatar {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  background: rgba(255,255,255,0.2);
  display: grid;
  place-items: center;
  font-size: 18px;
  position: relative;
  z-index: 1;
}
.tm-sw-avatar::after {
  content: '';
  position: absolute;
  bottom: 0; inset-inline-end: 0;
  width: 10px; height: 10px;
  background: #10b981;
  border: 2px solid white;
  border-radius: 50%;
}
.tm-sw-head-info { flex: 1; min-width: 0; position: relative; z-index: 1; }
.tm-sw-head-info strong { display: block; font-size: 15px; font-weight: 700; }
.tm-sw-head-info small { font-size: 11px; opacity: 0.9; }
.tm-sw-close {
  background: rgba(255,255,255,0.15);
  border: none;
  color: white;
  width: 30px; height: 30px;
  border-radius: 8px;
  cursor: pointer;
  display: grid;
  place-items: center;
  font-size: 14px;
  position: relative;
  z-index: 1;
  transition: background 0.2s;
}
.tm-sw-close:hover { background: rgba(255,255,255,0.3); }

.tm-sw-status {
  padding: 8px 14px;
  background: #f8fafc;
  border-bottom: 1px solid #e5e7eb;
  font-size: 11px;
  color: #64748b;
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}
.tm-sw-status.waiting { background: #fef3c7; color: #92400e; }
.tm-sw-status.human { background: #d1fae5; color: #065f46; }

.tm-sw-messages {
  flex: 1;
  overflow-y: auto;
  padding: 18px 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: #f9fafb;
  scroll-behavior: smooth;
}
.tm-sw-messages::-webkit-scrollbar { width: 4px; }
.tm-sw-messages::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 2px; }

.tm-sw-msg {
  display: flex;
  gap: 8px;
  max-width: 88%;
  animation: tm-sw-msg-in 0.25s ease;
}
@keyframes tm-sw-msg-in {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}
.tm-sw-msg.visitor { align-self: flex-end; flex-direction: row-reverse; }
.tm-sw-msg-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 12px;
  flex-shrink: 0;
  margin-top: 2px;
}
.tm-sw-msg.ai .tm-sw-msg-avatar { background: linear-gradient(135deg, var(--brand-primary,#6366f1), var(--brand-accent,#8b5cf6)); color: white; }
.tm-sw-msg.admin .tm-sw-msg-avatar { background: #10b981; color: white; }
.tm-sw-msg.system .tm-sw-msg-avatar { background: #f59e0b; color: white; }
.tm-sw-msg.visitor .tm-sw-msg-avatar { background: #e0e7ff; color: var(--brand-primary,#4f46e5); }
.tm-sw-msg-body {
  background: white;
  border: 1px solid #e5e7eb;
  border-radius: 14px;
  padding: 10px 14px;
  font-size: 13px;
  line-height: 1.6;
  word-wrap: break-word;
  overflow-wrap: break-word;
  color: #1f2937;
  white-space: pre-wrap;
}
.tm-sw-msg.visitor .tm-sw-msg-body {
  background: linear-gradient(135deg, var(--brand-primary,#6366f1), var(--brand-accent,#8b5cf6));
  color: white;
  border-color: transparent;
}
.tm-sw-msg.system .tm-sw-msg-body {
  background: #fef3c7;
  border-color: #fde68a;
  font-size: 12px;
  color: #92400e;
  text-align: center;
}
.tm-sw-msg-time { font-size: 10px; opacity: 0.6; margin-top: 4px; }

.tm-sw-typing {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  background: white;
  border-radius: 14px;
  border: 1px solid #e5e7eb;
  align-self: flex-start;
  margin-inline-start: 36px;
}
.tm-sw-typing span {
  width: 7px; height: 7px;
  background: #94a3b8;
  border-radius: 50%;
  animation: tm-sw-typing-dot 1.4s infinite;
}
.tm-sw-typing span:nth-child(2) { animation-delay: 0.2s; }
.tm-sw-typing span:nth-child(3) { animation-delay: 0.4s; }
@keyframes tm-sw-typing-dot {
  0%, 60%, 100% { opacity: 0.3; transform: translateY(0); }
  30% { opacity: 1; transform: translateY(-3px); }
}

.tm-sw-chips {
  padding: 0 14px 8px;
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  border-top: 1px solid #e5e7eb;
  padding-top: 10px;
  background: white;
}
.tm-sw-chip {
  background: #f1f5f9;
  border: 1px solid #e2e8f0;
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 12px;
  cursor: pointer;
  color: #1f2937;
  font-family: inherit;
  transition: all 0.15s;
}
.tm-sw-chip:hover {
  background: var(--brand-primary, var(--brand-primary,#6366f1));
  color: white;
  border-color: var(--brand-primary, var(--brand-primary,#6366f1));
}

.tm-sw-escalate {
  background: linear-gradient(135deg, #f59e0b, #ef4444);
  color: white;
  border: none;
  padding: 8px 14px;
  border-radius: 999px;
  cursor: pointer;
  font-size: 12px;
  font-family: inherit;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.tm-sw-escalate:hover { transform: translateY(-1px); box-shadow: 0 6px 16px rgba(239, 68, 68, 0.3); }

.tm-sw-form {
  display: grid;
  grid-template-columns: 1fr 40px;
  gap: 8px;
  padding: 12px 14px;
  background: white;
  border-top: 1px solid #e5e7eb;
}
.tm-sw-form textarea {
  background: #f8fafc;
  border: 1px solid #e5e7eb;
  border-radius: 12px;
  padding: 10px 14px;
  font-family: inherit;
  font-size: 13px;
  resize: none;
  max-height: 100px;
  color: #1f2937;
  outline: none;
  transition: border-color 0.2s;
}
.tm-sw-form textarea:focus { border-color: var(--brand-primary, var(--brand-primary,#6366f1)); background: white; }
.tm-sw-send {
  background: linear-gradient(135deg, var(--brand-primary, var(--brand-primary,#6366f1)), var(--brand-secondary, var(--brand-accent,#8b5cf6)));
  color: white;
  border: none;
  border-radius: 12px;
  cursor: pointer;
  font-size: 14px;
  display: grid;
  place-items: center;
  transition: transform 0.15s;
}
.tm-sw-send:hover { transform: scale(1.06); }
.tm-sw-send:disabled { opacity: 0.5; cursor: not-allowed; }

.tm-sw-esc-modal {
  background: rgba(15, 23, 42, 0.6);
  position: absolute;
  inset: 0;
  z-index: 10;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.tm-sw-esc-modal.open { display: flex; }
.tm-sw-esc-dialog {
  background: white;
  border-radius: 14px;
  width: 100%;
  max-width: 320px;
  padding: 20px;
  color: #1f2937;
}
.tm-sw-esc-dialog h3 { margin: 0 0 6px; font-size: 16px; }
.tm-sw-esc-dialog p { margin: 0 0 16px; font-size: 12px; color: #64748b; }
.tm-sw-esc-field { margin-bottom: 10px; }
.tm-sw-esc-field label { display: block; font-size: 11px; color: #64748b; margin-bottom: 4px; font-weight: 600; }
.tm-sw-esc-field input {
  width: 100%;
  background: #f8fafc;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  padding: 8px 10px;
  font: inherit;
  font-size: 13px;
  box-sizing: border-box;
}
.tm-sw-esc-actions {
  display: flex;
  gap: 8px;
  margin-top: 14px;
}
.tm-sw-esc-actions button {
  flex: 1;
  padding: 9px;
  border-radius: 8px;
  border: none;
  cursor: pointer;
  font: inherit;
  font-size: 13px;
  font-weight: 600;
}
.tm-sw-esc-cancel { background: #f1f5f9; color: #475569; }
.tm-sw-esc-confirm { background: linear-gradient(135deg, #f59e0b, #ef4444); color: white; }

@media (max-width: 480px) {
  #tm-support-widget { bottom: 14px; inset-inline-end: 14px; }
  .tm-sw-window {
    width: 100vw;
    height: 100vh;
    max-height: 100vh;
    bottom: 0;
    inset-inline-end: 0;
    border-radius: 0;
    position: fixed;
  }
  .tm-sw-launcher { width: 56px; height: 56px; font-size: 22px; }
}
