/* ============ Lanaland AI Chat Widget ============ */
#lnl-chat-root {
  --lnl-accent: #1d4ed8;
  --lnl-size: 62px;
  --lnl-offx: 22px;
  --lnl-offy: 22px;
  --lnl-side: right;
  --lnl-radius: 18px;
  --lnl-bg: #ffffff;
  --lnl-user: #1d4ed8;
  --lnl-bot: #f1f5f9;
  --lnl-text: #0f172a;
  direction: rtl;
}

/* از فونت پیش‌فرض سایت استفاده می‌شود (ارث‌بری از body) */
#lnl-chat-root,
#lnl-chat-root * {
  box-sizing: border-box;
  font-family: inherit;
}

/* دکمه شناور — موقعیت فیزیکی راست/چپ مستقل از جهت سایت */
.lnl-launcher {
  position: fixed;
  bottom: var(--lnl-offy);
  right: auto;
  left: auto;
  width: var(--lnl-size);
  height: var(--lnl-size);
  border-radius: 50%;
  background: var(--lnl-accent);
  color: #fff;
  border: none;
  cursor: pointer;
  box-shadow: 0 8px 24px rgba(0,0,0,.18);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 999998;
  transition: transform .15s ease, box-shadow .15s ease;
}
#lnl-chat-root[data-side="right"] .lnl-launcher { right: var(--lnl-offx); }
#lnl-chat-root[data-side="left"]  .lnl-launcher { left:  var(--lnl-offx); }
.lnl-launcher:hover { transform: scale(1.06); box-shadow: 0 10px 28px rgba(0,0,0,.24); }
.lnl-launcher svg { width: 52%; height: 52%; }

.lnl-launcher-label {
  position: fixed;
  bottom: calc(var(--lnl-offy) + (var(--lnl-size) / 2) - 16px);
  background: #fff;
  color: var(--lnl-text);
  padding: 7px 13px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  box-shadow: 0 4px 14px rgba(0,0,0,.12);
  white-space: nowrap;
  z-index: 999998;
  animation: lnl-fade 0.3s ease;
}
#lnl-chat-root[data-side="right"] .lnl-launcher-label { right: calc(var(--lnl-offx) + var(--lnl-size) + 10px); }
#lnl-chat-root[data-side="left"]  .lnl-launcher-label { left:  calc(var(--lnl-offx) + var(--lnl-size) + 10px); }

/* پنجره چت */
.lnl-window {
  position: fixed;
  bottom: calc(var(--lnl-offy) + var(--lnl-size) + 14px);
  width: 380px;
  max-width: calc(100vw - 28px);
  height: 560px;
  max-height: calc(100vh - 110px);
  background: var(--lnl-bg);
  border-radius: var(--lnl-radius);
  box-shadow: 0 18px 50px rgba(0,0,0,.26);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: 999999;
  animation: lnl-pop .18s ease;
}
#lnl-chat-root[data-side="right"] .lnl-window { right: var(--lnl-offx); }
#lnl-chat-root[data-side="left"]  .lnl-window { left:  var(--lnl-offx); }
@keyframes lnl-pop { from { opacity: 0; transform: translateY(14px) scale(.98); } to { opacity: 1; transform: none; } }
@keyframes lnl-fade { from { opacity: 0; } to { opacity: 1; } }

.lnl-header {
  background: var(--lnl-accent);
  color: #fff;
  padding: 14px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.lnl-header .lnl-title { font-weight: 700; font-size: 15px; }
.lnl-header .lnl-sub { font-size: 11px; opacity: .85; margin-top: 2px; }
.lnl-header-actions { display: flex; gap: 4px; }
.lnl-iconbtn {
  background: rgba(255,255,255,.16);
  border: none; color: #fff; cursor: pointer;
  width: 30px; height: 30px; border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
}
.lnl-iconbtn:hover { background: rgba(255,255,255,.28); }
.lnl-iconbtn svg { width: 16px; height: 16px; }

/* بدنه پیام‌ها */
.lnl-body {
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding: 14px;
  background: #fafbfc;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.lnl-msg { max-width: 84%; padding: 9px 13px; border-radius: 14px; font-size: 14px; line-height: 1.9; white-space: pre-wrap; word-break: break-word; }
.lnl-msg.bot { background: var(--lnl-bot); color: var(--lnl-text); align-self: flex-start; border-bottom-right-radius: 4px; }
.lnl-msg.user { background: var(--lnl-user); color: #fff; align-self: flex-end; border-bottom-left-radius: 4px; }
.lnl-msg a { color: inherit; text-decoration: underline; font-weight: 600; }
.lnl-msg.bot a { color: var(--lnl-accent); }

.lnl-typing { display: flex; gap: 4px; padding: 12px 14px; align-self: flex-start; }
.lnl-typing span { width: 7px; height: 7px; border-radius: 50%; background: #94a3b8; animation: lnl-bounce 1.2s infinite; }
.lnl-typing span:nth-child(2) { animation-delay: .2s; }
.lnl-typing span:nth-child(3) { animation-delay: .4s; }
@keyframes lnl-bounce { 0%, 60%, 100% { transform: translateY(0); opacity: .5; } 30% { transform: translateY(-6px); opacity: 1; } }

/* دکمه‌های سریع (نمایندگی و ...) */
.lnl-quick { display: flex; flex-wrap: wrap; gap: 6px; padding: 0 14px 8px; }
.lnl-quick button {
  background: #fff; border: 1.5px solid var(--lnl-accent); color: var(--lnl-accent);
  border-radius: 999px; padding: 6px 13px; font-size: 12.5px; font-weight: 600; cursor: pointer;
  transition: background .12s, color .12s; font-family: inherit;
}
.lnl-quick button:hover { background: var(--lnl-accent); color: #fff; }

/* ناحیه ورودی */
.lnl-input {
  border-top: 1px solid #e5e7eb;
  padding: 10px;
  display: flex;
  align-items: flex-end;
  gap: 8px;
  background: #fff;
}
.lnl-input textarea {
  flex: 1; resize: none; border: 1px solid #e5e7eb; border-radius: 12px;
  padding: 9px 12px; font-size: 14px; max-height: 96px; line-height: 1.6;
  outline: none; font-family: inherit;
}
.lnl-input textarea:focus { border-color: var(--lnl-accent); }
.lnl-send, .lnl-attach {
  border: none; cursor: pointer; border-radius: 10px;
  width: 40px; height: 40px; display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.lnl-send { background: var(--lnl-accent); color: #fff; }
.lnl-send:disabled { opacity: .5; cursor: default; }
.lnl-attach { background: #f1f5f9; color: #475569; }
.lnl-send svg, .lnl-attach svg { width: 19px; height: 19px; }

/* فرم نمایندگی (overlay داخل پنجره) */
.lnl-form-overlay {
  position: absolute; inset: 0; background: #fff; z-index: 5;
  display: flex; flex-direction: column; animation: lnl-fade .2s ease;
}
.lnl-form-overlay .lnl-header { flex-shrink: 0; }
.lnl-form-body { flex: 1; overflow-y: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; padding: 16px; display: flex; flex-direction: column; gap: 11px; }
.lnl-field label { display: block; font-size: 12.5px; font-weight: 600; margin-bottom: 4px; color: #334155; }
.lnl-field input, .lnl-field textarea {
  width: 100%; border: 1px solid #d1d5db; border-radius: 10px; padding: 9px 11px; font-size: 13.5px;
  outline: none; font-family: inherit;
}
.lnl-field input:focus, .lnl-field textarea:focus { border-color: var(--lnl-accent); }
.lnl-field .req { color: #dc2626; }
.lnl-form-submit {
  background: var(--lnl-accent); color: #fff; border: none; border-radius: 11px;
  padding: 12px; font-size: 14px; font-weight: 700; cursor: pointer; margin-top: 4px; font-family: inherit;
}
.lnl-form-submit:disabled { opacity: .6; cursor: default; }
.lnl-form-note { font-size: 11.5px; color: #64748b; line-height: 1.7; }
.lnl-form-success { text-align: center; padding: 30px 18px; color: #16a34a; font-weight: 600; font-size: 14.5px; line-height: 1.9; }

.lnl-consent { font-size: 11px; color: #64748b; padding: 0 14px 8px; line-height: 1.7; }
.lnl-attach-preview { font-size: 11.5px; color: #475569; padding: 0 14px 6px; }

@media (max-width: 480px) {
  .lnl-window {
    width: 100vw; max-width: 100vw; height: 100dvh; max-height: 100dvh;
    bottom: 0; right: 0; left: 0; border-radius: 0;
  }
}

/* ============ منوی شروع دو سطحی ============ */
#lnl-chat-root .lnl-menu {
  margin: 6px 0 10px;
  background: #fafafa;
  border: 1px solid #ececec;
  border-radius: 14px;
  padding: 10px;
}
#lnl-chat-root .lnl-menu-title {
  font-size: 13px;
  color: #555;
  margin-bottom: 8px;
  line-height: 1.6;
}
#lnl-chat-root .lnl-menu-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
#lnl-chat-root .lnl-menu-btn,
#lnl-chat-root .lnl-menu-back {
  text-align: right;
  background: #fff;
  border: 1px solid #e3e3e3;
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 13.5px;
  color: var(--lnl-text);
  cursor: pointer;
  transition: all .15s;
}
#lnl-chat-root .lnl-menu-btn:hover {
  border-color: var(--lnl-accent);
  background: color-mix(in srgb, var(--lnl-accent) 7%, #fff);
}
#lnl-chat-root .lnl-menu-back {
  background: transparent;
  border-style: dashed;
  color: #777;
  font-size: 12.5px;
}
/* پاسخ متنی داخل باکس منو (با امکان بازگشت) */
#lnl-chat-root .lnl-menu-answer {
  background: #fff;
  border: 1px solid #ececec;
  border-radius: 10px;
  padding: 11px 12px;
  font-size: 13.5px;
  line-height: 1.95;
  color: var(--lnl-text);
  white-space: pre-wrap;
  word-break: break-word;
}
#lnl-chat-root .lnl-menu-answer a { color: var(--lnl-accent); font-weight: 600; }

/* دکمه دسترسی به منو/سوالات متداول در ناحیه ورودی */
#lnl-chat-root .lnl-menu-toggle {
  border: none; cursor: pointer; border-radius: 10px;
  width: 40px; height: 40px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  background: #f1f5f9; color: var(--lnl-accent);
}
#lnl-chat-root .lnl-menu-toggle:hover { background: #e7edf5; }
#lnl-chat-root .lnl-menu-toggle svg { width: 20px; height: 20px; }

/* حالت نمایش متنی محصولات: عنوان لینک‌دار (بدون آدرس خام) */
#lnl-chat-root .lnl-ptext {
  margin: 6px 0 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  align-self: flex-start;
  max-width: 84%;
}
#lnl-chat-root .lnl-ptext-row {
  background: var(--lnl-bot);
  border-radius: 10px;
  padding: 8px 11px;
  font-size: 13.5px;
  line-height: 1.7;
}
#lnl-chat-root a.lnl-ptext-link {
  color: var(--lnl-accent);
  font-weight: 700;
  text-decoration: none;
}
#lnl-chat-root a.lnl-ptext-link:hover { text-decoration: underline; }
#lnl-chat-root .lnl-ptext-price { color: #475569; font-size: 12.5px; }

/* ============ کارت‌های محصول / کاروسل ============ */
#lnl-chat-root .lnl-products {
  margin: 8px 0 12px;
}
#lnl-chat-root .lnl-products.carousel {
  display: flex;
  gap: 10px;
  overflow-x: auto;
  padding-bottom: 6px;
  scroll-snap-type: x mandatory;
  -webkit-overflow-scrolling: touch;
}
#lnl-chat-root .lnl-products.carousel::-webkit-scrollbar { height: 6px; }
#lnl-chat-root .lnl-products.carousel::-webkit-scrollbar-thumb { background: #ddd; border-radius: 3px; }
#lnl-chat-root .lnl-products.list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
#lnl-chat-root .lnl-pcard {
  background: #fff;
  border: 1px solid #ececec;
  border-radius: 14px;
  overflow: hidden;
  box-shadow: 0 2px 8px rgba(0,0,0,.04);
  display: flex;
  flex-direction: column;
}
#lnl-chat-root .lnl-products.carousel .lnl-pcard {
  min-width: 165px;
  max-width: 165px;
  scroll-snap-align: start;
}
#lnl-chat-root .lnl-products.list .lnl-pcard {
  flex-direction: row;
}
#lnl-chat-root .lnl-pimg {
  width: 100%;
  height: 120px;
  background: #f5f5f5;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 32px;
  overflow: hidden;
}
#lnl-chat-root .lnl-products.list .lnl-pimg {
  width: 96px;
  min-width: 96px;
  height: auto;
}
#lnl-chat-root .lnl-pimg img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
#lnl-chat-root .lnl-pbody {
  padding: 9px 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex: 1;
}
#lnl-chat-root a.lnl-pname {
  font-size: 13px;
  font-weight: 600;
  color: var(--lnl-text);
  text-decoration: none;
  line-height: 1.5;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
#lnl-chat-root a.lnl-pname:hover { color: var(--lnl-accent); }
#lnl-chat-root .lnl-pmeta {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}
#lnl-chat-root .lnl-pprice {
  font-size: 12.5px;
  font-weight: 700;
  color: var(--lnl-accent);
}
#lnl-chat-root .lnl-pout {
  font-size: 11px;
  color: #c0392b;
  background: #fdecea;
  border-radius: 6px;
  padding: 1px 6px;
}
#lnl-chat-root a.lnl-pbtn {
  margin-top: auto;
  text-align: center;
  background: var(--lnl-accent);
  color: #fff;
  text-decoration: none;
  font-size: 12.5px;
  padding: 7px 8px;
  border-radius: 9px;
  transition: opacity .15s;
}
#lnl-chat-root a.lnl-pbtn:hover { opacity: .9; }

/* ============ تماس سریع شناور (بالای دکمه‌ی اصلی، هم‌مرکز) ============ */
#lnl-chat-root .lnl-qc {
  position: fixed;
  bottom: calc(var(--lnl-offy) + var(--lnl-size) + 16px);
  z-index: 99998;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}
/* وسط‌چین نسبت به مرکز دکمه‌ی اصلی: لبه‌ی دکمه‌ی اصلی + نصف اختلاف عرض */
#lnl-chat-root .lnl-qc[data-side="right"] { right: calc(var(--lnl-offx) + (var(--lnl-size) - 46px) / 2); }
#lnl-chat-root .lnl-qc[data-side="left"]  { left:  calc(var(--lnl-offx) + (var(--lnl-size) - 46px) / 2); }
#lnl-chat-root .lnl-qc-btn {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  box-shadow: 0 3px 10px rgba(0,0,0,.18);
  transition: transform .15s;
}
#lnl-chat-root .lnl-qc-btn:hover { transform: scale(1.08); }
#lnl-chat-root .lnl-qc-btn.wa  { background: #25d366; }
#lnl-chat-root .lnl-qc-btn.tel { background: var(--lnl-accent); }

@media (max-width: 780px) {
  #lnl-chat-root .lnl-products.carousel .lnl-pcard { min-width: 150px; max-width: 150px; }
  #lnl-chat-root .lnl-qc-btn { width: 42px; height: 42px; }
  #lnl-chat-root .lnl-qc[data-side="right"] { right: calc(var(--lnl-offx) + (var(--lnl-size) - 42px) / 2); }
  #lnl-chat-root .lnl-qc[data-side="left"]  { left:  calc(var(--lnl-offx) + (var(--lnl-size) - 42px) / 2); }
}
