/* ============================================================
   KIJANI SACCO — Theme & Sidebar
   "Kijani" = Green (Swahili)
   ============================================================ */

/* --- CSS Variables ----------------------------------------- */
:root {
    --k-sidebar-width: 240px;
    --k-dark:     #112a1c;   /* very dark forest green — sidebar */
    --k-mid:      #1e5e36;   /* mid green — sidebar hover */
    --k-accent:   #2ecc71;   /* bright emerald — sidebar icons */
    --k-hover:    #27ae60;   /* hover green */
    --k-text:     #c8e6c9;   /* light green text on dark bg */
    --k-subtext:  #81c784;   /* dimmer subtext */
    --k-active-bg:#2d7a4e;   /* active item bg */
    --k-sub-bg:   #0d1f13;   /* submenu background */
    --k-body-bg:  #f3f4f6;   /* page background — neutral gray */
    --k-card-bg:  #ffffff;
    --k-border:   #e5e7eb;   /* neutral border — was green-tinted */
    --k-primary:  #1b6b3a;   /* primary action colour — buttons, links only */
    --k-primary-hover: #145530;
    --k-danger:   #e74c3c;
    --k-warning:  #f39c12;
    --k-info:     #0ea5e9;
    --k-shadow:   0 1px 4px rgba(0,0,0,.08);
    --k-shadow-md:0 4px 16px rgba(0,0,0,.10);
    --k-radius:   8px;
    --radius-sm:  4px;
    --radius-lg:  12px;

    /* Semantic text tokens — use these, NOT --k-primary, for text */
    --k-label:   #374151;    /* form labels, table headers */
    --k-muted:   #6b7280;    /* secondary text, timestamps, meta */
    --k-surface: #f9fafb;    /* table header background */

    /* Type scale — fluid, minimum 14px */
    --text-xs:   0.75rem;    /* 12px — captions, badges */
    --text-sm:   0.875rem;   /* 14px — table cells, labels */
    --text-base: 1rem;       /* 16px — body */
    --text-lg:   1.125rem;   /* 18px — card values, sub-headings */
    --text-xl:   1.375rem;   /* 22px — KPI values */
    --text-2xl:  1.75rem;    /* 28px — page headings */

    /* Spacing scale — 4px base */
    --space-1:  0.25rem;
    --space-2:  0.5rem;
    --space-3:  0.75rem;
    --space-4:  1rem;
    --space-6:  1.5rem;
    --space-8:  2rem;
    --space-12: 3rem;
    --space-16: 4rem;
}

/* --- Body --------------------------------------------------- */
body {
    margin-left: var(--k-sidebar-width) !important;
    background-color: var(--k-body-bg) !important;
    font-family: 'Inter', 'Segoe UI', system-ui, sans-serif;
    font-size: var(--text-base);
}

/* --- Sidebar ----------------------------------------------- */
#kijani-sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: var(--k-sidebar-width);
    height: 100vh;
    background: var(--k-dark);
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    overflow-x: hidden;
    z-index: 1050;
    transition: transform 0.3s ease;
    scrollbar-width: thin;
    scrollbar-color: var(--k-mid) var(--k-dark);
}
#kijani-sidebar::-webkit-scrollbar { width: 4px; }
#kijani-sidebar::-webkit-scrollbar-thumb { background: var(--k-mid); border-radius: 2px; }

/* Brand */
.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 18px 20px 14px;
    border-bottom: 1px solid rgba(255,255,255,.08);
    color: var(--k-accent);
    font-size: 1.15rem;
    font-weight: 700;
    letter-spacing: .5px;
    flex-shrink: 0;
}
.sidebar-brand i {
    font-size: 1.4rem;
    color: var(--k-accent);
}

/* User panel */
.sidebar-user {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 16px;
    margin: 10px 10px 4px;
    background: rgba(255,255,255,.06);
    border-radius: var(--k-radius);
    flex-shrink: 0;
}
.sidebar-user-avatar {
    width: 36px;
    height: 36px;
    background: var(--k-mid);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}
.sidebar-user-avatar i {
    color: var(--k-accent);
    font-size: 1rem;
}
.sidebar-user-info { min-width: 0; }
.sidebar-username {
    color: #fff;
    font-weight: 600;
    font-size: .85rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.sidebar-user-role {
    color: var(--k-subtext);
    font-size: .72rem;
}

/* Nav list */
.sidebar-nav {
    list-style: none;
    padding: 8px 0;
    margin: 0;
    flex: 1;
}
.sidebar-nav li { margin: 0; padding: 0; }

.sidebar-link {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 16px;
    color: var(--k-text) !important;
    font-size: .875rem;
    font-weight: 400;
    text-decoration: none !important;
    transition: background .18s, color .18s;
    border-radius: 0;
    margin: 1px 8px;
    border-radius: 6px;
    position: relative;
}
.sidebar-link:hover {
    background: var(--k-mid);
    color: #fff !important;
}
.sidebar-item.active > .sidebar-link {
    background: var(--k-active-bg);
    color: #fff !important;
    font-weight: 600;
}
.sidebar-item.active > .sidebar-link .fa-fw:first-child {
    color: var(--k-accent);
}

/* Arrow icon in collapsible items */
.sidebar-arrow {
    margin-left: auto !important;
    font-size: .75rem;
    transition: transform .25s;
}
.sidebar-toggle[aria-expanded="true"] .sidebar-arrow {
    transform: rotate(180deg);
}

/* Submenu */
.sidebar-submenu {
    list-style: none;
    padding: 2px 0 6px 0;
    margin: 0;
    background: var(--k-sub-bg);
    border-radius: 0 0 6px 6px;
}
.sidebar-submenu li a {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px 8px 36px;
    color: var(--k-subtext) !important;
    font-size: .82rem;
    text-decoration: none !important;
    transition: color .15s, background .15s;
    border-radius: 4px;
    margin: 1px 8px;
}
.sidebar-submenu li a:hover {
    color: #fff !important;
    background: rgba(255,255,255,.07);
}
.sidebar-submenu li a .fa-fw {
    font-size: .65rem;
    color: var(--k-subtext);
}

/* Footer / logout */
.sidebar-footer {
    padding: 12px 10px;
    border-top: 1px solid rgba(255,255,255,.08);
    flex-shrink: 0;
}
.sidebar-logout {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    color: #ef9a9a !important;
    font-size: .875rem;
    text-decoration: none !important;
    border-radius: 6px;
    transition: background .18s;
}
.sidebar-logout:hover {
    background: rgba(231,76,60,.15);
    color: #ff6b6b !important;
}

/* Mobile toggle button */
.sidebar-mobile-toggle {
    position: fixed;
    top: 12px;
    left: 12px;
    z-index: 1100;
    background: var(--k-primary);
    border: none;
    color: #fff;
    width: 40px;
    height: 40px;
    border-radius: var(--k-radius);
    font-size: 1rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}
.sidebar-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.45);
    z-index: 1040;
}

/* --- Hide old nav elements --------------------------------- */
#menu_header,
#menu_tabs {
    display: none !important;
}

/* Restyle the old secondary action bar */
#menu_main {
    background: var(--k-card-bg) !important;
    border-radius: var(--k-radius) !important;
    border: 1px solid var(--k-border) !important;
    box-shadow: var(--k-shadow) !important;
    margin-bottom: 1.5rem !important;
    padding: .5rem 1rem !important;
    height: auto !important;
    line-height: normal !important;
    display: flex;
    flex-wrap: wrap;
    gap: .5rem;
    align-items: center;
}
#menu_main a {
    color: var(--k-primary) !important;
    border: 1px solid var(--k-border) !important;
    border-radius: 5px !important;
    padding: .35rem .85rem !important;
    font-size: .82rem !important;
    font-weight: 500 !important;
    background: var(--k-body-bg) !important;
    transition: background .15s, color .15s !important;
    border-right: 1px solid var(--k-border) !important;
}
#menu_main a:hover {
    background: var(--k-primary) !important;
    color: #fff !important;
}
#menu_main #item_selected {
    background: var(--k-primary) !important;
    color: #fff !important;
    border-color: var(--k-primary) !important;
}

/* Selection bar */
#menu_selection {
    background: var(--k-border) !important;
    border-radius: var(--k-radius) !important;
    border: 1px solid var(--k-border) !important;
    margin-bottom: 1.5rem !important;
    padding: .5rem 1rem !important;
    height: auto !important;
    margin-top: 0 !important;
}

/* --- Detail page layout (2-column staff pages) ------------ */
.detail-layout {
    display: grid;
    grid-template-columns: 3fr 2fr;
    gap: var(--space-6);
    align-items: start;
}
.detail-layout--form {
    display: grid;
    grid-template-columns: 2fr 3fr;
    gap: var(--space-6);
    align-items: start;
}
@media (max-width: 900px) {
    .detail-layout,
    .detail-layout--form { grid-template-columns: 1fr; }
}

/* --- Content areas ----------------------------------------- */
.content_center {
    width: 90% !important;
    max-width: 1200px !important;
    margin: 1.5rem auto !important;
    text-align: left !important;
}
.content_left {
    float: left;
}
.content_right {
    float: right;
    border-left: 1px solid var(--k-border) !important;
}
.content_settings {
    background: var(--k-card-bg);
    border-radius: var(--k-radius);
    padding: 1.5rem;
    box-shadow: var(--k-shadow);
    border: 1px solid var(--k-border);
}

/* --- Tables ------------------------------------------------ */
#tb_table,
table#tb_table,
.kijani-table {
    border-radius: var(--k-radius);
    overflow: hidden;
    border-collapse: collapse !important;
    width: 100% !important;
    margin-bottom: 1rem;
    background: var(--k-card-bg);
    box-shadow: var(--k-shadow);
}
#tb_table th.title,
table th.title,
.kijani-table th.title {
    background: var(--k-surface) !important;      /* was: dark green banner */
    color: var(--k-label) !important;             /* was: white */
    padding: .75rem 1rem !important;
    font-size: var(--text-base) !important;
    font-weight: 700;
    text-align: left;
    border-bottom: 2px solid var(--k-border) !important;
    letter-spacing: 0;
}
#tb_table th,
.kijani-table th {
    background: var(--k-surface) !important;      /* was: green-tinted #f0f7f2 */
    color: var(--k-label) !important;             /* was: --k-primary green */
    padding: .6rem .9rem !important;
    font-size: var(--text-sm) !important;         /* was: .8rem */
    font-weight: 600;
    border-bottom: 2px solid var(--k-border) !important;
    text-transform: none;                          /* DROP all-caps */
    letter-spacing: 0;
}
#tb_table td,
.kijani-table td {
    padding: .55rem .9rem !important;
    border-bottom: 1px solid var(--k-border) !important;
    font-size: var(--text-sm) !important;          /* was: .85rem */
    color: #111827;
}
#tb_table tr:last-child td,
.kijani-table tr:last-child td {
    border-bottom: none !important;
}
#tb_table tr:hover td,
.kijani-table tr:hover td {
    background: #f9fafb !important;               /* was: green-tinted #f0faf3 */
}
/* Delete / action icon in tables */
#tb_table td a[href*="del"],
#tb_table .btn-table-delete {
    color: var(--k-danger) !important;
}

/* --- Forms ------------------------------------------------- */
input[type=text],
input[type=number],
input[type=password],
select,
textarea {
    border: 1px solid var(--k-border) !important;
    border-radius: 5px !important;
    padding: .45rem .75rem !important;
    font-size: .875rem !important;
    color: #333 !important;
    background: #fff !important;
    transition: border-color .2s, box-shadow .2s !important;
    height: auto !important;
}
input[type=text]:focus,
input[type=number]:focus,
input[type=password]:focus,
select:focus,
textarea:focus {
    border-color: var(--k-primary) !important;
    box-shadow: 0 0 0 3px rgba(27,107,58,.12) !important;
    outline: none !important;
}
input[type=submit],
input[type=button] {
    background: var(--k-primary) !important;
    border: none !important;
    color: #fff !important;
    border-radius: 6px !important;
    padding: .5rem 1.2rem !important;
    font-size: .875rem !important;
    font-weight: 500 !important;
    cursor: pointer !important;
    transition: background .2s !important;
}
input[type=submit]:hover,
input[type=button]:hover {
    background: var(--k-primary-hover) !important;
}

/* --- Alerts / Messages ------------------------------------- */
.alert-success { border-left: 4px solid #2ecc71 !important; }
.alert-warning { border-left: 4px solid var(--k-warning) !important; }
.alert-danger  { border-left: 4px solid var(--k-danger)  !important; }

/* --- Form groups (label-above-input pattern) -------------- */
.form-group {
    display: flex;
    flex-direction: column;
    gap: .3rem;
    margin-bottom: 1rem;
}
.form-label {
    font-size: var(--text-sm);
    font-weight: 500;
    color: var(--k-label);
}
.form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem 1.5rem;
}
.form-grid--3 {
    grid-template-columns: 1fr 1fr 1fr;
}
.form-grid .span-2 {
    grid-column: span 2;
}
@media (max-width: 640px) {
    .form-grid,
    .form-grid--3 { grid-template-columns: 1fr; }
    .form-grid .span-2 { grid-column: span 1; }
}

/* --- Member header (customer profile) --------------------- */
.member-header {
    background: white;
    border: 1px solid var(--k-border);
    border-radius: var(--k-radius);
    padding: 1.5rem;
    display: flex;
    align-items: center;
    gap: 1.5rem;
    margin-bottom: 1.5rem;
    box-shadow: var(--k-shadow);
}
.member-avatar {
    width: 72px;
    height: 72px;
    border-radius: 50%;
    object-fit: cover;
    flex-shrink: 0;
    border: 3px solid var(--k-border);
    background: var(--k-surface);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2rem;
    color: var(--k-muted);
    overflow: hidden;
}
.member-avatar img { width: 100%; height: 100%; object-fit: cover; }
.member-info { flex: 1; min-width: 0; }
.member-name {
    font-size: var(--text-2xl);
    font-weight: 700;
    color: #111827;
    line-height: 1.2;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.member-meta {
    font-size: var(--text-sm);
    color: var(--k-muted);
    margin-top: .25rem;
    display: flex;
    gap: 1rem;
    align-items: center;
    flex-wrap: wrap;
}
.member-status-badge {
    display: inline-flex;
    align-items: center;
    gap: .3rem;
    padding: .2rem .6rem;
    border-radius: 99px;
    font-size: var(--text-xs);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .4px;
}
.member-status-badge.active   { background: #dcfce7; color: #166534; }
.member-status-badge.inactive { background: #fee2e2; color: #991b1b; }
.member-actions-group {
    display: flex;
    gap: .5rem;
    flex-shrink: 0;
    flex-wrap: wrap;
}

/* --- Section card (wraps form + table sections) ----------- */
.section-card {
    background: white;
    border: 1px solid var(--k-border);
    border-radius: var(--k-radius);
    box-shadow: var(--k-shadow);
    margin-bottom: 1.5rem;
    overflow: hidden;
}
.section-card__header {
    padding: .85rem 1.25rem;
    border-bottom: 1px solid var(--k-border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--k-surface);
}
.section-card__title {
    font-size: var(--text-base);
    font-weight: 700;
    color: var(--k-label);
    margin: 0;
}
.section-card__body {
    padding: 1.25rem;
}
.section-card__body--table {
    padding: 0;
}

/* --- Page heading ----------------------------------------- */
p.heading, h1.heading, h2.heading, .page-heading {
    font-size: var(--text-xl) !important;
    font-weight: 700 !important;
    color: #111827 !important;           /* was: --k-primary green */
    margin-bottom: 1rem !important;
}

/* --- Page headings ----------------------------------------- */
.content_center h1,
.content_center h2,
body > h1,
body > h2 {
    color: #111827;               /* was: --k-primary green */
    font-weight: 700;
    margin-bottom: 1rem;
}

/* --- Chart widget (dashboard) ----------------------------- */
.chart-widget {
    background: white;
    border: 1px solid var(--k-border);
    border-radius: var(--k-radius);
    box-shadow: var(--k-shadow);
    padding: 1.25rem 1.5rem;
    margin-bottom: 1.5rem;
}
.chart-widget__title {
    font-size: var(--text-sm);
    font-weight: 600;
    color: var(--k-label);
    margin-bottom: .75rem;
    text-transform: uppercase;
    letter-spacing: .4px;
}
.chart-bar-wrap {
    margin-bottom: 1.25rem;
}
.chart-bar-wrap:last-child { margin-bottom: 0; }
.chart-bar-label {
    display: flex;
    justify-content: space-between;
    font-size: var(--text-xs);
    color: var(--k-muted);
    margin-bottom: .35rem;
}
.chart-bar-track {
    height: 28px;
    background: var(--k-surface);
    border-radius: 6px;
    overflow: hidden;
    display: flex;
}
.chart-bar-fill {
    height: 100%;
    display: flex;
    align-items: center;
    padding: 0 .6rem;
    font-size: var(--text-xs);
    font-weight: 600;
    color: white;
    white-space: nowrap;
    overflow: hidden;
    transition: width .4s ease;
}
.chart-bar-fill--primary  { background: var(--k-primary); }
.chart-bar-fill--warning  { background: var(--k-warning); }
.chart-bar-fill--info     { background: var(--k-info); }
.chart-bar-fill--danger   { background: var(--k-danger); }
.chart-bar-fill--muted    { background: #9ca3af; }

/* --- KPI Cards (dashboard) --------------------------------- */
.kpi-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: var(--space-4);
    margin-bottom: var(--space-6);
}
.kpi-card {
    background: white;
    border: 1px solid var(--k-border);
    border-top: 3px solid transparent;      /* accent on top, not left */
    border-radius: var(--k-radius);
    box-shadow: var(--k-shadow);
    padding: 1.25rem 1.5rem;
    display: flex;
    align-items: center;
    gap: 1rem;
    transition: box-shadow .2s, transform .15s;
}
.kpi-card:hover {
    box-shadow: var(--k-shadow-md);
    transform: translateY(-1px);
}
/* top-border accent per category */
.kpi-card--members { border-top-color: var(--k-primary); }
.kpi-card--savings { border-top-color: var(--k-info); }
.kpi-card--loans   { border-top-color: var(--k-warning); }
.kpi-card--alert,
.kpi-card--overdue { border-top-color: var(--k-danger); }

/* icon: simpler — no background box */
.kpi-icon {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    background: var(--k-surface);
}
.kpi-icon i { font-size: 1.2rem; color: var(--k-muted); }
.kpi-card--members .kpi-icon i  { color: var(--k-primary); }
.kpi-card--savings .kpi-icon i  { color: var(--k-info); }
.kpi-card--loans .kpi-icon i    { color: var(--k-warning); }
.kpi-card--overdue .kpi-icon i  { color: var(--k-danger); }

/* legacy color variants kept for compatibility */
.kpi-icon--savings { background: rgba(14,165,233,.08); }
.kpi-icon--savings i { color: var(--k-info); }
.kpi-icon--loans { background: rgba(243,156,18,.08); }
.kpi-icon--loans i { color: var(--k-warning); }
.kpi-icon--overdue { background: rgba(231,76,60,.08); }
.kpi-icon--overdue i { color: var(--k-danger); }

.kpi-body { min-width: 0; }
.kpi-value {
    font-size: var(--text-xl);
    font-weight: 700;
    color: #111827;
    line-height: 1.2;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.kpi-label {
    font-size: var(--text-sm);
    color: var(--k-muted);
    margin-top: 3px;
    font-weight: 400;
}
@media (max-width: 900px) {
    .kpi-grid { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 480px) {
    .kpi-grid { grid-template-columns: 1fr; }
}

/* months.php specific adjustments */
.dashboard-header {
    border-left: 5px solid var(--k-accent) !important;
}
.btn-primary {
    background-color: var(--k-primary) !important;
    border-color: var(--k-primary) !important;
}
.btn-primary:hover {
    background-color: var(--k-primary-hover) !important;
    border-color: var(--k-primary-hover) !important;
}

/* --- Mobile --------------------------------------------- */
@media (max-width: 767px) {
    body {
        margin-left: 0 !important;
        padding-top: 56px;
    }
    #kijani-sidebar {
        transform: translateX(-100%);
    }
    #kijani-sidebar.sidebar-open {
        transform: translateX(0);
    }
}

/* --- Print: hide sidebar ----------------------------------- */
@media print {
    #kijani-sidebar,
    .sidebar-mobile-toggle,
    .sidebar-backdrop { display: none !important; }
    body { margin-left: 0 !important; }
}
