/* CRM Prestiton — stylesheet principale */

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
               "Helvetica Neue", Arial, sans-serif;
  font-size: 15px;
  line-height: 1.45;
  color: #1a2332;
  background: #f4f6fb;
  min-height: 100vh;
}

/* ── Colori ────────────────────────────────────────── */
:root {
  --c-primary:    #0b3d91;
  --c-primary-d:  #0a2f73;
  --c-accent:     #1f6feb;
  --c-bg:         #f4f6fb;
  --c-card:       #fff;
  --c-border:     #d8dde8;
  --c-muted:      #6b7280;
  --c-text:       #1a2332;

  --c-success:    #16a34a;
  --c-warning:    #eab308;
  --c-danger:     #dc2626;

  --c-ai-filled:  #e9fbf0;  /* verde chiaro campi AI */
  --c-ai-null:    #fffbcf;  /* giallo campi null */

  --radius:       6px;
  --shadow-sm:    0 1px 2px rgba(20,30,50,0.06);
  --shadow-md:    0 2px 8px rgba(20,30,50,0.08);
}

/* ── Header ────────────────────────────────────────── */
.app-header {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.4rem 0.65rem;
  background: var(--c-primary);
  color: white;
  box-shadow: var(--shadow-md);
  position: sticky;
  top: 0;
  z-index: 10;
  flex-wrap: nowrap;
  min-width: 0;
}
.app-header .logo {
  color: white;
  text-decoration: none;
  font-weight: 700;
  font-size: 1.15rem;
  letter-spacing: 0.5px;
}
.app-header .logo span { opacity: 0.85; font-weight: 400; }

.main-nav {
  display: flex;
  gap: 0.25rem;
  flex: 1;
  flex-wrap: wrap;
  row-gap: 0.3rem;
  min-width: 0;
  overflow: visible;
  align-items: center;
}
.main-nav a {
  color: rgba(255,255,255,0.85);
  text-decoration: none;
  padding: 0.25rem 0.45rem;
  border-radius: var(--radius);
  transition: background 0.15s;
  font-size: 0.88rem;
  white-space: nowrap;
}
.main-nav a:hover { background: rgba(255,255,255,0.12); color: white; }
.main-nav a.active { background: rgba(255,255,255,0.2); color: white; }
.main-nav a.disabled {
  opacity: 0.5;
  cursor: not-allowed;
  pointer-events: none;
}

.user-box {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-size: 0.9rem;
}
.user-box button {
  background: rgba(255,255,255,0.12);
  border: 1px solid rgba(255,255,255,0.25);
  color: white;
  padding: 0.3rem 0.75rem;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 0.85rem;
}
.user-box button:hover { background: rgba(255,255,255,0.2); }

/* ── View root ─────────────────────────────────────── */
.view-root {
  max-width: 1100px;
  margin: 1.5rem auto;
  padding: 0 1rem;
}
.view-root h1 {
  font-size: 1.4rem;
  font-weight: 600;
  margin: 0 0 1rem;
  color: var(--c-primary-d);
}
.view-root h2 {
  font-size: 1.1rem;
  font-weight: 600;
  margin: 1.5rem 0 0.75rem;
  color: var(--c-primary-d);
  padding-bottom: 0.25rem;
  border-bottom: 1px solid var(--c-border);
}

.loading {
  text-align: center;
  padding: 3rem;
  color: var(--c-muted);
}

.card {
  background: var(--c-card);
  border: 1px solid var(--c-border);
  border-radius: var(--radius);
  padding: 1.25rem;
  margin-bottom: 1rem;
  box-shadow: var(--shadow-sm);
}

/* ── Form ──────────────────────────────────────────── */
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 0.75rem 1rem;
}
.field { display: flex; flex-direction: column; gap: 0.25rem; }
.field label {
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--c-muted);
}
.field label .req { color: var(--c-danger); }

.field input, .field select, .field textarea {
  width: 100%;
  padding: 0.5rem 0.6rem;
  border: 1px solid var(--c-border);
  border-radius: var(--radius);
  font-size: 0.95rem;
  background: white;
  font-family: inherit;
  color: var(--c-text);
}
.field input:focus, .field select:focus, .field textarea:focus {
  outline: 2px solid var(--c-accent);
  outline-offset: -1px;
  border-color: var(--c-accent);
}

/* Stato campi auto-popolati da AI */
.field.ai-filled input, .field.ai-filled select, .field.ai-filled textarea {
  background: var(--c-ai-filled);
  border-color: var(--c-success);
}
.field.ai-null input, .field.ai-null select, .field.ai-null textarea {
  background: var(--c-ai-null);
  border-color: var(--c-warning);
}

/* Campo con errore */
.field.has-error input, .field.has-error select {
  border-color: var(--c-danger);
  background: #fff5f5;
}
.field .error-text {
  color: var(--c-danger);
  font-size: 0.8rem;
}

.field textarea { min-height: 80px; resize: vertical; }

.field-hint { font-size: 0.75rem; color: var(--c-muted); }

/* ── Bottoni ───────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.55rem 1rem;
  border: 1px solid transparent;
  border-radius: var(--radius);
  font-size: 0.95rem;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
  font-family: inherit;
  transition: all 0.15s;
  background: white;
  color: var(--c-text);
  border-color: var(--c-border);
}
.btn:hover { background: #f1f3f7; }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn-primary {
  background: var(--c-primary);
  color: white;
  border-color: var(--c-primary);
}
.btn-primary:hover { background: var(--c-primary-d); }
.btn-accent {
  background: var(--c-accent);
  color: white;
  border-color: var(--c-accent);
}
.btn-accent:hover { filter: brightness(0.92); }
.btn-danger {
  background: var(--c-danger);
  color: white;
  border-color: var(--c-danger);
}
.btn-ghost { background: transparent; border-color: transparent; }
.btn-lg { padding: 0.75rem 1.4rem; font-size: 1rem; }
.btn-sm { padding: 0.35rem 0.7rem; font-size: 0.85rem; }

.btn-row {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-top: 1rem;
}

/* ── Login ─────────────────────────────────────────── */
.login-wrap {
  max-width: 380px;
  margin: 6vh auto;
}
.login-wrap .card {
  padding: 2rem;
  text-align: center;
}
.login-wrap h1 {
  font-size: 1.5rem;
  color: var(--c-primary);
  margin-bottom: 0.25rem;
  text-align: center;
}
.login-wrap .subtitle {
  color: var(--c-muted);
  font-size: 0.9rem;
  margin-bottom: 1.5rem;
}
.login-wrap form { text-align: left; }

/* ── Pannelli AI input ─────────────────────────────── */
.ai-input-panel {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  margin-bottom: 1.5rem;
}
@media (max-width: 700px) {
  .ai-input-panel { grid-template-columns: 1fr; }
}

.voice-box, .screenshot-box {
  background: var(--c-card);
  border: 2px dashed var(--c-border);
  border-radius: var(--radius);
  padding: 1.25rem;
  text-align: center;
}
.voice-box h3, .screenshot-box h3 {
  margin: 0 0 0.5rem;
  color: var(--c-primary-d);
  font-size: 1rem;
  font-weight: 600;
}

.voice-status {
  font-size: 0.9rem;
  color: var(--c-muted);
  min-height: 1.3em;
  margin-top: 0.5rem;
}
.voice-status.recording { color: var(--c-danger); font-weight: 600; animation: pulse 1.2s infinite; }
.voice-status.processing { color: var(--c-accent); font-weight: 500; }
@keyframes pulse { 0%,100% {opacity:1} 50% {opacity:0.45} }

.voice-transcript {
  margin-top: 0.75rem;
  padding: 0.6rem;
  background: #f7f9fc;
  border: 1px solid var(--c-border);
  border-radius: var(--radius);
  min-height: 3em;
  font-size: 0.92rem;
  text-align: left;
  white-space: pre-wrap;
  max-height: 140px;
  overflow-y: auto;
}

.screenshot-preview img {
  max-width: 100%;
  max-height: 180px;
  margin: 0.5rem auto 0;
  display: block;
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}

.mic-icon {
  display: inline-block;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--c-primary);
  color: white;
  font-size: 1.5rem;
  line-height: 56px;
  margin-bottom: 0.5rem;
  border: none;
  cursor: pointer;
}
.mic-icon.recording { background: var(--c-danger); }

/* ── Toast ──────────────────────────────────────────── */
.toast-stack {
  position: fixed;
  bottom: 1rem;
  right: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  z-index: 100;
  pointer-events: none;
}
.toast {
  background: #222;
  color: white;
  padding: 0.75rem 1rem;
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  max-width: 380px;
  font-size: 0.9rem;
  animation: toast-in 0.2s ease-out;
  pointer-events: auto;
}
.toast.success { background: var(--c-success); }
.toast.warning { background: var(--c-warning); color: #1a2332; }
.toast.error   { background: var(--c-danger); }
@keyframes toast-in {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ── Utility ────────────────────────────────────────── */
.text-muted   { color: var(--c-muted); }
.text-center  { text-align: center; }
.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }
.mt-3 { margin-top: 1.5rem; }
.mb-1 { margin-bottom: 0.5rem; }
.mb-2 { margin-bottom: 1rem; }
.flex { display: flex; }
.flex-gap { display: flex; gap: 0.5rem; }
.flex-col { display: flex; flex-direction: column; }
.hidden { display: none !important; }

.badge {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 500;
  background: #e5e7eb;
  color: #374151;
}
.badge-success { background: #d1fae5; color: #065f46; }
.badge-warning { background: #fef3c7; color: #92400e; }
.badge-info    { background: #dbeafe; color: #1e40af; }

/* ── Wizard stepper ────────────────────────────────── */
.wizard-steps {
  display: flex;
  gap: 0.5rem;
  margin: 0 0 1.25rem;
  flex-wrap: wrap;
}
.wizard-step {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.5rem 0.75rem;
  border-radius: var(--radius);
  background: white;
  border: 1px solid var(--c-border);
  color: var(--c-muted);
  font-size: 0.85rem;
  min-width: 120px;
}
.wizard-step.active {
  background: var(--c-primary);
  color: white;
  border-color: var(--c-primary);
  font-weight: 600;
}
.wizard-step.done {
  background: var(--c-success);
  color: white;
  border-color: var(--c-success);
}
.wizard-num {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px; height: 24px;
  border-radius: 50%;
  background: rgba(0,0,0,0.12);
  font-weight: 700;
}
.wizard-step.active .wizard-num,
.wizard-step.done .wizard-num { background: rgba(255,255,255,0.2); }

/* ── Table compact ────────────────────────────────── */
.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--c-border);
  border-radius: var(--radius);
}
.table-compact {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}
.table-compact th, .table-compact td {
  padding: 0.4rem 0.6rem;
  border-bottom: 1px solid var(--c-border);
  text-align: left;
  white-space: nowrap;
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
}
.table-compact th {
  background: #eef2f7;
  font-weight: 600;
  position: sticky; top: 0;
}
.table-compact tr:last-child td { border-bottom: none; }
.table-compact tr:hover { background: #f7f9fc; }

/* ── Stats (import) ────────────────────────────────── */
.stats-row {
  display: flex;
  gap: 1rem;
  margin: 0.75rem 0 1.25rem;
  flex-wrap: wrap;
}
.stat {
  background: white;
  border: 1px solid var(--c-border);
  border-radius: var(--radius);
  padding: 0.75rem 1rem;
  min-width: 110px;
  text-align: center;
}
.stat-num { font-size: 1.8rem; font-weight: 700; color: var(--c-primary-d); line-height: 1; }
.stat-label { font-size: 0.8rem; color: var(--c-muted); margin-top: 0.25rem; }
.stat-ok { border-left: 4px solid var(--c-success); }
.stat-warn { border-left: 4px solid var(--c-warning); }
.stat-err { border-left: 4px solid var(--c-danger); }

/* ── Enum mapping display ──────────────────────────── */
.enum-map-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 1rem;
  margin-bottom: 1rem;
}
.enum-map-block {
  background: #f7f9fc;
  border: 1px solid var(--c-border);
  border-radius: var(--radius);
  padding: 0.75rem 1rem;
  font-size: 0.85rem;
}
.enum-map-block ul { margin: 0.4rem 0 0; padding-left: 1.25rem; }
.enum-map-block li { margin: 0.15rem 0; }
.enum-map-block code {
  background: white;
  padding: 0.05rem 0.35rem;
  border-radius: 3px;
  font-family: ui-monospace, monospace;
  font-size: 0.85em;
}

/* ── KPI banner ────────────────────────────────────── */
.kpi-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 0.75rem;
  margin-bottom: 1rem;
}
.kpi-card {
  background: white;
  border: 1px solid var(--c-border);
  border-radius: var(--radius);
  padding: 0.85rem 1rem;
  box-shadow: var(--shadow-sm);
}
.kpi-card .kpi-label { color: var(--c-muted); font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.5px; }
.kpi-card .kpi-value { font-size: 1.6rem; font-weight: 700; color: var(--c-primary-d); margin-top: 0.2rem; }
.kpi-card.alert { border-left: 4px solid var(--c-danger); }
.kpi-card.warn  { border-left: 4px solid var(--c-warning); }

.alert-banner {
  padding: 0.75rem 1rem;
  border-radius: var(--radius);
  margin-bottom: 1rem;
  font-size: 0.9rem;
}
.alert-banner.error   { background: #fee2e2; color: #991b1b; border: 1px solid #fca5a5; }
.alert-banner.warning { background: #fef3c7; color: #92400e; border: 1px solid #fcd34d; }

/* ── Trigger badges ────────────────────────────────── */
.trigger-badge {
  display: inline-block;
  padding: 0.12rem 0.55rem;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.3px;
  color: white;
  white-space: nowrap;
}
.trigger-badge.lead_freddo      { background: #9ca3af; }
.trigger-badge.non_erogato      { background: #f97316; }
.trigger-badge.consolidamento   { background: #2563eb; }
.trigger-badge.cqs_scadenza     { background: #dc2626; }
.trigger-badge.rinegoziazione   { background: #16a34a; }
.trigger-badge.post_vendita     { background: #0d9488; }
.trigger-badge.rientro_rifiuto  { background: #7c3aed; }
.trigger-badge.compleanno       { background: #ec4899; }
.trigger-badge.manuale          { background: #374151; }
/* SPECS v2025 — pipeline 5 stati */
.trigger-badge.chiamata_qualifica          { background: #0ea5e9; }   /* blu chiaro: prospect → qualificato */
.trigger-badge.chiamata_urgente_lead_caldo { background: #b91c1c; }   /* rosso scuro: priorita massima */
.trigger-badge.caricamento_pratica_prexta  { background: #6366f1; }   /* indaco: cliente in carico */
.trigger-badge.comunicazione_esito         { background: #059669; }   /* verde acqua: esito definitivo */
.trigger-badge.postvendita_reproposta      { background: #d97706; }   /* arancio: reattivazione cliente */

/* ── Filters row ───────────────────────────────────── */
.filters-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
  align-items: flex-end;
}
.filters-row .field { flex: 0 1 160px; margin: 0; }
.filters-row .field label { font-size: 0.75rem; margin-bottom: 0.1rem; }
.filters-row .field input, .filters-row .field select { font-size: 0.85rem; padding: 0.35rem 0.5rem; }

/* ── Side panel ────────────────────────────────────── */
.side-panel-backdrop {
  position: fixed; inset: 0;
  background: rgba(10, 20, 50, 0.4);
  z-index: 50;
  animation: fade-in 0.15s;
}
.side-panel {
  position: fixed;
  top: 0; right: 0; bottom: 0;
  width: min(480px, 100%);
  background: white;
  box-shadow: -4px 0 16px rgba(10,20,50,0.15);
  z-index: 51;
  display: flex;
  flex-direction: column;
  animation: slide-in-right 0.2s;
}
@keyframes fade-in { from {opacity:0} to {opacity:1} }
@keyframes slide-in-right {
  from { transform: translateX(100%); }
  to   { transform: translateX(0); }
}
.side-panel-header {
  padding: 1rem 1.25rem;
  background: var(--c-primary);
  color: white;
  display: flex; align-items: center; justify-content: space-between;
}
.side-panel-header h3 { margin: 0; font-size: 1.05rem; }
.side-panel-header button {
  background: transparent;
  border: 1px solid rgba(255,255,255,0.35);
  color: white;
  padding: 0.25rem 0.6rem;
  border-radius: var(--radius);
  cursor: pointer;
}
.side-panel-body {
  padding: 1rem 1.25rem;
  overflow-y: auto;
  flex: 1;
}
.side-panel-body h4 {
  font-size: 0.85rem;
  margin: 1rem 0 0.5rem;
  text-transform: uppercase;
  color: var(--c-muted);
  letter-spacing: 0.5px;
}
.side-panel-body details { margin-bottom: 1rem; }
.side-panel-body details summary {
  cursor: pointer;
  font-weight: 600;
  color: var(--c-primary-d);
  padding: 0.4rem 0;
}
.script-content {
  background: #f7f9fc;
  padding: 0.75rem;
  border-radius: var(--radius);
  white-space: pre-wrap;
  font-size: 0.88rem;
  line-height: 1.5;
  border: 1px solid var(--c-border);
}

.contact-info-grid {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.3rem 0.75rem;
  font-size: 0.9rem;
}
.contact-info-grid dt { color: var(--c-muted); font-weight: 500; }
.contact-info-grid dd { margin: 0; }

/* ── Kanban ────────────────────────────────────────── */
.kanban-board {
  display: flex;
  gap: 0.75rem;
  overflow-x: auto;
  padding-bottom: 1rem;
  min-height: 500px;
}
.kanban-col {
  flex: 0 0 280px;
  background: #eef2f7;
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  max-height: 80vh;
}
.kanban-col-header {
  padding: 0.6rem 0.75rem;
  font-weight: 600;
  font-size: 0.88rem;
  color: var(--c-primary-d);
  border-bottom: 1px solid var(--c-border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.kanban-col-body {
  padding: 0.5rem;
  flex: 1;
  overflow-y: auto;
  min-height: 200px;
}
.kanban-col.drop-target {
  background: #dbe6f5;
  outline: 2px dashed var(--c-accent);
  outline-offset: -4px;
}
.kanban-card {
  background: white;
  border: 1px solid var(--c-border);
  border-radius: var(--radius);
  padding: 0.55rem 0.7rem;
  margin-bottom: 0.5rem;
  cursor: grab;
  font-size: 0.85rem;
  box-shadow: var(--shadow-sm);
  transition: transform 0.1s;
}
.kanban-card:hover { border-color: var(--c-accent); }
.kanban-card:active { cursor: grabbing; }
.kanban-card.dragging { opacity: 0.5; transform: scale(0.96); }
.kanban-card .name { font-weight: 600; }
.kanban-card .meta { color: var(--c-muted); font-size: 0.78rem; margin-top: 0.2rem; }

/* ── Timeline ──────────────────────────────────────── */
.timeline {
  border-left: 3px solid var(--c-border);
  padding-left: 1rem;
  margin-left: 0.5rem;
}
.timeline-item {
  position: relative;
  padding-bottom: 1rem;
}
.timeline-item::before {
  content: '';
  position: absolute;
  left: -1.4rem;
  top: 0.3rem;
  width: 12px; height: 12px;
  background: var(--c-primary);
  border-radius: 50%;
  border: 3px solid white;
  box-shadow: 0 0 0 1px var(--c-border);
}
.timeline-item.completed::before { background: var(--c-success); }
.timeline-item.annullata::before  { background: var(--c-muted); }
.timeline-item.rinviata::before   { background: var(--c-warning); }
.timeline-head {
  font-weight: 600;
  font-size: 0.9rem;
  display: flex;
  gap: 0.5rem;
  align-items: center;
  flex-wrap: wrap;
}
.timeline-meta {
  color: var(--c-muted);
  font-size: 0.78rem;
  margin-top: 0.2rem;
}
.timeline-body {
  font-size: 0.9rem;
  margin-top: 0.35rem;
}

/* ── Tabs ──────────────────────────────────────────── */
.tabs {
  display: flex;
  gap: 0;
  border-bottom: 1px solid var(--c-border);
  margin: 0 0 1rem;
  overflow-x: auto;
}
.tab-btn {
  padding: 0.6rem 1rem;
  border: none;
  background: transparent;
  cursor: pointer;
  font-family: inherit;
  font-size: 0.92rem;
  color: var(--c-muted);
  border-bottom: 2px solid transparent;
  font-weight: 500;
}
.tab-btn:hover { color: var(--c-primary); }
.tab-btn.active {
  color: var(--c-primary);
  border-bottom-color: var(--c-primary);
  font-weight: 600;
}
.tab-content { padding: 0.5rem 0; }

/* ── Contact list ──────────────────────────────────── */
.contact-row {
  cursor: pointer;
}
.contact-row:hover { background: #eef2f7 !important; }

.pagination {
  display: flex;
  gap: 0.5rem;
  justify-content: center;
  margin-top: 1rem;
  align-items: center;
}
.pagination button {
  background: white;
  border: 1px solid var(--c-border);
  padding: 0.3rem 0.65rem;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 0.85rem;
}
.pagination button:disabled { opacity: 0.4; cursor: not-allowed; }
.pagination .current {
  background: var(--c-primary);
  color: white;
  border-color: var(--c-primary);
}

/* ── Tag list ──────────────────────────────────────── */
.tag-list { display: flex; gap: 0.3rem; flex-wrap: wrap; }
.tag {
  display: inline-block;
  padding: 0.1rem 0.5rem;
  background: #dbeafe;
  color: #1e40af;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 500;
}

/* ── Responsive ────────────────────────────────────── */
@media (max-width: 600px) {
  .view-root { margin: 1rem auto; padding: 0 0.5rem; }
  .side-panel { width: 100%; }
  .kanban-col { flex-basis: 85vw; }
  .filters-row .field { flex: 1 1 100%; }
  .stats-row { flex-direction: column; gap: 0.5rem; }
  .stats-row .stat { width: 100%; }
}

/* ── Templates / Scripts editor ────────────────────── */
.templates-layout {
  display: grid;
  grid-template-columns: 300px 1fr;
  gap: 1rem;
  align-items: start;
}
@media (max-width: 800px) {
  .templates-layout { grid-template-columns: 1fr; }
}

.templates-list {
  max-height: 75vh;
  overflow-y: auto;
  padding: 0.5rem;
}
.tmpl-group { margin-bottom: 0.75rem; }
.tmpl-group-title {
  font-size: 0.75rem;
  text-transform: uppercase;
  color: var(--c-muted);
  padding: 0.3rem 0.5rem;
  font-weight: 600;
  letter-spacing: 0.5px;
}
.tmpl-item {
  padding: 0.5rem 0.65rem;
  border-radius: var(--radius);
  cursor: pointer;
  margin-bottom: 0.25rem;
}
.tmpl-item:hover { background: #eef2f7; }
.tmpl-item.active {
  background: var(--c-primary);
  color: white;
}
.tmpl-item.active .tmpl-meta .badge { background: rgba(255,255,255,0.2); color: white; }
.tmpl-item.disabled { opacity: 0.5; }
.tmpl-name { font-weight: 500; font-size: 0.9rem; }
.tmpl-meta { font-size: 0.75rem; margin-top: 0.2rem; display: flex; gap: 0.3rem; flex-wrap: wrap; }

.toggle-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  cursor: pointer;
  font-size: 0.9rem;
  padding: 0.3rem 0;
}
.toggle-row input[type=checkbox] { width: 18px; height: 18px; cursor: pointer; }

/* ── Modal ──────────────────────────────────────────── */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(10, 20, 50, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 60;
  animation: fade-in 0.15s;
  padding: 1rem;
}
.modal {
  background: white;
  border-radius: var(--radius);
  width: 100%;
  max-width: 560px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 8px 32px rgba(10,20,50,0.3);
  animation: modal-in 0.2s;
}
@keyframes modal-in {
  from { opacity: 0; transform: translateY(-20px); }
  to   { opacity: 1; transform: translateY(0); }
}
.modal-header {
  padding: 1rem 1.25rem;
  background: var(--c-primary);
  color: white;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-top-left-radius: var(--radius);
  border-top-right-radius: var(--radius);
}
.modal-header h3 { margin: 0; font-size: 1.05rem; }
.modal-header button {
  background: transparent;
  border: 1px solid rgba(255,255,255,0.35);
  color: white;
  width: 28px; height: 28px;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 1.2rem;
  line-height: 1;
}
.modal-body {
  padding: 1rem 1.25rem;
  overflow-y: auto;
  flex: 1;
}
.modal-footer {
  padding: 0.75rem 1.25rem;
  border-top: 1px solid var(--c-border);
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
}

/* ────────────── Lead Inbox (v2) ────────────── */

.lead-card {
  border-left: 3px solid transparent;
}
.lead-card .tel {
  font-family: ui-monospace, SFMono-Regular, monospace;
  font-size: 0.82rem;
  color: #374151;
  margin-top: 0.15rem;
}
.lead-card .meta {
  margin-top: 0.25rem;
  font-size: 0.75rem;
  color: #6b7280;
}
.lead-card .scarto-tag {
  display: inline-block;
  margin-top: 0.4rem;
  background: #fee2e2;
  color: #991b1b;
  border-radius: 3px;
  padding: 0.1rem 0.4rem;
  font-size: 0.7rem;
  font-weight: 600;
}

/* Pannello laterale custom per Lead Inbox */
.lead-side-panel {
  position: fixed;
  top: 0;
  right: 0;
  width: 420px;
  max-width: 100%;
  height: 100vh;
  background: #fff;
  border-left: 1px solid #e5e7eb;
  box-shadow: -4px 0 20px rgba(0, 0, 0, 0.08);
  z-index: 1000;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: transform 0.18s ease-out;
}
.lead-side-panel.hidden {
  transform: translateX(100%);
  pointer-events: none;
}
.lead-side-panel .sp-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid #e5e7eb;
  background: #f9fafb;
}
.lead-side-panel .sp-head h2 {
  margin: 0;
  font-size: 1.05rem;
}
.lead-side-panel .sp-body {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 1rem;
  font-size: 0.9rem;
}
.lead-side-panel .sp-body .kv {
  display: flex;
  gap: 0.5rem;
  padding: 0.25rem 0;
}
.lead-side-panel .sp-body .kv b {
  flex: 0 0 100px;
  color: #4b5563;
  font-weight: 600;
}
.lead-side-panel .sp-body hr {
  margin: 0.75rem 0;
  border: 0;
  border-top: 1px solid #e5e7eb;
}
.lead-side-panel .sp-actions {
  display: flex;
  gap: 0.5rem;
  padding: 0.75rem 1rem;
  border-top: 1px solid #e5e7eb;
  background: #f9fafb;
  flex-wrap: wrap;
}
.lead-side-panel .sp-actions .btn {
  flex: 1 1 auto;
}

/* Badge stato (lead) */
.badge-stato {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  border-radius: 3px;
  background: #e5e7eb;
  color: #374151;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: lowercase;
}
.badge-stato[data-s="da_contattare"]   { background: #f3f4f6; color: #374151; }
.badge-stato[data-s="contattato"]      { background: #dbeafe; color: #1e40af; }
.badge-stato[data-s="in_qualifica"]    { background: #ffedd5; color: #9a3412; }
.badge-stato[data-s="qualificato"]     { background: #d1fae5; color: #065f46; }
.badge-stato[data-s="scartato"]        { background: #fee2e2; color: #991b1b; }
.badge-stato[data-s="non_contattare"]  { background: #f3f4f6; color: #6b7280; }

/* Tabella mapping colonne import CSV */
.mapping-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
}
.mapping-table th,
.mapping-table td {
  padding: 0.35rem 0.5rem;
  border-bottom: 1px solid #e5e7eb;
  text-align: left;
  vertical-align: middle;
}
.mapping-table thead th {
  background: #f3f4f6;
  font-weight: 600;
  color: #4b5563;
}
.mapping-table code {
  background: #f3f4f6;
  padding: 0.1rem 0.3rem;
  border-radius: 2px;
  font-size: 0.78rem;
}
.mapping-table select {
  width: 100%;
  padding: 0.25rem 0.3rem;
  font-size: 0.82rem;
}

/* Bottone danger (per anonimizza) */
.btn.btn-danger {
  background: #dc2626;
  color: #fff;
  border-color: #b91c1c;
}
.btn.btn-danger:hover {
  background: #b91c1c;
}

/* Header di pagina standard */
.page-header h1 {
  font-size: 1.5rem;
  margin: 0;
}

/* ────────────── Pratiche v2 Kanban ────────────── */

.pratiche-board .kanban-col { min-width: 200px; }
.pratica-card .pratica-prod {
  font-size: 0.82rem;
  font-weight: 600;
  color: #374151;
  margin-top: 0.2rem;
}
.pratica-card .pratica-prod .prod-code {
  background: #eef2ff;
  color: #3730a3;
  padding: 0.05rem 0.35rem;
  border-radius: 3px;
  font-family: ui-monospace, SFMono-Regular, monospace;
  font-size: 0.75rem;
  margin-right: 0.35rem;
}
.kanban-col-submeta {
  font-size: 0.75rem;
  color: #6b7280;
  text-align: center;
  padding: 0.2rem 0.4rem;
  border-bottom: 1px solid #f3f4f6;
}

/* Timeline side panel */
.timeline { font-size: 0.85rem; }
.timeline-item {
  border-left: 2px solid #e5e7eb;
  padding: 0.4rem 0 0.4rem 0.7rem;
  margin-left: 0.3rem;
  position: relative;
}
.timeline-item::before {
  content: '';
  position: absolute;
  left: -5px;
  top: 0.6rem;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #6b7280;
}
.timeline-item[data-t="liquidazione"]::before  { background: #16a34a; }
.timeline-item[data-t="ko_banca"]::before      { background: #dc2626; }
.timeline-item[data-t="annullamento"]::before  { background: #4b5563; }
.timeline-item[data-t="firma"]::before         { background: #0891b2; }
.timeline-item[data-t="ok_banca"]::before      { background: #7c3aed; }
.timeline-item[data-t="creazione"]::before     { background: #9ca3af; }
.timeline-item .t-head {
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
}
.timeline-item .t-head .text-muted {
  font-size: 0.75rem;
}
.timeline-item .t-note {
  margin-top: 0.15rem;
  font-size: 0.8rem;
  color: #4b5563;
}

/* ────────────── PostVendita ────────────── */

.pv-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 0.75rem;
}
.pv-card {
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 6px;
  padding: 0.75rem 0.9rem;
  cursor: pointer;
  transition: border-color 0.15s;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}
.pv-card:hover { border-color: var(--c-accent, #2563eb); }
.pv-head { display: flex; justify-content: space-between; align-items: center; gap: 0.5rem; }
.pv-name { font-weight: 600; color: #1e293b; }
.pv-name a { color: inherit; text-decoration: none; }
.pv-name a:hover { text-decoration: underline; }
.pv-tel {
  font-family: ui-monospace, SFMono-Regular, monospace;
  font-size: 0.82rem;
  color: #374151;
}
.pv-meta { font-size: 0.78rem; color: #6b7280; }
.pv-meta-row { font-size: 0.78rem; color: #4b5563; margin-top: 0.2rem; }
.pv-commento {
  margin-top: 0.35rem;
  padding: 0.35rem 0.5rem;
  background: #f9fafb;
  border-left: 3px solid #cbd5e1;
  font-size: 0.82rem;
  font-style: italic;
  color: #475569;
}
.pv-segn {
  margin-top: 0.3rem;
  font-size: 0.78rem;
  color: #065f46;
  background: #d1fae5;
  display: inline-block;
  padding: 0.1rem 0.4rem;
  border-radius: 3px;
}
.pv-actions {
  margin-top: 0.5rem;
  display: flex;
  gap: 0.4rem;
  flex-wrap: wrap;
}
.pv-actions .btn { flex: 1 1 auto; }

.nps-badge {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  border-radius: 3px;
  font-size: 0.75rem;
  font-weight: 600;
}
.nps-badge.nps-promoter   { background: #d1fae5; color: #065f46; }
.nps-badge.nps-passive    { background: #fef3c7; color: #92400e; }
.nps-badge.nps-detractor  { background: #fee2e2; color: #991b1b; }
.nps-badge.nps-na         { background: #e5e7eb; color: #4b5563; }

/* ────────────── Report Liquidato ────────────── */

.kpi-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 0.75rem;
}
.kpi-card {
  background: #f8fafc;
  border-left: 3px solid #0b3d91;
  padding: 0.6rem 0.8rem;
  border-radius: 4px;
}
.kpi-label {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: #64748b;
  font-weight: 600;
}
.kpi-value {
  font-size: 1.3rem;
  font-weight: 700;
  color: #0b3d91;
  margin-top: 0.15rem;
}
.text-right { text-align: right; }
.table-compact tfoot td {
  padding: 0.45rem 0.6rem;
  background: #f8fafc;
}

/* SPECS v2025: barra di ricerca globale nell'header */
.global-search-wrap {
  position: relative;
  flex: 0 1 280px;
  margin: 0 0.75rem;
}
.global-search-wrap input[type="search"] {
  width: 100%;
  padding: 0.4rem 0.6rem;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  font-size: 0.9rem;
  background: #fff;
}
.global-search-wrap input[type="search"]:focus {
  outline: none;
  border-color: var(--c-primary, #0b3d91);
  box-shadow: 0 0 0 3px rgba(11,61,145,0.12);
}
.global-search-dropdown {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 6px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.12);
  z-index: 1000;
  max-height: 70vh;
  overflow-y: auto;
}
.global-search-dropdown[hidden] { display: none; }
.gs-header {
  padding: 0.5rem 0.75rem;
  font-size: 0.8rem;
  color: #6b7280;
  background: #f9fafb;
  border-bottom: 1px solid #e5e7eb;
}
.gs-section { border-bottom: 1px solid #f3f4f6; }
.gs-section:last-child { border-bottom: none; }
.gs-section-title {
  padding: 0.4rem 0.75rem;
  font-size: 0.75rem;
  font-weight: 600;
  color: #374151;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  background: #fafbfc;
}
.gs-item {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.5rem 0.75rem;
  text-decoration: none;
  color: inherit;
  border-bottom: 1px solid #f9fafb;
}
.gs-item:hover { background: #f3f4f6; }
.gs-item:last-child { border-bottom: none; }
.gs-item-main { flex: 1; min-width: 0; }
.gs-item-main strong { display: block; font-size: 0.9rem; }
.gs-item-meta {
  display: block; font-size: 0.78rem; color: #6b7280;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.gs-item-side {
  display: flex; flex-direction: column; align-items: flex-end; gap: 0.2rem;
  font-size: 0.78rem;
}
.gs-loading, .gs-empty, .gs-error {
  padding: 1rem; text-align: center; color: #6b7280; font-size: 0.85rem;
}
.gs-error { color: var(--c-error, #dc2626); }

/* === Navigation dropdowns (BATCH 2 — workflow Prestiton) === */
.nav-dropdown {
  position: relative;
  display: inline-block;
}
.nav-dropdown-toggle {
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.20);
  color: rgba(255,255,255,0.92);
  padding: 0.32rem 0.55rem;
  white-space: nowrap;
  font-size: 0.88rem;
  border-radius: var(--radius);
  cursor: pointer;
  font-family: inherit;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  transition: background 0.15s;
}
.nav-dropdown-toggle:hover { background: rgba(255,255,255,0.18); color: white; }
.nav-dropdown-toggle .caret { font-size: 0.7rem; opacity: 0.85; }

.nav-dropdown-menu {
  display: none;
  position: absolute;
  top: 100%;
  left: 0;
  margin-top: 6px;
  min-width: 230px;
  background: var(--c-card);
  color: var(--c-text);
  border: 1px solid var(--c-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  padding: 0.4rem 0;
  z-index: 100;
}
.nav-dropdown-menu-right { left: auto; right: 0; }
.nav-dropdown.open > .nav-dropdown-menu { display: block; }
.nav-dropdown-menu a {
  display: block;
  padding: 0.5rem 0.95rem;
  color: var(--c-text);
  text-decoration: none;
  font-size: 0.92rem;
  border-radius: 0;
}
.nav-dropdown-menu a:hover { background: var(--c-bg); color: var(--c-primary); }
/* V2.0+ — Active state per dropdown menu: la pagina corrente nel menu deve essere VISIBILE */
.nav-dropdown-menu a.active,
.nav-dropdown-menu a[aria-current="page"] {
  background: linear-gradient(90deg, rgba(37,99,235,0.12) 0%, rgba(37,99,235,0.04) 100%);
  color: var(--c-primary) !important;
  font-weight: 700;
  border-left: 3px solid var(--c-primary);
  padding-left: calc(0.95rem - 3px);
}
.nav-dropdown-menu a.active::after {
  content: '●';
  float: right;
  color: var(--c-primary);
  font-size: 0.7rem;
  margin-top: 0.25rem;
}
/* Dropdown migliorato: ombra piu' calda, spacing, micro-anim */
.nav-dropdown-menu {
  animation: dropdownIn 0.12s ease-out;
  box-shadow: 0 12px 32px rgba(15, 23, 42, 0.18), 0 2px 6px rgba(15, 23, 42, 0.08);
  border-radius: 10px;
  padding: 0.5rem 0;
  min-width: 240px;
}
@keyframes dropdownIn {
  from { opacity: 0; transform: translateY(-4px); }
  to   { opacity: 1; transform: translateY(0); }
}
.nav-dropdown-menu a {
  transition: background 0.12s, color 0.12s, padding 0.12s;
  font-weight: 500;
}
.nav-dropdown-menu a:hover {
  padding-left: 1.1rem;
}
/* Toggle bottone: micro-effetto + active scale */
.nav-dropdown-toggle {
  transition: background 0.15s, transform 0.05s, box-shadow 0.15s;
  font-weight: 500;
}
.nav-dropdown-toggle:hover {
  box-shadow: 0 2px 8px rgba(255,255,255,0.10);
}
.nav-dropdown.open > .nav-dropdown-toggle {
  background: rgba(255,255,255,0.22);
  color: #fff;
}
.nav-dropdown.open > .nav-dropdown-toggle::after {
  content: '';
}
/* Toggle group attivo (cluster contiene la pagina corrente) */
.nav-dropdown.has-active > .nav-dropdown-toggle {
  background: rgba(255,255,255,0.18);
  box-shadow: 0 0 0 2px rgba(255,255,255,0.25) inset;
  color: #fff;
}

.dropdown-sep { border: 0; border-top: 1px solid var(--c-border); margin: 0.4rem 0; }
.dropdown-section-title {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--c-muted);
  padding: 0.4rem 0.95rem 0.2rem;
  font-weight: 600;
}
.dropdown-logout {
  display: block;
  width: 100%;
  text-align: left;
  background: none;
  border: 0;
  padding: 0.5rem 0.95rem;
  color: var(--c-danger);
  font-size: 0.92rem;
  cursor: pointer;
  font-family: inherit;
}
.dropdown-logout:hover { background: #fef2f2; }

.user-menu-toggle .avatar {
  background: rgba(255,255,255,0.20);
  border-radius: 50%;
  width: 22px;
  height: 22px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.85rem;
}

/* Hide admin section for non-admin users (set via JS removing data-admin-ok attribute) */
.dropdown-admin[data-admin-only]:not([data-admin-ok]) { display: none; }


/* V2.0+ — Header single-line layout (no wrap), piu' grande e leggibile */
.app-header .logo { white-space: nowrap; font-size: 1.15rem; flex-shrink: 0; }
.app-header .user-box { flex-shrink: 0; white-space: nowrap; font-size: 0.98rem; }
.app-header > a[href="/profilo"] { white-space: nowrap; flex-shrink: 0; margin-left: auto !important; font-size: 0.95rem; }
.app-header .global-search,
.app-header .global-search-input,
.app-header [id="global-search"],
.app-header [class*="search-input"],
.app-header input[type="search"],
.app-header input[placeholder*="Cerca"] {
  max-width: 220px;
  min-width: 160px;
  font-size: 0.92rem;
  padding: 0.35rem 0.65rem;
}
/* Default desktop ampio: bottoni nav grandi */
.nav-dropdown-toggle { font-size: 0.98rem; padding: 0.45rem 0.85rem; }
@media (max-width: 1600px) {
  .nav-dropdown-toggle { font-size: 0.92rem; padding: 0.4rem 0.7rem; }
}
@media (max-width: 1400px) {
  .nav-dropdown-toggle { font-size: 0.85rem; padding: 0.32rem 0.55rem; }
  .app-header .global-search,
  .app-header input[placeholder*="Cerca"] { max-width: 160px; min-width: 110px; font-size: 0.85rem; }
}
@media (max-width: 1200px) {
  .nav-dropdown-toggle { font-size: 0.8rem; padding: 0.28rem 0.45rem; }
  .app-header .logo { font-size: 1rem; }
  .app-header .global-search,
  .app-header input[placeholder*="Cerca"] { max-width: 130px; min-width: 90px; }
}

/* 2026-05-23 - Nav bar ottimizzata: media query per schermi medi/stretti */
@media (max-width: 1500px) {
  .nav-dropdown-toggle { padding: 0.28rem 0.45rem; font-size: 0.85rem; gap: 0.2rem; }
  .app-header .logo { font-size: 1rem; }
  .global-search-wrap input[type="search"] { width: 180px; font-size: 0.85rem; }
}
@media (max-width: 1280px) {
  .nav-dropdown-toggle { padding: 0.25rem 0.4rem; font-size: 0.8rem; }
  .app-header { padding: 0.35rem 0.5rem; gap: 0.3rem; }
  .main-nav { gap: 0.18rem; }
  .global-search-wrap input[type="search"] { width: 140px; }
}
