/* =========================================================================
   Palazzo Vitturi · Cost Intelligence · Apple-style design system v2.0
   Vanilla CSS · zero dipendenze esterne · system fonts

   REGOLA ORO (disciplina del colore brand):
   - ORO = identita' (brand mark, voce nav attiva), azione primaria
     (.btn-primary, stati .active/.suggested) e focus ring.
   - NEUTRO = hover secondari (icone riga, pill categorie, header tabella):
     background var(--surface-hover) + color var(--text). Mai oro sugli hover
     non-primari: l'oro si guadagna, non si spalma.
   ========================================================================= */
:root {
  color-scheme: light; /* i controlli nativi restano chiari anche in dark mode OS */
  --bg: #f5f5f7;
  --surface: #ffffff;
  --surface-2: #fafafc;
  --surface-hover: #f5f5f7;
  --border: #e8e8ed;
  --border-strong: #d8d8de;

  --text: #1d1d1f;
  --text-2: #6e6e73;
  --text-3: #86868b;

  --gold: #b8860b;
  --gold-light: #c9a84c;
  --gold-hover: #a67c0a;
  --gold-soft: #faf6ea;
  --gold-border: #ecdfbb;

  --green: #30a14e;
  --green-vivid: #30d158;
  --red: #e0342b;
  --red-vivid: #ff3b30;
  --amber: #e8890a;
  --amber-vivid: #ff9f0a;
  --blue: #0071e3;
  --violet: #7c3aed;
  --teal: #0d9488;
  --rose: #db2777;

  --shadow-sm: 0 1px 2px rgba(0,0,0,0.04);
  --shadow: 0 1px 3px rgba(0,0,0,0.04), 0 8px 24px rgba(0,0,0,0.06);
  --shadow-md: 0 2px 6px rgba(0,0,0,0.05), 0 16px 40px rgba(0,0,0,0.10);
  --shadow-lg: 0 8px 24px rgba(0,0,0,0.12), 0 32px 64px rgba(0,0,0,0.18);

  --r-lg: 20px;
  --r: 16px;
  --r-sm: 12px;
  --r-xs: 10px;
  --pill: 999px;

  --ease: cubic-bezier(0.4, 0, 0.2, 1);
  --t: 240ms var(--ease);
  --t-fast: 160ms var(--ease);

  --font: -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'SF Pro Text', 'Inter', system-ui, sans-serif;
  --mono: ui-monospace, 'SF Mono', 'JetBrains Mono', 'Menlo', monospace;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  display: flex;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}
[hidden] { display: none !important; }
a { color: inherit; text-decoration: none; }

/* ===================== Sidebar ===================== */
.sidebar {
  width: 256px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 26px 16px;
  display: flex;
  flex-direction: column;
  gap: 26px;
  flex-shrink: 0;
  height: 100vh;
  position: sticky;
  top: 0;
  z-index: 40;
}
.brand { display: flex; align-items: center; gap: 12px; padding: 0 6px; }
.brand-mark {
  width: 44px; height: 44px;
  background: linear-gradient(135deg, var(--gold-light) 0%, var(--gold-hover) 100%);
  color: #fff; font-weight: 800; font-size: 16px; letter-spacing: 0.4px;
  display: grid; place-items: center;
  border-radius: 13px;
  box-shadow: 0 4px 14px rgba(184,134,11,0.28);
}
.brand-title { font-weight: 600; font-size: 15px; color: var(--text); letter-spacing: -0.02em; }
.brand-sub { font-size: 11px; color: var(--text-3); letter-spacing: 1.4px; text-transform: uppercase; font-weight: 600; margin-top: 3px; }

nav { display: flex; flex-direction: column; gap: 3px; flex: 1; }
.nav-btn {
  background: transparent; border: 0; color: var(--text-2);
  text-align: left; font-family: inherit; font-size: 13.5px; font-weight: 500;
  padding: 11px 13px; border-radius: var(--r-sm);
  cursor: pointer; transition: var(--t-fast);
  display: flex; align-items: center; gap: 11px; position: relative;
}
.nav-ico { font-size: 15px; width: 18px; text-align: center; opacity: 0.9; }
.nav-btn:hover { background: var(--surface-hover); color: var(--text); }
.nav-btn:active { transform: scale(0.98); }
.nav-btn.active { background: var(--gold-soft); color: var(--gold-hover); font-weight: 600; }
.nav-badge {
  margin-left: auto; background: var(--red-vivid); color: #fff;
  font-size: 11px; font-weight: 700; padding: 2px 7px; border-radius: var(--pill);
  min-width: 20px; text-align: center; display: none;
}
.nav-badge:not(:empty) { display: inline-block; }

.sidebar-footer { display: flex; flex-direction: column; gap: 10px; }
.btn-ghost {
  background: var(--surface); border: 1px solid var(--border);
  color: var(--text-2); padding: 9px 13px; border-radius: var(--r-sm);
  font-family: inherit; font-size: 12.5px; font-weight: 500;
  cursor: pointer; transition: var(--t-fast);
  display: flex; align-items: center; gap: 8px; justify-content: center;
}
.btn-ghost:hover { background: var(--surface-hover); color: var(--text); border-color: var(--border-strong); }
.btn-ghost:active { transform: scale(0.98); }
.btn-ghost.btn-ai {
  background: linear-gradient(135deg, var(--gold-soft), #fffdf7);
  border-color: var(--gold-border); color: var(--gold-hover); font-weight: 600;
}
.btn-ghost.btn-ai span { font-size: 14px; }
.btn-ghost.btn-ai:hover { border-color: var(--gold); color: var(--gold); }
.btn-ghost.btn-ai.processing { background: var(--gold); color: #fff; border-color: var(--gold); pointer-events: none; animation: aiPulse 1.5s ease-in-out infinite; }
@keyframes aiPulse { 0%,100% { box-shadow: 0 0 0 0 rgba(184,134,11,0.4);} 50% { box-shadow: 0 0 0 8px rgba(184,134,11,0);} }
.version { font-size: 11px; color: var(--text-3); text-align: center; letter-spacing: 0.3px; }

.menu-toggle {
  display: none; position: fixed; top: 14px; left: 14px; z-index: 60;
  width: 42px; height: 42px; border-radius: var(--r-sm);
  background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow);
  font-size: 18px; cursor: pointer; color: var(--text);
}

/* ===================== Main ===================== */
.main { flex: 1; height: 100vh; overflow-y: auto; padding: 34px 40px 130px; scroll-behavior: smooth; }
.view { display: none; }
.view.active { display: block; animation: viewIn 0.34s var(--ease); }
@keyframes viewIn { from { opacity: 0; transform: translateY(8px);} to { opacity: 1; transform: translateY(0);} }

.view-header {
  display: flex; justify-content: space-between; align-items: flex-end;
  margin-bottom: 26px; padding-bottom: 20px; border-bottom: 1px solid var(--border); gap: 16px; flex-wrap: wrap;
}
.view-header h1 { font-size: 30px; font-weight: 700; letter-spacing: -0.03em; color: var(--text); }
.view-header p { color: var(--text-2); font-size: 13px; margin-top: 5px; }
.muted { color: var(--text-2); font-size: 12px; }
.header-actions { display: flex; gap: 10px; align-items: center; }

.pill {
  background: var(--surface); border: 1px solid var(--border);
  padding: 7px 13px; border-radius: var(--pill);
  font-size: 12px; color: var(--text-2); font-weight: 500; box-shadow: var(--shadow-sm);
}
.pill-btn { cursor: pointer; font-family: inherit; transition: var(--t-fast); }
.pill-btn:hover { background: var(--gold-soft); color: var(--gold-hover); border-color: var(--gold-border); }
.pill-btn:active { transform: scale(0.97); }

/* ===================== Buttons ===================== */
.btn {
  background: var(--surface); border: 1px solid var(--border);
  color: var(--text); padding: 10px 16px; border-radius: var(--r-sm);
  font-family: inherit; font-size: 13px; font-weight: 500;
  cursor: pointer; transition: var(--t-fast); display: inline-flex; align-items: center; gap: 6px; white-space: nowrap;
}
.btn:hover { background: var(--surface-hover); border-color: var(--border-strong); }
.btn:active { transform: scale(0.97); }
.btn-primary { background: linear-gradient(135deg, var(--gold) 0%, var(--gold-hover) 100%); color: #fff; border-color: transparent; font-weight: 600; box-shadow: 0 2px 8px rgba(184,134,11,0.24); }
.btn-primary:hover { transform: translateY(-1px); box-shadow: 0 6px 18px rgba(184,134,11,0.34); }
.btn-primary:active { transform: scale(0.97); }
.btn-success { background: var(--green); color: #fff; border-color: transparent; font-weight: 600; }
.btn-success:hover { background: #268a41; }
.btn-danger { background: transparent; color: var(--red); border: 1px solid #f5cfcc; font-weight: 500; }
.btn-danger:hover { background: #fdf2f1; border-color: var(--red); }
.btn-warn { background: linear-gradient(135deg, var(--amber), #d97706); color: #fff; border-color: transparent; font-weight: 600; }
.btn-warn:hover { transform: translateY(-1px); box-shadow: 0 6px 18px rgba(232,137,10,0.3); }
.ghost-sm { padding: 9px 13px; font-size: 12.5px; }

/* ===================== KPI ===================== */
.kpi-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 16px; margin-bottom: 22px; }
.kpi-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r);
  padding: 22px; position: relative; overflow: hidden; transition: var(--t); box-shadow: var(--shadow);
}
.kpi-card::before { content: ''; position: absolute; top: 0; left: 0; right: 0; height: 3px; }
.kpi-card.glow-1::before { background: linear-gradient(90deg, var(--gold), var(--gold-light)); }
.kpi-card.glow-2::before { background: linear-gradient(90deg, var(--green), var(--green-vivid)); }
/* scala semantica: 'Da pagare' = neutro (il rosso resta solo per 'scaduta') */
.kpi-card.glow-3::before { background: linear-gradient(90deg, #9a9aa0, #c4c4c9); }
.kpi-card.glow-danger::before { background: linear-gradient(90deg, #a01810, var(--red-vivid)); }
.kpi-card.glow-info::before { background: linear-gradient(90deg, var(--blue), #4aa3ff); }
.kpi-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }
.kpi-label { font-size: 11px; color: var(--text-2); letter-spacing: 0.4px; text-transform: uppercase; font-weight: 600; }
.kpi-value { font-size: 30px; font-weight: 700; margin-top: 10px; letter-spacing: -0.03em; color: var(--text); font-variant-numeric: tabular-nums; }
.kpi-sub { font-size: 12px; color: var(--text-2); margin-top: 4px; font-weight: 500; }

/* ===================== Cards ===================== */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 16px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r); padding: 22px; transition: var(--t); box-shadow: var(--shadow); }
.card.no-pad { padding: 0; overflow: hidden; }
.card.chart-card { margin-bottom: 16px; }
.card-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 18px; }
.card-head h3 { font-size: 15px; font-weight: 600; color: var(--text); letter-spacing: -0.01em; }

.svg-chart { width: 100%; }
.svg-chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.donut-wrap { display: flex; align-items: center; justify-content: center; gap: 24px; flex-wrap: wrap; }

/* segmented control */
.chart-toggle { display: inline-flex; background: var(--surface-hover); border-radius: var(--r-xs); padding: 3px; gap: 2px; }
.seg { border: 0; background: transparent; font-family: inherit; font-size: 12px; font-weight: 500; color: var(--text-2); padding: 6px 14px; border-radius: 8px; cursor: pointer; transition: var(--t-fast); }
.seg.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow-sm); font-weight: 600; }

/* year selector (dashboard) */
.year-seg { display: inline-flex; background: var(--surface-hover); border-radius: 999px; padding: 3px; gap: 2px; }
.year-btn { border: 0; background: transparent; font-family: inherit; font-size: 12px; font-weight: 600; color: var(--text-2); padding: 6px 14px; border-radius: 999px; cursor: pointer; transition: var(--t-fast); letter-spacing: -0.01em; }
.year-btn:hover { color: var(--text); }
.year-btn.active { background: var(--gold); color: #fff; box-shadow: var(--shadow-sm); }

/* KPI year-over-year */
.kpi-yoy { display: flex; align-items: baseline; gap: 8px; margin-top: 6px; font-size: 12px; flex-wrap: wrap; }
.kpi-yoy .yoy-up { color: #c62b22; font-weight: 700; }   /* costi in aumento = rosso (AA su bianco) */
.kpi-yoy .yoy-down { color: #1a7f37; font-weight: 700; } /* costi in calo = verde (AA su bianco) */
.kpi-yoy .yoy-delta { color: var(--text-2); font-weight: 500; }
.kpi-yoy .yoy-muted { color: var(--text-3); font-style: italic; }

.chart-legend { display: flex; flex-wrap: wrap; gap: 8px 16px; margin-top: 14px; }
.legend-item { display: flex; align-items: center; gap: 6px; font-size: 11.5px; color: var(--text-2); font-weight: 500; }
.legend-dot { width: 10px; height: 10px; border-radius: 3px; }

/* chart bars/lines animations */
.bar-rect { transition: transform 0.7s var(--ease), opacity 0.5s ease; transform-origin: bottom; }
.chart-tip { position: fixed; z-index: 300; background: var(--text); color: #fff; padding: 8px 12px; border-radius: 8px; font-size: 12px; font-weight: 500; pointer-events: none; box-shadow: var(--shadow-md); opacity: 0; transition: opacity 0.12s ease; white-space: nowrap; }
.chart-tip.show { opacity: 1; }

/* ===================== Search hero + filters ===================== */
.search-hero { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
.search-hero .search-ico { position: absolute; margin-left: 16px; font-size: 17px; color: var(--text-3); pointer-events: none; }
.search-hero input {
  flex: 1; background: var(--surface); border: 1px solid var(--border); color: var(--text);
  padding: 14px 16px 14px 44px; border-radius: var(--r-sm); font-family: inherit; font-size: 15px; font-weight: 500;
  box-shadow: var(--shadow-sm); transition: var(--t-fast);
}
.search-hero input::placeholder { color: var(--text-3); font-weight: 400; }
.search-hero input:focus { outline: none; border-color: var(--gold); box-shadow: 0 0 0 4px var(--gold-soft); }

.filter-bar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 12px; }
.fbtn, .date-field input {
  background: var(--surface); border: 1px solid var(--border); color: var(--text);
  padding: 9px 12px; border-radius: var(--r-xs); font-family: inherit; font-size: 12.5px; font-weight: 500; transition: var(--t-fast);
}
.fbtn { cursor: pointer; }
.fbtn:hover, .date-field:hover input { border-color: var(--border-strong); }
.fbtn:focus, .date-field input:focus { outline: none; border-color: var(--gold); box-shadow: 0 0 0 3px var(--gold-soft); }
.date-field { display: inline-flex; align-items: center; gap: 6px; font-size: 11px; color: var(--text-3); font-weight: 500; }

.active-chips { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; min-height: 0; }
.chip {
  display: inline-flex; align-items: center; gap: 7px; background: var(--gold-soft); color: var(--gold-hover);
  border: 1px solid var(--gold-border); border-radius: var(--pill); padding: 5px 8px 5px 12px; font-size: 12px; font-weight: 600;
  animation: chipIn 0.2s var(--ease);
}
@keyframes chipIn { from { opacity: 0; transform: scale(0.9);} to { opacity: 1; transform: scale(1);} }
.chip button { border: 0; background: rgba(0,0,0,0.06); color: inherit; width: 18px; height: 18px; border-radius: 50%; cursor: pointer; font-size: 12px; line-height: 1; display: grid; place-items: center; transition: var(--t-fast); }
.chip button:hover { background: rgba(0,0,0,0.14); }

/* ===================== Table ===================== */
/* il wrapper scrolla in verticale: cosi' il thead sticky si aggancia davvero.
   Offset tarato sull'altezza reale di header vista + search-hero + filtri +
   chips + footer tabella + padding .main (misurato: ~530px). Floor 320px per
   viewport bassi (li' un piccolo scroll di pagina e' inevitabile). */
.table-wrap { overflow: auto; max-height: max(320px, calc(100vh - 530px)); }
.datatable { width: 100%; border-collapse: collapse; font-size: 13px; }
.datatable thead th {
  text-align: left; padding: 13px 16px; font-size: 11px; font-weight: 600; color: var(--text-3);
  letter-spacing: 0.4px; text-transform: uppercase; border-bottom: 1px solid var(--border); background: var(--surface-2);
  position: sticky; top: 0; z-index: 2; white-space: nowrap; user-select: none;
  /* stacco netto dalle righe durante lo scroll (il border-bottom non "sticka" con border-collapse) */
  box-shadow: 0 1px 0 var(--border-strong), 0 3px 8px rgba(0,0,0,0.06);
}
.datatable thead th.sortable { cursor: pointer; }
.datatable thead th.sortable::after { content: ' ⇅'; opacity: 0.4; font-size: 11px; }
.datatable thead th.sort-asc::after { content: ' ↑'; opacity: 1; color: var(--text-2); }
.datatable thead th.sort-desc::after { content: ' ↓'; opacity: 1; color: var(--text-2); }
.datatable thead th.sortable:hover { color: var(--text); background: var(--surface-hover); }
.datatable thead th.num { text-align: right; }
.datatable tbody tr { border-bottom: 1px solid var(--border); transition: background var(--t-fast); }
.datatable tbody tr:hover { background: var(--surface-hover); cursor: pointer; }
.datatable tbody td { padding: 13px 16px; vertical-align: middle; color: var(--text); }
.datatable td.num { text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; color: var(--text); }
.supplier-cell { display: flex; flex-direction: column; gap: 2px; }
.supplier-cell .name { font-weight: 600; color: var(--text); display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.supplier-cell .piva { font-size: 11px; color: var(--text-2); font-family: var(--mono); }
.num-cell { font-family: var(--mono); font-size: 11px; color: var(--text-3); }

.tag { display: inline-block; font-size: 11px; font-weight: 700; padding: 3px 8px; border-radius: 6px; letter-spacing: 0.3px; text-transform: uppercase; border: 1px solid transparent; white-space: nowrap; }
.tag-rooms { background: #f3eefe; color: #6d28d9; border-color: #e0d4fd; }
.tag-fnb-food { background: #fff3e6; color: #c2410c; border-color: #fde0c2; }
.tag-fnb-beverage { background: #fce7f3; color: #be185d; border-color: #fbcfe8; }
.tag-it { background: #dbeafe; color: #1d4ed8; border-color: #bfdbfe; }
.tag-sm { background: #fce7f3; color: #be185d; border-color: #fbcfe8; }
.tag-utilities { background: #ccfbf1; color: #0f766e; border-color: #99f6e4; }
.tag-pom { background: #fef3c7; color: #b45309; border-color: #fde68a; }
.tag-ag { background: #f1f5f9; color: #475569; border-color: #e2e8f0; }
.tag-fixed { background: var(--gold-soft); color: var(--gold-hover); border-color: var(--gold-border); }
.tag-default { background: #f1f5f9; color: #64748b; border-color: #e2e8f0; }

/* status badge */
.st-badge { display: inline-flex; align-items: center; gap: 5px; font-size: 11px; font-weight: 600; padding: 4px 9px; border-radius: var(--pill); white-space: nowrap; }
/* scala semantica unica: pagata=verde, da pagare=neutro, in scadenza=ambra, scaduta=rosso */
.st-paid { background: #e7f7ec; color: var(--green); }
.st-unpaid { background: #ececf0; color: #48484d; }
.st-overdue { background: #b3261e; color: #fff; }
.st-due { background: #fff2e0; color: #b45309; }
.st-credit { background: #e7f7ec; color: var(--green); }
.st-none { background: var(--surface-hover); color: var(--text-3); }
.st-dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }

.action-btns { display: flex; gap: 6px; }
.icon-btn {
  background: var(--surface); border: 1px solid var(--border); color: var(--text-2);
  width: 32px; height: 32px; border-radius: 9px; cursor: pointer; display: grid; place-items: center;
  transition: var(--t-fast); font-size: 14px;
}
.icon-btn:hover { background: var(--surface-hover); color: var(--text); border-color: var(--border-strong); transform: translateY(-1px); }
.icon-btn:active { transform: scale(0.92); }
.table-footer { padding: 13px 16px; border-top: 1px solid var(--border); background: var(--surface-2); }

.badge-mini { font-size: 11px; font-weight: 700; padding: 2px 6px; border-radius: 5px; letter-spacing: 0.3px; }
.badge-estera { background: #eff6ff; color: var(--blue); border: 1px solid #bfdbfe; }
.badge-credit { background: #e7f7ec; color: var(--green); border: 1px solid #a7f3d0; }
.badge-review { background: #fff2e0; color: var(--amber); border: 1px solid #fde0c2; }
.badge-split { background: #f3eefe; color: var(--violet); border: 1px solid #e0d4fd; }
.metodo-mini { font-size: 11px; color: var(--text-3); font-weight: 500; }
.row-credit td { background: linear-gradient(90deg, rgba(48,161,78,0.04), transparent 40%); }

.amount-credit { color: var(--green) !important; font-weight: 700 !important; }

/* ===================== Skeleton ===================== */
.skeleton { background: linear-gradient(100deg, var(--surface-hover) 30%, #ececed 50%, var(--surface-hover) 70%); background-size: 200% 100%; animation: shimmer 1.3s infinite; border-radius: 8px; }
@keyframes shimmer { from { background-position: 200% 0;} to { background-position: -200% 0;} }
.skel-row { height: 46px; margin: 0; border-bottom: 1px solid var(--border); display: flex; align-items: center; padding: 0 16px; }
.skel-line { height: 12px; border-radius: 6px; }

/* ===================== Fornitori ===================== */
.forn-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); gap: 16px; }
.forn-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r); padding: 20px; cursor: pointer; transition: var(--t); box-shadow: var(--shadow); animation: viewIn 0.3s var(--ease); }
.forn-card:hover { transform: translateY(-3px); box-shadow: var(--shadow-md); border-color: var(--gold-border); }
.forn-card:active { transform: scale(0.99); }
.forn-name { font-size: 16px; font-weight: 600; color: var(--text); letter-spacing: -0.01em; }
.forn-meta { font-size: 11px; color: var(--text-3); font-family: var(--mono); margin-top: 3px; }
.forn-stats { display: flex; gap: 18px; margin: 16px 0 14px; }
.forn-stat .v { font-size: 18px; font-weight: 700; color: var(--text); font-variant-numeric: tabular-nums; letter-spacing: -0.02em; }
.forn-stat .v.due { color: #b45309; } /* 'da pagare' non e' mai rosso: ambra AA */
.forn-stat .l { font-size: 11px; color: var(--text-3); text-transform: uppercase; letter-spacing: 0.4px; font-weight: 600; margin-top: 2px; }
.forn-iban { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--r-xs); padding: 10px 12px; font-family: var(--mono); font-size: 11.5px; color: var(--text-2); display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.forn-iban .upd { font-family: var(--font); font-size: 11px; color: var(--text-3); white-space: nowrap; }

/* fornitore detail */
.fd-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; margin-bottom: 8px; }
.fd-title { font-size: 24px; font-weight: 700; letter-spacing: -0.02em; }
.fd-sub { font-size: 12px; color: var(--text-3); font-family: var(--mono); margin-top: 3px; }
.fd-section-title { font-size: 11px; font-weight: 700; color: var(--text-3); text-transform: uppercase; letter-spacing: 0.6px; margin: 24px 0 12px; }
.fd-mini-table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.fd-mini-table th { text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: 0.4px; color: var(--text-3); font-weight: 600; padding: 6px 8px; border-bottom: 1px solid var(--border); }
.fd-mini-table td { padding: 8px; border-bottom: 1px solid var(--border); }
.fd-mini-table td.num, .fd-mini-table th.num { text-align: right; font-variant-numeric: tabular-nums; }
.contact-form { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.contact-form .full { grid-column: 1 / -1; }
.contact-form label { display: block; font-size: 11px; text-transform: uppercase; letter-spacing: 0.4px; color: var(--text-3); font-weight: 600; margin-bottom: 5px; }
.btn-wa { background: #25D366; color: #fff; border-color: transparent; font-weight: 600; }
.btn-wa:hover { background: #1eb658; }

/* ===================== Scadenziario ===================== */
.scadenza-bucket { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r); margin-bottom: 16px; overflow: hidden; box-shadow: var(--shadow); }
.bucket-head { padding: 15px 22px; display: flex; justify-content: space-between; align-items: center; background: var(--surface-2); border-bottom: 1px solid var(--border); }
.bucket-head h3 { font-size: 14px; font-weight: 600; color: var(--text); display: flex; align-items: center; gap: 10px; }
.bucket-head .cnt { background: var(--surface); padding: 2px 9px; border-radius: var(--pill); font-size: 11px; font-weight: 700; color: var(--text-2); }
.bucket-head .total { font-variant-numeric: tabular-nums; color: var(--text); font-weight: 700; font-size: 15px; }
.bucket-head.danger { border-left: 3px solid var(--red); background: linear-gradient(90deg, #fdf2f1, var(--surface-2)); }
.bucket-head.warn { border-left: 3px solid var(--amber); background: linear-gradient(90deg, #fff7ed, var(--surface-2)); }
.bucket-head.info { border-left: 3px solid var(--blue); background: linear-gradient(90deg, #eff6ff, var(--surface-2)); }
.bucket-head.success { border-left: 3px solid var(--green); background: linear-gradient(90deg, #ecfdf5, var(--surface-2)); }
.bucket-head.credit { border-left: 3px solid var(--green); background: linear-gradient(90deg, #ecfdf5, var(--surface-2)); }
.scad-sort { display: flex; gap: 12px; margin-bottom: 14px; align-items: center; }
.scad-sort .lbl { font-size: 11px; color: var(--text-3); text-transform: uppercase; letter-spacing: 0.5px; font-weight: 600; }
.scad-sort button { border: 1px solid var(--border); background: var(--surface); border-radius: var(--pill); padding: 5px 12px; font-size: 12px; font-weight: 500; cursor: pointer; color: var(--text-2); transition: var(--t-fast); font-family: inherit; }
.scad-sort button.active { background: var(--gold-soft); color: var(--gold-hover); border-color: var(--gold-border); }

.scadenza-row { display: grid; grid-template-columns: 120px 1fr 120px 130px 190px 120px; gap: 16px; padding: 13px 22px; align-items: center; border-bottom: 1px solid var(--border); transition: var(--t-fast); cursor: pointer; }
.scadenza-row:last-child { border-bottom: 0; }
.scadenza-row:hover { background: var(--surface-hover); }
.scad-date { font-weight: 600; font-size: 13px; }
.scad-supp > div:first-child { color: var(--text); font-weight: 500; }
.scad-supp .num { font-size: 11px; color: var(--text-3); font-family: var(--mono); margin-top: 2px; }
.scad-amount { text-align: right; font-variant-numeric: tabular-nums; font-weight: 700; font-size: 15px; }
.scad-iban { font-family: var(--mono); font-size: 11px; color: var(--text-2); }
.scad-actions { display: flex; justify-content: flex-end; }
.days-badge { font-size: 11px; font-weight: 700; padding: 2px 7px; border-radius: var(--pill); margin-left: 6px; }
.days-over { background: #b3261e; color: #fff; }
.days-soon { background: #b45309; color: #fff; }

/* ===================== Classify queue (compact list) ===================== */
.queue-banner { display: flex; justify-content: space-between; align-items: center; gap: 16px; flex-wrap: wrap; margin-bottom: 16px; padding: 16px 20px; background: linear-gradient(135deg, #ecfdf5, #f0fdf9); border: 1px solid #b7ebd3; border-radius: var(--r); }
.qb-count { font-size: 15px; font-weight: 700; color: var(--text); }
.qb-help { font-size: 12px; color: var(--text-2); margin-top: 2px; }
.qb-actions { display: flex; gap: 8px; }

.qrow { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-sm); padding: 14px 16px; margin-bottom: 10px; box-shadow: var(--shadow-sm); transition: var(--t); animation: viewIn 0.25s var(--ease); }
.qrow:hover { box-shadow: var(--shadow); border-color: var(--border-strong); }
.qrow.done { opacity: 0.45; transform: scale(0.99); }
.qrow-top { display: flex; align-items: center; gap: 14px; }
.qrow-info { flex: 1; min-width: 0; }
.qrow-supp { font-weight: 600; font-size: 14px; color: var(--text); display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.qrow-meta { font-size: 11px; color: var(--text-2); margin-top: 2px; font-family: var(--mono); }
.qrow-amount { font-size: 17px; font-weight: 700; font-variant-numeric: tabular-nums; letter-spacing: -0.02em; white-space: nowrap; }
.qrow-auto { font-size: 11px; color: var(--text-3); margin-top: 3px; }
.qrow-auto .conf { font-weight: 600; }
.qrow-cats { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 12px; align-items: center; }
.qcat {
  border: 1px solid var(--border); background: var(--surface); color: var(--text-2);
  padding: 6px 11px; border-radius: var(--pill); font-size: 11px; font-weight: 600; cursor: pointer;
  font-family: inherit; transition: var(--t-fast); letter-spacing: 0.2px;
}
.qcat:hover { border-color: var(--border-strong); color: var(--text); background: var(--surface-hover); transform: translateY(-1px); }
.qcat:active { transform: scale(0.94); }
.qcat.suggested { border-color: var(--gold); color: var(--gold-hover); background: var(--gold-soft); box-shadow: 0 0 0 1px var(--gold-border); }
.qrow-actions { display: flex; gap: 6px; margin-left: auto; }
.qsep { width: 1px; align-self: stretch; background: var(--border); margin: 0 4px; }

.classify-empty { text-align: center; padding: 80px 20px; color: var(--text-2); }
.classify-empty .emoji { font-size: 56px; margin-bottom: 16px; }
.classify-empty h2 { font-size: 22px; color: var(--text); margin-bottom: 10px; font-weight: 700; }

/* ===================== Modal ===================== */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.32); backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); display: grid; place-items: center; z-index: 100; animation: fadeIn 0.2s ease; padding: 20px; }
@keyframes fadeIn { from { opacity: 0;} to { opacity: 1;} }
.modal { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); padding: 32px; max-width: 780px; width: 100%; max-height: 88vh; overflow-y: auto; position: relative; box-shadow: var(--shadow-lg); animation: modalIn 0.28s var(--ease); }
@keyframes modalIn { from { opacity: 0; transform: scale(0.96) translateY(8px);} to { opacity: 1; transform: scale(1) translateY(0);} }
.modal-close { position: absolute; top: 18px; right: 18px; background: var(--surface-hover); border: 1px solid var(--border); color: var(--text-2); width: 34px; height: 34px; border-radius: 10px; font-size: 20px; cursor: pointer; transition: var(--t-fast); line-height: 1; z-index: 2; }
.modal-close:hover { background: var(--surface); color: var(--text); border-color: var(--border-strong); }

.modal h2 { font-size: 22px; font-weight: 700; letter-spacing: -0.02em; margin-bottom: 6px; }
.classify-supplier { text-align: center; margin-bottom: 24px; padding-bottom: 22px; border-bottom: 1px solid var(--border); }
.classify-supplier h2 { font-size: 24px; }
.classify-supplier .meta { color: var(--text-2); font-size: 13px; }
.classify-amount { font-size: 40px; font-weight: 800; color: var(--text); margin: 14px 0 8px; letter-spacing: -0.03em; font-variant-numeric: tabular-nums; }

.classify-section { margin-bottom: 20px; }
.classify-section label { display: block; font-size: 11px; color: var(--text); letter-spacing: 0.5px; text-transform: uppercase; font-weight: 600; margin-bottom: 10px; }
.cat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.cat-pick { background: var(--surface); border: 1px solid var(--border); color: var(--text-2); padding: 12px 8px; border-radius: var(--r-xs); font-family: inherit; font-size: 12px; font-weight: 600; cursor: pointer; transition: var(--t-fast); }
.cat-pick:hover { background: var(--surface-hover); color: var(--text); border-color: var(--border-strong); }
.cat-pick.active { background: var(--gold); color: #fff; border-color: var(--gold); box-shadow: 0 2px 8px rgba(184,134,11,0.3); }
.cadenza-grid { display: grid; grid-template-columns: repeat(6, 1fr); gap: 8px; }
.cad-pick { background: var(--surface); border: 1px solid var(--border); color: var(--text-2); padding: 13px 8px; border-radius: var(--r-xs); font-family: inherit; font-size: 13px; font-weight: 600; cursor: pointer; transition: var(--t-fast); text-align: center; }
.cad-pick:hover { background: var(--surface-hover); color: var(--text); border-color: var(--border-strong); }
.cad-pick.active { background: var(--gold); color: #fff; border-color: var(--gold); }
.cad-pick small { display: block; font-weight: 500; font-size: 11px; opacity: 0.85; margin-top: 3px; }

.classify-input, .classify-textarea { width: 100%; background: var(--surface); border: 1px solid var(--border); color: var(--text); padding: 11px 13px; border-radius: var(--r-xs); font-family: inherit; font-size: 13px; transition: var(--t-fast); }
.classify-input:focus, .classify-textarea:focus { outline: none; border-color: var(--gold); box-shadow: 0 0 0 3px var(--gold-soft); }
.classify-textarea { resize: vertical; min-height: 76px; line-height: 1.5; }
.classify-actions { display: flex; gap: 10px; justify-content: flex-end; flex-wrap: wrap; padding-top: 20px; border-top: 1px solid var(--border); margin-top: 22px; }

.iban-row { display: flex; gap: 10px; align-items: center; }
.iban-confidence { font-size: 11px; padding: 3px 9px; border-radius: 6px; font-weight: 700; white-space: nowrap; }
.conf-high { background: #e7f7ec; color: var(--green); border: 1px solid #a7f3d0; }
.conf-mid { background: #fff2e0; color: var(--amber); border: 1px solid #fde0c2; }
.conf-low { background: #fdeceb; color: var(--red); border: 1px solid #f5cfcc; }

/* pay flow */
.metodo-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.metodo-pick { background: var(--surface); border: 1px solid var(--border); color: var(--text-2); padding: 13px 8px; border-radius: var(--r-xs); font-family: inherit; font-size: 12px; font-weight: 600; cursor: pointer; transition: var(--t-fast); display: flex; flex-direction: column; align-items: center; gap: 6px; }
.metodo-pick:hover { background: var(--surface-hover); color: var(--text); border-color: var(--border-strong); transform: translateY(-1px); }
.metodo-pick.active { background: var(--gold); color: #fff; border-color: var(--gold); box-shadow: 0 4px 12px rgba(184,134,11,0.3); }
.metodo-icon { font-size: 20px; }

/* inline pay popover (list row) */
.pay-inline { margin-top: 12px; padding: 16px; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--r-sm); animation: slideDown 0.25s var(--ease); overflow: hidden; }
@keyframes slideDown { from { opacity: 0; transform: translateY(-8px); max-height: 0;} to { opacity: 1; transform: translateY(0); max-height: 400px;} }
.pay-inline-row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.pay-inline-row .classify-input { flex: 1; min-width: 130px; width: auto; }

.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-bottom: 20px; }
.detail-row { padding: 11px 0; border-bottom: 1px solid var(--border); }
.detail-row .lbl { font-size: 11px; color: var(--text-3); text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: 5px; font-weight: 600; }
.detail-row .val { font-size: 13px; font-weight: 500; }
.detail-row .val.mono { font-family: var(--mono); color: var(--text); font-weight: 600; }
.badges-row { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; margin-bottom: 8px; }

/* glossary */
.glossary-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; max-height: 62vh; overflow-y: auto; padding-right: 4px; }
.glossary-item { padding: 14px; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--r-xs); transition: var(--t-fast); }
.glossary-item:hover { background: var(--surface); border-color: var(--gold-border); box-shadow: var(--shadow); }
.glossary-head { display: flex; align-items: center; gap: 10px; margin-bottom: 6px; }
.glossary-head strong { font-size: 14px; color: var(--text); font-weight: 700; }
.glossary-item p { font-size: 12px; color: var(--text-2); line-height: 1.5; }

/* per-line + split (reuse compact) */
.perline-rows { display: flex; flex-direction: column; gap: 4px; max-height: 420px; overflow-y: auto; padding-right: 4px; }
.perline-toolbar { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.perline-row { display: grid; grid-template-columns: 40px 1fr 90px 190px; gap: 10px; align-items: center; padding: 9px 12px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-xs); border-left: 4px solid var(--border); transition: var(--t-fast); }
.pl-num { font-family: var(--mono); font-size: 11px; font-weight: 700; color: var(--text-3); }
.pl-desc-text { font-size: 13px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pl-meta { font-size: 11px; color: var(--text-3); margin-top: 2px; }
.pl-amount { text-align: right; font-variant-numeric: tabular-nums; font-weight: 700; font-size: 13px; }
.pl-cat { background: var(--surface); border: 1px solid var(--border); color: var(--text); padding: 7px 9px; border-radius: var(--r-xs); font-family: inherit; font-size: 12px; cursor: pointer; }
.perline-summary { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--border); }
.sum-pill { font-size: 11px; font-weight: 600; padding: 4px 9px; border-radius: 6px; }
.review-block, .split-block { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--r-xs); padding: 16px; margin-bottom: 16px; }
.review-block { border-left: 3px solid var(--amber); }
.split-block { border-left: 3px solid var(--violet); }
.review-toggle, .split-toggle { display: flex; align-items: center; gap: 10px; cursor: pointer; }
.review-toggle input, .split-toggle input { width: 18px; height: 18px; accent-color: var(--gold); cursor: pointer; }
.review-toggle strong, .split-toggle strong { font-size: 13px; }
.review-help, .split-help { font-size: 11px; color: var(--text-2); line-height: 1.5; margin: 8px 0 12px 28px; }

.linee-preview { margin-top: 14px; text-align: left; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--r-xs); padding: 10px 14px; font-size: 12px; }
.linee-preview summary { cursor: pointer; font-weight: 600; color: var(--text-2); font-size: 11px; letter-spacing: 0.4px; text-transform: uppercase; }
.linee-list { margin-top: 10px; max-height: 180px; overflow-y: auto; }
.linee-list > div { padding: 4px 0; border-bottom: 1px solid var(--border); }
.hint-confirm { margin-top: 10px; padding: 8px 14px; background: #e7f7ec; border: 1px solid #a7f3d0; border-radius: 8px; font-size: 12px; color: #065f46; display: inline-block; }

/* ===================== Export grid ===================== */
.export-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; }
.export-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r); padding: 26px; text-align: left; cursor: pointer; transition: var(--t); font-family: inherit; color: var(--text); box-shadow: var(--shadow); }
.export-card:hover { border-color: var(--gold); transform: translateY(-3px); box-shadow: var(--shadow-md); }
.export-card:active { transform: scale(0.98); }
.export-emoji { font-size: 30px; margin-bottom: 14px; }
.export-card h3 { font-size: 15px; font-weight: 700; margin-bottom: 6px; }
.export-card p { font-size: 12px; color: var(--text-2); line-height: 1.5; }

/* ===================== Selection bar ===================== */
#selection-bar { position: fixed; bottom: 24px; left: calc(50% + 128px); transform: translateX(-50%) translateY(140%); z-index: 90; background: var(--text); color: #fff; border-radius: var(--r); box-shadow: var(--shadow-lg); padding: 16px 20px; display: flex; gap: 20px; align-items: center; min-width: 640px; max-width: 90vw; transition: transform 0.34s var(--ease), opacity 0.24s ease; opacity: 0; }
#selection-bar.visible { transform: translateX(-50%) translateY(0); opacity: 1; }
.selbar-supp { font-size: 14px; font-weight: 700; }
.selbar-meta { font-size: 11px; color: rgba(255,255,255,0.6); margin-top: 2px; text-transform: uppercase; letter-spacing: 0.4px; font-weight: 600; }
.selbar-total { font-size: 26px; font-weight: 800; color: var(--gold-light); font-variant-numeric: tabular-nums; letter-spacing: -0.02em; white-space: nowrap; flex: 1; text-align: center; }
.selbar-right { display: flex; gap: 8px; }
.selbar-right .btn { background: rgba(255,255,255,0.12); border-color: rgba(255,255,255,0.16); color: #fff; }
.selbar-right .btn:hover { background: rgba(255,255,255,0.22); }
.selbar-warn { color: var(--amber-vivid); font-size: 12px; font-weight: 600; flex: 1; }
.btn-icon-only { background: rgba(255,255,255,0.12); border: 0; color: #fff; width: 30px; height: 30px; border-radius: 8px; cursor: pointer; display: grid; place-items: center; font-size: 14px; transition: var(--t-fast); }
.btn-icon-only:hover { background: var(--gold); }

/* ===================== Toast ===================== */
#toast { position: fixed; bottom: 24px; right: 24px; background: var(--text); color: #fff; padding: 14px 22px; border-radius: var(--r-sm); box-shadow: var(--shadow-lg); z-index: 400; font-size: 13px; font-weight: 600; animation: toastIn 0.3s var(--ease); }
@keyframes toastIn { from { opacity: 0; transform: translateY(20px);} to { opacity: 1; transform: translateY(0);} }

/* ===================== Preview lightbox (iframe) ===================== */
.preview-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.72); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); z-index: 500; display: flex; flex-direction: column; animation: fadeIn 0.25s ease; }
.preview-shell { flex: 1; display: flex; flex-direction: column; max-width: 1000px; width: 96%; margin: 0 auto; padding: 22px 0; min-height: 0; }
.preview-toolbar { display: flex; justify-content: space-between; align-items: center; padding: 12px 16px; background: rgba(255,255,255,0.08); backdrop-filter: blur(12px); border: 1px solid rgba(255,255,255,0.12); border-radius: var(--r-sm); margin-bottom: 14px; }
.preview-toolbar-title { color: #fff; font-weight: 600; font-size: 14px; }
.preview-toolbar-actions { display: flex; gap: 8px; align-items: center; }
.preview-toolbar-actions .btn { background: rgba(255,255,255,0.12); border-color: rgba(255,255,255,0.16); color: #fff; }
.preview-toolbar-actions .btn:hover { background: rgba(255,255,255,0.24); }
.preview-frame-wrap { flex: 1; min-height: 0; border-radius: var(--r-sm); overflow: hidden; background: #fff; box-shadow: var(--shadow-lg); animation: modalIn 0.3s var(--ease); }
#preview-frame { width: 100%; height: 100%; border: 0; background: #fff; }

/* ===================== Scrollbar ===================== */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 10px; border: 2px solid var(--bg); }
::-webkit-scrollbar-thumb:hover { background: var(--text-3); }

/* ===================== Responsive ===================== */
@media (max-width: 1280px) {
  .kpi-grid { grid-template-columns: repeat(3, 1fr); }
  .export-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 1000px) {
  .grid-2 { grid-template-columns: 1fr; }
  .cat-grid { grid-template-columns: repeat(3, 1fr); }
  .cadenza-grid { grid-template-columns: repeat(3, 1fr); }
  .glossary-grid { grid-template-columns: 1fr; }
  /* su tablet il bottone Paga resta visibile: si sacrificano IBAN e categoria */
  .scadenza-row { grid-template-columns: 96px 1fr 104px 92px; gap: 10px; }
  .scad-iban, .scadenza-row > div:nth-child(3) { display: none; }
  #selection-bar { left: 50%; }
}
@media (max-width: 820px) {
  .menu-toggle { display: grid; place-items: center; }
  .sidebar { position: fixed; left: 0; top: 0; transform: translateX(-100%); transition: transform var(--t); box-shadow: var(--shadow-lg); }
  .sidebar.open { transform: translateX(0); }
  /* scrim sotto la sidebar aperta: contesto scuro + tap fuori per chiudere */
  .sidebar.open + .scrim { display: block; }
  .main { padding: 70px 20px 120px; }
  .kpi-grid { grid-template-columns: 1fr 1fr; }
  .view-header h1 { font-size: 24px; }
  .forn-grid { grid-template-columns: 1fr; }
  .detail-grid, .contact-form { grid-template-columns: 1fr; }
  #selection-bar { min-width: 0; width: 92vw; flex-direction: column; align-items: stretch; text-align: center; }
}
.scrim { display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.3); z-index: 38; animation: fadeIn 0.2s ease; }
/* niente zoom automatico iOS: campi ad almeno 16px su viewport piccoli e touch.
   !important voluto: deve vincere su ogni selettore di classe (.search-hero input,
   .fbtn, .classify-input, .ni, ...) o Safari zooma comunque al focus. */
@media (max-width: 820px), (pointer: coarse) {
  input:not([type="checkbox"]):not([type="radio"]), select, textarea { font-size: 16px !important; }
}

/* ===================== Reduced motion ===================== */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.001ms !important; transition-duration: 0.001ms !important; }
}

/* =========================================================================
   PERSONALE / NETTI
   ========================================================================= */
.pers-summary { margin-bottom: 24px; }
.pers-kpis { display: flex; gap: 16px; flex-wrap: wrap; margin-bottom: 18px; }
.pers-kpi { flex: 1; min-width: 160px; background: var(--surface); border-radius: var(--r); padding: 16px 20px; box-shadow: var(--shadow-sm); display: flex; flex-direction: column; gap: 4px; }
.pers-kpi .pl { font-size: 12px; color: var(--text-2); text-transform: uppercase; letter-spacing: 0.03em; }
.pers-kpi .pv { font-size: 24px; font-weight: 700; letter-spacing: -0.02em; }
.pers-kpi-total { background: linear-gradient(135deg, var(--gold), var(--gold-hover)); }
.pers-kpi-total .pl, .pers-kpi-total .pv { color: #fff; }

.pers-cl-table { width: 100%; border-collapse: collapse; background: var(--surface); border-radius: var(--r); overflow: hidden; box-shadow: var(--shadow-sm); }
.pers-cl-table th { background: var(--surface-hover); text-align: left; padding: 10px 16px; font-size: 12px; text-transform: uppercase; letter-spacing: 0.03em; color: var(--text-2); }
.pers-cl-table td { padding: 10px 16px; border-top: 1px solid var(--border); font-size: 14px; }
.pers-cl-table .r, .netti-table .r { text-align: right; }
.pers-cl-table tr.pers-empty td { color: var(--text-3); }
.pers-missing { color: #b45309; font-weight: 600; font-size: 13px; }

.pers-form-card { background: var(--surface); border-radius: var(--r-lg); box-shadow: var(--shadow-md); padding: 22px; }
.pers-form-head { display: flex; justify-content: space-between; align-items: flex-end; flex-wrap: wrap; gap: 16px; margin-bottom: 16px; }
.pers-form-title { display: flex; align-items: center; gap: 20px; flex-wrap: wrap; }
.pers-form-title h3 { font-size: 17px; font-weight: 600; }
.pers-month-pick { display: flex; align-items: center; gap: 8px; }
.pers-month-pick label { font-size: 12px; color: var(--text-2); text-transform: uppercase; }
.pers-month-pick input, .netti-table input { font-family: inherit; }
.pers-form-actions { display: flex; gap: 8px; align-items: center; }

.netti-table-wrap { overflow-x: auto; }
.netti-table { width: 100%; border-collapse: collapse; }
.netti-table th { text-align: left; padding: 8px 10px; font-size: 11px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-3); border-bottom: 1px solid var(--border); }
.netti-table td { padding: 4px 6px; border-bottom: 1px solid var(--border); }
.netti-table tfoot td { border-bottom: 0; border-top: 2px solid var(--border); padding-top: 12px; font-size: 15px; }
.ni { width: 100%; border: 1px solid transparent; background: transparent; border-radius: 8px; padding: 8px 10px; font-size: 13px; color: var(--text); transition: var(--t-fast); }
.ni:hover { background: var(--surface-hover); }
.ni:focus { outline: none; background: var(--surface); border-color: var(--gold); box-shadow: 0 0 0 3px rgba(184,134,11,0.12); }
.ni-cdip { max-width: 60px; }
.ni-netto { font-weight: 600; }
.netti-del { border: 0; background: transparent; color: var(--text-3); cursor: pointer; font-size: 14px; padding: 6px 8px; border-radius: 8px; transition: var(--t-fast); }
.netti-del:hover { background: rgba(255,59,48,0.1); color: #ff3b30; }

/* =========================================================================
   AUTH · login screen, user chip, ruoli
   ========================================================================= */

/* app nascosta finché la sessione non è verificata / durante il login */
body.auth-locked .sidebar,
body.auth-locked .main,
body.auth-locked .menu-toggle { display: none !important; }

.login-screen {
  position: fixed; inset: 0; z-index: 100;
  background: var(--bg);
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
}
.login-card {
  width: 100%; max-width: 400px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r-lg); box-shadow: var(--shadow-md);
  padding: 40px 36px;
  animation: viewIn 0.34s var(--ease);
}
.login-brand { display: flex; flex-direction: column; align-items: center; gap: 14px; margin-bottom: 28px; text-align: center; }
.login-mark {
  width: 64px; height: 64px; border-radius: 18px;
  background: linear-gradient(135deg, var(--gold-light) 0%, var(--gold-hover) 100%);
  color: #fff; font-weight: 800; font-size: 22px; letter-spacing: 0.5px;
  display: grid; place-items: center;
  box-shadow: 0 8px 24px rgba(184,134,11,0.30);
}
.login-title { font-size: 19px; font-weight: 700; letter-spacing: -0.02em; color: var(--text); }
.login-sub { font-size: 11px; color: var(--text-3); letter-spacing: 1.6px; text-transform: uppercase; font-weight: 600; margin-top: 4px; }
.login-setup-title { font-size: 17px; font-weight: 600; letter-spacing: -0.02em; margin-bottom: 6px; }
.login-setup-sub { font-size: 12.5px; color: var(--text-2); margin-bottom: 20px; }
.login-field { margin-bottom: 14px; }
.login-field label { display: block; font-size: 11px; font-weight: 600; letter-spacing: 0.5px; text-transform: uppercase; color: var(--text-3); margin-bottom: 6px; }
.login-label-hint { text-transform: none; letter-spacing: 0; font-weight: 500; color: var(--text-3); }
.login-input {
  width: 100%; padding: 12px 14px;
  border: 1px solid var(--border); border-radius: var(--r-sm);
  font-family: inherit; font-size: 14px; color: var(--text);
  background: var(--surface-2); transition: var(--t-fast);
}
.login-input:focus { outline: none; border-color: var(--gold); background: var(--surface); box-shadow: 0 0 0 3px rgba(184,134,11,0.12); }
.login-error { color: var(--red); font-size: 12.5px; min-height: 18px; margin: 2px 0 10px; }
.login-submit { width: 100%; justify-content: center; padding: 12px; font-size: 14px; }
.login-hint { text-align: center; font-size: 11px; color: var(--text-3); margin-top: 18px; }

/* user chip nel footer sidebar */
.user-chip {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--border); border-radius: var(--r-sm);
  background: var(--surface-2);
}
.user-chip-info { display: flex; flex-direction: column; gap: 4px; min-width: 0; flex: 1; }
.user-chip-name { font-size: 12.5px; font-weight: 600; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.role-badge {
  font-size: 11px; font-weight: 700; letter-spacing: 0.7px; text-transform: uppercase;
  padding: 2px 8px; border-radius: var(--pill); width: fit-content;
}
.badge-admin { background: var(--gold-soft); color: var(--gold-hover); border: 1px solid var(--gold-border); }
.badge-operatore { background: #eaf3fd; color: var(--blue); border: 1px solid #cfe4f9; }
.badge-viewer { background: var(--surface-hover); color: var(--text-2); border: 1px solid var(--border); }
.badge-contabile { background: #e6f6f3; color: var(--teal); border: 1px solid #c2e8e1; }
.user-chip-logout {
  border: 1px solid var(--border); background: var(--surface);
  color: var(--text-3); font-family: inherit; font-size: 11px; font-weight: 600;
  cursor: pointer; padding: 6px 10px; border-radius: var(--r-xs); transition: var(--t-fast);
}
.user-chip-logout:hover { background: #fdf2f1; color: var(--red); border-color: #f5cfcc; }

/* stato utente nella tabella Utenti */
.user-state { font-size: 11px; font-weight: 600; padding: 3px 10px; border-radius: var(--pill); }
.user-state.on { background: #e9f8ee; color: var(--green); }
.user-state.off { background: var(--surface-hover); color: var(--text-3); }
.row-user-off td { opacity: 0.55; }

/* --- visibilità per ruolo (solo UX: l'enforcement vero è server-side) --- */
body:not(.role-admin) .admin-only { display: none !important; }
body.role-viewer .hide-viewer { display: none !important; }
/* viewer: sola lettura, nessun controllo azione */
body.role-viewer .th-check,
body.role-viewer .td-check,
body.role-viewer #selection-bar,
body.role-viewer .qb-actions,
body.role-viewer .qrow-cats,
body.role-viewer .scad-actions,
body.role-viewer [data-act="open-pay"],
body.role-viewer [data-act="confirm-pay"],
body.role-viewer [data-act="unpay"],
body.role-viewer [data-act="save-contatto"],
body.role-viewer [data-act="quick-classify"],
body.role-viewer [data-act="confirm-classify"],
body.role-viewer [data-act="save-classify"],
body.role-viewer [onclick^="confirmBulk"] { display: none !important; }

/* visibilità dichiarativa per ruolo: data-roles="a,b" (filtro in auth.js) */
.role-hidden { display: none !important; }
/* contabile: fatture/scadenziario/upload operativi, zero classificazione e analisi */
body.role-contabile [data-act="open-classify"],
body.role-contabile [data-act="quick-classify"],
body.role-contabile [data-act="confirm-classify"],
body.role-contabile [data-act="save-classify"],
body.role-contabile .qb-actions,
body.role-contabile .qrow-cats,
body.role-contabile #btn-export,
body.role-contabile [onclick^="confirmBulk"] { display: none !important; }

/* --- feedback onesto: toast errore + error state con Riprova --- */
#toast.toast-error { background: #b3261e; color: #fff; }
.error-state {
  display: flex; flex-direction: column; align-items: center; gap: 10px;
  padding: 40px 20px; text-align: center;
}
.error-state .es-ico { font-size: 26px; }
.error-state .es-msg { color: var(--text-2); font-size: 14px; font-weight: 600; }

/* --- modale di conferma riusabile --- */
.confirm-body { font-size: 14px; color: var(--text); margin-top: 10px; line-height: 1.55; }

/* --- coda: skip onesto (nascondi != fatto) + riga attiva + hint tastiera --- */
.qrow.hidden-out { opacity: 0; transform: translateX(14px); }
.qrow.qrow-active { border-color: var(--gold-border); box-shadow: 0 0 0 1px var(--gold-border), var(--shadow-sm); }
.qkey {
  display: none; font-family: var(--mono); font-size: 11px; font-weight: 600;
  background: rgba(0,0,0,0.07); border-radius: 4px; padding: 0 4px; margin-right: 5px; line-height: 1.4;
}
.qrow.qrow-active .qkey { display: inline-block; }
.queue-hidden-note { margin-bottom: 10px; font-size: 12px; color: var(--text-2); }
.linklike { border: 0; background: transparent; color: var(--gold-hover); font: inherit; font-weight: 600; cursor: pointer; text-decoration: underline; padding: 0; }

/* --- KPI card cliccabili verso le viste filtrate --- */
.kpi-card[data-act] { cursor: pointer; }

/* =========================================================================
   ICONE SVG (sprite in index.html · monocromo currentColor)
   ========================================================================= */
.ico { width: 17px; height: 17px; flex-shrink: 0; vertical-align: -3px; }
.icon-btn .ico { width: 16px; height: 16px; vertical-align: 0; }
svg.nav-ico { width: 17px; height: 17px; opacity: 0.9; }
.badge-mini .ico { width: 12px; height: 12px; vertical-align: -2px; }
.metodo-icon { display: grid; place-items: center; }
.metodo-icon .ico { width: 20px; height: 20px; }
.export-ico { color: var(--text-2); margin-bottom: 14px; }
.export-ico .ico { width: 26px; height: 26px; }
.export-card:hover .export-ico { color: var(--gold-hover); }
.error-state .es-ico { color: var(--amber); }
.error-state .es-ico .ico { width: 28px; height: 28px; }
.bucket-head h3 .ico { width: 16px; height: 16px; }
.review-toggle .ico { width: 15px; height: 15px; }

/* =========================================================================
   CONFERMA IMPILATA (sopra il modale generico) + BANNER AI
   ========================================================================= */
.confirm-overlay {
  position: fixed; inset: 0; z-index: 250;
  background: rgba(0,0,0,0.34); backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px);
  display: grid; place-items: center; padding: 20px; animation: fadeIn 0.16s ease;
}
.confirm-modal { max-width: 480px; padding: 26px 28px; }

#ai-banner {
  position: fixed; bottom: 24px; left: 24px; z-index: 380;
  display: flex; align-items: center; gap: 10px;
  background: var(--text); color: #fff; padding: 12px 18px;
  border-radius: var(--r-sm); box-shadow: var(--shadow-lg);
  font-size: 13px; font-weight: 600; animation: toastIn 0.3s var(--ease);
}
.ai-banner-spin {
  width: 14px; height: 14px; border-radius: 50%;
  border: 2px solid rgba(255,255,255,0.25); border-top-color: var(--gold-light);
  animation: aiSpin 0.9s linear infinite;
}
@keyframes aiSpin { to { transform: rotate(360deg); } }

/* =========================================================================
   FOCUS VISIBILE (tastiera): ring oro coerente su tutto l'interattivo.
   Gli input restano col loro focus a bordo+ombra gia' definito.
   ========================================================================= */
:where(button, [role="button"], a.btn, .export-card, .nav-btn, th.sortable, tr[data-id], .linklike, .pill-btn):focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
}
/* superfici scure: ring piu' chiaro per contrasto */
#selection-bar :where(button):focus-visible,
.preview-toolbar :where(a, button):focus-visible {
  outline-color: var(--gold-light);
}

/* =========================================================================
   PREVISIONI · storico+forecast, fatture attese, categorie
   ========================================================================= */
.kpi-grid.kpi-grid-3 { grid-template-columns: repeat(3, 1fr); }
.kpi-range { font-variant-numeric: tabular-nums; }

/* legenda del grafico forecast: campioni coerenti con i riempimenti SVG */
.legend-hatch { background: repeating-linear-gradient(45deg, #98a1ad 0 3px, #d8dce1 3px 5px); }
.legend-fc { background: #f6edd2; border: 1.5px dashed var(--gold); box-sizing: border-box; }

/* fatture attese */
.att-head { padding: 16px 22px; border-bottom: 1px solid var(--border); background: var(--surface-2); display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; }
.att-head h3 { font-size: 15px; font-weight: 600; color: var(--text); display: flex; align-items: center; gap: 8px; }
.att-late-n { color: #b45309; font-weight: 700; }
.att-row { display: grid; grid-template-columns: 110px 1fr 170px 30px; gap: 14px; padding: 12px 22px; border-bottom: 1px solid var(--border); align-items: center; cursor: pointer; transition: var(--t-fast); }
.att-row:hover { background: var(--surface-hover); }
.att-date { font-weight: 600; font-size: 13px; display: flex; flex-direction: column; align-items: flex-start; gap: 4px; }
.late-badge { background: #fff2e0; color: #b45309; border: 1px solid #fde0c2; font-size: 11px; font-weight: 700; padding: 1px 8px; border-radius: var(--pill); white-space: nowrap; }
.att-name { font-weight: 600; font-size: 13.5px; color: var(--text); display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.cad-badge { font-size: 11px; font-weight: 600; color: var(--text-2); background: var(--surface-hover); border: 1px solid var(--border); border-radius: var(--pill); padding: 1px 8px; white-space: nowrap; }
.att-meta { font-size: 11px; color: var(--text-3); margin-top: 2px; }
.att-amount { text-align: right; }
.att-amount .v { font-weight: 700; font-size: 14px; font-variant-numeric: tabular-nums; }
.att-amount .range { font-size: 11px; color: var(--text-3); font-variant-numeric: tabular-nums; }
.att-conf { display: grid; place-items: center; }
/* pallino affidabilita': pieno / meta' / vuoto (il title spiega) */
.conf-dot { width: 12px; height: 12px; border-radius: 50%; display: inline-block; border: 2px solid var(--text-2); }
.conf-alta { background: var(--text-2); }
.conf-media { background: linear-gradient(90deg, var(--text-2) 50%, transparent 50%); }
.conf-bassa { background: transparent; }

/* per categoria */
.prev-cat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(215px, 1fr)); gap: 12px; }
.pcat-card { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--r-sm); padding: 14px 16px; transition: var(--t-fast); }
.pcat-card:hover { border-color: var(--border-strong); box-shadow: var(--shadow-sm); }
.pcat-name { font-size: 11px; font-weight: 700; letter-spacing: 0.4px; text-transform: uppercase; color: var(--text-2); display: flex; align-items: center; gap: 7px; }
.pcat-dot { width: 9px; height: 9px; border-radius: 3px; flex-shrink: 0; }
.pcat-val { font-size: 20px; font-weight: 700; margin-top: 7px; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.pcat-trend { font-size: 11px; margin-top: 2px; min-height: 16px; }
.pcat-up { color: #c62b22; font-weight: 700; }   /* costi in aumento = rosso, coerente con YoY */
.pcat-down { color: #1a7f37; font-weight: 700; }
.pcat-flat { color: var(--text-3); font-weight: 600; }
.pcat-vs { color: var(--text-3); }
.pcat-spark { width: 100%; height: 38px; margin-top: 8px; display: block; }
.badge-stima { background: var(--gold-soft); color: var(--gold-hover); border: 1px solid var(--gold-border); font-size: 11px; font-weight: 700; padding: 1px 8px; border-radius: var(--pill); letter-spacing: 0.3px; text-transform: uppercase; }

/* nota metodo: onesta, discreta, a portata di click */
.method-note { margin-top: 16px; font-size: 12px; color: var(--text-2); }
.method-note summary { cursor: pointer; font-weight: 600; display: inline-flex; align-items: center; gap: 7px; padding: 6px 2px; color: var(--text-2); transition: var(--t-fast); }
.method-note summary:hover { color: var(--text); }
.method-note p { margin: 8px 2px 0; max-width: 860px; line-height: 1.6; }

/* =========================================================================
   INSIGHTS · "Da tenere d'occhio" (dashboard)
   ========================================================================= */
.insights-block { margin-bottom: 22px; }
.insights-head { display: flex; align-items: baseline; gap: 10px; margin-bottom: 10px; }
.insights-head h3 { font-size: 15px; font-weight: 600; color: var(--text); letter-spacing: -0.01em; }
.insights-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.insight-card { position: relative; background: var(--surface); border: 1px solid var(--border); border-left: 3px solid var(--border-strong); border-radius: var(--r-sm); padding: 13px 34px 12px 16px; box-shadow: var(--shadow-sm); }
.insight-card.sev-alert { border-left-color: var(--red); }
.insight-card.sev-warn { border-left-color: var(--amber); }
.insight-card.sev-info { border-left-color: #64748b; }
.insight-top { display: flex; align-items: center; gap: 7px; font-size: 11px; font-weight: 700; letter-spacing: 0.4px; text-transform: uppercase; color: var(--text-3); }
.sev-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.sev-alert .sev-dot { background: var(--red); }
.sev-warn .sev-dot { background: var(--amber); }
.sev-info .sev-dot { background: #64748b; }
.insight-value { font-size: 19px; font-weight: 700; margin-top: 6px; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.insight-title { font-size: 12.5px; font-weight: 600; margin-top: 3px; color: var(--text); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.insight-det { font-size: 11.5px; color: var(--text-2); margin-top: 4px; line-height: 1.45; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.insight-cta { display: flex; gap: 14px; flex-wrap: wrap; margin-top: 8px; }
.insight-cta .linklike { text-decoration: none; font-size: 12px; }
.insight-cta .linklike:hover { text-decoration: underline; }
.insight-x { position: absolute; top: 8px; right: 8px; border: 0; background: transparent; color: var(--text-3); width: 24px; height: 24px; border-radius: 7px; font-size: 15px; line-height: 1; cursor: pointer; transition: var(--t-fast); }
.insight-x:hover { background: var(--surface-hover); color: var(--text); }
.insights-ok { font-size: 12.5px; color: var(--green); font-weight: 600; padding: 8px 2px; }
.insights-thin { font-size: 12px; padding: 6px 2px; }
.insights-more { margin-top: 10px; }
.insights-more .linklike, .insights-head .linklike { text-decoration: none; font-size: 12px; }
.insights-more .linklike:hover, .insights-head .linklike:hover { text-decoration: underline; }

/* =========================================================================
   LEARNING · chip regole apprese (solo admin, coda classificazione)
   ========================================================================= */
.learn-chip { display: inline-flex; align-items: center; gap: 6px; margin-top: 8px; background: var(--gold-soft); color: var(--gold-hover); border: 1px solid var(--gold-border); border-radius: var(--pill); padding: 3px 11px; font-size: 11.5px; font-weight: 600; width: fit-content; cursor: default; }

/* ===================== Responsive (nuove sezioni) ===================== */
@media (max-width: 1280px) {
  .insights-grid { grid-template-columns: repeat(2, 1fr); }
  .kpi-grid.kpi-grid-3 { grid-template-columns: repeat(3, 1fr); }
}
@media (max-width: 1000px) {
  .att-row { grid-template-columns: 96px 1fr 150px; }
  .att-conf { display: none; }
}
@media (max-width: 820px) {
  /* insights come strip orizzontale scrollabile: colpo d'occhio senza muro di card */
  .insights-grid { display: flex; overflow-x: auto; padding-bottom: 6px; -webkit-overflow-scrolling: touch; }
  .insights-grid .insight-card { flex: 0 0 84%; min-width: 235px; }
  .kpi-grid.kpi-grid-3 { grid-template-columns: 1fr 1fr; }
  .att-row { grid-template-columns: 88px 1fr; }
  .att-amount { grid-column: 2; text-align: left; margin-top: 2px; display: flex; gap: 10px; align-items: baseline; }
}

/* =========================================================================
   CARICA FATTURE (upload XML/P7M/ZIP)
   ========================================================================= */
.upload-drop {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 10px; text-align: center; cursor: pointer; user-select: none;
  min-height: 320px; padding: 48px 28px;
  background: var(--surface); border: 2px dashed var(--border-strong);
  border-radius: var(--r-lg); box-shadow: var(--shadow-sm);
  transition: border-color var(--t-fast), background var(--t-fast), transform var(--t-fast);
}
.upload-drop:hover { border-color: var(--gold-light); background: var(--gold-soft); }
.upload-drop.drag { border-color: var(--gold); background: var(--gold-soft); transform: scale(1.005); }
.upload-drop.upload-busy { cursor: default; }
.upload-drop.upload-busy:hover { border-color: var(--border-strong); background: var(--surface); }
.up-drop-ico { color: var(--gold); }
.up-drop-ico .ico { width: 44px; height: 44px; }
.up-drop-title { font-size: 17px; font-weight: 600; color: var(--text); max-width: 460px; line-height: 1.4; }
.up-drop-sub { font-size: 13px; font-weight: 500; color: var(--text-2); }
.up-drop-link { color: var(--gold-hover); font-weight: 600; text-decoration: underline; text-underline-offset: 3px; }
.up-drop-hint { font-size: 11px; font-weight: 500; color: var(--text-3); letter-spacing: 0.3px; margin-top: 6px; }
.up-spinner {
  width: 44px; height: 44px; border-radius: 50%;
  border: 4px solid var(--surface-hover); border-top-color: var(--gold);
  animation: up-spin 0.9s linear infinite;
}
@keyframes up-spin { to { transform: rotate(360deg); } }

.upload-result { display: flex; flex-direction: column; gap: 18px; }
.up-summary {
  display: flex; align-items: baseline; justify-content: center; gap: 14px; flex-wrap: wrap;
  padding: 26px 20px; background: var(--surface); border-radius: var(--r-lg); box-shadow: var(--shadow-sm);
}
.up-sum-item { display: flex; align-items: baseline; gap: 8px; }
.up-sum-item .v { font-size: 34px; font-weight: 700; font-variant-numeric: tabular-nums; letter-spacing: -0.5px; }
.up-sum-item .l { font-size: 13px; font-weight: 500; color: var(--text-2); }
.up-sum-ok .v { color: var(--green); }
.up-sum-dup .v { color: var(--text-3); }
.up-sum-err .v { color: var(--red); }
.up-sum-sep { color: var(--border-strong); font-size: 22px; font-weight: 600; }
.up-badge { display: inline-block; font-size: 11px; font-weight: 600; padding: 3px 10px; border-radius: var(--pill); white-space: nowrap; }
.up-ok { background: #e9f8ee; color: var(--green); }
.up-dup { background: var(--surface-hover); color: var(--text-2); border: 1px solid var(--border); }
.up-err { background: #fdf2f1; color: var(--red); }
.up-err-msg { font-size: 11px; font-weight: 500; color: var(--text-3); margin-top: 4px; max-width: 320px; }
.up-file { font-family: var(--mono); font-size: 11.5px; word-break: break-all; }
.up-table td { vertical-align: top; }
.up-actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; margin-top: 4px; }

/* =========================================================================
   Cadenza & spalmatura (badge lista · anteprima form · banner straordinari)
   ========================================================================= */
.badge-cad {
  display: inline-block; font-size: 11px; font-weight: 600; padding: 1px 7px;
  border-radius: var(--pill); background: var(--surface-hover); color: var(--text-2);
  border: 1px solid var(--border-strong); margin-left: 6px; vertical-align: 1px;
  letter-spacing: 0.2px; white-space: nowrap; cursor: default;
}
.badge-cad-straord { background: #fff2e0; color: var(--amber); border-color: #fde0c2; }
.classify-amount .badge-cad { font-size: 12px; vertical-align: 6px; }

.banner-straord {
  display: flex; align-items: center; gap: 9px;
  background: #fff7ed; border: 1px solid #fde0c2; border-left: 3px solid var(--amber);
  color: #8a5500; border-radius: var(--r-xs); padding: 11px 14px;
  font-size: 12.5px; font-weight: 600; margin-bottom: 16px;
}
.banner-straord .ico { width: 15px; height: 15px; color: var(--amber); flex: none; }

.spread-preview {
  margin-top: 12px; display: flex; align-items: center; gap: 8px;
  background: var(--gold-soft); border: 1px solid var(--gold-border);
  border-radius: var(--r-xs); padding: 10px 14px;
  font-size: 12.5px; font-weight: 500; color: var(--text);
}
.spread-preview:empty { display: none; }
.spread-preview .ico { width: 14px; height: 14px; color: var(--gold); flex: none; }

/* ---- domanda di propagazione a cascata (radio nel confirm) ---- */
.cascade-options { display: flex; flex-direction: column; gap: 8px; margin-top: 6px; }
.cascade-opt {
  display: flex; gap: 10px; align-items: flex-start; padding: 11px 12px;
  border: 1px solid var(--border); border-radius: var(--r-xs); cursor: pointer;
  transition: border-color var(--t-fast), background var(--t-fast);
}
.cascade-opt:hover { background: var(--surface-hover); }
.cascade-opt:has(input:checked) { border-color: var(--gold); background: var(--gold-soft); }
.cascade-opt input { margin-top: 2px; accent-color: var(--gold); flex: none; }
.cascade-opt span { display: flex; flex-direction: column; gap: 2px; font-size: 13px; font-weight: 600; color: var(--text); }
.cascade-opt small { font-size: 11.5px; font-weight: 500; color: var(--text-2); }
.cascade-opt-disabled { opacity: 0.55; cursor: not-allowed; }

/* ---- classificazione voce per voce (dettaglio fattura) ---- */
.lines-help { font-size: 11.5px; font-weight: 500; color: var(--text-3); margin: 4px 0 10px; }
.lines-table {
  display: flex; flex-direction: column; border: 1px solid var(--border);
  border-radius: var(--r-xs); overflow: hidden; background: var(--surface);
  max-height: 320px; overflow-y: auto;
}
.line-row {
  display: grid; grid-template-columns: 1fr auto 150px 26px; gap: 10px;
  align-items: center; padding: 8px 12px; border-bottom: 1px solid var(--border);
}
.line-row:last-child { border-bottom: none; }
.line-desc { font-size: 12px; font-weight: 500; color: var(--text); min-width: 0; overflow-wrap: anywhere; }
.line-sub { display: block; font-size: 11px; font-weight: 500; color: var(--text-3); margin-top: 1px; }
.line-amt { font-size: 12px; font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }
.line-cat-sel { padding: 5px 8px; font-size: 12px; width: 150px; }
.line-mode {
  font-size: 11px; font-weight: 700; text-align: center; color: var(--text-3);
  border-radius: 5px; padding: 1px 0; cursor: default;
}
.line-mode-ai { background: #f3eefe; color: var(--violet); }
.line-mode-man { background: var(--gold-soft); color: var(--gold); }
.lines-actions { display: flex; gap: 10px; margin-top: 12px; flex-wrap: wrap; }
.split-summary { display: flex; gap: 8px; flex-wrap: wrap; }
.split-chip {
  display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 600;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--pill);
  padding: 3px 10px 3px 4px;
}
@media (max-width: 640px) {
  .line-row { grid-template-columns: 1fr auto; }
  .line-cat-sel { width: 100%; grid-column: 1; }
  .line-mode { grid-column: 2; justify-self: end; min-width: 26px; }
}

/* voce-per-voce: solo chi puo' scrivere sulle linee (admin+operatore) */
body.role-contabile .lines-section,
body.role-viewer .lines-section { display: none !important; }

/* ---- bottone classificazione impattante (lista fatture, coda, dettaglio) ---- */
.btn-classify-row {
  display: inline-flex; align-items: center; gap: 6px; min-height: 36px; padding: 0 14px;
  border-radius: var(--pill); border: 1px solid var(--gold-border);
  background: var(--gold-soft); color: var(--gold); font-size: 12px; font-weight: 600;
  cursor: pointer; white-space: nowrap;
  transition: background var(--t-fast), color var(--t-fast), border-color var(--t-fast);
}
.btn-classify-row .ico { width: 14px; height: 14px; }
.btn-classify-row:hover { background: var(--gold); border-color: var(--gold); color: #fff; }
body.role-viewer .btn-classify-row { display: none !important; }

/* ---- pill sottovoci (editor + quick-classify coda) ---- */
.sub-grid { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; min-height: 36px; }
.sub-pick {
  background: var(--surface); border: 1px solid var(--border); color: var(--text-2);
  padding: 8px 13px; border-radius: var(--pill); font-family: inherit;
  font-size: 12px; font-weight: 600; cursor: pointer; transition: var(--t-fast);
}
.sub-pick:hover { background: var(--surface-hover); color: var(--text); border-color: var(--border-strong); }
.sub-pick.active { background: var(--gold); color: #fff; border-color: var(--gold); box-shadow: 0 2px 8px rgba(184,134,11,0.3); }
.sub-legacy { border-style: dashed; }
.sub-new { background: var(--gold-soft); color: var(--gold-hover); border-color: var(--gold-border); }
.sub-hint { font-size: 11.5px; font-weight: 500; color: var(--text-3); }
.sub-anim { animation: subIn 150ms var(--ease); }
@keyframes subIn { from { opacity: 0; transform: translateY(-3px); } to { opacity: 1; transform: none; } }

.qrow-subs { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.qrow-subs .sub-pick { padding: 6px 11px; font-size: 11.5px; }
.qrow-subs .sub-solo { background: var(--gold-soft); color: var(--gold-hover); border-color: var(--gold-border); }
.qcat.qcat-picked { border-color: var(--gold); color: var(--gold-hover); background: var(--gold-soft); }
body.role-viewer .qrow-subs, body.role-contabile .qrow-subs { display: none !important; }

/* ---- peso commissioni OTA sul venduto ---- */
.ota-headline { font-size: 13px; font-weight: 600; color: var(--text-2); }
.ota-yoy { font-size: 11.5px; font-weight: 700; padding: 2px 8px; border-radius: var(--pill); }
.ota-yoy-up { background: #fdf2f1; color: var(--red); }      /* in crescita = male */
.ota-yoy-down { background: #e9f8ee; color: var(--green); }
.ota-foot { font-size: 11px; margin-top: 10px; }

/* =========================================================================
   CARICA FATTURE v2 · uso in autonomia (passi, zona grande, avanzamento, esito)
   ========================================================================= */
.up-steps { list-style: none; margin: 0 0 16px; padding: 0; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.up-step { display: flex; gap: 12px; align-items: flex-start; background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-sm); padding: 14px 16px; box-shadow: var(--shadow-sm); }
.up-step-n { flex: none; width: 28px; height: 28px; border-radius: 50%; display: flex; align-items: center; justify-content: center; background: var(--gold-soft); color: var(--gold-hover); border: 1px solid var(--gold-border); font-size: 13px; font-weight: 600; }
.up-step-t { font-size: 13px; font-weight: 500; line-height: 1.5; color: var(--text-2); }
.up-step-t strong { color: var(--text); font-weight: 600; }
.up-steps-foot { text-align: center; font-size: 12px; font-weight: 500; color: var(--text-3); margin: 12px 0 0; }

/* zona di rilascio: grande, bordo tratteggiato oro, stati hover/drag evidenti */
.upload-drop { min-height: 300px; border: 2px dashed var(--gold-light); }
.upload-drop:hover, .upload-drop:focus-visible { border-color: var(--gold); background: var(--gold-soft); outline: none; }
.upload-drop.drag { border: 3px solid var(--gold); background: var(--gold-soft); transform: scale(1.01); box-shadow: 0 0 0 6px rgba(184,134,11,0.12); }
.upload-drop.drag .up-drop-ico { animation: up-bob 0.9s var(--ease) infinite; }
@keyframes up-bob { 50% { transform: translateY(-6px); } }
.upload-drop.upload-busy, .upload-drop.upload-busy:hover { border-style: solid; border-color: var(--gold-border); background: var(--surface); cursor: progress; transform: none; }
.up-drop-warn { font-size: 12px; font-weight: 600; color: var(--amber); }

/* tutta la vista accetta il rilascio: velo quando la zona non e' a schermo */
#view-upload { position: relative; }
#view-upload.drag-over::after {
  content: "Rilascia qui i file"; position: absolute; inset: 0; z-index: 30; pointer-events: none;
  display: flex; align-items: center; justify-content: center;
  border: 3px dashed var(--gold); border-radius: var(--r-lg); background: rgba(250,246,234,0.9);
  font-size: 20px; font-weight: 600; color: var(--gold-hover);
}

/* barra: % reale durante l'invio, indeterminata durante l'import */
.up-progress { width: min(420px, 100%); height: 8px; border-radius: var(--pill); background: var(--surface-hover); overflow: hidden; margin-top: 4px; }
.up-progress-bar { height: 100%; width: 0; border-radius: var(--pill); background: var(--gold); transition: width 200ms linear; }
.up-progress-bar.indet { width: 35%; animation: up-indet 1.3s var(--ease) infinite; }
@keyframes up-indet { from { transform: translateX(-110%); } to { transform: translateX(300%); } }

/* avvisi in pagina (non spariscono come i toast) */
.up-notice { display: flex; gap: 10px; align-items: flex-start; border-radius: var(--r-xs); padding: 12px 14px; font-size: 13px; font-weight: 500; line-height: 1.5; margin-bottom: 14px; text-align: left; }
.up-notice .ico { width: 16px; height: 16px; flex: none; margin-top: 2px; }
.up-notice strong { font-weight: 600; }
.up-notice-warn { background: #fff7ed; border: 1px solid #fde0c2; color: #8a5500; }
.up-notice-warn .ico { color: var(--amber); }
.up-notice-info { background: var(--surface-2); border: 1px solid var(--border); color: var(--text-2); }
.up-result-card .up-notice { margin: 0; }

/* esito: card grande, leggibile da chiunque */
.up-result-card { display: flex; flex-direction: column; gap: 16px; align-items: stretch; background: var(--surface); border: 1px solid var(--border); border-top: 4px solid var(--green); border-radius: var(--r-lg); box-shadow: var(--shadow); padding: 28px 28px 24px; }
.up-result-card.up-state-warn { border-top-color: var(--amber); }
.up-result-card.up-state-err { border-top-color: var(--red); }
.up-result-head { display: flex; align-items: center; justify-content: center; gap: 10px; font-size: 26px; font-weight: 600; letter-spacing: -0.4px; color: var(--text); text-align: center; }
.up-state-ok .up-result-head { color: var(--green); }
.up-result-head .ico { width: 24px; height: 24px; color: var(--red); }
.up-result-lead { margin: -6px 0 0; text-align: center; font-size: 14px; font-weight: 500; color: var(--text-2); }
.up-stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.up-stat { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--r-sm); padding: 14px 10px; text-align: center; }
.up-stat .v { font-size: 30px; font-weight: 600; font-variant-numeric: tabular-nums; letter-spacing: -0.5px; line-height: 1.1; }
.up-stat .l { font-size: 12px; font-weight: 500; color: var(--text-2); margin-top: 4px; }
.up-stat-ok .v { color: var(--green); }
.up-stat-dup .v { color: var(--text-3); }
.up-stat-err .v { color: var(--text-3); }
.up-stat-err.has { background: #fff7ed; border-color: #fde0c2; }
.up-stat-err.has .v { color: var(--amber); }

/* dettagli tecnici: richiusi di default */
.up-details { margin-top: 14px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-sm); overflow: hidden; }
.up-details > summary { cursor: pointer; padding: 12px 16px; font-size: 13px; font-weight: 600; color: var(--text-2); list-style: revert; }
.up-details > summary:hover { background: var(--surface-hover); color: var(--text); }
.up-details[open] > summary { border-bottom: 1px solid var(--border); }
.up-details-foot { padding: 10px 16px; font-size: 12px; font-weight: 500; color: var(--text-3); border-top: 1px solid var(--border); }

@media (max-width: 860px) {
  .up-steps { grid-template-columns: 1fr; gap: 8px; }
  .up-step { padding: 12px 14px; }
}
@media (max-width: 560px) {
  .upload-drop { min-height: 220px; padding: 32px 18px; }
  .up-result-card { padding: 22px 16px 18px; }
  .up-result-head { font-size: 21px; }
  .up-stat .v { font-size: 24px; }
  .up-stat .l { font-size: 11px; }
  .up-actions .btn { width: 100%; justify-content: center; }
}
