/* =====================================================================
   Gestionale · foglio di stile unico
   Colori come variabili: tema chiaro, tema scuro automatico (sistema)
   oppure scelto a mano (data-theme sul tag <html>).
   ===================================================================== */
[hidden] { display: none !important; }

:root {
  --bg: #f4f6fa;
  --panel: #ffffff;
  --panel-2: #f8fafc;
  --ink: #0f172a;
  --ink-2: #334155;
  --muted: #64748b;
  --line: #e5e9f0;
  --line-2: #d5dbe5;
  --brand: #4f46e5;
  --brand-2: #4338ca;
  --brand-ink: #ffffff;
  --brand-soft: #eef2ff;
  --brand-soft-ink: #3730a3;
  --side: #ffffff;
  --side-ink: #475569;
  --side-hover: #f1f5f9;
  --ok: #15803d;      --ok-soft: #e8f7ee;
  --err: #c2410c;     --err-soft: #fff1ea;
  --warn: #a16207;    --warn-soft: #fef6dc;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, .05);
  --shadow: 0 1px 2px rgba(15, 23, 42, .04), 0 4px 16px rgba(15, 23, 42, .05);
  --shadow-lg: 0 12px 40px rgba(15, 23, 42, .14);
  --radius: 14px;
  --radius-sm: 9px;
  --series-1: #2a78d6;
  --series-2: #eb6834;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0b1018; --panel: #121a25; --panel-2: #0f1620; --ink: #e8edf5; --ink-2: #c3ccd9; --muted: #8b98aa;
    --line: #212c3b; --line-2: #2c394b; --brand: #818cf8; --brand-2: #a5b4fc; --brand-ink: #0b1018;
    --brand-soft: #1e2142; --brand-soft-ink: #c7d2fe; --side: #0e151f; --side-ink: #a3aec0; --side-hover: #172131;
    --ok: #4ade80; --ok-soft: #0f2a1c; --err: #fb923c; --err-soft: #2e1a10; --warn: #facc15; --warn-soft: #2a2410;
    --shadow-sm: none; --shadow: 0 0 0 1px rgba(255,255,255,.02); --shadow-lg: 0 12px 40px rgba(0,0,0,.5);
    --series-1: #3987e5; --series-2: #d95926;
  }
}
:root[data-theme="dark"] {
  --bg: #0b1018; --panel: #121a25; --panel-2: #0f1620; --ink: #e8edf5; --ink-2: #c3ccd9; --muted: #8b98aa;
  --line: #212c3b; --line-2: #2c394b; --brand: #818cf8; --brand-2: #a5b4fc; --brand-ink: #0b1018;
  --brand-soft: #1e2142; --brand-soft-ink: #c7d2fe; --side: #0e151f; --side-ink: #a3aec0; --side-hover: #172131;
  --ok: #4ade80; --ok-soft: #0f2a1c; --err: #fb923c; --err-soft: #2e1a10; --warn: #facc15; --warn-soft: #2a2410;
  --shadow-sm: none; --shadow: 0 0 0 1px rgba(255,255,255,.02); --shadow-lg: 0 12px 40px rgba(0,0,0,.5);
  --series-1: #3987e5; --series-2: #d95926;
  color-scheme: dark;
}
:root[data-theme="light"] { color-scheme: light; }

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 14.5px/1.5 ui-sans-serif, -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", "Inter", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased; font-feature-settings: "tnum" 1, "cv11" 1;
}
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 2px; }
h1 { font-size: 24px; line-height: 1.25; font-weight: 700; letter-spacing: -.02em; margin: 0 0 18px; }
h2 { font-size: 15px; font-weight: 650; letter-spacing: -.005em; margin: 0 0 12px; }
h3 { font-size: 13px; font-weight: 650; margin: 16px 0 8px; color: var(--ink-2); }
p { margin: 0 0 12px; }
ul { padding-left: 20px; }
::selection { background: var(--brand-soft); }
:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; border-radius: 6px; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.ico { width: 18px; height: 18px; flex-shrink: 0; fill: none; stroke: currentColor; stroke-width: 1.75; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- struttura: menu laterale + contenuto ---------- */
.layout { display: flex; min-height: 100vh; }
.side {
  width: 256px; flex-shrink: 0; background: var(--side); color: var(--side-ink);
  border-right: 1px solid var(--line); display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh; padding: 18px 12px 12px;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 16px; color: var(--ink); padding: 0 8px 16px; letter-spacing: -.01em; }
.logo {
  width: 30px; height: 30px; border-radius: 9px; display: grid; place-items: center; color: #fff; font-size: 15px;
  background: linear-gradient(135deg, #6366f1, #4338ca 60%, #312e81); box-shadow: 0 4px 12px rgba(79,70,229,.35);
}
.company {
  display: flex; align-items: center; gap: 10px; margin: 0 0 14px; padding: 9px 10px;
  border: 1px solid var(--line); border-radius: 12px; background: var(--panel-2); color: var(--ink);
}
.company:hover { text-decoration: none; border-color: var(--line-2); }
.company .who { flex: 1; min-width: 0; }
.company strong { display: block; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.company .who span { display: block; font-size: 11.5px; color: var(--muted); }
.company .ico { width: 15px; height: 15px; color: var(--muted); }
.avatar {
  width: 30px; height: 30px; border-radius: 8px; flex-shrink: 0; display: grid; place-items: center;
  background: var(--brand-soft); color: var(--brand-soft-ink); font-weight: 700; font-size: 13px; text-transform: uppercase;
}
.avatar.user { border-radius: 50%; background: var(--side-hover); color: var(--ink-2); }
.side nav { flex: 1; overflow-y: auto; margin: 0 -4px; padding: 0 4px; scrollbar-width: thin; }
.side nav a {
  display: flex; align-items: center; gap: 11px; padding: 7px 10px; margin: 1px 0; border-radius: 8px;
  color: var(--side-ink); font-size: 13.5px; font-weight: 500;
}
.side nav a .ico { color: var(--muted); }
.side nav a:hover { background: var(--side-hover); color: var(--ink); text-decoration: none; }
.side nav a.on { background: var(--brand-soft); color: var(--brand-soft-ink); font-weight: 600; }
.side nav a.on .ico { color: var(--brand); }
.side .group { padding: 16px 10px 5px; font-size: 10.5px; font-weight: 650; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); opacity: .85; }
.logout {
  margin: 10px -12px 0; padding: 12px 12px 0; border-top: 1px solid var(--line);
  display: flex; align-items: center; gap: 8px; font-size: 13px;
}
.logout .who { flex: 1; min-width: 0; color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.iconbtn {
  display: inline-grid; place-items: center; width: 32px; height: 32px; border-radius: 8px; border: 0;
  background: transparent; color: var(--muted); cursor: pointer; padding: 0;
}
.iconbtn:hover { background: var(--side-hover); color: var(--ink); }
.main { flex: 1; min-width: 0; padding: 30px 36px 48px; max-width: 1320px; }
.mobilebar { display: none; }
.scrim { display: none; }

/* ---------- blocchi ---------- */
.card {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 20px 22px; margin-bottom: 18px; box-shadow: var(--shadow);
}
.card > h2:first-child, .card > .head:first-child h2 { margin-top: 0; }
.card.small { font-size: 13.5px; }
.card.small > div { margin: 4px 0; }
.head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.head h1 { margin: 0; }
.head > a.muted { font-size: 13.5px; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }

/* ---------- pulsanti ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  background: var(--brand); color: var(--brand-ink); border: 1px solid transparent; border-radius: var(--radius-sm);
  padding: 8px 15px; font: inherit; font-weight: 600; font-size: 13.5px; line-height: 1.35; cursor: pointer;
  box-shadow: 0 1px 2px rgba(15,23,42,.12), inset 0 1px 0 rgba(255,255,255,.12);
  transition: background .15s, border-color .15s, box-shadow .15s, transform .05s;
}
.btn:hover { background: var(--brand-2); text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn.light { background: var(--panel); color: var(--ink-2); border-color: var(--line-2); box-shadow: var(--shadow-sm); }
.btn.light:hover { background: var(--panel-2); color: var(--ink); border-color: var(--muted); }
.btn.ghost { background: transparent; color: var(--err); border-color: var(--line-2); box-shadow: none; }
.btn.ghost:hover { background: var(--err-soft); border-color: var(--err); }
.btn.big { width: 100%; padding: 12px; font-size: 15px; margin-top: 16px; border-radius: 11px; }
.btn.small { padding: 4px 10px; font-size: 12.5px; border-radius: 7px; }
.link { background: none; border: 0; color: var(--side-ink); cursor: pointer; font: inherit; padding: 0; }
.link.dark { color: var(--brand); text-decoration: none; }
.link.dark:hover { text-decoration: underline; }
.link.danger { color: var(--err); text-decoration: none; font-size: 15px; }
.link.danger.small { font-size: 12.5px; }
form.inline { display: inline; }

/* ---------- moduli (form) ---------- */
.form label, .login label, .grid4 label, .grid2 label, .card > label, .pair label {
  display: block; font-size: 12.5px; font-weight: 550; color: var(--ink-2); margin-bottom: 12px;
}
input, select, textarea {
  display: block; width: 100%; margin-top: 5px; padding: 8px 11px; border: 1px solid var(--line-2); border-radius: var(--radius-sm);
  font: inherit; font-size: 14px; font-weight: 400; background: var(--panel); color: var(--ink);
  transition: border-color .15s, box-shadow .15s;
}
input::placeholder, textarea::placeholder { color: var(--muted); opacity: .75; }
input:hover, select:hover, textarea:hover { border-color: var(--muted); }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand) 22%, transparent); }
input[type="file"] { padding: 7px; background: var(--panel-2); border-style: dashed; cursor: pointer; }
input[type="file"]::file-selector-button {
  font: inherit; font-size: 12.5px; font-weight: 600; margin-right: 10px; padding: 5px 11px; border-radius: 7px;
  border: 1px solid var(--line-2); background: var(--panel); color: var(--ink-2); cursor: pointer;
}
input[readonly] { background: var(--panel-2); }
input:disabled, select:disabled, textarea:disabled, fieldset:disabled input, fieldset:disabled select { background: var(--panel-2); color: var(--muted); }
select {
  appearance: none; -webkit-appearance: none; padding-right: 32px; cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 11px center;
}
.head select, td select { width: auto; display: inline-block; margin: 0; }
textarea { resize: vertical; }
fieldset { border: 0; padding: 0; margin: 0; min-width: 0; }
label.check { display: flex; align-items: center; gap: 9px; color: var(--ink); font-size: 14px; font-weight: 450; cursor: pointer; }
.grid4 label.check, .item-grid label.check, .card > label.check, .form label.check { display: flex; color: var(--ink); font-size: 13.5px; font-weight: 450; }
.grid4 label.check { margin: 22px 0 12px; }
.entity-box > a.small { display: inline-block; margin-bottom: 12px; }
label.check input { width: 17px; height: 17px; margin: 0; accent-color: var(--brand); flex-shrink: 0; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 18px; }
.grid2 > .card { margin-bottom: 18px; }
.span2, .actions { grid-column: 1 / -1; }
.actions { display: flex; gap: 8px; margin-top: 8px; flex-wrap: wrap; }
.grid4 { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 0 16px; }
.span3 { grid-column: span 3; }
.span4 { grid-column: 1 / -1; }
.grid4 .span2 { grid-column: span 2; }
.grid4 > h2, .grid4 > .actions { grid-column: 1 / -1; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.pair { display: grid; grid-template-columns: 1fr 1fr; gap: 0 10px; }

/* ---------- riquadri cliccabili ---------- */
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 14px; margin-bottom: 18px; }
.tiles form { margin: 0; }
.tile {
  display: block; width: 100%; text-align: left; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px 18px; color: var(--ink); cursor: pointer; font: inherit; box-shadow: var(--shadow);
  transition: border-color .15s, box-shadow .15s, transform .15s;
}
.tile:hover { border-color: var(--brand); box-shadow: var(--shadow-lg); transform: translateY(-1px); text-decoration: none; }
.tile.on { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
.tile strong { font-size: 15px; }
.tile span { display: block; color: var(--muted); font-size: 12.5px; margin-top: 2px; }

/* ---------- home ---------- */
.hello { margin-bottom: 22px; }
.hello h1 { margin-bottom: 4px; }
.hello p { color: var(--muted); margin: 0; }
.home-group { margin-bottom: 22px; }
.home-group h2 { font-size: 11px; font-weight: 650; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin-bottom: 10px; }
.tile.app { display: flex; align-items: center; gap: 14px; padding: 16px; }
.tile.app .tico {
  width: 42px; height: 42px; border-radius: 11px; display: grid; place-items: center; flex-shrink: 0;
  background: var(--brand-soft); color: var(--brand); margin: 0;
}
.tile.app .tico .ico { width: 21px; height: 21px; }
.tile.app .txt { flex: 1; min-width: 0; margin: 0; }
.tile.app .txt span { margin-top: 0; }
.tile.app .go { color: var(--muted); width: 16px; height: 16px; opacity: 0; transition: opacity .15s, transform .15s; }
.tile.app:hover .go { opacity: 1; transform: translateX(2px); color: var(--brand); }

/* ---------- tabelle ---------- */
table.list { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 13.5px; }
table.list td, table.list th { padding: 10px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
table.list td.right, table.list th.right { text-align: right; }
table.list th {
  font-size: 11px; font-weight: 650; text-transform: uppercase; letter-spacing: .06em; color: var(--muted);
  background: var(--panel-2); border-bottom: 1px solid var(--line); padding-top: 9px; padding-bottom: 9px;
}
table.list thead th:first-child { border-top-left-radius: 8px; }
table.list thead th:last-child { border-top-right-radius: 8px; }
table.list tbody tr:last-child td { border-bottom: 0; }
table.list tbody tr { transition: background .1s; }
table.list tbody tr:hover td { background: var(--panel-2); }
table.list tfoot td { font-weight: 650; border-top: 1px solid var(--line-2); border-bottom: 0; background: var(--panel-2); }
table.list tfoot td:first-child { border-bottom-left-radius: 8px; }
table.list tfoot td:last-child { border-bottom-right-radius: 8px; }
table.fixed { table-layout: fixed; }
table.fixed td:nth-child(2) { width: 90px; }
table.fixed td:nth-child(3) { width: 120px; }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: color-mix(in srgb, var(--brand) 5%, var(--panel)); }
tr.clickable td a strong { color: var(--ink); }
tr.clickable:hover td a strong { color: var(--brand); }
tr.disabled td, form.disabled { opacity: .55; }
.scroll { max-height: 470px; overflow-y: auto; margin: 0 -6px; padding: 0 6px; scrollbar-width: thin; }

/* ---------- etichette di stato ---------- */
.badge {
  display: inline-block; font-size: 11.5px; font-weight: 600; color: var(--muted); border: 1px solid var(--line-2);
  border-radius: 20px; padding: 1px 9px; line-height: 1.6; vertical-align: 1px;
}
.badge.on { color: var(--ok); border-color: color-mix(in srgb, var(--ok) 45%, transparent); background: var(--ok-soft); }
.pill {
  display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 600; padding: 3px 10px 3px 8px;
  border-radius: 20px; background: var(--warn-soft); color: var(--warn); white-space: nowrap; line-height: 1.4;
}
.pill::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.pill.ok { background: var(--ok-soft); color: var(--ok); }
.pill.err { background: var(--err-soft); color: var(--err); }
.ok { color: var(--ok); } .err { color: var(--err); } .warn { color: var(--warn); }
.toggle {
  position: relative; border: 1px solid var(--line-2); background: var(--panel-2); color: var(--muted); border-radius: 20px;
  padding: 4px 12px 4px 30px; cursor: pointer; font: inherit; font-size: 12.5px; font-weight: 600; transition: all .15s;
}
.toggle::before {
  content: ""; position: absolute; left: 5px; top: 50%; width: 18px; height: 18px; margin-top: -9px; border-radius: 50%;
  background: var(--panel); box-shadow: 0 1px 3px rgba(0,0,0,.25); transition: all .15s;
}
.toggle.on { background: var(--ok); border-color: var(--ok); color: #fff; padding: 4px 30px 4px 12px; }
.toggle.on::before { left: auto; right: 5px; background: #fff; }

/* ---------- avvisi ---------- */
.flash {
  padding: 11px 15px; border-radius: 11px; margin-bottom: 16px;
  background: var(--ok-soft); color: var(--ok); border: 1px solid color-mix(in srgb, var(--ok) 25%, transparent); font-weight: 500;
}
.flash.error { background: var(--err-soft); color: var(--err); border-color: color-mix(in srgb, var(--err) 25%, transparent); }
.flash a, .flash .link { color: inherit; text-decoration: underline; }

/* ---------- linguette, ricerca, mesi ---------- */
.tabs { display: flex; gap: 2px; align-items: center; margin-bottom: 16px; flex-wrap: wrap; }
.tabs > a {
  padding: 6px 13px; border-radius: 8px; color: var(--muted); font-size: 13.5px; font-weight: 550; transition: all .12s;
}
.tabs > a:hover { color: var(--ink); background: var(--panel); text-decoration: none; }
.tabs > a.on { background: var(--panel); color: var(--ink); font-weight: 650; box-shadow: var(--shadow-sm), 0 0 0 1px var(--line); }
.search { margin-left: auto; min-width: 280px; }
.search.wide { margin: 0 0 14px; max-width: 420px; }
.search input {
  margin: 0; padding-left: 34px; border-radius: 10px;
  background: var(--panel) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='15' height='15' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='2' stroke-linecap='round'%3E%3Ccircle cx='11' cy='11' r='7'/%3E%3Cpath d='m20 20-3.5-3.5'/%3E%3C/svg%3E") no-repeat 12px center;
}
.months { display: grid; grid-template-columns: repeat(13, minmax(0, 1fr)); gap: 6px; margin-bottom: 16px; }
.months a {
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 7px 4px 6px; color: var(--muted);
  font-size: 11.5px; text-align: center; transition: all .12s; box-shadow: var(--shadow-sm);
}
.months a:hover { border-color: var(--line-2); text-decoration: none; transform: translateY(-1px); }
.months a span { text-transform: uppercase; letter-spacing: .05em; font-size: 10.5px; font-weight: 600; }
.months a strong, .months a em { display: block; font-style: normal; color: var(--ink); font-size: 12.5px; }
.months a em { color: var(--muted); font-size: 10.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.months a:not(.has):not(:first-child) { opacity: .6; }
.months a.has { border-color: color-mix(in srgb, var(--brand) 22%, var(--line)); }
.months a.on { border-color: var(--brand); background: var(--brand-soft); box-shadow: 0 0 0 1px var(--brand); opacity: 1; }
.months a.on span, .months a.on strong { color: var(--brand-soft-ink); }

/* ---------- modulo fattura ---------- */
.docform { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 18px; align-items: start; }
.sticky { position: sticky; top: 20px; }
table.sum { width: 100%; border-collapse: collapse; font-size: 13.5px; }
table.sum td { padding: 7px 0; border-bottom: 1px dashed var(--line); }
table.sum td.right { text-align: right; }
table.sum tr.strong td { font-weight: 700; border-bottom-style: solid; }
table.sum tr.big td { font-weight: 750; font-size: 20px; color: var(--brand); border-bottom: 0; padding-top: 12px; letter-spacing: -.01em; }
.item {
  display: flex; gap: 10px; border: 1px solid var(--line); border-radius: 12px; padding: 14px 12px 2px 14px; margin-bottom: 12px;
  background: var(--panel-2); transition: border-color .15s;
}
.item:focus-within { border-color: color-mix(in srgb, var(--brand) 45%, var(--line)); }
.item-grid { flex: 1; display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 0 12px; }
.item-grid .span3 { grid-column: span 5; }
.item-grid .span4 { grid-column: 1 / -1; }
.item-grid .span2 { grid-column: span 3; }
.item-grid label { display: block; font-size: 12px; font-weight: 550; color: var(--ink-2); margin-bottom: 10px; }
.item-tools { display: flex; flex-direction: column; gap: 2px; }
.item-tools button { width: 28px; height: 28px; border-radius: 7px; display: grid; place-items: center; }
.item-tools button:hover { background: var(--panel); }
.line-total { background: transparent !important; border-color: transparent !important; font-weight: 700; text-align: right; box-shadow: none !important; }
.entity-box, .prod-box { position: relative; }
.dropdown {
  display: none; position: absolute; z-index: 20; left: 0; right: 0; top: calc(100% + 4px); background: var(--panel);
  border: 1px solid var(--line-2); border-radius: 11px; box-shadow: var(--shadow-lg); max-height: 300px; overflow-y: auto; padding: 4px;
}
.dropdown .opt { padding: 8px 10px; cursor: pointer; color: var(--ink); font-size: 13.5px; border-radius: 7px; font-weight: 400; }
.dropdown .opt:hover { background: var(--brand-soft); }
.chosen { margin: 2px 0 8px; }
.chosen:not(:empty) { padding: 9px 12px; border-radius: 10px; background: var(--brand-soft); color: var(--brand-soft-ink); }
details.card > summary { cursor: pointer; list-style: none; display: flex; align-items: center; gap: 8px; }
details.card > summary::-webkit-details-marker { display: none; }
details.card > summary h2 { display: inline; margin: 0; }
details.card > summary::before {
  content: ""; width: 7px; height: 7px; border-right: 2px solid var(--muted); border-bottom: 2px solid var(--muted);
  transform: rotate(-45deg); transition: transform .15s; margin-right: 4px; flex-shrink: 0;
}
details.card[open] > summary::before { transform: rotate(45deg); }
details.card[open] > summary { margin-bottom: 16px; }
details > summary { cursor: pointer; }
.pay-row { display: grid; grid-template-columns: 1.2fr 1fr auto 1.2fr 1.4fr auto; gap: 10px; align-items: end; padding: 10px 0; border-bottom: 1px dashed var(--line); }
.pay-row label { margin-bottom: 4px; font-size: 12px; font-weight: 550; color: var(--ink-2); }

/* ---------- dettaglio documento ---------- */
.toolbar {
  display: flex; gap: 8px; margin-bottom: 18px; flex-wrap: wrap; padding: 10px; background: var(--panel);
  border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow);
}
.toolbar form.inline:last-child { margin-left: auto; }
.docview { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 18px; align-items: start; }
.docview aside .card { padding: 16px 18px; }
.docview aside .card h2 { font-size: 11.5px; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); }
.pay { border-bottom: 1px solid var(--line); padding: 12px 0; }
.pay:last-child { border-bottom: 0; padding-bottom: 0; }
.pay.paid { opacity: .85; }
.pay.late > div:first-child strong { color: var(--err); }
.pay-form { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-top: 8px; }
.pay-form input, .pay-form select { margin: 0; font-size: 13px; padding: 6px 9px; }
.pay-form select { padding-right: 28px; }
.pay-form button { grid-column: 1 / -1; }

/* ---------- foglio fattura (resta "carta" anche col tema scuro) ---------- */
.paper {
  background: #fff; color: #111; border: 1px solid var(--line); border-radius: 12px; padding: 40px 44px;
  box-shadow: var(--shadow-lg); max-width: 840px; margin: 0 auto; font-size: 13px; color-scheme: light;
}
.paper a { color: #1f4f9a; }
.paper-head { display: flex; justify-content: space-between; gap: 20px; margin-bottom: 28px; }
.paper .title { text-align: right; }
.doc-title { font-size: 22px; font-weight: 750; letter-spacing: .06em; color: #312e81; }
.paper-to { margin-left: 50%; margin-bottom: 22px; }
.paper-subject { font-weight: 600; }
.paper-items { width: 100%; border-collapse: collapse; margin-bottom: 18px; }
.paper-items th { background: #f3f4f8; font-size: 10.5px; text-transform: uppercase; letter-spacing: .05em; color: #555; padding: 7px 6px; text-align: left; }
.paper-items th.right, .paper-items td.right { text-align: right; }
.paper-items td { padding: 8px 6px; border-bottom: 1px solid #e6e9ee; vertical-align: top; }
.paper-items .desc { color: #555; white-space: pre-line; }
.paper-bottom { display: grid; grid-template-columns: 1fr 260px; gap: 20px; }
.vat-box table { width: 100%; border-collapse: collapse; font-size: 12px; }
.vat-box th { text-align: left; font-size: 11px; color: #555; border-bottom: 1px solid #ccc; }
.vat-box th.right, .vat-box td.right { text-align: right; }
.paper .totals { width: 100%; border-collapse: collapse; }
.paper .totals td { padding: 4px 0; }
.paper .totals td.right { text-align: right; }
.paper .totals tr.strong td { font-weight: 700; border-top: 1px solid #ccc; }
.paper .totals tr.big td { font-weight: 750; font-size: 16px; color: #312e81; }
.paper-notes { margin-top: 16px; white-space: pre-line; }
.paper .muted { color: #666; }

/* ---------- grafici (Situazione) ---------- */
.chart { width: 100%; height: auto; max-height: 280px; display: block; }
.chart .grid { stroke: var(--line); stroke-width: 1; stroke-dasharray: 3 4; }
.chart .axis0 { stroke: var(--line-2); stroke-width: 1.2; }
.chart .tick { fill: var(--muted); font-size: 11px; }
.chart .bar { stroke: var(--panel); stroke-width: 1; transition: opacity .12s; }
.chart:hover .bar { opacity: .55; }
.chart .bar:hover { opacity: 1; }
.s1 { fill: var(--series-1); background: var(--series-1); }
.s2 { fill: var(--series-2); background: var(--series-2); }
.legend { display: flex; gap: 18px; font-size: 12.5px; font-weight: 550; color: var(--ink-2); margin-bottom: 10px; }
.legend .sw { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 7px; vertical-align: -1px; }
.kpis { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 14px; margin-bottom: 18px; }
.kpi {
  position: relative; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px 18px; box-shadow: var(--shadow); overflow: hidden;
}
.kpi::after { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 3px; background: var(--brand); opacity: .8; }
.kpi:nth-child(2)::after, .kpi:nth-child(6)::after { background: var(--series-2); }
.kpi:nth-child(3)::after { background: var(--ok); }
.kpi span { display: block; color: var(--muted); font-size: 11.5px; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; }
.kpi strong { display: block; font-size: 24px; font-weight: 750; letter-spacing: -.02em; margin-top: 6px; white-space: nowrap; }
.kpi em { display: block; font-style: normal; font-size: 12px; color: var(--muted); margin-top: 2px; }

/* ---------- spese: categorie a sinistra ---------- */
.grid-side { display: grid; grid-template-columns: 230px minmax(0, 1fr); gap: 18px; align-items: start; }
.grid-side > aside h3 { margin-top: 0; }
.grid-side > aside div { margin: 2px -8px; border-radius: 7px; }
.grid-side > aside div a { display: block; padding: 6px 8px 0; color: var(--ink-2); }
.grid-side > aside div > span.muted { display: block; padding: 0 8px 6px; font-size: 12px; }
.grid-side > aside div br { display: none; }
.grid-side > aside div:hover { background: var(--panel-2); }
.grid-side a.strong { font-weight: 700; color: var(--brand); }

/* ---------- accesso ---------- */
.login {
  min-height: 100vh; display: grid; place-items: center; padding: 16px;
  background:
    radial-gradient(1000px 600px at 10% -10%, color-mix(in srgb, var(--brand) 16%, transparent), transparent 60%),
    radial-gradient(800px 500px at 110% 110%, color-mix(in srgb, var(--series-2) 12%, transparent), transparent 60%),
    var(--bg);
}
.login .card { width: 100%; max-width: 380px; padding: 32px 30px; box-shadow: var(--shadow-lg); border-radius: 18px; }
.login .logo { width: 44px; height: 44px; font-size: 21px; border-radius: 13px; margin-bottom: 18px; }
.login h1 { margin-bottom: 4px; }
.login .sub { color: var(--muted); margin-bottom: 22px; }
.login .btn { width: 100%; margin-top: 8px; padding: 11px; font-size: 15px; }

/* ---------- schermi stretti ---------- */
@media (max-width: 1100px) {
  .docform, .docview { grid-template-columns: minmax(0, 1fr); }
  .months { grid-template-columns: repeat(7, minmax(0, 1fr)); }
  .grid4, .item-grid, .pay-row { grid-template-columns: 1fr 1fr; }
  .item-grid .span3, .item-grid .span2, .grid4 .span2 { grid-column: 1 / -1; }
  .paper-bottom { grid-template-columns: 1fr; }
  .paper-to { margin-left: 0; }
}
@media (max-width: 860px) {
  .side { position: fixed; left: 0; top: 0; z-index: 50; transform: translateX(-105%); transition: transform .2s ease; box-shadow: var(--shadow-lg); }
  .side.open { transform: none; }
  .scrim.open { display: block; position: fixed; inset: 0; z-index: 40; background: rgba(15,23,42,.45); }
  .mobilebar { display: flex; align-items: center; gap: 10px; margin: -6px 0 16px; }
  .main { padding: 20px 16px 40px; }
  .grid2, .grid-side { grid-template-columns: 1fr; }
  .search { min-width: 0; width: 100%; margin: 8px 0 0; }
  .card { padding: 16px; }
  .card:has(> table.list) { overflow-x: auto; }
  .paper { padding: 22px 18px; }
  .months { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}
@media print {
  .side, .mobilebar, .toolbar, .docview aside { display: none !important; }
  .main { padding: 0; }
  .paper { box-shadow: none; border: 0; }
}
.tile > strong:first-child { display: block; font-size: 20px; font-weight: 750; letter-spacing: -.02em; }
@media (max-width: 860px) {
  .kpis { grid-template-columns: 1fr 1fr; gap: 10px; }
  .kpi { padding: 13px 14px; }
  .kpi strong { font-size: 18px; }
  h1 { font-size: 21px; }
}
@media (max-width: 860px) {
  .months { display: flex; overflow-x: auto; scroll-snap-type: x mandatory; padding-bottom: 4px; scrollbar-width: none; }
  .months a { flex: 0 0 82px; scroll-snap-align: start; }
}

/* documenti del trimestre */
.docs td{vertical-align:top}
.docs input[type=file]{max-width:260px;font-size:13px}
.docs td:last-child{text-align:center}
