.app { display: flex; height: 100vh; overflow: hidden; }

.sidebar {
  width: 320px; flex-shrink: 0; background: var(--bg-panel);
  border-left: 1px solid var(--border); display: flex; flex-direction: column;
}
.sidebar-top { display: flex; align-items: center; justify-content: space-between; padding: 16px; }
.me { display: flex; align-items: center; gap: 10px; font-weight: 700; }
.icon-btn { background: none; border: none; color: var(--text-dim); font-size: 18px; cursor: pointer; padding: 6px; border-radius: 8px; }
.icon-btn:hover { background: var(--bg-elevated); color: var(--text); }

.new-chat { display: flex; gap: 8px; padding: 0 16px 12px; }
.new-chat input { flex: 1; min-width: 0; }

.tabs { display: flex; gap: 4px; padding: 0 16px 12px; }
.tab { flex: 1; background: var(--bg-elevated); border: none; color: var(--text-dim); padding: 9px; border-radius: var(--radius-sm); cursor: pointer; font-weight: 600; }
.tab.active { background: var(--accent); color: var(--accent-contrast); }

.list { flex: 1; overflow-y: auto; padding: 0 8px; }
.conv-item, .group-item {
  display: flex; align-items: center; gap: 10px; padding: 10px 8px; border-radius: var(--radius-sm);
  cursor: pointer; margin-bottom: 2px;
}
.conv-item:hover, .group-item:hover { background: var(--bg-elevated); }
.conv-item.active, .group-item.active { background: var(--accent-dim); }
.conv-meta { flex: 1; min-width: 0; }
.conv-name { font-weight: 600; font-size: 14px; }
.conv-last { color: var(--text-dim); font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 190px; }
.conv-unread { background: var(--accent); color: var(--accent-contrast); font-size: 11px; font-weight: 800; border-radius: 20px; padding: 1px 7px; }
.empty-list { color: var(--text-dim); text-align: center; padding: 24px 8px; font-size: 13px; }

.new-group-btn { margin: 8px 16px 16px; }

.thread { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.empty-state {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  color: var(--text-dim); gap: 8px;
}
.empty-emoji { font-size: 40px; }

.thread-view { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.thread-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 20px; border-bottom: 1px solid var(--border); flex-shrink: 0;
}
.thread-title { display: flex; align-items: center; gap: 10px; }
.thread-name { font-weight: 700; }
.thread-sub { color: var(--text-dim); font-size: 12.5px; }
.thread-actions { display: flex; align-items: center; gap: 6px; }
.encrypt-toggle { display: flex; align-items: center; gap: 4px; color: var(--text-dim); font-size: 13px; cursor: pointer; }

.messages { flex: 1; overflow-y: auto; padding: 20px; display: flex; flex-direction: column; gap: 10px; }
.msg-row { display: flex; flex-direction: column; max-width: 62%; }
.msg-row.mine { align-self: flex-start; align-items: flex-start; }
.msg-row.theirs { align-self: flex-end; align-items: flex-end; }
.msg-bubble {
  padding: 9px 13px; border-radius: 16px; font-size: 14.5px; line-height: 1.5;
  position: relative; word-break: break-word;
}
/* لونين مختلفين فعليًا للتمييز بين رسالتك ورسالة الطرف الآخر (كانا يستخدمان
   نفس المتغير --primary-light بالخطأ فيطلعان بنفس اللون تقريبًا) */
.msg-row.mine .msg-bubble { background: var(--primary-mid); border-bottom-left-radius: 4px; }
.msg-row.theirs .msg-bubble { background: var(--card); border: 1px solid var(--border); border-bottom-right-radius: 4px; }
.msg-bubble img:not(.femoji) { display: none; } /* الطراز القديم — الصور صارت خارج الفقاعة (.msg-image)؛ نستثني إيموجي Fluent */
.msg-image {
  max-width: 260px; max-height: 320px; display: block; margin-top: 4px;
  border-radius: 12px; cursor: pointer; border: none; background: none;
}
.msg-row.mine .msg-image { align-self: flex-end; }
.msg-row.theirs .msg-image { align-self: flex-start; }

/* بطاقة معاينة رابط (Open Graph) — تظهر تحت أي رسالة فيها رابط، بحال
   واتساب/تيليجرام. مقاسها بحدود .msg-row (max-width: 62%) عشان تنسجم
   مع باقي الفقاعات. */
.link-preview-card {
  display: block; margin-top: 6px; max-width: 280px; border-radius: 12px;
  overflow: hidden; text-decoration: none; background: var(--card);
  border: 1px solid var(--border); transition: opacity .12s ease;
}
.link-preview-card:hover { opacity: 0.88; }
.link-preview-img { width: 100%; max-height: 160px; object-fit: cover; display: block; }
.link-preview-body { padding: 8px 11px; }
.link-preview-title {
  font-size: 13px; font-weight: 700; color: var(--text); line-height: 1.35;
  overflow: hidden; text-overflow: ellipsis; display: -webkit-box;
  -webkit-line-clamp: 2; -webkit-box-orient: vertical;
}
.link-preview-desc {
  font-size: 12px; color: var(--text-dim); margin-top: 3px; line-height: 1.35;
  overflow: hidden; text-overflow: ellipsis; display: -webkit-box;
  -webkit-line-clamp: 2; -webkit-box-orient: vertical;
}
.link-preview-domain { font-size: 11px; color: var(--text-dim); margin-top: 5px; opacity: 0.75; }
.msg-row.mine .link-preview-card { align-self: flex-end; }
.msg-row.theirs .link-preview-card { align-self: flex-start; }
.msg-content { display: flex; flex-direction: column; }
.msg-row.mine .msg-content { align-items: flex-start; }
.msg-row.theirs .msg-content { align-items: flex-end; }
.msg-meta { font-size: 11px; color: var(--text-dim); margin-top: 3px; display: flex; gap: 6px; align-items: center; }
.msg-reactions { display: none; gap: 3px; margin-top: 4px; }
.msg-reaction { background: var(--bg); border: 1px solid var(--border); border-radius: 20px; padding: 1px 7px; font-size: 12px; cursor: pointer; }
.msg-reaction.mine { border-color: var(--accent); }
.msg-actions { display: none; gap: 6px; margin-top: 3px; }
.msg-row.msg-open .msg-reactions,
.msg-row.msg-open .msg-actions { display: flex; }
.msg-bubble { cursor: pointer; }
.msg-actions button { background: none; border: none; color: var(--text-dim); font-size: 11px; cursor: pointer; padding: 0; }
.msg-actions button:hover { color: var(--text); }
.msg-reply-ref { font-size: 11.5px; color: var(--text-dim); border-right: 2px solid var(--accent); padding-right: 6px; margin-bottom: 4px; }

.typing-indicator { padding: 0 20px; font-size: 12.5px; color: var(--text-dim); height: 18px; }

.reply-bar { display: flex; justify-content: space-between; align-items: center; padding: 8px 20px; background: var(--bg-elevated); font-size: 13px; }
.reply-bar button { background: none; border: none; color: var(--text-dim); cursor: pointer; }

.composer { display: flex; align-items: center; gap: 8px; padding: 14px 20px; border-top: 1px solid var(--border); flex-shrink: 0; }
.composer input#messageInput { flex: 1; min-width: 0; }
.composer #attachImageBtn { flex-shrink: 0; }
.composer .image-preview-name {
  max-width: 110px; font-size: 11.5px; color: var(--primary);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex-shrink: 0;
}

.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.55); display: flex;
  align-items: center; justify-content: center; z-index: 100;
}
.modal { background: var(--bg-panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 24px; width: 340px; }
.modal h3 { margin: 0 0 6px; }
.modal-desc { color: var(--text-dim); font-size: 13px; margin: 0 0 14px; }
.modal input, .modal textarea { width: 100%; margin-bottom: 10px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 6px; }

.members-list { max-height: 220px; overflow-y: auto; margin-bottom: 12px; }
.member-row { display: flex; align-items: center; gap: 8px; padding: 6px 0; font-size: 13.5px; }
.member-role { color: var(--text-dim); font-size: 11.5px; margin-right: auto; }
.add-member { display: flex; gap: 6px; margin-bottom: 10px; }
.add-member input { flex: 1; }

/* ================= توازن الديسكتوب/الهاتف =================
 * الوضع الافتراضي (ديسكتوب/تابلت عريض): القائمة والمحادثة جنباً لجنب،
 * زر الرجوع مخفي. تحت 860px (نفس فلسفة نقاط كسر Hostaka 680/400px):
 * تعرض القائمة أو المحادثة بالتناوب بملء الشاشة، متل أي تطبيق مراسلة
 * حقيقي على الجوال — بدل الحشر اللي كان يصير قبل (القائمة + مساحة فاضية
 * ضيقة جنبها، متل ما يظهر بالسكرين شوت الأصلي). */
.back-btn { display: none; }

@media (max-width: 860px) {
  .app { position: relative; }
  .sidebar { width: 100%; border-left: none; }
  .thread { position: absolute; inset: 0; width: 100%; }
  .app:not(.chat-open) .thread { display: none; }
  .app.chat-open .sidebar { display: none; }
  .back-btn { display: inline-flex; }
  .msg-row { max-width: 82%; }
  .messages { padding: 14px; }
  .composer { padding: 10px 14px; }
  .thread-header { padding: 12px 14px; }
  .modal { width: min(340px, calc(100vw - 32px)); }
}

@media (max-width: 400px) {
  .msg-row { max-width: 90%; }
  .conv-last { max-width: 130px; }
  .composer .image-preview-name { max-width: 60px; }
}

/* قائمة خيارات الرسالة (ضغط مطوّل بالهاتف / ضغطتين بالديسكتوب) */
.msg-menu-backdrop { position: fixed; inset: 0; z-index: 998; background: transparent; }
.msg-menu {
  position: fixed; z-index: 999; min-width: 170px;
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg); overflow: hidden;
  animation: msg-menu-in .12s ease;
}
@keyframes msg-menu-in { from { opacity: 0; transform: scale(.96); } to { opacity: 1; transform: scale(1); } }
.msg-menu button {
  display: flex; align-items: center; gap: 10px; width: 100%;
  padding: 11px 14px; border: none; background: none; text-align: right;
  font-family: var(--font-family); font-size: 13.5px; color: var(--text); cursor: pointer;
}
.msg-menu button:hover { background: var(--primary-light); }
.msg-menu button.danger { color: var(--danger); }
.msg-menu button svg { flex-shrink: 0; }
.msg-menu hr { border: none; border-top: 1px solid var(--border); margin: 0; }

/* قائمة خيارات رأس المحادثة: نفس شكل .msg-menu بس أوسع شوي وموضعنة تحت الهيدر */
.chat-menu { min-width: 220px; }

/* معرض الوسائط */
.media-modal { width: min(480px, calc(100vw - 32px)); }
.media-grid {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px;
  max-height: 360px; overflow-y: auto; margin-bottom: 12px;
}
.media-grid img {
  width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: var(--radius-sm);
  cursor: pointer; display: block;
}
.media-empty { color: var(--text-dim); font-size: 13px; text-align: center; padding: 30px 0; grid-column: 1 / -1; }

/* صف عضو محسّن: زر ⋮ لإدارة العضو */
.member-row { position: relative; }
.member-row .avatar, .member-row span:first-of-type { cursor: pointer; }
.member-kebab { background: none; border: none; color: var(--text-dim); cursor: pointer; padding: 4px; }
.member-kebab:hover { color: var(--text); }
.member-submenu {
  position: absolute; left: 0; top: 100%; z-index: 5; min-width: 150px;
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg); overflow: hidden;
}
.member-submenu button {
  display: block; width: 100%; padding: 9px 12px; border: none; background: none;
  text-align: right; font-size: 13px; color: var(--text); cursor: pointer;
}
.member-submenu button:hover { background: var(--primary-light); }
.member-submenu button.danger { color: var(--danger); }

/* نافذة عرض الصورة بالحجم الكامل */
.lightbox { position: fixed; inset: 0; z-index: 1000; display: flex; align-items: center; justify-content: center; }
.lightbox-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,.85); }
.lightbox-body { position: relative; z-index: 1; max-width: 92vw; max-height: 88vh; display: flex; flex-direction: column; align-items: center; gap: 14px; }
.lightbox-body img { max-width: 92vw; max-height: 76vh; border-radius: 10px; display: block; }
.lightbox-actions { display: flex; align-items: center; gap: 10px; }
.lightbox-actions .icon-btn { background: rgba(255,255,255,.12); color: #fff; }
.lightbox-actions .icon-btn:hover { background: rgba(255,255,255,.22); }

/* ============================================================
   تحسين الواجهة (UI/UX polish)
   ملاحظة: هذا القسم مضاف في نهاية الملف (بعد قواعد الجوال القديمة)
   ليتجاوزها بأمان؛ تجاوزات الجوال الخاصة به موجودة في نهايته أيضاً.
   ============================================================ */

/* ترويسة العلامة */
.sidebar-brand {
  display: flex; align-items: center; gap: 10px;
  padding: 16px 16px 12px; border-bottom: 1px solid var(--border);
}
.brand-logo { width: 26px; height: 26px; border-radius: 8px; display: block; }
.brand-name { font-weight: var(--font-weight-bold); font-size: var(--text-base); }

.sidebar-top { padding: 12px 16px; }
.me { font-size: var(--text-sm); }
.me .avatar { width: 38px; height: 38px; }

/* حقل بحث بأيقونة */
.new-chat { padding: 0 16px 12px; }
.search-field { position: relative; flex: 1; min-width: 0; display: flex; align-items: center; }
.search-icon {
  position: absolute; inset-inline-start: 11px; width: 16px; height: 16px;
  color: var(--text-dim); pointer-events: none;
}
.search-field input { width: 100%; padding-inline-start: 36px; }
.new-chat .btn { flex-shrink: 0; }

/* تبويبات كشريط مقسّم */
.tabs {
  gap: 4px; margin: 0 16px 12px; padding: 4px;
  background: var(--input-bg); border-radius: var(--radius-full);
}
.tab { background: transparent; border-radius: var(--radius-full); padding: 8px; }
.tab:hover { color: var(--text); }
.tab.active { background: var(--surface-elevated); color: var(--text); box-shadow: var(--shadow-sm); }

/* عناصر القائمة */
.list { padding: 4px 8px 8px; }
.conv-item, .group-item {
  gap: 12px; padding: 10px; border-radius: var(--radius-md);
  transition: background var(--transition-fast);
}
.conv-item.active, .group-item.active { background: var(--primary-mid); }
.conv-item .avatar, .group-item .avatar { width: 46px; height: 46px; }
.conv-row-top { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.conv-name { font-size: var(--text-sm); }
.conv-time { font-size: 11px; color: var(--text-dim); flex-shrink: 0; }
.conv-last { max-width: none; margin-top: 2px; }
.conv-you { color: var(--text-dim); }
.conv-item.unread .conv-name { font-weight: var(--font-weight-bold); }
.conv-item.unread .conv-last { color: var(--text); }
.conv-unread { min-width: 20px; text-align: center; }

/* حالة الفراغ */
.empty-state { gap: 14px; text-align: center; padding: 24px; }
.empty-emoji {
  width: 88px; height: 88px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  background: var(--primary-light); color: var(--primary);
}
.empty-emoji svg { width: 40px; height: 40px; }
.empty-title { font-size: var(--text-xl); font-weight: var(--font-weight-bold); color: var(--text); }
.empty-hint { font-size: var(--text-sm); color: var(--text-dim); max-width: 320px; line-height: 1.75; }

/* الرسائل */
.msg-bubble { box-shadow: var(--shadow-sm); }
.msg-row.mine .msg-bubble { box-shadow: none; }
.msg-meta { font-size: 10.5px; }

/* المحرّر */
.composer input#messageInput { border-radius: var(--radius-full); padding: 11px 16px; }

/* شريط الرد */
.reply-bar { border-top: 1px solid var(--border); }

@media (max-width: 860px) {
  .sidebar-brand { padding: 14px; }
  .sidebar-top { padding: 10px 14px; }
  .new-chat { padding: 0 14px 10px; }
  .tabs { margin: 0 14px 10px; }
  .empty-emoji { width: 72px; height: 72px; }
  .empty-title { font-size: var(--text-lg); }
}

/* ============================================================
   ثيم orbithub — أخضر غامق داكن (brand override)
   مُضاف في النهاية ليعلو على theme.css/bridge.css في صفحة orbithub فقط.
   ============================================================ */
:root, html {
  --primary: #1e7a4d;
  --primary-h: #17603c;
  --primary-light: rgba(30,122,77,.08);
  --primary-mid: rgba(30,122,77,.16);
  --primary-border: rgba(30,122,77,.28);
  --accent: var(--primary);
  --avatar-gradient: linear-gradient(145deg, #1e7a4d, #46b27a);
}

[data-theme="dark"] {
  --primary: #35c07d;
  --primary-h: #4fd894;
  --primary-light: rgba(53,192,125,.12);
  --primary-mid: rgba(53,192,125,.20);
  --primary-border: rgba(53,192,125,.32);
  --accent: var(--primary);
  --avatar-gradient: linear-gradient(145deg, #2a9d63, #4fd894);

  --black: #000000;
  --dark: #010301;          /* خلفية شبه سوداء */
  --bg: var(--dark);
  --card: #07100b;
  --border: rgba(255,255,255,.07);
  --text: #e7f4ec;
  --muted: #778c81;
  --input-bg: #050b08;
  --modal-bg: #07100b;
  --surface-elevated: #0c1611;
  --post-bg: #07100b;
}

/* فقاعات الرسائل — أخضر غامق داكن */
.msg-row.mine .msg-bubble {
  background: linear-gradient(135deg, #1e7a4d, #14512f);
  color: #f2fff8;
  box-shadow: none;
}
.msg-row.theirs .msg-bubble {
  background: var(--card);
  border: 1px solid var(--border);
}
[data-theme="dark"] .msg-row.mine .msg-bubble {
  background: linear-gradient(135deg, #176040, #0f3d28);
  color: #eafff3;
}
[data-theme="dark"] .msg-row.theirs .msg-bubble {
  background: #0e1d15;
  border-color: rgba(255,255,255,.07);
}

/* إيموجي كبير خارج بطاقة الرسالة (رسالة إيموجي فقط) */
.msg-emoji-only {
  font-size: 2.6rem;
  line-height: 1.15;
  padding: 2px 0;
}
.msg-emoji-only .femoji {
  width: 2.6rem;
  height: 2.6rem;
  vertical-align: middle;
}

/* رسائل النظام (تغيير صورة/كنية/إضافة عضو...) — نص خافت وسط المحادثة
   يظهر تدريجياً مثل ماسنجر */
.msg-system {
  align-self: center;
  max-width: 82%;
  margin: 12px auto;
  padding: 4px 12px;
  text-align: center;
  font-size: 12.5px;
  line-height: 1.5;
  color: var(--muted);
  background: var(--input-bg);
  border-radius: 12px;
  opacity: .9;
  animation: msgSystemFade .55s ease both;
}
.msg-system .femoji {
  width: 1.1em;
  height: 1.1em;
  vertical-align: -.2em;
}
@keyframes msgSystemFade {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: .9; transform: translateY(0); }
}
