/* ============ Base (mobile first) ============ */
:root {
  --bg: #f3f4f6;
  --card: #ffffff;
  --text: #1d2330;
  --muted: #6b7280;
  --line: #e3e6eb;
  --accent: #1f6feb;
  --accent-soft: #e8f0fe;
  --warn: #b45309;
  --warn-soft: #fff4dc;
  --danger: #c0392b;
  --radius: 12px;
  --bar-h: 64px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 15px;
  color: var(--text);
  -webkit-text-size-adjust: 100%;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; background: var(--bg); padding-bottom: calc(var(--bar-h) + env(safe-area-inset-bottom) + 12px); }
h1, h2, h3 { margin: 0; }
h2, h3 { font-size: 15px; margin-bottom: 10px; }
.muted { color: var(--muted); font-weight: 400; }
.only-desktop { display: none !important; }
button { -webkit-tap-highlight-color: transparent; }

/* Pulsanti */
.btn {
  font: inherit; font-size: 15px; cursor: pointer; border-radius: 10px; padding: 10px 14px; min-height: 44px;
  border: 1px solid var(--line); background: var(--card); color: var(--text); white-space: nowrap;
}
.btn:hover { border-color: #c5cad3; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.btn.full { width: 100%; margin-top: 10px; }

/* Campi: 16px evita lo zoom automatico su iPhone */
.in {
  font: inherit; font-size: 16px; color: inherit; width: 100%; min-height: 42px;
  padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: #fff;
}
.in:focus { outline: 3px solid var(--accent-soft); border-color: var(--accent); }
.in[readonly] { background: transparent; border-color: transparent; color: var(--muted); padding-left: 0; padding-right: 0; }
.in.num { text-align: right; font-variant-numeric: tabular-nums; }
.in.small { width: 76px; }
select.in { padding-right: 4px; }
textarea.in { resize: vertical; }
input[type="number"]::-webkit-inner-spin-button { opacity: 0; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.neg { color: var(--danger) !important; }
.empty { color: var(--muted); text-align: center; padding: 16px; margin: 0; }
.hint { color: var(--muted); font-size: 12px; margin: 10px 0 0; }

/* Barra in alto */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 8px 12px; padding-top: max(8px, env(safe-area-inset-top));
  background: var(--card); border-bottom: 1px solid var(--line);
}
.topbar h1 { font-size: 18px; }
#btn-menu { font-size: 20px; padding: 6px 14px; }
.actions {
  display: none; position: absolute; top: 100%; right: 8px; z-index: 30; flex-direction: column; gap: 6px;
  min-width: 200px; padding: 8px; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: 0 12px 30px rgba(0, 0, 0, .15);
}
.actions .btn { text-align: left; border-color: transparent; }
body.menu-open .actions { display: flex; }

.layout { display: flex; flex-direction: column; gap: 12px; padding: 12px; }
.quote { display: flex; flex-direction: column; gap: 12px; min-width: 0; }

/* Catalogo: foglio dal basso su telefono */
.catalog {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 40; height: 85vh; height: 85dvh;
  display: flex; flex-direction: column; border-radius: 18px 18px 0 0; border: 0;
  padding: 12px 14px calc(12px + env(safe-area-inset-bottom));
  transform: translateY(105%); transition: transform .25s ease; box-shadow: 0 -10px 40px rgba(0, 0, 0, .2);
}
body.sheet-open .catalog { transform: none; }
.backdrop { position: fixed; inset: 0; z-index: 35; background: rgba(15, 20, 30, .45); opacity: 0; pointer-events: none; transition: opacity .25s; }
body.sheet-open .backdrop { opacity: 1; pointer-events: auto; }
body.sheet-open, body.previewing { overflow: hidden; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.sheet-head h2 { margin: 0; font-size: 17px; }
.sheet-head .btn { min-height: 38px; padding: 6px 16px; }

.chips { display: flex; gap: 6px; margin: 10px -14px; padding: 0 14px 2px; overflow-x: auto; scrollbar-width: none; flex-shrink: 0; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  font: inherit; font-size: 13px; cursor: pointer; padding: 7px 12px; border-radius: 999px; white-space: nowrap;
  border: 1px solid color-mix(in srgb, var(--cat) 35%, white); background: #fff; color: var(--cat);
}
.chip.active { background: var(--cat); border-color: var(--cat); color: #fff; }
.cat-list { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; -webkit-overflow-scrolling: touch; }
.cat-list button {
  width: 100%; text-align: left; font: inherit; cursor: pointer; display: flex; align-items: center; gap: 10px;
  padding: 10px 8px; border: 0; border-bottom: 1px solid var(--line); background: none; color: inherit; min-height: 54px;
}
.cat-list button:active, .cat-list button:hover { background: color-mix(in srgb, var(--cat) 8%, white); }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--cat); flex-shrink: 0; }
.cat-text { display: flex; flex-direction: column; flex: 1; min-width: 0; }
.cat-name { font-weight: 500; }
.cat-sub { font-size: 12px; color: var(--muted); }
.cat-price { font-size: 13px; font-weight: 600; white-space: nowrap; }

/* Testata */
.meta-card summary {
  cursor: pointer; font-weight: 600; display: flex; gap: 8px; align-items: baseline; justify-content: space-between;
  list-style: none; min-height: 24px;
}
.meta-card summary::-webkit-details-marker { display: none; }
.meta-card summary::after { content: "▾"; color: var(--muted); }
.meta-card[open] summary::after { content: "▴"; }
.meta-card summary .muted { font-size: 13px; flex: 1; text-align: right; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.meta { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 12px; }
.meta label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
.meta .wide, .meta .full { grid-column: 1 / -1; }

/* Righe raggruppate per tipologia */
.rows-card { padding: 8px; }
.group { margin-bottom: 14px; }
.group:last-child { margin-bottom: 0; }
.group-head {
  display: flex; align-items: center; gap: 8px; padding: 8px 6px;
  border-bottom: 2px solid var(--cat); margin-bottom: 8px;
}
.tag {
  display: inline-block; font-size: 12px; font-weight: 600; padding: 3px 10px; border-radius: 999px; white-space: nowrap;
  background: color-mix(in srgb, var(--cat) 14%, white); color: color-mix(in srgb, var(--cat) 80%, black);
}
.g-count { font-size: 12px; color: var(--muted); }
.g-total { margin-left: auto; font-weight: 700; font-variant-numeric: tabular-nums; }

.row {
  display: grid; gap: 8px 10px; align-items: end;
  grid-template-columns: 1fr 1fr 1fr;
  grid-template-areas:
    "name name name"
    "desc desc desc"
    "qty  qty  eff"
    "pack pack eff"
    "cost price price"
    "total total total";
  padding: 12px; margin-bottom: 8px; border: 1px solid var(--line); border-left: 4px solid var(--cat);
  border-radius: 10px; background: color-mix(in srgb, var(--cat) 3%, white);
}
.row > div { min-width: 0; }
.c-name { grid-area: name; display: flex; flex-direction: column; gap: 6px; }
.c-name .name { font-weight: 600; }
.c-desc { grid-area: desc; }
.c-desc .in { font-size: 14px; color: var(--muted); min-height: 36px; }
.c-qty { grid-area: qty; }
.c-pack { grid-area: pack; font-size: 13px; color: var(--muted); }
.c-eff { grid-area: eff; text-align: right; align-self: center; }
.c-eff strong { font-size: 18px; display: block; }
.c-cost { grid-area: cost; }
.c-price { grid-area: price; }
.c-total {
  grid-area: total; display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap;
  padding-top: 8px; border-top: 1px dashed var(--line);
}
.c-total .m-lbl { margin: 0; }
.c-total strong { font-size: 17px; margin-left: auto; font-variant-numeric: tabular-nums; }
.c-total small { width: 100%; text-align: right; font-size: 12px; color: var(--muted); }
.row { position: relative; }
.c-name { padding-right: 46px; }
.c-act { position: absolute; top: 12px; right: 8px; }
.m-lbl { display: block; font-size: 11px; color: var(--muted); margin-bottom: 3px; text-transform: uppercase; letter-spacing: .03em; }

.stepper { display: flex; align-items: stretch; }
.stepper button {
  font: inherit; font-size: 20px; width: 44px; flex-shrink: 0; cursor: pointer;
  border: 1px solid var(--line); background: #fff; color: var(--text);
}
.stepper button:first-child { border-radius: 8px 0 0 8px; }
.stepper button:last-child { border-radius: 0 8px 8px 0; }
.stepper button:active { background: var(--accent-soft); }
.stepper .in { border-radius: 0; border-left: 0; border-right: 0; text-align: center; min-width: 0; font-weight: 600; }
.pack-in { display: flex; gap: 6px; }
.pack-in .in { min-width: 0; }

.price-wrap { display: flex; gap: 6px; }
.price-wrap .in { min-width: 0; }
.row.modified .price { background: var(--warn-soft); border-color: #f0c36d; color: var(--warn); font-weight: 600; }

.icon {
  font: inherit; font-size: 17px; cursor: pointer; width: 42px; height: 42px; flex-shrink: 0;
  border: 1px solid var(--line); border-radius: 8px; background: #fff; color: var(--text);
}
.icon.reset:not(:disabled) { color: var(--warn); border-color: #f0c36d; background: var(--warn-soft); font-weight: 700; }
.icon:disabled { opacity: .3; cursor: default; }
.icon.danger { color: var(--muted); border-color: transparent; background: transparent; }
.icon.danger:hover { color: #fff; background: var(--danger); }

.row.flash { animation: flash 1.2s ease-out; }
@keyframes flash { from { box-shadow: 0 0 0 3px var(--accent); } to { box-shadow: 0 0 0 3px transparent; } }

/* Riepilogo e totali */
.grid2 { display: flex; flex-direction: column; gap: 12px; }
.sum-group { margin-bottom: 12px; }
.sum-head {
  display: flex; justify-content: space-between; gap: 8px; padding: 6px 0; margin-bottom: 2px;
  border-bottom: 2px solid var(--cat); color: color-mix(in srgb, var(--cat) 80%, black);
  font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .03em;
}
.sum-row { display: flex; justify-content: space-between; gap: 10px; padding: 6px 0; border-bottom: 1px solid var(--line); }
.sum-row strong { white-space: nowrap; font-variant-numeric: tabular-nums; }
.sum-row small { display: block; font-size: 11px; color: var(--muted); }

.totals dl { display: grid; grid-template-columns: 1fr auto; gap: 10px 12px; margin: 0; align-items: center; }
.totals dt { color: var(--muted); }
.totals dt label { display: flex; align-items: center; gap: 8px; }
.totals dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; }
.totals .grand { font-size: 19px; font-weight: 700; color: var(--text); border-top: 1px solid var(--line); padding-top: 10px; }

/* Barra fissa in basso (telefono) */
.mobile-bar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
  background: rgba(255, 255, 255, .96); backdrop-filter: blur(8px); border-top: 1px solid var(--line);
}
.mb-total { flex: 1; display: flex; flex-direction: column; align-items: center; line-height: 1.15; }
.mb-total span { font-size: 11px; color: var(--muted); text-transform: uppercase; }
.mb-total strong { font-size: 17px; font-variant-numeric: tabular-nums; }

.toast {
  position: fixed; left: 50%; bottom: calc(var(--bar-h) + env(safe-area-inset-bottom) + 16px); z-index: 60;
  transform: translate(-50%, 20px); opacity: 0; pointer-events: none; transition: all .2s;
  background: #1d2330; color: #fff; padding: 10px 16px; border-radius: 999px; font-size: 14px; max-width: 90vw;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
body.sheet-open .toast { bottom: calc(85dvh + 12px); }

/* ============ Schede ============ */
.tabs {
  position: sticky; top: 61px; z-index: 15; display: flex; gap: 4px; padding: 6px 12px;
  background: var(--bg); border-bottom: 1px solid var(--line);
}
.tabs button {
  flex: 1; font: inherit; font-size: 15px; font-weight: 600; cursor: pointer; min-height: 40px;
  border: 0; border-radius: 10px; background: transparent; color: var(--muted);
}
.tabs button.active { background: var(--card); color: var(--accent); box-shadow: 0 1px 3px rgba(0, 0, 0, .12); }
body.tab-letter #btn-add-mobile { visibility: hidden; }

/* ============ Editor preventivo cliente ============ */
.letter-view { display: flex; flex-direction: column; gap: 12px; padding: 12px; max-width: 860px; margin: 0 auto; }
.letter-view[hidden] { display: none; }
.form { display: grid; grid-template-columns: 1fr; gap: 10px; }
.form label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); min-width: 0; }
.form .full { grid-column: 1 / -1; }
.form label.check { flex-direction: row; align-items: center; gap: 10px; font-size: 15px; color: var(--text); min-height: 36px; }
.form label.check input { width: 22px; height: 22px; flex-shrink: 0; }
textarea.grow { overflow: hidden; resize: none; line-height: 1.4; }
.hint.top { margin: -4px 0 10px; }
.calc-line { display: flex; justify-content: space-between; gap: 10px; font-size: 13px; color: var(--muted); padding: 4px 0; }
.calc-line strong { color: var(--text); font-size: 15px; }
#l-total-wrap.modified .price { background: var(--warn-soft); border-color: #f0c36d; color: var(--warn); font-weight: 600; }
.vat-only, .note-only { display: none !important; }
.show-vat .vat-only, .show-note .note-only { display: flex !important; }

.block { border: 1px solid var(--line); border-radius: 10px; padding: 10px; margin-bottom: 8px; background: #fff; }
.block.chapter { background: var(--accent-soft); border-color: #c9dafc; }
.block-head { display: flex; align-items: center; gap: 4px 8px; flex-wrap: wrap; }
.block-head .in { flex: 1 1 calc(100% - 40px); }
.block-btns { margin-left: auto; }
.block-num { font-weight: 700; min-width: 26px; color: var(--accent); }
.block.chapter .block-head .in { font-weight: 700; text-transform: uppercase; }
.block.voce .block-head .in { font-weight: 600; font-style: italic; }
.block-head .in { min-width: 0; }
.block-btns { display: flex; gap: 2px; }
.block-btns .icon { width: 34px; height: 38px; border-color: transparent; background: transparent; }
.block textarea { margin-top: 8px; font-size: 15px; }
.btn-row { display: flex; gap: 8px; margin-top: 4px; }
.btn-row .btn { flex: 1; }

/* Selettore tipo di anteprima */
.seg { display: flex; background: var(--bg); border-radius: 10px; padding: 3px; gap: 3px; }
.seg button {
  flex: 1; font: inherit; font-size: 14px; font-weight: 600; cursor: pointer; min-height: 36px; padding: 0 12px;
  border: 0; border-radius: 8px; background: transparent; color: var(--muted); white-space: nowrap;
}
.seg button.active { background: var(--card); color: var(--accent); box-shadow: 0 1px 3px rgba(0, 0, 0, .12); }
.pv-opts[hidden] { display: none; }

/* ============ Documento "Preventivo cliente" ============ */
.doc.letter { font-family: "Times New Roman", Times, Georgia, serif; font-size: 15px; line-height: 1.45; color: #111; }
.l-brand { text-align: center; margin-bottom: 18px; }
.l-name { font-size: 26px; font-weight: 700; letter-spacing: .12em; text-transform: uppercase; color: #1f3fbf; }
.l-tag { font-size: 14px; font-weight: 700; text-transform: uppercase; color: #1f3fbf; letter-spacing: .04em; }
.l-date { margin: 8px 0 14px; }
.l-to { margin: 0 0 28px auto; width: fit-content; max-width: 60%; }
.l-num { margin-bottom: 14px; }
.l-p { margin: 0 0 14px; }
.l-chapter { font-size: 15px; font-weight: 700; text-decoration: underline; margin: 22px 0 10px; }
.l-voce { margin-bottom: 12px; break-inside: avoid-page; }
.l-voce h4 { margin: 10px 0 4px; font-size: 15px; font-style: italic; font-weight: 700; }
.l-list { margin: 0 0 8px; padding-left: 22px; list-style: none; }
.l-list > li { position: relative; margin-bottom: 2px; }
.l-list > li::before { content: "-"; position: absolute; left: -16px; }
.l-sub { padding-left: 34px; margin: 2px 0; list-style: circle; }
.l-total-list { margin-top: 12px; }
.l-note { margin: 18px 0 18px 10px; }
.l-cond { margin: 18px 0; }
.l-closing { margin-top: 26px; }
.l-sign { margin: 30px 0 0 auto; width: fit-content; font-weight: 700; }
.l-foot { margin-top: 40px; padding-top: 10px; border-top: 1px solid #ccc; text-align: center; font-size: 12px; color: #555; }

/* ============ Schermate: accesso, elenco, editor ============ */
body:not(.screen-login) #view-login,
body:not(.screen-list) #view-list { display: none !important; }
body.screen-login > *:not(#view-login):not(#toast) { display: none !important; }
body.screen-list .tabs, body.screen-list #view-items, body.screen-list #view-letter,
body.screen-list .mobile-bar, body.screen-list .editor-only { display: none !important; }
body:not(.mode-cloud) .cloud-only { display: none !important; }
body.screen-list, body.screen-login { padding-bottom: 24px; }

.title-wrap { display: flex; align-items: center; gap: 8px; min-width: 0; flex: 1; }
.title-wrap h1 { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.btn.back { font-size: 24px; line-height: 1; padding: 4px 12px; min-height: 40px; }
.save-status { font-size: 12px; color: var(--muted); white-space: nowrap; flex-shrink: 0; }
.save-status[data-s="saved"] { color: #16a34a; }
.save-status[data-s="error"], .save-status[data-s="offline"] { color: var(--danger); font-weight: 600; }
.danger-text { color: var(--danger) !important; }

.login-view { min-height: 100vh; min-height: 100dvh; display: grid; place-items: center; padding: 20px; }
.login-card { width: 100%; max-width: 360px; display: flex; flex-direction: column; gap: 12px; padding: 24px; }
.login-card label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); }
.login-brand { font-size: 22px; font-weight: 800; letter-spacing: .06em; text-transform: uppercase; color: #1f3fbf; text-align: center; }
.login-card .muted { text-align: center; margin: 0; }
.err { color: var(--danger); margin: 0; min-height: 1em; font-size: 14px; }

.list-view { display: flex; flex-direction: column; gap: 12px; padding: 12px; max-width: 760px; margin: 0 auto; }
.list-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.list-head h2 { margin: 0; font-size: 22px; }
.list-seg { align-self: flex-start; }
#quote-list { display: flex; flex-direction: column; gap: 8px; }
.quote-item {
  display: flex; align-items: center; gap: 12px; padding: 14px; cursor: pointer;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); min-height: 64px;
}
.quote-item:hover, .quote-item:focus-visible { border-color: var(--accent); outline: none; }
.quote-item.in-trash { cursor: default; opacity: .85; }
.qi-main { display: flex; flex-direction: column; gap: 2px; flex: 1; min-width: 0; }
.qi-main strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.qi-main .muted { font-size: 13px; }
.qi-total { font-weight: 700; white-space: nowrap; font-variant-numeric: tabular-nums; }

/* ============ Anteprima ============ */
.modal { position: fixed; inset: 0; z-index: 50; background: rgba(15, 20, 30, .55); overflow-y: auto; }
.modal[hidden] { display: none; }
.modal-box { max-width: 860px; margin: 0 auto; min-height: 100%; background: #fff; }
.modal-bar {
  position: sticky; top: 0; z-index: 2; display: flex; flex-direction: column; gap: 10px;
  padding: 10px 12px; padding-top: max(10px, env(safe-area-inset-top));
  background: var(--card); border-bottom: 1px solid var(--line);
}
.pv-opts { display: flex; flex-wrap: wrap; gap: 6px 16px; font-size: 14px; }
.pv-opts label { display: flex; align-items: center; gap: 6px; min-height: 32px; }
.pv-opts input { width: 20px; height: 20px; }
.pv-btns { display: flex; gap: 8px; }
.pv-btns .btn { flex: 1; }

.doc { background: #fff; padding: 20px 16px; color: #111; font-size: 13px; }
.doc table { border-collapse: collapse; width: 100%; }
.doc-head { display: flex; justify-content: space-between; gap: 16px; padding-bottom: 14px; border-bottom: 2px solid #111; font-size: 11px; line-height: 1.5; }
.doc-company { font-size: 16px; font-weight: 700; }
.doc-title { text-align: right; }
.doc-title .big { font-size: 18px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; }
.doc-client { display: grid; gap: 4px; margin: 16px 0; }
.doc-client span, .doc-notes span { display: inline-block; min-width: 72px; color: #666; font-size: 12px; }
.doc-table th { text-align: left; font-size: 12px; border-bottom: 1px solid #111; padding: 6px 4px; }
.doc-table th.num { text-align: right; }
.doc-table td { padding: 6px 4px; border-bottom: 1px solid #e5e5e5; vertical-align: top; }
.doc-table td small { display: block; font-size: 11px; color: #666; font-weight: 400; }
.doc-table .grp td { background: #f3f4f6; font-weight: 700; font-size: 11px; text-transform: uppercase; letter-spacing: .03em; }
.doc-totals { width: 100%; max-width: 300px; margin: 16px 0 0 auto; }
.doc-totals td { padding: 4px; }
.doc-totals .grand td { font-size: 16px; font-weight: 700; border-top: 2px solid #111; padding-top: 8px; }
.doc-notes { margin-top: 24px; }
.doc-sign { margin-top: 40px; width: 240px; max-width: 100%; margin-left: auto; font-size: 12px; color: #666; }
.doc-sign .line { border-bottom: 1px solid #111; height: 40px; }

/* ============ Desktop ============ */
@media (min-width: 900px) {
  :root { font-size: 14px; --bar-h: 0px; }
  body { padding-bottom: 0; }
  .only-mobile { display: none !important; }
  .only-desktop { display: revert !important; }
  .rows-head.only-desktop { display: grid !important; }
  .in { font-size: 14px; min-height: 34px; padding: 6px 8px; }
  .btn { font-size: 14px; min-height: 36px; padding: 7px 12px; }

  .topbar { padding: 10px 20px; }
  .actions { display: flex; position: static; flex-direction: row; padding: 0; border: 0; box-shadow: none; min-width: 0; }
  .actions .btn { border-color: var(--line); }

  .layout { display: grid; grid-template-columns: 290px 1fr; gap: 16px; padding: 16px 20px; align-items: start; }
  .catalog {
    position: sticky; top: 70px; z-index: auto; height: auto; max-height: calc(100vh - 90px); transform: none;
    border: 1px solid var(--line); border-radius: var(--radius); box-shadow: none; padding: 14px; transition: none;
  }
  .backdrop { display: none; }
  .chips { flex-wrap: wrap; overflow: visible; margin: 10px 0; padding: 0; }
  .chip { padding: 3px 9px; font-size: 12px; }
  .cat-list button { min-height: 0; padding: 7px 8px; border-bottom: 0; border-radius: 6px; }

  .meta { grid-template-columns: repeat(4, 1fr); }
  .meta .wide { grid-column: span 2; }

  /* Righe come tabella */
  .rows-head, .row {
    grid-template-columns: minmax(180px, 2fr) minmax(140px, 2fr) 128px 128px 100px 82px 128px 130px 34px;
    grid-template-areas: "name desc qty pack eff cost price total act";
    gap: 8px; align-items: center;
  }
  .rows-head {
    padding: 4px 10px 8px 14px; font-size: 12px; font-weight: 600; color: var(--muted);
    border-bottom: 1px solid var(--line); margin-bottom: 10px;
  }
  .row { padding: 6px 10px; margin-bottom: 4px; border-radius: 8px; border-color: transparent; border-left-width: 4px; }
  .row:hover { border-color: var(--line); border-left-color: var(--cat); }
  .m-lbl { display: none; }
  .c-name { flex-direction: row; }
  .c-name select { width: 110px; flex-shrink: 0; }
  .c-desc .in { min-height: 34px; }
  .c-eff strong { font-size: 14px; }
  .c-total { display: block; text-align: right; padding: 0; border: 0; }
  .c-total strong { font-size: 14px; display: block; }
  .c-total small { display: block; font-size: 11px; }
  .c-name { padding-right: 0; }
  .c-act { grid-area: act; position: static; align-self: center; }
  .stepper button { width: 30px; font-size: 16px; }
  .icon { width: 32px; height: 34px; font-size: 15px; }
  .rows-card { padding: 14px; }

  .grid2 { display: grid; grid-template-columns: 1fr 340px; gap: 16px; align-items: start; }

  .modal { padding: 24px 12px; }
  .modal-box { min-height: 0; border-radius: var(--radius); overflow: hidden; }
  .modal-bar { flex-direction: row; align-items: center; justify-content: space-between; }
  .pv-btns .btn { flex: none; }
  .doc { padding: 40px 44px; font-size: 14px; }
  .tabs { top: 57px; padding: 8px 20px; gap: 6px; }
  .tabs button { flex: none; padding: 0 18px; min-height: 34px; font-size: 14px; }
  .letter-view { padding: 16px 20px; }
  .list-view { padding: 24px 20px; }
  .save-status { font-size: 13px; }
  .form { grid-template-columns: 1fr 1fr; }
  .block-head { flex-wrap: nowrap; }
  .block-head .in { flex: 1; }
  .modal-bar { flex-wrap: wrap; }
  .block-btns .icon { height: 32px; }
  .doc.letter { padding: 48px 64px; font-size: 16px; }
  .doc-head { font-size: 12px; }
  .doc-company { font-size: 18px; }
  .doc-title .big { font-size: 22px; }
}

/* ============ Stampa / PDF ============ */
@media print {
  @page { margin: 14mm; }
  body { background: #fff; padding: 0; }
  body > *:not(#preview) { display: none !important; }
  .no-print { display: none !important; }
  .modal { position: static; background: none; padding: 0; overflow: visible; }
  .modal-box { max-width: none; min-height: 0; }
  .doc { padding: 0; font-size: 12px; }
  .doc-table tr { break-inside: avoid; }
  .doc.letter { padding: 0; font-size: 12pt; }
}
