/* AM Suite — struttura Zoho Books, stile AM™. Tema chiaro predefinito, scuro a scelta (data-theme="dark"). */
:root {
  --bg: linear-gradient(160deg, #f7f7fa 0%, #eef0f6 100%);
  --grid: rgba(12, 12, 31, .04);
  --side: #0c0c1f;
  --surface: #fff;
  --surface-solid: #fff;
  --bar: #fff;
  --line: #e1e3ea;
  --line2: #eef0f4;
  --text: #0c0c1f;
  --muted: #4b5065;
  --chip: #f3f4f8;
  --chip-t: #3f4458;
  --field: #cdd1dc;
  --field-bg: #fff;
  --th-bg: #f3f4f8;
  --link: #1d4ed8;
  --blue-t: #1d4ed8; --blue-bg: #dbeafe;
  --amber-t: #b45309; --amber-bg: #fef3c7;
  --red-t: #b42318; --red-bg: #fee4e2;
  --green-t: #15803d; --green-bg: #dcfce7;
  --cyan-t: #0e7490; --cyan-bg: #cffafe;
  --violet-t: #6d28d9; --violet-bg: #ede9fe;
  --shadow: 0 1px 2px rgba(12, 12, 31, .05);
  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: linear-gradient(145deg, #06060b 0%, #0c0c1f 50%, #080814 100%);
  --grid: rgba(59, 130, 246, .05);
  --side: rgba(6, 6, 14, .7);
  --surface: rgba(255, 255, 255, .045);
  --surface-solid: #10101f;
  --bar: rgba(10, 10, 24, .92);
  --line: rgba(255, 255, 255, .1);
  --line2: rgba(255, 255, 255, .06);
  --text: #fff;
  --muted: rgba(255, 255, 255, .7);
  --chip: rgba(255, 255, 255, .07);
  --chip-t: rgba(255, 255, 255, .82);
  --field: rgba(255, 255, 255, .14);
  --field-bg: rgba(255, 255, 255, .04);
  --th-bg: rgba(255, 255, 255, .04);
  --link: #93c5fd;
  --blue-t: #93c5fd; --blue-bg: rgba(59, 130, 246, .16);
  --amber-t: #fcd34d; --amber-bg: rgba(245, 158, 11, .16);
  --red-t: #fca5a5; --red-bg: rgba(239, 68, 68, .16);
  --green-t: #86efac; --green-bg: rgba(34, 197, 94, .16);
  --cyan-t: #67e8f9; --cyan-bg: rgba(6, 182, 212, .16);
  --violet-t: #c4b5fd; --violet-bg: rgba(139, 92, 246, .2);
  --shadow: 0 20px 50px rgba(0, 0, 0, .35);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body { font-family: Lato, sans-serif; color: var(--text); background: var(--bg); background-attachment: fixed; }
body::before { content: ""; position: fixed; inset: 0; pointer-events: none; background-image: linear-gradient(var(--grid) 1px, transparent 1px), linear-gradient(90deg, var(--grid) 1px, transparent 1px); background-size: 84px 84px; }
a { color: var(--link); }
button, input, select, textarea { font: inherit; }
[hidden] { display: none !important; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
:focus-visible { outline: 2px solid #3B82F6; outline-offset: 2px; }

/* Struttura */
.shell { position: relative; display: flex; min-height: 100vh; }
.side { flex: 0 0 232px; display: flex; flex-direction: column; gap: 2px; padding: 16px 10px; background: var(--side); border-right: 1px solid var(--line2); position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.brand { display: flex; align-items: center; gap: 10px; padding: 2px 10px 14px; color: #fff; font-family: Poppins, sans-serif; font-weight: 800; font-size: 17px; letter-spacing: -.02em; text-decoration: none; }
.brand sup { font-size: 9px; color: #3B82F6; }
.side a.nav { display: flex; align-items: center; gap: 10px; padding: 8px 12px; border-radius: 10px; color: rgba(255, 255, 255, .75); text-decoration: none; font-family: Poppins, sans-serif; font-weight: 500; font-size: 13.5px; }
.side a.nav:hover { background: rgba(255, 255, 255, .06); color: #fff; }
.side a.nav.on { background: rgba(59, 130, 246, .25); color: #fff; }
.side a.nav.sub { padding-left: 42px; font-weight: 400; font-size: 13px; }
.side a.nav.soon { color: rgba(255, 255, 255, .45); }
.side .grp { font-family: Poppins, sans-serif; font-size: 10.5px; font-weight: 700; letter-spacing: .1em; text-transform: uppercase; color: rgba(255, 255, 255, .55); padding: 14px 12px 4px; }
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; position: relative; }
.top { display: flex; align-items: center; gap: 12px; padding: 12px 24px; border-bottom: 1px solid var(--line); background: var(--bar); flex-wrap: wrap; position: sticky; top: 0; z-index: 5; }
.search { flex: 1 1 260px; max-width: 460px; display: flex; align-items: center; gap: 8px; min-height: 40px; padding: 0 12px; border-radius: 10px; border: 1px solid var(--field); background: var(--field-bg); color: var(--muted); }
.search input { flex: 1; background: transparent; border: 0; color: var(--text); font-size: 14px; outline: none; min-width: 0; }
.top-actions { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.page { padding: 20px 24px 40px; display: flex; flex-direction: column; gap: 18px; }

/* Pulsanti */
.iconbtn { display: inline-flex; align-items: center; justify-content: center; width: 40px; height: 40px; border-radius: 10px; border: 1px solid var(--line); background: var(--field-bg); color: var(--text); text-decoration: none; cursor: pointer; }
.iconbtn.add { background: #3B82F6; border-color: #3B82F6; color: #fff; }
.btn { display: inline-flex; align-items: center; gap: 6px; min-height: 40px; padding: 0 14px; border-radius: 10px; border: 1px solid var(--field); background: var(--field-bg); color: var(--text); font-family: Poppins, sans-serif; font-weight: 500; font-size: 13px; text-decoration: none; cursor: pointer; white-space: nowrap; }
.btn:hover { border-color: #3B82F6; }
.btn.primary { border-color: #3B82F6; background: #3B82F6; color: #fff; font-weight: 600; font-size: 14px; box-shadow: 0 4px 14px rgba(59, 130, 246, .3); }
.btn.primary:hover { filter: brightness(1.08); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.danger { color: var(--red-t); }

/* Card e testo */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow); }
.card.pad { padding: 18px 20px; }
.card.alert { border-color: rgba(239, 68, 68, .45); padding: 12px 16px; display: flex; gap: 12px; align-items: center; font-size: 14px; }
.card.info { border-color: rgba(59, 130, 246, .45); padding: 12px 16px; font-size: 14px; }
.dot { width: 9px; height: 9px; border-radius: 50%; flex: none; }
h1.title { margin: 0; font-family: Poppins, sans-serif; font-weight: 700; font-size: 22px; }
.h2 { margin: 0; font-family: Poppins, sans-serif; font-weight: 600; font-size: 15px; }
.label { font-family: Poppins, sans-serif; font-size: 11px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.num { font-family: Poppins, sans-serif; font-weight: 700; font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.row { display: flex; flex-wrap: wrap; gap: 18px; }
.between { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px; font-size: 12px; font-family: Poppins, sans-serif; font-weight: 600; white-space: nowrap; }
.p-grey { background: var(--chip); color: var(--chip-t); } .p-blue { background: var(--blue-bg); color: var(--blue-t); } .p-amber { background: var(--amber-bg); color: var(--amber-t); } .p-red { background: var(--red-bg); color: var(--red-t); } .p-green { background: var(--green-bg); color: var(--green-t); } .p-cyan { background: var(--cyan-bg); color: var(--cyan-t); } .p-violet { background: var(--violet-bg); color: var(--violet-t); }
.t-blue { color: var(--blue-t); } .t-amber { color: var(--amber-t); } .t-red { color: var(--red-t); } .t-green { color: var(--green-t); } .t-violet { color: var(--violet-t); }
.tabs { display: flex; flex-wrap: wrap; border-bottom: 1px solid var(--line); }
.tabs a { display: inline-flex; align-items: center; gap: 6px; min-height: 40px; padding: 0 4px; margin-right: 22px; color: var(--muted); text-decoration: none; font-family: Poppins, sans-serif; font-weight: 500; font-size: 14px; border-bottom: 2px solid transparent; }
.tabs a.on { color: var(--text); border-bottom-color: #3B82F6; }

/* Cruscotto */
.buckets { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); }
.bucket { display: flex; flex-direction: column; gap: 2px; padding: 10px 12px; border-left: 1px solid var(--line2); }
.bucket:first-child { border-left: 0; }
.stack { display: flex; height: 10px; border-radius: 999px; overflow: hidden; background: var(--chip); }
.chart { display: flex; align-items: flex-end; gap: 10px; height: 170px; }
.chart .m { flex: 1; display: flex; flex-direction: column; align-items: stretch; gap: 6px; height: 100%; }
.chart .bars { flex: 1; display: flex; gap: 3px; align-items: flex-end; }
.chart .bars div { flex: 1; border-radius: 4px 4px 1px 1px; min-height: 2px; }
.chart .m span { font-size: 11px; text-align: center; color: var(--muted); }
.listrow { display: flex; justify-content: space-between; gap: 12px; padding: 11px 0; border-top: 1px solid var(--line2); font-size: 14px; color: var(--text); text-decoration: none; }
.listrow:first-child { border-top: 0; }
a.listrow:hover { color: var(--link); }

/* Tabelle */
.table-wrap { overflow-x: auto; }
table.list { width: 100%; border-collapse: collapse; font-size: 14px; }
.list th { text-align: left; padding: 11px 12px; font-family: Poppins, sans-serif; font-size: 11px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); background: var(--th-bg); border-bottom: 1px solid var(--line); white-space: nowrap; }
.list td { padding: 12px; border-bottom: 1px solid var(--line2); white-space: nowrap; }
.list .n { text-align: right; font-variant-numeric: tabular-nums; }
.list tbody tr.click { cursor: pointer; }
.list tbody tr.click:hover td { background: var(--chip); }
.list td.empty { text-align: center; color: var(--muted); padding: 28px; }
.list-foot { display: flex; justify-content: space-between; padding: 12px; font-size: 13px; color: var(--muted); }

/* Elenco a sinistra + scheda */
.split { display: flex; flex: 1; min-height: calc(100vh - 65px); }
.split > .left { flex: 0 0 300px; border-right: 1px solid var(--line); background: var(--surface); overflow-y: auto; max-height: calc(100vh - 65px); position: sticky; top: 65px; }
.split > .right { flex: 1; min-width: 0; }
.cust { display: flex; justify-content: space-between; gap: 10px; padding: 11px 14px; border-top: 1px solid var(--line2); color: var(--text); text-decoration: none; font-size: 14px; }
.cust span { color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.cust.on { background: var(--blue-bg); box-shadow: inset 3px 0 0 #3B82F6; }
.kv { display: grid; grid-template-columns: 130px minmax(0, 1fr); gap: 8px 12px; margin: 0; font-size: 14px; }
.kv dt { color: var(--muted); } .kv dd { margin: 0; overflow-wrap: anywhere; }
.event { display: flex; gap: 12px; padding: 11px 0; border-top: 1px solid var(--line2); font-size: 14px; }
.event:first-of-type { border-top: 0; }
.event .dot { margin-top: 6px; }

/* Moduli */
.field { display: grid; grid-template-columns: 180px minmax(0, 1fr); align-items: center; gap: 12px; font-size: 14px; }
.field > span { color: var(--chip-t); } .field > span.req { color: var(--red-t); }
.in { min-height: 40px; border: 1px solid var(--field); border-radius: 8px; padding: 0 12px; font-size: 14px; background: var(--field-bg); color: var(--text); width: 100%; }
textarea.in { padding: 10px 12px; min-height: 90px; resize: vertical; }
.in:focus { outline: none; border-color: #3B82F6; box-shadow: 0 0 0 3px rgba(59, 130, 246, .15); }
.in.bad { border-color: #EF4444; }
.in option { color: #0c0c1f; }
.err { color: var(--red-t); font-size: 13px; margin: 2px 0 0; }
.check { display: flex; gap: 10px; align-items: flex-start; font-size: 14px; padding: 8px 0; }
.sumbox { min-width: 280px; background: var(--chip); border-radius: 12px; padding: 14px 16px; display: flex; flex-direction: column; gap: 8px; font-size: 14px; }
.sumbox .tot { font-family: Poppins, sans-serif; font-weight: 700; font-size: 17px; border-top: 1px solid var(--line); padding-top: 8px; }
.footer-bar { position: sticky; bottom: 0; display: flex; gap: 10px; flex-wrap: wrap; padding: 14px 24px; background: var(--bar); border-top: 1px solid var(--line); z-index: 4; }
.lines td { vertical-align: top; white-space: normal; }
.lines td .in { min-width: 90px; }

/* Accesso */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; position: relative; }
.login form { width: min(400px, 100%); padding: 28px; display: flex; flex-direction: column; gap: 14px; }
.login label { display: grid; gap: 6px; font-size: 14px; color: var(--chip-t); }
.theme-btn { display: inline-flex; align-items: center; gap: 8px; min-height: 40px; padding: 0 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--field-bg); color: var(--text); font-family: Poppins, sans-serif; font-weight: 500; font-size: 13px; cursor: pointer; }

/* CRM: pipeline a colonne */
.kanban { display: flex; gap: 14px; align-items: flex-start; overflow-x: auto; padding-bottom: 8px; }
.col { flex: 0 0 260px; background: var(--chip); border: 1px solid var(--line2); border-radius: 14px; padding: 10px; display: flex; flex-direction: column; gap: 10px; }
.col-head { display: flex; justify-content: space-between; align-items: center; padding: 4px 4px 2px; font-family: Poppins, sans-serif; font-weight: 600; font-size: 13px; }
.col-body { display: flex; flex-direction: column; gap: 10px; max-height: calc(100vh - 290px); overflow-y: auto; }
.kcard { background: var(--surface-solid); border: 1px solid var(--line); border-radius: 12px; padding: 12px; display: flex; flex-direction: column; gap: 4px; font-size: 14px; color: var(--text); text-decoration: none; box-shadow: var(--shadow); }
.kcard:hover { border-color: #3B82F6; }
.kcard.stuck { border-color: rgba(239, 68, 68, .5); }
.meta { font-size: 13px; color: var(--muted); }

/* Conversazioni */
.bubbles { flex: 1; overflow-y: auto; max-height: calc(100vh - 380px); min-height: 260px; padding: 16px; display: flex; flex-direction: column; gap: 10px; }
.bubble { max-width: 72%; padding: 10px 12px; border-radius: 14px; font-size: 14px; line-height: 1.4; }
.bubble.in { align-self: flex-start; background: var(--chip); border-bottom-left-radius: 4px; }
.bubble.out { align-self: flex-end; background: var(--blue-bg); border-bottom-right-radius: 4px; }
.bubble.note { align-self: center; background: var(--amber-bg); max-width: 85%; }
.bubble.system { background: transparent; color: var(--muted); font-size: 13px; text-align: center; padding: 2px 8px; }
.bubble-meta { margin-top: 4px; font-size: 11.5px; color: var(--muted); }

/* Pagine pubbliche (acquisto, pagamento fattura) */
.public { min-height: 100vh; display: flex; justify-content: center; padding: 32px 16px; position: relative; }
.public-box { width: min(560px, 100%); background: var(--surface-solid); border: 1px solid var(--line); border-radius: 18px; box-shadow: 0 10px 40px rgba(12, 12, 31, .08); padding: 28px; align-self: flex-start; }
.public-box h1 { margin: 0 0 8px; font-family: Poppins, sans-serif; font-size: 26px; }
.public-box h2 { margin: 22px 0 10px; font-family: Poppins, sans-serif; font-size: 16px; }
.pdesc { white-space: pre-line; color: var(--muted); margin: 0 0 12px; }
.pprice { font-family: Poppins, sans-serif; font-weight: 700; font-size: 32px; margin: 8px 0 4px; }
.pfield { display: grid; gap: 4px; font-size: 14px; margin-bottom: 10px; flex: 1 1 140px; }
.pfield > span { color: var(--chip-t); }
.prow { display: flex; gap: 10px; flex-wrap: wrap; }

/* Documento fattura: copia del «Standard Template» di Zoho Books. Misure in punti dal PDF
   INV26-000047 (A4 = 595,42 × 841,69 pt; margini sinistro 45,6 e destro 34,8). */
.doc-wrap { display: flex; justify-content: center; overflow-x: auto; }
.doc { position: relative; flex: none; width: 595.42pt; min-height: 841.69pt; padding: 57.15pt 34.79pt 70pt 45.6pt; background: #fff; color: #333; box-shadow: 0 4px 24px rgba(12, 12, 31, .12); font-family: 'Open Sans', sans-serif; font-size: 9pt; line-height: 11.9pt; color-scheme: light; }
.doc * { box-sizing: border-box; }
.doc-head { display: flex; justify-content: space-between; align-items: flex-start; min-height: 180pt; }
.doc-logo { width: 180pt; height: 180pt; margin-left: .75pt; }
.doc-logo img { width: 100%; height: 100%; object-fit: contain; object-position: left top; }
.doc-title { text-align: right; padding-top: 2pt; }
.doc-title h1 { margin: 0; font-family: 'Open Sans', sans-serif; font-weight: 400; font-size: 28pt; line-height: 34pt; color: #000; letter-spacing: 0; }
.doc-number { font-weight: 700; font-size: 10pt; line-height: 13pt; margin-top: 1pt; }
.doc-due-label { font-weight: 700; font-size: 8pt; line-height: 11pt; margin-top: 17pt; }
.doc-due { font-weight: 700; font-size: 12pt; line-height: 15pt; }
.doc-seller { margin-top: 3.5pt; margin-left: .7pt; }
.doc-seller b, .doc-bill b { font-weight: 700; }
.doc-seller b { display: block; font-size: 10pt; line-height: 13pt; }
.doc-meta { display: flex; justify-content: space-between; align-items: flex-start; margin-top: 23pt; }
.doc-bill { margin-left: .7pt; }
.doc-bill-label { font-size: 10pt; line-height: 13pt; }
.doc-bill b { display: block; }
.doc-dates { border-collapse: collapse; margin-top: 2pt; }
.doc-dates th { font-weight: 400; font-size: 10pt; text-align: right; padding: 0 0 0 0; height: 20.7pt; vertical-align: top; white-space: nowrap; }
.doc-dates td { font-size: 9pt; text-align: right; width: 110pt; vertical-align: top; padding-top: .5pt; white-space: nowrap; }
.doc-items { width: 515.03pt; border-collapse: collapse; table-layout: fixed; margin-top: 13pt; }
.doc-items th { height: 24pt; padding: 0 6pt; background: #3c3d3a; color: #fff; font-weight: 400; font-size: 9pt; text-align: left; vertical-align: middle; }
.doc-items th + th { padding-left: 15pt; }
.doc-items th.n { text-align: right; padding-left: 6pt; border-left: .75pt solid rgba(255, 255, 255, .22); }
.doc-items th:last-child, .doc-items td:last-child { padding-right: 9pt; }
.doc-items td { padding: 8pt 6pt 7pt; color: #000; vertical-align: top; border-bottom: .75pt solid #adadad; overflow-wrap: anywhere; }
.doc-items td + td { padding-left: 15pt; }
.doc-items td.n { text-align: right; padding-left: 6pt; white-space: nowrap; }
.doc-items .c { text-align: center; padding-left: 0; padding-right: 0; }
.doc-desc { color: #666; font-size: 8pt; line-height: 10.5pt; white-space: pre-line; margin-top: 2pt; }
.doc-totals { width: 257.52pt; margin-left: auto; border-collapse: collapse; color: #000; }
.doc-totals th { font-weight: 400; text-align: right; padding: 0 10pt 0 0; height: 27pt; vertical-align: middle; }
.doc-totals td { width: 101.25pt; text-align: right; padding: 0 8pt 0 0; vertical-align: middle; white-space: nowrap; }
.doc-totals tr:first-child th, .doc-totals tr:first-child td { padding-top: 4pt; }
.doc-totals tr.strong th, .doc-totals tr.strong td { font-weight: 700; }
.doc-totals tr.due th, .doc-totals tr.due td { background: #f5f4f3; height: 30pt; }
.doc-totals td.paid { color: #e53935; }
.doc-notes { margin-top: 38pt; width: 380pt; }
.doc-notes-label { font-size: 10pt; line-height: 13pt; }
.doc-notes-text { font-size: 8pt; line-height: 10.5pt; white-space: pre-line; margin-top: 5pt; }
.doc-footer { position: absolute; left: 39.6pt; right: 28.79pt; bottom: 49.65pt; border-top: .75pt solid #adadad; }
.doc-footer span { position: absolute; right: 7pt; top: 8pt; font-size: 6pt; line-height: 8pt; color: #aaa; }

.print-page { background: #e9eaee; min-height: 100vh; padding: 20px 16px; }
.print-bar { display: flex; gap: 10px; justify-content: center; margin-bottom: 16px; }
@media print {
  @page { size: A4; margin: 0; }
  body { background: #fff; }
  body::before, .print-bar { display: none !important; }
  .print-page { padding: 0; background: #fff; }
  .doc { box-shadow: none; width: 210mm; min-height: 297mm; }
  /* Stampa da una scheda (es. preventivo): solo il documento. */
  .side, .top, .page > :not(.doc-wrap) { display: none !important; }
  .page { padding: 0; }
}

@media (max-width: 900px) {
  .side { display: none; }
  .split > .left { display: none; }
  .buckets { grid-template-columns: repeat(2, 1fr); }
  .field { grid-template-columns: 1fr; }
  .page { padding: 16px; }
}
