:root {
  --color-bg: #ffffff;
  --color-bg-soft: #f4faf9;
  --color-bg-card: #ffffff;
  --color-text: #1e2a28;
  --color-text-muted: #5b6b68;
  --color-text-faint: #8ba09c;
  --color-border: #dbe7e5;
  --color-border-soft: #e6f0ee;

  --color-accent: #0f5c56;
  --color-accent-dark: #0b443f;
  --color-accent-light: #dcefed;

  --color-danger: #b3261e;
  --color-danger-light: #fbe9e7;
  --color-danger-border: #f0b8b2;

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 12px;

  --shadow: 0 1px 2px rgba(15, 92, 86, 0.05), 0 10px 28px -14px rgba(15, 92, 86, 0.18);

  --ease-out: cubic-bezier(.16, 1, .3, 1);
  --ease-pop: cubic-bezier(.34, 1.56, .64, 1);
}

* {
  box-sizing: border-box;
}

.placeholder-data-notice {
  background: var(--color-accent-light);
  color: var(--color-accent-dark);
  border: 1px dashed var(--color-accent);
  border-radius: var(--radius-sm);
  padding: 10px 16px;
  font-size: 13px;
  text-align: center;
  font-family: "IBM Plex Sans Arabic", sans-serif;
}

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

@keyframes growLine {
  to { width: 40px; }
}

@keyframes dotPulse {
  0% { box-shadow: 0 0 0 0 rgba(15, 92, 86, .35); }
  70% { box-shadow: 0 0 0 7px rgba(15, 92, 86, 0); }
  100% { box-shadow: 0 0 0 0 rgba(15, 92, 86, 0); }
}

html, body {
  margin: 0;
  padding: 0;
}

body {
  font-family: "IBM Plex Sans Arabic", sans-serif;
}

.app-shell {
  font-family: "IBM Plex Sans Arabic", sans-serif;
  color: var(--color-text);
  background: var(--color-bg-soft);
  min-height: 100vh;
  display: flex;
  line-height: 1.6;
}

.app-shell :focus-visible {
  outline: 2px solid var(--color-accent);
  outline-offset: 2px;
  border-radius: 8px;
}

@media (prefers-reduced-motion: reduce) {
  .app-shell * {
    transition: none !important;
    animation: none !important;
  }
  .app-shell .nav-item, .app-shell .stat-card, .app-shell .panel,
  .app-shell .eyebrow, .app-shell .topbar h1, .app-shell .topbar .date,
  .app-shell .topbar-actions {
    opacity: 1 !important;
    transform: none !important;
  }
  .app-shell .accent-line { width: 40px !important; }
}

/* ---------- Sidebar ---------- */
.sidebar {
  width: 272px;
  flex-shrink: 0;
  background: var(--color-bg-card);
  border-inline-end: 1px solid var(--color-border);
  display: flex;
  flex-direction: column;
  padding: 20px 14px;
  gap: 18px;
  transition: width .32s var(--ease-out), padding .32s var(--ease-out);
}

.sidebar.collapsed { width: 76px; padding-inline: 12px; }

.brand {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 6px 6px 12px;
  border-bottom: 1px solid var(--color-border-soft);
  margin-bottom: 2px;
}

.brand-mark {
  width: 52px;
  height: 52px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.brand-mark img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  mix-blend-mode: multiply;
}

.brand-text { overflow: hidden; white-space: nowrap; }
.brand-title { font-size: 15px; font-weight: 700; letter-spacing: .01em; }
.brand-sub { font-size: 12px; color: var(--color-text-muted); margin-top: 1px; }
.sidebar.collapsed .brand-text { display: none; }
.sidebar.collapsed .brand { justify-content: center; }

.collapse-btn {
  margin-inline-start: auto;
  width: 26px;
  height: 26px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: 1px solid transparent;
  color: var(--color-text-faint);
  cursor: pointer;
  transition: background-color .2s var(--ease-out), color .2s var(--ease-out), transform .15s var(--ease-out);
}

.collapse-btn:hover { background: var(--color-accent-light); color: var(--color-accent-dark); }
.collapse-btn:active { transform: scale(.9); }
.collapse-btn svg { transition: transform .32s var(--ease-out); }
.sidebar.collapsed .collapse-btn svg { transform: rotate(180deg); }
.sidebar.collapsed .brand { position: relative; }
.sidebar.collapsed .collapse-btn { margin-inline-start: 0; }

.nav-eyebrow {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--color-text-faint);
  padding: 0 10px;
  margin-top: 4px;
  white-space: nowrap;
  overflow: hidden;
}

.sidebar.collapsed .nav-eyebrow { opacity: 0; height: 0; margin: 0; padding: 0; }

.nav-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
  overflow-y: auto;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 10px 11px;
  border-radius: var(--radius-md);
  border: none;
  background: transparent;
  color: var(--color-text-muted);
  font-family: inherit;
  font-size: 14.5px;
  font-weight: 500;
  cursor: pointer;
  text-align: start;
  white-space: nowrap;
  overflow: hidden;
  opacity: 0;
  animation: fadeUp .45s var(--ease-out) forwards;
  transition: background-color .2s var(--ease-out), color .2s var(--ease-out), transform .2s var(--ease-out);
}

.nav-list li:nth-child(1) .nav-item { animation-delay: .08s; }
.nav-list li:nth-child(2) .nav-item { animation-delay: .14s; }
.nav-list li:nth-child(3) .nav-item { animation-delay: .20s; }
.nav-list li:nth-child(4) .nav-item { animation-delay: .26s; }
.nav-list li:nth-child(5) .nav-item { animation-delay: .32s; }
.nav-list li:nth-child(6) .nav-item { animation-delay: .38s; }
.nav-list li:nth-child(7) .nav-item { animation-delay: .44s; }
.nav-footer .nav-item { opacity: 0; animation: fadeUp .45s var(--ease-out) .5s forwards; }
.nav-item:hover { background: var(--color-accent-light); color: var(--color-accent-dark); transform: translateY(-1px); }
.nav-item:active { transform: translateY(0) scale(.98); }
.nav-item .nav-icon { flex-shrink: 0; display: flex; }
.nav-item .nav-icon svg { transition: transform .3s var(--ease-pop); }
.nav-item:hover .nav-icon svg { transform: scale(1.12); }
.nav-item .nav-label { overflow: hidden; text-overflow: ellipsis; }
.nav-item[data-active="true"] {
  background: var(--color-accent);
  color: #ffffff;
  font-weight: 600;
  transform: scale(1.01);
}

.nav-badge {
  margin-inline-start: auto;
  background: var(--color-accent);
  color: #ffffff;
  font-size: 11px;
  font-weight: 700;
  min-width: 19px;
  height: 19px;
  border-radius: 999px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 5px;
  font-variant-numeric: tabular-nums;
  transition: background-color .2s var(--ease-out), color .2s var(--ease-out);
}

.nav-item[data-active="true"] .nav-badge { background: #ffffff; color: var(--color-accent-dark); }
.sidebar.collapsed .nav-item { justify-content: center; padding-inline: 0; }
.sidebar.collapsed .nav-label, .sidebar.collapsed .nav-badge { display: none; }

.nav-footer {
  margin-top: auto;
  padding-top: 10px;
  border-top: 1px solid var(--color-border-soft);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.user-chip {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 8px;
  border-radius: var(--radius-md);
}

.avatar {
  width: 32px;
  height: 32px;
  border-radius: 999px;
  flex-shrink: 0;
  background: var(--color-accent-light);
  border: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12.5px;
  font-weight: 700;
  color: var(--color-accent-dark);
}

.user-meta { overflow: hidden; white-space: nowrap; }
.user-name { font-size: 13.5px; font-weight: 600; }
.user-role { font-size: 11.5px; color: var(--color-text-faint); }
.sidebar.collapsed .user-meta { display: none; }
.sidebar.collapsed .user-chip { justify-content: center; }

/* ---------- Main content ---------- */
.content {
  flex: 1;
  min-width: 0;
  padding: 30px 40px 44px;
  display: flex;
  flex-direction: column;
  gap: 26px;
}

.view { display: flex; flex-direction: column; gap: 26px; }
.view[hidden] { display: none; }
.topbar { display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; flex-wrap: wrap; }

.eyebrow {
  font-size: 11.5px;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--color-text-faint);
  margin: 0 0 6px;
  opacity: 0;
  animation: fadeUp .4s var(--ease-out) forwards;
}

.topbar h1 {
  font-size: 25px;
  font-weight: 700;
  margin: 0;
  text-wrap: balance;
  opacity: 0;
  animation: fadeUp .45s var(--ease-out) .06s forwards;
}

.accent-line {
  width: 0;
  height: 3px;
  border-radius: 999px;
  background: var(--color-accent);
  margin-top: 10px;
  animation: growLine .5s var(--ease-out) .5s forwards;
}

.topbar .date {
  font-size: 13px;
  color: var(--color-text-muted);
  margin-top: 5px;
  opacity: 0;
  animation: fadeUp .4s var(--ease-out) .12s forwards;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  opacity: 0;
  animation: fadeUp .4s var(--ease-out) .18s forwards;
}

.icon-btn {
  position: relative;
  width: 36px;
  height: 36px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--color-bg-card);
  border: 1px solid var(--color-border);
  color: var(--color-text-muted);
  cursor: pointer;
  transition: background-color .2s var(--ease-out), color .2s var(--ease-out), transform .2s var(--ease-out), box-shadow .2s var(--ease-out);
}

.icon-btn:hover { color: var(--color-accent-dark); background: var(--color-accent-light); transform: translateY(-2px); box-shadow: var(--shadow); }
.icon-btn:active { transform: translateY(0) scale(.94); }
.icon-btn .dot {
  position: absolute;
  top: 6px;
  inset-inline-end: 6px;
  width: 7px;
  height: 7px;
  border-radius: 999px;
  background: var(--color-accent);
  border: 1.5px solid var(--color-bg-card);
  animation: dotPulse 2.4s ease-out .9s infinite;
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 14px;
}

.stat-card {
  background: var(--color-bg-card);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: 16px 18px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 10px;
  opacity: 0;
  animation: fadeUp .5s var(--ease-out) forwards;
  transition: transform .25s var(--ease-out), box-shadow .25s var(--ease-out), border-color .25s var(--ease-out);
}

.stat-card:hover {
  transform: translateY(-3px);
  border-color: var(--color-accent);
  box-shadow: 0 4px 10px -2px rgba(15, 92, 86, .08), 0 18px 34px -14px rgba(15, 92, 86, .22);
}

.stat-grid .stat-card:nth-child(1) { animation-delay: .5s; }
.stat-grid .stat-card:nth-child(2) { animation-delay: .58s; }
.stat-grid .stat-card:nth-child(3) { animation-delay: .66s; }
.stat-grid .stat-card:nth-child(4) { animation-delay: .74s; }

.stat-top { display: flex; align-items: center; justify-content: space-between; }
.stat-icon {
  width: 32px;
  height: 32px;
  border-radius: 9px;
  background: var(--color-accent-light);
  border: 1px solid var(--color-border-soft);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--color-accent-dark);
  transition: transform .35s var(--ease-pop);
}

.stat-card:hover .stat-icon { transform: rotate(-8deg) scale(1.08); }
.stat-num { font-size: 27px; font-weight: 700; font-variant-numeric: tabular-nums; color: var(--color-text); }
.stat-label { font-size: 12.5px; color: var(--color-text-muted); }

.panel {
  background: var(--color-bg-card);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  overflow: hidden;
  opacity: 0;
  animation: fadeUp .5s var(--ease-out) .78s forwards;
}

.panel-head {
  padding: 15px 20px;
  border-bottom: 1px solid var(--color-border-soft);
  font-size: 14px;
  font-weight: 700;
}

.activity-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 13px 20px;
  border-bottom: 1px solid var(--color-border-soft);
  font-size: 13.5px;
  transition: background-color .2s var(--ease-out);
}

.activity-row:hover { background: var(--color-bg-soft); }
.activity-row:last-child { border-bottom: none; }
.activity-avatar {
  width: 30px;
  height: 30px;
  border-radius: 999px;
  flex-shrink: 0;
  background: var(--color-accent-light);
  border: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11.5px;
  font-weight: 700;
  color: var(--color-accent-dark);
}

.activity-text { flex: 1; min-width: 0; }
.activity-time { font-size: 12px; color: var(--color-text-faint); white-space: nowrap; }

.table-wrap { overflow-x: auto; }
.users-table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.users-table th {
  text-align: start;
  padding: 12px 20px;
  white-space: nowrap;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--color-text-faint);
  border-bottom: 1px solid var(--color-border-soft);
}

.users-table td {
  padding: 12px 20px;
  white-space: nowrap;
  border-bottom: 1px solid var(--color-border-soft);
  font-variant-numeric: tabular-nums;
}

.users-table tbody tr { transition: background-color .2s var(--ease-out); }
.users-table tbody tr:hover { background: var(--color-bg-soft); }
.users-table tbody tr:last-child td { border-bottom: none; }
.user-cell { display: flex; align-items: center; gap: 10px; font-variant-numeric: normal; }
.table-avatar {
  width: 28px;
  height: 28px;
  border-radius: 999px;
  flex-shrink: 0;
  background: var(--color-accent-light);
  border: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 700;
  color: var(--color-accent-dark);
}

@media (max-width: 860px) {
  .sidebar { width: 76px; padding-inline: 12px; }
  .sidebar .brand-text, .sidebar .nav-label, .sidebar .nav-badge,
  .sidebar .nav-eyebrow, .sidebar .user-meta { display: none; }
  .sidebar .brand { justify-content: center; }
  .sidebar .nav-item { justify-content: center; padding-inline: 0; }
  .sidebar .user-chip { justify-content: center; }
  .sidebar.expanded { width: 272px; padding: 20px 14px; }
  .sidebar.expanded .brand-text, .sidebar.expanded .nav-label,
  .sidebar.expanded .nav-badge, .sidebar.expanded .nav-eyebrow,
  .sidebar.expanded .user-meta { display: block; }
  .sidebar.expanded .nav-item { justify-content: flex-start; padding: 10px 11px; }
  .content { padding: 24px 20px 36px; }
}

.ibm-plex-sans-arabic-thin { font-family: "IBM Plex Sans Arabic", sans-serif; font-weight: 100; font-style: normal; }
.ibm-plex-sans-arabic-extralight { font-family: "IBM Plex Sans Arabic", sans-serif; font-weight: 200; font-style: normal; }
.ibm-plex-sans-arabic-light { font-family: "IBM Plex Sans Arabic", sans-serif; font-weight: 300; font-style: normal; }
.ibm-plex-sans-arabic-regular { font-family: "IBM Plex Sans Arabic", sans-serif; font-weight: 400; font-style: normal; }
.ibm-plex-sans-arabic-medium { font-family: "IBM Plex Sans Arabic", sans-serif; font-weight: 500; font-style: normal; }
.ibm-plex-sans-arabic-semibold { font-family: "IBM Plex Sans Arabic", sans-serif; font-weight: 600; font-style: normal; }
.ibm-plex-sans-arabic-bold { font-family: "IBM Plex Sans Arabic", sans-serif; font-weight: 700; font-style: normal; }

/* ---------- Logout (danger) nav item ---------- */
.nav-item.nav-item-danger { color: var(--color-danger); }
.nav-item.nav-item-danger:hover { background: var(--color-danger-light); color: var(--color-danger); }
.nav-item.nav-item-danger .nav-icon { color: var(--color-danger); }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 18px;
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-weight: 500;
  font-size: 13.5px;
  border: 1px solid transparent;
  cursor: pointer;
  transition: background-color .2s var(--ease-out), border-color .2s var(--ease-out), color .2s var(--ease-out), transform .2s var(--ease-out);
}
.btn:active { transform: scale(.97); }
.btn svg { width: 16px; height: 16px; flex-shrink: 0; }
.btn-primary { background: var(--color-accent); color: #ffffff; }
.btn-primary:hover { background: var(--color-accent-dark); }
.btn-secondary { background: var(--color-bg-card); color: var(--color-text); border-color: var(--color-border); }
.btn-secondary:hover { border-color: var(--color-accent); color: var(--color-accent-dark); }
.btn-danger { background: #ffffff; color: var(--color-danger); border-color: var(--color-danger-border); }
.btn-danger:hover { background: var(--color-danger-light); }
.btn-sm { padding: 7px 13px; font-size: 12.5px; border-radius: var(--radius-sm); }

.toolbar-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.toolbar-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

/* ---------- Table actions dropdown ---------- */
.actions-dropdown { position: relative; display: inline-flex; }
.actions-dropdown-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--color-border);
  background: var(--color-bg-card);
  color: var(--color-text-muted);
  cursor: pointer;
  transition: background-color .2s var(--ease-out), border-color .2s var(--ease-out), color .2s var(--ease-out);
}
.actions-dropdown-toggle svg { width: 16px; height: 16px; }
.actions-dropdown-toggle:hover, .actions-dropdown.open .actions-dropdown-toggle {
  border-color: var(--color-accent);
  color: var(--color-accent-dark);
  background: var(--color-accent-light);
}
.actions-menu {
  position: fixed;
  min-width: 180px;
  background: var(--color-bg-card);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow);
  padding: 6px;
  z-index: 300;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.actions-menu[hidden] { display: none; }
.actions-menu-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 9px 10px;
  border: none;
  background: transparent;
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 13.5px;
  font-weight: 500;
  color: var(--color-text);
  cursor: pointer;
  text-align: start;
  transition: background-color .2s var(--ease-out), color .2s var(--ease-out);
}
.actions-menu-item svg { width: 16px; height: 16px; flex-shrink: 0; }
.actions-menu-item:hover { background: var(--color-accent-light); color: var(--color-accent-dark); }
.actions-menu-item.danger { color: var(--color-danger); }
.actions-menu-item.danger:hover { background: var(--color-danger-light); color: var(--color-danger); }
.actions-menu-item[data-done="true"] .check-state { color: var(--color-accent); }

/* ---------- Messages view ---------- */
.msg-tabs {
  display: flex;
  gap: 4px;
  background: var(--color-bg-soft);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 4px;
  width: fit-content;
}
.msg-tab {
  font-family: inherit;
  font-size: 13.5px;
  font-weight: 500;
  color: var(--color-text-muted);
  background: transparent;
  border: none;
  border-radius: var(--radius-sm);
  padding: 9px 18px;
  cursor: pointer;
  transition: background-color .2s var(--ease-out), color .2s var(--ease-out);
}
.msg-tab.active { background: var(--color-accent); color: #ffffff; font-weight: 700; }
.msg-panel[hidden] { display: none; }
.msg-list { list-style: none; margin: 0; padding: 0; }
.msg-item {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 15px 20px;
  border-bottom: 1px solid var(--color-border-soft);
}
.msg-item:last-child { border-bottom: none; }
.msg-item:hover { background: var(--color-bg-soft); }
.msg-body { flex: 1; min-width: 0; }
.msg-top { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.msg-name { font-size: 14px; font-weight: 700; }
.msg-time { font-size: 12px; color: var(--color-text-faint); white-space: nowrap; }
.msg-text { font-size: 13.5px; color: var(--color-text-muted); margin-top: 4px; }
.msg-status {
  display: inline-block;
  font-size: 11px;
  font-weight: 700;
  padding: 3px 10px;
  border-radius: 999px;
  margin-top: 8px;
  background: var(--color-accent-light);
  color: var(--color-accent-dark);
}
.msg-status.new { background: var(--color-danger-light); color: var(--color-danger); }

/* ---------- Family tree view (org-chart, mirrors site's /tree page) ---------- */
.tree-toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; justify-content: space-between; }
.tree-toolbar-left { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; flex: 1; }
.tree-search-input {
  flex: 1;
  min-width: 180px;
  max-width: 320px;
  padding: 10px 14px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 13.5px;
  background: var(--color-bg-card);
}
.tree-meta { font-size: 13px; color: var(--color-text-muted); margin-bottom: 4px; }

.tree-canvas-wrap {
  position: relative;
  overflow: auto;
  min-height: 560px;
  background: radial-gradient(circle at 50% 0%, var(--color-bg-soft) 0%, var(--color-bg) 65%);
  touch-action: none;
  cursor: grab;
}
.tree-canvas-wrap.dragging { cursor: grabbing; }
.tree-canvas-wrap.is-maximized {
  position: fixed;
  inset: 12px;
  width: auto;
  height: auto;
  z-index: 500;
  border-radius: var(--radius-lg);
  border: 1px solid var(--color-border);
  box-shadow: 0 20px 60px -20px rgba(15, 92, 86, .4);
}
.tree-maximize-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(15, 92, 86, .35);
  z-index: 400;
}
.tree-maximize-backdrop.visible { display: block; }
.tree-canvas {
  position: relative;
  display: inline-block;
  min-width: 100%;
  padding: 56px 48px 70px;
  transform-origin: top center;
  transition: transform .2s var(--ease-out);
  box-sizing: border-box;
  touch-action: none;
}

.tree-connectors {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: visible;
  pointer-events: none;
}
.tree-connectors path {
  fill: none;
  stroke: var(--color-border);
  stroke-width: 2;
}

.org-tree, .org-tree ul { list-style: none; margin: 0; padding: 0; }
.org-tree { position: relative; display: flex; justify-content: center; z-index: 1; }
.org-tree ul { position: relative; display: flex; justify-content: center; padding-top: 44px; z-index: 1; }
.org-tree li {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  flex-shrink: 0;
  padding: 0 22px;
}
.org-tree li.has-children { padding-bottom: 10px; }
.org-tree li.collapsed > ul { display: none; }

.org-card {
  position: relative;
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--color-bg-card);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: 12px 18px;
  width: 196px;
  box-sizing: border-box;
  cursor: pointer;
  box-shadow: 0 4px 10px -4px rgba(15, 92, 86, .12);
  transition: border-color .2s var(--ease-out), transform .2s var(--ease-out), box-shadow .2s var(--ease-out);
}
.org-card:hover { border-color: var(--color-accent); transform: translateY(-2px); box-shadow: 0 8px 18px -6px rgba(15, 92, 86, .22); }
.org-card.root { border: 2px solid var(--color-accent); background: var(--color-accent-light); width: 220px; }

.org-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--color-accent-light);
  color: var(--color-accent-dark);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 13.5px;
  flex-shrink: 0;
}
.org-card.root .org-avatar { background: #ffffff; width: 44px; height: 44px; font-size: 14px; }
.org-card-body { text-align: start; overflow: hidden; }
.org-name { font-size: 13.5px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.org-sub { font-size: 11.5px; color: var(--color-text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* expand / collapse toggle — bottom-center chevron */
.org-toggle {
  position: absolute;
  bottom: -12px;
  left: 50%;
  transform: translateX(-50%);
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--color-accent);
  color: #ffffff;
  border: 2px solid var(--color-bg-soft);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 3;
  padding: 0;
}
.org-tree li:not(.has-children) .org-toggle { display: none; }
.org-tree li.collapsed .org-toggle svg { transform: rotate(180deg); }
.org-toggle svg { width: 13px; height: 13px; transition: transform .2s var(--ease-out); }

/* add-child — clear "+" badge at the card's corner, shown on hover/focus */
.org-add-btn {
  position: absolute;
  top: -9px;
  inset-inline-end: -9px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--color-bg-card);
  color: var(--color-accent-dark);
  border: 1.5px solid var(--color-accent);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 4;
  padding: 0;
  opacity: 0;
  transform: scale(.85);
  transition: opacity .18s var(--ease-out), transform .18s var(--ease-out), background-color .18s var(--ease-out), color .18s var(--ease-out);
}
.org-card:hover .org-add-btn,
.org-add-btn:focus-visible {
  opacity: 1;
  transform: scale(1);
}
.org-add-btn:hover { background: var(--color-accent); color: #ffffff; }
.org-add-btn svg { width: 13px; height: 13px; }

.org-tree li.search-hit .org-card {
  border-color: var(--color-accent);
  box-shadow: 0 0 0 3px var(--color-accent-light), 0 8px 18px -6px rgba(15, 92, 86, .3);
  animation: pulseGlow 1.4s ease-in-out 2;
}
@keyframes pulseGlow {
  0%, 100% { box-shadow: 0 0 0 3px var(--color-accent-light); }
  50% { box-shadow: 0 0 0 6px var(--color-accent-light); }
}
.org-tree li[hidden] { display: none; }

.modal-actions { display: flex; gap: 10px; margin-top: 6px; }
.modal-actions .btn { flex: 1; justify-content: center; }

.zoom-controls {
  position: absolute;
  bottom: 20px;
  left: 20px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  background: var(--color-bg-card);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 6px;
  box-shadow: var(--shadow);
  z-index: 10;
}
.zoom-controls .icon-btn { width: 34px; height: 34px; border: none; background: transparent; }
.zoom-controls .zoom-divider { height: 1px; background: var(--color-border); margin: 2px 4px; }

.tree-legend {
  position: absolute;
  bottom: 20px;
  right: 20px;
  background: var(--color-bg-card);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 12px 16px;
  box-shadow: var(--shadow);
  font-size: 12px;
  color: var(--color-text-muted);
  display: flex;
  flex-direction: column;
  gap: 5px;
  z-index: 10;
}
.tree-legend b { color: var(--color-text); font-weight: 700; }
.tree-legend .legend-root { display: flex; align-items: center; gap: 6px; }
.tree-legend .legend-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--color-accent); flex-shrink: 0; }

@media (max-width: 640px) {
  .tree-legend { display: none; }
}

/* ---------- Modal ---------- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 92, 86, .25);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: 20px;
}
.modal-backdrop[hidden] { display: none; }
.modal {
  background: var(--color-bg-card);
  border-radius: var(--radius-lg);
  width: min(440px, 100%);
  max-height: 88vh;
  overflow-y: auto;
  padding: 28px;
  position: relative;
  box-shadow: 0 30px 70px -20px rgba(15, 92, 86, .35);
}
.modal-close {
  position: absolute;
  top: 16px;
  inset-inline-end: 16px;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--color-bg-soft);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--color-text-muted);
  cursor: pointer;
  border: none;
}
.modal-close:hover { background: var(--color-border-soft); }
.modal-title { font-size: 18px; font-weight: 700; margin-bottom: 4px; }
.modal-note { font-size: 13px; color: var(--color-text-muted); margin-bottom: 20px; }
.add-person-error { font-size: 13px; color: var(--color-danger); margin: -12px 0 14px; }
.modal-head { display: flex; align-items: center; gap: 14px; margin-bottom: 18px; }
.modal-avatar {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--color-accent-light);
  color: var(--color-accent-dark);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 19px;
  flex-shrink: 0;
}
.modal-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 18px; }
.modal-field { background: var(--color-bg-soft); border-radius: var(--radius-md); padding: 10px 13px; }
.modal-field span { display: block; font-size: 11px; color: var(--color-text-muted); margin-bottom: 3px; }
.modal-field b { font-size: 13.5px; font-weight: 600; }
.modal-children h4 { font-size: 13px; color: var(--color-text-muted); margin-bottom: 10px; font-weight: 600; }
.children-chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { background: var(--color-accent-light); color: var(--color-accent-dark); font-size: 12.5px; font-weight: 600; padding: 6px 13px; border-radius: 999px; }
.no-children { font-size: 13px; color: var(--color-text-muted); }

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 14px; }
.form-field { display: flex; flex-direction: column; gap: 6px; }
.form-field.full { grid-column: 1 / -1; }
.form-field span { font-size: 12px; color: var(--color-text-muted); font-weight: 600; }
.form-field input, .form-field select {
  width: 100%;
  font-family: inherit;
  font-size: 14px;
  color: var(--color-text);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: 9px 12px;
  outline: none;
  background: var(--color-bg-soft);
  transition: border-color .2s var(--ease-out);
}
.form-field input:focus, .form-field select:focus { border-color: var(--color-accent); }
.btn-submit { width: 100%; justify-content: center; font-weight: 700; margin-top: 6px; }

/* ---------- Events view (category dropdown + template image slot) ---------- */
.event-form-panel { max-width: 1180px; }
.event-layout {
  display: grid;
  grid-template-columns: 1.3fr 1fr;
  gap: 40px;
  align-items: start;
}

.event-image-slot {
  border: 1.5px dashed var(--color-border);
  border-radius: var(--radius-lg);
  background: var(--color-bg-soft);
  padding: 120px 32px;
  min-height: 480px;
  text-align: center;
  color: var(--color-text-muted);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
}
.event-image-slot[hidden] { display: none; }
.wedding-card[hidden] { display: none; }
.event-image-slot svg { width: 80px; height: 80px; margin-bottom: 8px; color: var(--color-text-faint); }
.event-image-slot div { font-size: 19px; font-weight: 700; color: var(--color-text); }
.event-image-slot span { font-size: 14px; }

.wedding-card {
  position: relative;
  width: 100%;
  max-width: 340px;
  margin: 0 auto;
  aspect-ratio: 1655 / 2071;
  border-radius: var(--radius-lg);
  overflow: hidden;
  background: var(--color-bg-soft);
  border: 1px solid var(--color-border);
}
.wedding-bg { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; z-index: 0; }
.wedding-bg-missing {
  position: absolute;
  inset: 0;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  text-align: center;
  padding: 20px;
  font-size: 13px;
  color: var(--color-text-muted);
  background: var(--color-bg-soft);
  z-index: 1;
}
.wedding-bg.load-error + .wedding-bg-missing { display: flex; }

.wedding-photo-box {
  position: absolute;
  left: 34.7%;
  top: 31.5%;
  width: 30.8%;
  height: 25.6%;
  border-radius: 9%;
  overflow: hidden;
  cursor: pointer;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(220, 239, 237, .55);
  border: 2px solid #e0e0e0;
}
.wedding-photo-box img { width: 100%; height: 100%; object-fit: cover; }
.wedding-photo-hint {
  font-size: 10.5px;
  font-weight: 600;
  color: var(--color-accent-dark);
  text-align: center;
  padding: 0 6px;
}
.wedding-photo-box img:not([hidden]) + .wedding-photo-hint { display: none; }

.wedding-photo-remove {
  position: absolute;
  top: 6px;
  inset-inline-end: 6px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: none;
  background: rgba(20, 16, 8, .55);
  color: #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 3;
  padding: 0;
}
.wedding-photo-remove svg { width: 13px; height: 13px; }
.wedding-photo-remove:hover { background: var(--color-danger); }
.wedding-photo-remove[hidden] { display: none; }

.wedding-name-overlay {
  position: absolute;
  left: 50%;
  top: 74.7%;
  transform: translate(-50%, -50%);
  width: 90%;
  text-align: center;
  font-weight: 700;
  font-size: 21px;
  color: #c1752c;
  z-index: 2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.event-fields { display: flex; flex-direction: column; gap: 18px; }
.event-fields .form-field span { font-size: 15px; font-weight: 700; }
.event-fields .form-field input,
.event-fields .form-field select { font-size: 17px; padding: 13px 14px; }
.event-fields .file-input { font-size: 15px; padding: 13px 14px; }
.event-fields .file-input svg { width: 20px; height: 20px; }

.event-actions { display: flex; gap: 10px; }
.event-actions .btn { flex: 1; font-size: 15px; padding: 13px 16px; }

.file-input {
  display: flex;
  align-items: center;
  gap: 10px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-bg-soft);
  padding: 10px 12px;
  font-size: 13.5px;
  color: var(--color-text-muted);
  cursor: pointer;
  transition: border-color .2s var(--ease-out), color .2s var(--ease-out), background-color .2s var(--ease-out);
}
.file-input:hover { border-color: var(--color-accent); color: var(--color-accent-dark); background: var(--color-accent-light); }
.file-input svg { width: 17px; height: 17px; flex-shrink: 0; }
.file-input span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-input.has-file { color: var(--color-text); font-weight: 500; }

.event-success {
  display: none;
  align-items: center;
  gap: 8px;
  background: var(--color-accent-light);
  color: var(--color-accent-dark);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  font-size: 13.5px;
}
.event-success.visible { display: flex; }
.event-success svg { width: 16px; height: 16px; flex-shrink: 0; }

@media (max-width: 640px) {
  .event-layout { grid-template-columns: 1fr; }
}
