html { scroll-behavior: smooth; }
/* 
  شجرة الحباب - ملف التصميم

  للتعديل السريع:
  - غيّر الألوان من :root
  - غيّر شكل البطاقات من .card
  - غيّر شكل الشجرة من .tree-box و .node-label
  - بعد التعديل نفذ: firebase deploy
*/

:root {
  --bg: #f7f6f2;
  --surface: #ffffff;
  --surface-soft: #fbfaf7;
  --text: #17201c;
  --muted: #6d746f;
  --line: #e6e0d6;
  --primary: #123d35;
  --primary-2: #1f5f50;
  --primary-soft: #edf5f2;
  --gold: #b89455;
  --danger: #a62b22;
  --danger-soft: #fff1ef;
  --shadow: 0 18px 45px rgba(30, 38, 34, .07);
  --radius-lg: 24px;
  --radius-md: 16px;
  --radius-sm: 12px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  direction: rtl;
  background:
    radial-gradient(circle at top right, rgba(184, 148, 85, .12), transparent 32rem),
    linear-gradient(180deg, #fbfaf7 0%, var(--bg) 100%);
  color: var(--text);
  font-family: 'Amiri', serif;
  line-height: 1.75;
}

.site-header {
  position: relative;
  background: rgba(255, 255, 255, .9);
  border-bottom: 1px solid rgba(230, 224, 214, .85);
  padding: 34px 18px 30px;
  text-align: center;
}

.site-header::after {
  content: "";
  position: absolute;
  bottom: -1px;
  right: 50%;
  transform: translateX(50%);
  width: 92px;
  height: 3px;
  border-radius: 999px;
  background: linear-gradient(90deg, transparent, var(--gold), transparent);
}

.site-header h1 {
  margin: 0;
  font-size: clamp(1.7rem, 4vw, 2.45rem);
  font-weight: 900;
  color: var(--primary);
}

.site-header p {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: .98rem;
}

.container {
  width: min(1180px, calc(100% - 28px));
  margin: 22px auto 48px;
  display: grid;
  gap: 18px;
}

.panel {
  background: rgba(255, 255, 255, .94);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 22px;
  box-shadow: var(--shadow);
}

.toolbar {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
  margin-bottom: 18px;
}

.toolbar h2,
.panel h2 {
  margin: 0 0 4px;
  font-size: 1.18rem;
  font-weight: 900;
  color: var(--primary);
}

.toolbar p,
.muted {
  margin: 0;
  color: var(--muted);
  font-size: .92rem;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  font-size: 1rem;
  background: var(--surface-soft);
  color: var(--text);
  outline: none;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--primary-2);
  box-shadow: 0 0 0 4px var(--primary-soft);
  background: #fff;
}

label {
  display: block;
  margin-bottom: 13px;
  color: var(--primary);
  font-weight: 800;
  font-size: .94rem;
}

button,
.link-button {
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 10px 15px;
  cursor: pointer;
  font-weight: 800;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
}

button:hover,
.link-button:hover {
  opacity: .92;
}

.primary {
  background: linear-gradient(135deg, var(--primary), var(--primary-2));
  color: #fff;
  box-shadow: 0 10px 24px rgba(18, 61, 53, .18);
}

.ghost {
  background: var(--surface-soft);
  color: var(--primary);
  border-color: var(--line);
}

.danger {
  background: var(--danger-soft);
  color: var(--danger);
  border-color: #f3c9c3;
}

.button-row,
.top-actions,
.card-actions {
  display: flex;
  gap: 9px;
  flex-wrap: wrap;
}

.top-actions {
  margin-bottom: 16px;
}

.cards {
  display: grid;
  gap: 12px;
}

.card {
  position: relative;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--surface);
  padding: 16px;
  box-shadow: 0 8px 22px rgba(30, 38, 34, .035);
}

.card::before {
  content: "";
  position: absolute;
  inset-block: 14px;
  inset-inline-start: 0;
  width: 3px;
  border-radius: 999px;
  background: var(--gold);
  opacity: .75;
}

.card h3 {
  margin: 0 0 6px;
  font-size: 1.08rem;
  font-weight: 900;
  color: var(--primary);
}

.badge {
  display: inline-block;
  background: var(--primary-soft);
  color: var(--primary);
  border: 1px solid rgba(31, 95, 80, .12);
  border-radius: 999px;
  padding: 3px 10px;
  font-size: .78rem;
  font-weight: 900;
  margin-inline-start: 7px;
}

.card .meta {
  color: var(--muted);
  font-size: .92rem;
  line-height: 1.9;
}

.tree-box {
  min-height: 300px;
  background: linear-gradient(180deg, rgba(251,250,247,.9), rgba(255,255,255,.95));
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 18px;
  overflow: auto;
}

.tree-node {
  margin: 10px 22px 10px 0;
  border-right: 1px solid #ddd5c9;
  padding-right: 14px;
}

.node-label {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 8px 13px;
  cursor: pointer;
  background: #fff;
  font-weight: 900;
  color: var(--text);
  box-shadow: 0 6px 18px rgba(30, 38, 34, .04);
}

.node-label:hover {
  background: var(--primary-soft);
}

.node-label.group {
  background: var(--primary-soft);
  color: var(--primary);
  border-color: rgba(31, 95, 80, .14);
}

.node-label.person {
  background: #fff;
}

.node-children {
  margin-top: 9px;
}

.empty {
  color: var(--muted);
  text-align: center;
  border: 1px dashed var(--line);
  border-radius: var(--radius-md);
  padding: 30px;
  background: var(--surface-soft);
}

.hidden {
  display: none !important;
}

#loginPanel {
  max-width: 620px;
  margin: 0 auto;
  width: 100%;
}

#adminPanel {
  display: grid;
  gap: 16px;
}

@media (max-width: 760px) {
  .site-header {
    padding: 26px 14px 24px;
  }

  .container {
    width: min(100% - 20px, 1180px);
    margin-top: 14px;
  }

  .panel {
    padding: 16px;
    border-radius: 18px;
  }

  .toolbar {
    align-items: stretch;
    flex-direction: column;
  }

  .button-row,
  .top-actions,
  .card-actions {
    display: grid;
    grid-template-columns: 1fr;
  }

  button,
  .link-button {
    width: 100%;
  }

  .tree-box {
    padding: 12px;
  }

  .tree-node {
    margin-right: 14px;
    padding-right: 10px;
  }
}


/* إصلاح عرض الشجرة: الأفرع والأشخاص يظهرون داخل الشجرة */
.node-label.group {
  font-weight: 900;
}

.node-label.person {
  background: #ffffff;
  border-color: var(--line);
}


/* تحديث شجرة النسب والبحث الذكي */
.tree-actions {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}

.tree-actions input {
  min-width: min(280px, 100%);
}

.tree-box {
  background:
    linear-gradient(180deg, rgba(255,255,255,.96), rgba(250,249,246,.96));
  padding: 22px;
}

.tree-node {
  position: relative;
  margin: 12px 26px 12px 0;
  border-right: 2px solid rgba(31, 95, 80, .14);
  padding-right: 18px;
}

.tree-node::before {
  content: "";
  position: absolute;
  top: 18px;
  right: -2px;
  width: 15px;
  border-top: 2px solid rgba(31, 95, 80, .14);
}

.node-label {
  min-width: 120px;
  justify-content: flex-start;
}

.node-label.group {
  background: #edf5f2;
  color: #123d35;
  border-color: rgba(31, 95, 80, .22);
}

.node-label.person {
  background: #ffffff;
  color: var(--text);
  border-color: var(--line);
}

.node-label.match {
  background: #fff7e6;
  border-color: #b89455;
  color: #5a3d10;
  box-shadow: 0 0 0 4px rgba(184,148,85,.14);
}

.toggle-symbol {
  color: #b89455;
  font-weight: 900;
}

.person-card .lineage {
  color: var(--primary);
  font-weight: 800;
}

@media (max-width: 760px) {
  .tree-actions {
    display: grid;
    grid-template-columns: 1fr;
  }
}


/* تحديث لوحة الإدارة: البحث الذكي وعرض التابعين */
.children-panel {
  border-color: rgba(31, 95, 80, .22);
  background: linear-gradient(180deg, rgba(237,245,242,.45), rgba(255,255,255,.96));
}

.child-card {
  border-right: 4px solid var(--primary);
}

.card-actions button {
  white-space: nowrap;
}


/* بحث النسب المطور */
.person-card .lineage,
.card .lineage {
  color: var(--primary);
  font-weight: 800;
}


.comment-form {
  display: grid;
  gap: 10px;
  margin-top: 14px;
}

.comment-card {
  border-right: 4px solid var(--gold);
}

/* التحديث الكبير للواجهة والشجرة */
.hero {
  min-height: 72vh;
  display: grid;
  place-items: center;
  text-align: center;
  padding: 48px 18px;
  background: radial-gradient(circle at top, rgba(184,148,85,.18), transparent 34rem), linear-gradient(180deg, rgba(255,255,255,.96), rgba(247,246,242,.95));
  border-bottom: 1px solid var(--line);
}
.hero-inner { animation: heroRise .9s ease both; max-width: 780px; }
.hero-kicker { display:inline-flex; border:1px solid var(--line); color:var(--primary); background:var(--surface-soft); border-radius:999px; padding:5px 14px; font-weight:800; margin-bottom:12px; }
.hero-title { font-size: clamp(2.4rem, 7vw, 5rem); margin:0; color:var(--primary); font-weight:900; animation:titleGlow 2.5s ease-in-out infinite alternate; }
.hero-subtitle { color:var(--muted); margin:12px auto 24px; font-size:1.05rem; }
.hero-actions { display:flex; justify-content:center; gap:12px; flex-wrap:wrap; }
.hero-link { min-width:160px; }
@keyframes heroRise { from { opacity:0; transform:translateY(28px);} to { opacity:1; transform:translateY(0);} }
@keyframes titleGlow { from { text-shadow:0 0 0 rgba(184,148,85,0);} to { text-shadow:0 10px 35px rgba(184,148,85,.28);} }
.section-muted {
  display: block !important;
}
.tree-actions, .bulk-form { display:flex; gap:10px; align-items:center; flex-wrap:wrap; }
.tree-actions input { min-width:min(320px,100%); }
.knockout-tree { overflow:auto; min-height:420px; text-align:center; }
.bracket-root { display:inline-flex; flex-direction:column; align-items:center; gap:28px; min-width:100%; padding:20px; }
.bracket-node { display:flex; align-items:center; justify-content:center; gap:24px; position:relative; }
.bracket-label { min-width:130px; max-width:240px; padding:10px 14px; border-radius:999px; border:1px solid var(--line); background:#fff; color:var(--text); font-weight:900; box-shadow:0 8px 22px rgba(30,38,34,.05); cursor:pointer; display:inline-flex; align-items:center; justify-content:center; gap:7px; white-space:nowrap; }
.bracket-label.group { background:var(--primary-soft); color:var(--primary); border-color:rgba(31,95,80,.22); }
.bracket-label.match { background:#fff7e6; border-color:var(--gold); box-shadow:0 0 0 4px rgba(184,148,85,.14); }
.bracket-children { display:flex; flex-direction:column; gap:16px; padding-right:28px; border-right:2px solid rgba(31,95,80,.16); position:relative; }
.bracket-children::before { content:""; position:absolute; top:50%; right:-28px; width:28px; border-top:2px solid rgba(31,95,80,.16); }
.print-tree-only .hero, .print-tree-only #namesSection, .print-tree-only #commentsSection, .print-tree-only .tree-actions, .print-tree-only .site-header { display:none !important; }
.print-tree-only #treeSection { box-shadow:none; border:none; }
.print-tree-only .container { width:100%; margin:0; }
@media print { body.print-tree-only { background:#fff; } }
@media (max-width:760px) { .hero-actions, .tree-actions, .bulk-form { display:grid; grid-template-columns:1fr; } .bracket-node { flex-direction:column; gap:12px; } .bracket-children { border-right:0; padding-right:0; border-top:2px solid rgba(31,95,80,.16); padding-top:14px; } .bracket-children::before { display:none; } }


/* تحسينات التنقل والأنيميشن */
.hero-kicker {
  display: none !important;
}

.focus-section {
  animation: sectionFade .35s ease both;
}

.section-hidden {
  display: block !important;
}

@keyframes sectionFade {
  from {
    opacity: 0;
    transform: translateY(14px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.hero-link,
button,
.card,
.panel {
  transition: transform .18s ease, opacity .18s ease, box-shadow .18s ease, background .18s ease;
}

.hero-link:hover,
button:hover {
  transform: translateY(-1px);
}

/* شجرة تفاعلية كخريطة */
.tree-viewport {
  height: min(72vh, 760px);
  min-height: 460px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 24px;
  background:
    linear-gradient(rgba(18,61,53,.035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(18,61,53,.035) 1px, transparent 1px),
    #fff;
  background-size: 28px 28px;
  cursor: grab;
  position: relative;
}

.tree-viewport.dragging {
  cursor: grabbing;
}

.tree-map {
  transform-origin: center top;
  transition: transform .08s linear;
  width: max-content;
  min-width: 100%;
  padding: 42px;
  margin: auto;
  text-align: center;
  box-shadow: none !important;
  border: none !important;
  background: transparent !important;
}

.map-root {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 34px;
}

.map-node {
  display: flex;
  flex-direction: column;
  align-items: center;
  position: relative;
}

.map-label {
  min-width: 132px;
  max-width: 240px;
  padding: 10px 15px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--text);
  font-weight: 900;
  box-shadow: 0 8px 22px rgba(30,38,34,.06);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  white-space: nowrap;
  position: relative;
  z-index: 2;
}

.map-label.group {
  background: var(--primary-soft);
  color: var(--primary);
  border-color: rgba(31,95,80,.22);
}

.map-label.person {
  background: #fff;
}

.map-label.match {
  background: #fff7e6;
  border-color: var(--gold);
  box-shadow: 0 0 0 4px rgba(184,148,85,.14);
}

.map-children {
  display: flex;
  justify-content: center;
  align-items: flex-start;
  gap: 24px;
  margin-top: 34px;
  padding-top: 28px;
  position: relative;
}

.map-children::before {
  content: "";
  position: absolute;
  top: 0;
  right: 50%;
  height: 28px;
  border-right: 2px solid rgba(31,95,80,.22);
}

.map-children > .map-node::before {
  content: "";
  position: absolute;
  top: -28px;
  right: 50%;
  height: 28px;
  border-right: 2px solid rgba(31,95,80,.22);
}

.map-children > .map-node::after {
  content: "";
  position: absolute;
  top: -28px;
  height: 2px;
  background: rgba(31,95,80,.22);
  width: calc(100% + 24px);
  right: 50%;
}

.map-children > .map-node:first-child::after {
  width: 50%;
}

.map-children > .map-node:last-child::after {
  right: auto;
  left: 50%;
  width: 50%;
}

.map-children > .map-node:only-child::after {
  display: none;
}

/* طباعة/تحميل الشجرة */
@media print {
  .print-tree-only .hero,
  .print-tree-only #namesSection,
  .print-tree-only #commentsSection,
  .print-tree-only .tree-actions {
    display: none !important;
  }
}

/* تحسين dropdown البحث في الإدارة */
#parentSearch,
#bulkParentSearch {
  margin-bottom: 8px;
}

select option {
  white-space: normal;
}

@media (max-width: 760px) {
  .tree-viewport {
    min-height: 520px;
  }

  .map-children {
    flex-direction: column;
    align-items: center;
    gap: 20px;
  }

  .map-children > .map-node::after,
  .map-children > .map-node::before,
  .map-children::before {
    display: none;
  }
}


/* إصلاح التنقل بين الأقسام */
.focus-section {
  scroll-margin-top: 24px;
  display: block;
}

.section-hidden,
.section-muted {
  display: block !important;
}
