/* ==========================================================
   قبل وبعد | أثر يمكن رؤيته (.ba-)
   مسار «قبل ← التدخل ← بعد» لكل مؤشر وبرنامج، والمقارنات المصورة.
   في RTL: «قبل» يمينًا، «التدخل» في الوسط، «بعد» يسارًا.
   ========================================================== */

.ba { overflow-wrap: anywhere; }

/* العنوان بجزأين */
.ba-title-sep { display: inline-block; width: 2px; height: .85em; margin-inline: .45em; vertical-align: -.08em; border-radius: 2px; background: var(--brand-200); }
.ba-title-sub { display: inline-block; color: var(--brand-700); }

/* ---------- دليل القراءة ---------- */
.ba-intro { display: grid; gap: 14px; }
.ba-guide {
  display: grid; gap: 14px; padding: 14px; border: 1px solid var(--line); border-radius: var(--radius-lg);
  background: linear-gradient(180deg, var(--surface-2), #fff 90%);
}
@media (min-width: 768px) { .ba-guide { padding: 18px 20px; } }
.ba-guide-steps { display: flex; align-items: stretch; gap: 6px; }
.ba-g {
  flex: 1 1 0; min-width: 0; display: flex; align-items: center; gap: 10px; padding: 10px 12px;
  background: #fff; border: 1px solid var(--line); border-inline-start-width: 4px; border-radius: var(--radius-sm);
}
.ba-g-icon { flex: none; display: grid; place-items: center; width: 34px; height: 34px; border-radius: 10px; }
.ba-g-text { display: grid; min-width: 0; line-height: 1.45; }
.ba-g-text strong { font-size: .98rem; }
.ba-g-text small { font-size: .8rem; color: var(--ink-3); }
.ba-g-before { border-inline-start-color: var(--role-baseline-line); }
.ba-g-before .ba-g-icon { background: var(--role-baseline-bg); color: var(--role-baseline); }
.ba-g-mid { border-inline-start-color: var(--brand-400); }
.ba-g-mid .ba-g-icon { background: var(--brand-50); color: var(--brand-700); }
.ba-g-after { border-inline-start-color: var(--role-actual-line); }
.ba-g-after .ba-g-icon { background: var(--role-actual-bg); color: var(--role-actual); }
.ba-g-arrow { flex: none; display: grid; place-items: center; color: var(--brand-300); }
@media (max-width: 640px) {
  .ba-guide-steps { gap: 4px; }
  .ba-g { flex-direction: column; justify-content: center; gap: 4px; padding: 8px 6px; text-align: center; }
  .ba-g-icon { width: 30px; height: 30px; }
  .ba-g-text small { display: none; }
  .ba-g-arrow .i { width: 14px; height: 14px; }
}
.ba-guide-foot { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 20px; padding-top: 12px; border-top: 1px solid var(--line); }
.ba-guide-note { flex: 1 1 320px; min-width: 0; display: flex; align-items: flex-start; gap: 8px; font-size: .86rem; color: var(--ink-2); line-height: 1.7; }
.ba-guide-note .i { flex: none; margin-top: .25em; color: var(--brand-600); }
.ba-legend { flex: none; }

/* التنقل بين الأقسام */
.ba-jump { gap: 8px; }
.ba-jump .chip { background: #fff; min-height: 36px; }
.ba-count {
  display: inline-grid; place-items: center; min-width: 20px; height: 20px; padding: 0 6px; border-radius: 999px;
  background: var(--surface-3); color: var(--ink-2); font-size: .72rem; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1;
}
.chip.active .ba-count { background: rgba(255, 255, 255, .22); color: #fff; }

/* ---------- الأقسام ---------- */
.ba-section .section-actions { align-self: center; }
.ba-view a { display: inline-flex; align-items: center; gap: 6px; }
.ba-view a:hover { color: var(--brand-800); }
.ba-list { display: grid; gap: 16px; }
@media (min-width: 768px) { .ba-list { gap: 22px; } }

/* ---------- بطاقة «قبل ← بعد» ---------- */
.ba-card { display: grid; gap: 16px; scroll-margin-top: 140px; }
.ba-card-head { display: flex; align-items: flex-start; flex-wrap: wrap; gap: 12px; }
.ba-card-titles { flex: 1; min-width: min(100%, 180px); }
.ba-card-titles a { color: var(--ink); }
.ba-card-titles a:hover { color: var(--brand-700); }
.ba-card-head > .badge { margin-inline-start: auto; }

/* المسار: عمودي على الجوال، أفقي على الشاشات الأوسع */
.ba-flow { display: grid; grid-template-columns: minmax(0, 1fr); gap: 4px; align-items: stretch; }
@media (min-width: 720px) {
  .ba-flow { grid-template-columns: minmax(0, 1fr) 30px minmax(0, 1.35fr) 30px minmax(0, 1fr); gap: 4px; }
}
.ba-arrow { display: grid; place-items: center; color: var(--brand-400); }
@media (max-width: 719px) { .ba-arrow { height: 22px; } .ba-arrow .i { transform: rotate(-90deg); } }

.ba-panel {
  position: relative; display: flex; flex-direction: column; gap: 4px; min-width: 0; padding: 12px 14px;
  border: 1px solid var(--line); border-radius: var(--radius-sm);
}
.ba-kicker { display: inline-flex; align-items: center; gap: 6px; font-size: .76rem; font-weight: 700; color: var(--ink-3); }
.ba-label { display: inline-flex; align-items: center; gap: 6px; font-size: .84rem; font-weight: 600; line-height: 1.5; }
.ba-label .i { flex: none; }
.ba-value { font-size: clamp(1.45rem, 1.25rem + .8vw, 1.9rem); font-weight: 700; line-height: 1.3; color: var(--ink); font-variant-numeric: tabular-nums; }
.ba-panel.is-empty .ba-value, .ba-mid .ba-value { font-size: 1rem; line-height: 1.6; margin-top: 2px; }
.ba-note { font-size: .78rem; color: var(--ink-3); }

.ba-baseline { background: var(--role-baseline-bg); border-color: #dfe5ea; border-inline-start: 4px solid var(--role-baseline-line); }
.ba-baseline .ba-label { color: var(--role-baseline); }
.ba-actual { background: var(--role-actual-bg); border-color: #c4e5de; border-inline-start: 4px solid var(--role-actual-line); }
.ba-actual .ba-label { color: var(--role-actual); }
/* «بعد» غير المرصود: إطار متقطع بلا تعبئة — لا يوحي بنتيجة */
.ba-actual.is-empty { background: #fff; border-style: dashed; border-color: #b9d9d2; border-inline-start-style: solid; }

.ba-mid { background: #fff; border-color: var(--brand-100); gap: 8px; }
.ba-mid .ba-kicker { color: var(--brand-700); }
.ba-mid-text {
  font-size: .9rem; color: var(--ink-2); line-height: 1.7; white-space: pre-line;
  display: -webkit-box; -webkit-line-clamp: 4; -webkit-box-orient: vertical; overflow: hidden;
}
.ba-mid-sub { display: inline-flex; align-items: center; gap: 6px; font-size: .8rem; font-weight: 600; color: var(--ink-3); }
.ba-mid-links { gap: 6px; }
.ba-mid-links .chip { font-size: .8rem; padding: 3px 10px; }
.ba-mid-links .chip .i { color: var(--brand-500); }
.ba-more { font-weight: 700; color: var(--brand-700); }

/* صف النتيجة: مقدار التحسن + المستهدف + الرسم */
.ba-result { display: grid; gap: 14px; padding-top: 16px; border-top: 1px solid var(--line); }
.ba-result-values { display: grid; gap: 8px; grid-template-columns: repeat(auto-fit, minmax(min(100%, 210px), 1fr)); align-content: start; }
.ba-result .rv-value { font-size: 1.15rem; }
.ba-result .rv-empty .rv-value { font-size: 1rem; }
.ba-chart { min-width: 0; padding: 4px 2px 0; }
@media (min-width: 880px) {
  .ba-result.has-chart { grid-template-columns: minmax(0, 1fr) minmax(0, 1.6fr); align-items: center; gap: 28px; }
  .ba-result.has-chart .ba-result-values { grid-template-columns: minmax(0, 1fr); }
}
.ba-foot { margin-top: 0; }

/* ---------- الجدول المختصر ---------- */
.ba-table { min-width: 860px; }
.ba-table th[scope="row"] { min-width: 170px; background: #fff; font-size: .92rem; white-space: normal; position: static; }
.ba-table td { min-width: 120px; }
.ba-t-name { color: var(--ink); font-weight: 700; }
.ba-t-name:hover { color: var(--brand-700); }
.ba-t-sub { display: block; font-size: .78rem; font-weight: 500; color: var(--ink-3); }
.ba-key { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-inline-end: 6px; vertical-align: 0; }
.ba-key-baseline { background: var(--role-baseline-line); }
.ba-key-target { background: var(--role-target-bg); border: 2px dashed var(--role-target-line); }
.ba-key-actual { background: var(--role-actual-line); }
.ba-key-delta { background: var(--role-delta-line); }
.ba-tv {
  display: inline-block; padding: 2px 10px; border-radius: 8px; border: 1px solid; font-weight: 700; line-height: 1.6;
  font-variant-numeric: tabular-nums;
}
.ba-tv-baseline { background: var(--role-baseline-bg); border-color: #dfe5ea; color: var(--ink); }
.ba-tv-target { background: var(--role-target-bg); border-color: var(--role-target-line); border-style: dashed; color: var(--role-target); font-weight: 600; }
.ba-tv-actual { background: var(--role-actual-bg); border-color: #b5ddd5; color: var(--role-actual); }
.ba-table .awaiting { font-size: .78rem; }

/* ---------- المقارنات المصورة ---------- */
.ba-filter { display: flex; align-items: center; gap: 10px; margin-bottom: 18px; min-width: 0; }
.ba-filter-label { flex: none; display: inline-flex; align-items: center; gap: 6px; font-size: .85rem; font-weight: 600; color: var(--ink-3); }
.ba-chips { gap: 6px; min-width: 0; }
.ba-chips .chip { min-height: 36px; padding: 6px 12px; }
@media (max-width: 560px) { .ba-filter { flex-direction: column; align-items: stretch; gap: 8px; } }

/* ---------- انتقل إلى ---------- */
.ba-next { display: grid; gap: 14px; margin-top: 48px; grid-template-columns: repeat(auto-fit, minmax(min(100%, 320px), 1fr)); }
@media (min-width: 768px) { .ba-next { margin-top: 64px; gap: 18px; } }
.ba-next-link { display: flex; align-items: center; gap: 14px; }
.ba-next-text { flex: 1; min-width: 0; display: grid; line-height: 1.5; }
.ba-next-text strong { font-size: 1.02rem; color: var(--ink); }
.ba-next-text small { font-size: .85rem; color: var(--ink-3); }
.ba-next-arrow { flex: none; color: var(--brand-500); transition: transform .25s var(--ease); }
.ba-next-link:hover .ba-next-arrow { transform: translateX(-4px); }

@media print {
  .ba-guide-foot, .ba-jump, .ba-view, .ba-filter, .ba-next { display: none !important; }
  .ba-card { break-inside: avoid; }
}

/* ---------- تحسينات العرض ---------- */
/* بطاقة مقارنة واحدة لا تتمدد إلى عرض الصفحة كاملًا */
.ba-photos { grid-template-columns: repeat(auto-fill, minmax(min(100%, 440px), 1fr)); }
/* تسميات محور الرسم لا تنكسر حرفًا حرفًا عند الحافة */
.ba-chart .ch-axis span, .sd-chart .ch-axis span { white-space: nowrap; }
/* أعمدة قبل/بعد بعرض مريح بدل الامتداد على مساحة واسعة فارغة */
.ba-chart .ch-cols, .sd-chart .ch-cols { max-width: 420px; margin-inline: auto; }

/* الجوال: «قبل» و«بعد» متجاوران للمقارنة السريعة، و«التدخل» تحتهما */
@media (max-width: 719px) {
  .ba-flow { grid-template-columns: minmax(0, 1fr) 20px minmax(0, 1fr); grid-template-areas: "before arrow after" "mid mid mid"; row-gap: 8px; column-gap: 2px; }
  .ba-flow > .ba-baseline { grid-area: before; }
  .ba-flow > .ba-actual { grid-area: after; }
  .ba-flow > .ba-mid { grid-area: mid; }
  .ba-flow > .ba-arrow:nth-child(2) { grid-area: arrow; height: auto; }
  .ba-flow > .ba-arrow:nth-child(2) .i { transform: none; }
  .ba-flow > .ba-arrow:nth-child(4) { display: none; }
  .ba-panel { padding: 10px; }
  .ba-value { font-size: 1.35rem; }
  .ba-panel .awaiting { font-size: .76rem; padding: 2px 8px; }
}
.ba .rv-empty.rv-delta { background: #fff; border-style: dashed; border-inline-start-style: solid; }

/* مراجعة: تباعد أوضح بين كلمات العنوان على الشاشات الصغيرة، ولا كسر للكلمات داخله */
.ba .page-title { overflow-wrap: normal; word-spacing: .06em; }
@media (max-width: 719px) {
  .ba-panel.is-empty .awaiting { border: 0; background: none; padding: 0; line-height: 1.5; }
}
