:root {
    --adm-tab-accent: var(--ap-green);
    --ap-green: #1d5b46;
    --ap-green-dark: #164735;
    --ap-soft: #eff6f0;
    --ap-gold: #d9b46e;
}
body { font-family: "Nunito", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; }

/* Keep the SB Admin structure and sizing; only adapt the brand color. */
.bg-gradient-primary {
    background-color: var(--ap-green);
    background-image: linear-gradient(180deg, var(--ap-green) 10%, var(--ap-green-dark) 100%);
    background-size: cover;
}
a, .text-primary { color: var(--ap-green); }
a:hover { color: var(--ap-green-dark); }
.text-primary { color: var(--ap-green) !important; }
.border-left-primary { border-left-color: var(--ap-green) !important; }
.btn-primary, .btn-outline-primary,
.btn-project-standard.btn-primary, .btn-project-standard.btn-outline-primary {
    color: var(--ap-green);
    border-color: var(--ap-green);
}
.btn-primary { color: #fff; background-color: var(--ap-green); }
.btn-project-standard.btn-primary { color: var(--ap-green); background-color: transparent; }
.btn-primary:hover, .btn-primary:focus, .btn-outline-primary:hover, .btn-outline-primary:focus,
.btn-project-standard.btn-primary:hover, .btn-project-standard.btn-primary:focus,
.btn-project-standard.btn-outline-primary:hover, .btn-project-standard.btn-outline-primary:focus {
    color: #fff;
    background-color: var(--ap-green-dark);
    border-color: var(--ap-green-dark);
}
.btn-primary:not(:disabled):not(.disabled):active,
.btn-outline-primary:not(:disabled):not(.disabled):active {
    background-color: var(--ap-green-dark);
    border-color: var(--ap-green-dark);
}
.pagination .page-item.active .page-link { background: var(--ap-green); border-color: var(--ap-green); }
.page-link { color: var(--ap-green); }
.form-control:focus { border-color: #85ab9b; box-shadow: 0 0 0 .2rem rgba(29, 91, 70, .15); }
.bootstrap-datetimepicker-widget td.active,
.bootstrap-datetimepicker-widget td.active:hover,
.bootstrap-datetimepicker-widget td span.active {
    background: var(--ap-green) !important;
    border-color: var(--ap-green) !important;
    text-shadow: none;
}
/* These headers use pb-0; Bootstrap's negative margin would overlap the body. */
#main-content .card-header-tabs {
    margin-bottom: 0;
    border-bottom: 0;
}
/* Access navigation links open other pages and keep their grouped container. */
#main-content .admin-user-access-tabs {
    gap: .3rem;
    padding: .4rem;
    background: #f8f9fc;
    border: 1px solid var(--admin-user-border);
    border-radius: .55rem;
}
#main-content .admin-user-access-tabs > .nav-item > .nav-link {
    border-radius: .4rem;
}
body.admin-user-module {
    --admin-user-primary: var(--ap-green);
    --admin-user-primary-soft: var(--ap-soft);
}

#accordionSidebar { flex-shrink: 0; }
.sidebar-brand-icon { flex-shrink: 0; }
.sidebar .sidebar-brand { letter-spacing: 0; text-transform: none; }
.sidebar .sidebar-brand-text { font-size: .9rem; line-height: 1.25; }
.sidebar .sidebar-brand-text small { font-size: .6rem; font-weight: 400; margin-top: .25rem; }
.sidebar .nav-item .nav-link i { width: 1.25rem; }
.sidebar .nav-item.active .nav-link { background: rgba(255, 255, 255, .08); }
.sidebar #sidebarToggle::after { display: none; }
.sidebar #sidebarToggle { color: rgba(255, 255, 255, .65); }
.sidebar.toggled #sidebarToggle i { transform: rotate(180deg); }
.topbar-page-heading { min-width: 0; max-width: none; margin-right: auto; }
.topbar-page-heading-accent { background: var(--ap-green); }
.topbar .navbar-nav { flex-shrink: 0; }
.topbar .img-profile { width: 2rem; height: 2rem; flex-shrink: 0; }
.topbar .dropdown-item { white-space: normal; }
h1, h2, h3, .card-header { overflow-wrap: anywhere; }

/* Flexible list ancestors must be allowed to shrink without clipping content. */
#wrapper, #content-wrapper, #content, #main-content,
.tab-content, .tab-pane, .card, .card-body, .dataTables_wrapper {
    min-width: 0;
}
#wrapper #content-wrapper { width: 100%; max-width: 100%; overflow-x: visible; }
#main-content, .dataTables_wrapper, .ap-table-viewport { width: 100%; max-width: 100%; }
table.dataTable { width: 100% !important; max-width: 100%; table-layout: fixed; }
table.dataTable th, table.dataTable td {
    overflow-wrap: anywhere;
    white-space: normal;
    vertical-align: middle;
}
#main-content table.dataTable th, #main-content table.dataTable td.ap-date-cell, #main-content table.dataTable td.ap-actions-cell {
    overflow-wrap: normal;
}
table.dataTable td a.text-secondary {
    display: inline-block;
    padding: .25rem;
    color: #858796 !important;
}
table.dataTable td a.text-secondary:hover { color: #5a5c69 !important; }
.dataTables_wrapper .dataTables_filter input { max-width: 100%; }
#main-content .dataTables_wrapper > .row { margin-left: 0; margin-right: 0; }
#main-content .dataTables_wrapper > .row > [class*="col-"] {
    min-width: 0;
    padding-left: 0;
    padding-right: 0;
}
#main-content .dataTables_wrapper .dataTables_length label { white-space: normal; }
#main-content .dataTables_wrapper .dataTables_filter label {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    flex-wrap: wrap;
    gap: .4rem;
    max-width: 100%;
    white-space: normal;
}
#main-content .dataTables_wrapper .dataTables_filter input {
    min-width: 0;
    flex: 0 1 12rem;
    width: 12rem;
    max-width: 100%;
    margin-left: 0;
}
#main-content .dataTables_wrapper .dataTables_paginate .pagination { flex-wrap: wrap; }
body.admin-user-module .dataTables_wrapper > .row:nth-child(2) > div { overflow-x: visible; }
table.dataTable th.vpg-actions, table.dataTable td.vpg-actions { width: 4rem; white-space: nowrap; }
.ap-table-viewport:focus-visible { outline: 2px solid var(--ap-green); outline-offset: 2px; }
/* Enabled by measurement only when the table really exceeds its container.
   Scrolling stays around the table; filters, pagination and badges stay outside. */
.ap-table-viewport.is-scrollable { overflow-x: auto; }
#main-content .ap-table-viewport.is-scrollable table.dataTable { max-width: none !important; }

a:focus-visible, button:focus-visible, [tabindex]:focus-visible {
    outline: 2px solid var(--ap-green);
    outline-offset: 3px;
}
.sidebar a:focus-visible, .sidebar button:focus-visible {
    outline: 2px solid var(--ap-gold);
    outline-offset: -3px;
}
.topbar .nav-item .nav-link:focus-visible {
    outline: 2px solid var(--ap-green);
    outline-offset: -3px;
}
.sidebar #sidebarToggle:focus-visible {
    outline: 2px solid var(--ap-gold);
    outline-offset: 3px;
}
.scroll-to-top:focus-visible { outline-color: var(--ap-gold); }
.tooltip { pointer-events: none; }

/* Preserve the existing authentication screens. */
.login-shell { display: flex; min-height: 100vh; }
.login-brand {
    width: 42%;
    background: var(--ap-green);
    color: white;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 3rem;
    text-align: center;
}
.login-brand img { margin-bottom: 1.5rem; border: 1px solid #ffffff32; border-radius: 25px; }
.login-brand h1 { font-weight: 800; font-size: 2.4rem; }
.login-brand p { font-size: 1.2rem; }
.login-brand span { color: #c7dbca; }
.login-main { flex: 1; min-width: 0; align-self: center; padding: 3rem 1rem; }
.login-panel { border-radius: 1rem; }
body.admin-user-module .login-panel__icon { color: var(--ap-green); background: var(--ap-soft); }
body.admin-user-module .login-panel__title, body.admin-user-module .login-recovery a { color: var(--ap-green); }

/* Tablets still have an expanded sidebar; let readable columns share their space. */
@media (max-width: 991.98px) {
    .dataTables_wrapper table.dataTable { table-layout: auto; font-size: .8rem; }
    /* Long e-mails and descriptions must shrink before local scrolling is needed. */
    .dataTables_wrapper table.dataTable td { overflow-wrap: anywhere; }
    table.dataTable th, table.dataTable td { padding: .5rem .35rem; }
}

@media (max-width: 767px) {
    #main-content { padding-left: .75rem; padding-right: .75rem; }
    .topbar { padding-left: .5rem; padding-right: .5rem; }
    .topbar .nav-item .nav-link { padding-left: .5rem !important; padding-right: .5rem !important; }
    .topbar-page-heading-context { font-size: .55rem; }
    .topbar-page-heading-title { font-size: .8rem; }
    .dataTables_wrapper .dataTables_length, .dataTables_wrapper .dataTables_filter { text-align: left; }
    .dataTables_wrapper .dataTables_filter label { display: block; }
    .dataTables_wrapper .dataTables_filter input { width: 100%; margin-left: 0; }
    #main-content .dataTables_wrapper .dataTables_filter label { display: block; text-align: left; }
    #main-content .dataTables_wrapper .dataTables_filter input { width: 100%; }
    .dataTables_wrapper .dataTables_paginate .pagination { flex-wrap: wrap; }
    .form-control { max-width: 100%; }
    #main-content .admin-user-page-header__actions .btn {
        max-width: 100%;
        min-width: 0;
        padding-left: .65rem;
        padding-right: .65rem;
        white-space: normal;
        flex-wrap: wrap;
    }
    .login-shell { display: block; }
    .login-brand { width: 100%; padding: 1.5rem; }
    .login-brand img { width: 52px; height: 52px; margin-bottom: .5rem; }
    .login-brand h1 { font-size: 1.5rem; }
    .login-brand p { font-size: 1rem; margin-bottom: .25rem; }
    .login-main { padding: 1.5rem .5rem; }
}
@media (prefers-reduced-motion: reduce) {
    .animated--grow-in, .sidebar .collapse { animation: none !important; }
    .scroll-to-top { scroll-behavior: auto; }
}

/* ---------------------------------------------------------------------
   Page header: title, optional description and screen actions.
   --------------------------------------------------------------------- */
.ap-page-header { gap: .75rem 1.5rem; }
.ap-page-header__title { min-width: 0; }
.ap-page-header__description { max-width: 52rem; margin: .35rem 0 0; color: #6e707e; }
.ap-page-header__actions { display: flex; flex-wrap: wrap; gap: .5rem; flex-shrink: 0; }
.ap-page-header__meta { display: flex; flex-wrap: wrap; align-items: center; gap: .35rem .75rem; margin-top: .4rem; color: #6e707e; }

/* Listing and form cards. */
.ap-card-title { font-size: .9rem; font-weight: 800; color: var(--ap-green); margin: 0; }
.ap-card-subtitle { display: block; font-size: .78rem; color: #858796; margin-top: .15rem; }
.ap-filters > [class*="col"] { margin-bottom: .75rem; }
.ap-filters label,
.ap-filters .tag-list-filter-label { display: block; margin-bottom: .35rem; font-size: .78rem; font-weight: 700; color: #5a5c69; }
.ap-filters .ap-filters__actions { display: flex; align-items: flex-end; justify-content: flex-end; gap: .5rem; }
.ap-filter-toggle { display: none; }
.ap-period .input-group-text { background: #fff; color: #858796; }
.ap-period input { background: #fff !important; }
.daterangepicker .ranges li.active,
.daterangepicker td.active, .daterangepicker td.active:hover { background-color: var(--ap-green); }
.daterangepicker td.in-range { background-color: var(--ap-soft); }
.daterangepicker .btn-primary { background: var(--ap-green); border-color: var(--ap-green); }

/* Status badges: soft tone, dark text, readable on striped rows. */
.ap-status {
    display: inline-flex;
    align-items: center;
    gap: .35rem;
    max-width: 100%;
    padding: .22rem .6rem;
    border-radius: 999px;
    font-size: .74rem;
    font-weight: 700;
    line-height: 1.2;
    white-space: normal;
    vertical-align: middle;
}
.ap-status::before { content: ""; width: .45rem; height: .45rem; border-radius: 50%; background: currentColor; flex-shrink: 0; }
.ap-status-primary { color: #164735; background: #e3efe8; }
.ap-status-success { color: #13653f; background: #def3e7; }
.ap-status-info { color: #0e5a70; background: #ddf1f6; }
.ap-status-warning { color: #7a5200; background: #fcefd2; }
.ap-status-danger { color: #9f1f2c; background: #fbe3e5; }
.ap-status-secondary { color: #4f5565; background: #eceef2; }

/* Definition lists in detail cards. */
.ap-dl dt { font-size: .78rem; font-weight: 700; color: #858796; text-transform: uppercase; letter-spacing: .02em; }
.ap-dl dd { margin-bottom: .85rem; color: #3a3b45; overflow-wrap: anywhere; }

/* Form helpers. */
.form-group:has(> [required]) > label:not(.custom-control-label)::after,
.form-group:has(> .bootstrap-select > select[required]) > label::after,
.form-group:has(> .input-group [required]) > label::after { content: " *"; color: #c93443; font-weight: 700; }
input[type="color"].form-control { width: 4.5rem; padding: .2rem .35rem; cursor: pointer; }
.ap-form-actions { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem; }
.mandate-detail form .btn {
    min-width: 0;
    max-width: 100%;
    white-space: normal;
    overflow-wrap: anywhere;
}
.ap-repeat-row { padding-top: .25rem; }
.ap-repeat-row + .ap-repeat-row { border-top: 1px dashed #dfe3eb; padding-top: 1rem; }
.ap-danger-zone { border-left: .25rem solid #e74a3b !important; }
.ap-danger-zone .card-header { color: #9f1f2c; background: #fdf3f4; font-weight: 700; }
.ap-timeline { list-style: none; margin: 0; padding: 0; }
.ap-timeline > li { position: relative; padding: 0 0 1rem 1.5rem; border-left: 2px solid #e3e6f0; margin-left: .4rem; }
.ap-timeline > li:last-child { padding-bottom: 0; }
.ap-timeline > li::before { content: ""; position: absolute; left: -.45rem; top: .2rem; width: .8rem; height: .8rem; border-radius: 50%; background: #fff; border: 2px solid var(--ap-green); }
.ap-timeline__meta { font-size: .78rem; color: #858796; }

/* Media library. */
.ap-media-cell { display: flex; align-items: center; gap: .75rem; min-width: 0; }
.ap-media-thumb { width: 4.5rem; height: 3.25rem; object-fit: cover; border-radius: .35rem; border: 1px solid #e3e6f0; background: #f8f9fc; flex-shrink: 0; }
.ap-media-thumb--empty { display: inline-flex; align-items: center; justify-content: center; color: #b7b9cc; }
.ap-media-preview { display: none; max-width: 100%; max-height: 12rem; border-radius: .5rem; border: 1px solid #e3e6f0; }
.ap-media-preview.is-visible { display: block; }

/* Dashboard. */
.ap-dashboard-card { color: inherit; }
.ap-dashboard-card:hover, .ap-dashboard-card:focus { text-decoration: none; box-shadow: 0 .35rem 1rem rgba(58, 59, 69, .12) !important; transform: translateY(-1px); }
.ap-dashboard-card { transition: box-shadow .15s ease, transform .15s ease; }
.ap-check-list .list-group-item { display: flex; align-items: center; justify-content: space-between; gap: .75rem; }
.ap-check-list .list-group-item a { color: inherit; }
.ap-quick-links .btn { justify-content: flex-start; }

/* Topbar alerts counter and breadcrumb context. */
.topbar .badge-counter.hidden { display: none; }
.topbar-page-heading-context a { color: inherit; }

@media (max-width: 767px) {
    .ap-filter-toggle { display: inline-flex; }
    .ap-filters-collapse:not(.show) { display: none; }
    .ap-page-header__actions { width: 100%; }
    .ap-page-header__actions .btn { flex: 1 1 auto; }
    .ap-filters .ap-filters__actions { justify-content: stretch; }
    .ap-filters .ap-filters__actions .btn { flex: 1 1 auto; }
    #accordionSidebar:not(.toggled) { box-shadow: .5rem 0 1.5rem rgba(0, 0, 0, .18); }
}
@media (min-width: 768px) {
    .ap-filters-collapse { display: block !important; height: auto !important; }
}
@media (max-width: 575.98px) {
    .ap-page-header h1 { font-size: 1.4rem; }
    .mandate-page > .card-body { padding: .75rem; }
    .mandate-page table.dataTable { font-size: .75rem; }
    .mandate-page table.dataTable th, .mandate-page table.dataTable td { padding: .5rem .25rem; }
    /* Empty lists also fit beside an expanded phone sidebar. */
    #main-content .mandate-page table.dataTable:not(:has(tbody td:not(.dataTables_empty))) th { width: auto !important; overflow-wrap: anywhere; }
    /* Populated seven-column lists need readable names and e-mails on phones.
       fitTable measures this width and enables local scrolling; empty lists stay flexible. */
    .mandate-page table.dataTable:has(tbody td:not(.dataTables_empty)) th:nth-child(1),
    .mandate-page table.dataTable:has(tbody td:not(.dataTables_empty)) td:nth-child(1) { min-width: 7.5rem; }
    .mandate-page table.dataTable:has(tbody td:not(.dataTables_empty)) th:nth-child(2),
    .mandate-page table.dataTable:has(tbody td:not(.dataTables_empty)) td:nth-child(2) { min-width: 9rem; }
    .summary-card .col-auto { display: none; }
    .summary-card { padding-top: .2rem !important; padding-bottom: .2rem !important; }
    .summary-card .card-body { padding: .45rem .85rem; }
    .summary-card .text-xs { font-size: .65rem; }
    .row > [class*="col"] > .summary-card { margin-bottom: 0; }
}
