:root {
    --brand: #1f5132;
    --brand-dark: #163b24;
    --brand-light: #e8f1eb;
    --sidebar-width: 250px;
    --bs-primary: #1f6f43;
    --bs-primary-rgb: 31, 111, 67;
    --bs-link-color: #1f6f43;
    --bs-link-color-rgb: 31, 111, 67;
    --bs-link-hover-color: #163b24;
}

body {
    background: #f3f5f4;
    font-size: 0.95rem;
    color: #212529;
}

.btn-primary {
    --bs-btn-bg: #1f6f43;
    --bs-btn-border-color: #1f6f43;
    --bs-btn-hover-bg: #185836;
    --bs-btn-hover-border-color: #185836;
    --bs-btn-active-bg: #134a2d;
    --bs-btn-active-border-color: #134a2d;
    --bs-btn-disabled-bg: #1f6f43;
    --bs-btn-disabled-border-color: #1f6f43;
}
.btn-outline-primary {
    --bs-btn-color: #1f6f43;
    --bs-btn-border-color: #1f6f43;
    --bs-btn-hover-bg: #1f6f43;
    --bs-btn-hover-border-color: #1f6f43;
    --bs-btn-active-bg: #185836;
}
.text-primary { color: #1f6f43 !important; }
.bg-primary { background-color: #1f6f43 !important; }
.page-link { color: #1f6f43; }
.nav-pills { --bs-nav-pills-link-active-bg: #1f6f43; --bs-nav-link-color: #1f6f43; --bs-nav-link-hover-color: #163b24; }
.nav-tabs { --bs-nav-link-color: #1f6f43; --bs-nav-link-hover-color: #163b24; }
.active > .page-link, .page-link.active { background-color: #1f6f43; border-color: #1f6f43; }
.form-control:focus, .form-select:focus { border-color: #6aa884; box-shadow: 0 0 0 .2rem rgba(31, 111, 67, .2); }

/* ---- Layout ---- */
.app-shell { display: flex; min-height: 100vh; }

.sidebar,
.sidebar.offcanvas-lg {
    --bs-offcanvas-bg: var(--brand);
    --bs-offcanvas-color: #fff;
    width: var(--sidebar-width);
    /* Bootstrap's .offcanvas-lg forces a transparent background on large screens */
    background-color: var(--brand) !important;
    color: #fff;
    display: flex;
    flex-direction: column;
}
@media (min-width: 992px) {
    .sidebar {
        position: fixed;
        inset: 0 auto 0 0;
        overflow-y: auto;
        z-index: 1030;
    }
    .main { margin-left: var(--sidebar-width); }
}
@media (max-width: 991.98px) {
    .sidebar.offcanvas-lg { --bs-offcanvas-width: 270px; }
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: .75rem;
    padding: 1.1rem 1rem;
    border-bottom: 1px solid rgba(255, 255, 255, .12);
}
.sidebar-brand > i { font-size: 1.8rem; color: #b9e4c9; }
.sidebar-brand small { display: block; font-size: .72rem; opacity: .75; line-height: 1.2; }

.sidebar-nav { padding: .5rem .6rem; flex: 1; overflow-y: auto; }
.sidebar-nav .nav-section {
    font-size: .7rem;
    text-transform: uppercase;
    letter-spacing: .06em;
    opacity: .6;
    padding: .9rem .6rem .3rem;
}
.sidebar-nav .nav-link {
    display: flex;
    align-items: center;
    gap: .7rem;
    color: rgba(255, 255, 255, .85);
    padding: .55rem .7rem;
    border-radius: .4rem;
    margin-bottom: 2px;
}
.sidebar-nav .nav-link i { font-size: 1.1rem; width: 1.25rem; text-align: center; }
.sidebar-nav .nav-link:hover { background: rgba(255, 255, 255, .1); color: #fff; }
.sidebar-nav .nav-link.active { background: #fff; color: var(--brand); font-weight: 600; }

.sidebar-footer {
    display: flex;
    gap: .6rem;
    align-items: center;
    padding: .8rem 1rem;
    border-top: 1px solid rgba(255, 255, 255, .12);
    font-size: .85rem;
}
.sidebar-footer > i { font-size: 1.4rem; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
    display: flex;
    align-items: center;
    background: #fff;
    border-bottom: 1px solid #e3e7e5;
    padding: .6rem 1.25rem;
    position: sticky;
    top: 0;
    z-index: 1020;
}
.topbar-title { font-weight: 600; font-size: 1.1rem; color: var(--brand); }

.content { padding: 1.25rem; }
@media (max-width: 575.98px) { .content { padding: .85rem; } }

/* ---- Components ---- */
.page-head {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: .75rem;
    margin-bottom: 1rem;
}
.page-head h1 { font-size: 1.35rem; margin: 0; font-weight: 600; }
.page-head .subtitle { color: #6c757d; font-size: .9rem; }
.page-head .actions { margin-left: auto; display: flex; flex-wrap: wrap; gap: .5rem; }

.card { border: 1px solid #e3e7e5; box-shadow: 0 1px 2px rgba(0, 0, 0, .03); }
.card-header { background: #fff; font-weight: 600; }

.stat-card {
    display: flex;
    align-items: center;
    gap: .9rem;
    padding: 1rem;
    height: 100%;
    color: inherit;
    text-decoration: none;
    background: #fff;
    border: 1px solid #e3e7e5;
    border-radius: .5rem;
    transition: box-shadow .15s, transform .15s;
}
a.stat-card:hover { box-shadow: 0 4px 12px rgba(0, 0, 0, .08); transform: translateY(-1px); color: inherit; }
.stat-card .stat-icon {
    width: 48px; height: 48px;
    flex-shrink: 0;
    display: grid; place-items: center;
    border-radius: .6rem;
    font-size: 1.4rem;
}
.stat-card .stat-value { font-size: 1.6rem; font-weight: 700; line-height: 1.1; }
.stat-card .stat-label { color: #6c757d; font-size: .85rem; }

.kpi-delta { font-size: .8rem; color: #52514e; margin-top: .15rem; }
.kpi-delta i { font-size: .8rem; }
.section-title { font-size: .8rem; text-transform: uppercase; letter-spacing: .05em; color: #6c757d; font-weight: 600; margin: 1.25rem 0 .6rem; }
.chart-box { position: relative; width: 100%; }
.chart-table summary { cursor: pointer; }
.period-filter .btn { min-width: 5.5rem; }

.action-tile {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: .35rem;
    padding: 1rem .5rem;
    background: #fff;
    border: 1px solid #e3e7e5;
    border-radius: .5rem;
    text-decoration: none;
    color: var(--brand);
    font-weight: 600;
    text-align: center;
    height: 100%;
}
.action-tile i { font-size: 1.8rem; }
.action-tile:hover { background: var(--brand-light); color: var(--brand-dark); }

.table > :not(caption) > * > * { padding: .6rem .75rem; }
.table thead th {
    background: #f6f8f7;
    font-size: .8rem;
    text-transform: uppercase;
    letter-spacing: .03em;
    color: #4b5a52;
    white-space: nowrap;
}
.table .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.table tfoot td { font-weight: 700; background: #f6f8f7; }
.table-clickable tbody tr[data-href] { cursor: pointer; }
.table-clickable tbody tr[data-href]:hover { background: var(--brand-light); }

.empty-state { text-align: center; padding: 2.5rem 1rem; color: #6c757d; }
.empty-state i { font-size: 2.6rem; opacity: .5; display: block; margin-bottom: .5rem; }

.available-box {
    background: var(--brand-light);
    border: 1px dashed #8fbf9f;
    border-radius: .5rem;
    padding: .6rem .9rem;
    font-size: .95rem;
}
.available-box.is-low { background: #fff4e5; border-color: #f0ad4e; }

.filter-bar { background: #fff; border: 1px solid #e3e7e5; border-radius: .5rem; padding: .85rem; margin-bottom: 1rem; }
.filter-bar .form-label { font-size: .8rem; margin-bottom: .2rem; color: #4b5a52; }

.form-label .req { color: #dc3545; }

.btn-loading .spinner-border { width: 1rem; height: 1rem; border-width: .15em; }

.login-page { min-height: 100vh; display: grid; place-items: center; background: linear-gradient(135deg, #1f5132, #2e7d4f); padding: 1rem; }
.login-card { width: 100%; max-width: 420px; }

/* ---- Searchable selects (Tom Select) ---- */
.ts-dropdown { z-index: 1060; }
.ts-dropdown .active { background-color: var(--brand-light); color: var(--brand-dark); }
.ts-dropdown .option .highlight { background: #ffe58a; border-radius: 2px; }
.ts-wrapper.single .ts-control { min-height: 38px; }
[data-quick-add] + .ts-wrapper .ts-control { border-color: #6aa884; background: #fff; }
.ts-dropdown .option { white-space: normal; line-height: 1.35; }
.ts-dropdown .dropdown-input-wrap { padding: .35rem; }
.ts-wrapper.single .ts-control { cursor: pointer; }
.ts-wrapper.single.input-hidden .ts-control > .item { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: calc(100% - 1.5rem); }
.ts-wrapper.disabled .ts-control { background-color: var(--bs-secondary-bg); opacity: 1; }
.input-group > .ts-wrapper { flex: 1 1 auto; width: 1%; min-width: 0; }
.input-group > .ts-wrapper:not(:last-child) .ts-control { border-top-right-radius: 0; border-bottom-right-radius: 0; }
.filter-bar .ts-wrapper.single .ts-control { min-height: 38px; }

/* ===================== Modern cards (whole app) ===================== */
.card { border: 1px solid #e4e9e6; border-radius: 14px; box-shadow: 0 1px 2px rgba(16, 24, 40, .04), 0 1px 3px rgba(16, 24, 40, .05); }
.card > .card-header:first-child { border-radius: 14px 14px 0 0; }
.card-header { background: transparent; border-bottom: 1px solid #edf1ef; padding: .85rem 1.1rem; font-weight: 600; color: #1d2b24; }
.card-header .bi { color: var(--brand); }
.card-footer:last-child { border-radius: 0 0 14px 14px; }
.stat-card { border-radius: 14px; border-color: #e4e9e6; box-shadow: 0 1px 2px rgba(16, 24, 40, .04); }

/* ===================== Directorate dashboard ===================== */
.dash-hero {
    position: relative; overflow: hidden;
    display: flex; flex-wrap: wrap; gap: 1.5rem; align-items: stretch; justify-content: space-between;
    margin-bottom: 1.5rem; padding: 1.75rem 1.75rem 1.5rem;
    border-radius: 18px; color: #fff;
    background: radial-gradient(circle at 85% -20%, rgba(255, 255, 255, .16) 0, rgba(255, 255, 255, 0) 45%),
                radial-gradient(circle at 0% 120%, rgba(185, 228, 201, .22) 0, rgba(185, 228, 201, 0) 40%),
                linear-gradient(135deg, #163b24 0%, #1f5132 45%, #2e7d4f 100%);
    box-shadow: 0 10px 30px -12px rgba(22, 59, 36, .55);
}
.dash-hero-main { flex: 1 1 420px; min-width: 0; }
.dash-eyebrow { font-size: .78rem; letter-spacing: .08em; text-transform: uppercase; opacity: .8; font-weight: 600; }
.dash-eyebrow .bi { margin-right: .3rem; }
.dash-title { font-size: 1.75rem; font-weight: 700; margin: .35rem 0 .25rem; letter-spacing: -.01em; }
.dash-sub { margin: 0 0 1.1rem; opacity: .9; }
.dash-actions { display: flex; flex-wrap: wrap; gap: .5rem; }
.dash-action {
    display: inline-flex; align-items: center; gap: .45rem; padding: .5rem .9rem;
    border-radius: 10px; color: #fff; text-decoration: none; font-weight: 500; font-size: .9rem;
    background: rgba(255, 255, 255, .12); border: 1px solid rgba(255, 255, 255, .22);
    transition: background .15s, transform .15s;
}
.dash-action:hover { background: rgba(255, 255, 255, .22); color: #fff; transform: translateY(-1px); }
.dash-action:first-child { background: #fff; color: var(--brand); border-color: #fff; }
.dash-action:first-child:hover { background: #eef7f1; color: var(--brand-dark); }
.dash-hero-side { display: flex; flex-direction: column; justify-content: space-between; align-items: flex-end; gap: 1rem; flex: 0 1 auto; }
.dash-period { display: inline-flex; flex-wrap: wrap; padding: 4px; border-radius: 12px; background: rgba(0, 0, 0, .18); }
.dash-period a { padding: .35rem .8rem; border-radius: 9px; color: rgba(255, 255, 255, .85); text-decoration: none; font-size: .85rem; font-weight: 500; }
.dash-period a:hover { color: #fff; background: rgba(255, 255, 255, .1); }
.dash-period a.active { background: #fff; color: var(--brand); box-shadow: 0 1px 3px rgba(0, 0, 0, .2); }
.dash-hero-stat { text-align: right; }
.dash-hero-stat-label { font-size: .85rem; opacity: .85; }
.dash-hero-stat-value { font-size: 2.6rem; font-weight: 700; line-height: 1.05; letter-spacing: -.02em; }
.dash-hero-stat-note { font-size: .82rem; opacity: .8; }
@media (max-width: 767.98px) {
    .dash-hero { padding: 1.25rem; }
    .dash-hero-side { align-items: flex-start; }
    .dash-hero-stat { text-align: left; }
    .dash-title { font-size: 1.4rem; }
}

.dash-kpi {
    position: relative; display: flex; flex-direction: column; height: 100%; padding: 1.1rem 1.15rem .4rem;
    background: #fff; border: 1px solid #e4e9e6; border-radius: 14px; color: inherit; text-decoration: none; overflow: hidden;
    box-shadow: 0 1px 2px rgba(16, 24, 40, .04), 0 1px 3px rgba(16, 24, 40, .05);
    transition: box-shadow .15s, transform .15s;
}
a.dash-kpi:hover { color: inherit; transform: translateY(-2px); box-shadow: 0 10px 24px -10px rgba(16, 24, 40, .22); }
.dash-kpi-top { display: flex; align-items: center; gap: .6rem; }
.dash-kpi-icon, .dash-glance-icon {
    width: 38px; height: 38px; flex-shrink: 0; display: grid; place-items: center; border-radius: 11px; font-size: 1.1rem;
}
.dash-kpi-label { font-size: .86rem; color: #5b6b62; font-weight: 500; }
.dash-kpi-value { font-size: 1.9rem; font-weight: 700; letter-spacing: -.02em; margin: .55rem 0 .15rem; color: #111b16; }
.dash-kpi-value small { font-size: .9rem; font-weight: 500; color: #6c757d; }
.dash-kpi-foot { display: flex; align-items: center; flex-wrap: wrap; gap: .4rem; min-height: 22px; margin-bottom: .45rem; }
.dash-kpi-note { font-size: .78rem; color: #7a8780; }
.dash-delta { display: inline-flex; align-items: center; gap: .15rem; padding: .1rem .45rem; border-radius: 999px; font-size: .75rem; font-weight: 600; background: #f1f3f2; color: #52514e; }
.dash-delta.up { background: #e7f5ec; color: #006300; }
.dash-delta.down { background: #fdecec; color: #b02a2a; }
.dash-spark { display: block; width: calc(100% + 2.3rem); height: 34px; margin: auto -1.15rem 0; }

.tone-blue { background: #e8f1fc; color: #1c5cab; }
.tone-orange { background: #fdeee6; color: #b84a1d; }
.tone-green { background: #e6f3eb; color: #1f6f43; }
.tone-teal { background: #e3f5ef; color: #137a55; }
.tone-amber { background: #fff4dc; color: #9a6400; }

.dash-panel .card-header { display: flex; align-items: center; }
.dash-glance { padding: .35rem .5rem; }
.dash-glance-row { display: flex; align-items: center; gap: .75rem; padding: .55rem .6rem; border-radius: 10px; color: inherit; text-decoration: none; }
.dash-glance-row:hover { background: #f4f8f6; color: inherit; }
.dash-glance-row span:nth-child(2) { flex: 1; color: #3c4a43; }
.dash-glance-row strong { font-size: 1.05rem; }
.dash-expiry { margin: .25rem 1.1rem 1.1rem; padding: .85rem; border-radius: 12px; background: #f7f9f8; border: 1px solid #edf1ef; }
.dash-expiry-ok { font-size: .85rem; color: #1f6f43; }
.dash-expiry-bar { display: flex; gap: 2px; height: 10px; border-radius: 999px; overflow: hidden; background: #e9ecea; }
.dash-expiry-bar .seg { display: block; min-width: 6px; }
.seg-expired { background: #d03b3b; }
.seg-30 { background: #ec835a; }
.seg-60 { background: #fab219; }
.seg-90 { background: #86b6ef; }
.dash-expiry-legend { display: grid; grid-template-columns: 1fr 1fr; gap: .35rem .75rem; margin-top: .65rem; }
.dash-expiry-legend a { display: flex; align-items: center; gap: .4rem; font-size: .8rem; color: #3c4a43; text-decoration: none; }
.dash-expiry-legend a strong { margin-left: auto; }
.dash-expiry-legend a.muted { opacity: .55; }
.dash-expiry-legend .dot { width: 9px; height: 9px; border-radius: 3px; display: inline-block; }

.dash-table thead th { background: #f7f9f8; border-bottom: 1px solid #edf1ef; font-size: .74rem; }
.dash-table td { border-color: #f0f3f1; }
.dash-avatar { width: 32px; height: 32px; border-radius: 10px; display: grid; place-items: center; font-weight: 700; font-size: .85rem; background: var(--brand-light); color: var(--brand); flex-shrink: 0; }
.dash-progress { height: 8px; border-radius: 999px; background: #edf1ef; overflow: hidden; }
.dash-progress span { display: block; height: 100%; border-radius: 999px; background: linear-gradient(90deg, #2e7d4f, #1baf7a); }

.dash-feed { padding: .35rem .5rem; }
.dash-feed-row { display: flex; align-items: center; gap: .8rem; padding: .65rem .6rem; border-radius: 10px; color: inherit; text-decoration: none; }
.dash-feed-row + .dash-feed-row { border-top: 1px solid #f0f3f1; }
.dash-feed-row:hover { background: #f4f8f6; color: inherit; }
.dash-chip { font-size: .7rem; padding: .1rem .5rem; border-radius: 999px; background: #f1f3f2; color: #52514e; font-weight: 500; }

/* ---- Uploaded logo ---- */
.sidebar-logo { width: 54px; height: 54px; margin: -4px 0; object-fit: contain; flex-shrink: 0; }
.login-logo { width: 180px; height: 180px; margin-bottom: -8px; object-fit: contain; filter: drop-shadow(0 6px 14px rgba(0, 0, 0, .25)); }
.logo-preview { width: 112px; height: 112px; border-radius: 16px; border: 1px dashed #b9cfc2; background: #f7f9f8; display: grid; place-items: center; flex-shrink: 0; }
.logo-preview img { max-width: 96px; max-height: 96px; object-fit: contain; }
.logo-preview .bi { font-size: 2.6rem; color: var(--brand); }
