/* ميزان — SMART_INTAKE_V1 : أنماط المحادثة المدمجة (Inline Chat — v2)
 * يدمج الأسئلة الموجّهة داخل سجل المحادثة — لا overlay، لا صفحة منفصلة.
 * يُكمل أنماط .bubble-ai / .bubble-user الموجودة بدون تجاوز.
 * RTL كامل · هوية ميزان · وضع داكن (CSS vars) · متجاوب (جوال/تابلت).
 * الأصناف مسبوقة بـ si- لتجنّب أي تعارض. يُزال بحذف الملف والوسم.
 */

/* ═══════════════════════════════════════════════════════════════════════════
   شريط المرحلة — ثابت أعلى #msgs أثناء التمرير
   ═══════════════════════════════════════════════════════════════════════════ */
.si-stage-bar {
  position: sticky;
  top: 0;
  z-index: 10;
  /* نسحب الشريط خارج حشوة #msgs (24px فوق، 26px جانبياً) */
  margin-top: -24px;
  margin-inline: -26px;
  margin-bottom: 4px;
  padding: 9px 26px;
  /* align-self: stretch حتى يمتد بالعرض الكامل داخل العمود المرن */
  align-self: stretch;
  background: rgba(247, 245, 242, 0.94);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line, #E5DDCD);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  flex-wrap: nowrap;
  min-height: 38px;
  user-select: none;
}

.si-stage-item {
  font-size: 12.5px;
  font-weight: 600;
  white-space: nowrap;
  transition: color 0.22s, opacity 0.22s;
}

.si-stage-cur  { color: var(--emerald, #0F4C45); font-weight: 700; }
.si-stage-past { color: var(--emerald, #0F4C45); opacity: 0.55; }
.si-stage-fut  { color: var(--muted, #6E685C); }

.si-stage-sep {
  color: var(--muted, #6E685C);
  font-size: 11px;
  padding: 0 2px;
  opacity: 0.45;
  flex-shrink: 0;
}

.si-stage-done-label {
  font-size: 12.5px;
  font-weight: 700;
  color: var(--emerald, #0F4C45);
}

/* ═══════════════════════════════════════════════════════════════════════════
   كتلة السؤال — حاوية فرعية مرنة تضمّ الفقاعة + الخيارات + إجابة المستخدم
   ═══════════════════════════════════════════════════════════════════════════ */
.si-qblock {
  display: flex;
  flex-direction: column;
  gap: 0;
  /* width:100% لضمان امتداده الكامل داخل العمود المرن لـ #msgs */
  width: 100%;
}

/* ═══════════════════════════════════════════════════════════════════════════
   فقاعة AI — تكملة لـ .bubble-ai الأصلية
   ═══════════════════════════════════════════════════════════════════════════ */
.si-ai-bubble {
  /* يرث تصميم .bubble-ai — هذا الصنف يضيف خصائص إضافية فقط */
  font-size: 15px;
  line-height: 1.85;
}

/* سؤال مُجاب — طباعة مضغوطة قليلاً */
.si-ai-bubble.si-q-compact {
  font-size: 14.5px;
  opacity: 0.88;
}

.si-ai-content p {
  margin: 0;
  line-height: 1.85;
  color: var(--charcoal, #1B1B1B);
}

/* ═══════════════════════════════════════════════════════════════════════════
   رقائق الترحيب (Greeting Chips)
   ═══════════════════════════════════════════════════════════════════════════ */
.si-eg-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 14px;
}

.si-eg-chip {
  display: inline-flex;
  align-items: center;
  cursor: pointer;
  font-family: inherit;
  font-size: 13.5px;
  font-weight: 600;
  padding: 10px 16px;
  min-height: 44px;
  border-radius: 100px;
  border: 1.5px solid var(--line, #E5DDCD);
  background: var(--paper, #F7F5F2);
  color: var(--charcoal, #1B1B1B);
  transition: border-color 0.16s, background 0.16s, transform 0.12s;
}

.si-eg-chip:hover {
  border-color: var(--emerald, #0F4C45);
  background: rgba(15, 76, 69, 0.06);
  transform: translateY(-1px);
}

.si-eg-chip:active {
  transform: translateY(0);
}

.si-eg-chip.si-chip-used,
.si-eg-chip[disabled] {
  opacity: 0.42;
  cursor: default;
  pointer-events: none;
}

/* ═══════════════════════════════════════════════════════════════════════════
   صف الخيارات — أسفل فقاعة السؤال على يسار المحادثة (جانب AI)
   ═══════════════════════════════════════════════════════════════════════════ */
.si-opts-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 10px 0 6px;
  /* يتراصّ على الجانب الأيسر (جانب AI) */
  align-self: flex-start;
  max-width: 82%;
}

/* بعد الإجابة — الخيارات تُخفَّت ولا تُستجاب */
.si-opts-answered {
  opacity: 0.45;
  pointer-events: none;
}

/* ═══════════════════════════════════════════════════════════════════════════
   زر الخيار الفردي
   ═══════════════════════════════════════════════════════════════════════════ */
.si-iopt {
  display: inline-flex;
  align-items: center;
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  padding: 10px 16px;
  min-height: 44px;
  border-radius: 100px;
  border: 1.5px solid var(--line, #E5DDCD);
  background: var(--white, #fff);
  color: var(--charcoal, #1B1B1B);
  cursor: pointer;
  white-space: nowrap;
  transition: border-color 0.15s, background 0.15s, transform 0.1s, color 0.15s, box-shadow 0.15s;
}

.si-iopt:hover:not(:disabled) {
  border-color: rgba(15, 76, 69, 0.5);
  background: rgba(15, 76, 69, 0.04);
  transform: translateY(-1px);
}

.si-iopt:active:not(:disabled) {
  transform: translateY(0);
}

.si-iopt.si-iopt-selected {
  border-color: var(--emerald, #0F4C45);
  background: rgba(15, 76, 69, 0.07);
  color: var(--emerald, #0F4C45);
  box-shadow: 0 0 0 3px rgba(15, 76, 69, 0.09);
}

/* "حالتي مختلفة" — حد منقّط */
.si-iopt.si-iopt-special {
  border-style: dashed;
  color: var(--emerald, #0F4C45);
}

.si-iopt.si-iopt-special:hover:not(:disabled) {
  background: rgba(15, 76, 69, 0.05);
  border-color: var(--emerald, #0F4C45);
  border-style: dashed;
}

.si-iopt:disabled {
  cursor: default;
  pointer-events: none;
}

/* ═══════════════════════════════════════════════════════════════════════════
   غلاف إجابة المستخدم — يجمع الفقاعة وزر التعديل أفقياً
   ═══════════════════════════════════════════════════════════════════════════ */
/* .msg.user.si-ans-wrap يرث align-self:flex-end من .msg.user → يتراص يميناً */
.si-ans-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  max-width: 88%; /* أوسع قليلاً لاستيعاب زر التعديل */
}

/* ═══════════════════════════════════════════════════════════════════════════
   زر تعديل الإجابة
   ═══════════════════════════════════════════════════════════════════════════ */
.si-edit-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  align-self: center;
  font-family: inherit;
  font-size: 12px;
  font-weight: 600;
  padding: 5px 12px;
  min-height: 30px;
  border-radius: 100px;
  border: 1.2px solid var(--line, #E5DDCD);
  background: transparent;
  color: var(--emerald, #0F4C45);
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s, border-color 0.15s;
}

.si-edit-btn:hover {
  background: rgba(15, 76, 69, 0.07);
  border-color: var(--emerald, #0F4C45);
}

/* ═══════════════════════════════════════════════════════════════════════════
   ملاحظة التعديل — تنبيه مؤقت يظهر أثناء التعديل
   ═══════════════════════════════════════════════════════════════════════════ */
.si-edit-note {
  font-size: 12.5px;
  line-height: 1.7;
  color: var(--muted, #6E685C);
  background: rgba(201, 162, 39, 0.08);
  border: 1px solid rgba(201, 162, 39, 0.28);
  border-radius: 10px;
  padding: 7px 13px;
  margin-bottom: 8px;
  align-self: flex-start;
  animation: si-fade-in 0.25s ease;
}

/* ═══════════════════════════════════════════════════════════════════════════
   حقل الإجابة المخصصة (custom)
   ═══════════════════════════════════════════════════════════════════════════ */
.si-custom-host {
  align-self: flex-start;
  max-width: 82%;
  margin-top: 6px;
  animation: si-fade-in 0.25s ease;
}

.si-custom-ta {
  display: block;
  width: 100%;
  min-height: 80px;
  resize: vertical;
  padding: 12px 14px;
  border-radius: 14px;
  font-family: inherit;
  font-size: 14.5px;
  line-height: 1.7;
  border: 1.5px solid var(--line, #E5DDCD);
  background: var(--white, #fff);
  color: var(--charcoal, #1B1B1B);
  margin-bottom: 10px;
  transition: border-color 0.18s, box-shadow 0.18s;
}

.si-custom-ta:focus {
  outline: none;
  border-color: var(--emerald, #0F4C45);
  box-shadow: 0 0 0 3px rgba(15, 76, 69, 0.1);
}

/* ═══════════════════════════════════════════════════════════════════════════
   الأزرار — أساسي / شبح
   ═══════════════════════════════════════════════════════════════════════════ */
.si-btn-primary,
.si-custom-ok {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-family: inherit;
  font-weight: 700;
  font-size: 14.5px;
  padding: 12px 22px;
  min-height: 44px;
  border-radius: 13px;
  border: 1.5px solid transparent;
  background: var(--emerald, #0F4C45);
  color: #fff;
  cursor: pointer;
  transition: background 0.18s, transform 0.12s, box-shadow 0.18s;
}

.si-btn-primary:hover:not(:disabled),
.si-custom-ok:hover:not(:disabled) {
  background: var(--emerald-l, #1C6056);
  transform: translateY(-1px);
  box-shadow: 0 8px 22px -8px rgba(15, 76, 69, 0.55);
}

.si-btn-primary:active:not(:disabled),
.si-custom-ok:active:not(:disabled) {
  transform: translateY(0);
}

.si-btn-primary:disabled,
.si-custom-ok:disabled {
  opacity: 0.6;
  cursor: default;
  pointer-events: none;
}

.si-btn-ghost {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-family: inherit;
  font-weight: 600;
  font-size: 14.5px;
  padding: 12px 22px;
  min-height: 44px;
  border-radius: 13px;
  border: 1.5px solid var(--line, #E5DDCD);
  background: transparent;
  color: var(--emerald, #0F4C45);
  cursor: pointer;
  transition: border-color 0.18s, background 0.18s;
}

.si-btn-ghost:hover:not(:disabled) {
  border-color: var(--emerald, #0F4C45);
  background: rgba(15, 76, 69, 0.05);
}

.si-btn-ghost:disabled {
  opacity: 0.6;
  cursor: default;
  pointer-events: none;
}

/* ═══════════════════════════════════════════════════════════════════════════
   عرض المستندات
   ═══════════════════════════════════════════════════════════════════════════ */
.si-doc-btns {
  display: flex;
  flex-wrap: wrap;
  gap: 9px;
  margin-top: 14px;
}

.si-doc-btn {
  display: inline-flex;
  align-items: center;
  font-family: inherit;
  font-size: 13.5px;
  font-weight: 600;
  padding: 10px 18px;
  min-height: 44px;
  border-radius: 100px;
  border: 1.5px solid transparent;
  background: var(--emerald, #0F4C45);
  color: #fff;
  cursor: pointer;
  transition: background 0.18s, transform 0.12s;
}

.si-doc-btn:hover:not(:disabled) {
  background: var(--emerald-l, #1C6056);
  transform: translateY(-1px);
}

.si-doc-btn:disabled {
  opacity: 0.5;
  cursor: default;
  pointer-events: none;
}

/* المستند الشبح */
.si-doc-ghost {
  background: transparent;
  color: var(--emerald, #0F4C45);
  border-color: var(--line, #E5DDCD);
}

.si-doc-ghost:hover:not(:disabled) {
  background: rgba(15, 76, 69, 0.05);
  border-color: var(--emerald, #0F4C45);
  transform: translateY(-1px);
}

/* شارة ملف مرفق */
.si-att-file {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 13px;
  font-weight: 600;
  padding: 5px 11px;
  border-radius: 9px;
  background: rgba(15, 76, 69, 0.07);
  border: 1px solid var(--line, #E5DDCD);
  color: var(--charcoal, #1B1B1B);
  margin-top: 6px;
  margin-inline-end: 6px;
}

/* ═══════════════════════════════════════════════════════════════════════════
   بطاقة المراجعة — فقاعة AI أوسع بملخص وأزرار
   ═══════════════════════════════════════════════════════════════════════════ */
.si-review-bubble {
  /* تُطبَّق على عنصر .bubble-ai — يُوسَّع المحتوى الداخلي */
  font-size: 15px;
  line-height: 1.85;
}

.si-review-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--emerald, #0F4C45);
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 1.5px solid var(--line, #E5DDCD);
}

.si-rv-rows {
  display: flex;
  flex-direction: column;
  margin-bottom: 14px;
}

.si-rv-row {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 11px 0;
  border-bottom: 1px solid var(--line, #E5DDCD);
}

.si-rv-row:last-child {
  border-bottom: none;
}

.si-rv-label {
  flex: 0 0 110px;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--muted, #6E685C);
  padding-top: 2px;
  line-height: 1.6;
}

.si-rv-value {
  flex: 1;
  font-size: 14.5px;
  font-weight: 600;
  color: var(--charcoal, #1B1B1B);
  line-height: 1.65;
}

.si-rv-edit {
  flex: 0 0 auto;
  font-family: inherit;
  font-size: 11.5px;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: 8px;
  border: none;
  background: transparent;
  color: var(--emerald, #0F4C45);
  cursor: pointer;
  transition: background 0.15s;
  white-space: nowrap;
}

.si-rv-edit:hover {
  background: rgba(15, 76, 69, 0.08);
}

.si-rv-note {
  font-size: 12.5px;
  line-height: 1.75;
  color: var(--muted, #6E685C);
  background: rgba(201, 162, 39, 0.07);
  border: 1px solid rgba(201, 162, 39, 0.25);
  border-radius: 12px;
  padding: 10px 14px;
  margin-bottom: 16px;
}

.si-rv-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
}

/* ═══════════════════════════════════════════════════════════════════════════
   الفاصل — شريط نصّي بين مراحل المحادثة
   ═══════════════════════════════════════════════════════════════════════════ */
.si-divider {
  align-self: stretch;
  text-align: center;
  font-size: 11.5px;
  font-weight: 700;
  letter-spacing: 0.4px;
  color: var(--muted, #6E685C);
  position: relative;
  padding: 5px 0;
}

.si-divider::before,
.si-divider::after {
  content: '';
  position: absolute;
  top: 50%;
  width: calc(50% - 68px);
  height: 1px;
  background: var(--line, #E5DDCD);
}

.si-divider::before { right: 0; }
.si-divider::after  { left: 0; }

.si-divider-review {
  color: var(--emerald, #0F4C45);
}

.si-divider-review::before,
.si-divider-review::after {
  background: rgba(15, 76, 69, 0.28);
}

/* ═══════════════════════════════════════════════════════════════════════════
   نقاط الكتابة الآلية
   ═══════════════════════════════════════════════════════════════════════════ */
.si-typing-dots {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  margin-top: 10px;
}

.si-typing-dots i {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--emerald, #0F4C45);
  opacity: 0.45;
  animation: si-bounce 1.2s infinite;
  font-style: normal;
}

.si-typing-dots i:nth-child(2) { animation-delay: 0.15s; }
.si-typing-dots i:nth-child(3) { animation-delay: 0.30s; }

@keyframes si-bounce {
  0%, 60%, 100% { transform: translateY(0);   opacity: 0.45; }
  30%            { transform: translateY(-5px); opacity: 1;    }
}

/* ═══════════════════════════════════════════════════════════════════════════
   الحركات
   ═══════════════════════════════════════════════════════════════════════════ */
@keyframes si-fade-in {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: none; }
}

/* ═══════════════════════════════════════════════════════════════════════════
   الوضع الداكن — تُعيد تعريف ألوان الـ rgba لأن CSS vars لا تغطيها كلها
   (ملاحظة: كثير من الأصناف تستخدم var(--charcoal/--line/--white/--muted)
    التي تتغيّر تلقائيًا في الوضع الداكن عبر تعريفات :root في HTML)
   ═══════════════════════════════════════════════════════════════════════════ */
[data-theme="dark"] .si-stage-bar {
  background: rgba(14, 18, 16, 0.94);
  border-bottom-color: var(--line, #2C2926);
}

[data-theme="dark"] .si-stage-cur  { color: #33B79C; }
[data-theme="dark"] .si-stage-past { color: #33B79C; }
[data-theme="dark"] .si-stage-done-label { color: #33B79C; }

[data-theme="dark"] .si-eg-chip {
  background: #162925;
  color: #eef4f2;
  border-color: #22403a;
}
[data-theme="dark"] .si-eg-chip:hover {
  border-color: #33B79C;
  background: #1a322d;
}

[data-theme="dark"] .si-iopt {
  background: #162925;
  color: #eef4f2;
  border-color: #22403a;
}
[data-theme="dark"] .si-iopt:hover:not(:disabled) {
  background: #1a322d;
  border-color: #33B79C;
}
[data-theme="dark"] .si-iopt.si-iopt-selected {
  background: rgba(51, 183, 156, 0.15);
  border-color: #33B79C;
  color: #33B79C;
  box-shadow: 0 0 0 3px rgba(51, 183, 156, 0.12);
}
[data-theme="dark"] .si-iopt.si-iopt-special {
  color: #33B79C;
}

[data-theme="dark"] .si-edit-btn {
  color: #33B79C;
  border-color: #22403a;
}
[data-theme="dark"] .si-edit-btn:hover {
  background: rgba(51, 183, 156, 0.1);
  border-color: #33B79C;
}

[data-theme="dark"] .si-edit-note {
  background: rgba(230, 195, 90, 0.08);
  border-color: rgba(230, 195, 90, 0.28);
}

[data-theme="dark"] .si-custom-ta {
  background: #0f1f1c;
  color: #eef4f2;
  border-color: #22403a;
}
[data-theme="dark"] .si-custom-ta:focus {
  border-color: #33B79C;
  box-shadow: 0 0 0 3px rgba(51, 183, 156, 0.14);
}

[data-theme="dark"] .si-btn-primary,
[data-theme="dark"] .si-custom-ok {
  background: #0F4C45;
}
[data-theme="dark"] .si-btn-primary:hover:not(:disabled),
[data-theme="dark"] .si-custom-ok:hover:not(:disabled) {
  background: #1C6056;
}

[data-theme="dark"] .si-btn-ghost {
  color: #33B79C;
  border-color: #22403a;
}
[data-theme="dark"] .si-btn-ghost:hover:not(:disabled) {
  border-color: #33B79C;
  background: rgba(51, 183, 156, 0.08);
}

[data-theme="dark"] .si-doc-btn { background: #0F4C45; }
[data-theme="dark"] .si-doc-btn:hover:not(:disabled) { background: #1C6056; }
[data-theme="dark"] .si-doc-ghost {
  background: transparent;
  color: #33B79C;
  border-color: #22403a;
}
[data-theme="dark"] .si-doc-ghost:hover:not(:disabled) {
  background: rgba(51, 183, 156, 0.08);
  border-color: #33B79C;
}

[data-theme="dark"] .si-att-file {
  background: rgba(51, 183, 156, 0.1);
  border-color: #22403a;
}

[data-theme="dark"] .si-review-title {
  color: #33B79C;
  border-bottom-color: #22403a;
}
[data-theme="dark"] .si-rv-row    { border-bottom-color: #22403a; }
[data-theme="dark"] .si-rv-edit   { color: #33B79C; }
[data-theme="dark"] .si-rv-edit:hover { background: rgba(51, 183, 156, 0.1); }
[data-theme="dark"] .si-rv-note {
  background: rgba(230, 195, 90, 0.07);
  border-color: rgba(230, 195, 90, 0.25);
}

[data-theme="dark"] .si-divider-review { color: #33B79C; }
[data-theme="dark"] .si-divider-review::before,
[data-theme="dark"] .si-divider-review::after {
  background: rgba(51, 183, 156, 0.3);
}
[data-theme="dark"] .si-divider::before,
[data-theme="dark"] .si-divider::after {
  background: #22403a;
}

[data-theme="dark"] .si-typing-dots i { background: #33B79C; }

/* ═══════════════════════════════════════════════════════════════════════════
   متجاوب — جوال (≤ 560px)
   ═══════════════════════════════════════════════════════════════════════════ */
@media (max-width: 560px) {
  .si-stage-bar {
    padding: 7px 16px;
    gap: 3px;
  }
  .si-stage-item,
  .si-stage-cur,
  .si-stage-past,
  .si-stage-fut { font-size: 11.5px; }

  .si-opts-row {
    gap: 7px;
    max-width: 100%;
  }
  .si-iopt {
    font-size: 13.5px;
    padding: 9px 13px;
  }

  .si-custom-host { max-width: 100%; }

  .si-rv-row { flex-wrap: wrap; }
  .si-rv-label { flex: 0 0 100%; margin-bottom: 2px; }

  .si-rv-actions {
    flex-direction: column;
    align-items: stretch;
  }
  .si-btn-primary,
  .si-btn-ghost,
  .si-custom-ok {
    width: 100%;
    justify-content: center;
  }

  .si-ans-wrap { max-width: 94%; }
}

/* ═══════════════════════════════════════════════════════════════════════════
   متجاوب — تابلت (561px – 900px)
   ═══════════════════════════════════════════════════════════════════════════ */
@media (min-width: 561px) and (max-width: 900px) {
  .si-opts-row  { max-width: 88%; }
  .si-custom-host { max-width: 88%; }
}
