/* ==========================================================
   بورتال العميل — تجربة محادثة مألوفة بأسلوب تطبيقات المراسلة
   (ألوان ونسب وتفاصيل مطابقة: فقاعات بذيل، علامات قراءة، شريط إدخال)
   ========================================================== */

:root {
  /* ألوان الوضع النهاري */
  --wa-header: #008069;
  --wa-header-text: #ffffff;
  --wa-bg: #efeae2;
  --wa-panel: #ffffff;
  --wa-panel-2: #f0f2f5;
  --wa-in: #ffffff;          /* فقاعة الطرف الآخر */
  --wa-out: #d9fdd3;         /* فقاعتك */
  --wa-text: #111b21;
  --wa-text-2: #667781;
  --wa-meta: #667781;
  --wa-tick: #8696a0;
  --wa-tick-read: #53bdeb;
  --wa-accent: #00a884;
  --wa-accent-dark: #017561;
  --wa-border: rgba(17, 27, 33, 0.08);
  --wa-shadow: 0 1px 0.5px rgba(11, 20, 26, 0.13);
  --wa-sys: #ffeecd;
  --wa-sys-text: #54656f;
  --wa-date: rgba(255, 255, 255, 0.92);
  --wa-danger: #ea0038;
  --wa-online: #06cf9c;
  /* الأزرار الرئيسية بألوان التطبيق نفسه (أخضر داكن + نص أبيض) — تباين AA */
  --wa-primary: #008069;
  --wa-primary-hover: #017561;
  --wa-on-primary: #ffffff;
  --wa-primary-text: #008069;
  /* الوقت وعلامات التسليم داخل فقاعتك (أغمق قليلًا لتقرأ على الأخضر الفاتح) */
  --wa-meta-out: #5b6b74;
  --wa-link: #016d9d;
}

[data-theme='dark'] {
  --wa-header: #202c33;
  --wa-header-text: #e9edef;
  --wa-bg: #0b141a;
  --wa-panel: #111b21;
  --wa-panel-2: #202c33;
  --wa-in: #202c33;
  --wa-out: #005c4b;
  --wa-text: #e9edef;
  --wa-text-2: #8696a0;
  --wa-meta: #8696a0;
  --wa-tick: #8696a0;
  --wa-tick-read: #53bdeb;
  --wa-accent: #00a884;
  --wa-accent-dark: #00a884;
  --wa-border: rgba(233, 237, 239, 0.08);
  --wa-shadow: 0 1px 0.5px rgba(0, 0, 0, 0.35);
  --wa-sys: #182229;
  --wa-sys-text: #8696a0;
  --wa-date: #182229;
  --wa-danger: #f15c6d;
  --wa-online: #06cf9c;
  /* في الوضع الليلي يستخدم التطبيق الأخضر الفاتح مع نص داكن */
  --wa-primary: #00a884;
  --wa-primary-hover: #06cf9c;
  --wa-on-primary: #111b21;
  --wa-primary-text: #00a884;
  --wa-meta-out: rgba(255, 255, 255, 0.72);
  --wa-link: #53bdeb;
}

.portal-body {
  background: var(--wa-bg);
  color: var(--wa-text);
  min-height: 100dvh;
  overflow: hidden;
  font-family: var(--font-sans);
  /* المكوّنات المشتركة (النوافذ، التنبيهات، حلقة التركيز) تأخذ لون التطبيق داخل البورتال */
  --accent: var(--wa-primary);
  --accent-hover: var(--wa-primary-hover);
  --accent-soft: rgba(0, 168, 132, 0.12);
  --accent-contrast: var(--wa-on-primary);
  --accent-text: var(--wa-primary-text);
  --focus-ring: var(--wa-primary-text);
  --shadow-focus: 0 0 0 3px rgba(0, 168, 132, 0.3);
}

.wa-ico { width: 24px; height: 24px; flex: none; }
.wa-ico-sm { width: 20px; height: 20px; }
.wa-ico-lg { width: 28px; height: 28px; }

/* ---------- شاشة الإقلاع ---------- */
.boot {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--sp-3);
  background: var(--wa-panel);
  z-index: 50;
}
.boot[hidden] { display: none !important; }
.boot-logo {
  width: 68px;
  height: 68px;
  border-radius: 50%;
  background: var(--wa-accent);
  display: grid;
  place-items: center;
  color: #fff;
  font-weight: var(--fw-black);
  font-size: var(--fs-lg);
  margin-bottom: var(--sp-2);
}
.boot .spinner { border-color: rgba(0, 168, 132, 0.25); border-top-color: var(--wa-accent); }

/* ---------- هيكل الشاشات ---------- */
.screen {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  background: var(--wa-bg);
  animation: fadeIn var(--t-base);
}
.screen[hidden] { display: none !important; }

/* على الشاشات الكبيرة: إطار تطبيق أنيق في المنتصف */
@media (min-width: 760px) {
  .portal-body { background: #d9dbd4; }
  [data-theme='dark'] .portal-body { background: #0c1317; }
  .portal-body::before {
    content: '';
    position: fixed;
    inset-block-start: 0;
    inset-inline: 0;
    height: 127px;
    background: var(--wa-header);
  }
  .screen {
    inset: auto;
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: min(480px, calc(100vw - 40px));
    height: min(860px, calc(100dvh - 38px));
    box-shadow: 0 6px 18px rgba(11, 20, 26, 0.18);
    overflow: hidden;
  }
  .boot { background: transparent; }
}

/* ==========================================================
   الشريط العلوي (رأس المحادثة)
   ========================================================== */
.wa-topbar {
  flex: none;
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  height: 60px;
  padding: 0 var(--sp-2) 0 var(--sp-3);
  padding-top: env(safe-area-inset-top);
  /* الهاتف بالوضع الأفقي: لا تدخل الأزرار تحت الحافة المقصوصة */
  padding-right: max(var(--sp-2), env(safe-area-inset-right));
  padding-left: max(var(--sp-3), env(safe-area-inset-left));
  height: calc(60px + env(safe-area-inset-top));
  background: var(--wa-header);
  color: var(--wa-header-text);
}
.wa-topbar .wa-icon-btn { color: var(--wa-header-text); }
/* حلقة التركيز بالأبيض فوق الشريط الملوّن حتى تبقى ظاهرة */
.wa-topbar :focus-visible { outline-color: #fff; }

.wa-icon-btn {
  width: 40px;
  height: 40px;
  border: 0;
  background: transparent;
  color: inherit;
  border-radius: 50%;
  display: grid;
  place-items: center;
  cursor: pointer;
  flex: none;
  transition: background var(--t-fast);
}
.wa-icon-btn:hover { background: rgba(255, 255, 255, 0.12); }
.wa-icon-btn:active { background: rgba(255, 255, 255, 0.2); }
[data-theme='dark'] .wa-icon-btn:hover { background: rgba(255, 255, 255, 0.08); }

.wa-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: #62737c;
  color: #fff;
  display: grid;
  place-items: center;
  font-size: var(--fs-base);
  font-weight: var(--fw-medium);
  flex: none;
  overflow: hidden;
}
.wa-avatar.lg { width: 96px; height: 96px; font-size: 2rem; }
.wa-avatar.xl { width: 120px; height: 120px; font-size: 2.6rem; }

.wa-title-block { flex: 1; min-width: 0; line-height: 1.25; }
.wa-title {
  font-size: var(--fs-md);
  font-weight: var(--fw-medium);
  color: var(--wa-header-text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.wa-status {
  font-size: var(--fs-xs);
  color: rgba(255, 255, 255, 0.95);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-height: 15px;
}
[data-theme='dark'] .wa-status { color: #8696a0; }

/* ==========================================================
   منطقة الرسائل
   ========================================================== */
.wa-chat {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: var(--sp-3) 5%;
  padding-right: max(5%, env(safe-area-inset-right));
  padding-left: max(5%, env(safe-area-inset-left));
  display: flex;
  flex-direction: column;
  gap: 2px;
  background-color: var(--wa-bg);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='260' height='260' viewBox='0 0 260 260'%3E%3Cg fill='none' stroke='%23000' stroke-width='1.1' stroke-linecap='round' stroke-linejoin='round' opacity='0.038'%3E%3Cpath d='M22 30c4-6 10-6 14 0M30 22v16'/%3E%3Ccircle cx='84' cy='26' r='7'/%3E%3Cpath d='M130 18l6 12h-12z'/%3E%3Crect x='170' y='16' width='16' height='12' rx='2'/%3E%3Cpath d='M222 16v14m-7-7h14'/%3E%3Cpath d='M18 78c6-8 14-8 20 0'/%3E%3Cpath d='M74 70h16v14H74zM78 70v-4h8v4'/%3E%3Ccircle cx='132' cy='78' r='8'/%3E%3Cpath d='M128 78l3 3 5-6'/%3E%3Cpath d='M172 84c0-8 6-12 10-12s10 4 10 12z'/%3E%3Cpath d='M216 72h16M216 78h12M216 84h16'/%3E%3Cpath d='M24 126c0-6 5-10 10-10s10 4 10 10c0 8-10 14-10 14s-10-6-10-14z'/%3E%3Crect x='76' y='120' width='18' height='14' rx='3'/%3E%3Cpath d='M126 120l10 6-10 6z'/%3E%3Ccircle cx='178' cy='126' r='6'/%3E%3Cpath d='M178 116v-4M178 140v-4M188 126h4M164 126h4'/%3E%3Cpath d='M214 132c4-10 12-10 16 0'/%3E%3Cpath d='M20 178h18v12H20zM26 178v-6h6v6'/%3E%3Cpath d='M76 186c0-8 6-12 10-12s10 4 10 12z'/%3E%3Cpath d='M126 174v16m-6-8h12'/%3E%3Ccircle cx='180' cy='182' r='8'/%3E%3Cpath d='M216 176l8 12h-16z'/%3E%3Cpath d='M24 232c6-8 14-8 20 0'/%3E%3Crect x='74' y='226' width='18' height='12' rx='2'/%3E%3Ccircle cx='132' cy='232' r='7'/%3E%3Cpath d='M172 226h16v14h-16zM176 226v-4h8v4'/%3E%3Cpath d='M218 226l6 12h-12z'/%3E%3C/g%3E%3C/svg%3E");
  background-repeat: repeat;
  background-size: 210px 210px;
}
[data-theme='dark'] .wa-chat { background-image: none; }

/* فاصل التاريخ + رسائل النظام */
.wa-pill {
  align-self: center;
  max-width: 90%;
  margin: var(--sp-2) 0;
  padding: 5px 12px;
  border-radius: 8px;
  background: var(--wa-date);
  color: var(--wa-sys-text);
  font-size: 12.5px;
  text-align: center;
  box-shadow: var(--wa-shadow);
  line-height: 1.6;
}
.wa-pill.notice { background: var(--wa-sys); color: #54656f; }
[data-theme='dark'] .wa-pill.notice { color: #ffd279; }

/* ---------- الفقاعات ---------- */
.wa-row { display: flex; width: 100%; }
.wa-row.out { justify-content: flex-start; }   /* رسائلك (RTL: يسار) */
.wa-row.in { justify-content: flex-end; }      /* رسائل الدعم */

.wa-bubble {
  position: relative;
  max-width: min(85%, 480px);
  padding: 6px 9px 8px 9px;
  border-radius: 7.5px;
  background: var(--wa-in);
  color: var(--wa-text);
  box-shadow: var(--wa-shadow);
  font-size: 14.2px;
  line-height: 19px;
  word-break: break-word;
  overflow-wrap: anywhere;
  margin-top: 2px;
}
.wa-row.out .wa-bubble { background: var(--wa-out); }

/* ذيل الفقاعة لأول رسالة في المجموعة
   الضلع العمودي للذيل ملاصق للفقاعة ورأسه يشير للخارج (الصفحة RTL دائمًا:
   فقاعة الدعم يسارًا وذيلها يسارها، وفقاعتك يمينًا وذيلها يمينها) */
.wa-row.first .wa-bubble::before {
  content: '';
  position: absolute;
  top: 0;
  width: 8px;
  height: 13px;
  background: inherit;
}
.wa-row.in.first .wa-bubble {
  border-start-end-radius: 0;
}
.wa-row.in.first .wa-bubble::before {
  inset-inline-end: -8px;
  clip-path: polygon(0 0, 100% 0, 100% 100%);
}
.wa-row.out.first .wa-bubble {
  border-start-start-radius: 0;
}
.wa-row.out.first .wa-bubble::before {
  inset-inline-start: -8px;
  clip-path: polygon(0 0, 100% 0, 0 100%);
}
.wa-row:not(.first) { margin-top: 2px; }
.wa-row.group-end { margin-bottom: var(--sp-2); }

.wa-sender {
  display: block;
  font-size: 12.8px;
  font-weight: var(--fw-medium);
  color: var(--wa-accent-dark);
  margin-bottom: 2px;
}
[data-theme='dark'] .wa-sender { color: #53bdeb; }

.wa-text { white-space: pre-wrap; }
.wa-text a { color: var(--wa-link); text-decoration: underline; }

/* الوقت وعلامات القراءة داخل الفقاعة — في الزاوية السفلية عند نهاية النص
   (inline-end = يسار الفقاعة في RTL) مع فراغ يفصله عن آخر كلمة */
.wa-meta {
  float: inline-end;
  display: inline-flex;
  align-items: center;
  gap: 3px;
  margin-inline-start: 8px;
  margin-top: 4px;
  height: 15px;
  font-size: 11px;
  color: var(--wa-meta);
  white-space: nowrap;
  user-select: none;
}
/* علامة «مُعدّلة» داخل سطر الوقت — يراها الطرفان */
.wa-edited { margin-inline-end: 4px; font-style: italic; opacity: 0.85; }

.wa-tick { width: 16px; height: 15px; color: var(--wa-tick); }
.wa-tick.read { color: var(--wa-tick-read); }
.wa-row.out .wa-meta,
.wa-row.out .wa-tick:not(.read) { color: var(--wa-meta-out); }

/* ---------- تعديل رسالة مُرسَلة ----------
   إجراء هادئ بجانب الفقاعة: يظهر عند المرور أو التركيز، وعلى اللمس يبقى
   خافتًا ليبقى في المتناول. يختفي من تلقائه حين تنتهي المهلة أو يقرأها الدعم. */
.wa-row { align-items: flex-end; }
.wa-edit-btn {
  flex: none;
  align-self: flex-end;
  margin: 0 8px 2px;
  padding: 2px 8px;
  border: 0;
  border-radius: var(--r-full);
  background: var(--wa-in);
  box-shadow: var(--wa-shadow);
  color: var(--wa-text-2);
  font: inherit;
  font-size: 11.5px;
  line-height: 18px;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.12s ease, color 0.12s ease;
}
.wa-row:hover .wa-edit-btn,
.wa-edit-btn:focus-visible { opacity: 1; }
.wa-edit-btn:hover { color: var(--wa-text); }
@media (hover: none), (pointer: coarse) {
  .wa-edit-btn { opacity: 0.6; }
}

/* الفقاعة أثناء التحرير */
.wa-row.editing .wa-bubble { min-width: min(260px, 72vw); }
.wa-edit-input {
  display: block;
  width: 100%;
  min-height: 20px;
  max-height: 120px;
  resize: none;
  border: 0;
  padding: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  line-height: 19px;
  outline: none;
}
.wa-edit-bar {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  margin-top: 6px;
  padding-top: 5px;
  border-top: 1px solid rgba(0, 0, 0, 0.08);
}
[data-theme='dark'] .wa-edit-bar { border-top-color: rgba(255, 255, 255, 0.1); }
.wa-edit-left { flex: 1; font-size: 11px; color: var(--wa-meta-out); }
.wa-edit-act {
  border: 0;
  border-radius: var(--r-full);
  padding: 3px 12px;
  background: transparent;
  color: var(--wa-accent-dark);
  font: inherit;
  font-size: 12.5px;
  font-weight: var(--fw-medium);
  cursor: pointer;
}
.wa-edit-act:hover { background: rgba(0, 0, 0, 0.06); }
[data-theme='dark'] .wa-edit-act { color: var(--wa-tick-read); }
[data-theme='dark'] .wa-edit-act:hover { background: rgba(255, 255, 255, 0.08); }
.wa-edit-act.primary { background: var(--wa-accent); color: #fff; }
.wa-edit-act.primary:hover { background: var(--wa-accent-dark); }
.wa-edit-act:disabled { opacity: 0.55; cursor: default; }

/* مرفقات */
.wa-bubble.media { padding: 3px 3px 8px; }
.wa-img {
  display: block;
  max-width: 100%;
  max-height: 320px;
  border-radius: 6px;
  cursor: pointer;
}
.wa-video { max-width: 100%; max-height: 320px; border-radius: 6px; display: block; }
.wa-caption { padding: 4px 6px 0; }

.wa-audio {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  min-width: 210px;
  padding: 2px 0;
}
.wa-audio audio { width: 100%; height: 36px; }

.wa-doc {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  padding: 8px;
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.04);
  text-decoration: none;
  color: inherit;
  min-width: 200px;
}
[data-theme='dark'] .wa-doc { background: rgba(255, 255, 255, 0.06); }
.wa-doc:hover { text-decoration: none; filter: brightness(0.98); }
.wa-doc .wa-ico { color: var(--wa-text-2); }
.wa-doc-name { font-size: 13.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.wa-doc-size { font-size: 11.5px; color: var(--wa-text-2); }

/* مؤشر الكتابة */
.wa-typing-row { display: flex; justify-content: flex-end; padding: 2px 0; }
.wa-typing {
  background: var(--wa-in);
  border-radius: 7.5px;
  box-shadow: var(--wa-shadow);
  padding: 10px 12px;
  display: flex;
  gap: 4px;
}
.wa-typing i {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #9aa6ac;
  animation: waType 1.2s infinite ease-in-out;
}
.wa-typing i:nth-child(2) { animation-delay: 0.18s; }
.wa-typing i:nth-child(3) { animation-delay: 0.36s; }
@keyframes waType {
  0%, 60%, 100% { opacity: 0.35; transform: translateY(0); }
  30% { opacity: 1; transform: translateY(-3px); }
}

/* زر النزول لآخر الرسائل */
.wa-jump {
  position: absolute;
  inset-block-end: 84px;
  inset-inline-start: 16px;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: 0;
  background: var(--wa-panel);
  color: var(--wa-text-2);
  box-shadow: 0 1px 3px rgba(11, 20, 26, 0.25);
  cursor: pointer;
  display: grid;
  place-items: center;
  z-index: 6;
}
.wa-jump .wa-badge {
  position: absolute;
  top: -4px;
  inset-inline-end: -2px;
  min-width: 18px;
  height: 18px;
  border-radius: 9px;
  background: var(--wa-primary);
  color: var(--wa-on-primary);
  font-size: 11px;
  display: grid;
  place-items: center;
  padding: 0 5px;
}

/* ==========================================================
   شريط الإدخال
   ========================================================== */
.wa-composer {
  flex: none;
  display: flex;
  align-items: flex-end;
  gap: 6px;
  padding: 5px 8px;
  padding-bottom: max(5px, env(safe-area-inset-bottom));
  padding-right: max(8px, env(safe-area-inset-right));
  padding-left: max(8px, env(safe-area-inset-left));
  background: var(--wa-panel-2);
}
.wa-input-pill {
  flex: 1;
  display: flex;
  align-items: flex-end;
  gap: 2px;
  min-height: 50px;
  padding: 6px 8px;
  border-radius: 25px;
  background: var(--wa-panel);
  box-shadow: 0 1px 1px rgba(11, 20, 26, 0.06);
}
.wa-input-pill .wa-icon-btn { color: var(--wa-text-2); width: 38px; height: 38px; }
.wa-input-pill .wa-icon-btn:hover { background: rgba(0, 0, 0, 0.05); }
[data-theme='dark'] .wa-input-pill .wa-icon-btn:hover { background: rgba(255, 255, 255, 0.06); }

.wa-input {
  flex: 1;
  border: 0;
  outline: 0;
  background: transparent;
  resize: none;
  min-height: 24px;
  height: 24px;
  max-height: 100px;
  overflow-y: auto;
  padding: 0 4px;
  margin-bottom: 7px;
  font-family: inherit;
  font-size: 15px;
  line-height: 24px;
  color: var(--wa-text);
}
.wa-input::placeholder { color: var(--wa-text-2); }

.wa-send {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  border: 0;
  background: var(--wa-accent);
  color: #fff;
  display: grid;
  place-items: center;
  cursor: pointer;
  flex: none;
  transition: transform var(--t-fast), background var(--t-fast);
}
.wa-send:active { transform: scale(0.93); }
.wa-send.recording { background: var(--wa-danger); }

/* لوحة المرفقات */
.wa-sheet-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(11, 20, 26, 0.45);
  z-index: 80;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  animation: fadeIn var(--t-fast);
}
.wa-sheet {
  width: 100%;
  max-width: 480px;
  background: var(--wa-panel);
  border-radius: 16px 16px 0 0;
  padding: var(--sp-4) var(--sp-4) max(var(--sp-5), env(safe-area-inset-bottom));
  animation: slideUp var(--t-base);
}
.wa-sheet-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--sp-4);
  text-align: center;
}
.wa-sheet-item {
  border: 0;
  background: transparent;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 4px 0;
  border-radius: 12px;
  font-family: inherit;
  font-size: 12.5px;
  color: var(--wa-text-2);
}
.wa-sheet-icon {
  width: 54px;
  height: 54px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: #fff;
}
/* على الشاشات الكبيرة تُحاذى الورقة مع أسفل إطار التطبيق المتوسّط بدل أسفل النافذة */
@media (min-width: 760px) {
  .wa-sheet { margin-bottom: max(19px, calc((100dvh - 860px) / 2)); }
  html[data-embed='1'] .wa-sheet { margin-bottom: 0; }
}
.wa-sheet-icon.doc { background: #5f66cd; }
.wa-sheet-icon.cam { background: #d3396d; }
.wa-sheet-icon.img { background: #bf59cf; }
.wa-sheet-icon.audio { background: #e67e22; }

/* شريط التسجيل الصوتي */
.wa-recording {
  flex: none;
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: 0 var(--sp-3);
  padding-bottom: env(safe-area-inset-bottom);
  padding-right: max(var(--sp-3), env(safe-area-inset-right));
  padding-left: max(var(--sp-3), env(safe-area-inset-left));
  /* الارتفاع يشمل الهامش السفلي للآيفون حتى لا ينضغط الشريط */
  height: calc(56px + env(safe-area-inset-bottom));
  background: var(--wa-panel-2);
  color: var(--wa-text);
}
.wa-recording[hidden] { display: none !important; }
.wa-rec-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--wa-danger);
  animation: blink 1.1s infinite;
}
.wa-rec-time { font-variant-numeric: tabular-nums; font-size: 15px; min-width: 46px; }
.wa-rec-hint { flex: 1; color: var(--wa-text-2); font-size: 13px; }

/* شريط الرفع */
.wa-upload {
  flex: none;
  padding: 6px var(--sp-4);
  background: var(--wa-panel-2);
  font-size: 12px;
  color: var(--wa-text-2);
}
.wa-upload[hidden] { display: none !important; }
.wa-upload .progress { height: 3px; margin-top: 4px; background: rgba(0, 0, 0, 0.1); }
.wa-upload .progress > span { background: var(--wa-accent); }

/* ==========================================================
   شاشة البداية (اختيار المشكلة)
   ========================================================== */
.wa-start-scroll { flex: 1; overflow-y: auto; background: var(--wa-panel); }
.wa-hero {
  background: var(--wa-header);
  color: #fff;
  padding: var(--sp-5) var(--sp-4) var(--sp-8);
  padding-top: max(var(--sp-5), env(safe-area-inset-top));
  text-align: center;
}
.wa-hero .wa-avatar { margin: 0 auto var(--sp-3); background: rgba(255, 255, 255, 0.18); }
.wa-hero h1 { color: #fff; font-size: var(--fs-lg); margin-bottom: 4px; }
.wa-hero p { color: rgba(255, 255, 255, 0.95); font-size: var(--fs-sm); margin: 0; }

.wa-card {
  margin: calc(-1 * var(--sp-6)) var(--sp-3) var(--sp-3);
  background: var(--wa-panel);
  border-radius: 12px;
  box-shadow: 0 2px 8px rgba(11, 20, 26, 0.12);
  padding: var(--sp-4);
}
/* في الوضع الليلي: البطاقة بلون اللوحة وإطار خفيف حتى لا تذوب في الشريط العلوي
   (كان لونها مطابقًا للشريط فتختفي حافتها العلوية) */
[data-theme='dark'] .wa-card {
  background: var(--wa-panel);
  border: 1px solid var(--wa-border);
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.35);
}

.wa-status-line {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  font-size: 13px;
  padding: 8px 10px;
  border-radius: 8px;
  margin-bottom: var(--sp-3);
}
.wa-status-line.open { background: rgba(0, 168, 132, 0.12); color: var(--wa-accent-dark); }
.wa-status-line.closed { background: rgba(255, 193, 7, 0.14); color: #735b00; }
[data-theme='dark'] .wa-status-line.open { color: #06cf9c; }
[data-theme='dark'] .wa-status-line.closed { color: #ffd279; }
.wa-status-line .dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; flex: none; }

.wa-section-title {
  font-size: 13px;
  font-weight: var(--fw-medium);
  color: var(--wa-text-2);
  margin: var(--sp-4) 0 var(--sp-2);
  padding: 0 var(--sp-1);
}

.wa-issues { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.wa-issue {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 10px;
  border: 1px solid var(--wa-border);
  border-radius: 10px;
  background: var(--wa-panel);
  color: var(--wa-text);
  font-size: 13.5px;
  font-family: inherit;
  cursor: pointer;
  text-align: start;
  transition: all var(--t-fast);
}
[data-theme='dark'] .wa-issue { background: var(--wa-panel-2); }
.wa-issue .ico { width: 20px; height: 20px; color: var(--wa-text-2); flex: none; }
.wa-issue:hover { border-color: var(--wa-accent); }
.wa-issue.active {
  border-color: var(--wa-accent);
  background: rgba(0, 168, 132, 0.1);
  color: var(--wa-accent-dark);
}
[data-theme='dark'] .wa-issue.active { color: #06cf9c; }
.wa-issue.active .ico { color: var(--wa-accent); }

.wa-field { margin-bottom: var(--sp-3); }
.wa-label { display: block; font-size: 12.5px; color: var(--wa-text-2); margin-bottom: 5px; }
.wa-select,
.wa-text-input {
  width: 100%;
  height: 44px;
  padding: 0 12px;
  border: 1px solid var(--wa-border);
  border-radius: 8px;
  background: var(--wa-panel);
  color: var(--wa-text);
  font-family: inherit;
  font-size: 14px;
}
[data-theme='dark'] .wa-select,
[data-theme='dark'] .wa-text-input { background: var(--wa-panel-2); }
/* حد أخضر بسماكة واضحة عند التركيز (بدل تغيّر لون خط رفيع فقط) */
.wa-select:focus,
.wa-text-input:focus { outline: 0; border-color: var(--wa-accent); box-shadow: 0 0 0 1px var(--wa-accent); }

.wa-cta {
  width: 100%;
  height: 50px;
  border: 0;
  border-radius: 25px;
  background: var(--wa-primary);
  color: var(--wa-on-primary);
  font-family: inherit;
  font-size: 15.5px;
  font-weight: var(--fw-medium);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  transition: background var(--t-fast), transform var(--t-fast);
}
.wa-cta:hover { background: var(--wa-primary-hover); }
.wa-cta:active { transform: scale(0.99); }
.wa-cta:disabled { opacity: 0.6; cursor: not-allowed; }
.wa-cta.ghost {
  background: transparent;
  color: var(--wa-primary-text);
  border: 1px solid var(--wa-primary-text);
}
/* كان التحويم يملأ الزر بالأخضر فيختفي نصه الأخضر */
.wa-cta.ghost:hover { background: rgba(0, 168, 132, 0.08); }

.wa-foot {
  flex: none;
  padding: var(--sp-3) var(--sp-4);
  padding-bottom: max(var(--sp-3), env(safe-area-inset-bottom));
  padding-right: max(var(--sp-4), env(safe-area-inset-right));
  padding-left: max(var(--sp-4), env(safe-area-inset-left));
  background: var(--wa-panel);
  border-top: 1px solid var(--wa-border);
}
.wa-foot-note { text-align: center; font-size: 11.5px; color: var(--wa-text-2); margin-top: 8px; }

/* صندوق «محادثة جارية» */
.wa-resume {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: 12px;
  border-radius: 10px;
  background: rgba(0, 168, 132, 0.1);
  margin-bottom: var(--sp-3);
}
.wa-resume[hidden] { display: none !important; }
.wa-resume .wa-avatar { width: 42px; height: 42px; background: var(--wa-accent); }
.wa-resume-title { font-size: 14px; font-weight: var(--fw-medium); }
.wa-resume-sub { font-size: 12px; color: #54656f; }
[data-theme='dark'] .wa-resume-sub { color: var(--wa-text-2); }
.wa-resume button {
  border: 0;
  background: var(--wa-primary);
  color: var(--wa-on-primary);
  border-radius: 18px;
  height: 34px;
  padding: 0 14px;
  font-family: inherit;
  font-size: 13px;
  cursor: pointer;
  flex: none;
}
/* على الهاتف ينزل الزر بعرض كامل تحت النص بدل أن يضغط العنوان في ثلاثة أسطر */
@media (max-width: 480px) {
  .wa-resume { flex-wrap: wrap; }
  .wa-resume > .grow { flex: 1 1 0; }
  .wa-resume button { width: 100%; height: 38px; }
}

/* سجل الطلبات */
.wa-history-row {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  padding: 10px 2px;
  border-bottom: 1px solid var(--wa-border);
  font-size: 13px;
}
.wa-history-row:last-child { border-bottom: 0; }
.wa-chip {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 10px;
  background: var(--wa-panel-2);
  color: var(--wa-text-2);
}

/* ==========================================================
   شاشة الشكر والتقييم
   ========================================================== */
.wa-center {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: var(--sp-6);
  text-align: center;
  background: var(--wa-panel);
  overflow-y: auto;
}
.wa-done-icon {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  background: rgba(0, 168, 132, 0.14);
  color: var(--wa-accent);
  display: grid;
  place-items: center;
  margin-bottom: var(--sp-4);
}
.wa-done-icon .wa-ico { width: 40px; height: 40px; }
.wa-center h2 { font-size: var(--fs-lg); color: var(--wa-text); margin-bottom: 6px; }
.wa-center p { color: var(--wa-text-2); font-size: 14px; }

.wa-stars { display: flex; justify-content: center; gap: 2px; direction: ltr; margin: var(--sp-3) 0; }
/* هدف لمس 44px ونجمة غير مختارة بلون ظاهر (كانت شبه مخفية على الأبيض) */
.wa-stars button {
  border: 0;
  background: transparent;
  cursor: pointer;
  padding: 5px;
  border-radius: 50%;
  color: var(--wa-tick);
  transition: transform var(--t-fast), color var(--t-fast);
}
.wa-stars button .wa-ico,
.wa-stars button .ico { width: 34px; height: 34px; stroke-width: 1.6; }
.wa-stars button:hover { transform: scale(1.12); }
.wa-stars button.on { color: #ffb300; }
.wa-stars button.on .ico { fill: currentColor; }

.wa-comment {
  width: 100%;
  max-width: 340px;
  min-height: 70px;
  padding: 10px 12px;
  border: 1px solid var(--wa-border);
  border-radius: 10px;
  background: var(--wa-panel);
  color: var(--wa-text);
  font-family: inherit;
  font-size: 14px;
  resize: vertical;
}
.wa-comment:focus { outline: 0; border-color: var(--wa-accent); box-shadow: 0 0 0 1px var(--wa-accent); }
[data-theme='dark'] .wa-comment { background: var(--wa-panel-2); }
.wa-rating-block { width: 100%; max-width: 340px; }

/* ==========================================================
   المكالمات — بأسلوب التطبيق نفسه
   ========================================================== */
.conf.wa-theme {
  background: linear-gradient(160deg, #1f2c34 0%, #0b141a 100%);
}
.conf.wa-theme .conf-top {
  background: transparent;
  padding-top: max(var(--sp-5), env(safe-area-inset-top));
}
.conf.wa-theme .conf-title { font-size: var(--fs-md); font-weight: var(--fw-medium); }
.conf.wa-theme .conf-grid { padding-top: 96px; }
/* الشريط العلوي هنا أطول، فينزل التنبيه قليلًا حتى لا يلامس سطر الحالة */
.conf.wa-theme .conf-notice { inset-block-start: calc(max(var(--sp-5), env(safe-area-inset-top)) + 52px); }
.conf.wa-theme .conf-tile { background: #24343d; border-radius: 14px; }
.conf.wa-theme .conf-avatar {
  flex: none;
  background: #6b7c85;
  width: 110px;
  height: 110px;
  font-size: 2.4rem;
}
.conf.wa-theme .conf-controls {
  background: transparent;
  gap: 22px;
  padding-bottom: max(var(--sp-8), env(safe-area-inset-bottom));
}
.conf.wa-theme .conf-btn {
  width: 58px;
  height: 58px;
  background: rgba(255, 255, 255, 0.16);
}
.conf.wa-theme .conf-btn.off { background: #fff; color: #111b21; }
.conf.wa-theme .conf-btn.danger { background: var(--wa-danger); }
.conf.wa-theme .conf-timer { background: transparent; opacity: 0.85; }
.conf.wa-theme .conf-count { background: rgba(255, 255, 255, 0.16); }

/* نافذة المكالمة الواردة */
.ring-overlay.wa-theme { background: rgba(11, 20, 26, 0.92); backdrop-filter: blur(4px); }
.ring-overlay.wa-theme .ring-card {
  background: transparent;
  box-shadow: none;
  max-width: 340px;
  color: #e9edef;
}
.ring-overlay.wa-theme .ring-pulse {
  width: 120px;
  height: 120px;
  background: #6b7c85;
  color: #fff;
  font-size: 2.6rem;
}
.ring-overlay.wa-theme .ring-title { color: #fff; font-size: var(--fs-lg); }
.ring-overlay.wa-theme .ring-sub { color: #8696a0; }
.ring-overlay.wa-theme .badge {
  display: block;
  width: fit-content;
  margin: 0 auto var(--sp-3);
  background: rgba(255, 255, 255, 0.14);
  color: #e9edef;
}
.ring-overlay.wa-theme .btn { border-radius: 30px; height: 54px; font-size: 15px; color: #fff; }
/* ألوان ثابتة فوق الخلفية الداكنة في الوضعين، بتباين AA للنص الأبيض */
.ring-overlay.wa-theme .btn-success,
.ring-overlay.wa-theme .btn-success:hover { background: #008069; }
.ring-overlay.wa-theme .btn-danger,
.ring-overlay.wa-theme .btn-danger:hover { background: #ea0038; }
.ring-overlay.wa-theme :focus-visible,
.conf.wa-theme :focus-visible { outline-color: #fff; }

/* شريط «مكالمة جارية» بأسلوب التطبيق */
.live-call-bar {
  background: var(--wa-primary);
  color: var(--wa-on-primary);
  border: 0;
  padding: 8px var(--sp-4);
  font-size: 13px;
}
.live-call-bar .dot { background: currentColor; }
.live-call-bar :focus-visible { outline-color: currentColor; }
.live-call-bar button {
  border: 0;
  background: rgba(255, 255, 255, 0.22);
  color: inherit;
  border-radius: 16px;
  height: 30px;
  padding: 0 14px;
  font-family: inherit;
  font-size: 12.5px;
  cursor: pointer;
}

/* شريط طلب المكالمة — وصل الطلب إلى الموظف والعميل ينتظر بهدوء.
   نبرة مطمئنة: لا رنين ولا كاميرا قبل أن يبدأ الموظف الاتصال. */
.wa-call-req {
  flex: none;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px var(--sp-4);
  background: rgba(0, 168, 132, 0.1);
  color: var(--wa-accent-dark);
  border-block-end: 1px solid var(--wa-border);
}
.wa-call-req[hidden] { display: none !important; }
[data-theme='dark'] .wa-call-req { background: #182229; color: var(--wa-accent); }

.wa-call-req-icon {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  flex: none;
  display: grid;
  place-items: center;
  background: rgba(0, 168, 132, 0.18);
  color: inherit;
  animation: waReqPulse 2.4s ease-out infinite;
}
@keyframes waReqPulse {
  0% { box-shadow: 0 0 0 0 rgba(0, 168, 132, 0.34); }
  70%, 100% { box-shadow: 0 0 0 8px rgba(0, 168, 132, 0); }
}
@media (prefers-reduced-motion: reduce) {
  .wa-call-req-icon { animation: none; }
}

.wa-call-req-title { font-size: 13.5px; font-weight: var(--fw-medium); line-height: 1.5; }
.wa-call-req-sub { font-size: 12px; color: var(--wa-text-2); line-height: 1.6; }

.wa-call-req-cancel {
  flex: none;
  border: 1px solid currentColor;
  background: transparent;
  color: inherit;
  border-radius: 16px;
  height: 30px;
  padding: 0 14px;
  font-family: inherit;
  font-size: 12.5px;
  cursor: pointer;
}
.wa-call-req-cancel:hover { background: rgba(0, 168, 132, 0.14); }
.wa-call-req-cancel:disabled { opacity: 0.6; cursor: default; }

/* أزرار المكالمة أثناء انتظار الموظف — ظاهرة لكن معطّلة حتى لا يُعاد الطلب */
.wa-topbar .wa-icon-btn:disabled { opacity: 0.45; cursor: default; }
.wa-topbar .wa-icon-btn:disabled:hover { background: transparent; }
.wa-menu button:disabled { opacity: 0.45; cursor: default; }
.wa-menu button:disabled:hover { background: transparent; }

@media (max-width: 420px) {
  .wa-call-req { gap: 8px; padding-inline: var(--sp-3); }
  .wa-call-req-cancel { padding: 0 10px; }
}

/* شريط تنبيه أعلى المحادثة */
.wa-notice {
  flex: none;
  padding: 8px var(--sp-4);
  background: var(--wa-sys);
  color: #54656f;
  font-size: 12.5px;
  text-align: center;
  line-height: 1.7;
}
[data-theme='dark'] .wa-notice { background: #182229; color: #ffd279; }
.wa-notice[hidden] { display: none !important; }

/* قائمة الخيارات (⋮) — تنسدل من جهة زرّها (نهاية الشريط = يسار الشاشة في RTL) */
.wa-menu {
  position: absolute;
  inset-block-start: calc(56px + env(safe-area-inset-top));
  inset-inline-end: 8px;
  min-width: 190px;
  background: var(--wa-panel);
  border-radius: 6px;
  box-shadow: 0 2px 10px rgba(11, 20, 26, 0.28);
  padding: 6px 0;
  z-index: 40;
  animation: fadeIn var(--t-fast);
}
.wa-menu[hidden] { display: none !important; }
.wa-menu button {
  display: block;
  width: 100%;
  border: 0;
  background: transparent;
  color: var(--wa-text);
  font-family: inherit;
  font-size: 14.5px;
  text-align: start;
  padding: 11px 18px;
  cursor: pointer;
}
.wa-menu button:hover { background: var(--wa-panel-2); }

/* شاشة الخطأ */
.wa-error-icon {
  width: 76px;
  height: 76px;
  border-radius: 50%;
  background: rgba(234, 0, 56, 0.12);
  color: var(--wa-danger);
  display: grid;
  place-items: center;
  margin-bottom: var(--sp-4);
}
.wa-error-icon .wa-ico { width: 38px; height: 38px; }

/* ==========================================================
   وضع التضمين داخل أنظمة عراق سوفت (?embed=1)
   الصفحة تملأ إطار الودجت بالكامل بدل إطار التطبيق المتوسّط
   ========================================================== */
html[data-embed='1'],
html[data-embed='1'] .portal-body { background: var(--wa-bg); }

@media (min-width: 760px) {
  html[data-embed='1'] .portal-body { background: var(--wa-bg); }
  html[data-embed='1'] .portal-body::before { display: none; }
  html[data-embed='1'] .screen {
    position: fixed;
    inset: 0;
    top: auto;
    left: auto;
    transform: none;
    width: 100%;
    height: 100%;
    box-shadow: none;
  }
}

/* بطاقة الهوية القادمة من النظام المُضيف */
.wa-embed-id {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  margin-top: var(--sp-3);
  padding: 10px 12px;
  border-radius: var(--r-md, 10px);
  background: rgba(0, 168, 132, 0.1);
  color: var(--wa-accent-dark);
  font-size: 12.5px;
  line-height: 1.7;
}
[data-theme='dark'] .wa-embed-id { color: #06cf9c; }
.wa-embed-id[hidden] { display: none !important; }

/* ==========================================================
   لوحة الترحيب على الشاشات الكبيرة
   ==========================================================
   تظهر بجانب إطار المحادثة من جهة البداية (يمين الشاشة في العربية)، وتحمل اسم
   العميل ورمز QR لنفس الرابط. مخفية تمامًا على الهاتف وداخل الودجت المضمّن.

   الحساب: المجموعة = اللوحة + الفجوة + الإطار، وتُزاح كل قطعة عن مركز الشاشة
   بنصف ما يقابلها — فتبقى المجموعة كلها متوازنة مهما تغيّرت المقاسات أدناه.  */
.wa-desk { display: none; }

/* 1000px: يشمل اللوحي أفقيًا (1024) — أضيق من ذلك لا تتسع اللوحة والإطار معًا */
@media (min-width: 1000px) {
  :root {
    --desk-frame: 480px;   /* عرض إطار المحادثة (مطابق لقاعدة .screen أعلاه) */
    --desk-panel: 384px;
    --desk-gap: 40px;
  }

  .screen {
    transform: translate(calc(-50% - (var(--desk-gap) + var(--desk-panel)) / 2), -50%);
  }

  .wa-desk {
    display: flex;
    flex-direction: column;
    gap: var(--sp-4);
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(calc(-50% + (var(--desk-gap) + var(--desk-frame)) / 2), -50%);
    width: var(--desk-panel);
    max-height: calc(100dvh - 38px);
    overflow-y: auto;
    padding: var(--sp-5);
    border-radius: 14px;
    background: var(--wa-panel);
    box-shadow: 0 6px 18px rgba(11, 20, 26, 0.18);
    color: var(--wa-text);
  }
  .wa-desk[hidden] { display: none !important; }
}

/* الودجت المضمّن داخل نظام العميل ضيّق دائمًا — لا مكان للوحة ولا داعي لها.
   إطار المحادثة لا يحتاج تصحيحًا هنا: قاعدة الودجت أعلاه تضبط transform: none
   بأولوية أعلى من قاعدة الإزاحة، فيبقى ملء الإطار كما هو. */
html[data-embed='1'] .wa-desk { display: none !important; }

.wa-desk-brand { display: flex; align-items: center; gap: 12px; }
.wa-desk-mark {
  width: 44px;
  height: 44px;
  flex: none;
  border-radius: 50%;
  background: var(--wa-accent);
  color: #fff;
  display: grid;
  place-items: center;
  font-weight: var(--fw-black);
  font-size: 15px;
}
.wa-desk-brandname { font-weight: var(--fw-bold); font-size: 15px; line-height: 1.4; }
.wa-desk-brandsub { font-size: 12px; color: var(--wa-text-2); }

.wa-desk-greet { padding-bottom: var(--sp-1); border-bottom: 1px solid var(--wa-border); }
.wa-desk-hello { font-size: 13px; color: var(--wa-text-2); }
.wa-desk-customer {
  margin: 4px 0 0;
  font-size: 23px;
  line-height: 1.45;
  font-weight: var(--fw-bold);
  color: var(--wa-text);
  overflow-wrap: anywhere;
}
.wa-desk-branch { margin: 6px 0 var(--sp-3); font-size: 13px; color: var(--wa-text-2); }
.wa-desk-branch[hidden] { display: none !important; }

.wa-desk-qr-card {
  border: 1px solid var(--wa-border);
  border-radius: 12px;
  padding: var(--sp-4);
  text-align: center;
  background: var(--wa-bg);
}
.wa-desk-qr-title { font-weight: var(--fw-bold); font-size: 14.5px; }
.wa-desk-qr-text {
  margin: 6px 0 var(--sp-3);
  font-size: 12.5px;
  line-height: 1.8;
  color: var(--wa-text-2);
}
.wa-desk-qr {
  width: 220px;
  height: 220px;
  margin: 0 auto;
  padding: 8px;
  border-radius: 10px;
  /* رمز QR يحتاج خلفية بيضاء دائمًا حتى في الوضع الليلي ليُقرأ */
  background: #fff;
}
.wa-desk-qr img { width: 100%; height: 100%; display: block; }
.wa-desk-copy {
  margin-top: var(--sp-3);
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--wa-border);
  border-radius: 8px;
  background: transparent;
  color: var(--wa-primary-text);
  font: inherit;
  font-size: 13px;
  font-weight: var(--fw-medium);
  cursor: pointer;
  transition: background var(--t-fast);
}
.wa-desk-copy:hover { background: rgba(0, 168, 132, 0.1); }

.wa-desk-points { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.wa-desk-points li {
  position: relative;
  padding-inline-start: 22px;
  font-size: 13px;
  line-height: 1.75;
  color: var(--wa-text-2);
}
.wa-desk-points li::before {
  content: '';
  position: absolute;
  inset-inline-start: 0;
  top: 8px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--wa-online);
}
.wa-desk-points li.off::before { background: var(--wa-text-2); opacity: 0.45; }

.wa-desk-foot { margin-top: auto; font-size: 11.5px; color: var(--wa-text-2); }
