/* ============================================================
   سهم دردشة — نظام التصميم
   عربي RTL بالكامل، وضع نهاري/ليلي، متجاوب
   ============================================================ */

/* ── المتغيرات ─────────────────────────────────────────────── */
:root {
  --brand: #4f6ef7;
  --brand-strong: #3d56d6;
  --brand-soft: rgba(79, 110, 247, 0.12);

  --bg: #f4f6fb;
  --panel: #ffffff;
  --panel-2: #f8f9fd;
  --hover: #eef1f9;
  --active: #e5eaf8;
  --border: #e3e7f0;
  --border-strong: #cdd4e3;

  --text: #1c2333;
  --text-2: #5a6478;
  --text-3: #8a93a8;

  --danger: #e5484d;
  --danger-soft: rgba(229, 72, 77, 0.1);
  --success: #21a464;
  --warning: #f0a020;

  --online: #22c55e;
  --busy: #ef4444;
  --meeting: #f59e0b;
  --away: #94a3b8;
  --offline: #cbd5e1;

  /* الشريط الجانبي: أبيض أنيق في النهاري */
  --sidebar-bg: #ffffff;
  --sidebar-text: #49536b;
  --sidebar-strong: #1c2333;
  --sidebar-hover: rgba(28, 35, 51, 0.055);
  --sidebar-active: rgba(79, 110, 247, 0.13);
  --sidebar-heading: #8a93a8;
  --sidebar-border: #e2e6f0;
  --sidebar-input: rgba(28, 35, 51, 0.05);
  --sidebar-scroll: #cdd4e3;

  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 4px 24px rgba(28, 35, 51, 0.09);
  --shadow-lg: 0 12px 48px rgba(28, 35, 51, 0.18);

  --font: 'IBM Plex Sans Arabic', 'Segoe UI', Tahoma, Arial, sans-serif;
}

[data-theme='dark'] {
  --bg: #12151f;
  --panel: #1a1f2e;
  --panel-2: #161a27;
  --hover: #232939;
  --active: #2a3147;
  --border: #2a3044;
  --border-strong: #3a4158;

  --text: #e8ecf5;
  --text-2: #a0a8bd;
  --text-3: #6d7690;

  --brand-soft: rgba(79, 110, 247, 0.2);
  --danger-soft: rgba(229, 72, 77, 0.16);

  /* الشريط الجانبي في الليلي: داكن كما كان */
  --sidebar-bg: #151928;
  --sidebar-text: #aeb6cc;
  --sidebar-strong: #ffffff;
  --sidebar-hover: rgba(255, 255, 255, 0.07);
  --sidebar-active: rgba(79, 110, 247, 0.28);
  --sidebar-heading: #6d7690;
  --sidebar-border: rgba(255, 255, 255, 0.07);
  --sidebar-input: rgba(255, 255, 255, 0.06);
  --sidebar-scroll: rgba(255, 255, 255, 0.15);

  --shadow: 0 4px 24px rgba(0, 0, 0, 0.35);
  --shadow-lg: 0 12px 48px rgba(0, 0, 0, 0.5);
}

/* ── الأساسيات ─────────────────────────────────────────────── */
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 14.5px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }

::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 8px; }
::-webkit-scrollbar-track { background: transparent; }

svg.icon {
  width: 18px;
  height: 18px;
  stroke: currentColor;
  stroke-width: 2;
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
  vertical-align: -3px;
  flex-shrink: 0;
}

/* ── الأزرار ───────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 9px 18px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  background: var(--brand);
  color: #fff;
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
  white-space: nowrap;
}

.btn:hover { background: var(--brand-strong); text-decoration: none; }
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }

.btn-ghost {
  background: transparent;
  color: var(--text-2);
  border-color: var(--border);
}
.btn-ghost:hover { background: var(--hover); color: var(--text); }

.btn-danger { background: var(--danger); }
.btn-danger:hover { background: #c93a3f; }

.btn-soft { background: var(--brand-soft); color: var(--brand); }
.btn-soft:hover { background: var(--brand); color: #fff; }

.btn-sm { padding: 5px 12px; font-size: 13px; }

.btn-icon {
  padding: 8px;
  background: transparent;
  color: var(--text-2);
  border-radius: var(--radius-sm);
  border: none;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, color 0.15s;
}
.btn-icon:hover { background: var(--hover); color: var(--text); }

/* ── النماذج ───────────────────────────────────────────────── */
.field { margin-bottom: 16px; }

.field label {
  display: block;
  font-weight: 600;
  font-size: 13.5px;
  margin-bottom: 6px;
  color: var(--text);
}

.input, select.input, textarea.input {
  width: 100%;
  padding: 10px 14px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--panel);
  color: var(--text);
  font-family: inherit;
  font-size: 14px;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.input:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px var(--brand-soft);
}

.input::placeholder { color: var(--text-3); }

.field .hint { font-size: 12.5px; color: var(--text-3); margin-top: 4px; }
.field .error { font-size: 12.5px; color: var(--danger); margin-top: 4px; font-weight: 600; }

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 8px 0;
  cursor: pointer;
  font-size: 14px;
}
.checkbox-row input { width: 17px; height: 17px; accent-color: var(--brand); cursor: pointer; }

/* ── التنبيهات ─────────────────────────────────────────────── */
.alert {
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  margin-bottom: 16px;
  font-size: 13.5px;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 9px;
}
.alert-success { background: rgba(33, 164, 100, 0.12); color: var(--success); }
.alert-error { background: var(--danger-soft); color: var(--danger); }

/* ── الصور الرمزية والحضور ─────────────────────────────────── */
.avatar {
  width: 38px;
  height: 38px;
  border-radius: 11px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-weight: 700;
  font-size: 14px;
  flex-shrink: 0;
  position: relative;
  user-select: none;
  overflow: hidden;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.avatar.sm { width: 30px; height: 30px; font-size: 12px; border-radius: 9px; }
.avatar.lg { width: 72px; height: 72px; font-size: 26px; border-radius: 20px; }

.presence-dot {
  width: 11px;
  height: 11px;
  border-radius: 50%;
  border: 2px solid var(--panel);
  background: var(--offline);
  position: absolute;
  bottom: -1px;
  left: -1px;
  box-sizing: content-box;
}
.presence-dot.online { background: var(--online); }
.presence-dot.busy { background: var(--busy); }
.presence-dot.meeting { background: var(--meeting); }
.presence-dot.away { background: var(--away); }

.avatar-wrap { position: relative; display: inline-flex; flex-shrink: 0; }

/* ── الشارات ───────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  min-width: 19px;
  height: 19px;
  padding: 0 6px;
  border-radius: 10px;
  background: var(--danger);
  color: #fff;
  font-size: 11.5px;
  font-weight: 700;
  justify-content: center;
}

.tag {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
  background: var(--brand-soft);
  color: var(--brand);
}
.tag.gray { background: var(--hover); color: var(--text-2); }
.tag.green { background: rgba(33, 164, 100, 0.12); color: var(--success); }
.tag.red { background: var(--danger-soft); color: var(--danger); }
.tag.orange { background: rgba(240, 160, 32, 0.14); color: var(--warning); }

/* ============================================================
   صفحات الدخول
   ============================================================ */
.auth-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background:
    radial-gradient(1000px 500px at 85% -10%, var(--brand-soft), transparent),
    radial-gradient(800px 400px at 10% 110%, rgba(79, 110, 247, 0.08), transparent),
    var(--bg);
}

.auth-card {
  width: 100%;
  max-width: 420px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 40px 36px;
  box-shadow: var(--shadow-lg);
}

.auth-logo {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  margin-bottom: 28px;
  text-align: center;
}

.auth-logo .mark {
  width: 58px;
  height: 58px;
  border-radius: 17px;
  background: linear-gradient(135deg, var(--brand), #7c93ff);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  box-shadow: 0 8px 24px var(--brand-soft);
}
.auth-logo .mark svg { width: 28px; height: 28px; }

.auth-logo h1 { margin: 0; font-size: 22px; }
.auth-logo p { margin: 0; color: var(--text-2); font-size: 13.5px; }

.auth-footer {
  text-align: center;
  margin-top: 20px;
  font-size: 13px;
  color: var(--text-3);
}

/* ============================================================
   واجهة الدردشة الرئيسية
   ============================================================ */
.chat-app {
  display: flex;
  position: fixed;                       /* تثبيت التطبيق — سفاري لا يستطيع دفعه مع لوحة المفاتيح */
  inset-block-start: 0;
  inset-inline: 0;
  height: 100vh;
  height: 100dvh;                        /* ارتفاع ديناميكي يتكيف مع لوحة مفاتيح الجوال */
  height: var(--app-height, 100dvh);     /* قيمة دقيقة من visualViewport (آيفون) */
  transform: translateY(var(--vv-offset, 0px)); /* يلتصق بالمنطقة المرئية عند انزياح سفاري */
  overflow: hidden;
}

/* ── الشريط الجانبي ─────────────────────────────────────────── */
.sidebar {
  width: 300px;
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  z-index: 40;
  border-inline-end: 1px solid var(--sidebar-border);
}

.sidebar-header {
  padding: 16px;
  display: flex;
  align-items: center;
  gap: 11px;
  border-bottom: 1px solid var(--sidebar-border);
}

.sidebar-header .mark {
  width: 38px;
  height: 38px;
  border-radius: 11px;
  background: linear-gradient(135deg, var(--brand), #7c93ff);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  flex-shrink: 0;
  overflow: hidden;
}
.sidebar-header .mark img { width: 100%; height: 100%; object-fit: cover; }

.sidebar-header .title { flex: 1; min-width: 0; }
.sidebar-header .title h2 { margin: 0; color: var(--sidebar-strong); font-size: 15.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-header .title span { font-size: 12px; color: var(--sidebar-heading); }

.sidebar-search { padding: 12px 14px 6px; }

.sidebar-search .search-box {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--sidebar-input);
  border: 1px solid var(--sidebar-border);
  border-radius: 9px;
  padding: 8px 12px;
  color: var(--sidebar-text);
  cursor: pointer;
  font-size: 13px;
  transition: background 0.15s;
  width: 100%;
  font-family: inherit;
}
.sidebar-search .search-box:hover { background: var(--sidebar-hover); }

.sidebar-nav {
  display: flex;
  padding: 8px 14px;
  gap: 6px;
  border-bottom: 1px solid var(--sidebar-border);
}

.sidebar-nav a {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 8px 4px;
  border-radius: 9px;
  color: var(--sidebar-text);
  font-size: 11px;
  font-weight: 600;
  position: relative;
  transition: background 0.15s;
}
.sidebar-nav a:hover { background: var(--sidebar-hover); text-decoration: none; }
.sidebar-nav a .badge { position: absolute; top: 2px; inset-inline-end: 8px; }

.sidebar-body { flex: 1; overflow-y: auto; padding: 10px 8px 20px; overscroll-behavior-y: contain; }
.sidebar-body::-webkit-scrollbar-thumb { background: var(--sidebar-scroll); }

.sidebar-section { margin-bottom: 10px; }

.sidebar-section .section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 7px 10px 5px;
  color: var(--sidebar-heading);
  font-size: 12px;
  font-weight: 700;
}
.sidebar-section .section-head .btn-icon { color: var(--sidebar-heading); padding: 3px; }
.sidebar-section .section-head .btn-icon:hover { color: var(--sidebar-strong); background: var(--sidebar-hover); }
.sidebar-section .section-head svg.icon { width: 15px; height: 15px; }

.channel-item {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 7px 10px;
  border-radius: 9px;
  cursor: pointer;
  color: var(--sidebar-text);
  transition: background 0.12s;
  position: relative;
  min-height: 38px;
}
.channel-item:hover { background: var(--sidebar-hover); }
.channel-item.active { background: var(--sidebar-active); color: var(--sidebar-strong); }
.channel-item.unread { color: var(--sidebar-strong); font-weight: 700; }

.channel-item .ch-icon {
  width: 20px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  opacity: 0.85;
}
.channel-item .ch-icon svg.icon { width: 16px; height: 16px; }

.channel-item .ch-name {
  flex: 1;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: 13.5px;
}
.channel-item .ch-sub {
  display: block;
  font-size: 11.5px;
  color: var(--sidebar-heading);
  font-weight: 400;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.channel-item.unread .ch-sub { color: var(--sidebar-text); }

.channel-item .muted-icon { opacity: 0.5; }
.channel-item .muted-icon svg.icon { width: 13px; height: 13px; }

.sidebar-footer {
  padding: 12px 14px;
  border-top: 1px solid var(--sidebar-border);
  display: flex;
  align-items: center;
  gap: 10px;
}

.sidebar-footer .me { flex: 1; min-width: 0; cursor: pointer; display: flex; align-items: center; gap: 10px; border-radius: 9px; padding: 4px; transition: background .15s; }
.sidebar-footer .me:hover { background: var(--sidebar-hover); }
.sidebar-footer .me .info { min-width: 0; }
.sidebar-footer .me .info .name { color: var(--sidebar-strong); font-size: 13.5px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-footer .me .info .status { font-size: 11.5px; color: var(--sidebar-heading); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-footer .btn-icon { color: var(--sidebar-text); }
.sidebar-footer .btn-icon:hover { background: var(--sidebar-hover); color: var(--sidebar-strong); }

/* ── منطقة المحادثة ─────────────────────────────────────────── */
.chat-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--bg);
}

.chat-header {
  height: 62px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 18px;
  flex-shrink: 0;
}

.chat-header .ch-title { flex: 1; min-width: 0; }
.chat-header .ch-title h3 {
  margin: 0;
  font-size: 15.5px;
  display: flex;
  align-items: center;
  gap: 7px;
  white-space: nowrap;
  overflow: hidden;
}
.chat-header .ch-title .sub {
  font-size: 12px;
  color: var(--text-3);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: block;
}
.chat-header .actions { display: flex; gap: 2px; }

.chat-empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  color: var(--text-3);
  text-align: center;
  padding: 30px;
}
.chat-empty .big-icon {
  width: 90px;
  height: 90px;
  border-radius: 26px;
  background: var(--brand-soft);
  color: var(--brand);
  display: flex;
  align-items: center;
  justify-content: center;
}
.chat-empty .big-icon svg { width: 42px; height: 42px; }
.chat-empty h3 { margin: 0; color: var(--text); }
.chat-empty p { margin: 0; max-width: 380px; }

/* ── الرسائل ────────────────────────────────────────────────── */
.messages-area {
  flex: 1;
  overflow-y: auto;
  padding: 18px 20px 8px;
  scroll-behavior: smooth;
  overscroll-behavior-y: contain; /* المحتوى يتحرك والإطار ثابت (iOS) */
}

.date-divider {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 18px 0 10px;
  color: var(--text-3);
  font-size: 12px;
  font-weight: 700;
}
.date-divider::before, .date-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}

.msg {
  display: flex;
  gap: 11px;
  padding: 5px 8px;
  border-radius: var(--radius);
  position: relative;
  margin-bottom: 2px;
}
.msg:hover { background: var(--hover); }
.msg.highlight { background: rgba(240, 160, 32, 0.15); }

.msg .msg-body { flex: 1; min-width: 0; }

.msg .msg-head {
  display: flex;
  align-items: baseline;
  gap: 8px;
  flex-wrap: wrap;
}
.msg .msg-head .name { font-weight: 700; font-size: 13.5px; color: var(--text); }
.msg .msg-head .time { font-size: 11.5px; color: var(--text-3); }
.msg .msg-head .edited { font-size: 11px; color: var(--text-3); }
.msg .msg-head .pin-mark { color: var(--warning); display: inline-flex; align-items: center; gap: 3px; font-size: 11px; font-weight: 600; }
.msg .msg-head .pin-mark svg.icon { width: 12px; height: 12px; }

.msg .msg-text {
  font-size: 14px;
  color: var(--text);
  word-wrap: break-word;
  white-space: pre-wrap;
}
.msg .msg-text a { word-break: break-all; }
.msg .msg-text .mention {
  background: var(--brand-soft);
  color: var(--brand);
  padding: 1px 5px;
  border-radius: 5px;
  font-weight: 600;
}

.msg.system-msg {
  justify-content: center;
  padding: 3px;
}
.msg.system-msg:hover { background: transparent; }
.msg.system-msg .sys-text {
  font-size: 12.5px;
  color: var(--text-3);
  background: var(--panel-2);
  border: 1px solid var(--border);
  padding: 4px 14px;
  border-radius: 20px;
}

.msg.deleted-msg .msg-text {
  color: var(--text-3);
  font-style: italic;
  font-size: 13px;
}

/* اقتباس الرد */
.reply-quote {
  border-inline-start: 3px solid var(--brand);
  background: var(--brand-soft);
  border-radius: 7px;
  padding: 5px 10px;
  margin-bottom: 5px;
  font-size: 12.5px;
  cursor: pointer;
  max-width: 480px;
}
.reply-quote .rq-name { font-weight: 700; color: var(--brand); }
.reply-quote .rq-text { color: var(--text-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.forward-mark {
  font-size: 12px;
  color: var(--text-3);
  display: flex;
  align-items: center;
  gap: 5px;
  margin-bottom: 3px;
}
.forward-mark svg.icon { width: 13px; height: 13px; }

/* المرفقات */
.attachments { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 7px; }

.attach-image {
  border-radius: 10px;
  overflow: hidden;
  cursor: pointer;
  border: 1px solid var(--border);
  max-width: 320px;
  max-height: 240px;
  display: block;
}
.attach-image img { max-width: 100%; max-height: 240px; display: block; object-fit: cover; }

.attach-video { max-width: 380px; border-radius: 10px; overflow: hidden; border: 1px solid var(--border); }
.attach-video video { width: 100%; display: block; max-height: 260px; }

.attach-file {
  display: flex;
  align-items: center;
  gap: 11px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 13px;
  min-width: 230px;
  max-width: 340px;
}

.attach-file .f-icon {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  flex-shrink: 0;
  font-size: 10px;
  font-weight: 800;
}
.f-icon.pdf { background: #e5484d; }
.f-icon.word { background: #2b579a; }
.f-icon.excel { background: #217346; }
.f-icon.powerpoint { background: #d24726; }
.f-icon.archive { background: #f0a020; }
.f-icon.text { background: #64748b; }
.f-icon.video { background: #8b5cf6; }
.f-icon.image { background: #0ea5e9; }
.f-icon.other { background: #94a3b8; }

.attach-file .f-info { flex: 1; min-width: 0; }
.attach-file .f-name { font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--text); }
.attach-file .f-meta { font-size: 11.5px; color: var(--text-3); }
.attach-file .f-actions { display: flex; gap: 2px; }
.attach-file .f-actions .btn-icon { padding: 5px; }
.attach-file .f-actions svg.icon { width: 15px; height: 15px; }

/* التفاعلات */
.reactions-bar { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 6px; }

.reaction-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 9px;
  border-radius: 14px;
  border: 1.5px solid var(--border);
  background: var(--panel);
  font-size: 12.5px;
  cursor: pointer;
  transition: border-color 0.15s;
  font-family: inherit;
}
.reaction-chip:hover { border-color: var(--brand); }
.reaction-chip.mine { background: var(--brand-soft); border-color: var(--brand); color: var(--brand); font-weight: 700; }

/* شريط النقاش الفرعي */
.thread-link {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  margin-top: 6px;
  color: var(--brand);
  font-size: 12.5px;
  font-weight: 700;
  cursor: pointer;
  background: none;
  border: none;
  font-family: inherit;
  padding: 4px 8px;
  border-radius: 7px;
}
.thread-link:hover { background: var(--brand-soft); }
.thread-link svg.icon { width: 14px; height: 14px; }

/* حالة القراءة */
.read-status { display: inline-flex; align-items: center; margin-inline-start: 4px; color: var(--text-3); }
.read-status svg.icon { width: 15px; height: 15px; }
.read-status.read { color: var(--brand); }

/* أزرار الرسالة العائمة */
.msg-actions {
  position: absolute;
  top: -14px;
  inset-inline-end: 14px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: var(--shadow);
  display: none;
  padding: 2px;
  z-index: 5;
}
.msg:hover .msg-actions { display: flex; }
.msg-actions .btn-icon { padding: 6px; border-radius: 7px; }
.msg-actions .btn-icon svg.icon { width: 16px; height: 16px; }

/* منتقي التفاعلات */
.emoji-pop {
  position: absolute;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow-lg);
  padding: 7px;
  display: flex;
  gap: 3px;
  z-index: 60;
}
.emoji-pop button {
  border: none;
  background: transparent;
  font-size: 20px;
  cursor: pointer;
  padding: 5px 7px;
  border-radius: 8px;
  transition: transform 0.1s;
  line-height: 1;
}
.emoji-pop button:hover { background: var(--hover); transform: scale(1.2); }

/* مؤشر الكتابة */
.typing-bar {
  padding: 2px 24px 6px;
  font-size: 12.5px;
  color: var(--text-3);
  min-height: 22px;
  display: flex;
  align-items: center;
  gap: 7px;
}
.typing-dots { display: inline-flex; gap: 3px; }
.typing-dots span {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--text-3);
  animation: typingBounce 1.2s infinite;
}
.typing-dots span:nth-child(2) { animation-delay: 0.15s; }
.typing-dots span:nth-child(3) { animation-delay: 0.3s; }
@keyframes typingBounce { 0%, 60%, 100% { transform: none; } 30% { transform: translateY(-4px); } }

/* ── صندوق الكتابة ──────────────────────────────────────────── */
.composer-wrap { padding: 0 18px 16px; }

.reply-preview, .edit-preview {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-bottom: none;
  border-radius: var(--radius) var(--radius) 0 0;
  padding: 8px 14px;
  font-size: 12.5px;
  color: var(--text-2);
}
.reply-preview .rp-body { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.reply-preview b { color: var(--brand); }

.composer {
  position: relative; /* مرجع قائمة الإشارات @ حتى تطفو فوق الصندوق */
  background: var(--panel);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  transition: border-color 0.15s, box-shadow 0.15s;
}
.composer:focus-within { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
.composer.has-preview { border-radius: 0 0 var(--radius) var(--radius); }

.composer.dragover { border-color: var(--brand); border-style: dashed; background: var(--brand-soft); }

.composer textarea {
  width: 100%;
  border: none;
  background: transparent;
  color: var(--text);
  font-family: inherit;
  font-size: 14.5px;
  padding: 13px 16px 4px;
  resize: none;
  max-height: 180px;
  min-height: 46px;
}
.composer textarea:focus { outline: none; }

.composer .composer-bar {
  display: flex;
  align-items: center;
  padding: 4px 8px 7px;
  gap: 2px;
}
.composer .composer-bar .spacer { flex: 1; }

.composer .send-btn {
  background: var(--brand);
  color: #fff;
  border: none;
  border-radius: 9px;
  width: 38px;
  height: 38px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
}
.composer .send-btn:hover { background: var(--brand-strong); }
.composer .send-btn:active { transform: scale(0.94); }
.composer .send-btn:disabled { opacity: 0.4; cursor: default; }
.composer .send-btn svg.icon { transform: scaleX(-1); }

/* ملفات جاهزة للإرسال */
.pending-files { display: flex; flex-wrap: wrap; gap: 8px; padding: 8px 12px 0; }
.pending-file {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 6px 10px;
  font-size: 12.5px;
  max-width: 230px;
}
.pending-file .pf-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pending-file button { border: none; background: none; color: var(--danger); cursor: pointer; display: flex; padding: 2px; }
.pending-file button svg.icon { width: 14px; height: 14px; }

/* الرسائل الصوتية */
.attach-audio {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 7px 10px;
  max-width: 380px;
}
.attach-audio audio { height: 40px; max-width: 250px; flex: 1; min-width: 160px; }
.attach-audio .f-icon { width: 34px; height: 34px; border-radius: 9px; }
.f-icon.audio { background: #22c55e; }
.f-icon.audio svg.icon { width: 16px; height: 16px; }

/* شريط التسجيل الصوتي */
.voice-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  background: var(--danger-soft);
  border-radius: var(--radius) var(--radius) 0 0;
}
.voice-bar .rec-dot {
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: var(--danger);
  animation: recPulse 1.1s infinite;
}
.voice-bar .rec-time { font-weight: 800; color: var(--danger); font-variant-numeric: tabular-nums; }
.voice-bar .rec-hint { font-size: 12.5px; color: var(--text-2); }
.voice-bar .spacer { flex: 1; }

@keyframes recPulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.35; transform: scale(0.8); }
}

#voiceBtn.recording { color: var(--danger); background: var(--danger-soft); }

/* صفوف معلومات (بديل الجداول في الملف الشخصي) */
.info-rows {
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  background: var(--panel);
}
.info-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 12px 15px;
  border-bottom: 1px solid var(--border);
  font-size: 13.5px;
  flex-wrap: wrap;
}
.info-row:last-child { border-bottom: none; }
.info-row span { color: var(--text-3); flex-shrink: 0; }
.info-row b { word-break: break-all; text-align: end; }

/* مؤشر السحب للتحديث (iOS) */
.ptr-indicator {
  position: absolute;
  top: calc(env(safe-area-inset-top, 0px) + 8px);
  inset-inline-start: 50%;
  margin-inline-start: -19px;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: var(--panel);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--brand);
  z-index: 95;
  opacity: 0;
  transform: translateY(-46px);
  transition: transform 0.18s ease, opacity 0.18s ease;
  pointer-events: none;
}
.ptr-indicator svg.icon { width: 19px; height: 19px; transition: transform 0.15s; }
.ptr-indicator.ready svg.icon { transform: rotate(180deg); }
.ptr-indicator.spinning svg.icon { animation: ptrSpin 0.7s linear infinite; }

@keyframes ptrSpin {
  to { transform: rotate(360deg); }
}

/* لافتة تفعيل الإشعارات */
.push-banner {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 10px 16px 0;
  padding: 11px 15px;
  background: var(--brand-soft);
  border: 1px solid var(--brand);
  border-radius: 13px;
}
.push-banner .pb-text { flex: 1; min-width: 0; }
.push-banner .pb-text b { display: block; font-size: 13.5px; }
.push-banner .pb-text span { font-size: 12.5px; color: var(--text-2); }

/* قائمة الإشارات @ */
.mention-pop {
  position: absolute;
  bottom: 100%;
  inset-inline-start: 14px;
  margin-bottom: 8px;
  width: 280px;
  max-height: 260px;
  overflow-y: auto;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow-lg);
  z-index: 70;
  padding: 5px;
}
.mention-item {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 7px 10px;
  border-radius: 8px;
  cursor: pointer;
}
.mention-item:hover, .mention-item.selected { background: var(--brand-soft); }
.mention-item .mi-name { font-size: 13.5px; font-weight: 600; }
.mention-item .mi-sub { font-size: 11.5px; color: var(--text-3); }

/* ── اللوحة الجانبية (النقاش/المعلومات/الملفات) ─────────────── */
.side-panel {
  width: 380px;
  background: var(--panel);
  border-inline-start: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}

.side-panel .sp-header {
  height: 62px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 16px;
  flex-shrink: 0;
}
.side-panel .sp-header h3 { margin: 0; font-size: 15px; flex: 1; }

.side-panel .sp-body { flex: 1; overflow-y: auto; padding: 14px; overscroll-behavior-y: contain; }

.member-row {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 8px 6px;
  border-radius: 9px;
}
.member-row:hover { background: var(--hover); }
.member-row .m-info { flex: 1; min-width: 0; }
.member-row .m-name { font-size: 13.5px; font-weight: 600; }
.member-row .m-sub { font-size: 12px; color: var(--text-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ── النوافذ المنبثقة ───────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 19, 32, 0.55);
  backdrop-filter: blur(3px);
  z-index: 100;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 60px 20px 20px;
  overflow-y: auto;
}

.modal {
  background: var(--panel);
  border-radius: 18px;
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 520px;
  animation: modalIn 0.18s ease;
}
.modal.wide { max-width: 680px; }

@keyframes modalIn {
  from { opacity: 0; transform: translateY(-14px) scale(0.98); }
  to { opacity: 1; transform: none; }
}

.modal-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 18px 22px 0;
}
.modal-head h3 { margin: 0; flex: 1; font-size: 17px; }

.modal-body { padding: 18px 22px; }
.modal-foot {
  display: flex;
  justify-content: flex-end;
  gap: 9px;
  padding: 0 22px 20px;
}

/* قائمة اختيار مستخدمين */
.user-pick-list { max-height: 300px; overflow-y: auto; border: 1px solid var(--border); border-radius: 10px; padding: 5px; }
.user-pick {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 10px;
  border-radius: 8px;
  cursor: pointer;
}
.user-pick:hover { background: var(--hover); }
.user-pick input { accent-color: var(--brand); width: 16px; height: 16px; }
.user-pick .up-name { font-size: 13.5px; font-weight: 600; }
.user-pick .up-sub { font-size: 11.5px; color: var(--text-3); }

/* ── القوائم المنسدلة ───────────────────────────────────────── */
.dropdown { position: relative; }

.dropdown-menu {
  position: absolute;
  top: calc(100% + 6px);
  inset-inline-end: 0;
  min-width: 210px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow-lg);
  padding: 6px;
  z-index: 90;
  display: none;
}
.dropdown-menu.open { display: block; }
.dropdown-menu.up { top: auto; bottom: calc(100% + 6px); }

.dd-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 8px 12px;
  border: none;
  background: none;
  color: var(--text);
  font-family: inherit;
  font-size: 13.5px;
  font-weight: 500;
  border-radius: 8px;
  cursor: pointer;
  text-align: start;
}
.dd-item:hover { background: var(--hover); text-decoration: none; color: var(--text); }
.dd-item.danger { color: var(--danger); }
.dd-item.danger:hover { background: var(--danger-soft); }
.dd-item svg.icon { width: 16px; height: 16px; color: var(--text-2); }
.dd-item.danger svg.icon { color: var(--danger); }
.dd-sep { height: 1px; background: var(--border); margin: 5px 8px; }
.dd-head { padding: 6px 12px 2px; font-size: 11.5px; font-weight: 700; color: var(--text-3); }

/* ── الإشعارات المنبثقة (Toast) ─────────────────────────────── */
.toast-wrap {
  position: fixed;
  bottom: 22px;
  inset-inline-start: 22px;
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 9px;
}

.toast {
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--border);
  border-inline-start: 4px solid var(--brand);
  padding: 12px 16px;
  border-radius: 12px;
  box-shadow: var(--shadow-lg);
  font-size: 13.5px;
  min-width: 260px;
  max-width: 360px;
  animation: toastIn 0.25s ease;
  cursor: pointer;
}
.toast.error { border-inline-start-color: var(--danger); }
.toast.success { border-inline-start-color: var(--success); }
.toast b { display: block; margin-bottom: 2px; }
.toast .t-body { color: var(--text-2); font-size: 12.5px; }

@keyframes toastIn {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: none; }
}

/* ── معاينة الوسائط (Lightbox) ──────────────────────────────── */
.lightbox {
  position: fixed;
  inset: 0;
  background: rgba(10, 12, 20, 0.9);
  z-index: 300;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 30px;
}
.lightbox img { max-width: 92%; max-height: 82vh; border-radius: 10px; }
.lightbox iframe { width: 92%; height: 85vh; border: none; border-radius: 10px; background: #fff; }
.lightbox .lb-bar { position: absolute; top: 14px; inset-inline-end: 18px; display: flex; gap: 8px; }
.lightbox .lb-bar .btn-icon { color: #fff; background: rgba(255,255,255,0.12); }
.lightbox .lb-bar .btn-icon:hover { background: rgba(255,255,255,0.25); }
.lightbox .lb-name { color: #cbd5e1; margin-top: 12px; font-size: 13px; }

/* ============================================================
   الصفحات العامة (قنوات/ملفات/إشعارات/ملف شخصي)
   ============================================================ */
.page-shell { min-height: 100vh; display: flex; flex-direction: column; }

.topbar {
  height: 60px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 22px;
  position: sticky;
  top: 0;
  z-index: 50;
}

.topbar .brand { display: flex; align-items: center; gap: 10px; font-weight: 800; color: var(--text); font-size: 15.5px; }
.topbar .brand:hover { text-decoration: none; }
.topbar .brand .mark {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--brand), #7c93ff);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  overflow: hidden;
}
.topbar .brand .mark img { width: 100%; height: 100%; object-fit: cover; }
.topbar .brand .mark svg { width: 17px; height: 17px; }

.topbar nav { display: flex; gap: 4px; flex: 1; }
.topbar nav a {
  padding: 7px 14px;
  border-radius: 9px;
  color: var(--text-2);
  font-size: 13.5px;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 7px;
}
.topbar nav a:hover { background: var(--hover); color: var(--text); text-decoration: none; }
.topbar nav a.active { background: var(--brand-soft); color: var(--brand); }

.page-content { flex: 1; padding: 26px; max-width: 1200px; margin: 0 auto; width: 100%; }

.page-head { display: flex; align-items: center; gap: 14px; margin-bottom: 22px; flex-wrap: wrap; }
.page-head h1 { margin: 0; font-size: 22px; flex: 1; }
.page-head p { margin: 4px 0 0; color: var(--text-2); font-size: 13.5px; width: 100%; }

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}

.grid { display: grid; gap: 16px; }
.grid.cols-2 { grid-template-columns: repeat(2, 1fr); }
.grid.cols-3 { grid-template-columns: repeat(3, 1fr); }
.grid.cols-4 { grid-template-columns: repeat(4, 1fr); }

/* جداول */
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); background: var(--panel); }

table.table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
table.table th {
  text-align: start;
  padding: 12px 16px;
  background: var(--panel-2);
  color: var(--text-2);
  font-size: 12.5px;
  font-weight: 700;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
table.table td { padding: 12px 16px; border-bottom: 1px solid var(--border); vertical-align: middle; }
table.table tr:last-child td { border-bottom: none; }
table.table tr:hover td { background: var(--panel-2); }

/* ترقيم الصفحات */
.pagination { display: flex; gap: 6px; margin-top: 18px; flex-wrap: wrap; }
.pagination a, .pagination span {
  padding: 7px 13px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text-2);
  font-size: 13px;
  font-weight: 600;
}
.pagination a:hover { border-color: var(--brand); color: var(--brand); text-decoration: none; }
.pagination .current { background: var(--brand); color: #fff; border-color: var(--brand); }

/* ============================================================
   لوحة التحكم الإدارية
   ============================================================ */
.admin-shell { display: flex; min-height: 100vh; }

.admin-sidebar {
  width: 250px;
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  border-inline-end: 1px solid var(--sidebar-border);
}

.admin-sidebar .as-header { padding: 18px 16px; display: flex; align-items: center; gap: 11px; border-bottom: 1px solid var(--sidebar-border); }
.admin-sidebar .as-header .mark {
  width: 38px; height: 38px; border-radius: 11px;
  background: linear-gradient(135deg, var(--brand), #7c93ff);
  display: flex; align-items: center; justify-content: center; color: #fff;
}
.admin-sidebar .as-header h2 { margin: 0; color: var(--sidebar-strong); font-size: 15px; }
.admin-sidebar .as-header span { font-size: 11.5px; color: var(--sidebar-heading); }

.admin-sidebar nav { padding: 12px 10px; flex: 1; }
.admin-sidebar nav .nav-head { padding: 12px 10px 5px; font-size: 11px; font-weight: 700; color: var(--sidebar-heading); }
.admin-sidebar nav a {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 9px 12px;
  border-radius: 9px;
  color: var(--sidebar-text);
  font-size: 13.5px;
  font-weight: 600;
  margin-bottom: 2px;
}
.admin-sidebar nav a:hover { background: var(--sidebar-hover); color: var(--sidebar-strong); text-decoration: none; }
.admin-sidebar nav a.active { background: var(--sidebar-active); color: var(--sidebar-strong); }

.admin-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.admin-content { padding: 26px; max-width: 1250px; width: 100%; margin: 0 auto; }

/* بطاقات الإحصائيات */
.stat-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  display: flex;
  align-items: center;
  gap: 14px;
}
.stat-card .s-icon {
  width: 46px;
  height: 46px;
  border-radius: 13px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--brand-soft);
  color: var(--brand);
  flex-shrink: 0;
}
.stat-card .s-icon.green { background: rgba(33,164,100,0.12); color: var(--success); }
.stat-card .s-icon.orange { background: rgba(240,160,32,0.14); color: var(--warning); }
.stat-card .s-icon.red { background: var(--danger-soft); color: var(--danger); }
.stat-card .s-num { font-size: 22px; font-weight: 800; line-height: 1.2; }
.stat-card .s-label { font-size: 12.5px; color: var(--text-2); }

/* رسم بياني بالأعمدة */
.bar-chart { display: flex; align-items: flex-end; gap: 6px; height: 160px; padding-top: 10px; }
.bar-chart .bar-col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 6px; height: 100%; justify-content: flex-end; }
.bar-chart .bar {
  width: 100%;
  max-width: 34px;
  background: linear-gradient(180deg, var(--brand), #7c93ff);
  border-radius: 6px 6px 3px 3px;
  min-height: 3px;
  position: relative;
  transition: opacity .15s;
}
.bar-chart .bar:hover { opacity: .8; }
.bar-chart .bar-label { font-size: 10.5px; color: var(--text-3); }
.bar-chart .bar-val { font-size: 10.5px; font-weight: 700; color: var(--text-2); }

/* صفوف الترتيب (الأكثر نشاطًا) */
.rank-row { display: flex; align-items: center; gap: 11px; padding: 9px 4px; border-bottom: 1px solid var(--border); }
.rank-row:last-child { border-bottom: none; }
.rank-row .r-num {
  width: 24px; height: 24px; border-radius: 7px;
  background: var(--hover); color: var(--text-2);
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 800; flex-shrink: 0;
}
.rank-row:nth-child(1) .r-num { background: rgba(240,160,32,.18); color: var(--warning); }
.rank-row .r-name { flex: 1; min-width: 0; font-weight: 600; font-size: 13.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rank-row .r-val { font-size: 12.5px; color: var(--text-2); font-weight: 700; }

/* ── بطاقات الملفات ─────────────────────────────────────────── */
.file-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  display: flex;
  gap: 12px;
  align-items: flex-start;
}
.file-card .f-icon { width: 44px; height: 44px; border-radius: 12px; font-size: 11px; }
.file-card .fc-info { flex: 1; min-width: 0; }
.file-card .fc-name { font-weight: 700; font-size: 13.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.file-card .fc-meta { font-size: 12px; color: var(--text-3); margin-top: 2px; }

/* ── الإشعارات ──────────────────────────────────────────────── */
.notif-row {
  display: flex;
  gap: 13px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  align-items: flex-start;
  background: var(--panel);
}
.notif-row:last-child { border-bottom: none; }
.notif-row.unread { background: var(--brand-soft); }
.notif-row .n-body { flex: 1; min-width: 0; }
.notif-row .n-title { font-weight: 700; font-size: 13.5px; }
.notif-row .n-text { font-size: 13px; color: var(--text-2); margin-top: 2px; }
.notif-row .n-time { font-size: 11.5px; color: var(--text-3); margin-top: 4px; }

/* ============================================================
   التجاوب مع الشاشات
   ============================================================ */
.mobile-toggle { display: none; }

@media (max-width: 1100px) {
  .side-panel {
    position: fixed;
    inset-inline-end: 0;
    top: 0;
    bottom: 0;
    z-index: 80;
    box-shadow: var(--shadow-lg);
    width: min(380px, 92vw);
  }
  .grid.cols-4 { grid-template-columns: repeat(2, 1fr); }
  .grid.cols-3 { grid-template-columns: repeat(2, 1fr); }
}

/* زر الرجوع (يظهر على الجوال فقط) */
.back-btn { display: none; }

@media (max-width: 860px) {
  /* منع أي انزلاق أفقي للصفحات (الدُرج المخفي كان يوسّع الصفحة) */
  html, body { overflow-x: hidden; }

  /* إيقاف ارتداد iOS المطاطي على مستوى الصفحة — السحب للتحديث
     المخصص أدناه يتولى التحديث في سفاري وكروم على السواء */
  body:has(.chat-app) { overscroll-behavior-y: none; }

  /* ═══ تدفق تطبيق حقيقي: قائمة المحادثات ← المحادثة بملء الشاشة ═══ */
  .chat-app .sidebar {
    position: static;
    transform: none;
    width: 100%;
    height: 100%;
  }

  .chat-app .chat-main { display: none; }

  body.chat-open .chat-app .sidebar { display: none; }
  body.chat-open .chat-app .chat-main { display: flex; }

  .back-btn { display: inline-flex; }
  .chat-header .mobile-toggle { display: none; }

  /* شريط تنقل سفلي مثل التطبيقات */
  .sidebar-nav {
    order: 10;
    border-bottom: none;
    border-top: 1px solid var(--sidebar-border);
    padding: 8px 14px calc(8px + env(safe-area-inset-bottom));
  }
  .sidebar-nav a { font-size: 11.5px; gap: 4px; padding: 8px 2px; }
  .sidebar { display: flex; flex-direction: column; }
  .sidebar-body { flex: 1; }

  /* لمسات أصلية: أهداف لمس أكبر */
  .channel-item { min-height: 60px; padding: 10px 12px; border-radius: 12px; gap: 12px; }
  .channel-item .ch-name { font-size: 15px; }
  .channel-item .ch-sub { font-size: 12.5px; margin-top: 2px; }
  .sidebar-header { padding-top: calc(16px + env(safe-area-inset-top)); }

  /* الصور الشخصية أوضح وأكبر في قائمة المحادثات على الجوال */
  .channel-item .avatar { width: 44px !important; height: 44px !important; font-size: 15px !important; border-radius: 13px !important; }
  .channel-item .avatar-wrap .presence-dot { width: 12px; height: 12px; }
  .channel-item .ch-icon { width: 44px; height: 44px; border-radius: 13px; background: var(--sidebar-hover); }
  .channel-item .ch-icon svg.icon { width: 20px; height: 20px; }

  /* رأس المحادثة: صورة الطرف الآخر أوضح */
  .chat-header .avatar { width: 40px !important; height: 40px !important; font-size: 14px !important; border-radius: 12px !important; }
  .chat-header .ch-icon svg.icon { width: 22px; height: 22px; }

  /* في المحادثات الجماعية على الجوال: أظهر صورة المُرسِل عند الرسائل الواردة */
  .msg:not(.mine):not(.system-msg) .avatar { width: 34px !important; height: 34px !important; font-size: 12px !important; border-radius: 10px !important; }

  /* الصورة الرمزية للفوتر (المستخدم الحالي) */
  .sidebar-footer .avatar { width: 38px !important; height: 38px !important; font-size: 13px !important; }

  /* ═══ فقاعات رسائل مثل تطبيقات المحادثة ═══ */
  .messages-area { padding: 12px 10px 6px; }

  .msg { padding: 2px 4px; margin-bottom: 5px; }
  .msg:hover { background: transparent; }

  .msg .msg-body {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 4px 16px 16px 16px;
    padding: 8px 13px;
    max-width: 85%;
    flex: 0 1 auto;
    box-shadow: 0 1px 2px rgba(28, 35, 51, 0.05);
  }

  .msg.mine { flex-direction: row-reverse; }
  .msg.mine .avatar-wrap { display: none; }
  .msg.mine .msg-head .name { display: none; }
  .msg.mine .msg-body {
    background: var(--brand-soft);
    border-color: transparent;
    border-radius: 16px 4px 16px 16px;
  }

  .msg.system-msg { padding: 3px; }
  .msg.system-msg .sys-text { background: var(--panel-2); }

  /* الإجراءات باللمس بدل التمرير: نقرة على الرسالة تظهرها */
  .msg:hover .msg-actions { display: none; }
  .msg.show-actions .msg-actions { display: flex; }

  /* اللوحة الجانبية تملأ الشاشة */
  .side-panel { width: 100vw; }

  /* المناطق الآمنة (النوتش وشريط آيفون السفلي) */
  .chat-header { padding: 0 10px; padding-top: env(safe-area-inset-top); height: calc(62px + env(safe-area-inset-top)); }
  /* مسافة سفلية كافية لزر الإرسال فوق مؤشر الهوم/شريط سفاري */
  .composer-wrap { padding: 0 10px; padding-bottom: max(12px, env(safe-area-inset-bottom)); }

  .attach-image { max-width: 230px; }
  .attach-audio audio { max-width: 190px; min-width: 130px; }

  /* ═══ بقية الصفحات (topbar/admin) ═══ */
  .mobile-toggle { display: inline-flex; }

  .sidebar-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(10, 12, 20, 0.5);
    z-index: 39;
  }

  .admin-sidebar {
    position: fixed;
    inset-inline-start: 0;
    transform: translateX(100%);
    visibility: hidden; /* لا يوسّع الصفحة وهو مخفي */
    transition: transform 0.22s ease, visibility 0.22s;
    z-index: 80;
  }
  .admin-sidebar.open { transform: none; visibility: visible; }

  /* الرسم البياني في الإحصائيات: تمرير أفقي داخلي أنيق */
  .bar-chart { overflow-x: auto; padding-bottom: 6px; }
  .bar-chart .bar-col { min-width: 26px; }

  .page-content, .admin-content { padding: 16px; }
  .grid.cols-2, .grid.cols-3 { grid-template-columns: 1fr; }
  .grid.cols-4 { grid-template-columns: repeat(2, 1fr); }

  .topbar nav { overflow-x: auto; }
  .topbar nav a span.nav-label { display: none; }

  /* ═══ صفحات المحتوى (الملف الشخصي وغيرها) على الجوال ═══ */
  .page-head h1 { font-size: 19px; }
  .card { padding: 16px 14px; border-radius: 14px; }
  .card h3 { font-size: 15.5px; }

  table.table th, table.table td { padding: 9px 10px; font-size: 12.5px; }

  /* 16px حد أدنى للحقول — أقل من ذلك يجعل آيفون يكبّر الصفحة تلقائيًا */
  .input, select.input, textarea.input { padding: 12px 14px; font-size: 16px; }
  .composer textarea { font-size: 16px; }
  #threadInput { font-size: 16px; }
  .btn { padding: 11px 18px; }
  .checkbox-row { padding: 11px 0; }
  .checkbox-row input { width: 20px; height: 20px; }

  .avatar.lg { width: 60px; height: 60px; font-size: 22px; }

  .page-content { padding-bottom: calc(24px + env(safe-area-inset-bottom)); }
  .topbar { padding-top: env(safe-area-inset-top); height: calc(60px + env(safe-area-inset-top)); }

  /* الملف الشخصي على الجوال: هيدر مركزي وأزرار بعرض كامل */
  .identity-head { flex-direction: column; text-align: center; }
  .identity-head .avatar.lg { width: 76px; height: 76px; font-size: 26px; }
  .hide-mobile { display: none !important; }
  .card form > .btn:not(.btn-sm) { width: 100%; }
  .info-row { font-size: 14px; }
}

/* ── أدوات مساعدة ───────────────────────────────────────────── */
.flex { display: flex; }
.flex-1 { flex: 1; min-width: 0; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 12px; }
.mt-2 { margin-top: 8px; }
.mt-4 { margin-top: 16px; }
.mb-2 { margin-bottom: 8px; }
.mb-4 { margin-bottom: 16px; }
.text-muted { color: var(--text-3); }
.text-sm { font-size: 12.5px; }
.fw-bold { font-weight: 700; }
.hidden { display: none !important; }
.text-center { text-align: center; }
.empty-state { text-align: center; padding: 44px 20px; color: var(--text-3); }
.empty-state svg { width: 44px; height: 44px; margin-bottom: 10px; opacity: .5; }
