body {
  direction: rtl;
  font-family: Tahoma, Arial, sans-serif;
  background: linear-gradient(135deg, #606060, #f2f2f2, #1fc480, #f2f2f2, rgb(245, 194, 194));
  background-size: 400% 400%;
  animation: gradientBG 12s ease infinite;
  min-height: 100vh;
}
@keyframes gradientBG { 0% {background-position: 0% 50%} 50% {background-position: 100% 50%} 100% {background-position: 0% 50%} }

.app-main { padding: 55px 10px 30px; }
.loading { text-align: center; padding: 60px 0; font-size: 18px; }

/* الشريط العلوي */
.main-header {
  position: fixed; top: 0; right: 0; left: 0; height: 44px;
  background: #f8f9fa; border-bottom: 1px solid #ccc;
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 15px; z-index: 1000;
}
.site-title { font-size: 20px; font-weight: bold; text-align: center; flex-grow: 1; color: #333; }
.btn-back { background: #ffc107; color: #000; border-radius: 8px; padding: 4px 12px; text-decoration: none; }
.btn-back:hover { background: #e0a800; color: #000; }
.menu-toggle { display: flex; flex-direction: column; justify-content: center; cursor: pointer; padding: 4px; }
.menu-toggle div { width: 32px; height: 3px; background: #333; margin: 3px 0; border-radius: 2px; }

/* القائمة */
.side-menu {
  position: fixed; top: 44px; right: 10px; background: #fff; border: 1px solid #ccc;
  border-radius: 8px; display: none; flex-direction: column; min-width: 240px; max-height: calc(100vh - 60px);
  overflow-y: auto; box-shadow: 0 4px 12px rgba(0,0,0,.2); z-index: 1001;
}
.side-menu.open { display: flex; }
.side-menu a, .side-menu .menu-user { padding: 10px 15px; color: #333; text-decoration: none; border-bottom: 1px solid #eee; }
.side-menu a:hover { background: #f0f0f0; }
.side-menu .sub a { padding-right: 32px; font-size: 14px; }
.menu-user small { display: block; color: #411be9; font-size: 11px; }

/* قائمة الزر اليمين */
.ctx-menu {
  position: fixed; display: none; background: #fff; border: 1px solid #ccc; border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0,0,0,.25); z-index: 1100; min-width: 200px;
}
.ctx-menu a { display: block; padding: 9px 14px; color: #333; text-decoration: none; border-bottom: 1px solid #eee; }
.ctx-menu a:hover { background: #f0f0f0; }

/* الصفحة الرئيسية — المستويات */
.level { display: flex; justify-content: center; flex-wrap: wrap; gap: 6px; margin: 40px 0; }
.member {
  width: 230px; padding: 10px 4px; background: #e0f7fa; border-radius: 10px; border: 1px solid #00796b;
  cursor: pointer; transition: .3s; user-select: none; -webkit-user-select: none; text-align: center;
}
.member:hover { transform: scale(1.05); background: #b2dfdb; }
.member.deceased { color: darkred; font-weight: bold; }
.member.selected { background: #28a745 !important; color: #fff !important; font-weight: bold; }
.member.ancestor { background: #fff9c4 !important; color: #3e2723 !important; font-weight: bold; }
.member.descendant { background: #a5d6a7 !important; border-color: #4caf50; }

/* صفحة الشجرة */
.tree-wrap { position: relative; overflow-x: auto; -webkit-overflow-scrolling: touch; padding-bottom: 20px; }
.tree-inner { position: relative; min-width: max-content; padding: 0 20px; }
.tree-level { display: flex; justify-content: center; flex-wrap: nowrap; gap: 25px; margin-top: 45px; position: relative; z-index: 2; }
.tree-level .member { width: 130px; padding: 6px 8px; background: #fff; }
.tree-level .member.is-root { width: 230px; }
.tree-level .member.selected-member { background: #2e7d32 !important; color: #fff !important; font-weight: bold; }
.tree-level .member.ancestor-member { background: #fff9c4 !important; border: 2px solid #ffb600; }
.tree-level .member.descendant-member { background: #a5d6a7 !important; border-color: #4caf50; }
.tree-level .member.selected-deceased { background: rgba(200,0,0,.55) !important; }
svg.lines { position: absolute; top: 0; right: 0; pointer-events: none; z-index: 1; }
.lineage { margin: 6px; color: #0d47a1; font-weight: bold; font-size: 19px; text-align: center; }

/* البطاقات */
.page-card {
  max-width: 760px; margin: 25px auto; background: #fff; border-radius: 18px; padding: 24px;
  box-shadow: 0 8px 24px rgba(0,0,0,.18);
}
.page-card.wide { max-width: 1250px; }
.profile-img { width: 115px; height: 150px; object-fit: cover; border-radius: 14px; border: 2px solid #ccc; background: #f8f8f8; }
.photo-picker { width: 115px; height: 150px; border: 2px dashed #aaa; border-radius: 12px; overflow: hidden; cursor: pointer; display: flex; align-items: center; justify-content: center; }
.photo-picker img { width: 100%; height: 100%; object-fit: cover; }
.steps { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 16px; }
.steps button { flex: 1; min-width: 90px; border: 0; border-radius: 10px; padding: 7px; background: #ddd; }
.steps button.active { background: #0d6efd; color: #fff; }
.step { display: none; }
.step.active { display: block; }
.form-row-label { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.form-row-label > label { width: 120px; flex-shrink: 0; margin: 0; font-size: 14px; }
.form-row-label > .f { flex: 1; }
.social-links a { font-size: 15px; margin-left: 10px; }
.stats-box { display: flex; gap: 14px; justify-content: center; flex-wrap: wrap; margin-bottom: 18px; }
.stats-box .s { flex: 1; min-width: 180px; background: #f5f9ff; border-radius: 12px; padding: 14px; text-align: center; font-weight: bold; }
.filter-chips button { margin: 3px; }
.search-results .result { display: flex; justify-content: space-between; align-items: center; padding: 8px 10px; border-bottom: 1px solid #eee; }

/* التقرير المطبوع */
.report-head { text-align: center; margin-bottom: 14px; }
.report-head img { height: 90px; width: 190px; object-fit: contain; }
@media print {
  body { background: #fff !important; animation: none; }
  .noprint, .noprint * { display: none !important; }
  .app-main { padding: 0; }
  .page-card { box-shadow: none; margin: 0; padding: 0; max-width: none; }
}
@media (max-width: 576px) {
  .member { width: 46%; font-size: 14px; }
  .form-row-label { flex-direction: column; align-items: stretch; }
  .form-row-label > label { width: auto; }
}

/* الجرس */
.bell { position: relative; font-size: 20px; text-decoration: none; margin-left: 10px; }
.bell .cnt { position: absolute; top: -6px; left: -10px; background: #dc3545; color: #fff; border-radius: 10px; font-size: 11px; padding: 1px 6px; font-weight: bold; }
.side-menu .badge, .top-nav .badge { font-size: 11px; vertical-align: middle; }

/* الرسائل */
.chat-card { max-width: 820px; }
.chat-box { height: 55vh; overflow-y: auto; background: #f4f6f8; border-radius: 12px; padding: 12px; display: flex; flex-direction: column; gap: 8px; }
.msg { max-width: 80%; padding: 8px 12px; border-radius: 12px; box-shadow: 0 1px 2px rgba(0,0,0,.08); word-wrap: break-word; }
.msg.mine { align-self: flex-start; background: #d1f7d6; border-top-right-radius: 2px; }
.msg.theirs { align-self: flex-end; background: #fff; border-top-left-radius: 2px; }
.msg .meta { font-size: 11px; color: #777; margin-bottom: 3px; }

/* شاشات الكمبيوتر */
.top-nav { display: none; }
@media (min-width: 992px) {
  .main-header { height: 52px; padding: 0 24px; }
  .side-menu { top: 52px; right: 24px; }
  .app-main { padding: 70px 30px 40px; }
  .site-title { flex-grow: 0; margin-left: 24px; font-size: 22px; }
  .top-nav { display: flex; gap: 4px; flex-grow: 1; }
  .top-nav a { color: #333; text-decoration: none; padding: 6px 12px; border-radius: 8px; font-size: 15px; }
  .top-nav a:hover { background: #e9ecef; }
  .page-card { max-width: 900px; padding: 32px; }
  .page-card.wide { max-width: 1300px; }
  .chat-card { max-width: 900px; }
  .level { gap: 10px; margin: 46px auto; max-width: 1600px; }
  .member { width: 250px; font-size: 16px; }
  .tree-level .member { width: 150px; }
  .profile-img { width: 150px; height: 195px; }
  .form-row-label > label { width: 150px; }
  .lineage { font-size: 22px; }
}
@media (min-width: 1400px) {
  .page-card { max-width: 1000px; }
}
