/* =============================================================
   BulkApp — palette pastello lavanda/malva con accenti salvia.
   Ombre delicate, riquadri professionali.
   by Massimo Del Pizzo 2026
   ============================================================= */
:root {
  /* Base */
  --bg: #fbf9f5;
  --bg-soft: #f6efe5;
  --panel: #ffffff;
  --panel-alt: #fbf7f1;
  --border: #eee3d5;
  --border-strong: #e0d0bc;

  /* Testo */
  --text: #2e2a26;
  --text-soft: #5a4f43;
  --muted: #96897a;
  --muted-strong: #726555;

  /* Primario (arancione-rosso come il marchio BULK) */
  --primary: #d85a20;
  --primary-hover: #ad4110;
  --primary-soft: #f8dccb;
  --primary-text: #6f2808;

  /* Accenti pastello */
  --success: #9ec9b5;
  --success-soft: #e3f2ea;
  --success-text: #3d7257;
  --warning: #e9c79a;
  --warning-soft: #f9efdf;
  --warning-text: #875d2c;
  --danger: #e5a3a3;
  --danger-soft: #f8e4e4;
  --danger-text: #8e3e3e;
  --info: #a7cfd9;
  --info-soft: #e4f2f5;
  --info-text: #3c6a75;
  --accent: #ffcf9b; /* pesca chiaro */
  --accent-soft: #fff0de;

  /* Ombre delicate */
  --shadow-xs: 0 1px 2px rgba(140, 80, 20, 0.04);
  --shadow-sm:
    0 1px 3px rgba(140, 80, 20, 0.06), 0 1px 2px rgba(140, 80, 20, 0.04);
  --shadow:
    0 4px 10px rgba(140, 80, 20, 0.06), 0 1px 3px rgba(140, 80, 20, 0.04);
  --shadow-md:
    0 8px 24px rgba(140, 80, 20, 0.08), 0 2px 6px rgba(140, 80, 20, 0.05);
  --shadow-lg:
    0 16px 40px rgba(140, 80, 20, 0.14), 0 4px 12px rgba(140, 80, 20, 0.06);

  --radius: 10px;
  --radius-sm: 7px;
  --radius-lg: 14px;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  font-family:
    -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto,
    Helvetica, Arial, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

a {
  color: var(--primary-text);
  text-decoration: none;
}
a:hover {
  color: var(--primary-hover);
  text-decoration: underline;
}

h1 {
  font-size: 24px;
  margin: 0 0 4px 0;
  font-weight: 700;
  letter-spacing: -0.2px;
}
h2 {
  font-size: 18px;
  margin: 0;
  font-weight: 600;
}

/* --- Topbar -------------------------------------------------- */
header.topbar {
  display: flex;
  align-items: center;
  gap: 28px;
  padding: 10px 28px;
  background: #ffffff;
  color: var(--text);
  border-bottom: 1px solid var(--border);
  box-shadow: 0 2px 10px rgba(140, 80, 20, 0.06);
  position: sticky;
  top: 0;
  z-index: 10;
}
header.topbar .brand {
  display: flex;
  align-items: center;
  gap: 8px;
  line-height: 0;
  padding: 2px 0;
}
header.topbar .brand img,
header.topbar .brand svg {
  height: 48px;
  width: auto;
  display: block;
}
header.topbar nav {
  display: flex;
  gap: 4px;
  flex: 1;
}
header.topbar nav a {
  color: var(--muted-strong);
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  font-weight: 500;
  font-size: 13.5px;
  transition:
    background 0.15s,
    color 0.15s;
}
header.topbar nav a:hover {
  background: var(--primary-soft);
  color: var(--primary-text);
  text-decoration: none;
}
header.topbar nav a.active {
  background: var(--primary-soft);
  color: var(--primary-text);
  font-weight: 600;
}
header.topbar .topbar-right {
  color: var(--muted);
  font-size: 12px;
}
header.topbar .topbar-right a {
  color: inherit;
}
header.topbar .topbar-right a:hover {
  color: var(--primary-text);
  text-decoration: underline;
}
header.topbar .topbar-user {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 8px;
}
header.topbar .pwd-btn {
  font-size: 12.5px;
  color: var(--muted-strong);
  padding: 7px 12px;
  border-radius: var(--radius-sm);
  text-decoration: none;
  font-weight: 500;
}
header.topbar .pwd-btn:hover {
  background: var(--primary-soft);
  color: var(--primary-text);
  text-decoration: none;
}
header.topbar .logout-btn {
  background: #fff;
  color: var(--text-soft);
  border: 1px solid var(--border-strong);
  padding: 7px 14px;
  font-size: 12.5px;
  font-weight: 500;
  border-radius: var(--radius-sm);
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
header.topbar .logout-btn .who {
  color: var(--primary-text);
  font-weight: 600;
  font-size: 12px;
}
header.topbar .logout-btn:hover {
  background: var(--primary-soft);
  border-color: var(--primary);
  color: var(--primary-text);
}

main {
  max-width: 1320px;
  margin: 0 auto;
  padding: 28px;
}

.page-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  margin-bottom: 20px;
  flex-wrap: wrap;
  gap: 16px;
}
.page-header.centered {
  justify-content: center;
  text-align: center;
}
.page-header .subtitle {
  color: var(--muted);
  font-size: 13px;
  margin-top: 2px;
}

/* --- Toolbar / Form -------------------------------------------- */
.toolbar {
  display: flex;
  gap: 10px;
  align-items: center;
  margin-bottom: 18px;
  flex-wrap: wrap;
  background: var(--panel);
  padding: 12px 14px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-xs);
}
.toolbar label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--muted-strong);
  font-weight: 500;
}

input[type="text"],
input[type="date"],
input[type="number"],
input[type="email"],
input[type="tel"],
input[type="time"],
select,
textarea {
  padding: 8px 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-family: inherit;
  background: #fff;
  color: var(--text);
  transition:
    border-color 0.12s,
    box-shadow 0.12s;
}
input[type="text"]:focus,
input[type="date"]:focus,
input[type="number"]:focus,
input[type="email"]:focus,
input[type="tel"]:focus,
input[type="time"]:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-soft);
}
input::placeholder,
textarea::placeholder {
  color: #b6afc9;
}

textarea {
  resize: vertical;
  min-height: 60px;
}

/* --- Bottoni (stile standard: salva / annulla) ------------------- */
button,
.btn {
  padding: 8px 18px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  font-size: 13.5px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition:
    background 0.12s,
    border-color 0.12s,
    color 0.12s,
    box-shadow 0.12s,
    transform 0.05s;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
button:active,
.btn:active {
  transform: translateY(0.5px);
}

.btn-salva,
button[type="submit"]:not(.secondary) {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
  box-shadow: var(--shadow-sm);
}
.btn-salva:hover,
button[type="submit"]:not(.secondary):hover {
  background: var(--primary-hover);
  border-color: var(--primary-hover);
}

.btn-annulla,
.secondary {
  background: #fff;
  color: var(--text-soft);
  border-color: var(--border-strong);
  box-shadow: none;
}
.btn-annulla:hover,
.secondary:hover {
  background: var(--bg-soft);
  color: var(--text);
  border-color: var(--primary);
}

.btn-elimina {
  background: #fff;
  color: var(--danger-text);
  border-color: var(--danger);
}
.btn-elimina:hover {
  background: var(--danger-soft);
  color: var(--danger-text);
  border-color: var(--danger-text);
}

.btn-icon {
  padding: 6px 10px;
  font-size: 12px;
}

.btn-new {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
  box-shadow: var(--shadow-sm);
  padding: 10px 18px;
  font-weight: 600;
}
.btn-new:hover {
  background: var(--primary-hover);
  border-color: var(--primary-hover);
}

.btn-stampa {
  background: #fff;
  color: var(--text-soft);
  border: 1px solid var(--border-strong);
  box-shadow: var(--shadow-sm);
  padding: 10px 18px;
  font-weight: 600;
}
.btn-stampa:hover {
  background: var(--warning-soft);
  border-color: var(--warning);
  color: var(--warning-text);
}

.header-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}
.header-actions a.btn-new,
.header-actions a.btn-stampa {
  text-decoration: none;
  display: inline-flex;
  align-items: center;
}
.header-actions a.btn-new:hover,
.header-actions a.btn-stampa:hover {
  text-decoration: none;
}

.form-panel {
  padding: 24px 24px 18px;
}
.form-panel .form-footer {
  margin-top: 22px;
  padding-top: 18px;
  border-top: 1px solid var(--border);
}

/* Sezione carte di credito dentro la modale di modifica contatto */
.cards-host {
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
}
.cards-host table.cards-table {
  background: #fff;
  border-radius: var(--radius-sm);
  overflow: hidden;
  border: 1px solid var(--border);
}
.cards-host .cards-footer {
  margin-top: 10px;
  text-align: right;
}
.card-inline-form {
  background: var(--primary-soft);
  border: 1px dashed var(--primary);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
}
.card-inline-form .form-footer {
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px solid var(--border-strong);
}

/* --- Panel / Table --------------------------------------------- */
.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
table th {
  background: var(--bg-soft);
  text-align: left;
  padding: 8px 12px;
  font-weight: 600;
  color: var(--muted-strong);
  border-bottom: 1px solid var(--border);
  text-transform: uppercase;
  font-size: 10.5px;
  letter-spacing: 0.6px;
  white-space: nowrap;
}
table td {
  padding: 6px 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
  line-height: 1.35;
}
table tbody tr {
  cursor: pointer;
  transition: background 0.08s;
}
table tbody tr:hover {
  background: var(--primary-soft);
}
table tbody tr:last-child td {
  border-bottom: none;
}

.actions-cell {
  text-align: right;
  white-space: nowrap;
  width: 1%;
}
.actions-cell button {
  padding: 3px 8px;
  font-size: 11.5px;
  margin-left: 4px;
}

/* --- Badge ----------------------------------------------------- */
.badge {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  background: var(--primary-soft);
  color: var(--primary-text);
}
.badge.publish {
  background: var(--success-soft);
  color: var(--success-text);
}
.badge.draft {
  background: var(--warning-soft);
  color: var(--warning-text);
}

/* --- Paginazione ----------------------------------------------- */
.pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  background: var(--panel-alt);
  border-top: 1px solid var(--border);
  font-size: 13px;
  color: var(--muted-strong);
}
.pagination .pages {
  display: flex;
  gap: 8px;
}
.pagination button {
  padding: 6px 14px;
  background: #fff;
  color: var(--text-soft);
  border-color: var(--border-strong);
  font-weight: 500;
  font-size: 12.5px;
}
.pagination button:hover:not(:disabled) {
  background: var(--primary-soft);
  border-color: var(--primary);
  color: var(--primary-text);
}
.pagination button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* --- Stat cards (dashboard) ------------------------------------ */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}
.stat-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 22px;
  box-shadow: var(--shadow-sm);
  transition:
    box-shadow 0.15s,
    transform 0.12s,
    border-color 0.15s;
  position: relative;
  overflow: hidden;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  text-decoration: none;
  color: inherit;
  cursor: pointer;
}
.stat-card:hover {
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
  border-color: var(--primary);
  text-decoration: none;
  color: inherit;
}
.stat-card-content {
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.stat-card-avatar {
  width: 54px;
  height: 54px;
  border-radius: 14px;
  background: var(--primary-soft);
  color: var(--primary-text);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  box-shadow: inset 0 0 0 1px rgba(140, 80, 20, 0.04);
  transition: transform 0.15s;
}
.stat-card:hover .stat-card-avatar {
  transform: scale(1.06) rotate(-3deg);
}
.stat-card-avatar svg {
  width: 28px;
  height: 28px;
  stroke-width: 1.8;
}
.stat-card::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: linear-gradient(90deg, var(--primary) 0%, var(--accent) 100%);
}
.stat-card .label {
  color: var(--muted-strong);
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  font-weight: 600;
  margin-bottom: 10px;
}
.stat-card .value {
  font-size: 30px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.4px;
  line-height: 1.1;
}

.stat-card.sage::before {
  background: linear-gradient(90deg, var(--success) 0%, var(--info) 100%);
}
.stat-card.peach::before {
  background: linear-gradient(90deg, var(--warning) 0%, var(--accent) 100%);
}
.stat-card.sky::before {
  background: linear-gradient(90deg, var(--info) 0%, var(--primary) 100%);
}
.stat-card.rose::before {
  background: linear-gradient(90deg, var(--danger) 0%, var(--accent) 100%);
}
.stat-card.sage .stat-card-avatar {
  background: var(--success-soft);
  color: var(--success-text);
}
.stat-card.peach .stat-card-avatar {
  background: var(--warning-soft);
  color: var(--warning-text);
}
.stat-card.sky .stat-card-avatar {
  background: var(--info-soft);
  color: var(--info-text);
}
.stat-card.rose .stat-card-avatar {
  background: var(--danger-soft);
  color: var(--danger-text);
}

/* --- Modal ----------------------------------------------------- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(48, 38, 22, 0.5);
  -webkit-backdrop-filter: blur(3px);
  backdrop-filter: blur(3px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s;
}
.modal-backdrop.show {
  opacity: 1;
  pointer-events: auto;
}
.modal {
  background: var(--panel);
  border-radius: var(--radius-lg);
  width: min(860px, 94vw);
  max-height: 90vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-lg);
  transform: translateY(8px) scale(0.985);
  transition: transform 0.22s cubic-bezier(0.2, 0.8, 0.2, 1);
}
.modal-backdrop.show .modal {
  transform: none;
}
.modal-header {
  padding: 18px 24px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: linear-gradient(
    135deg,
    var(--panel) 0%,
    var(--primary-soft) 180%
  );
}
.brand-link {
  display: flex;
  align-items: center;
  text-decoration: none;
}
.brand-link:hover {
  text-decoration: none;
}
.modal-header h2 {
  margin: 0;
  font-size: 17px;
  font-weight: 600;
  color: var(--text);
}
.modal-header h2 .credits-title-logo {
  height: 35px;            /* +10% rispetto a 32px */
  width: auto;
  display: block;
  margin: 0 auto;
}
/* Credits: logo centrato nella barra del titolo (pulsante chiudi sovrapposto a destra) */
.modal-header:has(.credits-title-logo) {
  justify-content: center;
  position: relative;
}
.modal-header:has(.credits-title-logo) h2 {
  flex: 1;
}
.modal-header:has(.credits-title-logo) button.close {
  position: absolute;
  right: 24px;
  top: 50%;
  transform: translateY(-50%);
}
.modal-header button.close {
  background: transparent;
  color: var(--muted);
  font-size: 22px;
  padding: 2px 10px;
  line-height: 1;
  border: none;
  font-weight: 400;
}
.modal-header button.close:hover {
  color: var(--text);
  background: var(--bg-soft);
}
.modal-body {
  padding: 22px 24px;
  overflow: auto;
}
.modal-footer {
  padding: 14px 22px;
  border-top: 1px solid var(--border);
  background: var(--panel-alt);
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  align-items: center;
}
.modal-footer .spacer {
  flex: 1;
}
.stampa-group {
  display: inline-flex;
  gap: 8px;
  align-items: center;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 12px 10px;
  margin: 0;
  background: var(--panel);
}
/* --- Ca.R.G.O.S. (invio Polizia di Stato) --- */
.cargos-group {
  display: block;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 12px 12px;
  margin: 14px 0 0;
  background: var(--panel);
}
.cargos-group > legend {
  padding: 0 6px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.4px;
  text-transform: uppercase;
  color: var(--muted, #666);
}
.cargos-status { font-size: 13px; margin: 4px 2px 10px; }
.cargos-status .cargos-ok { color: var(--ok-text, #137333); font-weight: 600; }
.cargos-status .cargos-no { color: var(--muted, #777); }
.cargos-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.cargos-out { margin-top: 10px; font-size: 13px; }
.cargos-out ul { margin: 4px 0 8px; padding-left: 18px; }
.cargos-out .err li { color: var(--danger, #b3261e); }
.cargos-out .warn li { color: var(--warning-text, #8a5a00); }
.cargos-out pre {
  background: #0f172a; color: #e2e8f0; border-radius: 6px;
  padding: 8px; overflow-x: auto; font-size: 11px; line-height: 1.5;
  white-space: pre; max-height: 160px;
}
.cargos-out .esito-ok { color: var(--ok-text, #137333); font-weight: 600; }
.cargos-out .esito-ko { color: var(--danger, #b3261e); font-weight: 600; }

.invio-massivo-scroll { max-height: 50vh; overflow-y: auto; border: 1px solid var(--border); border-radius: 6px; }
.invio-massivo table.mini { width: 100%; border-collapse: collapse; font-size: 13px; }
.invio-massivo table.mini th,
.invio-massivo table.mini td { padding: 5px 8px; border-bottom: 1px solid var(--border); text-align: left; }
.invio-massivo table.mini thead th { position: sticky; top: 0; background: var(--panel); z-index: 1; }

.modal:has(.credits-body) {
  width: auto;
  max-width: min(420px, 94vw);
}
.modal:has(.credits-body) .modal-body {
  padding: 14px 18px;
}
.stampa-group > legend {
  padding: 0 6px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.4px;
  text-transform: uppercase;
  color: var(--muted, #666);
}

/* Form-footer (stile standard Modifica Documento) */
.form-footer {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  align-items: center;
  padding: 16px 0 4px;
}

/* --- Form layout ----------------------------------------------- */
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 14px 18px;
}
.form-grid .full {
  grid-column: 1 / -1;
}
.field {
  display: flex;
  flex-direction: column;
  gap: 5px;
}
.field label {
  font-size: 11.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  color: var(--muted-strong);
}
.field input,
.field select,
.field textarea {
  width: 100%;
}
.field .hint {
  font-size: 11.5px;
  color: var(--muted);
}

.field-group-title {
  font-size: 11.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--primary-text);
  margin: 12px 0 6px;
  padding-bottom: 6px;
  border-bottom: 1px dashed var(--border-strong);
  grid-column: 1 / -1;
}
.field-group-title:first-child {
  margin-top: 0;
}

dl.fields {
  display: grid;
  grid-template-columns: 200px 1fr;
  gap: 10px 18px;
  margin: 0;
}
dl.fields dt {
  color: var(--muted-strong);
  font-weight: 600;
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  padding-top: 4px;
}
dl.fields dd {
  margin: 0;
  padding-top: 4px;
  color: var(--text);
  word-break: break-word;
}

.section-title {
  margin: 24px 0 10px 0;
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--primary-text);
  font-weight: 700;
  padding-top: 18px;
  border-top: 1px solid var(--border);
}

.empty {
  padding: 48px 20px;
  text-align: center;
  color: var(--muted);
  font-style: italic;
}

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

/* Utility classes (usate nei markup delle pagine) */
.welcome-panel {
  padding: 22px;
}
.welcome-panel h2 {
  font-size: 15px;
  color: var(--primary-text);
  margin-bottom: 8px;
}
.welcome-panel p {
  margin: 0;
}
.by-devsystems {
  font-size: 0.78em;
}
.dpm-brand {
  font-weight: 700;
  letter-spacing: 0.3px;
}
.welcome-centered { text-align: center; }
.welcome-centered h2 { font-size: 16px; margin-bottom: 6px; }
.welcome-centered p { font-size: 12.5px; }
.brand-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 18px;
  margin-top: 10px;
}
.dpm-logo {
  height: 30px;            /* stessa dimensione del logo DEV Systems */
  width: auto;
  cursor: pointer;
  transition: transform 0.15s ease;
}
.dpm-logo:hover { transform: scale(1.06); }
.devsystems-logo {
  display: block;
  height: 30px;
  width: auto;
}
.avvertenze-link {
  display: block;
  text-align: center;
  margin-top: 9px;
  font-size: 9px;
  color: var(--muted);
  text-decoration: none;
}
.avvertenze-link:hover {
  text-decoration: underline;
  color: var(--primary-text);
}
.wave-trigger {
  cursor: pointer;
  display: inline-block;
  transition: transform 0.15s ease;
  -webkit-user-select: none;
  user-select: none;
}
.wave-trigger:hover { transform: scale(1.18) rotate(-8deg); }
.wave-trigger:focus-visible { outline: 2px solid var(--primary-text); outline-offset: 2px; border-radius: 4px; }
.code-chip {
  background: var(--primary-soft);
  padding: 1px 6px;
  border-radius: 4px;
  color: var(--primary-text);
}
.filter-input {
  flex: 1;
  min-width: 260px;
}
.col-wide {
  width: 38%;
}

/* --- Toast / Notifications ------------------------------------- */
.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: var(--panel);
  border: 1px solid var(--border-strong);
  border-left: 4px solid var(--success);
  border-radius: var(--radius);
  padding: 12px 18px;
  box-shadow: var(--shadow-lg);
  font-size: 13.5px;
  color: var(--text);
  z-index: 200;
  opacity: 0;
  transform: translateY(10px);
  transition:
    opacity 0.2s,
    transform 0.2s;
}
.toast.show {
  opacity: 1;
  transform: none;
}
.toast.error {
  border-left-color: var(--danger);
}

/* --- Autocomplete --------------------------------------------- */
.autocomplete {
  position: relative;
}
.autocomplete-list {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: #fff;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  margin-top: 4px;
  box-shadow: var(--shadow-md);
  max-height: 240px;
  overflow-y: auto;
  z-index: 150;
  display: none;
}
.autocomplete-list.show {
  display: block;
}
.autocomplete-item {
  padding: 8px 12px;
  cursor: pointer;
  font-size: 13.5px;
  border-bottom: 1px solid var(--border);
}
.autocomplete-item:last-child {
  border-bottom: none;
}
.autocomplete-item:hover,
.autocomplete-item.active {
  background: var(--primary-soft);
  color: var(--primary-text);
}
.autocomplete .clear-btn {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  background: transparent;
  border: none;
  color: var(--muted);
  padding: 2px 6px;
  cursor: pointer;
}
.autocomplete .clear-btn:hover {
  color: var(--danger-text);
  background: transparent;
}

/* --- Responsive ----------------------------------------------- */
/* ===================================================================
   Visualizzazione per cellulare / tablet — tutte le maschere
   =================================================================== */
@media (max-width: 720px) {
  /* --- Barra superiore: brand + utente in alto, menu scorrevole sotto --- */
  header.topbar {
    flex-wrap: wrap;
    padding: 10px 14px;
    gap: 10px;
  }
  header.topbar .brand img,
  header.topbar .brand svg { height: 38px; }
  header.topbar nav {
    order: 3;
    width: 100%;
    flex: 1 0 100%;
    gap: 6px;
    overflow-x: auto;
    padding-bottom: 2px;
  }
  header.topbar nav a { flex: 0 0 auto; white-space: nowrap; padding: 8px 12px; }
  header.topbar .topbar-user { gap: 6px; }

  main { padding: 16px 12px; }
  h1 { font-size: 22px; }

  /* --- Intestazione pagina e pulsanti azione a tutta larghezza --- */
  .page-header { align-items: stretch; gap: 12px; margin-bottom: 16px; }
  .header-actions { width: 100%; display: flex; flex-wrap: wrap; gap: 8px; }
  .header-actions > * { flex: 1 1 auto; text-align: center; justify-content: center; }

  /* --- Toolbar filtri: in colonna, controlli a tutta larghezza --- */
  .toolbar { flex-direction: column; align-items: stretch; gap: 8px; padding: 10px; }
  .toolbar > * { width: 100%; }
  .toolbar label { justify-content: space-between; }
  .toolbar label input { flex: 1; }
  .toolbar .toggle-attivi { justify-content: flex-start; }

  /* --- Card statistiche / badge: due per riga --- */
  .stats-grid { grid-template-columns: repeat(2, 1fr); gap: 12px; margin-bottom: 18px; }
  .stat-card { padding: 14px; }

  /* --- Tabelle: scorrimento orizzontale dentro il pannello --- */
  .panel { overflow-x: auto; }
  .panel > table { width: auto; min-width: 100%; }
  .panel td { white-space: nowrap; }
  table { font-size: 12.5px; }
  table th, table td { padding: 9px 10px; }

  /* --- Dettagli (chiave/valore) in colonna singola --- */
  dl.fields { grid-template-columns: 1fr; gap: 2px 0; }
  dl.fields dt { padding-top: 10px; }

  /* --- Form a colonna singola --- */
  .form-grid { grid-template-columns: 1fr; }

  /* --- Modali quasi a tutto schermo --- */
  .modal { width: 96vw; max-height: 92vh; border-radius: 12px; }
  .modal-header { padding: 14px 16px; }
  .modal-body { padding: 16px; }
  .modal-footer { padding: 12px 16px; flex-wrap: wrap; gap: 8px; }
  .modal-footer .spacer { display: none; }
  .modal-footer > button,
  .modal-footer > a { flex: 1 1 auto; text-align: center; justify-content: center; }
  .modal-footer .stampa-group { flex: 1 1 100%; justify-content: center; }

  /* --- Strumenti Ca.R.G.O.S. / alias / esclusione --- */
  .cargos-actions { flex-direction: column; align-items: stretch; }
  .alias-tool { flex-wrap: wrap; }
  .alias-tool input, .alias-tool select { flex: 1 1 100%; }
  .invio-massivo-scroll { overflow-x: auto; }
}

/* Telefoni stretti: badge a piena larghezza */
@media (max-width: 400px) {
  .stats-grid { grid-template-columns: 1fr; }
}

/* ─── Banner avviso documenti mancanti (form contratti) ───────── */
.doc-warning {
  background: #fff3cd;
  border: 1px solid #ffe69c;
  border-left: 4px solid #f59e0b;
  border-radius: 8px;
  padding: 10px 14px;
  margin: 8px 0 12px;
  color: #5a3d00;
  font-size: 13px;
  line-height: 1.4;
}
.doc-warning.ok {
  background: #e6f4ea;
  border-color: #b7e1c4;
  border-left-color: #137333;
  color: #137333;
}
.alias-tool { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin: 4px 0 12px; }
.toggle-attivi { display: inline-flex; align-items: center; gap: 8px; white-space: nowrap; font-size: 13px; cursor: pointer; -webkit-user-select: none; user-select: none; }
.toggle-attivi input { position: absolute; opacity: 0; width: 0; height: 0; }
.toggle-attivi .switch {
  position: relative; width: 40px; height: 22px; border-radius: 22px; flex: 0 0 auto;
  background: var(--border-strong, #cbd5e1); transition: background .2s;
}
.toggle-attivi .switch::after {
  content: ''; position: absolute; top: 2px; left: 2px; width: 18px; height: 18px;
  background: #fff; border-radius: 50%; transition: transform .2s; box-shadow: 0 1px 2px rgba(0,0,0,.3);
}
.toggle-attivi input:checked + .switch { background: var(--ok-text, #137333); }
.toggle-attivi input:checked + .switch::after { transform: translateX(18px); }
.toggle-attivi input:focus-visible + .switch { outline: 2px solid var(--primary, #2563eb); outline-offset: 2px; }
.alias-tool select, .alias-tool input { padding: 7px 9px; }
.alias-tool input { flex: 1 1 160px; }
.alias-res { font-size: 13px; }
.doc-warning ul { list-style: disc; }
.doc-warning.hidden { display: none; }

.btn-inserisci-docs {
  margin-left: 6px;
  padding: 3px 10px;
  background: #fff;
  border: 1px solid #f59e0b;
  border-radius: 6px;
  color: #92400e;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
}
.btn-inserisci-docs:hover {
  background: #f59e0b;
  color: #fff;
}

/* ─── Banner con scaduti: bordo rosso più forte ───────────────── */
.doc-warning.has-scaduti {
  border-left-color: #dc2626;
  background: #fef2f2;
  color: #7f1d1d;
}

/* ─── Overlay modale per inserimento documenti (sopra il modal-backdrop) ─── */
.docs-overlay-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2000;          /* sopra .modal-backdrop (z-index ~1000) */
  padding: 16px;
}
.docs-overlay-modal {
  background: #fff;
  border-radius: 10px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.25);
  width: 100%;
  max-width: 520px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
}
.docs-overlay-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 18px;
  border-bottom: 1px solid #e5e7eb;
}
.docs-overlay-header h3 {
  margin: 0;
  font-size: 16px;
  color: #1a3a6e;
}
.docs-overlay-close {
  background: transparent;
  border: none;
  font-size: 24px;
  line-height: 1;
  cursor: pointer;
  color: #6b7280;
  padding: 0 4px;
}
.docs-overlay-close:hover { color: #1a3a6e; }
.docs-overlay-body {
  padding: 16px 18px;
  overflow-y: auto;
}
.docs-section + .docs-section { margin-top: 18px; padding-top: 14px; border-top: 1px dashed #e5e7eb; }
.docs-section h4 {
  margin: 0 0 10px 0;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: #1a3a6e;
}
.docs-row {
  display: grid;
  grid-template-columns: 130px 1fr;
  gap: 10px;
  align-items: center;
  margin-bottom: 8px;
}
.docs-row label { font-size: 13px; color: #4b5563; }
.docs-row input {
  padding: 7px 10px;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  font-size: 14px;
  font-family: inherit;
}
.docs-row input:focus {
  outline: none;
  border-color: #1a3a6e;
  box-shadow: 0 0 0 2px rgba(26, 58, 110, 0.15);
}
.docs-overlay-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 12px 18px;
  border-top: 1px solid #e5e7eb;
  background: #f9fafb;
  border-radius: 0 0 10px 10px;
}
.docs-overlay-footer .btn-primary {
  background: #1a3a6e;
  color: #fff;
  border: 1px solid #1a3a6e;
  padding: 8px 18px;
  border-radius: 6px;
  cursor: pointer;
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
}
.docs-overlay-footer .btn-primary:hover:not(:disabled) { background: #142e58; }
.docs-overlay-footer .btn-primary:disabled { opacity: 0.6; cursor: not-allowed; }
.docs-overlay-footer .btn-secondary {
  background: #fff;
  color: #4b5563;
  border: 1px solid #d1d5db;
  padding: 8px 16px;
  border-radius: 6px;
  cursor: pointer;
  font-family: inherit;
  font-size: 14px;
}
.docs-overlay-footer .btn-secondary:hover { background: #f3f4f6; }

/* Marcatore campi obbligatori per Ca.R.G.O.S. (asterisco rosso) */
.req-mark { color: #c0392b; font-weight: 700; cursor: help; }

/* Legenda colori riquadro (solo nei form con validazione Ca.R.G.O.S.):
   ORO = a riposo · ROSSO = obbligatorio · VERDE = mentre si inserisce (focus). */
.form-req .field > input,
.form-req .field > select,
.form-req .field > textarea,
.form-req .field > .autocomplete input[type="text"] {
  border-color: #d9b15a;  /* oro */
}
.form-req .field.req > input,
.form-req .field.req > select,
.form-req .field.req > textarea,
.form-req .field.req > .autocomplete input[type="text"] {
  border-color: #c0392b;  /* rosso: campo obbligatorio */
}
.form-req .field > input:focus,
.form-req .field > select:focus,
.form-req .field > textarea:focus,
.form-req .field > .autocomplete input[type="text"]:focus {
  border-color: #1e8e3e !important;  /* verde: mentre inserisci */
  box-shadow: 0 0 0 2px rgba(30, 142, 62, 0.20);
}

/* Nota campi obbligatori Ca.R.G.O.S. in cima al form */
.note-cargos {
  margin: 0 0 14px; padding: 9px 13px; border-radius: 8px; font-size: 13.5px;
  background: rgba(192, 57, 43, 0.06); border-left: 3px solid #c0392b; color: #333;
}

/* Campo data a 3 segmenti gg/mm/aaaa */
.date-seg {
  display: inline-flex; align-items: center; gap: 1px;
  border: 1px solid #cfd6e4; border-radius: 7px; padding: 0 8px;
  background: #fff; height: 40px; box-sizing: border-box;
}
.date-seg input { border: none; outline: none; background: transparent; text-align: center;
  font: inherit; padding: 4px 1px; color: inherit; }
.date-seg .ds-d, .date-seg .ds-m { width: 2.2em; }
.date-seg .ds-y { width: 3.4em; }
.date-seg .ds-sep { color: #9aa6bd; user-select: none; }
/* legenda colori anche per il campo data nei form con validazione */
.form-req .field > .date-seg { border-color: #d9b15a; }            /* oro a riposo */
.form-req .field.req > .date-seg { border-color: #c0392b; }         /* rosso se obbligatorio */
.form-req .field > .date-seg:focus-within {                         /* verde mentre inserisci */
  border-color: #1e8e3e; box-shadow: 0 0 0 2px rgba(30, 142, 62, 0.20);
}
/* focus del campo data: alone sul riquadro, non sui singoli segmenti */
.date-seg input:focus { box-shadow: none; border: none; }
.date-seg:focus-within { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }

/* Calendarietto e validazione del campo data a segmenti */
.date-seg { position: relative; }
.ds-calbtn { background: none; border: none; padding: 0 2px 0 5px; margin: 0; cursor: pointer;
  font-size: 15px; line-height: 1; }
.ds-calbtn:hover { filter: brightness(1.1); }
.ds-cal { position: absolute; right: 8px; bottom: 2px; width: 18px; height: 1px;
  opacity: 0; pointer-events: none; border: none; padding: 0; margin: 0; }
.date-seg.ds-invalid { border-color: #c0392b !important; box-shadow: 0 0 0 2px rgba(192, 57, 43, 0.18); }

/* Validazione di formato (CF, P.IVA, CAP, targa, email, tel): campo compilato ma malformato */
.fmt-msg { display: none; font-size: 11px; color: #c0392b; margin-top: 3px; }
.field.fmt-invalid > input { border-color: #c0392b !important; box-shadow: 0 0 0 2px rgba(192, 57, 43, 0.18); }
.field.fmt-invalid > .fmt-msg { display: block; }

/* Tutti i controlli dei form alla stessa altezza (40px) */
.field > input:not([type="checkbox"]):not([type="hidden"]),
.field > select,
.field > .date-seg,
.field > .autocomplete > input[type="text"] { height: 40px; }

/* ════════ Credits DPM Software House (portata da ios.Appuntamenti / nutridil.com) ════════ */
.crm-backdrop{ position:fixed; inset:0; background:rgba(20,20,30,.45); z-index:9999;
  display:flex; align-items:center; justify-content:center; }
.crm-backdrop[hidden]{ display:none; }
.crm-modal{ background:#fff; color:#222; border-radius:12px; box-shadow:0 20px 60px rgba(0,0,0,.25);
  width:auto; max-width:min(420px,94vw); display:flex; flex-direction:column; overflow:hidden;
  animation:crmPop .18s ease-out; }
@keyframes crmPop{ from{ transform:translateY(8px) scale(.98); opacity:0; } to{ transform:none; opacity:1; } }
.crm-header{ padding:12px 18px; border-bottom:1px solid #eee; display:flex; align-items:center; justify-content:space-between; }
.crm-title-logo{ height:42px; width:auto; }
.crm-close{ background:transparent; border:0; font-size:22px; line-height:1; color:#888; padding:0 4px; cursor:pointer; }
.crm-body{ display:flex; align-items:center; gap:18px; padding:16px 18px; }
.crm-photo{ width:120px; height:120px; object-fit:contain; border-radius:8px; flex:0 0 auto; }
.crm-text{ line-height:1.35; text-align:left; }
.crm-subtitle{ font-size:15px; color:#0f172a; }
.crm-author{ font-size:20px; font-weight:700; color:#0f172a; }
.crm-line{ font-size:14px; margin-top:4px; display:flex; align-items:center; gap:6px; color:#0f172a; }
.crm-line a{ color:#0f172a; text-decoration:none; }
.crm-muted{ font-size:13px; margin-top:4px; color:#888; }
.crm-foot{ padding:12px 18px; border-top:1px solid #eee; display:flex; justify-content:space-between; align-items:center; }
.crm-link{ color:#2a7de1; text-decoration:none; font-size:13px; font-style:italic; }
.crm-chiudi{ padding:8px 16px; border-radius:6px; border:1px solid #2a7de1; background:#2a7de1;
  font-size:13px; font-weight:600; color:#fff; cursor:pointer; }
