/* ============================================================
   EasyCRM — App stylesheet
   ============================================================ */

/* ============================================
   LIGHT THEME (default)
   ============================================ */
:root,
[data-theme="light"] {
  --bg-app:          #EDF0F5;
  --bg-navbar:       #ffffff;
  --bg-sidebar:      #ffffff;
  --bg-card:         #ffffff;
  --bg-card-hover:   #f8fafc;
  --bg-column:       #E3E8EF;
  --bg-input:        #EFF2F7;
  --board-grad:      radial-gradient(130% 90% at 50% -25%, #F6F8FC 0%, #E8EDF4 55%, #E1E7F0 100%);
  --border:          #D8DEE8;
  --border-focus:    #2563eb;
  --text-primary:    #0f172a;
  --text-secondary:  #4E5868;
  --text-muted:      #7A8595;
  --text-white:      #ffffff;
  --navbar-text:     #0f172a;
  --navbar-border:   #DDE3EC;
  --logo-color:      #0f172a;
  --nav-link-color:  #64748b;
  --nav-link-active: #2563eb;
  --card-shadow:     0 1px 3px rgba(16,24,40,.05), 0 10px 24px -14px rgba(16,24,40,.20);
  --shadow-sm:       0 1px 2px rgba(16,24,40,.06);
  --shadow:          0 6px 18px -8px rgba(16,24,40,.18);
  --shadow-lg:       0 20px 44px -18px rgba(16,24,40,.30);
  --accent:          #2563eb;
  --accent-hover:    #1d4ed8;
  --accent-light:    #eff6ff;
  --success:         #10b981;
  --success-light:   #d1fae5;
  --warning:         #f59e0b;
  --warning-light:   #fef3c7;
  --danger:          #ef4444;
  --danger-light:    #fee2e2;
  --purple:          #8b5cf6;
  --purple-light:    #ede9fe;
  --brand:           #C2D700;
  --brand-hover:     #B5C900;
  --brand-ink:       #181B1F;
  --brand-deep:      #5F6E00;   /* lime aziendale scurito, ~5.7:1 su bianco — accenti su fondo chiaro */
  /* Dashboard column charts — validated (lightness band, CVD, ≥3:1 on the card). */
  --chart-win:       #059669;
  --chart-loss:      #dc2626;
  --chart-open:      #2563eb;
  --chart-late:      #d97706;
  --radius-sm:       9px;
  --radius:          14px;
  --radius-lg:       18px;
  --transition:      0.18s ease;
  --font:            'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  --sidebar-width:   240px;
  --navbar-height:   56px;
}

/* ============================================
   DARK THEME
   ============================================ */
[data-theme="dark"] {
  --chart-win:       #12a072;
  --chart-loss:      #f0524f;
  --chart-open:      #3b82f6;
  --chart-late:      #d97706;
  --bg-app:          #11151B;
  --bg-navbar:       #161A21;
  --bg-sidebar:      #161A21;
  --bg-card:         #1D242C;
  --bg-card-hover:   #20262E;
  --bg-column:       #14181E;
  --bg-input:        #1B2027;
  --board-grad:      radial-gradient(130% 90% at 50% -25%, #161A21 0%, #11151B 55%, #0E1218 100%);
  --border:          #2F3742;
  --border-focus:    #3b82f6;
  --text-primary:    #E8ECF1;
  --text-secondary:  #A6AEB9;
  --text-muted:      #7C8590;
  --text-white:      #ffffff;
  --navbar-text:     #E8ECF1;
  --navbar-border:   #232A33;
  --logo-color:      #ffffff;
  --nav-link-color:  #9AA3AF;
  --nav-link-active: #60a5fa;
  --card-shadow:     0 1px 3px rgba(0,0,0,.40), 0 10px 24px -14px rgba(0,0,0,.50);
  --shadow-sm:       0 1px 2px rgba(0,0,0,.40);
  --shadow:          0 6px 18px -8px rgba(0,0,0,.45);
  --shadow-lg:       0 20px 44px -18px rgba(0,0,0,.50);
  --accent:          #3b82f6;
  --accent-hover:    #60A5FA;
  --accent-light:    rgba(59,130,246,.16);
  --success:         #10b981;
  --success-light:   #064e3b;
  --warning:         #f59e0b;
  --warning-light:   #451a03;
  --danger:          #ef4444;
  --danger-light:    #450a0a;
  --purple:          #a78bfa;
  --purple-light:    #2e1065;
  --brand:           #C2D700;
  --brand-hover:     #B5C900;
  --brand-ink:       #15181C;
  --brand-deep:      #C2D700;   /* su fondi scuri il lime pieno resta leggibile (lo scurito sparirebbe) */
}

/* ============================================
   TYPOGRAPHY SCALE
   ============================================ */

/* Base */
*, *::before, *::after {
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: var(--font);
  font-size: 14px;
  font-weight: 400;
  line-height: 1.6;
  color: var(--text-primary);
  letter-spacing: 0;
}

/* Display — page titles */
.type-display {
  font-size: 24px;
  font-weight: 700;
  letter-spacing: -0.5px;
  line-height: 1.2;
  color: var(--text-primary);
}

/* Heading 1 — section titles */
.type-h1, h1 {
  font-size: 20px;
  font-weight: 600;
  letter-spacing: -0.3px;
  line-height: 1.3;
  color: var(--text-primary);
}

/* Heading 2 — card titles */
.type-h2, h2 {
  font-size: 16px;
  font-weight: 600;
  letter-spacing: -0.2px;
  line-height: 1.4;
  color: var(--text-primary);
}

/* Heading 3 — subtitles */
.type-h3, h3 {
  font-size: 14px;
  font-weight: 600;
  letter-spacing: -0.1px;
  line-height: 1.4;
  color: var(--text-primary);
}

/* Body — base text */
.type-body {
  font-size: 14px;
  font-weight: 400;
  line-height: 1.6;
  color: var(--text-primary);
}

/* Body medium — company names, important values */
.type-body-medium {
  font-size: 14px;
  font-weight: 500;
  line-height: 1.6;
  color: var(--text-primary);
}

/* Secondary — metadata, supporting text */
.type-secondary {
  font-size: 13px;
  font-weight: 400;
  line-height: 1.5;
  color: var(--text-secondary);
}

/* Caption — timestamps, hints */
.type-caption {
  font-size: 12px;
  font-weight: 400;
  line-height: 1.5;
  color: var(--text-secondary);
}

/* Label — form labels, KPI labels, column headers */
.type-label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-secondary);
  line-height: 1;
}

/* KPI number — dashboard big numbers */
.type-kpi {
  font-size: 32px;
  font-weight: 700;
  letter-spacing: -0.5px;
  line-height: 1;
  color: var(--text-primary);
}

/* Mono — tokens, IDs, code */
.type-mono {
  font-family: 'Courier New', Courier, monospace;
  font-size: 12px;
  line-height: 1.5;
  color: var(--text-secondary);
}

/* ============================================
   APPLY SCALE TO COMPONENTS
   ============================================ */

/* Navbar */
.nav-logo-text {
  font-size: 17px;
  font-weight: 700;
  letter-spacing: -0.3px;
}

.nav-link {
  font-size: 13px;
  font-weight: 500;
  letter-spacing: 0;
}

#user-name {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
}

#nav-project-name {
  font-size: 11px;
  font-weight: 400;
  color: var(--text-muted);
  letter-spacing: 0;
}

/* Kanban column header */
.column-header .column-title,
.kanban-column__title {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--text-secondary);
}

.column-count,
.kanban-badge {
  font-size: 11px;
  font-weight: 600;
}

/* Lead cards */
.lead-card .card-company,
.lead-card__company {
  font-size: 14px;
  font-weight: 600;
  letter-spacing: -0.1px;
  line-height: 1.3;
}

.lead-card .card-contact,
.lead-card__contact {
  font-size: 12px;
  font-weight: 400;
  color: var(--text-secondary);
  margin-top: 2px;
}

.lead-card .card-date,
.lead-card__date {
  font-size: 11px;
  font-weight: 400;
  color: var(--text-muted);
}

/* Drawer */
.drawer-title h2 {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.3px;
  line-height: 1.2;
}

.drawer-tabs .tab {
  font-size: 13px;
  font-weight: 500;
}

.field-row label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-secondary);
}

.field-display {
  font-size: 14px;
  font-weight: 400;
}

.activity-text {
  font-size: 13px;
  font-weight: 400;
  line-height: 1.5;
}

.activity-meta {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 2px;
}

/* Dashboard */
.dash-header h2 {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.4px;
}

.kpi-label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-secondary);
}

.kpi-value {
  font-size: 32px;
  font-weight: 700;
  letter-spacing: -0.5px;
  line-height: 1;
  margin: 8px 0 4px;
}

.kpi-sub {
  font-size: 12px;
  font-weight: 400;
  color: var(--text-muted);
}

.chart-header h3 {
  font-size: 14px;
  font-weight: 600;
  letter-spacing: -0.1px;
}

/* Settings */
.settings-nav-item {
  font-size: 13px;
  font-weight: 500;
}

.settings-card h3 {
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.2px;
}

.card-desc {
  font-size: 13px;
  font-weight: 400;
  line-height: 1.6;
  color: var(--text-secondary);
}

.form-group label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-secondary);
}

.field-hint {
  font-size: 12px;
  font-weight: 400;
  color: var(--text-muted);
}

/* Table view */
.leads-table th {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-secondary);
}

.leads-table td {
  font-size: 13px;
  font-weight: 400;
}

/* Buttons */
.btn-primary, .btn-secondary {
  font-size: 13px;
  font-weight: 500;
  letter-spacing: 0.01em;
}

.btn-sm {
  font-size: 12px;
  font-weight: 500;
}

/* Modals */
.modal-box h3,
.modal-title {
  font-size: 17px;
  font-weight: 700;
  letter-spacing: -0.3px;
}

/* Badges and pills */
.role-badge {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.03em;
}

.status-pill {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.02em;
}

/* Inputs */
input, select, textarea {
  font-family: var(--font);
  font-size: 14px;
  font-weight: 400;
}

input::placeholder,
textarea::placeholder {
  font-weight: 400;
  color: var(--text-muted);
}

/* Token code */
.token-box code {
  font-family: 'Courier New', monospace;
  font-size: 12px;
  letter-spacing: 0.02em;
}

.code-block {
  font-family: 'Courier New', monospace;
  font-size: 12px;
  line-height: 1.7;
  letter-spacing: 0.02em;
}

/* Toast notifications */
.toast {
  font-size: 13px;
  font-weight: 500;
}

/* Empty states */
.empty-state p,
.empty-state {
  font-size: 14px;
  font-weight: 400;
  color: var(--text-muted);
}

.empty-state h3 {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

/* Filter bar */
.filter-input,
.filter-select {
  font-size: 13px;
  font-weight: 400;
}

/* Import wizard */
.import-header h3 {
  font-size: 17px;
  font-weight: 700;
  letter-spacing: -0.3px;
}

.step-indicator {
  font-size: 12px;
  font-weight: 400;
  color: var(--text-muted);
  margin-top: 3px;
}

.val-number {
  font-size: 36px;
  font-weight: 700;
  letter-spacing: -0.5px;
  line-height: 1;
}

.val-label {
  font-size: 12px;
  font-weight: 500;
  margin-top: 4px;
}

/* -------- Reset & base -------- */
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  font-family: var(--font);
  font-size: 14px;
  color: var(--text-primary);
  background: var(--bg-app);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  display: flex;
  flex-direction: column;
}
button { font-family: inherit; }
a { color: inherit; text-decoration: none; }
.hidden { display: none !important; }

/* -------- Navbar -------- */
#navbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 20px;
  height: var(--navbar-height);
  background: var(--bg-navbar);
  color: var(--navbar-text);
  border-bottom: 1px solid var(--navbar-border);
  flex-shrink: 0;
  position: sticky;
  top: 0;
  z-index: 50;
}
.nav-logo {
  display: flex;
  align-items: center;
  gap: 8px;
  text-decoration: none;
  flex-shrink: 0;
  min-width: 140px;
}
.nav-logo-text {
  font-size: 18px;
  font-weight: 700;
  color: var(--logo-color);
  letter-spacing: -0.3px;
  line-height: 1;
}
.nav-logo-accent {
  color: #2563eb;
}
[data-theme="dark"] .nav-logo-accent {
  color: #60a5fa;
}
.nav-project-name {
  font-size: 11px;
  color: var(--text-muted);
  max-width: 140px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  padding-left: 10px;
  margin-left: 4px;
  border-left: 1px solid var(--border);
}
.nav-project-name:empty { display: none; }

/* Desktop-only utility: visible on desktop, hidden via media query below */
.desktop-only {
  display: flex;
}

/* Project switcher — custom .ms-dropdown replacing the old native <select>.
   The wrapper carries the width so it flexes like the old select did; the
   toggle button fills it and wears the chip look. */
#project-selector.project-switcher {
  width: 220px;
  min-width: 160px;
  /* Niente flex-shrink:0 → su navbar stretta cede DOPO la ricerca (flex:1),
     poi si ferma a min-width:160px. */
}
.project-switcher .ms-toggle {
  width: 100%;
  height: 34px;
  padding: 0 11px;
  gap: 7px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: transparent;
  color: var(--text-primary);
  font-size: 13.5px;
  font-family: var(--font);
  font-weight: 500;
  outline: none;
  transition: background var(--transition), border-color var(--transition);
}
.project-switcher .ms-toggle:hover,
.project-switcher .ms-toggle:focus-visible {
  background: var(--bg-card-hover);
  border-color: var(--border-focus);
}
.project-switcher .ms-label {
  /* Ellissi pulita quando il nome del progetto eccede la width. */
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1 1 auto;
  min-width: 0;
  text-align: left;
}
.project-switcher .ms-toggle > .ti-chevron-down {
  flex: 0 0 auto;
  transition: transform var(--transition);
}
.project-switcher .ms-toggle[aria-expanded="true"] > .ti-chevron-down {
  transform: rotate(180deg);
}
/* Active project row: subtle accent + visible check. */
.project-switcher__opt { justify-content: space-between; }
.project-switcher__check { visibility: hidden; color: var(--accent); font-size: 15px; }
.project-switcher__opt.is-active { color: var(--accent); font-weight: 600; }
.project-switcher__opt.is-active .project-switcher__check { visibility: visible; }
.project-switcher__opt .ms-opt-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
[data-theme="dark"] .project-switcher .ms-toggle {
  background: rgba(255, 255, 255, 0.06);
  border-color: var(--border);
  color: var(--text-primary);
}

/* When there's a single project the nav-project-name subline is promoted
   to the primary in-navbar display (the dropdown is hidden). */
.nav-project-name.is-primary {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
  padding: 0 12px;
  max-width: 200px;
}
.nav-project-name.is-empty {
  font-style: italic;
  color: var(--text-muted);
}

.nav-links {
  display: flex;
  align-items: center;
  gap: 2px;
  flex: 1;
  justify-content: center;
}
.nav-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: transparent;
  border: none;
  color: var(--nav-link-color);
  padding: 8px 12px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  border-radius: var(--radius-sm);
  position: relative;
  transition: color var(--transition), background var(--transition);
}
.nav-link:hover { color: var(--nav-link-active); background: var(--bg-column); }
.nav-link.active { color: var(--nav-link-active); }
.nav-link.active::after {
  content: '';
  position: absolute;
  left: 12px; right: 12px; bottom: -2px;
  height: 2px;
  background: var(--nav-link-active);
  border-radius: 2px;
}
[data-theme="dark"] .nav-link:hover { background: rgba(255,255,255,0.06); }

.nav-actions {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
  margin-left: auto;
}
#user-name {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  white-space: nowrap;
  max-width: 120px;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* -------- App main -------- */
#app-main {
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
  background: var(--bg-app);
  position: relative;
}
/* Views are hidden by default; .active is the toggle that shows the current one.
   Pattern is symmetric: navigate() removes .active + adds .hidden on all, then
   adds .active + removes .hidden on the target. */
.view {
  display: none !important;
  height: 100%;
  width: 100%;
}
.view.active {
  display: flex !important;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}
.view.hidden {
  display: none !important;
}

/* -------- Buttons -------- */
.btn-primary, .btn-secondary, .btn-danger {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  border: none;
  cursor: pointer;
  transition: background var(--transition), border-color var(--transition), color var(--transition), opacity var(--transition);
}
.btn-primary { background: var(--brand); color: var(--brand-ink); font-weight: 600; }
.btn-primary:hover:not(:disabled) { background: var(--brand-hover); }
.btn-secondary {
  background: transparent;
  color: var(--text-primary);
  border: 1px solid var(--border);
}
.btn-secondary:hover:not(:disabled) { background: var(--bg-card-hover); }
.btn-danger { background: var(--danger); color: var(--text-white); }
.btn-danger:hover:not(:disabled) { background: #dc2626; }
.btn-primary:disabled, .btn-secondary:disabled, .btn-danger:disabled { opacity: 0.6; cursor: not-allowed; }

.btn-icon {
  width: 32px; height: 32px;
  background: transparent;
  border: none;
  color: var(--navbar-text);
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background var(--transition);
  font-size: 16px;
}
.btn-icon:hover { background: var(--bg-column); }
[data-theme="dark"] .btn-icon:hover { background: rgba(255,255,255,0.08); }

/* -------- Theme toggle button -------- */
.theme-toggle-btn {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  background: transparent;
  border: none;
  cursor: pointer;
  font-size: 16px;
  transition: all var(--transition);
  display: flex;
  align-items: center;
  justify-content: center;
}
.theme-toggle-btn:hover { background: var(--bg-column); }
[data-theme="dark"] .theme-toggle-btn:hover { background: rgba(255,255,255,0.08); }

/* ============================================================
   TOP CHROME — dark navbar in BOTH themes (persistent chrome).
   Scoped under #navbar so the dark surface never leaks into the
   sidebar, the board, or popovers (notif panel / search results).
   ============================================================ */
#navbar {
  --nav-bg:    #181B21;
  --nav-text:  #EDEFF2;
  --nav-muted: #9AA3AF;
  --nav-line:  #2A2F37;
  --nav-chip:  #23272F;
  background: var(--nav-bg);
  color: var(--nav-text);
  border-bottom: 1px solid var(--nav-line);
  box-shadow: 0 2px 8px -4px rgba(0,0,0,.35);
}

/* Logo: "easy" wordmark goes light HERE ONLY (var(--logo-color) is read by
   the SVG); "crm" keeps its hard-coded lime fill, untouched elsewhere. */
#navbar .nav-logo { --logo-color: var(--nav-text); }
#navbar .nav-logo-accent { color: var(--brand); }

/* Project name / subline */
#navbar .nav-project-name { color: var(--nav-muted); border-left-color: var(--nav-line); }
#navbar .nav-project-name.is-primary { color: var(--nav-text); }

/* Project switcher chip — light-on-dark to read on the dark topbar. Only the
   toggle button lives on the dark surface; the .ms-panel below opens over the
   light content area and keeps its default (white) styling. */
/* Clean transparent chip on the dark topbar (no flat grey fill) — the light-bar
   equivalent of the filter panel's .tkn-btn look. */
#navbar #project-selector .ms-toggle {
  background: transparent;
  color: var(--nav-text);
  border-color: var(--nav-line);
}
#navbar #project-selector .ms-toggle:hover,
#navbar #project-selector .ms-toggle:focus-visible {
  background: rgba(255, 255, 255, 0.06);
  border-color: var(--brand);
}
#navbar #project-selector .ms-toggle .ti { color: var(--nav-muted); }

/* Global search input — !important required to defeat the final !important
   block at the bottom of the file. */
#navbar .global-search-input {
  background: var(--nav-chip) !important;
  color: var(--nav-text) !important;
  border-color: var(--nav-line) !important;
}
#navbar .global-search-input:focus {
  background: var(--nav-chip) !important;
  border-color: var(--brand) !important;
  box-shadow: 0 0 0 3px rgba(194,215,0,.18) !important;
}
#navbar .global-search-input::placeholder { color: var(--nav-muted) !important; }
#navbar .global-search-icon { color: var(--nav-muted) !important; }
#navbar .search-kbd {
  color: var(--nav-muted);
  background: var(--nav-line);
  border-color: var(--nav-line);
}
#navbar .search-clear { color: var(--nav-muted); }
#navbar .search-clear:hover { color: var(--nav-text); background: var(--nav-line); }

/* Nav links: muted; ACTIVE = lime text + lime underline; hover = light */
#navbar .nav-link { color: var(--nav-muted); }
#navbar .nav-link:hover { color: var(--nav-text); background: rgba(255,255,255,.06); }
#navbar .nav-link.active { color: var(--brand); }
#navbar .nav-link.active::after { background: var(--brand); }

/* Action icon buttons (segnalazioni, bell, shortcuts, theme, profile, logout).
   Scoped to direct nav-actions children + the bell, so the white notif-panel
   popover internals (close / dashboard buttons) stay on the board theme. */
#navbar .nav-actions > .btn-icon,
#navbar .nav-actions > .theme-toggle-btn,
#navbar .notif-btn { color: var(--nav-text); }
#navbar .nav-actions > .btn-icon:hover,
#navbar .nav-actions > .theme-toggle-btn:hover,
#navbar .notif-btn:hover { background: rgba(255,255,255,.08); }

/* Bell red dot: ring matches the dark bar so it reads as a notch */
#navbar .notif-badge { border-color: var(--nav-bg); }

/* User name + mobile hamburger lines */
#navbar #user-name { color: var(--nav-muted); }
#navbar .hamburger-line { background: var(--nav-text); }

/* -------- Form elements -------- */
input[type="text"],
input[type="email"],
input[type="password"],
input[type="tel"],
input[type="url"],
input[type="number"],
input[type="date"],
select,
textarea {
  width: 100%;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  font-size: 14px;
  color: var(--text-primary);
  font-family: inherit;
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition), background var(--transition);
}
textarea { resize: vertical; min-height: 80px; }
input:focus, select:focus, textarea:focus {
  border-color: var(--border-focus);
  background: var(--bg-card);
  box-shadow: 0 0 0 3px rgba(37,99,235,0.10);
}
label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  margin: 0 0 6px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.form-group { margin-bottom: 14px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

/* -------- Kanban board --------
   Layout: #view-board is a column flex that holds the toolbar + filter bar
   at fixed height, then gives the remaining space to #kanban-wrapper, which
   scrolls horizontally. Each .kanban-column is its own vertical-scroll
   container so cards inside don't push the board height.
   Scoped to .active so the new `.view`/`.view.active` toggle still hides
   Board when other views are shown (ID > class specificity would otherwise
   keep Board displayed over other views). */
#view-board.active {
  display: flex !important;
  flex-direction: column !important;
  height: 100% !important;
  overflow: hidden !important;
}

.board-toolbar { flex-shrink: 0 !important; }
.filter-bar    { flex-shrink: 0 !important; }
.tag-filter-row { flex-shrink: 0 !important; }

#kanban-wrapper {
  flex: 1 !important;
  overflow-x: auto !important;
  overflow-y: hidden !important;
  padding: 16px 20px !important;
  min-height: 0 !important;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
  /* "Luce dall'alto": glow anchored top-center, painted on the scroll
     container's padding box so it stays put during horizontal scroll. */
  background: var(--board-grad) !important;
  cursor: grab;
}
/* Drag-to-pan: while panning the background, show the grabbing cursor and
   suppress text selection. Cards/columns keep their own cursor (they sit on
   top and aren't part of the pan gesture). */
#kanban-wrapper.panning { cursor: grabbing; user-select: none; }
#kanban-wrapper::-webkit-scrollbar { height: 8px; }
#kanban-wrapper::-webkit-scrollbar-track { background: var(--bg-column); border-radius: 4px; }
#kanban-wrapper::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
#kanban-wrapper::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

.kanban-board {
  display: flex !important;
  gap: 14px !important;
  height: 100% !important;
  align-items: flex-start !important;
  min-width: max-content !important;
  padding-bottom: 16px !important;
}

.kanban-column {
  width: 270px !important;
  min-width: 270px !important;
  max-width: 270px !important;
  flex-shrink: 0 !important;
  display: flex !important;
  flex-direction: column !important;
  max-height: 100% !important;
  background: rgba(255,255,255,.04);   /* dark: faint lift over the gradient */
  border-radius: var(--radius-lg);
  transition: background var(--transition), box-shadow var(--transition);
  /* Soft status tint derived from --col-color (set inline by kanban.js).
     A white/dark veil over the colour avoids color-mix() for compatibility. */
  --tint-veil: rgba(255,255,255,.88);
  --col-tint: linear-gradient(var(--tint-veil), var(--tint-veil)), var(--col-color, var(--bg-column));
}
[data-theme="dark"] .kanban-column { --tint-veil: rgba(22,26,33,.84); }

/* Drop highlight: tint the target column in its own colour + inset ring. */
.kanban-column.is-drop-target {
  background: var(--col-tint);
  box-shadow: inset 0 0 0 2px var(--col-color, var(--accent));
}

/* DOM uses .kanban-cards; .cards-container kept as alias for future-proofing. */
.cards-container,
.kanban-cards {
  overflow-y: auto !important;
  flex: 1 !important;
  min-height: 100px !important;
  padding: 8px !important;
}
.cards-container::-webkit-scrollbar,
.kanban-cards::-webkit-scrollbar { width: 4px; }
.cards-container::-webkit-scrollbar-track,
.kanban-cards::-webkit-scrollbar-track { background: transparent; }
.cards-container::-webkit-scrollbar-thumb,
.kanban-cards::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.kanban-column__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  gap: 8px;
  background: var(--col-tint);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
}
.kanban-column__title {
  font-weight: 600;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  /* Title colour follows the status TYPE: neutral grey by default, green on the
     vinto column, red on the perso column (set by kanban.js via --col-type-color). */
  color: var(--col-type-color, #64748b);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
/* Count badge text in the status colour, on a clear chip. */
.kanban-column__header .kanban-badge:not(.kanban-badge--value) {
  color: var(--col-color, var(--text-secondary));
}
.kanban-column__badges { display: inline-flex; align-items: center; gap: 6px; flex-shrink: 0; }
.kanban-badge {
  display: inline-block;
  background: var(--bg-card);
  color: var(--text-secondary);
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 20px;
  line-height: 1.4;
}
.kanban-badge--value {
  background: var(--success-light);
  color: var(--success);
}

.kanban-cards {
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  overflow-y: auto;
  flex: 1 1 auto;
  min-height: 0;
  scrollbar-width: thin;
  scrollbar-color: rgba(100,116,139,.32) transparent;
}

/* -------- Thin scrollbars — discreet, theme-agnostic (light/dark) -------- */
.kanban-cards,
.cards-container,
.tab-content,
.drawer-body,
.notif-panel-body {
  scrollbar-width: thin;
  scrollbar-color: rgba(100,116,139,.32) transparent;
}
.kanban-cards::-webkit-scrollbar,
.cards-container::-webkit-scrollbar,
.tab-content::-webkit-scrollbar,
.drawer-body::-webkit-scrollbar,
.notif-panel-body::-webkit-scrollbar { width: 8px; height: 8px; }
.kanban-cards::-webkit-scrollbar-track,
.cards-container::-webkit-scrollbar-track,
.tab-content::-webkit-scrollbar-track,
.drawer-body::-webkit-scrollbar-track,
.notif-panel-body::-webkit-scrollbar-track { background: transparent; }
.kanban-cards::-webkit-scrollbar-thumb,
.cards-container::-webkit-scrollbar-thumb,
.tab-content::-webkit-scrollbar-thumb,
.drawer-body::-webkit-scrollbar-thumb,
.notif-panel-body::-webkit-scrollbar-thumb {
  background: rgba(100,116,139,.32);
  border-radius: 999px;
}

/* -------- Lead card -------- */
.lead-card {
  position: relative;                       /* anchor for .lead-card__owner badge */
  background: var(--bg-card);
  box-sizing: border-box;
  border-style: solid;
  border-width: 2px 2px 2px 4px;          /* alto · destra · basso · SINISTRA */
  /* Left border encodes the OWNER (primary). Won/lost cards override
     --owner-color with green/red in kanban.js. No owner → neutral fallback. */
  border-color: transparent transparent transparent var(--owner-color, var(--border));
  border-radius: var(--radius);
  padding: 14px;
  box-shadow: var(--shadow-sm);
  cursor: pointer;
  transition: border-color .16s ease, box-shadow .16s ease, transform .16s ease, opacity var(--transition);
  user-select: none;
}
.lead-card:hover {
  /* Thick hover border: the whole perimeter lights up in the owner colour
     (green/red on won/lost via --owner-color). The 4px left bar is already that
     colour, so it stays intact — top/right/bottom just gain the matching tint. */
  border-color: var(--owner-color, var(--accent));
  transform: translateY(-3px);
  box-shadow: var(--shadow);
  background: var(--bg-card-hover);
}
.lead-card.is-dragging { opacity: 0.5; border: 2px dashed var(--accent); }

/* Owner initials badge — top-right, inset from the rounded corner. Inline
   styles (kanban.js) set the per-owner background + readable text colour. */
.lead-card__owner {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 23px;
  height: 23px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.02em;
  line-height: 1;
  box-shadow: 0 1px 3px rgba(0, 0, 0, .22);
  /* Accept pointer events so the native title tooltip (owner name) shows on
     hover. Safe: the card click bubbles up here, and the drag starts from the
     nearest draggable ancestor (the card), so neither breaks. */
  pointer-events: auto;
  cursor: inherit;          /* keep the card's grab/pointer cursor over the badge */
  user-select: none;
}

.lead-card[data-status-key="in-attesa"]      { --col-color: var(--warning); }
.lead-card[data-status-key="preventivo"]     { --col-color: var(--accent);  }
.lead-card[data-status-key="lavorazione"]    { --col-color: var(--purple);  }
.lead-card[data-status-key="confermato"]     { --col-color: var(--success); }
.lead-card[data-status-key="lead-ko"]        { --col-color: var(--danger);  }

.lead-card__top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.lead-card__date { font-size: 11px; color: var(--text-muted); white-space: nowrap; font-variant-numeric: tabular-nums; }
.lead-card__company {
  font-weight: 700;
  font-size: 15px;
  letter-spacing: -0.2px;
  color: var(--text-primary);
  margin-top: 8px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.lead-card__contact {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 2px;
  /* Card identifier line (descrizione_breve, or contact_name fallback). Clamp to
     2 lines with an ellipsis so an 80-char description never breaks card height,
     instead of the old single-line nowrap. */
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  text-overflow: ellipsis;
}
.lead-card__bottom {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: 10px;
}

/* Sector pill (light bg) */
.sector-pill {
  display: inline-block;
  font-size: 11px;
  background: var(--bg-column);
  color: var(--text-secondary);
  padding: 2px 8px;
  border-radius: 20px;
  max-width: 60%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Follow-up indicator */
.followup {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
}
.followup__dot {
  width: 7px; height: 7px; border-radius: 50%;
  flex-shrink: 0;
}
.followup--overdue { color: var(--danger); }
.followup--overdue .followup__dot { background: var(--danger); }
.followup--today   { color: var(--warning); }
.followup--today .followup__dot   { background: var(--warning); }
.followup--future  { color: var(--text-secondary); }
.followup--future .followup__dot  { background: var(--text-muted); }

/* -------- Empty / loading states -------- */
.kanban-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 24px 12px;
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  color: var(--text-muted);
  font-size: 12px;
  margin: 4px;
  gap: 6px;
}
.kanban-empty__icon { font-size: 24px; opacity: 0.55; }
.kanban-empty__title { font-size: 12px; font-weight: 600; color: var(--text-muted); }
.kanban-empty__hint { font-size: 11px; color: var(--text-muted); opacity: 0.75; }

.skeleton {
  background: linear-gradient(90deg, var(--border) 0%, var(--bg-column) 50%, var(--border) 100%);
  background-size: 200% 100%;
  border-radius: var(--radius);
  animation: skeleton-shimmer 1.4s infinite linear;
}
@keyframes skeleton-shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}
.lead-card--skeleton {
  height: 92px;
  border: 1px solid var(--border);
  cursor: default;
}
.lead-card--skeleton:hover { transform: none; box-shadow: var(--shadow-sm); }

/* -------- Floating Add Lead button -------- */
.fab-add-lead {
  position: fixed;
  right: 28px;
  bottom: 28px;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: var(--accent);
  color: var(--text-white);
  font-size: 26px;
  line-height: 1;
  border: none;
  cursor: pointer;
  box-shadow: var(--shadow-lg);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  z-index: 80;
  transition: transform var(--transition), background var(--transition);
}
.fab-add-lead:hover { transform: scale(1.08); background: var(--accent-hover); }
.fab-add-lead:active { transform: scale(1.02); }

/* -------- Modal -------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  animation: fade-in 0.15s ease;
}
.modal-box {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  padding: 28px;
  min-width: 420px;
  max-width: 560px;
  width: 100%;
  box-shadow: var(--shadow-lg);
  position: relative;
  max-height: calc(100vh - 32px);
  overflow-y: auto;
  animation: modal-pop 0.18s ease;
}
/* Wider variant — used only by the "Collega/Cambia cliente" lookup modal
   (boxClass: 'modal-box--lookup'). Overrides only max-width; min-width/width:100%
   are inherited, so it still shrinks to the viewport on small screens. */
.modal-box--lookup { max-width: 680px; }
/* In-flow results list (NOT absolute) so the modal grows to contain it instead
   of clipping the dropdown via .modal-box overflow. Scoped to the lookup modal
   only — the inline filter lookup (board/dashboard) keeps the absolute .cl-panel
   anchored under its field. The list scrolls internally past ~8-10 rows; the
   input stays visible above it and the footer below. */
.modal-box--lookup .cl-panel {
  position: static;
  margin-top: 4px;
  max-height: 360px;
  overflow-y: auto;
}
.modal-title {
  margin: 0 0 16px;
  font-size: 18px;
  font-weight: 600;
}
.modal-close {
  position: absolute;
  top: 12px; right: 12px;
  width: 32px; height: 32px;
  border: none; background: transparent;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 18px;
  color: var(--text-secondary);
}
.modal-close:hover { background: var(--bg-card-hover); }
.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 18px;
}
.modal-error {
  margin-top: 10px;
  padding: 8px 12px;
  background: var(--danger-light);
  color: var(--danger);
  border-radius: var(--radius-sm);
  font-size: 12px;
  display: none;
}
.modal-error.is-visible { display: block; }

/* -------- Drawer (lead detail) -------- */
.drawer-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  -webkit-backdrop-filter: blur(2px);
          backdrop-filter: blur(2px);
  z-index: 89;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.28s cubic-bezier(0.4, 0, 0.2, 1);
}
.drawer-overlay.open { opacity: 1; pointer-events: auto; }

.drawer {
  position: fixed;
  top: 0; right: 0;
  height: 100vh;
  width: 760px;
  max-width: 100vw;
  background: var(--bg-card);
  box-shadow: -8px 0 40px rgba(0, 0, 0, 0.15);
  z-index: 90;
  transform: translateX(100%);
  transition: transform 0.28s cubic-bezier(0.4, 0, 0.2, 1);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.drawer.open { transform: translateX(0); }

@media (max-width: 1280px) {
  .drawer { width: 520px; }
}

.drawer-header {
  position: relative;
  padding: 20px 20px 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
/* Close pinned to the header's top-right corner, out of the .drawer-actions row,
   so it never wraps/detaches (esp. on the 100vw mobile drawer) and is always
   tappable. The title reserves right padding so long names don't run under it. */
.drawer-header > .drawer-close {
  position: absolute;
  top: 14px;
  right: 14px;
  z-index: 3;
  flex: 0 0 auto;
  color: var(--text-secondary);
}
.drawer-header > .drawer-close:hover {
  background: var(--bg-card-hover);
  color: var(--text-primary);
}
.drawer-header > .drawer-title {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding-right: 40px;
}
.drawer-title h2 {
  font-size: 18px;
  font-weight: 700;
  color: var(--text-primary);
  margin: 0;
  margin-top: 6px;
  word-break: break-word;
}

.drawer-actions {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}
.drawer-actions .btn-icon {
  color: var(--text-secondary);
}
.drawer-actions .btn-icon:hover {
  background: var(--bg-card-hover);
  color: var(--text-primary);
}
.drawer-actions .btn-delete:hover { color: var(--danger); }

#lp-status-select {
  padding: 6px 10px;
  font-size: 13px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-input);
  color: var(--text-primary);
  cursor: pointer;
  flex: 1;
  min-width: 0;
}

.drawer-tabs {
  display: flex;
  gap: 0;
  border-bottom: 1px solid var(--border);
  padding: 0 20px;
  flex-shrink: 0;
}
.tab {
  padding: 10px 16px;
  border: none;
  background: transparent;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  transition: color var(--transition), border-color var(--transition);
}
.tab:hover { color: var(--text-primary); }
.tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

.tab-content {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 20px;
  min-height: 0;
}
.tab-content.hidden { display: none !important; }

/* Fields grid */
.fields-grid {
  display: flex;
  flex-direction: column;
  gap: 0;
}

.field-row {
  display: flex;
  align-items: center;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  gap: 12px;
  min-height: 42px;
}

.field-row:last-child {
  border-bottom: none;
}

.field-row label {
  width: 130px;
  min-width: 130px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  gap: 5px;
  flex-shrink: 0;
  margin: 0;
}

.field-value {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.field-display {
  font-size: 14px;
  color: var(--text-primary);
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.field-display a { color: var(--accent); }
.field-display a:hover { text-decoration: underline; }

.field-input {
  flex: 1;
  width: 100%;
  min-width: 0;
}

.btn-edit-field {
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 12px;
  padding: 4px 6px;
  border-radius: var(--radius-sm);
  /* Persistent affordance: a faint pencil at rest signals "you can edit here"
     at a glance; it goes full-opacity on row hover/focus. */
  opacity: 0.4;
  transition: opacity var(--transition), background var(--transition);
  flex-shrink: 0;
}
.btn-edit-field:hover { background: var(--bg-card-hover); color: var(--text-primary); }

.field-row:hover .btn-edit-field,
.field-row:focus-within .btn-edit-field,
.drawer-company:hover .btn-edit-field,
.drawer-company:focus-within .btn-edit-field { opacity: 1; }

/* "Nome trattativa" header block (layout B): eyebrow lime + prominent value.
   Scoped to .deal-name so ONLY this field is restyled — every other Dati row
   keeps its default label-beside-value layout. The inner markup is the generic
   .field-row[data-field="descrizione_breve"] (inline edit auto-wires); here we
   only change its look. */
/* Air above (≈16px with the .drawer-title flex gap:6px) detaches the title block
   from the status/#id row; a hair below (≈8px to the client name) keeps the deal
   name + client name reading as one cohesive title block. */
.deal-name { margin-top: 10px; margin-bottom: 0; }
/* Client name's margin-top is scoped to "follows the deal name" only — leads
   without a deal-name keep their h2 spacing unchanged. */
.deal-name + h2.drawer-company { margin-top: 2px; }
/* Stack the eyebrow on top of the value (default .field-row is side-by-side) and
   strip the data-row chrome (border / min-height / vertical padding). */
.deal-name .field-row {
  flex-direction: column;
  align-items: flex-start;
  gap: 6px;
  padding: 0;
  min-height: 0;
  border-bottom: none;
}
/* Title-sized like the section headers (.drawer-panel-title: 13px/800/0.06em),
   but kept lime (--brand-deep) to preserve the layout-B eyebrow identity. */
.deal-name .field-row > label {
  width: auto;
  min-width: 0;
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--brand-deep);
}
/* Once the deal name is filled, hide its eyebrow label — the value speaks for
   itself; the label + "Aggiungi…" prompt only show when the field is empty. */
.deal-name--filled .field-row > label { display: none; }
.deal-name .field-value { width: 100%; }
/* Value: prominent — the deal's title above the client name. Click-to-edit. */
.deal-name .field-display {
  font-size: 17px;
  font-weight: 600;
  color: var(--text-primary);
  line-height: 1.25;
  cursor: pointer;
}
/* Empty state: muted italic placeholder, clearly not a real value. */
.deal-name .field-display.deal-name-empty {
  color: var(--text-muted);
  font-style: italic;
  font-weight: 400;
}

/* Read-only treatment: muted text, no pencil, no control — for values the user
   can never change here (owner, creator, created/updated timestamps). */
.is-readonly { color: var(--text-muted); }

/* ── Drawer panels — soft depth via existing tokens (no new tokens, no hard
   shadows/gradients; tokens already adapt to dark mode). ─────────────────── */
.drawer-panel {
  background: var(--bg-card-hover);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 8px 14px;
  margin-top: 4px;
}
/* Uniform gap between stacked panels (Opzione A). Spacing comes from the card
   padding + this gap, replacing the old per-section margin/padding/border rules. */
.drawer-panel + .drawer-panel { margin-top: 12px; }
.drawer-panel-title {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-secondary);
  padding: 8px 0 4px;
}
/* Section head icon in the darkened brand lime (only the leading icon — a direct
   child — so the "+" inside .drawer-panel-action stays neutral). Slightly larger
   than the 11px title text for legibility (Tabler outline ignores font-weight). */
.drawer-panel-title > i { color: var(--brand-deep); font-size: 19px; }
/* A right-aligned action inside a panel title (Allegati "+" / Checklist counter). */
.drawer-panel-title .drawer-panel-action {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 6px;
}
/* "Sistema" (read-only): same shape, attenuated — dashed, flat, muted. A bit more
   detached than the +12 gap since it's the closing read-only panel. */
.drawer-panel--system {
  background: transparent;
  border-style: dashed;
  box-shadow: none;
  margin-top: 20px;
  padding-top: 6px;
}
.drawer-panel + .drawer-panel--system { margin-top: 20px; }
.drawer-panel--system .drawer-panel-title { color: var(--text-muted); }
/* Sistema stays fully muted — its lock icon is NOT lime. */
.drawer-panel--system .drawer-panel-title > i { color: var(--text-muted); }
.drawer-panel--system .ownership-row { margin-bottom: 8px; }

/* Refinements: bolder status pill in the header, more prominent value, and a
   small leading icon next to email/phone values. */
.drawer-title-row .status-pill {
  font-size: 12px;
  padding: 4px 12px;
  font-weight: 600;
}
.field-row[data-field="value"] .field-display {
  font-weight: 500;
  font-size: 15px;
}
.field-val-icon {
  color: var(--text-muted);
  font-size: 14px;
  flex-shrink: 0;
}

/* Follow-up + Notes + Ownership sections — separation now handled by the shared
   .drawer-panel card + .drawer-panel + .drawer-panel gap (Opzione A). */
.ownership-section h4,
.checklist-section h4 {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin: 0 0 12px;
}

/* ---- Checklist (sub-tasks) ---- */
.checklist-section h4 {
  display: flex;
  align-items: center;
  gap: 8px;
}
.checklist-counter {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: none;
  color: var(--text-secondary);
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 1px 8px;
}
.checklist-counter:empty { display: none; }

.checklist-add {
  display: flex;
  gap: 8px;
  margin-bottom: 10px;
}
.checklist-add input {
  flex: 1 1 auto;
  min-width: 0;
  border: 1px solid var(--border);
  background: var(--bg-input);
  color: var(--text-primary);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  font-size: 13px;
}
.checklist-add input:focus { outline: none; border-color: var(--border-focus); }

.checklist-list { display: flex; flex-direction: column; gap: 2px; }
.checklist-empty {
  font-size: 13px;
  color: var(--text-muted);
  padding: 8px 2px;
}
.checklist-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 8px;
  border-radius: var(--radius-sm);
}
.checklist-item:hover { background: var(--bg-card-hover); }
.checklist-check {
  flex: 0 0 auto;
  width: 16px;
  height: 16px;
  cursor: pointer;
  accent-color: var(--accent);
}
.checklist-text {
  flex: 1 1 auto;
  min-width: 0;
  font-size: 13px;
  color: var(--text-primary);
  cursor: text;
  word-break: break-word;
}
.checklist-item.done .checklist-text {
  text-decoration: line-through;
  color: var(--text-muted);
}
.checklist-edit {
  flex: 1 1 auto;
  min-width: 0;
  border: 1px solid var(--border-focus);
  background: var(--bg-input);
  color: var(--text-primary);
  border-radius: var(--radius-sm);
  padding: 5px 8px;
  font-size: 13px;
}
.checklist-edit:focus { outline: none; }
.checklist-del {
  flex: 0 0 auto;
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px;
  border-radius: 6px;
  opacity: 0;
  transition: opacity .12s, color .12s, background .12s;
}
.checklist-item:hover .checklist-del { opacity: 1; }
.checklist-del:hover { color: var(--danger); background: var(--danger-light); }
.checklist-del:focus-visible { opacity: 1; outline: 2px solid var(--accent); outline-offset: 1px; }

/* Attività (step 028): optional per-item due date — compact, fixed width.
   Scoped under .checklist-item so the selector (0,2,0) beats the global
   input[type="date"] rule (0,1,1) that otherwise forces width:100% +
   padding:8px 12px (which collapses the text to a vertical column). */
.checklist-item .checklist-due {
  flex: 0 0 138px;
  width: 138px;
  font-size: 12px;
  color: var(--text-secondary);
  border: 1px solid var(--border);
  background: var(--bg-input);
  border-radius: var(--radius-sm);
  padding: 3px 6px;
  font-variant-numeric: tabular-nums;
}
.checklist-item .checklist-due:focus { outline: none; border-color: var(--border-focus); }
.checklist-item.done .checklist-due { opacity: 0.6; }

/* Attività assignees — compact avatar chips + a per-row picker popover. The zone
   is fixed-width (flex:0 0 auto) so the text keeps flexing and the row stays on a
   single line next to the 138px date picker. position:relative anchors the panel. */
.checklist-assignees {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 4px;
  position: relative;
}
.assignee-avatars { display: inline-flex; align-items: center; }
/* Overlapping initials circles. */
.assignee-avatars .assignee-avatar + .assignee-avatar { margin-left: -6px; }
.assignee-avatar {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--accent);
  color: #ffffff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 9px;
  font-weight: 700;
  flex-shrink: 0;
  border: 1.5px solid var(--bg-card);
  box-sizing: border-box;
}
.assignee-avatar--more { background: var(--text-muted); }
.assignee-avatar--sm { width: 20px; height: 20px; font-size: 9px; border: none; }
.assignee-add {
  flex: 0 0 auto;
  background: none;
  border: 1px dashed var(--border);
  color: var(--text-muted);
  cursor: pointer;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  opacity: 0;
  transition: opacity .12s, color .12s, border-color .12s;
}
.checklist-item:hover .assignee-add,
.assignee-add:focus-visible { opacity: 1; }
/* Keep the trigger visible when the row already has assignees (so it's findable). */
.checklist-assignees .assignee-avatars:not(:empty) + .assignee-add { opacity: 1; }
.assignee-add:hover { color: var(--accent); border-color: var(--accent); }

/* Picker popover — anchored to the assignees zone, floats over the list. */
.assignee-panel {
  position: absolute;
  top: calc(100% + 4px);
  right: 0;
  z-index: 30;
  min-width: 180px;
  max-height: 240px;
  overflow-y: auto;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  padding: 4px;
}
.assignee-opt {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 6px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 13px;
  color: var(--text-primary);
}
.assignee-opt:hover { background: var(--bg-card-hover); }
.assignee-opt input { accent-color: var(--accent); cursor: pointer; flex: 0 0 auto; }
.assignee-opt-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.assignee-owner-tag { color: var(--text-muted); font-size: 11px; }
.assignee-empty { padding: 8px; color: var(--text-muted); font-size: 12px; }

/* Ownership rows — same label/value rhythm as the field rows */
.ownership-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
  flex-wrap: wrap;
}
.ownership-row:last-child { margin-bottom: 0; }
.ownership-label {
  width: 110px;
  min-width: 110px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-secondary);
}
.ownership-value { font-size: 13px; color: var(--text-primary); }
.ownership-row select { flex: 1; min-width: 160px; }
.checkbox-label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--text-primary);
  cursor: pointer;
  text-transform: none;
  letter-spacing: 0;
  font-weight: 400;
  margin: 0;
}
.checkbox-label input[type="checkbox"] {
  width: auto;
  margin: 0;
}
/* Add note + activity timeline */
.add-note-form {
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 4px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.add-note-form textarea { margin: 0; }
.add-note-form .btn-primary { align-self: flex-end; }

/* Notes tab (Feature B) — cascade of free-text notes, each with an optional date. */
.note-date-input { flex: 0 0 auto; width: 150px; font-size: 13px; }
/* Beat the global input[type="date"] rule (0,1,1) which forces width:100% +
   padding:8px 12px. (0,2,0) wins → compact 150px, height aligned to the btn-sm
   next to it. Covers both the add form and the inline-edit form (.comment-actions). */
.comment-actions .note-date-input {
  flex: 0 0 150px;
  width: 150px;
  padding: 5px 8px;
  font-size: 13px;
}
.notes-list { display: flex; flex-direction: column; gap: 10px; margin-top: 18px; }
.note-row {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
}
.note-row-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-height: 20px;
}
.note-date {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-secondary);
  font-variant-numeric: tabular-nums;
}
.note-actions { display: inline-flex; gap: 4px; margin-left: auto; }
.note-edit, .note-del {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px;
  border-radius: 6px;
  opacity: 0;
  transition: opacity .12s, color .12s, background .12s;
}
.note-row:hover .note-edit, .note-row:hover .note-del { opacity: 1; }
.note-edit:hover { color: var(--accent); background: var(--accent-light); }
.note-del:hover  { color: var(--danger); background: var(--danger-light); }
.note-body {
  font-size: 13px;
  color: var(--text-primary);
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
  margin-top: 4px;
}
.note-meta { font-size: 11px; color: var(--text-muted); margin-top: 6px; }
.note-edit-form { display: flex; flex-direction: column; gap: 8px; }
.note-edit-form textarea { margin: 0; }

.activity-timeline {
  display: flex;
  flex-direction: column;
  gap: 0;
  margin-top: 20px;
}
.activity-item {
  display: flex;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}
.activity-item:last-child { border-bottom: none; }
.activity-icon {
  font-size: 16px;
  flex-shrink: 0;
  width: 28px;
  text-align: center;
  line-height: 1.4;
}
.activity-body { flex: 1; min-width: 0; }
.activity-text {
  font-size: 13px;
  color: var(--text-primary);
  line-height: 1.5;
  word-break: break-word;
}
.activity-meta {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 3px;
}
.activity-arrow { color: var(--text-muted); margin: 0 2px; }

.status-pill {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 500;
  background: var(--bg-column);
  color: var(--text-secondary);
  margin: 0 2px;
}
.value-old,
.value-new {
  display: inline-block;
  font-size: 11px;
  font-weight: 600;
  padding: 1px 8px;
  border-radius: 20px;
  background: var(--bg-column);
  color: var(--text-secondary);
  margin: 0 2px;
  font-variant-numeric: tabular-nums;
}
.status-pill--new,
.value-new { background: var(--accent-light); color: var(--accent); }

/* Full-slug status pill colour variants (used by dashboard + follow-up table) */
.status-in-attesa-di-info  { background: var(--warning-light); color: var(--warning); }
.status-preventivo-inviato { background: var(--accent-light);  color: var(--accent);  }
.status-in-lavorazione     { background: var(--purple-light);  color: var(--purple);  }
.status-confermato         { background: var(--success-light); color: var(--success); }
.status-lead-ko            { background: var(--danger-light);  color: var(--danger);  }

/* Status pill as a clickable control (lead drawer header, Change 1). Reset the
   UA button chrome so it keeps the pill look, add an affordance on hover. */
button.status-pill {
  border: 0;
  cursor: pointer;
  font-family: var(--font);
  line-height: 1.4;
  transition: filter 0.12s ease, box-shadow 0.12s ease;
}
button.status-pill:hover { filter: brightness(0.96); }
button.status-pill:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}
button.status-pill[aria-expanded="true"] {
  box-shadow: 0 0 0 2px var(--accent);
}

/* Status picker popover — reuses .ms-panel; each row is a colored status chip. */
.status-pick-panel { min-width: 200px; }
.status-pick-opt {
  justify-content: space-between;
  gap: 10px;
}
.status-pick-opt .status-pill { pointer-events: none; }
.status-pick-opt.is-active { background: var(--bg-column); }
.status-pick-check {
  color: var(--accent);
  font-size: 15px;
  flex-shrink: 0;
}

/* Leading building icon before the client name in the drawer header (Change 3). */
.drawer-company-icon {
  color: var(--text-muted);
  font-size: 16px;
  flex-shrink: 0;
}

/* Meta info */
.meta-info {
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 11px;
  color: var(--text-muted);
}
.raw-payload {
  margin-top: 6px;
  font-size: 11px;
}
.raw-payload summary {
  cursor: pointer;
  color: var(--text-secondary);
  user-select: none;
  padding: 4px 0;
}
.raw-payload pre {
  background: var(--bg-column);
  padding: 10px;
  border-radius: var(--radius-sm);
  overflow: auto;
  max-height: 240px;
  font-size: 11px;
  margin: 6px 0 0;
}

/* Small button modifier */
.btn-sm { padding: 5px 10px; font-size: 12px; }

/* ============================================================
   Lead attachments
   ============================================================ */
/* .attachments-section separation now via .drawer-panel card + gap (Opzione A). */
/* Drag&drop highlight while files hover the zone */
.attachments-section.is-dragover {
  outline: 2px dashed var(--accent, #2563eb);
  outline-offset: 4px;
  border-radius: var(--radius-md, 8px);
  background: rgba(37, 99, 235, 0.06);
}
.attachments-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}
.attachments-header h4 {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 0;
}
.btn-attach {
  width: 28px;
  height: 28px;
  border-radius: var(--radius-sm);
  background: var(--bg-column);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 14px;
  color: var(--text-secondary);
  transition: all var(--transition);
}
.btn-attach:hover {
  background: var(--accent-light);
  color: var(--accent);
  border-color: var(--accent);
}
.attach-file-input { display: none; }

.attachments-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.attach-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px;
  background: var(--bg-column);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  transition: background var(--transition);
}
.attach-item:hover { background: var(--bg-input); }

.attach-preview {
  width: 48px;
  height: 48px;
  border-radius: 6px;
  overflow: hidden;
  flex-shrink: 0;
  cursor: pointer;
  background: var(--border);
}
.attach-preview img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: opacity var(--transition);
}
.attach-preview:hover img { opacity: 0.85; }

.attach-icon {
  width: 48px;
  height: 48px;
  border-radius: 6px;
  background: var(--accent-light);
  color: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  flex-shrink: 0;
}

.attach-info { flex: 1; min-width: 0; }
.attach-name {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.attach-meta {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 2px;
}

.attach-actions {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
}

.attach-empty {
  text-align: center;
  padding: 20px;
  color: var(--text-muted);
  font-size: 13px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}
.attach-loading {
  text-align: center;
  padding: 16px;
  color: var(--text-muted);
  font-size: 13px;
}
.attach-uploading {
  padding: 10px;
  background: var(--accent-light);
  border-radius: var(--radius-sm);
  color: var(--accent);
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.attach-error {
  text-align: center;
  padding: 16px;
  color: var(--danger);
  font-size: 13px;
}

/* Lightbox */
.attach-lightbox {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.85);
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: zoom-out;
  animation: notif-drop 0.15s ease;
}
.attach-lightbox img {
  max-width: 90vw;
  max-height: 90vh;
  object-fit: contain;
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
}
.attach-lightbox-close {
  position: fixed;
  top: 20px;
  right: 20px;
  color: white;
  font-size: 24px;
  cursor: pointer;
  background: rgba(0,0,0,0.5);
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ============================================================
   CSV Import wizard
   ============================================================ */

.import-modal {
  min-width: 560px;
  max-width: 720px;
}

.import-header {
  margin-bottom: 16px;
}
.import-header h3 {
  margin: 0;
  font-size: 18px;
  font-weight: 700;
  color: var(--text-primary);
}
.step-indicator {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 4px;
}

.import-hint {
  font-size: 13px;
  color: var(--text-secondary);
  margin: 0 0 16px;
  line-height: 1.5;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 18px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

/* Step 1 — upload */
.upload-zone {
  border: 2px dashed var(--border);
  border-radius: var(--radius-lg);
  padding: 40px;
  text-align: center;
  cursor: pointer;
  transition: border-color var(--transition), background var(--transition);
  background: var(--bg-input);
}
.upload-zone:hover,
.upload-zone.drag-over {
  border-color: var(--accent);
  background: var(--accent-light);
}
.upload-zone .upload-icon {
  font-size: 48px;
  margin-bottom: 12px;
  line-height: 1;
}
.upload-zone p { margin: 6px 0; color: var(--text-secondary); font-size: 14px; }
.upload-link {
  color: var(--accent);
  cursor: pointer;
  text-decoration: underline;
  font-weight: 500;
}
.upload-hint {
  font-size: 12px;
  color: var(--text-muted) !important;
  margin-top: 8px !important;
}

#file-preview .file-info {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  font-size: 13px;
  margin-bottom: 8px;
}
#file-preview .file-info #file-name { font-weight: 600; color: var(--text-primary); }
#file-preview .file-info #file-stats { color: var(--text-muted); font-size: 12px; }

.preview-table-wrap {
  overflow-x: auto;
  margin-top: 12px;
  max-height: 200px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}
.preview-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}
.preview-table th {
  background: var(--bg-column);
  padding: 6px 10px;
  text-align: left;
  font-weight: 600;
  border: 1px solid var(--border);
  white-space: nowrap;
  position: sticky;
  top: 0;
  z-index: 1;
}
.preview-table td {
  padding: 5px 10px;
  border: 1px solid var(--border);
  white-space: nowrap;
  max-width: 150px;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Step 2 — mapping */
.mapping-grid {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 360px;
  overflow-y: auto;
  padding-right: 4px;
}
.mapping-row {
  display: grid;
  grid-template-columns: 1fr 24px 1fr;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: var(--bg-input);
  border: 1px solid var(--border);
  transition: background var(--transition), border-color var(--transition);
}
.mapping-row.auto-mapped {
  border-color: var(--success);
  background: var(--success-light);
}
.col-preview { min-width: 0; }
.col-header {
  font-weight: 600;
  font-size: 13px;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.col-sample {
  font-size: 11px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.col-sample.muted { opacity: 0.7; }
.col-arrow {
  color: var(--text-muted);
  text-align: center;
  font-size: 16px;
}
.col-map-select { width: 100%; }

/* Step 3 — validation */
.validation-summary {
  display: flex;
  gap: 16px;
  justify-content: center;
  margin: 20px 0;
}
.val-stat {
  text-align: center;
  padding: 16px 24px;
  border-radius: var(--radius);
  background: var(--bg-column);
  flex: 1;
}
.val-stat.success .val-number { color: var(--success); }
.val-stat.warning .val-number { color: var(--warning); }
.val-stat.info    .val-number { color: var(--accent); }
.val-number {
  display: block;
  font-size: 32px;
  font-weight: 700;
  line-height: 1.1;
}
.val-label {
  display: block;
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 4px;
}

.error-rows-list {
  max-height: 180px;
  overflow-y: auto;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  margin-top: 8px;
}
.error-rows-list h4 {
  margin: 0 0 8px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.error-rows-list ul { margin: 0; padding-left: 18px; font-size: 12px; color: var(--text-secondary); line-height: 1.6; }
.error-rows-list li.muted { color: var(--text-muted); list-style: none; margin-left: -18px; }

.import-confirm-msg {
  text-align: center;
  padding: 16px;
  background: var(--accent-light);
  border-radius: var(--radius-sm);
  font-size: 14px;
  line-height: 1.6;
  margin-top: 16px;
  color: var(--text-primary);
}

/* Step 4 — progress + results */
.import-progress { padding: 20px 0; }
.progress-bar {
  height: 8px;
  background: var(--bg-column);
  border-radius: 4px;
  overflow: hidden;
  margin-bottom: 12px;
}
.progress-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 4px;
  transition: width 0.4s ease;
}
#progress-label {
  font-size: 13px;
  color: var(--text-secondary);
  text-align: center;
}

.import-results {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin: 20px 0;
}
.result-stat {
  padding: 14px 20px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  display: flex;
  align-items: center;
  gap: 10px;
}
.result-stat span {
  font-weight: 700;
  font-size: 20px;
}
.result-stat.success { background: var(--success-light); color: var(--success); }
.result-stat.warning { background: var(--warning-light); color: var(--warning); }
.result-stat.danger  { background: var(--danger-light);  color: var(--danger);  }
.result-stat .errors-list {
  background: var(--bg-card);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  margin-top: 6px;
  font-size: 12px;
  color: var(--text-primary);
  max-height: 160px;
  overflow-y: auto;
}

/* Responsive tweaks */
@media (max-width: 640px) {
  .import-modal { min-width: 0; }
  .validation-summary { flex-direction: column; gap: 8px; }
  .val-stat { padding: 12px 16px; }
}

/* ============================================================
   Dashboard view
   ============================================================ */

#view-dashboard {
  /* Scroll as a normal block. .view.active forces display:flex column (for the
     board); here that combined with the .dash-section { overflow:hidden } children
     (flex auto-min-size → 0) let the sections shrink to fit instead of overflowing,
     so overflow-y:auto never engaged and content below the fold was clipped by
     #app-main. The display:block override (restoring native block scrolling with
     overflow-y:auto + height:100% set here) is scoped to .active below, so when
     inactive the dashboard falls back to .view { display:none } like every other
     view and doesn't push settings/anagrafica below the fold. */
  padding: 24px;
  overflow-y: auto;
  height: 100%;
  background: var(--bg-app);
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

/* Specificity 1,1,0 beats .view.active (0,2,0); only the active dashboard renders
   as a block, inactive stays display:none via .view. */
#view-dashboard.active {
  display: block !important;
}

.dash-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 24px;
  gap: 16px;
  flex-wrap: wrap;
}
.dash-header h2 {
  font-size: 22px;
  font-weight: 700;
  color: var(--text-primary);
  margin: 0;
  letter-spacing: 0.2px;
}
/* Shared right-aligned toolbar controls cluster — keeps the dashboard and the
   calendar visually consistent (controls hug the top-right, wrap as a block).
   Neutral for the calendar: it already sat right via the toolbar's
   space-between, so margin-left:auto is redundant there and justify-end has no
   effect on a shrink-to-fit cluster. */
.view-toolbar-controls,
.dash-controls,
.calendar-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
  flex-wrap: wrap;
  justify-content: flex-end;
}

/* Dashboard filters on two rows (Proposta 1). Scoped override (0,2,0) so the
   SHARED cluster rule above (board table-toolbar + calendar) is NOT affected —
   only the dashboard's own .dash-controls becomes a full-width column of rows.
   Row1 = Periodo (presets + DAL/AL); Row2 = owner + client. */
.dash-header .dash-controls {
  width: 100%;
  margin-left: 0;
  flex-direction: column;
  align-items: stretch;
  justify-content: flex-start;
  gap: 10px;
}
.dash-filter-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
/* Dashboard uses the shared two-level .filter-bar, but it sits INSIDE the header
   (not below a toolbar like board/calendario). Give it a self-contained rounded
   card look instead of the full-bleed strip (border-bottom + heavy shadow). */
.dash-header .filter-bar {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}
.dash-header .dash-periodo { gap: 8px; }
.dash-header .dash-periodo .date-range-picker { flex-wrap: wrap; }
.dash-filter-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--text-secondary);
}
.dash-select {
  /* #11(A): aligned to the .filter-select 32px control system (board/anagrafica/
     calendario) so every bar matches. height + padding mirror .filter-select;
     min-width kept for the wider dashboard selects. */
  height: 32px;
  padding: 0 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 13px;
  background: var(--bg-card);
  color: var(--text-primary);
  cursor: pointer;
  outline: none;
  min-width: 180px;
}
.dash-select:hover { border-color: var(--accent); }
.dash-select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15); }

/* KPI grid — definitive rule lives at the bottom of this file */
.kpi-card {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  padding: 20px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  transition: transform var(--transition);
  min-width: 0;
}
.kpi-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow);
}
.kpi-card.success { border-top: 3px solid var(--success); }
.kpi-card.accent  { border-top: 3px solid var(--accent);  }
.kpi-card.warning { border-top: 3px solid var(--warning); }

.kpi-label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-secondary);
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  gap: 5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.kpi-value {
  font-size: 28px;
  font-weight: 700;
  letter-spacing: -0.5px;
  line-height: 1;
  margin-bottom: 6px;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-variant-numeric: tabular-nums;
}
.kpi-card.success .kpi-value { color: var(--success); }
.kpi-card.accent  .kpi-value { color: var(--accent);  }
.kpi-card.warning .kpi-value { color: var(--warning); }
.kpi-sub {
  font-size: 12px;
  font-weight: 400;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Charts grid */
.charts-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 16px;
  margin-bottom: 16px;
}
.chart-card {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  padding: 20px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  min-width: 0;
}
/* All cards same size — no wide override */
.chart-card.wide { grid-column: span 1; }
.chart-header { margin-bottom: 16px; }
.chart-header h3 {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  margin: 0;
}
.chart-header p {
  font-size: 12px;
  color: var(--text-muted);
  margin: 4px 0 0;
}
/* Dashboard bar charts (HTML/CSS, shared component "style B"). Bar colours are
   inline (owner / status-type / neutral); everything else is CSS-var driven so
   light and dark themes both render correctly. */
.dash-chart { display: flex; flex-direction: column; gap: 14px; }

/* Forecast · Pipeline aperta — hero total above the per-status breakdown. */
.forecast-hero {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 4px 10px;
  padding-bottom: 14px;
  margin-bottom: 14px;
  border-bottom: 1px solid var(--border);
}
.forecast-hero__value {
  font-size: 30px;
  font-weight: 700;
  line-height: 1;
  color: var(--text-primary);
  font-variant-numeric: tabular-nums;
}
.forecast-hero__sub { font-size: 14px; color: var(--text-muted); }
.dc-row { display: flex; flex-direction: column; gap: 5px; }
.dc-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.dc-meter { display: flex; align-items: center; gap: 10px; }
.dc-track {
  flex: 1;
  height: 14px;
  background: var(--bg-column);
  border-radius: 999px;
  overflow: hidden;
}
.dc-bar {
  height: 100%;
  min-width: 4px;
  border-radius: 999px;
  transition: width .3s ease;
}
.dc-value {
  flex-shrink: 0;
  min-width: 76px;
  text-align: right;
  font-size: 12px;
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1.2;
}
.dc-sub {
  display: block;
  font-size: 11px;
  font-weight: 500;
  color: var(--text-muted);
}
.dc-empty {
  padding: 24px;
  text-align: center;
  color: var(--text-muted);
  font-size: 13px;
}

/* Follow-up section */
.dash-section {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
  margin-bottom: 24px;
}
.section-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.section-header h3 {
  font-size: 14px;
  font-weight: 600;
  margin: 0;
  color: var(--text-primary);
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.data-table th {
  padding: 10px 16px;
  text-align: left;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-secondary);
  background: var(--bg-column);
  border-bottom: 1px solid var(--border);
}
.data-table td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: var(--bg-input); }
.data-table .text-muted { color: var(--text-muted); font-size: 11px; margin-top: 2px; }

.row-overdue td:first-child { border-left: 3px solid var(--danger);  }
.row-today   td:first-child { border-left: 3px solid var(--warning); }

/* Skeleton placeholders */
.skeleton-kpi   { height: 100px; border-radius: var(--radius-lg); }
.skeleton-chart { height: 220px; border-radius: var(--radius-lg); }

/* Empty + error states */
.empty-state {
  text-align: center;
  padding: 32px;
  color: var(--text-muted);
  font-size: 14px;
}
.error-state {
  text-align: center;
  padding: 40px;
  color: var(--danger);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}
.error-state p { margin: 0; }

/* Responsive */
@media (max-width: 768px) {
  .charts-grid { grid-template-columns: 1fr; }
}

/* ============================================================
   Settings view
   ============================================================ */

/* #view-settings, .settings-layout, .settings-nav, .settings-content
   are consolidated into a single !important block at the bottom of the file
   so they survive the .view.active overrides introduced for the kanban scroll
   fix. Item-level styles (.settings-nav-item*) stay here. */

.settings-nav-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 14px;
  border-radius: var(--radius-sm);
  border: none;
  background: transparent;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  text-align: left;
  width: 100%;
  transition: background var(--transition), color var(--transition);
}
.settings-nav-item:hover {
  background: var(--bg-column);
  color: var(--text-primary);
}
.settings-nav-item.active {
  background: var(--accent-light);
  color: var(--accent);
  font-weight: 600;
}

/* .settings-content moved to consolidated block at bottom of file. */
.settings-section { display: none; }
.settings-section.active {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.settings-card {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  padding: 28px;
  box-shadow: var(--shadow-sm);
  width: 100%;
}
.settings-card .data-table { width: 100%; }
.settings-card h3 {
  font-size: 15px;
  font-weight: 700;
  color: var(--text-primary);
  margin: 0 0 6px;
}
.settings-card h4 {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  margin: 18px 0 8px;
}

.card-desc {
  font-size: 13px;
  color: var(--text-secondary);
  margin: 0 0 20px;
  line-height: 1.5;
}
.card-header-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
  gap: 12px;
  flex-wrap: wrap;
}
.card-header-row h3 { margin: 0; }

/* Capability chips (role catalog) */
.chip-row { display: flex; flex-wrap: wrap; gap: 4px; }
.chip {
  display: inline-block;
  padding: 2px 8px;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-secondary);
  background: var(--bg-column);
  border: 1px solid var(--border);
  border-radius: 999px;
  white-space: nowrap;
}

.form-group { margin-bottom: 16px; }
.form-group label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.field-hint {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 5px;
}
.field-hint.danger { color: var(--danger); }

.input-readonly {
  background: var(--bg-column) !important;
  color: var(--text-muted);
  cursor: not-allowed;
}

.info-grid {
  display: flex;
  flex-direction: column;
}
.info-row {
  display: flex;
  justify-content: space-between;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}
.info-row:last-child { border-bottom: none; }
.info-row > span:first-child {
  color: var(--text-secondary);
  font-weight: 500;
}
/* Read-only project id + inline copy button (Informazioni sistema). */
.info-id-value {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}
.info-id-code {
  font-family: monospace;
  font-size: 13px;
  color: var(--text-primary);
  background: var(--bg-column);
  padding: 2px 8px;
  border-radius: var(--radius-sm);
}
.btn-copy-inline {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-secondary);
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 14px;
  transition: background var(--transition), color var(--transition), border-color var(--transition);
}
.btn-copy-inline:hover {
  background: var(--bg-card-hover);
  color: var(--text-primary);
}

/* Sortable list (statuses) */
.sortable-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 16px;
}
.sortable-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: grab;
  transition: border-color var(--transition), background var(--transition), opacity var(--transition);
}
.sortable-item:active { cursor: grabbing; }
.sortable-item.drag-over,
.sortable-item.is-dragging {
  border-color: var(--accent);
  background: var(--accent-light);
}
.sortable-item.is-dragging { opacity: 0.5; }
.drag-handle {
  color: var(--text-muted);
  font-size: 16px;
  cursor: grab;
  user-select: none;
}
.sortable-item input {
  flex: 1;
  min-width: 0; /* allow the input to shrink (default min-width:auto would keep
                   a long status name from compressing, pushing the X outside) */
  border: none;
  background: transparent;
  font-size: 14px;
  outline: none;
  padding: 0;
  color: var(--text-primary);
}
.sortable-item .status-type {
  flex: 0 0 auto;
  width: auto; /* override the global `select { width:100% }` (app.css:773) that
                  otherwise makes the type select fill the row and push the X out */
  font-size: 13px;
  padding: 4px 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-input);
  color: var(--text-primary);
  cursor: pointer;
}
/* Per-status colour: picker + "Automatico" (no chosen colour). */
.sortable-item .status-color {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex: 0 0 auto;
}
.status-color-input {
  width: 32px;
  height: 28px;
  padding: 2px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-input);
  cursor: pointer;
}
.status-color.is-auto .status-color-input { opacity: 0.4; }
.status-color-reset {
  border: 0;
  background: transparent;
  padding: 2px 4px;
  font-size: 12px;
  color: var(--text-muted);
  cursor: pointer;
}
.status-color-reset:hover { color: var(--text-primary); }
.status-color.is-auto .status-color-reset { color: var(--accent); font-weight: 600; }
.btn-remove-status {
  background: transparent;
  color: var(--danger);
  border-radius: var(--radius-sm);
  flex-shrink: 0;
}
.btn-remove-status:hover:not(:disabled) { background: var(--danger-light); }
.btn-remove-status:disabled { opacity: 0.35; cursor: not-allowed; }

.status-actions {
  display: flex;
  gap: 10px;
  margin-top: 8px;
  flex-wrap: wrap;
}

.settings-warning {
  margin-top: 16px;
  padding: 12px 16px;
  background: var(--warning-light);
  color: var(--warning);
  border-radius: var(--radius-sm);
  font-size: 12px;
  line-height: 1.6;
  border-left: 3px solid var(--warning);
}

/* Token box */
.token-box {
  padding: 10px 14px;
  background: var(--bg-column);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}
.token-box code {
  font-size: 13px;
  font-family: 'Courier New', ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  color: var(--text-secondary);
  word-break: break-all;
}

.btn-danger-soft {
  color: var(--danger) !important;
  border-color: var(--danger) !important;
  margin-top: 12px;
}
.btn-danger-soft:hover { background: var(--danger-light) !important; }

.code-block {
  background: #1e293b;
  color: #e2e8f0;
  padding: 16px;
  border-radius: var(--radius-sm);
  font-size: 12px;
  font-family: 'Courier New', ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  overflow-x: auto;
  line-height: 1.6;
  margin: 0;
  white-space: pre;
}
[data-theme="dark"] .code-block {
  background: #0f172a;
  color: #94a3b8;
}

/* Alerts */
.alert {
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  line-height: 1.5;
}
.alert.success { background: var(--success-light); color: var(--success); }
.alert.danger  { background: var(--danger-light);  color: var(--danger); }

/* Role badges */
.role-badge {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
}
.role-badge.role-super_admin { background: var(--warning-light); color: var(--warning); }
.role-badge.role-admin       { background: var(--accent-light);  color: var(--accent); }
.role-badge.role-client      { background: var(--bg-column);     color: var(--text-secondary); }
.role-badge.role-viewer      { background: var(--bg-column);     color: var(--text-muted); }

/* SSO provenance badge (colonna "Accesso" della tabella utenti) */
.sso-badge {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
}
.sso-badge-microsoft { background: var(--accent-light); color: var(--accent); }
.sso-badge-local     { background: var(--bg-column);    color: var(--text-secondary); }

/* User row + status dot */
.row-disabled td { opacity: 0.5; }
.status-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-right: 5px;
  vertical-align: middle;
  background: var(--text-muted);
}
.status-dot.active   { background: var(--success); }
.status-dot.inactive { background: var(--text-muted); }

.action-buttons {
  display: flex;
  gap: 4px;
}
.action-buttons .btn-icon {
  color: var(--text-secondary);
  width: 28px;
  height: 28px;
  font-size: 13px;
}
.action-buttons .btn-icon:hover { background: var(--bg-column); color: var(--text-primary); }

/* Project assignments — extension to the spec's basic Users section */
.assignment-block {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  margin-bottom: 10px;
  background: var(--bg-input);
}
.assignment-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
  flex-wrap: wrap;
}
.assignment-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.assignment-row {
  display: grid;
  grid-template-columns: 1fr auto 32px;
  align-items: center;
  gap: 10px;
  padding: 6px 10px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 13px;
}
.assignment-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Modal header used by lbModal title in user/project forms */
.modal-header { margin-bottom: 16px; }
.modal-header h3 {
  font-size: 16px;
  font-weight: 700;
  margin: 0;
  color: var(--text-primary);
}

/* Responsive — .settings-layout / .settings-nav are consolidated at the
   bottom of the file; only .settings-nav-item size tweaks remain here. */
@media (max-width: 768px) {
  .settings-nav-item {
    padding: 7px 12px;
    font-size: 12px;
  }
}

/* ============================================================
   Polish: page loader, quick search, hamburger, empty states
   ============================================================ */

/* Top loading bar */
#page-loader {
  position: fixed;
  top: 0;
  left: 0;
  height: 3px;
  width: 0%;
  background: var(--accent);
  z-index: 9999;
  transition: width 0.3s ease, opacity 0.3s ease;
  box-shadow: 0 0 8px rgba(37, 99, 235, 0.6);
  pointer-events: none;
}

/* Quick search */
.nav-search {
  flex: 1;
  max-width: 280px;
  margin: 0 16px;
  display: flex;
  align-items: center;
}
.search-input {
  width: 100%;
  padding: 7px 14px;
  background: var(--bg-column);
  border: 1px solid var(--border);
  border-radius: 20px;
  color: var(--text-primary);
  font-size: 13px;
  outline: none;
  transition: background 0.2s, box-shadow 0.2s, border-color 0.2s;
  font-family: inherit;
}
.search-input::placeholder { color: var(--text-muted); }
.search-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.15);
}
[data-theme="dark"] .search-input {
  background: rgba(255, 255, 255, 0.08);
  border: none;
  color: var(--text-white);
}
[data-theme="dark"] .search-input::placeholder { color: rgba(255, 255, 255, 0.4); }
[data-theme="dark"] .search-input:focus {
  background: rgba(255, 255, 255, 0.15);
  box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.2);
}
[data-theme="dark"] .search-input:focus::placeholder { color: rgba(255, 255, 255, 0.55); }

/* Cards filtered out by quick search are removed from layout */
.lead-card.search-hidden { display: none !important; }

/* ============================================
   HAMBURGER BUTTON
   ============================================ */

.hamburger-btn {
  display: none;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 5px;
  width: 36px;
  height: 36px;
  background: transparent;
  border: none;
  cursor: pointer;
  padding: 4px;
  border-radius: var(--radius-sm);
  flex-shrink: 0;
}

.hamburger-btn:hover {
  background: var(--bg-column);
}

.hamburger-line {
  display: block;
  width: 20px;
  height: 2px;
  background: var(--navbar-text);
  border-radius: 2px;
  transition: all 0.25s ease;
  transform-origin: center;
}

/* Hamburger -> X animation */
.hamburger-btn.open .hamburger-line:nth-child(1) {
  transform: translateY(7px) rotate(45deg);
}
.hamburger-btn.open .hamburger-line:nth-child(2) {
  opacity: 0;
  transform: scaleX(0);
}
.hamburger-btn.open .hamburger-line:nth-child(3) {
  transform: translateY(-7px) rotate(-45deg);
}

/* ============================================
   MOBILE OVERLAY
   ============================================ */

.mobile-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.5);
  backdrop-filter: blur(3px);
  z-index: 400;
  opacity: 0;
  transition: opacity 0.25s ease;
  pointer-events: none;
}

.mobile-overlay.open {
  opacity: 1;
  pointer-events: auto;
}

/* ============================================
   MOBILE SIDEBAR
   ============================================ */

.mobile-sidebar {
  position: fixed;
  top: 0;
  left: 0;
  width: 280px;
  height: 100vh;
  height: 100dvh;
  background: var(--bg-card);
  border-right: 1px solid var(--border);
  box-shadow: var(--shadow-lg);
  z-index: 401;
  transform: translateX(-100%);
  transition: transform 0.28s cubic-bezier(0.4, 0, 0.2, 1);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
}

.mobile-sidebar.open {
  transform: translateX(0);
}

/* Sidebar header */
.mobile-sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.mobile-sidebar-logo {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 17px;
  font-weight: 700;
  color: var(--text-primary);
}

/* Sidebar sections */
.mobile-sidebar-section {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}

.mobile-section-label {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 10px;
}

/* Mobile project select */
.mobile-project-select {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-input);
  color: var(--text-primary);
  font-size: 14px;
  font-family: var(--font);
  outline: none;
}

/* Mobile nav items */
.mobile-nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.mobile-nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 14px;
  border: none;
  background: transparent;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 500;
  color: var(--text-secondary);
  cursor: pointer;
  text-align: left;
  width: 100%;
  transition: all var(--transition);
}

.mobile-nav-item:hover {
  background: var(--bg-column);
  color: var(--text-primary);
}

.mobile-nav-item.active {
  background: var(--accent-light);
  color: var(--accent);
  font-weight: 600;
}

.mobile-nav-item .ti {
  font-size: 18px;
  flex-shrink: 0;
}

/* Sidebar footer */
.mobile-sidebar-footer {
  margin-top: auto;
  padding: 16px 20px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 12px;
  flex-shrink: 0;
}

.mobile-user-info {
  display: flex;
  align-items: center;
  gap: 12px;
}

.mobile-user-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--accent);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 700;
  flex-shrink: 0;
}

.mobile-user-name {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
}

.mobile-user-role {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 1px;
}

.mobile-sidebar-actions {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.mobile-action-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 14px;
  border: none;
  background: transparent;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  cursor: pointer;
  text-align: left;
  width: 100%;
  transition: all var(--transition);
}

.mobile-action-btn:hover {
  background: var(--bg-column);
  color: var(--text-primary);
}

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

.mobile-action-btn.danger:hover {
  background: var(--danger-light);
}

/* Board-level empty state */
.board-empty-state {
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 10px;
  color: var(--text-primary);
  padding: 40px 20px;
  background: var(--bg-app);
}
.board-empty-state h3 {
  margin: 12px 0 0;
  font-size: 20px;
  font-weight: 700;
  color: var(--text-primary);
}
.board-empty-state p {
  margin: 0;
  font-size: 14px;
  color: var(--text-secondary);
  max-width: 380px;
}
.board-empty-state .btn-primary { margin-top: 16px; padding: 10px 20px; }

/* Dashboard empty state */
.dash-empty {
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 10px;
  color: var(--text-secondary);
  padding: 60px 20px;
}
.dash-empty h3 {
  margin: 12px 0 0;
  font-size: 20px;
  font-weight: 700;
  color: var(--text-primary);
}
.dash-empty p {
  margin: 0;
  font-size: 14px;
  color: var(--text-secondary);
  max-width: 380px;
}
.dash-empty .btn-primary { margin-top: 16px; padding: 10px 20px; }

/* Drawer header — split source badge + status pill on the same row */
.drawer-title-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

/* ============================================
   RESPONSIVE - hide/show elements
   ============================================ */

@media (max-width: 768px) {

  /* Hide everything tagged desktop-only */
  .desktop-only {
    display: none !important;
  }

  /* Show hamburger */
  .hamburger-btn {
    display: flex !important;
  }

  /* Show overlay (still kept off-screen until .open) */
  .mobile-overlay {
    display: block;
  }

  /* Compact navbar; spread hamburger/logo and right-side actions */
  #navbar {
    padding: 0 12px;
    justify-content: space-between;
  }

  /* Reset action-group separator on mobile */
  .nav-actions {
    padding-left: 0;
    margin-left: 0;
    border-left: none;
    gap: 4px;
  }

  /* Drop the inline project-name divider on mobile to keep navbar tight */
  .nav-project-name {
    border-left: none;
    padding-left: 0;
    margin-left: 0;
  }

  /* Kanban horizontal scroll on mobile */
  #kanban-wrapper {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .kanban-column {
    min-width: 260px;
  }

  /* Floating button */
  #btn-floating-add {
    bottom: 20px;
    right: 16px;
  }

  /* board empty state shrinks gracefully */
  .board-empty-state h3 { font-size: 18px; }
}

/* -------- Toast -------- */
#toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}
.toast {
  background: #0f172a;
  color: #ffffff;
  padding: 10px 16px;
  border-radius: var(--radius);
  font-size: 13px;
  box-shadow: var(--shadow);
  animation: slide-up 0.2s ease;
  min-width: 200px;
  pointer-events: auto;
}
[data-theme="dark"] .toast {
  background: #1e293b;
  color: #f1f5f9;
  border: 1px solid var(--border);
}
.toast.success { border-left: 3px solid var(--success); }
.toast.error   { border-left: 3px solid var(--danger);  }
.toast.is-leaving { animation: fade-out 0.18s ease forwards; }

/* Toast with an inline action (e.g. "Annulla" after a soft-delete). The toast
   background is dark in both themes, so the action uses a fixed light accent. */
.toast.toast-action {
  display: flex;
  align-items: center;
  gap: 14px;
}
.toast-action__msg { flex: 1 1 auto; }
.toast-action__btn {
  flex: 0 0 auto;
  background: transparent;
  border: none;
  color: #7dd3fc;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  padding: 2px 4px;
  border-radius: 6px;
  text-decoration: underline;
}
.toast-action__btn:hover { color: #bae6fd; }
.toast-action__btn:focus-visible { outline: 2px solid #7dd3fc; outline-offset: 2px; }

/* ------ Cestino (trash) modal ------ */
.trash-box { max-width: 560px; width: 100%; text-align: left; }
.trash-hint {
  margin: 4px 0 14px;
  font-size: 13px;
  color: var(--text-secondary);
}
.trash-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 60vh;
  overflow-y: auto;
}
.trash-empty {
  padding: 28px 12px;
  text-align: center;
  color: var(--text-secondary);
  font-size: 13px;
}
.trash-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  background: var(--bg-card-hover);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}
.trash-row__main {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}
.trash-row__title {
  font-weight: 600;
  font-size: 14px;
  color: var(--text-primary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.trash-row__sub {
  font-size: 12px;
  color: var(--text-secondary);
}
.trash-row__status {
  font-size: 11px;
  color: var(--text-secondary);
  margin-top: 2px;
}
.trash-row__actions {
  display: flex;
  gap: 8px;
  flex: 0 0 auto;
}
@media (max-width: 560px) {
  .trash-row { flex-direction: column; align-items: stretch; }
  .trash-row__actions { justify-content: flex-end; }
}

@keyframes slide-up {
  from { transform: translateY(8px); opacity: 0; }
  to   { transform: translateY(0); opacity: 1; }
}
@keyframes fade-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}
@keyframes fade-out {
  from { opacity: 1; transform: translateY(0); }
  to   { opacity: 0; transform: translateY(-4px); }
}
@keyframes modal-pop {
  from { opacity: 0; transform: scale(0.96); }
  to   { opacity: 1; transform: scale(1); }
}

/* -------- Placeholders for stub views -------- */
.view-placeholder {
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  font-size: 14px;
  background: var(--bg-app);
}
.view-placeholder__inner {
  background: var(--bg-card);
  padding: 32px 40px;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  color: var(--text-secondary);
  text-align: center;
}

/* -------- Responsive: stack columns vertically below 768px -------- */
@media (max-width: 768px) {
  .drawer { width: 100vw; }
  .modal-box { min-width: 0; }
}

/* ---------- Locked sortable items (statuses & sources) ---------- */
.sortable-item[data-locked="true"] {
  background: var(--bg-column);
  border-style: dashed;
}
.sortable-item[data-locked="true"] input {
  color: var(--text-secondary);
  cursor: default;
}
.lock-icon {
  font-size: 14px;
  color: var(--text-secondary);
  padding: 0 6px;
  flex-shrink: 0;
}

/* ---------- Fields config ---------- */
.fields-config-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 16px;
}
.field-config-row {
  display: grid;
  grid-template-columns: 56px 1fr 1.2fr;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}
.field-config-toggle { display: flex; justify-content: center; }
.field-config-name { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.field-original-name { font-weight: 600; color: var(--text-primary); font-size: 14px; }
.field-original-key {
  font-size: 11px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color: var(--text-muted);
}
.field-config-rename input {
  width: 100%;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-card);
  color: var(--text-primary);
  font-size: 13px;
}
.field-config-rename input:focus { outline: none; border-color: var(--accent); }

/* Toggle switch */
.toggle-label {
  position: relative;
  display: inline-block;
  width: 38px;
  height: 22px;
  cursor: pointer;
}
.toggle-label input { opacity: 0; width: 0; height: 0; }
.toggle-slider {
  position: absolute; inset: 0;
  background: var(--border);
  border-radius: 999px;
  transition: background var(--transition);
}
.toggle-slider::before {
  content: "";
  position: absolute;
  width: 16px; height: 16px;
  left: 3px; top: 3px;
  background: #fff;
  border-radius: 50%;
  transition: transform var(--transition);
  box-shadow: 0 1px 2px rgba(0,0,0,0.2);
}
.toggle-label input:checked + .toggle-slider { background: var(--accent); }
.toggle-label input:checked + .toggle-slider::before { transform: translateX(16px); }

.inline-check {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  cursor: pointer;
}
.inline-check input { width: auto; }

/* ---------- Custom fields list ---------- */
.custom-field-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  margin-top: 8px;
}
.cf-info { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.cf-meta {
  font-size: 12px;
  color: var(--text-secondary);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
.cf-actions { display: flex; gap: 6px; flex-shrink: 0; }
.btn-edit-cf:hover { background: var(--accent-light); color: var(--accent); }
.btn-delete-cf { color: var(--danger); }
.btn-delete-cf:hover { background: var(--danger-light); }

@media (max-width: 720px) {
  .field-config-row {
    grid-template-columns: 44px 1fr;
    grid-template-rows: auto auto;
  }
  .field-config-rename { grid-column: 1 / -1; }
}

/* ---------- Unified fields list (Impostazioni → Campi, lotto 6a) ----------
   Own flex layout: the legacy .field-config-row grid (3 fixed columns) and
   the .sortable-item input overrides (border:none, flex:1) must never apply
   to these rows. */
.field-cfg-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}
.field-cfg-row .drag-handle         { flex: 0 0 auto; }
.field-cfg-row .field-config-toggle { flex: 0 0 auto; justify-content: center; }
.field-cfg-row .field-config-name   { flex: 1 1 auto; min-width: 0; }
.field-cfg-actions {
  margin-left: auto;
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 6px;
}
.field-cfg-actions .btn-icon { flex: 0 0 auto; white-space: nowrap; }
.field-cfg-actions .cf-meta  { white-space: nowrap; }
/* Rename input: fixed width, real border — beats `.sortable-item input`
   (border:none, transparent, flex:1) by specificity. */
.field-cfg-row .field-cfg-actions .field-rename-input {
  flex: none;
  width: 200px;
  min-width: 0;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-card);
  color: var(--text-primary);
  font-size: 13px;
}
.field-cfg-row .field-cfg-actions .field-rename-input:focus {
  outline: none;
  border-color: var(--accent);
}
@media (max-width: 720px) {
  .field-cfg-row { flex-wrap: wrap; }
  .field-cfg-actions { margin-left: 0; flex: 1 1 100%; }
  .field-cfg-row .field-cfg-actions .field-rename-input { width: 100%; flex: 1 1 auto; }
}

/* ---------- Board toolbar (top row, view toggle right-aligned) ---------- */
.board-toolbar {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  padding: 10px 20px;
  background: var(--bg-card);
  /* First row of the unified white toolbar: hairline divider only, no bottom
     shadow (the shadow lives under the last row). */
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  position: relative;
  z-index: 2;
}

/* ---------- Filter bar (second row, all left-aligned) ---------- */
.filter-bar {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 8px;
  padding: 10px 20px;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  flex-wrap: wrap;
  /* Elevated toolbar block (filter-bar + tag-filter-row). z-index lifts it
     over the board (a later sibling) so the bottom shadow stays visible, over
     .tag-filter-row, AND — in Tabella — over the table-view sticky header cells
     (.leads-table th, z-index:10) which would otherwise paint over the bar and
     its open dropdowns. The status/owner/etichette dropdowns (.ms-panel, z:50)
     live inside this bar's stacking context, so they ride this value and open
     ABOVE the sticky header. 20 stays well below navbar/drawer (z >= 50).
     (Supersedes the per-view .anag-view .filter-bar override, now redundant.) */
  position: relative;
  z-index: 20;
  box-shadow: 0 3px 10px -6px rgba(16,24,40,.22);
}

.filter-group {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

/* Filter inputs */
.filter-input,
.filter-select {
  height: 32px;
  padding: 0 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-input);
  color: var(--text-primary);
  font-size: 13px;
  font-family: var(--font);
  outline: none;
  transition: border-color var(--transition);
}
.filter-input:focus,
.filter-select:focus {
  border-color: var(--border-focus);
}

/* Clear button */
#btn-clear-filters {
  margin-left: 4px;
  height: 32px;
  white-space: nowrap;
}

.filter-arrow { color: var(--text-muted); font-size: 13px; }

/* Filter count badge */
.filter-count {
  font-size: 12px;
  color: var(--accent);
  font-weight: 600;
  padding: 3px 10px;
  background: var(--accent-light);
  border-radius: 20px;
  white-space: nowrap;
}

/* Small caption preceding a date range */
.filter-range-label {
  font-size: 11px;
  color: var(--text-muted);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .03em;
}

/* ---------- Multi-select dropdown (status / owner) ---------- */
.ms-dropdown { position: relative; }
.ms-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  min-width: 110px;
  justify-content: space-between;
}
.ms-toggle .ti { font-size: 14px; color: var(--text-muted); }
.ms-toggle.has-sel {
  border-color: var(--accent);
  color: var(--accent);
}
.ms-panel {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  z-index: 50;
  min-width: 200px;
  max-height: 280px;
  overflow-y: auto;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  padding: 6px;
}
.ms-panel.hidden { display: none; }
.ms-opt {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 6px 8px;
  border-radius: var(--radius-sm);
  /* Rows are often <button>s (project/views/overflow menus) — reset the UA grey
     button chrome so the panel rows read as clean menu items. */
  border: 0;
  background: transparent;
  text-align: left;
  font-size: 13px;
  font-family: var(--font);
  color: var(--text-primary);
  cursor: pointer;
  white-space: nowrap;
}
.ms-opt:hover { background: var(--bg-column); }
.ms-opt input { cursor: pointer; }
.ms-empty { padding: 8px; font-size: 12px; color: var(--text-muted); }

/* ---------- Advanced (custom field) filters ---------- */
.advanced-filters-wrap {
  padding: 0 20px;
  flex-shrink: 0;
}
.adv-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 8px;
  background: none;
  border: 1px dashed var(--border);
  border-radius: var(--radius-sm);
  padding: 5px 10px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  cursor: pointer;
}
.adv-toggle:hover { border-color: var(--accent); color: var(--accent); }
.adv-count {
  background: var(--accent);
  color: #fff;
  border-radius: 20px;
  padding: 0 6px;
  font-size: 11px;
  min-width: 16px;
  text-align: center;
}
.advanced-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 16px;
  padding: 10px 0 2px;
}
.adv-filter-row {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.adv-filter-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
}
.adv-filter-row .cf-input { width: 150px; }
.adv-filter-row .cf-range { width: 92px; }

/* ==========================================================================
   Shared two-level filter bar (BEM) — Fase B
   --------------------------------------------------------------------------
   A reusable family layered ON TOP of the existing `.filter-bar` strip, so the
   Board, Calendario and Dashboard can share one look. It is additive and
   backward-compatible: `.filter-bar__row` is a full-width flex child, so rows
   STACK inside the wrapping `.filter-bar` without altering the base rule —
   legacy single-row `.filter-bar` usages (calendario/anagrafica) are unaffected
   until they opt in. All sizing uses the app tokens (spacing/border/radius).
   ========================================================================== */

/* A row of filters. flex-basis:100% forces each row onto its own line inside
   the wrapping `.filter-bar`, so multiple rows stack vertically. */
.filter-bar__row {
  flex: 1 1 100%;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  min-width: 0;
}

/* A single control (select / input / multiselect) with UNIFORM width. Never
   stretches (flex:0 0 auto) — fixes the "Attività stirato" case. The inner
   native control fills the group so every control is the same width. */
.filter-bar__control { flex: 0 0 auto; min-width: 160px; }
.filter-bar__control--wide { min-width: 200px; }   /* cliente: un filo più largo */
.filter-bar__control > .filter-select,
.filter-bar__control > .filter-input,
.filter-bar__control.ms-dropdown .ms-toggle { width: 100%; }
/* Customer lookup fills its (wide) control group so it reads as one uniform
   control; the results panel (.cl-panel) stays anchored under the input via
   .cl-wrap's position:relative, so it never floats over the bar. */
.filter-bar__control .ms-lookup,
.filter-bar__control .dash-lookup,
.filter-bar__control .cl-wrap { width: 100%; }
/* The lookup <input> carries .field-input{min-width:0}, so in a tight flex row
   the whole chain (input → .cl-wrap → .ms-lookup) can shrink to width:0 and the
   customer filter disappears. Floor the input itself (0,2,0 beats .field-input
   0,1,0) so it — and its container — can NEVER collapse below a readable width,
   independent of the width:100% chain above. Scoped to the filter bar only, so
   the lead-card / dashboard lookups are untouched. */
.filter-bar__control .cl-input { min-width: 180px; }
/* Date inputs: compact. The global `input[type="date"]{width:100%}` rule
   (app.css ~857, specificity 0,1,1) would otherwise stretch these to full width
   and blow out the advanced row — so the width lives on an `input.` selector
   (0,1,1, later in the cascade → wins the tie). Mirrors the existing
   `.comment-actions .note-date-input` fix. */
.filter-bar__control--date { flex: 0 0 auto; min-width: 0; }
input.filter-bar__control--date { width: 150px; }

/* Uniform filter label / caption. */
.filter-bar__label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

/* Right-aligned actions group (Pulisci + count). */
.filter-bar__actions {
  margin-left: auto;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

/* Row 2 — "Filtri avanzati" collapsible. Full-width so it sits on its own line
   under the primary row; no horizontal padding (the parent .filter-bar already
   pads). Reuses the .hidden toggle mechanism. */
.filter-bar__advanced-wrap { flex: 1 1 100%; }
.filter-bar__advanced-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: none;
  border: 1px dashed var(--border);
  border-radius: var(--radius-sm);
  padding: 5px 10px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  cursor: pointer;
  transition: border-color var(--transition), color var(--transition);
}
.filter-bar__advanced-toggle:hover { border-color: var(--accent); color: var(--accent); }
.filter-bar__advanced {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 16px;
  padding-top: 10px;
}
.filter-bar__advanced.hidden { display: none; }

/* Chip group + chip (etichette). Values mirror .filter-tag-btn so a chip
   carrying BOTH classes looks identical, and pages using only the new class
   get the same look. */
.filter-bar__chips {
  display: inline-flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
}
.filter-bar__chip {
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 500;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--transition);
}
.filter-bar__chip:hover { border-color: var(--accent); color: var(--accent); }
.filter-bar__chip.active { font-weight: 600; }

/* ==========================================================================
   Token filter bar (redesign — "Filtri CRM" opzione 1a)
   --------------------------------------------------------------------------
   Single-row bar that replaces the old primary selector row + the ETICHETTE
   band on the Kanban board. Every active filter is a removable TOKEN derived
   from _deriveTokens(); "+ Filtro" adds one, "⇅ Avanzati" drives the existing
   collapsible panel, the ⋯ menu holds Esporta CSV / Archivio. Structural
   surfaces use the app theme vars (dark-mode aware); the selection accent uses
   the spec's blue palette with a dark override at the bottom.
   Desktop (≥1024px) is the target; below that the row simply wraps (the
   dedicated mobile sheet is a later slice).
   ========================================================================== */

.filter-bar--tokenbar { padding: 12px 20px; }

/* The bar row itself. Reuses .filter-bar for stacking (z-index/shadow) + the
   20px horizontal padding; this is its own full-width flex row. */
.tokenbar {
  position: relative;         /* anchor for the floating editor layer */
  flex: 1 1 100%;
  display: flex;
  flex-direction: column;     /* two stacked rows: actions, then filters */
  gap: 10px;
  min-width: 0;
}
/* Each row: a left cluster + a right cluster pinned to the right edge.
   align-items:flex-start so the right cluster stays pinned top when the left
   grows taller (row 2 tokens wrapping onto multiple lines). */
.tkn-row {
  display: flex;
  align-items: center;        /* vertically center every control in the row */
  gap: 10px;
  min-height: 34px;           /* consistent row height even when a side is text-only */
}
.tkn-row-left {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 0 1 auto;
  min-width: 0;
}
.tkn-row-right {
  margin-left: auto;          /* pin to the right edge */
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 10px;
}
/* Row 2 left: tokens + "+ Filtro". Wraps onto extra lines as tokens accumulate;
   the count + Pulisci stay pinned top-right. */
.tkn-row--filters .tkn-left {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
}
/* Fixed left pieces (Viste + "+ Filtro") never shrink. */
.tkn-viste,
.tkn-add { flex: 0 0 auto; }

/* Generic bar button (Viste / +Filtro / Avanzati / Salva vista). */
.tkn-btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  height: 34px;
  padding: 0 12px;
  border: 1px solid var(--border);
  background: var(--bg-card);
  border-radius: 8px;
  font-size: 13.5px;
  font-family: var(--font);
  color: var(--text-primary);
  cursor: pointer;
  white-space: nowrap;
  transition: background var(--transition), border-color var(--transition), color var(--transition);
}
.tkn-btn:hover { background: var(--bg-card-hover); }
.tkn-btn .tkn-caret,
.tkn-btn .ti-chevron-down { font-size: 14px; color: var(--text-muted); }
.tkn-btn--dashed {
  padding: 0 13px;
  border-style: dashed;
  background: transparent;
  color: var(--text-secondary);
}
.tkn-btn--dashed:hover { border-color: var(--accent); color: var(--accent); background: transparent; }

/* Tokens container: tokens WRAP onto additional lines instead of scrolling
   horizontally (row-gap keeps wrapped rows tidy). Sits inside .tkn-left. */
.tkn-tokens {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.tkn-count {
  /* Same box + centering as .tkn-clear so the monospace count and the underlined
     "Pulisci" sit on the same vertical line (their font metrics differ). */
  display: inline-flex;
  align-items: center;
  height: 34px;
  line-height: 1;
  font-family: var(--font-mono, ui-monospace, "SFMono-Regular", "IBM Plex Mono", Menlo, monospace);
  font-size: 12.5px;
  color: var(--text-muted);
  white-space: nowrap;
}

/* ---- Active token ---- One clean pill: "Stato: Nuova Lead +3 ▾ ×". The
   clickable body reopens the editor; the × removes just that dimension. */
.tkn-token {
  flex: 0 0 auto;             /* never shrink inside the scrolling tokens row */
  display: inline-flex;
  align-items: stretch;
  height: 34px;
  border: 1px solid var(--tkn-accent-border, #c7d7fb);
  background: var(--tkn-accent-bg, #eef3ff);
  border-radius: 8px;
  overflow: hidden;
  white-space: nowrap;
}
.tkn-token__body {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 100%;
  padding: 0 4px 0 11px;
  border: 0;
  background: transparent;
  font-size: 13.5px;
  font-family: var(--font);
  cursor: pointer;
  white-space: nowrap;
  transition: background var(--transition);
}
.tkn-token__body:hover { background: var(--tkn-accent-hover, #e2ebff); }
.tkn-token__key  { color: var(--tkn-accent-key, #5f7196); }
.tkn-token__val  { color: var(--tkn-accent-text, #1b3fa0); font-weight: 600; }
.tkn-token__caret { font-size: 11px; color: var(--tkn-accent-caret, #8ba0c9); }
.tkn-token__x {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  width: 26px;
  border: 0;
  background: transparent;
  color: var(--tkn-accent-x, #7f93bd);
  font-size: 15px;
  line-height: 1;
  cursor: pointer;
  transition: background var(--transition), color var(--transition);
}
.tkn-token__x:hover { background: var(--tkn-accent-xhover, #dbe6ff); color: var(--tkn-accent-text, #1b3fa0); }

/* ---- Pulisci ---- */
.tkn-clear {
  display: inline-flex;
  align-items: center;
  height: 34px;
  line-height: 1;
  padding: 0 8px;
  border: 0;
  background: transparent;
  font-size: 13px;
  font-family: var(--font);
  color: var(--text-muted);
  text-decoration: underline;
  cursor: pointer;
}
.tkn-clear:hover { color: var(--text-primary); }
.tkn-clear.hidden,
.tkn-save.hidden { display: none; }

/* "Salva vista" — a real, clearly readable bordered button (README §1.9), not
   faint text. Explicit here (over the shared .tkn-btn base) so it always reads as
   a button. */
.tkn-save {
  height: 34px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg-card);
  font-size: 13.5px;
  color: var(--text-primary);
}
.tkn-save:hover { background: var(--bg-card-hover); }

/* ---- ⋯ overflow icon button ---- */
.tkn-add,
.tkn-overflow { position: relative; display: inline-flex; }
.tkn-iconbtn {
  height: 34px;
  width: 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border);
  background: var(--bg-card);
  border-radius: 8px;
  color: var(--text-muted);
  font-size: 16px;
  cursor: pointer;
  transition: background var(--transition);
}
.tkn-iconbtn:hover { background: var(--bg-card-hover); }

/* ⋯ menu + "+ Filtro" popover ride the shared .ms-panel styling (white surface,
   soft shadow, 8px radius); only tweaks below. The ⋯ menu right-anchors so it
   never opens off the right edge of the screen. */
.tkn-menu { min-width: 190px; }
.tkn-overflow .ms-panel { right: 0; left: auto; }
.tkn-menuitem {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 8px 10px;
  border: 0;
  background: transparent;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-family: var(--font);
  color: var(--text-primary);
  cursor: pointer;
  text-align: left;
  white-space: nowrap;
}
.tkn-menuitem:hover { background: var(--bg-column); }

/* "+ Filtro" popover — proper menu: white surface, 8px radius, soft shadow
   (from .ms-panel), ~240px wide, a search box on top and clean full-width rows. */
.tkn-addpanel { min-width: 240px; padding: 6px; }
.tkn-addsearch {
  width: 100%;
  height: 32px;
  margin-bottom: 6px;
  padding: 0 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-input);
  color: var(--text-primary);
  font-size: 13px;
  font-family: var(--font);
  outline: none;
}
.tkn-addsearch:focus { border-color: var(--border-focus); }
.tkn-addlist { display: flex; flex-direction: column; gap: 1px; }
/* Menu rows: transparent, full-width, left-aligned icon + label, comfortable
   padding, subtle hover — no grey UA-button block, no inter-item borders. */
.tkn-addopt {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 8px 12px;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  font-size: 13.5px;
  font-family: var(--font);
  color: var(--text-primary);
  text-align: left;
  white-space: nowrap;
  cursor: pointer;
}
.tkn-addopt:hover { background: var(--bg-column); }
.tkn-addopt .ti { color: var(--text-muted); font-size: 16px; }
.tkn-addopt.hidden { display: none; }

/* ---- Floating editor layer (Stato/Proprietario/Etichetta/Attività/Cliente) ---- */
.tkn-editor-layer {
  position: absolute;
  z-index: 60;
  min-width: 220px;
  max-width: 320px;
  max-height: 300px;
  overflow-y: auto;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  padding: 6px;
}
.tkn-editor-layer.hidden { display: none; }
.tkn-editor { display: flex; flex-direction: column; gap: 1px; }
.tkn-editor--client { min-width: 240px; }
/* Cliente editor — inline search field + results list. The list rows are plain
   .ms-opt buttons; the editor layer's own overflow-y:auto scrolls them (no
   absolute dropdown, which the layer would clip). */
.tkn-cl-search {
  width: 100%;
  height: 34px;
  margin-bottom: 6px;
  padding: 0 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-input);
  color: var(--text-primary);
  font-size: 13.5px;
  font-family: var(--font);
  outline: none;
}
.tkn-cl-search:focus { border-color: var(--border-focus); }
.tkn-cl-list { display: flex; flex-direction: column; gap: 1px; }
.tkn-cl-opt { width: 100%; text-align: left; }
.tkn-radio { justify-content: space-between; width: 100%; border: 0; background: transparent; font-family: var(--font); cursor: pointer; }
.tkn-radio.is-sel { color: var(--tkn-accent-text, #1b3fa0); font-weight: 600; }
.tkn-radio.is-sel .ti { color: var(--tkn-accent-text, #1b3fa0); }

/* Data creazione + custom-range editors — two inputs with a → separator. */
.tkn-editor--created,
.tkn-editor--range { min-width: 240px; }
.tkn-daterow { display: flex; align-items: center; gap: 8px; padding: 4px 2px; }
.tkn-date {
  flex: 1 1 0;
  min-width: 0;
  height: 34px;
  padding: 0 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-input);
  color: var(--text-primary);
  font-size: 13.5px;
  font-family: var(--font);
  outline: none;
}
.tkn-date:focus { border-color: var(--border-focus); }
.tkn-datearrow { flex: 0 0 auto; color: var(--text-muted); font-size: 13px; }

/* Relative-period preset chips ABOVE the two date inputs (opt-in via the
   dimension's `presets:true`). ~30px pill; off = grey border/white, on = the
   selection accent (falls back to the design blues outside .tokenbar scope). */
.ftb-presets { display: flex; flex-wrap: wrap; gap: 6px; padding: 2px 2px 8px; }
.ftb-preset {
  height: 30px;
  padding: 0 11px;
  border: 1px solid var(--tkn-chip-off-border, #dfe4ee);
  border-radius: 20px;
  background: var(--bg-input, #fff);
  color: var(--text-secondary, #4b5563);
  font-size: 12.5px;
  font-family: var(--font);
  cursor: pointer;
  white-space: nowrap;
}
.ftb-preset:hover { border-color: var(--tkn-accent-border, #c7d7fb); }
.ftb-preset.is-on {
  border-color: var(--tkn-accent-border, #c7d7fb);
  background: var(--tkn-accent-bg, #eef3ff);
  color: var(--tkn-accent-text, #1b3fa0);
  font-weight: 600;
}

/* Dark-theme accent overrides for the selection blue (tokens + Avanzati open). */
[data-theme="dark"] .tokenbar {
  --tkn-accent-bg: rgba(37,99,235,.16);
  --tkn-accent-border: rgba(37,99,235,.45);
  --tkn-accent-hover: rgba(37,99,235,.24);
  --tkn-accent-text: #bcd0ff;
  --tkn-accent-key: #93a4c8;
  --tkn-accent-caret: #7f93bd;
  --tkn-accent-x: #93a4c8;
  --tkn-accent-xhover: rgba(37,99,235,.3);
}

/* ===========================================================================
   REUSABLE TOKEN FILTER BAR — LB_TokenFilterBar (token-filter-bar.js).
   A view-agnostic generalization of the board's bespoke `.tokenbar`. The
   generalized row layout (`.fbar-row*`) replaces `.tkn-row*` for hosts other
   than the board; the component reuses all the board's token/editor visuals by
   ALSO applying the `.tkn-*` classes, so only layout + accent scoping live here.
   Rows WRAP on narrow screens (these views have no mobile sheet).
   =========================================================================== */
.fbar-row      { display: flex; align-items: center; gap: 10px; min-height: 34px; flex-wrap: wrap; }
.fbar-row-left { display: flex; align-items: center; flex-wrap: wrap; gap: 10px; flex: 1 1 auto; min-width: 0; }
.fbar-row-right{ margin-left: auto; flex: 0 0 auto; display: flex; align-items: center; gap: 10px; }

/* Component root — the anchor for its floating editor layer; two stacked rows. */
.ftb-bar {
  position: relative;         /* anchor for .ftb-editor-layer (position:absolute) */
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-width: 0;
  flex: 1 1 100%;             /* fill the row when hosted inside a flex .filter-bar */
}
/* Token accent palette: light values come from the inline var() fallbacks in the
   shared `.tkn-token*` rules; dark theme needs the same overrides the board
   scopes to `.tokenbar`. */
[data-theme="dark"] .ftb-bar {
  --tkn-accent-bg: rgba(37,99,235,.16);
  --tkn-accent-border: rgba(37,99,235,.45);
  --tkn-accent-hover: rgba(37,99,235,.24);
  --tkn-accent-text: #bcd0ff;
  --tkn-accent-key: #93a4c8;
  --tkn-accent-caret: #7f93bd;
  --tkn-accent-x: #93a4c8;
  --tkn-accent-xhover: rgba(37,99,235,.3);
}
/* Fixed left pieces (tokens container flexes; "+ Filtro" never shrinks). */
.ftb-add { flex: 0 0 auto; }

/* Optional ALWAYS-VISIBLE persistent search box at the start of row 2. Bordered
   like a .tkn-btn (same 34px height / radius), with a leading search icon and a
   borderless, transparent input. Participates in the row-2 wrap. */
.ftb-search {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  height: 34px;
  padding: 0 11px;
  border: 1px solid var(--border);
  background: var(--bg-card);
  border-radius: 8px;
  flex: 0 1 260px;
  min-width: 160px;
}
/* The whole field highlights as ONE box on focus (not the inner input). */
.ftb-search:focus-within {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.10);
}
.ftb-search .ti-search { font-size: 15px; color: var(--text-muted); flex: 0 0 auto; }
/* The extra `input` raises specificity above the global input[type=text] AND
   input:focus rules (which otherwise re-add a border/background/glow on focus,
   making the input look like a second box inside the field). Keep it seamless
   in every state. */
.ftb-search input.ftb-search-input,
.ftb-search input.ftb-search-input:focus {
  flex: 1 1 auto;
  min-width: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 0;
  border: 0;
  outline: none;
  background: transparent;
  box-shadow: none;
  font-family: var(--font);
  font-size: 13.5px;
  color: var(--text-primary);
}
.ftb-search-input::placeholder { color: var(--text-muted); }
/* rightMeta ("N attività") is empty until a count is written — collapse its gap
   so it doesn't add a stray 10px before Pulisci when blank. */
.ftb-meta:empty { display: none; }

/* ===========================================================================
   MOBILE filter bar + bottom sheet (redesign §3 + §4).
   Both the desktop `.tokenbar` and this mobile bar/sheet are always in the DOM;
   the switch is purely these breakpoints — mobile bar/sheet are display:none by
   default (desktop) and revealed below 768px, where the desktop bar is hidden.
   =========================================================================== */
.mfilter-bar,
.mfilter-sheet-root { display: none; }

@media (max-width: 767px) {
  /* Breakpoint switch: hide the desktop token bar, show the mobile bar. */
  #filter-region .filter-bar--tokenbar { display: none; }

  .mfilter-bar {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 0 10px 14px;
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 20;
    min-width: 0;
  }

  /* "Filtri" pill (dark) + lime count badge. */
  .mfilter-pill {
    flex: 0 0 auto;
    display: inline-flex;
    align-items: center;
    gap: 7px;
    height: 34px;
    padding: 0 12px;
    border: 0;
    border-radius: 8px;
    background: #0f1420;
    color: #fff;
    font-family: var(--font);
    font-size: 13.5px;
    cursor: pointer;
    white-space: nowrap;
  }
  .mfilter-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 18px;
    padding: 1px 6px;
    border-radius: 20px;
    background: #c6f24e;
    color: #0f1420;
    font-weight: 700;
    font-size: 11px;
    line-height: 1.4;
  }
  .mfilter-badge.hidden { display: none; }

  /* Horizontally-scrolling token strip (scrollbar hidden). */
  .mfilter-tokens {
    display: flex;
    align-items: center;
    gap: 8px;
    overflow-x: auto;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
    min-width: 0;
    flex: 1 1 auto;
    padding-right: 14px;
  }
  .mfilter-tokens::-webkit-scrollbar { display: none; }
  .mtoken {
    flex: 0 0 auto;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    height: 34px;
    padding: 0 4px 0 10px;
    border: 1px solid var(--tkn-accent-border, #c7d7fb);
    background: var(--tkn-accent-bg, #eef3ff);
    border-radius: 8px;
    white-space: nowrap;
  }
  .mtoken__val {
    font-size: 13px;
    color: var(--tkn-accent-text, #1b3fa0);
    font-weight: 600;
  }
  .mtoken__x {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 26px;
    height: 100%;
    border: 0;
    background: transparent;
    color: var(--tkn-accent-caret, #8ba0c9);
    font-size: 16px;
    line-height: 1;
    cursor: pointer;
  }

  /* ---- Right cluster (fixed): Viste + Board/Tabella switch ---- */
  .mfilter-lead-actions {
    flex: 0 0 auto;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding-right: 12px;
    padding-left: 6px;
  }
  .mfilter-views { position: relative; display: inline-flex; }
  .mfilter-iconbtn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--bg-card);
    color: var(--text-primary);
    font-size: 17px;
    cursor: pointer;
  }
  .mfilter-iconbtn:hover { background: var(--bg-card-hover); }
  .mfilter-views-panel {
    position: absolute;
    top: calc(100% + 6px);
    right: 0;
    z-index: 30;
    min-width: 220px;
    max-height: 60vh;
    overflow-y: auto;
    padding: 6px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--bg-card);
    box-shadow: 0 10px 30px rgba(15, 20, 32, .18);
  }
  .mfilter-views-panel.hidden { display: none; }
  .mfilter-views-group {
    padding: 6px 8px 2px;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: .06em;
    text-transform: uppercase;
    color: var(--text-muted);
  }
  .mfilter-view-item {
    display: flex;
    align-items: center;
    gap: 6px;
    width: 100%;
    min-height: 44px;
    padding: 0 10px;
    border: 0;
    border-radius: 8px;
    background: transparent;
    font-family: var(--font);
    font-size: 14.5px;
    color: var(--text-primary);
    text-align: left;
    cursor: pointer;
  }
  .mfilter-view-item:hover { background: var(--bg-card-hover); }
  .mfilter-views-empty { padding: 8px; font-size: 13px; color: var(--text-muted); }

  .mfilter-viewtoggle {
    flex: 0 0 auto;
    display: inline-flex;
    height: 34px;
    padding: 3px;
    gap: 2px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--bg-column, #f0f3f8);
  }
  .mfilter-vt-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    border: 0;
    border-radius: 6px;
    background: transparent;
    color: var(--text-muted);
    font-size: 16px;
    cursor: pointer;
  }
  .mfilter-vt-btn.active {
    background: var(--bg-card);
    color: var(--text-primary);
    box-shadow: 0 1px 2px rgba(15, 20, 32, .08);
  }

  /* ---- Bottom sheet ---- */
  .mfilter-sheet-root { display: none; }
  .mfilter-sheet-root.is-open {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 1000;
  }
  .mfilter-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(15, 20, 32, .45);
    animation: mfilter-fade 220ms ease both;
  }
  .mfilter-sheet {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    flex-direction: column;
    max-height: 78vh;
    background: var(--bg-card);
    border-radius: 20px 20px 0 0;
    box-shadow: 0 -12px 40px rgba(15, 20, 32, .25);
    animation: mfilter-slideup 220ms cubic-bezier(.32, .72, 0, 1) both;
  }
  @keyframes mfilter-slideup { from { transform: translateY(100%); } to { transform: translateY(0); } }
  @keyframes mfilter-fade { from { opacity: 0; } to { opacity: 1; } }

  .mfilter-grabber {
    flex: 0 0 auto;
    width: 38px;
    height: 4px;
    margin: 10px auto 4px;
    border-radius: 4px;
    background: var(--border);
  }
  .mfilter-head {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 6px 18px 12px;
    border-bottom: 1px solid var(--border);
  }
  .mfilter-title { font-size: 17px; font-weight: 700; color: var(--text-primary); }
  .mfilter-clear {
    border: 0;
    background: transparent;
    font-family: var(--font);
    font-size: 13.5px;
    color: var(--accent);
    cursor: pointer;
    min-height: 44px;
    padding: 0 4px;
  }

  .mfilter-body {
    flex: 1 1 auto;
    overflow-y: auto;
    padding: 16px 18px 12px;
    display: flex;
    flex-direction: column;
    gap: 18px;
  }
  .mfilter-sec { display: flex; flex-direction: column; gap: 9px; }
  .mfilter-label {
    margin: 0;
    font-size: 11.5px;
    font-weight: 700;
    letter-spacing: .08em;
    color: var(--text-muted);
    text-transform: uppercase;
  }
  .mfilter-chips { display: flex; flex-wrap: wrap; gap: 8px; }
  .mchip {
    min-height: 44px;
    padding: 8px 13px;
    border: 1px solid #dfe4ee;
    background: var(--bg-card);
    border-radius: 20px;
    font-family: var(--font);
    font-size: 14px;
    color: var(--text-secondary);
    cursor: pointer;
  }
  .mchip.is-on {
    border-color: var(--tkn-accent-border, #c7d7fb);
    background: var(--tkn-accent-bg, #eef3ff);
    color: var(--tkn-accent-text, #1b3fa0);
    font-weight: 600;
  }
  .mfilter-select {
    height: 46px;
    width: 100%;
    padding: 0 13px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--bg-card);
    color: var(--text-primary);
    font-family: var(--font);
    font-size: 14.5px;
  }
  .mfilter-seg {
    display: flex;
    gap: 0;
    padding: 3px;
    border-radius: 10px;
    background: var(--bg-column, #f0f3f8);
  }
  .mseg {
    flex: 1;
    min-height: 44px;
    padding: 9px 0;
    border: 0;
    background: transparent;
    border-radius: 8px;
    font-family: var(--font);
    font-size: 14px;
    color: var(--text-muted);
    cursor: pointer;
  }
  .mseg.is-on {
    background: var(--bg-card);
    color: var(--text-primary);
    font-weight: 600;
    box-shadow: 0 1px 2px rgba(15, 20, 32, .1);
  }

  /* Data-creazione + custom-field controls (now normal .mfilter-sec sections). */
  .mfilter-daterow { display: flex; align-items: center; gap: 10px; }
  .mfilter-date {
    flex: 1;
    min-width: 0;
    height: 46px;
    padding: 0 12px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--bg-card);
    color: var(--text-primary);
    font-family: var(--font);
    font-size: 14.5px;
  }
  .mfilter-arrow { flex: 0 0 auto; color: var(--text-muted); }

  .mfilter-foot {
    flex: 0 0 auto;
    display: flex;
    gap: 10px;
    /* Keep the CTA clear of the iOS home indicator / notch bottom inset. */
    padding: 12px 18px max(20px, env(safe-area-inset-bottom));
    border-top: 1px solid var(--border);
  }
  .mfilter-star {
    flex: 0 0 auto;
    width: 46px;
    height: 48px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: var(--bg-card);
    color: var(--text-secondary);
    font-size: 20px;
    cursor: pointer;
  }
  .mfilter-cta {
    flex: 1 1 auto;
    height: 48px;
    border: 0;
    border-radius: 12px;
    background: #0f1420;
    color: #fff;
    font-family: var(--font);
    font-size: 15.5px;
    font-weight: 600;
    cursor: pointer;
  }
}

/* Respect reduced-motion: no slide/fade on the sheet. */
@media (prefers-reduced-motion: reduce) {
  .mfilter-sheet,
  .mfilter-backdrop { animation: none !important; }
}

/* ---------- Saved views menu ---------- */
.views-menu .ms-toggle { gap: 6px; }
.views-panel { min-width: 240px; padding: 4px; }
.views-group-title {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--text-muted);
  padding: 8px 8px 4px;
}
.views-empty { padding: 4px 8px 8px; font-size: 12px; color: var(--text-muted); }
.view-item {
  display: flex;
  align-items: center;
  gap: 4px;
  border-radius: var(--radius-sm);
}
.view-item:hover { background: var(--bg-column); }
.view-apply {
  flex: 1;
  text-align: left;
  background: none;
  border: none;
  cursor: pointer;
  font-size: 13px;
  color: var(--text-primary);
  padding: 7px 8px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.view-actions { display: inline-flex; gap: 2px; padding-right: 4px; }
.view-act {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-muted);
  padding: 4px;
  border-radius: var(--radius-sm);
  font-size: 14px;
}
.view-act:hover { color: var(--accent); background: var(--bg-card); }
.view-act--on, .view-act--on:hover { color: var(--warning); }

/* Save-view dialog scope radios */
.view-scope { display: flex; flex-direction: column; gap: 6px; }
.view-scope-opt {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--text-primary);
  cursor: pointer;
}
.view-scope-hint { color: var(--text-muted); font-size: 12px; }

/* ---------- Active filter chips ---------- */
.active-filter-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
  padding: 0 20px;
}
.active-filter-chips:empty { display: none; }
.active-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  font-weight: 600;
  color: var(--accent);
  background: var(--accent-light);
  border: 1px solid var(--accent);
  border-radius: 20px;
  padding: 2px 6px 2px 10px;
  white-space: nowrap;
}
.active-chip-x {
  border: none;
  background: none;
  color: inherit;
  cursor: pointer;
  font-size: 15px;
  line-height: 1;
  padding: 0 2px;
}
.active-chip-x:hover { color: var(--danger); }
.active-filter-chips { margin-top: 8px; }
.active-filter-chips:not(:empty) { padding-bottom: 8px; }

/* ---------- View toggle (Kanban / Table) — right side of board-toolbar ---------- */
.view-toggle {
  display: flex;
  gap: 4px;
  padding: 3px;
  background: var(--bg-column);
  border-radius: var(--radius-sm);
  margin-left: auto;
}

.view-toggle-btn {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 5px 12px;
  border: none;
  background: transparent;
  border-radius: 4px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--transition);
  white-space: nowrap;
}

.view-toggle-btn.active {
  background: var(--bg-card);
  color: var(--text-primary);
  box-shadow: var(--shadow-sm);
}

.view-toggle-btn:hover:not(.active) {
  color: var(--text-primary);
}

/* Responsive */
/* NOTE: the old mobile filter-bar overrides (`.filter-bar { overflow-x:auto }`
   + the dead `#filter-search` / `#filter-date-from` / `#filter-date-to` ids from
   the pre-token-bar markup) were removed here — below 768px the desktop
   `.filter-bar--tokenbar` is hidden entirely and the mobile bar/sheet take over
   (see the "MOBILE filter bar + bottom sheet" block above). */
@media (max-width: 768px) {
  .board-toolbar {
    padding: 8px 12px;
  }
}

/* ---------- Table view ---------- */
/* Note: no `display` rules on .kanban-wrapper / .table-wrapper — visibility is
   controlled imperatively in kanban.js (_setViewMode). Adding rules here
   would override inline style/hidden and break the toggle. */
/* Table view layout:
   #table-wrapper is the scroll container (it sits as a flex sibling of
   the kanban wrapper under #view-board.active, which is height:100%
   flex-column overflow:hidden). Without flex+min-height:0 it'd collapse
   to content height, and #view-board's overflow:hidden would clip the
   bottom rows with no way to scroll — which is why position:sticky on
   <th> previously did nothing (no scroll ancestor). */
#table-wrapper {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: auto;
}
.table-view-wrap {
  display: flex;
  flex-direction: column;
  min-height: 100%;
  /* padding intentionally removed — table now goes edge-to-edge so
     the sticky scrollbar isn't visually offset from the content. */
}
.leads-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  white-space: nowrap;
  background: var(--bg-card);
  /* Keep natural height inside the .table-view-wrap flex column —
     otherwise flex would size the table to the wrap's height and the
     scroll container above never sees overflow. */
  flex-shrink: 0;
}
.leads-table th {
  padding: 10px 14px;
  text-align: left;
  background: var(--bg-column);
  border-bottom: 2px solid var(--border);
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-secondary);
  cursor: pointer;
  user-select: none;
  position: sticky;
  top: 0;
  /* Paint above rows that scroll underneath. */
  z-index: 10;
}
.leads-table th:hover { background: var(--border); }
.leads-table th.sorted-asc,
.leads-table th.sorted-desc { color: var(--accent); }
.leads-table th .sort-icon { font-size: 10px; opacity: 0.7; margin-left: 4px; }
.leads-table th.th-actions { cursor: default; text-align: right; }
.leads-table td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
}
.leads-table td.td-actions { text-align: right; }
.leads-table .cell-truncate {
  display: inline-block;
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  vertical-align: bottom;
}

/* Edge padding lives on the first/last cells (not on .table-view-wrap)
   so the sticky scrollbar still hugs the wrapper edge while content
   reads as 20px-inset. Footer already has padding:12px 20px so it
   aligns visually with this. */
.leads-table th:first-child,
.leads-table td:first-child { padding-left: 20px; }
.leads-table th:last-child,
.leads-table td:last-child { padding-right: 20px; }

.leads-table tr.lead-row { cursor: pointer; transition: background 0.1s; }
.leads-table tr.lead-row:hover td { background: var(--bg-input); }
.leads-table a { color: var(--accent); text-decoration: none; }
.leads-table a:hover { text-decoration: underline; }

.table-footer {
  display: flex;
  justify-content: space-between;
  padding: 12px 20px;
  font-size: 13px;
  color: var(--text-secondary);
  background: var(--bg-card);
  border-top: 1px solid var(--border);
  /* Sticks to the bottom of the #table-wrapper scrollport so it stays
     visible while scrolling through long lead lists. flex-shrink:0 is
     belt-and-suspenders — sticky elements stay in flow but this also
     prevents them from being squeezed by the table above. */
  position: sticky;
  bottom: 0;
  flex-shrink: 0;
  z-index: 5;
}

/* Custom scrollbar to match the rest of the app's restrained styling. */
#table-wrapper::-webkit-scrollbar { width: 6px; height: 6px; }
#table-wrapper::-webkit-scrollbar-track { background: var(--bg-column); }
#table-wrapper::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}
#table-wrapper::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ---------- Dashboard date range ---------- */
/* Compact, single-row range: Dal [input] Al [input] [Applica] [Reset]. Gap
   matches the calendar (8). Wraps only on mobile (see <768 override). The
   quick-period presets reuse the shared .view-toggle segmented control. */
.date-range-picker {
  display: inline-flex;
  gap: 8px;
  align-items: center;
  font-size: 13px;
  flex-wrap: nowrap;
}
.date-range-picker label {
  font-size: 12px;
  color: var(--text-secondary);
  font-weight: 500;
}

/* ---------- Custom fields section on the lead panel ---------- */
.custom-fields-section {
  margin: 12px 0;
  padding: 12px 14px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}
.custom-fields-section h4 {
  margin: 0 0 10px;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-secondary);
}
.custom-field-input {
  width: 100%;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-input);
  font-size: 13px;
  color: var(--text-primary);
  outline: none;
}
.custom-field-input:focus { border-color: var(--accent); }
.field-row--custom { padding-top: 4px; }

/* Unit affix for percentuale (%) / valuta (€) custom fields. */
.cf-affixed {
  display: flex;
  align-items: center;
  gap: 6px;
}
.cf-affixed .custom-field-input { width: auto; flex: 1; }
.cf-unit {
  flex-shrink: 0;
  font-size: 13px;
  color: var(--text-secondary);
  font-weight: 600;
}

/* Multi-select (select_multipla) checkbox group.
   Rendered "wide": label on top, options below at full row width. In the default
   side-by-side layout the options are squeezed into the narrow value column and
   long labels collapse to their longest word (wrapping one word per line). Note:
   .fields-grid is a single-column flex (not a real grid), so "wide" = stack +
   full width, not grid-column. */
.field-row--wide {
  flex-direction: column;
  align-items: stretch;
  gap: 6px;
}
.field-row--wide > label {
  width: 100%;
  min-width: 0;
}
.field-row--wide > .field-value {
  width: 100%;
  align-items: stretch;
}
/* .inline-check è una <label>, quindi come discendente di .field-row eredita
   .field-row label (width:130px, text-transform:uppercase, font-size:11px,
   font-weight:600, letter-spacing, color:secondary…) — regola pensata per le
   label-TITOLO dei campi. Le opzioni (checkbox di select_multipla e il "Sì" del
   tipo checkbox) sono testo-contenuto normale: annulla la width fissa che le
   comprimeva a 130px (→ wrap parola-per-parola su schermo largo) e l'aspetto da
   label-titolo. NON tocca il layout flex dell'opzione (display/align/gap/cursor
   restano da .inline-check / .cf-checkbox-group .inline-check). Specificità
   (0,2,0) batte .field-row label (0,1,1); vale a ogni larghezza. */
.field-row .inline-check {
  width: auto;
  min-width: 0;
  flex-shrink: 1;
  text-transform: none;
  font-size: 13px;
  font-weight: 400;
  letter-spacing: normal;
  color: var(--text-primary);
}

.cf-checkbox-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 100%;
}
.cf-checkbox-group .inline-check {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  font-size: 13px;
  line-height: 1.4;
}
.cf-checkbox-group .inline-check input {
  flex-shrink: 0;
  width: 16px;
  height: 16px;
  margin-top: 2px;
  accent-color: var(--accent);
}
.field-row--custom label { display: block; margin-bottom: 4px; font-size: 12px; color: var(--text-secondary); }

/* (Old 720px toolbar overrides removed — replaced by the 768px block
   above which handles padding/gap and keeps the 32px input height.) */

/* ============================================================
   Light theme — kanban visibility tweaks
   Real class names in this codebase are .kanban-column__header,
   .kanban-cards, .kanban-badge, .kanban-empty. We target both
   the real names and the conventional .column-* / .cards-container
   names so the rules apply regardless of which the markup uses.
   ============================================================ */

[data-theme="light"] #view-board { background: var(--bg-app); }

[data-theme="light"] .kanban-board { background: transparent; }

[data-theme="light"] .kanban-column {
  background: rgba(255,255,255,.35);   /* light: barely-there panel over the glow */
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
}

[data-theme="light"] .kanban-column .kanban-column__header,
[data-theme="light"] .kanban-column .column-header {
  background: var(--col-tint);
  border-bottom: 1px solid var(--border);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
}

/* Light: win specificity over [data-theme="light"] .kanban-column so the
   drop tint shows on the target column. */
[data-theme="light"] .kanban-column.is-drop-target {
  background: var(--col-tint);
  box-shadow: inset 0 0 0 2px var(--col-color, var(--accent));
}

[data-theme="light"] .kanban-column .kanban-cards,
[data-theme="light"] .kanban-column .cards-container {
  background: transparent;
}

[data-theme="light"] .lead-card {
  background: var(--bg-card);
  border-top: 2px solid var(--border);
  border-right: 2px solid var(--border);
  border-bottom: 2px solid var(--border);
  border-left-width: 4px;
  /* Left border = owner colour (--owner-color), set by kanban.js; green/red on
     won/lost cards. Neutral fallback when no owner. */
  border-left-color: var(--owner-color, var(--border));
  box-shadow: var(--card-shadow);
}

[data-theme="light"] .lead-card:hover {
  box-shadow: var(--shadow);
  /* Thick hover border: the neutral perimeter lights up in the owner colour
     (green/red on won/lost); the 4px left bar stays the owner colour. */
  border-color: var(--owner-color, var(--accent));
}

/* Source card while its detail panel is open: status-colour ring. Placed
   after the light overrides so it wins in both themes. */
.lead-card.is-panel-open {
  box-shadow: 0 0 0 2px var(--col-color, var(--accent)), var(--card-shadow);
}

[data-theme="light"] .kanban-badge,
[data-theme="light"] .column-count {
  background: var(--bg-card);
  color: var(--text-secondary);
  border: 1px solid var(--border);
}

[data-theme="light"] .kanban-empty,
[data-theme="light"] .column-empty {
  background: var(--bg-card);
  border: 2px dashed var(--border);
}

[data-theme="light"] .board-toolbar {
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
}
/* Filter strip is the white "toolbar in rilievo": keep base --bg-card (white)
   in light rather than the toolbar's off-white. */
[data-theme="light"] .filter-bar {
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
}
/* Dark: same elevated --bg-card surface, deeper shadow for the lift. */
[data-theme="dark"] .filter-bar,
[data-theme="dark"] .tag-filter-row {
  box-shadow: 0 3px 10px -6px rgba(0,0,0,.5);
}

/* ============================================
   TABLER ICONS — monochromatic, theme-aware
   Icons inherit color from their parent. No
   colored variants; size is controlled via
   font-size only. Outline-only (no -filled).
   ============================================ */
.ti {
  font-size: 16px;
  line-height: 1;
  vertical-align: middle;
  flex-shrink: 0;
  color: inherit;
}
.ti-sm { font-size: 13px; }
.ti-lg { font-size: 20px; }
.ti-xl { font-size: 24px; }

/* Navbar icon buttons */
.btn-icon .ti { font-size: 18px; }

/* Settings nav */
.settings-nav-item .ti {
  font-size: 16px;
  margin-right: 2px;
}

/* KPI card icons */
.kpi-label .ti {
  font-size: 14px;
  margin-right: 6px;
  opacity: 0.7;
}

/* Field label icons (modals + drawer) */
.field-row label .ti,
.form-group label .ti {
  font-size: 12px;
  margin-right: 5px;
  opacity: 0.6;
}

/* Activity timeline icons */
.activity-icon .ti { font-size: 16px; }

/* Tab icons */
.tab .ti {
  font-size: 14px;
  margin-right: 5px;
}

/* Lead card icons */
.lead-card .ti {
  font-size: 12px;
  color: var(--text-muted);
}

/* Search input wrap (icon-inside) */
.search-wrap {
  position: relative;
  display: flex;
  align-items: center;
}
.search-wrap .ti {
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 14px;
  color: var(--text-muted);
  pointer-events: none;
}
.search-wrap input,
.search-wrap .search-input,
.search-wrap .filter-input {
  padding-left: 32px;
}

/* Button icon spacing */
.btn-primary .ti,
.btn-secondary .ti {
  margin-right: 5px;
  font-size: 14px;
}

/* Source/sector pills inside cards */
.sector-pill .ti,
.followup .ti {
  font-size: 11px;
  margin-right: 3px;
  vertical-align: middle;
}

/* ============================================
   KPI GRID — DEFINITIVE RULE
   Placed at end of file so it wins the cascade.
   ============================================ */
.kpi-grid {
  display: grid !important;
  grid-template-columns: repeat(7, 1fr) !important;
  gap: 12px;
  margin-bottom: 24px;
}

@media (max-width: 1280px) {
  .kpi-grid {
    grid-template-columns: repeat(4, 1fr) !important;
  }
}

@media (max-width: 900px) {
  .kpi-grid {
    grid-template-columns: repeat(3, 1fr) !important;
  }
}

@media (max-width: 640px) {
  .kpi-grid {
    grid-template-columns: repeat(2, 1fr) !important;
  }
}

/* ============================================
   NOTIFICATIONS — bell + badge + dropdown panel
   ============================================ */
.nav-notifications {
  position: relative;
}

.notif-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  min-width: 18px;
  height: 18px;
  background: var(--danger);
  color: #ffffff;
  font-size: 10px;
  font-weight: 700;
  border-radius: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 4px;
  border: 2px solid var(--bg-navbar);
  pointer-events: none;
  animation: badge-pop 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes badge-pop {
  from { transform: scale(0); opacity: 0; }
  to   { transform: scale(1); opacity: 1; }
}

.notif-panel {
  position: absolute;
  top: calc(100% + 10px);
  right: -8px;
  width: 340px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  z-index: 200;
  overflow: hidden;
  animation: notif-drop 0.2s ease;
}

@keyframes notif-drop {
  from { opacity: 0; transform: translateY(-8px); }
  to   { opacity: 1; transform: translateY(0); }
}

.notif-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
}

.notif-panel-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 6px;
}

.notif-panel-body {
  max-height: 320px;
  overflow-y: auto;
}

.notif-item {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background var(--transition);
}

.notif-item:last-child { border-bottom: none; }
.notif-item:hover { background: var(--bg-column); }

.notif-item-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
  margin-top: 4px;
}
.notif-item-dot.overdue { background: var(--danger);  }
.notif-item-dot.today   { background: var(--warning); }

.notif-item-body {
  flex: 1;
  min-width: 0;
}

.notif-item-company {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.notif-item-meta {
  font-size: 11px;
  color: var(--text-secondary);
  margin-top: 2px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.notif-item-tag {
  font-size: 10px;
  font-weight: 600;
  padding: 1px 6px;
  border-radius: 20px;
}
.notif-item-tag.overdue {
  background: var(--danger-light);
  color: var(--danger);
}
.notif-item-tag.today {
  background: var(--warning-light);
  color: var(--warning);
}

.notif-loading {
  padding: 24px;
  text-align: center;
  font-size: 13px;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.notif-empty {
  padding: 32px 16px;
  text-align: center;
  color: var(--text-muted);
  font-size: 13px;
}
.notif-empty .ti {
  font-size: 32px;
  display: block;
  margin-bottom: 8px;
  color: var(--success);
}

.notif-panel-footer {
  padding: 10px 16px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

/* Unread notification row: subtle tint + heavier title, plus an accent dot. */
.notif-item.unread { background: var(--accent-light); }
.notif-item.unread:hover { background: var(--bg-column); }
.notif-item.unread .notif-item-company { font-weight: 700; }
.notif-item-dot.unread { background: var(--accent); }
.notif-item-dot:not(.unread) { background: transparent; }

/* "Segna tutte come lette" link in the footer. */
.notif-markall {
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
  font-size: 12px;
  font-weight: 600;
  color: var(--accent);
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.notif-markall:hover { text-decoration: underline; }
.notif-markall.hidden { display: none; }

.notif-btn.has-notifications .ti-bell {
  animation: bell-ring 0.5s ease;
}

@keyframes bell-ring {
  0%   { transform: rotate(0deg); }
  20%  { transform: rotate(15deg); }
  40%  { transform: rotate(-12deg); }
  60%  { transform: rotate(8deg); }
  80%  { transform: rotate(-5deg); }
  100% { transform: rotate(0deg); }
}

/* Continuous spin for busy/loading icons (e.g. CSV export button). */
.spin { animation: lb-spin 0.8s linear infinite; display: inline-block; }
@keyframes lb-spin { to { transform: rotate(360deg); } }

[data-theme="dark"] .notif-panel {
  background: var(--bg-card);
  border-color: var(--border);
}

/* ============================================
   GLOBAL SEARCH — navbar search with dropdown
   ============================================ */
.global-search-wrap {
  position: relative;
  flex: 1;
  max-width: 320px;
  min-width: 180px;
}

.global-search-input-wrap {
  position: relative;
  display: flex;
  align-items: center;
  width: 100%;
}

.search-kbd {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 10px;
  font-weight: 500;
  color: var(--text-muted);
  background: var(--bg-column);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 2px 5px;
  pointer-events: none;
  font-family: var(--font);
  line-height: 1.4;
  transition: opacity var(--transition);
}

.search-clear {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-muted);
  padding: 3px;
  border-radius: 4px;
  display: flex;
  align-items: center;
  font-size: 13px;
  line-height: 1;
}
.search-clear:hover {
  color: var(--text-primary);
  background: var(--bg-column);
}

.search-results {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  z-index: 300;
  overflow: hidden;
  animation: notif-drop 0.15s ease;
  max-height: 480px;
  display: flex;
  flex-direction: column;
}

#search-results-body {
  overflow-y: auto;
  flex: 1;
}

.search-section-label {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
  padding: 10px 14px 4px;
}

.search-result-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  cursor: pointer;
  transition: background var(--transition);
}
.search-result-item:hover,
.search-result-item.selected {
  background: var(--accent-light);
}
.search-result-item.selected .search-result-company {
  color: var(--accent);
}

.search-result-icon {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  flex-shrink: 0;
  background: var(--bg-column);
  color: var(--text-secondary);
}

.search-result-body {
  flex: 1;
  min-width: 0;
}

.search-result-company {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.search-result-deal {
  font-size: 12px;
  color: var(--text-primary);
  margin-top: 1px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.search-result-company mark,
.search-result-deal mark {
  background: transparent;
  color: var(--accent);
  font-weight: 700;
}

.search-result-meta {
  font-size: 11px;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 1px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.search-result-status {
  font-size: 10px;
  font-weight: 600;
  padding: 1px 6px;
  border-radius: 20px;
}

.search-result-arrow {
  font-size: 14px;
  color: var(--text-muted);
  flex-shrink: 0;
}

.search-empty {
  padding: 32px 16px;
  text-align: center;
  color: var(--text-muted);
  font-size: 13px;
}
.search-empty .ti {
  font-size: 28px;
  display: block;
  margin-bottom: 8px;
}

.search-loading {
  padding: 20px;
  text-align: center;
  color: var(--text-muted);
  font-size: 13px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.search-results-footer {
  border-top: 1px solid var(--border);
  padding: 8px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}
.search-results-footer:empty { display: none; }

.search-footer-hint {
  font-size: 11px;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 10px;
}
.search-footer-hint kbd {
  font-size: 10px;
  background: var(--bg-column);
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 1px 5px;
  font-family: var(--font);
}

.search-footer-count {
  font-size: 11px;
  color: var(--text-muted);
  font-weight: 500;
}

/* Source icon color */
.search-icon-manuale  { background: var(--warning-light); color: var(--warning); }

/* ============================================
   NAVBAR RESPONSIVE — la barra è una riga sola, non va a capo e non scrolla
   (i pannelli assoluti — notifiche / risultati ricerca — non sopravvivono a un
   overflow:auto sul contenitore). Quindi il contenuto DEVE starci: ogni fascia
   comprime o toglie l'elemento meno essenziale, fino al breakpoint mobile
   (768px) dove subentra l'hamburger. Larghezze tarate sul caso peggiore
   (super_admin: 5 link + selettore progetti + tutte le azioni). */

/* Rete di sicurezza a ogni larghezza: .nav-actions non è più incomprimibile,
   ma l'unico elemento che cede è il nome utente (ellissi) — icone e pulsanti
   restano interi. Senza questo, l'eccedenza usciva dalla viewport tagliata. */
.nav-actions { flex-shrink: 1; min-width: 0; }
.nav-actions > * { flex-shrink: 0; }
#user-name { flex-shrink: 1; min-width: 0; }

/* Stessa logica a sinistra: il gruppo logo può cedere, ma solo il nome del
   progetto va in ellissi — il marchio resta a dimensione piena. */
.nav-logo { flex-shrink: 1; min-width: 0; }
.nav-logo > svg { flex-shrink: 0; }
.nav-project-name { min-width: 0; }

/* Tutte le fasce partono da 769px: sotto comanda il layout mobile
   (hamburger + sidebar), che ha già le sue regole e non va toccato. */
@media (min-width: 769px) and (max-width: 1320px) {
  .global-search-wrap {
    max-width: 220px;
    min-width: 150px;
  }
  #project-selector.project-switcher {
    width: 170px;
  }
  .nav-link { padding: 8px 10px; }
  .nav-link.active::after { left: 10px; right: 10px; }
  .nav-project-name.is-primary { max-width: 160px; }

  /* Le etichette dei link cadono prima quando le voci sono 5 (super_admin:
     c'è anche Anagrafica) — con 4 voci ci stanno fino a 1200px, quindi non
     le togliamo a chi non serve. Anagrafica è nel DOM sempre: conta come
     visibile solo se il ruolo non le ha messo .hidden. Selezionata per
     data-view, non per posizione: l'ordine delle voci può cambiare. */
  .nav-links:has(> .nav-link[data-view="anagrafica"]:not(.hidden)) .nav-link span {
    display: none;
  }
}

@media (min-width: 769px) and (max-width: 1200px) {
  /* Solo icone per tutti (il testo resta nel title del pulsante). */
  .nav-links .nav-link span { display: none; }
  .global-search-wrap { max-width: 200px; }
}

@media (min-width: 769px) and (max-width: 1100px) {
  /* L'icona profilo identifica già l'utente: il nome è ridondante. */
  #user-name { display: none !important; }
}

@media (min-width: 769px) and (max-width: 950px) {
  /* Ultima fascia prima dell'hamburger: tutto compatto. */
  #navbar { padding: 0 12px; gap: 6px; }
  .nav-logo { min-width: 0; }
  .nav-logo svg { height: 24px !important; }  /* height è inline nel markup */
  .nav-project-name.is-primary { max-width: 120px; padding: 0 8px; }
  #project-selector.project-switcher { width: 150px; min-width: 120px; }
  .global-search-wrap { max-width: 180px; min-width: 120px; }
  .nav-link { padding: 8px; }
  .nav-link.active::after { left: 8px; right: 8px; }
  /* Le scorciatoie da tastiera contano poco su schermi stretti; il pannello
     resta raggiungibile col tasto "?" e ⌘K continua a funzionare. */
  #btn-shortcuts { display: none !important; }
  /* Senza il badge ⌘K l'input recupera spazio a destra (resta il margine
     per la × di "cancella ricerca"). */
  .search-kbd { display: none; }
  .global-search-input { padding-right: 32px !important; }
}

@media (max-width: 768px) {
  .search-kbd { display: none; }
}

/* ============================================
   DRAG & DROP — smooth animations
   ============================================ */
.lead-card { cursor: grab; }
.lead-card:active { cursor: grabbing; }

.lead-card.dragging {
  opacity: 0.4;
  cursor: grabbing;
  transform: scale(0.98);
}

.kanban-column.drop-target .kanban-cards,
.kanban-column.drop-target .cards-container {
  background: var(--accent-light);
  border: 2px dashed var(--accent);
  border-radius: var(--radius);
  transition: all 0.15s ease;
}

.drop-indicator {
  height: 3px;
  background: var(--accent);
  border-radius: 2px;
  margin: 2px 4px;
  animation: indicator-appear 0.15s ease;
  flex-shrink: 0;
}

@keyframes indicator-appear {
  from { opacity: 0; transform: scaleX(0.5); }
  to   { opacity: 1; transform: scaleX(1); }
}

@keyframes card-drop-in {
  from { opacity: 0; transform: translateY(-8px) scale(0.97); }
  to   { opacity: 1; transform: translateY(0)     scale(1); }
}

/* ============================================
   KEYBOARD SHORTCUTS PANEL
   ============================================ */
.shortcuts-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.5);
  backdrop-filter: blur(3px);
  z-index: 500;
  opacity: 0;
  transition: opacity 0.2s ease;
}
.shortcuts-overlay.open { opacity: 1; }

.shortcuts-panel {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -44%);
  width: 580px;
  max-width: calc(100vw - 32px);
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-lg);
  z-index: 501;
  opacity: 0;
  transition: opacity 0.2s ease, transform 0.2s ease;
}
.shortcuts-panel.open {
  opacity: 1;
  transform: translate(-50%, -50%);
}

.shortcuts-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 20px;
  border-bottom: 1px solid var(--border);
}
.shortcuts-header h3 {
  font-size: 15px;
  font-weight: 700;
  color: var(--text-primary);
  margin: 0;
}

.shortcuts-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0;
  padding: 8px 0;
  max-height: 400px;
  overflow-y: auto;
}

.shortcuts-category {
  padding: 12px 20px;
}

.shortcuts-category-title {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 10px;
}

.shortcut-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 5px 0;
}

.shortcut-desc {
  font-size: 13px;
  color: var(--text-secondary);
}

.shortcut-keys {
  display: flex;
  gap: 3px;
  align-items: center;
}

.shortcut-kbd {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 22px;
  height: 22px;
  padding: 0 6px;
  background: var(--bg-column);
  border: 1px solid var(--border);
  border-bottom-width: 2px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-primary);
  font-family: var(--font);
}

.shortcuts-footer {
  padding: 12px 20px;
  border-top: 1px solid var(--border);
  font-size: 12px;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 6px;
}

.shortcuts-footer kbd { font-family: var(--font); }

.btn-shortcuts {
  opacity: 0.6;
  font-size: 13px;
  font-weight: 600;
}
.btn-shortcuts:hover { opacity: 1; }

@media (max-width: 640px) {
  .shortcuts-grid { grid-template-columns: 1fr; }
}

/* ============================================
   USER PROFILE
   ============================================ */
.profile-wrap {
  /* This is a form (account + password), not a data table — cap it at a
     comfortable form width rather than full-width. width:100% is required
     because .view.active is a flex column: without it, the auto margins
     collapse the wrap to its content width (the old "mobile-like" narrowness). */
  width: 100%;
  max-width: 1800px;
  margin: 0 auto;
  padding: 24px;
}

.profile-header {
  display: flex;
  align-items: center;
  gap: 20px;
  margin-bottom: 28px;
  padding: 24px;
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
}

.profile-avatar {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: var(--accent);
  color: #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  font-weight: 700;
  flex-shrink: 0;
  letter-spacing: -1px;
}

/* Personal colour picker (profile → Preferenze). The preview chip mirrors the
   board's owner badge: same round initials, background = the picked colour,
   text = LB_textOnColor's readable choice, so the user judges the contrast
   before saving. Background/colour on both the chip and .profile-avatar are set
   inline by profile.js — the CSS only owns the shape. */
.color-pref {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.color-pref__preview {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 700;
  flex-shrink: 0;
  border: 1px solid var(--border);
  box-sizing: border-box;
}

.color-pref input[type="color"] {
  width: 36px;
  height: 32px;
  padding: 2px;
  border: 1px solid var(--border);
  border-radius: 4px;
  cursor: pointer;
  background: var(--bg-card);
  flex-shrink: 0;
}

/* Disabled = the colour is already automatic, so there's nothing to reset. */
.color-pref .btn-secondary:disabled {
  opacity: 0.5;
  cursor: default;
}

.profile-info h2 {
  font-size: 20px;
  font-weight: 700;
  margin: 0 0 4px;
}

.profile-info p {
  font-size: 14px;
  color: var(--text-secondary);
  margin: 0 0 8px;
}

.profile-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 20px;
}

.profile-grid .settings-card:first-child {
  grid-column: span 2;
  /* Card Info a tutta larghezza: i campi (Nome, Email) vanno su 2 colonne
     così riempiono lo spazio senza stirare i singoli input. h3 e bottone
     restano full-width. */
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0 20px;
  align-content: start;
}
.profile-grid .settings-card:first-child > h3,
.profile-grid .settings-card:first-child > .btn-primary {
  grid-column: 1 / -1;
}

.theme-picker {
  display: flex;
  gap: 10px;
}

.theme-option { flex: 1; cursor: pointer; }
.theme-option input { display: none; }

.theme-option span {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  transition: all var(--transition);
  cursor: pointer;
}

.theme-option input:checked + span {
  border-color: var(--accent);
  background: var(--accent-light);
  color: var(--accent);
}

@media (max-width: 768px) {
  .profile-grid { grid-template-columns: 1fr; }
  .profile-grid .settings-card:first-child {
    grid-column: span 1;
    grid-template-columns: 1fr;
  }
}

/* ============================================
   KANBAN COLUMN SORT
   ============================================ */
.column-header {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.column-header-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.column-sort { display: flex; }

.column-sort-select {
  font-size: 11px;
  padding: 3px 6px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-card);
  color: var(--text-secondary);
  cursor: pointer;
  outline: none;
  max-width: 110px;
  font-family: var(--font);
}

.column-sort-select:hover { border-color: var(--accent); }
.column-sort-select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1); }

/* ============================================
   WELCOME TOUR (welcome-tour.js) — theme over the vendored driver.css.
   Only overrides here; the vendored file stays byte-for-byte upstream.
   ============================================ */
.driver-popover.lb-tour {
  font-family: Inter, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg-card);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow-lg, 0 10px 30px rgba(0, 0, 0, 0.25));
  padding: 18px 18px 14px;
  max-width: 340px;
}
.lb-tour .driver-popover-title { font-size: 16px; font-weight: 700; letter-spacing: -0.2px; }
.lb-tour .driver-popover-description { font-size: 14px; line-height: 1.55; color: var(--text-secondary); }
.lb-tour .driver-popover-progress-text { font-size: 12px; color: var(--text-muted); }
.lb-tour .driver-popover-close-btn { color: var(--text-muted); }
.lb-tour .driver-popover-close-btn:hover,
.lb-tour .driver-popover-close-btn:focus { color: var(--text-primary); }
.lb-tour .driver-popover-footer-btn,
.lb-tour .lb-tour-skip {
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text-primary);
  text-shadow: none;
  cursor: pointer;
}
.lb-tour .driver-popover-footer-btn:hover,
.lb-tour .driver-popover-footer-btn:focus { background: var(--bg-card-hover); }
.lb-tour .driver-popover-next-btn {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.lb-tour .driver-popover-next-btn:hover,
.lb-tour .driver-popover-next-btn:focus { background: var(--accent); filter: brightness(1.08); }
.lb-tour .lb-tour-skip { border-color: transparent; background: none; color: var(--text-secondary); margin-right: auto; }
.lb-tour .lb-tour-skip:hover { color: var(--text-primary); }
/* Arrow: recolour only the visible side (the others are transparent upstream). */
.lb-tour .driver-popover-arrow-side-left   { border-left-color: var(--bg-card); }
.lb-tour .driver-popover-arrow-side-right  { border-right-color: var(--bg-card); }
.lb-tour .driver-popover-arrow-side-top    { border-top-color: var(--bg-card); }
.lb-tour .driver-popover-arrow-side-bottom { border-bottom-color: var(--bg-card); }

/* ============================================
   CONFIRM DIALOG — context-aware
   ============================================ */
.confirm-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.5);
  backdrop-filter: blur(3px);
  z-index: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.2s ease;
}
.confirm-overlay.open { opacity: 1; }

.confirm-box {
  width: 100%;
  max-width: 400px;
  text-align: center;
  padding: 32px 28px 24px;
  animation: modal-pop 0.2s ease;
}

@keyframes modal-pop {
  from { transform: scale(0.95); opacity: 0; }
  to   { transform: scale(1);    opacity: 1; }
}

.confirm-icon-wrap {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--danger-light);
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 16px;
}

.confirm-title {
  font-size: 17px;
  font-weight: 700;
  margin-bottom: 8px;
  color: var(--text-primary);
}

.confirm-message {
  font-size: 14px;
  color: var(--text-secondary);
  line-height: 1.6;
  margin-bottom: 12px;
}

.confirm-detail {
  padding: 12px 16px;
  background: var(--bg-column);
  border-radius: var(--radius-sm);
  margin-bottom: 20px;
  text-align: left;
}

.confirm-actions {
  display: flex;
  gap: 10px;
  justify-content: center;
  margin-top: 20px;
}

.confirm-actions .btn-secondary,
.confirm-actions .btn-danger,
.confirm-actions .btn-warning,
.confirm-actions .btn-primary {
  flex: 1;
  justify-content: center;
}

.btn-danger {
  background: var(--danger);
  color: #ffffff;
  border: none;
  padding: 9px 18px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: background var(--transition);
  font-family: var(--font);
}
.btn-danger:hover { background: #dc2626; }

.btn-warning {
  background: var(--warning);
  color: #ffffff;
  border: none;
  padding: 9px 18px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: background var(--transition);
  font-family: var(--font);
}
.btn-warning:hover { background: #d97706; }

/* ============================================
   ACTIVITY TIMELINE — change diff badges
   ============================================ */
.activity-change {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 4px 0;
  flex-wrap: wrap;
}

.change-old {
  font-size: 12px;
  color: var(--text-muted);
  background: var(--bg-column);
  padding: 2px 8px;
  border-radius: 4px;
  text-decoration: line-through;
  max-width: 160px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.change-new {
  font-size: 12px;
  background: var(--success-light);
  color: var(--success);
  padding: 2px 8px;
  border-radius: 4px;
  font-weight: 500;
  max-width: 160px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ============================================
   CALENDAR VIEW — month + week
   ============================================ */
.calendar-wrap {
  /* No outer padding: the token bar (#cal-filter-bar) must sit EDGE-TO-EDGE like
     the board's #filter-region bar (full-width strip + border-bottom + shadow),
     not inset as a floating card. The content below the bar re-applies the 20px
     inset via .calendar-legend / .calendar-grid so the grid keeps its tray look. */
  padding: 0;
  height: 100%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.calendar-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
  flex-shrink: 0;
}

.calendar-nav {
  display: flex;
  align-items: center;
  gap: 8px;
}

.calendar-title {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.3px;
  min-width: 200px;
  text-align: center;
  text-transform: capitalize;
  margin: 0;
}

/* .calendar-controls layout is provided by the shared .view-toolbar-controls
   group rule (display/align/gap:8 + right-align). */

/* Calendar filter-bar (commit 2): the bar reuses the shared .filter-bar rule
   (full-width strip + z-index:20 so .ms-panel floats over the grid). Only the
   collapsible "Creazione" interval group and the right-aligned clear/count
   cluster need extra rules. */
.cal-created-range { gap: 6px; }
.cal-created-range.hidden { display: none; }
.cal-filter-right { margin-left: auto; display: flex; align-items: center; gap: 8px; }

/* Status legend: dot+label chips aligned with the grid's left edge (same 20px
   inset), evenly spaced, with a touch of breathing room above/below the bar and
   grid. Each item is a soft inline pill so the row reads as one tidy legend. */
.calendar-legend {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding: 14px 20px 12px;
  margin: 0;
  flex-shrink: 0;
}

.cal-legend-item {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 12px;
  font-weight: 500;
  line-height: 1;
  color: var(--text-secondary);
  padding: 5px 11px 5px 9px;
  background: var(--bg-card-hover);
  border: 1px solid var(--border);
  border-radius: 999px;
}

.cal-legend-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  flex-shrink: 0;
}

.cal-legend-item.overdue .cal-legend-dot { background: var(--danger);  }
.cal-legend-item.today   .cal-legend-dot { background: var(--warning); }
.cal-legend-item.future  .cal-legend-dot { background: var(--accent);  }
.cal-legend-item.done    .cal-legend-dot { background: var(--success); }

.calendar-grid {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  /* Inset to match the legend's left edge (was provided by .calendar-wrap
     padding, now removed so the filter bar can go edge-to-edge). */
  margin: 0 20px 20px;
  /* Soft card tray (Profondità morbida): off-white surface that the white cells
     sit on, with a gentle border + shadow. */
  background: var(--bg-card-hover);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 10px;
}

/* Month grid — header row and cell grid share the SAME columns + gap so the
   weekday labels sit exactly over their columns. */
.cal-header-row {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 6px;
  margin-bottom: 6px;
}

.cal-day-header {
  text-align: center;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-secondary);
  padding: 4px 0;
}

.cal-month-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  grid-auto-rows: 1fr;
  gap: 6px;
  flex: 1;
  overflow: hidden;
}

.cal-cell {
  background: var(--bg-card);
  /* Lighter border than the tray (--border) so nested cells don't double-frame;
     white cells still read against the off-white tray. */
  border: 1px solid var(--bg-column);
  border-radius: 10px;
  padding: 8px;
  min-height: 92px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  overflow: hidden;
}

.cal-cell-outside { background: var(--bg-app); opacity: 0.45; }
/* Today: same 1px border as every other cell (so the box size — and therefore
   the grid alignment — is identical), with an inset brand ring for emphasis
   instead of a thicker border that would shift the cell's inner content. */
.cal-cell-today   { border-color: var(--brand); box-shadow: inset 0 0 0 1px var(--brand); }
.cal-cell-past    { background: var(--bg-column); }
/* Weekend tint (CSS only): Sat (6th) + Sun (7th) columns of each month row.
   :not() keeps outside/past cells on their own background override. */
.cal-month-grid > .cal-cell:nth-child(7n+6):not(.cal-cell-outside):not(.cal-cell-past),
.cal-month-grid > .cal-cell:nth-child(7n+7):not(.cal-cell-outside):not(.cal-cell-past) { background: var(--bg-column); }

.cal-cell-header {
  display: flex;
  justify-content: flex-end;
  align-items: flex-start;
  min-height: 22px;
}

.cal-cell-events {
  display: flex;
  flex-direction: column;
  gap: 3px;
  overflow: hidden;
}

.cal-day-num {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);
  width: 22px;
  height: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
}

.cal-today-num {
  background: var(--brand);
  color: var(--brand-ink);
  font-weight: 700;
}

/* Lead chips */
.cal-lead-chip {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 3px 7px;
  border-radius: 7px;
  font-size: 11px;
  font-weight: 500;
  cursor: pointer;
  transition: opacity var(--transition);
  overflow: hidden;
}

.cal-lead-chip:hover { opacity: 0.8; }

.cal-chip-name {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
  min-width: 0;
}

.cal-chip-overdue { background: var(--danger-light);  color: var(--danger);  }
.cal-chip-today   { background: var(--warning-light); color: var(--warning); }
.cal-chip-future  { background: var(--accent-light);  color: var(--accent);  }
.cal-chip-done {
  background: var(--success-light);
  color: var(--success);
  text-decoration: line-through;
  opacity: 0.7;
}

.cal-more {
  font-size: 10px;
  color: var(--text-muted);
  padding: 1px 4px;
  cursor: pointer;
}
.cal-more:hover { color: var(--text); text-decoration: underline; }

/* Day-detail overlay: vertical scrollable list of a day's follow-ups
   (reuses .modal-overlay/.modal-box; the chips reuse .cal-lead-chip). */
.cal-day-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 60vh;
  overflow-y: auto;
  margin-top: 12px;
}
.cal-day-list .cal-lead-chip {
  font-size: 13px;
  padding: 8px 10px;
}

/* Week grid */
.cal-week-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 8px;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
}

.cal-week-col {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.cal-col-today { border-color: var(--brand); border-width: 2px; }
.cal-col-past  { background: var(--bg-column); }
/* Weekend tint (week view): Sat + Sun columns; :not() keeps past on its override. */
.cal-week-grid > .cal-week-col:nth-child(6):not(.cal-col-past),
.cal-week-grid > .cal-week-col:nth-child(7):not(.cal-col-past) { background: var(--bg-column); }

.cal-week-header {
  padding: 10px 8px;
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  background: var(--bg-column);
}

.cal-week-dayname {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-secondary);
}

.cal-week-daynum {
  font-size: 18px;
  font-weight: 700;
  color: var(--text-primary);
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
}

.cal-week-events {
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 1;
  overflow-y: auto;
}

.cal-week-empty {
  font-size: 13px;
  color: var(--text-muted);
  text-align: center;
  padding: 16px 0;
}

.cal-chip-status {
  font-size: 10px;
  opacity: 0.8;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

@media (max-width: 768px) {
  .cal-cell { min-height: 60px; }
  .cal-week-grid { grid-template-columns: 1fr; }
}

/* ============================================
   TAGS / LABELS
   ============================================ */
.tags-section {
  /* Now a .drawer-panel card; the old padding:12px 0 + border-bottom separator
     is replaced by the card padding + .drawer-panel gap (Opzione A). */
}

.tags-label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-secondary);
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  gap: 5px;
}

.tags-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}

.lead-tag {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 500;
  cursor: default;
}

.tag-remove {
  background: none;
  border: none;
  cursor: pointer;
  padding: 0;
  display: flex;
  align-items: center;
  font-size: 10px;
  opacity: 0.6;
  transition: opacity var(--transition);
  color: inherit;
}
.tag-remove:hover { opacity: 1; }

.btn-add-tag {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 500;
  border: 1px dashed var(--border);
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--transition);
}
.btn-add-tag:hover {
  border-color: var(--accent);
  color: var(--accent);
}

/* Tag dropdown (assign / create) */
.tag-dropdown {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  z-index: 1000;
  min-width: 240px;
  padding: 6px 0;
  animation: notif-drop 0.15s ease;
}

.tag-dropdown-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  cursor: pointer;
  font-size: 13px;
  transition: background var(--transition);
}
.tag-dropdown-item:hover { background: var(--bg-column); }

.tag-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

.tag-dropdown-divider {
  height: 1px;
  background: var(--border);
  margin: 4px 0;
}

.tag-create-form {
  padding: 8px 12px;
  display: flex;
  gap: 6px;
  align-items: center;
}

.tag-create-form input[type="text"] {
  flex: 1;
  padding: 5px 8px;
  font-size: 12px;
}

.tag-create-form input[type="color"] {
  width: 28px;
  height: 28px;
  padding: 2px;
  border: 1px solid var(--border);
  border-radius: 4px;
  cursor: pointer;
  background: var(--bg-card);
}

/* Tag chips on kanban cards */
.lead-card__tags {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 4px;
}
.card-tag {
  display: inline-block;
  padding: 1px 6px;
  border-radius: 3px;
  font-size: 10px;
  font-weight: 600;
}
.card-tag--more {
  background: var(--bg-column);
  color: var(--text-secondary);
}

/* Tag filter row — sibling of .filter-bar, continues the filter strip */
.tag-filter-row {
  padding: 6px 20px 10px;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  /* Last row of the elevated toolbar block: carries the visible shadow. */
  position: relative;
  z-index: 2;
  box-shadow: 0 3px 10px -6px rgba(16,24,40,.22);
}
[data-theme="light"] .tag-filter-row {
  background: var(--bg-card);
  border-bottom-color: var(--border);
}

/* Tag filter chips */
.filter-tags {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  align-items: center;
  padding: 0;
}
.filter-tags-label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-secondary);
  margin-right: 4px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.filter-tag-btn {
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 500;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--transition);
}
.filter-tag-btn:hover { border-color: var(--accent); color: var(--accent); }
.filter-tag-btn.active { font-weight: 600; }

/* Settings → Etichette list */
.tags-settings-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 8px;
}
.tag-settings-row {
  display: grid;
  grid-template-columns: 140px 1fr 40px 80px auto auto;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}
.tag-settings-row .lead-tag { justify-self: start; }
.tag-edit-name {
  padding: 5px 8px;
  font-size: 13px;
}
.tag-edit-color {
  width: 32px;
  height: 28px;
  padding: 2px;
  border: 1px solid var(--border);
  border-radius: 4px;
  cursor: pointer;
  background: var(--bg-card);
}
.tag-usage {
  font-size: 11px;
  color: var(--text-muted);
  text-align: right;
}
.tag-create-row {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-top: 8px;
}
.tag-create-row input[type="text"] { flex: 1; padding: 6px 10px; }
.tag-create-row input[type="color"] { width: 36px; height: 32px; padding: 2px; border: 1px solid var(--border); border-radius: 4px; cursor: pointer; background: var(--bg-card); }

/* ============================================
   COMMENTS / @MENTIONS
   ============================================ */
.comment-input-wrap {
  position: relative;
}

#new-note {
  width: 100%;
  resize: vertical;
  min-height: 60px;
}

.comment-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 8px;
  gap: 8px;
}

.comment-hint {
  font-size: 11px;
  color: var(--text-muted);
}

.comment-hint kbd {
  font-size: 10px;
  background: var(--bg-column);
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 1px 4px;
  font-family: var(--font);
}

/* Mention dropdown lives at document.body (see _showMentionDropdown
   in lead-panel.js) so its `position: fixed` is viewport-anchored —
   not trapped by .drawer's transform, which would otherwise become
   the containing block. */
.mention-dropdown {
  position: fixed;
  z-index: 9999;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  min-width: 220px;
  max-height: 220px;
  overflow-y: auto;
  animation: notif-drop 0.15s ease;
}

.mention-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  cursor: pointer;
  transition: background var(--transition);
}
.mention-item:hover,
.mention-item.selected {
  background: var(--accent-light);
}

.mention-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--accent);
  color: #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 700;
  flex-shrink: 0;
}

.mention-name {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-primary);
}

.mention-email {
  font-size: 11px;
  color: var(--text-muted);
}

.mention-highlight {
  color: var(--accent);
  font-weight: 600;
  background: var(--accent-light);
  padding: 0 3px;
  border-radius: 3px;
}

/* ── GLOBAL SEARCH INPUT — FINAL RULE ──
   Single source of truth for .global-search-input and .global-search-icon.
   Lives at the bottom of app.css with !important to defeat any future
   override added higher in the cascade. Do not duplicate these selectors
   elsewhere in this file. */
.global-search-input {
  width: 100% !important;
  height: 36px !important;
  padding-top: 0 !important;
  padding-bottom: 0 !important;
  padding-left: 34px !important;
  padding-right: 60px !important;
  border: 1px solid var(--border) !important;
  border-radius: 8px !important;
  background: var(--bg-input) !important;
  color: var(--text-primary) !important;
  font-size: 13px !important;
  font-family: var(--font) !important;
  outline: none !important;
  transition: border-color 0.18s ease,
              box-shadow 0.18s ease,
              background 0.18s ease !important;
  box-sizing: border-box !important;
}

.global-search-input:focus {
  border-color: var(--border-focus) !important;
  background: var(--bg-card) !important;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1) !important;
}

.global-search-input::placeholder {
  color: var(--text-muted) !important;
  font-size: 13px !important;
  padding: 0 !important;
}

.global-search-icon {
  position: absolute !important;
  left: 10px !important;
  top: 50% !important;
  transform: translateY(-50%) !important;
  font-size: 14px !important;
  color: var(--text-muted) !important;
  pointer-events: none !important;
  z-index: 2 !important;
  line-height: 1 !important;
  display: flex !important;
  align-items: center !important;
}

/* Fade the ⌘K hint while the input is focused. .search-kbd already has
   transition: opacity, so this just changes the target value. */
.global-search-input:focus ~ .search-kbd {
  opacity: 0;
}

/* ============================================================
   Settings layout — consolidated (last in file)
   Lives here at the end so the !important block wins over the
   .view.active flex+overflow defaults introduced for the kanban
   scroll fix. Also restores #view-settings scrolling that
   .view.active { overflow: hidden !important } would otherwise kill.
   ============================================================ */

#view-settings {
  padding: 24px !important;
  overflow-y: auto !important;
  height: 100% !important;
}

.settings-layout {
  display: grid !important;
  grid-template-columns: 220px 1fr !important;
  gap: 24px !important;
  max-width: 1800px !important;
  margin: 0 auto !important;
  width: 100% !important;
}

/* Form a 2 colonne — i .form-group si affiancano per riempire la card senza
   stirare i singoli campi. Riutilizzabile come wrapper .form-grid-2; gli h3,
   i bottoni e gli elementi .field-full restano a tutta larghezza. Lo spazio
   verticale fra le righe resta quello del margin-bottom dei .form-group, quindi
   il gap di colonna è l'unico gap della grid. */
.form-grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0 20px;
  align-content: start;
}
.form-grid-2 > h3,
.form-grid-2 > .card-desc,
.form-grid-2 > .field-full,
.form-grid-2 > .btn-primary { grid-column: 1 / -1; }

/* Card-form in-page di Impostazioni › Generali: i campi vanno su 2 colonne.
   Scoped alla PRIMA card della sezione (Informazioni progetto) così le card
   con tabella (.data-table) e la card "Informazioni sistema" restano intatte. */
#section-general > .settings-card:first-child {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0 20px;
  align-content: start;
}
#section-general > .settings-card:first-child > h3,
#section-general > .settings-card:first-child > .btn-primary {
  grid-column: 1 / -1;
}

@media (max-width: 768px) {
  .form-grid-2,
  #section-general > .settings-card:first-child { grid-template-columns: 1fr !important; }
}

.settings-nav {
  display: flex !important;
  flex-direction: column !important;
  gap: 2px !important;
  position: sticky !important;
  top: 0 !important;
  align-self: start !important;
  min-width: 220px !important;
}

.settings-content {
  display: flex !important;
  flex-direction: column !important;
  gap: 20px !important;
  min-width: 0 !important;
  flex: 1 !important;
}

@media (max-width: 768px) {
  .settings-layout {
    grid-template-columns: 1fr !important;
  }
  .settings-nav {
    flex-direction: row !important;
    flex-wrap: wrap !important;
    position: static !important;
    min-width: unset !important;
  }
}

/* ============================================================
   RESPONSIVE PATCH — consolidated tail block.
   Lives last so it overrides earlier @media (max-width: 768px)
   declarations. Earlier blocks already cover: hamburger/desktop-only,
   navbar tightening, kanban horizontal scroll, drawer 100vw, modal
   min-width, charts 1-col, filter bar scroll, calendar week-grid,
   settings layout/nav, profile-grid. This block fixes the remaining
   gaps surfaced by the 390 / 768 / 1024 audit.
   ============================================================ */

/* ------ MOBILE (< 768px) ------ */
@media (max-width: 768px) {

  /* Use dynamic viewport units so the iOS Safari URL bar doesn't
     leave a sliver of unreachable content at the bottom of the page. */
  #app-main {
    height: calc(100vh - 52px);
    height: calc(100dvh - 52px);
  }

  /* Tighten navbar to 52px on small viewports so it doesn't dominate. */
  #navbar { height: 52px; padding: 0 12px; gap: 8px; }
  .nav-logo-text { font-size: 15px; }

  /* View toggle: full-width pill so each button is tap-sized. */
  .view-toggle { width: 100%; justify-content: center; }
  .view-toggle-btn { flex: 1; justify-content: center; }

  /* Filter controls (advanced panel / any remaining inline inputs): readable
     density. The pre-token-bar `#filter-search` / `#filter-date-*` ids are gone. */
  .filter-input,
  .filter-select { font-size: 13px; }

  /* Kanban: existing base rule pins width/min/max to 270px !important
     for desktop card consistency; override all three on mobile so the
     scroll viewport peeks at the next column. */
  #kanban-wrapper { padding: 12px; }
  .kanban-board   { min-width: max-content; gap: 10px; }
  .kanban-column {
    width:     260px !important;
    min-width: 260px !important;
    max-width: 260px !important;
  }

  /* Table view: ensure horizontal scroll + readable density. */
  #table-wrapper { -webkit-overflow-scrolling: touch; }
  .leads-table   { font-size: 12px; }
  .leads-table th,
  .leads-table td { padding: 8px 10px; }

  /* Drawer: full viewport on mobile. Use dvw/dvh so the iOS Safari URL
     bar doesn't hide the bottom of the drawer body. */
  .drawer {
    width: 100dvw !important;
    height: 100vh;
    height: 100dvh;
    border-radius: 0;
  }
  .drawer-header { padding: 14px 16px 0; }
  .drawer-header > .drawer-close { top: 10px; right: 10px; }
  .drawer-title h2 { font-size: 16px; }
  .tab-content   { padding: 14px 16px; }

  /* Stack label above value so neither truncates on narrow screens. */
  .field-row {
    flex-direction: column;
    align-items: flex-start;
    gap: 4px;
    padding: 10px 0;
    min-height: 0;
  }
  .field-row label { width: 100%; min-width: 0; }
  .field-value     { width: 100%; }

  /* Attachment rows wrap so name+meta drop below the thumb if needed. */
  .attach-item { flex-wrap: wrap; }

  /* Dashboard header stacks; controls span full width. */
  #view-dashboard { padding: 12px; }
  .dash-header {
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
    margin-bottom: 16px;
  }
  .dash-header h2 { font-size: 18px; }
  .dash-controls  { width: 100%; flex-direction: column; align-items: stretch; gap: 8px; }
  .dash-filter-row { width: 100%; }
  .date-range-picker { flex-wrap: wrap; gap: 6px; }
  .date-range-picker input { flex: 1; min-width: 120px; }
  /* The quick-period presets use .view-toggle → its own <768 rule (full-width,
     buttons flex:1) already handles the mobile layout. */

  /* KPI grid: spec wants 2 cols at 768 (the 7→4→3→2 ladder bottoms
     out at 640 today, leaving 3 cols at 700px which is too cramped). */
  .kpi-grid { grid-template-columns: repeat(2, 1fr) !important; gap: 10px; }
  .kpi-card  { padding: 14px; }
  .kpi-value { font-size: 24px; }

  /* Calendar: compact chips on month view; horizontally-scrolling
     week view. The wrap is display:flex so .cal-week-grid is a flex
     item — without min-width:0 its min-content (7×100=700px) prevents
     shrinking and overflow-x:auto can't take effect. */
  /* Bar stays edge-to-edge (padding:0); the 20px content inset shrinks to 12px. */
  .calendar-wrap   { padding: 0; }
  .calendar-legend { padding: 10px 12px; gap: 6px; }
  .calendar-grid   { margin: 0 12px 12px; }
  .calendar-toolbar { flex-direction: column; gap: 10px; align-items: stretch; }
  .calendar-title  { font-size: 15px; min-width: 0; }
  .cal-cell        { min-height: 55px; padding: 4px; }
  .cal-lead-chip   { font-size: 9px; padding: 2px 4px; }
  .cal-chip-name   { display: none; }
  .cal-week-grid {
    grid-template-columns: repeat(7, 100px) !important;
    width: 100%;
    min-width: 0;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  /* Settings: nav items 2-up grid; smaller card padding. */
  #view-settings   { padding: 12px; }
  #view-changelog,
  #view-guida      { padding: 12px; }
  .settings-nav    { gap: 4px !important; }
  .settings-nav-item {
    flex: 1;
    min-width: calc(50% - 4px);
    justify-content: center;
    text-align: center;
    font-size: 12px;
    padding: 8px 10px;
  }
  .settings-nav-item .ti { font-size: 14px; }
  .settings-card   { padding: 16px; }

  /* Profile: stack header centered. */
  .profile-wrap   { padding: 12px; }
  .profile-header {
    flex-direction: column;
    text-align: center;
    gap: 12px;
    padding: 16px;
  }

  /* Modals: fill the overlay's flex content area. The overlay has
     padding:16px so width:100% gives a calc(100vw - 32px) modal that
     can't overflow horizontally. */
  .modal-box {
    width: 100% !important;
    max-width: none !important;
    min-width: 0 !important;
    margin: 0;
    padding: 20px;
  }
  .confirm-box { width: 100%; }

  /* Import wizard: tighten the validation summary + mapping rows. */
  .import-header h3 { font-size: 15px; }
  .val-number       { font-size: 28px; }
  .mapping-grid     { max-height: 300px; }
  .mapping-row {
    grid-template-columns: 1fr 20px 1fr;
    gap: 6px;
    padding: 8px;
  }

  /* Floating add-lead button: bigger thumb target. Keep the desktop
     26px icon — a smaller icon on a larger button looks under-filled. */
  .fab-add-lead {
    bottom: 16px;
    right: 16px;
    width: 52px;
    height: 52px;
  }

  /* Toast container: lift above the FAB and span the bottom edge so
     long messages don't overflow off-screen. FAB top edge at
     16 + 52 = 68 from bottom; leave a 16px gap. */
  #toast-container {
    bottom: 84px;
    right: 16px;
    left: 16px;
    align-items: flex-end;
  }
  #toast-container .toast { min-width: 0; max-width: 100%; }
}

/* ------ TABLET (769–1024px) ------ */
@media (min-width: 769px) and (max-width: 1024px) {
  .kpi-grid    { grid-template-columns: repeat(4, 1fr) !important; }
  .charts-grid { grid-template-columns: repeat(2, 1fr); }
  .drawer      { width: 420px; }
  .kanban-column {
    width:     240px !important;
    min-width: 240px !important;
    max-width: 240px !important;
  }
  .settings-nav-item { font-size: 12px; padding: 8px 12px; }
}

/* ------ SMALL MOBILE (< 390px / iPhone SE) ------ */
@media (max-width: 390px) {
  .kpi-grid          { grid-template-columns: 1fr !important; }
  .kpi-value         { font-size: 20px; }
  .kanban-column {
    width:     240px !important;
    min-width: 240px !important;
    max-width: 240px !important;
  }
  .settings-nav-item { min-width: 100%; }
  .cal-cell          { min-height: 44px; }
}

/* ------ TOUCH DEVICES ------ */
/* Reveal hover-only affordances on touch devices that can't fire
   hover/focus-within reliably from a tap. Field-row edit pencil is the
   biggest offender — it's opacity:0 by default, so the drawer looks
   read-only on mobile. */
@media (hover: none) and (pointer: coarse) {
  .btn-edit-field { opacity: 1; }
}

/* ============================================================
   INFO PAGES — app footer + Novità (changelog) + Guida
   ============================================================ */

/* Info pages own their vertical scroll, exactly like #view-dashboard /
   #view-settings. The .view.active default is overflow:hidden, so without this
   tall content (full changelog / full guida) gets clipped. ID specificity beats
   the .view.active class rule, so no !important is needed. The footer sits in
   normal flow (not fixed) and shrinks #app-main rather than overlapping it, so
   no extra padding-bottom for the footer is required. */
#view-changelog,
#view-guida {
  overflow-y: auto;
  height: 100%;
  padding: 24px;
  background: var(--bg-app);
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

/* Profile owns its vertical scroll, exactly like #view-dashboard /
   #view-settings / #view-changelog. The .view.active default is
   overflow:hidden, so without this tall profile content gets clipped.
   No padding here — .profile-wrap already supplies its own 24px (and the
   form cap/centering), so adding padding on the view would double it. */
#view-profile {
  overflow-y: auto;
  height: 100%;
  background: var(--bg-app);
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

/* Anagrafica owns its vertical scroll, exactly like #view-dashboard /
   #view-settings / #view-profile. The .view.active default is flex-column +
   overflow:hidden, which collapsed/clipped the list so nothing rendered. ID
   specificity beats the .view.active class rule, so no !important is needed.
   No padding here: the list root (.anag-view--list) is padding:0 so the token
   bar goes edge-to-edge, and the 20px inset is re-applied on #anag-table. */
#view-anagrafica {
  overflow-y: auto;
  height: 100%;
  background: var(--bg-app);
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

/* Scheda cliente owns its vertical scroll too — twin of #view-anagrafica. The
   .view.active default (overflow:hidden) was clipping long schede (many
   referenti/indirizzi/attività). ID specificity beats .view.active,
   so no !important; .anag-view already supplies its own 20px padding. */
#view-scheda-cliente {
  overflow-y: auto;
  height: 100%;
  background: var(--bg-app);
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

/* Back-to-board header for the footer-reached info pages. Aligned to the
   760px content card's left edge; the top navbar stays persistent. */
.page-back {
  max-width: 760px;
  margin: 0 auto 12px;
}
.page-back-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background .12s, color .12s, border-color .12s;
}
.page-back-btn:hover {
  color: var(--text-primary);
  border-color: var(--accent);
  background: var(--bg-card-hover);
}
.page-back-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ------ Novità (changelog) ------ */
.changelog-entry {
  padding: 14px 0;
  border-top: 1px solid var(--border);
}
.changelog-entry:first-of-type { border-top: none; padding-top: 4px; }
.changelog-entry-head {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 8px;
}
.changelog-badge {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 700;
  background: var(--accent-light);
  color: var(--accent);
}
.changelog-ver-title {
  font-weight: 600;
  color: var(--text-primary);
}
.changelog-date {
  margin-left: auto;
  font-size: 12px;
  color: var(--text-muted);
}
.changelog-list {
  margin: 0;
  padding-left: 20px;
  color: var(--text-secondary);
}
.changelog-list li { margin: 4px 0; line-height: 1.5; }

/* ------ Guida ------ */
.guida-section {
  padding: 16px 0;
  border-top: 1px solid var(--border);
}
.guida-section:first-of-type { border-top: none; padding-top: 4px; }
.guida-section-title {
  margin: 0 0 8px;
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary);
}
.guida-section-body {
  color: var(--text-secondary);
  line-height: 1.6;
  font-size: 14px;
}
.guida-section-body p  { margin: 0 0 10px; }
.guida-section-body p:last-child { margin-bottom: 0; }
.guida-section-body ul { margin: 0 0 10px; padding-left: 22px; }
.guida-section-body li { margin: 4px 0; }
.guida-section-body strong { color: var(--text-primary); }

/* ============================================================
   Audit log — per-card activity filter chips + project view
   ============================================================ */

/* Per-card timeline filter chips (lead panel) */
.activity-filters {
  display: flex;
  gap: 6px;
  margin: 0 0 10px;
  flex-wrap: wrap;
}
.act-chip {
  border: 1px solid var(--border);
  background: var(--bg-input);
  color: var(--text-secondary);
  font-size: 12px;
  font-weight: 600;
  padding: 4px 12px;
  border-radius: 999px;
  cursor: pointer;
  transition: background .12s, color .12s, border-color .12s;
}
.act-chip:hover { border-color: var(--accent); color: var(--text-primary); }
.act-chip.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

/* Segnalazioni view — full-width view that owns its vertical scroll, like
   #view-settings / #view-audit. Without padding/overflow here it inherited the
   .view.active default (overflow:hidden, no padding) → content touched the edges
   and long lists were clipped instead of scrolling. */
#view-segnalazioni {
  padding: 24px;
  overflow-y: auto;
  height: 100%;
}
.segn-wrap {
  width: 100%;
  max-width: 1800px;
  margin: 0 auto;
}
/* Status select in the admin "Gestione segnalazioni" list: opt out of the
   global form `select { width:100% }` so it sits at its natural width on the
   right of the flex row, leaving the content (flex:1) readable instead of
   collapsed. */
.segn-status-select { flex: 0 0 auto; width: auto; min-width: 150px; }
/* "Nuova segnalazione" (form) ⟷ "Le mie segnalazioni" (lista) affiancate.
   La card "Gestione segnalazioni" (super_admin) sta full-width SOTTO, fuori da
   questa grid. Il gap verticale prima della card Gestione è il margin-bottom. */
.segn-top {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  align-items: start;
  margin-bottom: 16px;
}
@media (max-width: 768px) {
  .segn-top { grid-template-columns: 1fr; }
}

/* Project Audit view — full-width view that owns its vertical scroll, exactly
   like #view-dashboard / #view-settings (the .view.active default is
   overflow:hidden, which would otherwise kill scrolling). */
#view-audit {
  padding: 24px !important;
  overflow-y: auto !important;
  height: 100% !important;
  background: var(--bg-app);
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}
.audit-wrap { width: 100%; padding: 0 0 8px; }
.audit-head { margin-bottom: 16px; }
.audit-title { display: flex; align-items: center; gap: 8px; font-size: 20px; margin: 0 0 4px; color: var(--text-primary); }
.audit-sub { margin: 0; font-size: 13px; color: var(--text-secondary); }

.audit-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}
.audit-chips { display: flex; gap: 6px; flex-wrap: wrap; }
.audit-chip {
  border: 1px solid var(--border);
  background: var(--bg-input);
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 600;
  padding: 6px 14px;
  border-radius: 999px;
  cursor: pointer;
}
.audit-chip:hover { border-color: var(--accent); color: var(--text-primary); }
.audit-chip.active { background: var(--accent); border-color: var(--accent); color: #fff; }

.audit-filter-grp { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.audit-date { font-size: 12px; color: var(--text-secondary); display: inline-flex; align-items: center; gap: 4px; }
.audit-input {
  border: 1px solid var(--border);
  background: var(--bg-input);
  color: var(--text-primary);
  border-radius: var(--radius-sm);
  padding: 6px 10px;
  font-size: 13px;
}
.audit-input:focus { outline: none; border-color: var(--border-focus); }

.audit-table-wrap {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--bg-card);
}
.audit-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.audit-table thead th {
  text-align: left;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--text-secondary);
  background: var(--bg-card-hover);
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
}
.audit-table tbody td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  color: var(--text-primary);
  vertical-align: middle;
}
.audit-table tbody tr:last-child td { border-bottom: none; }
.audit-table tbody tr:hover { background: var(--bg-card-hover); }
.audit-when { white-space: nowrap; color: var(--text-secondary); }
.audit-empty { text-align: center; color: var(--text-secondary); padding: 28px 12px; }

.audit-lead {
  font: inherit;
  color: var(--text-primary);
  background: none;
  border: none;
  padding: 0;
  text-align: left;
}
.audit-lead--link { color: var(--accent); cursor: pointer; font-weight: 600; }
.audit-lead--link:hover { text-decoration: underline; }
.audit-trash { color: var(--text-secondary); font-size: 12px; margin-left: 4px; }

.audit-event { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.audit-delta { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.audit-delta .ti-arrow-right { font-size: 12px; color: var(--text-secondary); }
.audit-old { color: var(--text-secondary); }
.audit-new { color: var(--text-primary); font-weight: 600; }

.audit-footer { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 12px; }
.audit-count { font-size: 12px; color: var(--text-secondary); }

@media (max-width: 720px) {
  #view-audit { padding: 12px !important; }
  .audit-table thead { display: none; }
  .audit-table tbody td { display: block; border: none; padding: 4px 14px; }
  .audit-table tbody tr { display: block; border-bottom: 1px solid var(--border); padding: 8px 0; }
  .audit-filters { flex-direction: column; align-items: stretch; }
}

/* ============================================================
   Dashboard — "In stallo" / aging section
   ============================================================ */
.section-sub { font-size: 12px; color: var(--text-secondary); margin-left: 8px; }

.aging-bands {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  /* L/R margin so the bands don't touch the .dash-section borders (the section
     has no padding so .data-table can sit edge-to-edge with its own cell pad). */
  margin: 4px 20px 16px;
}
/* Inset for the NON-tabular section bodies that would otherwise hug the section
   borders (under the header / sides): kpi-grid (Esiti / Registro), charts-grid
   (bar charts), aging-bands (In stallo). The .data-table / #followup-table-wrap
   are deliberately NOT listed (cells carry their own padding), and the top-level
   dashboard kpi-grid/charts-grid are NOT .dash-section children, so they stay
   full-width. Wins over the base .aging-bands margin by specificity (0,2,0). */
.dash-section > .kpi-grid,
.dash-section > .charts-grid,
.dash-section > .aging-bands {
  padding: 16px 20px;   /* simmetrico top/bottom + L/R */
  margin: 0;            /* neutralizza i margin ereditati: kpi-grid 24px, charts-grid 16px, aging-bands 4/20/16 */
}
.aging-band {
  border: 1px solid var(--border);
  border-left-width: 3px;
  border-radius: var(--radius-sm);
  background: var(--bg-card);
  padding: 10px 12px;
  text-align: center;
}
.aging-band__count { font-size: 20px; font-weight: 700; color: var(--text-primary); line-height: 1.1; }
.aging-band__label { font-size: 11px; color: var(--text-secondary); margin-top: 2px; }
.aging-band--ok   { border-left-color: var(--success); }
.aging-band--warn { border-left-color: var(--warning); }
.aging-band--high { border-left-color: #f97316; }
.aging-band--crit { border-left-color: var(--danger); }

.aging-table { width: 100%; }
.aging-row { cursor: pointer; transition: background .12s; }
.aging-row:hover { background: var(--bg-card-hover); }
.aging-go { text-align: right; color: var(--text-muted); }

.aging-owner-cell { display: inline-flex; align-items: center; gap: 8px; min-width: 0; }
.aging-owner {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  font-size: 9px;
  font-weight: 700;
  background: var(--bg-column);
  color: var(--text-secondary);
  border: 1px solid var(--border);
}
.aging-owner-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.aging-days {
  font-size: 12px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 999px;
  white-space: nowrap;
}
.aging-days--ok   { color: var(--success); background: var(--success-light); }
.aging-days--warn { color: var(--warning); background: var(--warning-light); }
.aging-days--high { color: #f97316;        background: var(--warning-light); }
.aging-days--crit { color: var(--danger);  background: var(--danger-light);  }

@media (max-width: 640px) {
  .aging-bands { grid-template-columns: repeat(2, 1fr); }
  .aging-owner-name { display: none; }
}

/* ============================================================
   Anagrafica (global customer registry) — reuses .filter-bar,
   .ms-*, .leads-table, .active-chip, .modal. Only the bits below
   are net-new (chips, header layout, scheda detail).
   ============================================================ */
.anag-view { padding: 20px; }
.anag-loading { padding: 40px 20px; color: var(--text-secondary); text-align: center; }

/* LIST view (AnagraficaView) only: the token bar must sit EDGE-TO-EDGE like the
   board's #filter-region bar and the calendar (full-width strip + its own
   12px 20px padding + border-bottom), not inset as a padded card. So the root
   drops its 20px padding and the inset is re-applied only to the content below
   the bar (#anag-table). Scoped via the --list modifier so the SHARED .anag-view
   used by the scheda-cliente detail view (.anag-view.scheda-view) keeps its
   20px card padding untouched. */
.anag-view--list { padding: 0; }
.anag-view--list #anag-table { padding: 20px; }

.anag-header {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; margin-bottom: 14px;
}
/* Page title now lives INSIDE the token bar's row1 (actionsLeft), so it must sit
   inline in the ~34px row: smaller, no margins, single line. */
.anag-title {
  display: flex; align-items: center; gap: 8px;
  font-size: 16px; font-weight: 700; line-height: 1.2;
  letter-spacing: -0.2px; white-space: nowrap; margin: 0;
}

/* Import CSV (Fase B3) — row-status badges + modal hints. */
.import-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: var(--radius-sm);
  font-size: 11px;
  font-weight: 600;
}
.import-badge--valid { background: var(--success-light); color: var(--success); }
.import-badge--skip  { background: var(--warning-light); color: var(--warning); }
.import-badge--error { background: var(--danger-light);  color: var(--danger);  }
.import-hint { font-size: 12px; color: var(--text-secondary); margin: 0 0 10px; }
.import-summary { font-size: 13px; margin: 0 0 8px; }

/* Status / source chip in table + scheda. */
.anag-chip {
  display: inline-flex; align-items: center;
  font-size: 12px; font-weight: 600;
  padding: 2px 9px; border-radius: 20px;
  background: var(--bg-muted, rgba(0,0,0,0.05)); color: var(--text-secondary);
  border: 1px solid var(--border, rgba(0,0,0,0.1));
}
.anag-chip--empty { background: none; border-color: transparent; }

.anag-table tbody tr.anag-row { cursor: pointer; }
.anag-empty { padding: 40px 20px; text-align: center; }

/* Client table reads as a rounded card like the app's other table cards
   (same --radius-lg as .dash-section / .kpi-card). overflow:hidden clips the
   footer/last row (bottom) to the arc. Scoped to .anag-view so the SHARED
   .table-view-wrap on the board (table-view.js, intentionally edge-to-edge)
   stays untouched. min-height reset so the card hugs its content instead of
   the board's fill-height. */
.anag-view .table-view-wrap {
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  min-height: 0;
}
/* The header cells are position:sticky with their own background, so they
   paint over (escape) the wrapper's rounded clip → the TOP corners stay
   square while the footer below clips fine. Round the first/last header cells
   to match the wrapper so the grey header follows the arc too. */
.anag-view .table-view-wrap thead th:first-child { border-top-left-radius: var(--radius-lg); }
.anag-view .table-view-wrap thead th:last-child  { border-top-right-radius: var(--radius-lg); }

/* Filter dropdowns (.ms-panel) open downward over the table below. The table's
   sticky header cells (.leads-table th) carry z-index:10, which would otherwise
   paint OVER an open dropdown. Lift the anagrafica filter-bar (and the dropdown
   in its stacking context) above the sticky headers. The .ms-panel lives inside
   the filter-bar — a SIBLING of .table-view-wrap — so the wrap's overflow:hidden
   (rounding fix) never clips it. Scoped to .anag-view so the board's shared
   .filter-bar (z-index:3) is untouched and does not regress. Stays well below
   navbar/drawer (z >= 50). */
.anag-view .filter-bar { z-index: 20; }
.anag-empty p { color: var(--text-secondary); margin: 8px 0 14px; }

/* Scheda cliente (B2a stub) */
.scheda-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius); padding: 20px; margin-bottom: 16px;
  box-shadow: var(--shadow-sm);
}
/* Header identità: monogramma + nome/meta + chips a destra. */
.scheda-head {
  display: flex; align-items: center; flex-wrap: wrap;
  gap: 14px; margin-bottom: 16px;
}
.scheda-monogram {
  width: 48px; height: 48px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 16px; font-weight: 600; flex-shrink: 0;
  background: var(--bg-input); color: var(--text-secondary);
}
.scheda-identity { flex: 1; min-width: 160px; }
.scheda-meta-line {
  font-size: 13px; color: var(--text-secondary);
  display: flex; align-items: center; flex-wrap: wrap; gap: 6px; margin-top: 2px;
}
.scheda-meta-sep { color: var(--text-muted); }
.scheda-name { margin: 0; font-size: 20px; }
.scheda-chips { display: flex; gap: 6px; }
/* Modifica button anchored to the far right of the header card. */
.scheda-head-edit { margin-left: auto; flex-shrink: 0; }
.scheda-meta { display: grid; grid-template-columns: repeat(auto-fit, minmax(360px, 1fr)); gap: 12px; }
/* Anagrafica ridotta: il grid Dati ha un solo campo (Settore) → una colonna piena. */
.scheda-meta--single { grid-template-columns: 1fr; }
.scheda-meta-item {
  display: flex; flex-direction: column; gap: 2px;
  background: var(--bg-input); border-radius: var(--radius); padding: 12px 14px;
}
.scheda-meta-label { font-size: 12px; letter-spacing: 0; color: var(--text-secondary); }
.scheda-meta-item > span:last-child { font-size: 15px; }
.scheda-val-icon { color: var(--text-muted); font-size: 14px; vertical-align: -1px; }
.scheda-placeholder {
  display: flex; align-items: center; gap: 8px;
  padding: 16px 20px; border: 1px dashed var(--border, rgba(0,0,0,0.15));
  border-radius: 10px; color: var(--text-secondary);
}
.scheda-note { margin-top: 14px; }
.scheda-note p { margin: 4px 0 0; white-space: pre-wrap; }

/* Inline-editable scheda fields (B1): display + hidden input + pencil per field. */
.anag-field-value { display: flex; align-items: center; gap: 6px; }
.anag-display { font-size: 15px; flex: 1; min-width: 0; cursor: pointer; word-break: break-word; }
.anag-display a { color: var(--accent); }
.anag-display a:hover { text-decoration: underline; }
.anag-editable--wide .anag-display { white-space: pre-wrap; } /* note keeps newlines */
.anag-display-empty { color: var(--text-muted); font-style: italic; }
.anag-input {
  width: 100%; box-sizing: border-box;
  border: 1px solid var(--border-focus);
  background: var(--bg-card); color: var(--text-primary);
  border-radius: var(--radius-sm); padding: 6px 8px;
  font-size: 14px; font-family: inherit;
}
.anag-input:focus { outline: none; }
textarea.anag-input { resize: vertical; }
.anag-editable--wide { grid-column: 1 / -1; }
/* Pencil: faint at rest (global .btn-edit-field), full on row hover/focus. */
.anag-editable:hover .btn-edit-field,
.anag-editable:focus-within .btn-edit-field { opacity: 1; }
.anag-field-err { color: var(--danger); font-size: 12px; margin: 4px 0 0; }

/* Header name (ragione_sociale) inline edit. */
.scheda-name { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.scheda-name .anag-display { cursor: pointer; font-size: inherit; flex: 0 1 auto; }
.anag-input--name { font-size: 20px; font-weight: 700; max-width: 420px; }
.scheda-name:hover .btn-edit-field,
.scheda-name:focus-within .btn-edit-field { opacity: 1; }

/* Collapsible sections (chevron + .hidden, like kanban "Filtri avanzati") */
.scheda-section {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius); margin-bottom: 14px; overflow: hidden;
  box-shadow: var(--shadow-sm);
}
.scheda-section-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px; padding: 10px 14px;
}
.scheda-section-toggle {
  display: flex; align-items: center; gap: 8px;
  background: none; border: none; cursor: pointer;
  font-size: 15px; font-weight: 600; color: var(--text-primary);
  padding: 4px 2px;
}
.scheda-section-toggle .scheda-chevron { color: var(--text-secondary); }
/* Neutral icon pill next to the section title (Proposta 1). */
.scheda-section-toggle .scheda-section-icon {
  width: 28px; height: 28px; border-radius: var(--radius);
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--bg-input); color: var(--text-secondary); font-size: 16px;
}
.scheda-section-actions { display: flex; gap: 6px; align-items: center; }
/* Linked-leads count in the "Attività CRM" header — sober, secondary, right. */
.scheda-attivita-count {
  color: var(--text-secondary);
  font-size: 14px;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
}
.scheda-section-body { padding: 4px 14px 14px; }
.scheda-section-body.hidden { display: none; }
.scheda-empty {
  display: flex; align-items: center; gap: 8px;
  color: var(--text-muted); padding: 8px 2px;
}
.scheda-empty i { font-size: 20px; flex-shrink: 0; }
.scheda-empty-hint { display: block; font-size: 13px; color: var(--text-muted); margin-top: 2px; }

/* Sub-entity row (indirizzo / referente) */
.scheda-item {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; border: 1px solid var(--border, rgba(0,0,0,0.08));
  border-radius: 8px; margin-bottom: 8px;
}
.scheda-item.is-principale { border-color: var(--accent, #2563eb); background: var(--accent-light, rgba(37,99,235,0.06)); }
.scheda-item-main { flex: 1; min-width: 0; }
.scheda-item-title { font-weight: 600; display: flex; align-items: center; gap: 6px; }
.scheda-item-sub { font-size: 13px; color: var(--text-secondary); margin-top: 2px; }
.scheda-item-actions { display: flex; gap: 4px; }
.principale-badge {
  font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em;
  color: var(--accent, #2563eb); background: var(--accent-light, rgba(37,99,235,0.12));
  border-radius: 10px; padding: 1px 7px;
}
.star-btn {
  background: none; border: none; cursor: pointer; padding: 4px;
  color: var(--text-secondary); font-size: 18px; line-height: 1;
}
.star-btn:hover { color: #f59e0b; }
.star-btn.active { color: #f59e0b; }

/* Riconciliazione anagrafiche (settings — Fase 2 B6) */
#recon-toolbar { margin: 8px 0 4px; }
#recon-list { margin-top: 14px; display: flex; flex-direction: column; gap: 10px; }
.recon-loading, .recon-empty { color: var(--text-secondary); padding: 12px 2px; }
.recon-empty { display: flex; align-items: center; gap: 8px; }
.recon-row {
  border: 1px solid var(--border, rgba(0,0,0,0.08)); border-radius: 10px;
  padding: 12px 14px; background: var(--surface, #fff);
}
.recon-head { display: flex; align-items: baseline; gap: 10px; margin-bottom: 8px; }
.recon-cn { font-weight: 700; font-size: 15px; }
.recon-count {
  font-size: 12px; color: var(--text-secondary);
  background: var(--surface-2, rgba(0,0,0,0.05)); border-radius: 10px; padding: 1px 8px;
}
.recon-suggs { display: flex; flex-direction: column; gap: 6px; margin-bottom: 10px; }
.recon-sugg { display: flex; align-items: center; gap: 10px; }
.recon-sugg-name { font-weight: 600; }
.recon-nosugg { font-size: 13px; color: var(--text-secondary); margin-bottom: 10px; }
.recon-badge {
  font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em;
  border-radius: 10px; padding: 1px 7px;
}
.recon-badge--exact { color: #166534; background: rgba(22,101,52,0.12); }
.recon-badge--fuzzy { color: #92400e; background: rgba(146,64,14,0.12); }
.recon-sugg .btn-sm { margin-left: auto; }
.recon-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.btn-text {
  background: none; border: none; color: var(--text-secondary); cursor: pointer;
  padding: 6px 8px; border-radius: 6px;
}
.btn-text:hover { color: var(--text-primary, #111); background: var(--surface-2, rgba(0,0,0,0.05)); }

/* Attività CRM (leads linked to the cliente — Fase 2 B5) */
.scheda-attivita-list { display: flex; flex-direction: column; gap: 8px; }
.scheda-attivita-row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 8px 10px; border: 1px solid var(--border, rgba(0,0,0,0.08));
  border-radius: 8px; cursor: pointer; transition: background 0.12s, border-color 0.12s;
}
.scheda-attivita-row:hover { border-color: var(--accent, #2563eb); background: var(--accent-light, rgba(37,99,235,0.06)); }
.scheda-attivita-row:focus-visible { outline: 2px solid var(--accent, #2563eb); outline-offset: 1px; }
.scheda-attivita-main { min-width: 0; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.scheda-attivita-name { font-weight: 600; }
.scheda-attivita-proj { font-size: 12px; color: var(--text-secondary); }
.scheda-attivita-proj::before { content: "·"; margin-right: 8px; color: var(--text-secondary); }
.scheda-attivita-meta { display: flex; align-items: center; gap: 12px; flex-shrink: 0; flex-wrap: wrap; justify-content: flex-end; }
.scheda-attivita-val { font-weight: 600; }
.scheda-attivita-owner, .scheda-attivita-date { font-size: 12px; color: var(--text-secondary); }
.scheda-attivita-hidden {
  margin-top: 10px; padding: 6px 2px; font-size: 13px; color: var(--text-secondary);
}

/* Enum catalog rows (settings → Anagrafica — Cataloghi) */
.enum-dot {
  display: inline-block; width: 12px; height: 12px; border-radius: 50%;
  margin-right: 8px; vertical-align: middle;
  border: 1px solid rgba(0,0,0,0.15);
}
.enum-dot--none { background: var(--bg-muted, rgba(0,0,0,0.06)); }

/* Customer lookup widget (lead card — Fase 2 B3). Reuses .ms-panel styling. */
.cl-wrap { position: relative; }
.cl-input { width: 100%; }
.cl-panel {
  position: absolute; left: 0; right: 0; top: calc(100% + 4px); z-index: 50;
  max-height: 280px; overflow-y: auto; padding: 4px;
}
.cl-opt {
  display: flex; flex-direction: column; align-items: flex-start; gap: 1px;
  width: 100%; text-align: left; cursor: pointer;
}
.cl-name { font-weight: 600; }
.cl-sub  { font-size: 12px; color: var(--text-secondary); }
.cl-empty { padding: 8px 10px; font-size: 13px; color: var(--text-secondary); }
.cl-actions { border-top: 1px solid var(--border, rgba(0,0,0,0.08)); margin-top: 4px; padding-top: 4px; }
.cl-action {
  display: flex; align-items: center; gap: 6px; width: 100%; text-align: left;
  background: none; border: none; cursor: pointer; padding: 8px 10px; border-radius: 6px;
  font-size: 13px; color: var(--accent, #2563eb);
}
.cl-action:hover { background: var(--accent-light, rgba(37,99,235,0.08)); }
.btn-client-link { white-space: nowrap; }

/* ============================================================
   Dashboard — layout "B" (hero numbers, small numbers, past/future
   column charts, Ferme da tempo + Attività side by side)
   ============================================================ */
.dsh-hero  { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; margin-bottom: 12px; }
.dsh-stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin-bottom: 16px; }
.dsh-two   { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; margin-bottom: 16px; align-items: start; }
.dsh-two > .dash-section { margin-bottom: 0; }

.dsh-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 14px 18px;
  min-width: 0;
}
.dsh-card--hero { padding: 18px 20px; }
.dsh-label {
  display: flex; align-items: center; gap: 6px;
  font-size: 11px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase;
  color: var(--text-muted);
}
.dsh-value {
  margin-top: 8px;
  font-size: 32px; font-weight: 700; letter-spacing: -.02em; line-height: 1.1;
  color: var(--text-primary);
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
}
.dsh-value--sm { font-size: 20px; margin-top: 6px; }
.dsh-sub { margin-top: 4px; font-size: 12px; color: var(--text-secondary); }
.dsh-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.dsh-dot--win  { background: var(--chart-win); }
.dsh-dot--loss { background: var(--chart-loss); }

.dsh-chart-card { padding: 18px 20px; }
.dsh-card-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; margin-bottom: 14px; }
.dsh-card-head h3 { margin: 0; font-size: 14px; font-weight: 600; color: var(--text-primary); }
.dsh-card-head span { font-size: 12px; color: var(--text-muted); white-space: nowrap; }

/* Column chart */
.cc { position: relative; }
.cc-plot {
  display: flex; align-items: stretch; gap: 6px;
  height: 160px;
  border-bottom: 1px solid var(--border);
}
.cc-col {
  flex: 1 1 0; min-width: 0;
  display: flex; align-items: flex-end; justify-content: center;
  border-radius: 6px 6px 0 0;
  cursor: default; outline: none;
}
.cc-col:hover, .cc-col:focus-visible { background: var(--bg-card-hover); }
.cc-col:focus-visible { box-shadow: inset 0 0 0 2px var(--accent); }
.cc-bars { display: flex; align-items: flex-end; justify-content: center; gap: 2px; height: 100%; width: 100%; }
.cc-bar { display: block; flex: 0 1 16px; min-width: 4px; border-radius: 4px 4px 0 0; }
.cc-bar--win  { background: var(--chart-win); }
.cc-bar--loss { background: var(--chart-loss); }
.cc-bar--open { background: var(--chart-open); flex-basis: 28px; }
.cc-bar--late { background: var(--chart-late); flex-basis: 28px; }
.cc-axis { display: flex; gap: 6px; padding-top: 6px; }
.cc-tick {
  flex: 1 1 0; min-width: 0; text-align: center;
  font-size: 11px; color: var(--text-muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.cc-legend { display: flex; flex-wrap: wrap; gap: 6px 16px; margin-top: 12px; font-size: 12px; color: var(--text-secondary); }
.cc-legend span { display: inline-flex; align-items: center; gap: 6px; }
.cc-legend .cc-swatch { flex: 0 0 10px; width: 10px; height: 10px; border-radius: 3px; }
.cc-tip {
  position: absolute; top: -8px; z-index: 5; pointer-events: none;
  transform: translateY(-100%);
  background: var(--bg-card); color: var(--text-primary);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  box-shadow: var(--shadow); padding: 8px 10px;
  font-size: 12px; line-height: 1.5; white-space: nowrap;
}
.cc-tip strong { display: block; font-size: 12px; text-transform: capitalize; }

/* Compact lists: Ferme da tempo + Attività in scadenza */
.dsh-list { list-style: none; margin: 0; padding: 0 0 6px; }
.dsh-list li {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 20px; border-top: 1px solid var(--border);
  cursor: pointer;
}
.dsh-list li:hover { background: var(--bg-card-hover); }
.dsh-list__main { min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.dsh-list__main strong { font-size: 13px; font-weight: 600; color: var(--text-primary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dsh-list__main span { font-size: 12px; color: var(--text-secondary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dsh-due { flex-shrink: 0; font-size: 12px; color: var(--text-secondary); white-space: nowrap; }
.dsh-due--late { color: var(--danger); font-weight: 600; }
.dsh-aging .aging-bands { padding: 16px 20px; margin: 0; }

@media (max-width: 1100px) {
  .dsh-two { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 767px) {
  .dsh-hero  { grid-template-columns: minmax(0, 1fr); gap: 10px; }
  .dsh-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .dsh-value { font-size: 28px; }
  .dsh-value--sm { font-size: 18px; }
  .cc-plot { height: 140px; gap: 3px; }
  .cc-axis { gap: 3px; }
  .cc-yr { display: none; }
  .dsh-aging .aging-bands { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

/* ============================================================
   Calendar — "Nuova attività" from a day (calendar.js openNewTask)
   ============================================================ */
.cal-cell[data-date], .cal-week-col[data-date] { cursor: pointer; }
.cal-cell[data-date] .cal-cell-header { position: relative; }
.cal-cell[data-date]:hover .cal-cell-header::after,
.cal-week-col[data-date]:hover .cal-week-header::after {
  content: '+';
  position: absolute; left: 8px; top: 2px;   /* left: the day number sits on the right */
  font-size: 16px; font-weight: 600; line-height: 1;
  color: var(--accent);
}
.cal-week-col[data-date] .cal-week-header { position: relative; }
.nt-assignees {
  display: flex; flex-direction: column; gap: 2px;
  max-height: 200px; overflow-y: auto;
  border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 4px;
}
.nt-hint { font-size: 12px; color: var(--text-secondary); padding: 6px 8px 2px; }
/* The options are <label>s inside .form-group: undo the uppercase form-label look. */
.nt-assignees .assignee-opt {
  gap: 8px; margin: 0;
  text-transform: none; letter-spacing: normal;
  font-size: 13px; font-weight: 500; color: var(--text-primary);
}
.nt-assignees .assignee-owner-tag { text-transform: none; }
.nt-assignees .assignee-opt-name { margin-left: 2px; }
