/* ═══════════ وصلة — التنسيق العام ═══════════ */
:root {
  --green: #2e7d32;
  --green-dark: #1b5e20;
  --green-light: #e8f5e9;
  --red: #d32f2f;
  --bg: #f6f8f6;
  --card: #ffffff;
  --text: #1c2b1c;
  --muted: #6b7c6b;
  --bubble-me: #d5f0d6;
  --bubble-them: #ffffff;
  --radius: 18px;
  --shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
  --pill: #eef2ee;          /* سطح حبة الكتابة، أفتح قليلاً من الشريط الأبيض */
  --pill-border: #dbe4db;   /* حدّ خفيف للحبة والبطاقات المنبثقة */
  --muted-ic: #5f6f5f;      /* لون الأيقونات الصغيرة داخل الحبة */
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  /* مكدّس خطوط عابر للمنصات: على أندرويد كان يسقط إلى Noto Naskh (نسخ تقليدي)
     لغياب Segoe UI وTahoma، فيبدو التطبيق مختلفاً تماماً عن الحاسوب.
     system-ui يعطي Segoe UI على ويندوز وRoboto على أندرويد، والعربية
     تُصيَّر بـ Noto Sans Arabic الحديث بدل النسخ التقليدي. */
  font-family: system-ui, -apple-system, "Segoe UI", Roboto,
               "Noto Sans Arabic", "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  overscroll-behavior: none;
}

.hidden { display: none !important; }

/* ─────────── الشاشات ─────────── */
.screen {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  max-width: 720px;
  margin: 0 auto;
}

/* ─────────── الشريط العلوي ─────────── */
.topbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  padding-top: calc(12px + env(safe-area-inset-top));
  background: var(--green);
  color: #fff;
  box-shadow: var(--shadow);
  z-index: 5;
}
.topbar h1 { font-size: 1.25rem; flex: 1; }
/* اسم المحادثة وتحته حالة الاتصال */
.chat-head { flex: 1; min-width: 0; }
.chat-head h1 { flex: none; line-height: 1.25; }
.chat-presence {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 0.74rem;
  opacity: 0.85;
  margin-top: 1px;
}
.chat-presence .dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: currentColor;
  flex-shrink: 0;
}
.chat-presence.is-online .dot { background: #6dd66d; }

/* نفس المؤشر داخل لوحة الإدارة */
.presence-line { display: flex; align-items: center; gap: 5px; }
.presence-line .dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--muted); flex-shrink: 0;
}
.presence-line.is-online { color: var(--green); font-weight: 600; }
.presence-line.is-online .dot { background: var(--green); }

/* دليل الحسابات (المسؤول العام) */
#dir-filter { margin-bottom: 8px; }
.dir-row { cursor: pointer; }
.dir-status {
  font-size: 0.78rem;
  color: var(--green);
  font-weight: 600;
  flex-shrink: 0;
  text-align: center;
}
.topbar-actions { display: flex; gap: 8px; }

/* ─────────── الأزرار ─────────── */
button {
  font-family: inherit;
  font-size: 1rem;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.btn-primary {
  background: var(--green);
  color: #fff;
  padding: 14px 20px;
  font-size: 1.1rem;
  font-weight: 600;
  width: 100%;
}
.btn-primary:active { background: var(--green-dark); }

.btn-danger {
  background: var(--red);
  color: #fff;
  padding: 14px 20px;
  font-size: 1.1rem;
  font-weight: 600;
  width: 100%;
}

.btn-big { font-size: 1.3rem; padding: 18px 24px; }
.btn-small { width: auto; padding: 10px 18px; font-size: 1rem; }

.btn-link {
  background: none;
  color: var(--green);
  text-decoration: underline;
  padding: 12px;
  width: 100%;
}

.btn-icon {
  background: rgba(255, 255, 255, 0.15);
  font-size: 1.5rem;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.composer .btn-icon, .recording-bar .btn-icon { background: var(--green-light); }

.btn-emergency {
  background: var(--red);
  font-size: 1.5rem;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  animation: pulse 2s infinite;
}
@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(211, 47, 47, 0.5); }
  50% { box-shadow: 0 0 0 8px rgba(211, 47, 47, 0); }
}


.fab {
  position: absolute;
  bottom: calc(24px + env(safe-area-inset-bottom));
  inset-inline-end: 24px;
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: var(--green);
  color: #fff;
  font-size: 1.8rem;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.25);
}

/* ─────────── تسجيل الدخول ─────────── */
#screen-auth {
  justify-content: center;
  align-items: center;
  padding: 24px;
}
/* مبدّل اللغة في شاشة الدخول: أيقونة 🌐 بارزة أعلى الشاشة + قائمة */
.lang-switch {
  position: absolute;
  top: calc(14px + env(safe-area-inset-top));
  inset-inline-end: 14px;
  z-index: 30;
}
.lang-btn {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  background: var(--card);
  border: 1px solid var(--pill-border);
  box-shadow: var(--shadow);
  font-size: 1.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
}
.lang-btn:active { background: var(--green-light); }
.lang-menu {
  position: absolute;
  top: calc(100% + 6px);
  inset-inline-end: 0;
  min-width: 160px;
  background: var(--card);
  border: 1px solid var(--pill-border);
  border-radius: 14px;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.18);
  overflow: hidden;
}
.lang-menu button {
  display: block;
  width: 100%;
  text-align: start;
  padding: 13px 18px;
  background: transparent;
  color: var(--text);
  font-size: 1.05rem;
}
.lang-menu button + button { border-top: 1px solid var(--pill-border); }
.lang-menu button:hover { background: var(--green-light); }
.lang-menu button.active {
  background: var(--green-light);
  color: var(--green-dark);
  font-weight: 700;
}

.auth-box {
  width: 100%;
  max-width: 380px;
  background: var(--card);
  border-radius: 24px;
  padding: 32px 24px;
  box-shadow: var(--shadow);
  text-align: center;
}
.auth-logo { width: 84px; height: 84px; border-radius: 22px; }
.auth-box h1 { color: var(--green); margin: 8px 0 2px; }
.auth-subtitle { color: var(--muted); margin-bottom: 20px; }

input, select, textarea {
  font-family: inherit;
  font-size: 1.05rem;
  width: 100%;
  padding: 14px;
  margin-bottom: 12px;
  border: 2px solid #dde5dd;
  border-radius: var(--radius);
  background: #fff;
  color: var(--text);
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--green); }

.error-box {
  background: #fdecea;
  color: var(--red);
  padding: 12px;
  border-radius: var(--radius);
  margin-bottom: 12px;
  font-size: 0.95rem;
}

/* ─────────── القوائم ─────────── */
.list { flex: 1; overflow-y: auto; padding: 12px; }
.pad { flex: 1; overflow-y: auto; padding: 16px; }
.hint { color: var(--muted); font-size: 0.9rem; margin-bottom: 12px; }

.list-item {
  display: flex;
  align-items: center;
  gap: 14px;
  background: var(--card);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 10px;
  box-shadow: var(--shadow);
  cursor: pointer;
  border: 3px solid transparent;
}
.list-item:active { background: var(--green-light); }
.list-item.selected { border-color: var(--green); background: var(--green-light); }

.avatar {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: var(--green);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.4rem;
  font-weight: 700;
  flex-shrink: 0;
}
.avatar.group { background: #7b1fa2; }

/* صورة شخصية: تملأ الدائرة نفسها بأبعاد ثابتة أينما ظهرت */
.avatar.has-photo { background: var(--pill); overflow: hidden; }
.avatar.has-photo img {
  width: 100%;
  height: 100%;
  object-fit: cover;      /* يمنع التمدّد المشوّه مهما كانت نسبة الأصل */
  display: block;
}

/* صورة الطرف الآخر في رأس شاشة المحادثة (أصغر من صفوف القائمة) */
.chat-avatar .avatar { width: 36px; height: 36px; font-size: 1rem; }

/* قسم الصورة في الإعدادات */
.avatar-setting {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 6px;
}
.avatar-preview .avatar { width: 84px; height: 84px; font-size: 2.1rem; }
.avatar-controls { flex: 1; min-width: 0; }
.avatar-label { font-weight: 600; }
.avatar-buttons { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 6px; }

.item-body { flex: 1; min-width: 0; }
.item-title { font-weight: 700; font-size: 1.05rem; }
.item-sub {
  color: var(--muted);
  font-size: 0.9rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.item-time { color: var(--muted); font-size: 0.8rem; flex-shrink: 0; }

.empty-state {
  text-align: center;
  color: var(--muted);
  padding: 48px 24px;
  font-size: 1.05rem;
  line-height: 2;
}
.empty-state .big { font-size: 3rem; }

/* ─────────── الرسائل ─────────── */
.messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.msg {
  position: relative;
  max-width: 80%;
  padding: 10px 14px;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  word-wrap: break-word;
}

/* ─────────── التفاعلات بالإيموجي ─────────── */
/* رقائق التفاعل ملتصقة بزاوية الفقاعة السفلية */
.msg:has(.reactions) { margin-bottom: 14px; }
.reactions {
  position: absolute;
  bottom: -12px;
  inset-inline-start: 8px;
  display: flex;
  gap: 4px;
  z-index: 2;
}
.msg.me .reactions { inset-inline-start: auto; inset-inline-end: 8px; }
.reaction-chip {
  background: var(--card);
  border: 1px solid var(--pill-border);
  border-radius: 999px;
  padding: 1px 7px;
  font-size: 0.9rem;
  line-height: 1.5;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12);
  display: flex;
  align-items: center;
  gap: 2px;
  font-variant-numeric: tabular-nums;
}
.reaction-chip.mine { background: var(--green-light); border-color: var(--green); font-weight: 700; }

/* شريط اختيار الإيموجي عند الضغط المطول */
/* ─────────── شاشة المكالمة ─────────── */
.call-screen {
  position: fixed;
  inset: 0;
  z-index: 90;
  background: linear-gradient(160deg, #1b5e20, #2e7d32 55%, #14331a);
  color: #fff;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 32px 20px calc(40px + env(safe-area-inset-bottom));
  text-align: center;
}
.call-avatar {
  width: 110px;
  height: 110px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.15);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 3.2rem;
  margin-bottom: 12px;
}
.call-name { font-size: 1.7rem; font-weight: 700; }
.call-kind-label { font-size: 0.95rem; opacity: 0.75; }
.call-status { font-size: 1rem; opacity: 0.9; margin-top: 6px; }
.call-timer {
  font-size: 1.25rem;
  font-variant-numeric: tabular-nums;
  margin-top: 4px;
  letter-spacing: 1px;
}
.call-actions {
  display: flex;
  gap: 26px;
  margin-top: auto;
  padding-top: 36px;
}
.call-btn {
  width: 68px;
  height: 68px;
  border-radius: 50%;
  font-size: 1.7rem;
  background: rgba(255, 255, 255, 0.2);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
}
.call-btn.accept { background: #2ecc71; }
.call-btn.output { background: rgba(255, 255, 255, 0.2); }

/* ─── السحب للرد/الرفض ─── */
.call-swipe { width: 100%; max-width: 340px; margin-top: auto; padding-top: 30px; }
.swipe-track {
  position: relative;
  direction: ltr;                 /* ثابت الاتجاه: السحب نحو ✅ يميناً دائماً حتى بالعربية */
  height: 76px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.14);
  border: 1px solid rgba(255, 255, 255, 0.25);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 18px;
  overflow: hidden;
  /* بلا انتقال: التلوين يتبع الإصبع لحظياً أثناء السحب */
}
.swipe-side { font-size: 1.5rem; opacity: 0.85; user-select: none; }
.swipe-handle {
  position: absolute;
  left: 50%;
  margin-left: -32px;             /* توسيط المقبض */
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: #fff;
  color: #1b5e20;
  font-size: 1.6rem;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 3px 12px rgba(0, 0, 0, 0.3);
  cursor: grab;
  touch-action: none;             /* السحب لا يمرّر الصفحة */
  user-select: none;
}
.swipe-handle:active { cursor: grabbing; }
.swipe-hint {
  text-align: center;
  font-size: 0.85rem;
  opacity: 0.75;
  margin-top: 10px;
}

/* ─── قائمة مخرج الصوت ─── */
.output-menu {
  position: absolute;
  bottom: calc(120px + env(safe-area-inset-bottom));
  background: var(--card);
  color: var(--text);
  border-radius: 14px;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.3);
  overflow: hidden;
  min-width: 200px;
  z-index: 5;
}
.output-item {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 14px 16px;
  background: transparent;
  color: var(--text);
  font-size: 1rem;
  text-align: start;
}
.output-item + .output-item { border-top: 1px solid var(--pill-border); }
.output-ic { font-size: 1.45rem; width: 30px; text-align: center; flex-shrink: 0; }
.output-label { flex: 1; }
/* ✓ للخيار العامل حالياً — مخفية للبقية ليبقى الاصطفاف ثابتاً */
.output-check { color: var(--green); font-weight: 800; font-size: 1.15rem; visibility: hidden; }
.output-item.active { background: var(--green-light); color: var(--green-dark); font-weight: 700; }
.output-item.active .output-check { visibility: visible; }
.call-btn.hangup { background: var(--red); transform: rotate(135deg); }
.call-btn.mute.is-muted { background: #fff; color: var(--red); }
.call-btn:active { filter: brightness(1.15); }

/* سجل المكالمة داخل المحادثة */
.msg.call-log { background: var(--pill); border: 1px dashed var(--pill-border); }
.call-log-body { display: flex; align-items: center; gap: 10px; text-align: start; }
.call-log-ic { font-size: 1.4rem; }
.call-log-sub { font-size: 0.85rem; color: var(--muted); }

/* قائمة خيارات الرسالة (ضغط مطول): صف تفاعلات + قائمة إجراءات */
.msg-menu {
  position: fixed;
  z-index: 60;
  max-width: min(300px, calc(100vw - 16px));
  background: var(--card);
  border: 1px solid var(--pill-border);
  border-radius: 18px;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.22);
  overflow: hidden;
}
.reaction-bar {
  display: flex;
  gap: 4px;
  padding: 6px 8px;
  border-bottom: 1px solid var(--pill-border);
}
.msg-actions { padding: 4px; }
.msg-action {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 11px 14px;
  border-radius: 12px;
  background: transparent;
  color: var(--text);
  font-size: 1rem;
  text-align: start;
}
.msg-action:active { background: var(--green-light); }
.msg-action.danger { color: var(--red); }
.msg-action.danger:active { background: #fff5f5; }
.msg-action-ic { font-size: 1.1rem; width: 22px; text-align: center; flex-shrink: 0; }

/* الاقتباس داخل الفقاعة */
.reply-quote {
  display: block;
  border-inline-start: 3px solid var(--green);
  background: rgba(0, 0, 0, 0.05);
  border-radius: 10px;
  padding: 6px 9px;
  margin-bottom: 6px;
  cursor: pointer;
  max-width: 100%;
}
.msg.me .reply-quote { background: rgba(0, 0, 0, 0.07); }
.reply-quote-name {
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--green-dark);
  margin-bottom: 1px;
}
.reply-quote-text {
  font-size: 0.85rem;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  word-break: break-word;
}

/* وميض عند الانتقال إلى الرسالة الأصلية */
.msg.flash { animation: msgFlash 1.6s ease; }
@keyframes msgFlash {
  0%, 100% { box-shadow: var(--shadow); }
  25% { box-shadow: 0 0 0 3px var(--green), 0 0 18px 4px rgba(46, 125, 50, 0.35); }
}

/* شريط الرد فوق حقل الكتابة */
.reply-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  background: var(--card);
  border-top: 1px solid var(--pill-border);
  border-inline-start: 4px solid var(--green);
}
.reply-bar-body { flex: 1; min-width: 0; }
.reply-bar-name { font-size: 0.82rem; font-weight: 700; color: var(--green-dark); }
.reply-bar-text {
  font-size: 0.88rem;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.reply-cancel {
  flex-shrink: 0;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: transparent;
  color: var(--muted);
  font-size: 1rem;
}
.reply-cancel:active { background: var(--pill); }
.reaction-bar button {
  background: transparent;
  font-size: 1.7rem;
  line-height: 1;
  padding: 4px;
  border-radius: 50%;
  transition: transform .1s;
}
.reaction-bar button:active { transform: scale(1.3); background: var(--green-light); }

/* الحضن الدافئ 🫂: توهّج برتقالي هادئ (دفء عائلي، لا طابع آخر) + حضن يطفو */
.msg.hugged { animation: hugGlow 1.5s ease; }
@keyframes hugGlow {
  0%, 100% { box-shadow: var(--shadow); }
  30% { box-shadow: 0 0 0 3px rgba(46, 125, 50, 0.22), 0 0 24px 7px rgba(240, 170, 90, 0.5); }
}
.hug-float {
  position: absolute;
  top: -4px;
  inset-inline-start: 50%;
  font-size: 2.4rem;
  pointer-events: none;
  z-index: 3;
  animation: hugRise 1.6s ease-out forwards;
}
@keyframes hugRise {
  0% { opacity: 0; transform: translate(-50%, 12px) scale(0.6); }
  22% { opacity: 1; transform: translate(-50%, -6px) scale(1.2); }
  100% { opacity: 0; transform: translate(-50%, -64px) scale(1); }
}

/* علامات الإرسال/التسليم/القراءة */
.ticks { font-size: 0.75rem; margin-inline-start: 4px; color: var(--muted); letter-spacing: -2px; }
.ticks.read { color: #2196f3; }
.read-time { font-size: 0.7rem; color: #2196f3; }

/* زر حذف الرسالة (يظهر فقط عندما يسمح الإعداد) */
/* الصور: زر تحميل عائم + مؤشر نقر */
.img-wrap { position: relative; display: inline-block; }
.img-wrap img.photo { cursor: pointer; }
.img-dl {
  position: absolute;
  bottom: 8px;
  inset-inline-end: 8px;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.55);
  color: #fff;
  font-size: 1rem;
  padding: 0;
}
.img-dl:active { background: rgba(0, 0, 0, 0.8); }

/* عارض الصور بالحجم الكامل */
.lightbox-box {
  background: var(--card);
  border-radius: 20px;
  padding: 14px;
  max-width: min(94vw, 900px);
  text-align: center;
}
#lightbox-img {
  max-width: 100%;
  max-height: 72vh;
  object-fit: contain;
  border-radius: 12px;
}
.btn-link-download {
  display: flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  width: 100%;
}

/* بطاقة ملف مرفق */
.file-card {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--green-light);
  border-radius: 12px;
  padding: 10px 12px;
  text-decoration: none;
  color: var(--text);
  max-width: 260px;
}
.file-card .file-icon { font-size: 1.7rem; flex-shrink: 0; }
.file-card .file-meta {
  display: flex;
  flex-direction: column;
  min-width: 0;
  flex: 1;
}
.file-card .file-meta b {
  font-size: 0.9rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.file-card .file-meta span { font-size: 0.75rem; color: var(--muted); }
.file-card .file-dl { font-size: 1.1rem; flex-shrink: 0; }

/* شريط تقدم الرفع */
.upload-bar { background: var(--green-light); border-top: 2px solid var(--green); }
.upload-name {
  max-width: 30%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: 0.85rem;
}
.progress-track {
  flex: 1;
  height: 10px;
  background: #d5e2d5;
  border-radius: 999px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  width: 0%;
  background: var(--green);
  border-radius: 999px;
  transition: width 0.15s;
}
#upload-pct { font-size: 0.8rem; font-weight: 700; color: var(--green-dark); }

/* معاينة قبل الإرسال */
.preview-img {
  max-width: 100%;
  max-height: 45vh;
  border-radius: 12px;
  object-fit: contain;
}
.preview-doc { margin: 0 auto; }

/* رسالة محذوفة (ظاهرياً) */
.msg.deleted { opacity: 0.75; }
.msg .deleted-text { font-style: italic; color: var(--muted); font-size: 0.9rem; }
.msg.me {
  align-self: flex-start;      /* جهة البداية: يمين في RTL ويسار في LTR */
  background: var(--bubble-me);
  border-end-start-radius: 6px;
}
.msg.them {
  align-self: flex-end;
  background: var(--bubble-them);
  border-end-end-radius: 6px;
}
/* نص الرسالة: احفظ الأسطر المتعددة (\n) واللف مع كسر الكلمات الطويلة */
.msg .msg-text { white-space: pre-wrap; overflow-wrap: break-word; }
.msg .sender { font-size: 0.8rem; font-weight: 700; color: var(--green); margin-bottom: 2px; }
.msg .time { font-size: 0.7rem; color: var(--muted); margin-top: 4px; text-align: end; }
.msg .translated {
  border-top: 1px dashed #b0c0b0;
  margin-top: 6px;
  padding-top: 6px;
  font-size: 0.95rem;
  color: #33691e;
}
.msg .translated::before { content: "🌐 "; }

.msg.emergency {
  background: #ffebee;
  border: 3px solid var(--red);
  font-weight: 700;
}

.msg audio { max-width: 220px; width: 220px; display: block; }
.msg img.photo {
  max-width: 220px;
  border-radius: 12px;
  display: block;
}

.msg .map-frame {
  border: 0;
  border-radius: 12px;
  width: 240px;
  height: 180px;
  max-width: 100%;
  display: block;
}
.msg .map-link {
  display: block;
  margin-top: 6px;
  color: var(--green);
  font-weight: 600;
  font-size: 0.9rem;
}

/* فاصل اليوم: خط أفقي رفيع والتاريخ في منتصفه (متماثل في RTL وLTR) */
.day-divider {
  align-self: stretch;
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  font-size: 0.78rem;
  margin: 6px 2px;
  user-select: none;
}
.day-divider::before,
.day-divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--pill-border);
}

/* ─────────── شريط الكتابة (نمط واتساب) ─────────── */
.composer {
  position: relative;
  display: flex;
  align-items: flex-end;
  gap: 7px;
  padding: 8px 8px;
  padding-bottom: calc(8px + env(safe-area-inset-bottom));
  background: var(--card);
  box-shadow: 0 -2px 8px rgba(0, 0, 0, 0.06);
}

/* الحبة العريضة: تحوي الإيموجي + الحقل + المرفق داخل حدّ واحد */
.composer-pill {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: flex-end;
  gap: 2px;
  background: var(--pill);
  border: 1.5px solid var(--pill-border);
  border-radius: 24px;
  padding: 3px 6px;
  transition: border-color .15s;
}
.composer-pill:focus-within { border-color: var(--green); }

/* أيقونتان صغيرتان مدمجتان داخل الحبة */
.pill-icon {
  flex-shrink: 0;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: transparent;
  font-size: 1.25rem;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted-ic);
}
.pill-icon:active { background: rgba(0, 0, 0, 0.06); }

.composer textarea {
  flex: 1;
  min-width: 0;
  margin: 0;
  border: none;
  background: transparent;
  /* يتمدد تلقائياً عبر JS بين سطر واحد و~6 أسطر ثم يظهر شريط تمرير داخلي */
  min-height: 36px;
  max-height: 132px;
  height: 36px;
  padding: 7px 4px;
  line-height: 1.4;
  resize: none;
  overflow-y: hidden;
  white-space: pre-wrap;
  word-break: break-word;
}
.composer textarea:focus { border: none; }

/* الدائرة الوحيدة خارج الحبة: تسجيل عند الفراغ / إرسال عند وجود نص */
.btn-round {
  flex-shrink: 0;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: var(--green);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}
.btn-round:active { background: var(--green-dark); }
.btn-round .ic-send { display: none; }
.btn-round.is-send .ic-send { display: block; }
.btn-round.is-send .ic-mic { display: none; }
:root[dir="rtl"] .btn-round .ic-send { transform: scaleX(-1); }

/* قائمة المرفقات ومنتقي الإيموجي: بطاقات منبثقة فوق الشريط */
.pop-menu, .emoji-pop {
  position: absolute;
  bottom: calc(100% + 6px);
  background: var(--card);
  border: 1px solid var(--pill-border);
  border-radius: 16px;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.18);
  z-index: 20;
}
.pop-menu {
  inset-inline-start: 8px;
  min-width: 190px;
  padding: 6px;
}
.pop-item {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border-radius: 12px;
  background: transparent;
  font-size: 1rem;
  color: var(--text);
  text-align: start;
}
.pop-item:active { background: var(--green-light); }
.pop-ic { font-size: 1.3rem; width: 26px; text-align: center; }

.emoji-pop {
  inset-inline: 8px;
  padding: 10px;
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 2px;
  max-height: 200px;
  overflow-y: auto;
}
.emoji-pop button {
  background: transparent;
  font-size: 1.5rem;
  padding: 6px 0;
  border-radius: 10px;
  line-height: 1;
}
.emoji-pop button:active { background: var(--green-light); }

/* ─────────── الوضع الصامت للقراءة ───────────
   شريط تنبيه مثبَّت تحت رأس المحادثة طوال تفعيل الوضع. لونه كهرماني مميّز عن
   شريط التسجيل الأحمر وعن الشريط الأخضر، فلا يُخلط بينها بنظرة سريعة. */
.silent-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 14px;
  background: #fff6e0;
  border-bottom: 2px solid #e0a63c;
  color: #6b4b10;
  font-size: 0.86rem;
  line-height: 1.35;
  z-index: 4;
}
.silent-ic { font-size: 1.1rem; flex-shrink: 0; }
.silent-bar-text { flex: 1; font-weight: 600; }
.silent-bar-off {
  flex-shrink: 0;
  border: 1px solid #e0a63c;
  background: #fff;
  color: #6b4b10;
  font: inherit;
  font-weight: 700;
  padding: 5px 12px;
  border-radius: 999px;
  cursor: pointer;
}
.silent-bar-off:active { background: #f5e2bd; }

.recording-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: #fff3f3;
  border-top: 2px solid var(--red);
}
.rec-dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--red);
  animation: blink 1s infinite;
}
@keyframes blink { 50% { opacity: 0.2; } }
#rec-time { flex: 1; font-weight: 700; color: var(--red); font-size: 1.1rem; }

/* ─────────── الإعدادات ─────────── */
.settings label {
  display: block;
  font-weight: 600;
  margin-bottom: 16px;
}
.settings label input, .settings label select { margin-top: 6px; }
.settings label.row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--card);
  padding: 14px;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.settings label.row input[type="checkbox"] {
  width: 28px;
  height: 28px;
  margin: 0;
  accent-color: var(--green);
}
.settings .btn-primary { margin: 18px 0 10px; }

/* ─────────── النوافذ المنبثقة ─────────── */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  padding: 20px;
}
.modal-box {
  background: var(--card);
  border-radius: 24px;
  padding: 24px;
  width: 100%;
  max-width: 420px;
  text-align: center;
}
.modal-box h2 { margin-bottom: 14px; }
.modal-box p { margin-bottom: 14px; line-height: 1.7; }
.modal-actions { display: flex; gap: 12px; margin-top: 16px; }
.emergency-box { border: 4px solid var(--red); }

#selfie-video {
  width: 100%;
  border-radius: 16px;
  background: #000;
  transform: scaleX(-1);
}

/* ─────────── طلبات التواصل والبحث ─────────── */
.search-row { display: flex; gap: 8px; margin-bottom: 12px; }
.search-row input, .search-row select { flex: 1; margin-bottom: 0; }
.search-row .btn-small { width: auto; flex-shrink: 0; }

.list-flat { margin-bottom: 8px; }

.request-card { border: 2px solid var(--green); cursor: default; }
.request-card:active { background: var(--card); }
.req-actions {
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex-shrink: 0;
}
.req-actions .btn-small { width: auto; font-size: 0.85rem; padding: 8px 12px; }

.empty-state.small { padding: 20px 12px; font-size: 0.95rem; }

.badge-locked { background: #ede7f6; color: #4527a0; }
.badge-verified { background: #e3f2fd; color: #1565c0; }

/* صف دخول مشبوه (دولة جديدة/مختلفة) */
.login-warn {
  background: #fdecea;
  border-radius: 8px;
  border-inline-start: 4px solid var(--red);
  padding-inline-start: 8px;
}

/* ─────────── لوحة الإدارة ─────────── */
.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
}
.card h2 { font-size: 1.05rem; margin-bottom: 12px; }

.admin-item { align-items: flex-start; cursor: default; }
.admin-item:active { background: var(--card); }

/* ─────────── منطقة الخطر: التصفير الكامل ─────────── */
.danger-zone {
  border: 2px solid var(--red);
  background: #fff5f5;
  margin-top: 24px;
}
.danger-zone > h2 { color: var(--red); }
.danger-zone input { margin-bottom: 10px; }
.danger-note {
  color: var(--red);
  font-size: 0.92rem;
  font-weight: 600;
  line-height: 1.6;
  margin-bottom: 12px;
}
.danger-changepw { color: var(--muted); display: block; margin-top: 10px; }

.danger-modal { border-top: 6px solid var(--red); text-align: start; }
.danger-modal h2 { color: var(--red); }
.fr-counts {
  display: grid;
  gap: 8px;
  margin: 8px 0 16px;
}
.fr-count-row {
  display: flex;
  justify-content: space-between;
  padding: 10px 14px;
  background: #fff5f5;
  border: 1px solid #f3caca;
  border-radius: 12px;
  font-size: 1rem;
}
.fr-count-row b { color: var(--red); font-size: 1.15rem; }
.fr-warn {
  background: #fff8e1;
  border: 1px solid #f0d089;
  color: #8a6d00;
  border-radius: 12px;
  padding: 12px 14px;
  font-size: 0.92rem;
  font-weight: 600;
  line-height: 1.6;
  margin-bottom: 14px;
}
.danger-final { font-size: 1.05rem; }
.btn-secondary {
  background: var(--bg);
  color: var(--text);
  padding: 14px 20px;
  font-size: 1.05rem;
  font-weight: 600;
  width: 100%;
  border: 1px solid var(--pill-border);
}

/* ─────────── النسخ الاحتياطي والاسترجاع ─────────── */
.backup-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
  margin: 10px 0;
}
.backup-row .btn-primary { width: auto; }
.backup-latest { font-size: 0.95rem; color: var(--muted); }
.backup-latest b { color: var(--text); font-variant-numeric: tabular-nums; }
.backup-ok {
  background: var(--green-light);
  color: var(--green-dark);
  border-radius: 12px;
  padding: 12px 14px;
  font-weight: 600;
  margin-bottom: 10px;
}
.backup-note { font-size: 0.85rem; }

/* زر الاسترجاع بلون كهرماني ليتمّيز عن زر التصفير الأحمر */
.btn-restore { background: #b26a00; margin-bottom: 10px; }
.btn-restore:active { background: #8a5200; }

.rs-list { display: grid; gap: 8px; margin: 10px 0 14px; max-height: 280px; overflow-y: auto; }
.rs-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border: 1px solid var(--pill-border);
  border-radius: 12px;
  cursor: pointer;
  font-size: 0.98rem;
}
.rs-item:has(input:checked) { border-color: var(--green); background: var(--green-light); }
.rs-item input { width: auto; margin: 0; }
.rs-when { font-variant-numeric: tabular-nums; }
.rs-age { color: var(--muted); font-size: 0.85rem; margin-inline-start: auto; }

/* عرض المساحة الإجمالية وعدد النسخ */
.backup-storage { font-size: 0.9rem; color: var(--muted); margin: 4px 0 10px; font-variant-numeric: tabular-nums; }

/* أزرار التحميل (سريع/كامل) */
.dl-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.btn-dl {
  width: auto;
  padding: 8px 12px;
  font-size: 0.9rem;
  background: var(--card);
  color: var(--green-dark);
  border: 1px solid var(--green);
  border-radius: 10px;
  font-weight: 600;
}
.btn-dl:active { background: var(--green-light); }
.dl-new-label { font-weight: 600; margin-bottom: 6px; }
.dl-warn {
  flex-basis: 100%;
  background: #fff8e1;
  border: 1px solid #f0d089;
  color: #8a6d00;
  border-radius: 10px;
  padding: 8px 12px;
  font-size: 0.85rem;
  font-weight: 600;
}

/* صندوق سياسة الاحتفاظ الموثّق */
.retention-box {
  margin-top: 16px;
  padding: 12px 16px;
  background: var(--bg);
  border: 1px solid var(--pill-border);
  border-radius: 12px;
}
.retention-box h3 { font-size: 0.95rem; margin-bottom: 8px; color: var(--text); }
.retention-box ul { margin: 0; padding-inline-start: 20px; }
.retention-box li { font-size: 0.88rem; color: var(--muted); margin-bottom: 4px; line-height: 1.5; }

/* أزرار التحميل داخل عناصر قائمة الاسترجاع */
.rs-item { flex-wrap: wrap; }
.rs-item .dl-actions { flex-basis: 100%; margin-top: 6px; }

/* زر المسح النهائي بجانب المستخدم — أحمر داكن ليتمّيز عن الحذف الناعم */
.btn-harddel {
  width: auto;
  padding: 8px 14px;
  font-size: 0.9rem;
  font-weight: 700;
  color: #fff;
  background: #7a1414;
  border: 1px solid #500d0d;
  border-radius: 10px;
}
.btn-harddel:active { background: #500d0d; }

/* نافذة المسح النهائي */
.hd-target { font-weight: 700; margin-bottom: 12px; font-size: 1.05rem; }
.hd-modes { display: grid; gap: 8px; margin-bottom: 12px; }
.hd-mode {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px 14px;
  border: 1px solid var(--pill-border);
  border-radius: 12px;
  cursor: pointer;
  font-size: 0.95rem;
  line-height: 1.5;
}
.hd-mode:has(input:checked) { border-color: var(--red); background: #fff5f5; }
.hd-mode input { width: auto; margin: 3px 0 0; flex-shrink: 0; }
.hd-date-row { margin-bottom: 12px; }
.hd-date-row label { display: block; font-weight: 600; margin-bottom: 6px; font-size: 0.9rem; }
.hd-preview {
  background: #fff5f5;
  border: 1px solid #f3caca;
  color: var(--red);
  border-radius: 12px;
  padding: 12px 14px;
  font-weight: 700;
  margin-bottom: 12px;
  font-variant-numeric: tabular-nums;
}
.hd-purge {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 12px;
  margin-bottom: 12px;
  border: 1px dashed var(--red);
  border-radius: 12px;
  font-size: 0.92rem;
  line-height: 1.5;
  cursor: pointer;
}
.hd-purge input { width: auto; margin: 3px 0 0; flex-shrink: 0; }

/* اختيار مصدر الاسترجاع: السيرفر / ملف على الجهاز */
.rs-source-tabs { display: flex; gap: 6px; margin-bottom: 12px; }
.rs-tab {
  flex: 1;
  padding: 10px;
  border-radius: 10px;
  background: var(--bg);
  border: 1px solid var(--pill-border);
  color: var(--muted);
  font-weight: 600;
  font-size: 0.95rem;
}
.rs-tab.active { background: var(--green-light); color: var(--green-dark); border-color: var(--green); }
.rs-file-name { font-size: 0.9rem; color: var(--green-dark); margin-top: 8px; word-break: break-all; }

/* بطاقة تأسيس البيانات في شاشة الدخول (سيرفر جديد فارغ) */
.bootstrap-card { margin-top: 16px; border: 2px dashed var(--green); }
.bootstrap-card h2 { color: var(--green); font-size: 1.1rem; margin-bottom: 8px; }
.bootstrap-card input[type="file"] { margin: 10px 0; }

.admin-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex-shrink: 0;
}
.admin-actions .btn-small { width: auto; font-size: 0.85rem; padding: 8px 12px; }

.btn-warn {
  background: #f9a825;
  color: #fff;
  font-weight: 600;
}

.badge {
  display: inline-block;
  font-size: 0.7rem;
  font-weight: 600;
  background: #e0e8e0;
  color: var(--muted);
  border-radius: 999px;
  padding: 2px 8px;
  margin-inline-start: 6px;
  vertical-align: middle;
}
.badge-admin { background: var(--green-light); color: var(--green-dark); }
.badge-mod { background: #fff3e0; color: #e65100; }
.badge-frozen { background: #e3f2fd; color: #1565c0; }

.sec-title { margin: 20px 4px 10px; font-size: 1.1rem; }

.radio-row {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 4px;
  cursor: pointer;
  font-size: 0.95rem;
}
.radio-row input[type="radio"] {
  width: 22px;
  height: 22px;
  margin: 0;
  flex-shrink: 0;
  accent-color: var(--green);
}

.viewer-box { max-width: 560px; text-align: start; }
.viewer-messages {
  height: 55vh;
  overflow-y: auto;
  background: var(--bg);
  border-radius: 12px;
  padding: 12px;
  margin: 12px 0;
}
.viewer-msg { max-width: 100%; }
.deleted-marker {
  background: #fdecea;
  border: 1px dashed var(--red);
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 0.8rem;
  color: var(--red);
  margin-bottom: 6px;
}

.audit-row {
  font-size: 0.85rem;
  padding: 8px 4px;
  border-bottom: 1px solid #edf2ed;
  line-height: 1.7;
}
.audit-row:last-child { border-bottom: none; }
.audit-time {
  display: inline-block;
  color: var(--muted);
  font-size: 0.75rem;
  margin-inline-end: 8px;
}

/* ─────────── التنبيهات ─────────── */
.toast {
  position: fixed;
  bottom: 90px;
  left: 50%;
  transform: translateX(-50%);
  background: #323b32;
  color: #fff;
  padding: 12px 22px;
  border-radius: 999px;
  z-index: 99;
  font-size: 0.95rem;
  box-shadow: var(--shadow);
  max-width: 90%;
  text-align: center;
}

/* سطر إصدار التطبيق في الإعدادات */
.app-version {
  display: flex;
  align-items: center;
  gap: 8px;
  justify-content: center;
  flex-wrap: wrap;
  margin-top: 18px;
  font-size: 0.85rem;
  color: var(--muted);
}
.app-version b { color: var(--text); font-variant-numeric: tabular-nums; }
.app-version .btn-link { width: auto; padding: 4px 8px; font-size: 0.85rem; }

/* ─── قفل عناصر التحكم أثناء المكالمة ─── */
.call-lock {
  position: absolute;
  inset: 0;
  z-index: 10;
  background: rgba(9, 28, 14, 0.93);
  backdrop-filter: blur(3px);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  text-align: center;
  padding: 24px;
  touch-action: none;            /* تمتصّ اللمسات فلا تصل للأزرار تحتها */
}
.call-lock-inner { display: flex; flex-direction: column; align-items: center; gap: 8px; max-width: 280px; }
.call-lock-icon { font-size: 2.6rem; opacity: .9; }
.call-lock-name { font-size: 1.25rem; font-weight: 700; }
.call-lock-timer { font-size: 1.05rem; font-variant-numeric: tabular-nums; opacity: .85; letter-spacing: 1px; }
.call-lock-hint { font-size: .88rem; opacity: .75; line-height: 1.6; margin-top: 4px; }
.call-unlock {
  margin-top: 10px;
  padding: 13px 22px;
  border-radius: 999px;
  background: rgba(255, 255, 255, .18);
  color: #fff;
  font-size: 1rem;
  font-weight: 600;
}
.call-unlock:active { background: rgba(255, 255, 255, .3); }

/* تلميح داخل قائمة المخارج حين لا يكشف النظام إلا مخرجاً واحداً */
.output-hint {
  padding: 11px 14px;
  font-size: .8rem;
  line-height: 1.55;
  color: var(--muted);
  background: var(--pill);
  border-top: 1px solid var(--pill-border);
}

/* لوحة المعلومات التشخيصية */
.diag-box {
  margin-top: 14px;
  border: 1px solid var(--pill-border);
  border-radius: 12px;
  background: var(--card);
  overflow: hidden;
}
.diag-box summary {
  padding: 12px 14px;
  cursor: pointer;
  font-size: .92rem;
  font-weight: 600;
  color: var(--muted);
}
.diag-output {
  margin: 0;
  padding: 12px 14px;
  background: var(--pill);
  font-family: ui-monospace, "Cascadia Mono", Consolas, monospace;
  font-size: .72rem;
  line-height: 1.65;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 300px;
  overflow-y: auto;
  direction: ltr;
  text-align: start;
  color: var(--text);
}
.diag-box .btn-primary { border-radius: 0; }

/* ─── شارة الرسائل غير المقروءة في قائمة المحادثات ─── */
.item-meta { display: flex; flex-direction: column; align-items: flex-end; gap: 6px; flex-shrink: 0; }
.unread-badge {
  min-width: 22px;
  height: 22px;
  padding: 0 7px;
  border-radius: 999px;
  background: var(--green);
  color: #fff;
  font-size: 0.78rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  font-variant-numeric: tabular-nums;
}
.list-item.has-unread .item-title { font-weight: 800; }
.list-item.has-unread .item-sub { color: var(--text); }

/* ─── التنبيه اللحظي على الشاشة الرئيسية ─── */
.live-toast {
  position: absolute;
  top: calc(12px + env(safe-area-inset-top));
  inset-inline: 12px;
  z-index: 40;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border-radius: 16px;
  background: var(--card);
  border: 1px solid var(--pill-border);
  box-shadow: 0 8px 26px rgba(0, 0, 0, 0.22);
  cursor: pointer;
  animation: toastDrop .22s ease;
}
@keyframes toastDrop {
  from { opacity: 0; transform: translateY(-14px); }
  to { opacity: 1; transform: translateY(0); }
}
.live-toast:active { background: var(--green-light); }
.live-toast-ic { font-size: 1.5rem; flex-shrink: 0; }
.live-toast-body { flex: 1; min-width: 0; }
.live-toast-name { font-weight: 700; font-size: 0.95rem; }
.live-toast-text {
  font-size: 0.88rem;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
@media (prefers-reduced-motion: reduce) { .live-toast { animation: none; } }
