/* مساعد الحاكورة — بنفس لغة الموقع: كريمي وأخضر غامق متل القائمة، خطوط رفيعة بدل الظلال، والاقتراحات مرقّمة (01، 02...)
   متل روابط القائمة. الصندوق data-theme="light" (من chat.js) فالألوان من متغيرات النظام: --bg --fg --surface --border */
.chat-trigger {
  position: fixed;
  inset-block-end: clamp(16px, 3vw, 24px);
  inset-inline-end: clamp(16px, 3vw, 24px);
  z-index: 75;
  box-shadow: 0 8px 24px rgb(0 33 30 / .28);
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

/* ---------- الصندوق ---------- */
.chat-window {
  --chat-ease: cubic-bezier(.475, .425, 0, .995); /* نفس منحنى القائمة */
  position: fixed;
  inset-block-end: calc(clamp(16px, 3vw, 24px) + 64px);
  inset-inline-end: clamp(16px, 3vw, 24px);
  z-index: 75;
  inline-size: min(400px, calc(100vw - 32px));
  block-size: min(600px, calc(100svh - 120px));
  display: flex; flex-direction: column;
  overflow: hidden; isolation: isolate;
  background: var(--bg); color: var(--fg);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: 0 24px 60px rgb(0 33 30 / .3);
  opacity: 0; transform: translateY(16px); visibility: hidden; /* مسكّر: ولا الكيبورد بيوصل لجوّاه */
  pointer-events: none;
  transition: opacity .35s ease, transform .6s var(--chat-ease), visibility 0s linear .6s;
}
.chat-window.is-open { opacity: 1; transform: none; visibility: visible; pointer-events: auto; transition: opacity .35s ease, transform .6s var(--chat-ease), visibility 0s; }
/* الموتيف الباهت بالزاوية، متل خلفية القائمة */
.chat-window::before {
  content: ""; position: absolute; z-index: -1; inset-block-end: -60px; inset-inline-start: -70px;
  inline-size: 300px; aspect-ratio: 1;
  background-color: var(--fg); opacity: .05;
  -webkit-mask: var(--motif-leaf-corner) center / contain no-repeat;
  mask: var(--motif-leaf-corner) center / contain no-repeat;
  pointer-events: none;
}

/* ---------- الترويسة ---------- */
.chat-head {
  display: flex; align-items: center; gap: var(--space-3);
  padding: var(--space-4) var(--space-4) var(--space-4) var(--space-3);
  padding-inline-start: var(--space-5);
  border-block-end: 1px solid var(--border);
}
/* شعار الحاكورة الذهبي بدائرة خضرا (الخط الرفيع تبع الأخضر بيضيع بهالحجم) */
.chat-head__mark { flex: none; display: grid; place-items: center; inline-size: 42px; block-size: 42px; border-radius: 50%; background: var(--fg); }
.chat-head__mark img { inline-size: 26px; block-size: auto; }
.chat-head__text { flex: 1; min-inline-size: 0; }
.chat-head__title { margin: 0; font-size: var(--size-lg); font-weight: var(--weight-bold); line-height: 1.3; }
.chat-head__status { margin: 0; font-size: var(--size-xs); color: var(--fg-muted); }
/* زر الإغلاق: دائرة خضرا متل زر القائمة وهي مفتوحة */
.chat-head__close {
  flex: none; display: grid; place-items: center;
  inline-size: 40px; block-size: 40px; border: 0; border-radius: var(--radius-full);
  background: var(--fg); color: var(--bg); font-size: 18px; cursor: pointer;
  transition: transform .45s var(--chat-ease);
}
.chat-head__close:hover { transform: rotate(90deg); }
.chat-head__close:focus-visible { outline: 2px solid var(--fg); outline-offset: 3px; }

/* ---------- الرسائل ---------- */
.chat-body {
  flex: 1; overflow-y: auto; overscroll-behavior: contain;
  display: flex; flex-direction: column; gap: var(--space-4);
  padding: var(--space-5);
  scrollbar-width: thin; scrollbar-color: color-mix(in srgb, var(--fg) 25%, transparent) transparent;
}
.chat-msg { display: flex; flex-direction: column; gap: var(--space-2); max-inline-size: 88%; animation: chat-in .5s var(--chat-ease) backwards; }
@keyframes chat-in { from { opacity: 0; transform: translateY(10px); } }
.chat-msg--bot { align-self: flex-start; }
.chat-msg--user { align-self: flex-end; }
.chat-bubble { padding: 10px 14px; border-radius: var(--radius-md); font-size: var(--size-sm); line-height: 1.75; overflow-wrap: anywhere; }
.chat-msg--bot .chat-bubble { background: var(--surface); border: 1px solid var(--border); border-start-start-radius: var(--radius-sm); }
.chat-msg--user .chat-bubble { background: var(--fg); color: var(--bg); border-start-end-radius: var(--radius-sm); }
.chat-bubble strong { font-weight: var(--weight-bold); }

/* الترحيب: بدون فقاعة، السطر الأول عنوان كبير والباقي نص هادي */
.chat-msg--hello { max-inline-size: none; align-self: stretch; gap: var(--space-4); }
.chat-msg--hello .chat-bubble { padding: 0; background: none; border: 0; color: var(--fg-muted); font-size: var(--size-sm); }
.chat-msg--hello .chat-bubble::first-line { color: var(--fg); font-size: var(--size-xl); font-weight: var(--weight-bold); line-height: 1.9; }

/* الاقتراحات الأولى: قائمة مرقّمة بخطوط رفيعة؛ المؤشر بيطلّع السهم وبيزيح النص (متل القائمة) */
.chat-starters { margin: 0; padding: 0; list-style: none; border-block-start: 1px solid var(--border); }
.chat-starters li { border-block-end: 1px solid var(--border); animation: chat-in .6s var(--chat-ease) backwards; animation-delay: calc(.15s + var(--i, 0) * 60ms); }
.chat-starters .chat-chip {
  display: flex; align-items: center; gap: var(--space-3); inline-size: 100%;
  padding: var(--space-3) var(--space-1); border: 0; background: none; color: var(--fg);
  font: inherit; font-size: var(--size-base); font-weight: var(--weight-semibold); text-align: start; cursor: pointer;
}
.chat-chip__num { inline-size: 2ch; font-size: var(--size-xs); color: var(--fg-muted); font-variant-numeric: tabular-nums; }
.chat-chip__text { flex: 1; transition: transform .5s var(--chat-ease); }
.chat-starters .chat-chip i { font-size: 18px; opacity: 0; transform: translateX(8px); transition: opacity .3s ease, transform .5s var(--chat-ease); }
.chat-starters .chat-chip:is(:hover, :focus-visible) .chat-chip__text { transform: translateX(-6px); }
.chat-starters .chat-chip:is(:hover, :focus-visible) i { opacity: 1; transform: none; }
.chat-starters .chat-chip:focus-visible { outline: 2px solid var(--fg); outline-offset: -2px; border-radius: var(--radius-sm); }

/* الاقتراحات بعد الرد: حبوب بإطار رفيع، بتتعبّى بالأخضر مع المؤشر */
.chat-suggestions { display: flex; flex-wrap: wrap; gap: var(--space-2); }
.chat-suggestions .chat-chip {
  padding: 6px 14px; border: 1.5px solid color-mix(in srgb, var(--fg) 22%, transparent); border-radius: var(--radius-full);
  background: none; color: var(--fg); font: inherit; font-size: var(--size-xs); font-weight: var(--weight-semibold); cursor: pointer;
  transition: background-color .2s ease, color .2s ease, border-color .2s ease;
}
.chat-suggestions .chat-chip:hover, .chat-suggestions .chat-chip:focus-visible { background: var(--fg); border-color: var(--fg); color: var(--bg); }

/* روابط داخل الرد (الكتالوج، واتساب، السوشيال): زر صغير بإطار متل .btn--secondary؛ الواتساب معبّى */
.chat-link-btn {
  display: inline-flex; align-items: center; gap: 6px;
  margin-block: 3px; padding: 5px 14px;
  border: 1.5px solid var(--fg); border-radius: var(--radius-full);
  color: var(--fg); font-size: var(--size-xs); font-weight: var(--weight-semibold); text-decoration: none;
  transition: background-color .2s ease, color .2s ease;
}
.chat-link-btn i { font-size: 15px; }
.chat-link-btn:hover, .chat-link-btn:focus-visible { background: var(--fg); color: var(--bg); }
.chat-link-btn[href*="wa.me"] { background: var(--success); border-color: var(--success); color: var(--bg); }
.chat-link-btn[href*="wa.me"]:hover { background: var(--fg); border-color: var(--fg); }

/* بطاقات المنتجات داخل الرد */
.chat-products { display: grid; gap: var(--space-2); }
.chat-product-card {
  display: flex; align-items: center; gap: var(--space-3);
  padding: var(--space-2); padding-inline-end: var(--space-3);
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-md);
}
.chat-product-card img { inline-size: 56px; block-size: 56px; flex: none; object-fit: cover; border-radius: var(--radius-sm); background: var(--color-green-950); }
.chat-product-card__info { flex: 1; min-inline-size: 0; }
.chat-product-card__name { margin: 0; font-size: var(--size-sm); font-weight: var(--weight-bold); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-product-card__meta { margin: 2px 0 0; font-size: var(--size-xs); color: var(--fg-muted); }
.chat-product-card__price { font-weight: var(--weight-bold); color: var(--fg); }
.chat-product-card__action {
  flex: none; display: inline-flex; align-items: center; gap: 4px;
  padding: 6px 12px; border-radius: var(--radius-full);
  background: var(--success); color: var(--bg); font-size: var(--size-xs); font-weight: var(--weight-semibold); text-decoration: none;
  transition: background-color .2s ease;
}
.chat-product-card__action:hover { background: var(--fg); }

/* بيكتب... */
.chat-typing { display: flex; align-items: center; gap: 5px; padding: 14px 16px; }
.chat-typing span { inline-size: 6px; block-size: 6px; border-radius: 50%; background: var(--fg-muted); animation: chat-dot 1.2s infinite ease-in-out; }
.chat-typing span:nth-child(2) { animation-delay: .15s; }
.chat-typing span:nth-child(3) { animation-delay: .3s; }
@keyframes chat-dot { 0%, 70%, 100% { transform: translateY(0); opacity: .4; } 35% { transform: translateY(-4px); opacity: 1; } }

/* ---------- الإدخال ---------- */
.chat-foot { padding: var(--space-3) var(--space-4) var(--space-4); border-block-start: 1px solid var(--border); }
.chat-form { display: flex; align-items: center; gap: var(--space-2); }
.chat-input {
  flex: 1; min-inline-size: 0; min-block-size: 46px; padding: 8px 18px;
  border: 1.5px solid var(--border); border-radius: var(--radius-full);
  background: var(--surface); color: var(--fg); font: inherit; font-size: var(--size-base);
  outline: none; transition: border-color .2s ease;
}
.chat-input::placeholder { color: color-mix(in srgb, var(--fg) 45%, transparent); }
.chat-input:focus { border-color: var(--fg); }
.chat-send {
  flex: none; display: grid; place-items: center;
  inline-size: 46px; block-size: 46px; border: 0; border-radius: 50%;
  background: var(--fg); color: var(--bg); font-size: 20px; cursor: pointer;
  transition: transform .45s var(--chat-ease), background-color .2s ease;
}
.chat-send:hover { transform: translateX(-3px); }
.chat-send:active { transform: scale(.94); }
.chat-send:focus-visible { outline: 2px solid var(--fg); outline-offset: 3px; }

/* ---------- الزر العائم ---------- */
/* بيتخبّى وقت التمرير لتحت (chat.js) عشان ما يغطي أزرار البطاقات */
.chat-trigger { transition: transform .35s cubic-bezier(.16, 1, .3, 1), opacity .35s ease, box-shadow .45s cubic-bezier(.16, 1, .3, 1); }
.chat-trigger.is-tucked { transform: translateY(160%); opacity: 0; pointer-events: none; }
/* زر وصندوق الشات بيختفوا لما القائمة أو السلة مفتوحة (body.is-locked): ما بيصير يطلع الزر فوقهم */
body.is-locked .chat-trigger, body.is-locked .chat-window { opacity: 0; pointer-events: none; }

/* ---------- موبايل: لوح من تحت بعرض الشاشة ---------- */
@media (max-width: 600px) {
  /* الزر دائري بأيقونة بس (النص للقارئ بالـ aria-label) */
  .chat-trigger { inline-size: 52px; block-size: 52px; min-block-size: 52px; padding: 0; border-radius: 50%; }
  .chat-trigger span { position: absolute; inline-size: 1px; block-size: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
  .chat-trigger i { font-size: 26px; }
  .chat-trigger[aria-expanded="true"] { opacity: 0; pointer-events: none; } /* اللوح فيه زر إغلاق */
  .chat-window {
    inset-inline: 0; inset-block-end: 0; inline-size: auto;
    block-size: min(88svh, 680px);
    border-inline: 0; border-block-end: 0; border-radius: var(--radius-md) var(--radius-md) 0 0;
    transform: translateY(100%); opacity: 1; visibility: hidden;
    transition: transform .6s var(--chat-ease), visibility 0s linear .6s;
  }
  .chat-window.is-open { transform: none; visibility: visible; transition: transform .6s var(--chat-ease), visibility 0s; }
  .chat-foot { padding-block-end: max(var(--space-4), env(safe-area-inset-bottom)); }
}
@media (prefers-reduced-motion: reduce) {
  .chat-trigger, .chat-window, .chat-head__close, .chat-send, .chat-chip__text, .chat-starters .chat-chip i { transition: none; }
  .chat-msg, .chat-starters li, .chat-typing span { animation: none; }
}
