/* ==========================================================================
   eJamii - Vikoba & Vikundi vya Jamii Management System
   Application stylesheet (Bootstrap 5 overrides + layout)
   ========================================================================== */
:root {
  /* eHUB brand palette (ehub.co.tz) */
  --ej-primary: #af3378;        /* sampled from the eHUB logo */
  --ej-primary-dark: #8a1a55;   /* eHUB button colour */
  --ej-primary-light: #f9e9f2;
  --ej-accent: #e6a51e;
  --ej-accent-light: #fbf3e2;
  --ej-sidebar-bg: #231522;
  --ej-sidebar-bg-2: #4a1a3a;
  --ej-sidebar-text: #d9c8d2;
  --ej-sidebar-active: rgba(230, 165, 30, 0.18);
  --ej-body-bg: #fdfbf9;
  --ej-border: #ece3e8;
  --ej-text: #231522;
  --ej-muted: #6b5a64;
  --ej-sidebar-width: 260px;
  --ej-topbar-height: 60px;
  --bs-primary: var(--ej-primary);
  --bs-primary-rgb: 175, 51, 120;
  --bs-link-color: var(--ej-primary);
  --bs-link-hover-color: var(--ej-primary-dark);
  --bs-body-bg: var(--ej-body-bg);
  --bs-body-color: var(--ej-text);
  --bs-body-font-family: "Schibsted Grotesk", "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
}

html, body { height: 100%; }
body { background: var(--ej-body-bg); color: var(--ej-text); font-size: 0.925rem; }
a { text-decoration: none; }
a:hover { text-decoration: underline; }

.btn-primary, .btn-primary:focus { background-color: var(--ej-primary); border-color: var(--ej-primary); }
.btn-primary:hover, .btn-primary:active { background-color: var(--ej-primary-dark) !important; border-color: var(--ej-primary-dark) !important; }
.btn-outline-primary { color: var(--ej-primary); border-color: var(--ej-primary); }
.btn-outline-primary:hover { background-color: var(--ej-primary); border-color: var(--ej-primary); }
.text-primary { color: var(--ej-primary) !important; }
.bg-primary { background-color: var(--ej-primary) !important; }
.text-bg-primary { background-color: var(--ej-primary) !important; }
.form-control:focus, .form-select:focus { border-color: var(--ej-primary); box-shadow: 0 0 0 0.2rem rgba(175, 51, 120, 0.18); }
.form-check-input:checked { background-color: var(--ej-primary); border-color: var(--ej-primary); }
.page-link { color: var(--ej-primary); }
.page-item.active .page-link { background-color: var(--ej-primary); border-color: var(--ej-primary); }
.nav-tabs .nav-link.active { color: var(--ej-primary); font-weight: 600; border-bottom-color: #fff; }
.nav-tabs .nav-link { color: var(--ej-muted); }

/* --------------------------------------------------------------------------
   Layout: sidebar + topbar + content
   -------------------------------------------------------------------------- */
.ej-sidebar {
  position: fixed; top: 0; left: 0; bottom: 0; width: var(--ej-sidebar-width); z-index: 1040;
  background: linear-gradient(180deg, var(--ej-sidebar-bg) 0%, var(--ej-sidebar-bg-2) 100%);
  color: var(--ej-sidebar-text); display: flex; flex-direction: column; overflow-y: auto;
  transition: transform 0.2s ease;
}
.ej-sidebar::-webkit-scrollbar { width: 6px; }
.ej-sidebar::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.15); border-radius: 3px; }
.ej-brand { display: flex; align-items: center; gap: 0.6rem; padding: 1rem 1.15rem; color: #fff; font-weight: 700; font-size: 1.15rem; border-bottom: 1px solid rgba(255,255,255,0.08); }
.ej-brand:hover { color: #fff; text-decoration: none; }
.ej-brand .logo { width: 38px; height: 38px; border-radius: 9px; background: #fff; display: inline-flex; align-items: center; justify-content: center; overflow: hidden; padding: 3px; }
.ej-brand .logo img { width: 100%; height: 100%; object-fit: contain; }
.ej-brand small { display: block; font-size: 0.68rem; font-weight: 400; opacity: 0.7; letter-spacing: 0.02em; }
.ej-group-pill { margin: 0.85rem 1rem 0.35rem; padding: 0.6rem 0.75rem; background: rgba(255,255,255,0.06); border-radius: 10px; font-size: 0.8rem; }
.ej-group-pill .name { color: #fff; font-weight: 600; display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ej-group-pill .role { opacity: 0.7; }
.ej-nav { list-style: none; padding: 0.5rem 0.75rem 1.5rem; margin: 0; flex: 1; }
.ej-nav .section { font-size: 0.68rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--ej-accent); opacity: 0.85; padding: 0.9rem 0.6rem 0.35rem; }
.ej-nav a { display: flex; align-items: center; gap: 0.7rem; padding: 0.52rem 0.7rem; border-radius: 8px; color: var(--ej-sidebar-text); font-size: 0.88rem; }
.ej-nav a:hover { background: rgba(255,255,255,0.07); color: #fff; text-decoration: none; }
.ej-nav a.active { background: var(--ej-sidebar-active); color: #fff; font-weight: 600; box-shadow: inset 3px 0 0 var(--ej-accent); }
.ej-nav a i { font-size: 1.05rem; width: 20px; text-align: center; opacity: 0.9; }
.ej-nav a .badge { margin-left: auto; }
.ej-sidebar-footer { padding: 0.75rem 1rem; font-size: 0.72rem; opacity: 0.55; border-top: 1px solid rgba(255,255,255,0.08); }

.ej-topbar {
  position: sticky; top: 0; z-index: 1030; height: var(--ej-topbar-height); background: #fff; border-bottom: 1px solid var(--ej-border);
  display: flex; align-items: center; gap: 0.75rem; padding: 0 1.25rem;
}
.ej-topbar .search { position: relative; flex: 1; max-width: 520px; }
.ej-topbar .search input { padding-left: 2.3rem; background: #f6f1f4; border-color: transparent; }
.ej-topbar .search input:focus { background: #fff; }
.ej-topbar .search .bi-search { position: absolute; left: 0.85rem; top: 50%; transform: translateY(-50%); color: var(--ej-muted); }
.ej-search-results { position: absolute; top: 110%; left: 0; right: 0; background: #fff; border: 1px solid var(--ej-border); border-radius: 10px; box-shadow: 0 10px 30px rgba(0,0,0,0.12); max-height: 420px; overflow-y: auto; display: none; z-index: 1050; }
.ej-search-results.show { display: block; }
.ej-search-results a { display: flex; gap: 0.75rem; padding: 0.6rem 0.9rem; border-bottom: 1px solid #f0f2f1; color: var(--ej-text); }
.ej-search-results a:hover { background: var(--ej-primary-light); text-decoration: none; }
.ej-search-results a i { color: var(--ej-primary); font-size: 1.1rem; }
.ej-search-results .type { font-size: 0.7rem; text-transform: uppercase; color: var(--ej-muted); }
.ej-search-results .sub { font-size: 0.78rem; color: var(--ej-muted); }
.ej-icon-btn { position: relative; width: 38px; height: 38px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; color: var(--ej-text); background: transparent; border: 0; }
.ej-icon-btn:hover { background: #f3ecf0; }
.ej-icon-btn .badge { position: absolute; top: 2px; right: 0; font-size: 0.6rem; }
.ej-avatar { width: 34px; height: 34px; border-radius: 50%; background: var(--ej-primary); color: #fff; display: inline-flex; align-items: center; justify-content: center; font-weight: 700; font-size: 0.8rem; }
.ej-avatar.lg { width: 72px; height: 72px; font-size: 1.5rem; }
.ej-avatar.xl { width: 110px; height: 110px; font-size: 2.2rem; }
.ej-avatar img { width: 100%; height: 100%; border-radius: 50%; object-fit: cover; }
.ej-notif-menu { width: 360px; max-width: 92vw; }
.ej-notif-menu .item { padding: 0.6rem 0.9rem; border-bottom: 1px solid #f0f2f1; display: block; color: var(--ej-text); }
.ej-notif-menu .item:hover { background: var(--ej-primary-light); text-decoration: none; }
.ej-notif-menu .item .t { font-weight: 600; font-size: 0.85rem; }
.ej-notif-menu .item .m { font-size: 0.78rem; color: var(--ej-muted); }
.ej-notif-menu .item .d { font-size: 0.7rem; color: var(--ej-muted); }

.ej-main { margin-left: var(--ej-sidebar-width); min-height: 100vh; display: flex; flex-direction: column; }
.ej-content { padding: 1.5rem 1.5rem 3rem; flex: 1; }
.ej-footer { padding: 1rem 1.5rem; font-size: 0.78rem; color: var(--ej-muted); border-top: 1px solid var(--ej-border); }

@media (max-width: 991.98px) {
  .ej-sidebar { transform: translateX(-100%); }
  body.sidebar-open .ej-sidebar { transform: translateX(0); box-shadow: 0 0 40px rgba(0,0,0,0.4); }
  .ej-sidebar-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,0.45); z-index: 1035; display: none; }
  body.sidebar-open .ej-sidebar-backdrop { display: block; }
  .ej-main { margin-left: 0; }
  .ej-content { padding: 1rem 0.9rem 2.5rem; }
  .ej-topbar { padding: 0 0.75rem; }
}

/* --------------------------------------------------------------------------
   Page header, breadcrumbs, cards
   -------------------------------------------------------------------------- */
.ej-page-header { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 0.75rem; margin-bottom: 1.25rem; }
.ej-page-header h1 { font-size: 1.35rem; font-weight: 700; margin: 0; letter-spacing: -0.01em; }
.ej-page-header .subtitle { color: var(--ej-muted); font-size: 0.85rem; margin-top: 0.15rem; }
.breadcrumb { font-size: 0.78rem; margin-bottom: 0.35rem; }
.breadcrumb-item + .breadcrumb-item::before { content: "›"; }
.card { border: 1px solid var(--ej-border); border-radius: 12px; box-shadow: 0 1px 2px rgba(35, 21, 34, 0.04), 0 8px 24px rgba(175, 51, 120, 0.06); }
.card-header { background: #fff; border-bottom: 1px solid var(--ej-border); font-weight: 600; padding: 0.8rem 1rem; border-radius: 12px 12px 0 0 !important; display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; }
.card-header .card-title { font-size: 0.95rem; margin: 0; font-weight: 600; }
.card-body { padding: 1rem; }

.stat-card { display: flex; align-items: center; gap: 0.9rem; padding: 1rem 1.1rem; height: 100%; }
.stat-card .icon { width: 46px; height: 46px; border-radius: 12px; display: inline-flex; align-items: center; justify-content: center; font-size: 1.35rem; flex-shrink: 0; background: var(--ej-primary-light); color: var(--ej-primary); }
.stat-card .icon.warning { background: var(--ej-accent-light); color: #8a5f0e; }
.stat-card .icon.danger { background: #fde8e8; color: #c0392b; }
.stat-card .icon.info { background: #e4f1fb; color: #1b6fa8; }
.stat-card .icon.secondary { background: #eef0ef; color: #4d5a55; }
.stat-card .icon.success { background: #e3f6ea; color: #1e7f4b; }
.stat-card .label { font-size: 0.74rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--ej-muted); margin-bottom: 0.15rem; }
.stat-card .value { font-size: 1.15rem; font-weight: 700; line-height: 1.2; word-break: break-word; }
.stat-card .hint { font-size: 0.74rem; color: var(--ej-muted); }

/* --------------------------------------------------------------------------
   Tables
   -------------------------------------------------------------------------- */
.table { font-size: 0.875rem; margin-bottom: 0; }
.table > :not(caption) > * > * { padding: 0.6rem 0.75rem; vertical-align: middle; }
.table thead th { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--ej-muted); background: #faf6f8; border-bottom: 1px solid var(--ej-border); white-space: nowrap; font-weight: 600; }
.table tfoot td, .table tfoot th { font-weight: 700; background: #faf6f8; }
.table-hover tbody tr:hover { background: #fbf4f8; }
.table .money { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }
.table .actions { white-space: nowrap; text-align: right; }
.table a.row-link { color: var(--ej-text); font-weight: 600; }
.table a.row-link:hover { color: var(--ej-primary); }
.table-responsive { border-radius: 0 0 12px 12px; }
.card > .table-responsive:first-child { border-radius: 12px; }
.empty-state { text-align: center; padding: 2.5rem 1rem; color: var(--ej-muted); }
.empty-state i { font-size: 2.4rem; display: block; margin-bottom: 0.5rem; opacity: 0.5; }

/* --------------------------------------------------------------------------
   Forms & filters
   -------------------------------------------------------------------------- */
.filter-bar { background: #fff; border: 1px solid var(--ej-border); border-radius: 12px; padding: 0.75rem 1rem; margin-bottom: 1rem; }
.filter-bar .form-label { font-size: 0.72rem; text-transform: uppercase; color: var(--ej-muted); margin-bottom: 0.2rem; }
.form-label { font-weight: 600; font-size: 0.82rem; }
.form-text { font-size: 0.75rem; }
.required label::after, label.required::after { content: " *"; color: #c0392b; }
.invalid-feedback { display: block; }
.form-section-title { font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--ej-primary); font-weight: 700; margin: 1.25rem 0 0.6rem; padding-bottom: 0.3rem; border-bottom: 1px solid var(--ej-border); }
.form-section-title:first-child { margin-top: 0; }

/* --------------------------------------------------------------------------
   Misc
   -------------------------------------------------------------------------- */
.dl-grid { display: grid; grid-template-columns: max-content 1fr; gap: 0.35rem 1rem; font-size: 0.875rem; margin: 0; }
.dl-grid dt { color: var(--ej-muted); font-weight: 500; }
.dl-grid dd { margin: 0; font-weight: 500; }
.timeline { list-style: none; padding: 0; margin: 0; }
.timeline li { position: relative; padding: 0 0 1rem 1.4rem; border-left: 2px solid var(--ej-border); margin-left: 0.4rem; font-size: 0.85rem; }
.timeline li::before { content: ""; position: absolute; left: -7px; top: 3px; width: 12px; height: 12px; border-radius: 50%; background: var(--ej-primary); border: 2px solid #fff; }
.timeline li:last-child { padding-bottom: 0; }
.timeline .time { font-size: 0.72rem; color: var(--ej-muted); }
.leader-card { text-align: center; padding: 1rem 0.5rem; }
.leader-card .position { font-size: 0.72rem; text-transform: uppercase; color: var(--ej-primary); font-weight: 700; letter-spacing: 0.05em; }
.progress { height: 8px; border-radius: 4px; }
.badge { font-weight: 600; letter-spacing: 0.01em; }
.chart-box { position: relative; height: 260px; }
.chart-box.sm { height: 200px; }
.quick-actions .btn { text-align: left; }
.list-group-item { border-color: var(--ej-border); }
.text-money { font-variant-numeric: tabular-nums; }
.cursor-pointer { cursor: pointer; }
.fs-7 { font-size: 0.78rem; }
.mw-0 { min-width: 0; }
.alert { border-radius: 10px; }
.toast-container { z-index: 1090; }
.sticky-actions { position: sticky; bottom: 0; background: #fff; border-top: 1px solid var(--ej-border); padding: 0.75rem 0; margin-top: 1rem; }

/* Login page */
.auth-page { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: radial-gradient(1200px 600px at 10% 10%, #6e1f52 0%, var(--ej-sidebar-bg) 60%); padding: 1.5rem; }
.auth-card { width: 100%; max-width: 420px; border-radius: 16px; box-shadow: 0 25px 60px rgba(0,0,0,0.35); }
.auth-card .brand { text-align: center; margin-bottom: 1.25rem; }
.auth-card .brand { display: flex; flex-direction: column; align-items: center; }
.auth-card .brand .logo { width: 88px; height: 88px; border-radius: 50%; background: #fff; border: 2px solid var(--ej-accent-light); box-shadow: 0 0 0 6px #fff, 0 0 0 7px var(--ej-border); display: flex; align-items: center; justify-content: center; margin: 0 auto 0.85rem; padding: 12px; }
.auth-card .brand .logo img { width: 100%; height: 100%; object-fit: contain; display: block; }

/* Receipt & print */
.receipt { max-width: 720px; margin: 0 auto; background: #fff; border: 1px solid var(--ej-border); padding: 2rem; }
.receipt.small { max-width: 380px; padding: 1.25rem; font-size: 0.82rem; }
.receipt .head { display: flex; align-items: center; gap: 1rem; border-bottom: 2px solid var(--ej-primary); padding-bottom: 0.75rem; margin-bottom: 1rem; }
.receipt .head img { height: 60px; }
.receipt .amount-box { background: var(--ej-primary-light); border-radius: 8px; padding: 0.75rem 1rem; font-size: 1.3rem; font-weight: 700; text-align: right; }
.receipt .sign { display: flex; justify-content: space-between; margin-top: 3rem; }
.receipt .sign div { border-top: 1px solid #333; width: 42%; text-align: center; padding-top: 0.3rem; font-size: 0.78rem; }
.report-header { display: flex; align-items: center; gap: 1rem; border-bottom: 2px solid var(--ej-primary); padding-bottom: 0.75rem; margin-bottom: 1rem; }
.report-header img { height: 56px; }
.report-header h2 { font-size: 1.2rem; margin: 0; font-weight: 700; }
.report-header .meta { font-size: 0.8rem; color: var(--ej-muted); }

@media print {
  .ej-sidebar, .ej-topbar, .ej-footer, .no-print, .btn, .filter-bar, .breadcrumb, .pagination { display: none !important; }
  .ej-main { margin-left: 0; }
  .ej-content { padding: 0; }
  body { background: #fff; font-size: 11pt; }
  .card { border: 0; box-shadow: none; }
  .table { font-size: 10pt; }
  a { color: inherit; }
  .receipt { border: 0; }
}

/* --------------------------------------------------------------------------
   Leadership organisation chart (tree with connectors)
   -------------------------------------------------------------------------- */
.org-chart { --org-line: #d9cbd3; display: flex; flex-direction: column; align-items: center; padding: 1rem 0.5rem 0.5rem; overflow-x: auto; }
.org-level { display: flex; justify-content: center; flex-wrap: nowrap; list-style: none; margin: 0; padding: 0; position: relative; }
.org-level > li { position: relative; padding: 22px 10px 0; display: flex; flex-direction: column; align-items: center; }
/* stub from the horizontal bar down to the card */
.org-level > li::before { content: ""; position: absolute; top: 0; left: 50%; width: 2px; height: 22px; background: var(--org-line); transform: translateX(-50%); }
/* horizontal bar joining siblings */
.org-level > li::after { content: ""; position: absolute; top: 0; left: 0; right: 0; height: 2px; background: var(--org-line); }
.org-level > li:first-child::after { left: 50%; }
.org-level > li:last-child::after { right: 50%; }
.org-level > li:only-child::after { display: none; }
/* the top level has no bar above it */
.org-level.org-root > li { padding-top: 0; }
.org-level.org-root > li::before, .org-level.org-root > li::after { display: none; }
/* trunk from a level down to the next bar */
.org-level.has-next { padding-bottom: 22px; }
.org-level.has-next::after { content: ""; position: absolute; bottom: 0; left: 50%; width: 2px; height: 22px; background: var(--org-line); transform: translateX(-50%); }
/* bottom bus bar under a multi-node level that has children */
.org-level.has-next.org-multi > li { padding-bottom: 22px; }
.org-level.has-next.org-multi > li .org-down::before { content: ""; position: absolute; bottom: 0; left: 50%; width: 2px; height: 22px; background: var(--org-line); transform: translateX(-50%); }
.org-level.has-next.org-multi > li .org-down::after { content: ""; position: absolute; bottom: 0; left: 0; right: 0; height: 2px; background: var(--org-line); }
.org-level.has-next.org-multi > li:first-child .org-down::after { left: 50%; }
.org-level.has-next.org-multi > li:last-child .org-down::after { right: 50%; }
.org-node { width: 168px; background: #fff; border: 1px solid var(--ej-border); border-radius: 14px; padding: 0.9rem 0.6rem 0.75rem; text-align: center; box-shadow: 0 1px 2px rgba(35,21,34,.04), 0 8px 24px rgba(175,51,120,.06); transition: transform .15s ease, box-shadow .15s ease; }
.org-node:hover { transform: translateY(-2px); box-shadow: 0 12px 28px rgba(175,51,120,.14); }
.org-node .ej-avatar { margin: 0 auto 0.5rem; border: 3px solid #fff; box-shadow: 0 0 0 2px var(--ej-primary-light); }
.org-node .position { font-size: 0.68rem; text-transform: uppercase; letter-spacing: 0.06em; font-weight: 700; color: var(--ej-primary); margin-bottom: 0.15rem; line-height: 1.2; }
.org-node .name { font-weight: 700; font-size: 0.9rem; line-height: 1.2; }
.org-node .term { font-size: 0.7rem; color: var(--ej-muted); margin-top: 0.25rem; }
.org-node.top { width: 200px; border-color: var(--ej-primary); background: linear-gradient(180deg, #fff 0%, var(--ej-primary-light) 100%); }
.org-node.top .ej-avatar { box-shadow: 0 0 0 3px var(--ej-accent); }
.org-node.vacant { border-style: dashed; background: var(--ej-body-bg); box-shadow: none; }
.org-node.vacant .ej-avatar { background: #fff; color: var(--ej-muted); border: 2px dashed var(--ej-border-strong, #d9cbd3); box-shadow: none; }
.org-node.vacant .name { color: var(--ej-muted); font-weight: 500; font-style: italic; }
.org-node .actions { margin-top: 0.4rem; }
@media (max-width: 767.98px) { .org-node { width: 140px; padding: 0.7rem 0.4rem; } .org-node.top { width: 170px; } .org-level > li { padding-left: 5px; padding-right: 5px; } }
@media print { .org-node { box-shadow: none; } }

/* --------------------------------------------------------------------------
   Sidebar accordion groups
   -------------------------------------------------------------------------- */
.ej-nav-group { margin-top: 0.15rem; }
.ej-nav-toggle { display: flex; align-items: center; gap: 0.7rem; width: 100%; padding: 0.55rem 0.7rem; border: 0; border-radius: 8px; background: transparent; color: var(--ej-sidebar-text); font-size: 0.88rem; font-weight: 600; text-align: left; cursor: pointer; }
.ej-nav-toggle:hover { background: rgba(255,255,255,0.07); color: #fff; }
.ej-nav-toggle > i:first-child { font-size: 1.05rem; width: 20px; text-align: center; color: var(--ej-accent); }
.ej-nav-toggle > span { flex: 1; }
.ej-nav-toggle .chev { font-size: 0.75rem; opacity: 0.7; transition: transform 0.2s ease; }
.ej-nav-group.open > .ej-nav-toggle .chev { transform: rotate(180deg); }
.ej-nav-group.open > .ej-nav-toggle { color: #fff; }
.ej-nav-group.has-active > .ej-nav-toggle > i:first-child { color: #fff; }
.ej-nav-sub { list-style: none; margin: 0; padding: 0 0 0 0.6rem; max-height: 0; overflow: hidden; transition: max-height 0.25s ease; }
.ej-nav-group.open > .ej-nav-sub { max-height: 600px; }
.ej-nav-sub a { padding: 0.42rem 0.7rem 0.42rem 1.1rem; font-size: 0.85rem; position: relative; }
.ej-nav-sub a::before { content: ""; position: absolute; left: 0.35rem; top: 50%; width: 5px; height: 5px; border-radius: 50%; background: rgba(255,255,255,0.25); transform: translateY(-50%); }
.ej-nav-sub a.active::before { background: var(--ej-accent); }
.ej-nav-sub a i { font-size: 0.95rem; opacity: 0.8; }
