/* Sheet ordini «ludem». Aspetto e interazione dal prototipo approvato (prototipo/sheet-ordini.html).
   Font self-hosted (SIL OFL 1.1, licenze in fonts/): Geist, Geist Mono, Bricolage Grotesque. */
@font-face { font-family: "Geist"; font-style: normal; font-weight: 100 900; font-display: swap; src: url("fonts/geist-latin.woff2") format("woff2"); }
@font-face { font-family: "Geist Mono"; font-style: normal; font-weight: 100 900; font-display: swap; src: url("fonts/geist-mono-latin.woff2") format("woff2"); }
@font-face { font-family: "Bricolage Grotesque"; font-style: normal; font-weight: 200 800; font-display: swap; src: url("fonts/bricolage-grotesque-latin.woff2") format("woff2"); }

/* Layout: una schermata da lavoro. Barra in alto, riepilogo che fa anche da filtro, barra della cella, griglia che riempie il resto. Sotto i 760px la griglia diventa una lista di schede. */
:root {
  --paper: #f3f5f9;
  --sheet: #ffffff;
  --head: #e6ecf5;
  --ink: #162033;
  --muted: #5b667a;
  --line: #e2e7ef;
  --line-2: #cbd4e1;
  --accent: #2443c9;
  --accent-ink: #ffffff;
  --accent-soft: #e7ecff;
  --ok: #157a3c;
  --ok-soft: #e1f3e7;
  --warn: #9a530a;
  --warn-soft: #fcefd9;
  --bad: #bf2530;
  --bad-soft: #fbe4e5;
  --shadow: 0 1px 2px rgba(22, 32, 51, .06), 0 10px 30px rgba(22, 32, 51, .10);
  --toast-bg: #162033;
  --toast-fg: #f3f5f9;
  --toast-act: #a9bbff;
  --scrim: rgba(12, 18, 32, .38);
  --f-display: "Bricolage Grotesque", "Geist", system-ui, sans-serif;
  --f-ui: "Geist", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --f-mono: "Geist Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #0d121d; --sheet: #131a28; --head: #1a2234; --ink: #e5e9f2; --muted: #96a1b6;
    --line: #222b3c; --line-2: #313b51; --accent: #8ea4ff; --accent-ink: #0d121d; --accent-soft: #1d2849;
    --ok: #5fd38d; --ok-soft: #123222; --warn: #f2b45a; --warn-soft: #36280f; --bad: #ff7d86; --bad-soft: #3b181d;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 12px 32px rgba(0, 0, 0, .5);
    --toast-bg: #e5e9f2; --toast-fg: #0d121d; --toast-act: #2443c9; --scrim: rgba(0, 0, 0, .55);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --paper: #0d121d; --sheet: #131a28; --head: #1a2234; --ink: #e5e9f2; --muted: #96a1b6;
  --line: #222b3c; --line-2: #313b51; --accent: #8ea4ff; --accent-ink: #0d121d; --accent-soft: #1d2849;
  --ok: #5fd38d; --ok-soft: #123222; --warn: #f2b45a; --warn-soft: #36280f; --bad: #ff7d86; --bad-soft: #3b181d;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 12px 32px rgba(0, 0, 0, .5);
  --toast-bg: #e5e9f2; --toast-fg: #0d121d; --toast-act: #2443c9; --scrim: rgba(0, 0, 0, .55);
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
html { height: 100%; }
body { height: 100%; background: var(--paper); color: var(--ink); font: 14px/1.45 var(--f-ui); -webkit-font-smoothing: antialiased; }
button { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.app {
  height: 100%; max-width: 1680px; margin-inline: auto;
  display: flex; flex-direction: column; gap: 12px;
  padding-block: 14px;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
}

/* Barra in alto */
.bar { display: flex; align-items: center; flex-wrap: wrap; gap: 12px 18px; }
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.mark { width: 28px; height: 28px; flex: none; border-radius: 7px; background: var(--accent); color: var(--accent-ink); display: grid; place-items: center; }
.brand h1 { margin: 0; font: 700 23px/1 var(--f-display); letter-spacing: -.015em; }
.tabs { display: inline-flex; gap: 2px; padding: 3px; border-radius: 9px; background: var(--head); }
.tab { appearance: none; border: 0; background: transparent; color: var(--muted); font: 500 13.5px/1 var(--f-ui); padding: 7px 12px; border-radius: 7px; display: inline-flex; align-items: center; gap: 8px; cursor: pointer; }
.tab:hover { color: var(--ink); }
.tab[aria-selected="true"], .tab[aria-pressed="true"] { background: var(--sheet); color: var(--ink); box-shadow: 0 1px 2px rgba(0, 0, 0, .1); }
.vista { display: none; }
.tab .n { font: 500 11.5px/1 var(--f-mono); padding: 3px 6px; border-radius: 5px; background: var(--line); color: var(--muted); font-variant-numeric: tabular-nums; }
.tab[aria-selected="true"] .n { background: var(--accent-soft); color: var(--accent); }
.spacer { flex: 1; }
.live { display: inline-flex; align-items: center; gap: 8px; font-size: 12.5px; color: var(--muted); white-space: nowrap; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); box-shadow: 0 0 0 3px var(--ok-soft); }
.live.ping .dot { animation: ping .9s ease-out 3; }
@keyframes ping { 50% { box-shadow: 0 0 0 7px var(--ok-soft); } }
.search { position: relative; display: flex; align-items: center; }
.search svg { position: absolute; left: 10px; color: var(--muted); pointer-events: none; }
.search input { width: 250px; height: 34px; padding: 0 34px 0 32px; border: 1px solid var(--line-2); border-radius: 8px; background: var(--sheet); color: var(--ink); font: inherit; }
.search input::placeholder { color: var(--muted); }
.search input:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
.search kbd { position: absolute; right: 8px; }
kbd { font: 500 11px/1 var(--f-mono); color: var(--muted); background: var(--sheet); border: 1px solid var(--line-2); border-bottom-width: 2px; border-radius: 4px; padding: 2px 5px; }
.btn { appearance: none; height: 34px; padding: 0 14px; border-radius: 8px; border: 1px solid var(--line-2); background: var(--sheet); color: var(--ink); font: 500 13.5px/1 var(--f-ui); display: inline-flex; align-items: center; justify-content: center; gap: 7px; white-space: nowrap; cursor: pointer; }
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.08); }

/* Riepilogo: ogni riquadro è anche un filtro */
.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; }
.stat { appearance: none; text-align: left; cursor: pointer; border: 1px solid var(--line); background: var(--sheet); border-radius: 10px; padding: 10px 14px; display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 3px 12px; }
.stat:hover { border-color: var(--line-2); }
.stat .lab { display: flex; align-items: center; gap: 7px; font: 500 11.5px/1.2 var(--f-ui); letter-spacing: .05em; text-transform: uppercase; color: var(--muted); }
.stat .lab i { width: 7px; height: 7px; border-radius: 50%; flex: none; background: var(--ink); }
.stat.warn .lab i { background: var(--warn); }
.stat.bad .lab i { background: var(--bad); }
.stat.parz .lab i { background: var(--accent); }
.stat .val { grid-row: 1 / span 2; grid-column: 2; font: 600 26px/1 var(--f-display); font-variant-numeric: tabular-nums; }
.stat .sub { font-size: 12.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stat.warn.has .val { color: var(--warn); }
.stat.bad.has .val { color: var(--bad); }
.stat[aria-pressed="true"] { border-color: var(--accent); background: var(--accent-soft); }

/* Barra della cella, come in ogni foglio */
.fbar { display: flex; align-items: stretch; height: 36px; border: 1px solid var(--line-2); border-radius: 9px; background: var(--sheet); overflow: hidden; }
.namebox { width: 64px; flex: none; display: grid; place-items: center; font: 600 12.5px/1 var(--f-mono); background: var(--head); border-right: 1px solid var(--line); }
.fxl { flex: none; display: grid; place-items: center; padding: 0 11px; font: italic 500 13px/1 var(--f-mono); color: var(--muted); border-right: 1px solid var(--line); }
#fx { flex: 1; min-width: 0; border: 0; background: transparent; color: var(--ink); font: 13.5px var(--f-ui); padding: 0 12px; }
#fx:focus { outline: none; box-shadow: inset 0 0 0 2px var(--accent); }
#fx[aria-invalid="true"] { box-shadow: inset 0 0 0 2px var(--bad); }
#fx[readonly] { color: var(--muted); }
.fxnote { flex: none; display: flex; align-items: center; gap: 6px; padding: 0 12px; font-size: 12px; color: var(--muted); white-space: nowrap; }

/* Griglia */
.gridwrap { flex: 1; min-height: 0; overflow: auto; background: var(--sheet); border: 1px solid var(--line-2); border-radius: 10px; scroll-padding: 48px 0 0 110px; outline: none; }
.gridwrap:focus-visible { box-shadow: 0 0 0 3px var(--accent-soft); }
table { border-collapse: separate; border-spacing: 0; table-layout: fixed; width: 100%; min-width: 1440px; }
th, td { border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); }
thead th { position: sticky; top: 0; z-index: 5; padding: 0; text-align: left; font-weight: 500; background: var(--head); border-bottom-color: var(--line-2); }
.sortbtn { all: unset; box-sizing: border-box; width: 100%; display: flex; align-items: center; gap: 7px; padding: 7px 10px 8px; cursor: pointer; }
.sortbtn:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.let { font: 500 10.5px/1 var(--f-mono); color: var(--muted); }
.hname { min-width: 0; display: flex; align-items: center; gap: 6px; font: 600 12.5px/1.2 var(--f-ui); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.arrow { margin-left: auto; font-size: 11px; color: var(--accent); }
th.curcol { background: var(--accent-soft); }
th.curcol .let { color: var(--accent); }
td { height: 40px; padding: 0 10px; position: relative; background: var(--sheet); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; cursor: cell; }
td.num { text-align: right; font-variant-numeric: tabular-nums; }
.rn { position: sticky; left: 0; z-index: 3; padding: 0; text-align: center; font: 500 11.5px/1 var(--f-mono); color: var(--muted); background: var(--head) !important; cursor: pointer; }
thead .rn { z-index: 6; cursor: default; }
.rn .ic { display: none; }
tbody tr:hover .rn .n { display: none; }
tbody tr:hover .rn .ic { display: inline-flex; color: var(--accent); }
.c-id { position: sticky; left: 44px; z-index: 3; font: 500 13px var(--f-mono); border-right-color: var(--line-2); }
thead .c-id { z-index: 6; }
tbody tr:hover td { background: color-mix(in srgb, var(--accent) 3%, var(--sheet)); }
tr.cur td { background: color-mix(in srgb, var(--accent) 5%, var(--sheet)); }
tr.cur td.rn { color: var(--accent); background: var(--accent-soft) !important; }
td.ro { color: var(--ink); }
td.c-data, td.c-cliente { color: var(--muted); }
td.sel { box-shadow: inset 0 0 0 2px var(--accent); z-index: 2; }
td.editing { padding: 0; overflow: visible; }
.cell-input { width: 100%; height: 100%; border: 0; outline: none; padding: 0 10px; background: var(--sheet); color: var(--ink); font: inherit; box-shadow: inset 0 0 0 2px var(--accent); }
.cell-input.num { text-align: right; font-variant-numeric: tabular-nums; }
td.invalid .cell-input { box-shadow: inset 0 0 0 2px var(--bad); }
tr.flash td:not(.rn) { animation: flash 2.6s ease-out; }
@keyframes flash { 0%, 45% { background: var(--accent-soft); } }
tr.leaving td, .card.leaving { opacity: .2; transition: opacity .2s; }

.part { appearance: none; border: 0; background: transparent; padding: 2px 4px; margin: 0 -2px; border-radius: 5px; font: inherit; color: inherit; }
.part.tg { cursor: pointer; }
.part.tg:hover { background: var(--accent-soft); color: var(--accent); }
.part.done { text-decoration: line-through; text-decoration-thickness: 1.5px; color: var(--muted); }
.plus { color: var(--muted); padding: 0 5px; }
.nil { color: var(--muted); }
.due { display: inline-flex; align-items: center; gap: 8px; font-variant-numeric: tabular-nums; }
.chip { font: 500 11.5px/1 var(--f-ui); padding: 4px 7px; border-radius: 999px; white-space: nowrap; color: var(--muted); background: var(--line); }
.chip.warn { color: var(--warn); background: var(--warn-soft); }
.chip.bad { color: var(--bad); background: var(--bad-soft); }
.sub { margin-left: 6px; font-size: 11.5px; color: var(--muted); }
.pill { font: 500 12px/1 var(--f-ui); padding: 5px 9px; border-radius: 999px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--muted); background: var(--line); }
.pill.part { color: var(--accent); background: var(--accent-soft); }
.pill.ok { color: var(--ok); background: var(--ok-soft); }
/* Colonna Azioni: sempre visibile a destra, come i comandi del bot */
col.col-act { width: 216px; } /* 204 nel prototipo: con Geist il pulsante ⋯ veniva tagliato */
th.act, td.act { position: sticky; right: 0; z-index: 3; padding: 0 8px; border-right: 0; border-left: 1px solid var(--line-2); cursor: default; }
thead th.act { z-index: 6; padding: 0 10px; font: 600 12.5px/1.2 var(--f-ui); }
.acts { display: flex; align-items: center; gap: 6px; }
.abtn { appearance: none; flex: none; height: 28px; padding: 0 9px; display: inline-flex; align-items: center; justify-content: center; gap: 5px; border: 1px solid var(--line-2); border-radius: 6px; background: var(--sheet); font: 500 12.5px/1 var(--f-ui); white-space: nowrap; cursor: pointer; }
.abtn:hover { border-color: var(--muted); }
.abtn.ok { color: var(--ok); border-color: color-mix(in srgb, var(--ok) 45%, var(--line-2)); }
.abtn.ok:hover { background: var(--ok-soft); border-color: var(--ok); }
.abtn.back:hover { color: var(--accent); background: var(--accent-soft); border-color: var(--accent); }
.abtn.more { width: 28px; padding: 0; }
.abtn[aria-expanded="true"], .btn[aria-expanded="true"] { color: var(--accent); background: var(--accent-soft); border-color: var(--accent); }

/* Menu Allunga / Altro */
.menu { position: fixed; z-index: 25; width: 260px; max-width: calc(100vw - 24px); padding: 6px; background: var(--sheet); border: 1px solid var(--line-2); border-radius: 11px; box-shadow: var(--shadow); }
.menu h4 { margin: 6px 8px 4px; font: 600 11.5px/1.3 var(--f-ui); letter-spacing: .05em; text-transform: uppercase; color: var(--muted); }
.mnote { margin: 0 8px 10px; font-size: 12.5px; color: var(--muted); font-variant-numeric: tabular-nums; }
.mgrid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; padding: 0 2px 4px; }
.mgrid button { appearance: none; height: 36px; border: 1px solid var(--line-2); border-radius: 7px; background: var(--paper); font: 500 13px/1 var(--f-ui); cursor: pointer; }
.mgrid button:hover, .mgrid button:focus-visible { color: var(--accent); background: var(--accent-soft); border-color: var(--accent); }
.mi { appearance: none; width: 100%; display: flex; align-items: center; gap: 10px; padding: 9px 10px; border: 0; border-radius: 7px; background: transparent; text-align: left; font: 500 13.5px/1.3 var(--f-ui); cursor: pointer; }
.mi:hover, .mi:focus-visible { background: var(--head); outline: none; }
.mi svg { flex: none; color: var(--muted); }
.mi .k { margin-left: auto; font: 500 11px var(--f-mono); color: var(--muted); white-space: nowrap; }
.msep { height: 1px; margin: 6px 4px; background: var(--line); }
.tag { font: 500 10.5px/1 var(--f-ui); letter-spacing: .02em; padding: 3px 5px; border-radius: 4px; color: var(--muted); background: var(--line); }
td.emptycell { height: auto; padding: 48px 16px; text-align: center; cursor: default; white-space: normal; background: var(--sheet) !important; }
.emptybox { display: grid; justify-items: center; gap: 12px; color: var(--muted); }
.emptybox strong { color: var(--ink); font: 600 15px var(--f-ui); }

/* Barra di stato */
.status { display: flex; align-items: center; flex-wrap: wrap; gap: 6px 18px; font-size: 12.5px; color: var(--muted); }
.status b { color: var(--ink); font-weight: 600; font-variant-numeric: tabular-nums; }
.saved { display: inline-flex; align-items: center; gap: 6px; transition: color .3s; }
.saved.just { color: var(--ok); }
.keys { margin-left: auto; display: flex; flex-wrap: wrap; gap: 14px; }

/* Schede per il telefono */
.cards { display: none; }
.card { display: grid; gap: 10px; padding: 13px 14px; border: 1px solid var(--line); border-radius: 12px; background: var(--sheet); }
.card header { display: flex; align-items: center; gap: 8px; min-width: 0; }
.cid { font: 600 13px var(--f-mono); }
.ccl { flex: 1; min-width: 0; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cprod { font: 600 16px/1.4 var(--f-ui); }
.cprod .part.tg { padding: 3px 6px; margin: 0; background: var(--head); }
.cmeta { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 14px; margin: 0; }
.cmeta dt { font-size: 11px; letter-spacing: .05em; text-transform: uppercase; color: var(--muted); }
.cmeta dd { margin: 2px 0 0; font-variant-numeric: tabular-nums; }
.cnote { margin: 0; font-size: 13px; color: var(--muted); }
.card footer { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.card footer .pill { flex: 1 1 100%; justify-self: start; width: max-content; max-width: 100%; }
.card footer .btn { flex: 1; height: 40px; }
.card footer .btn.more { flex: none; width: 44px; padding: 0; }
.cardsempty { padding: 40px 16px; text-align: center; color: var(--muted); display: grid; justify-items: center; gap: 12px; }

/* Pannello dettagli */
.scrim { position: fixed; inset: 0; z-index: 20; background: var(--scrim); opacity: 0; transition: opacity .2s; }
.scrim.on { opacity: 1; }
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; z-index: 21; width: min(430px, 100%); overflow: auto;
  background: var(--sheet); border-left: 1px solid var(--line-2); box-shadow: var(--shadow);
  padding: calc(18px + env(safe-area-inset-top, 0px)) calc(20px + env(safe-area-inset-right, 0px)) calc(24px + env(safe-area-inset-bottom, 0px)) 22px;
  opacity: 0; transform: translateX(18px); transition: opacity .2s, transform .2s;
}
.drawer.on { opacity: 1; transform: none; }
.dh { display: flex; align-items: flex-start; gap: 12px; margin-bottom: 18px; }
.dh > div { flex: 1; min-width: 0; }
.eyebrow { margin: 0 0 5px; font: 500 12px/1.2 var(--f-mono); color: var(--muted); }
.dh h2 { margin: 0; font: 700 22px/1.2 var(--f-display); letter-spacing: -.01em; text-wrap: balance; }
.dsub { margin: 9px 0 0; display: flex; flex-wrap: wrap; align-items: center; gap: 8px; font-size: 12.5px; color: var(--muted); }
.iconbtn { flex: none; appearance: none; border: 0; width: 32px; height: 32px; border-radius: 8px; background: var(--head); display: grid; place-items: center; cursor: pointer; }
.iconbtn:hover { background: var(--line-2); }
#dform { display: grid; gap: 15px; }
.field { display: grid; gap: 6px; min-width: 0; margin: 0; padding: 0; border: 0; }
.field > label, .field legend, .lbl { display: flex; align-items: center; gap: 8px; padding: 0; font: 600 12.5px/1.2 var(--f-ui); }
.field legend { margin-bottom: 6px; }
.field input, .field textarea { width: 100%; height: 38px; padding: 0 11px; border: 1px solid var(--line-2); border-radius: 8px; background: var(--paper); color: var(--ink); font: 14px var(--f-ui); }
.field textarea { height: auto; padding: 9px 11px; line-height: 1.45; resize: vertical; }
.field input:focus, .field textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; background: var(--sheet); }
.field input[aria-invalid="true"] { border-color: var(--bad); outline-color: var(--bad); }
.hint { margin: 0; font-size: 12px; color: var(--muted); }
.ferr { margin: 0; font-size: 12px; color: var(--bad); }
.ferr:empty { display: none; }
.row2 { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 12px; }
.affix { position: relative; }
.affix input { padding-right: 28px; text-align: right; font-variant-numeric: tabular-nums; }
.affix span { position: absolute; right: 11px; top: 50%; transform: translateY(-50%); color: var(--muted); pointer-events: none; }
.checks { display: flex; flex-wrap: wrap; gap: 8px; }
.check { display: inline-flex; align-items: center; gap: 8px; padding: 7px 11px; border: 1px solid var(--line-2); border-radius: 8px; font-weight: 500; cursor: pointer; }
.check input { width: 16px; height: 16px; margin: 0; accent-color: var(--accent); }
.check:has(input:checked) span { text-decoration: line-through; color: var(--muted); }
.stepper { display: inline-flex; align-items: center; gap: 10px; }
.stepper button { width: 34px; height: 34px; border-radius: 8px; border: 1px solid var(--line-2); background: var(--sheet); font: 500 18px/1 var(--f-ui); cursor: pointer; }
.stepper button:disabled { opacity: .4; cursor: default; }
.stepper output { min-width: 22px; text-align: center; font: 600 19px/1 var(--f-display); font-variant-numeric: tabular-nums; }
.of { color: var(--muted); }
.dactions { display: flex; flex-wrap: wrap; gap: 8px; padding-top: 4px; }
.dactions .btn { height: 40px; }
.storia { margin-top: 24px; padding-top: 16px; border-top: 1px solid var(--line); }
.storia h3 { margin: 0 0 12px; font: 600 11.5px/1 var(--f-ui); letter-spacing: .07em; text-transform: uppercase; color: var(--muted); }
.storia ol { list-style: none; margin: 0; padding: 0; display: grid; gap: 11px; }
.storia li { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 2px 10px; font-size: 13px; }
.who { grid-row: span 2; align-self: start; font: 600 10.5px/1 var(--f-ui); padding: 4px 6px; border-radius: 4px; color: var(--muted); background: var(--line); }
.who.tu { color: var(--accent); background: var(--accent-soft); }
.storia time { font: 11.5px var(--f-mono); color: var(--muted); }

/* Avvisi */
.toasts { position: fixed; left: 50%; bottom: calc(18px + env(safe-area-inset-bottom, 0px)); transform: translateX(-50%); z-index: 30; width: min(470px, calc(100% - 32px)); display: grid; gap: 8px; pointer-events: none; }
.toast { pointer-events: auto; display: flex; align-items: center; gap: 12px; padding: 11px 14px; border-radius: 10px; background: var(--toast-bg); color: var(--toast-fg); font-size: 13.5px; box-shadow: var(--shadow); animation: tin .18s ease-out; }
.toast.bad::before { content: ""; flex: none; width: 8px; height: 8px; border-radius: 50%; background: #ff6b75; }
.toast button { margin-left: auto; flex: none; appearance: none; border: 0; background: transparent; padding: 4px; color: var(--toast-act); font: 600 13.5px var(--f-ui); cursor: pointer; white-space: nowrap; }
@keyframes tin { from { opacity: 0; transform: translateY(6px); } }

@media (max-width: 1100px) {
  .stat .sub { display: none; }
  .stat .val { grid-row: 1; }
}
@media (max-width: 760px) {
  html, body, .app { height: auto; }
  .keys, .live .txt, .fxnote { display: none; }
  .vista { display: inline-flex; order: 4; }
  .gridwrap { flex: none; height: 68vh; min-height: 340px; }
  body.v-schede .gridwrap, body.v-schede .fbar { display: none; }
  body.v-schede .cards { display: grid; gap: 10px; }
  tbody .rn { position: static; }
  thead .rn { left: auto; }
  .c-id { left: 0; }
  col.col-act { width: 114px; }
  td.act { padding: 0 6px; }
  .acts { gap: 4px; }
  .abtn { width: 30px; height: 32px; padding: 0; }
  .abtn .lbl { display: none; }
  .brand { flex: 1 1 calc(100% - 96px); min-width: 0; }
  #export .lbl, #who .lbl { display: none; }
  #export, #who { width: 36px; padding: 0; }
  .brand { flex-basis: calc(100% - 144px); }
  .bar .spacer { display: none; }
  .tabs { order: 4; }
  .search { order: 5; flex: 1 1 100%; }
  .search input { width: 100%; height: 40px; }
  .search kbd { display: none; }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .stat .sub { display: block; }
  .stat .val { grid-row: 1 / span 2; }
  .drawer { top: auto; left: 0; width: 100%; max-height: 90%; border-left: 0; border-top: 1px solid var(--line-2); border-radius: 16px 16px 0 0; transform: translateY(24px); padding-left: calc(20px + env(safe-area-inset-left, 0px)); }
  .row2 { grid-template-columns: 1fr; }
}

/* Accesso: una colonna stretta al centro, il metodo principale (passkey) in alto e grande, le altre vie sotto «oppure». */
.app[hidden], .auth[hidden] { display: none; }
.auth {
  min-height: 100%; display: flex; justify-content: center; align-items: flex-start;
  padding-top: max(40px, 9vh); padding-bottom: calc(32px + env(safe-area-inset-bottom, 0px));
  padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px));
}
.abox { width: min(400px, 100%); }
.ahead { text-align: center; margin-bottom: 26px; }
.amark { width: 58px; height: 58px; margin: 0 auto 14px; border-radius: 15px; background: var(--accent); color: var(--accent-ink); display: grid; place-items: center; box-shadow: var(--shadow); }
.ahead h1 { margin: 0; font: 700 30px/1.05 var(--f-display); letter-spacing: -.02em; }
.ahead p { margin: 7px 0 0; color: var(--muted); font-size: 14px; }
.abtn-l { width: 100%; height: 50px; border-radius: 12px; font: 600 15.5px/1 var(--f-ui); gap: 10px; }
.abtn-l.ink { background: var(--ink); border-color: var(--ink); color: var(--paper); }
.abtn-l.ink:hover { filter: brightness(1.15); }
.abtn-l:disabled { cursor: progress; opacity: .8; }
.ahelp { margin: 9px 0 0; text-align: center; font-size: 13px; color: var(--muted); }
.aor { display: flex; align-items: center; gap: 14px; margin: 24px 0 20px; font: 600 11.5px/1 var(--f-ui); letter-spacing: .09em; text-transform: uppercase; color: var(--muted); }
.aor::before, .aor::after { content: ""; flex: 1; height: 1px; background: var(--line-2); }
.auth .field input { height: 50px; border-radius: 12px; padding: 0 14px; font-size: 16px; }
.aerr { margin: 2px 0 0; font-size: 13px; color: var(--bad); }
.aerr:empty { display: none; }
.astack { display: grid; gap: 10px; margin-top: 12px; }
.anote { margin: 14px 0 0; font-size: 13px; line-height: 1.5; color: var(--muted); }
.anote b { color: var(--ink); font-weight: 600; }
.afoot { margin: 30px 0 0; padding-top: 18px; border-top: 1px solid var(--line); text-align: center; font-size: 13px; color: var(--muted); }
.alink { appearance: none; border: 0; background: none; padding: 0; color: var(--accent); font: 500 13px/1.4 var(--f-ui); cursor: pointer; text-decoration: underline; text-underline-offset: 3px; }
.aback { appearance: none; border: 0; background: none; padding: 6px 0; margin: 0 0 10px; color: var(--accent); font: 500 14px/1 var(--f-ui); cursor: pointer; display: inline-flex; align-items: center; gap: 4px; }
.auth h2 { margin: 0 0 6px; font: 700 21px/1.2 var(--f-display); letter-spacing: -.01em; }
.auth h2:focus { outline: none; }
.alead { margin: 0 0 18px; color: var(--muted); font-size: 14px; line-height: 1.5; }
.alead b { color: var(--ink); font-weight: 600; }
.acode { text-align: center; font: 600 26px/1 var(--f-mono) !important; letter-spacing: .28em; font-variant-numeric: tabular-nums; }
.acode::placeholder { color: var(--line-2); letter-spacing: .28em; }
.ameta { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-top: 12px; font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }
.anum { padding: 18px 16px 20px; border-radius: 14px; background: var(--head); text-align: center; }
.anum span { display: block; font-size: 13px; color: var(--muted); }
.anum strong { display: block; margin-top: 6px; font: 700 64px/1 var(--f-display); letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.atimer { margin: 12px 0 0; text-align: center; font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }
.dev b small { font-weight: 400; }
#who .av { width: auto; min-width: 22px; padding: 0 5px; border-radius: 11px; }
.abox-note { display: flex; gap: 11px; padding: 12px 14px; border-radius: 12px; font-size: 13.5px; line-height: 1.45; margin: 0 0 16px; }
.abox-note svg { flex: none; margin-top: 2px; }
.abox-note.warn { background: var(--warn-soft); color: var(--warn); }
.abox-note.warn b { color: var(--ink); }
.abox-note.ok { background: var(--ok-soft); color: var(--ok); }
.abox-note.bad { background: var(--bad-soft); color: var(--bad); }
.achips { display: flex; flex-wrap: wrap; gap: 6px; margin: 0 0 18px; }
.achips span { font-size: 12.5px; padding: 5px 9px; border-radius: 999px; background: var(--head); color: var(--muted); }
.spin { width: 16px; height: 16px; border-radius: 50%; border: 2px solid currentColor; border-right-color: transparent; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.adim { opacity: .45; pointer-events: none; }
/* Chi è entrato, in alto a destra */
#who .av { width: 22px; height: 22px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; font: 700 11.5px/1 var(--f-ui); }
#who { padding-left: 6px; }
.dev { display: flex; align-items: center; gap: 10px; padding: 7px 10px; font-size: 13px; }
.dev div { min-width: 0; flex: 1; }
.dev b { display: block; font-weight: 500; }
.dev small { color: var(--muted); font-size: 12px; }
.dev .here { font-size: 11.5px; color: var(--ok); font-weight: 600; }
.dev button { appearance: none; border: 1px solid var(--line-2); background: var(--paper); border-radius: 7px; padding: 5px 9px; font: 500 12.5px/1 var(--f-ui); cursor: pointer; }
.dev button:hover { border-color: var(--bad); color: var(--bad); }
.mi.danger { color: var(--bad); }
.mi.danger svg { color: var(--bad); }
.mi .on { margin-left: auto; font: 600 11.5px/1 var(--f-ui); padding: 4px 7px; border-radius: 999px; background: var(--ok-soft); color: var(--ok); }
.mi .on.off { background: var(--head); color: var(--muted); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* ---- Aggiunte per la versione vera (nessuno stile inline: la CSP lo vieta) ---- */
[hidden] { display: none !important; }
body { margin: 0; }
/* Larghezze delle colonne della griglia (prima erano attributi style) */
col.col-rn { width: 44px; }
col.col-id { width: 64px; }
col.col-data { width: 156px; }
col.col-cliente { width: 128px; }
col.col-prodotto { width: 250px; }
col.col-prezzo { width: 110px; }
col.col-metodo { width: 156px; }
col.col-deadline { width: 204px; }
col.col-qta { width: 108px; }
col.col-stato { width: 196px; }
/* Nel prototipo la colonna Note restava larga 0 (le altre superano già la larghezza minima): qui ha una larghezza sua. */
col.col-note { width: 240px; }
@media (max-width: 760px) { col.col-act { width: 114px; } }
.mt8 { margin-top: 8px; }
.mt4 { margin-top: 4px; }
.mb14 { margin-bottom: 14px; }
/* Separatori fra le parti del prodotto: il testo arriva dal server così com'è (" + ", ", "…) */
.plus { padding: 0 1px; white-space: pre; }
/* Diretta caduta: pallino grigio */
.live.off .dot { background: var(--muted); box-shadow: 0 0 0 3px var(--line); }
.live.off { color: var(--muted); }
/* Errore del server sotto la barra della cella */
.fxerr { margin: -6px 0 0; padding: 0 2px; font-size: 12.5px; line-height: 1.4; color: var(--bad); }
.fxerr:empty { display: none; }
@media (max-width: 760px) { body.v-schede .fxerr { display: none; } }
/* Avvio: niente da mostrare finché il server non dice se sei dentro */
.boot { min-height: 100%; display: grid; place-items: center; color: var(--muted); }
/* Storico: chi ha fatto la modifica (nome della persona web, «Tu» o «Bot») */
.who { max-width: 110px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.storia .vuota { color: var(--muted); font-size: 13px; }
/* Cliente col link a Telegram nel pannello e nelle schede */
.eyebrow a, .ccl a { color: inherit; text-decoration: underline; text-decoration-color: var(--line-2); text-underline-offset: 3px; }
.eyebrow a:hover, .ccl a:hover { color: var(--accent); text-decoration-color: currentColor; }
/* Il mio accesso: lista lunga, scorre dentro il menu */
#account { width: 290px; overflow: auto; overscroll-behavior: contain; }
#account .dev button:disabled { opacity: .5; cursor: progress; }
.dev .role { font-weight: 400; color: var(--muted); }
.mnote.load { display: flex; align-items: center; gap: 8px; margin-top: 4px; }
.mnote.load .spin { width: 13px; height: 13px; }
/* Pulsante in attesa della risposta del server */
.btn:disabled, .abtn:disabled { cursor: progress; opacity: .7; }
.drawer .btn:disabled { cursor: progress; }
.aurl { display: block; width: 100%; margin: 0 0 10px; padding: 10px 12px; border: 1px solid var(--line-2); border-radius: 10px; background: var(--paper); color: var(--ink); font: 500 13px/1.3 var(--f-mono); }
