/* ==========================================================================
   FirmaPro — design system
   Palette: neutro caldo + 1 accent verde petrolio ("conforme")
   Font: Manrope (titoli) + Inter (testo)
   ========================================================================== */
:root {
  --bg: #ffffff;
  --bg-app: #f5f7fb;
  --bg-subtle: #eef2f8;
  --border: rgb(20 24 31 / 0.09);
  --border-strong: rgb(20 24 31 / 0.18);
  --text: #0b1d51;
  --text-body: #3a4250;
  --text-muted: #667080;
  --accent: #0056fc;
  --accent-hover: #0046d1;
  --accent-soft: rgb(0 86 252 / 0.08);
  --ok: #0e7a5f;
  --ok-soft: rgb(14 122 95 / 0.1);
  --warn: #a15c07;
  --warn-soft: rgb(217 119 6 / 0.12);
  --info: #6941c6;
  --info-soft: rgb(105 65 198 / 0.1);
  --danger: #b4372a;
  --danger-soft: rgb(180 55 42 / 0.09);

  --font-head: 'Manrope', system-ui, sans-serif;
  --font-body: 'Inter', system-ui, sans-serif;

  --text-xs: 0.75rem;
  --text-sm: 0.8125rem;
  --text-base: 0.875rem;
  --text-lg: 1.125rem;
  --text-xl: 1.5rem;
  --text-2xl: 1.875rem;

  --space-1: 0.25rem; --space-2: 0.5rem; --space-3: 0.75rem;
  --space-4: 1rem; --space-6: 1.5rem; --space-8: 2rem;
  --space-12: 3rem; --space-16: 4rem;

  --radius-sm: 6px;
  --radius: 8px;
  --radius-lg: 12px;
  --shadow-sm: 0 1px 2px rgb(20 24 31 / 0.06);
  --shadow-md: 0 4px 12px rgb(20 24 31 / 0.08);
  --shadow-lg: 0 16px 40px rgb(20 24 31 / 0.16);

  --sidebar-w: 248px;
  --topbar-h: 64px;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  font-family: var(--font-body);
  font-size: var(--text-base);
  line-height: 1.6;
  color: var(--text-body);
  background: var(--bg-app);
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}
h1, h2, h3, h4 { font-family: var(--font-head); color: var(--text); line-height: 1.15; letter-spacing: -0.02em; font-weight: 700; }
a { color: var(--accent); text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
svg { flex-shrink: 0; }
.num { font-variant-numeric: tabular-nums; }
.muted { color: var(--text-muted); }
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- Layout ---------- */
.app { display: flex; min-height: 100vh; }

.sidebar {
  position: fixed; inset: 0 auto 0 0; width: var(--sidebar-w);
  background: var(--bg); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; padding: var(--space-4);
  z-index: 40; transition: transform 0.2s ease;
}
.brand { display: flex; align-items: center; gap: var(--space-2); padding: var(--space-2) var(--space-2) var(--space-6); }
.brand-icon { width: 34px; height: 34px; flex-shrink: 0; }
.brand-word { font-family: var(--font-head); font-weight: 800; font-size: 1.375rem; color: #0b1d51; letter-spacing: -0.03em; line-height: 1; }
.brand-word b { color: #0056fc; font-weight: 800; }

.nav { display: flex; flex-direction: column; gap: var(--space-1); }
.nav-label { font-size: var(--text-xs); text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-muted); font-weight: 600; padding: var(--space-4) var(--space-3) var(--space-2); }
.nav a {
  display: flex; align-items: center; gap: var(--space-3);
  padding: var(--space-2) var(--space-3); min-height: 40px;
  border-radius: var(--radius-sm); color: var(--text-body); font-weight: 500; white-space: nowrap;
  transition: background 0.15s ease, color 0.15s ease;
}
.nav a:hover { background: var(--bg-subtle); color: var(--text); }
.nav a.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.nav a .count { margin-left: auto; font-size: var(--text-xs); color: var(--text-muted); font-variant-numeric: tabular-nums; }

.sidebar-foot { margin-top: auto; display: flex; flex-direction: column; gap: var(--space-3); }
.sidebar-foot { position: relative; }
.company-row { width: 100%; border: 0; border-top: 1px solid var(--border); background: none; padding: var(--space-4) var(--space-2) var(--space-1); display: flex; align-items: center; gap: var(--space-3); text-align: left; cursor: pointer; border-radius: 0 0 var(--radius-sm) var(--radius-sm); transition: background .15s ease; }
.company-row:hover { background: var(--bg-subtle); }
.company-more { margin-left: auto; color: var(--text-muted); }
.account-menu { position: absolute; left: 0; right: 0; bottom: 64px; background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-lg); padding: var(--space-1); display: flex; flex-direction: column; z-index: 5; animation: pop .15s ease; }
.account-menu a, .account-menu button { display: flex; align-items: center; gap: var(--space-3); min-height: 40px; padding: 0 var(--space-3); border-radius: var(--radius-sm); color: var(--text-body); font-weight: 500; border: 0; background: none; cursor: pointer; text-align: left; font-size: var(--text-base); }
.account-menu a:hover, .account-menu button:hover { background: var(--bg-subtle); color: var(--text); }
.account-menu button { color: var(--danger); }
.company-initial { display: grid; place-items: center; font-weight: 800; color: var(--accent); font-family: var(--font-head); }
.company-logo { width: 36px; height: 36px; border-radius: var(--radius); object-fit: contain; background: var(--bg-subtle); border: 1px solid var(--border); }
.company-meta { min-width: 0; }
.company-meta strong { display: block; color: var(--text); font-size: var(--text-sm); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.company-meta span { font-size: var(--text-xs); color: var(--text-muted); }

.main { flex: 1; margin-left: var(--sidebar-w); min-width: 0; display: flex; flex-direction: column; }

.topbar {
  position: sticky; top: 0; z-index: 30; height: var(--topbar-h);
  background: rgb(245 247 251 / 0.85); backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: var(--space-4); padding: 0 var(--space-8);
}
.topbar h1 { font-size: var(--text-lg); }
.topbar .crumb { color: var(--text-muted); font-size: var(--text-sm); }
.topbar-actions { margin-left: auto; display: flex; gap: var(--space-2); align-items: center; }
.topbar .menu-btn { display: none; }

.content { padding: var(--space-8); max-width: 1400px; width: 100%; }

.scrim { display: none; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--space-2);
  min-height: 40px; padding: 0 var(--space-4);
  border-radius: var(--radius-sm); border: 1px solid transparent;
  font-weight: 600; font-size: var(--text-base); cursor: pointer; white-space: nowrap;
  transition: background 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease, transform 0.15s ease;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); box-shadow: var(--shadow-md); transform: translateY(-1px); }
.btn-secondary { background: var(--bg); color: var(--text); border-color: var(--border-strong); }
.btn-secondary:hover { background: var(--bg-subtle); border-color: var(--text-muted); }
.btn-ghost { background: transparent; color: var(--text-body); }
.btn-ghost:hover { background: var(--bg-subtle); color: var(--text); }
.btn-danger { background: transparent; color: var(--danger); }
.btn-danger:hover { background: var(--danger-soft); }
.btn-icon { width: 40px; padding: 0; }
.btn-sm { min-height: 32px; padding: 0 var(--space-3); font-size: var(--text-sm); }
.btn-block { width: 100%; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; box-shadow: none; }

/* ---------- Cards / KPI ---------- */
.card { background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow-sm); }
.card-pad { padding: var(--space-6); }
.card-head { display: flex; align-items: center; gap: var(--space-3); padding: var(--space-4) var(--space-6); border-bottom: 1px solid var(--border); }
.card-head h2 { font-size: var(--text-base); }
.card-head .btn { margin-left: auto; }

.grid { display: grid; gap: var(--space-6); }
.kpis { grid-template-columns: repeat(4, 1fr); }
.kpi { padding: var(--space-6); display: flex; flex-direction: column; gap: var(--space-2); }
.kpi-label { display: flex; align-items: center; gap: var(--space-2); font-size: var(--text-sm); color: var(--text-muted); font-weight: 500; }
.kpi-value { font-family: var(--font-head); font-size: var(--text-2xl); font-weight: 800; color: var(--text); letter-spacing: -0.02em; font-variant-numeric: tabular-nums; line-height: 1.1; }
.kpi-sub { font-size: var(--text-sm); color: var(--text-muted); }

.quick { grid-template-columns: repeat(2, 1fr); }
.quick-card {
  display: flex; align-items: center; gap: var(--space-4); padding: var(--space-6);
  color: var(--text-body); transition: box-shadow 0.18s ease, transform 0.18s ease, border-color 0.18s ease;
}
.quick-card:hover { box-shadow: var(--shadow-md); transform: translateY(-2px); border-color: var(--border-strong); }
.quick-icon { width: 48px; height: 48px; border-radius: var(--radius); display: grid; place-items: center; background: var(--accent-soft); color: var(--accent); }
.quick-card h3 { font-size: var(--text-lg); margin-bottom: var(--space-1); }
.quick-card p { font-size: var(--text-sm); color: var(--text-muted); }
.quick-card .arrow { margin-left: auto; color: var(--text-muted); transition: transform 0.18s ease; }
.quick-card:hover .arrow { transform: translateX(4px); color: var(--accent); }

.section-gap { margin-top: var(--space-6); }

/* ---------- Table ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th {
  text-align: left; font-size: var(--text-xs); text-transform: uppercase; letter-spacing: 0.05em;
  color: var(--text-muted); font-weight: 600; padding: var(--space-3) var(--space-6);
  border-bottom: 1px solid var(--border); white-space: nowrap; background: var(--bg);
}
td { padding: var(--space-3) var(--space-6); border-bottom: 1px solid var(--border); vertical-align: middle; }
tbody tr { transition: background 0.15s ease; cursor: pointer; }
tbody tr:hover { background: var(--bg-subtle); }
tbody tr:last-child td { border-bottom: 0; }
td.right, th.right { text-align: right; }
.doc-cell { display: flex; align-items: center; gap: var(--space-3); }
.doc-type-icon { flex-shrink: 0; width: 32px; height: 32px; border-radius: var(--radius-sm); display: grid; place-items: center; background: var(--bg-subtle); color: var(--text-muted); }
.doc-type-icon.dico { background: var(--accent-soft); color: var(--accent); }
.doc-cell > div { min-width: 0; }
.doc-cell strong { color: var(--text); display: block; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.doc-cell span { font-size: var(--text-xs); color: var(--text-muted); white-space: nowrap; }
table.doc-table { table-layout: fixed; }
.doc-table .w-client { width: 24%; } .doc-table .w-date { width: 120px; } .doc-table .w-amount { width: 112px; } .doc-table .w-status { width: 124px; }
.doc-table th, .doc-table td { padding-left: var(--space-4); padding-right: var(--space-4); }
.doc-table th:first-child, .doc-table td:first-child { padding-left: var(--space-6); }
.doc-table td { overflow: hidden; text-overflow: ellipsis; }
td:not(:first-child) { white-space: nowrap; }

.badge {
  display: inline-flex; align-items: center; gap: 6px; white-space: nowrap;
  padding: 2px var(--space-2); border-radius: 999px; font-size: var(--text-xs); font-weight: 600;
  background: var(--bg-subtle); color: var(--text-muted);
}
.badge::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge.bozza { background: var(--warn-soft); color: var(--warn); }
.badge.firmato { background: var(--ok-soft); color: var(--ok); }
.badge.inviato { background: var(--info-soft); color: var(--info); }
.badge.rifiutato { background: var(--danger-soft); color: var(--danger); }

/* ---------- Filters ---------- */
.toolbar { display: flex; flex-wrap: wrap; gap: var(--space-3); align-items: center; padding: var(--space-4) var(--space-6); border-bottom: 1px solid var(--border); }
.search { position: relative; flex: 1; min-width: 200px; max-width: 360px; }
.search svg { position: absolute; left: var(--space-3); top: 50%; transform: translateY(-50%); color: var(--text-muted); pointer-events: none; }
.search input { padding-left: 36px; }
.segmented { display: inline-flex; background: var(--bg-subtle); border-radius: var(--radius-sm); padding: 2px; }
.segmented button {
  border: 0; background: transparent; padding: 0 var(--space-3); min-height: 32px; border-radius: 4px;
  font-size: var(--text-sm); font-weight: 500; color: var(--text-muted); cursor: pointer; transition: all 0.15s ease;
}
.segmented button:hover { color: var(--text); }
.segmented button.on { background: var(--bg); color: var(--text); box-shadow: var(--shadow-sm); font-weight: 600; }

/* ---------- Forms ---------- */
.form-grid { display: grid; grid-template-columns: repeat(12, 1fr); gap: var(--space-4); }
.col-12 { grid-column: span 12; } .col-8 { grid-column: span 8; } .col-6 { grid-column: span 6; }
.col-4 { grid-column: span 4; } .col-3 { grid-column: span 3; } .col-2 { grid-column: span 2; } .col-1 { grid-column: span 1; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field label, .label { font-size: var(--text-sm); font-weight: 600; color: var(--text); }
.field .hint { font-size: var(--text-xs); color: var(--text-muted); }
.input, .field input, .field select, .field textarea {
  width: 100%; min-height: 40px; padding: var(--space-2) var(--space-3);
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm); background: var(--bg);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.field textarea { min-height: 88px; resize: vertical; line-height: 1.5; }
.input:focus, .field input:focus, .field select:focus, .field textarea:focus {
  outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft);
}
.field.error input, .field.error select { border-color: var(--danger); }
.field .err { font-size: var(--text-xs); color: var(--danger); }

.form-section { padding: var(--space-6); border-bottom: 1px solid var(--border); }
.form-section:last-child { border-bottom: 0; }
.form-section > h3 { font-size: var(--text-base); margin-bottom: var(--space-1); display: flex; align-items: center; gap: var(--space-2); }
.form-section > h3 .step { width: 22px; height: 22px; border-radius: 50%; background: var(--accent); color: #fff; font-size: var(--text-xs); display: grid; place-items: center; }
.form-section > p { font-size: var(--text-sm); color: var(--text-muted); margin-bottom: var(--space-4); }

.checks { display: grid; grid-template-columns: repeat(2, 1fr); gap: var(--space-2); }
.check {
  display: flex; align-items: flex-start; gap: var(--space-3); padding: var(--space-3);
  border: 1px solid var(--border); border-radius: var(--radius-sm); cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease; font-size: var(--text-sm); line-height: 1.45;
}
.check:hover { border-color: var(--border-strong); }
.check input { margin-top: 2px; accent-color: var(--accent); width: 16px; height: 16px; flex-shrink: 0; }
.check:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.check b { color: var(--text); font-weight: 600; }

/* Righe preventivo */
.lines { width: 100%; }
.lines th, .lines td { padding: var(--space-2); border-bottom: 1px solid var(--border); }
.lines th:first-child, .lines td:first-child { padding-left: 0; }
.lines tbody tr { cursor: default; }
.lines tbody tr:hover { background: transparent; }
.lines input, .lines select { min-height: 36px; }
.lines .c-desc { width: 40%; } .lines .c-um { width: 13%; } .lines .c-qty { width: 10%; }
.lines .c-price { width: 14%; } .lines .c-iva { width: 10%; } .lines .c-tot { width: 11%; text-align: right; }
.lines td.c-tot { font-weight: 600; color: var(--text); font-variant-numeric: tabular-nums; white-space: nowrap; }
.totals { margin-left: auto; width: 280px; margin-top: var(--space-4); display: flex; flex-direction: column; gap: var(--space-2); }
.totals div { display: flex; justify-content: space-between; font-variant-numeric: tabular-nums; }
.totals .grand { border-top: 1px solid var(--border); padding-top: var(--space-2); font-family: var(--font-head); font-weight: 800; font-size: var(--text-lg); color: var(--text); }

.sticky-actions {
  position: sticky; bottom: 0; z-index: 20; margin-top: var(--space-6);
  background: rgb(255 255 255 / 0.92); backdrop-filter: blur(8px);
  border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow-md);
  padding: var(--space-3) var(--space-4); display: flex; gap: var(--space-2); align-items: center;
}
.sticky-actions .spacer { flex: 1; }

/* ---------- Document view ---------- */
.doc-layout { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: var(--space-6); align-items: start; }
.doc-stage { background: var(--bg-subtle); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: var(--space-8); overflow-x: auto; }
.doc-side { position: sticky; top: calc(var(--topbar-h) + var(--space-6)); display: flex; flex-direction: column; gap: var(--space-4); }
.doc-side .card-pad { display: flex; flex-direction: column; gap: var(--space-3); }
.side-title { font-size: var(--text-xs); text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-muted); font-weight: 600; }
.sig-row { display: flex; align-items: center; gap: var(--space-3); padding: var(--space-3); border: 1px solid var(--border); border-radius: var(--radius-sm); }
.sig-row .dot { width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; background: var(--bg-subtle); color: var(--text-muted); }
.sig-row.done .dot { background: var(--ok-soft); color: var(--ok); }
.sig-row div { flex: 1; min-width: 0; }
.sig-row strong { display: block; color: var(--text); font-size: var(--text-sm); }
.sig-row span { font-size: var(--text-xs); color: var(--text-muted); }
.timeline { display: flex; flex-direction: column; gap: var(--space-3); }
.timeline li { list-style: none; display: flex; gap: var(--space-3); font-size: var(--text-sm); }
.timeline li::before { content: ''; width: 8px; height: 8px; border-radius: 50%; background: var(--border-strong); margin-top: 7px; flex-shrink: 0; }
.timeline li.ok::before { background: var(--accent); }
.timeline time { display: block; font-size: var(--text-xs); color: var(--text-muted); }

/* ---------- Paper (A4) — anche base del PDF ---------- */
.paper {
  width: 794px; min-height: 1123px; margin: 0 auto; background: #fff; color: #1b1f27;
  box-shadow: var(--shadow-md); padding: 48px 56px; font-size: 11.5px; line-height: 1.5;
  font-family: var(--font-body);
}
.paper * { letter-spacing: normal; }
.p-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 24px; padding-bottom: 16px; border-bottom: 2px solid #1b1f27; }
.p-logo { max-width: 160px; max-height: 64px; object-fit: contain; }
.p-company { text-align: right; font-size: 10.5px; color: #4a5260; line-height: 1.5; }
.p-company strong { display: block; font-size: 13px; color: #1b1f27; font-family: var(--font-head); }
.p-title { margin: 24px 0 4px; font-family: var(--font-head); font-size: 20px; font-weight: 800; color: #1b1f27; letter-spacing: -0.01em; line-height: 1.2; }
.p-subtitle { font-size: 10.5px; color: #667080; margin-bottom: 16px; }
.p-meta { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin: 16px 0; }
.p-box { border: 1px solid #d9dde3; border-radius: 6px; padding: 10px 12px; }
.p-box h4 { font-family: var(--font-body); font-size: 9px; text-transform: uppercase; letter-spacing: 0.08em; color: #667080; font-weight: 700; margin-bottom: 4px; }
.p-box p { max-width: none; }
.p-section { margin: 14px 0; }
.p-section h4 { font-family: var(--font-body); font-size: 9.5px; text-transform: uppercase; letter-spacing: 0.08em; color: #0056fc; font-weight: 700; margin-bottom: 6px; padding-bottom: 4px; border-bottom: 1px solid #e5e8ec; }
.p-section p { max-width: none; margin-bottom: 4px; }
.p-checks { display: grid; grid-template-columns: 1fr 1fr; gap: 3px 16px; }
.p-check { display: flex; gap: 6px; align-items: flex-start; }
.p-box-mark { width: 10px; height: 10px; border: 1px solid #1b1f27; border-radius: 2px; flex-shrink: 0; margin-top: 3px; display: grid; place-items: center; font-size: 8px; line-height: 1; }
.p-check.on .p-box-mark { background: #1b1f27; color: #fff; }
.p-check.off { color: #8a929e; }
.p-table { width: 100%; border-collapse: collapse; margin: 12px 0; }
.p-table th { font-size: 9px; text-transform: uppercase; letter-spacing: 0.06em; color: #667080; text-align: left; padding: 6px 8px; border-bottom: 1px solid #1b1f27; background: none; }
.p-table td { padding: 7px 8px; border-bottom: 1px solid #e5e8ec; vertical-align: top; }
.p-table tbody tr { cursor: default; }
.p-table tbody tr:hover { background: none; }
.p-table .r { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.p-totals { margin-left: auto; width: 240px; }
.p-totals div { display: flex; justify-content: space-between; padding: 3px 0; font-variant-numeric: tabular-nums; }
.p-totals .grand { border-top: 2px solid #1b1f27; margin-top: 4px; padding-top: 6px; font-weight: 800; font-size: 14px; font-family: var(--font-head); }
.p-sigs { display: grid; grid-template-columns: 1fr 1fr; gap: 32px; margin-top: 28px; page-break-inside: avoid; }
.p-sig { display: flex; flex-direction: column; }
.p-sig-img { height: 72px; border-bottom: 1px solid #1b1f27; display: flex; align-items: flex-end; justify-content: center; }
.p-sig-img img { max-height: 70px; max-width: 100%; }
.p-sig-img .empty { color: #a0a7b2; font-size: 10px; padding-bottom: 6px; }
.p-sig small { margin-top: 4px; color: #4a5260; font-size: 10px; }
.p-legal { margin-top: 20px; font-size: 9px; color: #667080; line-height: 1.5; }
.p-legal p { max-width: none; }
.p-foot { margin-top: 24px; padding-top: 8px; border-top: 1px solid #e5e8ec; font-size: 9px; color: #8a929e; display: flex; justify-content: space-between; }

/* ---------- Modal / signature ---------- */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 100; background: rgb(20 24 31 / 0.5);
  display: grid; place-items: center; padding: var(--space-4); animation: fade 0.15s ease;
}
.modal { background: var(--bg); border-radius: var(--radius-lg); box-shadow: var(--shadow-lg); width: 100%; max-width: 560px; max-height: calc(100vh - 32px); overflow: auto; animation: pop 0.18s ease; }
.modal.wide { max-width: 760px; }
.modal-head { display: flex; align-items: center; gap: var(--space-3); padding: var(--space-4) var(--space-6); border-bottom: 1px solid var(--border); }
.modal-head h2 { font-size: var(--text-lg); }
.modal-head .btn { margin-left: auto; }
.modal-body { padding: var(--space-6); display: flex; flex-direction: column; gap: var(--space-4); }
.modal-foot { display: flex; gap: var(--space-2); justify-content: flex-end; padding: var(--space-4) var(--space-6); border-top: 1px solid var(--border); }
@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { opacity: 0; transform: translateY(8px) scale(0.98); } }

.sig-pad-wrap { position: relative; border: 1px dashed var(--border-strong); border-radius: var(--radius); background: var(--bg-subtle); }
.sig-pad { display: block; width: 100%; height: 240px; touch-action: none; cursor: crosshair; border-radius: var(--radius); }
.sig-line { position: absolute; left: 10%; right: 10%; bottom: 56px; border-bottom: 1px solid var(--border-strong); pointer-events: none; }
.sig-hint { position: absolute; left: 0; right: 0; bottom: 24px; text-align: center; font-size: var(--text-xs); color: var(--text-muted); pointer-events: none; }
.sig-declare { font-size: var(--text-sm); color: var(--text-muted); background: var(--bg-subtle); border-radius: var(--radius-sm); padding: var(--space-3); }

.email-preview { border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.email-attach { display: flex; align-items: center; gap: var(--space-3); padding: var(--space-3); background: var(--bg-subtle); border-top: 1px solid var(--border); font-size: var(--text-sm); }
.email-attach .pdf { width: 32px; height: 32px; border-radius: var(--radius-sm); background: var(--danger-soft); color: var(--danger); display: grid; place-items: center; font-size: 9px; font-weight: 800; }

/* ---------- Empty / toast / misc ---------- */
.empty { text-align: center; padding: var(--space-16) var(--space-6); }
.empty-icon { width: 56px; height: 56px; border-radius: 50%; background: var(--bg-subtle); color: var(--text-muted); display: grid; place-items: center; margin: 0 auto var(--space-4); }
.empty h3 { font-size: var(--text-lg); margin-bottom: var(--space-2); }
.empty p { color: var(--text-muted); margin: 0 auto var(--space-6); max-width: 42ch; }

.toasts { position: fixed; right: var(--space-6); bottom: var(--space-6); z-index: 200; display: flex; flex-direction: column; gap: var(--space-2); }
.toast {
  display: flex; align-items: center; gap: var(--space-3); min-width: 280px; max-width: 400px;
  background: var(--text); color: #fff; padding: var(--space-3) var(--space-4); border-radius: var(--radius);
  box-shadow: var(--shadow-lg); font-size: var(--text-sm); animation: pop 0.2s ease;
}
.toast svg { color: #8fb5ff; }

.logo-drop {
  display: flex; align-items: center; gap: var(--space-4); padding: var(--space-4);
  border: 1px dashed var(--border-strong); border-radius: var(--radius);
}
.logo-drop img { width: 96px; height: 64px; object-fit: contain; background: var(--bg-subtle); border-radius: var(--radius-sm); }
.sig-preview { width: 200px; height: 72px; object-fit: contain; background: var(--bg-subtle); border-radius: var(--radius-sm); border: 1px solid var(--border); }

.client-row-actions { opacity: 0; transition: opacity 0.15s ease; }
tbody tr:hover .client-row-actions { opacity: 1; }

.demo-note { display: flex; gap: var(--space-3); align-items: flex-start; padding: var(--space-3) var(--space-4); border-radius: var(--radius); background: var(--info-soft); color: var(--info); font-size: var(--text-sm); }
.demo-note p { max-width: none; }

/* ---------- Automazioni DiCo ---------- */
.modelli { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--space-2); }
.modello {
  display: flex; align-items: center; gap: var(--space-3); min-height: 48px; padding: var(--space-2) var(--space-3);
  border: 1px solid var(--border-strong); border-radius: var(--radius); background: var(--bg); cursor: pointer;
  font-weight: 600; color: var(--text); text-align: left; transition: border-color 0.15s ease, background 0.15s ease, transform 0.15s ease;
}
.modello svg { color: var(--accent); }
.modello:hover { border-color: var(--accent); background: var(--accent-soft); transform: translateY(-1px); }
.modello.on { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }
em.auto { font-style: normal; font-size: var(--text-xs); font-weight: 600; color: var(--accent); background: var(--accent-soft); padding: 1px 6px; border-radius: 999px; margin-left: 4px; white-space: nowrap; }
.lines .empty-row td { padding: var(--space-4) 0; font-size: var(--text-sm); }
.mat .m-marca { width: 20%; } .mat .m-norma { width: 22%; } .mat .m-qty { width: 10%; }
.ver .v-val { width: 160px; } .ver .v-esito { width: 130px; }
.ver .v-label { font-size: var(--text-sm); color: var(--text); }
.unit-input { display: flex; align-items: center; border: 1px solid var(--border-strong); border-radius: var(--radius-sm); background: var(--bg); transition: border-color .15s, box-shadow .15s; }
.unit-input:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.unit-input input { border: 0 !important; box-shadow: none !important; min-width: 0; }
.unit-input span { padding: 0 var(--space-3); color: var(--text-muted); font-size: var(--text-sm); white-space: nowrap; }

.alerts { display: flex; flex-direction: column; gap: var(--space-2); margin-bottom: var(--space-4); }
.alert { display: flex; align-items: center; gap: var(--space-3); padding: var(--space-3) var(--space-4); border-radius: var(--radius); font-size: var(--text-sm); font-weight: 500; background: var(--warn-soft); color: var(--warn); margin-bottom: var(--space-4); }
.alerts .alert { margin-bottom: 0; }
.alert.danger { background: var(--danger-soft); color: var(--danger); }
.alert .alert-cta { margin-left: auto; display: inline-flex; align-items: center; gap: 4px; font-weight: 700; white-space: nowrap; }
a.alert:hover { filter: brightness(0.97); }

.reg-row { display: flex; flex-direction: column; gap: var(--space-3); padding: var(--space-4) 0; border-bottom: 1px dashed var(--border); }
.reg-row:first-of-type { padding-top: 0; }
.reg-row .check { border: 0; padding: 0; background: none !important; }
.doc-tile { display: flex; align-items: flex-start; gap: var(--space-4); padding: var(--space-4); border: 1px solid var(--border); border-radius: var(--radius); height: 100%; }
.doc-tile .quick-icon { width: 40px; height: 40px; flex-shrink: 0; }
.file-name { font-size: var(--text-xs); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rows { display: flex; flex-direction: column; gap: var(--space-3); margin-bottom: var(--space-3); }
.row-card { border: 1px solid var(--border); border-radius: var(--radius); padding: var(--space-4); background: var(--bg-app); }
.row-card input { background: var(--bg); }
.row-foot { display: flex; align-items: center; gap: var(--space-3); margin-top: var(--space-3); flex-wrap: wrap; }
.row-foot .btn { margin-left: auto; }
.chips { display: flex; align-items: center; flex-wrap: wrap; gap: var(--space-1); }
.chip { position: relative; cursor: pointer; }
.chip input { position: absolute; opacity: 0; pointer-events: none; }
.chip span { display: grid; place-items: center; width: 32px; height: 32px; border-radius: var(--radius-sm); border: 1px solid var(--border-strong); background: var(--bg); font-weight: 700; font-size: var(--text-sm); color: var(--text-muted); transition: all .15s ease; }
.chip input:checked + span { background: var(--accent); border-color: var(--accent); color: #fff; }
.chip input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- Piano / abbonamento ---------- */
.plan-box { display: flex; flex-direction: column; gap: var(--space-2); padding: var(--space-3); border-radius: var(--radius); background: var(--accent-soft); color: var(--text-body); transition: filter .15s ease; }
.plan-box:hover { filter: brightness(0.97); }
.plan-box-head { display: flex; justify-content: space-between; align-items: baseline; font-size: var(--text-sm); }
.plan-box-head strong { color: var(--text); }
.plan-box-head span { font-size: var(--text-xs); color: var(--text-muted); }
.plan-box-cta { display: inline-flex; align-items: center; gap: 4px; font-size: var(--text-sm); font-weight: 700; color: var(--accent); }
.usage-bar { height: 6px; border-radius: 999px; background: rgb(20 24 31 / 0.08); overflow: hidden; }
.usage-bar span { display: block; height: 100%; background: var(--accent); border-radius: inherit; transition: width .3s ease; }
.usage-bar span.full { background: var(--warn); }
.usage { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-6); margin-top: var(--space-6); padding-top: var(--space-6); border-top: 1px solid var(--border); }
.usage-row { display: flex; flex-direction: column; gap: var(--space-2); }
.usage-label { display: flex; justify-content: space-between; font-size: var(--text-sm); }
.usage-label strong { color: var(--text); }
.plan-current-head { display: flex; align-items: center; gap: var(--space-4); flex-wrap: wrap; }
.plan-current-head h2 { font-size: var(--text-xl); margin: 2px 0; }
.plan-current-head > div { flex: 1; min-width: 200px; }
.plan-cards { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-4); }
.plan-card { position: relative; border: 1px solid var(--border-strong); border-radius: var(--radius-lg); padding: var(--space-6); display: flex; flex-direction: column; gap: var(--space-3); }
.plan-card.best { border: 2px solid var(--accent); box-shadow: var(--shadow-md); }
.plan-card p { font-size: var(--text-sm); }
.plan-name { font-weight: 700; color: var(--text); }
.plan-price { color: var(--text-muted); font-size: var(--text-sm); }
.plan-price span { font-family: var(--font-head); font-size: var(--text-2xl); font-weight: 800; color: var(--text); letter-spacing: -0.02em; margin-right: 4px; }
.plan-flag { position: absolute; top: -11px; right: var(--space-4); background: var(--accent); color: #fff; font-size: var(--text-xs); font-weight: 700; padding: 2px var(--space-2); border-radius: 999px; }
.plan-feats { list-style: none; display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-2) var(--space-6); margin-top: var(--space-6); font-size: var(--text-sm); }
.plan-feats li { display: flex; gap: var(--space-2); align-items: flex-start; }
.plan-feats svg { color: var(--accent); margin-top: 3px; }
.paywall-head { display: flex; gap: var(--space-4); align-items: flex-start; margin-bottom: var(--space-6); }
.paywall-head strong { color: var(--text); font-size: var(--text-lg); }
.alert.ok { background: var(--ok-soft); color: var(--ok); }
.alert.onboard { background: var(--info-soft); color: var(--info); }
.alert.plan { background: var(--bg); color: var(--text-body); border: 1px solid var(--border); }
.alert.plan svg:first-child { color: var(--accent); }
.alert.plan .alert-cta { color: var(--accent); }
.alert strong { font-weight: 700; }

/* ---------- Accesso ---------- */
.app.auth-mode .sidebar, .app.auth-mode .topbar { display: none; }
.app.auth-mode .main { margin-left: 0; }
.app.auth-mode .content { max-width: none; padding: 0; }
.auth-wrap { min-height: 100vh; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: var(--space-8) var(--space-4); gap: var(--space-6); }
.auth-brand { padding: 0; }
.auth-brand .brand-icon { width: 44px; height: 44px; }
.auth-brand .brand-word { font-size: 1.875rem; }
.auth-card { width: 100%; max-width: 420px; padding: var(--space-8); }
.auth-card h1 { font-size: var(--text-xl); margin-bottom: var(--space-2); }
.auth-card > p { font-size: var(--text-sm); margin-bottom: var(--space-6); }
.auth-card form { display: flex; flex-direction: column; gap: var(--space-4); }
.auth-err { padding: var(--space-2) var(--space-3); background: var(--danger-soft); border-radius: var(--radius-sm); font-size: var(--text-sm) !important; }
.auth-links { margin-top: var(--space-6); display: flex; flex-direction: column; gap: var(--space-2); align-items: center; font-size: var(--text-sm); color: var(--text-muted); }
.auth-links a { font-weight: 600; display: inline-flex; align-items: center; gap: 4px; }
.boot { display: flex; align-items: center; justify-content: center; gap: var(--space-2); min-height: 50vh; color: var(--text-muted); }

/* ---------- Area account ---------- */
.tabs { display: flex; gap: var(--space-1); margin-bottom: var(--space-4); overflow-x: auto; scrollbar-width: none; border-bottom: 1px solid var(--border); }
.tabs::-webkit-scrollbar { display: none; }
.tab { display: inline-flex; align-items: center; gap: var(--space-2); min-height: 44px; padding: 0 var(--space-4); border: 0; background: none; cursor: pointer; font-weight: 600; color: var(--text-muted); border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; transition: color .15s ease, border-color .15s ease; }
.tab:hover { color: var(--text); }
.tab.on { color: var(--accent); border-bottom-color: var(--accent); }
.num-card { border: 1px solid var(--border); border-radius: var(--radius); padding: var(--space-4); display: flex; flex-direction: column; gap: var(--space-3); }
.num-preview { font-size: var(--text-sm); color: var(--text-muted); background: var(--bg-subtle); border-radius: var(--radius-sm); padding: var(--space-2) var(--space-3); }
.num-preview strong { color: var(--text); font-variant-numeric: tabular-nums; }
.account-card { padding: var(--space-6); }
.account-head { display: flex; align-items: center; gap: var(--space-4); flex-wrap: wrap; }
.account-head h2 { font-size: var(--text-lg); }
.account-head p { font-size: var(--text-sm); }
.avatar { width: 48px; height: 48px; border-radius: 50%; background: var(--accent); color: #fff; display: grid; place-items: center; font-family: var(--font-head); font-weight: 800; font-size: var(--text-lg); flex-shrink: 0; }
.account-row { display: flex; align-items: center; gap: var(--space-4); padding: var(--space-4) var(--space-6); border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.account-row:last-child { border-bottom: 0; }
.account-row > div { flex: 1; min-width: 220px; }
.account-row strong { color: var(--text); }
.account-row p { font-size: var(--text-sm); }
.danger-zone { border-color: rgb(180 55 42 / 0.25); }

/* Rendering PDF fuori schermo */
.pdf-render { position: fixed; left: -10000px; top: 0; width: 794px; }
.pdf-render .paper { box-shadow: none; min-height: 0; }
.paper + .paper { margin-top: var(--space-6); }
.pdf-render .paper + .paper { margin-top: 0; }

/* ---------- Responsive ---------- */
@media (max-width: 1100px) { .hide-md { display: none; } }
@media (max-width: 1200px) {
  .kpis { grid-template-columns: repeat(2, 1fr); }
  .doc-layout { grid-template-columns: 1fr; }
  .doc-side { display: contents; }
  .doc-side > .card:first-child { order: -1; }
}
@media (max-width: 900px) {
  .sidebar { transform: translateX(-100%); }
  .app.nav-open .sidebar { transform: none; box-shadow: var(--shadow-lg); }
  .app.nav-open .scrim { display: block; position: fixed; inset: 0; background: rgb(20 24 31 / 0.4); z-index: 35; }
  .main { margin-left: 0; }
  .topbar .menu-btn { display: inline-flex; }
  .topbar { padding: 0 var(--space-4); }
  .content { padding: var(--space-4); }
  .col-8, .col-6, .col-4 { grid-column: span 12; }
  .col-3, .col-2 { grid-column: span 6; }
  .col-1 { grid-column: span 6; }
  .checks { grid-template-columns: 1fr; }
  .modelli { grid-template-columns: 1fr 1fr; }
  .doc-stage { padding: var(--space-4); }
}
@media (max-width: 640px) {
  .quick { grid-template-columns: 1fr; }
  .plan-cards, .plan-feats, .usage { grid-template-columns: 1fr; }
  .auth-card { padding: var(--space-6); }
  .grid { gap: var(--space-3); }
  .section-gap { margin-top: var(--space-3); }
  .kpis { grid-template-columns: 1fr 1fr; }
  .kpi { padding: var(--space-4); gap: var(--space-1); }
  .kpi-value { font-size: var(--text-xl); }
  .kpi-label { font-size: var(--text-xs); line-height: 1.3; }
  .kpi-label svg { display: none; }
  .kpi-sub { font-size: var(--text-xs); line-height: 1.4; }
  .quick-card { padding: var(--space-4); }
  .quick-card h3 { font-size: var(--text-base); }
  .topbar h1 { font-size: var(--text-base); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .topbar > div { min-width: 0; }
  .topbar .crumb, .topbar-actions .hide-sm { display: none; }
  th, td { padding: var(--space-3) var(--space-4); }
  .doc-table .w-status { width: 112px; }
  .hide-sm { display: none; }
  .toolbar { padding: var(--space-3) var(--space-4); }
  .search { max-width: none; flex-basis: 100%; }
  .form-section { padding: var(--space-4); }
  .totals { width: 100%; }
  .toasts { left: var(--space-4); right: var(--space-4); bottom: var(--space-4); }
  .toast { min-width: 0; max-width: none; }
  .sticky-actions { flex-wrap: wrap; }
  .sticky-actions .btn { flex: 1; }
  .sticky-actions .spacer { display: none; }
  .modal-backdrop { padding: 0; place-items: end stretch; }
  .modal { border-radius: var(--radius-lg) var(--radius-lg) 0 0; max-height: 92vh; }
  .sig-pad { height: 220px; }
  .modal-foot { padding: var(--space-3) var(--space-4); }
  .modal-body { padding: var(--space-4); }
}

/* Tabelle di righe (voci, materiali, verifiche) come schede sotto i 900px */
@media (max-width: 900px) {
  .lines thead { display: none; }
  .lines, .lines tbody, .lines tr, .lines td { display: block; width: 100% !important; }
  .lines tr { display: grid; grid-template-columns: repeat(4, 1fr); gap: var(--space-2); padding: var(--space-3) 0; border-bottom: 1px solid var(--border); }
  .lines td { border: 0; padding: 0 !important; }
  .lines td.c-desc { grid-column: span 4; }
  .lines td.c-tot { grid-column: span 3; text-align: left; align-self: center; }
  .lines .empty-row td { grid-column: span 4; }
  .mat tr { grid-template-columns: 1fr 1fr 64px 40px; }
  .mat td.c-desc { grid-column: 1 / -1; }
  .ver tr { grid-template-columns: 1fr 1fr; }
  .ver td.c-desc { grid-column: 1 / -1; }
}
