/* ویجت چت Rozet — UI مدرن RTL */
#rozet-chat-root {
  --rc-primary: var(--rozet-chat-accent, #696cff);
  --rc-primary-dark: #5f61e6;
  --rc-bg: #f0f2f5;
  --rc-surface: #ffffff;
  --rc-user: #696cff;
  --rc-user-text: #fff;
  --rc-bot: #ffffff;
  --rc-shadow: 0 12px 48px rgba(16, 24, 40, 0.18);
  font-family: inherit;
  z-index: 99990;
  direction: rtl;
}

/* دکمه شناور */
.rozet-chat-fab {
  position: fixed;
  bottom: 28px;
  z-index: 99991;
  width: 60px;
  height: 60px;
  border: none;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--rc-primary) 0%, var(--rc-primary-dark) 100%);
  color: #fff;
  box-shadow: 0 8px 28px rgba(105, 108, 255, 0.45);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.75rem;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}
.rozet-chat-fab:hover { transform: scale(1.06); }
.rozet-chat-fab.pos-right { left: 28px; }
.rozet-chat-fab.pos-left { right: 28px; }
.rozet-chat-fab .fab-pulse {
  position: absolute;
  inset: -4px;
  border-radius: 50%;
  border: 2px solid var(--rc-primary);
  opacity: 0.35;
  animation: rc-pulse 2s infinite;
}
.rozet-chat-fab .status-dot {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: #22c55e;
  border: 2px solid #fff;
}
.rozet-chat-fab .status-dot.offline { background: #94a3b8; }
@keyframes rc-pulse {
  0%, 100% { opacity: 0.35; }
  50% { opacity: 0.08; }
}

@media (prefers-reduced-motion: reduce) {
  .rozet-chat-fab .fab-pulse {
    animation: none;
  }
}

/* پنل */
.rozet-chat-panel {
  position: fixed;
  bottom: 100px;
  width: 380px;
  max-width: calc(100vw - 24px);
  height: min(560px, calc(100vh - 120px));
  background: var(--rc-surface);
  border-radius: 20px;
  box-shadow: var(--rc-shadow);
  display: none;
  flex-direction: column;
  z-index: 99992;
  overflow: hidden;
}
.rozet-chat-panel.open { display: flex; }
.rozet-chat-panel.pos-right { left: 28px; }
.rozet-chat-panel.pos-left { right: 28px; }

.rozet-chat-header {
  background: linear-gradient(135deg, var(--rc-primary) 0%, var(--rc-primary-dark) 100%);
  color: #fff;
  padding: 16px 18px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-shrink: 0;
}
.rozet-chat-header .brand { display: flex; align-items: center; gap: 12px; }
.rozet-chat-header .brand-icon {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  background: rgba(255,255,255,0.2);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.35rem;
}
.rozet-chat-header h3 { margin: 0; font-size: 1rem; font-weight: 600; }
.rozet-chat-header .status-line { font-size: 0.78rem; opacity: 0.9; margin-top: 2px; }
.rozet-chat-header .status-line.online::before { content: '● '; color: #86efac; }
.rozet-chat-header .status-line.offline::before { content: '● '; color: #fde68a; }
.rozet-chat-close {
  width: 36px;
  height: 36px;
  border: none;
  border-radius: 10px;
  background: rgba(255,255,255,0.15);
  color: #fff;
  font-size: 1.4rem;
  line-height: 1;
  cursor: pointer;
}

.rozet-chat-offline-banner {
  background: linear-gradient(90deg, #fff7ed, #ffedd5);
  border-bottom: 1px solid #fed7aa;
  padding: 12px 16px;
  font-size: 0.85rem;
  color: #9a3412;
  flex-shrink: 0;
}
.rozet-chat-offline-banner a { color: #c2410c; font-weight: 600; }

/* فقط فرم مهمان — تمام صفحه پنل */
.rozet-chat-guest-screen {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 24px 20px;
  background: var(--rc-bg);
}
.rozet-chat-guest-screen.is-hidden { display: none !important; }
.rozet-chat-guest-card {
  background: var(--rc-surface);
  border-radius: 16px;
  padding: 22px 20px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.06);
}
.rozet-chat-guest-card h4 { margin: 0 0 6px; font-size: 1.05rem; font-weight: 600; color: #1e293b; }
.rozet-chat-guest-card p { margin: 0 0 18px; font-size: 0.85rem; color: #64748b; }
.rozet-chat-field { margin-bottom: 14px; }
.rozet-chat-field label {
  display: block;
  font-size: 0.8rem;
  font-weight: 500;
  color: #475569;
  margin-bottom: 6px;
}
.rozet-chat-field input {
  width: 100%;
  padding: 11px 14px;
  border: 1px solid #e2e8f0;
  border-radius: 10px;
  font-size: 0.95rem;
  transition: border-color 0.15s, box-shadow 0.15s;
  box-sizing: border-box;
}
.rozet-chat-field input:focus {
  outline: none;
  border-color: var(--rc-primary);
  box-shadow: 0 0 0 3px rgba(105, 108, 255, 0.15);
}
.rozet-chat-guest-submit {
  width: 100%;
  margin-top: 8px;
  padding: 12px;
  border: none;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--rc-primary), var(--rc-primary-dark));
  color: #fff;
  font-weight: 600;
  font-size: 0.95rem;
  cursor: pointer;
}
.rozet-chat-guest-error {
  margin-top: 10px;
  padding: 10px 12px;
  border-radius: 10px;
  background: #fef2f2;
  border: 1px solid #fecaca;
  color: #b91c1c;
  font-size: 0.85rem;
  line-height: 1.5;
}
.rozet-chat-guest-error.is-hidden { display: none !important; }
.rozet-chat-field input.is-invalid {
  border-color: #ef4444;
  box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.12);
}

/* سوالات پرتکرار — یک‌بار داخل گفتگو بعد از خوش‌آمد */
.rozet-chat-faq-inline {
  clear: both;
  margin: 12px 0 16px;
  padding: 12px;
  background: var(--rc-surface);
  border: 1px solid #e8ecf1;
  border-radius: 14px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.04);
}
.rozet-chat-faq-inline .faq-inline-title {
  font-size: 0.8rem;
  font-weight: 600;
  color: #64748b;
  margin-bottom: 10px;
}
.rozet-chat-faq-inline .faq-inline-buttons {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.rozet-chat-faq-inline .rozet-chat-faq-btn {
  display: block;
  width: 100%;
  text-align: right;
  border: 1px solid #e8ecf1;
  background: #f8fafc;
  padding: 9px 12px;
  border-radius: 10px;
  font-size: 0.84rem;
  color: #334155;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
.rozet-chat-faq-inline .rozet-chat-faq-btn:hover {
  background: #eff6ff;
  border-color: #c7d2fe;
}

/* بخش چت (بعد از شروع) */
.rozet-chat-main {
  flex: 1;
  display: none;
  flex-direction: column;
  min-height: 0;
  background: var(--rc-bg);
}
.rozet-chat-main.is-active { display: flex; }

.rozet-chat-messages-wrap {
  flex: 1;
  overflow-y: auto;
  padding: 16px 14px;
  min-height: 0;
}
.rozet-chat-messages-wrap::after { content: ''; display: table; clear: both; }

.rozet-chat-msg {
  margin-bottom: 12px;
  max-width: 85%;
  clear: both;
  animation: rc-msg-in 0.25s ease;
}
@keyframes rc-msg-in {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}
.rozet-chat-msg.user { float: right; }
.rozet-chat-msg.admin,
.rozet-chat-msg.faq,
.rozet-chat-msg.ai,
.rozet-chat-msg.system { float: left; }

.rozet-chat-msg .bubble {
  padding: 10px 14px;
  border-radius: 16px;
  font-size: 0.9rem;
  line-height: 1.55;
  box-shadow: 0 1px 2px rgba(0,0,0,0.06);
}
.rozet-chat-msg.user .bubble {
  background: linear-gradient(135deg, var(--rc-primary), var(--rc-primary-dark));
  color: var(--rc-user-text);
  border-bottom-left-radius: 4px;
}
.rozet-chat-msg.admin .bubble {
  background: var(--rc-bot);
  color: #1e293b;
  border: 1px solid #e8ecf1;
  border-bottom-right-radius: 4px;
}
.rozet-chat-msg.faq .bubble {
  background: #eff6ff;
  color: #1e40af;
  border: 1px solid #bfdbfe;
  border-bottom-right-radius: 4px;
}
.rozet-chat-msg.ai .bubble {
  background: #f0fdf4;
  color: #14532d;
  border: 1px solid #bbf7d0;
  border-bottom-right-radius: 4px;
}
.rozet-chat-msg.ai .meta::before {
  content: 'مشاور هوشمند · ';
  color: #15803d;
}
.rozet-chat-typing {
  clear: both;
  float: left;
  font-size: 0.82rem;
  color: #64748b;
  padding: 8px 12px;
  font-style: italic;
}
.rozet-chat-typing.d-none { display: none; }
.rozet-chat-msg.system .bubble {
  background: #f8fafc;
  color: #64748b;
  font-size: 0.82rem;
  text-align: center;
  max-width: 100%;
  margin: 0 auto;
  float: none;
}
.rozet-chat-msg .reply-quote {
  font-size: 0.75rem;
  opacity: 0.9;
  border-right: 3px solid var(--rc-primary);
  padding-right: 8px;
  margin-bottom: 6px;
}
.rozet-chat-msg .meta {
  font-size: 0.7rem;
  color: #94a3b8;
  margin-top: 4px;
}
.rozet-chat-msg.user .meta { text-align: left; }
.rozet-chat-msg .reply-link {
  cursor: pointer;
  color: var(--rc-primary);
  margin-right: 6px;
}


.rozet-chat-rating {
  text-align: center;
  padding: 14px;
  background: var(--rc-surface);
  border-top: 1px solid #eef1f6;
}
.rozet-chat-rating .stars span {
  font-size: 1.75rem;
  cursor: pointer;
  color: #e2e8f0;
  transition: color 0.15s, transform 0.15s;
}
.rozet-chat-rating .stars span:hover,
.rozet-chat-rating .stars span.on { color: #fbbf24; transform: scale(1.1); }

/* نوار ارسال */
.rozet-chat-composer {
  flex-shrink: 0;
  padding: 12px 14px 14px;
  background: var(--rc-surface);
  border-top: 1px solid #eef1f6;
}
.rozet-chat-reply-bar {
  background: #f1f5f9;
  border-radius: 10px;
  padding: 8px 10px;
  margin-bottom: 8px;
  font-size: 0.8rem;
  color: #475569;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 8px;
}
.rozet-chat-reply-bar.is-hidden { display: none !important; }
.rozet-chat-composer-row {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  background: #f1f5f9;
  border-radius: 14px;
  padding: 6px 6px 6px 12px;
  border: 1px solid #e2e8f0;
}
.rozet-chat-composer-row:focus-within {
  border-color: var(--rc-primary);
  box-shadow: 0 0 0 3px rgba(105, 108, 255, 0.12);
}
.rozet-chat-composer textarea {
  flex: 1;
  border: none;
  background: transparent;
  resize: none;
  min-height: 24px;
  max-height: 100px;
  padding: 8px 0;
  font-size: 0.92rem;
  line-height: 1.4;
}
.rozet-chat-composer textarea:focus { outline: none; }
.rozet-chat-send-btn {
  width: 44px;
  height: 44px;
  flex-shrink: 0;
  border: none;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--rc-primary), var(--rc-primary-dark));
  color: #fff;
  font-size: 1.25rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.rozet-chat-send-btn:disabled { opacity: 0.5; cursor: not-allowed; }

@media (max-width: 480px) {
  .rozet-chat-panel {
    left: 12px !important;
    right: 12px !important;
    width: auto;
  }
}

@media (max-width: 991.98px) {
  /* FAB در منوی پایین است — از فلش لحظه‌ای جلوگیری (CSS در head لود می‌شود) */
  .rozet-chat-fab {
    display: none !important;
  }

  body.head-pro-has-mobile-nav .rozet-chat-panel {
    bottom: calc(var(--mob-nav-float-offset, 92px) + 10px) !important;
    max-height: min(560px, calc(100vh - var(--mob-nav-float-offset, 92px) - 30px));
  }
}
