/* AI Support Chat Widget — bottom-right rectangular launcher (above support FAB) */
.xui-ai-chat {
  --xai-ink: #0f172a;
  --xai-ink-soft: #1e293b;
  --xai-teal: #0d9488;
  --xai-teal-bright: #14b8a6;
  --xai-cyan: #22d3ee;
  --xai-sand: #f8fafc;
  --xai-line: rgba(15, 23, 42, 0.08);
  --xai-shadow: 0 22px 50px rgba(15, 23, 42, 0.22);
  --xai-radius: 18px;
  font-family: 'Vazirmatn', Tahoma, sans-serif;
  position: fixed !important;
  right: 18px !important;
  left: auto !important;
  bottom: 78px !important; /* بالای دکمه پشتیبانی شناور */
  top: auto !important;
  z-index: 999997 !important;
  direction: rtl;
  color: var(--xai-ink);
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 10px;
}

.xui-ai-chat__fab {
  position: relative;
  width: auto;
  min-width: 196px;
  height: 52px;
  padding: 0 14px 0 16px;
  border: 0;
  border-radius: 14px;
  cursor: pointer;
  color: #fff;
  background: linear-gradient(120deg, #0f172a 0%, #134e4a 48%, #0e7490 100%);
  box-shadow: 0 10px 28px rgba(15, 23, 42, 0.28), inset 0 1px 0 rgba(255, 255, 255, 0.12);
  display: flex;
  align-items: center;
  transition: transform 0.25s cubic-bezier(0.22, 1, 0.36, 1), box-shadow 0.25s, min-width 0.25s, padding 0.25s;
  overflow: hidden;
}

.xui-ai-chat__fab:hover {
  transform: translateY(-2px);
  box-shadow: 0 14px 34px rgba(15, 118, 110, 0.35);
}

.xui-ai-chat__fab-inner {
  position: relative;
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
}

.xui-ai-chat__fab-glow {
  position: absolute;
  inset: -2px;
  border-radius: 16px;
  background: linear-gradient(90deg, transparent, rgba(34, 211, 238, 0.22), transparent);
  animation: xai-shine 2.8s ease-in-out infinite;
  pointer-events: none;
}

.xui-ai-chat.is-open .xui-ai-chat__fab-glow {
  opacity: 0;
}

.xui-ai-chat__fab-icon {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.12);
  display: grid;
  place-items: center;
  flex-shrink: 0;
  transition: opacity 0.2s, transform 0.2s;
}

.xui-ai-chat__fab-copy {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  line-height: 1.25;
  text-align: right;
  transition: opacity 0.2s, width 0.2s;
}

.xui-ai-chat__fab-label {
  font-size: 0.86rem;
  font-weight: 800;
  white-space: nowrap;
}

.xui-ai-chat__fab-hint {
  font-size: 0.68rem;
  opacity: 0.78;
  white-space: nowrap;
}

.xui-ai-chat__fab-close {
  display: none;
  place-items: center;
}

.xui-ai-chat.is-open .xui-ai-chat__fab {
  min-width: 52px;
  width: 52px;
  padding: 0;
  justify-content: center;
  border-radius: 14px;
}

.xui-ai-chat.is-open .xui-ai-chat__fab-inner {
  justify-content: center;
}

.xui-ai-chat.is-open .xui-ai-chat__fab-icon,
.xui-ai-chat.is-open .xui-ai-chat__fab-copy {
  display: none;
}

.xui-ai-chat.is-open .xui-ai-chat__fab-close {
  display: grid;
}

.xui-ai-chat__panel {
  position: relative;
  order: -1;
  width: min(400px, calc(100vw - 28px));
  height: min(560px, calc(100vh - 160px));
  display: flex;
  flex-direction: column;
  border-radius: var(--xai-radius);
  overflow: hidden;
  background:
    radial-gradient(120% 80% at 100% -10%, rgba(34, 211, 238, 0.14), transparent 45%),
    radial-gradient(90% 70% at -10% 100%, rgba(13, 148, 136, 0.1), transparent 50%),
    linear-gradient(180deg, #ffffff 0%, #f8fafc 100%);
  box-shadow: var(--xai-shadow);
  border: 1px solid rgba(148, 163, 184, 0.25);
  transform-origin: bottom right;
  animation: xai-pop 0.34s cubic-bezier(0.22, 1, 0.36, 1);
}

.xui-ai-chat__panel[hidden] {
  display: none !important;
}

.xui-ai-chat__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 14px 14px 12px;
  color: #f8fafc;
  background:
    linear-gradient(125deg, rgba(15, 23, 42, 0.96), rgba(15, 118, 110, 0.92) 70%, rgba(8, 145, 178, 0.9));
}

.xui-ai-chat__brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.xui-ai-chat__avatar {
  width: 38px;
  height: 38px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  background: rgba(255, 255, 255, 0.12);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.18);
  flex-shrink: 0;
}

.xui-ai-chat__title {
  display: block;
  font-size: 0.95rem;
  font-weight: 800;
  line-height: 1.3;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.xui-ai-chat__subtitle {
  display: block;
  font-size: 0.72rem;
  opacity: 0.82;
  margin-top: 2px;
}

.xui-ai-chat__header-actions {
  display: flex;
  gap: 4px;
}

.xui-ai-chat__icon-btn {
  width: 32px;
  height: 32px;
  border: 0;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: background 0.2s;
}

.xui-ai-chat__icon-btn:hover {
  background: rgba(255, 255, 255, 0.2);
}

.xui-ai-chat__status {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  font-size: 0.75rem;
  color: #0f766e;
  background: rgba(13, 148, 136, 0.08);
  border-bottom: 1px solid var(--xai-line);
}

.xui-ai-chat__dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #14b8a6;
  box-shadow: 0 0 0 0 rgba(20, 184, 166, 0.5);
  animation: xai-dot 1.8s infinite;
}

.xui-ai-chat__messages {
  flex: 1;
  overflow-y: auto;
  padding: 14px 12px 8px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  scroll-behavior: smooth;
}

.xui-ai-chat__msg {
  max-width: 88%;
  padding: 10px 12px;
  border-radius: 16px;
  font-size: 0.88rem;
  line-height: 1.7;
  white-space: pre-wrap;
  word-break: break-word;
  animation: xai-fade 0.28s ease;
}

.xui-ai-chat__msg--bot {
  align-self: flex-start;
  background: #fff;
  border: 1px solid var(--xai-line);
  color: var(--xai-ink);
  border-bottom-right-radius: 6px;
  box-shadow: 0 4px 14px rgba(15, 23, 42, 0.04);
}

.xui-ai-chat__msg--user {
  align-self: flex-end;
  background: linear-gradient(135deg, #0f766e, #0e7490);
  color: #fff;
  border-bottom-left-radius: 6px;
  box-shadow: 0 8px 18px rgba(15, 118, 110, 0.22);
}

.xui-ai-chat__msg img {
  display: block;
  max-width: 100%;
  border-radius: 12px;
  margin-top: 8px;
}

.xui-ai-chat__typing {
  display: inline-flex;
  gap: 4px;
  padding: 4px 2px;
}

.xui-ai-chat__typing i {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #94a3b8;
  animation: xai-bounce 1.1s infinite;
}

.xui-ai-chat__typing i:nth-child(2) { animation-delay: 0.15s; }
.xui-ai-chat__typing i:nth-child(3) { animation-delay: 0.3s; }

.xui-ai-chat__suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 0 12px 10px;
}

.xui-ai-chat__chip {
  border: 1px solid rgba(13, 148, 136, 0.28);
  background: rgba(255, 255, 255, 0.85);
  color: #0f766e;
  border-radius: 999px;
  padding: 7px 12px;
  font-size: 0.78rem;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.2s, transform 0.2s, border-color 0.2s;
  text-align: right;
  line-height: 1.4;
}

.xui-ai-chat__chip:hover {
  background: rgba(13, 148, 136, 0.1);
  border-color: rgba(13, 148, 136, 0.5);
  transform: translateY(-1px);
}

.xui-ai-chat__preview {
  position: relative;
  margin: 0 12px 8px;
  width: 88px;
}

.xui-ai-chat__preview img {
  width: 88px;
  height: 88px;
  object-fit: cover;
  border-radius: 14px;
  border: 1px solid var(--xai-line);
  box-shadow: 0 6px 16px rgba(15, 23, 42, 0.12);
}

.xui-ai-chat__preview-clear {
  position: absolute;
  top: -6px;
  left: -6px;
  width: 22px;
  height: 22px;
  border: 0;
  border-radius: 50%;
  background: var(--xai-ink);
  color: #fff;
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
}

.xui-ai-chat__human-wrap {
  padding: 0 12px 8px;
}

.xui-ai-chat__human-btn {
  width: 100%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1px solid rgba(34, 158, 217, 0.35);
  background: linear-gradient(180deg, #f0f9ff, #e0f2fe);
  color: #0369a1;
  border-radius: 12px;
  padding: 9px 12px;
  font: inherit;
  font-size: 0.82rem;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.2s, transform 0.2s, border-color 0.2s;
}

.xui-ai-chat__human-btn:hover {
  background: linear-gradient(180deg, #e0f2fe, #bae6fd);
  border-color: rgba(2, 132, 199, 0.5);
  transform: translateY(-1px);
}

.xui-ai-chat__msg a.xui-ai-chat__tg-link {
  display: inline-block;
  margin-top: 6px;
  color: #0284c7;
  font-weight: 700;
  text-decoration: underline;
  word-break: break-all;
}

.xui-ai-chat__composer {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 8px;
  align-items: end;
  padding: 10px 12px 6px;
  border-top: 1px solid var(--xai-line);
  background: rgba(255, 255, 255, 0.72);
  backdrop-filter: blur(10px);
}

.xui-ai-chat__tools {
  display: flex;
  gap: 4px;
  padding-bottom: 4px;
}

.xui-ai-chat__tool {
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: 12px;
  background: #eef2f7;
  color: #334155;
  display: grid;
  place-items: center;
  cursor: pointer;
  position: relative;
  transition: background 0.2s, color 0.2s;
}

.xui-ai-chat__tool:hover {
  background: #e2e8f0;
  color: #0f766e;
}

.xui-ai-chat__tool.is-recording {
  background: #fee2e2;
  color: #dc2626;
}

.xui-ai-chat__rec-pulse {
  display: none;
  position: absolute;
  inset: -3px;
  border-radius: 14px;
  border: 2px solid rgba(220, 38, 38, 0.45);
  animation: xai-pulse 1s infinite;
}

.xui-ai-chat__tool.is-recording .xui-ai-chat__rec-pulse {
  display: block;
}

.xui-ai-chat__input {
  width: 100%;
  min-height: 42px;
  max-height: 110px;
  resize: none;
  border: 1px solid #dbe3ee;
  border-radius: 14px;
  padding: 10px 12px;
  font: inherit;
  font-size: 0.88rem;
  line-height: 1.55;
  background: #fff;
  color: var(--xai-ink);
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.xui-ai-chat__input:focus {
  border-color: rgba(13, 148, 136, 0.55);
  box-shadow: 0 0 0 3px rgba(20, 184, 166, 0.15);
}

.xui-ai-chat__send {
  width: 42px;
  height: 42px;
  border: 0;
  border-radius: 14px;
  background: linear-gradient(135deg, #0f766e, #0891b2);
  color: #fff;
  cursor: pointer;
  display: grid;
  place-items: center;
  box-shadow: 0 8px 18px rgba(8, 145, 178, 0.28);
  transition: transform 0.2s, opacity 0.2s;
}

.xui-ai-chat__send:hover {
  transform: translateY(-1px);
}

.xui-ai-chat__send:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  transform: none;
}

.xui-ai-chat__privacy {
  margin: 0;
  padding: 0 14px 10px;
  font-size: 0.68rem;
  color: #94a3b8;
  text-align: center;
  line-height: 1.5;
}

.xui-ai-chat__error {
  align-self: stretch;
  margin: 0;
  padding: 8px 10px;
  border-radius: 12px;
  background: #fef2f2;
  color: #b91c1c;
  font-size: 0.8rem;
  border: 1px solid #fecaca;
}

@media (max-width: 768px) {
  .xui-ai-chat {
    right: 12px !important;
    left: auto !important;
    bottom: 72px !important;
  }
  .xui-ai-chat__panel {
    width: min(360px, calc(100vw - 24px));
    height: min(68vh, 540px);
  }
  .xui-ai-chat__fab {
    min-width: 168px;
    height: 48px;
  }
  .xui-ai-chat__fab-label { font-size: 0.8rem; }
  .xui-ai-chat__fab-hint { display: none; }
}

/* Logged-in mobile shell: above bottom nav; support FAB hidden */
@media (max-width: 768px) {
  body.xui-user-logged-in #xui-ai-chat {
    bottom: 96px !important;
    right: 12px !important;
  }
  body.xui-user-logged-in #xui-ai-chat .xui-ai-chat__panel {
    height: min(58vh, 500px);
  }
}

@keyframes xai-pop {
  from { opacity: 0; transform: translateY(10px) scale(0.96); }
  to { opacity: 1; transform: none; }
}

@keyframes xai-fade {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}

@keyframes xai-shine {
  0%, 100% { opacity: 0.15; transform: translateX(8%); }
  50% { opacity: 0.55; transform: translateX(-8%); }
}

@keyframes xai-pulse {
  0%, 100% { transform: scale(1); opacity: 0.7; }
  50% { transform: scale(1.08); opacity: 0.25; }
}

@keyframes xai-dot {
  0% { box-shadow: 0 0 0 0 rgba(20, 184, 166, 0.45); }
  70% { box-shadow: 0 0 0 8px rgba(20, 184, 166, 0); }
  100% { box-shadow: 0 0 0 0 rgba(20, 184, 166, 0); }
}

@keyframes xai-bounce {
  0%, 80%, 100% { transform: translateY(0); opacity: 0.45; }
  40% { transform: translateY(-4px); opacity: 1; }
}
