/* =============================================================================
   1. TOKEN GRAFICI E RESET GLOBALE
   Variabili condivise, box model e stile base della pagina.
   ============================================================================= */
:root {
  --green: #185e20;
  --green-2: #2e7d32;
  --green-3: #e9f4ea;
  --ink: #152119;
  --muted: #6e766f;
  --border: #dde3de;
  --bg: #f5f7f5;
  --danger: #d62828;
  --shadow: 0 8px 28px rgba(21,50,27,.09);
}

* {
  box-sizing: border-box;
}

html {
  font-family: Inter,system-ui,sans-serif;
  color: var(--ink);
  background: var(--bg);
}

body {
  margin: 0;
}

/* =============================================================================
   2. HEADER E NAVIGAZIONE PRINCIPALE
   Brand, titolo e azioni globali della webapp.
   ============================================================================= */
.topbar {
  height: 90px;
  background: linear-gradient(120deg,#0f4e19,var(--green));
  color: #fff;
  display: flex;
  align-items: center;
  padding: 0 32px;
  gap: 36px;
  position: sticky;
  top: 0;
  z-index: 10;
  box-shadow: 0 2px 10px rgba(0,0,0,.15);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  color: #fff;
  text-decoration: none;
}

.brand-icon {
  font-size: 42px;
}

.brand span:last-child {
  display: flex;
  flex-direction: column;
  line-height: .95;
  font-size: 19px;
}

.topbar h1 {
  font-size: 24px;
  margin: 0;
  flex: 1;
}

.top-actions {
  display: flex;
  gap: 12px;
}

/* =============================================================================
   3. COMPONENTI CONDIVISI
   Pulsanti, card e controlli riutilizzati nelle diverse sezioni.
   ============================================================================= */
.btn {
  border: 1px solid transparent;
  border-radius: 7px;
  padding: 12px 18px;
  font: 600 14px Inter;
  cursor: pointer;
  transition: .18s;
}

.btn:hover {
  transform: translateY(-1px);
}

.btn-primary {
  background: linear-gradient(#247d31,#176322);
  color: #fff;
  border-color: #3b9247;
}

.btn-light {
  background: #fff;
  color: #1e2820;
  border-color: #e3e6e3;
}

.btn-ghost {
  background: #f7f8f7;
  border-color: var(--border);
  color: #465047;
}

.full {
  width: 100%;
}

/* =============================================================================
   4. LAYOUT, STATISTICHE, FILTRI E TABELLA
   Struttura desktop del contenuto principale.
   ============================================================================= */
.layout {
  max-width: 1500px;
  margin: 0 auto;
  padding: 28px;
  display: grid;
  grid-template-columns: minmax(0,1fr) 300px;
  gap: 24px;
}

.content {
  min-width: 0;
}

.section-label {
  text-transform: uppercase;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: .04em;
  margin-bottom: 10px;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(6,minmax(130px,1fr));
  gap: 12px;
  margin-bottom: 20px;
}

.stat-card {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px;
  min-height: 95px;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.stat-card strong {
  font-size: 22px;
}

.stat-card small {
  color: var(--muted);
}

.stat-title {
  font-size: 12px;
  font-weight: 700;
  margin-bottom: 8px;
}

.card {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 1px 2px rgba(0,0,0,.02);
}

.filters {
  display: grid;
  grid-template-columns: minmax(320px,1fr) 220px auto auto;
  gap: 12px;
  padding: 14px;
  align-items: center;
  margin-bottom: 16px;
}

.search-field {
  display: flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 0 12px;
  background: #fff;
}

.search-field input {
  border: 0;
  outline: 0;
  padding: 11px 0;
  width: 100%;
  font: inherit;
}

.filters select, .form-grid select, .form-grid input, .form-grid textarea, .modal-body > label input {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 11px;
  font: inherit;
  background: #fff;
}

.result-count {
  font-size: 13px;
  color: var(--muted);
  white-space: nowrap;
}

.table-card {
  overflow: hidden;
}

.table-wrap {
  overflow: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 1050px;
}

th, td {
  text-align: left;
  padding: 13px 14px;
  border-bottom: 1px solid #edf0ed;
  font-size: 13px;
}

th {
  font-size: 11px;
  text-transform: uppercase;
  color: #59615b;
  background: #fafbfa;
}

tbody tr:hover {
  background: #fafcfa;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 8px;
  border-radius: 5px;
  font-weight: 700;
  font-size: 11px;
}

.row-actions {
  display: flex;
  gap: 7px;
}

.icon-btn {
  border: 1px solid var(--border);
  background: #fff;
  border-radius: 6px;
  width: 32px;
  height: 32px;
  cursor: pointer;
}

.icon-btn.danger {
  color: var(--danger);
}

.table-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 13px 15px;
  font-size: 12px;
}

.table-footer select {
  padding: 6px;
  border: 1px solid var(--border);
  border-radius: 5px;
}

.pagination {
  display: flex;
  gap: 4px;
}

.page-btn {
  width: 30px;
  height: 30px;
  border: 1px solid var(--border);
  background: #fff;
  border-radius: 5px;
  cursor: pointer;
}

.page-btn.active {
  background: var(--green);
  color: #fff;
}

/* =============================================================================
   5. SIDEBAR, CATEGORIE E AZIONI RAPIDE
   Pannello laterale desktop e contenuti del menu mobile.
   ============================================================================= */
.sidebar {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.side-card {
  padding: 16px;
}

.side-card h2 {
  font-size: 16px;
  margin: 0;
}

.side-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}

.category-list {
  margin-top: 10px;
}

.category-item {
  display: grid;
  grid-template-columns: 10px 1fr auto auto;
  align-items: center;
  gap: 10px;
  padding: 12px 2px;
  border-bottom: 1px solid #edf0ed;
  font-size: 12px;
}

.dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
}

.count-pill {
  background: #f1f3f1;
  border-radius: 4px;
  padding: 3px 6px;
}

.toggle {
  width: 32px;
  height: 18px;
  border-radius: 999px;
  background: #ccc;
  position: relative;
  border: 0;
  cursor: pointer;
}

.toggle:after {
  content: "";
  position: absolute;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #fff;
  top: 2px;
  left: 2px;
  transition: .2s;
}

.toggle.on {
  background: var(--green-2);
}

.toggle.on:after {
  left: 16px;
}

.quick-action {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  border: 0;
  background: #fff;
  text-align: left;
  padding: 13px 4px;
  cursor: pointer;
  border-bottom: 1px solid #edf0ed;
}

.quick-action > span:first-child {
  font-size: 22px;
}

.quick-action span:last-child {
  display: flex;
  flex-direction: column;
}

.quick-action small {
  color: var(--muted);
  margin-top: 3px;
}

.file-action {
  cursor: pointer;
}

/* =============================================================================
   6. MODAL E FORM
   Finestre di dialogo per persone, categorie e cestino.
   ============================================================================= */
.modal {
  border: 0;
  border-radius: 12px;
  padding: 0;
  min-width: min(690px,calc(100vw - 24px));
  box-shadow: var(--shadow);
}

.modal-small {
  min-width: min(430px,calc(100vw - 24px));
}

.modal::backdrop {
  background: rgba(6,23,10,.48);
  backdrop-filter: blur(2px);
}

.modal-header {
  background: linear-gradient(120deg,#0f4e19,var(--green));
  color: #fff;
  padding: 17px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-header h2 {
  font-size: 17px;
  margin: 0;
}

.close-btn {
  border: 0;
  background: transparent;
  color: inherit;
  font-size: 25px;
  cursor: pointer;
}

.modal-body {
  padding: 22px;
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px;
}

.form-grid label, .modal-body > label {
  font-size: 12px;
  font-weight: 700;
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.form-grid textarea {
  min-height: 70px;
  resize: vertical;
}

.modal-footer {
  padding: 0 22px 22px;
  display: flex;
  justify-content: flex-end;
  gap: 12px;
}

.color-picker {
  border: 0;
  padding: 0;
  margin: 18px 0 0;
}

.color-picker legend {
  font-size: 12px;
  font-weight: 700;
  margin-bottom: 8px;
}

.color-picker label input {
  display: none;
}

.color-picker label span {
  display: inline-block;
  width: 25px;
  height: 25px;
  background: var(--c);
  border-radius: 50%;
  margin-right: 9px;
  border: 3px solid transparent;
  cursor: pointer;
}

.color-picker input:checked + span {
  outline: 2px solid var(--green);
  outline-offset: 2px;
}

.trash-item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  padding: 12px;
  border-bottom: 1px solid var(--border);
}

/* =============================================================================
   7. FEEDBACK E CONTROLLI MOBILE
   Notifiche temporanee e componenti usati dal menu responsive.
   ============================================================================= */
.toast {
  position: fixed;
  right: 24px;
  bottom: 24px;
  background: #172219;
  color: #fff;
  padding: 13px 18px;
  border-radius: 8px;
  opacity: 0;
  transform: translateY(10px);
  pointer-events: none;
  transition: .25s;
  z-index: 100;
}

.toast.show {
  opacity: 1;
  transform: none;
}

.mobile-menu {
  display: none;
}

.mobile-sidebar-header {
  display: none;
}

.mobile-sidebar-backdrop {
  display: none;
}

/* =============================================================================
   8. RESPONSIVE WEBAPP
   Trasforma la sidebar in pannello mobile e adatta griglie/toolbar.
   ============================================================================= */
@media (max-width: 1100px) {
  .stats-grid {
    grid-template-columns: repeat(3,1fr);
  }

  .layout {
    grid-template-columns: 1fr;
  }

  .mobile-menu {
    display: inline-block;
  }

  .filters {
    grid-template-columns: 1fr 1fr;
  }

  .result-count {
    grid-column: 1/2;
  }

  .topbar h1 {
    display: none;
  }

  .sidebar {
    display: flex;
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    width: min(390px,88vw);
    padding: 18px;
    background: var(--bg);
    z-index: 80;
    overflow-y: auto;
    box-shadow: -14px 0 40px rgba(0,0,0,.24);
    transform: translateX(110%);
    transition: transform .24s ease;
    visibility: hidden;
  }

  .sidebar.open {
    transform: translateX(0);
    visibility: visible;
  }

  .mobile-sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 2px 2px 12px;
    font-size: 18px;
  }

  .mobile-sidebar-header .icon-btn {
    font-size: 23px;
  }

  .mobile-sidebar-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.48);
    z-index: 70;
    opacity: 0;
    transition: opacity .24s ease;
  }

  .mobile-sidebar-backdrop.open {
    opacity: 1;
  }

  .mobile-sidebar-backdrop[hidden] {
    display: none !important;
  }

  body.menu-open {
    overflow: hidden;
  }
}

@media (max-width: 720px) {
  .topbar {
    height: auto;
    min-height: 76px;
    padding: 12px 16px;
    gap: 10px;
  }

  .brand span:last-child {
    font-size: 14px;
  }

  .brand-icon {
    font-size: 32px;
  }

  .top-actions {
    margin-left: auto;
  }

  .top-actions .btn:not(.btn-primary):not(.mobile-menu) {
    display: none;
  }

  .top-actions .btn {
    padding: 10px;
    font-size: 12px;
  }

  .layout {
    padding: 14px;
  }

  .stats-grid {
    grid-template-columns: repeat(2,1fr);
  }

  .filters {
    grid-template-columns: 1fr;
  }

  .result-count {
    grid-column: auto;
  }

  .form-grid {
    grid-template-columns: 1fr;
  }

  .table-footer {
    flex-wrap: wrap;
  }

  .modal-footer {
    justify-content: stretch;
  }

  .modal-footer .btn {
    flex: 1;
  }
}

/* =============================================================================
   9. STAMPA BASE
   Nasconde i comandi interattivi e compatta la tabella.
   ============================================================================= */
@media print {
  body {
    background: #fff;
  }

  .topbar {
    position: static;
    background: #fff;
    color: #000;
    border-bottom: 2px solid #000;
  }

  .top-actions, .sidebar, .filters, .row-actions, .table-footer, .section-label, .stats-grid {
    display: none !important;
  }

  .layout {
    display: block;
    max-width: none;
    padding: 0;
  }

  .card {
    border: 0;
    box-shadow: none;
  }

  table {
    min-width: 0;
  }

  th, td {
    padding: 8px;
    font-size: 10px;
  }

  .brand {
    color: #000;
  }

  .table-card {
    overflow: visible;
  }
}

/* =============================================================================
   10. LOGIN
   Layout desktop/mobile e stati di errore della schermata di accesso.
   ============================================================================= */

body.auth-locked {
  overflow: hidden;
}

.login-screen[hidden], .topbar[hidden], .layout[hidden] {
  display: none !important;
}

.login-screen {
  min-height: 100vh;
  padding: 28px;
  background: linear-gradient(135deg,#f7f4ec,#edf2ef);
  display: grid;
  place-items: center;
}

.login-shell {
  width: min(1240px,100%);
  min-height: 690px;
  display: grid;
  grid-template-columns: 1.35fr .85fr;
  background: #fff;
  border: 1px solid #d8dfda;
  border-radius: 22px;
  overflow: hidden;
  box-shadow: 0 22px 70px rgba(18,55,27,.15);
}

.login-visual {
  position: relative;
  padding: 72px 64px;
  color: #0d4520;
  background: linear-gradient(rgba(255,255,255,.14),rgba(255,255,255,.08)),linear-gradient(180deg,#f4ead9 0%,#fbd991 52%,#7a9b47 100%);
  overflow: hidden;
}

.login-brand-large {
  display: flex;
  align-items: center;
  gap: 22px;
  font-size: 48px;
  line-height: .95;
}

.login-brand-large > span:last-child {
  display: flex;
  flex-direction: column;
}

.login-tractor {
  font-size: 86px;
}

.login-visual h2 {
  font-size: 30px;
  margin: 28px 0 10px;
}

.login-visual > p {
  font-size: 18px;
  max-width: 420px;
  line-height: 1.6;
}

.login-scene {
  position: absolute;
  inset: auto 0 0;
  height: 48%;
  overflow: hidden;
}

.sun {
  position: absolute;
  width: 110px;
  height: 110px;
  border-radius: 50%;
  background: #fff7c4;
  left: 20%;
  top: 10%;
  box-shadow: 0 0 60px #fff5b6;
}

.field {
  position: absolute;
  left: -5%;
  width: 110%;
  border-radius: 50% 50% 0 0;
}

.field-back {
  height: 42%;
  bottom: 15%;
  background: #789746;
}

.field-front {
  height: 32%;
  bottom: -6%;
  background: #4d6f2d;
}

.tractor-art {
  position: absolute;
  right: 14%;
  bottom: 14%;
  font-size: 160px;
  z-index: 2;
  filter: drop-shadow(0 12px 12px rgba(0,0,0,.22));
}

.local-note {
  position: absolute;
  left: 48px;
  bottom: 48px;
  z-index: 3;
  display: flex;
  gap: 14px;
  max-width: 330px;
  padding: 16px 18px;
  border-radius: 10px;
  color: #fff;
  background: rgba(10,32,16,.78);
  font-size: 13px;
  line-height: 1.45;
}

.login-panel-wrap {
  padding: 72px 58px 28px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  background: #f7f8f7;
}

.login-card {
  background: #fff;
  border: 1px solid #dfe4e0;
  border-radius: 14px;
  padding: 34px;
  box-shadow: 0 14px 38px rgba(21,50,27,.12);
}

.login-card h1 {
  color: var(--green);
  font-size: 28px;
  margin: 0 0 8px;
}

.login-card > p {
  color: var(--muted);
  margin: 0 0 28px;
}

.login-card > label {
  display: flex;
  flex-direction: column;
  gap: 8px;
  font-size: 13px;
  font-weight: 700;
  margin-bottom: 18px;
}

.input-with-icon {
  display: flex;
  align-items: center;
  border: 1px solid #cfd7d1;
  border-radius: 7px;
  overflow: hidden;
}

.input-with-icon:focus-within {
  border-color: var(--green);
  box-shadow: 0 0 0 3px rgba(24,94,32,.1);
}

.input-with-icon input {
  width: 100%;
  border: 0;
  outline: 0;
  padding: 13px;
  font: inherit;
}

.input-with-icon > span, .password-toggle {
  width: 42px;
  border: 0;
  background: transparent;
  text-align: center;
}

.password-toggle {
  cursor: pointer;
  font-size: 17px;
}

.login-options {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 15px;
  font-size: 13px;
  margin: 4px 0 20px;
}

.login-options label {
  display: flex;
  gap: 8px;
  align-items: center;
}

.link-button {
  border: 0;
  background: transparent;
  color: var(--green);
  cursor: pointer;
}

.login-submit, .guest-button {
  width: 100%;
}

.guest-button {
  background: #fff;
  color: var(--green);
  border-color: var(--green);
  margin-top: 10px;
}

.login-divider {
  display: flex;
  align-items: center;
  gap: 12px;
  color: #777;
  font-size: 12px;
  margin: 18px 0;
}

.login-divider:before, .login-divider:after {
  content: "";
  height: 1px;
  background: #e0e4e1;
  flex: 1;
}

.login-error {
  display: none;
  color: #c92222;
  font-size: 12px;
  font-weight: 700;
  margin: -8px 0 16px;
}

.login-error.show {
  display: block;
}

.login-card input[aria-invalid="true"] {
  background: #fff5f5;
}

.demo-hint {
  display: block;
  text-align: center;
  margin-top: 12px;
  color: #666;
}

.login-footer {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin-top: 24px;
  color: #535d55;
  font-size: 12px;
}

.mobile-login-brand {
  display: none;
}

@media (max-width: 900px) {
  body.auth-locked {
    overflow: auto;
  }

  .login-screen {
    padding: 0;
    background: #f5f7f5;
  }

  .login-shell {
    min-height: 100vh;
    border: 0;
    border-radius: 0;
    display: block;
    background: #f5f7f5;
  }

  .login-visual {
    display: none;
  }

  .login-panel-wrap {
    min-height: 100vh;
    padding: 0 18px 24px;
    justify-content: flex-start;
  }

  .login-panel-wrap:before {
    content: "🚜 FESTA TRATTORI";
    display: block;
    margin: 0 -18px 28px;
    padding: 22px;
    color: #fff;
    background: linear-gradient(120deg,#0f4e19,var(--green));
    font-size: 20px;
    font-weight: 800;
    text-align: center;
  }

  .login-card {
    padding: 26px 22px;
  }

  .login-footer {
    margin-top: 26px;
  }

  .mobile-login-brand {
    display: none;
  }
}

/* =============================================================================
   11. GESTIONE CATEGORIE
   Modal elenco categorie, stato, conteggi e azioni.
   ============================================================================= */

.category-settings-modal {
  min-width: min(760px,calc(100vw - 24px));
}

.settings-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.settings-toolbar > div {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.settings-toolbar small {
  color: var(--muted);
  font-weight: 400;
}

.category-settings-list {
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
}

.category-setting-row {
  display: grid;
  grid-template-columns: 22px minmax(140px,1fr) 80px 90px 92px;
  align-items: center;
  gap: 12px;
  padding: 13px 14px;
  border-bottom: 1px solid #edf0ed;
}

.category-setting-row:last-child {
  border-bottom: 0;
}

.category-setting-row.inactive {
  background: #fafafa;
  color: #777;
}

.category-setting-color {
  width: 15px;
  height: 15px;
  border-radius: 50%;
  box-shadow: 0 0 0 3px rgba(0,0,0,.04);
}

.category-setting-name {
  font-weight: 700;
}

.category-setting-count {
  text-align: center;
  background: #f1f3f1;
  border-radius: 5px;
  padding: 5px 7px;
  font-size: 12px;
}

.category-setting-actions {
  display: flex;
  justify-content: flex-end;
  gap: 6px;
}

.category-setting-state {
  display: flex;
  justify-content: center;
}

@media (max-width: 620px) {
  .settings-toolbar {
    align-items: stretch;
    flex-direction: column;
  }

  .category-setting-row {
    grid-template-columns: 18px 1fr auto;
  }

  .category-setting-count {
    display: none;
  }

  .category-setting-state {
    grid-column: 2;
    justify-content: flex-start;
  }

  .category-setting-actions {
    grid-column: 3;
    grid-row: 1/3;
  }

  .category-settings-modal .modal-body {
    padding: 14px;
  }
}

/* =============================================================================
   12. TABELLA PERSONE
   Ordinamento colonne, testi lunghi e stati vuoti.
   ============================================================================= */

th.sortable {
  padding: 0;
}

.sort-button {
  width: 100%;
  min-height: 42px;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 7px;
  padding: 13px 14px;
  border: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  font-weight: 800;
  text-transform: uppercase;
  cursor: pointer;
}

.sort-button:hover, .sort-button:focus-visible {
  background: #eef5ef;
  color: var(--green);
  outline: 0;
}

th.is-sorted {
  background: #eef5ef;
  color: var(--green);
}

.sort-indicator {
  display: inline-flex;
  min-width: 12px;
  justify-content: center;
  font-size: 10px;
  color: #8b948d;
}

th.is-sorted .sort-indicator {
  color: var(--green);
}

.long-text-cell {
  min-width: 150px;
  max-width: 250px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  line-height: 1.4;
}

.empty-table {
  text-align: center !important;
  padding: 40px !important;
  color: #777;
}

.empty-message {
  padding: 18px;
  color: #777;
}

.form-span-2 {
  grid-column: 1/-1;
}

.category-item.category-disabled {
  opacity: .55;
}

.icon-btn:disabled {
  opacity: .35;
  cursor: not-allowed;
}

@media (max-width: 720px) {
  .form-span-2 {
    grid-column: auto;
  }

  .filters .btn {
    width: 100%;
  }
}

@media print {
  .sort-indicator {
    display: none;
  }

  .sort-button {
    padding: 8px 0;
    min-height: 0;
  }
}

/* =============================================================================
   13. COLORI CATEGORIA E STAMPA A COLORI
   Tinta della riga, bordo categoria e conservazione dei colori in stampa.
   ============================================================================= */

.category-colored-row > td {
  background-color: var(--category-row-tint);
  transition: background-color .16s ease;
}

.category-colored-row > td:first-child {
  border-left: 6px solid var(--category-color);
  padding-left: 10px;
}

.category-colored-row:hover > td {
  background-color: var(--category-row-hover);
}

@media print {
  html, body, table, thead, tbody, tr, th, td, .badge {
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }

  .category-colored-row > td {
    background-color: var(--category-row-tint) !important;
  }

  .category-colored-row > td:first-child {
    border-left: 6px solid var(--category-color) !important;
  }
}

/* =============================================================================
   14. FASE 0 BACKEND — STRUTTURA APPLICATIVA E STATI GLOBALI
   Nuove viste, permessi dinamici, caricamento e componenti amministrativi.
   ============================================================================= */
[hidden] {
  display: none !important;
}

button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
a:focus-visible {
  outline: 3px solid rgba(24, 94, 32, .25);
  outline-offset: 2px;
}

button:disabled,
.btn:disabled {
  cursor: not-allowed;
  opacity: .55;
  transform: none;
}

.btn-danger {
  background: #c62828;
  border-color: #a71919;
  color: #fff;
}

.btn-danger:hover {
  background: #a91d1d;
}

.btn-small {
  padding: 8px 10px;
  font-size: 12px;
}

.muted-text {
  color: var(--muted);
}

.global-loader {
  position: fixed;
  inset: 0;
  z-index: 500;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 14px;
  background: #f5f7f5;
  color: var(--green);
  font-weight: 700;
}

.spinner {
  width: 38px;
  height: 38px;
  border: 4px solid #dce8dd;
  border-top-color: var(--green);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.topbar-title {
  flex: 1;
  min-width: 0;
}

.topbar-title h1 {
  margin: 0;
  font-size: 22px;
}

.topbar-title small {
  display: block;
  margin-top: 3px;
  color: rgba(255, 255, 255, .75);
  font-size: 11px;
}

.app-layout {
  align-items: start;
}

.app-view {
  min-width: 0;
}

.view-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 22px;
}

.view-heading h2 {
  margin: 4px 0 7px;
  font-size: 28px;
}

.view-heading p {
  margin: 0;
  color: var(--muted);
}

.eyebrow {
  color: var(--green);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: .08em;
  text-transform: uppercase;
}

/* =============================================================================
   15. LOGIN E CAMBIO PASSWORD
   Stati di errore, caricamento e schermata obbligatoria.
   ============================================================================= */
.login-card > label {
  margin: 0 0 8px;
}

.login-card .input-with-icon {
  margin-bottom: 4px;
}

.login-help {
  margin: 18px 0 0 !important;
  text-align: center;
  font-size: 12px;
  line-height: 1.5;
}

.environment-badge {
  margin: 16px auto 0;
  width: fit-content;
  padding: 6px 9px;
  border: 1px dashed #c59022;
  border-radius: 6px;
  background: #fff8df;
  color: #73500e;
  font-size: 11px;
  font-weight: 700;
}

.form-error-banner {
  margin: 0 0 16px;
  padding: 11px 13px;
  border: 1px solid #efb4b4;
  border-radius: 7px;
  background: #fff1f1;
  color: #a51d1d;
  font-size: 12px;
  font-weight: 700;
  line-height: 1.45;
}

.field-error {
  display: block;
  min-height: 15px;
  color: #bd2020;
  font-size: 11px;
  line-height: 1.3;
}

.password-gate {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: linear-gradient(135deg, #edf4ee, #f7f3e9);
}

.password-card {
  width: min(510px, 100%);
  padding: 34px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: #fff;
  box-shadow: var(--shadow);
}

.password-card-icon {
  font-size: 42px;
}

.password-card h1 {
  margin: 12px 0 8px;
  color: var(--green);
  font-size: 27px;
}

.password-card > p {
  margin: 0 0 24px;
  color: var(--muted);
  line-height: 1.55;
}

.password-card > label,
.profile-form > label,
.modal-body > label {
  display: block;
  margin: 15px 0 7px;
  font-size: 12px;
  font-weight: 700;
}

.password-card > small,
.profile-form > small {
  display: block;
  margin-top: 6px;
  color: var(--muted);
  font-size: 11px;
}

.password-field {
  display: flex;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: #fff;
}

.password-field:focus-within {
  border-color: var(--green);
  box-shadow: 0 0 0 3px rgba(24, 94, 32, .1);
}

.password-field input {
  flex: 1;
  min-width: 0;
  padding: 11px;
  border: 0;
  outline: 0;
  font: inherit;
}

.password-field button {
  width: 44px;
  border: 0;
  background: transparent;
  cursor: pointer;
}

.password-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 24px;
}

/* =============================================================================
   16. NAVIGAZIONE LATERALE E ACCOUNT
   Voci nascoste/mostrate dal sistema centralizzato dei permessi.
   ============================================================================= */
.nav-card h2,
.admin-nav h2,
.account-card h2 {
  margin-bottom: 10px;
}

.side-nav {
  display: grid;
  gap: 5px;
  margin-top: 10px;
}

.side-nav button {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 10px 11px;
  border: 1px solid transparent;
  border-radius: 7px;
  background: transparent;
  color: #334137;
  text-align: left;
  font: 600 13px Inter, sans-serif;
  cursor: pointer;
}

.side-nav button:hover,
.side-nav button.active {
  border-color: #dbe7dc;
  background: #eef6ef;
  color: var(--green);
}

.side-nav button b {
  margin-left: auto;
  min-width: 22px;
  padding: 2px 6px;
  border-radius: 999px;
  background: #e5eae5;
  color: #59625b;
  text-align: center;
  font-size: 10px;
}

.side-nav .danger-nav {
  color: #a72121;
}

.side-nav .danger-nav:hover,
.side-nav .danger-nav.active {
  border-color: #f1c6c6;
  background: #fff1f1;
  color: #a72121;
}

.account-summary {
  display: flex;
  align-items: center;
  gap: 11px;
  padding-bottom: 13px;
  border-bottom: 1px solid var(--border);
}

.account-summary > span:last-child {
  display: flex;
  min-width: 0;
  flex-direction: column;
}

.account-summary strong,
.account-summary small {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.account-summary small {
  margin-top: 3px;
  color: var(--muted);
}

.account-avatar {
  display: grid;
  width: 42px;
  height: 42px;
  flex: 0 0 42px;
  place-items: center;
  border-radius: 50%;
  background: var(--green);
  color: #fff;
  font-weight: 800;
}

/* =============================================================================
   17. FORM E TABELLA PERSONE CON TELEFONO
   ============================================================================= */
.form-field {
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.form-field > label {
  font-size: 12px;
  font-weight: 700;
}

.form-field input,
.form-field select,
.form-field textarea,
.modal-body > input,
.modal-body > select {
  width: 100%;
  padding: 11px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: #fff;
  font: inherit;
}

.form-field input[aria-invalid="true"],
.form-field select[aria-invalid="true"] {
  border-color: #c62828;
  background: #fff8f8;
}

.checkbox-field {
  justify-content: center;
}

.checkbox-field label {
  display: flex;
  align-items: center;
  gap: 9px;
  min-height: 42px;
  font-weight: 600;
}

.checkbox-field input {
  width: auto;
}

.phone-link {
  color: var(--green);
  font-weight: 600;
  text-decoration: none;
  white-space: nowrap;
}

.phone-link:hover {
  text-decoration: underline;
}

.trash-actions {
  display: flex;
  align-items: center;
  gap: 7px;
}

.modal-intro {
  margin-top: 0;
  color: var(--muted);
  font-size: 13px;
}

/* =============================================================================
   18. PAGINE AMMINISTRATIVE
   Utenti, ruoli, riepiloghi, stato account e permessi.
   ============================================================================= */
.summary-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}

.summary-card {
  display: flex;
  align-items: center;
  gap: 13px;
  padding: 17px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #fff;
}

.summary-card > span {
  font-size: 26px;
}

.summary-card div {
  display: flex;
  flex-direction: column;
}

.summary-card strong {
  font-size: 23px;
}

.summary-card small {
  color: var(--muted);
}

.admin-table-card {
  overflow: hidden;
}

.admin-table {
  min-width: 980px;
}

.status-badge {
  display: inline-flex;
  padding: 5px 8px;
  border-radius: 999px;
  font-size: 10px;
  font-weight: 800;
  white-space: nowrap;
}

.status-badge.success {
  background: #e8f6ea;
  color: #267330;
}

.status-badge.warning {
  background: #fff4d7;
  color: #80560b;
}

.status-badge.muted {
  background: #ecefec;
  color: #687069;
}

.roles-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}

.role-card {
  padding: 20px;
}

.role-card.disabled {
  opacity: .68;
}

.role-card-header,
.role-card-header > div {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.role-card-header h3 {
  margin: 0;
}

.role-icon {
  font-size: 26px;
}

.role-card > p {
  min-height: 42px;
  color: var(--muted);
  line-height: 1.5;
}

.role-metrics {
  display: flex;
  gap: 18px;
  padding: 12px 0;
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  color: var(--muted);
  font-size: 12px;
}

.role-metrics strong {
  color: var(--ink);
}

.role-permission-preview {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  min-height: 70px;
  padding: 14px 0;
}

.role-permission-preview code {
  padding: 4px 6px;
  border-radius: 4px;
  background: #f0f3f0;
  color: #4e5b51;
  font-size: 10px;
}

.role-permission-preview small {
  color: var(--muted);
}

.role-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.system-role-label {
  margin-left: auto;
  color: var(--muted);
  font-size: 11px;
}

.role-modal {
  width: min(900px, calc(100vw - 24px));
}

.permissions-title {
  margin: 24px 0 10px;
  font-size: 15px;
}

.permissions-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.permission-group {
  min-width: 0;
  margin: 0;
  padding: 13px;
  border: 1px solid var(--border);
  border-radius: 9px;
}

.permission-group legend {
  padding: 0 7px;
  color: var(--green);
  font-size: 12px;
  font-weight: 800;
}

.permission-group label {
  display: flex;
  align-items: flex-start;
  gap: 9px;
  padding: 8px 4px;
  cursor: pointer;
}

.permission-group label + label {
  border-top: 1px solid #edf0ed;
}

.permission-group input {
  margin-top: 3px;
}

.permission-group span {
  display: flex;
  min-width: 0;
  flex-direction: column;
  gap: 3px;
}

.permission-group strong {
  font-size: 12px;
}

.permission-group code {
  overflow-wrap: anywhere;
  color: var(--muted);
  font-size: 10px;
}

/* =============================================================================
   19. BACKUP, PROFILO, RESET E STATI VUOTI
   ============================================================================= */
.admin-panels {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}

.admin-panel {
  display: flex;
  min-height: 280px;
  flex-direction: column;
  align-items: flex-start;
  padding: 26px;
}

.admin-panel-icon {
  font-size: 40px;
}

.admin-panel h3 {
  margin: 14px 0 8px;
  font-size: 21px;
}

.admin-panel p {
  flex: 1;
  margin: 0 0 20px;
  color: var(--muted);
  line-height: 1.55;
}

.admin-panel small {
  margin-top: 12px;
  color: var(--muted);
}

.file-button {
  display: inline-flex;
}

.profile-form {
  display: grid;
  width: min(600px, 100%);
  padding: 26px;
}

.profile-form > div:last-child {
  margin-top: 22px;
}

.danger-zone {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 22px;
  padding: 26px;
  border: 2px solid #d54141;
  background: #fff8f8;
}

.danger-zone-icon {
  font-size: 44px;
}

.danger-zone h3 {
  margin: 0 0 8px;
  color: #a51e1e;
  font-size: 23px;
}

.danger-zone p,
.danger-zone li {
  color: #704040;
  line-height: 1.5;
}

.danger-header {
  background: linear-gradient(120deg, #8f1616, #c62828);
}

.warning-box,
.info-box {
  margin: 15px 0;
  padding: 14px;
  border-radius: 8px;
  font-size: 12px;
  line-height: 1.5;
}

.warning-box {
  border: 1px solid #efb1b1;
  background: #fff2f2;
  color: #7b2929;
}

.info-box {
  border: 1px solid #b8d3ba;
  background: #f0f8f1;
  color: #315d35;
}

.restore-summary {
  display: grid;
  gap: 8px;
  margin: 17px 0;
}

.restore-summary > div {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  padding: 9px 0;
  border-bottom: 1px solid var(--border);
}

.reset-modal {
  width: min(720px, calc(100vw - 24px));
}

.reset-progress {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 4px;
  padding: 12px 20px 0;
  background: #fff;
}

.reset-progress span {
  height: 5px;
  border-radius: 999px;
  background: #e4e6e4;
}

.reset-progress span.active {
  background: #c62828;
}

.reset-steps section {
  min-height: 320px;
}

.reset-steps h3 {
  margin: 6px 0 10px;
  font-size: 22px;
}

.reset-steps p {
  color: var(--muted);
  line-height: 1.55;
}

.reset-step-icon {
  margin-bottom: 10px;
  font-size: 44px;
}

.preserved-data {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 22px;
}

.preserved-data strong {
  width: 100%;
}

.preserved-data span {
  padding: 7px 10px;
  border-radius: 999px;
  background: #eaf4eb;
  color: var(--green);
  font-size: 11px;
  font-weight: 700;
}

.choice-card {
  display: flex;
  align-items: flex-start;
  gap: 11px;
  margin: 10px 0;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: 9px;
  cursor: pointer;
}

.choice-card:has(input:checked) {
  border-color: var(--green);
  background: #f0f8f1;
}

.choice-card span {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.choice-card small {
  color: var(--muted);
}

.final-choice:has(input:checked) {
  border-color: #c62828;
  background: #fff3f3;
}

.confirmation-code {
  display: inline-block;
  margin: 6px 0 18px;
  padding: 10px 13px;
  border-radius: 7px;
  background: #232823;
  color: #fff;
  font-size: 14px;
  font-weight: 700;
  letter-spacing: .05em;
}

.reset-steps input:not([type="radio"]):not([type="checkbox"]) {
  width: 100%;
  padding: 11px;
  border: 1px solid var(--border);
  border-radius: 7px;
  font: inherit;
}

.empty-state {
  display: grid;
  min-height: 360px;
  place-items: center;
  align-content: center;
  gap: 10px;
  padding: 30px;
  text-align: center;
}

.empty-state > span {
  font-size: 48px;
}

.empty-state h2,
.empty-state p {
  margin: 0;
}

.empty-state p {
  color: var(--muted);
}

.empty-state.compact {
  min-height: 160px;
}

.empty-state.compact > span {
  font-size: 32px;
}

/* =============================================================================
   20. RESPONSIVE FASE 0
   ============================================================================= */
@media (max-width: 1100px) {
  .topbar-title h1 {
    display: block;
  }

  .topbar-title small {
    display: none;
  }

  .summary-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 820px) {
  .roles-grid,
  .admin-panels,
  .permissions-grid {
    grid-template-columns: 1fr;
  }

  .danger-zone {
    grid-template-columns: 1fr;
  }

  .danger-zone-icon {
    display: none;
  }

  .view-heading {
    flex-direction: column;
  }

  .view-heading .btn {
    width: 100%;
  }
}

@media (max-width: 720px) {
  .topbar-title {
    display: none;
  }

  .top-actions .btn-primary {
    max-width: 132px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .summary-grid {
    grid-template-columns: 1fr;
  }

  .password-card {
    padding: 25px 20px;
  }

  .password-actions {
    flex-direction: column-reverse;
  }

  .password-actions .btn {
    width: 100%;
  }

  .trash-item {
    grid-template-columns: 1fr;
  }

  .trash-actions {
    flex-wrap: wrap;
  }

  .trash-actions .btn {
    flex: 1;
  }

  .reset-footer {
    flex-wrap: wrap;
  }

  .reset-footer .btn {
    flex: 1 1 100%;
  }
}

/* =============================================================================
   21. STAMPA DEDICATA
   Tutti i risultati filtrati, telefono e colori delle categorie.
   ============================================================================= */
.print-sheet {
  display: none;
}

@media print {
  #appShell,
  #loginScreen,
  #passwordGate,
  dialog,
  .toast,
  .global-loader {
    display: none !important;
  }

  .print-sheet {
    display: block !important;
    color: #000;
    background: #fff;
  }

  .print-header {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 20px;
    margin-bottom: 18px;
    padding-bottom: 12px;
    border-bottom: 2px solid #000;
  }

  .print-header h1 {
    margin: 4px 0 0;
    font-size: 22px;
  }

  .print-header > div:last-child {
    display: flex;
    flex-direction: column;
    text-align: right;
    font-size: 10px;
  }

  .print-sheet table {
    width: 100%;
    min-width: 0;
    border-collapse: collapse;
  }

  .print-sheet th,
  .print-sheet td {
    padding: 6px 7px;
    border: 1px solid #d4d4d4;
    font-size: 9px;
    vertical-align: top;
  }

  .print-sheet th {
    background: #f0f0f0 !important;
  }

  .print-sheet .category-colored-row > td {
    background-color: var(--category-row-tint) !important;
  }

  .print-sheet .category-colored-row > td:first-child {
    border-left: 6px solid var(--category-color) !important;
  }

  .print-sheet,
  .print-sheet * {
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }
}
