:root {
    --bs-font-sans-serif: "Poppins", sans-serif;
    --bs-body-font-family: var(--bs-font-sans-serif);
    --bs-primary: #435ebe;
    --bs-primary-rgb: 67, 94, 190;
    --bs-link-color: #435ebe;
    --bs-link-color-rgb: 67, 94, 190;
    --bs-link-hover-color: #5368c6;
    --bs-link-hover-color-rgb: 83, 104, 198;
    --dashboard-accent: #435ebe;
    --dashboard-accent-deep: #3950a2;
    --dashboard-accent-violet: #5368c6;
    --dashboard-accent-gradient: linear-gradient(135deg, #5368c6 0%, #4b62c2 48%, #435ebe 100%);
}

html {
    scroll-behavior: smooth !important;
}

body,
button,
input,
optgroup,
select,
textarea,
.form-control,
.form-select,
.btn,
.table,
.card,
.modal,
.sidebar-wrapper,
#sidebar,
#main,
.page-heading,
h1,
h2,
h3,
h4,
h5,
h6,
p,
label,
.select2-container,
.select2-container .select2-selection,
.select2-results__option,
.dataTables_wrapper,
.login-page {
    font-family: "Poppins", sans-serif;
}

.select2 {
    width: 100% !important;
}

.select2-container {
    max-width: 100% !important;
    width: 100% !important;
}

body {
    overflow-x: hidden !important;
}

.logo .dashboard-brand {
    align-items: center;
    display: inline-flex;
    gap: 0.75rem;
    min-width: 0;
    text-decoration: none;
}

.dashboard-brand__mark {
    align-items: center;
    background: var(--dashboard-accent-gradient) !important;
    border-radius: 1rem;
    box-shadow: 0 12px 28px rgba(67, 94, 190, 0.24);
    color: #ffffff;
    display: inline-flex;
    flex: 0 0 auto;
    height: 2.8rem;
    justify-content: center;
    width: 2.8rem;
}

.dashboard-brand__mark svg,
.dashboard-brand__mark i {
    display: block;
    height: 1.2rem;
    line-height: 1;
    width: 1.2rem;
}

.dashboard-brand__mark svg {
    fill: currentColor;
}

.dashboard-brand__mark i {
    font-size: 1.2rem;
    text-align: center;
}

.dashboard-brand__text {
    color: #25396f;
    font-size: 1rem;
    font-weight: 800;
    letter-spacing: -0.03em;
    white-space: nowrap;
}

html[data-bs-theme="dark"] .dashboard-brand__text {
    color: #ffffff;
}

img,
table,
input,
select,
textarea,
.btn {
    max-width: 100%;
}

.btn {
    align-items: center;
    border-radius: 0.45rem;
    display: inline-flex;
    gap: 0.35rem;
    justify-content: center;
}

.btn-primary {
    --bs-btn-bg: var(--dashboard-accent);
    --bs-btn-border-color: var(--dashboard-accent);
    --bs-btn-hover-bg: var(--dashboard-accent-deep);
    --bs-btn-hover-border-color: var(--dashboard-accent-deep);
    --bs-btn-active-bg: #435ebe;
    --bs-btn-active-border-color: #435ebe;
    --bs-btn-disabled-bg: var(--dashboard-accent);
    --bs-btn-disabled-border-color: var(--dashboard-accent);
}

.btn-outline-primary {
    --bs-btn-color: var(--dashboard-accent-deep);
    --bs-btn-border-color: var(--dashboard-accent);
    --bs-btn-hover-bg: var(--dashboard-accent);
    --bs-btn-hover-border-color: var(--dashboard-accent);
    --bs-btn-active-bg: var(--dashboard-accent-deep);
    --bs-btn-active-border-color: var(--dashboard-accent-deep);
    --bs-btn-disabled-color: var(--dashboard-accent);
    --bs-btn-disabled-border-color: var(--dashboard-accent);
}

.text-primary {
    color: var(--dashboard-accent-deep) !important;
}

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

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

.btn>i,
.btn>.bi,
.btn>.fas,
.btn>.far,
.btn>.fab {
    align-items: center;
    display: inline-flex;
    line-height: 1;
    vertical-align: middle;
}

.btn [class^="bi-"]::before,
.btn [class*=" bi-"]::before {
    display: block;
    line-height: 1;
}

.input-group-text .form-check {
    margin-bottom: 0;
    min-height: auto;
    padding-left: 0;
}

.input-group-text .form-check-input {
    float: none;
    margin: 0;
}

.input-group-text .form-check-label {
    display: none;
}

.card-title,
.card-text,
.page-heading h3,
.page-heading p {
    overflow-wrap: anywhere;
}

.table-responsive {
    border-radius: 0.65rem;
    position: relative;
}

.table-responsive:not(.table-stack-mobile)>.table {
    margin-bottom: 0;
    min-width: 720px;
}

.table-responsive.table-stack-mobile>.table {
    margin-bottom: 0;
    min-width: 0;
}

.table-responsive:not(.table-stack-mobile)>.table.table-no-stack {
    min-width: 0;
    width: 100%;
}

.table th,
.table td {
    vertical-align: middle;
}

.table thead th {
    white-space: nowrap;
}

.table td {
    max-width: 280px;
    white-space: normal;
}

/* * Standard application table — use: table table-bordered table-striped table-app mb-0 */
.table-app {
    --table-app-stripe-bg: #e9ecef;
    --table-app-row-bg: #ffffff;
    --table-app-row-hover-bg: #dee2e6;
    margin-bottom: 0;
}

html[data-bs-theme="dark"] .table-app {
    --table-app-stripe-bg: #2d2d3f;
    --table-app-row-bg: #1e1e2d;
    --table-app-row-hover-bg: #3a3a50;
}

.table-app > :not(caption) > * > * {
    padding: 0.65rem 0.75rem;
}

.table-app thead th {
    background-color: var(--bs-tertiary-bg);
    border-bottom-width: 2px;
    font-size: 0.8125rem;
    font-weight: 600;
}

html[data-bs-theme="dark"] .table-app thead th {
    background-color: rgba(255, 255, 255, 0.04);
}

/* * Zebra striping — explicit background so it works with Bootstrap + DataTables */
.table-app tbody tr:nth-of-type(odd) > td,
.table-app tbody tr:nth-of-type(odd) > th {
    background-color: var(--table-app-stripe-bg) !important;
    box-shadow: none !important;
}

.table-app tbody tr:nth-of-type(even) > td,
.table-app tbody tr:nth-of-type(even) > th {
    background-color: var(--table-app-row-bg) !important;
    box-shadow: none !important;
}

table.table-app.dataTable tbody tr:nth-of-type(odd) > td,
table.table-app.dataTable tbody tr:nth-of-type(odd) > th {
    background-color: var(--table-app-stripe-bg) !important;
    box-shadow: none !important;
}

table.table-app.dataTable tbody tr:nth-of-type(even) > td,
table.table-app.dataTable tbody tr:nth-of-type(even) > th {
    background-color: var(--table-app-row-bg) !important;
    box-shadow: none !important;
}

.table-app tbody tr:hover > td,
.table-app tbody tr:hover > th,
table.table-app.dataTable tbody tr:hover > td,
table.table-app.dataTable tbody tr:hover > th {
    background-color: var(--table-app-row-hover-bg) !important;
    box-shadow: none !important;
}

/* * Toolbar area above tables (actions, filters) */
.page-toolbar {
    align-items: flex-start;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    margin-bottom: 1rem;
}

.page-toolbar > .btn,
.page-toolbar > a.btn,
.page-toolbar > button.btn {
    width: auto;
}

.page-toolbar .toolbar-actions,
.page-toolbar .toolbar-filters {
    align-self: stretch;
    width: 100%;
}

/* * Scroll hint for wide tables on touch devices */
.table-scroll-hint {
    color: #6c757d;
    display: none;
    font-size: 0.75rem;
    margin-top: 0.35rem;
    text-align: center;
}

html[data-bs-theme="dark"] .table-scroll-hint {
    color: #a0aec0;
}

.modal-footer {
    gap: 0.5rem;
}

.theme-toggle {
    flex-shrink: 0;
    white-space: nowrap;
}

.theme-toggle .form-switch {
    margin-bottom: 0;
    min-height: auto;
    min-width: 2.5rem;
    padding-left: 0;
}

.theme-toggle .form-switch .form-check-input {
    appearance: none;
    background-color: #d8dee9;
    background-image: none !important;
    border: 0;
    border-radius: 999px;
    box-shadow: inset 0 0 0 1px rgba(90, 103, 128, 0.22);
    height: 1.25rem;
    margin-left: 0;
    position: relative;
    transition: background-color 0.2s ease, box-shadow 0.2s ease;
    width: 2.5rem;
}

.theme-toggle .form-switch .form-check-input::before {
    background-color: #ffffff;
    border-radius: 50%;
    box-shadow: 0 1px 3px rgba(15, 23, 42, 0.25);
    content: "";
    height: 0.95rem;
    left: 0.15rem;
    position: absolute;
    top: 0.15rem;
    transition: transform 0.2s ease;
    width: 0.95rem;
}

.theme-toggle .form-switch .form-check-input:checked {
    background-color: var(--dashboard-accent);
    box-shadow: none;
}

.theme-toggle .form-switch .form-check-input:checked::before {
    transform: translateX(1.25rem);
}

.theme-toggle .form-switch .form-check-input:focus {
    box-shadow: 0 0 0 0.15rem rgba(67, 94, 190, 0.25);
}

/* * Bottom navigation */
#bottom-bar {
    width: 100%;
    background: #fff;
    position: fixed;
    bottom: 0;
    left: 0;
    display: none;
    justify-content: space-around;
    align-items: stretch;
    border-top: 1px solid #e0e0e0;
    box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.08);
    transition: 0.3s;
    z-index: 1030;
    padding-bottom: env(safe-area-inset-bottom, 0);
    min-height: calc(56px + env(safe-area-inset-bottom, 0));
}

#sidebar {
    position: relative;
    z-index: 1040;
}

.sidebar-backdrop {
    z-index: 1035;
}

.sidebar-wrapper {
    z-index: 1040;
}

.bottom-bar-element {
    align-items: center;
    color: #607080;
    display: flex;
    flex: 1;
    flex-direction: column;
    font-size: 11px;
    justify-content: center;
    min-height: 56px;
    padding: 6px 4px;
    text-align: center;
    text-decoration: none;
    transition: 0.3s;
}

.bottom-bar-element i {
    display: block;
    font-size: 24px;
    margin-bottom: 2px;
}

.bottom-bar-element-active {
    color: var(--dashboard-accent-deep);
}

.bottom-bar-element:hover {
    color: #78909c;
}

/* * Light mode */
html[data-bs-theme="light"] #bottom-bar {
    background: #ffffff;
    border-top: 1px solid #e0e0e0;
    box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.08);
}

html[data-bs-theme="light"] .bottom-bar-element {
    color: #607080;
}

html[data-bs-theme="light"] .bottom-bar-element-active {
    color: var(--dashboard-accent-deep);
}

/* * Dark mode */
html[data-bs-theme="dark"] #bottom-bar {
    background: #1e1e2d;
    border-top: 1px solid #2a2a2a;
    box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.4);
}

html[data-bs-theme="dark"] .bottom-bar-element {
    color: #9e9e9e;
}

html[data-bs-theme="dark"] .bottom-bar-element-active {
    color: #ffffff;
}

/* * Mobile layout */
@media screen and (max-width: 768px) {
    #bottom-bar {
        display: flex;
    }

    #main {
        padding: 1rem 0.75rem 0.75rem;
    }

    body {
        padding-bottom: calc(70px + env(safe-area-inset-bottom, 0));
    }

    .burger-btn {
        align-items: center;
        display: inline-flex;
        min-height: 44px;
        min-width: 44px;
        padding: 0.35rem;
    }

    header.mb-3 {
        margin-bottom: 0.75rem !important;
    }

    .page-heading {
        margin-bottom: 1rem;
    }

    .row {
        --bs-gutter-y: 0.75rem;
    }

    .card {
        border-radius: 0.9rem;
        margin-bottom: 1rem;
    }

    .card-body {
        padding: 1rem;
    }

    .page-heading .d-flex.justify-content-between,
    .page-heading .d-flex.align-items-start {
        align-items: flex-start !important;
        flex-direction: column;
        gap: 0.75rem;
    }

    .page-heading p,
    .card-text {
        line-height: 1.5;
    }

    .card-body>.d-flex.justify-content-between.align-items-center.mb-3,
    .card-body>.d-flex.justify-content-between.align-items-start.mb-3,
    form>.d-flex.justify-content-between.align-items-center.mb-3,
    form>.d-flex.justify-content-between.align-items-start.mb-3 {
        align-items: flex-start !important;
        flex-direction: column;
        gap: 0.75rem;
    }

    .card-body>.d-flex.justify-content-between.align-items-start.mb-3>.text-end {
        text-align: start !important;
    }

    .page-toolbar {
        margin-bottom: 0.75rem;
    }

    .table-responsive:not(.table-stack-mobile) {
        margin-left: -0.25rem;
        margin-right: -0.25rem;
        overflow-x: auto;
        padding-bottom: 0.25rem;
        -webkit-overflow-scrolling: touch;
    }

    .table-responsive.table-stack-mobile {
        margin-left: 0;
        margin-right: 0;
        overflow-x: visible;
    }

    .table-responsive:not(.table-stack-mobile)>.table {
        min-width: 640px;
    }

    .table-scroll-hint {
        display: block;
    }

    form>a.btn+button.btn,
    form>button.btn+button.btn,
    form>.btn+.btn {
        margin-top: 0.5rem;
    }

    /* * Card-style stacked rows for standard tables */
    .table-responsive.table-stack-mobile>.table.table-mobile-stack {
        border: 0;
        min-width: 0;
    }

    .table-mobile-stack thead {
        display: none;
    }

    .table-mobile-stack tbody tr {
        background: var(--bs-body-bg, #fff);
        border: 1px solid var(--bs-border-color, #dee2e6);
        border-radius: 0.75rem;
        box-shadow: 0 1px 4px rgba(15, 23, 42, 0.06);
        display: block;
        margin-bottom: 0.85rem;
        padding: 0.65rem 0.85rem;
    }

    .table-mobile-stack tbody tr:nth-of-type(odd) {
        background: #e9ecef;
    }

    .table-mobile-stack tbody tr:nth-of-type(even) {
        background: #ffffff;
    }

    html[data-bs-theme="dark"] .table-mobile-stack tbody tr {
        background: #1e1e2d;
        border-color: #2d2d3f;
    }

    html[data-bs-theme="dark"] .table-mobile-stack tbody tr:nth-of-type(odd) {
        background: #2d2d3f;
    }

    .table-mobile-stack tbody td,
    .table-mobile-stack tbody th {
        background-color: transparent !important;
        box-shadow: none !important;
    }

    .table-mobile-stack tbody td {
        align-items: flex-start;
        border: 0;
        border-bottom: 1px solid rgba(0, 0, 0, 0.06);
        display: flex;
        gap: 0.75rem;
        justify-content: space-between;
        max-width: none;
        padding: 0.55rem 0;
        text-align: right;
        white-space: normal;
    }

    html[data-bs-theme="dark"] .table-mobile-stack tbody td {
        border-bottom-color: rgba(255, 255, 255, 0.08);
    }

    .table-mobile-stack tbody td:last-child {
        border-bottom: 0;
    }

    .table-mobile-stack tbody td::before {
        color: #6c757d;
        content: attr(data-label);
        flex: 0 0 42%;
        font-size: 0.72rem;
        font-weight: 600;
        letter-spacing: 0.02em;
        text-align: left;
        text-transform: uppercase;
    }

    html[data-bs-theme="dark"] .table-mobile-stack tbody td::before {
        color: #a0aec0;
    }

    .table-mobile-stack tbody td[colspan] {
        display: block;
        text-align: center;
    }

    .table-mobile-stack tbody td[colspan]::before {
        display: none;
    }

    .table-mobile-stack tbody td.cell-actions {
        align-items: stretch;
        flex-direction: column;
    }

    .table-mobile-stack tbody td.cell-actions::before {
        margin-bottom: 0.25rem;
    }

    .table-mobile-stack tbody td.cell-actions .d-flex {
        flex-wrap: wrap !important;
        gap: 0.5rem !important;
        justify-content: flex-start !important;
        white-space: normal !important;
    }

    .table-mobile-stack tbody td.cell-actions .btn {
        flex: 0 0 auto;
        width: auto;
    }

    .table-mobile-stack tbody td ul {
        list-style: none;
        margin-bottom: 0;
        padding-left: 0;
        text-align: left;
        width: 100%;
    }

    .table-mobile-stack tbody td ul li + li {
        margin-top: 0.25rem;
    }

    .table th,
    .table td {
        font-size: 0.875rem;
        padding: 0.65rem;
    }

    .table:not(.table-mobile-stack) td .d-flex.gap-1,
    .table:not(.table-mobile-stack) td .d-flex.gap-2 {
        flex-wrap: nowrap;
        white-space: nowrap;
    }

    .table td .btn-sm {
        min-height: 36px;
        padding: 0.35rem 0.55rem;
    }

    /* * DataTables mobile toolbar */
    .dataTables_wrapper .row {
        margin-left: 0;
        margin-right: 0;
    }

    .dataTables_wrapper .dataTables_length,
    .dataTables_wrapper .dataTables_filter {
        float: none !important;
        margin-bottom: 0.75rem;
        text-align: left;
        width: 100%;
    }

    .dataTables_wrapper .dataTables_filter input {
        margin-left: 0 !important;
        margin-top: 0.35rem;
        width: 100% !important;
    }

    .dataTables_wrapper .dataTables_info,
    .dataTables_wrapper .dataTables_paginate {
        float: none !important;
        margin-top: 0.5rem;
        text-align: center;
        width: 100%;
    }

    .dataTables_wrapper .dt-buttons {
        display: flex;
        flex-wrap: wrap;
        gap: 0.5rem;
        justify-content: flex-start;
        margin-bottom: 0.75rem;
        width: 100%;
    }

    .dataTables_wrapper .dt-buttons .btn {
        flex: 0 0 auto;
        width: auto;
    }

    .dataTables_wrapper .pagination {
        justify-content: center;
    }

    .input-group {
        min-width: 0;
    }

    .input-group>.form-control,
    .input-group>.form-select {
        min-width: 0;
    }

    .pagination {
        flex-wrap: wrap;
        justify-content: center;
        row-gap: 0.35rem;
    }

    .table-responsive+.d-flex.justify-content-end,
    .table-responsive .d-flex.justify-content-end {
        justify-content: center !important;
    }

    .footer {
        display: flex;
        flex-direction: column;
        gap: 0.35rem;
        text-align: center;
    }

    .footer .float-start,
    .footer .float-end {
        float: none !important;
    }

    .modal-dialog {
        margin: 0.75rem;
    }

    .modal-footer {
        align-items: stretch;
        flex-direction: column;
    }
}

@media screen and (max-width: 575.98px) {
    #main {
        padding-left: 0.65rem;
        padding-right: 0.65rem;
    }

    .card-body {
        padding: 0.9rem;
    }

    .btn {
        white-space: normal;
    }

    .row {
        --bs-gutter-x: 0.75rem;
    }

    .input-group .btn,
    .input-group .input-group-text {
        padding-left: 0.65rem;
        padding-right: 0.65rem;
    }

    .input-group .input-group-text {
        white-space: nowrap;
    }

    .d-flex.gap-2:not(.theme-toggle):not(.btn-icon-group),
    .d-flex.gap-1:not(.btn-icon-group) {
        flex-wrap: wrap;
    }

    .chart-wrap {
        height: 220px !important;
    }

    .chart-wrap--compact {
        height: 200px !important;
    }

    .chart-wrap--bar {
        height: 220px !important;
    }

    .input-group {
        flex-wrap: wrap;
    }

    .input-group>.form-control,
    .input-group>.form-select {
        flex: 1 1 100%;
        min-width: 0;
    }

    .input-group>.btn,
    .input-group>a.btn {
        flex: 1 1 auto;
    }
}

/* * Tablet layout (sidebar overlay, no bottom bar) */
@media screen and (min-width: 769px) and (max-width: 1199.98px) {
    #main {
        padding: 1.25rem 1rem;
    }

    .page-heading h3 {
        font-size: 1.5rem;
    }

    .table-responsive:not(.table-stack-mobile)>.table {
        min-width: 680px;
    }
}

/* * Desktop layout */
@media screen and (min-width: 769px) {
    #bottom-bar {
        display: none;
    }

    #main {
        padding-left: 1.25rem;
        padding-right: 1.25rem;
    }
}

/* * Chrome, Safari, and Edge */
input[type="number"]::-webkit-outer-spin-button,
input[type="number"]::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

/* * Firefox */
input[type="number"] {
    appearance: textfield;
    -moz-appearance: textfield;
}

/* * Select2 dark mode uses Bootstrap data-bs-theme="dark". */
html[data-bs-theme="dark"] .select2-container--default .select2-selection--single {
    background-color: #1e1e2d !important;
    border: 1px solid #555 !important;
    height: 38px;
}

html[data-bs-theme="dark"] .select2-container--default .select2-selection--single .select2-selection__rendered {
    color: #ffffff !important;
    line-height: 36px;
}

html[data-bs-theme="dark"] .select2-container--default .select2-selection--single .select2-selection__placeholder {
    color: #b5b5c3 !important;
}

html[data-bs-theme="dark"] .select2-container--default .select2-selection--single .select2-selection__arrow b {
    border-color: #ffffff transparent transparent transparent !important;
}

html[data-bs-theme="dark"] .select2-dropdown {
    background-color: #1e1e2d !important;
    border: 1px solid #555 !important;
}

html[data-bs-theme="dark"] .select2-search--dropdown .select2-search__field {
    background-color: #2a2a3c !important;
    color: #ffffff !important;
    border: 1px solid #555 !important;
}

html[data-bs-theme="dark"] .select2-results__option {
    background-color: #1e1e2d !important;
    color: #ffffff !important;
}

html[data-bs-theme="dark"] .select2-results__option--highlighted {
    background-color: var(--dashboard-accent) !important;
    color: #ffffff !important;
}

html[data-bs-theme="dark"] .select2-results__option[aria-selected="true"] {
    background-color: var(--dashboard-accent-deep) !important;
    color: #ffffff !important;
}

html[data-bs-theme="dark"] .select2-container--default .select2-selection--multiple {
    background-color: #1e1e2d !important;
    border: 1px solid #555 !important;
}

html[data-bs-theme="dark"] .select2-container--default .select2-selection--multiple .select2-selection__choice {
    background-color: var(--dashboard-accent) !important;
    border: none !important;
    color: #ffffff !important;
}

html[data-bs-theme="dark"] .select2-selection__choice__remove {
    color: #ffffff !important;
}

html[data-bs-theme="dark"] .select2-container--default.select2-container--focus .select2-selection--single,
html[data-bs-theme="dark"] .select2-container--default.select2-container--focus .select2-selection--multiple {
    border-color: var(--dashboard-accent) !important;
    box-shadow: 0 0 0 0.2rem rgba(67, 94, 190, 0.25);
}
