/* ===== Variables ===== */
:root {
  --brand: #197b46;
  --brand-ink: #04331e;
  --brand-light: #e8f5e9;
  --bg: #efefef;
  --card: #fff;
  --ink: #1f2937;
  --muted: #6b7280;
  --shadow: 0 2px 8px rgba(0,0,0,0.06);
}

/* ===== Base ===== */
*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: "Tajawal", system-ui, sans-serif;
  background: #efefef;
  color: var(--ink);
}

/* ===== Header ===== */
header {
  position: sticky;
  top: 0;
  z-index: 50;
  background: var(--brand-ink);
  border-bottom: none;
  padding: 12px 16px;
  display: grid;
  grid-template-columns: 200px 1fr 80px;
  align-items: center;
  gap: 8px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.18);
}
.logo { justify-self: end; }
.logo img {
  display: block;
  max-height: 84px;
  width: auto;
  border-radius: 14px;
  background: #fff;
  padding: 6px;
  border: 1px solid rgba(255,255,255,0.65);
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}
.title { justify-self: center; text-align: center; color: #fff; }
.title h1 { margin: 0; font-size: 22px; font-weight: 800; line-height: 1.2; color: #fff; }
.title small { color: rgba(255,255,255,0.8); font-size: 11px; }

/* ===== Toolbar ===== */
.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
  justify-content: center;
  padding: 10px;
}
.search {
  flex: 1;
  min-width: 200px;
  max-width: 500px;
}
.search input {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  outline: none;
  transition: all 0.2s;
}
.search input:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(25,123,70,0.15);
}
.btn {
  padding: 8px 12px;
  border-radius: 8px;
  border: 1px solid rgba(4,51,30,0.3);
  background: #fff;
  color: var(--brand-ink);
  cursor: pointer;
  transition: all 0.2s;
  font-weight: 600;
  font-size: 13px;
}
.btn:hover {
  background: var(--brand-light);
  border-color: rgba(4,51,30,0.5);
  transform: translateY(-1px);
}
.btn.primary {
  background: var(--brand);
  border-color: var(--brand);
  color: #fff;
  box-shadow: 0 2px 6px rgba(4,51,30,0.2);
}
.btn.primary:hover { background: var(--brand-ink); border-color: var(--brand-ink); box-shadow: 0 4px 10px rgba(4,51,30,0.25); }

/* ===== Tree Container ===== */
.wrap {
  max-width: 1200px;
  margin: 12px auto;
  padding: 0 12px;
}
.card {
  background: var(--card);
  border: 1px solid #eef2f7;
  border-radius: 12px;
  box-shadow: var(--shadow);
}
.tree { padding: 12px 8px 16px; }
.tree ul { list-style: none; margin: 0; padding: 0; }
/* إزالة المسافات قبل أقسام محددة (التوريد: العنصر الجذري الثاني، التوزيع: الأخير) */
#tree > ul > li:nth-child(2) > details,
#tree > ul > li:last-child > details { margin-top: 0; }

/* ===== Tree Nodes ===== */
details {
  border: 1px solid #eef2f7;
  border-radius: 10px;
  background: #fff;
  margin: 6px 4px;
  padding: 0;
  transition: all 0.2s;
}
details:hover { box-shadow: 0 2px 6px rgba(0,0,0,0.08); }
details[open] {
  border-color: #c8e6d0;
  background: #f8fcfa;
}
summary {
  list-style: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  transition: background 0.2s;
}
summary:hover { background: var(--brand-light); }
summary::-webkit-details-marker { display: none; }
summary::before {
  content: "▼";
  font-size: 9px;
  color: var(--brand);
  transition: transform 0.2s;
  margin-left: 2px;
}
details[open] > summary::before { transform: rotate(180deg); }

/* ===== Labels & Bullets ===== */
.bullet {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--brand);
  flex-shrink: 0;
}
.label { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.label .title {
  font-weight: 700;
  font-size: 14px;
  position: relative;
  color: #000;
}
.label .title.has-link {
  color: #000;
}
.label .title.has-link::after {
  content: "🔗";
  position: absolute;
  left: -18px;
  font-size: 12px;
  opacity: 0.5;
}
.label .meta {
  font-size: 11px;
  color: var(--muted);
  line-height: 1.4;
}

/* ===== Children ===== */
.children {
  padding: 4px 8px 8px;
  animation: slideDown 0.2s ease;
}
.children ul {
  border-right: 2px solid #e8f5e9;
  margin-right: 12px;
  padding-right: 8px;
}
@keyframes slideDown {
  from { opacity: 0; transform: translateY(-5px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ===== Leaf Nodes ===== */
.leaf {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-radius: 8px;
  border: 1px dashed #e5e7eb;
  margin: 6px 12px;
  transition: all 0.2s;
  position: relative;
  background: #fafbfc;
}
.leaf:hover {
  border-color: var(--brand);
  background: #f9fdfb;
  transform: translateX(-2px);
}
.leaf:has(.has-link) {
  border-style: solid;
  border-color: #b8dcc4;
  background: linear-gradient(135deg, #fff 0%, #f8fcfa 100%);
}
.leaf:has(.has-link):hover {
  border-color: var(--brand);
  box-shadow: 0 4px 12px rgba(25,123,70,0.15);
  transform: translateX(-3px);
}
.leaf:has(.has-link)::before {
  content: "📄";
  position: absolute;
  right: 10px;
  font-size: 16px;
  opacity: 0.4;
}

/* ===== Tags ===== */
.tag {
  background: #f1f5f9;
  color: #0f172a;
  font-size: 10px;
  font-weight: 600;
  border-radius: 999px;
  padding: 3px 8px;
  border: 1px solid #cbd5e1;
}

/* ===== Utilities ===== */
.hidden { display: none !important; }
footer {
  color: var(--muted);
  text-align: center;
  font-size: 11px;
  padding: 20px;
}

/* ===== Responsive ===== */
@media (max-width: 700px) {
  header { grid-template-columns: 140px 1fr 40px; padding: 10px 12px; }
  .logo img { max-height: 68px; }
  .title h1 { font-size: 18px; }
  .toolbar { justify-content: stretch; }
  .btn { font-size: 12px; padding: 6px 10px; }
}
