/* === الأساسيات === */

.alh-ft-wrapper {
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  direction: rtl;
  color: #e5e7eb;
}

.alh-ft-card {
  background: radial-gradient(circle at top, #111827 0, #020617 50%, #020617 100%);
  border-radius: 18px;
  border: 1px solid rgba(129, 140, 248, 0.7);
  padding: 16px 18px 20px;
  box-shadow: 0 16px 40px rgba(15, 23, 42, 0.8);
  overflow: hidden;
}

/* === رأس الكارت === */

.alh-ft-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.alh-ft-title {
  font-size: 1.2rem;
  font-weight: 700;
  color: #f9fafb;
}

.alh-ft-actions {
  display: flex;
  gap: 8px;
}

/* === الأزرار === */

.alh-ft-btn {
  border: none;
  border-radius: 999px;
  padding: 6px 14px;
  font-size: 0.8rem;
  cursor: pointer;
  background: rgba(15, 23, 42, 0.9);
  color: #e5e7eb;
  border: 1px solid rgba(148, 163, 184, 0.7);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  transition: transform 0.12s ease, box-shadow 0.12s ease, background 0.12s ease, border-color 0.12s ease;
  white-space: nowrap;
}

.alh-ft-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 8px 20px rgba(15, 23, 42, 0.7);
  border-color: rgba(129, 140, 248, 0.9);
}

.alh-ft-btn-primary {
  background: linear-gradient(135deg, #7c3aed, #a855f7);
  border-color: transparent;
  color: #f9fafb;
}

.alh-ft-btn-primary:hover {
  background: linear-gradient(135deg, #8b5cf6, #c084fc);
}

.alh-ft-btn-secondary {
  background: rgba(15, 23, 42, 0.9);
}

.alh-ft-btn-small {
  padding: 4px 10px;
  font-size: 0.75rem;
}

/* === نموذج الإدخال === */

.alh-ft-form-row {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 12px;
  align-items: flex-end;
}

@media (max-width: 1100px) {
  .alh-ft-form-row {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

.alh-ft-form-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.alh-ft-form-group label {
  font-size: 0.7rem;
  color: #9ca3af;
}

.alh-ft-form-group select,
.alh-ft-form-group input[type="text"] {
  background: rgba(15, 23, 42, 0.9);
  border-radius: 999px;
  border: 1px solid rgba(55, 65, 81, 0.8);
  padding: 6px 10px;
  font-size: 0.8rem;
  color: #e5e7eb;
  outline: none;
}

.alh-ft-form-group select:focus,
.alh-ft-form-group input[type="text"]:focus {
  border-color: rgba(129, 140, 248, 0.9);
  box-shadow: 0 0 0 1px rgba(129, 140, 248, 0.4);
}

.alh-ft-form-group--buttons {
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-start;
  gap: 6px;
}

/* === الشجرة === */

.alh-ft-tree-container {
  overflow-x: auto;
  padding-bottom: 6px;
}

.alh-ft-tree {
  min-height: 120px;
  padding: 14px 8px 4px;
  border-radius: 14px;
  border: 1px dashed rgba(75, 85, 99, 0.8);
  background: radial-gradient(circle at top, rgba(15, 23, 42, 0.9), #020617);
}

/* أدوات تحت الشجرة */

.alh-ft-tree-tools {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 6px;
  margin-bottom: 4px;
}

/* طبقة الأب */

.alh-ft-root-layer {
  display: flex;
  justify-content: center;
  margin-bottom: 16px;
  position: relative;
}

.alh-ft-root-node {
  position: relative;
}

.alh-ft-root-connector {
  position: absolute;
  left: 50%;
  bottom: -22px;
  width: 0;
  height: 22px;
  border-left: 2px solid rgba(148, 163, 184, 0.7);
}

/* طبقة الزوجات */

.alh-ft-wives-layer {
  display: flex;
  justify-content: center;
  gap: 18px;
  margin-bottom: 22px;
  margin-top: 14px;
  position: relative;
}

.alh-ft-wives-layer::before {
  content: "";
  position: absolute;
  top: -12px;
  left: 12%;
  right: 12%;
  border-top: 2px solid rgba(148, 163, 184, 0.7);
}

.alh-ft-wife-column {
  display: flex;
  flex-direction: column;
  align-items: center;
  position: relative;
}

.alh-ft-wife-connector-up {
  width: 0;
  height: 12px;
  border-left: 2px solid rgba(148, 163, 184, 0.7);
  margin-bottom: 4px;
}

.alh-ft-wife-connector {
  width: 0;
  height: 14px;
  border-left: 2px solid rgba(148, 163, 184, 0.7);
  margin-bottom: 4px;
}

/* صف الأبناء لكل زوجة */

.alh-ft-children-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
}

.alh-ft-child-connector {
  width: 0;
  height: 10px;
  border-left: 2px solid rgba(148, 163, 184, 0.7);
  margin: 2px 0;
}

/* كتل الزوجات تحت الابن (تصميم A) */

.alh-ft-child-wives-block-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
}

.alh-ft-child-wife-block {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.alh-ft-child-wife-children {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

/* كتلة عائلة الابن (تمييز عائلة مستقلة) */

.alh-ft-family-block {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 6px 8px 8px;
  border-radius: 16px;
  border: 1px dashed rgba(148, 163, 184, 0.55);
  background: radial-gradient(circle at top, rgba(15, 23, 42, 0.85), rgba(15, 23, 42, 0.75));
}

/* === الحقول (العُقَد) === */

.alh-ft-node {
  min-width: 110px;
  max-width: 170px;
  height: 60px;            /* ارتفاع ثابت */
  padding: 5px 9px;
  border-radius: 14px;
  border: 1px solid;
  font-size: 0.75rem;
  text-align: center;
  cursor: pointer;
  position: relative;
  box-shadow: 0 10px 25px rgba(15, 23, 42, 0.7);
  transition: transform 0.12s ease, box-shadow 0.12s ease, border-color 0.12s ease, background 0.12s ease;
  display: flex;
  flex-direction: column;
  justify-content: center;
  overflow: hidden;
}

.alh-ft-node:hover {
  transform: translateY(-2px);
  box-shadow: 0 14px 30px rgba(15, 23, 42, 0.85);
}

.alh-ft-node-main-label {
  display: block;
  font-weight: 600;
  color: #f9fafb;
  margin-bottom: 1px;
  font-size: 0.78rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.alh-ft-node-sub-label {
  display: block;
  font-size: 0.62rem;
  line-height: 1.3;
  color: #cbd5f5;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ألوان الأساس حسب النوع */

.alh-ft-node-father {
  border-color: rgba(252, 211, 77, 1);
  background: rgba(252, 211, 77, 0.16);
}

.alh-ft-node-wife {
  border-color: rgba(244, 114, 182, 1);
  background: rgba(244, 114, 182, 0.18);
}

/* أبناء / بنات الأب الرئيسي (جيل أول) */

.alh-ft-node-main-child.alh-ft-node-son {
  border-color: rgba(34, 197, 94, 1);
  background: rgba(34, 197, 94, 0.24);
}

.alh-ft-node-main-child.alh-ft-node-daughter {
  border-color: rgba(56, 189, 248, 1);
  background: rgba(56, 189, 248, 0.24);
}

/* الأحفاد (جيل ثاني وما بعده) */

.alh-ft-node-grand-child.alh-ft-node-son {
  border-color: rgba(22, 163, 74, 1);
  background: rgba(22, 163, 74, 0.18);
}

.alh-ft-node-grand-child.alh-ft-node-daughter {
  border-color: rgba(37, 99, 235, 1);
  background: rgba(37, 99, 235, 0.18);
}

/* لو لم يُحدد جيل (احتياط) */

.alh-ft-node-son:not(.alh-ft-node-main-child):not(.alh-ft-node-grand-child) {
  border-color: rgba(34, 197, 94, 1);
  background: rgba(34, 197, 94, 0.16);
}

.alh-ft-node-daughter:not(.alh-ft-node-main-child):not(.alh-ft-node-grand-child) {
  border-color: rgba(56, 189, 248, 1);
  background: rgba(56, 189, 248, 0.16);
}

/* المتوفى */

.alh-ft-node-deceased {
  border-style: dashed;
  opacity: 0.95;
}

.alh-ft-node-deceased::after {
  content: "متوفى";
  position: absolute;
  inset-inline-start: 6px;
  inset-block-start: 4px;
  font-size: 0.6rem;
  padding: 1px 6px;
  border-radius: 999px;
  background: rgba(127, 29, 29, 0.9);
  border: 1px solid rgba(248, 250, 252, 0.4);
  color: #fee2e2;
}

/* المحدد */

.alh-ft-node--selected {
  box-shadow: 0 0 0 2px rgba(250, 204, 21, 0.9), 0 18px 40px rgba(15, 23, 42, 0.9);
  transform: translateY(-3px);
}

/* === الليجند === */

.alh-ft-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 8px;
  font-size: 0.7rem;
  color: #9ca3af;
}

.alh-ft-pill {
  border-radius: 999px;
  padding: 2px 10px;
  border: 1px solid rgba(148, 163, 184, 0.8);
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.alh-ft-pill::before {
  content: "";
  width: 10px;
  height: 10px;
  border-radius: 999px;
  background: #6b7280;
}

.alh-ft-pill-father::before {
  background: linear-gradient(135deg, rgba(252, 211, 77, 1), rgba(250, 204, 21, 1));
}

.alh-ft-pill-wife::before {
  background: linear-gradient(135deg, rgba(236, 72, 153, 1), rgba(244, 114, 182, 1));
}

.alh-ft-pill-main-son::before {
  background: linear-gradient(135deg, rgba(34, 197, 94, 1), rgba(74, 222, 128, 1));
}

.alh-ft-pill-main-daughter::before {
  background: linear-gradient(135deg, rgba(56, 189, 248, 1), rgba(129, 140, 248, 1));
}

.alh-ft-pill-grand-son::before {
  background: linear-gradient(135deg, rgba(22, 163, 74, 1), rgba(45, 212, 191, 1));
}

.alh-ft-pill-grand-daughter::before {
  background: linear-gradient(135deg, rgba(37, 99, 235, 1), rgba(129, 140, 248, 1));
}

.alh-ft-pill-deceased::before {
  background: linear-gradient(135deg, rgba(127, 29, 29, 1), rgba(220, 38, 38, 1));
}

/* === الإحصائيات === */

.alh-ft-stats-wrapper {
  margin-top: 10px;
}

.alh-ft-stats-card {
  margin-top: 6px;
  border-radius: 14px;
  border: 1px solid rgba(148, 163, 184, 0.7);
  background: radial-gradient(circle at top, rgba(15, 23, 42, 0.96), rgba(15, 23, 42, 0.96));
  padding: 10px 12px 12px;
  display: none;
}

.alh-ft-stats-card--visible {
  display: block;
}

.alh-ft-stats-title {
  font-size: 0.85rem;
  font-weight: 600;
  margin-bottom: 8px;
  color: #e5e7eb;
}

.alh-ft-stats-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 6px;
}

@media (max-width: 700px) {
  .alh-ft-stats-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

.alh-ft-stat {
  border-radius: 10px;
  padding: 6px 8px;
  background: radial-gradient(circle at top, rgba(15, 23, 42, 0.9), rgba(15, 23, 42, 0.7));
  border: 1px solid rgba(55, 65, 81, 0.9);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.alh-ft-stat-label {
  font-size: 0.65rem;
  color: #9ca3af;
  margin-bottom: 2px;
  text-align: center;
}

.alh-ft-stat-value {
  font-size: 0.9rem;
  font-weight: 700;
  color: #f9fafb;
  text-align: center;
}

/* === نافذة رسائل الخطأ === */

.alh-ft-notice {
  position: fixed;
  inset-inline-end: 24px;
  inset-block-end: 24px;
  z-index: 9999;
  pointer-events: none;
}

.alh-ft-notice-inner {
  background: radial-gradient(circle at top, rgba(30, 64, 175, 0.96), rgba(30, 64, 175, 0.96));
  border-radius: 12px;
  border: 1px solid rgba(191, 219, 254, 0.9);
  padding: 8px 10px;
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.78rem;
  color: #e5f0ff;
  box-shadow: 0 14px 40px rgba(15, 23, 42, 0.9);
  opacity: 0;
  transform: translateY(10px);
  transition: opacity 0.18s ease, transform 0.18s ease;
  pointer-events: auto;
}

.alh-ft-notice--visible .alh-ft-notice-inner {
  opacity: 1;
  transform: translateY(0);
}

.alh-ft-notice-icon {
  font-size: 0.95rem;
}

.alh-ft-notice-message {
  flex: 1;
}

.alh-ft-notice-close {
  border: none;
  background: transparent;
  color: #e5f0ff;
  font-size: 1rem;
  cursor: pointer;
  padding: 0 4px;
}

/* === طباعة === */

@media print {
  body * {
    visibility: hidden;
  }
  .alh-ft-card,
  .alh-ft-card * {
    visibility: visible;
  }
  .alh-ft-card {
    box-shadow: none !important;
    border-radius: 0 !important;
  }
  .alh-ft-wrapper {
    margin: 0;
  }
  .alh-ft-actions,
  .alh-ft-tree-tools,
  .alh-ft-stats-wrapper .alh-ft-btn,
  .alh-ft-notice {
    display: none !important;
  }
}
