:root {
    --app-sidebar-width: 220px;
    --app-topbar-height: 3rem;
    --app-footer-height: 2.25rem;
    --app-page-padding: 1rem;
    --app-font-size: 0.8125rem;
    --app-line-height: 1.4;

    --app-bg: #f5f7fa;
    --app-surface: #fff;
    --app-surface-hover: #f8f9fa;
    --app-border: #e9ecef;
    --app-border-strong: #dee2e6;
    --app-text: #212529;
    --app-text-secondary: var(--brand-gray);
    --app-sidebar-nav: #343a40;
    --app-sidebar-hover-bg: var(--brand-primary-subtle);
    --app-sidebar-group: #5c5c5c;
    --app-topbar-user: var(--brand-gray-strong);
    --app-btn-primary-hover: var(--brand-primary-hover);
    --app-btn-primary-active: var(--brand-primary-active);
    --app-btn-border-mix-light: 76%;
    --app-btn-border-mix-saturated: 48%;
    --app-btn-border-mix-color: #000;
    --app-focus-border: var(--brand-primary-focus);
    --app-focus-shadow: var(--brand-primary-focus-shadow);
    --app-shadow-sm: rgba(0,0,0,.08);
}

[data-bs-theme="dark"] {
    --app-bg: #1a1d23;
    --app-surface: #21252b;
    --app-surface-hover: #2a2e36;
    --app-border: #2d3138;
    --app-border-strong: #383c44;
    --app-text: #e4e7eb;
    --app-text-secondary: var(--brand-gray-on-dark);
    --app-sidebar-nav: var(--brand-gray-on-dark);
    --app-sidebar-hover-bg: rgba(var(--brand-primary-rgb), 0.1);
    --app-sidebar-group: var(--brand-gray);
    --app-topbar-user: #d1d5db;
    --app-btn-primary-hover: var(--brand-primary-hover);
    --app-btn-primary-active: var(--brand-primary-active);
    --app-btn-border-mix-light: 76%;
    --app-btn-border-mix-saturated: 40%;
    --app-btn-border-mix-color: #000;
    --app-focus-border: var(--brand-primary-accent);
    --app-focus-shadow: rgba(var(--brand-primary-accent-rgb), 0.35);
    --app-shadow-sm: rgba(0,0,0,.3);
}

html.app-desktop {
    min-width: 1280px;
}

body.app-desktop {
    background-color: var(--app-bg);
    font-size: var(--app-font-size);
    line-height: var(--app-line-height);
}

body {
    background-color: var(--app-bg);
    color: var(--app-text);
    font-family: var(--bs-font-sans-serif);
}

.sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: var(--app-sidebar-width);
    height: 100vh;
    background-color: var(--app-surface);
    color: var(--app-text);
    z-index: 1040;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
}

.sidebar-header {
    padding: 0.65rem 1rem;
    border-bottom: 1px solid var(--app-border);
    text-align: center;
}

.sidebar-brand {
    color: var(--bs-primary);
    text-decoration: none;
    font-size: 1rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: .5rem;
}

.sidebar-brand:hover {
    color: var(--bs-link-hover-color);
}

.sidebar-brand img {
    max-width: 100%;
    height: auto;
}

.sidebar-nav {
    flex: 1 1 auto;
    padding-bottom: 0.5rem;
}

.sidebar .nav-link {
    color: var(--app-sidebar-nav);
    padding: 0.42rem 0.9rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.8125rem;
    border-left: 3px solid transparent;
    transition: background-color .15s, color .15s, border-color .15s;
}

.sidebar .nav-link:hover {
    background-color: var(--app-sidebar-hover-bg);
    color: var(--bs-primary);
}

.sidebar .nav-link i {
    font-size: 0.9rem;
    width: 1.1rem;
    text-align: center;
}

.sidebar .nav-link.active {
    background-color: var(--app-sidebar-hover-bg);
    color: var(--bs-primary);
    border-left-color: var(--bs-primary);
    font-weight: 600;
}

.sidebar-nav-group {
    list-style: none;
    margin: 0.65rem 0 0.2rem;
    padding: 0 0.9rem 0.15rem;
    font-size: 0.62rem;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--app-sidebar-group);
}

.sidebar-nav .nav-item:first-child,
.sidebar-nav-group:first-child {
    margin-top: 0.35rem;
}

.sidebar .nav-link .badge {
    margin-left: auto;
}

.sidebar-footer {
    border-top: 1px solid var(--app-border);
    padding: 0.65rem 0.9rem;
    margin-top: auto;
}

.sidebar-theme-toggle {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.35rem 0;
    cursor: pointer;
    color: var(--app-sidebar-nav);
    font-size: 0.75rem;
    border: none;
    background: none;
    width: 100%;
    transition: color .15s;
}

.sidebar-theme-toggle:hover {
    color: var(--bs-primary);
}

.sidebar-theme-toggle i {
    font-size: 0.9rem;
    width: 1.1rem;
    text-align: center;
}

.app-topbar {
    position: fixed;
    top: 0;
    left: var(--app-sidebar-width);
    right: 0;
    z-index: 1035;
    height: var(--app-topbar-height);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 0 1rem 0 1.25rem;
    background: var(--app-surface);
    border-bottom: 1px solid var(--app-border);
}

.app-topbar-start {
    min-width: 0;
    flex: 1 1 auto;
}

.app-topbar-title {
    font-size: 0.95rem;
    font-weight: 600;
    margin: 0;
    color: var(--app-text);
}

.app-topbar-end {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    margin-left: auto;
    flex-shrink: 0;
}

.app-topbar-user {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.25rem 0.5rem;
    border: 0;
    border-radius: 0.375rem;
    background: transparent;
    color: var(--app-topbar-user);
    font-size: 0.8125rem;
}

.app-topbar-user::after {
    margin-left: 0.15rem;
}

.app-topbar-user-name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 12rem;
}

.app-topbar-user:hover,
.app-topbar-user:focus {
    background: var(--app-surface-hover);
    color: var(--bs-primary);
}

.main-content {
    margin-left: var(--app-sidebar-width);
    padding-top: var(--app-topbar-height);
    padding-bottom: var(--app-footer-height);
    min-height: 100vh;
}

.app-page {
    padding: var(--app-page-padding) 1.25rem;
    max-width: 1680px;
}

.app-footer {
    position: fixed;
    bottom: 0;
    left: var(--app-sidebar-width);
    right: 0;
    z-index: 1030;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    height: var(--app-footer-height);
    font-size: 0.68rem;
    padding: 0.35rem 1.25rem 0;
    background: var(--app-surface);
    border-top: 1px solid var(--app-border);
    color: var(--app-text-secondary);
}

.btn {
    border-radius: 8px;
    font-weight: 500;
    border-width: 1px;
}

.btn-sm {
    border-radius: 6px;
}

.btn-primary {
    --bs-btn-bg: var(--bs-primary);
    --bs-btn-border-color: color-mix(in srgb, var(--bs-primary) var(--app-btn-border-mix-saturated), var(--app-btn-border-mix-color));
    --bs-btn-hover-bg: var(--app-btn-primary-hover);
    --bs-btn-hover-border-color: color-mix(in srgb, var(--app-btn-primary-hover) var(--app-btn-border-mix-saturated), var(--app-btn-border-mix-color));
    --bs-btn-active-bg: var(--app-btn-primary-active);
    --bs-btn-active-border-color: color-mix(in srgb, var(--app-btn-primary-active) var(--app-btn-border-mix-saturated), var(--app-btn-border-mix-color));
}

.form-control:focus,
.form-select:focus,
.btn:focus-visible {
    border-color: var(--app-focus-border);
    box-shadow: 0 0 0 .25rem var(--app-focus-shadow);
}

.form-control,
.form-select {
    background-color: var(--app-surface);
    color: var(--app-text);
    border-color: var(--app-border);
}

a {
    color: var(--bs-link-color);
}

a:hover {
    color: var(--bs-link-hover-color);
}

.card {
    border: none;
    box-shadow: 0 0 0 1.5px var(--bs-primary), 0 1px 3px var(--app-shadow-sm);
    border-radius: .5rem;
    background-color: var(--app-surface);
    color: var(--app-text);
    overflow: hidden;
}

.card-header {
    background-color: var(--app-surface);
    border-bottom: 1px solid var(--app-border);
    font-weight: 600;
}

.card-footer {
    background-color: var(--app-surface);
    border-top: 1px solid var(--app-border);
    color: var(--app-text);
}

.table {
    color: var(--app-text);
    --bs-table-bg: transparent;
    --bs-table-border-color: var(--app-border);
}

.table th {
    font-weight: 600;
    font-size: .8rem;
    text-transform: uppercase;
    letter-spacing: .03em;
    color: var(--app-text-secondary);
}

.table td {
    vertical-align: middle;
}

[data-bs-theme="dark"] .bg-light:not(.badge),
[data-bs-theme="dark"] .bg-white {
    background-color: var(--app-surface-hover) !important;
    color: var(--app-text);
}

[data-bs-theme="dark"] .table-light {
    --bs-table-bg: var(--app-surface-hover);
    --bs-table-color: var(--app-text);
    --bs-table-border-color: var(--app-border);
}

.page-link {
    background-color: var(--app-surface);
    color: var(--bs-link-color);
    border-color: var(--app-border);
}

.page-link:hover {
    background-color: var(--app-surface-hover);
    color: var(--bs-link-hover-color);
    border-color: var(--app-border);
}

.page-item.active .page-link {
    background-color: var(--bs-primary);
    border-color: var(--bs-primary);
}

.dashboard-stat-section-title {
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--app-text-secondary);
    margin-bottom: 0.5rem;
}

.dashboard-stat-grid {
    --bs-gutter-x: 0.75rem;
    --bs-gutter-y: 0.75rem;
}

.dashboard-stat-grid .dashboard-stat-card .card-body {
    padding: 0.65rem 0.5rem;
}

.dashboard-stat-grid .dashboard-stat-card .stat-icon {
    font-size: 1.2rem;
    line-height: 1;
    margin-bottom: 0.2rem;
}

.dashboard-stat-grid .dashboard-stat-card .stat-value {
    font-size: 1.15rem;
    font-weight: 700;
    line-height: 1.15;
}

.dashboard-stat-grid .dashboard-stat-card .stat-label {
    font-size: 0.68rem;
    color: var(--app-text-secondary);
    margin-top: 0.1rem;
    line-height: 1.2;
}

.dashboard-stat-card {
    border-color: var(--app-border);
}

.dashboard-stat-card .stat-icon,
.dashboard-stat-card.app-stat-neutral .stat-value {
    color: var(--app-text-secondary);
}

.dashboard-stat-card.app-stat-highlight {
    border-color: var(--bs-primary);
}

.dashboard-stat-card.app-stat-highlight .stat-icon,
.dashboard-stat-card.app-stat-highlight .stat-value {
    color: var(--bs-primary);
}

.dashboard-stat-card.app-stat-attention {
    border-color: rgba(var(--bs-warning-rgb), 0.55);
}

.dashboard-stat-card.app-stat-attention .stat-icon,
.dashboard-stat-card.app-stat-attention .stat-value {
    color: var(--bs-warning);
}

.dashboard-stat-card.app-stat-critical {
    border-color: rgba(var(--bs-danger-rgb), 0.55);
}

.dashboard-stat-card.app-stat-critical .stat-icon,
.dashboard-stat-card.app-stat-critical .stat-value {
    color: var(--bs-danger);
}

[data-bs-theme="dark"] .dashboard-stat-card.app-stat-attention .stat-icon,
[data-bs-theme="dark"] .dashboard-stat-card.app-stat-attention .stat-value {
    color: #ffda6a;
}

body.app-desktop h4,
body.app-desktop .h4 {
    font-size: 1.2rem;
    margin-bottom: 0.65rem;
}

body.app-desktop h5,
body.app-desktop .h5 {
    font-size: 1.05rem;
}

body.app-desktop h6,
body.app-desktop .h6 {
    font-size: 0.95rem;
}

body.app-desktop .card-header {
    padding: 0.55rem 0.85rem;
    font-size: 0.85rem;
}

body.app-desktop .card-body {
    padding: 0.85rem;
}

body.app-desktop .table {
    font-size: 0.8125rem;
}

body.app-desktop .form-control {
    font-size: 0.8125rem;
    padding: 0.35rem 0.65rem;
}

body.app-desktop .form-select {
    font-size: 0.8125rem;
    padding: 0.35rem 2rem 0.35rem 0.65rem;
}

.alert {
    border-radius: 0.5rem;
}

.text-muted {
    color: var(--app-text-secondary) !important;
}

.dropdown-menu {
    background-color: var(--app-surface);
    border-color: var(--app-border);
    color: var(--app-text);
}

.dropdown-item {
    color: var(--app-text);
}

.dropdown-item:hover,
.dropdown-item:focus {
    background-color: var(--app-surface-hover);
    color: var(--app-text);
}

.dropdown-header {
    color: var(--app-text-secondary);
}

.dropdown-divider {
    border-color: var(--app-border);
}

.badge.bg-warning {
    color: #212529;
}

[data-bs-theme="dark"] .badge.bg-warning {
    color: #212529;
}

.list-group-item {
    background-color: var(--app-surface);
    color: var(--app-text);
    border-color: var(--app-border);
}

.input-group-text {
    background-color: var(--app-surface-hover);
    color: var(--app-text-secondary);
    border-color: var(--app-border);
}

code {
    color: var(--bs-primary);
}

[data-bs-theme="dark"] code {
    color: var(--brand-primary-accent);
}
