:root {
    --brand: #27509A;
    --brand-dark: #1c3c73;
    --brand-lime: #B5C832;
    --brand-lime-dark: #6B8A20;
    --brand-orange: #D57C1B;
    --brand-black: #14161A;

    --sidebar-bg: linear-gradient(180deg, #10131a 0%, #1a2c4d 100%);
    --sidebar-bg-hover: rgba(255, 255, 255, .08);
    --sidebar-fg: rgba(255, 255, 255, .72);
    --sidebar-fg-active: #fff;

    --page-bg: #eef1f8;
    --card-shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
    --radius: .65rem;
}

[data-bs-theme="dark"] {
    --page-bg: #0a0c10;
    --card-shadow: 0 1px 2px rgba(0, 0, 0, .5), 0 2px 8px rgba(0, 0, 0, .4);
    --sidebar-bg: linear-gradient(180deg, #000000 0%, #0f1c33 100%);
    --sidebar-bg-hover: rgba(255, 255, 255, .06);
}

html {
    font-size: 14px;
}

body {
    margin: 0;
    background-color: var(--page-bg);
    color: var(--bs-body-color);
}

a {
    text-decoration: none;
}

.brand-heading {
    font-family: "Krona One", "Raleway", sans-serif;
    letter-spacing: .01em;
}

/* ---------- Shell layout ---------- */

.app-wrapper {
    display: flex;
    min-height: 100vh;
}

.sidebar {
    width: 264px;
    min-width: 264px;
    display: flex;
    flex-direction: column;
    background: var(--sidebar-bg);
    padding: 1.25rem 1rem;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: .6rem;
    color: #fff;
    margin-bottom: 1.5rem;
    padding: 0 .5rem;
}

.sidebar-brand-mark {
    width: 32px;
    height: auto;
    flex-shrink: 0;
}

.sidebar-brand-text {
    font-weight: 400;
    font-size: .95rem;
    line-height: 1.2;
}

.sidebar-brand-sub {
    font-size: .7rem;
    color: rgba(255, 255, 255, .45);
    font-weight: 400;
}

.sidebar-section-label {
    font-size: .7rem;
    text-transform: uppercase;
    letter-spacing: .06em;
    color: rgba(255, 255, 255, .35);
    padding: .9rem .75rem .35rem;
}

.sidebar .nav-link {
    color: var(--sidebar-fg);
    border-radius: .5rem;
    padding: .5rem .75rem;
    display: flex;
    align-items: center;
    gap: .65rem;
    font-size: .92rem;
    transition: background-color .12s ease, color .12s ease;
}

.sidebar .nav-link .bi {
    font-size: 1.05rem;
    width: 1.1rem;
    text-align: center;
    opacity: .85;
}

.sidebar .nav-link.active,
.sidebar .nav-link:hover {
    color: var(--sidebar-fg-active);
    background-color: var(--sidebar-bg-hover);
}

.sidebar .nav-link.active {
    background-color: var(--brand);
}

.sidebar .nav-link.active .bi {
    opacity: 1;
}

.sidebar-footer {
    margin-top: auto;
    padding-top: 1rem;
    border-top: 1px solid rgba(255, 255, 255, .08);
}

.sidebar-user {
    display: flex;
    align-items: center;
    gap: .6rem;
    color: rgba(255, 255, 255, .8);
    font-size: .85rem;
    padding: 0 .5rem .6rem;
}

.sidebar-user .avatar {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    background: var(--brand);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: .8rem;
    color: #fff;
    flex-shrink: 0;
}

.sidebar-backdrop {
    display: none;
}

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

.main-header {
    display: flex;
    align-items: center;
    gap: .75rem;
    padding: .9rem 1.5rem;
    background: var(--bs-body-bg);
    border-bottom: 1px solid var(--bs-border-color);
    position: sticky;
    top: 0;
    z-index: 10;
}

.main-header h1 {
    font-size: 1.05rem;
    font-weight: 500;
    margin: 0;
}

.btn-icon {
    border: none;
    background: transparent;
    color: var(--bs-secondary-color);
    font-size: 1.3rem;
    line-height: 1;
    padding: .25rem .4rem;
    border-radius: .4rem;
}

.btn-icon:hover {
    background: var(--bs-tertiary-bg);
    color: var(--bs-body-color);
}

.main-body {
    padding: 1.5rem;
    flex: 1;
}

@media (max-width: 991.98px) {
    .sidebar {
        position: fixed;
        inset: 0 auto 0 0;
        z-index: 1050;
        transform: translateX(-100%);
        transition: transform .2s ease;
        box-shadow: 0 0 0 rgba(0, 0, 0, 0);
    }

    .sidebar.show {
        transform: translateX(0);
        box-shadow: 0 0 40px rgba(0, 0, 0, .35);
    }

    .sidebar-backdrop {
        display: block;
        position: fixed;
        inset: 0;
        background: rgba(15, 18, 28, .5);
        z-index: 1040;
        opacity: 0;
        pointer-events: none;
        transition: opacity .2s ease;
    }

    .sidebar-backdrop.show {
        opacity: 1;
        pointer-events: auto;
    }

    .main-body {
        padding: 1rem;
    }
}

@media (min-width: 992px) {
    #sidebarToggle {
        display: none;
    }
}

/* ---------- Cards / metrics ---------- */

.card-metric {
    border: none;
    border-radius: var(--radius);
    box-shadow: var(--card-shadow);
}

.card-metric .card-body {
    padding: 1.1rem 1.25rem;
}

.metric-icon {
    width: 2.5rem;
    height: 2.5rem;
    border-radius: .6rem;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    flex-shrink: 0;
}

.metric-icon.bg-soft-primary { background: rgba(39, 80, 154, .12); color: var(--brand); }
.metric-icon.bg-soft-success { background: rgba(107, 138, 32, .14); color: var(--brand-lime-dark); }
.metric-icon.bg-soft-warning { background: rgba(213, 124, 27, .16); color: var(--brand-orange); }
.metric-icon.bg-soft-danger { background: rgba(220, 53, 69, .12); color: #dc3545; }

[data-bs-theme="dark"] .metric-icon.bg-soft-primary { background: rgba(90, 140, 220, .18); color: #8fb4e8; }
[data-bs-theme="dark"] .metric-icon.bg-soft-success { background: rgba(181, 200, 50, .16); color: var(--brand-lime); }
[data-bs-theme="dark"] .metric-icon.bg-soft-warning { background: rgba(213, 124, 27, .2); color: #eb9a4c; }
[data-bs-theme="dark"] .metric-icon.bg-soft-danger { background: rgba(220, 53, 69, .18); color: #e88b95; }

.metric-value {
    font-size: 1.6rem;
    font-weight: 700;
    line-height: 1.2;
}

.metric-label {
    font-size: .78rem;
    color: var(--bs-secondary-color);
    text-transform: uppercase;
    letter-spacing: .03em;
    font-weight: 600;
}

.section-card {
    border: none;
    border-radius: var(--radius);
    box-shadow: var(--card-shadow);
}

.section-card .card-header {
    background: var(--bs-body-bg);
    border-bottom: 1px solid var(--bs-border-color);
    font-weight: 700;
    font-size: .95rem;
    padding: .9rem 1.25rem;
    border-top-left-radius: var(--radius);
    border-top-right-radius: var(--radius);
}

.section-card .card-body {
    padding: 1.25rem;
}

.form-section-title {
    font-size: .78rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: var(--bs-secondary-color);
    margin: 1.4rem 0 .6rem;
}

.form-section-title:first-child {
    margin-top: 0;
}

.required-mark {
    color: #dc3545;
    margin-left: .15rem;
}

/* ---------- Tables ---------- */

.table-responsive {
    background: var(--bs-body-bg);
    border-radius: var(--radius);
    box-shadow: var(--card-shadow);
}

.table > :not(caption) > * > * {
    padding: .75rem 1rem;
}

.table thead th {
    font-size: .74rem;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: var(--bs-secondary-color);
    font-weight: 700;
    border-bottom-width: 1px;
    white-space: nowrap;
}

.table tbody tr:hover {
    background-color: var(--bs-tertiary-bg);
}

.toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: .6rem;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1rem;
}

.search-box {
    position: relative;
    max-width: 320px;
    flex: 1;
    min-width: 200px;
}

.search-box .bi {
    position: absolute;
    left: .7rem;
    top: 50%;
    transform: translateY(-50%);
    color: var(--bs-tertiary-color);
}

.search-box input {
    padding-left: 2.1rem;
}

.empty-state {
    text-align: center;
    padding: 3rem 1.5rem;
    color: var(--bs-secondary-color);
}

.empty-state .bi {
    font-size: 2.4rem;
    color: var(--bs-border-color);
    margin-bottom: .75rem;
    display: block;
}

.empty-state p {
    margin: 0 0 1rem;
}

/* ---------- Auth page ---------- */

.auth-body {
    background: linear-gradient(160deg, #0d1117 0%, #16213f 55%, #27509A 150%);
}

.auth-card {
    background: var(--bs-body-bg);
}

/* ---------- Misc ---------- */

.btn .bi {
    margin-right: .35rem;
}

.btn-icon-only .bi {
    margin-right: 0;
}

.nav-tabs .nav-link {
    color: var(--bs-secondary-color);
    font-weight: 600;
}

.nav-tabs .nav-link.active {
    color: var(--brand);
}

.toast-container {
    z-index: 1080;
}

.alert-banner {
    border: none;
    border-radius: var(--radius);
    box-shadow: var(--card-shadow);
}

@media (max-width: 768px) {
    .toolbar {
        flex-direction: column;
        align-items: stretch;
    }

    .search-box {
        max-width: none;
    }
}
