#tyw-root, #tyw-root * { box-sizing: border-box; }
#tyw-root {
  position: fixed;
  bottom: 22px;
  z-index: 999999;
  font-family: 'IRANSansX', Tahoma, 'Segoe UI', sans-serif;
  direction: rtl;
  line-height: 1.7;

  /* مقادیر پیش‌فرض؛ از PHP بازنویسی می‌شوند */
  --tyw-grad1:#4f46e5; --tyw-grad2:#7c3aed; --tyw-header-text:#fff;
  --tyw-btn1:#4f46e5; --tyw-btn2:#7c3aed; --tyw-btn-icon:#fff;
  --tyw-panel:#fff; --tyw-bg:#f3f4f8; --tyw-text:#1e293b;
  --tyw-user-bubble:#4f46e5; --tyw-user-bubble-text:#fff;
  --tyw-agent-bubble:#fff;   --tyw-agent-bubble-text:#1e293b;
  --tyw-primary:#4f46e5; --tyw-size:62px; --tyw-chat-image:none;
  --tyw-radius:22px;
}
#tyw-root.tyw-pos-right { right: 22px; }
#tyw-root.tyw-pos-left  { left: 22px; }

.tyw-launcher{
  width:var(--tyw-size); height:var(--tyw-size);
  border-radius:50%; border:none; cursor:pointer;
  background:linear-gradient(135deg,var(--tyw-btn1),var(--tyw-btn2));
  color:var(--tyw-btn-icon);
  display:flex; align-items:center; justify-content:center;
  box-shadow:0 12px 28px -8px rgba(0,0,0,.45), 0 4px 10px rgba(0,0,0,.18);
  position:relative; transition:transform .25s cubic-bezier(.34,1.56,.64,1), box-shadow .25s;
  -webkit-tap-highlight-color:transparent;
}
.tyw-launcher:hover{ transform:translateY(-3px) scale(1.04); }
.tyw-launcher:active{ transform:scale(.96); }
.tyw-ic-chat, .tyw-ic-close{
  position:absolute; inset:0;
  display:flex; align-items:center; justify-content:center;
  transition:transform .3s, opacity .2s;
}
.tyw-launcher svg{ width:46%; height:46%; display:block; }
.tyw-launcher .tyw-ic-close{ opacity:0; transform:rotate(-90deg) scale(.6); }
#tyw-root.tyw-open .tyw-launcher .tyw-ic-chat{ opacity:0; transform:rotate(90deg) scale(.6); }
#tyw-root.tyw-open .tyw-launcher .tyw-ic-close{ opacity:1; transform:rotate(0) scale(1); }

.tyw-launcher::after{
  content:''; position:absolute; inset:0; border-radius:50%;
  border:2px solid var(--tyw-btn1); opacity:.55;
  animation:tyw-pulse 2.4s ease-out infinite;
}
#tyw-root.tyw-open .tyw-launcher::after{ display:none; }
@keyframes tyw-pulse{ 0%{transform:scale(1);opacity:.5} 80%,100%{transform:scale(1.7);opacity:0} }

.tyw-badge{
  position:absolute; top:-4px; inset-inline-start:-4px;
  min-width:22px; height:22px; padding:0 6px; border-radius:11px;
  background:#ef4444; color:#fff; font-size:12px; font-weight:700;
  display:none; align-items:center; justify-content:center;
  box-shadow:0 2px 6px rgba(239,68,68,.5); border:2px solid #fff;
}
.tyw-badge.show{ display:flex; }

.tyw-invite{
  position:absolute; top:50%;
  background:#fff; color:#1f2937; border-radius:16px;
  padding:12px 15px; width:max-content; max-width:230px; font-size:13.5px; font-weight:600;
  box-shadow:0 14px 34px -12px rgba(0,0,0,.4); cursor:pointer;
  opacity:0; pointer-events:none;
  transition:opacity .35s, transform .35s cubic-bezier(.34,1.56,.64,1);
}
#tyw-root.tyw-pos-right .tyw-invite{ right:calc(var(--tyw-size) + 16px); transform:translateY(-50%) translateX(10px) scale(.9); transform-origin:right center; }
#tyw-root.tyw-pos-left  .tyw-invite{ left:calc(var(--tyw-size) + 16px);  transform:translateY(-50%) translateX(-10px) scale(.9); transform-origin:left center; }
#tyw-root.tyw-pos-right .tyw-invite.show,
#tyw-root.tyw-pos-left  .tyw-invite.show{ opacity:1; transform:translateY(-50%) translateX(0) scale(1); pointer-events:auto; }
.tyw-invite::after{
  content:''; position:absolute; top:50%; width:13px; height:13px;
  background:#fff; box-shadow:2px -2px 6px -3px rgba(0,0,0,.18);
}
#tyw-root.tyw-pos-right .tyw-invite::after{ right:-6px; transform:translateY(-50%) rotate(45deg); }
#tyw-root.tyw-pos-left  .tyw-invite::after{ left:-6px;  transform:translateY(-50%) rotate(45deg); box-shadow:-2px 2px 6px -3px rgba(0,0,0,.18); }
.tyw-invite-x{
  position:absolute; top:-8px; inset-inline-start:-8px;
  width:22px; height:22px; border-radius:50%; border:none;
  background:#1f2937; color:#fff; font-size:13px; cursor:pointer;
  display:flex; align-items:center; justify-content:center; line-height:1;
}

.tyw-panel{
  position:absolute; bottom:calc(var(--tyw-size) + 16px);
  width:380px; max-width:calc(100vw - 32px);
  height:min(640px, calc(100vh - 120px));
  background:var(--tyw-panel); border-radius:var(--tyw-radius);
  box-shadow:0 30px 70px -20px rgba(15,23,42,.55), 0 8px 24px rgba(15,23,42,.18);
  display:flex; flex-direction:column; overflow:hidden;
  transform-origin:bottom right; opacity:0; transform:translateY(20px) scale(.92);
  pointer-events:none; transition:opacity .28s ease, transform .3s cubic-bezier(.34,1.4,.64,1);
}
#tyw-root.tyw-pos-right .tyw-panel{ right:0; transform-origin:bottom right; }
#tyw-root.tyw-pos-left  .tyw-panel{ left:0;  transform-origin:bottom left; }
#tyw-root.tyw-open .tyw-panel{ opacity:1; transform:translateY(0) scale(1); pointer-events:auto; }

.tyw-head{
  background:linear-gradient(135deg,var(--tyw-grad1),var(--tyw-grad2));
  color:var(--tyw-header-text); padding:16px 18px;
  display:flex; align-items:center; gap:12px; position:relative; flex-shrink:0;
}
  width:44px; height:44px; border-radius:50%; object-fit:cover;
  border:2px solid rgba(255,255,255,.55); background:rgba(255,255,255,.2); flex-shrink:0;
}
.tyw-head-txt{ flex:1; min-width:0; }
.tyw-head-title{ font-size:15.5px; font-weight:800; margin:0; display:flex; align-items:center; gap:7px;
  white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }
.tyw-head-sub{ font-size:12px; opacity:.92; margin-top:2px; display:flex; align-items:center; gap:6px; }
.tyw-head-actions{ display:flex; gap:4px; align-items:center; }
.tyw-hbtn{
  width:32px; height:32px; border-radius:9px; border:none; cursor:pointer;
  background:rgba(255,255,255,.16); color:var(--tyw-header-text);
  display:flex; align-items:center; justify-content:center; transition:.15s;
}
.tyw-hbtn:hover{ background:rgba(255,255,255,.3); }
.tyw-hbtn svg{ width:17px; height:17px; }

.tyw-dot{ width:8px; height:8px; border-radius:50%; flex-shrink:0; }
.tyw-dot.on{ background:#34d399; box-shadow:0 0 0 3px rgba(52,211,153,.3); }
.tyw-dot.off{ background:#cbd5e1; }

.tyw-body{ flex:1; min-height:0; display:flex; flex-direction:column; background:var(--tyw-bg); position:relative; }

.tyw-home{ overflow-y:auto; padding:0 0 16px; }
.tyw-welcome{
  background:linear-gradient(135deg,var(--tyw-grad1),var(--tyw-grad2));
  color:var(--tyw-header-text); padding:8px 20px 26px; margin-bottom:-14px;
}
.tyw-welcome p{ margin:0; font-size:14px; font-weight:600; opacity:.97; }
.tyw-card{
  background:#fff; margin:0 14px 12px; border-radius:16px; padding:14px 16px;
  box-shadow:0 6px 20px -10px rgba(15,23,42,.25); position:relative;
}
.tyw-card.tyw-card-cta{ display:flex; align-items:center; gap:12px; cursor:pointer; transition:.18s; }
.tyw-card.tyw-card-cta:hover{ transform:translateY(-2px); box-shadow:0 12px 26px -10px rgba(15,23,42,.35); }
.tyw-card-cta-ic{
  width:42px; height:42px; border-radius:12px; flex-shrink:0;
  background:linear-gradient(135deg,var(--tyw-btn1),var(--tyw-btn2)); color:#fff;
  display:flex; align-items:center; justify-content:center;
}
.tyw-card-cta-ic svg{ width:22px; height:22px; }
.tyw-card-cta-t{ font-size:14px; font-weight:800; color:var(--tyw-text); }
.tyw-card-cta-s{ font-size:12px; color:#94a3b8; margin-top:1px; }
.tyw-card-cta-arrow{ margin-inline-start:auto; color:#cbd5e1; }

.tyw-faq-title{ font-size:12.5px; font-weight:700; color:#94a3b8; margin:6px 18px 8px; }
.tyw-faq-item{ border-bottom:1px solid #f1f5f9; }
.tyw-faq-item:last-child{ border-bottom:none; }
.tyw-faq-q{
  width:100%; text-align:right; background:none; border:none; cursor:pointer;
  padding:12px 4px; font-size:13.5px; font-weight:700; color:var(--tyw-text);
  display:flex; align-items:center; gap:8px; font-family:inherit;
}
.tyw-faq-q .tyw-chev{ margin-inline-start:auto; transition:transform .25s; color:#94a3b8; flex-shrink:0; }
.tyw-faq-item.open .tyw-chev{ transform:rotate(180deg); }
.tyw-faq-a{ max-height:0; overflow:hidden; transition:max-height .3s ease; }
.tyw-faq-a-inner{ padding:0 4px 13px; font-size:13px; color:#475569; line-height:1.9; }

.tyw-form{ padding:20px 18px; overflow-y:auto; }
.tyw-form-lead{ font-size:13.5px; color:var(--tyw-text); font-weight:600; margin:0 0 16px; }
.tyw-field{ margin-bottom:14px; }
.tyw-field label{ display:block; font-size:12.5px; font-weight:700; color:#475569; margin-bottom:6px; }
.tyw-field label .tyw-req{ color:#ef4444; }
.tyw-field input, .tyw-field select, .tyw-field textarea{
  width:100%; padding:11px 14px; border:1.5px solid #e2e8f0; border-radius:12px;
  font-size:13.5px; font-family:inherit; outline:none; background:#fff; color:var(--tyw-text);
  direction:rtl; transition:border-color .15s, box-shadow .15s;
}
.tyw-field input:focus, .tyw-field select:focus, .tyw-field textarea:focus{
  border-color:var(--tyw-primary); box-shadow:0 0 0 3px color-mix(in srgb, var(--tyw-primary) 16%, transparent);
}
.tyw-field .tyw-err{ font-size:11.5px; color:#ef4444; margin-top:4px; display:none; }
.tyw-field.has-err input, .tyw-field.has-err select{ border-color:#ef4444; }
.tyw-field.has-err .tyw-err{ display:block; }

.tyw-cf-radio{ display:flex; flex-direction:column; gap:6px; }
.tyw-opt{ display:flex; align-items:center; gap:8px; font-size:13px; font-weight:500; color:var(--tyw-text); cursor:pointer; padding:7px 12px; border:1.5px solid #e2e8f0; border-radius:10px; transition:.15s; }
.tyw-opt:hover{ border-color:var(--tyw-primary); }
.tyw-opt input{ width:16px; height:16px; accent-color:var(--tyw-primary); margin:0; }
.tyw-field.tyw-cf .tyw-err{ font-size:11.5px; color:#ef4444; margin-top:4px; display:none; }
.tyw-field.tyw-cf.has-err .tyw-err{ display:block; }
.tyw-field.tyw-cf.has-err input, .tyw-field.tyw-cf.has-err select, .tyw-field.tyw-cf.has-err textarea, .tyw-field.tyw-cf.has-err .tyw-opt{ border-color:#ef4444; }

.tyw-cta-btn{
  width:100%; padding:13px; border:none; border-radius:13px; cursor:pointer;
  background:linear-gradient(135deg,var(--tyw-btn1),var(--tyw-btn2)); color:#fff;
  font-size:14.5px; font-weight:800; font-family:inherit; transition:.18s;
  display:flex; align-items:center; justify-content:center; gap:8px;
  box-shadow:0 10px 24px -10px color-mix(in srgb, var(--tyw-btn1) 70%, black 0%);
}
.tyw-cta-btn:hover:not(:disabled){ filter:brightness(1.06); transform:translateY(-1px); }
.tyw-cta-btn:disabled{ opacity:.6; cursor:not-allowed; }

.tyw-chat{ flex:1; min-height:0; display:flex; flex-direction:column; }
.tyw-msgs{
  flex:1; min-height:0; overflow-y:auto; padding:16px 14px 8px;
  display:flex; flex-direction:column; gap:3px;
  background-image:var(--tyw-chat-image);
  background-size:cover; background-position:center;
}
.tyw-msgs::-webkit-scrollbar, .tyw-home::-webkit-scrollbar, .tyw-form::-webkit-scrollbar{ width:6px; }
.tyw-msgs::-webkit-scrollbar-thumb{ background:rgba(100,116,139,.3); border-radius:3px; }

.tyw-day{ text-align:center; margin:8px 0; }
.tyw-day span{ background:rgba(15,23,42,.55); color:#fff; font-size:11px; padding:3px 12px; border-radius:20px; }

.tyw-m{ display:flex; align-items:flex-end; gap:7px; max-width:85%; }
.tyw-m.out{ align-self:flex-end; flex-direction:row-reverse; }     /* پیام من (کاربر) → چپ */
.tyw-m.in { align-self:flex-start; }                               /* پیام کارشناس → راست */
.tyw-m.sys{ align-self:center; max-width:92%; }
.tyw-m-ava{ width:28px; height:28px; border-radius:50%; object-fit:cover; flex-shrink:0; margin-bottom:2px; }
.tyw-m.out .tyw-m-ava{ display:none; }

.tyw-bubble{
  padding:9px 13px; border-radius:16px; font-size:13.5px; line-height:1.75;
  word-break:break-word; position:relative; box-shadow:0 1px 2px rgba(0,0,0,.06);
}
.tyw-m.in .tyw-bubble{
  background:var(--tyw-agent-bubble); color:var(--tyw-agent-bubble-text);
  border-bottom-left-radius:5px;
}
.tyw-m.out .tyw-bubble{
  background:var(--tyw-user-bubble); color:var(--tyw-user-bubble-text);
  border-bottom-right-radius:5px;
}
.tyw-m.sys .tyw-bubble{
  background:rgba(15,23,42,.07); color:#475569; font-size:12px; text-align:center;
  border-radius:12px; box-shadow:none;
}
.tyw-bubble img.tyw-img{ max-width:200px; border-radius:10px; display:block; cursor:pointer; }
.tyw-bubble audio{ max-width:210px; height:38px; }
.tyw-bubble video{ max-width:210px; border-radius:10px; }
.tyw-sticker-only{ background:transparent !important; box-shadow:none !important; font-size:46px; padding:0 !important; }
.tyw-file{ display:flex; align-items:center; gap:9px; min-width:170px; }
.tyw-file a{ color:inherit; text-decoration:underline; font-size:12px; margin-inline-start:auto; }

.tyw-meta{ font-size:10.5px; opacity:.65; margin:2px 4px 6px; display:flex; align-items:center; gap:4px; }
.tyw-m.out .tyw-meta{ flex-direction:row-reverse; align-self:flex-end; }
.tyw-m.in  .tyw-meta{ align-self:flex-start; }
.tyw-tick{ font-size:12px; }
.tyw-tick.read{ color:#38bdf8; }
.tyw-tick.sent{ opacity:.8; }
.tyw-tick.sending{ opacity:.6; }

.tyw-typing{ align-self:flex-end; display:flex; align-items:center; gap:7px; padding:2px 6px 8px; }
.tyw-typing .tyw-m-ava{ width:24px; height:24px; }
.tyw-typing-dots{ background:var(--tyw-agent-bubble); padding:10px 14px; border-radius:16px; display:flex; gap:4px; box-shadow:0 1px 2px rgba(0,0,0,.06); }
.tyw-typing-dots i{ width:7px; height:7px; border-radius:50%; background:#94a3b8; animation:tyw-bounce 1.3s infinite; }
.tyw-typing-dots i:nth-child(2){ animation-delay:.18s; }
.tyw-typing-dots i:nth-child(3){ animation-delay:.36s; }
@keyframes tyw-bounce{ 0%,60%,100%{transform:translateY(0);opacity:.5} 30%{transform:translateY(-5px);opacity:1} }

.tyw-waiting{
  margin:4px 14px 8px; padding:9px 14px; border-radius:12px;
  background:#fffbeb; color:#92400e; font-size:12px; font-weight:600;
  display:flex; align-items:center; gap:8px;
}

.tyw-input{ border-top:1px solid #eef2f7; background:#fff; padding:8px 10px; flex-shrink:0; }
.tyw-reply{ display:none; background:#f1f5f9; border-inline-start:3px solid var(--tyw-primary);
  border-radius:8px; padding:6px 10px; margin-bottom:7px; font-size:12px; position:relative; }
.tyw-reply b{ color:var(--tyw-primary); }
.tyw-reply .tyw-reply-x{ position:absolute; inset-inline-start:8px; top:6px; border:none; background:none; cursor:pointer; color:#94a3b8; font-size:14px; }
.tyw-input-row{ display:flex; align-items:flex-end; gap:6px; }
.tyw-tool{
  width:36px; height:36px; border:none; background:none; cursor:pointer; border-radius:10px;
  font-size:19px; color:#64748b; display:flex; align-items:center; justify-content:center; transition:.15s; flex-shrink:0;
}
.tyw-tool:hover{ background:#f1f5f9; color:var(--tyw-primary); }
.tyw-tool svg{ width:20px; height:20px; }
.tyw-ta{
  flex:1; resize:none; border:1.5px solid #e2e8f0; border-radius:18px;
  padding:9px 14px; font-size:13.5px; font-family:inherit; outline:none; max-height:96px;
  line-height:1.6; color:var(--tyw-text); background:#fff; transition:border-color .15s;
}
.tyw-ta:focus{ border-color:var(--tyw-primary); }
.tyw-send{
  width:40px; height:40px; border-radius:50%; border:none; cursor:pointer; flex-shrink:0;
  background:linear-gradient(135deg,var(--tyw-btn1),var(--tyw-btn2)); color:#fff;
  display:flex; align-items:center; justify-content:center; transition:.15s;
}
.tyw-send:hover{ filter:brightness(1.07); transform:scale(1.05); }
.tyw-send svg{ width:19px; height:19px; }

.tyw-emoji-pop{
  display:none; background:#fff; border:1px solid #eef2f7; border-radius:14px;
  padding:8px; margin-bottom:7px; grid-template-columns:repeat(8,1fr); gap:2px;
  box-shadow:0 -6px 18px -8px rgba(0,0,0,.18); max-height:140px; overflow-y:auto;
}
.tyw-emoji-pop.show{ display:grid; }
.tyw-emoji-pop button{ border:none; background:none; cursor:pointer; font-size:20px; padding:5px; border-radius:8px; }
.tyw-emoji-pop button:hover{ background:#f1f5f9; }

.tyw-rec{ display:flex; align-items:center; gap:10px; width:100%; padding:2px 4px; }
.tyw-rec-dot{ width:11px; height:11px; border-radius:50%; background:#ef4444; animation:tyw-blink 1s infinite; }
@keyframes tyw-blink{ 50%{opacity:.25} }
.tyw-rec-time{ font-size:13px; font-weight:700; color:#ef4444; min-width:42px; }
.tyw-rec-wave{ flex:1; display:flex; align-items:center; gap:2px; height:24px; }
.tyw-rec-wave i{ flex:1; background:var(--tyw-primary); border-radius:2px; opacity:.5; animation:tyw-wave 1s infinite ease-in-out; height:30%; }
@keyframes tyw-wave{ 50%{height:100%;opacity:1} }
.tyw-rec-btn{ width:36px; height:36px; border-radius:50%; border:none; cursor:pointer; color:#fff; display:flex; align-items:center; justify-content:center; flex-shrink:0; }
.tyw-rec-cancel{ background:#94a3b8; }
.tyw-rec-ok{ background:linear-gradient(135deg,var(--tyw-btn1),var(--tyw-btn2)); }
.tyw-rec-btn svg{ width:18px; height:18px; }

.tyw-foot{ text-align:center; font-size:11px; color:#cbd5e1; padding:5px 0 8px; flex-shrink:0; background:#fff; }
.tyw-foot a{ color:#94a3b8; text-decoration:none; font-weight:600; }

.tyw-loading{ flex:1; display:flex; flex-direction:column; align-items:center; justify-content:center; gap:12px; color:#94a3b8; font-size:13px; }
.tyw-spin{ width:34px; height:34px; border:3px solid #e2e8f0; border-top-color:var(--tyw-primary); border-radius:50%; animation:tyw-rot .8s linear infinite; }
@keyframes tyw-rot{ to{ transform:rotate(360deg); } }

@media (max-width:480px){
  #tyw-root{ bottom:16px; }
  #tyw-root.tyw-pos-right{ right:16px; }
  #tyw-root.tyw-pos-left{ left:16px; }
  .tyw-panel{
    width:calc(100vw - 24px); height:min(78vh, calc(100vh - 96px));
    bottom:calc(var(--tyw-size) + 12px);
  }
}
@media (prefers-reduced-motion:reduce){
  .tyw-launcher::after{ animation:none; }
  #tyw-root *{ transition:none !important; animation-duration:.001s !important; }
}

.tyw-bubble.tyw-bubble-product{background:transparent!important;border:none!important;box-shadow:none!important;padding:0!important;max-width:260px}
.tyw-product-card{width:240px;max-width:75vw;background:var(--tyw-panel,#fff);border:1px solid rgba(0,0,0,.08);border-radius:15px;overflow:hidden;box-shadow:0 6px 20px rgba(0,0,0,.12)}
.tyw-prod-img{width:100%;aspect-ratio:16/10;background:#f1f5f9;overflow:hidden;display:block}
.tyw-prod-img img{width:100%;height:100%;object-fit:cover;display:block}
.tyw-prod-body{padding:10px 12px 12px}
.tyw-prod-title{font-weight:800;font-size:13.5px;color:var(--tyw-text,#1e293b);line-height:1.5;display:-webkit-box;-webkit-line-clamp:2;-webkit-box-orient:vertical;overflow:hidden}
.tyw-prod-exc{margin:5px 0 0;font-size:11.5px;line-height:1.7;color:#94a3b8;display:-webkit-box;-webkit-line-clamp:2;-webkit-box-orient:vertical;overflow:hidden}
.tyw-prod-foot{display:flex;align-items:center;justify-content:space-between;gap:8px;margin-top:10px;flex-wrap:wrap}
.tyw-prod-price{font-weight:800;font-size:14px;color:var(--tyw-primary,#4f46e5);white-space:nowrap}
.tyw-prod-price del{color:#94a3b8;font-weight:600;font-size:11px;margin-left:3px}
.tyw-prod-price ins{text-decoration:none}
.tyw-prod-btn{flex-shrink:0;text-decoration:none;font-weight:800;font-size:12px;color:#fff;white-space:nowrap;padding:7px 14px;border-radius:9px;background:linear-gradient(135deg,var(--tyw-grad1,#4f46e5),var(--tyw-grad2,#7c3aed));box-shadow:0 4px 12px rgba(0,0,0,.15)}
.tyw-prod-btn:hover{color:#fff;opacity:.95}