/* ============================================================
   DLINK SALES — Custom admin theme (Bootstrap 5)
   ============================================================ */

/* --- CSS variables ---------------------------------------- */
:root {
    --sidebar-width: 260px;
    --sidebar-collapsed-width: 68px;
    --topbar-height: 60px;

    --sidebar-bg: #16213e;
    --sidebar-brand-bg: #0f172a;
    --sidebar-text: rgba(255,255,255,.75);
    --sidebar-text-muted: rgba(255,255,255,.38);
    --sidebar-hover-bg: rgba(255,255,255,.07);
    --sidebar-active-bg: rgba(99,102,241,.15);
    --sidebar-active-text: #6366f1;
    --sidebar-border: rgba(255,255,255,.07);
    --sidebar-section: rgba(255,255,255,.30);

    --topbar-bg: #ffffff;
    --topbar-border: #e2e8f0;
    --topbar-shadow: 0 1px 3px 0 rgb(0 0 0 / 0.07);

    --content-bg: #f8fafc;
    --card-shadow: 0 1px 3px 0 rgb(0 0 0 / 0.1);

    --accent: #6366f1;
    --accent-dark: #4f46e5;
}

[data-bs-theme="dark"] {
    --topbar-bg: #1a2234;
    --topbar-border: rgba(255,255,255,.08);
    --topbar-shadow: 0 1px 4px rgba(0,0,0,.25);
    --content-bg: #111827;
    --card-shadow: 0 2px 8px rgba(0,0,0,.3);
}

/* --- Reset / base ----------------------------------------- */
*, *::before, *::after { box-sizing: border-box; }

html, body {
    height: 100%;
    margin: 0;
}

body {
    background-color: var(--content-bg);
    font-family: 'Inter', 'Plus Jakarta Sans', system-ui, -apple-system, sans-serif;
    transition: background-color .25s;
}

/* Premium heading feel — tighten tracking on all heading sizes */
h1, h2, h3, h4, h5, h6,
.h1, .h2, .h3, .h4, .h5, .h6 {
    letter-spacing: -0.01em;
    font-family: 'Plus Jakarta Sans', 'Inter', system-ui, -apple-system, sans-serif;
}

/* ============================================================
   SIDEBAR
   ============================================================ */
.sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: var(--sidebar-width);
    height: 100vh;
    background: var(--sidebar-bg);
    display: flex;
    flex-direction: column;
    z-index: 1050;
    transition: width .28s ease, transform .28s ease;
    overflow: hidden;
}

/* Brand */
.sidebar-brand {
    display: flex;
    align-items: center;
    gap: .75rem;
    padding: 0 1.1rem;
    height: var(--topbar-height);
    background: var(--sidebar-brand-bg);
    text-decoration: none;
    flex-shrink: 0;
    border-bottom: 1px solid var(--sidebar-border);
    white-space: nowrap;
    overflow: hidden;
}

.sidebar-brand-icon {
    width: 34px;
    height: 34px;
    background: var(--accent);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-size: 1rem;
    color: #fff;
    font-weight: 700;
}

.sidebar-brand-text {
    color: #fff;
    font-weight: 700;
    font-size: .95rem;
    letter-spacing: .01em;
    line-height: 1.2;
}
.sidebar-brand-text small {
    display: block;
    font-weight: 400;
    font-size: .7rem;
    color: var(--sidebar-text-muted);
    letter-spacing: .04em;
    text-transform: uppercase;
}

/* Nav scrollable area */
.sidebar-scroll {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    scrollbar-width: thin;
    scrollbar-color: rgba(255,255,255,.15) transparent;
    padding: .75rem 0;
}

.sidebar-scroll::-webkit-scrollbar { width: 4px; }
.sidebar-scroll::-webkit-scrollbar-track { background: transparent; }
.sidebar-scroll::-webkit-scrollbar-thumb { background: rgba(255,255,255,.15); border-radius: 2px; }

/* Section labels */
.sidebar-section {
    padding: 1rem 1.1rem .3rem;
    font-size: .65rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .09em;
    color: var(--sidebar-section);
    white-space: nowrap;
    overflow: hidden;
    transition: opacity .2s;
}

/* Nav list */
.sidebar-nav {
    list-style: none;
    padding: 0;
    margin: 0;
}

.sidebar-nav-item { position: relative; }

.sidebar-nav-link {
    display: flex;
    align-items: center;
    gap: .75rem;
    padding: .55rem 1.1rem;
    color: var(--sidebar-text);
    text-decoration: none;
    border-radius: 0;
    white-space: nowrap;
    overflow: hidden;
    transition: background .15s, color .15s;
    font-size: .875rem;
}

.sidebar-nav-link:hover {
    background: var(--sidebar-hover-bg);
    color: #fff;
}

.sidebar-nav-link.active {
    background: var(--sidebar-active-bg);
    color: var(--sidebar-active-text);
    font-weight: 600;
}

.sidebar-nav-link.active::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 3px;
    background: var(--accent);
    border-radius: 0 2px 2px 0;
}

.sidebar-nav-icon {
    font-size: 1.05rem;
    width: 20px;
    text-align: center;
    flex-shrink: 0;
}

.sidebar-nav-label {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Sub-menu */
.sidebar-submenu {
    list-style: none;
    padding: 0;
    margin: 0;
    max-height: 0;
    overflow: hidden;
    transition: max-height .25s ease;
}

.sidebar-submenu.open { max-height: 1200px; }

.sidebar-submenu-link {
    display: flex;
    align-items: center;
    gap: .5rem;
    padding: .45rem 1.1rem .45rem 3rem;
    color: var(--sidebar-text);
    text-decoration: none;
    font-size: .825rem;
    white-space: nowrap;
    overflow: hidden;
    transition: background .15s, color .15s;
}

.sidebar-submenu-link:hover {
    background: var(--sidebar-hover-bg);
    color: #fff;
}

.sidebar-submenu-link.active { color: var(--sidebar-active-text); }

.sidebar-chevron {
    transition: transform .25s;
    font-size: .7rem;
    flex-shrink: 0;
    color: var(--sidebar-text-muted);
}

.sidebar-nav-link[aria-expanded="true"] .sidebar-chevron {
    transform: rotate(90deg);
}

/* User card at bottom */
.sidebar-user {
    padding: .85rem 1.1rem;
    border-top: 1px solid var(--sidebar-border);
    display: flex;
    align-items: center;
    gap: .7rem;
    flex-shrink: 0;
    overflow: hidden;
    white-space: nowrap;
}

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

.sidebar-user-info { flex: 1; min-width: 0; }
.sidebar-user-name {
    font-size: .8rem;
    font-weight: 600;
    color: #fff;
    overflow: hidden;
    text-overflow: ellipsis;
}
.sidebar-user-role {
    font-size: .7rem;
    color: var(--sidebar-text-muted);
    overflow: hidden;
    text-overflow: ellipsis;
}

.sidebar-user-logout {
    color: var(--sidebar-text-muted);
    font-size: 1rem;
    flex-shrink: 0;
    text-decoration: none;
    transition: color .15s;
}
.sidebar-user-logout:hover { color: #ef4444; }

/* ============================================================
   COLLAPSED STATE (desktop toggle)
   ============================================================ */
body.sidebar-collapsed .sidebar       { width: var(--sidebar-collapsed-width); }
body.sidebar-collapsed .main-wrapper  { margin-left: var(--sidebar-collapsed-width); }

/* Section dividers — collapse height so no dead gaps */
body.sidebar-collapsed .sidebar-section {
    height: 0;
    padding: 0;
    overflow: hidden;
    opacity: 0;
    pointer-events: none;
}

/* Text labels & chevron — removed from flex layout so icon centres cleanly */
body.sidebar-collapsed .sidebar-nav-label,
body.sidebar-collapsed .sidebar-brand-text,
body.sidebar-collapsed .sidebar-chevron,
body.sidebar-collapsed .sidebar-user-info,
body.sidebar-collapsed .sidebar-user-logout {
    width: 0;
    overflow: hidden;
    opacity: 0;
    pointer-events: none;
    flex-shrink: 1;
}

/* Submenus — force collapsed even when .open */
body.sidebar-collapsed .sidebar-submenu {
    max-height: 0 !important;
    overflow: hidden;
    opacity: 0;
    pointer-events: none;
}

/* Nav link — centre the icon, remove gap */
body.sidebar-collapsed .sidebar-nav-link {
    justify-content: center;
    padding-left: 0;
    padding-right: 0;
    gap: 0;
}

body.sidebar-collapsed .sidebar-nav-icon        { width: auto; }
body.sidebar-collapsed .sidebar-nav-link.active::before { display: none; }

/* Brand — centre the icon square, remove gap */
body.sidebar-collapsed .sidebar-brand {
    justify-content: center;
    padding: 0;
    gap: 0;
}

/* User card — centre the avatar, remove gap */
body.sidebar-collapsed .sidebar-user {
    justify-content: center;
    padding: .85rem 0;
    gap: 0;
}

/* ============================================================
   MAIN WRAPPER
   ============================================================ */
.main-wrapper {
    margin-left: var(--sidebar-width);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    transition: margin-left .28s ease;
}

/* ============================================================
   TOPBAR
   ============================================================ */
.topbar {
    height: var(--topbar-height);
    background: var(--topbar-bg);
    border-bottom: 1px solid var(--topbar-border);
    box-shadow: var(--topbar-shadow);
    display: flex;
    align-items: center;
    padding: 0 1.25rem;
    gap: .75rem;
    position: sticky;
    top: 0;
    z-index: 1020;
    transition: background .25s, border-color .25s;
}

.topbar-toggle {
    background: none;
    border: none;
    color: var(--bs-body-color);
    font-size: 1.15rem;
    cursor: pointer;
    padding: .35rem .45rem;
    border-radius: 6px;
    line-height: 1;
    flex-shrink: 0;
    transition: background .15s;
}
.topbar-toggle:hover { background: var(--bs-tertiary-bg); }

.topbar-title {
    font-weight: 600;
    font-size: .9rem;
    color: var(--bs-body-color);
    margin: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.topbar-right {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: .5rem;
}

.topbar-btn {
    background: none;
    border: 1px solid var(--bs-border-color);
    color: var(--bs-body-color);
    font-size: .9rem;
    cursor: pointer;
    padding: .35rem .55rem;
    border-radius: 8px;
    line-height: 1;
    transition: background .15s, border-color .15s;
    display: flex;
    align-items: center;
    gap: .35rem;
}
.topbar-btn:hover {
    background: var(--bs-tertiary-bg);
    border-color: var(--bs-border-color-translucent);
}

.topbar-user {
    display: flex;
    align-items: center;
    gap: .5rem;
    color: var(--bs-body-color);
    font-size: .85rem;
    text-decoration: none;
    padding: .25rem .5rem;
    border-radius: 8px;
    transition: background .15s;
}
.topbar-user:hover { background: var(--bs-tertiary-bg); }

.topbar-avatar {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    background: var(--accent);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: .7rem;
    font-weight: 700;
    flex-shrink: 0;
    text-transform: uppercase;
}

.topbar-username {
    font-weight: 500;
    max-width: 120px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ============================================================
   PAGE CONTENT
   ============================================================ */
.page-content {
    flex: 1;
    padding: 1.5rem;
}

/* page header */
.page-header {
    margin-bottom: 1.5rem;
}

.page-header h1, .page-header .h1 {
    font-size: 1.35rem;
    font-weight: 700;
    margin-bottom: .15rem;
    color: var(--bs-body-color);
}

/* ============================================================
   CARDS
   ============================================================ */
.card {
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    box-shadow: 0 1px 3px 0 rgb(0 0 0 / 0.1);
    transition: box-shadow .2s;
}

.card:hover { box-shadow: 0 4px 16px rgb(0 0 0 / 0.10); }

.card-header {
    background: transparent;
    border-bottom: 1px solid #e2e8f0;
    padding: 1rem 1.25rem;
    font-weight: 600;
    font-size: .9rem;
}

/* ============================================================
   CRM CARD — reusable component
   .crm-card on any block element gives it the standard card
   treatment without inheriting Bootstrap's .card padding rules.
   ============================================================ */
.crm-card {
    background: #ffffff;
    border: 1px solid #e2e8f0;
    box-shadow: 0 1px 3px 0 rgb(0 0 0 / 0.1);
    border-radius: 0.75rem;
}

.crm-card:hover {
    box-shadow: 0 4px 12px 0 rgb(0 0 0 / 0.10);
}

/* stat cards */
.stat-card {
    border-radius: 12px;
    padding: 1.25rem;
    display: flex;
    align-items: flex-start;
    gap: 1rem;
}

.stat-card-icon {
    width: 48px;
    height: 48px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.3rem;
    flex-shrink: 0;
}

.stat-card-value {
    font-size: 1.65rem;
    font-weight: 700;
    line-height: 1.1;
    color: var(--bs-body-color);
}

.stat-card-label {
    font-size: .78rem;
    color: var(--bs-secondary-color);
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: .04em;
}

/* ============================================================
   TABLE / GRID
   ============================================================ */

/* ── Base resets ─────────────────────────────────────────── */
/*
 * dataTables.bootstrap5.min.css loads AFTER site.css (registered in views).
 * All DataTables-specific rules use the high-specificity prefix
 * "div.dataTables_wrapper table.dataTable" to guarantee they win.
 * Plain .table rules still apply to non-DT tables (forms, modals, etc.).
 */

/* Remove vertical borders on plain tables */
.table > :not(caption) > * > * {
    border-right-width: 0;
    border-left-width: 0;
}

/* Remove vertical borders on DataTables — overrides table-bordered if present */
div.dataTables_wrapper table.dataTable > :not(caption) > * > * {
    border-right-width: 0 !important;
    border-left-width: 0 !important;
}

/* ── Header — plain tables ───────────────────────────────── */
.table thead th,
.table thead td {
    font-size: .68rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .07em;
    color: #64748b;
    background: #f8fafc;
    border-bottom: 2px solid #e2e8f0 !important;
    border-top: 0 !important;
    padding: .55rem .85rem;
    white-space: nowrap;
}

/* ── Header — DataTables (beats CDN's table.dataTable thead th rule) ── */
div.dataTables_wrapper table.dataTable > thead > tr > th,
div.dataTables_wrapper table.dataTable > thead > tr > td {
    font-size: .68rem !important;
    font-weight: 700 !important;
    text-transform: uppercase !important;
    letter-spacing: .07em !important;
    color: #64748b !important;
    background: #f8fafc !important;
    border-bottom: 2px solid #e2e8f0 !important;
    border-top: 0 !important;
    padding: .52rem .85rem !important;
    white-space: nowrap;
}

[data-bs-theme="dark"] .table thead th,
[data-bs-theme="dark"] .table thead td,
[data-bs-theme="dark"] div.dataTables_wrapper table.dataTable > thead > tr > th,
[data-bs-theme="dark"] div.dataTables_wrapper table.dataTable > thead > tr > td {
    background: rgba(255,255,255,.04) !important;
    color: #94a3b8 !important;
    border-bottom-color: rgba(255,255,255,.1) !important;
}

/* ── Data cells — plain tables ───────────────────────────── */
.table td {
    padding: .42rem .85rem;
    vertical-align: middle;
    font-size: .8125rem;
    border-bottom: 1px solid #f1f5f9;
}

/* ── Data cells — DataTables (beats CDN padding) ─────────── */
div.dataTables_wrapper table.dataTable > tbody > tr > td,
div.dataTables_wrapper table.dataTable > tbody > tr > th {
    padding: .42rem .85rem !important;
    vertical-align: middle !important;
    font-size: .8125rem !important;
    border-bottom: 1px solid #f1f5f9 !important;
    border-top: 0 !important;
}

[data-bs-theme="dark"] .table td,
[data-bs-theme="dark"] div.dataTables_wrapper table.dataTable > tbody > tr > td {
    border-bottom-color: rgba(255,255,255,.06) !important;
}

/* No bottom border on last body row */
.table > tbody > tr:last-child > td,
div.dataTables_wrapper table.dataTable > tbody > tr:last-child > td {
    border-bottom: 0 !important;
}

/* ── Row hover ───────────────────────────────────────────── */
.table-hover > tbody > tr { transition: background-color .1s; }

.table-hover > tbody > tr:hover > *,
div.dataTables_wrapper table.dataTable.table-hover > tbody > tr:hover > * {
    background-color: rgba(99, 102, 241, 0.055) !important;
    --bs-table-accent-bg: transparent;
}

/* ── table-light thead ───────────────────────────────────── */
.table-light th { background: #f8fafc !important; color: #475569 !important; }

/* ── table-sm tighter compact ────────────────────────────── */
.table-sm thead th,
.table-sm thead td { padding: .42rem .75rem !important; }
.table-sm td,
.table-sm th       { padding: .32rem .75rem !important; }

/* ── Utility: dim row (e.g. rolled-back) ─────────────────── */
tr.row-muted > td { opacity: .55; }

/* ── Card-table flush ────────────────────────────────────── */
.card > .table-responsive > .table,
.card > .table { margin-bottom: 0; }

.card > .table-responsive > .table thead th:first-child,
.card > .table-responsive > .table td:first-child,
.card > .table thead th:first-child,
.card > .table td:first-child { padding-left: 1.25rem !important; }

.card > .table-responsive > .table thead th:last-child,
.card > .table-responsive > .table td:last-child,
.card > .table thead th:last-child,
.card > .table td:last-child { padding-right: 1.25rem !important; }

/* ── DataTables wrapper controls ────────────────────────── */
div.dataTables_wrapper { font-size: .8125rem; }

div.dataTables_wrapper div.dataTables_length,
div.dataTables_wrapper div.dataTables_filter {
    padding: .65rem 1rem .45rem !important;
}

div.dataTables_wrapper div.dataTables_length label,
div.dataTables_wrapper div.dataTables_filter label {
    display: flex !important;
    align-items: center;
    gap: .45rem;
    margin-bottom: 0;
    font-size: .78rem;
    color: var(--bs-secondary-color);
    white-space: nowrap;
}

/* length select */
div.dataTables_wrapper div.dataTables_length select {
    width: auto;
    min-width: 4.5rem;
    padding: .28rem .55rem !important;
    font-size: .78rem !important;
    border-radius: .375rem !important;
    border: 1px solid #cbd5e1 !important;
    background-color: var(--bs-body-bg);
    color: var(--bs-body-color);
    transition: border-color .15s, box-shadow .15s;
}

div.dataTables_wrapper div.dataTables_length select:focus {
    outline: none;
    border-color: var(--accent) !important;
    box-shadow: 0 0 0 3px rgba(99,102,241,.14) !important;
}

/* search input */
div.dataTables_wrapper div.dataTables_filter input {
    width: 200px;
    padding: .28rem .65rem !important;
    font-size: .78rem !important;
    border-radius: .375rem !important;
    border: 1px solid #cbd5e1 !important;
    background-color: var(--bs-body-bg);
    color: var(--bs-body-color);
    transition: border-color .15s, box-shadow .15s;
}

div.dataTables_wrapper div.dataTables_filter input:focus {
    outline: none;
    border-color: var(--accent) !important;
    box-shadow: 0 0 0 3px rgba(99,102,241,.14) !important;
}

/* info text */
div.dataTables_wrapper div.dataTables_info {
    padding: .65rem 1rem .5rem !important;
    font-size: .74rem !important;
    color: var(--bs-secondary-color);
}

/* paginate wrapper */
div.dataTables_wrapper div.dataTables_paginate {
    padding: .4rem 1rem .65rem !important;
}

/* DataTables pagination — pill style */
div.dataTables_wrapper .pagination .page-link {
    border-radius: 50rem !important;
    padding: .22rem .6rem;
    font-size: .75rem;
    line-height: 1.5;
    border-color: #e2e8f0;
    color: #6366f1;
}

div.dataTables_wrapper .pagination .page-item.active .page-link {
    background-color: #6366f1 !important;
    border-color: #6366f1 !important;
    color: #fff !important;
    box-shadow: 0 1px 4px rgba(99,102,241,.35);
}

div.dataTables_wrapper .pagination .page-item.disabled .page-link {
    color: #94a3b8;
    background-color: transparent;
    border-color: #e2e8f0;
}

/* processing overlay */
div.dataTables_processing {
    background: rgba(255,255,255,.92) !important;
    border: 1px solid #e2e8f0 !important;
    border-radius: .6rem;
    box-shadow: 0 4px 16px rgba(0,0,0,.1) !important;
    font-size: .78rem;
    color: #64748b;
    padding: .55rem 1.75rem !important;
    backdrop-filter: blur(2px);
}

[data-bs-theme="dark"] div.dataTables_processing {
    background: rgba(26,34,52,.94) !important;
    border-color: rgba(255,255,255,.1) !important;
}

[data-bs-theme="dark"] div.dataTables_wrapper div.dataTables_length select,
[data-bs-theme="dark"] div.dataTables_wrapper div.dataTables_filter input {
    border-color: rgba(255,255,255,.15) !important;
}

/* ── Sorting icons ───────────────────────────────────────── */
table.dataTable thead .sorting:after,
table.dataTable thead .sorting_asc:after,
table.dataTable thead .sorting_desc:after,
table.dataTable thead .sorting_asc_disabled:after,
table.dataTable thead .sorting_desc_disabled:after {
    opacity: .45;
    font-size: .6rem;
    bottom: .6rem;
}

table.dataTable thead .sorting_asc:after  { opacity: 1; color: var(--accent); }
table.dataTable thead .sorting_desc:after { opacity: 1; color: var(--accent); }


/* ============================================================
   BREADCRUMB
   ============================================================ */
.breadcrumb {
    margin-bottom: .75rem;
    font-size: .8rem;
}

/* ============================================================
   ALERTS
   ============================================================ */
.alert { border-radius: 10px; border-left-width: 4px; }

/* ============================================================
   PAGINATION — small, rounded-pill buttons with indigo accent
   ============================================================ */
.pagination { gap: .2rem; }

.page-link {
    border-radius: 50rem !important;
    padding: .25rem .65rem;
    font-size: .8rem;
    line-height: 1.5;
    border-color: #e2e8f0;
    color: #6366f1;
    transition: background .15s, border-color .15s, color .15s;
}

.page-link:hover {
    background-color: rgba(99, 102, 241, .08);
    border-color: #6366f1;
    color: #4f46e5;
}

.page-item.active .page-link {
    background-color: #6366f1;
    border-color: #6366f1;
    color: #ffffff;
    box-shadow: 0 1px 4px rgb(99 102 241 / 0.35);
}

.page-item.disabled .page-link {
    color: #94a3b8;
    background-color: transparent;
    border-color: #e2e8f0;
}

/* ============================================================
   GRID-VIEW sort arrows
   ============================================================ */
a.asc::after, a.desc::after {
    content: '';
    display: inline-block;
    width: 0; height: 0;
    margin: 3px 3px 1px 4px;
    border: solid 4px transparent;
    background: transparent;
}
a.asc::after  { border-bottom: solid 6px var(--bs-body-color); border-top-width: 0; }
a.desc::after { border-top: solid 6px var(--bs-body-color); border-bottom-width: 0; }

.grid-view th { white-space: nowrap; }

.hint-block {
    display: block;
    margin-top: 4px;
    color: var(--bs-secondary-color);
    font-size: .82rem;
}

.error-summary {
    color: var(--bs-danger-text-emphasis);
    background: var(--bs-danger-bg-subtle);
    border-left: 4px solid var(--bs-danger);
    padding: .75rem 1rem;
    margin-bottom: 1rem;
    border-radius: 0 8px 8px 0;
}

/* ============================================================
   SIDEBAR OVERLAY (mobile)
   ============================================================ */
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.45);
    z-index: 1045;
}

/* ============================================================
   RESPONSIVE
   ============================================================ */
@media (max-width: 991.98px) {
    .sidebar {
        transform: translateX(-100%);
        width: var(--sidebar-width) !important;
    }

    .sidebar.mobile-open {
        transform: translateX(0);
    }

    .sidebar-overlay.active { display: block; }

    .main-wrapper {
        margin-left: 0 !important;
    }

    /* reset ALL collapsed-state overrides on mobile — sidebar is full-width */
    body.sidebar-collapsed .sidebar-section {
        height: auto;
        padding: 1rem 1.1rem .3rem;
        overflow: visible;
        opacity: 1;
        pointer-events: auto;
    }

    body.sidebar-collapsed .sidebar-nav-label,
    body.sidebar-collapsed .sidebar-brand-text,
    body.sidebar-collapsed .sidebar-chevron,
    body.sidebar-collapsed .sidebar-user-info,
    body.sidebar-collapsed .sidebar-user-logout {
        width: auto;
        overflow: visible;
        opacity: 1;
        pointer-events: auto;
        flex-shrink: 1;
    }

    body.sidebar-collapsed .sidebar-submenu {
        max-height: 0 !important; /* keep submenus closed; JS manages .open on mobile */
    }

    body.sidebar-collapsed .sidebar-nav-link {
        justify-content: flex-start;
        padding-left: 1.1rem;
        padding-right: 1.1rem;
        gap: .75rem;
    }

    body.sidebar-collapsed .sidebar-brand {
        justify-content: flex-start;
        padding: 0 1.1rem;
        gap: .75rem;
    }

    body.sidebar-collapsed .sidebar-user {
        justify-content: flex-start;
        padding: .85rem 1.1rem;
        gap: .7rem;
    }
}

/* ============================================================
   NOT-SET (form helpers)
   ============================================================ */
.not-set { color: var(--bs-danger); font-style: italic; }

/* ============================================================
   FOOTER
   ============================================================ */
.main-footer {
    padding: .85rem 1.5rem;
    font-size: .78rem;
    color: var(--bs-secondary-color);
    border-top: 1px solid var(--bs-border-color);
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    flex-wrap: wrap;
}

/* ============================================================
   MODAL CHROME — all Bootstrap modals
   ============================================================ */
.modal-content {
    border-radius: 14px;
    border: none;
    box-shadow: 0 20px 60px rgba(0,0,0,.18);
    overflow: hidden;
}

.modal-header {
    border-bottom: 1px solid #e2e8f0;
    padding: 1rem 1.25rem;
    position: relative;
}

.modal-header::before {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0;
    height: 3px;
    background: linear-gradient(90deg, var(--accent), #818cf8);
}

.modal-title {
    font-size: 1rem;
    font-weight: 700;
    letter-spacing: -.02em;
    line-height: 1.3;
    color: var(--bs-body-color);
    display: flex;
    align-items: center;
    gap: .6rem;
    margin-bottom: 0;
}

/* Coloured icon badge inside modal titles */
.modal-title-icon {
    width: 30px;
    height: 30px;
    border-radius: 8px;
    background: rgba(99,102,241,.12);
    color: var(--accent);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: .95rem;
    flex-shrink: 0;
}

[data-bs-theme="dark"] .modal-title-icon {
    background: rgba(99,102,241,.22);
}

.modal-body { padding: 1.25rem; }

.modal-footer {
    border-top: 1px solid #e2e8f0;
    padding: .85rem 1.25rem;
    background: #f8fafc;
}

[data-bs-theme="dark"] .modal-header { border-bottom-color: rgba(255,255,255,.08); }
[data-bs-theme="dark"] .modal-footer {
    border-top-color: rgba(255,255,255,.08);
    background: rgba(255,255,255,.03);
}

/* ============================================================
   FORM COMPONENTS — global (crm-form-field / crm-form-section)
   Used in all modal forms and standalone form pages.
   ============================================================ */

/* Section divider */
.crm-form-section {
    font-size: .68rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .09em;
    color: var(--accent);
    margin: 0 0 10px;
    padding-bottom: 5px;
    border-bottom: 2px solid rgba(99,102,241,.18);
}

/* Field wrapper */
.crm-form-field { margin-bottom: 12px; }

.crm-form-field label {
    display: block;
    font-size: .75rem;
    font-weight: 600;
    color: #374151;
    margin-bottom: 4px;
}

[data-bs-theme="dark"] .crm-form-field label { color: #cbd5e1; }

/* Inputs and selects — scoped to crm-form-field or modal-body */
.crm-form-field .form-control,
.crm-form-field .form-control-sm,
.crm-form-field .form-select,
.crm-form-field .form-select-sm,
.modal-body .form-control,
.modal-body .form-control-sm,
.modal-body .form-select,
.modal-body .form-select-sm {
    font-size: .875rem;
    height: 36px;
    padding: .375rem .75rem;
    border-radius: 8px;
    border: 1.5px solid #d1d5db;
    background-color: #fff;
    transition: border-color .15s ease, box-shadow .15s ease;
    box-shadow: none;
}

.crm-form-field textarea.form-control,
.modal-body textarea.form-control {
    height: auto;
    min-height: 76px;
    resize: vertical;
}

.crm-form-field .form-control:focus,
.crm-form-field .form-select:focus,
.modal-body .form-control:focus,
.modal-body .form-select:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(99,102,241,.14);
    outline: none;
}

[data-bs-theme="dark"] .crm-form-field .form-control,
[data-bs-theme="dark"] .crm-form-field .form-select,
[data-bs-theme="dark"] .modal-body .form-control,
[data-bs-theme="dark"] .modal-body .form-select {
    background: #1e293b;
    border-color: rgba(255,255,255,.16);
    color: #f1f5f9;
}

/* Validation states */
.has-error .form-control,
.has-error .form-select                   { border-color: #ef4444 !important; }
.has-error .form-control:focus,
.has-error .form-select:focus             { box-shadow: 0 0 0 3px rgba(239,68,68,.15) !important; }

.help-block {
    display: block;
    font-size: .72rem;
    color: #ef4444;
    margin-top: 3px;
}

/* Input group */
.crm-form-field .input-group-text,
.modal-body .input-group-text {
    font-size: .85rem;
    padding: 0 10px;
    background: #f8fafc;
    border: 1.5px solid #d1d5db;
    color: #6b7280;
}

.crm-form-field .input-group .form-control,
.modal-body .input-group .form-control    { border-left: 0; }

[data-bs-theme="dark"] .crm-form-field .input-group-text,
[data-bs-theme="dark"] .modal-body .input-group-text {
    background: #1e293b;
    border-color: rgba(255,255,255,.16);
    color: #94a3b8;
}

/* ============================================================
   TOM SELECT — scoped to modal body (form dropdowns)
   ============================================================ */
.modal-body .ts-wrapper.single .ts-control,
.modal-body .ts-wrapper.multi  .ts-control {
    min-height: 36px;
    padding: 3px 10px;
    font-size: .875rem;
    border: 1.5px solid #d1d5db;
    border-radius: 8px;
    background: #fff;
    transition: border-color .15s, box-shadow .15s;
}

.modal-body .ts-wrapper.multi .ts-control {
    flex-wrap: wrap;
    gap: 2px;
    padding: 3px 8px;
    height: auto;
}

.modal-body .ts-wrapper.multi .ts-control .item {
    font-size: .78rem;
    background: rgba(99,102,241,.1);
    border: 1px solid rgba(99,102,241,.25);
    color: #4f46e5;
    border-radius: 4px;
    padding: 1px 7px;
    font-weight: 500;
    margin: 1px;
}

.modal-body .ts-wrapper.focus .ts-control {
    border-color: var(--accent) !important;
    box-shadow: 0 0 0 3px rgba(99,102,241,.14) !important;
}

.modal-body .ts-dropdown {
    font-size: .875rem;
    border: 1.5px solid #e2e8f0;
    border-radius: 8px;
    box-shadow: 0 8px 24px rgba(0,0,0,.12);
    margin-top: 2px;
}

.modal-body .ts-dropdown .option {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 7px 12px;
}

.modal-body .ts-dropdown .option.active,
.modal-body .ts-dropdown .option:hover {
    background: rgba(99,102,241,.07);
    color: var(--accent);
}

.modal-body .ts-dropdown .option input[type=checkbox] {
    flex-shrink: 0;
    accent-color: var(--accent);
}

[data-bs-theme="dark"] .modal-body .ts-wrapper .ts-control {
    background: #1e293b;
    border-color: rgba(255,255,255,.16);
    color: #f1f5f9;
}

[data-bs-theme="dark"] .modal-body .ts-dropdown {
    background: #1e293b;
    border-color: rgba(255,255,255,.1);
    color: #f1f5f9;
}

/* ============================================================
   GRADIENT THEME + COMPACT DENSITY
   ============================================================ */

/* ---- CSS variable overrides -------------------------------- */
:root { --topbar-height: 56px; }

/* ---- Sidebar ---- */
.sidebar        { background: linear-gradient(160deg, #0d1117 0%, #1e1b4b 100%); }
.sidebar-brand  { background: linear-gradient(135deg, #080c14 0%, #100d2a 100%); }

.sidebar-nav-link {
    padding: .46rem 1.1rem;
}

.sidebar-nav-link.active {
    background: linear-gradient(90deg, rgba(99,102,241,.22) 0%, rgba(99,102,241,.06) 100%);
}

.sidebar-nav-link.active::before {
    background: linear-gradient(180deg, #a5b4fc 0%, #6366f1 100%);
}

/* ---- Topbar ---- */
.topbar {
    background: linear-gradient(135deg, #ffffff 0%, #faf9ff 100%);
}

/* ---- Page content ---- */
.page-content {
    padding: 1.25rem;
    background:
        linear-gradient(160deg, rgba(99,102,241,.04) 0%, transparent 35%),
        var(--content-bg);
}

/* ---- Cards ---- */
.card-header {
    padding: .7rem 1.25rem;
    background: linear-gradient(135deg, rgba(99,102,241,.055) 0%, transparent 60%) !important;
}

/* ---- Primary buttons ---- */
.btn-primary {
    background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
    border-color: transparent;
    box-shadow: 0 2px 8px rgba(99,102,241,.28);
}

.btn-primary:hover,
.btn-primary:focus-visible {
    background: linear-gradient(135deg, #4f46e5 0%, #7c3aed 100%);
    border-color: transparent;
    box-shadow: 0 4px 14px rgba(99,102,241,.38);
}

.btn-primary:active {
    background: linear-gradient(135deg, #4338ca 0%, #6d28d9 100%) !important;
    border-color: transparent !important;
}

.btn-primary:focus-visible {
    box-shadow: 0 0 0 3px rgba(99,102,241,.35) !important;
}

/* ---- Outline-primary: gradient border illusion on hover ---- */
.btn-outline-primary:hover {
    background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
    border-color: transparent;
    color: #fff;
}

/* ---- Modal header ---- */
.modal-header {
    background: linear-gradient(135deg, rgba(99,102,241,.09) 0%, rgba(139,92,246,.04) 100%);
}

/* ---- Modal title icon ---- */
.modal-title-icon {
    width: 28px;
    height: 28px;
    background: linear-gradient(135deg, rgba(99,102,241,.2) 0%, rgba(139,92,246,.14) 100%);
}

/* ---- Compact modal ---- */
.modal-body   { padding: .9rem 1.1rem; }
.modal-footer { padding: .6rem 1.1rem; }

/* ---- Compact form fields ---- */
.crm-form-field { margin-bottom: 10px; }
.crm-form-section { margin-bottom: 8px; }

/* ---- Table header gradient ---- */
.table thead th,
.table thead td {
    background: linear-gradient(180deg, #f8fafc 0%, #f1f5f9 100%);
}

div.dataTables_wrapper table.dataTable > thead > tr > th,
div.dataTables_wrapper table.dataTable > thead > tr > td {
    background: linear-gradient(180deg, #f8fafc 0%, #f1f5f9 100%) !important;
}

/* ---- Dark mode ---- */
[data-bs-theme="dark"] .topbar {
    background: linear-gradient(135deg, #1a2234 0%, #1a1535 100%);
}

[data-bs-theme="dark"] .card-header {
    background: linear-gradient(135deg, rgba(99,102,241,.09) 0%, transparent 60%) !important;
}

[data-bs-theme="dark"] .modal-header {
    background: linear-gradient(135deg, rgba(99,102,241,.14) 0%, rgba(139,92,246,.06) 100%);
}

[data-bs-theme="dark"] .table thead th,
[data-bs-theme="dark"] .table thead td,
[data-bs-theme="dark"] div.dataTables_wrapper table.dataTable > thead > tr > th,
[data-bs-theme="dark"] div.dataTables_wrapper table.dataTable > thead > tr > td {
    background: linear-gradient(180deg, rgba(255,255,255,.04) 0%, rgba(255,255,255,.02) 100%) !important;
}

/* ============================================================
   PERMISSION TABS  — segmented pill control
   ============================================================ */
.perm-tab-track {
    display: inline-flex;
    background: #f1f5f9;
    border-radius: 10px;
    padding: 3px;
    gap: 2px;
    margin-bottom: 10px;
}

.perm-tab-btn {
    display: inline-flex;
    align-items: center;
    padding: 5px 16px;
    border-radius: 7px;
    font-size: .8125rem;
    font-weight: 500;
    color: #64748b;
    text-decoration: none;
    transition: background .14s, color .14s, box-shadow .14s;
    white-space: nowrap;
    user-select: none;
    line-height: 1.4;
}

.perm-tab-btn:hover:not(.active) {
    background: rgba(0,0,0,.05);
    color: #334155;
}

.perm-tab-btn.active {
    background: #fff;
    color: var(--accent);
    font-weight: 600;
    box-shadow: 0 1px 3px rgba(0,0,0,.1), 0 0 0 1px rgba(0,0,0,.05);
}

.perm-tab-content {
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    padding: .875rem 1rem;
    margin-bottom: 1rem;
}

/* Permission table — horizontal rules only, no box borders */
.perm-table {
    margin-bottom: 0;
    font-size: .8125rem;
    border-collapse: collapse;
}

.perm-table thead th {
    font-size: .7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .05em;
    color: #94a3b8;
    padding: 0 8px 8px;
    border-bottom: 1px solid #e2e8f0 !important;
    background: none !important;
    vertical-align: bottom;
}

.perm-table tbody tr {
    border-bottom: 1px solid #f1f5f9;
}

.perm-table tbody tr:last-child {
    border-bottom: none;
}

.perm-table tbody td {
    padding: 6px 8px;
    border: none !important;
    vertical-align: middle;
}

/* ---- Dark mode ---- */
[data-bs-theme="dark"] .perm-tab-track {
    background: rgba(255,255,255,.06);
}

[data-bs-theme="dark"] .perm-tab-btn {
    color: rgba(255,255,255,.45);
}

[data-bs-theme="dark"] .perm-tab-btn:hover:not(.active) {
    background: rgba(255,255,255,.07);
    color: rgba(255,255,255,.75);
}

[data-bs-theme="dark"] .perm-tab-btn.active {
    background: rgba(99,102,241,.2);
    color: #a5b4fc;
    box-shadow: 0 1px 3px rgba(0,0,0,.25);
}

[data-bs-theme="dark"] .perm-tab-content {
    border-color: rgba(255,255,255,.1);
}

[data-bs-theme="dark"] .perm-table thead th {
    color: rgba(255,255,255,.3);
    border-bottom-color: rgba(255,255,255,.08) !important;
}

[data-bs-theme="dark"] .perm-table tbody tr {
    border-bottom-color: rgba(255,255,255,.05);
}

/* ============================================================
   CHECKBOXES — crisp visible border, clear states
   ============================================================ */
.form-check-input[type=checkbox] {
    width: 1rem;
    height: 1rem;
    border: 1.5px solid #94a3b8;
    border-radius: 4px;
    background-color: #fff;
    cursor: pointer;
    flex-shrink: 0;
    transition: border-color .12s, background-color .12s, box-shadow .12s;
    appearance: none;
    -webkit-appearance: none;
    background-repeat: no-repeat;
    background-position: center;
    background-size: .75em .75em;
    print-color-adjust: exact;
    vertical-align: middle;
}

.form-check-input[type=checkbox]:hover:not(:checked):not(:disabled) {
    border-color: var(--accent);
    background-color: rgba(99,102,241,.04);
}

.form-check-input[type=checkbox]:checked {
    background-color: var(--accent);
    border-color: var(--accent);
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20'%3e%3cpath fill='none' stroke='%23fff' stroke-linecap='round' stroke-linejoin='round' stroke-width='3' d='m6 10 3 3 6-6'/%3e%3c/svg%3e");
}

.form-check-input[type=checkbox]:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(99,102,241,.15);
    outline: none;
}

.form-check-input[type=checkbox]:disabled {
    opacity: .45;
    cursor: not-allowed;
}

/* Dark mode */
[data-bs-theme="dark"] .form-check-input[type=checkbox] {
    background-color: rgba(255,255,255,.06);
    border-color: rgba(255,255,255,.3);
}

[data-bs-theme="dark"] .form-check-input[type=checkbox]:hover:not(:checked):not(:disabled) {
    border-color: #a5b4fc;
    background-color: rgba(99,102,241,.1);
}

[data-bs-theme="dark"] .form-check-input[type=checkbox]:checked {
    background-color: var(--accent);
    border-color: var(--accent);
}
