/* =========================================================
   Khashoggi Family — Tree (heritage edition, mobile-first)
   ========================================================= */

.kf-tree-root {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background:
    radial-gradient(ellipse 70% 60% at 50% 0%, rgba(230, 192, 125, 0.05), transparent 70%),
    var(--ink-deep);
}

.kf-tree-canvas {
  position: absolute;
  inset: 0;
  cursor: grab;
  touch-action: none;
  overscroll-behavior: contain;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}
.kf-tree-canvas:active { cursor: grabbing; }
.kf-tree-canvas svg {
  width: 100%; height: 100%; display: block;
  touch-action: none;
}

/* Toolbar */
.kf-tree-toolbar {
  position: absolute;
  top: 14px; right: 14px; left: 14px;
  display: flex; align-items: center; gap: 10px;
  z-index: 10;
  flex-wrap: wrap;
  pointer-events: none;
}
.kf-tree-toolbar > * { pointer-events: auto; }

.kf-tree-search {
  position: relative;
  flex: 1 1 240px;
  max-width: 400px;
  display: flex;
  align-items: center;
}
.kf-tree-search input {
  width: 100%;
  padding: 11px 40px 11px 14px;
  border-radius: 12px;
  border: 1px solid var(--glass-line);
  background: rgba(11, 12, 28, 0.8);
  backdrop-filter: blur(14px);
  color: var(--parchment);
  font-family: inherit;
  font-size: 15px;
  direction: rtl;
  min-height: 44px;
}
.kf-tree-search input:focus {
  outline: none;
  border-color: var(--gold);
  box-shadow: 0 0 0 3px rgba(230, 192, 125, 0.15);
}
.kf-tree-search kbd {
  position: absolute; left: 10px;
  font-family: 'Reem Kufi', sans-serif;
  font-size: 11px;
  color: var(--parchment-dim);
  background: rgba(255,255,255,0.06);
  padding: 2px 6px;
  border-radius: 4px;
}

/* Smart search dropdown */
.kf-search-dropdown {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  left: 0;
  background: linear-gradient(160deg, rgba(23, 26, 53, 0.96), rgba(17, 19, 42, 0.99));
  backdrop-filter: blur(24px) saturate(160%);
  border: 1px solid var(--glass-line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  z-index: 20;
  max-height: 440px;
  overflow-y: auto;
  padding: 6px;
  animation: kf-fade-in .15s ease-out;
}
.kf-search-item {
  padding: 10px 14px;
  border-radius: 10px;
  cursor: pointer;
  transition: background .12s;
}
.kf-search-item:hover,
.kf-search-item.active {
  background: rgba(230, 192, 125, 0.1);
  outline: 1px solid var(--line);
}
.kf-sb-name {
  font-family: 'Amiri', serif;
  font-size: 18px;
  color: var(--gold-bright);
  line-height: 1.3;
}
.kf-sb-name mark {
  background: rgba(230, 192, 125, 0.35);
  color: var(--gold-glow);
  border-radius: 3px;
  padding: 0 2px;
}
.kf-sb-meta {
  display: flex;
  gap: 6px;
  align-items: center;
  margin-top: 4px;
  flex-wrap: wrap;
}
.kf-sb-badge {
  font-size: 10px;
  padding: 2px 8px;
  border-radius: 99px;
  background: rgba(255,255,255,0.06);
  color: var(--parchment-dim);
  font-family: 'Reem Kufi', sans-serif;
  letter-spacing: 0.5px;
}
.kf-sb-male   { background: rgba(122, 168, 224, 0.18); color: var(--male); }
.kf-sb-female { background: rgba(230, 159, 184, 0.18); color: var(--female); }
.kf-sb-gen    { background: rgba(230, 192, 125, 0.14); color: var(--gold-bright); }
.kf-sb-lineage {
  font-size: 12px;
  color: var(--parchment-dim);
  margin-top: 4px;
  line-height: 1.5;
  direction: rtl;
}

@media (max-width: 720px) {
  .kf-search-dropdown { max-height: 60vh; font-size: 14px; }
  .kf-sb-name { font-size: 16px; }
}

.kf-tree-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.kf-tree-actions .kf-btn {
  padding: 9px 14px;
  font-size: 13px;
  background: rgba(11, 12, 28, 0.8);
  backdrop-filter: blur(14px);
  min-height: 44px;
}

/* Info panel (side on desktop, bottom-sheet on mobile) */
.kf-tree-info {
  position: absolute;
  top: 74px; right: 14px;
  width: 340px;
  max-width: calc(100% - 28px);
  background: linear-gradient(160deg, rgba(23, 26, 53, 0.9), rgba(17, 19, 42, 0.95));
  backdrop-filter: blur(26px) saturate(160%);
  border: 1px solid var(--glass-line);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg);
  padding: 22px;
  z-index: 11;
  animation: kf-info-in .25s cubic-bezier(.16,.84,.44,1) both;
  max-height: calc(100vh - var(--header-h) - 100px);
  overflow-y: auto;
}
@keyframes kf-info-in {
  from { opacity: 0; transform: translateY(-8px) scale(.98); }
  to   { opacity: 1; transform: none; }
}

.kf-tree-info header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 16px;
  gap: 12px;
}
.kf-tree-info-name {
  font-family: 'Amiri', serif;
  font-size: 22px;
  color: var(--gold-bright);
  line-height: 1.2;
}
.kf-tree-info-gender {
  color: var(--parchment-dim);
  font-size: 13px;
  margin-top: 4px;
}
.kf-tree-info-close {
  background: transparent;
  border: none;
  color: var(--parchment-dim);
  cursor: pointer;
  font-size: 22px;
  line-height: 1;
  padding: 6px 10px;
  border-radius: 8px;
  transition: all .15s;
  min-width: 36px;
  min-height: 36px;
}
.kf-tree-info-close:hover { background: rgba(255,255,255,0.08); color: var(--parchment); }

.kf-tree-info-label {
  font-family: 'Reem Kufi', sans-serif;
  font-size: 11px;
  letter-spacing: 2px;
  color: var(--gold-800);
  text-transform: uppercase;
  margin-bottom: 8px;
}
.kf-tree-info-lineage {
  color: var(--cream);
  font-size: 14px;
  line-height: 1.7;
  padding: 12px 14px;
  background: rgba(11, 12, 28, 0.55);
  border-radius: 12px;
  border: 1px solid var(--glass-line);
  margin-bottom: 14px;
}

.kf-tree-info-fullname {
  color: var(--gold-bright);
  font-family: 'Amiri', serif;
  font-size: 17px;
  line-height: 1.6;
  padding: 14px 16px;
  background: linear-gradient(160deg, rgba(230, 192, 125, 0.1), rgba(201, 160, 89, 0.05));
  border-radius: 12px;
  border: 1px solid var(--line);
  margin-bottom: 16px;
  text-align: right;
  direction: rtl;
  word-spacing: 2px;
}
.kf-tree-info-stats { font-size: 13px; color: var(--parchment-dim); margin-bottom: 18px; }
.kf-tree-info-stats strong { color: var(--gold-bright); font-family: 'Amiri', serif; font-size: 16px; }

.kf-tree-info-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* Legend */
.kf-tree-legend {
  position: absolute;
  bottom: 20px; right: 14px;
  background: rgba(11, 12, 28, 0.82);
  backdrop-filter: blur(14px);
  border: 1px solid var(--glass-line);
  border-radius: 12px;
  padding: 13px 16px;
  z-index: 5;
  font-size: 12px;
}
.kf-tree-legend-title {
  font-family: 'Reem Kufi', sans-serif;
  font-size: 10px; letter-spacing: 2px;
  color: var(--gold-800);
  text-transform: uppercase;
  margin-bottom: 8px;
}
.kf-tree-legend-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 4px 0;
  color: var(--cream);
}
.sw { width: 10px; height: 10px; border-radius: 50%; }
.sw-root   { background: var(--gold-bright); box-shadow: 0 0 8px var(--gold-bright); }
.sw-male   { background: var(--male); }
.sw-female { background: var(--female); }

/* Zoom controls */
.kf-tree-zoom {
  position: absolute;
  bottom: 20px; left: 14px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  z-index: 5;
}
.kf-zoom-btn {
  width: 44px; height: 44px;
  border-radius: 12px;
  background: rgba(11, 12, 28, 0.82);
  backdrop-filter: blur(14px);
  border: 1px solid var(--glass-line);
  color: var(--parchment);
  font-size: 18px;
  cursor: pointer;
  transition: all .2s;
}
.kf-zoom-btn:hover { background: rgba(230, 192, 125, 0.14); border-color: var(--gold); color: var(--gold-bright); }

/* Hint */
.kf-tree-hint {
  position: absolute;
  bottom: 18px; left: 50%;
  transform: translateX(-50%);
  font-size: 12px;
  color: var(--parchment-dim);
  text-align: center;
  z-index: 4;
  pointer-events: none;
}
.kf-tree-hint kbd {
  font-family: 'Reem Kufi', sans-serif;
  background: rgba(255,255,255,0.06);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 11px;
  margin: 0 2px;
}

/* =========================================================
   NODE CARDS — readable name pills with gender accent
   ========================================================= */
.kf-node { cursor: pointer; transition: transform .15s; }
.kf-node:hover { filter: drop-shadow(0 4px 12px rgba(0, 0, 0, 0.35)); }

/* Card background */
.kf-node-card {
  fill: rgba(23, 26, 53, 0.96);
  stroke: rgba(255, 255, 255, 0.1);
  stroke-width: 1;
  transition: all .18s ease-out;
}

/* Hover: brighten stroke, lift */
.kf-node:hover .kf-node-card {
  stroke: var(--gold);
  stroke-width: 1.5;
}

/* Gender variants */
.kf-node.male   .kf-node-card   { fill: rgba(28, 40, 68, 0.96); }
.kf-node.female .kf-node-card   { fill: rgba(48, 30, 48, 0.96); }

.kf-node.male   .kf-node-accent { fill: var(--male); }
.kf-node.female .kf-node-accent { fill: var(--female); }

/* Root — gold, larger, glowing */
.kf-node.root .kf-node-card {
  fill: rgba(230, 192, 125, 0.18);
  stroke: var(--gold-glow);
  stroke-width: 2;
  filter: drop-shadow(0 0 16px rgba(255, 217, 138, 0.5));
}
.kf-node.root .kf-node-accent { fill: var(--gold-glow); }

/* Collapsed (has hidden children) — double outline indicator */
.kf-node.collapsed .kf-node-card {
  stroke-dasharray: 4 3;
  stroke: var(--gold);
}
.kf-node-expand {
  fill: var(--gold-bright);
  stroke: var(--ink-deep);
  stroke-width: 2;
  pointer-events: none;
}

/* Search match — glowing gold border */
.kf-node.match .kf-node-card {
  stroke: var(--match);
  stroke-width: 2.5;
  filter: drop-shadow(0 0 8px rgba(255, 226, 138, 0.6));
}

/* Selected — strong gold border */
.kf-node.selected .kf-node-card {
  stroke: var(--gold-glow);
  stroke-width: 2.5;
  filter: drop-shadow(0 0 12px rgba(255, 217, 138, 0.5));
}

/* Label text */
.kf-node-label {
  font-family: 'Tajawal', 'Reem Kufi', system-ui, sans-serif;
  fill: var(--parchment);
  pointer-events: none;
  direction: rtl;
  paint-order: stroke fill;
}

.kf-node.root .kf-node-label {
  font-family: 'Amiri', serif;
  fill: var(--gold-bright);
}

.kf-node.male   .kf-node-label { fill: #dce9fa; }
.kf-node.female .kf-node-label { fill: #f7d9e4; }

/* Links — refined warm gold */
.kf-link {
  fill: none;
  stroke: rgba(230, 192, 125, 0.28);
  stroke-width: 1.4;
  transition: stroke .2s;
}
.kf-link.highlight {
  stroke: var(--gold-bright);
  stroke-width: 2.2;
  filter: drop-shadow(0 0 4px rgba(230, 192, 125, 0.4));
}

/* CRITICAL: [hidden] must override display rules for modal & side panel.
   Triple-guarded: HTML attribute, class, and default state all hide it. */
.kf-modal[hidden],
.kf-tree-info[hidden] { display: none !important; }

.kf-modal:not(.kf-open) { display: none !important; }

/* Modal — only shown when .kf-open class is added */
.kf-modal {
  position: fixed;
  inset: 0;
  background: rgba(11, 12, 28, 0.78);
  backdrop-filter: blur(8px);
  align-items: center;
  justify-content: center;
  z-index: 200;
  animation: kf-fade-in .2s ease-out;
  padding: 16px;
}
.kf-modal.kf-open { display: flex; }
@keyframes kf-fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes kf-scale-in { from { transform: scale(.92); opacity: 0; } to { transform: none; opacity: 1; } }

.kf-modal-box {
  background: linear-gradient(160deg, rgba(23, 26, 53, 0.95), rgba(17, 19, 42, 0.98));
  border: 1px solid var(--glass-line);
  border-radius: var(--radius-xl);
  padding: 26px;
  width: 100%;
  max-width: 440px;
  box-shadow: var(--shadow-lg);
  animation: kf-scale-in .25s cubic-bezier(.16,.84,.44,1);
}
.kf-modal-box header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--glass-line);
}
.kf-modal-box h3 {
  font-family: 'Amiri', serif;
  font-size: 22px;
  color: var(--gold-bright);
}
.kf-modal-close {
  background: transparent;
  border: none;
  color: var(--parchment-dim);
  font-size: 22px;
  cursor: pointer;
  line-height: 1;
  padding: 6px 10px;
  border-radius: 8px;
  min-width: 36px; min-height: 36px;
}
.kf-modal-close:hover { background: rgba(255,255,255,0.08); color: var(--parchment); }

/* =========================================================
   MOBILE — bottom sheet for info panel
   ========================================================= */
@media (max-width: 720px) {
  .kf-tree-toolbar { top: 10px; right: 10px; left: 10px; gap: 8px; }
  .kf-tree-actions .kf-btn { padding: 10px 12px; font-size: 12px; }
  .kf-tree-legend { display: none; }
  .kf-tree-hint   { display: none; }

  .kf-tree-info {
    position: fixed;
    top: auto;
    bottom: 0; left: 0; right: 0;
    width: 100%;
    max-width: none;
    max-height: 72vh;
    border-radius: 24px 24px 0 0;
    animation: kf-sheet-in .3s cubic-bezier(.16,.84,.44,1) both;
    box-shadow: 0 -20px 60px rgba(0, 0, 0, 0.5);
    padding: 20px 18px 26px;
  }
  .kf-tree-info::before {
    content: '';
    position: absolute;
    top: 8px; left: 50%;
    transform: translateX(-50%);
    width: 40px; height: 4px;
    border-radius: 2px;
    background: rgba(255,255,255,0.25);
  }
  .kf-tree-info header { margin-top: 14px; }
  .kf-tree-info-actions .kf-btn { flex: 1; min-width: 0; justify-content: center; font-size: 13px; }

  .kf-tree-zoom { bottom: 14px; left: 10px; }
  .kf-zoom-btn { width: 40px; height: 40px; font-size: 16px; }

  .kf-modal-box { padding: 22px 18px; }
}

@keyframes kf-sheet-in {
  from { transform: translateY(100%); opacity: 0; }
  to   { transform: translateY(0); opacity: 1; }
}

/* =========================================================
   RELATIONSHIP FINDER MODAL
   ========================================================= */
.kf-modal-box-wide { max-width: 560px; }

.kf-rel-field { margin-bottom: 18px; }
.kf-rel-field > label {
  display: block;
  font-family: 'Reem Kufi', sans-serif;
  font-size: 12px;
  letter-spacing: 2px;
  color: var(--gold-800);
  text-transform: uppercase;
  margin-bottom: 8px;
}

.kf-rel-input-wrap { position: relative; }
.kf-rel-input-wrap input {
  width: 100%;
  padding: 14px 16px;
  background: rgba(11, 12, 28, 0.7);
  border: 1px solid var(--glass-line);
  border-radius: 12px;
  color: var(--parchment);
  font-family: inherit;
  font-size: 16px;
  direction: rtl;
  min-height: 48px;
  transition: all .2s;
}
.kf-rel-input-wrap input:focus {
  outline: none;
  border-color: var(--gold);
  background: rgba(11, 12, 28, 0.9);
  box-shadow: 0 0 0 4px rgba(230, 192, 125, 0.12);
}

.kf-rel-dropdown {
  position: absolute;
  top: calc(100% + 4px);
  left: 0; right: 0;
  background: linear-gradient(160deg, rgba(23, 26, 53, 0.97), rgba(17, 19, 42, 0.99));
  backdrop-filter: blur(20px);
  border: 1px solid var(--glass-line);
  border-radius: 12px;
  box-shadow: var(--shadow-lg);
  z-index: 100;
  max-height: 240px;
  overflow-y: auto;
  padding: 4px;
}
.kf-rel-dropdown-item {
  padding: 10px 12px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 14px;
  transition: background .12s;
}
.kf-rel-dropdown-item:hover,
.kf-rel-dropdown-item.active {
  background: rgba(230, 192, 125, 0.12);
}
.kf-rel-dropdown-item .kf-rdi-name {
  font-family: 'Amiri', serif;
  font-size: 16px;
  color: var(--gold-bright);
}
.kf-rel-dropdown-item .kf-rdi-meta {
  font-size: 11px;
  color: var(--parchment-dim);
  margin-top: 2px;
}

.kf-rel-picked {
  margin-top: 8px;
  padding: 10px 14px;
  background: rgba(230, 192, 125, 0.1);
  border: 1px solid var(--line);
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.kf-rel-picked-name {
  font-family: 'Amiri', serif;
  font-size: 18px;
  color: var(--gold-bright);
}
.kf-rel-picked-clear {
  background: transparent;
  border: none;
  color: var(--parchment-dim);
  cursor: pointer;
  font-size: 18px;
  padding: 4px 8px;
  border-radius: 6px;
}
.kf-rel-picked-clear:hover {
  background: rgba(255,255,255,0.08);
  color: var(--parchment);
}

.kf-rel-result {
  margin-top: 22px;
  padding: 20px;
  background: linear-gradient(160deg, rgba(230, 192, 125, 0.1), rgba(201, 160, 89, 0.04));
  border: 1px solid var(--line);
  border-radius: 14px;
  text-align: center;
  animation: kf-rise .4s cubic-bezier(.16,.84,.44,1);
}
.kf-rel-result-main {
  font-family: 'Amiri', serif;
  font-size: 22px;
  color: var(--gold-bright);
  line-height: 1.5;
  margin-bottom: 10px;
}
.kf-rel-result-meta {
  color: var(--parchment-dim);
  font-size: 13px;
}
.kf-rel-result-meta strong {
  color: var(--gold-bright);
  font-family: 'Amiri', serif;
  font-size: 16px;
}

.kf-rel-result-error {
  background: rgba(227, 115, 115, 0.1);
  border-color: rgba(227, 115, 115, 0.4);
}
.kf-rel-result-error .kf-rel-result-main { color: var(--danger); }

@media (max-width: 720px) {
  .kf-modal-box-wide { max-width: 100%; }
  .kf-rel-result-main { font-size: 18px; }
}

