/* =========================================================
   الشات: قائمة المحادثات وفقاعات الرسائل والمرفقات
   ========================================================= */
/**
 * 🔴 `100%` مش `calc(100vh - رقم)`.
 *
 * كان `calc(100vh - 118px)` — و`118` رقم حد قاسه على مقاس واحد.
 * وأثره على تابلت صلاح (فيديو ١٦ أغسطس ٢٠٢٦): الصفحة كلها بقت أطول
 * من الشاشة، فالترويسة ومربع الكتابة **مايظهروش مع بعض** — تنزّل
 * يروح اسم عمر وأزرار المكالمة، تطلع يروح المربع. وفي الوضع العرضي
 * المربع كان بيقع **تحت شريط أندرويد** فمينفعش يتكتب فيه أصلًا.
 *
 * دلوقتي `.view` هي اللي بتتمرّر وارتفاعها معروف، فـ`100%` بتاخد
 * المتاح مهما كان. و`min-height` اتشالت: كانت بتخلي الغلاف أطول من
 * المتاح على شاشة قصيرة (تابلت بالعرض) — نفس العيب بشكل تاني.
 */
.chat-wrap {
  display: grid;
  grid-template-columns: 300px 1fr;
  gap: 14px;
  height: 100%;
}
.chat-list {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--r);
  overflow-y: auto;
  box-shadow: var(--shadow);
}
.chat-pane {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--r);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: var(--shadow);
}
.chat-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 14px;
  border-bottom: 1px solid var(--border);
  background: var(--card-2);
  flex: 0 0 auto;
}
.chat-body {
  flex: 1;
  overflow-y: auto;
  padding: 14px 18px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  /* خلفية زي واتساب: تينت دافي (رملي) — **مش** أخضر.
     جرّبتها بالأخضر الأول وقستها: فقاعتي الخضرا كانت بتتلاشى فيها
     (تباين ١٫٠١ يعني بلا حدود مرئية) — الخلفية الدافية بتخلي الأخضر
     يبان وحده. */
  background: color-mix(in srgb, var(--bg) 88%, #c9b896 12%);
}
[data-theme='dark'] .chat-body {
  background: color-mix(in srgb, var(--bg) 88%, black 12%);
}
.chat-foot {
  flex: 0 0 auto;
  border-top: 1px solid var(--border);
  padding: 9px 11px;
  display: flex;
  gap: 7px;
  align-items: flex-end;
  background: var(--card-2);
}
.chat-foot textarea {
  min-height: 42px;
  max-height: 130px;
  resize: none;
  margin: 0;
  border-radius: 20px;
  padding: 10px 15px;
}
.conv-item {
  display: flex;
  gap: 10px;
  align-items: center;
  padding: 11px 13px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
}
.conv-item:hover { background: var(--bg-soft); }
.conv-item.active { background: var(--brand-soft); }
/* أفاتار دائري كبير زي قايمة واتساب */
.conv-item .av {
  position: relative;
  font-size: 25px;
  width: 46px;
  height: 46px;
  flex: 0 0 46px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-soft);
  border-radius: 50%;
}
.conv-item .av.on::after {
  content: '';
  position: absolute;
  inset-block-end: 0;
  inset-inline-end: 0;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--ok);
  border: 2px solid var(--card);
}
.conv-item .meta { flex: 1; min-width: 0; }
.conv-item .meta strong { display: block; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv-item .meta span { font-size: 12.5px; color: var(--text-dim); display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* فقاعات نمط واتساب: بتاعتي أخضر فاتح بنص غامق (مش أخضر مصمت)،
   والتانية بيضا — وكل فقاعة ليها ذيل صغير ناحية صاحبها */
.bubble {
  max-width: 78%;
  padding: 7px 12px;
  border-radius: 12px;
  background: var(--card);
  align-self: flex-start;
  border-end-start-radius: 4px;
  position: relative;
  box-shadow: 0 1px 1px rgba(60, 50, 30, 0.1);
}
.bubble::after {
  content: '';
  position: absolute;
  bottom: 0;
  inset-inline-start: -7px;
  width: 11px;
  height: 13px;
  background: inherit;
  clip-path: polygon(0 0, 0 100%, 100% 100%);
}
.bubble.mine {
  align-self: flex-end;
  background: color-mix(in srgb, var(--noor-em, var(--brand)) 26%, var(--card));
  color: var(--text);
  border-end-start-radius: 12px;
  border-end-end-radius: 4px;
}
.bubble.mine::after {
  inset-inline-start: auto;
  inset-inline-end: -7px;
  clip-path: polygon(100% 0, 100% 100%, 0 100%);
}
[data-theme='dark'] .bubble.mine {
  background: color-mix(in srgb, var(--noor-em, var(--brand)) 35%, var(--card));
}
.bubble .who { font-size: 12px; font-weight: 800; margin-bottom: 2px; opacity: 0.95; }
.bubble .txt { white-space: pre-wrap; word-break: break-word; line-height: 1.7; }
.bubble .when { font-size: 10.5px; opacity: 0.7; margin-top: 3px; text-align: end; }
.bubble .reply {
  border-inline-start: 3px solid currentColor;
  padding-inline-start: 8px;
  margin-bottom: 5px;
  font-size: 12.5px;
  opacity: 0.8;
  max-height: 44px;
  overflow: hidden;
}
.bubble img { max-width: 100%; border-radius: 10px; display: block; margin-top: 4px; }
/* الضغطة المطولة بتاخد الأكشنات (msg-actions.js) — بنمنع تحديد النص
   عشان الضغطة الطويلة على أندرويد ماتفتحش تحديد النسخ بتاع النظام */
.bubble { user-select: none; -webkit-user-select: none; }
.sys-msg {
  align-self: center;
  font-size: 12px;
  color: var(--text-dim);
  background: var(--bg-soft);
  padding: 3px 12px;
  border-radius: 999px;
}
.day-sep {
  align-self: center;
  font-size: 11.5px;
  font-weight: 700;
  color: var(--text-dim);
  margin: 8px 0 2px;
}

@media (max-width: 860px) {
  .chat-wrap {
    grid-template-columns: 1fr;
  }
  .chat-wrap.showing-thread .chat-list { display: none; }
  .chat-wrap:not(.showing-thread) .chat-pane { display: none; }
  .bubble { max-width: 88%; }
}

.muted { color: var(--text-soft); }
.dim { color: var(--text-dim); }
.small { font-size: 12.5px; }
.center { text-align: center; }
.nowrap { white-space: nowrap; }
.mt { margin-top: 14px; }
.mb { margin-bottom: 14px; }
.hidden { display: none !important; }

/* الطباعة: التقارير تطلع نضيفة على ورق */
@media print {
  .sidebar,
  .topbar,
  .toasts,
  #scrim,
  button,
  select {
    display: none !important;
  }
  body { background: #fff; color: #000; }
  .view { padding: 0; max-width: none; }
  .card {
    box-shadow: none;
    border: 1px solid #ccc;
    break-inside: avoid;
    page-break-inside: avoid;
  }
  .grid.cols-4 { grid-template-columns: repeat(4, 1fr); }
  .grid.cols-3 { grid-template-columns: repeat(3, 1fr); }
}

.skeleton {
  background: linear-gradient(90deg, var(--bg-soft) 25%, var(--card-2) 50%, var(--bg-soft) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.3s infinite;
  border-radius: var(--r-sm);
  height: 14px;
}
@keyframes shimmer { to { background-position: -200% 0; } }

/* ===== الرسايل الصوتية =====
   الزرار بيتحول عدّاد أحمر بينبض وقت التسجيل — إشارة واضحة
   للولد إن المايك شغال، وضغطة تانية بتبعت على طول. */
.rec-wrap {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.rec-timer {
  font-size: 12.5px;
  font-weight: 800;
  color: #c23a3a;
  min-width: 38px;
  text-align: center;
}
.icon-btn.recording {
  background: #c23a3a;
  color: #fff;
  border-radius: 50%;
  animation: rec-pulse 1.1s ease-in-out infinite;
}
.rec-cancel {
  color: var(--text-dim);
}
@keyframes rec-pulse {
  0%,
  100% {
    box-shadow: 0 0 0 0 rgba(194, 58, 58, 0.45);
  }
  50% {
    box-shadow: 0 0 0 8px rgba(194, 58, 58, 0);
  }
}
@media (prefers-reduced-motion: reduce) {
  .icon-btn.recording {
    animation: none;
  }
}

/* ═══════════════════════════ 📞 المكالمات ═══════════════════════════
 *
 * طبقة فوق كل حاجة: المكالمة بتاخد الشاشة كاملة لأنها **مقاطعة**
 * مش محتوى — الولد مش مفروض يكمّل درس والمكالمة شغالة.
 *
 * ⚠️ و`env(safe-area-inset-*)` ممنوعة في أي ملف CSS غير `base.css`
 * (حارس في `test/frontend.test.js`) — كابستور بيرجّعها صفرًا في
 * الويب‑ڤيو، فبنستخدم `--sa-*` المحقونة من `MainActivity`.
 */
.call-overlay {
  position: fixed;
  inset: 0;
  z-index: 9000;
  display: grid;
  grid-template-rows: 1fr auto;
  background: #000;
  padding-top: var(--sa-top, 0);
  padding-bottom: var(--sa-bottom, 0);
}
.call-stage {
  position: relative;
  overflow: hidden;
}
.call-remote {
  width: 100%;
  height: 100%;
  object-fit: cover;
  background: #111;
}
/* صورتك الصغيرة: في الركن اللي مش بيغطي وش الطرف التاني عادةً */
.call-self {
  position: absolute;
  inset-inline-end: 12px;
  top: 12px;
  width: min(28vw, 140px);
  aspect-ratio: 3 / 4;
  object-fit: cover;
  border-radius: 12px;
  border: 2px solid rgba(255, 255, 255, 0.5);
  background: #222;
}
.call-bar {
  display: grid;
  gap: 6px;
  justify-items: center;
  padding: 16px 12px 22px;
  background: #0b0b0c;
  color: #fff;
}
.call-who {
  font-weight: 800;
  font-size: 19px;
}
.call-state {
  font-size: 13.5px;
  opacity: 0.75;
  min-height: 1.2em;
  text-align: center;
}
.call-actions {
  display: flex;
  gap: 14px;
  margin-top: 8px;
}
.call-btn {
  border: 0;
  border-radius: 999px;
  padding: 13px 26px;
  font-family: inherit;
  font-weight: 800;
  font-size: 15.5px;
  color: #fff;
  cursor: pointer;
}
/* أخضر/أحمر مقصودان: دول أكتر زرارين بيتضغطوا بسرعة وبلا قراءة */
.call-btn.accept {
  background: #0f9d58;
}
.call-btn.hang {
  background: #d93025;
}
.call-buttons {
  display: flex;
  gap: 4px;
}
