:root {
    --sidebar-width: 240px;
    --topnav-height: 56px;
    /* KRA Hub plum palette — adapted from the supplied brand reference */
    --primary: #43245f;
    --primary-dark: #281638;
    --accent: #8a5bb2;
    --accent-soft: #eee6f5;
    --brand-gold: #c6a064;
    --sidebar-bg: #f8f9fa;
    --sidebar-border: #e3dbe9;
    --sidebar-link-active: #43245f;
    --sidebar-link-hover: #f3edf7;
    --brand-gradient:
        radial-gradient(circle at 82% -20%, rgba(138, 91, 178, .52), transparent 42%),
        linear-gradient(135deg, var(--primary-dark) 0%, var(--primary) 58%, #61377d 100%);
}

body {
    background-color: #f7f5f8;
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
}

/* --- Topnav --- */
#topnav {
    background: var(--brand-gradient);
    height: var(--topnav-height);
    box-shadow: 0 2px 8px rgba(0,0,0,0.15);
    z-index: 1030;
}

.progress-bar-purple {
    background: var(--brand-gradient);
}

#topnav .navbar-brand {
    font-size: 1.1rem;
    letter-spacing: 0.02em;
}
#topnav > .container-fluid {
    position: relative;
    height: 100%;
}
.global-search {
    position: absolute;
    left: 50%;
    top: 50%;
    width: min(520px, calc(100vw - 32px));
    max-width: 520px;
    transform: translate(-50%, -50%);
    z-index: 1060;
}
.global-search-control {
    position: relative;
    display: flex;
    align-items: center;
}
.global-search-input {
    width: 100%;
    height: 36px;
    padding: 0 2.5rem 0 2.35rem;
    border: 1px solid rgba(255,255,255,.32);
    border-radius: 999px;
    background: rgba(255,255,255,.14);
    color: #fff;
    outline: none;
}
.global-search-input::placeholder { color: rgba(255,255,255,.76); }
.global-search-input:focus {
    background: #fff;
    color: #2c2140;
    border-color: #fff;
    box-shadow: 0 0 0 .2rem rgba(255,255,255,.18);
}
.global-search-input::placeholder,
.global-search-input:focus::placeholder {
    color: #8c8297;
    opacity: 1;
}
.global-search-input::-webkit-search-cancel-button {
    -webkit-appearance: none;
    appearance: none;
}
.global-search-icon {
    position: absolute;
    left: .9rem;
    color: rgba(255,255,255,.8);
    pointer-events: none;
    z-index: 1;
}
.global-search-clear {
    align-items: center;
    background: var(--accent-soft);
    border: 1px solid rgba(67, 36, 95, .5);
    border-radius: 50%;
    color: var(--primary);
    display: flex;
    font-size: .95rem;
    height: 22px;
    justify-content: center;
    line-height: 1;
    padding: 0 0 2px;
    position: absolute;
    right: .65rem;
    top: 50%;
    transform: translateY(-50%);
    width: 22px;
    z-index: 2;
}
.global-search-clear:hover,
.global-search-clear:focus-visible {
    background: var(--primary);
    color: #fff;
    outline: none;
}
.global-search-results {
    position: fixed;
    top: var(--topnav-height);
    left: 50%;
    min-width: 0;
    max-height: calc(100vh - var(--topnav-height) - 50px);
    overflow-y: auto;
    padding: .45rem;
    background: #fff;
    border: 1px solid #e5ddec;
    border-radius: .65rem;
    box-shadow: 0 12px 30px rgba(37, 21, 55, .22);
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transform: translateX(-50%) translateY(-8px) scale(.985);
    transition: opacity .18s ease, transform .18s ease, visibility 0s linear .18s;
}
.global-search-results-grid {
    display: grid;
}
.global-search-group {
    min-width: 0;
    padding: .15rem;
}
.global-search-group + .global-search-group {
    border-left: 1px solid #eee7f2;
}
.global-search-group-empty {
    color: #92899a;
    font-size: .82rem;
    padding: .6rem .7rem;
}
.global-search-results.open {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
    transform: translateX(-50%) translateY(0) scale(1);
    transition: opacity .18s ease, transform .18s ease, visibility 0s linear 0s;
}
.global-search-heading {
    padding: .45rem .7rem .25rem;
    color: #7b7185;
    font-size: .68rem;
    font-weight: 700;
    letter-spacing: .08em;
    text-transform: uppercase;
}
.global-search-result {
    display: flex;
    align-items: flex-start;
    gap: .7rem;
    padding: .55rem .7rem;
    color: #31263b;
    text-decoration: none;
    border-radius: .45rem;
}
.global-search-result:hover,
.global-search-result:focus {
    color: var(--primary);
    background: var(--accent-soft);
    outline: none;
}
.global-search-result-icon {
    width: 1.5rem;
    color: var(--accent);
    font-size: 1.05rem;
    text-align: center;
}
.global-search-result-text {
    min-width: 0;
    flex: 1;
    display: flex;
    flex-direction: column;
}
.global-search-result-text strong,
.global-search-result-text small {
    overflow-wrap: anywhere;
    word-break: break-word;
}
.global-search-result-text small {
    color: #817889;
}
.global-search-result-text .global-search-result-meta {
    color: #a095aa;
    font-size: .72rem;
    line-height: 1.3;
    margin-top: .08rem;
}
.global-search-result-text mark {
    background: #ffe08a;
    border-radius: .18rem;
    color: #2c2140;
    padding: 0 .12rem;
}
.topnav-account {
    position: relative;
    z-index: 1065;
}
.topnav-notifications {
    position: relative;
    z-index: 1065;
    margin-right: .45rem;
}
.topnav-icon-toggle {
    flex: 0 0 36px;
    width: 36px;
    min-width: 36px;
    height: 36px;
    padding: 0;
    border: 1px solid rgba(255,255,255,.45);
    border-radius: 50%;
    color: #fff;
    font-size: 1.05rem;
    line-height: 1;
}
.topnav-icon-toggle:hover,
.topnav-icon-toggle:active,
.topnav-icon-toggle:focus,
.topnav-icon-toggle:focus-visible,
.topnav-icon-toggle.show {
    color: #fff;
    background: rgba(255,255,255,.16);
    border-color: rgba(255,255,255,.8);
}
.topnav-icon-toggle:focus,
.topnav-icon-toggle:focus-visible,
.topnav-icon-toggle.show {
    color: #fff !important;
}
.topnav-notification-badge {
    position: absolute;
    top: -7px;
    right: -8px;
    z-index: 2;
    min-width: 18px;
    min-height: 18px;
    padding: 2px 5px;
    font-size: .62rem;
    font-weight: 700;
    line-height: 1.2;
    white-space: nowrap;
    pointer-events: none;
    border: 2px solid var(--primary);
    box-shadow: 0 2px 5px rgba(0, 0, 0, .28);
}
.topnav-notification-menu {
    display: block;
    width: min(560px, calc(100vw - 24px));
    padding: 0;
    margin-top: .1rem !important;
    overflow: hidden;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition:
        opacity .18s ease,
        margin-top .18s ease,
        visibility 0s linear .18s;
}
.topnav-notification-menu.show {
    margin-top: .35rem !important;
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
    transition:
        opacity .18s ease,
        margin-top .18s ease,
        visibility 0s linear 0s;
}
.topnav-notification-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: .8rem 1rem;
    border-bottom: 1px solid #eee7f2;
    color: var(--primary-dark);
}
.topnav-notification-list {
    max-height: min(650px, calc(100vh - 90px));
    overflow-y: auto;
}
.topnav-notification-item {
    display: flex;
    gap: .7rem;
    padding: .75rem 1rem;
    color: #31263b;
    text-decoration: none;
    border-bottom: 1px solid #f0ebf3;
}
.topnav-notification-item:hover,
.topnav-notification-item:focus {
    color: var(--primary);
    background: var(--accent-soft);
}
.topnav-notification-item.is-unread {
    background: #e9dcf6;
    border-left: 4px solid var(--accent);
    padding-left: calc(1rem - 4px);
}
.topnav-notification-icon {
    flex: 0 0 30px;
    width: 30px;
    height: 30px;
    display: grid;
    place-items: center;
    border-radius: 50%;
    color: var(--primary);
    background: var(--accent-soft);
}
.topnav-notification-copy {
    flex: 1 1 auto;
    width: 0;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
    font-size: .82rem;
}
.topnav-notification-copy strong {
    font-size: .82rem;
}
.topnav-notification-title-row {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: .75rem;
}
.topnav-notification-copy span {
    overflow-wrap: anywhere;
}
.topnav-notification-meta {
    display: flex;
    flex-wrap: wrap;
    gap: .25rem .8rem;
    color: #62586b;
    font-size: .74rem;
}
.topnav-notification-deadline {
    color: #403748;
    font-weight: 700;
}
.notification-deadline-deadline_today {
    color: #b45309;
}
.notification-deadline-deadline_overdue {
    color: #dc2626;
}
.notification-deadline-deadline_3_days {
    color: #111827;
}
.notification-status-urgent {
    font-weight: 700;
}
.topnav-notification-copy small {
    color: #8a8490;
    font-size: .7rem;
}
.topnav-notification-empty {
    padding: 2rem 1rem;
    color: #8a8490;
    text-align: center;
    font-size: .85rem;
}
.topnav-account-toggle {
    width: 36px;
    height: 36px;
    padding: 0;
    border: 1px solid rgba(255,255,255,.45);
    border-radius: 50%;
    color: #fff;
    font-size: 1.25rem;
    line-height: 1;
}
.topnav-account-toggle:hover,
.topnav-account-toggle:focus-visible {
    color: #fff;
    background: rgba(255,255,255,.16);
    border-color: rgba(255,255,255,.8);
}
.topnav-account-menu {
    min-width: 220px;
    margin-top: .35rem !important;
}
.topnav-account-user {
    display: flex;
    align-items: center;
    white-space: nowrap;
}

/* --- Sidebar --- */
#wrapper {
    padding-top: var(--topnav-height);
    min-height: 100vh;
}

#sidebar {
    width: var(--sidebar-width);
    min-width: var(--sidebar-width);
    min-height: calc(100vh - var(--topnav-height));
    background: #fff;
    border-right: 1px solid var(--sidebar-border);
    padding: 1.5rem 0;
    position: sticky;
    top: var(--topnav-height);
    height: calc(100vh - var(--topnav-height));
    overflow-y: auto;
}

.sidebar-header {
    padding: 0 1rem 0.75rem 1rem;
    font-size: 0.7rem;
    letter-spacing: 0.08em;
}

.sidebar-nav {
    margin: 0;
    padding: 0;
}

.sidebar-link {
    display: flex;
    align-items: center;
    padding: 0.6rem 1rem;
    color: #495057;
    text-decoration: none;
    border-radius: 0;
    font-size: 0.9rem;
    transition: background 0.15s, color 0.15s;
    border-left: 3px solid transparent;
}

.sidebar-link:hover {
    background: var(--sidebar-link-hover);
    color: var(--primary);
}

.sidebar-link.active {
    background: var(--accent-soft);
    color: var(--primary);
    border-left-color: var(--primary);
    font-weight: 600;
}

/* --- Page content --- */
#page-content-wrapper {
    flex: 1;
    min-width: 0;
}

/* --- Cards --- */
.card {
    border: none;
    box-shadow: 0 1px 4px rgba(0,0,0,0.08);
    border-radius: 10px;
}

.card-header {
    background: #fff;
    border-bottom: 1px solid #f0f0f0;
    border-radius: 10px 10px 0 0 !important;
    padding: 1rem 1.25rem;
}

/* --- Page title --- */
.page-title {
    font-size: 1.4rem;
    font-weight: 700;
    color: var(--primary);
    margin-bottom: 1.5rem;
}

/* --- Stats cards (admin) --- */
.stat-card {
    border-radius: 12px;
    border: none;
    box-shadow: 0 2px 8px rgba(0,0,0,0.07);
}

.stat-icon {
    width: 48px;
    height: 48px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.4rem;
}

/* --- Auth pages --- */
.auth-wrapper {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, var(--primary) 0%, var(--accent) 100%);
}

.auth-card {
    width: 100%;
    max-width: 420px;
    border-radius: 16px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.25);
}

.auth-layout {
    width: min(100% - 2rem, 980px);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 1.5rem;
}

.demo-accounts-panel {
    width: 100%;
    max-width: 360px;
    max-height: calc(100vh - 2rem);
    overflow-y: auto;
    border-radius: 16px;
    background: rgba(255,255,255,0.96);
    border: 1px solid rgba(255,255,255,0.7);
    box-shadow: 0 20px 60px rgba(0,0,0,0.2);
}

.demo-account {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    margin: 0;
    padding: 0.7rem 0.75rem;
    border: 1px solid #e7dcef;
    border-radius: 10px;
    background: #fff;
}

.demo-account-details {
    min-width: 0;
    display: grid;
    gap: 0.12rem;
}

.demo-account-details strong,
.demo-account-details code,
.demo-account-details small {
    overflow-wrap: anywhere;
}

.demo-account-details code {
    color: var(--primary);
    font-size: 0.76rem;
}

.demo-account-role {
    color: #6c757d;
    font-size: 0.8rem;
}

.auth-demo-intro {
    padding: 1.5rem 0 0.75rem;
}

@media (max-width: 767.98px) {
    .auth-wrapper {
        padding: 1rem 0;
    }

    .auth-layout {
        flex-direction: column;
        align-items: stretch;
    }

    .demo-accounts-panel {
        max-width: none;
        max-height: none;
    }
}

.auth-logo {
    font-size: 1.8rem;
    font-weight: 800;
    color: var(--primary);
    letter-spacing: -0.02em;
}

/* --- Tables --- */
.table th {
    font-size: 0.78rem;
    text-transform: none;
    letter-spacing: 0.06em;
    color: var(--primary);
    font-weight: 600;
    border-top: none;
}

.table thead th {
    background-color: var(--accent-soft) !important;
    color: var(--primary) !important;
    border-bottom: 2px solid #dde2ed;
}

.table thead th a {
    color: inherit;
}

.table thead th[data-sortable],
.table thead th[data-sort-col],
.table thead th[data-report-sort] {
    cursor: pointer;
    user-select: none;
}

/* --- Status colors --- */
.status-active { color: #198754; }
.status-dissolved { color: #dc3545; }
.status-liquidation { color: #fd7e14; }

/* --- Section card headers --- */
.section-header {
    background: #f8f9fb;
    border-bottom: 1px solid #edf0f3;
    padding: 0.65rem 1.25rem;
    font-size: 0.875rem;
}

/* --- Form controls refinements --- */
.form-label {
    font-size: 0.85rem;
    font-weight: 500;
    color: #495057;
    margin-bottom: 0.3rem;
}

/* --- Sidebar submenu / collapsible --- */
.sidebar-link-toggle {
    cursor: pointer;
    user-select: none;
}

.sidebar-link-toggle .toggle-icon {
    font-size: 0.7rem;
    transition: transform 0.2s ease;
    flex-shrink: 0;
}

.sidebar-link-toggle[aria-expanded="true"] .toggle-icon {
    transform: rotate(-180deg);
}

.sidebar-submenu {
    background: #f8f9fb;
    border-left: 3px solid #dee2e6;
    margin-left: 0;
    padding: 0.25rem 0;
}

.sidebar-sublink {
    display: flex;
    align-items: center;
    padding: 0.45rem 1rem 0.45rem 1.75rem;
    color: #6c757d;
    text-decoration: none;
    font-size: 0.84rem;
    transition: background 0.15s, color 0.15s;
}

.sidebar-sublink:hover {
    background: var(--sidebar-link-hover);
    color: var(--primary);
}

.sidebar-sublink.active {
    color: var(--primary);
    font-weight: 600;
    background: var(--accent-soft);
}

/* --- Responsive --- */
@media (max-width: 991.98px) {
    #topnav {
        height: auto;
        min-height: var(--topnav-height);
    }
    #topnav > .container-fluid {
        flex-wrap: wrap;
    }
    .global-search {
        position: relative;
        left: auto;
        top: auto;
        order: 3;
        flex: 1 0 100%;
        width: 100%;
        max-width: none;
        margin: .35rem 0 .55rem;
        transform: none;
    }
    #wrapper {
        padding-top: 102px;
    }
    .global-search-results-grid {
        grid-template-columns: 1fr;
    }
    .global-search-group + .global-search-group {
        border-left: 0;
        border-top: 1px solid #eee7f2;
    }
}

@media (max-width: 768px) {
    #sidebar {
        display: none;
    }
}

/* --- Brand color bridge for Bootstrap and page-level components --- */
.btn-primary {
    --bs-btn-bg: var(--primary);
    --bs-btn-border-color: var(--primary);
    --bs-btn-hover-bg: var(--primary-dark);
    --bs-btn-hover-border-color: var(--primary-dark);
    --bs-btn-active-bg: var(--primary-dark);
    --bs-btn-active-border-color: var(--primary-dark);
    background: linear-gradient(135deg, var(--primary) 0%, var(--accent) 100%);
    border-color: transparent;
}

.btn-outline-primary {
    --bs-btn-color: var(--primary);
    --bs-btn-border-color: var(--accent);
    --bs-btn-hover-color: #fff;
    --bs-btn-hover-bg: var(--primary);
    --bs-btn-hover-border-color: var(--primary);
}

.text-primary,
.link-primary {
    color: var(--primary) !important;
}

.bg-primary {
    background-color: var(--primary) !important;
}

.border-primary {
    border-color: var(--accent) !important;
}

/* --- Purple pagination --- */
.pagination .page-link {
    color: var(--primary);
    border-color: var(--sidebar-border);
}

.pagination .page-link:hover {
    color: #fff;
    background: var(--accent);
    border-color: var(--accent);
}

.pagination .page-item.active .page-link {
    color: #fff;
    background: var(--brand-gradient);
    border-color: var(--primary);
}

.pagination .page-item.disabled .page-link {
    color: #adb5bd;
    background: #fff;
    border-color: var(--sidebar-border);
}

.pagination {
    justify-content: flex-end;
}

a {
    color: var(--primary);
}

a:hover {
    color: var(--accent);
}

.form-control:focus,
.form-select:focus,
.form-check-input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 .2rem rgba(138, 91, 178, .16);
}

.form-check-input:checked {
    background-color: var(--primary);
    border-color: var(--primary);
}
