: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; }
.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; }
