/* ============================================================================
   TICKET SYNC — Master Stylesheet v3.6
   Server-driven dark mode (both [data-theme="dark"] and [data-bs-theme="dark"])
   ============================================================================ */

/* ============================================================================
   1. CSS VARIABLES — LIGHT MODE (DEFAULT)
   ============================================================================ */
   :root {
    --primary: #0d6efd;
    --primary-dark: #0a58ca;
    --primary-light: #e7f1ff;
    --primary-rgb: 13, 110, 253;

    --secondary: #6c757d;
    --success: #198754;
    --danger: #dc3545;
    --warning: #ffc107;
    --info: #0dcaf0;
    --dark: #212529;
    --light: #f8f9fa;

    /* Background */
    --bg-body: #f0f2f5;
    --bg-white: #ffffff;
    --bg-card: #ffffff;
    --bg-light: #f8f9fa;
    --bg-dark: #1a1a2e;
    --bg-input: #ffffff;
    --bg-dropdown: #ffffff;
    --bg-modal: #ffffff;
    --bg-table: #ffffff;
    --bg-table-stripe: #f8f9fa;

    /* Text */
    --text-primary: #212529;
    --text-secondary: #6c757d;
    --text-muted: #6c757d;
    --text-white: #ffffff;
    --text-body: #212529;
    --text-heading: #212529;
    --text-dark: #212529;

    /* Borders */
    --border-color: #dee2e6;
    --border-light: #e9ecef;
    --border-dark: #ced4da;

    /* Sidebar (always dark) */
    /* Sidebar surfaces follow the active theme; the dark values are
       re-declared in the dark-mode block below. */
    --sidebar-bg: #ffffff;
    --sidebar-border: #e5e7eb;
    --sidebar-text: #475569;
    --sidebar-text-hover: #0f172a;
    --sidebar-hover: rgba(15, 23, 42, 0.06);
    --sidebar-active: rgba(var(--accent-color-rgb), 0.12);
    --sidebar-subnav-bg: rgba(15, 23, 42, 0.035);

    /* Shadows */
    --shadow-sm: 0 0.125rem 0.25rem rgba(0, 0, 0, 0.075);
    --shadow-md: 0 0.5rem 1rem rgba(0, 0, 0, 0.15);
    --shadow-lg: 0 1rem 3rem rgba(0, 0, 0, 0.175);

    /* Auth pages */
    --auth-box-border: #dee2e6;
    --auth-link-hover: #0d6efd;
    --auth-shadow-alpha: 0.15;

    /* Layout */
    --sidebar-width: 260px;
    --right-sidebar-width: 300px;
    --header-height: 64px;

    /* Radius */
    --radius-sm: 0.25rem;
    --radius-md: 0.5rem;
    --radius-lg: 1rem;

    /* Font */
    --font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    --transition-speed: 0.3s;

    /* Accent (per-user, unchanged) */
    --accent-color: #0d6efd;
    --accent-color-rgb: 13, 110, 253;
    --accent-color-dark: #0a58ca;
    --accent-color-light: #e7f1ff;
}

/* ============================================================================
   2. DARK MODE VARIABLES
   Two selectors so both our JS and Bootstrap 5.3 both work.
   ============================================================================ */
[data-theme="dark"],
[data-bs-theme="dark"] {
    --bg-body: #0d1117;
    --bg-white: #161b22;
    --bg-card: #161b22;
    --bg-light: #21262d;
    --bg-input: #0d1117;
    --bg-dropdown: #161b22;
    --bg-modal: #161b22;
    --bg-table: #161b22;
    --bg-table-stripe: #21262d;

    --text-primary: #f0f6fc;
    --text-secondary: #9da7b3;
    --text-muted: #9da7b3;
    --text-white: #ffffff;
    --text-body: #f0f6fc;
    --text-heading: #f0f6fc;
    --text-dark: #f0f6fc;

    --border-color: #30363d;
    --border-light: #21262d;
    --border-dark: #484f58;

    --shadow-sm: 0 0.125rem 0.25rem rgba(0, 0, 0, 0.3);
    --shadow-md: 0 0.5rem 1rem rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 1rem 3rem rgba(0, 0, 0, 0.5);

    --auth-box-border: rgba(255, 255, 255, 0.35);
    --auth-link-hover: #ffffff;
    --auth-shadow-alpha: 0.5;

    --sidebar-bg: #0f172a;
    --sidebar-border: rgba(255, 255, 255, 0.08);
    --sidebar-text: rgba(255, 255, 255, 0.72);
    --sidebar-text-hover: #ffffff;
    --sidebar-hover: rgba(255, 255, 255, 0.08);
    --sidebar-active: rgba(var(--accent-color-rgb), 0.22);
    --sidebar-subnav-bg: rgba(0, 0, 0, 0.18);

    color-scheme: dark;
}

/* ============================================================================
   3. ACCENT COLOR VARIANTS
   ============================================================================ */
[data-accent="blue"]   { --accent-color: #0d6efd; --accent-color-rgb: 13,110,253; --accent-color-dark: #0a58ca; --accent-color-light: #e7f1ff; }
[data-accent="purple"] { --accent-color: #6f42c1; --accent-color-rgb: 111,66,193; --accent-color-dark: #5a32a3; --accent-color-light: #f0e6ff; }
[data-accent="green"]  { --accent-color: #198754; --accent-color-rgb: 25,135,84; --accent-color-dark: #157347; --accent-color-light: #e6f5ed; }
[data-accent="red"]    { --accent-color: #dc3545; --accent-color-rgb: 220,53,69; --accent-color-dark: #b02a37; --accent-color-light: #fce8ea; }
[data-accent="orange"] { --accent-color: #fd7e14; --accent-color-rgb: 253,126,20; --accent-color-dark: #d96c0e; --accent-color-light: #fff0e6; }
[data-accent="teal"]   { --accent-color: #20c997; --accent-color-rgb: 32,201,151; --accent-color-dark: #1ba87e; --accent-color-light: #e6f9f2; }
[data-accent="pink"]   { --accent-color: #d63384; --accent-color-rgb: 214,51,132; --accent-color-dark: #b62a6e; --accent-color-light: #fce6f2; }

/* ============================================================================
   4. APPLY ACCENT
   ============================================================================ */
.btn-primary { background-color: var(--accent-color) !important; border-color: var(--accent-color) !important; color: #fff !important; }
.btn-primary:hover { background-color: var(--accent-color-dark) !important; border-color: var(--accent-color-dark) !important; color: #fff !important; }
.btn-outline-primary { color: var(--accent-color) !important; border-color: var(--accent-color) !important; }
.btn-outline-primary:hover { background-color: var(--accent-color) !important; color: #fff !important; }
.text-primary { color: var(--accent-color) !important; }
.bg-primary { background-color: var(--accent-color) !important; }
.border-primary { border-color: var(--accent-color) !important; }
.sidebar .nav-link.active { border-left-color: var(--accent-color) !important; background: var(--sidebar-active) !important; }
.sidebar .nav-link:hover { border-left-color: var(--accent-color) !important; }
.stat-card-primary { background: linear-gradient(135deg, var(--accent-color), var(--accent-color-dark)) !important; }

/* ============================================================================
   5. BASE
   ============================================================================ */
* { margin: 0; padding: 0; box-sizing: border-box; }

body {
    font-family: var(--font-family);
    background-color: var(--bg-body);
    color: var(--text-body);
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
    transition: background-color 0.3s ease, color 0.3s ease;
}

a { text-decoration: none; color: var(--accent-color); transition: color var(--transition-speed); }
a:hover { color: var(--accent-color-dark); }
a.text-muted:hover { color: var(--accent-color) !important; }

/* ============================================================================
   6. TYPOGRAPHY
   ============================================================================ */
h1, h2, h3, h4, h5, h6,
.h1, .h2, .h3, .h4, .h5, .h6 { color: var(--text-heading); }

p, span, div, li, td, th, label, .text, .content { color: var(--text-body); }

.text-muted { color: var(--text-muted) !important; }
.text-secondary { color: var(--text-secondary) !important; }
.text-dark { color: var(--text-dark) !important; }
.text-light { color: var(--text-white) !important; }

/* ============================================================================
   7. LAYOUT
   ============================================================================ */
.app-wrapper { display: flex; min-height: 100vh; background-color: var(--bg-body); }

.sidebar {
    position: fixed; top: 0; left: 0;
    width: var(--sidebar-width); height: 100vh;
    background: var(--sidebar-bg);
    color: var(--sidebar-text);
    border-right: 1px solid var(--sidebar-border);
    z-index: 1040;
    transition: transform var(--transition-speed) ease, background-color var(--transition-speed) ease;
    display: flex; flex-direction: column; overflow: hidden;
}
.sidebar.active { transform: translateX(-100%); }

.sidebar-header { padding: 1rem; border-bottom: 1px solid var(--sidebar-border); flex-shrink: 0;
    display: flex; flex-direction: column; align-items: stretch; gap: 0.6rem; }
/* Logo: no frame, no circle, no background tile. The image is scaled to fit
   the available width/height with object-fit: contain, so a square mark and a
   wide wordmark are both shown in full — never cropped. */
/* Header logo: a large, borderless box that spans the sidebar width and sits
   above the brand/user block. The image is contained inside it and can never
   spill out over the sidebar edge or into the page content. */
.sidebar-logo { display: flex; align-items: center; justify-content: center;
    width: 100%; height: 120px; flex: 0 0 auto;
    background: none; border: 0; border-radius: 0; box-shadow: none;
    overflow: hidden; }
.sidebar-header .d-flex { gap: 0.5rem; min-width: 0; }
.sidebar-brand { min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-header .sidebar-brand { text-align: center; }
.sidebar-brand { font-size: 1.1rem; line-height: 1.2; color: var(--sidebar-text-hover); }
.sidebar-brand small { font-size: 0.65rem; opacity: 0.75; color: var(--sidebar-text); }
.sidebar-brand .fw-bold { color: var(--sidebar-text-hover); }

.sidebar-user { padding: 1rem; border-bottom: 1px solid var(--sidebar-border); flex-shrink: 0; }
.sidebar-user .fw-bold { color: var(--sidebar-text-hover); }
.sidebar-user .badge { color: var(--badge-ink); }
.avatar-circle { width: 40px; height: 40px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-weight: 600; font-size: 1rem; flex-shrink: 0; color: #fff; }

/* One vertical column, always.
   The menu is a Bootstrap .nav (display:flex; flex-wrap:wrap). Inside a
   height-limited sidebar a wrapped column-direction flex container lays the
   overflowing items out in a NEW COLUMN to the right instead of scrolling —
   that is why an expanded submenu used to appear beside the drawer and spill
   over the page. nowrap + min-height:0 keeps everything stacked and lets the
   list scroll vertically. */
.sidebar .nav {
    flex: 1 1 auto;
    min-height: 0;
    flex-direction: column;
    flex-wrap: nowrap;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 0.5rem 0;
}
.sidebar .nav > .nav-item { width: 100%; flex: 0 0 auto; }
.sidebar .nav-link { color: var(--sidebar-text); padding: 0.6rem 1rem; border-radius: 0; border-left: 3px solid transparent; transition: all var(--transition-speed) ease; display: flex; align-items: center; font-size: 0.9rem; }
.sidebar .nav-link:hover { color: var(--sidebar-text-hover); background: var(--sidebar-hover); border-left-color: var(--accent-color); }
.sidebar .nav-link.active { color: var(--sidebar-text-hover); background: var(--sidebar-active); border-left-color: var(--accent-color); }
.sidebar .nav-link i:first-child { width: 20px; text-align: center; margin-right: 10px; font-size: 1rem; }
.sidebar .nav-link .fa-chevron-down { margin-left: auto; font-size: 0.7rem; transition: transform var(--transition-speed); }
.sidebar .nav-link[aria-expanded="true"] .fa-chevron-down { transform: rotate(180deg); }
.sidebar .nav .nav { background: var(--sidebar-subnav-bg); }
.sidebar .collapse-menu { background: transparent; }
.sidebar .nav .nav .nav-link { padding-left: 2.5rem; font-size: 0.85rem; }
.sidebar .nav .nav .nav-link i:first-child { width: 16px; font-size: 0.8rem; }

/* Sub-menus rendered by includes/sidebar.php (collapsible groups).
   They must stay in normal flow inside their <li>, i.e. expand straight down
   under the parent link — never a floating/off-canvas panel. */
.sidebar .collapse,
.sidebar .collapsing { width: 100%; position: static; float: none; }
.sidebar .collapse-menu { list-style: none; padding-left: 1.25rem; margin: 0.25rem 0 0.35rem 0;
    width: 100%; display: block; }
.sidebar .collapse-menu > li { display: block; width: 100%; }
.sidebar .sub-link { display: flex; align-items: center; gap: 0.5rem;
    color: var(--sidebar-text); padding: 0.45rem 0.85rem; font-size: 0.85rem;
    text-decoration: none; border-radius: var(--radius-sm);
    white-space: normal; overflow-wrap: anywhere;
    transition: color 0.2s ease, background-color 0.2s ease; }
.sidebar .sub-link i { font-size: 0.8rem; width: 15px; text-align: center; flex: 0 0 15px; }
.sidebar .sub-link:hover, .sidebar .sub-link.active { color: var(--sidebar-text-hover); background-color: var(--sidebar-hover); }
.badge-pending { animation: pulse-badge 2s infinite; }
@keyframes pulse-badge { 0%, 100% { opacity: 1; } 50% { opacity: 0.6; } }

.sidebar-footer { padding: 1rem; border-top: 1px solid var(--sidebar-border); flex-shrink: 0; }

.right-sidebar {
    position: fixed; top: 0; right: 0;
    width: var(--right-sidebar-width); height: 100vh;
    background: var(--bg-body);
    border-left: 1px solid var(--border-color);
    z-index: 1020; overflow-y: auto;
    padding: 70px 12px 20px 12px;
    transition: transform 0.3s ease;
    display: block !important;
}
.right-sidebar.collapsed { transform: translateX(var(--right-sidebar-width)); }
.right-sidebar-content { display: flex; flex-direction: column; gap: 12px; }

#content {
    margin-left: var(--sidebar-width);
    margin-right: var(--right-sidebar-width);
    min-height: 100vh;
    width: calc(100% - var(--sidebar-width) - var(--right-sidebar-width));
    transition: all var(--transition-speed) ease;
    display: flex; flex-direction: column;
    background-color: var(--bg-body);
}
#content.active { margin-left: 0; width: calc(100% - var(--right-sidebar-width)); }
#content.expanded { margin-right: 0; width: calc(100% - var(--sidebar-width)); }
#content.active.expanded { margin-left: 0; margin-right: 0; width: 100%; }
#content.full-width { margin-left: 0; margin-right: 0; width: 100%; }

.navbar {
    padding: 0.5rem 1.5rem;
    height: var(--header-height);
    flex-shrink: 0;
    background: var(--bg-white) !important;
    border-bottom: 1px solid var(--border-color);
    box-shadow: var(--shadow-sm);
    transition: background-color 0.3s ease, border-color 0.3s ease;
}
.navbar .btn-link { color: var(--text-primary); padding: 0.25rem 0.5rem; }
.navbar .btn-link:hover { color: var(--accent-color); }
.navbar .navbar-brand,
.ts-header-brand { color: var(--text-primary) !important; }
.navbar .text-dark { color: var(--text-primary) !important; }
.navbar .user-name { color: var(--text-primary); }

.main-content { flex: 1; padding: 1.5rem; overflow-y: auto; background-color: var(--bg-body); }
.main-content-inner { display: flex; gap: 1.5rem; min-height: 100%; }
.page-content { flex: 1; min-width: 0; overflow-x: hidden; }

#sidebarCollapse {
    font-size: 1.5rem; padding: 0.25rem 0.5rem;
    border: none; background: transparent; color: var(--text-primary);
    cursor: pointer !important; user-select: none !important;
    transition: all 0.3s ease;
    display: inline-flex; align-items: center; justify-content: center;
    width: 44px; height: 44px; border-radius: 8px;
    caret-color: transparent !important;
}
#sidebarCollapse *, #sidebarCollapse i, #sidebarCollapse .fas, #sidebarCollapse .fa-bars {
    cursor: pointer !important; user-select: none !important;
    pointer-events: none;
}
#sidebarCollapse:hover { background: rgba(var(--accent-color-rgb), 0.08); color: var(--accent-color); }
#sidebarCollapse:focus, #sidebarCollapse:active { outline: none !important; box-shadow: none !important; cursor: pointer !important; }
#sidebarCollapse i { font-size: 1.4rem; transition: transform 0.3s ease; pointer-events: none; }
#sidebarCollapse:hover i { transform: scale(1.1); }

#rightSidebarToggle {
    display: none;
    background: var(--bg-white) !important;
    border: 1px solid var(--border-color) !important;
    box-shadow: 0 4px 15px rgba(0,0,0,0.15) !important;
    transition: all 0.3s ease;
}
#rightSidebarToggle:hover { transform: scale(1.05); box-shadow: 0 6px 20px rgba(0,0,0,0.2) !important; }
#rightSidebarToggle i { font-size: 1.2rem; color: var(--text-primary); }

/* ============================================================================
   8. CARDS
   ============================================================================ */
.card { border: none; border-radius: var(--radius-md); box-shadow: var(--shadow-sm); transition: all var(--transition-speed) ease; background: var(--bg-card); color: var(--text-primary); }
.card:hover { box-shadow: var(--shadow-md); }
.card-header { background: var(--bg-light); border-bottom: 1px solid var(--border-color); padding: 1rem 1.25rem; font-weight: 600; color: var(--text-primary); }
.card-header .text-muted { color: var(--text-muted) !important; }
.card-body { padding: 1.25rem; color: var(--text-body); }
.card-footer { background: var(--bg-light); border-top: 1px solid var(--border-color); padding: 0.75rem 1.25rem; color: var(--text-secondary); }

/* ============================================================================
   9. STAT CARDS
   ============================================================================ */
.stat-card { border-radius: var(--radius-md); overflow: hidden; transition: all var(--transition-speed) ease; }
.stat-card:hover { transform: translateY(-4px); box-shadow: var(--shadow-md); }
.stat-card .stat-icon { font-size: 2.5rem; opacity: 0.2; position: absolute; right: 1rem; top: 50%; transform: translateY(-50%); }
.stat-card .card-body { padding: 1.25rem; position: relative; color: #fff; }
.stat-card .stat-value { font-size: 2rem; font-weight: 700; margin-bottom: 0; color: #fff; }
.stat-card .stat-label { font-size: 0.85rem; opacity: 0.8; margin-bottom: 0; color: rgba(255,255,255,0.9); }

.stat-card-primary { background: linear-gradient(135deg, var(--accent-color), var(--accent-color-dark)); color: #fff; }
.stat-card-success { background: linear-gradient(135deg, #198754, #157347); color: #fff; }
.stat-card-warning { background: linear-gradient(135deg, #ffc107, #d39e00); color: #212529; }
.stat-card-warning .stat-value, .stat-card-warning .stat-label { color: #212529; }
.stat-card-danger  { background: linear-gradient(135deg, #dc3545, #b02a37); color: #fff; }
/* Sky blue is a light surface in both themes, so it needs dark ink. */
.stat-card-info    { background: linear-gradient(135deg, #0dcaf0, #0aa2c0); color: #212529; }
.stat-card-info .card-body { color: #212529; }
.stat-card-info .stat-value, .stat-card-info .stat-label { color: #212529; }
.stat-card-secondary { background: linear-gradient(135deg, #6c757d, #5a6268); color: #fff; }

/* ============================================================================
   10. TABLES
   ============================================================================ */
.table { margin-bottom: 0; color: var(--text-body); background-color: var(--bg-table); }
.table th { font-weight: 600; font-size: 0.85rem; text-transform: uppercase; letter-spacing: 0.5px; border-top: none; background: var(--bg-light); color: var(--text-secondary); border-color: var(--border-color); }
.table td { vertical-align: middle; font-size: 0.9rem; border-color: var(--border-color); color: var(--text-body); }
.table-hover tbody tr:hover { background-color: rgba(var(--accent-color-rgb), 0.04); }
.table-striped tbody tr:nth-of-type(odd) { background-color: var(--bg-table-stripe); }
.table .text-muted { color: var(--text-muted) !important; }

/* ============================================================================
   11. FORMS
   ============================================================================ */
.form-control, .form-select { border-radius: var(--radius-sm); border: 1px solid var(--border-color); transition: all var(--transition-speed) ease; background: var(--bg-input); color: var(--text-primary); }
.form-control:focus, .form-select:focus { border-color: var(--accent-color); box-shadow: 0 0 0 0.2rem rgba(var(--accent-color-rgb), 0.25); background: var(--bg-input); color: var(--text-primary); }
.form-control::placeholder { color: var(--text-muted); }
.form-control.is-valid { border-color: var(--success); }
.form-control.is-invalid { border-color: var(--danger); }
.form-label { font-weight: 500; font-size: 0.9rem; margin-bottom: 0.25rem; color: var(--text-secondary); }

/* ============================================================================
   12. BUTTONS
   ============================================================================ */
.btn { border-radius: var(--radius-sm); padding: 0.5rem 1rem; font-weight: 500; transition: all var(--transition-speed) ease; }
.btn:hover { transform: translateY(-1px); box-shadow: var(--shadow-sm); }
.btn-primary { background: var(--accent-color); border-color: var(--accent-color); color: #fff !important; }
.btn-primary:hover { background: var(--accent-color-dark); border-color: var(--accent-color-dark); color: #fff !important; }
.btn-outline-primary { color: var(--accent-color); border-color: var(--accent-color); }
.btn-outline-primary:hover { background: var(--accent-color); color: #fff !important; }
.btn-secondary { background: var(--secondary); border-color: var(--secondary); color: #fff !important; }
.btn-secondary:hover { background: #5a6268; border-color: #5a6268; color: #fff !important; }
.btn-outline-secondary { color: var(--text-secondary); border-color: var(--border-color); }
.btn-outline-secondary:hover { background: var(--secondary); color: #fff !important; }
.btn-link { color: var(--text-primary); }
.btn-link:hover { color: var(--accent-color); }

/* ============================================================================
   13. BADGES — soft status labels
   ----------------------------------------------------------------------------
   Saturated solid pills were replaced with quiet tinted labels: a 10% wash
   of the status colour, a hairline matching border, readable ink and a small
   radius. Same class names as before (bg-*, badge-status-*, badge-priority-*,
   badge-asset-*, badge-condition-*), so every page updates at once.
   ============================================================================ */
.badge {
    --badge-rgb: 108, 117, 125;
    --badge-ink: #565e64;
    display: inline-flex;
    align-items: center;
    gap: .3rem;
    padding: .22rem .55rem;
    border: 1px solid rgba(var(--badge-rgb), .30);
    border-radius: 6px;
    background-color: rgba(var(--badge-rgb), .10) !important;
    color: var(--badge-ink) !important;
    font-size: .72rem;
    font-weight: 600;
    line-height: 1.35;
    letter-spacing: .01em;
    vertical-align: middle;
    white-space: nowrap;
}
a.badge:hover { background-color: rgba(var(--badge-rgb), .17) !important; }

/* Page-header size variant (details pages use .badge.fs-6) */
.badge.fs-6 {
    font-size: .8rem !important;
    padding: .3rem .68rem;
}

/* --- colours: Bootstrap bg-* and the domain status classes --- */
.badge.bg-primary,
.badge-status-in_progress        { --badge-rgb: var(--accent-color-rgb); --badge-ink: var(--accent-color-dark); }

.badge.bg-secondary,
.badge-status-on_hold,
.badge-asset-disposed            { --badge-rgb: 108, 117, 125; --badge-ink: #565e64; }

.badge.bg-success,
.badge-status-resolved,
.badge-priority-low,
.badge-asset-active,
.badge-condition-excellent       { --badge-rgb: 25, 135, 84;   --badge-ink: #146c43; }

.badge.bg-danger,
.badge-status-unresolved,
.badge-priority-critical,
.badge-asset-condemned,
.badge-condition-poor            { --badge-rgb: 220, 53, 69;   --badge-ink: #b02a37; }

.badge.bg-warning,
.badge-status-pending,
.badge-priority-high,
.badge-asset-for_repair,
.badge-condition-fair            { --badge-rgb: 255, 193, 7;   --badge-ink: #8a6700; }

.badge.bg-info,
.badge-status-assigned,
.badge-priority-medium,
.badge-asset-in_storage,
.badge-condition-good            { --badge-rgb: 13, 202, 240;  --badge-ink: #087990; }

.badge.bg-dark,
.badge-status-for_replacement,
.badge-asset-lost                { --badge-rgb: 33, 37, 41;    --badge-ink: #343a40; }

.badge.bg-light,
.badge-status-cancelled          { --badge-rgb: 173, 181, 189; --badge-ink: #565e64; }

/* --- dark theme: brighter ink, slightly stronger tint --- */
[data-theme="dark"] .badge,
[data-bs-theme="dark"] .badge {
    --badge-ink: #adb5bd;
    background-color: rgba(var(--badge-rgb), .16) !important;
    border-color: rgba(var(--badge-rgb), .34);
    color: var(--badge-ink) !important;
}
[data-theme="dark"] .badge.bg-primary,
[data-bs-theme="dark"] .badge.bg-primary,
[data-theme="dark"] .badge-status-in_progress,
[data-bs-theme="dark"] .badge-status-in_progress {
    --badge-ink: #8bb9fe;
    --badge-ink: color-mix(in srgb, var(--accent-color) 55%, #ffffff);
}
[data-theme="dark"] .badge.bg-secondary,
[data-bs-theme="dark"] .badge.bg-secondary,
[data-theme="dark"] .badge-status-on_hold,
[data-bs-theme="dark"] .badge-status-on_hold,
[data-theme="dark"] .badge-asset-disposed,
[data-bs-theme="dark"] .badge-asset-disposed,
[data-theme="dark"] .badge.bg-light,
[data-bs-theme="dark"] .badge.bg-light,
[data-theme="dark"] .badge-status-cancelled,
[data-bs-theme="dark"] .badge-status-cancelled { --badge-ink: #ced4da; }
[data-theme="dark"] .badge.bg-success,
[data-bs-theme="dark"] .badge.bg-success,
[data-theme="dark"] .badge-status-resolved,
[data-bs-theme="dark"] .badge-status-resolved,
[data-theme="dark"] .badge-priority-low,
[data-bs-theme="dark"] .badge-priority-low,
[data-theme="dark"] .badge-asset-active,
[data-bs-theme="dark"] .badge-asset-active,
[data-theme="dark"] .badge-condition-excellent,
[data-bs-theme="dark"] .badge-condition-excellent { --badge-ink: #75b798; }
[data-theme="dark"] .badge.bg-danger,
[data-bs-theme="dark"] .badge.bg-danger,
[data-theme="dark"] .badge-status-unresolved,
[data-bs-theme="dark"] .badge-status-unresolved,
[data-theme="dark"] .badge-priority-critical,
[data-bs-theme="dark"] .badge-priority-critical,
[data-theme="dark"] .badge-asset-condemned,
[data-bs-theme="dark"] .badge-asset-condemned,
[data-theme="dark"] .badge-condition-poor,
[data-bs-theme="dark"] .badge-condition-poor { --badge-ink: #f1aeb5; }
[data-theme="dark"] .badge.bg-warning,
[data-bs-theme="dark"] .badge.bg-warning,
[data-theme="dark"] .badge-status-pending,
[data-bs-theme="dark"] .badge-status-pending,
[data-theme="dark"] .badge-priority-high,
[data-bs-theme="dark"] .badge-priority-high,
[data-theme="dark"] .badge-asset-for_repair,
[data-bs-theme="dark"] .badge-asset-for_repair,
[data-theme="dark"] .badge-condition-fair,
[data-bs-theme="dark"] .badge-condition-fair { --badge-ink: #ffda6a; }
[data-theme="dark"] .badge.bg-info,
[data-bs-theme="dark"] .badge.bg-info,
[data-theme="dark"] .badge-status-assigned,
[data-bs-theme="dark"] .badge-status-assigned,
[data-theme="dark"] .badge-priority-medium,
[data-bs-theme="dark"] .badge-priority-medium,
[data-theme="dark"] .badge-asset-in_storage,
[data-bs-theme="dark"] .badge-asset-in_storage,
[data-theme="dark"] .badge-condition-good,
[data-bs-theme="dark"] .badge-condition-good { --badge-ink: #6edff6; }
[data-theme="dark"] .badge.bg-dark,
[data-bs-theme="dark"] .badge.bg-dark,
[data-theme="dark"] .badge-status-for_replacement,
[data-bs-theme="dark"] .badge-status-for_replacement,
[data-theme="dark"] .badge-asset-lost,
[data-bs-theme="dark"] .badge-asset-lost { --badge-ink: #e9ecef; }

/* Counters sit on the dark sidebar chrome: keep them solid and compact. */
.sidebar .badge.bg-danger {
    padding: .16rem .42rem;
    border: 0;
    border-radius: 999px;
    background-color: #dc3545 !important;
    color: #fff !important;
    font-size: .64rem;
    font-weight: 700;
    line-height: 1.25;
}

/* ============================================================================
   14. ALERTS
   ============================================================================ */
.alert { border: none; border-radius: var(--radius-md); padding: 1rem 1.25rem; color: var(--text-body); }
.alert-success { background-color: rgba(25, 135, 84, 0.15); color: #198754; border-left: 4px solid #198754; }
.alert-danger { background-color: rgba(220, 53, 69, 0.15); color: #dc3545; border-left: 4px solid #dc3545; }
.alert-warning { background-color: rgba(255, 193, 7, 0.15); color: #b8860b; border-left: 4px solid #ffc107; }
.alert-info { background-color: rgba(13, 202, 240, 0.15); color: #0aa2c0; border-left: 4px solid #0dcaf0; }
.alert-dismissible .btn-close { padding: 1rem; }

/* ============================================================================
   15. MODALS
   ============================================================================ */
.modal-content { border: none; border-radius: var(--radius-md); box-shadow: var(--shadow-lg); background: var(--bg-modal); color: var(--text-primary); }
.modal-header { border-bottom: 1px solid var(--border-color); padding: 1rem 1.25rem; }
.modal-header .modal-title { color: var(--text-heading); }
.modal-body { padding: 1.25rem; color: var(--text-body); }
.modal-footer { border-top: 1px solid var(--border-color); padding: 0.75rem 1.25rem; }

/* ============================================================================
   16. DROPDOWNS
   ============================================================================ */
.dropdown-menu { background: var(--bg-dropdown); border: 1px solid var(--border-color); color: var(--text-primary); }
.dropdown-item { color: var(--text-body); }
.dropdown-item:hover { background: var(--bg-light); color: var(--text-primary); }
.dropdown-header { color: var(--text-muted); }
.dropdown-divider { border-color: var(--border-color); }

/* ============================================================================
   17. RIGHT SIDEBAR WIDGETS
   ============================================================================ */
.right-sidebar .widget-card { background: var(--bg-card); border: 1px solid var(--border-color); }
.right-sidebar .widget-card .card-header { background: var(--bg-light); color: var(--text-secondary); border-bottom: 1px solid var(--border-color); }
.right-sidebar .widget-card .card-body { background: var(--bg-card); color: var(--text-body); }
.right-sidebar .widget-card .list-group-item { background: var(--bg-card); color: var(--text-primary); border-color: var(--border-color); }
.right-sidebar .widget-card .list-group-item:hover { background: var(--bg-light); }

.right-sidebar .sidebar-header-widget { background: var(--sidebar-bg) !important; }
.right-sidebar .sidebar-header-widget h6 { color: #fff !important; }
.right-sidebar .sidebar-header-widget small { color: rgba(255,255,255,0.7) !important; }
.right-sidebar .sidebar-header-widget .badge { color: #fff !important; }

/* Footer strip: themed, full panel width, no floating rounded card. */
.right-sidebar .sidebar-footer-widget {
    background: var(--bg-light) !important;
    border-top: 1px solid var(--border-color);
    border-left: 0;
    border-right: 0;
    border-bottom: 0;
    border-radius: 0 !important;
    margin: 0 !important;
    padding: 8px 10px !important;
    color: var(--text-muted) !important;
    box-shadow: none !important;
}
.right-sidebar .sidebar-footer-widget small { color: var(--text-muted) !important; }
.right-sidebar .sidebar-footer-widget a { color: var(--accent-color) !important; }

/* ============================================================================
   18. THEME TOGGLE BUTTON
   ============================================================================ */
#navbarThemeToggle { color: var(--text-primary); font-size: 1.2rem; transition: all 0.3s ease; }
#navbarThemeToggle:hover { color: var(--accent-color); transform: rotate(20deg); }

/* Header theme picker (System / Light / Dark) */
.theme-picker-btn {
    color: var(--text-primary) !important;
    font-size: 1.15rem;
    line-height: 1;
    padding: 0.35rem 0.5rem;
    border-radius: 0.5rem;
    transition: color .15s ease, background .15s ease, transform .2s ease;
}
.theme-picker-btn:hover,
.theme-picker-btn:focus-visible {
    color: var(--accent-color) !important;
    background: rgba(var(--accent-color-rgb), .10);
    transform: rotate(12deg);
}
.theme-picker-menu .dropdown-header {
    color: var(--text-muted);
    font-size: .7rem;
    text-transform: uppercase;
    letter-spacing: .06em;
    padding: .35rem 1rem;
}
.theme-picker-menu .theme-option { position: relative; }
.theme-picker-menu .theme-option.active,
.theme-picker-menu .theme-option[aria-pressed="true"] {
    color: var(--accent-color);
    background: rgba(var(--accent-color-rgb), .10);
    font-weight: 600;
}
.theme-picker-menu .theme-option.active::after {
    content: "\F26E"; /* bootstrap-icons check */
    font-family: "bootstrap-icons";
    position: absolute;
    right: 1rem;
    top: 50%;
    transform: translateY(-50%);
    font-size: .8rem;
}

/* ============================================================================
   19. THEME PREVIEW CARDS (Settings page)
   ============================================================================ */
.theme-option-card { cursor: pointer; border: 3px solid var(--border-color); border-radius: 8px; padding: 12px; transition: all 0.3s ease; background: var(--bg-card); }
.theme-option-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }
.theme-option-card.active { border-color: var(--accent-color); box-shadow: 0 0 0 3px rgba(var(--accent-color-rgb), 0.2); }
.theme-preview { border-radius: 6px; overflow: hidden; height: 80px; margin-bottom: 8px; }
.theme-preview.light-preview { background: #ffffff; border: 1px solid #dee2e6; }
.theme-preview.dark-preview { background: #0d1117; border: 1px solid #30363d; }
.theme-preview.system-preview { background: linear-gradient(45deg, #ffffff 50%, #0d1117 50%); border: 1px solid #dee2e6; }
.theme-preview-header { height: 20px; background: var(--accent-color); opacity: 0.8; }
.theme-preview-body { padding: 8px; }
.theme-preview-line { height: 6px; background: #dee2e6; margin: 4px 0; border-radius: 3px; }
.light-preview .theme-preview-line { background: #dee2e6; }
.dark-preview .theme-preview-line { background: #30363d; }
.theme-preview-line.short { width: 60%; }
.theme-label { text-align: center; font-size: 0.85rem; font-weight: 500; color: var(--text-primary); }

.accent-option-btn { display: flex; align-items: center; gap: 8px; padding: 8px 16px; border: 2px solid var(--border-color); border-radius: 8px; background: var(--bg-card); color: var(--text-primary); transition: all 0.3s ease; }
.accent-option-btn:hover { transform: translateY(-2px); box-shadow: var(--shadow-sm); }
.accent-option-btn.active { border-color: var(--accent-color); box-shadow: 0 0 0 3px rgba(var(--accent-color-rgb), 0.2); }
.accent-color-circle { display: inline-block; width: 20px; height: 20px; border-radius: 50%; border: 2px solid var(--border-color); }

/* ============================================================================
   20. CHAT
   ============================================================================ */
#chatWindow { background: var(--bg-card) !important; border: 1px solid var(--border-color) !important; }
#chatWindow .card-header { background: var(--accent-color) !important; color: #fff !important; }
#chatWindow .card-header .btn-light { color: #fff !important; background: rgba(255,255,255,0.2) !important; border: none !important; }
#chatUserList { background: var(--bg-card) !important; border-bottom: 1px solid var(--border-color) !important; }
#chatMessages { background: var(--bg-body) !important; }
.chat-user-item:hover { background: var(--bg-light) !important; }
.chat-user-item.active { background: var(--primary-light) !important; }
.message-wrapper.mine .message-bubble { background: var(--accent-color) !important; color: #fff !important; }
.message-wrapper.other .message-bubble { background: var(--bg-light) !important; color: var(--text-primary) !important; }
.chat-input-area { background: var(--bg-card) !important; border-top: 1px solid var(--border-color) !important; }
.chat-input-area .form-control { background: var(--bg-input) !important; color: var(--text-primary) !important; border-color: var(--border-color) !important; }
.chat-input-area .form-control:disabled { background: var(--bg-light) !important; color: var(--text-muted) !important; }

/* Popup chrome rendered by chat.js — search bar and attachment rows. */
.chat-search-wrap { background: var(--bg-card) !important; border-color: var(--border-color) !important; }
.chat-search-wrap .input-group-text {
    background: var(--bg-card) !important;
    color: var(--text-secondary) !important;
    border-color: var(--border-color) !important;
}
.ts-chat-file {
    background: var(--bg-input) !important;
    border: 1px solid var(--border-color) !important;
    color: var(--text-primary) !important;
}
/* Chat.js writes plain <span>/<div> children; the global
   `p, span, div { color: var(--text-body) }` rule would otherwise
   repaint them independently of the bubble. */
.ts-chat-file span { color: inherit !important; }

/* Message bubbles. `mine`/`other` are set by chat.js (popup) and the
   full chat page sets .message-wrapper equivalents. Both must use theme
   variables: hard-coded #e9ecef/#212529 made other people's messages
   white-on-white in dark mode. */
.message-bubble.mine {
    background: var(--accent-color) !important;
    color: #fff !important;
}
.message-bubble.mine .ts-chat-text { color: #fff !important; }
.message-bubble.other {
    background: var(--bg-light) !important;
    color: var(--text-primary) !important;
    border: 1px solid var(--border-color) !important;
}
.message-bubble.other .ts-chat-text { color: var(--text-primary) !important; }
.ts-deleted-bubble span { color: inherit !important; }
/* The popup injects `#chatBubble .ts-deleted-bubble { color:#6c757d }`, so the
   dark override needs at least the same specificity to stay legible. */
[data-theme="dark"] #chatBubble .ts-deleted-bubble,
[data-bs-theme="dark"] #chatBubble .ts-deleted-bubble,
[data-theme="dark"] .chat-container .ts-deleted-bubble,
[data-bs-theme="dark"] .chat-container .ts-deleted-bubble { color: var(--text-muted) !important; }

/* ============================================================================
   21. DATATABLES
   ============================================================================ */
.dataTables_wrapper .dataTables_filter input { background: var(--bg-input) !important; color: var(--text-primary) !important; border: 1px solid var(--border-color) !important; }
.dataTables_wrapper .dataTables_filter input:focus { border-color: var(--accent-color) !important; box-shadow: 0 0 0 0.2rem rgba(var(--accent-color-rgb), 0.25) !important; }
.dataTables_wrapper .dataTables_length select { background: var(--bg-input) !important; color: var(--text-primary) !important; border: 1px solid var(--border-color) !important; }
.dataTables_wrapper .dataTables_info, .dataTables_wrapper .dataTables_paginate { color: var(--text-secondary) !important; }
.dataTables_wrapper .dataTables_paginate .paginate_button { color: var(--text-primary) !important; }
.dataTables_wrapper .dataTables_paginate .paginate_button.current { background: var(--accent-color) !important; color: #fff !important; }

/* ============================================================================
   22. SELECT2
   ============================================================================ */
.select2-container--bootstrap-5 .select2-selection { background-color: var(--bg-input) !important; border-color: var(--border-color) !important; color: var(--text-primary) !important; }
.select2-container--bootstrap-5 .select2-selection__placeholder { color: var(--text-muted) !important; }
.select2-dropdown { background: var(--bg-dropdown) !important; border-color: var(--border-color) !important; }
.select2-container--bootstrap-5 .select2-results__option { color: var(--text-primary) !important; }
.select2-container--bootstrap-5 .select2-results__option--highlighted { background: var(--accent-color) !important; color: #fff !important; }

/* ============================================================================
   22b. SMART SELECT — searchable, grouped selection controls
   Used by form pages that opt in with .ts-smart-select.
   ============================================================================ */
.ts-smart-field { position: relative; container-type: inline-size; }
.ts-smart-field .select2-container { width: 100% !important; }

.ts-smart-select + .select2-container--bootstrap-5 .select2-selection--single {
  display: flex;
  align-items: center;
  height: 46px;
  padding: 0 2.4rem 0 0.95rem;
  border: 1px solid var(--border-color);
  border-radius: 10px;
  background-color: var(--bg-input) !important;
  box-shadow: inset 0 1px 2px rgba(15, 23, 42, 0.04);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.ts-smart-select + .select2-container--bootstrap-5 .select2-selection--single:hover {
  border-color: var(--border-dark);
}
.ts-smart-select + .select2-container--bootstrap-5.select2-container--focus .select2-selection--single,
.ts-smart-select + .select2-container--bootstrap-5.select2-container--open .select2-selection--single {
  border-color: var(--accent-color) !important;
  border-radius: 10px !important;
  box-shadow: 0 0 0 3px rgba(var(--accent-color-rgb), 0.16);
}
.ts-smart-select + .select2-container--bootstrap-5.select2-container--open.select2-container--below .select2-selection--single,
.ts-smart-select + .select2-container--bootstrap-5.select2-container--open.select2-container--above .select2-selection--single {
  border-top-width: 1px;
  border-bottom-width: 1px;
  border-top-color: var(--accent-color) !important;
  border-bottom-color: var(--accent-color) !important;
}
.ts-smart-select + .select2-container--bootstrap-5 .select2-selection__rendered {
  display: flex;
  align-items: center;
  min-width: 0;
  width: 100%;
  overflow: hidden;
  padding: 0;
  margin: 0;
  line-height: 1.25;
  color: var(--text-primary) !important;
}
.ts-smart-select + .select2-container--bootstrap-5 .select2-selection__placeholder {
  color: var(--text-muted) !important;
  font-weight: 400;
}
.ts-smart-select + .select2-container--bootstrap-5 .select2-selection__clear {
  position: absolute;
  right: 2.35rem;
  top: 50%;
  transform: translateY(-50%);
  margin: 0;
  padding: 0 0.25rem;
  color: var(--text-muted);
  background: transparent;
  font-size: 1.05rem;
  line-height: 1;
  z-index: 2;
}
.ts-smart-select + .select2-container--bootstrap-5 .select2-selection__clear:hover { color: var(--danger); }
.ts-smart-select + .select2-container--bootstrap-5.select2-container--disabled .select2-selection--single {
  background-color: var(--bg-light) !important;
  box-shadow: none;
  opacity: 0.75;
  cursor: not-allowed;
}
.ts-smart-select + .select2-container--bootstrap-5 .select2-selection__arrow { right: 0.7rem; }

/* Compact controls — filter bars that use .form-select-sm inside a <form>.
   Per-row table selects stay native, so this only styles real filters. */
.ts-smart-select.form-select-sm + .select2-container--bootstrap-5 .select2-selection--single {
  height: 38px;
  padding: 0 2.1rem 0 0.7rem;
  border-radius: 8px;
  font-size: 0.875rem;
}
.ts-smart-select.form-select-sm + .select2-container--bootstrap-5 .select2-selection__clear {
  right: 2rem;
  font-size: 0.95rem;
}
.ts-smart-select.form-select-sm + .select2-container--bootstrap-5 .select2-selection__placeholder {
  font-size: 0.875rem;
}

/* Filter selects live in tight columns; let the label ellipsis cleanly. */
.ts-smart-select + .select2-container--bootstrap-5 .select2-selection__rendered > span {
  min-width: 0;
}

/* Selected value: primary label + quiet metadata */
.ts-opt-selected {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  min-width: 0;
  max-width: 100%;
}
.ts-opt-selected .ts-opt-main {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--text-primary);
}
.ts-opt-selected .ts-opt-meta {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text-muted);
  font-size: 0.8rem;
  font-weight: 400;
}
.ts-opt-selected .ts-opt-meta::before { content: "·"; color: var(--border-dark); }
@container (max-width: 300px) {
  .ts-opt-selected .ts-opt-meta { display: none; }
}
@container (max-width: 250px) {
  .ts-opt-selected .ts-opt-tag { display: none; }
}
.ts-opt-tag {
  display: inline-flex;
  align-items: center;
  max-width: 11rem;
  padding: 0.1rem 0.45rem;
  border-radius: 5px;
  background: var(--bg-light);
  border: 1px solid var(--border-color);
  color: var(--text-secondary);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.7rem;
  font-weight: 500;
  letter-spacing: 0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Dropdown */
.ts-smart-dropdown.select2-dropdown {
  margin-top: 0;
  padding: 0;
  border: 1px solid var(--border-color) !important;
  border-radius: 12px !important;
  background: var(--bg-dropdown) !important;
  box-shadow: 0 18px 40px rgba(15, 23, 42, 0.16), 0 3px 8px rgba(15, 23, 42, 0.06);
  overflow: hidden;
  max-width: calc(100vw - 24px) !important;
}
.ts-smart-dropdown.select2-dropdown--below { margin-top: 6px; }
.ts-smart-dropdown.select2-dropdown--above { margin-bottom: 6px; }
.ts-smart-dropdown .select2-search--dropdown { padding: 10px 10px 6px !important; }
.ts-smart-dropdown .select2-search__field {
  height: 40px;
  padding: 0 0.8rem !important;
  border: 1px solid var(--border-color) !important;
  border-radius: 9px !important;
  background: var(--bg-input) !important;
  color: var(--text-primary) !important;
  font-size: 0.875rem;
  box-shadow: none !important;
}
.ts-smart-dropdown .select2-search__field:focus {
  outline: none;
  border-color: var(--accent-color) !important;
  box-shadow: 0 0 0 3px rgba(var(--accent-color-rgb), 0.15) !important;
}
.ts-smart-dropdown .select2-search__field::placeholder { color: var(--text-muted); }
.ts-smart-dropdown .select2-results__options {
  max-height: 286px !important;
  padding: 2px 6px 8px;
}
.ts-smart-dropdown .select2-results__group {
  padding: 10px 10px 4px;
  background: transparent;
  color: var(--text-muted);
  font-size: 0.66rem;
  font-weight: 700;
  letter-spacing: 0.09em;
  text-transform: uppercase;
}
.ts-smart-dropdown .select2-results__option {
  margin: 1px 0;
  padding: 9px 10px;
  border-radius: 8px;
  background: transparent;
  color: var(--text-primary) !important;
  line-height: 1.3;
}
.ts-smart-dropdown .select2-results__option--highlighted {
  background: rgba(var(--accent-color-rgb), 0.11) !important;
  color: var(--text-primary) !important;
  box-shadow: inset 3px 0 0 var(--accent-color);
}
.ts-smart-dropdown .select2-results__option--selected,
.ts-smart-dropdown .select2-results__option[aria-selected="true"]:not(.select2-results__option--highlighted) {
  background: rgba(var(--accent-color-rgb), 0.07) !important;
  color: var(--text-primary) !important;
  font-weight: 600;
}
.ts-smart-dropdown .select2-results__option--selected.select2-results__option--highlighted {
  background: rgba(var(--accent-color-rgb), 0.13) !important;
  color: var(--text-primary) !important;
}
.ts-smart-dropdown .select2-results__message {
  padding: 14px 12px;
  color: var(--text-muted);
  font-size: 0.85rem;
}

/* Result rows */
.ts-opt {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  min-width: 0;
  width: 100%;
}
.ts-opt .ts-opt-main {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 500;
}
.ts-opt .ts-opt-meta {
  flex-shrink: 0;
  color: var(--text-muted);
  font-size: 0.75rem;
  font-weight: 400;
}
.ts-opt .ts-opt-tag {
  flex-shrink: 0;
  max-width: 9rem;
}

.ts-select-help {
  display: flex;
  align-items: flex-start;
  gap: 0.4rem;
  margin-top: 6px;
  color: var(--text-muted);
  font-size: 0.74rem;
  line-height: 1.35;
}
.ts-select-help i { margin-top: 0.1rem; color: var(--accent-color); }
.ts-select-help strong { color: var(--text-secondary); font-weight: 600; }

[data-theme="dark"] .ts-smart-select + .select2-container--bootstrap-5 .select2-selection--single,
[data-bs-theme="dark"] .ts-smart-select + .select2-container--bootstrap-5 .select2-selection--single {
  background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3e%3cpath fill='none' stroke='%239da7b3' stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M2 5l6 6 6-6'/%3e%3c/svg%3e");
  background-repeat: no-repeat;
  background-position: right 0.75rem center;
  background-size: 16px 12px;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.02);
}
[data-theme="dark"] .select2-container--bootstrap-5 .ts-smart-dropdown .select2-results__option--highlighted,
[data-bs-theme="dark"] .select2-container--bootstrap-5 .ts-smart-dropdown .select2-results__option--highlighted {
  background: rgba(var(--accent-color-rgb), 0.18) !important;
  color: var(--text-primary) !important;
}
[data-theme="dark"] .ts-smart-dropdown.select2-dropdown {
  box-shadow: 0 22px 48px rgba(0, 0, 0, 0.55), 0 3px 10px rgba(0, 0, 0, 0.4);
}
[data-theme="dark"] .ts-opt-tag {
  background: var(--bg-light);
  border-color: var(--border-color);
  color: var(--text-secondary);
}

@media (max-width: 575.98px) {
  .ts-smart-select + .select2-container--bootstrap-5 .select2-selection--single { height: 48px; }
  .ts-smart-dropdown .select2-results__options { max-height: 240px !important; }
  .ts-opt-selected .ts-opt-meta { display: none; }
  .ts-smart-dropdown .select2-results__option { padding: 11px 10px; }
}

/* ============================================================================
   22c. SUCCESS CELEBRATION — animated, centered confirmation popup
   Rendered by public/js/ts-success.js from a ts_flash_celebrate() payload.
   Auto-dismisses after ~3s (hover/focus pauses), follows light/dark theme,
   and scales down cleanly on phones.
   ============================================================================ */
.ts-success-overlay {
  position: fixed;
  inset: 0;
  z-index: 3000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(9, 14, 26, 0.45);
  -webkit-backdrop-filter: blur(3px);
  backdrop-filter: blur(3px);
  opacity: 0;
  transition: opacity 0.18s ease;
}
.ts-success-overlay.is-visible { opacity: 1; }
.ts-success-overlay.is-leaving { opacity: 0; pointer-events: none; }

.ts-success-card {
  position: relative;
  width: min(420px, 100%);
  padding: 30px 26px 26px;
  text-align: center;
  background: var(--bg-card);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
  border-radius: 20px;
  box-shadow: 0 26px 70px rgba(3, 10, 24, 0.28), 0 6px 18px rgba(3, 10, 24, 0.12);
  transform: translateY(14px) scale(0.88);
  opacity: 0;
  transition: transform 0.44s cubic-bezier(0.16, 1, 0.3, 1), opacity 0.26s ease;
  will-change: transform, opacity;
}
.ts-success-overlay.is-visible .ts-success-card { transform: none; opacity: 1; }
.ts-success-overlay.is-leaving .ts-success-card {
  transform: translateY(6px) scale(0.96);
  opacity: 0;
  transition-duration: 0.2s;
}

/* Animated tick + burst */
.ts-success-check {
  position: relative;
  width: 84px;
  height: 84px;
  margin: 0 auto 14px;
  border-radius: 50%;
  background: radial-gradient(circle at 50% 46%, rgba(25, 135, 84, 0.16), rgba(25, 135, 84, 0) 70%);
  display: grid;
  place-items: center;
}
.ts-success-check::before {
  content: "";
  position: absolute;
  inset: -5px;
  border-radius: 50%;
  border: 2px solid rgba(25, 135, 84, 0.32);
  opacity: 0;
  animation: ts-succ-ping 1s ease-out 0.34s 2;
}
.ts-success-check svg {
  width: 66px;
  height: 66px;
  display: block;
  overflow: visible;
}
.ts-success-ring {
  stroke: #198754;
  stroke-width: 3.2;
  stroke-linecap: round;
  stroke-dasharray: 145;
  stroke-dashoffset: 145;
  animation: ts-succ-draw 0.62s cubic-bezier(0.65, 0, 0.35, 1) 0.08s forwards;
}
.ts-success-tick {
  stroke: #198754;
  stroke-width: 4.6;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-dasharray: 42;
  stroke-dashoffset: 42;
  animation: ts-succ-draw 0.4s cubic-bezier(0.65, 0, 0.35, 1) 0.5s forwards;
}
@keyframes ts-succ-draw { to { stroke-dashoffset: 0; } }
@keyframes ts-succ-ping {
  0% { opacity: 0.7; transform: scale(0.9); }
  70% { opacity: 0; transform: scale(1.22); }
  100% { opacity: 0; transform: scale(1.22); }
}

.ts-success-burst {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 0;
  height: 0;
  pointer-events: none;
}
.ts-success-burst i {
  position: absolute;
  left: -3px;
  top: -3px;
  width: 6px;
  height: 6px;
  border-radius: 2px;
  opacity: 0;
  animation: ts-succ-pop 0.9s cubic-bezier(0.15, 0.65, 0.4, 1) forwards;
  animation-delay: var(--delay, 0ms);
}
@keyframes ts-succ-pop {
  0% { opacity: 0; transform: translate(0, 0) scale(0.6) rotate(0); }
  15% { opacity: 1; }
  70% { opacity: 1; }
  100% { opacity: 0; transform: translate(var(--tx, 40px), var(--ty, -40px)) scale(1) rotate(var(--rot, 90deg)); }
}

/* Text */
.ts-success-title {
  position: relative;
  z-index: 1;
  margin: 0 0 6px;
  font-size: clamp(1.15rem, 4.2vw, 1.35rem);
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--text-heading);
}
.ts-success-badge {
  position: relative;
  z-index: 1;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin: 0 0 10px;
  padding: 4px 12px;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--accent-color);
  background: rgba(var(--accent-color-rgb), 0.12);
  border: 1px solid rgba(var(--accent-color-rgb), 0.25);
}
.ts-success-msg {
  position: relative;
  z-index: 1;
  margin: 0 auto;
  max-width: 34ch;
  font-size: 0.9rem;
  line-height: 1.55;
  color: var(--text-secondary);
}
.ts-success-action {
  position: relative;
  z-index: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-top: 16px;
  padding: 9px 18px;
  border-radius: 10px;
  font-size: 0.875rem;
  font-weight: 600;
  color: #fff;
  background: var(--accent-color);
  transition: background 0.2s ease, transform 0.2s ease;
}
.ts-success-action:hover {
  color: #fff;
  background: var(--accent-color-dark);
  transform: translateY(-1px);
}

/* The global `[data-theme="dark"] a` rule outranks a plain class selector. */
[data-theme="dark"] .ts-success-action,
[data-bs-theme="dark"] .ts-success-action { color: #fff; }
[data-theme="dark"] .ts-success-action:hover,
[data-bs-theme="dark"] .ts-success-action:hover { color: #fff; }

/* Programmatic focus should not paint a browser ring around the card. */
.ts-success-card:focus { outline: none; }

/* Close + countdown */
.ts-success-close {
  position: absolute;
  top: 9px;
  right: 11px;
  z-index: 2;
  width: 30px;
  height: 30px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--text-muted);
  font-size: 1.35rem;
  line-height: 1;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}
.ts-success-close:hover { background: var(--bg-light); color: var(--text-primary); }
.ts-success-progress {
  position: absolute;
  left: 16px;
  right: 16px;
  bottom: 10px;
  z-index: 2;
  height: 3px;
  border-radius: 999px;
  overflow: hidden;
  background: rgba(var(--accent-color-rgb), 0.14);
}
.ts-success-progress span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--accent-color), var(--accent-color-dark));
  transform-origin: left center;
  animation: ts-succ-bar var(--ts-succ-duration, 3000ms) linear forwards;
}
.ts-success-overlay.is-paused .ts-success-progress span { animation-play-state: paused; }
@keyframes ts-succ-bar {
  from { transform: scaleX(1); }
  to { transform: scaleX(0); }
}

/* Dark theme */
[data-theme="dark"] .ts-success-overlay,
[data-bs-theme="dark"] .ts-success-overlay { background: rgba(0, 0, 0, 0.62); }
[data-theme="dark"] .ts-success-card,
[data-bs-theme="dark"] .ts-success-card {
  box-shadow: 0 28px 80px rgba(0, 0, 0, 0.62), inset 0 1px 0 rgba(255, 255, 255, 0.03);
}
[data-theme="dark"] .ts-success-check,
[data-bs-theme="dark"] .ts-success-check {
  background: radial-gradient(circle at 50% 46%, rgba(61, 220, 151, 0.16), rgba(61, 220, 151, 0) 70%);
}
[data-theme="dark"] .ts-success-check::before,
[data-bs-theme="dark"] .ts-success-check::before { border-color: rgba(61, 220, 151, 0.34); }
[data-theme="dark"] .ts-success-ring,
[data-bs-theme="dark"] .ts-success-ring,
[data-theme="dark"] .ts-success-tick,
[data-bs-theme="dark"] .ts-success-tick { stroke: #3ddc97; }
[data-theme="dark"] .ts-success-action:hover,
[data-bs-theme="dark"] .ts-success-action:hover { color: #fff; }

/* Phones — keep the card comfortable and the action tappable */
@media (max-width: 480px) {
  .ts-success-overlay { padding: 14px; }
  .ts-success-card { padding: 26px 18px 24px; border-radius: 18px; }
  .ts-success-check { width: 74px; height: 74px; margin-bottom: 12px; }
  .ts-success-check svg { width: 58px; height: 58px; }
  .ts-success-msg { font-size: 0.875rem; }
  .ts-success-action { width: 100%; padding: 11px 18px; }
  .ts-success-progress { left: 14px; right: 14px; bottom: 9px; }
}

/* Short landscape screens */
@media (max-height: 460px) {
  .ts-success-check { width: 60px; height: 60px; margin-bottom: 8px; }
  .ts-success-check svg { width: 50px; height: 50px; }
  .ts-success-card { padding: 20px 20px 20px; }
}

/* Motion-sensitive visitors still get the confirmation, minus the bounce */
@media (prefers-reduced-motion: reduce) {
  .ts-success-card {
    transform: none !important;
    transition: opacity 0.18s ease !important;
  }
  .ts-success-check::before,
  .ts-success-burst i { display: none !important; }
  .ts-success-ring,
  .ts-success-tick { animation: none !important; stroke-dashoffset: 0 !important; }
}

/* Lock background scrolling only while the dialog is on screen. */
html.ts-success-lock,
html.ts-success-lock body { overflow: hidden; }

/* ============================================================================
   23. EMPTY STATES, LISTS, TABS, PAGINATION
   ============================================================================ */
.empty-state { padding: 3rem 1rem; text-align: center; }
.empty-state .empty-icon { font-size: 4rem; color: var(--text-muted); opacity: 0.3; }
.empty-state h5 { margin-top: 1rem; color: var(--text-heading); }
.empty-state p { color: var(--text-muted); }

.list-group-item { background: var(--bg-card); color: var(--text-body); border-color: var(--border-color); }
.list-group-item:hover { background: var(--bg-light); }
.list-group-item-primary { background: var(--primary-light); color: var(--text-primary); }
.list-group-item-warning { background: rgba(255,193,7,0.15); color: #b8860b; }
.list-group-item-info { background: rgba(13,202,240,0.15); color: #0aa2c0; }
.list-group-item-success { background: rgba(25,135,84,0.15); color: #198754; }

.nav-tabs .nav-link { color: var(--text-secondary); border-color: transparent; }
.nav-tabs .nav-link:hover { color: var(--text-primary); border-color: var(--border-color) var(--border-color) transparent; }
.nav-tabs .nav-link.active { color: var(--text-primary); background: var(--bg-card); border-color: var(--border-color) var(--border-color) transparent; }

.pagination .page-link { color: var(--text-primary); background: var(--bg-card); border-color: var(--border-color); }
.pagination .page-link:hover { color: var(--text-primary); background: var(--bg-light); border-color: var(--border-color); }
.pagination .page-item.active .page-link { background: var(--accent-color); border-color: var(--accent-color); color: #fff; }
.pagination .page-item.disabled .page-link { color: var(--text-muted); background: var(--bg-light); border-color: var(--border-color); }

.progress { height: 0.6rem; border-radius: 50rem; background: var(--bg-light); }
.progress-bar { border-radius: 50rem; font-size: 0.65rem; font-weight: 600; color: #fff; }

.toast-container { z-index: 1060; }
.toast { border: none; box-shadow: var(--shadow-md); border-radius: var(--radius-md); background: var(--bg-card) !important; border: 1px solid var(--border-color) !important; }
.toast-header { border-bottom: 1px solid var(--border-color); background: var(--bg-light) !important; color: var(--text-heading) !important; }
.toast-body { color: var(--text-body) !important; }

/* ============================================================================
   24. RESPONSIVE
   ============================================================================ */
@media (max-width: 1200px) {
    :root { --right-sidebar-width: 270px; }
    #content { margin-right: var(--right-sidebar-width); width: calc(100% - var(--sidebar-width) - var(--right-sidebar-width)); }
    #content.active { width: calc(100% - var(--right-sidebar-width)); }
    #content.expanded { width: calc(100% - var(--sidebar-width)); }
}
@media (max-width: 992px) {
    :root { --sidebar-width: 280px; --right-sidebar-width: 320px; }
    .sidebar { transform: translateX(-100%); }
    .sidebar.active { transform: translateX(0); }
    .right-sidebar { transform: translateX(100%); display: block !important; }
    .right-sidebar.mobile-visible { transform: translateX(0); }
    #content { margin-left: 0; margin-right: 0; width: 100%; }
    #content.active { margin-left: 0; width: 100%; }
    #content.expanded { margin-right: 0; width: 100%; }
    #rightSidebarToggle { display: flex !important; align-items: center; justify-content: center; }
}
@media (max-width: 768px) {
    .main-content { padding: 0.75rem; }
    .stat-card .stat-value { font-size: 1.5rem; }
    .stat-card .stat-icon { font-size: 2rem; }
}
@media (max-width: 576px) {
    :root { --sidebar-width: 100%; --right-sidebar-width: 100%; }
    .sidebar { width: 100%; }
    .right-sidebar { width: 100%; }
}

/* ============================================================================
   25. PRINT — always light
   ============================================================================ */
@media print {
    .sidebar, .navbar, .right-sidebar, .btn, .no-print { display: none !important; }
    #content { margin-left: 0 !important; margin-right: 0 !important; width: 100% !important; }
    .card { box-shadow: none !important; border: 1px solid #dee2e6 !important; background: #fff !important; color: #212529 !important; }
    .card-header { background: #f8f9fa !important; color: #212529 !important; }
    body, html { background: #fff !important; color: #212529 !important; }
}

/* ============================================================================
   26. SCROLLBAR
   ============================================================================ */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--bg-light); }
::-webkit-scrollbar-thumb { background: var(--secondary); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ============================================================================
   27. UTILITIES
   ============================================================================ */
.text-justify { text-align: justify; }
.cursor-pointer { cursor: pointer; }

.status-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; }
.status-dot.online { background: #28a745; animation: pulse-dot 2s infinite; }
.status-dot.offline { background: #dc3545; }
@keyframes pulse-dot {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.5; transform: scale(0.8); }
}

/* ============================================================================
   28. SIDEBAR COLOURS FOLLOW THE THEME
   ----------------------------------------------------------------------------
   This block used to force white text on every sidebar element in BOTH
   themes, which made the whole menu invisible on a light sidebar. Colours
   now come from the --sidebar-* tokens, so they flip with [data-theme].
   ============================================================================ */
.sidebar { color: var(--sidebar-text); }
.sidebar .sidebar-brand,
.sidebar .sidebar-brand .fw-bold { color: var(--sidebar-text-hover) !important; }
.sidebar .sidebar-brand small { color: var(--sidebar-text) !important; opacity: 0.75; }
.sidebar .sidebar-user { color: var(--sidebar-text) !important; }
.sidebar .sidebar-user .fw-bold { color: var(--sidebar-text-hover) !important; }
/* Role badge: the badge palette already gives each colour a readable ink
   (dark teal for bg-info, etc.). Forcing white here made the "Personnel"
   pill invisible against the pale sky-blue wash on the light sidebar. */
.sidebar .sidebar-user .badge { color: var(--badge-ink) !important; }
[data-theme="dark"] .sidebar .sidebar-user .badge,
[data-bs-theme="dark"] .sidebar .sidebar-user .badge { color: #fff !important; }
.sidebar .sidebar-header { color: var(--sidebar-text-hover); }
.sidebar .nav-link { color: var(--sidebar-text) !important; }
.sidebar .nav-link:hover,
.sidebar .nav-link.active { color: var(--sidebar-text-hover) !important; }
.sidebar .text-muted { color: var(--sidebar-text) !important; opacity: 0.75; }
.sidebar .badge { color: #fff !important; }
.sidebar .sidebar-footer .btn { color: inherit; }

/* ============================================================================
   29. DARK-MODE BOOTSTRAP OVERRIDES
   Also matches [data-bs-theme="dark"] so Bootstrap 5.3's own defaults
   are overridden correctly. Rule of thumb: dark bg → light text,
   light bg → dark text (#212529).
   ============================================================================ */

/* The whole document inherits variables in both dark selectors. */
[data-theme="dark"] body,
[data-bs-theme="dark"] body {
    background-color: var(--bg-body) !important;
    color: var(--text-body) !important;
}

/* ---------- bg-light / bg-white / text-dark / text-muted ---------- */
[data-theme="dark"] .bg-light,
[data-bs-theme="dark"] .bg-light { background-color: var(--bg-light) !important; color: var(--text-body) !important; }
[data-theme="dark"] .bg-white,
[data-bs-theme="dark"] .bg-white { background-color: var(--bg-card) !important; color: var(--text-body) !important; }
[data-theme="dark"] .bg-body,
[data-bs-theme="dark"] .bg-body { background-color: var(--bg-body) !important; }
[data-theme="dark"] .text-dark,
[data-bs-theme="dark"] .text-dark { color: var(--text-primary) !important; }
[data-theme="dark"] .text-muted,
[data-bs-theme="dark"] .text-muted { color: var(--text-muted) !important; }
[data-theme="dark"] .text-secondary,
[data-bs-theme="dark"] .text-secondary { color: var(--text-secondary) !important; }
[data-theme="dark"] .border,
[data-bs-theme="dark"] .border { border-color: var(--border-color) !important; }

/* ---------- cards ---------- */
[data-theme="dark"] .card,
[data-bs-theme="dark"] .card {
    background-color: var(--bg-card) !important;
    color: var(--text-body) !important;
    border-color: var(--border-color) !important;
}
[data-theme="dark"] .card-header,
[data-bs-theme="dark"] .card-header {
    background-color: var(--bg-light) !important;
    color: var(--text-primary) !important;
    border-bottom-color: var(--border-color) !important;
}
[data-theme="dark"] .card-footer,
[data-bs-theme="dark"] .card-footer {
    background-color: var(--bg-light) !important;
    color: var(--text-secondary) !important;
    border-top-color: var(--border-color) !important;
}

/* ---------- tables ---------- */
[data-theme="dark"] .table,
[data-bs-theme="dark"] .table {
    --bs-table-bg: var(--bg-table) !important;
    --bs-table-color: var(--text-body) !important;
    --bs-table-striped-bg: var(--bg-table-stripe) !important;
    --bs-table-striped-color: var(--text-body) !important;
    --bs-table-hover-bg: var(--bg-table-stripe) !important;
    --bs-table-hover-color: var(--text-body) !important;
    --bs-table-border-color: var(--border-color) !important;
    color: var(--text-body) !important;
    border-color: var(--border-color) !important;
}
[data-theme="dark"] .table > :not(caption) > * > *,
[data-bs-theme="dark"] .table > :not(caption) > * > * {
    background-color: var(--bg-table) !important;
    color: var(--text-body) !important;
    border-color: var(--border-color) !important;
}
[data-theme="dark"] .table thead th,
[data-bs-theme="dark"] .table thead th,
[data-theme="dark"] .table-light,
[data-bs-theme="dark"] .table-light {
    background-color: var(--bg-light) !important;
    color: var(--text-secondary) !important;
    border-color: var(--border-color) !important;
}
[data-theme="dark"] .table-light th,
[data-bs-theme="dark"] .table-light th,
[data-theme="dark"] .table-light td,
[data-bs-theme="dark"] .table-light td {
    background-color: var(--bg-light) !important;
    color: var(--text-secondary) !important;
    border-color: var(--border-color) !important;
}
[data-theme="dark"] .table tbody tr:hover,
[data-bs-theme="dark"] .table tbody tr:hover {
    background-color: var(--bg-table-stripe) !important;
}
[data-theme="dark"] .table-striped tbody tr:nth-of-type(odd) > *,
[data-bs-theme="dark"] .table-striped tbody tr:nth-of-type(odd) > * {
    background-color: var(--bg-table-stripe) !important;
    color: var(--text-body) !important;
}
[data-theme="dark"] .table a,
[data-bs-theme="dark"] .table a { color: var(--accent-color) !important; }
/* Badge colours now come from the soft badge palette in §13; do not force
   white text here or every status label loses its tint. */
[data-theme="dark"] .table .text-muted,
[data-bs-theme="dark"] .table .text-muted { color: var(--text-muted) !important; }

/* ---------- forms ---------- */
[data-theme="dark"] .form-control,
[data-bs-theme="dark"] .form-control,
[data-theme="dark"] .form-select,
[data-bs-theme="dark"] .form-select {
    background-color: var(--bg-input) !important;
    color: var(--text-primary) !important;
    border-color: var(--border-color) !important;
}
[data-theme="dark"] .form-control::placeholder,
[data-bs-theme="dark"] .form-control::placeholder {
    color: var(--text-muted) !important;
}
[data-theme="dark"] .form-control:focus,
[data-bs-theme="dark"] .form-control:focus,
[data-theme="dark"] .form-select:focus,
[data-bs-theme="dark"] .form-select:focus {
    background-color: var(--bg-input) !important;
    color: var(--text-primary) !important;
    border-color: var(--accent-color) !important;
    box-shadow: 0 0 0 0.2rem rgba(var(--accent-color-rgb), 0.25) !important;
}
[data-theme="dark"] .form-control:disabled,
[data-bs-theme="dark"] .form-control:disabled,
[data-theme="dark"] .form-select:disabled,
[data-bs-theme="dark"] .form-select:disabled {
    background-color: var(--bg-light) !important;
    color: var(--text-muted) !important;
}
[data-theme="dark"] .form-label,
[data-bs-theme="dark"] .form-label { color: var(--text-secondary) !important; }
[data-theme="dark"] .form-text,
[data-bs-theme="dark"] .form-text { color: var(--text-muted) !important; }
[data-theme="dark"] .form-check-input,
[data-bs-theme="dark"] .form-check-input {
    background-color: var(--bg-input);
    border-color: var(--border-color);
}
[data-theme="dark"] .form-check-input:checked,
[data-bs-theme="dark"] .form-check-input:checked {
    background-color: var(--accent-color);
    border-color: var(--accent-color);
}
[data-theme="dark"] .form-check-label,
[data-bs-theme="dark"] .form-check-label { color: var(--text-body); }
[data-theme="dark"] .input-group-text,
[data-bs-theme="dark"] .input-group-text {
    background-color: var(--bg-light) !important;
    color: var(--text-muted) !important;
    border-color: var(--border-color) !important;
}

/* ---------- buttons ---------- */
[data-theme="dark"] .btn-light,
[data-bs-theme="dark"] .btn-light {
    background-color: var(--bg-light) !important;
    color: var(--text-primary) !important;
    border-color: var(--border-color) !important;
}
[data-theme="dark"] .btn-outline-secondary,
[data-bs-theme="dark"] .btn-outline-secondary {
    color: var(--text-secondary) !important;
    border-color: var(--border-color) !important;
}
[data-theme="dark"] .btn-outline-secondary:hover,
[data-bs-theme="dark"] .btn-outline-secondary:hover {
    background-color: var(--secondary) !important;
    color: #fff !important;
}

/* ---------- modals, dropdowns ---------- */
[data-theme="dark"] .modal-content,
[data-bs-theme="dark"] .modal-content {
    background-color: var(--bg-modal) !important;
    color: var(--text-body) !important;
    border: 1px solid var(--border-color) !important;
}
[data-theme="dark"] .modal-header,
[data-bs-theme="dark"] .modal-header { border-bottom-color: var(--border-color) !important; }
[data-theme="dark"] .modal-footer,
[data-bs-theme="dark"] .modal-footer { border-top-color: var(--border-color) !important; }
[data-theme="dark"] .modal .btn-close,
[data-bs-theme="dark"] .modal .btn-close { filter: invert(1) grayscale(100%) brightness(200%); }
[data-theme="dark"] .modal-header .btn-close-white,
[data-bs-theme="dark"] .modal-header .btn-close-white { filter: brightness(0) invert(1); }
[data-theme="dark"] .modal .list-group-item,
[data-bs-theme="dark"] .modal .list-group-item {
    background-color: var(--bg-card) !important;
    color: var(--text-body) !important;
    border-color: var(--border-color) !important;
}
[data-theme="dark"] .modal .list-group-item:hover,
[data-bs-theme="dark"] .modal .list-group-item:hover { background-color: var(--bg-light) !important; }
[data-theme="dark"] .modal .list-group-item.active,
[data-bs-theme="dark"] .modal .list-group-item.active {
    background-color: var(--accent-color) !important;
    color: #fff !important;
    border-color: var(--accent-color) !important;
}
[data-theme="dark"] .modal .list-group-item.active a,
[data-bs-theme="dark"] .modal .list-group-item.active a,
[data-theme="dark"] .modal .list-group-item.active .fw-semibold,
[data-bs-theme="dark"] .modal .list-group-item.active .fw-semibold,
[data-theme="dark"] .modal .list-group-item.active .text-muted,
[data-bs-theme="dark"] .modal .list-group-item.active .text-muted {
    color: #fff !important;
}

[data-theme="dark"] .dropdown-menu,
[data-bs-theme="dark"] .dropdown-menu {
    background-color: var(--bg-dropdown) !important;
    border-color: var(--border-color) !important;
    color: var(--text-body) !important;
}
[data-theme="dark"] .dropdown-item,
[data-bs-theme="dark"] .dropdown-item { color: var(--text-body) !important; }
[data-theme="dark"] .dropdown-item:hover,
[data-bs-theme="dark"] .dropdown-item:hover {
    background-color: var(--bg-light) !important;
    color: var(--text-primary) !important;
}
[data-theme="dark"] .dropdown-header,
[data-bs-theme="dark"] .dropdown-header { color: var(--text-muted) !important; }
[data-theme="dark"] .dropdown-divider,
[data-bs-theme="dark"] .dropdown-divider { border-color: var(--border-color) !important; }

/* ---------- list group, nav tabs, pagination, breadcrumb ---------- */
[data-theme="dark"] .list-group-item,
[data-bs-theme="dark"] .list-group-item {
    background-color: var(--bg-card) !important;
    color: var(--text-body) !important;
    border-color: var(--border-color) !important;
}
[data-theme="dark"] .list-group-item:hover,
[data-bs-theme="dark"] .list-group-item:hover { background-color: var(--bg-light) !important; }
[data-theme="dark"] .list-group-item-action,
[data-bs-theme="dark"] .list-group-item-action { color: var(--text-body) !important; }

[data-theme="dark"] .nav-tabs,
[data-bs-theme="dark"] .nav-tabs { border-bottom-color: var(--border-color); }
[data-theme="dark"] .nav-tabs .nav-link,
[data-bs-theme="dark"] .nav-tabs .nav-link { color: var(--text-secondary); }
[data-theme="dark"] .nav-tabs .nav-link.active,
[data-bs-theme="dark"] .nav-tabs .nav-link.active {
    color: var(--text-primary);
    background-color: var(--bg-card);
    border-color: var(--border-color) var(--border-color) transparent;
}
[data-theme="dark"] .nav-pills .nav-link.active,
[data-bs-theme="dark"] .nav-pills .nav-link.active {
    background-color: var(--accent-color);
    color: #fff;
}

[data-theme="dark"] .pagination .page-link,
[data-bs-theme="dark"] .pagination .page-link {
    color: var(--text-primary) !important;
    background-color: var(--bg-card) !important;
    border-color: var(--border-color) !important;
}
[data-theme="dark"] .pagination .page-link:hover,
[data-bs-theme="dark"] .pagination .page-link:hover {
    background-color: var(--bg-light) !important;
}
[data-theme="dark"] .pagination .page-item.active .page-link,
[data-bs-theme="dark"] .pagination .page-item.active .page-link {
    background-color: var(--accent-color) !important;
    border-color: var(--accent-color) !important;
    color: #fff !important;
}
[data-theme="dark"] .pagination .page-item.disabled .page-link,
[data-bs-theme="dark"] .pagination .page-item.disabled .page-link {
    color: var(--text-muted) !important;
    background-color: var(--bg-light) !important;
}

[data-theme="dark"] .breadcrumb,
[data-bs-theme="dark"] .breadcrumb { background-color: transparent; }
[data-theme="dark"] .breadcrumb-item + .breadcrumb-item::before,
[data-bs-theme="dark"] .breadcrumb-item + .breadcrumb-item::before { color: var(--text-muted); }
[data-theme="dark"] .breadcrumb-item.active,
[data-bs-theme="dark"] .breadcrumb-item.active { color: var(--text-muted); }

/* ---------- alerts ---------- */
[data-theme="dark"] .alert-success,
[data-bs-theme="dark"] .alert-success { background-color: rgba(25,135,84,0.18) !important; color: #7ee2a8 !important; border-left-color: #198754 !important; }
[data-theme="dark"] .alert-danger,
[data-bs-theme="dark"] .alert-danger { background-color: rgba(220,53,69,0.18) !important; color: #f3a0a7 !important; border-left-color: #dc3545 !important; }
[data-theme="dark"] .alert-warning,
[data-bs-theme="dark"] .alert-warning { background-color: rgba(255,193,7,0.18) !important; color: #ffd971 !important; border-left-color: #ffc107 !important; }
[data-theme="dark"] .alert-info,
[data-bs-theme="dark"] .alert-info { background-color: rgba(13,202,240,0.18) !important; color: #8ee5f7 !important; border-left-color: #0dcaf0 !important; }
[data-theme="dark"] .alert .btn-close,
[data-bs-theme="dark"] .alert .btn-close { filter: invert(1) grayscale(100%) brightness(200%); }

/* ---------- toasts, offcanvas ---------- */
[data-theme="dark"] .toast,
[data-bs-theme="dark"] .toast { background-color: var(--bg-card) !important; color: var(--text-body) !important; border-color: var(--border-color) !important; }
[data-theme="dark"] .toast-header,
[data-bs-theme="dark"] .toast-header { background-color: var(--bg-light) !important; color: var(--text-primary) !important; border-bottom-color: var(--border-color) !important; }
[data-theme="dark"] .toast-body,
[data-bs-theme="dark"] .toast-body { color: var(--text-body) !important; }
[data-theme="dark"] .offcanvas,
[data-bs-theme="dark"] .offcanvas { background-color: var(--bg-card) !important; color: var(--text-body) !important; }
[data-theme="dark"] .offcanvas-header,
[data-bs-theme="dark"] .offcanvas-header { border-bottom: 1px solid var(--border-color); }

/* ---------- links, code, hr ---------- */
[data-theme="dark"] a,
[data-bs-theme="dark"] a { color: var(--accent-color); }
[data-theme="dark"] a:hover,
[data-bs-theme="dark"] a:hover { color: var(--accent-color-dark); }
[data-theme="dark"] code,
[data-bs-theme="dark"] code,
[data-theme="dark"] pre,
[data-bs-theme="dark"] pre { color: #f0f6fc; background-color: rgba(255,255,255,0.05); border-radius: 4px; }
[data-theme="dark"] hr,
[data-bs-theme="dark"] hr { border-color: var(--border-color); opacity: 1; }

/* ---------- progress ---------- */
[data-theme="dark"] .progress,
[data-bs-theme="dark"] .progress { background-color: var(--bg-light) !important; }

/* ---------- DataTables in dark ---------- */
[data-theme="dark"] .dataTables_wrapper .dataTables_filter input,
[data-bs-theme="dark"] .dataTables_wrapper .dataTables_filter input {
    background-color: var(--bg-input) !important;
    color: var(--text-primary) !important;
    border: 1px solid var(--border-color) !important;
}
[data-theme="dark"] .dataTables_wrapper .dataTables_length select,
[data-bs-theme="dark"] .dataTables_wrapper .dataTables_length select {
    background-color: var(--bg-input) !important;
    color: var(--text-primary) !important;
    border: 1px solid var(--border-color) !important;
}
[data-theme="dark"] .dataTables_wrapper .dataTables_info,
[data-bs-theme="dark"] .dataTables_wrapper .dataTables_info,
[data-theme="dark"] .dataTables_wrapper .dataTables_paginate,
[data-bs-theme="dark"] .dataTables_wrapper .dataTables_paginate {
    color: var(--text-secondary) !important;
}
[data-theme="dark"] .dataTables_wrapper .dataTables_paginate .paginate_button,
[data-bs-theme="dark"] .dataTables_wrapper .dataTables_paginate .paginate_button {
    color: var(--text-primary) !important;
}
[data-theme="dark"] .dataTables_wrapper .dataTables_paginate .paginate_button.current,
[data-bs-theme="dark"] .dataTables_wrapper .dataTables_paginate .paginate_button.current {
    background: var(--accent-color) !important;
    color: #fff !important;
    border-color: var(--accent-color) !important;
}

/* ---------- Select2 in dark ---------- */
[data-theme="dark"] .select2-container--bootstrap-5 .select2-selection,
[data-bs-theme="dark"] .select2-container--bootstrap-5 .select2-selection {
    background-color: var(--bg-input) !important;
    color: var(--text-primary) !important;
    border-color: var(--border-color) !important;
}
[data-theme="dark"] .select2-container--bootstrap-5 .select2-selection__placeholder,
[data-bs-theme="dark"] .select2-container--bootstrap-5 .select2-selection__placeholder { color: var(--text-muted) !important; }
[data-theme="dark"] .select2-dropdown,
[data-bs-theme="dark"] .select2-dropdown { background-color: var(--bg-dropdown) !important; border-color: var(--border-color) !important; }
[data-theme="dark"] .select2-container--bootstrap-5 .select2-results__option,
[data-bs-theme="dark"] .select2-container--bootstrap-5 .select2-results__option { color: var(--text-primary) !important; }
[data-theme="dark"] .select2-container--bootstrap-5 .select2-results__option--highlighted,
[data-bs-theme="dark"] .select2-container--bootstrap-5 .select2-results__option--highlighted {
    background: var(--accent-color) !important;
    color: #fff !important;
}

/* ---------- Right sidebar widgets in dark ---------- */
[data-theme="dark"] .right-sidebar,
[data-bs-theme="dark"] .right-sidebar {
    background: var(--bg-card) !important;
    border-left: 1px solid var(--border-color) !important;
}
[data-theme="dark"] .right-sidebar .widget-card,
[data-bs-theme="dark"] .right-sidebar .widget-card {
    background: var(--bg-card) !important;
    border: 1px solid var(--border-color) !important;
}
[data-theme="dark"] .right-sidebar .widget-card .card-header,
[data-bs-theme="dark"] .right-sidebar .widget-card .card-header {
    background: var(--bg-light) !important;
    color: var(--text-secondary) !important;
    border-bottom: 1px solid var(--border-color) !important;
}
[data-theme="dark"] .right-sidebar .widget-card .card-body,
[data-bs-theme="dark"] .right-sidebar .widget-card .card-body {
    background: var(--bg-card) !important;
    color: var(--text-body) !important;
}
[data-theme="dark"] .right-sidebar .widget-card .list-group-item,
[data-bs-theme="dark"] .right-sidebar .widget-card .list-group-item {
    background: var(--bg-card) !important;
    color: var(--text-body) !important;
    border-color: var(--border-color) !important;
}
[data-theme="dark"] .right-sidebar .widget-card .list-group-item:hover,
[data-bs-theme="dark"] .right-sidebar .widget-card .list-group-item:hover {
    background: var(--bg-light) !important;
}
[data-theme="dark"] .right-sidebar .stat-value,
[data-bs-theme="dark"] .right-sidebar .stat-value { color: #fff !important; }
[data-theme="dark"] .right-sidebar .stat-label,
[data-bs-theme="dark"] .right-sidebar .stat-label { color: rgba(255,255,255,0.8) !important; }

/* ---------- Navbar in dark ---------- */
[data-theme="dark"] .navbar,
[data-bs-theme="dark"] .navbar {
    background: var(--bg-white) !important;
    border-bottom-color: var(--border-color) !important;
}
[data-theme="dark"] .navbar .btn-link,
[data-bs-theme="dark"] .navbar .btn-link { color: var(--text-primary) !important; }

/* ---------- Chat in dark ---------- */
[data-theme="dark"] #chatWindow,
[data-bs-theme="dark"] #chatWindow {
    background: var(--bg-card) !important;
    border: 1px solid var(--border-color) !important;
}
[data-theme="dark"] #chatMessages,
[data-bs-theme="dark"] #chatMessages { background: var(--bg-body) !important; }
[data-theme="dark"] #chatUserList,
[data-bs-theme="dark"] #chatUserList {
    background: var(--bg-card) !important;
    border-bottom: 1px solid var(--border-color) !important;
}
[data-theme="dark"] .chat-user-item:hover,
[data-bs-theme="dark"] .chat-user-item:hover { background: var(--bg-light) !important; }

/* ---------- Table-in-card full coverage ---------- */
[data-theme="dark"] .card-body .table-responsive,
[data-bs-theme="dark"] .card-body .table-responsive { background: transparent !important; }
[data-theme="dark"] .card-body .table-responsive .table,
[data-bs-theme="dark"] .card-body .table-responsive .table { background-color: var(--bg-table) !important; }
[data-theme="dark"] .card-body .table-responsive .table td,
[data-bs-theme="dark"] .card-body .table-responsive .table th,
[data-bs-theme="dark"] .card .table-responsive .table td,
[data-bs-theme="dark"] .card .table-responsive .table th {
    background-color: var(--bg-table) !important;
    color: var(--text-body) !important;
    border-color: var(--border-color) !important;
}
[data-theme="dark"] .card-body .table-responsive .table thead th,
[data-bs-theme="dark"] .card .table-responsive .table thead th {
    background-color: var(--bg-light) !important;
    color: var(--text-secondary) !important;
}

/* ---------- Sidebar always dark ---------- */
[data-theme="dark"] .sidebar,
[data-bs-theme="dark"] .sidebar { background: var(--sidebar-bg) !important; }

/* ---------- Login page tokens in dark ---------- */
[data-theme="dark"] {
    --public-bg: #0d1117;
    --public-card-bg: #161b22;
    --public-text-primary: #f0f6fc;
    --public-text-secondary: #9da7b3;
    --public-text-muted: #9da7b3;
    --public-input-bg: #0d1117;
    --public-input-border: #30363d;
    --public-input-text: #f0f6fc;
    --public-input-placeholder: #6e7681;
    --public-navbar-bg: rgba(22,27,34,0.9);
    --public-feature-card-bg: #161b22;
    --public-feature-card-border: #30363d;
    --public-card-border: #30363d;
    --public-hero-overlay: linear-gradient(135deg, #0d1117 0%, #161b22 50%, #1a1a2e 100%);
    --public-shadow: 0 20px 60px rgba(0,0,0,0.5);
    --public-footer-bg: #0d1117;
    --public-footer-text: #9da7b3;
    --public-stat-number: #f0f6fc;
}
[data-theme="light"] {
    --public-bg: #f0f2f5;
    --public-card-bg: #ffffff;
    --public-text-primary: #212529;
    --public-text-secondary: #6c757d;
    --public-text-muted: #6c757d;
    --public-input-bg: #ffffff;
    --public-input-border: #dee2e6;
    --public-input-text: #212529;
    --public-input-placeholder: #a0a0a0;
    --public-navbar-bg: rgba(255,255,255,0.9);
    --public-feature-card-bg: #ffffff;
    --public-feature-card-border: #dee2e6;
    --public-card-border: #dee2e6;
    --public-hero-overlay: linear-gradient(135deg, #f0f2f5 0%, #e7f1ff 50%, #dbeafe 100%);
    --public-shadow: 0 20px 60px rgba(0,0,0,0.1);
    --public-footer-bg: #1a1a2e;
    --public-footer-text: #9da7b3;
    --public-stat-number: #212529;
}

/* ============================================================
   BRANDING — uploaded logo pair (Settings → Appearance → Branding)
   ------------------------------------------------------------
   brand_logo_html() prints BOTH files when both exist; CSS picks
   one. Server-side selection would go stale, because theme.js can
   flip data-theme from localStorage after the page has rendered.
   ============================================================ */
.brand-logo-dark { display: none !important; }

[data-theme="dark"] .brand-logo-light,
[data-bs-theme="dark"] .brand-logo-light { display: none !important; }

[data-theme="dark"] .brand-logo-dark,
[data-bs-theme="dark"] .brand-logo-dark { display: inline-block !important; }

/* The visible variant keeps its own surface's box. */
[data-theme="dark"] .auth-logo.brand-logo-dark,
[data-bs-theme="dark"] .auth-logo.brand-logo-dark { display: block !important; }

[data-theme="dark"] .sidebar-logo-img.brand-logo-dark,
[data-bs-theme="dark"] .sidebar-logo-img.brand-logo-dark { display: block !important; }

.sidebar-logo-img {
    /* Fills the fixed header box without distortion and without a frame:
       aspect ratio is preserved, nothing is cropped, nothing overflows. */
    width: 100%;
    height: 100%;
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    object-position: center;
    border: 0;
    border-radius: 0;
    background: none;
    padding: 0;
    box-shadow: none;
}


/* ── Guide popup (ts_guide_modal) ────────────────────────────── */
.ts-guide-steps { display: flex; flex-direction: column; gap: 14px; }
.ts-guide-step { display: flex; align-items: flex-start; gap: 12px; }
.ts-guide-dot { flex: 0 0 32px; width: 32px; height: 32px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: .85rem; font-weight: 700; color: #fff; background: var(--accent-color); }
.ts-guide-title { font-size: .92rem; font-weight: 600; line-height: 1.25; color: var(--text-primary); }
.ts-guide-title i { color: var(--accent-color); }
.ts-guide-text { font-size: .82rem; line-height: 1.4; color: var(--text-muted); margin-top: 1px; }
.ts-guide-states { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-top: 16px; padding-top: 12px; border-top: 1px dashed var(--border-color); }
.ts-guide-states > i { color: var(--text-muted); font-size: .7rem; }
.ts-guide-state { font-size: .72rem; font-weight: 600; padding: .14rem .55rem; border-radius: 999px; background: #e2e3e5; color: #41464b; }
.ts-guide-state--for  { background: #fff3cd; color: #664d03; }
.ts-guide-state--in   { background: #cfe2ff; color: #084298; }
.ts-guide-state--done { background: #d1e7dd; color: #0f5132; }
.ts-guide-state--bad  { background: #f8d7da; color: #842029; }
.ts-guide-state--ref  { background: #e2e3e5; color: #41464b; }
.ts-guide-sep { color: var(--text-muted); font-size: .72rem; padding: 0 1px; }
.ts-guide-modal.show .ts-guide-step { animation: tsGuideIn .5s cubic-bezier(.2, .8, .3, 1) both; animation-delay: var(--d, 0s); }
.ts-guide-modal.show .ts-guide-dot { animation: tsGuideDot 1.1s ease-out both; animation-delay: var(--d, 0s); }
@keyframes tsGuideIn { from { opacity: 0; transform: translateX(-10px); } to { opacity: 1; transform: none; } }
@keyframes tsGuideDot { 0% { box-shadow: 0 0 0 0 rgba(var(--accent-color-rgb), .55); } 70% { box-shadow: 0 0 0 10px rgba(var(--accent-color-rgb), 0); } 100% { box-shadow: 0 0 0 0 rgba(var(--accent-color-rgb), 0); } }
@media (prefers-reduced-motion: reduce) {
  .ts-guide-modal.show .ts-guide-step,
  .ts-guide-modal.show .ts-guide-dot { animation: none; }
}
