/* ================================================================
   Rapha-Bethel BNPS — Custom CSS
   Mobile-first. Optimised for low-bandwidth Cameroon context.
   Design: warm institutional (deep red + gold), DM Sans typeface.
================================================================ */

/* ── DESIGN TOKENS ───────────────────────────────────────────── */
:root {
    --rb-red:        #8B0000;
    --rb-red-dark:   #5a0000;
    --rb-red-light:  #b30000;
    --rb-gold:       #C9952A;
    --rb-gold-light: #e8b84b;
    --rb-surface:    #f7f4f1;
    --rb-sidebar-w:  248px;
    --rb-nav-h:      56px;
    --rb-bottom-h:   64px;
    --rb-radius:     10px;
    --rb-shadow:     0 1px 6px rgba(0,0,0,.10);
    --rb-shadow-md:  0 4px 16px rgba(0,0,0,.12);
    --font-main:     'DM Sans', system-ui, sans-serif;
}

/* ── BASE ────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }

html, body {
    font-family: var(--font-main);
    background: var(--rb-surface);
    color: #1a1a1a;
    min-height: 100%;
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
}

/* ── TOP BAR ─────────────────────────────────────────────────── */
.rb-topbar {
    position: fixed;
    top: 0; left: 0; right: 0;
    height: var(--rb-nav-h);
    background: linear-gradient(135deg, var(--rb-red-dark) 0%, var(--rb-red) 100%);
    display: flex;
    align-items: center;
    padding: 0 1rem;
    gap: 0.75rem;
    z-index: 1030;
    box-shadow: 0 2px 8px rgba(0,0,0,.25);
}

.rb-menu-toggle {
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 5px;
    width: 44px; height: 44px;
    border: none;
    background: rgba(255,255,255,.12);
    border-radius: 8px;
    cursor: pointer;
    padding: 10px;
    flex-shrink: 0;
    transition: background .2s;
}
.rb-menu-toggle:hover { background: rgba(255,255,255,.22); }
.rb-menu-toggle span {
    display: block; height: 2px;
    background: #fff; border-radius: 2px;
    transition: transform .25s, opacity .25s;
}
body.sidebar-open .rb-menu-toggle span:nth-child(1) { transform: translateY(7px) rotate(45deg); }
body.sidebar-open .rb-menu-toggle span:nth-child(2) { opacity: 0; }
body.sidebar-open .rb-menu-toggle span:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }

.rb-brand {
    display: flex; align-items: center; gap: 0.5rem;
    text-decoration: none; flex: 1; min-width: 0;
}
.rb-brand img {
    height: 34px; width: 34px;
    border-radius: 6px; object-fit: cover; flex-shrink: 0;
}
.rb-brand-text {
    color: #fff; font-weight: 700; font-size: 0.95rem;
    line-height: 1.1; white-space: nowrap;
    overflow: hidden; text-overflow: ellipsis;
}
.rb-brand-sub {
    color: rgba(255,255,255,.65); font-size: 0.65rem;
    display: block; font-weight: 400;
}
.rb-topbar-actions { display: flex; align-items: center; gap: 0.5rem; margin-left: auto; }
.rb-topbar-btn {
    width: 38px; height: 38px; border-radius: 8px;
    border: none; background: rgba(255,255,255,.12); color: #fff;
    display: flex; align-items: center; justify-content: center;
    cursor: pointer; text-decoration: none; font-size: 0.9rem;
    transition: background .2s;
}
.rb-topbar-btn:hover { background: rgba(255,255,255,.22); color: #fff; }
.rb-avatar {
    width: 34px; height: 34px; border-radius: 50%;
    background: var(--rb-gold); color: var(--rb-red-dark);
    font-weight: 700; font-size: 0.8rem;
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0; border: 2px solid rgba(255,255,255,.3);
}

/* ── SIDEBAR OVERLAY ─────────────────────────────────────────── */
.rb-overlay {
    display: none; position: fixed; inset: 0;
    background: rgba(0,0,0,.45); z-index: 1039;
    backdrop-filter: blur(2px);
}
body.sidebar-open .rb-overlay { display: block; }

/* ── SIDEBAR ─────────────────────────────────────────────────── */
.rb-sidebar {
    position: fixed;
    top: var(--rb-nav-h); left: 0; bottom: 0;
    width: var(--rb-sidebar-w);
    background: #fff; z-index: 1040;
    overflow-y: auto; overflow-x: hidden;
    overscroll-behavior: contain;
    transition: transform .28s cubic-bezier(.4,0,.2,1);
    border-right: 1px solid #ede8e3;
    display: flex; flex-direction: column;
    padding-bottom: 1rem;
}
@media (max-width: 991px) {
    .rb-sidebar { transform: translateX(-100%); top: 0; box-shadow: var(--rb-shadow-md); }
    body.sidebar-open .rb-sidebar { transform: translateX(0); }
}
@media (min-width: 992px) {
    .rb-menu-toggle { display: none; }
    .rb-sidebar { transform: none !important; }
    .rb-main-wrap { margin-left: var(--rb-sidebar-w); }
}

/* Sidebar user card */
.sb-user {
    padding: 1rem 1rem 0.75rem;
    border-bottom: 1px solid #f0ebe5;
    display: flex; align-items: center; gap: 0.75rem;
    background: linear-gradient(135deg, #fdf8f3 0%, #fff 100%);
}
.sb-user-avatar {
    width: 42px; height: 42px; border-radius: 50%;
    background: linear-gradient(135deg, var(--rb-red), var(--rb-gold));
    color: #fff; font-weight: 700; font-size: 1rem;
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0;
}
.sb-user-name { font-weight: 600; font-size: 0.85rem; color: #1a1a1a; line-height: 1.2; }
.sb-user-role { font-size: 0.7rem; color: var(--rb-red); font-weight: 600; text-transform: uppercase; letter-spacing: 0.4px; }

/* Section headers */
.sb-section {
    padding: 0.85rem 1rem 0.2rem;
    font-size: 0.65rem; font-weight: 700;
    text-transform: uppercase; letter-spacing: 0.8px; color: #aaa;
}

/* Nav links */
.sb-link {
    display: flex; align-items: center; gap: 0.65rem;
    padding: 0.6rem 0.85rem; margin: 0 0.5rem;
    border-radius: 8px; color: #444; text-decoration: none;
    font-size: 0.875rem; font-weight: 500;
    transition: background .15s, color .15s;
    min-height: 44px;
}
.sb-link:hover { background: #f5ede6; color: var(--rb-red); }
.sb-link.active {
    background: linear-gradient(135deg, var(--rb-red-dark), var(--rb-red));
    color: #fff; font-weight: 600;
}
.sb-link.active .sb-icon { color: rgba(255,255,255,.9); }
.sb-icon { width: 18px; text-align: center; font-size: 0.85rem; color: #888; flex-shrink: 0; transition: color .15s; }
.sb-link:hover .sb-icon { color: var(--rb-red); }

/* Collapsible groups */
.sb-group-toggle {
    display: flex; align-items: center; gap: 0.65rem;
    padding: 0.6rem 0.85rem; margin: 0 0.5rem;
    border-radius: 8px; color: #444;
    font-size: 0.875rem; font-weight: 500;
    cursor: pointer; user-select: none; min-height: 44px;
    border: none; background: transparent;
    width: calc(100% - 1rem); text-align: left;
    transition: background .15s, color .15s;
}
.sb-group-toggle:hover { background: #f5ede6; color: var(--rb-red); }
.sb-group-toggle:hover .sb-icon,
.sb-group-toggle.open .sb-icon { color: var(--rb-red); }
.sb-group-toggle.open { color: var(--rb-red); }
.sb-chevron { margin-left: auto; font-size: 0.7rem; color: #bbb; transition: transform .2s; }
.sb-group-toggle.open .sb-chevron { transform: rotate(90deg); }

.sb-children { display: none; padding-left: 0.75rem; }
.sb-children.open { display: block; }
.sb-children .sb-link { font-size: 0.84rem; font-weight: 400; min-height: 40px; }
.sb-children .sb-link .sb-icon { font-size: 0.75rem; }

.sb-divider { height: 1px; background: #f0ebe5; margin: 0.4rem 1rem; }

.sb-logout { margin-top: auto; padding: 0.75rem 1rem 0; border-top: 1px solid #f0ebe5; }
.sb-logout a {
    display: flex; align-items: center; gap: 0.65rem;
    padding: 0.6rem 0.85rem; border-radius: 8px;
    color: #888; text-decoration: none; font-size: 0.875rem;
    font-weight: 500; min-height: 44px; transition: background .15s, color .15s;
}
.sb-logout a:hover { background: #fff0f0; color: var(--rb-red); }

/* Scrollbar (sidebar) */
@media (min-width: 992px) {
    .rb-sidebar::-webkit-scrollbar { width: 4px; }
    .rb-sidebar::-webkit-scrollbar-thumb { background: #ddd; border-radius: 4px; }
}

/* ── MOBILE BOTTOM TAB BAR ───────────────────────────────────── */
.rb-bottom-nav { display: none; }
@media (max-width: 991px) {
    .rb-bottom-nav {
        display: flex; position: fixed;
        bottom: 0; left: 0; right: 0;
        height: var(--rb-bottom-h);
        background: #fff; border-top: 1px solid #e8e2db;
        z-index: 1020; box-shadow: 0 -2px 12px rgba(0,0,0,.08);
    }
    .rb-main-wrap { padding-bottom: calc(var(--rb-bottom-h) + 0.5rem) !important; }
}
.rb-tab {
    flex: 1; display: flex; flex-direction: column;
    align-items: center; justify-content: center; gap: 3px;
    text-decoration: none; color: #999;
    font-size: 0.6rem; font-weight: 600;
    text-transform: uppercase; letter-spacing: 0.3px;
    padding: 0 0.25rem;
    transition: color .15s; min-height: 44px;
    border: none; background: none; cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}
.rb-tab i { font-size: 1.2rem; transition: transform .15s; }
.rb-tab.active { color: var(--rb-red); }
.rb-tab.active i { transform: scale(1.1); }
.rb-tab:hover { color: var(--rb-red); }

/* ── MAIN CONTENT ────────────────────────────────────────────── */
.rb-main-wrap {
    margin-top: var(--rb-nav-h);
    padding: 1.25rem 0.875rem 1.5rem;
    min-height: calc(100vh - var(--rb-nav-h));
}
@media (min-width: 768px)  { .rb-main-wrap { padding: 1.5rem 1.5rem 2rem; } }
@media (min-width: 992px)  { .rb-main-wrap { padding: 1.75rem 2rem 2.5rem; } }

/* ── OFFLINE BANNER ──────────────────────────────────────────── */
#rb-offline-bar {
    display: none; position: fixed;
    bottom: 0; left: 0; right: 0;
    background: #1a1a1a; color: #fbbf24;
    text-align: center; font-size: 0.8rem; font-weight: 600;
    padding: 0.5rem; z-index: 2000; letter-spacing: 0.3px;
}
@media (max-width: 991px) {
    #rb-offline-bar { bottom: var(--rb-bottom-h); }
}

/* ── CARDS ───────────────────────────────────────────────────── */
.card {
    border: 1px solid #ede8e3;
    border-radius: var(--rb-radius);
    box-shadow: var(--rb-shadow);
    transition: box-shadow .2s;
}
.card-header {
    background: #fdfaf7;
    border-bottom: 1px solid #f0ebe5;
    font-weight: 600; font-size: 0.9rem;
}
.card:hover { box-shadow: var(--rb-shadow-md); }

/* Stat cards */
.stat-card {
    background: #fff; border-radius: var(--rb-radius);
    padding: 1rem 1.25rem;
    box-shadow: var(--rb-shadow); border: 1px solid #ede8e3;
    border-left: 4px solid transparent;
}
.stat-card.green  { border-left-color: #22c55e; }
.stat-card.blue   { border-left-color: #3b82f6; }
.stat-card.red    { border-left-color: var(--rb-red); }
.stat-card.gold   { border-left-color: var(--rb-gold); }
.stat-card.orange { border-left-color: #f97316; }
.stat-label { font-size: 0.7rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.5px; color: #999; }
.stat-value { font-size: 1.55rem; font-weight: 700; line-height: 1.1; margin-top: 0.2rem; }

/* Page headers */
.rb-page-header {
    display: flex; flex-wrap: wrap;
    align-items: flex-start; justify-content: space-between;
    gap: 0.75rem; margin-bottom: 1.25rem;
}
.rb-page-title { font-size: 1.25rem; font-weight: 700; color: #1a1a1a; margin: 0; line-height: 1.2; }
.rb-page-subtitle { font-size: 0.8rem; color: #888; margin: 0.15rem 0 0; }

/* ── ALERTS ──────────────────────────────────────────────────── */
.rb-alert {
    border-radius: var(--rb-radius); border-left: 4px solid;
    padding: 0.85rem 1rem; margin-bottom: 0.75rem; font-size: 0.875rem;
}
.rb-alert-success { background: #f0fdf4; border-color: #22c55e; color: #166534; }
.rb-alert-danger  { background: #fef2f2; border-color: var(--rb-red); color: #7f1d1d; }
.rb-alert-info    { background: #eff6ff; border-color: #3b82f6; color: #1e3a5f; }
.rb-alert-warning { background: #fffbeb; border-color: var(--rb-gold); color: #78350f; }

/* ── FORMS — fat touch targets ───────────────────────────────── */
.form-control, .form-select { min-height: 44px; border-radius: 8px; border-color: #ddd; font-size: 0.9rem; }
.form-control:focus, .form-select:focus { border-color: var(--rb-red); box-shadow: 0 0 0 3px rgba(139,0,0,.12); }
label.form-label { font-weight: 600; font-size: 0.85rem; color: #444; margin-bottom: 0.3rem; }
.btn { min-height: 42px; font-weight: 500; border-radius: 8px; }

/* ── TABLES ──────────────────────────────────────────────────── */
.table { font-size: 0.875rem; }
.table th { font-size: 0.7rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.4px; color: #888; }
.table tbody tr:hover td { background: #fdfaf7; }

/* ── BADGES ──────────────────────────────────────────────────── */
.rb-badge { display: inline-flex; align-items: center; gap: 0.25rem; padding: 0.2rem 0.55rem; border-radius: 20px; font-size: 0.72rem; font-weight: 600; }
.rb-badge-green  { background: #dcfce7; color: #166534; }
.rb-badge-red    { background: #fee2e2; color: #991b1b; }
.rb-badge-gold   { background: #fef9c3; color: #854d0e; }
.rb-badge-blue   { background: #dbeafe; color: #1e40af; }
.rb-badge-gray   { background: #f1f5f9; color: #475569; }

/* Legacy Bootstrap overrides (keeps old templates working) */
.border-left-primary  { border-left: 4px solid #3b82f6 !important; }
.border-left-success  { border-left: 4px solid #22c55e !important; }
.border-left-warning  { border-left: 4px solid var(--rb-gold) !important; }
.border-left-danger   { border-left: 4px solid var(--rb-red) !important; }
.border-left-info     { border-left: 4px solid #0ea5e9 !important; }
.font-weight-bold     { font-weight: 700 !important; }
.text-xs              { font-size: 0.72rem; }
.shadow               { box-shadow: var(--rb-shadow) !important; }

/* ── PRINT ───────────────────────────────────────────────────── */
@media print {
    .rb-topbar, .rb-sidebar, .rb-bottom-nav, #rb-offline-bar { display: none !important; }
    .rb-main-wrap { margin: 0 !important; padding: 0 !important; }
}

/* ── JS SIDEBAR LOGIC (inlined here so no extra request) ──────── */
/* (handled in base.html <script> block) */
