/* Preventivi HWC - stile: sobrio, font di sistema, materiali traslucidi, movimento minimo */
:root {
  --bg: #f5f5f7; --surface: #ffffff; --surface-2: #fafafc; --text: #1d1d1f; --muted: #6e6e73;
  --line: rgba(0, 0, 0, .1); --accent: #0a5fd3; --accent-text: #ffffff; --accent-soft: rgba(10, 95, 211, .1);
  --ok: #1f8a4c; --warn: #b26a00; --err: #c8372d; --bar: rgba(245, 245, 247, .72);
  --shadow: 0 1px 2px rgba(0, 0, 0, .04), 0 8px 24px rgba(0, 0, 0, .06);
  --radius: 14px; --ease: cubic-bezier(.2, .8, .2, 1);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #000000; --surface: #1c1c1e; --surface-2: #232326; --text: #f5f5f7; --muted: #a1a1a6;
    --line: rgba(255, 255, 255, .14); --accent: #4d94ff; --accent-text: #000000; --accent-soft: rgba(77, 148, 255, .16);
    --ok: #4cc27a; --warn: #f0a63a; --err: #ff6a5f; --bar: rgba(28, 28, 30, .72);
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 8px 24px rgba(0, 0, 0, .5);
  }
}
* { box-sizing: border-box; }
html { font: 100%/1.5 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased; color-scheme: light dark; }
body { margin: 0; background: var(--bg); color: var(--text); font-size: .95rem; }
h1, h2, h3 { font-weight: 650; margin: 0; }
h1 { font-size: clamp(1.6rem, 3vw, 2rem); line-height: 1.1; letter-spacing: -.022em; }
h2 { font-size: 1.15rem; line-height: 1.2; letter-spacing: -.012em; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
.muted { color: var(--muted); }
.num { font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }

/* barra traslucida: il contenuto scorre sotto */
.bar { position: sticky; top: 0; z-index: 20; background: var(--bar); backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px); border-bottom: 1px solid var(--line); }
.bar-in { max-width: 1080px; margin: 0 auto; padding: 0 20px; height: 54px; display: flex; align-items: center; gap: 22px; }
.brand { font-weight: 650; letter-spacing: -.015em; color: var(--text); display: flex; align-items: center; gap: 8px; }
.brand:hover { text-decoration: none; }
.brand i { font-style: normal; font-size: .68rem; font-weight: 700; letter-spacing: .06em; color: var(--accent);
  background: var(--accent-soft); padding: 2px 7px; border-radius: 6px; }
.nav { display: flex; gap: 4px; flex: 1; }
.nav a { color: var(--muted); padding: 6px 12px; border-radius: 9px; font-weight: 500; transition: background-color 120ms, color 120ms; }
.nav a:hover { color: var(--text); text-decoration: none; background: var(--accent-soft); }
.nav a[aria-current="page"] { color: var(--text); background: var(--accent-soft); }
.bar form { margin: 0; }

main { max-width: 1080px; margin: 0 auto; padding: 28px 20px 80px; }
.head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 20px; }
.head p { margin: 4px 0 0; color: var(--muted); }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 20px; margin-bottom: 18px; }
.card h2 { margin-bottom: 14px; }

/* pulsanti: il feedback parte alla pressione, non al rilascio */
.btn { font: inherit; font-weight: 550; display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line);
  background: var(--surface); color: var(--text); padding: 8px 16px; border-radius: 10px; cursor: pointer;
  transition: transform 100ms ease-out, background-color 120ms; touch-action: manipulation; }
.btn:hover { text-decoration: none; background: var(--surface-2); }
.btn:active { transform: scale(.97); }
.btn.primary { background: var(--accent); border-color: transparent; color: var(--accent-text); }
.btn.primary:hover { filter: brightness(1.06); }
.btn.danger { color: var(--err); }
.btn.small { padding: 4px 10px; font-size: .85rem; border-radius: 8px; }
.btn.ghost { border-color: transparent; background: transparent; color: var(--accent); }
.btn:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, a:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px; }

/* campi */
label { display: block; font-size: .8rem; font-weight: 550; color: var(--muted); margin-bottom: 5px; }
input, select, textarea { font: inherit; width: 100%; color: var(--text); background: var(--surface-2); border: 1px solid var(--line);
  border-radius: 10px; padding: 9px 12px; transition: border-color 120ms, box-shadow 120ms; }
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); outline: none; }
textarea { resize: vertical; min-height: 84px; }
.grid { display: grid; gap: 14px; grid-template-columns: repeat(12, 1fr); }
.grid > * { grid-column: span 12; }
@media (min-width: 720px) {
  .c3 { grid-column: span 3; } .c4 { grid-column: span 4; } .c5 { grid-column: span 5; } .c6 { grid-column: span 6; }
  .c8 { grid-column: span 8; } .c2 { grid-column: span 2; }
}
.actions { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }

/* tabelle */
.table { width: 100%; border-collapse: collapse; }
.table th { text-align: left; font-size: .75rem; letter-spacing: .04em; text-transform: uppercase; color: var(--muted);
  font-weight: 600; padding: 8px 10px; border-bottom: 1px solid var(--line); }
.table td { padding: 12px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table tbody tr { transition: background-color 120ms; }
.table tbody tr:hover { background: var(--accent-soft); }
.table td.num, .table th.num { text-align: right; }
.scroll { overflow-x: auto; }

.pill { display: inline-block; font-size: .75rem; font-weight: 600; padding: 2px 10px; border-radius: 999px; }
.pill.bozza { background: rgba(110, 110, 115, .16); color: var(--muted); }
.pill.inviato { background: var(--accent-soft); color: var(--accent); }
.pill.accettato { background: rgba(31, 138, 76, .15); color: var(--ok); }
.pill.rifiutato { background: rgba(200, 55, 45, .14); color: var(--err); }

.flash { padding: 11px 14px; border-radius: 11px; margin-bottom: 14px; font-weight: 500; animation: entra 260ms var(--ease); }
.flash.ok { background: rgba(31, 138, 76, .14); color: var(--ok); }
.flash.errore { background: rgba(200, 55, 45, .13); color: var(--err); }
@keyframes entra { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; transform: none; } }

.toolbar { display: flex; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; }
.toolbar input { max-width: 320px; }
.toolbar select { max-width: 170px; }
.empty { text-align: center; padding: 42px 10px; color: var(--muted); }

/* editor righe */
.riga { display: grid; gap: 8px; grid-template-columns: 1fr; padding: 12px 0; border-bottom: 1px solid var(--line); position: relative; }
.riga:last-child { border-bottom: 0; }
@media (min-width: 820px) {
  .riga { grid-template-columns: minmax(220px, 1fr) 100px 78px 104px 76px 100px 34px; align-items: start; }
}
.riga .imp { padding: 10px 0; font-weight: 600; }
.riga .x { padding: 6px; border: 0; background: transparent; color: var(--muted); cursor: pointer; border-radius: 8px; font-size: 1.2rem; line-height: 1; }
.riga .x:hover { color: var(--err); background: rgba(200, 55, 45, .1); }
.riga.nuova { animation: entra 240ms var(--ease); }
.riga-label { display: none; }
@media (max-width: 819px) { .riga-label { display: block; } }
.cerca { position: relative; }
.sug { position: absolute; left: 0; right: 0; top: calc(100% + 4px); z-index: 15; list-style: none; margin: 0; padding: 5px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); max-height: 280px; overflow: auto; }
.sug li { padding: 8px 10px; border-radius: 8px; cursor: pointer; display: flex; justify-content: space-between; gap: 12px; }
.sug li[aria-selected="true"], .sug li:hover { background: var(--accent-soft); }
.sug small { color: var(--muted); white-space: nowrap; }
.totali { margin-left: auto; width: min(100%, 330px); }
.totali div { display: flex; justify-content: space-between; padding: 5px 0; }
.totali .tot { border-top: 1px solid var(--line); margin-top: 6px; padding-top: 10px; font-size: 1.2rem; font-weight: 650; letter-spacing: -.01em; }

/* invio email: modulo e anteprima PDF affiancati */
.due { display: grid; gap: 18px; grid-template-columns: 1fr; align-items: start; }
@media (min-width: 980px) { .due { grid-template-columns: minmax(340px, 5fr) 6fr; } }
.stack > * + * { margin-top: 14px; }
.anteprima iframe { width: 100%; height: min(78vh, 900px); border: 1px solid var(--line); border-radius: 10px; background: #fff; }
.sezione { margin: 22px 0 8px; font-size: .95rem; }

/* accesso */
.login { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login .card { width: min(100%, 400px); padding: 30px; }
.login h1 { margin-bottom: 6px; }
.login form > * + * { margin-top: 14px; }
.logo-prev { max-height: 64px; max-width: 200px; display: block; margin-bottom: 10px; }

/* preferenze di sistema: movimento, trasparenza, contrasto */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
  .btn:active { transform: none; }
}
@media (prefers-reduced-transparency: reduce) {
  .bar { background: var(--bg); backdrop-filter: none; -webkit-backdrop-filter: none; }
}
@media (prefers-contrast: more) {
  :root { --line: rgba(128, 128, 128, .7); --muted: var(--text); }
  .card, input, select, textarea, .btn { border-width: 1.5px; }
}
@media print { .bar, .actions, .btn { display: none !important; } body { background: #fff; } }
