/*
  style.css — Stili globali MyLife
  ═══════════════════════════════════════════════════════════════════════

  STRUTTURA:
    1. Variabili CSS (colori dei temi)
    2. Stili globali
    3. Tema SPP  (navbar scura, blu)
    4. Tema Casa (navbar verde oliva, toni caldi)
    5. Navbar e switch ambiente
    6. Portale (pagina scelta ambiente)
    7. Login
    8. Badge scadenze
    9. Utility e animazioni

  COS'È UNA VARIABILE CSS?
    Come le variabili in Python, ma per i colori/misure.
    Si definisce una volta e si riusa ovunque:
      --colore-primario: #2d6a4f;
    Poi si usa con: color: var(--colore-primario);
    Per cambiare tema basta ridefinire le variabili su un selettore padre.
*/

/* ═══════════════════════════════════════════════════════════════════
   1. VARIABILI CSS — tema di default (SPP)
═══════════════════════════════════════════════════════════════════ */

:root {
  --ml-nav-bg:          #1a1a2e;    /* sfondo navbar SPP: blu notte */
  --ml-nav-text:        #e0e0e0;    /* testo navbar */
  --ml-nav-hover:       #4fc3f7;    /* hover link navbar */
  --ml-nav-active:      #ffffff;    /* link attivo */
  --ml-accent:          #0d6efd;    /* colore accento Bootstrap blu */
  --ml-badge-bg:        #dc3545;    /* rosso per badge scadenze */
  --ml-body-bg:         #f8f9fa;    /* sfondo pagina */
  --ml-card-border:     #dee2e6;
  --ml-transition:      0.25s ease;
}

/* Tema Casa: sovrascrive le variabili quando il body ha classe .tema-casa */
body.tema-casa {
  --ml-nav-bg:          #2d6a4f;    /* verde scuro oliva */
  --ml-nav-hover:       #b7e4c7;    /* verde chiaro */
  --ml-accent:          #40916c;    /* verde medio */
  --ml-body-bg:         #fdf6ec;    /* bianco caldo panna */
}

/* ═══════════════════════════════════════════════════════════════════
   2. STILI GLOBALI
═══════════════════════════════════════════════════════════════════ */

body {
  background-color: var(--ml-body-bg);
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  font-size: 0.9375rem;
  overflow-x: hidden;
  transition: background-color var(--ml-transition);
}

/* Link globali */
a { text-decoration: none; }
a:hover { text-decoration: underline; }

/* Scrollbar personalizzata (solo Chrome/Edge) */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: #f1f1f1; }
::-webkit-scrollbar-thumb { background: #c1c1c1; border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: #a8a8a8; }

/* ═══════════════════════════════════════════════════════════════════
   3. NAVBAR
═══════════════════════════════════════════════════════════════════ */

.ml-navbar {
  background-color: var(--ml-nav-bg) !important;
  border-bottom: 3px solid rgba(255,255,255,0.08);
  transition: background-color var(--ml-transition);
  padding: 0.4rem 1rem;
}

.ml-navbar .navbar-brand {
  color: var(--ml-nav-active) !important;
  font-weight: 700;
  font-size: 1.15rem;
  letter-spacing: -0.3px;
}

.ml-navbar .nav-link {
  color: var(--ml-nav-text) !important;
  font-size: 0.875rem;
  padding: 0.4rem 0.75rem !important;
  border-radius: 6px;
  transition: color var(--ml-transition), background var(--ml-transition);
}

.ml-navbar .nav-link:hover,
.ml-navbar .nav-link.active {
  color: var(--ml-nav-active) !important;
  background: rgba(255,255,255,0.12);
}

.ml-navbar .dropdown-menu {
  background: #2a2a3e;
  border: 1px solid rgba(255,255,255,0.1);
  box-shadow: 0 8px 24px rgba(0,0,0,0.3);
}

body.tema-casa .ml-navbar .dropdown-menu {
  background: #1b4332;
}

.ml-navbar .dropdown-item {
  color: #d0d0d0;
  font-size: 0.875rem;
  padding: 0.5rem 1rem;
}

.ml-navbar .dropdown-item:hover {
  background: rgba(255,255,255,0.1);
  color: #fff;
}

.ml-navbar .dropdown-divider {
  border-color: rgba(255,255,255,0.1);
}

/* Dropdown navbar aperti all'hover (solo su desktop) */
@media (min-width: 992px) {
  .nav-hover-dropdown:hover > .dropdown-menu {
    display: block;
    margin-top: 0;
  }
  .nav-hover-dropdown > .dropdown-menu {
    margin-top: 0;
  }
}

/* ═══════════════════════════════════════════════════════════════════
   4. SWITCH AMBIENTE (SPP ↔ Casa)
═══════════════════════════════════════════════════════════════════ */

.ambiente-switch {
  display: flex;
  align-items: center;
  gap: 4px;
  background: rgba(255,255,255,0.1);
  border-radius: 20px;
  padding: 3px 5px;
  margin: 0 0.5rem;
}

.ambiente-btn {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 4px 12px;
  border-radius: 16px;
  font-size: 0.8rem;
  font-weight: 600;
  color: rgba(255,255,255,0.65);
  text-decoration: none !important;
  transition: all var(--ml-transition);
  border: none;
  background: transparent;
  cursor: pointer;
}

.ambiente-btn:hover {
  color: #fff;
  background: rgba(255,255,255,0.15);
}

.ambiente-btn.attivo {
  background: rgba(255,255,255,0.22);
  color: #fff;
  box-shadow: 0 1px 4px rgba(0,0,0,0.2);
  cursor: default;
}

a.ambiente-btn:not(.attivo):hover {
  background: rgba(255,255,255,0.18);
  color: #fff;
  transform: translateY(-1px);
}

/* ═══════════════════════════════════════════════════════════════════
   5. BADGE SCADENZE NAVBAR
═══════════════════════════════════════════════════════════════════ */

.badge-scad {
  font-size: 0.65rem;
  padding: 2px 5px;
  vertical-align: middle;
  animation: pulse-badge 2s infinite;
}

@keyframes pulse-badge {
  0%, 100% { transform: scale(1);   opacity: 1; }
  50%       { transform: scale(1.2); opacity: 0.8; }
}

/* ═══════════════════════════════════════════════════════════════════
   6. PAGINA LOGIN
═══════════════════════════════════════════════════════════════════ */

.login-wrapper {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #1a1a2e 0%, #16213e 50%, #0f3460 100%);
  padding: 1rem;
}

.login-card {
  width: 100%;
  max-width: 420px;
  background: rgba(255,255,255,0.05);
  backdrop-filter: blur(12px);
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 16px;
  padding: 2.5rem 2rem;
  box-shadow: 0 20px 60px rgba(0,0,0,0.5);
}

.login-logo {
  width: 72px;
  height: 72px;
  background: linear-gradient(135deg, #0d6efd, #6610f2);
  border-radius: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 1.25rem;
  font-size: 2rem;
  box-shadow: 0 8px 24px rgba(13,110,253,0.4);
}

.login-title {
  color: #ffffff;
  font-weight: 700;
  font-size: 1.5rem;
  text-align: center;
  margin-bottom: 0.25rem;
}

.login-subtitle {
  color: rgba(255,255,255,0.5);
  text-align: center;
  font-size: 0.85rem;
  margin-bottom: 1.75rem;
}

.login-card .form-label {
  color: rgba(255,255,255,0.75);
  font-size: 0.85rem;
  font-weight: 500;
}

.login-card .form-control {
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.15);
  color: #fff;
  border-radius: 8px;
  padding: 0.6rem 0.85rem;
}

.login-card .form-control:focus {
  background: rgba(255,255,255,0.12);
  border-color: #0d6efd;
  color: #fff;
  box-shadow: 0 0 0 3px rgba(13,110,253,0.25);
}

.login-card .form-control::placeholder { color: rgba(255,255,255,0.3); }

.login-card .input-group-text {
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.15);
  color: rgba(255,255,255,0.5);
}

.btn-login {
  background: linear-gradient(135deg, #0d6efd, #6610f2);
  border: none;
  border-radius: 8px;
  padding: 0.65rem;
  font-weight: 600;
  font-size: 0.95rem;
  letter-spacing: 0.3px;
  transition: all var(--ml-transition);
  box-shadow: 0 4px 15px rgba(13,110,253,0.3);
}

.btn-login:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 20px rgba(13,110,253,0.4);
}

.login-card .form-check-label { color: rgba(255,255,255,0.6); font-size: 0.85rem; }
.login-footer { color: rgba(255,255,255,0.25); font-size: 0.75rem; text-align: center; margin-top: 1.5rem; }

/* ═══════════════════════════════════════════════════════════════════
   7. PORTALE (pagina scelta ambiente)
═══════════════════════════════════════════════════════════════════ */

.portale-wrapper {
  min-height: calc(100vh - 140px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 2rem 1rem;
}

.portale-benvenuto {
  text-align: center;
  margin-bottom: 2.5rem;
}

.portale-benvenuto h2 {
  font-weight: 700;
  font-size: 1.75rem;
  color: #1a1a2e;
}

.portale-benvenuto p {
  color: #6c757d;
  font-size: 1rem;
}

.portale-cards {
  display: flex;
  gap: 1.5rem;
  flex-wrap: wrap;
  justify-content: center;
  max-width: 900px;
}

.portale-card {
  flex: 1;
  min-width: 260px;
  max-width: 340px;
  border: none;
  border-radius: 20px;
  padding: 2.5rem 2rem;
  text-align: center;
  text-decoration: none !important;
  transition: all 0.3s ease;
  position: relative;
  overflow: hidden;
  box-shadow: 0 4px 20px rgba(0,0,0,0.08);
}

.portale-card::before {
  content: '';
  position: absolute;
  inset: 0;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.portale-card:hover {
  transform: translateY(-6px);
  box-shadow: 0 12px 40px rgba(0,0,0,0.15);
}

/* Card SPP — sfondo nero identico all'app originale */
.portale-card-spp {
  background: #000;
  color: #fff;
}

.portale-card-spp:hover { color: #fff; }

/* Card Casa */
.portale-card-casa {
  background: linear-gradient(145deg, #2d6a4f, #40916c);
  color: #fff;
}

.portale-card-casa:hover { color: #fff; }

.portale-card-icon {
  width: 80px;
  height: 80px;
  border-radius: 20px;
  background: rgba(255,255,255,0.15);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2.2rem;
  margin: 0 auto 1.25rem;
  backdrop-filter: blur(4px);
}

.portale-card h3 {
  font-size: 1.3rem;
  font-weight: 700;
  margin-bottom: 0.5rem;
}

.portale-card p {
  font-size: 0.875rem;
  opacity: 0.75;
  margin-bottom: 1.25rem;
}

.portale-card .portale-btn {
  background: rgba(255,255,255,0.2);
  border: 1px solid rgba(255,255,255,0.3);
  color: #fff;
  border-radius: 8px;
  padding: 0.5rem 1.25rem;
  font-size: 0.875rem;
  font-weight: 600;
  transition: background var(--ml-transition);
}

.portale-card:hover .portale-btn {
  background: rgba(255,255,255,0.3);
}

/* Card Agenda — arancione bruciato */
.portale-card-agenda {
  background: linear-gradient(145deg, #b5420a, #e65100);
  color: #fff;
  min-width: 200px;
  max-width: 240px;
  padding: 1.75rem 1.5rem;
}

.portale-card-agenda:hover { color: #fff; }

/* Badge scadenze sulla card portale */
.portale-badge {
  position: absolute;
  top: 14px;
  right: 14px;
  background: #dc3545;
  color: #fff;
  border-radius: 12px;
  padding: 2px 8px;
  font-size: 0.75rem;
  font-weight: 700;
  animation: pulse-badge 2s infinite;
}

/* ═══════════════════════════════════════════════════════════════════
   8. BADGE SCADENZA (semaforo)
═══════════════════════════════════════════════════════════════════ */

.scad-rosso     { background: #dc3545 !important; color: #fff !important; }
.scad-arancione { background: #fd7e14 !important; color: #fff !important; }
.scad-giallo    { background: #ffc107 !important; color: #212529 !important; }
.scad-verde     { background: #198754 !important; color: #fff !important; }
.scad-grigio    { background: #6c757d !important; color: #fff !important; }
.scad-neutro    { background: #6c757d !important; color: #fff !important; }
.scad-completata{ background: #198754 !important; color: #fff !important; }

@keyframes scad-blink {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.2; }
}
.scad-blink { animation: scad-blink 1s ease-in-out infinite; }

/* Lampeggio link scadenze in navbar */
@keyframes blink-nav-alert {
  0%, 100% { opacity: 1; }
  50%       { opacity: .35; }
}
.nav-scad-alert { animation: blink-nav-alert 1.5s ease-in-out infinite; cursor: pointer; }

/* ═══════════════════════════════════════════════════════════════════
   9. SPP TABELLA — celle colorate, stato select, legenda
═══════════════════════════════════════════════════════════════════ */

/* Celle con sfondo colore (Oggetto / Note) */
.cell-colored { max-width: 300px; }
.wrap-cell    { white-space: normal; word-break: break-word; }

/* Select stato colorato — identici all'app originale SPP */
.stato-select   { font-size: .75rem; padding: 2px 4px; font-weight: 600; border-radius: 4px;
                  transition: background-color .2s, color .2s; width: 100%; }
.stato-aperta     { background-color: #dc3545 !important; color: #fff    !important; border-color: #dc3545 !important; }
.stato-in_corso   { background-color: #ffc107 !important; color: #212529 !important; border-color: #ffc107 !important; }
.stato-completata { background-color: #198754 !important; color: #fff    !important; border-color: #198754 !important; }
.stato-annullata  { background-color: #212529 !important; color: #fff    !important; border-color: #444    !important; }

/* Operatore con descrizione_altro → giallo vivace (identico originale) */
.op-has-desc { background-color: #ffc107 !important; color: #212529 !important; font-weight: 600; cursor: help; }

/* Selettore colore (form modifica/nuova) */
.color-swatch-label { display: flex; flex-direction: column; align-items: center; cursor: pointer; gap: 2px; }
.color-swatch-label input[type="radio"] { display: none; }
.color-swatch {
  display: inline-block; width: 26px; height: 26px;
  border-radius: 4px; border: 2px solid #ccc;
  transition: transform .15s, box-shadow .15s;
}
.color-swatch-label input[type="radio"]:checked + .color-swatch {
  transform: scale(1.25);
  box-shadow: 0 0 0 3px #0d6efd;
}
.color-swatch-name { font-size: .65rem; color: #555; text-align: center; line-height: 1.1; }

/* Pallino colore (legenda) */
.color-dot { display: inline-block; width: 16px; height: 16px; border-radius: 50%; flex-shrink: 0; }

/* Celle tabella SPP — selezione testo abilitata */
#tbl-attivita td { vertical-align: middle; }
#tbl-attivita td.wrap-cell,
#tbl-attivita td.cell-colored { user-select: text !important; -webkit-user-select: text !important; cursor: text; }

/* Hover riga tabella SPP — leggero scurimento (identico all'originale) */
#tbl-attivita tbody tr:hover { filter: brightness(0.96); }

/* Textarea colorata — transizione fluida del colore di sfondo */
textarea.form-control { transition: background-color .2s; }

/* ═══════════════════════════════════════════════════════════════════
   10. UTILITY
═══════════════════════════════════════════════════════════════════ */

/* Carte standard */
.ml-card {
  border: 1px solid var(--ml-card-border);
  border-radius: 12px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.06);
  background: #fff;
}

body.tema-casa .ml-card { background: #fff; }

/* Footer */
.ml-footer {
  text-align: center;
  color: #adb5bd;
  font-size: 0.78rem;
  padding: 1rem;
  border-top: 1px solid #dee2e6;
  margin-top: 2rem;
}

/* Alert flash */
.flash-container { margin: 0.75rem 0; }

/* Fix: tab-pane inattivi non devono occupare spazio */
.tab-pane.fade:not(.show) { display: none !important; }

/* Responsive: nasconde il testo dello switch su schermi piccoli */
@media (max-width: 576px) {
  .ambiente-btn span.amb-label { display: none; }

  /* Portale: disattiva centramento verticale su mobile */
  .portale-wrapper {
    min-height: auto;
    justify-content: flex-start;
    padding: .75rem .25rem;
  }
  .portale-benvenuto { margin-bottom: 1.5rem; }
  .portale-benvenuto h2 { font-size: 1.4rem; }

  /* Card portale: tutte stessa larghezza su mobile */
  .portale-cards { flex-direction: column; align-items: stretch; gap: .75rem; width: 100% !important; }
  .portale-card  { max-width: 100% !important; min-width: 0 !important; width: 100% !important; }
  .portale-card-agenda { max-width: 100% !important; min-width: 0 !important; width: 100%; }
  .portale-card { padding: 1.5rem 1.25rem; }
  .portale-card h3 { font-size: 1.1rem; }
  .portale-card p { font-size: .8rem; margin-bottom: .75rem; }
  .portale-card-icon { width: 50px; height: 50px; font-size: 1.4rem; margin-bottom: .75rem; }
  .portale-card-spp img { width: 50px !important; height: 50px !important; margin-bottom: .5rem !important; }

  /* Form: colonna singola su mobile */
  .col-sm-6, .col-sm-4, .col-sm-3 { flex: 0 0 100% !important; max-width: 100% !important; }

  /* Pulsanti toolbar: wrap su mobile */
  .d-flex.gap-2 { flex-wrap: wrap; }
  .d-flex.justify-content-between { flex-wrap: wrap; gap: 0.5rem; }
  .d-flex.justify-content-between > .d-flex { flex-wrap: wrap; gap: 0.5rem; }

  /* Pulsanti più grandi per touch */
  .btn-sm { padding: 0.4rem 0.75rem; font-size: 0.85rem; }

  /* Card: padding ridotto */
  .card-body { padding: 0.75rem; }

  /* Breadcrumb compatto */
  .breadcrumb { font-size: 0.8rem; }

  /* Modal: larghezza piena */
  .modal-dialog { margin: 0.5rem; max-width: calc(100% - 1rem); }

  /* Tabelle: font più piccolo */
  .table { font-size: 0.82rem; }
  .table th, .table td { padding: 0.35rem 0.5rem; }

  /* Navbar mobile: menu collassato con scroll */
  .navbar-collapse.show,
  .navbar-collapse.collapsing {
    max-height: 80vh;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  /* Tab admin: scroll orizzontale su mobile */
  .nav-tabs {
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  .nav-tabs::-webkit-scrollbar { display: none; }
  .nav-tabs .nav-item { flex-shrink: 0; }
  .nav-tabs .nav-link { white-space: nowrap; font-size: .82rem; padding: .4rem .6rem; }

  /* Dropdown nella navbar mobile: non sovrapporre */
  .navbar-nav .dropdown-menu {
    position: static !important;
    float: none;
    border: none;
    box-shadow: none;
    padding-left: 1rem;
    background: transparent;
  }

  /* Ricerca navbar: larghezza piena su mobile */
  .navbar-search-input { width: 100% !important; }
  .navbar form.d-flex { width: 100%; }
  .navbar form.d-flex .input-group { width: 100% !important; }
}

/* ═══════════════════════════════════════════════════════════════════
   11. MODULO CASA — stili specifici
═══════════════════════════════════════════════════════════════════ */

/* Card sub-modulo nella dashboard Casa */
.casa-modulo-card {
  transition: transform .15s ease, box-shadow .15s ease;
  cursor: pointer;
}
.casa-modulo-card:hover {
  transform: translateY(-3px);
  box-shadow: 0 .5rem 1.25rem rgba(0,0,0,.13) !important;
}

/* Icona colorata nella dashboard Casa */
.casa-icon {
  width: 42px; height: 42px;
  border-radius: 11px;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.15rem;
  flex-shrink: 0;
}

/* Dashboard Casa: card non traboccano su mobile */
.casa-modulo-card .card-body {
  overflow: hidden;
}
.casa-modulo-card .fw-semibold {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.casa-modulo-card .small.text-muted {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
@media (max-width: 576px) {
  .casa-icon {
    width: 32px; height: 32px;
    font-size: .95rem;
    border-radius: 8px;
  }
  .casa-modulo-card .card-body {
    padding: .6rem !important;
  }
  .casa-modulo-card .fs-5 {
    font-size: 1.1rem !important;
  }
}

/* Semaforo bollette / manutenzioni in riga tabella */
.scad-cell-danger  { color: #dc3545; font-weight: 600; }
.scad-cell-warning { color: #856404; font-weight: 600; }
.scad-cell-ok      { color: #198754; }

/* Note promemoria — card colorate */
.nota-card {
  transition: transform .12s ease, box-shadow .12s ease;
}
.nota-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 .4rem 1rem rgba(0,0,0,.15) !important;
}

/* Lista spesa — checkbox stile custom */
.item-check:checked {
  background-color: #20c997;
  border-color: #20c997;
}

/* Barra progress verde Casa */
.progress-bar.bg-casa {
  background-color: #40916c !important;
}

/* Tabella Casa — stile compatto */
.table-casa thead th {
  font-size: .78rem;
  text-transform: uppercase;
  letter-spacing: .03em;
}
.table-casa tbody td {
  vertical-align: middle;
  font-size: .875rem;
}

/* Btn xs utility (usato in tutto il modulo Casa) */
.btn-xs {
  padding: .15rem .4rem;
  font-size: .75rem;
  line-height: 1.4;
}

/* Veicoli — badge targa */
.targa-badge {
  font-family: monospace;
  letter-spacing: 2px;
  font-size: .8rem;
  background: #212529;
  color: #fff;
  padding: 2px 8px;
  border-radius: 4px;
}

/* Contatti — stelle rating */
.star-rating .star-on  { color: #ffc107; }
.star-rating .star-off { color: #dee2e6; }

/* Dashboard Casa — sezione alerts */
.casa-alert-row {
  border-left: 4px solid transparent;
  transition: background .1s;
}
.casa-alert-row:hover { background: rgba(0,0,0,.02); }

/* ═══════════════════════════════════════════════════════════════════
   12. LIBRERIA LIBRI
═══════════════════════════════════════════════════════════════════ */

/* Card libro nella griglia */
.libro-card {
  border-radius: 10px;
  overflow: hidden;
  transition: transform .18s ease, box-shadow .18s ease;
  cursor: default;
}
.libro-card:hover {
  transform: translateY(-4px);
  box-shadow: 0 8px 24px rgba(111,66,193,.18) !important;
}

/* Immagine copertina nella griglia */
.libro-copertina-thumb {
  width: 100%;
  height: 200px;
  object-fit: cover;
  object-position: top center;
  display: block;
  border-bottom: 1px solid #ede9fe;
}

/* Placeholder quando non c'è immagine */
.libro-copertina-placeholder {
  width: 100%;
  height: 200px;
  background: linear-gradient(160deg, #f5f3ff 0%, #ede9fe 100%);
  border-bottom: 1px solid #ddd6fe;
}

/* Titolo nella card — massimo 2 righe poi tronca */
.libro-titolo-card {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  line-height: 1.3;
}

/* Immagine grande nella pagina dettaglio */
.libro-img-grande {
  width: 100%;
  max-height: 420px;
  object-fit: contain;
  background: #f8f9fa;
  border-radius: 8px;
}

/* Placeholder immagine grande */
.libro-img-placeholder {
  width: 100%;
  height: 300px;
  background: linear-gradient(160deg, #f5f3ff 0%, #ede9fe 100%);
}

/* Stelline interattive nella scheda dettaglio */
.stelle-interattive .bi {
  transition: transform .1s ease;
}
.stelle-interattive .bi:hover {
  transform: scale(1.25);
}

/* ═══════════════════════════════════════════════════════════════════
   13. RICERCA GLOBALE
═══════════════════════════════════════════════════════════════════ */

/* Input ricerca nella navbar Casa */
.navbar-search-input::placeholder {
  color: rgba(255,255,255,.55) !important;
}
.navbar-search-input:focus {
  background: rgba(255,255,255,.25) !important;
  box-shadow: none !important;
  color: #fff !important;
  outline: none;
}

/* ═══════════════════════════════════════════════════════════════════
   14. STICKY — breadcrumb e intestazione tabelle durante lo scroll
═══════════════════════════════════════════════════════════════════ */

:root {
  --navbar-h: 60px;     /* fallback — JS sovrascrive con il valore reale misurato */
  --breadcrumb-h: 36px; /* fallback — JS sovrascrive con il valore reale misurato */
  --sticky-table-top: calc(var(--navbar-h) + var(--breadcrumb-h));
}

/* Breadcrumb fisso sotto la navbar */
nav.breadcrumb-sticky {
  position: sticky;
  top: var(--navbar-h);
  z-index: 10;
  background: var(--ml-body-bg, #f8f9fa);
  padding: 4px 0 6px;
  margin-bottom: 4px;
}

/* Sostituto di .table-responsive che non rompe position:sticky */
.table-hscroll {
  overflow-x: auto;
  /* nessun overflow-y: il thead sticky funziona rispetto alla pagina */
}

/* Barra filtri sticky — usata nei moduli con form di ricerca sopra la tabella */
.sticky-toolbar {
  position: sticky;
  top: var(--sticky-table-top);
  z-index: 9;
  background: var(--ml-body-bg, #f8f9fa);
  padding-bottom: 4px;
}

/* thead: scorre normalmente — sticky thead non è compatibile con overflow-x:auto */

/* ═══════════════════════════════════════════════════════════════════
   15. STAMPA / @media print
═══════════════════════════════════════════════════════════════════ */

@media print {
  /* Nascondi elementi UI non necessari in stampa */
  nav.navbar,
  footer.ml-footer,
  .flash-container,
  .btn, .btn-group,
  .dropdown,
  .navbar-toggler,
  .ambiente-switch,
  .no-print,
  #banner-backup,
  form.d-flex.me-2 {        /* barra ricerca navbar */
    display: none !important;
  }

  /* Sfondo bianco, testo nero */
  body {
    background: #fff !important;
    color: #000 !important;
    font-size: 11pt;
  }

  /* Container senza padding */
  .container-fluid {
    padding: 0 !important;
    margin: 0 !important;
    max-width: 100% !important;
  }

  /* Intestazione pagina (aggiunta automaticamente dal browser) */
  h1, h2, h3, h4, h5, h6 {
    color: #000 !important;
  }

  /* Card: niente ombra, bordo sottile */
  .card, .ml-card {
    border: 1px solid #ccc !important;
    box-shadow: none !important;
    break-inside: avoid;
  }

  /* Tabelle: bordi visibili */
  table { border-collapse: collapse !important; width: 100% !important; }
  th, td { border: 1px solid #ccc !important; padding: 4px 8px !important; }
  thead th { background: #eee !important; color: #000 !important; }

  /* Badge: solo testo con bordo */
  .badge {
    border: 1px solid #999 !important;
    color: #000 !important;
    background: #fff !important;
    print-color-adjust: exact;
    -webkit-print-color-adjust: exact;
  }

  /* Non spezzare le righe tabella tra pagine */
  tr { break-inside: avoid; }

  /* Copertina libro — stampa scheda dettaglio */
  .libro-img-grande {
    max-height: 220px !important;
    object-fit: contain !important;
  }
  .libro-img-placeholder { display: none !important; }

  /* Alert / card colored: sfondo bianco, bordo colorato */
  .alert { border: 1px solid #aaa !important; background: #fff !important; }

  /* Link: mostra URL tra parentesi */
  a[href]::after {
    content: none;   /* non mostrare URL — troppo rumore in schede interne */
  }

  /* Forza nuova pagina prima di sezioni principali (opzionale) */
  .print-page-break { page-break-before: always; }

  /* Pulsante stampa — nascosto in stampa (ovvio) */
  .btn-print { display: none !important; }
}

/* Pulsante stampa — visibile solo su schermo */
.btn-print {
  display: inline-flex;
  align-items: center;
  gap: .35rem;
}

/* ═══════════════════════════════════════════════════════════════════
   16. DARK MODE
═══════════════════════════════════════════════════════════════════ */

html[data-tema="scuro"] {
  --ml-body-bg:       #1a1a2e;
  --ml-card-border:   #2d2d44;
}

html[data-tema="scuro"] body {
  background-color: #1a1a2e;
  color: #e0e0e0;
}

html[data-tema="scuro"] .card,
html[data-tema="scuro"] .ml-card {
  background: #252540;
  border-color: #2d2d44;
  color: #e0e0e0;
}

html[data-tema="scuro"] .card-header {
  background: #2a2a45 !important;
  border-color: #3a3a55;
  color: #e0e0e0;
}

html[data-tema="scuro"] .card-body { color: #d0d0d0; }

html[data-tema="scuro"] .table { color: #d0d0d0; --bs-table-bg: transparent; }
html[data-tema="scuro"] .table-hover > tbody > tr:hover > * {
  --bs-table-hover-bg: rgba(255,255,255,.05);
  color: #e0e0e0;
}
html[data-tema="scuro"] .table-dark,
html[data-tema="scuro"] thead.table-dark { --bs-table-bg: #1e1e38; }
html[data-tema="scuro"] .table-light { --bs-table-bg: #2a2a45; color: #d0d0d0; }

html[data-tema="scuro"] .form-control,
html[data-tema="scuro"] .form-select {
  background-color: #2a2a45;
  border-color: #3a3a55;
  color: #e0e0e0;
}
html[data-tema="scuro"] .form-control:focus,
html[data-tema="scuro"] .form-select:focus {
  background-color: #303050;
  border-color: #0d6efd;
  color: #fff;
}
html[data-tema="scuro"] .form-control:disabled,
html[data-tema="scuro"] .form-control[readonly] {
  background-color: #1e1e38;
  color: #888;
}
html[data-tema="scuro"] .form-control::placeholder,
html[data-tema="scuro"] .form-select::placeholder,
html[data-tema="scuro"] textarea::placeholder {
  color: #8888aa;
  opacity: 1;
}
html[data-tema="scuro"] .form-check-input {
  background-color: #2a2a45;
  border-color: #3a3a55;
}
html[data-tema="scuro"] .form-check-input:checked {
  background-color: #0d6efd;
  border-color: #0d6efd;
}
html[data-tema="scuro"] .input-group-text {
  background-color: #1e1e38;
  border-color: #3a3a55;
  color: #aaa;
}
html[data-tema="scuro"] .list-group-item {
  background-color: #252540;
  border-color: #3a3a55;
  color: #d0d0d0;
}
html[data-tema="scuro"] .badge.bg-light {
  background-color: #2a2a45 !important;
  color: #d0d0d0 !important;
}
html[data-tema="scuro"] .accordion-item {
  background-color: #252540;
  border-color: #3a3a55;
}
html[data-tema="scuro"] .accordion-button {
  background-color: #2a2a45;
  color: #d0d0d0;
}
html[data-tema="scuro"] .accordion-button:not(.collapsed) {
  background-color: #303050;
  color: #e0e0e0;
}
html[data-tema="scuro"] .accordion-body {
  background-color: #252540;
  color: #d0d0d0;
}
html[data-tema="scuro"] .offcanvas {
  background-color: #252540;
  color: #e0e0e0;
}
html[data-tema="scuro"] .offcanvas-header {
  border-color: #3a3a55;
}
html[data-tema="scuro"] .toast {
  background-color: #252540;
  border-color: #3a3a55;
  color: #d0d0d0;
}

html[data-tema="scuro"] .modal-content {
  background: #252540;
  color: #e0e0e0;
  border-color: #3a3a55;
}
html[data-tema="scuro"] .modal-header { border-color: #3a3a55; }
html[data-tema="scuro"] .modal-footer { border-color: #3a3a55; }

html[data-tema="scuro"] .breadcrumb { --bs-breadcrumb-divider-color: #666; }
html[data-tema="scuro"] .breadcrumb-item a { color: #7aabff; }
html[data-tema="scuro"] .breadcrumb-item.active { color: #999; }

html[data-tema="scuro"] .text-muted { color: #888 !important; }
html[data-tema="scuro"] .text-dark { color: #d0d0d0 !important; }
html[data-tema="scuro"] .bg-white { background-color: #252540 !important; }
html[data-tema="scuro"] .bg-light { background-color: #1e1e38 !important; }
html[data-tema="scuro"] .border { border-color: #3a3a55 !important; }
html[data-tema="scuro"] .border-top { border-color: #3a3a55 !important; }
html[data-tema="scuro"] .border-bottom { border-color: #3a3a55 !important; }

html[data-tema="scuro"] .alert-success { background: #1a3a2a; color: #7cc89e; border-color: #2a5a3a; }
html[data-tema="scuro"] .alert-danger  { background: #3a1a1a; color: #e88; border-color: #5a2a2a; }
html[data-tema="scuro"] .alert-warning { background: #3a3a1a; color: #dd8; border-color: #5a5a2a; }
html[data-tema="scuro"] .alert-info    { background: #1a2a3a; color: #8ad; border-color: #2a4a5a; }

html[data-tema="scuro"] .btn-outline-secondary {
  color: #aaa;
  border-color: #555;
}
html[data-tema="scuro"] .btn-outline-secondary:hover {
  background: #3a3a55;
  color: #fff;
}

html[data-tema="scuro"] .dropdown-menu {
  background: #252540;
  border-color: #3a3a55;
}
html[data-tema="scuro"] .dropdown-item { color: #d0d0d0; }
html[data-tema="scuro"] .dropdown-item:hover { background: #2a2a45; color: #fff; }
html[data-tema="scuro"] .dropdown-divider { border-color: #3a3a55; }

html[data-tema="scuro"] nav.breadcrumb-sticky {
  background: #1a1a2e;
}
html[data-tema="scuro"] .sticky-toolbar {
  background: #1a1a2e;
}

html[data-tema="scuro"] .ml-footer {
  color: #555;
  border-color: #2d2d44;
}

html[data-tema="scuro"] .portale-benvenuto h2 { color: #e0e0e0; }
html[data-tema="scuro"] .portale-benvenuto p { color: #999; }

html[data-tema="scuro"] ::-webkit-scrollbar-track { background: #1e1e38; }
html[data-tema="scuro"] ::-webkit-scrollbar-thumb { background: #3a3a55; }
html[data-tema="scuro"] ::-webkit-scrollbar-thumb:hover { background: #555; }

html[data-tema="scuro"] .progress { background-color: #2a2a45; }

html[data-tema="scuro"] h1, html[data-tema="scuro"] h2,
html[data-tema="scuro"] h3, html[data-tema="scuro"] h4,
html[data-tema="scuro"] h5, html[data-tema="scuro"] h6 { color: #e0e0e0; }

html[data-tema="scuro"] a:not(.btn):not(.nav-link):not(.dropdown-item):not(.portale-card):not(.list-group-item) {
  color: #7aabff;
}

/* ═══════════════════════════════════════════════════════════════════
   17. PROFILO — selettore tema
═══════════════════════════════════════════════════════════════════ */

.tema-option {
  display: flex;
  flex-direction: column;
  align-items: center;
  cursor: pointer;
  padding: 8px;
  border: 2px solid transparent;
  border-radius: 12px;
  transition: all .2s;
}
.tema-option:hover { background: rgba(0,0,0,.04); }
.tema-option.active {
  border-color: #0d6efd;
  background: rgba(13,110,253,.06);
}

html[data-tema="scuro"] .tema-option:hover { background: rgba(255,255,255,.06); }
html[data-tema="scuro"] .tema-option.active { background: rgba(13,110,253,.15); }

.tema-preview {
  width: 100px;
  height: 70px;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid #dee2e6;
}
.tema-preview-chiaro { background: #f8f9fa; }
.tema-preview-chiaro .tema-preview-nav { height: 14px; background: #1a1a2e; }
.tema-preview-chiaro .tema-preview-body { padding: 6px; display: flex; gap: 4px; }
.tema-preview-chiaro .tema-preview-card {
  flex: 1; height: 36px; background: #fff;
  border: 1px solid #dee2e6; border-radius: 4px;
}

.tema-preview-scuro { background: #1a1a2e; border-color: #333; }
.tema-preview-scuro .tema-preview-nav { height: 14px; background: #0d0d1a; }
.tema-preview-scuro .tema-preview-body { padding: 6px; display: flex; gap: 4px; }
.tema-preview-scuro .tema-preview-card {
  flex: 1; height: 36px; background: #252540;
  border: 1px solid #2d2d44; border-radius: 4px;
}

/* ═══════════════════════════════════════════════════════════════════
   18. CAMPANELLA NOTIFICHE NAVBAR
═══════════════════════════════════════════════════════════════════ */

.notifiche-dropdown .dropdown-item:hover { background: rgba(13,110,253,.08); }
.notifiche-dropdown .dropdown-header { color: #6c757d; }
a[title="Notifiche"].dropdown-toggle::after { display: none; }

html[data-tema="scuro"] .notifiche-dropdown {
  background: #252540;
  border-color: #3a3a55;
}
html[data-tema="scuro"] .notifiche-dropdown .dropdown-header { color: #999; }
html[data-tema="scuro"] .notifiche-dropdown .dropdown-item { color: #d0d0d0; }
html[data-tema="scuro"] .notifiche-dropdown .dropdown-item:hover { background: rgba(255,255,255,.08); color: #fff; }
html[data-tema="scuro"] .notifiche-dropdown .dropdown-divider { border-color: #3a3a55; }

/* ═══════════════════════════════════════════════════════════════════
   19. MULTI-SELECT DROPDOWN (filtri con checkbox)
═══════════════════════════════════════════════════════════════════ */

.ms-dropdown { position: relative; width: 100%; }
.ms-btn {
  display: flex; align-items: center; justify-content: space-between;
  width: 100%; padding: 0.25rem 0.5rem; cursor: pointer;
  background: #fff; border: 1px solid #dee2e6;
  border-radius: 0.25rem; font-size: .8125rem; color: #212529;
  line-height: 1.5; gap: 4px; white-space: nowrap; overflow: hidden;
}
.ms-btn:hover { border-color: #adb5bd; background: #f8f9fa; }
.ms-btn .ms-lbl { flex: 1; overflow: hidden; text-overflow: ellipsis; }
.ms-btn .ms-caret { flex-shrink: 0; font-size: .65rem; opacity: .6; }
.ms-panel {
  position: absolute; top: calc(100% + 2px); left: 0; z-index: 1060;
  background: #fff; border: 1px solid #adb5bd; border-radius: 4px;
  box-shadow: 0 4px 18px rgba(0,0,0,.35); min-width: 210px; max-width: 340px;
  color: #212529;
}
.ms-search-row { padding: 6px 8px; border-bottom: 1px solid #e9ecef; }
.ms-search-row input {
  width: 100%; padding: 4px 8px; font-size: .8rem;
  border: 1px solid #dee2e6; border-radius: 3px; outline: none; color: #212529;
}
.ms-search-row input:focus { border-color: #86b7fe; }
.ms-items-wrap { max-height: 260px; overflow-y: auto; padding: 2px 0; }
.ms-item {
  display: flex; align-items: center; gap: 7px;
  padding: 4px 10px; cursor: pointer; font-size: .8125rem;
  user-select: none; margin: 0; color: #212529;
}
.ms-item:hover { background: #f0f4ff; }
.ms-item input[type="checkbox"] { flex-shrink: 0; cursor: pointer; width: 14px; height: 14px; }
.ms-item.ms-item-all {
  border-bottom: 1px solid #e9ecef;
  font-weight: 600; background: #f8f9fa;
}
.ms-item.ms-item-all:hover { background: #e8ecf8; }
.ms-footer {
  display: flex; gap: 6px; justify-content: flex-end;
  padding: 6px 8px; border-top: 1px solid #e9ecef; background: #f8f9fa;
  border-radius: 0 0 4px 4px;
}
.ms-footer .btn { font-size: .75rem; padding: 2px 12px; }
.ms-active .ms-btn { border-color: #0d6efd; background: #e7f1ff; color: #0a58ca; font-weight: 500; }
.color-pip { display: inline-block; width: 13px; height: 13px; border-radius: 2px; border: 1px solid #aaa; flex-shrink: 0; }

html[data-tema="scuro"] .ms-btn { background: #252540; border-color: #3a3a55; color: #d0d0d0; }
html[data-tema="scuro"] .ms-btn:hover { background: #2d2d50; border-color: #555; }
html[data-tema="scuro"] .ms-panel { background: #252540; border-color: #3a3a55; color: #d0d0d0; }
html[data-tema="scuro"] .ms-search-row { border-color: #3a3a55; }
html[data-tema="scuro"] .ms-search-row input { background: #1a1a2e; border-color: #3a3a55; color: #d0d0d0; }
html[data-tema="scuro"] .ms-item:hover { background: rgba(255,255,255,.08); }
html[data-tema="scuro"] .ms-item.ms-item-all { background: #2d2d50; }
html[data-tema="scuro"] .ms-item.ms-item-all:hover { background: #353560; }
html[data-tema="scuro"] .ms-footer { background: #2d2d50; border-color: #3a3a55; }
html[data-tema="scuro"] .ms-active .ms-btn { background: #1e2a4a; border-color: #3d7af5; color: #7db4ff; }

/* ═══════════════════════════════════════════════════════════════════
   20. FLATPICKR — Dark mode + stile coerente
═══════════════════════════════════════════════════════════════════ */

.flatpickr-input.form-control { background: #fff; }
html[data-tema="scuro"] .flatpickr-calendar {
  background: #252540; border-color: #3a3a55; box-shadow: 0 4px 18px rgba(0,0,0,.5);
}
html[data-tema="scuro"] .flatpickr-calendar .flatpickr-month,
html[data-tema="scuro"] .flatpickr-calendar .flatpickr-weekdays,
html[data-tema="scuro"] .flatpickr-calendar .flatpickr-weekday {
  background: #1a1a2e; color: #9a9ab0;
}
html[data-tema="scuro"] .flatpickr-calendar .flatpickr-day {
  color: #d0d0d0; border-radius: 4px;
}
html[data-tema="scuro"] .flatpickr-calendar .flatpickr-day:hover {
  background: #3a3a55; border-color: #3a3a55;
}
html[data-tema="scuro"] .flatpickr-calendar .flatpickr-day.selected {
  background: #0d6efd; border-color: #0d6efd; color: #fff;
}
html[data-tema="scuro"] .flatpickr-calendar .flatpickr-day.today {
  border-color: #0d6efd;
}
html[data-tema="scuro"] .flatpickr-calendar .flatpickr-day.prevMonthDay,
html[data-tema="scuro"] .flatpickr-calendar .flatpickr-day.nextMonthDay {
  color: #555;
}
html[data-tema="scuro"] .flatpickr-calendar .flatpickr-months .flatpickr-prev-month,
html[data-tema="scuro"] .flatpickr-calendar .flatpickr-months .flatpickr-next-month {
  fill: #9a9ab0; color: #9a9ab0;
}
html[data-tema="scuro"] .flatpickr-calendar .flatpickr-months .flatpickr-prev-month:hover,
html[data-tema="scuro"] .flatpickr-calendar .flatpickr-months .flatpickr-next-month:hover {
  fill: #fff; color: #fff;
}
html[data-tema="scuro"] .flatpickr-calendar .flatpickr-current-month input.cur-year,
html[data-tema="scuro"] .flatpickr-calendar .flatpickr-current-month .flatpickr-monthDropdown-months {
  background: #1a1a2e; color: #d0d0d0; border: 1px solid #3a3a55;
}
html[data-tema="scuro"] .flatpickr-calendar .flatpickr-monthDropdown-months option {
  background: #252540; color: #d0d0d0;
}
