:root {
    --primary: #1f6f5b;
    --primary-rgb: 31, 111, 91;
    --bg: #f5f7fb;
    --bg-alt: #eef1f6;
    --surface: #ffffff;
    --surface-subtle: color-mix(in srgb, var(--surface) 94%, #0b1021 6%);
    --surface-strong: color-mix(in srgb, var(--surface) 86%, #0b1021 14%);
    --border: #e3e8ef;
    --muted: #6b7280;
    --text: color-mix(in srgb, var(--muted) 32%, #0b1324 68%);
    --text-muted: var(--muted);
    --primary-600: color-mix(in srgb, var(--primary) 82%, #0b1021 18%);
    --primary-100: color-mix(in srgb, var(--primary) 12%, #ffffff 88%);
    --sidebar-bg: color-mix(in srgb, var(--primary) 22%, #0b1021 78%);
    --focus-ring: rgba(var(--primary-rgb), 0.35);
    --success: #22c55e;
    --warning: #f59e0b;
    --danger: #ef4444;
    --radius: 0.2rem;
    --shadow: 0 2px 8px rgba(15, 23, 42, 0.06);
    --shadow-soft: 0 1px 4px rgba(15, 23, 42, 0.08);
    --sidebar-width: 250px;
    --sidebar-collapsed-width: 78px;
    --content-padding: 32px;
    --skeleton: #e9edf3;
    --overlay: rgba(255, 255, 255, 0.7);
    --code-bg: color-mix(in srgb, var(--surface) 90%, #0b1021 10%);
    --sidebar-active-text: #ffffff;

    --bs-primary: var(--primary);
    --bs-primary-rgb: var(--primary-rgb);
    --bs-body-bg: var(--bg);
    --bs-body-color: var(--text);
    --bs-border-color: var(--border);
    --bs-card-bg: var(--surface);
    --bs-card-border-color: var(--border);
    --bs-card-cap-bg: var(--surface-subtle);
    --bs-dropdown-bg: var(--surface);
    --bs-dropdown-link-color: var(--text);
    --bs-dropdown-link-hover-bg: rgba(var(--primary-rgb), 0.08);
    --bs-dropdown-link-hover-color: var(--text);
    --bs-dropdown-border-color: var(--border);
    --bs-navbar-bg: var(--surface);
    --bs-offcanvas-bg: var(--surface);
    --bs-modal-bg: var(--surface);
    --bs-modal-border-color: var(--border);
    --bs-table-bg: var(--surface);
    --bs-table-border-color: var(--border);
    --bs-secondary-bg: var(--surface-subtle);
}

:root[data-theme="dark"] {
    color-scheme: dark;
    --primary: #0d6efd;
    --primary-rgb: 0, 74, 119;
    --bg: #121212;
    --bg-alt: #171717;
    --surface: #1d1d1d;
    --surface-subtle: #222222;
    --surface-strong: #262626;
    --border: #2a2a2a;
    --muted: #b0b0b0;
    --text: #e0e0e0;
    --text-muted: #b0b0b0;
    --primary-600: color-mix(in srgb, var(--primary) 82%, #0b1021 18%);
    --primary-100: color-mix(in srgb, var(--primary) 18%, #ffffff 82%);
    --sidebar-bg: #171717;
    --focus-ring: rgba(var(--primary-rgb), 0.45);
    --shadow: 0 2px 8px rgba(0, 0, 0, 0.35);
    --shadow-soft: 0 1px 4px rgba(0, 0, 0, 0.45);
    --overlay: rgba(18, 18, 18, 0.7);
    --code-bg: #1f1f1f;
    --skeleton: #1f1f1f;
    --sidebar-active-text: #ffffff;
    --danger: #ef9a9a;

    --bs-primary: var(--primary);
    --bs-primary-rgb: var(--primary-rgb);
    --bs-body-bg: var(--bg);
    --bs-body-color: var(--text);
    --bs-border-color: var(--border);
    --bs-card-bg: var(--surface);
    --bs-card-border-color: var(--border);
    --bs-card-cap-bg: var(--surface-subtle);
    --bs-dropdown-bg: var(--surface);
    --bs-dropdown-link-color: var(--text);
    --bs-dropdown-link-hover-bg: rgba(var(--primary-rgb), 0.16);
    --bs-dropdown-link-hover-color: var(--text);
    --bs-dropdown-border-color: var(--border);
    --bs-navbar-bg: var(--surface);
    --bs-offcanvas-bg: var(--surface);
    --bs-modal-bg: var(--surface);
    --bs-modal-border-color: var(--border);
    --bs-table-bg: var(--surface);
    --bs-table-border-color: var(--border);
    --bs-secondary-bg: var(--surface-subtle);
}

:root[data-theme="dark"] .btn-primary,
:root[data-theme="dark"] .bg-primary,
:root[data-theme="dark"] .text-bg-primary,
:root[data-theme="dark"] .badge.bg-primary,
:root[data-theme="dark"] .badge.text-bg-primary,
:root[data-theme="dark"] .nav-pills .nav-link.active,
:root[data-theme="dark"] .list-group-item.active {
    color: #ffffff;
}

* {
    box-sizing: border-box;
}

body {
    font-family: system-ui, -apple-system, "Segoe UI", "Roboto", "Helvetica Neue", Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    font-size: 15px;
    font-weight: 400;
    line-height: 1.5;
    letter-spacing: 0.01em;
}

a {
    color: var(--primary);
    text-decoration: none;
    font-weight: 500;
}

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

a:focus-visible {
    outline: 3px solid var(--focus-ring);
    outline-offset: 2px;
}

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

h1, .h1 {
    font-size: 24px;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 0.25rem;
}

h2, .h2 {
    font-size: 18px;
    font-weight: 600;
    color: var(--text);
}

h3, .h3 {
    font-size: 16px;
    font-weight: 600;
    color: var(--text);
}

p {
    color: var(--text);
}

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

small, .small {
    font-size: 0.88rem;
}

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

.bg-body-secondary {
    background: var(--bg-alt) !important;
}

.bg-white {
    background: var(--surface) !important;
    color: var(--text) !important;
}

.bg-light {
    background: var(--surface-subtle) !important;
    color: var(--text) !important;
}

code {
    background: var(--code-bg);
    padding: 0.25rem 0.4rem;
    border-radius: 0.45rem;
    border: 1px solid var(--border);
}

:focus-visible {
    outline: 3px solid var(--focus-ring);
    outline-offset: 2px;
}

.app-body {
    min-height: 100vh;
    background: var(--bg);
}

.app-shell {
    display: flex;
    min-height: 100vh;
    background: var(--bg);
}

.app-main {
    flex: 1;
    min-width: 0;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    background: var(--bg);
}

.app-content {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 0;
    background: var(--bg);
    padding: 0;
    overflow-x: hidden;
}

.app-content > .container-fluid {
    flex: 1;
    padding: 0;
    width: 100%;
}

.app-content .row {
    margin-left: 0;
    margin-right: 0;
}

.app-topbar {
    background: var(--surface);
    border-bottom: 1px solid color-mix(in srgb, var(--border) 85%, transparent 15%);
    position: sticky;
    top: 0;
    z-index: 1020;
    padding: 0.6rem 1rem;
    box-shadow: none;
    backdrop-filter: none;
}

.app-topbar .container-fluid {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    flex-wrap: nowrap;
}

.app-topbar .container-fluid > .d-flex {
    flex-wrap: nowrap;
    gap: 0.5rem;
    flex: 1 1 auto;
    min-width: 0;
}

.app-topbar .navbar-brand {
    padding: 0;
    margin: 0;
}

.app-brand .brand-text {
    white-space: nowrap;
}

.app-topbar .brand-logo {
    gap: 0.45rem;
}

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

.app-topbar-actions {
    flex: 0 1 auto;
    min-width: 0;
    justify-content: flex-end;
    flex-wrap: nowrap;
    gap: 0.4rem 0.6rem;
    margin-left: auto;
}

.app-topbar-actions > * {
    flex: 0 0 auto;
}

.app-topbar .btn {
    border-radius: 10px;
}

.app-topbar .input-group {
    height: 42px;
    border-radius: 10px;
    overflow: hidden;
    border: 1px solid var(--border);
    background: var(--surface-subtle);
}

.app-topbar .input-group-text,
.app-topbar .form-control {
    background: transparent;
    border: none;
    color: var(--text);
}

.app-topbar .form-control::placeholder {
    color: var(--text-muted);
}

.app-topbar .btn-outline-secondary {
    background: var(--surface-subtle);
}

.app-topbar .btn-outline-primary {
    background: var(--primary);
    color: #ffffff;
    border-color: var(--primary);
}

.app-topbar .btn-outline-primary:hover,
.app-topbar .btn-outline-primary:focus {
    background: var(--primary-600);
    border-color: var(--primary-600);
    color: #ffffff;
}

@media (max-width: 768px) {
    .app-topbar .container-fluid {
        gap: 0.6rem;
    }

    .app-topbar .container-fluid > .d-flex:last-child {
        width: auto;
        justify-content: flex-end;
        gap: 0.4rem 0.6rem;
    }

    .app-brand .brand-text {
        display: none;
    }

    .org-chip {
        display: none;
    }
}

@media (max-width: 992px) {
    .app-topbar .container-fluid {
        flex-direction: row;
        align-items: center;
        flex-wrap: nowrap;
    }

    .app-topbar .container-fluid > .d-flex {
        width: auto;
        justify-content: flex-start;
    }

    .app-topbar .container-fluid > .d-flex:last-child {
        justify-content: flex-end;
        gap: 0.4rem 0.6rem;
    }

    .app-topbar-brand {
        justify-content: flex-start;
    }

    .app-topbar-actions {
        justify-content: flex-end;
    }

    .app-quick-menu {
        margin-left: auto;
    }
}

@media (max-width: 576px) {
    .app-topbar {
        padding: 0.5rem 0.75rem;
    }

    .app-topbar-actions {
        width: auto;
        justify-content: flex-end;
    }

    .app-quick-menu {
        margin-left: auto;
    }
}

.app-shell .app-sidebar {
    width: var(--sidebar-width);
    background: var(--sidebar-bg);
    color: #e5e7eb;
    border-right: 1px solid rgba(255, 255, 255, 0.06);
    padding: 1.6rem 1.25rem;
    gap: 0.75rem;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    position: sticky;
    top: 0;
    align-self: flex-start;
    transition: width 0.2s ease, padding 0.2s ease;
}

.app-sidebar nav {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.nav-section {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
}

.nav-section-title {
    font-size: 0.68rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: rgba(255, 255, 255, 0.6);
    padding: 0.25rem 0.85rem;
}

.nav-section-items {
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
}

.app-sidebar-brand {
    padding: 0.25rem 0 0.9rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    margin-bottom: 0.85rem;
    display: flex;
    align-items: center;
    justify-content: center;
}

.app-sidebar .app-brand {
    color: #ffffff;
    text-decoration: none;
}

.app-sidebar-brand .brand-logo img {
    height: auto;
    max-height: var(--app-logo-height-sm, 32px);
    max-width: 100%;
    object-fit: contain;
}

.app-sidebar .sidebar-brand .brand-text {
    font-size: var(--app-title-size, clamp(1.2rem, 1.5vw + 0.65rem, 1.65rem));
    letter-spacing: 0.06em;
    line-height: 1.1;
    color: inherit;
    max-width: 180px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex-shrink: 1;
}

@media (max-width: 575px) {
    .app-sidebar .sidebar-brand .brand-text {
        font-size: var(--app-title-size, 1.25rem);
        max-width: 160px;
    }
}

.sidebar-toggle {
    position: absolute;
    right: 0;
    top: 50%;
    transform: translateY(-50%);
    width: 18px;
    height: 72px;
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--border);
    border-right: 0;
    transition: transform 0.2s ease, background 0.2s ease, color 0.2s ease, border-color 0.2s ease;
    z-index: 1021;
    opacity: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    line-height: 1;
    font-size: 0.9rem;
    border-top-right-radius: 0 !important;
    border-bottom-right-radius: 0 !important;
}

.sidebar-toggle i {
    display: inline-block;
    transition: transform 0.2s ease;
}

.sidebar-toggle:hover {
    background: var(--bg-alt);
    border-color: var(--border);
}

.app-sidebar .nav-link {
    color: rgba(255, 255, 255, 0.82);
    border-radius: 10px;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.65rem 0.85rem;
    border: 1px solid transparent;
    background: transparent;
    transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.app-sidebar .nav-link:hover {
    background: rgba(255, 255, 255, 0.06);
    color: #ffffff;
}

.app-sidebar .nav-link.active {
    background: rgba(var(--primary-rgb), 0.22);
    color: #ffffff;
    border-color: rgba(var(--primary-rgb), 0.45);
}

.app-body.sidebar-collapsed .app-sidebar {
    width: var(--sidebar-collapsed-width);
    padding: 1.6rem 0.75rem;
}

.app-body.sidebar-collapsed .sidebar-toggle {
    transform: translateY(-50%);
    right: 0;
}

.app-body.sidebar-collapsed .sidebar-toggle i {
    transform: rotate(180deg);
}

.app-body.sidebar-collapsed .app-sidebar-brand {
    padding: 0.25rem 0 0.5rem;
    margin-bottom: 0.6rem;
    justify-content: center;
    border-bottom-color: rgba(255, 255, 255, 0.04);
}

.app-body.sidebar-collapsed .app-sidebar-brand .brand-text {
    display: none;
}

.app-body.sidebar-collapsed .app-sidebar .nav-link {
    justify-content: center;
    padding: 0.75rem;
}

.app-body.sidebar-collapsed .app-sidebar .nav-link span,
.app-body.sidebar-collapsed .nav-section-title {
    display: none;
}

#sidebarOffcanvas {
    background: var(--sidebar-bg);
    color: #f0f4f8;
}

#sidebarOffcanvas .offcanvas-header {
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

#sidebarOffcanvas .app-sidebar-brand {
    border: none;
    margin-bottom: 0;
    padding: 0;
}

#sidebarOffcanvas .nav-link {
    color: #f0f4f8;
    border-radius: 12px;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.8rem 1rem;
}

#sidebarOffcanvas .nav-link:hover {
    background: rgba(255, 255, 255, 0.06);
}

.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1.25rem;
    background: transparent;
    border: 0;
    border-radius: 0;
    padding: 0.75rem 1rem;
    box-shadow: none;
}

.page-header p {
    margin: 0;
    color: var(--text-muted);
}

.page-header > .d-flex,
.page-header > form,
.page-header > .btn-group {
    flex-shrink: 0;
}

.page-header .btn,
.page-header .input-group,
.page-header .form-control,
.page-header .form-select {
    height: 42px;
    border-radius: 10px;
}

.page-header .input-group {
    overflow: hidden;
}

.kpi-card {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: none;
    background: var(--surface);
}

.card {
    border-radius: var(--radius);
    border: 1px solid var(--border);
    background: var(--surface);
    box-shadow: none;
}

.card-header {
    background: var(--surface-subtle);
    border-bottom: 1px solid var(--border);
    font-weight: 600;
    color: var(--text);
    padding: 0.9rem 1rem;
}

.card-body {
    padding: 1rem;
}

.card-footer {
    background: var(--surface-subtle);
    border-top: 1px solid var(--border);
    padding: 0.85rem 1rem;
}

.app-content .card,
.app-content .kpi-card {
    border-left: 0;
    border-right: 0;
    border-radius: 0;
    box-shadow: none;
}

.form-section {
    margin-bottom: 1.5rem;
}

.form-actions {
    padding: 0 1.25rem 1.25rem;
}

.form-label {
    font-size: 0.82rem;
    font-weight: 700;
    color: var(--text-muted);
}

.form-control,
.form-select,
.input-group-text {
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--text);
    border-radius: 10px;
    height: 42px;
    transition: border-color 0.15s ease, box-shadow 0.15s ease, background-color 0.15s ease;
}

.form-control:focus,
.form-select:focus {
    border-color: var(--primary-600);
    box-shadow: 0 0 0 3px var(--focus-ring);
    background: var(--surface);
    outline: none;
}

.form-control::placeholder {
    color: var(--text-muted);
}

.form-control:focus-visible,
.form-select:focus-visible,
.input-group-text:focus-visible,
.form-check-input:focus-visible {
    outline: none;
}

.btn:focus-visible {
    outline: none;
    box-shadow: 0 0 0 3px var(--focus-ring);
}

.btn-primary:focus-visible {
    box-shadow: 0 0 0 3px var(--focus-ring);
}

.form-check-input {
    width: 1.15rem;
    height: 1.15rem;
    min-width: 1.15rem;
    border-radius: 8px;
    background: var(--surface);
    border: 1px solid var(--border);
    background-image: var(--bs-form-check-bg-image);
    background-repeat: no-repeat;
    background-position: center;
    background-size: 68% 68%;
    margin-top: 0.2rem;
    transition: border-color 0.15s ease, box-shadow 0.15s ease, background-color 0.15s ease;
}

.form-check-input:checked {
    background-color: var(--primary);
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--focus-ring);
}

.form-check-input:focus {
    border-color: var(--primary-600);
    box-shadow: 0 0 0 3px var(--focus-ring);
}

.form-check-input[type="radio"] {
    border-radius: 999px;
    background-size: 55% 55%;
}

.input-group {
    border-radius: 10px;
    overflow: hidden;
    height: 42px;
    background: var(--surface);
    border: 1px solid var(--border);
}

.input-group .input-group-text {
    border: none;
    background: transparent;
    color: var(--text-muted);
}

.input-group .form-control {
    border: none;
    height: 100%;
    background: transparent;
}

.input-group:focus-within {
    box-shadow: 0 0 0 3px var(--focus-ring);
    border-color: var(--primary-600);
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.35rem;
    border-radius: 10px;
    font-weight: 600;
    min-height: 38px;
}

.btn-sm {
    min-height: 36px;
    padding: 0.35rem 0.8rem;
}

.btn-primary {
    background: var(--primary);
    border-color: var(--primary);
    box-shadow: none;
}

.btn-primary:hover,
.btn-primary:focus {
    background: var(--primary-600);
    border-color: var(--primary-600);
}

.btn-outline-primary {
    color: var(--primary);
    border-color: rgba(var(--primary-rgb), 0.45);
    background: transparent;
}

.btn-outline-primary:hover,
.btn-outline-primary:focus {
    background: rgba(var(--primary-rgb), 0.08);
    border-color: var(--primary);
    color: var(--primary-600);
}

.btn-outline-secondary {
    color: var(--text);
    border-color: var(--border);
    background: var(--surface);
}

.btn-outline-secondary:hover,
.btn-outline-secondary:focus {
    background: var(--surface-subtle);
    color: var(--text);
    border-color: color-mix(in srgb, var(--border) 70%, var(--primary) 30%);
}

.badge {
    border-radius: 999px;
    padding: 6px 10px;
    font-weight: 700;
    letter-spacing: 0.01em;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.badge .badge-dot,
.badge-dot {
    width: 10px;
    height: 10px;
    border-radius: 999px;
    background: currentColor;
    display: inline-block;
}

.badge.bg-light {
    border: 1px solid var(--border);
    background: var(--surface-subtle) !important;
    color: var(--text) !important;
}

.badge.bg-success-subtle {
    background: color-mix(in srgb, var(--success) 14%, var(--surface) 86%) !important;
    color: color-mix(in srgb, var(--success) 80%, #0b1021 20%) !important;
}

.badge.bg-warning-subtle {
    background: color-mix(in srgb, var(--warning) 16%, var(--surface) 84%) !important;
    color: color-mix(in srgb, var(--warning) 80%, #0b1021 20%) !important;
}

.badge.bg-danger-subtle {
    background: color-mix(in srgb, var(--danger) 16%, var(--surface) 84%) !important;
    color: color-mix(in srgb, var(--danger) 80%, #0b1021 20%) !important;
}

.badge.bg-secondary-subtle {
    background: color-mix(in srgb, var(--muted) 16%, var(--surface) 84%) !important;
    color: color-mix(in srgb, var(--muted) 80%, #0b1021 20%) !important;
}

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

.table {
    border-collapse: collapse;
    border-spacing: 0;
    margin: 0;
}

.table > thead > tr > th,
.table > thead > tr > td {
    border: none;
    background: var(--surface-subtle);
    border-bottom: 1px solid var(--border);
    color: var(--text-muted);
    font-size: 0.8rem;
    font-weight: 700;
    text-transform: none;
    letter-spacing: 0;
    padding: 0.6rem 0.75rem;
}

.table > tbody > tr {
    background: transparent;
}

.table > tbody > tr > * {
    padding: 0.75rem;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}

.table > tbody > tr:hover {
    background: var(--surface-subtle);
}

.table-responsive {
    padding: 0;
    border-radius: 0;
}

.table-striped > tbody > tr:nth-of-type(odd) > * {
    background: color-mix(in srgb, var(--surface-subtle) 60%, var(--surface) 40%);
}

.table-hover > tbody > tr:hover > * {
    background: var(--surface-subtle);
    color: var(--text);
}

.modal-content,
.dropdown-menu,
.offcanvas,
.toast {
    background: var(--surface);
    color: var(--text);
    border-color: var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.toast-header,
.offcanvas-header {
    background: var(--surface-subtle);
    border-color: var(--border);
}

.app-toast-container {
    top: calc(var(--topbar-offset, 50px));
    bottom: auto;
    padding-top: 0;
    z-index: 1080;
}

.alert {
    border-radius: 12px;
    border: 1px solid var(--border);
    box-shadow: none;
}

.empty-state {
    text-align: center;
    padding: 1.8rem 1rem;
}

.empty-state .empty-icon {
    font-size: 1.6rem;
    color: var(--text-muted);
}

.skeleton {
    position: relative;
    overflow: hidden;
    background: var(--skeleton);
    border-radius: 0.75rem;
}

.skeleton::after {
    content: "";
    position: absolute;
    inset: 0;
    transform: translateX(-100%);
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.55), transparent);
    animation: skeleton-shimmer 1.2s infinite;
}

.skeleton-line {
    height: 12px;
    margin: 0.45rem 0;
    border-radius: 999px;
}

.skeleton-card {
    padding: 1rem;
    border-radius: var(--radius);
}

.skeleton-circle {
    width: 36px;
    height: 36px;
    border-radius: 50%;
}

@keyframes skeleton-shimmer {
    100% {
        transform: translateX(100%);
    }
}

.timeline {
    list-style: none;
    padding-left: 0;
    margin: 0;
    border-left: 2px solid var(--border);
}

.timeline li {
    position: relative;
    padding: 0 0 1.5rem 1.5rem;
}

.timeline li:last-child {
    padding-bottom: 0;
}

.timeline-dot {
    position: absolute;
    left: -6px;
    top: 4px;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: var(--primary);
}

.detail-item {
    padding: 0.75rem 0;
    border-bottom: 1px dashed var(--border);
}

.detail-item:last-child {
    border-bottom: none;
}

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

.app-footer a {
    color: var(--text-muted);
}

.app-footer a:hover {
    color: var(--primary);
}

.brand-mark {
    width: 14px;
    height: 14px;
    border-radius: 999px !important;
    background: var(--primary);
    display: inline-block;
}

.brand-logo {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.55rem;
    color: inherit;
    text-decoration: none;
    font-weight: 700;
}

.brand-logo img {
    height: max(var(--app-logo-height, 40px), 40px);
    width: auto;
    display: block;
}

.brand-logo--sm img {
    height: max(var(--app-logo-height-sm, 32px), 28px);
}

.brand-logo--lg img {
    height: max(var(--app-logo-height-lg, 64px), 64px);
}

.brand-logo--lg .brand-mark {
    width: 20px;
    height: 20px;
}

.brand-text {
    font-weight: 700;
    letter-spacing: 0.02em;
    font-size: var(--app-title-size, 1.1rem);
}

.org-chip {
    font-weight: 600;
    cursor: default;
    max-width: 240px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.color-swatch {
    width: 18px;
    height: 18px;
    border-radius: 6px;
    border: 1px solid var(--border);
    display: inline-block;
}

.branding-palettes {
    padding: 0.25rem 0;
}

.palette-card {
    width: 100%;
    border: 1px solid var(--border);
    background: var(--surface);
    border-radius: 0.85rem;
    padding: 0.85rem;
    text-align: left;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    box-shadow: none;
    transition: border-color 0.15s ease;
}

.palette-card:hover,
.palette-card:focus-visible {
    border-color: rgba(var(--primary-rgb), 0.35);
}

.palette-card.is-selected {
    border-color: rgba(var(--primary-rgb), 0.7);
    box-shadow: none;
}

.palette-swatches {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 0.35rem;
}

.palette-swatches span {
    display: block;
    width: 100%;
    padding-top: 70%;
    border-radius: 6px;
    border: 1px solid rgba(15, 23, 42, 0.08);
}

.palette-title {
    font-weight: 600;
}

.palette-note {
    font-size: 0.85rem;
    color: var(--text-muted);
}

.branding-manual {
    border: 1px dashed var(--border);
    border-radius: 0.75rem;
    padding: 0.25rem 1rem 1rem;
}

.branding-manual-toggle {
    cursor: pointer;
    font-weight: 600;
    padding: 0.6rem 0.2rem;
}

.auth-body,
.plain-body {
    background: radial-gradient(circle at 18% 18%, color-mix(in srgb, var(--bg-alt) 86%, var(--primary-100) 14%), var(--bg));
    color: var(--text);
}

.auth-shell,
.plain-shell {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 2rem;
    position: relative;
}

.auth-card,
.plain-card {
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 2.5rem;
    width: min(420px, 100%);
    border: 1px solid var(--border);
}

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

.auth-header .brand-logo img {
    height: calc(var(--app-logo-height-lg, 40px) + 16px);
}

.auth-header .auth-brand {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.85rem;
    margin-bottom: 0.55rem;
    flex-wrap: wrap;
    text-align: center;
}

.auth-header .auth-brand .brand-text {
    font-size: var(--app-title-size, clamp(1.25rem, 2vw + 1rem, 1.65rem));
    letter-spacing: 0.06em;
    line-height: 1.1;
    color: inherit;
    max-width: min(340px, 80vw);
    word-break: break-word;
    text-wrap: balance;
}

@media (max-width: 575px) {
    .auth-header .auth-brand .brand-text {
        font-size: var(--app-title-size, 1.4rem);
    }
}

.code-chip {
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
    padding: 0.5rem 0.75rem;
    border-radius: 0.6rem;
    background: var(--code-bg);
    border: 1px solid var(--border);
}

.loading-overlay {
    position: fixed;
    inset: 0;
    background: var(--overlay);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 2000;
}

.loading-overlay.show {
    display: flex;
}

.loading-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
}

.loading-content .spinner-border {
    border-radius: 50% !important;
    width: 2.75rem;
    height: 2.75rem;
    border-width: 0.3rem;
}

.loading-text {
    font-size: 0.9rem;
    color: var(--text-muted);
}

.mfa-qr {
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 1rem;
    border: 1px dashed var(--border);
    border-radius: var(--radius) !important;
    background: var(--surface-subtle);
}

.mfa-qr svg,
.mfa-qr img {
    width: 180px;
    height: auto;
    display: block;
}

.locale-switcher .dropdown-toggle {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
}

.auth-locale {
    display: flex;
    justify-content: flex-end;
    position: absolute;
    top: 1.5rem;
    right: 1.5rem;
    margin: 0;
    z-index: 5;
}

@media (max-width: 575px) {
    .auth-locale {
        top: 1rem;
        right: 1rem;
    }
}

@media (max-width: 991px) {
    .app-shell {
        flex-direction: column;
    }

    .app-content {
        padding: 1rem;
    }

    .page-header {
        flex-direction: column;
        align-items: flex-start;
    }

    .page-header > .d-flex,
    .page-header > form,
    .page-header > .btn-group {
        width: 100%;
    }
}

@media (max-width: 767px) {
    .app-content {
        padding: 0.75rem;
        gap: 0.75rem;
    }

    .app-content .row {
        margin-left: -0.25rem;
        margin-right: -0.25rem;
    }
}

.chat-page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    flex-wrap: wrap;
    margin-bottom: 0.75rem;
}

.chat-shell {
    display: grid;
    grid-template-columns: 280px 1fr;
    background: var(--surface);
    border-radius: 0;
    border: 1px solid var(--border);
    box-shadow: none;
    overflow: hidden;
    height: calc(100vh - 240px);
}

.chat-sidebar {
    background: var(--surface-subtle);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    min-width: 240px;
}

.chat-sidebar-header {
    padding: 1rem;
    border-bottom: 1px solid var(--border);
}

.chat-session-list {
    flex: 1;
    overflow-y: auto;
    padding: 0.5rem 0;
}

.chat-session-group-title {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    padding: 0.25rem 1rem;
}

.chat-session-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.65rem 1rem;
    margin: 0 0.65rem 0.35rem;
    border-radius: 0.75rem;
    color: var(--text);
    border: 1px solid transparent;
    transition: background 0.2s ease, border-color 0.2s ease;
}

.chat-session-item:hover {
    background: rgba(var(--primary-rgb), 0.08);
    border-color: rgba(var(--primary-rgb), 0.2);
}

.chat-session-item.active {
    background: rgba(var(--primary-rgb), 0.14);
    border-color: rgba(var(--primary-rgb), 0.3);
}

.chat-session-link {
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
    color: var(--text);
    text-decoration: none;
    flex: 1;
    min-width: 0;
}

.chat-session-title {
    font-weight: 600;
    font-size: 0.95rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-session-meta {
    font-size: 0.78rem;
    color: var(--text-muted);
}

.chat-session-actions {
    display: flex;
    align-items: center;
    gap: 0.35rem;
}

.chat-session-actions form {
    margin: 0;
}

.chat-session-actions .btn {
    padding: 0.25rem 0.45rem;
}

.chat-actions-list {
    border-top: 1px solid var(--border);
    padding: 0.85rem 1rem 1rem;
    background: var(--surface-subtle);
}

.chat-actions-title {
    font-weight: 600;
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin-bottom: 0.5rem;
}

.chat-actions-items {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 0.55rem;
    max-height: 200px;
    overflow-y: auto;
}

.chat-actions-items li {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 0.7rem;
    padding: 0.55rem 0.65rem;
}

.chat-action-name {
    font-weight: 600;
    font-size: 0.85rem;
}

.chat-action-desc {
    font-size: 0.78rem;
    color: var(--text-muted);
}

.chat-main {
    display: flex;
    flex-direction: column;
    background: var(--surface);
    min-height: 0;
    position: relative;
}

.chat-topbar {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    padding: 0.85rem 1.5rem;
    border-bottom: 1px solid var(--border);
    background: var(--surface);
}

.chat-panel {
    flex: 1;
    min-width: 280px;
    border: 1px solid var(--border);
    border-radius: 0.9rem;
    background: var(--surface-subtle);
    padding: 0.55rem 0.75rem;
}

.chat-panel summary {
    cursor: pointer;
    font-weight: 700;
    font-size: 0.85rem;
    color: var(--text);
    list-style: none;
}

.chat-panel summary::-webkit-details-marker {
    display: none;
}

.chat-panel-list {
    list-style: none;
    margin: 0.6rem 0 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    font-size: 0.82rem;
}

.chat-k {
    font-weight: 700;
    color: var(--text);
    margin-right: 0.35rem;
}

.chat-v {
    color: var(--text-muted);
}

.chat-action-row {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 0.25rem 0.5rem;
    padding: 0.4rem 0.55rem;
    border-radius: 0.75rem;
    border: 1px solid var(--border);
    background: var(--surface);
}

.chat-action-row-ok {
    border-color: rgba(34, 197, 94, 0.35);
}

.chat-action-row-fail {
    border-color: rgba(239, 68, 68, 0.35);
}

.chat-action-key {
    font-weight: 700;
    color: var(--text);
    font-size: 0.82rem;
}

.chat-action-time {
    color: var(--text-muted);
    font-size: 0.78rem;
    white-space: nowrap;
}

.chat-action-msg {
    grid-column: 1 / -1;
    color: var(--text-muted);
    font-size: 0.8rem;
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    min-height: 0;
    padding-bottom: 5.5rem;
}

.chat-empty {
    margin-top: 2rem;
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
}

.chat-suggestions {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 0.75rem;
}

.chat-suggestion {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    width: 100%;
    text-align: left;
    cursor: pointer;
    border-radius: 0.9rem;
    padding: 0.75rem 0.9rem;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    font-weight: 600;
    transition: background 0.2s ease, border-color 0.2s ease;
}

.chat-suggestion:hover {
    background: var(--surface-subtle);
    border-color: rgba(var(--primary-rgb), 0.25);
}

.chat-suggestion i {
    font-size: 0.9rem;
}

.chat-message {
    display: flex;
}

.chat-message.is-user {
    justify-content: flex-end;
}

.chat-message.is-assistant,
.chat-message.is-tool {
    justify-content: flex-start;
}

.chat-bubble {
    max-width: min(720px, 82%);
    background: var(--surface-subtle);
    border: 1px solid var(--border);
    padding: 0.8rem 0.95rem;
    border-radius: 1rem;
}

.chat-message.is-user .chat-bubble {
    background: color-mix(in srgb, var(--primary) 28%, var(--surface-strong) 72%);
    border-color: rgba(var(--primary-rgb), 0.3);
    color: #0f172a;
}

.chat-message.is-tool .chat-bubble {
    background: #0f172a;
    border-color: rgba(var(--primary-rgb), 0.3);
    color: #f8fafc;
}

.chat-bubble-meta {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.75rem;
    color: rgba(15, 23, 42, 0.65);
    margin-bottom: 0.35rem;
}

.chat-bubble-tag {
    background: rgba(var(--primary-rgb), 0.16);
    color: #0f172a;
    padding: 0.15rem 0.5rem;
    border-radius: 999px;
    font-size: 0.7rem;
}

.chat-message.is-tool .chat-bubble-meta {
    color: rgba(248, 250, 252, 0.85);
}

.chat-message.is-tool .chat-bubble-tag {
    background: rgba(248, 250, 252, 0.16);
    color: #f8fafc;
}

.theme-dark .chat-message.is-assistant .chat-bubble,
.theme-dark .chat-message.is-tool .chat-bubble {
    color: #f8fafc;
}

.theme-dark .chat-message.is-assistant .chat-bubble-meta,
.theme-dark .chat-message.is-tool .chat-bubble-meta {
    color: rgba(248, 250, 252, 0.85);
}

:root[data-theme="dark"] .chat-shell {
    border-color: rgba(255, 255, 255, 0.06);
    background: var(--surface);
}

:root[data-theme="dark"] .chat-sidebar,
:root[data-theme="dark"] .chat-actions-list {
    background: var(--bg-alt);
    border-color: rgba(255, 255, 255, 0.06);
}

:root[data-theme="dark"] .chat-session-item {
    background: var(--surface-strong);
    border-color: rgba(255, 255, 255, 0.08);
}

:root[data-theme="dark"] .chat-session-item:hover {
    background: color-mix(in srgb, var(--primary) 18%, var(--surface-strong) 82%);
    border-color: rgba(var(--primary-rgb), 0.45);
}

:root[data-theme="dark"] .chat-session-item.active {
    background: color-mix(in srgb, var(--primary) 28%, var(--surface-strong) 72%);
    border-color: rgba(var(--primary-rgb), 0.6);
}

:root[data-theme="dark"] .chat-session-title {
    color: #f5f5f5;
}

:root[data-theme="dark"] .chat-session-meta {
    color: #c8c8c8;
}

:root[data-theme="dark"] .chat-messages {
    background: var(--bg-alt);
}

:root[data-theme="dark"] .chat-message.is-assistant .chat-bubble {
    background: var(--surface-strong);
    border-color: rgba(255, 255, 255, 0.1);
}

:root[data-theme="dark"] .chat-message.is-user .chat-bubble {
    color: #f8fafc;
}

:root[data-theme="dark"] .chat-message.is-user .chat-bubble-meta {
    color: rgba(248, 250, 252, 0.85);
}

:root[data-theme="dark"] .chat-attachment {
    background: var(--surface);
    border-color: rgba(255, 255, 255, 0.16);
    color: var(--text);
}

.chat-bubble-content {
    white-space: pre-wrap;
    word-wrap: break-word;
    font-size: 0.95rem;
    color: inherit;
}

.chat-bubble-content:empty {
    display: none;
}

.chat-attachments {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    margin-top: 0.6rem;
}

.chat-attachment {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    padding: 0.4rem 0.6rem;
    border-radius: 0.7rem;
    border: 1px dashed var(--border);
    background: var(--surface-strong);
    color: #0f172a;
    text-decoration: none;
    font-size: 0.8rem;
}

.chat-attachment i {
    font-size: 0.9rem;
}

.chat-attachment-meta {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.chat-input {
    border-top: 1px solid var(--border);
    padding: 1rem 1.5rem 1.2rem;
    background: var(--surface);
    position: sticky;
    bottom: 0;
    z-index: 2;
    box-shadow: 0 -6px 16px rgba(15, 23, 42, 0.05);
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.chat-input.is-dragover {
    border-color: rgba(var(--primary-rgb), 0.4);
    box-shadow: 0 -10px 20px rgba(var(--primary-rgb), 0.15);
}

.chat-input-box {
    display: flex;
    gap: 0.75rem;
    align-items: flex-end;
}

.chat-attach {
    border-radius: 999px;
    padding: 0.6rem 0.75rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.chat-file-input {
    display: none;
}

.chat-attachment-list {
    display: none;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-top: 0.75rem;
}

.chat-attachment-list.is-visible {
    display: flex;
}

.chat-attachment-chip {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.35rem 0.6rem;
    border-radius: 999px;
    border: 1px solid var(--border);
    background: var(--surface-subtle);
    font-size: 0.8rem;
    color: var(--text);
}

.chat-attachment-clear {
    border: 1px solid var(--border);
    background: transparent;
    border-radius: 999px;
    padding: 0.35rem 0.7rem;
    font-size: 0.78rem;
    color: var(--text-muted);
}

.chat-textarea {
    resize: none;
    border-radius: 1rem;
    padding: 0.75rem 1rem;
    background: var(--surface);
    border: 1px solid var(--border);
}

.chat-textarea:focus {
    border-color: rgba(var(--primary-rgb), 0.5);
    box-shadow: 0 0 0 3px var(--focus-ring);
}

.chat-send {
    border-radius: 999px;
    padding: 0.6rem 0.9rem;
}

.chat-input-footer {
    margin-top: 0.5rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.chat-typing {
    display: inline-flex;
    gap: 0.25rem;
    align-items: center;
}

.chat-typing span {
    width: 0.35rem;
    height: 0.35rem;
    background: var(--text-muted);
    border-radius: 50%;
    animation: chatPulse 1.4s infinite ease-in-out;
}

.chat-typing span:nth-child(2) {
    animation-delay: 0.2s;
}

.chat-typing span:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes chatPulse {
    0%, 80%, 100% {
        transform: scale(0.6);
        opacity: 0.4;
    }
    40% {
        transform: scale(1);
        opacity: 1;
    }
}

@media (max-width: 992px) {
    .chat-shell {
        grid-template-columns: 1fr;
        height: auto;
        display: flex;
        flex-direction: column;
    }

    .chat-sidebar {
        border-right: none;
        border-bottom: 1px solid var(--border);
        order: 2;
    }

    .chat-main {
        order: 1;
        min-height: 60vh;
    }

    .chat-messages {
        padding: 1.35rem;
    }

    .chat-topbar {
        padding: 0.85rem 1rem;
    }

    .chat-input {
        padding: 1rem;
    }

    .chat-actions-list {
        margin-top: 0.5rem;
    }
}

@media (max-width: 640px) {
    .chat-suggestions {
        grid-template-columns: 1fr;
    }

    .chat-input-footer {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.35rem;
    }
}

/* Flat UI overrides */
:root,
:root[data-theme="dark"] {
    --shadow: none;
    --shadow-soft: none;
    --surface-subtle: var(--surface);
    --surface-strong: var(--surface);
}

body,
.auth-body,
.plain-body {
    background: var(--bg) !important;
}

*,
*::before,
*::after {
    box-shadow: none !important;
    border-radius: 0 !important;
}

button,
.btn,
input,
textarea,
select,
.form-control,
.form-select,
.input-group {
    border-radius: var(--radius) !important;
}

*:focus-visible {
    outline: 2px solid var(--focus-ring) !important;
    outline-offset: 2px;
    box-shadow: none !important;
}

.app-topbar {
    box-shadow: none !important;
    backdrop-filter: none !important;
}

.table {
    border-collapse: collapse;
    border-spacing: 0;
}

.table > tbody > tr,
.table > tbody > tr:hover,
.palette-card,
.palette-card:hover,
.palette-card:focus-visible {
    transform: none !important;
}

.skeleton::after {
    display: none;
}

.roles-section + .roles-section {
    margin-top: 1.5rem;
}

.roles-section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 0.75rem;
}

.roles-list {
    display: flex;
    flex-direction: column;
}

.role-list-card[data-collapsed="true"] [data-role-list-body] {
    display: none;
}

.role-form-card[data-collapsed="true"] {
    display: none;
}

.role-row {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1.5rem;
    padding: 0.9rem 0;
    border-bottom: 1px solid var(--border);
}

.role-row:last-child {
    border-bottom: 0;
}

.role-info {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
}

.role-title {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.role-badge {
    font-weight: 600;
    font-size: 0.7rem;
}

.role-meta {
    color: var(--text-muted);
}

.role-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    justify-content: flex-end;
    flex-shrink: 0;
}

.permission-group {
    border: 1px solid var(--border);
    border-radius: 0.75rem;
    padding: 0.75rem 0.9rem;
    background: var(--surface);
}

.permission-group-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 0.75rem;
}

.permission-group-title {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.permission-group[data-collapsed="true"] {
    background: var(--surface-subtle);
}

.permission-group[data-collapsed="true"] .permission-group-body {
    display: none;
}

[data-permission-item] {
    padding: 0.25rem 0.4rem;
    border-radius: 0.6rem;
}

.form-check-input:focus-visible {
    outline: 2px solid var(--focus-ring);
    outline-offset: 2px;
    box-shadow: none;
}

@media (max-width: 768px) {
    .role-row {
        flex-direction: column;
        align-items: flex-start;
    }

    .role-actions {
        justify-content: flex-start;
    }
}
