:root {
  --sfondo: #f5f4f1; --carta: #fff; --testo: #24262b; --tenue: #62666f; --bordo: #d9d7d1;
  --accento: #0f6b63; --accento-testo: #fff; --pericolo: #a4262c; --ok-sf: #e2f1ec; --err-sf: #f8e4e4; --all-sf: #fdf3df;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--sfondo); color: var(--testo); font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; display: flex; min-height: 100vh; }
body.senza-menu { display: block; }
a { color: var(--accento); }
h1 { font-size: 1.55rem; margin: 0 0 .75rem; }
h2 { font-size: 1.1rem; margin: 1.5rem 0 .5rem; }
main { flex: 1; min-width: 0; padding: 20px 24px 48px; max-width: 1240px; }
.senza-menu main { margin: 0 auto; }

.menu { width: 190px; flex: none; background: #1f2a2e; color: #fff; padding: 14px 10px; display: flex; flex-direction: column; gap: 10px; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.marchio { color: #fff; font-weight: 700; font-size: 1.15rem; text-decoration: none; padding: 4px 10px; letter-spacing: .04em; }
.voci { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.voci a { color: #dfe5e6; text-decoration: none; padding: 10px; border-radius: 6px; min-height: 44px; display: flex; align-items: center; }
.voci a:hover { background: #2d3b40; }
.voci a.attiva { background: var(--accento); color: #fff; }
.profilo { border-top: 1px solid #3a474c; padding: 10px 10px 0; font-size: .9rem; display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.profilo a, .link { color: #dfe5e6; background: none; border: 0; padding: 6px 0; font: inherit; cursor: pointer; text-decoration: underline; }
.profilo form { margin: 0; }

.scheda { background: var(--carta); border: 1px solid var(--bordo); border-radius: 8px; padding: 16px; margin-bottom: 14px; }
.stretta { max-width: 460px; }
.senza-menu .stretta { margin: 8vh auto 0; }
.testata { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.testata h1 { margin: 0; }
.griglia { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 12px 16px; }
.intera { grid-column: 1 / -1; }
.campo { margin-bottom: 12px; min-width: 0; }
.griglia .campo { margin-bottom: 0; }
label { display: block; font-size: .875rem; color: var(--tenue); margin-bottom: 4px; }
input, select, textarea { width: 100%; padding: 10px; min-height: 44px; font: inherit; color: inherit; background: #fff; border: 1px solid #b9b7b0; border-radius: 6px; }
input[type=checkbox] { width: 22px; height: 22px; min-height: 0; flex: none; margin: 0; }
input:focus-visible, select:focus-visible, textarea:focus-visible, .btn:focus-visible, a:focus-visible { outline: 2px solid var(--accento); outline-offset: 1px; }
.spunta { display: flex; align-items: center; gap: 8px; color: var(--testo); font-size: 1rem; margin: 8px 0; min-height: 44px; }
.btn { display: inline-flex; align-items: center; justify-content: center; min-height: 44px; padding: 8px 16px; font: inherit; font-weight: 600; color: var(--testo); background: #fff; border: 1px solid #a9a79f; border-radius: 6px; cursor: pointer; text-decoration: none; }
.btn:hover { background: #efeee9; }
.btn.primario { background: var(--accento); color: var(--accento-testo); border-color: var(--accento); }
.btn.primario:hover { background: #0b564f; }
.btn.pericolo { color: var(--pericolo); border-color: var(--pericolo); }
.btn.largo { width: 100%; }
.btn.piccolo { min-height: 44px; min-width: 44px; padding: 4px 10px; }
.azioni { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin: 10px 0; }
.azioni form { margin: 0; }
.ricerca { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; align-items: center; }
.ricerca input[type=search], .ricerca select { flex: 1 1 200px; width: auto; }
.ricerca .spunta { margin: 0; }

table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: .8125rem; color: var(--tenue); font-weight: 600; border-bottom: 1px solid var(--bordo); padding: 8px; white-space: nowrap; }
td { padding: 10px 8px; border-bottom: 1px solid #ecebe6; vertical-align: top; }
tr:last-child td { border-bottom: 0; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.vuoto { color: var(--tenue); text-align: center; padding: 18px; }
.scorri { overflow-x: auto; }
tr.allerta { background: var(--all-sf); }
tfoot td { font-weight: 700; border-top: 1px solid var(--bordo); }

.avviso { padding: 12px 14px; border-radius: 6px; margin-bottom: 12px; background: var(--ok-sf); border: 1px solid #b5dbcf; }
.avviso-errore { background: var(--err-sf); border-color: #e8bcbc; }
.avviso-attenzione { background: var(--all-sf); border-color: #ecd6a4; }
.nota { color: var(--tenue); font-size: .9rem; margin: 8px 0 0; }
.evidenza { font-size: 1.1rem; }
.stato { display: inline-block; font-size: .8125rem; font-weight: 600; padding: 2px 8px; border-radius: 10px; background: #e7e6e1; white-space: nowrap; }
.stato-in_lavorazione, .stato-inviato { background: #dfeaf7; color: #1c4a7d; }
.stato-pronto, .stato-parziale { background: var(--all-sf); color: #71500a; }
.stato-consegnato, .stato-accettato, .stato-ricevuto_merce { background: var(--ok-sf); color: #0b564f; }
.stato-annullato, .stato-rifiutato { background: var(--err-sf); color: var(--pericolo); }
.dati { display: grid; grid-template-columns: 170px 1fr; gap: 6px 12px; margin: 0; }
.dati dt { color: var(--tenue); }
.dati dd { margin: 0; overflow-wrap: anywhere; }

.tessere { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 12px; margin-bottom: 14px; }
.tessera { background: var(--carta); border: 1px solid var(--bordo); border-radius: 8px; padding: 14px 16px; text-decoration: none; color: inherit; display: block; }
.tessera b { display: block; font-size: 1.6rem; font-variant-numeric: tabular-nums; }
.tessera span { color: var(--tenue); font-size: .9rem; }
progress { width: 100%; height: 12px; accent-color: var(--accento); }

.riga { display: grid; grid-template-columns: 1.2fr 1.1fr 2fr 80px 100px 44px; gap: 8px; align-items: end; padding: 8px 0; border-bottom: 1px solid #ecebe6; }
.righe[data-acquisto="1"] .riga { grid-template-columns: 1.4fr 2fr 80px 100px 44px; }
.riga .campo { margin: 0; }
.azioni-riga { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 8px; margin: 12px 0 0; }

.firma-area { background: #fff; border: 2px dashed #8e8c85; border-radius: 8px; touch-action: none; display: block; width: 100%; height: 260px; cursor: crosshair; }
.condizioni { background: #f8f7f4; border: 1px solid var(--bordo); border-radius: 6px; padding: 12px; white-space: pre-line; font-size: .95rem; }
.firma-img { max-width: 320px; width: 100%; border: 1px solid var(--bordo); border-radius: 6px; background: #fff; display: block; }

.calendario { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 1px; background: var(--bordo); border: 1px solid var(--bordo); border-radius: 8px; overflow: hidden; }
.cal-testa { background: #ecebe6; font-size: .8125rem; font-weight: 600; padding: 6px; text-align: center; }
.cal-giorno { background: var(--carta); min-height: 104px; padding: 6px; font-size: .85rem; min-width: 0; }
.cal-giorno.fuori { background: #f3f2ee; color: #8b8d92; }
.cal-giorno.oggi { box-shadow: inset 0 0 0 2px var(--accento); }
.cal-num { font-weight: 600; display: block; margin-bottom: 4px; }
.cal-voce { display: block; padding: 3px 5px; margin-bottom: 3px; border-radius: 4px; background: #e7e6e1; color: inherit; text-decoration: none; overflow-wrap: anywhere; }
.cal-voce.evento { background: #f4dfee; color: #6d2259; }

@media (max-width: 1024px) {
  body { display: block; }
  .menu { width: auto; height: auto; position: sticky; top: 0; z-index: 5; flex-direction: row; align-items: center; padding: 6px 10px; flex-wrap: wrap; overflow: visible; }
  .voci { flex-direction: row; order: 3; width: 100%; overflow-x: auto; flex: none; scrollbar-width: none; }
  .voci a { white-space: nowrap; padding: 8px 12px; }
  .profilo { border: 0; padding: 0; margin-left: auto; }
  main { padding: 16px; }
  .riga, .righe[data-acquisto="1"] .riga { grid-template-columns: repeat(2, minmax(0, 1fr)) ; }
  .r-desc { grid-column: 1 / -1; }
  .r-via { justify-self: end; grid-column: 2; }
}
@media (max-width: 640px) {
  .dati { grid-template-columns: 1fr; }
  .dati dd { margin-bottom: 8px; }
  .cal-giorno { min-height: 72px; padding: 3px; font-size: .75rem; }
}
@media print {
  .menu, .azioni, .ricerca, form { display: none; }
  body, main, .scheda { background: #fff; border: 0; }
}
