:root {
    --bg-deep: #0b0b09;
    --vignette-center: #1f1f1c;
    --text-main: #f8f9f8;
    --text-dim: #a1a19a;
    --sbmf-gold: #e2be3d;
    --sbmf-orange: #f39c12;
    --sbmf-dark-grey: #54534a;
    --glass-base: rgba(84, 83, 74, 0.45);
    --card-inner-bg: rgba(0, 0, 0, 0.25);
    --pattern-opacity: 0.12;
}

body.light-theme {
    --bg-deep: #e2e8e2;
    --vignette-center: #ffffff;
    --text-main: #3d3c36;
    --text-dim: #71716a;
    --sbmf-gold: #c5a028;
    --sbmf-orange: #e67e22;
    --glass-base: rgba(255, 255, 255, 0.9);
    --card-inner-bg: #f1f3f1;
    --pattern-opacity: 0.08;
}

body {
    font-family: "Tajawal", sans-serif;
    background: radial-gradient(
        circle,
        var(--vignette-center) 0%,
        var(--bg-deep) 100%
    );
    color: var(--text-main);
    min-height: 100vh; /* grows with content instead of clipping */
    height: auto;
    margin: 0;
    transition:
        background 0.5s ease,
        color 0.5s ease;
    overflow-y: auto; /* vertical scrollbar when zoomed */
}

/* Skip Link للوصول السريع */
.skip-link {
    position: absolute;
    top: -40px;
    left: 0;
    background: var(--sbmf-gold);
    color: #000;
    padding: 8px 16px;
    text-decoration: none;
    z-index: 10000;
    border-radius: 0 0 8px 0;
    font-weight: 700;
}

.skip-link:focus {
    top: 0;
}

/* Focus States محسّنة */
button:focus-visible,
.category-card:focus-visible,
.lending-badge.clickable:focus-visible {
    outline: 2px solid var(--sbmf-gold);
    outline-offset: 2px;
}

.main-wrapper {
    max-width: 1600px;
    margin: 0 auto;
    padding: 0.3rem 1rem;
    min-height: 100vh; /* at least full viewport, grows on zoom */
    height: auto;
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
}

/* Header: sticky so it stays visible during vertical scroll */
header {
    position: sticky;
    top: 0;
    z-index: 500;
    background-color: var(--bg-deep, #0b0b09);
    backdrop-filter: blur(30px);
    -webkit-backdrop-filter: blur(30px);
}
body.light-theme header {
    background-color: rgba(245, 243, 238, 0.95);
}

/* ── وضع التقارير: header ثابت فوق الشاشة ── */
body.report-mode header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 600;
}
body.report-mode #reportWrapper {
    padding-top: 4rem; /* مسافة تحت الـ header الثابت */
}

.premium-card {
    position: relative;
    border-radius: 1.5rem;
    backdrop-filter: blur(40px);
    border: 1px solid rgba(226, 190, 61, 0.15);
    background:
        radial-gradient(
            circle at center,
            rgba(255, 255, 255, 0.04) 0%,
            rgba(255, 255, 255, 0) 85%
        ),
        linear-gradient(
            to bottom,
            rgba(255, 255, 255, 0.06) 0%,
            rgba(255, 255, 255, 0) 100%
        );
    background-color: var(--glass-base);
    box-shadow: 0 15px 30px -10px rgba(0, 0, 0, 0.5);
    transition: all 0.7s cubic-bezier(0.4, 0, 0.2, 1);
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.premium-card::before {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 0;
    opacity: var(--pattern-opacity);
    background-image: url("data:image/svg+xml,%3Csvg width='60' height='60' viewBox='0 0 60 60' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='none' stroke='%23E2BE3D' stroke-width='0.8'%3E%3Crect x='10' y='10' width='40' height='40'/%3E%3Crect x='10' y='10' width='40' height='40' transform='rotate(45 30 30)'/%3E%3C/g%3E%3C/svg%3E");
    background-size: 60px 60px;
    pointer-events: none;
}

.cards-container {
    display: flex;
    gap: 0.75rem;
    width: 100%;
    align-items: stretch;
    flex: 1.4;
    min-height: 380px; /* cards won't disappear on heavy zoom */
}

.category-card {
    flex: 1;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    transition: all 0.7s cubic-bezier(0.4, 0, 0.2, 1);
}

.category-card.expanded {
    flex: 8;
    cursor: default;
}
.category-card.collapsed {
    flex: 0.25;
    opacity: 0.5;
}

.section-main-title,
.card-main-title {
    font-weight: 800;
    font-size: 1.1rem;
    color: var(--sbmf-gold);
    text-align: center;
    transition: all 0.5s ease;
    position: relative;
    z-index: 2;
    padding: 0.25rem 1rem;
    margin: 0.4rem auto;
    border: 1px solid rgba(226, 190, 61, 0.4);
    border-radius: 0.75rem;
    width: fit-content;
    display: block;
    white-space: nowrap;
    background: rgba(226, 190, 61, 0.05);
}

.collapsed .card-main-title {
    writing-mode: vertical-rl;
    padding: 0.75rem 0.25rem;
    margin: auto;
    letter-spacing: 1px;
    transform: rotate(180deg);
}

.expanded .card-main-title {
    font-size: 1.25rem;
    padding: 0.4rem 1.5rem;
    margin: 0.5rem auto 0.3rem auto;
}

.card-full-content {
    position: relative;
    z-index: 1;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    padding: 0 0.5rem 0.2rem 0.5rem;
    overflow: hidden;
    transition: opacity 0.5s ease;
}

/* Change layout when expanded - horizontal split */
.category-card.expanded .card-full-content {
    flex-direction: row;
    gap: 0.75rem;
    align-items: stretch;
}

/* Left side - data stays same width */
.card-data-section {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    flex: 1;
    min-width: 0;
}

/* Right side - chart appears */
.card-expanded-chart {
    display: none;
    opacity: 0;
    transition: opacity 0.5s ease;
    flex: 0;
    min-width: 0;
}

.category-card.expanded .card-expanded-chart {
    display: flex;
    opacity: 1;
    flex: 1.2;
    align-items: center;
    justify-content: center;
}

/* ── Chart stack: Doughnut (3 slices) + Mini bar ─────────────── */
.card-charts-stack {
    display: flex;
    flex-direction: column;
    width: 100%;
    height: 100%;
    gap: 0.4rem;
    padding: 0.5rem;
    box-sizing: border-box;
    min-width: 0;
}
.card-charts-stack .chart-container {
    flex: 1;
    min-height: 0;
    position: relative;
}
.completion-mini {
    flex-shrink: 0;
    padding: 0.4rem 0.55rem 0.5rem;
    background: rgba(255, 255, 255, 0.025);
    border: 1px solid rgba(255, 255, 255, 0.06);
    border-radius: 8px;
}
body.light-theme .completion-mini {
    background: rgba(0, 0, 0, 0.025);
    border-color: rgba(0, 0, 0, 0.07);
}
.cm-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 10.5px;
    font-weight: 700;
    color: var(--text-dim);
    margin-bottom: 4px;
    gap: 0.5rem;
}
.cm-header .cm-pct {
    color: var(--sbmf-gold);
    font-weight: 800;
    font-size: 11.5px;
}
.cm-bar-track {
    height: 8px;
    background: rgba(226, 190, 61, 0.1);
    border-radius: 4px;
    overflow: hidden;
    position: relative;
}
body.light-theme .cm-bar-track {
    background: rgba(226, 190, 61, 0.15);
}
.cm-bar-fill {
    height: 100%;
    background: linear-gradient(
        90deg,
        rgba(226, 190, 61, 0.5) 0%,
        rgba(226, 190, 61, 0.8) 100%
    );
    border-radius: 4px;
    transition: width 0.6s cubic-bezier(0.4, 0, 0.2, 1);
    width: 0%;
}
.cm-bar-fill.over {
    background: linear-gradient(90deg, #ef4444 0%, #b91c1c 100%);
}
.cm-stats {
    display: flex;
    justify-content: space-between;
    font-size: 11px;
    color: var(--text-dim);
    margin-top: 4px;
    font-family: monospace;
    direction: ltr;
}
.cm-stats span:first-child {
    direction: rtl;
    font-family: inherit;
}

.collapsed .card-full-content {
    display: none;
    opacity: 0;
}

/* ============================================
Multi-Level Drill-Down Styling
============================================ */

/* Level 2: Domains/Main Accounts - dynamic full-width row */
.level-2-container {
    display: flex;
    gap: 0.75rem;
    width: 100%;
    align-items: stretch;
    flex-shrink: 0;
}
.level-2-container .level-card {
    flex: 1;
    min-width: 0;
    /* Mirror .category-card: flex column so height propagates to children */
    display: flex;
    flex-direction: column;
    height: 410px; /* explicit height = definite → height:100% resolves */
    overflow: hidden;
    transition:
        flex 0.7s cubic-bezier(0.4, 0, 0.2, 1),
        opacity 0.4s ease;
}
.level-2-container .level-card.expanded {
    flex: 8;
    cursor: default;
}
.level-2-container .level-card.collapsed {
    flex: 0.4;
    opacity: 0.55;
}
.level-2-container .level-card .card-full-content {
    display: flex;
    flex-direction: column;
    flex: 1; /* fill remaining height inside flex-column level-card */
    min-height: 0;
    padding: 0.5rem;
    gap: 0.4rem;
    box-sizing: border-box;
}
.level-2-container .level-card.expanded .card-full-content {
    flex-direction: row;
    gap: 0.75rem;
}
.level-2-container .level-card .card-data-section {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    gap: 0.4rem;
}
.level-2-container .level-card.expanded .card-data-section {
    flex: 0 0 280px;
    justify-content: space-between;
}
.level-2-container .level-card .card-expanded-chart {
    display: none;
    flex: 1.2;
    min-width: 0;
}
/* v6: use display:flex — flex-stretch gives real clientHeight to the cell.
JS (initLevel2Chart) reads getBoundingClientRect + sets canvas px explicitly.
responsive:false means Chart.js won't fight our sizes. */
.level-2-container .level-card.expanded .card-expanded-chart {
    display: flex;
    opacity: 1;
    align-items: center;
    justify-content: center;
    position: relative;
    overflow: visible;
}
.level-2-container .level-card .card-expanded-chart > div {
    position: relative;
    width: 100%;
}
.level-2-container .level-card .card-expanded-chart canvas {
    display: block;
}
.level-2-container .level-card .card-expanded-chart {
    position: relative;
    z-index: 1;
}
.level-2-container
    .level-card
    .card-expanded-chart
    .chart-container {
    position: relative;
    z-index: 2;
    overflow: visible;
}
.level-2-container .level-card .card-expanded-chart canvas {
    position: relative;
    z-index: 3;
    display: block;
}

/* ══ Loan Pool View ══════════════════════════════════════════════
   شاشة "مجمع القروض الكلي" — تظهر عند النقر على بطاقة مجمع القروض.
   مبنية بنفس نمط detailsView (back + content + grid). */
#loanPoolView {
    overflow-y: auto;
    overflow-x: hidden;
}
.lp-header-card {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 1rem;
}
.lp-title {
    color: var(--sbmf-gold);
    font-size: 1.15rem;
    font-weight: 800;
    margin: 0;
}
.lp-toggle-view {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    background: rgba(226, 190, 61, 0.08);
    border: 1px solid rgba(226, 190, 61, 0.35);
    border-radius: 10px;
    color: var(--sbmf-gold);
    padding: 0.4rem 0.9rem;
    font-family: inherit;
    font-size: 12px;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
}
.lp-toggle-view:hover {
    background: rgba(226, 190, 61, 0.15);
    border-color: var(--sbmf-gold);
}
body.light-theme .lp-toggle-view {
    background: rgba(226, 190, 61, 0.1);
    color: #8a6d1a;
}
body.light-theme .lp-toggle-view:hover {
    background: rgba(226, 190, 61, 0.2);
}

/* Two main summary cards (Entities + Individuals) */
.lp-summary-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
    margin-top: 1rem;
}
@media (max-width: 768px) {
    .lp-summary-row {
        grid-template-columns: 1fr;
    }
}
.lp-summary-card {
    /* glassmorphism موحّد مع .premium-card — blur مخفَّف لـ 22+ بطاقة */
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    background:
        radial-gradient(circle at center, rgba(255,255,255,0.04) 0%, rgba(255,255,255,0) 85%),
        linear-gradient(to bottom, rgba(255,255,255,0.06) 0%, rgba(255,255,255,0) 100%);
    background-color: var(--glass-base);
    box-shadow: 0 8px 20px -6px rgba(0, 0, 0, 0.35);
    border: 1px solid rgba(255, 255, 255, 0.03);
    border-radius: 0.6rem;
    padding: 0.75rem 0.9rem;
    position: relative;
    will-change: transform;
    transition: all 0.2s;
}
.lp-summary-card.lp-entities {
    border-top: 3px solid rgba(226, 190, 61, 0.55);
}
.lp-summary-card.lp-individuals {
    border-top: 3px solid rgba(226, 190, 61, 0.3);
}
body.light-theme .lp-summary-card {
    background-color: rgba(255, 255, 255, 0.6);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.07);
    border-color: rgba(0, 0, 0, 0.06);
}
.lp-summary-title {
    font-size: 13px;
    font-weight: 800;
    color: var(--text-dim);
    margin-bottom: 0.6rem;
    text-align: center;
}
.lp-summary-card.lp-entities .lp-summary-title {
    color: var(--sbmf-gold);
}
.lp-summary-card.lp-individuals .lp-summary-title {
    color: rgba(226, 190, 61, 0.75);
}
.lp-summary-row-item {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    padding: 0.35rem 0;
    font-size: 13px;
    color: var(--text-dim);
    border-bottom: 1px dashed rgba(255, 255, 255, 0.05);
}
body.light-theme .lp-summary-row-item {
    border-bottom-color: rgba(0, 0, 0, 0.06);
}
.lp-summary-row-item:last-of-type {
    border-bottom: none;
}
.lp-summary-row-item .lp-val {
    font-variant-numeric: tabular-nums;
    font-weight: 700;
    color: var(--text-main);
    font-size: 14px;
}
.lp-pct-bar {
    margin-top: 0.5rem;
}
.lp-pct-track {
    height: 7px;
    background: rgba(255, 255, 255, 0.06);
    border-radius: 4px;
    overflow: hidden;
    position: relative;
}
body.light-theme .lp-pct-track {
    background: rgba(0, 0, 0, 0.06);
}
.lp-pct-fill {
    height: 100%;
    border-radius: 4px;
    transition: width 0.5s cubic-bezier(0.4, 0, 0.2, 1);
}
.lp-pct-fill.purple {
    background: linear-gradient(90deg, rgba(226, 190, 61, 0.7), rgba(226, 190, 61, 0.95));
}
.lp-pct-fill.orange {
    background: linear-gradient(90deg, rgba(226, 190, 61, 0.4), rgba(226, 190, 61, 0.65));
}
.lp-pct-fill.green {
    background: linear-gradient(90deg, #4ade80, #22c55e);
}
.lp-pct-fill.red {
    background: linear-gradient(90deg, #f87171, #ef4444);
}
.lp-pct-fill.amber {
    background: linear-gradient(90deg, #fbbf24, #f59e0b);
}
.lp-pct-label {
    font-size: 11px;
    color: var(--text-dim);
    text-align: right;
    margin-top: 0.2rem;
    font-variant-numeric: tabular-nums;
}

/* ── Filters bar (next to toggle-view button) ─────────────────── */
.lp-filters-bar {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: wrap;
}
.lp-filter-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    background: rgba(226, 190, 61, 0.05);
    border: 1px solid rgba(226, 190, 61, 0.25);
    border-radius: 10px;
    color: var(--text-dim);
    padding: 0.4rem 0.9rem;
    font-family: inherit;
    font-size: 12px;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
}
.lp-filter-btn:hover {
    background: rgba(226, 190, 61, 0.15);
    border-color: var(--sbmf-gold);
    color: var(--sbmf-gold);
}
.lp-filter-btn.active {
    background: rgba(226, 190, 61, 0.14);
    border-color: rgba(226, 190, 61, 0.5);
    color: var(--sbmf-gold);
}
.lp-filter-btn .lp-filter-icon {
    font-size: 14px;
    line-height: 1;
}
body.light-theme .lp-filter-btn {
    background: rgba(226, 190, 61, 0.06);
    border-color: rgba(197, 160, 40, 0.3);
    color: #6b6b6b;
}
body.light-theme .lp-filter-btn:hover {
    background: rgba(226, 190, 61, 0.15);
    border-color: #c5a028;
    color: #8a6d1a;
}
body.light-theme .lp-filter-btn.active {
    background: rgba(226, 190, 61, 0.15);
    border-color: rgba(197, 160, 40, 0.55);
    color: #8a6d1a;
}
/* Filter result hint (e.g., "عرض 5 من 22") */
.lp-results-hint {
    font-size: 11px;
    color: var(--text-dim);
    font-weight: 600;
    margin-right: auto;
    font-variant-numeric: tabular-nums;
}

/* Make summary cards clickable as filters (entities / individuals) */
.lp-summary-card {
    cursor: pointer;
    user-select: none;
}
.lp-summary-card:hover {
    border-color: rgba(226, 190, 61, 0.4);
    border-top-color: var(--sbmf-gold);
    transform: translateY(-2px);
    box-shadow: 0 4px 16px rgba(226, 190, 61, 0.1);
}
.lp-summary-card.lp-active-filter {
    box-shadow: 0 0 0 2px rgba(226, 190, 61, 0.55);
}
.lp-summary-card.lp-dimmed {
    opacity: 0.55;
}
.lp-filter-active-hint {
    position: absolute;
    top: 0.4rem;
    left: 0.6rem;
    font-size: 10px;
    color: var(--sbmf-gold);
    font-weight: 800;
    background: rgba(226, 190, 61, 0.18);
    padding: 0.15rem 0.5rem;
    border-radius: 20px;
    display: none;
}
.lp-summary-card.lp-active-filter .lp-filter-active-hint {
    display: inline-block;
}

/* Borrowers grid */
.lp-borrowers-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 0.8rem;
    margin-top: 1rem;
    padding-bottom: 1rem;
}
.lp-borrower-card {
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    background:
        radial-gradient(circle at center, rgba(255,255,255,0.04) 0%, rgba(255,255,255,0) 85%),
        linear-gradient(to bottom, rgba(255,255,255,0.06) 0%, rgba(255,255,255,0) 100%);
    background-color: var(--glass-base);
    box-shadow: 0 6px 16px -4px rgba(0, 0, 0, 0.3);
    border: 1px solid rgba(255, 255, 255, 0.03);
    border-radius: 0.6rem;
    overflow: hidden;
    will-change: transform;
    transition: all 0.2s;
}
.lp-borrower-card:hover {
    border-color: rgba(226, 190, 61, 0.3);
    transform: translateY(-2px);
}
body.light-theme .lp-borrower-card {
    background-color: rgba(255, 255, 255, 0.6);
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.07);
    border-color: rgba(0, 0, 0, 0.06);
}
.lp-borrower-head {
    background: rgba(226, 190, 61, 0.05);
    padding: 0.5rem 0.7rem;
    text-align: center;
    border-bottom: 1px solid rgba(226, 190, 61, 0.15);
}
body.light-theme .lp-borrower-head {
    background: rgba(226, 190, 61, 0.1);
}
.lp-borrower-label {
    font-size: 11px;
    color: var(--text-dim);
    font-weight: 700;
    margin-bottom: 0.15rem;
}
.lp-borrower-name {
    font-size: 13px;
    font-weight: 700;
    color: var(--text-main);
    line-height: 1.3;
}
.lp-borrower-body {
    padding: 0.6rem 0.7rem;
}
.lp-borrower-row {
    display: flex;
    justify-content: space-between;
    font-size: 12px;
    padding: 0.2rem 0;
    color: var(--text-dim);
}
.lp-borrower-row .lp-val {
    font-variant-numeric: tabular-nums;
    color: var(--text-main);
    font-weight: 600;
}
.lp-borrower-row.divider {
    border-top: 1px solid rgba(255, 255, 255, 0.06);
    margin-top: 0.25rem;
    padding-top: 0.4rem;
}
body.light-theme .lp-borrower-row.divider {
    border-top-color: rgba(0, 0, 0, 0.07);
}
.lp-borrower-footer {
    padding: 0.4rem 0.7rem 0.6rem;
}
.lp-borrower-footer .lp-pct-label {
    font-size: 11px;
    text-align: center;
    margin-top: 0.3rem;
}

/* Empty-state message when filters hide everything */
.lp-empty-state {
    grid-column: 1 / -1;
    text-align: center;
    padding: 2rem 1rem;
    color: var(--text-dim);
    font-size: 13px;
    background: rgba(255, 255, 255, 0.02);
    border: 1px dashed rgba(255, 255, 255, 0.1);
    border-radius: 9px;
}
body.light-theme .lp-empty-state {
    background: rgba(0, 0, 0, 0.02);
    border-color: rgba(0, 0, 0, 0.1);
}

/* Make "مجمع القروض" badge clickable */
.lending-badge.clickable-loan-pool {
    cursor: pointer;
    transition: all 0.2s;
}
.lending-badge.clickable-loan-pool:hover {
    background: rgba(226, 190, 61, 0.08);
    border-color: rgba(226, 190, 61, 0.3);
    transform: translateY(-2px);
}
.lending-badge.clickable-loan-pool .open-loan-pool-hint {
    font-size: 11px;
    color: var(--sbmf-gold);
    margin-top: 0.3rem;
    font-weight: 700;
    opacity: 0.85;
}
.lending-badge.clickable-loan-pool:hover .open-loan-pool-hint {
    opacity: 1;
}

/* ── Level-1 (المستوى الأول) tri-chart layout ─────────────────────
   2 doughnuts side-by-side + mini progress bar below.
   Layout matches main cards (.card-charts-stack) but has 2 charts in a row. */
.l1-charts-stack {
    display: flex;
    flex-direction: column;
    width: 100%;
    height: 100%;
    gap: 0.4rem;
    padding: 0.5rem;
    box-sizing: border-box;
    min-height: 0;
}
.l1-doughnuts-row {
    flex: 1;
    min-height: 0;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.5rem;
}
.l1-chart-cell {
    position: relative;
    min-width: 0;
    min-height: 0;
    z-index: 2;
}
.l1-chart-cell canvas {
    display: block;
    position: relative;
    z-index: 3;
}
/* On narrow screens stack the doughnuts vertically */
@media (max-width: 900px) {
    .l1-doughnuts-row {
        grid-template-columns: 1fr;
    }
}

.level-2-container .level-card.collapsed .card-full-content {
    display: none;
}
.level-2-container .level-card.collapsed .card-main-title {
    writing-mode: vertical-rl;
    padding: 0.75rem 0.25rem;
    margin: auto;
    letter-spacing: 1px;
    transform: rotate(180deg);
}

/* Level 3 & 4: Programs/Projects - fixed-width wrapping cards
CRITICAL: no flex:1, no overflow-y here. These containers grow with content. */
.level-3-container,
.level-4-container {
    display: flex;
    flex-wrap: wrap;
    gap: 0.85rem;
    width: 100%;
    align-content: flex-start;
    justify-content: flex-start;
    padding-bottom: 0.5rem;
}
.level-3-card,
.level-4-card {
    flex: 0 0 auto;
    display: flex;
    flex-direction: column;
}
.level-3-card .card-full-content,
.level-4-card .card-full-content {
    display: flex;
    flex-direction: column;
    padding: 0.5rem;
    gap: 0.4rem;
}
/* Width: original was ~280px, +30% = ~365px for level 3, ~365px for level 4 too */
.level-3-card {
    width: 365px;
}
.level-4-card {
    width: 365px;
}

/* Color-coded borders to distinguish levels */
.level-2-container .level-card {
    border-color: rgba(226, 190, 61, 0.25); /* gold - same as main */
}
.level-3-card {
    border-color: rgba(226, 190, 61, 0.2) !important;
    box-shadow: 0 0 0 1px rgba(226, 190, 61, 0.06) inset;
}
.level-3-card .card-main-title {
    color: rgba(226, 190, 61, 0.85) !important;
    border-color: rgba(226, 190, 61, 0.25) !important;
    background: rgba(226, 190, 61, 0.06) !important;
}
.level-4-card {
    border-color: rgba(226, 190, 61, 0.13) !important;
    box-shadow: 0 0 0 1px rgba(226, 190, 61, 0.04) inset;
}
.level-4-card .card-main-title {
    color: rgba(226, 190, 61, 0.65) !important;
    border-color: rgba(226, 190, 61, 0.18) !important;
    background: rgba(226, 190, 61, 0.04) !important;
}

/* CRITICAL: detailsView must allow vertical scrolling, NOT force flex:1 on content */
/* ── كل الـ views تتمرر داخلياً → الـ header يبقى دائماً مرئياً ── */
#dashboardView,
#detailsView,
#loanPoolView,
#beneficiaryView {
    overflow-y: auto !important;
    overflow-x: hidden;
    /* max-height ضرورية لتفعيل التمرير الداخلي */
    max-height: calc(100vh - 72px);
}

#detailsView > #subCardsContainer {
    flex-shrink: 0;
}

/* Section title before sub-cards (clarifies what's being shown) */
.sub-section-label {
    font-size: 0.85rem;
    font-weight: 800;
    color: var(--sbmf-gold);
    margin: 0.5rem 0 0.3rem;
    padding: 0.4rem 0.8rem;
    border-right: 3px solid var(--sbmf-gold);
    background: rgba(226, 190, 61, 0.05);
    border-radius: 0.4rem;
    display: inline-block;
}

/* Empty state when no sub-items */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 3rem 2rem;
    color: var(--text-dim);
    background: rgba(226, 190, 61, 0.03);
    border: 1px dashed rgba(226, 190, 61, 0.2);
    border-radius: 1rem;
    margin: 1rem 0;
    width: 100%;
    text-align: center;
}
.empty-state-icon {
    font-size: 2.5rem;
    margin-bottom: 0.5rem;
    opacity: 0.6;
}
.empty-state-text {
    font-size: 0.95rem;
    font-weight: 700;
}
.empty-state-hint {
    font-size: 0.8rem;
    margin-top: 0.4rem;
    opacity: 0.7;
}

/* Horizontal navigation bar (siblings) - SINGLE LINE WITH SCROLL */
.siblings-nav-wrapper {
    width: 100%;
    margin-bottom: 0.6rem;
}
.siblings-nav {
    display: flex;
    flex-wrap: nowrap;
    gap: 0.5rem;
    padding: 0.5rem 0.7rem;
    background: rgba(226, 190, 61, 0.04);
    border: 1px solid rgba(226, 190, 61, 0.15);
    border-radius: 0.6rem;
    overflow-x: auto;
    overflow-y: hidden;
    scrollbar-width: thin;
    min-height: 38px;
    align-items: center;
}
.siblings-nav::-webkit-scrollbar {
    height: 4px;
}
.siblings-nav::-webkit-scrollbar-thumb {
    background: rgba(226, 190, 61, 0.25);
    border-radius: 2px;
}
.siblings-nav-item {
    padding: 0.3rem 0.85rem;
    border-radius: 0.45rem;
    font-size: 0.75rem;
    font-weight: 700;
    cursor: pointer;
    white-space: nowrap;
    transition: all 0.2s ease;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.06);
    color: var(--text-dim);
}
.siblings-nav-item:hover {
    background: rgba(226, 190, 61, 0.08);
    color: var(--text-main);
    border-color: rgba(226, 190, 61, 0.3);
}
.siblings-nav-item.active {
    background: rgba(226, 190, 61, 0.12);
    color: var(--sbmf-gold);
    border-color: rgba(226, 190, 61, 0.5);
}
body.light-theme .siblings-nav-item.active {
    color: #8a6d1a;
    background: rgba(226, 190, 61, 0.12);
}

/* Breadcrumb styling */
.breadcrumb-bar {
    font-size: 0.85rem;
    margin-bottom: 0.5rem;
    text-align: right;
    padding: 0.3rem 0.5rem;
}
.breadcrumb-bar .crumb-link {
    cursor: pointer;
    color: var(--text-dim);
    transition: color 0.2s;
}
.breadcrumb-bar .crumb-link:hover {
    color: var(--text-main);
}
.breadcrumb-bar .crumb-current {
    color: var(--sbmf-gold);
    font-weight: 800;
}
.breadcrumb-bar .crumb-separator {
    color: var(--text-dim);
    margin: 0 0.4rem;
    opacity: 0.5;
}

/* View mode toggle button */
.view-toggle-btn {
    background: rgba(226, 190, 61, 0.1);
    border: 1px solid rgba(226, 190, 61, 0.3);
    color: var(--sbmf-gold);
    padding: 0.4rem 1rem;
    border-radius: 0.5rem;
    font-size: 0.8rem;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.2s;
}
.view-toggle-btn:hover {
    background: rgba(226, 190, 61, 0.2);
    border-color: rgba(226, 190, 61, 0.5);
}

/* Tree View Styling */
.tree-container {
    display: block;
    width: 100%;
    overflow-y: auto;
    padding-bottom: 1rem;
    flex: 1;
    min-height: 0;
}
.tree-view-wrapper {
    background: var(--card-bg);
    border-radius: 0.75rem;
    border: 1px solid var(--card-border);
    overflow: hidden;
}
.tree-row {
    display: grid;
    grid-template-columns: 2.2fr 1fr 1fr 1fr 1.4fr;
    gap: 0.5rem;
    padding: 0.6rem 1rem;
    align-items: center;
    border-bottom: 1px solid rgba(255, 255, 255, 0.04);
    transition: background 0.2s;
}
body.light-theme .tree-row {
    border-bottom-color: rgba(0, 0, 0, 0.04);
}
.tree-row:last-child {
    border-bottom: none;
}
.tree-row:hover {
    background: rgba(226, 190, 61, 0.04);
}
.tree-header {
    background: rgba(226, 190, 61, 0.08);
    font-weight: 800;
    font-size: 0.78rem;
    color: var(--sbmf-gold);
    letter-spacing: 0.5px;
}
.tree-header:hover {
    background: rgba(226, 190, 61, 0.08);
}
.tree-parent-row {
    background: rgba(226, 190, 61, 0.03);
    font-weight: 700;
}
.tree-parent-row:hover {
    background: rgba(226, 190, 61, 0.07);
}
.tree-parent-name {
    color: var(--sbmf-gold);
    font-size: 0.95rem;
    font-weight: 800;
}
body.light-theme .tree-parent-name {
    color: #8a6d1a;
}
.tree-icon {
    color: rgba(226, 190, 61, 0.65);
    margin-left: 0.5rem;
    font-size: 0.7rem;
}
.tree-child-name {
    padding-right: 1.5rem;
    color: var(--text-main);
    font-size: 0.85rem;
}
.tree-bullet {
    margin-left: 0.4rem;
    opacity: 0.8;
}
.tree-cell {
    text-align: right;
    font-size: 0.8rem;
}
.tree-name {
    text-align: right;
}
.tree-amount {
    font-variant-numeric: tabular-nums;
    font-weight: 600;
    color: var(--text-main);
}
.tree-actual {
    color: rgba(226, 190, 61, 0.6);
    font-weight: 700;
}
body.light-theme .tree-actual {
    color: #8a6d1a;
}
.tree-pct {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-weight: 700;
    color: var(--sbmf-gold);
}
.tree-pct-bar {
    flex: 1;
    height: 6px;
    background: rgba(255, 255, 255, 0.08);
    border-radius: 3px;
    overflow: hidden;
}
body.light-theme .tree-pct-bar {
    background: rgba(0, 0, 0, 0.08);
}
.tree-pct-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--sbmf-gold), #f39c12);
    border-radius: 3px;
}
@media (max-width: 768px) {
    .tree-row {
        display: flex;
        flex-wrap: wrap;
        gap: 0.25rem 0.5rem;
        padding: 0.5rem 0.75rem;
    }
    .tree-row .tree-name {
        flex: 0 0 100%;
        font-size: 0.8rem;
    }
    .tree-row .tree-cell {
        flex: 1 1 auto;
        font-size: 0.72rem;
        text-align: right;
        min-width: 0;
    }
}
@media (max-width: 480px) {
    .tree-row .tree-cell {
        flex: 0 0 calc(50% - 0.25rem);
    }
}

.stat-badge {
    background: var(--card-inner-bg);
    border-radius: 0.6rem;
    padding: 0.3rem;
    text-align: center;
    border: 1px solid rgba(226, 190, 61, 0.05);
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.gold-text {
    color: var(--sbmf-gold);
}
.orange-text {
    color: var(--sbmf-orange);
}

.indicators-frame {
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 0.75rem;
    padding: 0.4rem 0.5rem;
    background: rgba(0, 0, 0, 0.1);
    margin-top: 0.15rem;
}

.progress-rail {
    height: 6px;
    background: rgba(0, 0, 0, 0.25);
    border-radius: 20px;
    overflow: hidden;
}

.progress-fill {
    background: linear-gradient(90deg, #d4af37, var(--sbmf-gold));
    box-shadow: 0 0 10px rgba(226, 190, 61, 0.3);
    transition: width 0.6s ease;
}

.progress-fill-achievement {
    background: var(--sbmf-orange);
    box-shadow: 0 0 10px rgba(243, 156, 18, 0.3);
    transition: width 0.6s ease;
}

/* ── RAG Progress Bars ─────────────────────────────────────────────
   completion_ratio : ≥70% أخضر | 40–70% أصفر | <40% أحمر
   spend_ratio      : ≥60% أخضر | 30–60% أصفر | <30% أحمر      */
.progress-fill-rag-green {
    background: linear-gradient(90deg, #15803d, #22c55e);
    box-shadow: 0 0 10px rgba(34, 197, 94, 0.35);
    transition: width 0.6s ease;
}
.progress-fill-rag-yellow {
    background: linear-gradient(90deg, #b45309, #f59e0b);
    box-shadow: 0 0 10px rgba(245, 158, 11, 0.35);
    transition: width 0.6s ease;
}
.progress-fill-rag-red {
    background: linear-gradient(90deg, #991b1b, #ef4444);
    box-shadow: 0 0 10px rgba(239, 68, 68, 0.35);
    transition: width 0.6s ease;
}
/* ألوان النص المتناسقة مع الـ RAG */
.rag-text-green  { color: #22c55e; }
.rag-text-yellow { color: #f59e0b; }
.rag-text-red    { color: #ef4444; }

.model-toggle {
    display: flex;
    background: var(--glass-base);
    padding: 4px;
    border-radius: 12px;
    border: 1px solid rgba(226, 190, 61, 0.2);
    cursor: pointer;
}

.toggle-icon {
    padding: 3px 8px;
    border-radius: 6px;
    transition: 0.3s;
    font-weight: 700;
    font-size: 10px;
    color: var(--text-dim);
}

.active-model {
    background: var(--sbmf-gold);
    color: #000;
}

.expense-box {
    padding-top: 0.2rem;
    padding-bottom: 0.2rem;
    margin-bottom: 0.15rem;
    flex: 0.5;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.lending-section {
    padding: 0.2rem 1rem 0.3rem 1rem !important;
    margin-top: 0;
    flex-shrink: 0;
}

.lending-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 0.4rem;
    margin-top: 0.2rem;
}

.lending-badge {
    background: var(--card-inner-bg);
    border-radius: 0.6rem;
    padding: 0.3rem 0.2rem;
    text-align: center;
    border: 1px solid rgba(255, 255, 255, 0.03);
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    align-items: center;
    min-height: 60px;
    transition: all 0.3s ease;
}

.lending-badge.clickable {
    cursor: pointer;
    border: 1px solid rgba(226, 190, 61, 0.2);
}

.lending-badge.clickable:hover {
    background: rgba(226, 190, 61, 0.1);
    transform: translateY(-2px);
}

.show-details-btn {
    text-align: center;
    font-size: 11px;
    font-weight: 800;
    color: var(--sbmf-gold);
    cursor: pointer;
    padding: 0.4rem 0.75rem;
    border-top: 1px solid rgba(255, 255, 255, 0.05);
    transition: all 0.3s;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-top: 0.3rem;
    background: rgba(226, 190, 61, 0.05);
    border-radius: 8px;
    border: 1px solid rgba(226, 190, 61, 0.2);
}

.show-details-btn:hover {
    background: rgba(226, 190, 61, 0.15);
    transform: translateY(-1px);
    box-shadow: 0 4px 8px rgba(226, 190, 61, 0.2);
}

/* Toggle Charts Button Styling */
#toggleChartsBtn {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    background: rgba(226, 190, 61, 0.08);
    border: 1px solid rgba(226, 190, 61, 0.3);
}

#toggleChartsBtn:hover {
    background: rgba(226, 190, 61, 0.15);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(226, 190, 61, 0.2);
}

#chartsButtonIcon {
    font-size: 10px;
    transition: transform 0.3s ease;
}

.out-of-budget-compact {
    padding: 0.3rem 1.5rem 0.4rem 1.5rem !important;
    flex-shrink: 0;
}

.out-of-budget-compact .section-main-title {
    margin: 0.15rem auto 0.25rem auto !important;
    padding: 0.15rem 0.75rem !important;
    font-size: 0.95rem !important;
}

.out-of-budget-compact .stat-badge {
    padding: 0.15rem 0.25rem !important;
}

.out-of-budget-compact .indicators-grid {
    margin-top: 0.2rem !important;
    padding-top: 0.2rem !important;
    gap: 1.5rem !important;
}

#detailsView,
#beneficiaryView {
    display: none;
    opacity: 0;
    transition: opacity 0.5s ease;
}

.back-btn {
    display: flex !important;
    align-items: center;
    gap: 0.5rem;
    color: var(--sbmf-gold);
    cursor: pointer;
    font-weight: 800;
    font-size: 13px;
    padding: 0.5rem 1.2rem;
    border: 1px solid rgba(226, 190, 61, 0.3);
    border-radius: 10px;
    width: fit-content;
    margin-bottom: 0.4rem;
    background: rgba(226, 190, 61, 0.05);
    transition: 0.3s;
    position: relative;
    z-index: 10;
    flex-shrink: 0;
    align-self: flex-start;
}

.back-btn:hover {
    background: rgba(226, 190, 61, 0.15);
    border-color: rgba(226, 190, 61, 0.5);
}

/* Toast Notifications */
.toast {
    position: fixed;
    top: 20px;
    left: 50%;
    transform: translateX(-50%) translateY(-100px);
    background: var(--glass-base);
    backdrop-filter: blur(20px);
    padding: 1rem 2rem;
    border-radius: 12px;
    border: 1px solid rgba(226, 190, 61, 0.3);
    opacity: 0;
    transition: all 0.3s ease;
    z-index: 9999;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
    min-width: 300px;
}

.toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

.toast-content {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.toast-icon {
    width: 20px;
    height: 20px;
    fill: none;
    stroke: var(--sbmf-gold);
    stroke-width: 2;
    flex-shrink: 0;
}

.toast-success {
    border-color: rgba(52, 211, 153, 0.3);
}
.toast-success .toast-icon {
    stroke: #34d399;
}
.toast-error {
    border-color: rgba(239, 68, 68, 0.3);
}
.toast-error .toast-icon {
    stroke: #ef4444;
}

/* Global Loader - v5: opacity reduced to 0.40 + pointer-events:none to avoid black-screen */
#globalLoader {
    position: fixed;
    inset: 0;
    background: rgba(11, 11, 9, 0.4);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10000;
    opacity: 1;
    transition: opacity 0.3s ease;
    pointer-events: none; /* prevent loader from blocking clicks during drill-down */
}
body.light-theme #globalLoader {
    background: rgba(255, 255, 255, 0.4);
}

.loader-content {
    text-align: center;
}

.spinner {
    width: 50px;
    height: 50px;
    border: 3px solid rgba(226, 190, 61, 0.2);
    border-top-color: var(--sbmf-gold);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto 1rem;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* Search Container */
.search-container {
    position: relative;
    display: flex;
    align-items: center;
    width: 520px;
    max-width: 100%;
}

.search-input {
    width: 100%;
    padding: 0.5rem 2.5rem 0.5rem 1rem;
    background: var(--glass-base);
    border: 1px solid rgba(226, 190, 61, 0.2);
    border-radius: 10px;
    color: var(--text-main);
    font-size: 13px;
    font-family: "Tajawal", sans-serif;
    transition: all 0.3s ease;
}

.search-input:focus {
    outline: none;
    border-color: var(--sbmf-gold);
    box-shadow: 0 0 0 3px rgba(226, 190, 61, 0.1);
}

.search-input::placeholder {
    color: var(--text-dim);
}

.search-icon {
    position: absolute;
    left: 0.75rem;
    width: 18px;
    height: 18px;
    fill: none;
    stroke: var(--text-dim);
    stroke-width: 2;
    pointer-events: none;
}

/* Search Results */
.search-results {
    position: absolute;
    top: calc(100% + 0.5rem);
    left: 0;
    right: 0;
    background: var(--glass-base);
    backdrop-filter: blur(20px);
    border: 1px solid rgba(226, 190, 61, 0.2);
    border-radius: 10px;
    max-height: 400px;
    overflow-y: auto;
    z-index: 1000;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
}

.search-result-item {
    padding: 0.75rem 1rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    cursor: pointer;
    transition: all 0.2s;
}

.search-result-item:hover {
    background: rgba(226, 190, 61, 0.1);
}

.search-result-item:last-child {
    border-bottom: none;
}

/* Export Button */
.export-btn {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.4rem 1rem;
    background: var(--glass-base);
    border: 1px solid rgba(226, 190, 61, 0.2);
    border-radius: 10px;
    color: var(--sbmf-gold);
    font-weight: 700;
    font-size: 12px;
    cursor: pointer;
    transition: all 0.3s;
}

.export-btn:hover {
    background: rgba(226, 190, 61, 0.1);
    transform: translateY(-1px);
}

/* v5: Logout button - red accent to differentiate from export */
.logout-btn {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.4rem 1rem;
    background: var(--glass-base);
    border: 1px solid rgba(220, 80, 80, 0.35);
    border-radius: 10px;
    color: #dc5050;
    font-weight: 700;
    font-size: 12px;
    cursor: pointer;
    transition: all 0.3s;
    text-decoration: none;
}
.logout-btn:hover {
    background: rgba(220, 80, 80, 0.12);
    border-color: rgba(220, 80, 80, 0.6);
    transform: translateY(-1px);
}
body.light-theme .logout-btn {
    color: #b33a3a;
    border-color: rgba(179, 58, 58, 0.4);
}

/* Chart Container */
.chart-container {
    position: relative;
    height: 250px;
    padding: 1rem;
    background: var(--card-inner-bg);
    border-radius: 0.75rem;
    border: 1px solid rgba(255, 255, 255, 0.05);
}

/* Media Queries */
@media (max-width: 1024px) {
    .cards-container {
        flex-direction: column;
        gap: 1rem;
    }

    .category-card.collapsed {
        flex: 1;
        opacity: 1;
    }

    .collapsed .card-main-title {
        writing-mode: horizontal-tb;
        transform: rotate(0deg);
        padding: 0.25rem 1rem;
    }

    .collapsed .card-full-content {
        display: flex;
        opacity: 1;
    }

    .lending-grid {
        grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    }

    .search-container {
        max-width: 100%;
    }
}

@media (max-width: 768px) {
    .main-wrapper {
        padding: 0.5rem;
    }

    header {
        flex-direction: column;
        gap: 1rem;
        align-items: flex-start !important;
    }

    header h1 {
        font-size: 1.25rem !important;
    }

    .header-controls {
        width: 100%;
        display: flex;
        gap: 0.5rem;
        flex-wrap: wrap;
    }

    .search-container {
        flex: 1;
        min-width: 200px;
    }

    .lending-grid {
        grid-template-columns: 1fr;
    }

    .stat-badge {
        min-height: auto;
        padding: 0.5rem;
    }

    .section-main-title,
    .card-main-title {
        font-size: 0.95rem !important;
    }

    .chart-container {
        height: 200px;
    }
}

@media (max-width: 640px) {
    .cards-container {
        gap: 0.5rem;
    }

    .premium-card {
        border-radius: 1rem;
    }

    .export-btn {
        font-size: 10px;
        padding: 0.3rem 0.75rem;
    }
}

::-webkit-scrollbar {
    width: 4px;
}
::-webkit-scrollbar-thumb {
    background: var(--sbmf-gold);
    border-radius: 10px;
}

/* ── Main Category Card: fix height:100% overflow clipping button ─ */
/* height:100% on a flex child = full card height, but h4 title
   already occupies ~40px above it → combined overflow clips the
   "إظهار التفاصيل" button at the bottom.
   Fix: flex:1 fills remaining space correctly. */
.category-card .card-full-content {
    height: auto;
    flex: 1;
    min-height: 0;
}

/* ── Responsive Layout Fixes ────────────────────────────────── */

/* Prevent horizontal scroll at all widths */
.main-wrapper {
    overflow-x: hidden;
}

/* ≤1024px: cards stack vertically → internal scroll + sub-card width guard */
@media (max-width: 1024px) {
    .cards-container {
        overflow-y: auto;
        overflow-x: hidden;
    }
    .level-3-card,
    .level-4-card {
        width: min(365px, calc(50% - 0.5rem));
    }
}

/* ≤768px: switch to scrollable-page layout; remove fixed-height constraints */
@media (max-width: 768px) {
    body {
        overflow: auto;
        height: auto;
        min-height: 100vh;
    }
    .main-wrapper {
        height: auto;
        min-height: 100vh;
    }
    #dashboardView,
    #detailsView,
    #beneficiaryView {
        overflow: visible !important;
        flex: unset;
    }
    .cards-container {
        overflow: visible;
    }
    /* Level-2 cards: reduce fixed height */
    .level-2-container .level-card {
        height: 350px;
    }
    .level-2-container .level-card.expanded .card-data-section {
        flex: 0 0 200px;
    }
    /* Level-3/4: single column on narrow screens */
    .level-3-card,
    .level-4-card {
        width: 100%;
        min-width: 0;
    }
    /* Override single-column lending grid from base 768px rule */
    .lending-grid {
        grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    }
}

/* ≤480px: compact single-column mobile */
@media (max-width: 480px) {
    .main-wrapper {
        padding: 0.25rem 0.5rem;
    }
    header h1 {
        font-size: 1rem !important;
    }
    .level-2-container .level-card {
        height: 300px;
    }
    .level-2-container .level-card.expanded .card-data-section {
        flex: 0 0 150px;
    }
    .chart-container {
        height: 150px;
    }
    .lending-grid {
        grid-template-columns: repeat(2, 1fr);
    }
    .level-3-container,
    .level-4-container {
        gap: 0.5rem;
    }
}

/* ── Dashboard Options Button & Modal ───────────── */
.options-btn {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.4rem 0.9rem;
    background: rgba(226, 190, 61, 0.08);
    border: 1px solid rgba(226, 190, 61, 0.35);
    border-radius: 10px;
    color: var(--sbmf-gold);
    font-family: inherit;
    font-size: 12px;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
}
.options-btn:hover {
    background: rgba(226, 190, 61, 0.15);
    border-color: var(--sbmf-gold);
}

/* Badge showing active filter in header */
.filter-active-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    background: rgba(226, 190, 61, 0.1);
    border: 1px solid rgba(226, 190, 61, 0.2);
    border-radius: 6px;
    padding: 0.15rem 0.5rem;
    color: var(--sbmf-gold);
    font-size: 11px;
    font-weight: 700;
    cursor: pointer;
    transition: background 0.2s;
}
.filter-active-badge:hover {
    background: rgba(226, 190, 61, 0.18);
}

/* Year selector in left header */
.header-year-select {
    background: transparent;
    border: 1px solid rgba(226, 190, 61, 0.3);
    border-radius: 6px;
    color: var(--sbmf-gold);
    font-family: inherit;
    font-size: 11px;
    font-weight: 700;
    padding: 0.15rem 0.4rem;
    cursor: pointer;
}
.header-year-select option {
    background: #1a1a17;
    color: #f8f9f8;
}
body.light-theme .header-year-select option {
    background: #fff;
    color: #333;
}
body.light-theme .header-year-select {
    color: #b8992a;
}

/* Modal Overlay */
.options-modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    z-index: 9000;
    align-items: center;
    justify-content: center;
}
.options-modal-overlay.open {
    display: flex;
}

/* Modal Box */
.options-modal {
    background: var(--card-bg, #16160f);
    border: 1px solid rgba(226, 190, 61, 0.25);
    border-radius: 1.25rem;
    padding: 1.5rem;
    min-width: 340px;
    max-width: 480px;
    width: 90%;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
    direction: rtl;
}
body.light-theme .options-modal {
    background: #fff;
}

.options-modal h3 {
    font-size: 1.1rem;
    font-weight: 800;
    color: var(--sbmf-gold);
    margin-bottom: 1.25rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}
.modal-field {
    margin-bottom: 1rem;
}
.modal-field label {
    display: block;
    font-size: 12px;
    font-weight: 700;
    color: var(--text-dim);
    margin-bottom: 0.35rem;
}
.modal-select {
    width: 100%;
    background: var(--glass-base);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    color: var(--text-main);
    font-family: inherit;
    font-size: 13px;
    padding: 0.45rem 0.75rem;
    cursor: pointer;
}
.modal-select:focus {
    outline: none;
    border-color: var(--sbmf-gold);
}
body.light-theme .modal-select {
    background: #f5f3ee;
    border-color: #ddd;
}

.modal-row {
    display: flex;
    gap: 0.75rem;
}
.modal-row .modal-field {
    flex: 1;
}

.modal-actions {
    display: flex;
    gap: 0.75rem;
    margin-top: 1.5rem;
    justify-content: flex-end;
}
.modal-btn-primary {
    background: var(--sbmf-gold);
    color: #0b0b09;
    border: none;
    border-radius: 8px;
    padding: 0.5rem 1.25rem;
    font-family: inherit;
    font-size: 13px;
    font-weight: 800;
    cursor: pointer;
    transition: opacity 0.2s;
}
.modal-btn-primary:hover {
    opacity: 0.85;
}
.modal-btn-cancel {
    background: transparent;
    color: var(--text-dim);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    padding: 0.5rem 1.25rem;
    font-family: inherit;
    font-size: 13px;
    cursor: pointer;
    transition: border-color 0.2s;
}
.modal-btn-cancel:hover {
    border-color: rgba(255, 255, 255, 0.25);
}

/* Filter select (kept for modal) */
.filter-select {
    background: var(--glass-base);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 6px;
    color: var(--text-main);
    font-family: inherit;
    font-size: 12px;
    padding: 0.25rem 0.5rem;
    cursor: pointer;
}
.filter-select:focus {
    outline: none;
    border-color: var(--sbmf-gold);
}
body.light-theme .filter-select {
    background: #f5f3ee;
}

/* ══ Side Navigation ════════════════════════════════════════════════ */
.sidenav-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.55);
    z-index: 8000;
}
.sidenav-overlay.open {
    display: block;
}
.sidenav {
    position: fixed;
    top: 0;
    right: -300px;
    bottom: 0;
    width: 270px;
    background: var(--card-bg, #111108);
    border-left: 1px solid rgba(226, 190, 61, 0.2);
    z-index: 8001;
    display: flex;
    flex-direction: column;
    transition: right 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    overflow: hidden;
}
body.light-theme .sidenav {
    background: #fff;
}
.sidenav.open {
    right: 0;
}
.sidenav-head {
    padding: 0.9rem 1rem 0.7rem;
    border-bottom: 1px solid rgba(226, 190, 61, 0.15);
    display: flex;
    align-items: center;
    gap: 0.6rem;
    flex-shrink: 0;
}
.sidenav-logo {
    width: 30px;
    height: 30px;
    background: rgba(226, 190, 61, 0.1);
    border: 1px solid rgba(226, 190, 61, 0.3);
    border-radius: 7px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}
.sidenav-title {
    font-size: 14px;
    font-weight: 800;
    color: var(--sbmf-gold);
}
.sidenav-close {
    margin-right: auto;
    background: none;
    border: none;
    color: var(--text-dim);
    cursor: pointer;
    padding: 0.2rem;
    border-radius: 4px;
}
.sidenav-close:hover {
    color: var(--text-main);
}
.sidenav-user {
    padding: 0.55rem 1rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
    font-size: 11px;
    color: var(--text-dim);
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-shrink: 0;
}
.sidenav-body {
    flex: 1;
    overflow-y: auto;
    padding: 0.4rem 0;
}
.sidenav-main-link {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.6rem 1rem;
    cursor: pointer;
    color: var(--text-main);
    font-size: 13px;
    font-weight: 700;
    text-decoration: none;
    transition: background 0.15s;
}
.sidenav-main-link:hover,
.sidenav-main-link.active {
    background: rgba(226, 190, 61, 0.1);
    color: var(--sbmf-gold);
}
.sidenav-section {
    margin: 0.2rem 0;
}
.sidenav-section-title {
    padding: 0.5rem 1rem 0.2rem;
    font-size: 10px;
    font-weight: 800;
    letter-spacing: 0.06em;
    color: var(--sbmf-gold);
    opacity: 0.75;
    text-transform: uppercase;
}
.sidenav-item {
    display: flex;
    align-items: center;
    gap: 0.55rem;
    padding: 0.45rem 1rem 0.45rem 1.3rem;
    cursor: pointer;
    color: var(--text-dim);
    font-size: 12px;
    font-weight: 600;
    transition: background 0.15s;
}
.sidenav-item:hover {
    background: rgba(255, 255, 255, 0.04);
    color: var(--text-main);
}
.sidenav-item.active {
    color: var(--sbmf-gold);
    background: rgba(226, 190, 61, 0.07);
}
.sidenav-footer {
    padding: 0.6rem 1rem;
    flex-shrink: 0;
    border-top: 1px solid rgba(255, 255, 255, 0.06);
    font-size: 10px;
    color: var(--text-dim);
}
/* ══ Report Page ════════════════════════════════════════════════════ */
.rf-group-label {
    font-size: 11px;
    font-weight: 800;
    color: var(--sbmf-gold);
    opacity: 0.8;
    white-space: nowrap;
}
.rf-sep {
    width: 1px;
    height: 16px;
    background: rgba(255, 255, 255, 0.1);
    flex-shrink: 0;
}
body.light-theme .rf-sep {
    background: rgba(0, 0, 0, 0.1);
}
.report-table-wrapper {
    overflow-x: auto;
    overflow-y: auto;
}
.report-back-btn {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    color: var(--text-dim);
    font-size: 12px;
    font-weight: 700;
    cursor: pointer;
    padding: 0.3rem 0;
    margin-bottom: 0.5rem;
    background: none;
    border: none;
    font-family: inherit;
    flex-shrink: 0;
}
.report-back-btn:hover {
    color: var(--sbmf-gold);
}
.report-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 0.6rem;
    flex-shrink: 0;
    flex-wrap: wrap;
    gap: 0.5rem;
}
.report-title {
    font-size: 1.1rem;
    font-weight: 800;
    color: var(--sbmf-gold);
}
.report-actions {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}
.report-btn {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.35rem 0.8rem;
    border-radius: 7px;
    cursor: pointer;
    font-family: inherit;
    font-size: 12px;
    font-weight: 700;
    border: 1px solid rgba(255, 255, 255, 0.12);
    background: var(--glass-base);
    color: var(--text-main);
    transition: all 0.2s;
}
.report-btn:hover {
    border-color: var(--sbmf-gold);
    color: var(--sbmf-gold);
}
.report-btn.excel {
    border-color: rgba(34, 197, 94, 0.4);
    color: #22c55e;
}
.report-btn.excel:hover {
    background: rgba(34, 197, 94, 0.08);
}
.report-filters {
    display: flex;
    gap: 1rem;
    padding: 0.45rem 0.75rem;
    background: var(--glass-base);
    border-radius: 8px;
    border: 1px solid rgba(255, 255, 255, 0.06);
    margin-bottom: 0.6rem;
    flex-shrink: 0;
    flex-wrap: wrap;
    align-items: center;
}
.report-filter-toggle {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    font-size: 11px;
    font-weight: 600;
    color: var(--text-dim);
    cursor: pointer;
}
.report-filter-toggle input[type="checkbox"] {
    accent-color: var(--sbmf-gold);
}
.report-table-wrapper {
    flex: 1;
    min-height: 0;
    overflow: auto;
    border-radius: 8px;
    border: 1px solid rgba(255, 255, 255, 0.07);
}
.report-table {
    border-collapse: collapse;
    font-size: 13px;
    white-space: nowrap;
    width: max-content;
    min-width: 100%;
}
.report-table th {
    position: sticky;
    top: 0;
    z-index: 2;
    background: var(--glass-base);
    backdrop-filter: blur(12px);
    color: var(--sbmf-gold);
    padding: 0.45rem 0.5rem;
    text-align: center;
    border-bottom: 2px solid rgba(226, 190, 61, 0.3);
    border-left: 1px solid rgba(255, 255, 255, 0.06);
    font-weight: 700;
    line-height: 1.3;
}
.report-table td {
    padding: 0.35rem 0.5rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    border-left: 1px solid rgba(255, 255, 255, 0.04);
    text-align: center;
    vertical-align: middle;
}
body.light-theme .report-table td {
    border-color: rgba(0, 0, 0, 0.07);
}

/* Sticky fixed columns base */
.th-fixed,
.td-fixed {
    position: sticky;
    z-index: 2;
    background: var(--card-bg);
    backdrop-filter: blur(20px);
    border-left: 1px solid rgba(226, 190, 61, 0.12) !important;
}
.report-table thead .th-fixed {
    z-index: 4;
    background: var(--glass-base) !important;
    backdrop-filter: blur(20px);
}

/* Row types */
.td-scope {
    color: var(--sbmf-gold) !important;
    font-weight: 800;
    text-align: right;
    background: var(--card-bg) !important;
}
.td-program {
    color: rgba(226, 190, 61, 0.72);
    font-weight: 700;
    text-align: right;
}
.td-fixed-2 {
    text-align: right;
} /* project/child name */

.row-main .td-fixed-0,
.row-main .td-fixed-1 {
    color: var(--sbmf-gold);
    font-weight: 800;
}
.row-project:hover td,
.row-child:hover td {
    background: rgba(255, 255, 255, 0.025) !important;
}
.row-total td {
    background: rgba(226, 190, 61, 0.12) !important;
    font-weight: 800;
    border-top: 2px solid rgba(226, 190, 61, 0.35) !important;
}
body.light-theme .row-total td {
    background: #faf5e0 !important;
}

/* Period column headers */
.th-period {
    background: rgba(226, 190, 61, 0.05) !important;
    font-size: 12px;
}
.th-actual {
    color: rgba(226, 190, 61, 0.65) !important;
    font-size: 11px;
}
.th-scheduled {
    color: #9ca3af !important;
    font-size: 11px;
    font-style: italic;
}

/* Data cells */
.actual-cell {
    color: rgba(226, 190, 61, 0.6);
}
.scheduled-cell {
    color: #9ca3af;
    font-style: italic;
}
.zero {
    color: rgba(255, 255, 255, 0.18);
}
body.light-theme .zero {
    color: rgba(0, 0, 0, 0.15);
}
.num-neg {
    color: #ef4444;
}
.num-pos {
    color: #22c55e;
}
.num {
    text-align: right;
}

/* ══ Report Tabs ═════════════════════════════════════════════════════ */
.report-tabs {
    display: flex;
    gap: 0.3rem;
    margin-bottom: 0.7rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    flex-wrap: wrap;
    flex-shrink: 0;
    padding-bottom: 0;
}
.report-tab {
    padding: 0.5rem 0.95rem;
    border-radius: 7px 7px 0 0;
    background: var(--glass-base);
    border: 1px solid rgba(255, 255, 255, 0.06);
    border-bottom: none;
    color: var(--text-dim);
    font-family: inherit;
    font-size: 12px;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.15s;
    margin-bottom: -1px;
    white-space: nowrap;
}
.report-tab:hover {
    color: var(--sbmf-gold);
    border-color: rgba(226, 190, 61, 0.3);
    background: rgba(226, 190, 61, 0.05);
}
.report-tab.active {
    background: rgba(226, 190, 61, 0.14);
    color: var(--sbmf-gold);
    border-color: rgba(226, 190, 61, 0.45);
    border-bottom: 2px solid var(--sbmf-gold);
}
body.light-theme .report-tabs {
    border-bottom-color: rgba(0, 0, 0, 0.1);
}
body.light-theme .report-tab {
    background: #f3eee0;
    border-color: rgba(0, 0, 0, 0.08);
    color: #6b6b6b;
}
body.light-theme .report-tab:hover {
    background: #faf3d8;
    color: #8a6d1a;
}
body.light-theme .report-tab.active {
    background: #fff5d4;
    color: #8a6d1a;
    border-color: rgba(226, 190, 61, 0.55);
}

/* ══ Sticky Columns (Frozen panes for reports) ═══════════════════════ */
.report-table th.rep-fix,
.report-table td.rep-fix {
    position: sticky;
    z-index: 3;
    background: var(--card-bg);
    backdrop-filter: blur(20px);
}
.report-table thead th.rep-fix {
    z-index: 5;
    background: var(--glass-base);
    backdrop-filter: blur(20px);
}
.report-table th.rep-fix {
    box-shadow: -3px 0 5px -2px rgba(0, 0, 0, 0.45);
}
.report-table td.rep-fix {
    box-shadow: -3px 0 5px -2px rgba(0, 0, 0, 0.25);
}
/* الحدّ الأخير من العمود الثابت — يفصله بصرياً عن أعمدة الأشهر */
.report-table th.rep-fix-last,
.report-table td.rep-fix-last {
    border-left: 2px solid rgba(226, 190, 61, 0.4) !important;
}
/* الصفّ الإجمالي يحافظ على لونه حتى في الأعمدة الثابتة */
.report-table tr.row-total td.rep-fix,
.report-table td.rep-fix.row-total-cell {
    background: rgba(226, 190, 61, 0.12) !important;
}
body.light-theme .report-table th.rep-fix,
body.light-theme .report-table td.rep-fix {
    box-shadow: -3px 0 5px -2px rgba(0, 0, 0, 0.12);
}
body.light-theme .report-table tr.row-total td.rep-fix,
body.light-theme .report-table td.rep-fix.row-total-cell {
    background: rgba(226, 190, 61, 0.15) !important;
}

/* ══ Print Styles ═══════════════════════════════════════════════════ */
@media print {
    body {
        background: #fff !important;
        color: #000 !important;
    }
    header,
    .sidenav,
    .sidenav-overlay,
    .report-back-btn,
    .report-tabs,
    .report-actions,
    .report-filters,
    .options-modal-overlay {
        display: none !important;
    }
    #reportWrapper {
        display: flex !important;
        flex-direction: column;
        padding: 0 !important;
        overflow: visible !important;
    }
    .report-title {
        color: #000 !important;
        font-size: 14pt;
    }
    .report-table {
        font-size: 8pt;
    }
    .report-table th {
        background: #f0ede4 !important;
        color: #000 !important;
        border: 1px solid #ccc !important;
    }
    .report-table td {
        border: 1px solid #ddd !important;
        color: #000 !important;
    }
    .report-table tr.level-scope td {
        background: #faf5e8 !important;
    }
    .report-table tr.level-program td {
        background: #f0f5fa !important;
    }
    .report-table tr.level-total td {
        background: #f5f0e0 !important;
        font-weight: bold;
    }
    .report-table .actual-cell {
        color: #1a5276 !important;
    }
    .report-table .num-positive {
        color: #1a7a2e !important;
    }
    .report-table .num-negative {
        color: #922 !important;
    }
    .report-table td.zero {
        color: #bbb !important;
    }
    .report-table-wrapper {
        border: none !important;
        overflow: visible !important;
    }
}