:root{
  --chat-text: #0f172a;
  --chat-muted: #475569;
  --chat-border: #e5e7eb;
  --chat-bg: #ffffff;
  --chat-bot-bg: #eef2ff;
  --chat-user-bg: #d1fae5;
  --chat-accent: #0076ce;
}

/* جلوگیری از اسکرول صفحه وقتی چت باز است */
body.va-open { 
  overflow: hidden; 
}

/* Container اصلی چت */
.chat-widget{
  position: fixed;
  right: max(16px, env(safe-area-inset-right));
  bottom: max(16px, env(safe-area-inset-bottom));
  z-index: 10000;
}

/* Toggle button */
#chat-toggle-btn{
  background-color: var(--chat-accent);
  color:#fff;
  border:none;
  padding:12px 20px;
  border-radius:30px;
  cursor:pointer; font-size:15px;
  box-shadow:0 6px 18px rgba(0,0,0,.15);
  transition: transform .15s ease;
}
#chat-toggle-btn.va-open{ pointer-events: none; opacity:.6; }

/* Overlay */
.chat-overlay{
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.4);
  backdrop-filter: blur(2px);
  z-index: 2147483000;
  display:none;
  overflow: hidden;
  /* برای دریافت کلیک‌ها */
  pointer-events: auto;
}
.chat-overlay.is-open{ display: flex; justify-content: flex-end; align-items: flex-end; }
.chat-overlay .chat-box {
  pointer-events: auto; /* پنل کلیک‌پذیر بماند */
}

/* پنجره چت */
#chat-overlay .chat-box{
  position: relative;
  right: 0;
  left: auto;
  bottom: 16px;
  width: 500px;
  max-width: 90vw;
  max-height: 80vh;
  background: var(--chat-bg);
  color: var(--chat-text);
  border-radius: 16px;
  display:flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 10px 30px rgba(0,0,0,.25);
  transition: width 0.3s ease, height 0.3s ease;
}

/* Fullscreen */
#chat-overlay.fullscreen .chat-box{
  width: 100vw;
  height: 100vh;
  border-radius:0;
  right:0;
  left:0;
  bottom:0;
  max-width: none;
  max-height: none;
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

.chat-window {
  width: 400px; /* یا بیشتر برای فضای بیشتر */
  min-width: 400px;
}
/* Header */
.chat-header{
  display:flex;
  justify-content: space-between;
  align-items: center;
  padding:14px 16px;
  font-weight:700;
  background:#121826;
  color:#fff;
  border-top-left-radius:16px;
  border-top-right-radius:16px;
}
.btn-max{
  background: transparent;
  border: none;
  color: silver; /* رنگ نقره‌ای برای آیکون و متن */
  font-size: 18px;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 6px;
  transition: background 0.2s ease, color 0.2s ease;
}
.btn-max:hover{
  background: rgba(255,255,255,0.1);
  color: #3b82f6; /* رنگ هنگام هاور */
}
.chat-search{
  background:#1f2937;
  border-bottom:1px solid #374151;
  padding:10px;
  display:flex;
  gap:8px;
}
.chat-search input{
  flex:1;
  background:#111827;
  border:1px solid #374151;
  color:#e5e7eb;
  border-radius:6px;
  padding:8px 10px;
  font-size:14px;
}
.chat-search button{
  background:#3b82f6;
  color:#fff;
  border:none;
  border-radius:6px;
  padding:8px 12px;
  cursor:pointer;
  font-size:14px;
  font-weight:600;
}
.chat-search input:focus{
  outline:none;
  border-color:#3b82f6;
}
.chat-search button:hover{
  background:#2563eb;
}
#typing-indicator{
  background:#1f2937;
  color:#9ca3af;
  padding:10px 16px;
  font-size:14px;
  font-style:italic;
  border-top:1px solid #374151;
  animation: pulse 2s infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 0.6; }
  50% { opacity: 1; }
}
/* Body */
.chat-body{
  flex:1 1 auto;
  padding:12px;
  overflow-y: auto;
  font-size:15px;
  line-height:1.6;
  color:#e5e7eb;
  background:#0f172a;
  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch;
}
.chat-message.bot{
  background:#0b1220;
  border:1px solid #1f2937;
  color:#e5e7eb;
  border-radius:12px;
  padding:12px;
  margin:10px 0;
}
.chat-message.user{
  background:#1e293b;
  border:1px solid #334155;
  color:#e2e8f0;
  border-radius:12px;
  padding:10px 12px;
  margin:10px 0 10px auto;
  max-width:80%;
}
.chat-options{
  display:grid;
  grid-template-columns:repeat(2,minmax(0,1fr));
  gap:10px;
  background:#0b1220;
  border:1px solid #1f2937;
  border-radius:12px;
  padding:12px;
}
.chat-options button{
  display:flex;
  align-items:center;
  gap:10px;
  border:1px solid #263142;
  background:#111827;
  color:#e5e7eb;
  border-radius:10px;
  padding:10px 12px;
  font-weight:600;
  transition:.15s;
  cursor:pointer;
  font-size:14px;
}
.chat-options button:hover{
  transform:translateY(-1px);
  border-color:#3b82f6;
  background:#0f1a2f;
}
.chat-options button .emoji{
  font-size:18px;
}

/* Category buttons */
.category-btn {
  background-color: #4CAF50; /* رنگ پس‌زمینه */
  border: none;
  color: white;
  padding: 10px 20px;
  text-align: center;
  display: inline-block;
  font-size: 16px;
  cursor: pointer;
  border-radius: 5px;
  margin: 5px;
}

.category-btn:hover {
  background-color: #45a049; /* تغییر رنگ هنگام hover */
}

/* Grouped options */
.chat-group { 
  margin: 8px 0 12px; 
}
.chat-group-title {
  font-weight: 600;
  font-size: 12px;
  color: var(--chat-muted);
  margin: 2px 0 6px;
  letter-spacing: .2px;
  text-transform: none; /* اگر خواستی uppercase کن */
}
.chat-group-items {
  display: grid;
  gap: 8px;
  grid-template-columns: 1fr;
}
@media (min-width: 460px) {
  .chat-group-items { 
    grid-template-columns: 1fr 1fr; 
  }
}

/* Disambiguation suggestions */
.chat-suggestions {
  padding: 12px;
}
.suggestion-hint {
  font-size: 13px;
  color: var(--chat-muted);
  margin-bottom: 10px;
  font-style: italic;
}
.suggestion-buttons {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 8px;
}
.suggestion-btn {
  background: #1e293b;
  border: 1px solid #334155;
  color: #e5e7eb;
  padding: 10px 14px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  transition: all 0.15s ease;
  text-align: left;
}
.suggestion-btn:hover {
  background: #334155;
  border-color: #3b82f6;
  transform: translateY(-1px);
}
.suggestion-btn.fallback {
  background: transparent;
  border-style: dashed;
  color: var(--chat-muted);
  font-size: 13px;
}
.suggestion-btn.fallback:hover {
  color: #e5e7eb;
  border-color: #3b82f6;
}

/* Input پایین */
.chat-input{
  display:flex;
  gap:8px;
  padding:10px;
  background:#0f172a;
  border-top:1px solid #1f2937;
}
#chat-input-text {
  flex: 3 1 auto; /* طول 3 برابر File Upload */
  min-width: 0;   /* جلوگیری از overflow */
  border:1px solid #334155;
  border-radius:10px;
  padding:10px;
  font-size:15px;
  background:#0b1220;
  color:#e5e7eb;
}
#chat-send-btn{
  border:0;
  background:#3b82f6;
  color:#fff;
  border-radius:10px;
  padding:0 16px;
  font-weight:700;
  cursor:pointer;
  font-size:14px;
}
#chat-send-btn:disabled{ opacity:.6; cursor:not-allowed; }

/* tabs */
.chat-tabs{
  display:flex;
  gap:6px;
  margin-bottom:10px;
}
.chat-tab{
  padding:6px 10px;
  border-radius:8px;
  border:1px solid #253149;
  background:#0f172a;
  color:#cbd5e1;
}
.chat-tab.active{
  background:#1e293b;
  border-color:#3b82f6;
  color:#fff;
}

/* states */
.chat-alert{
  border:1px solid #374151;
  background:#111827;
  border-radius:10px;
  padding:10px;
}
.chat-typing{
  opacity:.7;
  font-style:italic;
}

/* فرم تیکت */
.ticket-form{ display:block; }
.chat-form-row{ margin:8px 0; display:flex; flex-direction:column; gap:4px; }
.chat-form-row label{
  font-size:12px;
  color: var(--chat-muted);
}
.chat-form-row input{
  padding:10px 12px;           /* +2 */
  border:1px solid var(--chat-border);
  border-radius:8px;
  font-size:15px;              /* +1 */
  line-height:1.5;
}
.chat-form-actions{ margin-top:8px; display:flex; gap:8px; }
.btn-primary{
  background: var(--chat-accent);
  color:#fff;
  border:none; padding:10px 12px; border-radius:8px; cursor:pointer;
}
.btn-primary:hover{ filter:brightness(0.95); }

/* فرم بازگشت و گارانتی */
#returns-form{
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 16px;
  background: #0b1220;
  border: 1px solid #1f2937;
  border-radius: 12px;
  margin: 10px 0;
}

#returns-form input[type="email"],
#returns-form input[type="text"]{
  padding: 12px 16px;
  border: 1px solid #334155;
  background: #111827;
  color: #e5e7eb;
  border-radius: 8px;
  font-size: 15px;
  line-height: 1.5;
  width: 100%;
  box-sizing: border-box;
}

#returns-form input[type="email"]:focus,
#returns-form input[type="text"]:focus{
  outline: none;
  border-color: #3b82f6;
  box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.1);
}

#returns-form textarea{
  padding: 12px 16px;
  border: 1px solid #334155;
  background: #111827;
  color: #e5e7eb;
  border-radius: 8px;
  font-size: 15px;
  line-height: 1.5;
  width: 100%;
  min-height: 100px;
  resize: vertical;
  font-family: inherit;
  box-sizing: border-box;
}

#returns-form textarea:focus{
  outline: none;
  border-color: #3b82f6;
  box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.1);
}

#returns-form .btn-primary{
  background: #3b82f6;
  color: #fff;
  border: none;
  padding: 12px 20px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 15px;
  font-weight: 600;
  transition: background-color 0.2s ease;
  width: 100%;
}

#returns-form .btn-primary:hover{
  background: #2563eb;
}

#returns-form .btn-primary:disabled{
  background: #6b7280;
  cursor: not-allowed;
}

#returns-form-result{
  margin-top: 12px;
  padding: 12px;
  border-radius: 8px;
  font-size: 14px;
  text-align: center;
}

#returns-form-result.success{
  background: #064e3b;
  color: #10b981;
  border: 1px solid #059669;
}

#returns-form-result.error{
  background: #7f1d1d;
  color: #f87171;
  border: 1px solid #dc2626;
}

/* استایل دادن به دکمه آپلود */
.file-upload-label {
  flex: 1 1 auto; /* طول کمتر */
  display: flex;
  justify-content: center;
  align-items: center;
  background-color: #3b82f6;
  color: white;
  padding: 10px;
  border-radius: 8px;
  cursor: pointer;
  font-size:16px;
}

.file-upload-label i {
    margin-right: 8px; /* فاصله بین آیکون و متن */
}

/* استایل برای آیکون کلیپ */
.upload-icon {
    width: 20px;   /* اندازه آیکون */
    height: 20px;  /* اندازه آیکون */
    margin-right: 8px;
    fill: white;
}

/* Responsive موبایل */
@media (max-width:768px){
  #chat-overlay .chat-box{
    width: auto;
    max-width: 90vw;
    max-height: 90vh;
    bottom:12px;
    right:12px;
    left:12px;
  }
  .chat-body{ max-height: calc(80vh - 60px); font-size:16px; }
  .chat-input input{ font-size:16px; min-height:44px; }
}
@media (max-width:380px){
  .chat-box{ border-radius:10px; }
  .chat-header{ padding:8px 10px; }
  .chat-body{ padding:10px; }
  #chat-toggle-btn{ padding:9px 12px; }
}
/* Guard: if any display:none accidentally set on .chat-box */
.chat-overlay.is-open .chat-box{ display:flex; }

/* Smooth scroll & prevent background page scroll on mobile */
.chat-body{
  overscroll-behavior: contain;
  box-sizing: border-box;
}

/* Motion reduce */
@media (prefers-reduced-motion: reduce){
  #chat-toggle-btn:hover{ transform: none; }
  .chat-body{ scroll-behavior: auto; }
}

/* A11y: focus-visible for keyboard users */
.chat-options button:focus-visible,
#chat-toggle-btn:focus-visible,
.chat-input button:focus-visible,
.chat-form-row input:focus-visible{
  outline: 2px solid var(--chat-accent);
  outline-offset: 2px;
}

/* Touch tweaks */
.chat-widget, .chat-box, .chat-options button, .chat-input button{
  -webkit-tap-highlight-color: transparent;
}

/* Hover/active states for option buttons */
.chat-options button:hover{ filter: brightness(0.98); }
.chat-options button:active{ transform: translateY(1px); }

/* Optional: slim scrollbar (WebKit) */
.chat-body::-webkit-scrollbar{ width: 10px; }
.chat-body::-webkit-scrollbar-thumb{ background: #d1d5db; border-radius: 8px; }
.chat-body::-webkit-scrollbar-track{ background: #f3f4f6; }

/* Dark mode */
@media (prefers-color-scheme: dark){
  :root{
    --chat-text: #e5e7eb;       /* gray-200 */
    --chat-muted:#9ca3af;       /* gray-400 */
    --chat-border:#374151;      /* gray-700 */
    --chat-bg:#111827;          /* gray-900 */
    --chat-bot-bg:#1f2937;      /* gray-800 */
    --chat-user-bg:#064e3b;     /* emerald-900 */
    --chat-accent:#60a5fa;      /* blue-400 */
  }
  .chat-box, .chat-header, .chat-body, .chat-input{
    background: var(--chat-bg);
    color: var(--chat-text);
  }
  .chat-options button{
    background: #111827; color: var(--chat-text); border-color: var(--chat-border);
  }
}

/* Print */
@media print{
  .chat-widget,
  .chat-overlay{ display:none !important; }
}