/* Tema condiviso: gli override sono caricati dopo gli stili isolati dei componenti. */
html[data-theme="dark"] {
    --st-bg: #0e1016;
    --st-surface: #161922;
    --st-surface-soft: #1b1f2a;
    --st-border: #2a2f3c;
    --st-border-strong: #394053;
    --st-text: #e8ebf2;
    --st-text-soft: #98a2b6;
    --st-primary: #8b8df5;
    --st-primary-hover: #a3a5f8;
    --st-primary-soft: #23264d;
    --st-primary-border: #3f4390;
    --st-success: #3fc68f;
    --st-warning: #f0aa45;
    --st-danger: #ff7b72;
    --st-shadow: 0 7px 20px rgba(0, 0, 0, .22);
    --st-shadow-lg: 0 22px 58px rgba(0, 0, 0, .38);
}

.course-calendar-layout-switch,
.teacher-calendar-layout-switch {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: .7rem;
    margin: .4rem 0 .75rem;
    color: var(--st-text-soft, #68758a);
    font-size: .82rem;
    font-weight: 700;
}

.course-calendar-google-state,
.teacher-calendar-google-state {
    display: inline-flex;
    align-items: center;
    gap: .45rem;
    padding: .35rem .65rem;
    border: 1px solid var(--st-border, #dce3ec);
    border-radius: 999px;
    background: var(--st-surface, #fff);
    color: var(--st-text-soft, #68758a);
    font-size: .78rem;
    font-weight: 700;
}

html[data-theme="dark"] body {
    background: var(--st-bg);
    color: var(--st-text);
}

/* Selettore tema */
.app-theme-toggle {
    position: relative;
    width: 40px;
    height: 40px;
    flex: 0 0 40px;
    display: inline-grid;
    place-items: center;
    padding: 0;
    border: 1px solid var(--st-border);
    border-radius: 11px;
    background: var(--st-surface-soft);
    color: var(--st-text-soft);
    cursor: pointer;
    transition: color .15s ease, background-color .15s ease, border-color .15s ease, transform .15s ease;
}

.app-theme-toggle:hover,
.app-theme-toggle:focus-visible {
    color: var(--st-primary);
    border-color: var(--st-primary-border);
    background: var(--st-primary-soft);
    outline: none;
    transform: translateY(-1px);
}

.app-theme-toggle-icon::before {
    content: "\263E";
    display: block;
    font-size: 1.35rem;
    line-height: 1;
    transform: rotate(-18deg);
}

html[data-theme="dark"] .app-theme-toggle-icon::before {
    content: "\2600";
    transform: none;
}

/* Struttura principale e navigazione */
html[data-theme="dark"] .app-shell,
html[data-theme="dark"] .app-main,
html[data-theme="dark"] .app-content {
    background: var(--st-bg);
}

html[data-theme="dark"] .app-sidebar,
html[data-theme="dark"] .sidebar-container,
html[data-theme="dark"] .top-row,
html[data-theme="dark"] .sidebar-footer {
    background: var(--st-surface);
    border-color: var(--st-border) !important;
    color: var(--st-text);
}

html[data-theme="dark"] .app-topbar {
    background: rgba(22, 25, 34, .9);
    border-color: var(--st-border);
}

html[data-theme="dark"] .app-topbar-brand,
html[data-theme="dark"] .navbar-brand span,
html[data-theme="dark"] .sidebar-footer .fw-semibold {
    color: var(--st-text) !important;
}

html[data-theme="dark"] .app-topbar-brand small,
html[data-theme="dark"] .app-topbar-status,
html[data-theme="dark"] .sidebar-footer,
html[data-theme="dark"] .user-box .small,
html[data-theme="dark"] .menu-section-title {
    color: var(--st-text-soft) !important;
}

html[data-theme="dark"] .navbar-toggler {
    background: var(--st-surface-soft);
    border-color: var(--st-border-strong);
}

html[data-theme="dark"] .navbar-toggler-icon { filter: invert(88%); }

html[data-theme="dark"] .user-box {
    color: var(--st-text) !important;
    border-color: var(--st-border);
    background: linear-gradient(135deg, #1b1f2a 0%, #222541 100%);
}

html[data-theme="dark"] .user-profile-avatar {
    color: var(--st-text-soft);
    background: #252a36;
    border-color: var(--st-border-strong);
}

html[data-theme="dark"] .user-box .btn-outline-light {
    color: var(--st-primary);
    background: var(--st-surface);
    border-color: var(--st-primary-border);
}

html[data-theme="dark"] .nav-item .nav-link { color: #b7c0d0; }
html[data-theme="dark"] .nav-item .nav-link:hover {
    color: var(--st-text);
    background: #202531;
    border-color: var(--st-border);
}

html[data-theme="dark"] .nav-item .nav-link.active {
    color: #b7b8ff;
    background: var(--st-primary-soft);
    border-color: var(--st-primary-border);
}

html[data-theme="dark"] .settings-submenu { border-color: var(--st-border); }
html[data-theme="dark"] .nav-item .communication-badge { border-color: var(--st-surface); }

/* Controlli e componenti Bootstrap */
html[data-theme="dark"] .card,
html[data-theme="dark"] .modal-content,
html[data-theme="dark"] .dropdown-menu,
html[data-theme="dark"] .offcanvas,
html[data-theme="dark"] .list-group-item,
html[data-theme="dark"] .popover {
    color: var(--st-text);
    background-color: var(--st-surface);
    border-color: var(--st-border) !important;
}

html[data-theme="dark"] .card-header,
html[data-theme="dark"] .card-footer,
html[data-theme="dark"] .modal-header,
html[data-theme="dark"] .modal-footer,
html[data-theme="dark"] .accordion-item,
html[data-theme="dark"] .accordion-button {
    color: var(--st-text);
    background-color: var(--st-surface-soft);
    border-color: var(--st-border) !important;
}

html[data-theme="dark"] .accordion-button:not(.collapsed) {
    color: var(--st-primary);
    background: var(--st-primary-soft);
}

html[data-theme="dark"] .form-label,
html[data-theme="dark"] label { color: #c2c9d6; }

html[data-theme="dark"] .form-control,
html[data-theme="dark"] .form-select,
html[data-theme="dark"] .input-group-text,
html[data-theme="dark"] input:not([type="checkbox"]):not([type="radio"]):not([type="range"]),
html[data-theme="dark"] textarea,
html[data-theme="dark"] select {
    color: var(--st-text);
    background-color: #12151d;
    border-color: var(--st-border-strong);
}

html[data-theme="dark"] .form-control::placeholder,
html[data-theme="dark"] textarea::placeholder,
html[data-theme="dark"] input::placeholder { color: #737f93; }

html[data-theme="dark"] .form-control:disabled,
html[data-theme="dark"] .form-select:disabled,
html[data-theme="dark"] input:disabled,
html[data-theme="dark"] textarea:disabled,
html[data-theme="dark"] select:disabled {
    color: #788398;
    background-color: #20242e;
}

html[data-theme="dark"] .form-check-input {
    background-color: #12151d;
    border-color: #566078;
}

html[data-theme="dark"] .form-check-input:checked {
    background-color: var(--st-primary);
    border-color: var(--st-primary);
}

html[data-theme="dark"] .btn-close { filter: invert(1) grayscale(100%) brightness(180%); }
html[data-theme="dark"] .btn-light {
    color: var(--st-text);
    background: var(--st-surface-soft);
    border-color: var(--st-border);
}

html[data-theme="dark"] .btn-outline-secondary {
    color: #b8c0ce;
    border-color: var(--st-border-strong);
}

html[data-theme="dark"] .btn-outline-secondary:hover {
    color: #fff;
    background: #4a5365;
}

html[data-theme="dark"] .table-responsive {
    background: var(--st-surface);
    border-color: var(--st-border);
}

html[data-theme="dark"] .table {
    --bs-table-bg: var(--st-surface);
    --bs-table-color: var(--st-text);
    --bs-table-border-color: var(--st-border);
    --bs-table-striped-bg: #1a1e28;
    --bs-table-striped-color: var(--st-text);
    --bs-table-hover-bg: #202531;
    --bs-table-hover-color: var(--st-text);
    color: var(--st-text);
    background: var(--st-surface);
}

html[data-theme="dark"] .table > :not(caption) > * > * { border-color: var(--st-border); }
html[data-theme="dark"] .table thead th,
html[data-theme="dark"] thead.sticky-top th {
    color: #aeb7c7;
    background: #1d222d;
}

html[data-theme="dark"] .page-link {
    color: var(--st-primary);
    background: var(--st-surface);
    border-color: var(--st-border);
}

html[data-theme="dark"] .page-item.disabled .page-link { color: #69758a; background: #1b1f28; }
html[data-theme="dark"] .nav-tabs .nav-link.active {
    color: var(--st-primary);
    background: var(--st-surface);
    border-color: var(--st-border) var(--st-border) var(--st-surface);
}

html[data-theme="dark"] .bg-white,
html[data-theme="dark"] .bg-light { background-color: var(--st-surface) !important; }
html[data-theme="dark"] .text-dark { color: var(--st-text) !important; }
html[data-theme="dark"] .border,
html[data-theme="dark"] .border-top,
html[data-theme="dark"] .border-bottom { border-color: var(--st-border) !important; }

html[data-theme="dark"] .alert-warning { color: #ffd48b; background: #332817; border-color: #685126; }
html[data-theme="dark"] .alert-danger { color: #ffaaa4; background: #351e22; border-color: #71343b; }
html[data-theme="dark"] .alert-success { color: #85dfb9; background: #173128; border-color: #295e49; }
html[data-theme="dark"] .alert-info { color: #9bd6f5; background: #182d3a; border-color: #315b72; }

/* Superfici ricorrenti delle pagine SmartTraining */
html[data-theme="dark"] :is(
    .registry-pagination, .courses-pagination, .private-pagination,
    .company-contact-row, .private-form-card, .private-table-card,
    .company-summary-card, .summary-toolbar, .summary-table-card,
    .overview-card, .overview-worker-card, .overview-detail, .send-modal,
    .calendar-hub-card, .course-calendar-grid, .course-calendar-corner,
    .course-calendar-day-heading, .course-calendar-hours,
    .teacher-calendar-grid, .teacher-calendar-corner,
    .teacher-calendar-day-heading, .teacher-calendar-hours,
    .teacher-picker-item, .teacher-calendar-overlap-list > button,
    .backup-status-card, .backup-empty, .cloud-connection-status,
    .safety-stats article, .safety-panel, .document-card, .safety-empty,
    .missing-kpis > div, .missing-card,
    .rich-editor, .rich-editor__toolbar button, .rich-editor__color, .rich-editor__image,
    .comm-chat-choice, .comm-body,
    .mail-shell, .mail-row, .mail-thread-message, .mail-html-body,
    .wa-shell, .wa-conversations, .wa-chat-row, .wa-chat-header,
    .wa-composer, .wa-empty-compose, .wa-connection-card,
    .wa-connection-wait, .wa-emoji-picker, .wa-load-older,
    .logout-confirm-dialog
) {
    color: var(--st-text);
    background-color: var(--st-surface);
    border-color: var(--st-border);
}

html[data-theme="dark"] :is(
    .registry-table-scroll thead th, .courses-table-head,
    .private-table-card thead th, .summary-table thead th,
    .missing-table-scroll thead th, .overview-detail__header,
    .rich-editor__toolbar, .mail-sidebar, .mail-move
) {
    color: #aeb7c7;
    background: var(--st-surface-soft);
    border-color: var(--st-border);
}

html[data-theme="dark"] :is(
    .calendar-hub-card, .registry-choice-card,
    .course-calendar-detail-facts strong, .teacher-calendar-detail-facts strong,
    .comm-title, .comm-chat-choice, .wa-connection-card strong,
    .missing-heading h1, .missing-kpis strong, .missing-courses strong
) { color: var(--st-text); }

html[data-theme="dark"] :is(
    .calendar-hub-card p, .course-calendar-heading p, .course-calendar-count,
    .course-calendar-legend, .course-calendar-detail p,
    .teacher-calendar-heading p, .teacher-calendar-count,
    .teacher-calendar-legend, .teacher-calendar-detail p,
    .comm-meta, .comm-contact, .comm-chat-number,
    .wa-status, .wa-chat-main small, .wa-chat-meta,
    .missing-heading p, .missing-toolbar p, .missing-kpis span,
    .private-heading p, .private-list-heading span
) { color: var(--st-text-soft); }

html[data-theme="dark"] .course-row--parent > td {
    color: var(--st-text);
    background: #242744 !important;
    border-color: #42477e;
}

html[data-theme="dark"] .course-row--child > td { background: #181b24; }

html[data-theme="dark"] .course-calendar-day,
html[data-theme="dark"] .teacher-calendar-day {
    background: repeating-linear-gradient(to bottom, #151922 0, #151922 47px, #2a303c 48px);
    border-color: var(--st-border);
}

/* Calendari: nel tema scuro nessuna superficie resta bianca. */
html[data-theme="dark"] :is(
    .calendar-hub-card:hover,
    .course-calendar-unscheduled-list button,
    .teacher-calendar-overlap-list > button:hover,
    .calendar-picker-item,
    .private-event-modal,
    .google-event-modal,
    .smart-calendar-month,
    .smart-calendar-month-day,
    .smart-calendar-week-grid,
    .smart-calendar-week-corner,
    .smart-calendar-week-heading,
    .smart-calendar-hours,
    .smart-calendar-agenda-day,
    .smart-calendar-agenda-event
) {
    color: var(--st-text);
    background-color: var(--st-surface);
    border-color: var(--st-border);
}

html[data-theme="dark"] :is(
    .smart-calendar-month-day.is-outside,
    .smart-calendar-agenda-day > header,
    .smart-calendar-agenda-event:hover,
    .calendar-picker-item.is-selected
) {
    color: var(--st-text);
    background: var(--st-surface-soft);
    border-color: var(--st-border-strong);
}

html[data-theme="dark"] :is(
    .calendar-hub-card:hover,
    .calendar-hub-card:hover h2,
    .course-calendar-unscheduled-list button strong,
    .smart-calendar-chip,
    .smart-calendar-week-event
) { color: var(--st-text); }

html[data-theme="dark"] .wa-main { background: #11151c; }
html[data-theme="dark"] .wa-messages {
    background-color: #111820;
    background-image: radial-gradient(#2a343b 1px, transparent 1px);
}

html[data-theme="dark"] .wa-chat-row:hover { background: #1d222c; }
html[data-theme="dark"] .wa-chat-row.active {
    background: linear-gradient(90deg, #28254b 0, #202132 100%);
}

html[data-theme="dark"] .wa-bubble { color: var(--st-text); background: #252b35; }
html[data-theme="dark"] .wa-bubble.sent { color: #dff8ec; background: #174837; }
html[data-theme="dark"] .comm-content { border-color: var(--st-border); }
html[data-theme="dark"] .comm-body { background: var(--st-surface-soft); }

/* Contrasto delle tabelle: interessa soltanto il tema scuro. */
html[data-theme="dark"] table {
    color: var(--st-text) !important;
    background-color: var(--st-surface) !important;
}

html[data-theme="dark"] table thead,
html[data-theme="dark"] table thead tr,
html[data-theme="dark"] table thead th,
html[data-theme="dark"] :is(
    .agenda-table-head, .forecast-table-head, .courses-table-head,
    .workers-table-head, .registry-table-scroll thead th,
    .projects-table-scroll thead th, .medical-visits-table-scroll thead th,
    .slot-table-wrap thead th, .missing-workers-table thead th
) {
    color: #c7cfdd !important;
    background: #1d222d !important;
    border-color: var(--st-border) !important;
}

html[data-theme="dark"] table thead :is(button, a),
html[data-theme="dark"] :is(
    .projects-sortable-header, .medical-visits-sortable-header,
    .medical-visits-sortable-header button
) {
    color: inherit !important;
}

html[data-theme="dark"] table tbody td {
    color: var(--st-text);
    border-color: var(--st-border) !important;
}

html[data-theme="dark"] table tbody tr:hover > td {
    background-color: #202531;
}

html[data-theme="dark"] :is(
    .catalog-table tr.selected, .table tr.selected,
    .table tr.active
) > td {
    background-color: #292c50 !important;
}

html[data-theme="dark"] :is(
    .client-medical-table thead th:not(.client-medical-actions-heading):hover,
    .client-medical-table thead th.is-sorted,
    .my-workers-table thead th:not(.my-workers-actions-heading):hover,
    .my-workers-table thead th.is-sorted,
    .projects-sortable-header:hover,
    .medical-visits-sortable-header:hover
) {
    color: #b9bbff !important;
}

/* Gli accenti blu usati nel tema chiaro diventano lilla chiaro sul fondo scuro. */
html[data-theme="dark"] :is(
    a:not(.btn):not(.nav-link), .btn-link,
    .course-row--parent .course-title-text,
    .calendar-hub-eyebrow, .calendar-hub-card strong,
    .course-calendar-eyebrow, .course-calendar-detail-source,
    .private-eyebrow, .registry-choice-eyebrow,
    .summary-eyebrow, .company-summary-card__label,
    .missing-eyebrow, .eyebrow, .catalog-tabs button.active,
    .sidebar-version
) {
    color: #adafff !important;
}

html[data-theme="dark"] :is(
    .overview-course-row > button, .overview-worker-card button,
    .view-button.active, .rich-editor__toolbar button:hover,
    .rich-editor__image:hover, .wa-compose-icon:hover
) {
    color: #b9bbff !important;
    border-color: var(--st-primary-border);
}

html[data-theme="dark"] .course-row--parent .course-title-text {
    color: #d0d1ff !important;
}

html[data-theme="dark"] .registry-compact-table td:nth-child(2),
html[data-theme="dark"] .catalog-table td strong,
html[data-theme="dark"] .summary-table td strong {
    color: var(--st-text) !important;
}

/*
 * Copertura dei componenti con colori locali non basati sulle variabili globali.
 * Tutte queste regole sono vincolate al solo tema scuro.
 */
html[data-theme="dark"] :is(
    .filter-card, .versions-card, .results-card, .upload-card, .loading-card,
    .cert-search-card, .cert-results-card, .bulk, .bulk-toolbar,
    .hub-card, .choice-card, .worker-result, .worker-item,
    .company-assignment-card, .company-role-section, .company-roles-body,
    .company-roles-footer, .company-roles-modal, .company-roles-empty,
    .detail-heading, .detail-section, .invoice-card, .payment-dialog,
    .summary-grid > div, .invoice-totals > div, .accounting-card,
    .account-section, .review-box, .safety-file-card,
    .worker-cert-modal, .worker-cert-preview-modal,
    .worker-assignments-view-modal, .worker-assignments-view-role,
    .worker-assignments-view-empty, .worker-roles-modal, .worker-roles-add,
    .worker-roles-empty, .model-choice, .send-card,
    .worker-box, .loading-box, .document-box, .box, .category-card,
    .delete-confirm, .empty-models, .placeholder-help, .upload-panel,
    .worker-alert-card, .worker-alert-empty, .user-photo-editor,
    .users-table-shell, .availability-teacher,
    .registry-choice-card, .dashboard-date, .valid-only,
    .course-calendar-unscheduled-list button,
    .docentes-table-scroll, .agenda-table-scroll, .forecast-table-scroll,
    .my-workers-table-scroll, .client-medical-table-scroll,
    .projects-pagination, .medical-visits-pagination,
    .workers-pagination, .my-workers-pagination, .client-medical-pagination,
    .missing-report, .missing-company,
    .catalog-hero, .catalog-stats > div, .catalog-filters,
    .catalog-empty, .catalog-table-shell, .course-detail,
    .catalog-modal, .catalog-modal > footer, .program-source,
    .program-source span, .program-empty, .source-excerpt,
    .slot-existing-panel, .slot-empty-state, .participant-single-selection,
    .participant-single-selection__header, .group-overview-item,
    .group-tab, .worker-interrupted-option, .medical-employer-exclusion,
    .rls-card, .rls-manage, .upload-details,
    .rls-history-title, .attachment-row,
    .attachment-upload-row td, .dvr-edit-row td
) {
    color: var(--st-text) !important;
    background: var(--st-surface) !important;
    border-color: var(--st-border) !important;
}

html[data-theme="dark"] :is(
    .global-back-button, .view-button,
    .overview-course-row > button, .overview-worker-card button,
    .rich-editor__toolbar button, .rich-editor__color, .rich-editor__image,
    .wa-tool, .wa-compose-icon, .wa-load-older
) {
    color: #c7cfdd !important;
    background: var(--st-surface-soft) !important;
    border-color: var(--st-border-strong) !important;
}

html[data-theme="dark"] :is(
    .global-back-button:hover, .view-button:hover,
    .worker-result:hover, .worker-result.selected,
    .worker-item:hover, .worker-item.selected,
    .mail-row:hover, .comm-chat-choice:hover,
    .teacher-calendar-overlap-list > button:hover,
    .safety-tabs button.active
) {
    color: var(--st-text) !important;
    background: #242938 !important;
    border-color: var(--st-primary-border) !important;
}

html[data-theme="dark"] :is(
    .card-header, .card-footer,
    .incarichi-card .card-header,
    .worker-employer-card .card-header,
    .backup-config-card .card-header,
    .backup-components-card .card-header,
    .rls-card-header, .rls-history-title,
    .upload-details summary, .participant-single-selection__header,
    .overview-detail__header, .program-source,
    .worker-alert-card header
) {
    color: var(--st-text) !important;
    background: var(--st-surface-soft) !important;
    border-color: var(--st-border) !important;
}

html[data-theme="dark"] .rls-card-header {
    background: linear-gradient(135deg, #1b1f2a, #172721) !important;
}

html[data-theme="dark"] :is(
    .rls-card-header h2, .rls-manage summary,
    .rls-history-title h3, .upload-details summary,
    .forecast-course, .agenda-course,
    .course-title-text, .registry-choice-card,
    .catalog-page, .program-content,
    .legacy-page, .client-cert-page, .cert-page,
    .hub-page, .client-cert-hub,
    .safety-file-card, .choice-card b, .hub-card,
    .company-assignment-name strong,
    .company-role-title h3, .company-assignments-heading h3,
    .overview-card__heading h3, .overview-detail__header h3,
    .overview-course-row > strong, .overview-worker-card strong,
    .group-configuration-row h5, .group-overview-item strong,
    .slot-panel-heading h5, .slot-existing-heading h5,
    .missing-report__header h3, .missing-detail__header h3,
    .forms-heading h1, .page-heading h1, .document-header h2,
    .worker-box h2, .users-list-heading h5,
    .availability-request__title, .availability-teacher__heading h6
) {
    color: var(--st-text) !important;
}

html[data-theme="dark"] :is(
    .rls-card-header p, .rls-history-title p,
    .rls-table td:first-child small, .rls-history-table td:first-child small,
    .filter-help, .upload-help, .inline-edit small,
    .incarichi-heading p, .forecast-period span,
    .attachment-row, .worker-alert-heading span,
    .company-assignment-name span, .company-assignments-count,
    .worker-assignments-view-title span, .worker-assignments-view-role span,
    .worker-roles-section-title span, .selected-worker span,
    .catalog-hero p, .catalog-stats span, .catalog-table td small,
    .history-detail dt, .source-excerpt, .program-source,
    .overview-worker-card span, .company-summary-card__stats span,
    .index-summary span, .availability-summary, .availability-slots span
) {
    color: var(--st-text-soft) !important;
}

html[data-theme="dark"] :is(
    .filter-grid label, .upload-details-body label,
    .inline-upload-fields label, .rls-mode-row label span,
    .rls-form label span, .cert-search-fields label,
    .worker-search label, .type-filter, .payment-form label,
    .form-grid label, .catalog-filters label, .detail-grid label,
    .mode-editor legend, .worker-select label, .send-card label,
    .upload-panel label
) {
    color: #c7cfdd !important;
}

/* Testo normale dentro le tabelle: badge e stati mantengono i propri colori. */
html[data-theme="dark"] table tbody td {
    color: var(--st-text) !important;
}

html[data-theme="dark"] table tbody td > :is(strong, b) {
    color: var(--st-text) !important;
}

html[data-theme="dark"] table tbody td > small,
html[data-theme="dark"] table tbody td > span:not([class*="status"]):not([class*="badge"]):not([class*="deadline"]):not([class*="trust"]):not([class*="result"]) {
    color: var(--st-text-soft) !important;
}

html[data-theme="dark"] table tbody td > a:not(.btn),
html[data-theme="dark"] :is(.document-link, .attachment-link, .worker-action) {
    color: #b9bbff !important;
}

html[data-theme="dark"] :is(
    .forecast-course, .agenda-course,
    .course-row--parent .course-title-text,
    .course-row--child .course-title-text,
    .mail-row.unread .mail-row__sender,
    .mail-row.unread .mail-row__subject,
    .mail-row.unread .mail-row__date
) {
    color: var(--st-text) !important;
}

html[data-theme="dark"] :is(
    .courses-total, .private-total, .registry-total,
    .incarichi-total, .rls-history-title > span,
    .scope-badge, .match-badge, .result-count,
    .worker-count--total, .worker-count--inactive,
    .my-workers-count--inactive
) {
    color: #c7c8ff !important;
    background: #292c50 !important;
    border-color: #464b8a !important;
}

/* Stati mantenuti leggibili senza alterarne il significato cromatico. */
html[data-theme="dark"] :is(
    .forecast-status, .agenda-status, .course-status,
    .registry-status, .worker-status, .rls-status,
    .status, .status-badge, .validity-badge,
    .log-result, .trust, .event-badge, .role-pill
) {
    filter: saturate(.9) brightness(1.05);
}

html[data-theme="dark"] .rls-expired { background: #2b1c20 !important; }
html[data-theme="dark"] .incarico-inattivo { color: var(--st-text-soft) !important; background: #1b1f28 !important; }

/* Modali applicative scure; i documenti PDF/iframe restano intenzionalmente bianchi. */
html[data-theme="dark"] :is(
    .pdf-modal, .cert-modal, .preview-modal,
    .worker-cert-preview-modal, .pdf-preview-dialog,
    .prescription-preview-dialog
) {
    color: var(--st-text);
    background: var(--st-surface) !important;
    border-color: var(--st-border) !important;
}

html[data-theme="dark"] .login-logo-wrap,
html[data-theme="dark"] .login-card {
    background: rgba(22, 25, 34, .96);
    border-color: var(--st-border);
}

html[data-theme="dark"] .login-shell {
    background:
        radial-gradient(circle at 12% 15%, rgba(139, 141, 245, .16), transparent 32%),
        radial-gradient(circle at 88% 82%, rgba(63, 198, 143, .1), transparent 30%),
        var(--st-bg);
}

html[data-theme="dark"] ::-webkit-scrollbar-thumb { background: #454d5d; background-clip: padding-box; }

@media print {
    html[data-theme="dark"] { color-scheme: light; }
    html[data-theme="dark"] body,
    html[data-theme="dark"] .app-shell,
    html[data-theme="dark"] .app-main,
    html[data-theme="dark"] .app-content {
        color: #172033;
        background: #fff;
    }
}
