/* =====================================================================================
 * CRTRAS - tema scuro, CSS comune (fase 1, 22/10/2026)
 *
 * Caricato SEMPRE con media="screen": in stampa non si applica mai (stampe, PDF ed etichette
 * restano chiare). Tutte le regole valgono solo con html[data-bs-theme=dark], che imposta
 * tema-init.js.
 *
 * 1) Palette scura aziendale (variabili --crt-d-*), derivata dai colori del logo e del
 *    template: antracite #171717/#252525, blu logo #0084ca, blu template #0345bf,
 *    grigio logo #bcc0c3. Contrasti misurati (WCAG):
 *      testo #e5e7e9 su fondo #141618 = 14.6 / su superficie #1d2023 = 13.2
 *      tenue #a7adb3 su fondo = 8.0 / su superficie-2 #262a2e = 6.4
 *      link  #5bbcf0 su fondo = 8.6 / su superficie-2 = 6.8
 *      bianco su blu template #0345bf (pulsanti) = 8.05
 *    Il blu logo #0084ca (4.0 sulle superfici) si usa SOLO per linee e bordi, mai per testo.
 * 2) Bootstrap 5.3 (data-bs-theme): si ridefiniscono le sue variabili sulla palette.
 *    html[data-bs-theme=dark] (0,1,1) vince su [data-bs-theme=dark] di Bootstrap (0,1,0)
 *    a prescindere dall'ordine dei file.
 * 3) Compatibilita' generica per le pagine con colori fissi (bgcolor, style="background:#fff",
 *    .bg-white/.bg-light, tabelle senza classi). Non riscrive le pagine: dove non basta,
 *    la pagina e' annotata per la fase 2.
 * ===================================================================================== */

:root {
    --crt-d-fondo: #141618;
    --crt-d-superficie: #1d2023;
    --crt-d-superficie-2: #262a2e;
    --crt-d-superficie-3: #2f3439;
    --crt-d-bordo: #3b4046;
    --crt-d-testo: #e5e7e9;
    --crt-d-tenue: #a7adb3;
    --crt-d-link: #5bbcf0;
    --crt-d-link-hover: #8fd0f5;
    --crt-d-linea: #0084ca;          /* blu logo: solo linee/bordi */
    --crt-d-primario: #0345bf;       /* blu template: fondi pulsanti, testo bianco */
    --crt-d-primario-hover: #044cd0;
    --crt-d-sel: #1b3a52;            /* righe selezionate/evidenziate */
    --crt-d-giallo-bg: #3a3214;      /* evidenze "warning" chiare (#fff3cd) */
    --crt-d-giallo-fg: #ffe69c;
}

/* ---------- 2) Bootstrap 5.3 sulla palette aziendale ---------- */
html[data-bs-theme=dark] {
    color-scheme: dark;
    --bs-body-bg: var(--crt-d-fondo);
    --bs-body-bg-rgb: 20, 22, 24;
    --bs-body-color: var(--crt-d-testo);
    --bs-body-color-rgb: 229, 231, 233;
    --bs-emphasis-color: #fff;
    --bs-secondary-color: var(--crt-d-tenue);
    --bs-secondary-bg: var(--crt-d-superficie-2);
    --bs-secondary-bg-rgb: 38, 42, 46;
    --bs-tertiary-bg: var(--crt-d-superficie);
    --bs-tertiary-bg-rgb: 29, 32, 35;
    --bs-border-color: var(--crt-d-bordo);
    --bs-border-color-translucent: rgba(255, 255, 255, .12);
    --bs-link-color: var(--crt-d-link);
    --bs-link-color-rgb: 91, 188, 240;
    --bs-link-hover-color: var(--crt-d-link-hover);
    --bs-link-hover-color-rgb: 143, 208, 245;
    --bs-primary-text-emphasis: var(--crt-d-link-hover);
    --bs-primary-bg-subtle: #0c2a45;
    --bs-primary-border-subtle: #0a4a7a;
    /* NB: --bs-white-rgb / --bs-light-rgb / --bs-dark-rgb NON si toccano: li usano anche
       .text-white, .text-light e .bg-dark, che devono restare come sono. Le classi chiare
       fisse (.bg-white, .bg-light, .text-dark) sono corrette una per una piu' sotto. */
}
html[data-bs-theme=dark] body { background-color: var(--crt-d-fondo); color: var(--crt-d-testo); }
html[data-bs-theme=dark] .card,
html[data-bs-theme=dark] .modal-content,
html[data-bs-theme=dark] .dropdown-menu,
html[data-bs-theme=dark] .list-group-item,
html[data-bs-theme=dark] .accordion-item,
html[data-bs-theme=dark] .offcanvas { --bs-card-bg: var(--crt-d-superficie); --bs-modal-bg: var(--crt-d-superficie);
    --bs-dropdown-bg: var(--crt-d-superficie-2); --bs-list-group-bg: var(--crt-d-superficie); --bs-accordion-bg: var(--crt-d-superficie);
    --bs-offcanvas-bg: var(--crt-d-superficie); }
html[data-bs-theme=dark] .table { --bs-table-bg: var(--crt-d-superficie); --bs-table-color: var(--crt-d-testo);
    --bs-table-border-color: var(--crt-d-bordo); --bs-table-striped-bg: rgba(255, 255, 255, .04); --bs-table-hover-bg: rgba(91, 188, 240, .10); }
html[data-bs-theme=dark] .table-light,
html[data-bs-theme=dark] .table > thead.table-light > tr > th { --bs-table-bg: var(--crt-d-superficie-3); --bs-table-color: var(--crt-d-testo);
    --bs-table-border-color: var(--crt-d-bordo); color: var(--crt-d-testo); }
html[data-bs-theme=dark] .btn-primary { --bs-btn-bg: var(--crt-d-primario); --bs-btn-border-color: var(--crt-d-primario); --bs-btn-color: #fff;
    --bs-btn-hover-bg: var(--crt-d-primario-hover); --bs-btn-hover-border-color: var(--crt-d-primario-hover); --bs-btn-hover-color: #fff; }
html[data-bs-theme=dark] .btn-light { --bs-btn-bg: var(--crt-d-superficie-2); --bs-btn-border-color: var(--crt-d-bordo); --bs-btn-color: var(--crt-d-testo);
    --bs-btn-hover-bg: var(--crt-d-superficie-3); --bs-btn-hover-color: #fff; }
html[data-bs-theme=dark] .btn-outline-dark { --bs-btn-color: var(--crt-d-testo); --bs-btn-border-color: var(--crt-d-tenue);
    --bs-btn-hover-bg: var(--crt-d-testo); --bs-btn-hover-color: var(--crt-d-fondo); }
html[data-bs-theme=dark] .form-control,
html[data-bs-theme=dark] .form-select { background-color: var(--crt-d-superficie-2); color: var(--crt-d-testo); border-color: var(--crt-d-bordo); }
html[data-bs-theme=dark] .form-control::placeholder { color: var(--crt-d-tenue); }
html[data-bs-theme=dark] .form-control:disabled,
html[data-bs-theme=dark] .form-control[readonly] { background-color: var(--crt-d-superficie); }

/* ---------- 3) compatibilita' per pagine con colori fissi ---------- */
/* attributi HTML vecchi */
html[data-bs-theme=dark] [bgcolor="#ffffff" i],
html[data-bs-theme=dark] [bgcolor="#fff" i],
html[data-bs-theme=dark] [bgcolor="white" i],
html[data-bs-theme=dark] [bgcolor="#f8f9fa" i],
html[data-bs-theme=dark] [bgcolor="#f0f0f0" i],
html[data-bs-theme=dark] [bgcolor="#eeeeee" i] { background-color: var(--crt-d-superficie) !important; color: var(--crt-d-testo); }
/* stili in linea con sfondo bianco o quasi: il colore deve FINIRE li' (; spazio ! o fine stile),
   altrimenti "background:#fff" prenderebbe anche #ffff00 e simili */
html[data-bs-theme=dark] [style*="background:#fff;" i],
html[data-bs-theme=dark] [style*="background:#fff " i],
html[data-bs-theme=dark] [style*="background:#fff!" i],
html[data-bs-theme=dark] [style$="background:#fff" i],
html[data-bs-theme=dark] [style*="background:#ffffff;" i],
html[data-bs-theme=dark] [style*="background:#ffffff " i],
html[data-bs-theme=dark] [style*="background:#ffffff!" i],
html[data-bs-theme=dark] [style$="background:#ffffff" i],
html[data-bs-theme=dark] [style*="background:white;" i],
html[data-bs-theme=dark] [style*="background:white " i],
html[data-bs-theme=dark] [style*="background:white!" i],
html[data-bs-theme=dark] [style$="background:white" i],
html[data-bs-theme=dark] [style*="background:#f8f9fa;" i],
html[data-bs-theme=dark] [style*="background:#f8f9fa " i],
html[data-bs-theme=dark] [style*="background:#f8f9fa!" i],
html[data-bs-theme=dark] [style$="background:#f8f9fa" i],
html[data-bs-theme=dark] [style*="background: #fff;" i],
html[data-bs-theme=dark] [style*="background: #fff " i],
html[data-bs-theme=dark] [style*="background: #fff!" i],
html[data-bs-theme=dark] [style$="background: #fff" i],
html[data-bs-theme=dark] [style*="background: #ffffff;" i],
html[data-bs-theme=dark] [style*="background: #ffffff " i],
html[data-bs-theme=dark] [style*="background: #ffffff!" i],
html[data-bs-theme=dark] [style$="background: #ffffff" i],
html[data-bs-theme=dark] [style*="background: white;" i],
html[data-bs-theme=dark] [style*="background: white " i],
html[data-bs-theme=dark] [style*="background: white!" i],
html[data-bs-theme=dark] [style$="background: white" i],
html[data-bs-theme=dark] [style*="background: #f8f9fa;" i],
html[data-bs-theme=dark] [style*="background: #f8f9fa " i],
html[data-bs-theme=dark] [style*="background: #f8f9fa!" i],
html[data-bs-theme=dark] [style$="background: #f8f9fa" i],
html[data-bs-theme=dark] [style*="background-color:#fff;" i],
html[data-bs-theme=dark] [style*="background-color:#fff " i],
html[data-bs-theme=dark] [style*="background-color:#fff!" i],
html[data-bs-theme=dark] [style$="background-color:#fff" i],
html[data-bs-theme=dark] [style*="background-color:#ffffff;" i],
html[data-bs-theme=dark] [style*="background-color:#ffffff " i],
html[data-bs-theme=dark] [style*="background-color:#ffffff!" i],
html[data-bs-theme=dark] [style$="background-color:#ffffff" i],
html[data-bs-theme=dark] [style*="background-color:white;" i],
html[data-bs-theme=dark] [style*="background-color:white " i],
html[data-bs-theme=dark] [style*="background-color:white!" i],
html[data-bs-theme=dark] [style$="background-color:white" i],
html[data-bs-theme=dark] [style*="background-color:#f8f9fa;" i],
html[data-bs-theme=dark] [style*="background-color:#f8f9fa " i],
html[data-bs-theme=dark] [style*="background-color:#f8f9fa!" i],
html[data-bs-theme=dark] [style$="background-color:#f8f9fa" i],
html[data-bs-theme=dark] [style*="background-color: #fff;" i],
html[data-bs-theme=dark] [style*="background-color: #fff " i],
html[data-bs-theme=dark] [style*="background-color: #fff!" i],
html[data-bs-theme=dark] [style$="background-color: #fff" i],
html[data-bs-theme=dark] [style*="background-color: #ffffff;" i],
html[data-bs-theme=dark] [style*="background-color: #ffffff " i],
html[data-bs-theme=dark] [style*="background-color: #ffffff!" i],
html[data-bs-theme=dark] [style$="background-color: #ffffff" i],
html[data-bs-theme=dark] [style*="background-color: white;" i],
html[data-bs-theme=dark] [style*="background-color: white " i],
html[data-bs-theme=dark] [style*="background-color: white!" i],
html[data-bs-theme=dark] [style$="background-color: white" i],
html[data-bs-theme=dark] [style*="background-color: #f8f9fa;" i],
html[data-bs-theme=dark] [style*="background-color: #f8f9fa " i],
html[data-bs-theme=dark] [style*="background-color: #f8f9fa!" i],
html[data-bs-theme=dark] [style$="background-color: #f8f9fa" i] { background-color: var(--crt-d-superficie) !important; color: var(--crt-d-testo) !important; }
/* evidenze gialle chiare in linea (#fff3cd = alert warning di Bootstrap) */
html[data-bs-theme=dark] [style*="#fff3cd" i] { background-color: var(--crt-d-giallo-bg) !important; color: var(--crt-d-giallo-fg) !important; }
/* testo nero fisso in linea: diventa chiaro */
html[data-bs-theme=dark] [style*="color:#000" i]:not([style*="background" i]),
html[data-bs-theme=dark] [style*="color: #000" i]:not([style*="background" i]),
html[data-bs-theme=dark] [style*="color:black" i]:not([style*="background" i]),
html[data-bs-theme=dark] [style*="color: black" i]:not([style*="background" i]) { color: var(--crt-d-testo) !important; }
/* <font color="black"> e simili */
html[data-bs-theme=dark] font[color="black" i],
html[data-bs-theme=dark] font[color="#000000" i],
html[data-bs-theme=dark] font[color="#000" i] { color: var(--crt-d-testo); }
/* tabelle "nude" (senza .table) */
html[data-bs-theme=dark] table:not(.table) { border-color: var(--crt-d-bordo); }
html[data-bs-theme=dark] table:not(.table) th { background-color: var(--crt-d-superficie-3); color: var(--crt-d-testo); }
/* classi Bootstrap che in 5.3 restano chiare anche in dark */
html[data-bs-theme=dark] .bg-white,
html[data-bs-theme=dark] .bg-light,
html[data-bs-theme=dark] .text-bg-light { background-color: var(--crt-d-superficie) !important; color: var(--crt-d-testo) !important; }
/* testo scuro fisso -> chiaro, ma NON sui fondi che restano chiari (badge/pulsanti/avvisi gialli e azzurri) */
html[data-bs-theme=dark] :is(.text-dark, .text-black, .link-dark):not(.bg-warning):not(.bg-info):not(.text-bg-warning):not(.text-bg-info):not(.badge):not(.btn):not(:is(.bg-warning, .bg-info, .text-bg-warning, .text-bg-info, .alert-warning, .alert-info, .badge, .btn-warning, .btn-info) *) { color: var(--crt-d-testo) !important; }
html[data-bs-theme=dark] .navbar-light,
html[data-bs-theme=dark] .navbar.bg-light { background-color: var(--crt-d-superficie) !important; }
html[data-bs-theme=dark] .border-dark { border-color: var(--crt-d-bordo) !important; }
html[data-bs-theme=dark] hr { border-color: var(--crt-d-bordo); opacity: 1; }
/* campi nativi senza classi Bootstrap */
html[data-bs-theme=dark] input:not([type=checkbox]):not([type=radio]):not([type=button]):not([type=submit]):not([type=image]):not([type=color]):not([type=range]):not(.form-control):not(.btn),
html[data-bs-theme=dark] select:not(.form-select):not(.form-control),
html[data-bs-theme=dark] textarea:not(.form-control) { background-color: var(--crt-d-superficie-2); color: var(--crt-d-testo); border-color: var(--crt-d-bordo); }
/* immagini e canvas (firme, codici a barre, foto): restano come sono, su fondo chiaro se trasparenti */
html[data-bs-theme=dark] img[src*="barcode" i],
html[data-bs-theme=dark] img[src*="qr" i],
html[data-bs-theme=dark] canvas { background-color: #fff; }
/* barre di scorrimento */
html[data-bs-theme=dark] * { scrollbar-color: var(--crt-d-bordo) var(--crt-d-fondo); }

/* ---------- famiglia "elenco.css" (Spedizioni, Bordero, Affidi, Servizi, Contrassegni, Importa:
   stessi selettori copiati in ogni cartella): barra #navigation, titoli table.title,
   tabelle table.footcollapse con testate pari/dispari ---------- */
html[data-bs-theme=dark] div#navigation,
html[data-bs-theme=dark] div#navigation li a,
html[data-bs-theme=dark] table.title,
html[data-bs-theme=dark] table.title th,
html[data-bs-theme=dark] table.title td { background-color: var(--crt-d-superficie); color: var(--crt-d-testo); }
html[data-bs-theme=dark] div#navigation { border-bottom-color: var(--crt-d-bordo); }
html[data-bs-theme=dark] div#navigation li a:hover { background-color: var(--crt-d-superficie-3); }
html[data-bs-theme=dark] div#header { background-color: var(--crt-d-superficie-3); color: var(--crt-d-testo); }
html[data-bs-theme=dark] table.footcollapse thead.pari { background: #1f3550; color: var(--crt-d-testo); }
html[data-bs-theme=dark] table.footcollapse thead.dispari { background: #27456b; color: var(--crt-d-testo); }
html[data-bs-theme=dark] table.footcollapse thead tr:hover { background: var(--crt-d-superficie-3); }
html[data-bs-theme=dark] table.footcollapse tbody,
html[data-bs-theme=dark] table.footcollapse tbody td { background-color: var(--crt-d-superficie); color: var(--crt-d-testo); }
html[data-bs-theme=dark] table.footcollapse,
html[data-bs-theme=dark] table.footcollapse th,
html[data-bs-theme=dark] table.footcollapse td { border-color: var(--crt-d-bordo); }
html[data-bs-theme=dark] .checkmark { background-color: var(--crt-d-superficie-3); }

/* ---------- fase 2: varianti colorate delle tabelle Bootstrap (in 5.3 restano chiare anche in
   scuro, e col testo chiaro del tema diventavano illeggibili) ---------- */
html[data-bs-theme=dark] .table-primary { --bs-table-bg: #12304d; --bs-table-color: var(--crt-d-testo); --bs-table-border-color: #23486b; --bs-table-striped-bg: #163655; --bs-table-hover-bg: #1a3d5f; --bs-table-active-bg: #1a3d5f; --bs-table-striped-color: var(--crt-d-testo); --bs-table-hover-color: var(--crt-d-testo); --bs-table-active-color: var(--crt-d-testo); }
html[data-bs-theme=dark] .table-secondary { --bs-table-bg: #2b2f33; --bs-table-color: var(--crt-d-testo); --bs-table-border-color: #41464b; --bs-table-striped-bg: #30353a; --bs-table-hover-bg: #353a40; --bs-table-active-bg: #353a40; --bs-table-striped-color: var(--crt-d-testo); --bs-table-hover-color: var(--crt-d-testo); --bs-table-active-color: var(--crt-d-testo); }
html[data-bs-theme=dark] .table-success { --bs-table-bg: #12301f; --bs-table-color: var(--crt-d-testo); --bs-table-border-color: #22503a; --bs-table-striped-bg: #163723; --bs-table-hover-bg: #1a3e28; --bs-table-active-bg: #1a3e28; --bs-table-striped-color: var(--crt-d-testo); --bs-table-hover-color: var(--crt-d-testo); --bs-table-active-color: var(--crt-d-testo); }
html[data-bs-theme=dark] .table-info { --bs-table-bg: #0f3340; --bs-table-color: var(--crt-d-testo); --bs-table-border-color: #1d5263; --bs-table-striped-bg: #133a48; --bs-table-hover-bg: #174150; --bs-table-active-bg: #174150; --bs-table-striped-color: var(--crt-d-testo); --bs-table-hover-color: var(--crt-d-testo); --bs-table-active-color: var(--crt-d-testo); }
html[data-bs-theme=dark] .table-warning { --bs-table-bg: #3a3214; --bs-table-color: var(--crt-d-giallo-fg); --bs-table-border-color: #5a4c1c; --bs-table-striped-bg: #41381a; --bs-table-hover-bg: #48401e; --bs-table-active-bg: #48401e; --bs-table-striped-color: var(--crt-d-giallo-fg); --bs-table-hover-color: var(--crt-d-giallo-fg); --bs-table-active-color: var(--crt-d-giallo-fg); }
html[data-bs-theme=dark] .table-danger { --bs-table-bg: #3d1418; --bs-table-color: #f1aeb5; --bs-table-border-color: #5c2128; --bs-table-striped-bg: #44181d; --bs-table-hover-bg: #4b1c21; --bs-table-active-bg: #4b1c21; --bs-table-striped-color: #f1aeb5; --bs-table-hover-color: #f1aeb5; --bs-table-active-color: #f1aeb5; }
html[data-bs-theme=dark] .table-dark { --bs-table-bg: #0d0e0f; }
/* accordion: il bottone aperto usa un azzurro chiaro fisso */
html[data-bs-theme=dark] .accordion { --bs-accordion-active-bg: #12304d; --bs-accordion-active-color: var(--crt-d-link-hover); --bs-accordion-btn-bg: var(--crt-d-superficie); --bs-accordion-btn-color: var(--crt-d-testo); }
