:root {
    color-scheme: dark;
    --site-surface: #212121;
    --site-surface-strong: #303030;
    --site-border: #505050;
    --site-ink: #d4d4d4;
    --site-muted: #b5b5b5;
    --site-control-border: #858585;
    --site-link: #44b8f0;
    --site-on-accent: #10242e;
    --site-shell-surface: #212121;
    --site-shell-background: #303030;
    --site-shell-ink: #d4d4d4;
    --site-shell-accent: #44b8f0;
    --site-shell-border: #858585;
    --site-table-head: #212121;
    --site-table-heading-ink: #d4d4d4;
    --site-field-surface: #303030;
    --site-row-surface: #212121;
    --site-row-alternate: #212121;
    --site-row-hover: #303030;
    --site-impersonate: #9933cc;
    --site-impersonate-strong: #7a29a3;
    --site-danger-on-shell: #ff6b6b;
    --site-danger-ink: #ff8a8a;
    --site-toast-error-surface: #3b2929;
    --site-toast-error-border: #ff8a8a;
    --site-toast-error-ink: #ffd6d6;
    --menu-icon-interface: #5aaef0;
    --menu-icon-admin: #f27070;
    --menu-icon-data: #3cc9b4;
    --menu-icon-config: #ffa25c;
    --menu-icon-maintenance: #f2c94c;
    --menu-icon-transfer: #b88cf2;
    --menu-icon-versions: #a3b4c2;
    --menu-icon-statistics: #6fcf7c;
    --menu-icon-trajectories: #8c9cf7;
    --menu-icon-add-intervention: #f584c4;
    --menu-icon-interventions: #d4a373;
    --menu-icon-comment: #c6d65a;
    --menu-icon-bag: #4dd0e1;
}

html[data-theme="light"] .container-fluid,
html[data-theme="light"] .activity-period-popup {
    --site-danger-ink: #b02a37;
    color-scheme: light;
    --site-surface: #f7fafc;
    --site-surface-strong: #eaf5fa;
    --site-border: #c7d8e0;
    --site-ink: #1f2d35;
    --site-muted: #52636d;
    --site-control-border: #74858f;
    --site-link: #08759e;
    --site-on-accent: #fff;
    --site-table-head: #243139;
    --site-table-heading-ink: #fff;
    --site-field-surface: #fff;
    --site-row-surface: #fff;
    --site-row-alternate: #eaf5fa;
    --site-row-hover: #deeff7;
    --menu-icon-interface: #1565c0;
    --menu-icon-admin: #c62828;
    --menu-icon-data: #00796b;
    --menu-icon-config: #c2410c;
    --menu-icon-maintenance: #8a5a00;
    --menu-icon-transfer: #6a1b9a;
    --menu-icon-versions: #455a64;
    --menu-icon-statistics: #2e7d32;
    --menu-icon-trajectories: #3949ab;
    --menu-icon-add-intervention: #ad1457;
    --menu-icon-interventions: #795548;
    --menu-icon-comment: #6b6b00;
    --menu-icon-bag: #00727e;
}

html[data-theme],
html[data-theme] .container-fluid {
    --maintenance-surface: var(--site-surface);
    --maintenance-surface-strong: var(--site-surface-strong);
    --maintenance-border: var(--site-border);
    --maintenance-ink: var(--site-ink);
    --maintenance-muted: var(--site-muted);
}

html[data-theme] .container-fluid {
    background-color: var(--site-shell-background);
    color: var(--site-ink);
}

html[data-theme] body {
    background-color: var(--site-shell-background) !important;
    color: var(--site-ink) !important;
    transition: background-color .18s ease, color .18s ease;
}

html[data-theme] .tooltip {
    pointer-events: none;
}

html[data-theme] #main_navbar {
    --site-surface: var(--site-shell-surface);
    --site-surface-strong: var(--site-shell-background);
    --site-ink: var(--site-shell-ink);
    --site-link: var(--site-shell-accent);
    --site-control-border: var(--site-shell-border);
}

html[data-theme] .navbar.navbar-dark,
html[data-theme] .navbar.navbar-dark .navbar-nav .nav-item > .nav-link,
html[data-theme] .dropdown-menu-header,
html[data-theme] .bg-black {
    background-color: var(--site-surface) !important;
}

html[data-theme] .bg-black-2,
html[data-theme] .dropdown-header-panel-robot,
html[data-theme] .maintenance-panel,
html[data-theme] .card,
html[data-theme] .modal-content {
    background-color: var(--site-surface) !important;
    color: var(--site-ink);
}

html[data-theme] .maintenance-page {
    --maintenance-surface: var(--site-surface);
    --maintenance-surface-strong: var(--site-surface-strong);
    --maintenance-border: var(--site-border);
    --maintenance-ink: var(--site-ink);
    --maintenance-muted: var(--site-muted);
    color: var(--site-ink);
}

html[data-theme] .statistics-workspace {
    --maintenance-surface: var(--site-surface);
    --maintenance-surface-strong: var(--site-surface-strong);
    --maintenance-border: var(--site-border);
    --maintenance-ink: var(--site-ink);
    --maintenance-muted: var(--site-muted);
    --statistics-panel: var(--site-surface);
    --statistics-panel-strong: var(--site-surface-strong);
    --statistics-border: var(--site-border);
    --statistics-ink: var(--site-ink);
    --statistics-muted: var(--site-muted);
    --statistics-control-surface: var(--site-field-surface);
    --statistics-table-head: var(--site-table-head);
    --statistics-accent: var(--site-link);
    --statistics-accent-ink: var(--site-on-accent);
    color-scheme: inherit;
}

html[data-theme="light"] .statistics-workspace {
    --statistics-warning-surface: #fff0d6;
    --statistics-warning-text: #8f4c00;
    --statistics-error-surface: #ffe1e1;
    --statistics-error-text: #9e2020;
}

html[data-theme] .text-grey,
html[data-theme] .navbar .nav-link,
html[data-theme] .navbar .dropdown-menu a:not(.active) {
    color: var(--site-ink) !important;
}

html[data-theme] .navbar.navbar-dark .navbar-nav .nav-item.active > .nav-link,
html[data-theme] .navbar.navbar-dark .navbar-nav .nav-item > .nav-link:hover {
    color: var(--site-link) !important;
    border-bottom-color: var(--site-link);
}

/* Exit-impersonation link keeps its danger color over the generic navbar link color */
html[data-theme] .navbar .nav-link.text-danger,
html[data-theme] .navbar.navbar-dark .navbar-nav .nav-item > .nav-link.text-danger:hover { color: var(--site-danger-on-shell) !important; }

/* Copy-session (impersonate) table button stays violet in every state */
html[data-theme] .btn-table.btn-secondary { background-color: var(--site-impersonate) !important; color: #fff !important; }
html[data-theme] .btn-table.btn-secondary:hover,
html[data-theme] .btn-table.btn-secondary:focus,
html[data-theme] .btn-table.btn-secondary:active { background-color: var(--site-impersonate-strong) !important; }

html[data-theme] .dropdown-menu-header,
html[data-theme] .card,
html[data-theme] .modal-content,
html[data-theme] .maintenance-panel {
    border-color: var(--site-border);
}

html[data-theme] .table {
    color: var(--site-ink);
}

html[data-theme] .maintenance-table thead th,
html[data-theme] .statistics-workspace .statistics-table.maintenance-table thead th,
html[data-theme] .maintenance-modal-header {
    background: var(--site-table-head);
    color: var(--site-table-heading-ink);
}

html[data-theme] .maintenance-table tbody tr,
html[data-theme] .statistics-workspace .statistics-table tbody tr,
html[data-theme] .maintenance-robot-options,
html[data-theme] .maintenance-part-options,
html[data-theme] .maintenance-import-label {
    background: var(--site-row-surface);
}

html[data-theme] .maintenance-table tbody tr:nth-child(even),
html[data-theme] .statistics-workspace .statistics-table tbody tr:nth-child(even) {
    background: var(--site-row-alternate);
}

html[data-theme] .statistics-workspace .statistics-table tbody td { background-color: inherit; }

html[data-theme] .maintenance-table tbody tr:hover,
html[data-theme] .statistics-workspace .statistics-table tbody tr:hover {
    background: var(--site-row-hover) !important;
}

html[data-theme] .dropdown-item:hover,
html[data-theme] .dropdown-header-panel-robot .dropdown-item:hover {
    background: var(--site-surface-strong) !important;
    color: var(--site-ink) !important;
}

html[data-theme] .form-control,
html[data-theme] .custom-select {
    background-color: var(--site-field-surface);
    border-color: var(--site-control-border);
    color: var(--site-ink);
}

html[data-theme] .form-control::placeholder { color: var(--site-muted); opacity: 1; }
html[data-theme] .custom-select option { background: var(--site-field-surface); color: var(--site-ink); }
html[data-theme] .maintenance-btn-secondary.btn,
html[data-theme] .statistics-option-search,
html[data-theme] .statistics-workspace .dataTables_filter input {
    border-color: var(--site-control-border);
}
html[data-theme] .statistics-workspace .statistics-option-search,
html[data-theme] .statistics-workspace .dataTables_filter input {
    background-color: var(--site-field-surface);
    color: var(--site-ink);
}
html[data-theme] .btn-warning { color: #10242e !important; }
html[data-theme] .btn-danger { background-color: #c53b43 !important; color: #fff !important; }
html[data-theme] .btn-secondary { background-color: #505050 !important; color: #fff !important; }

.theme-toggle {
    background: transparent !important;
    border: 0;
    color: inherit;
    cursor: pointer;
    padding: .5rem 1rem;
}

.theme-toggle i { font-size: 1.1rem; }

.theme-toggle:focus-visible {
    outline: 2px solid #44b8f0;
    outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
    html[data-theme] body { transition: none; }
}

/* One colour per "..." menu action so each option is recognisable at a glance */
.dropdown-menu .dropdown-item[id^="btn_robot_interface_"] > i,
.dropdown-menu .dropdown-item[id^="btn_robot_global_interface_"] > i { color: var(--menu-icon-interface); }
.dropdown-menu .dropdown-item[id^="btn_admin_robot_interface_"] > i,
.dropdown-menu .dropdown-item[id^="btn_admin_global_robot_interface_"] > i { color: var(--menu-icon-admin); }
.dropdown-menu .dropdown-item[id^="btn_robot_data_"] > i { color: var(--menu-icon-data); }
.dropdown-menu .dropdown-item[id^="manage_configuration_"] > i { color: var(--menu-icon-config); }
.dropdown-menu .dropdown-item[id^="switch_maintenance_"] > i { color: var(--menu-icon-maintenance); }
.dropdown-menu .dropdown-item[id^="history_transfer_"] > i { color: var(--menu-icon-transfer); }
.dropdown-menu .dropdown-item[id^="manage_versions_"] > i { color: var(--menu-icon-versions); }
.dropdown-menu .dropdown-item.btn_see_global_for_robot > i { color: var(--menu-icon-statistics); }
.dropdown-menu .dropdown-item.btn_see_trajectories_for_robot > i { color: var(--menu-icon-trajectories); }
.dropdown-menu .dropdown-item.add_modal_technical_intervention > i { color: var(--menu-icon-add-intervention); }
.dropdown-menu .dropdown-item.read_modal_technical_intervention > i { color: var(--menu-icon-interventions); }
.dropdown-menu .dropdown-item.btn_robot_statistics_comment > i { color: var(--menu-icon-comment); }
.dropdown-menu .dropdown-item.btn_retrieve_bag > i { color: var(--menu-icon-bag); }
.dropdown-menu .btn_retrieve_bag > i.fa-ban { color: var(--site-muted); }
.dropdown-menu .dropdown-item.disabled > i { color: var(--site-muted); }

/* DataTables headers: same horizontal padding as the body cells so every title sits above its values */
html[data-theme] table.dataTable thead > tr > th { padding-left: .75rem; padding-right: .75rem; }
html[data-theme] .robot-workspace table.dataTable.robot-table thead > tr > th { padding-left: .4rem; padding-right: .4rem; }
html[data-theme] .statistics-trajectories-panel table.dataTable thead > tr > th { padding-left: .5rem; padding-right: .5rem; }
html[data-theme] .statistics-workspace .statistics-table thead > tr > th { text-align: center; }
html[data-theme] .statistics-workspace .statistics-table tbody td:nth-child(3) { text-align: center; }

/* Sort arrow: inline after the label without shifting it; the sizing header keeps room for it with a zero-height float */
html[data-theme] table.dataTable thead .sorting::before,
html[data-theme] table.dataTable thead .sorting_asc::before,
html[data-theme] table.dataTable thead .sorting_desc::before { display: none; }
html[data-theme] table.dataTable thead .sorting::after,
html[data-theme] table.dataTable thead .sorting_asc::after,
html[data-theme] table.dataTable thead .sorting_desc::after {
    content: "\f062";
    display: inline-block;
    font-size: .7rem;
    margin-left: .4em;
    margin-right: -1.4em;
    opacity: 0;
    position: static;
    vertical-align: middle;
    width: 1em;
}
html[data-theme] table.dataTable thead .sorting:hover::after { opacity: .6; }
html[data-theme] table.dataTable thead .sorting_asc::after { content: "\f062"; opacity: 1; }
html[data-theme] table.dataTable thead .sorting_desc::after { content: "\f063"; opacity: 1; }
html[data-theme] .dataTables_scrollBody table.dataTable thead .sorting::after,
html[data-theme] .dataTables_scrollBody table.dataTable thead .sorting_asc::after,
html[data-theme] .dataTables_scrollBody table.dataTable thead .sorting_desc::after { float: right; height: 0; margin-right: 0; visibility: hidden; }

/* Admin pages place the breadcrumb and table controls directly on the dark shell, outside any panel */
html[data-theme] .bc-icons-2 .breadcrumb .text-grey,
html[data-theme] .bc-icons-2 .breadcrumb .breadcrumb-item { color: var(--site-shell-ink) !important; }
html[data-theme] .dataTables_wrapper:not(.maintenance-panel *) > .dataTables_filter label,
html[data-theme] .dataTables_wrapper:not(.maintenance-panel *) > .dataTables_info { color: var(--site-shell-ink); }
html[data-theme] td.btn-rights { white-space: nowrap; }

/* Site-wide error popup (crdNotify.error), above modals so errors raised inside a dialog stay visible */
.crd-toasts { display: flex; flex-direction: column; gap: .5rem; max-width: min(26rem, calc(100vw - 2rem)); position: fixed; right: 1rem; top: 4.5rem; z-index: 1070; }
.crd-toast {
    align-items: flex-start;
    background: var(--site-toast-error-surface);
    border: 1px solid var(--site-toast-error-border);
    border-radius: 6px;
    box-shadow: 0 6px 18px rgba(0, 0, 0, .25);
    color: var(--site-toast-error-ink);
    display: flex;
    font-size: .9rem;
    gap: .6rem;
    padding: .7rem .75rem .7rem .9rem;
    transition: opacity 180ms ease-out, transform 180ms ease-out;
}
.crd-toast.is-leaving { opacity: 0; transform: translateY(-4px); }
.crd-toast > i { margin-top: .15rem; }
.crd-toast-message { flex: 1; overflow-wrap: anywhere; }
.crd-toast-close { background: transparent; border: 0; color: inherit; cursor: pointer; font-size: 1.25rem; line-height: 1; min-height: 28px; min-width: 28px; padding: 0; }
.crd-toast-close:focus-visible { outline: 2px solid currentColor; outline-offset: 1px; }
@media (prefers-reduced-motion: reduce) { .crd-toast { transition: none; } }

/* Table being recalculated: greyed, not clickable, with a centred spinner */
.dataTables_wrapper { position: relative; }
.dataTables_wrapper::after {
    background: color-mix(in srgb, var(--site-surface) 65%, transparent);
    content: "";
    inset: 0;
    opacity: 0;
    pointer-events: none;
    position: absolute;
    transition: opacity .2s ease;
    z-index: 5;
}
.dataTables_wrapper.crd-table-busy::after { opacity: 1; pointer-events: auto; }
.dataTables_wrapper .dataTables_processing {
    align-items: center;
    background: var(--site-surface-strong);
    border: 1px solid var(--site-border);
    border-radius: 6px;
    box-shadow: 0 6px 24px rgba(0, 0, 0, .25);
    color: var(--site-ink);
    flex-direction: column;
    font-size: .85rem;
    font-weight: 600;
    gap: .6rem;
    height: auto;
    left: 50%;
    margin: 0;
    padding: 1rem 1.5rem;
    position: absolute;
    top: min(50%, 12rem);
    transform: translate(-50%, -50%);
    width: auto;
    z-index: 6;
}
.dataTables_wrapper .dataTables_processing::before {
    animation: crd-table-spin .8s linear infinite;
    border: 3px solid var(--site-border);
    border-radius: 50%;
    border-top-color: var(--site-link);
    content: "";
    height: 2rem;
    width: 2rem;
}
.dataTables_wrapper.crd-table-busy .dataTables_processing { display: flex !important; }
.dataTables_wrapper:not(.crd-table-busy) .dataTables_processing { display: none !important; }
@keyframes crd-table-spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) {
    .dataTables_wrapper::after { transition: none; }
    .dataTables_wrapper .dataTables_processing::before { animation-duration: 2.4s; }
}

/* Password field with a show / hide eye, coloured like the field it sits in */
.crd-password-field { position: relative; }
.crd-password-field .form-control { padding-right: 2.75rem; }
.crd-password-field .form-control::-ms-reveal { display: none; }
.crd-password-toggle {
    align-items: center;
    background: transparent;
    border: 0;
    border-radius: 4px;
    color: var(--site-muted);
    cursor: pointer;
    display: inline-flex;
    height: 2.25rem;
    justify-content: center;
    padding: 0;
    position: absolute;
    right: .25rem;
    top: 50%;
    transform: translateY(-50%);
    width: 2.25rem;
}
.crd-password-toggle:hover { color: var(--site-ink); }
.crd-password-toggle:focus-visible { color: var(--site-ink); outline: 2px solid var(--site-link); outline-offset: 1px; }
