/* Gestionale commesse – stile ottimizzato per tablet */
:root {
    --bg: #f3f4f6;
    --surface: #ffffff;
    --text: #1c2230;
    --muted: #5f6b7a;
    --border: #dde2e9;
    --primary: #1c5aa6;
    --primary-dark: #154683;
    --primary-soft: #e8f0fa;
    --success: #1f7a4d;
    --success-soft: #e5f4ec;
    --warning: #a35b00;
    --warning-soft: #fff3e0;
    --danger: #b42318;
    --danger-soft: #fdecea;
    --topbar: #1c2230;
    --radius: 10px;
    --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
    font-size: 16px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.45;
    -webkit-text-size-adjust: 100%;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.5rem; margin: 0 0 .25rem; }
h2 { font-size: 1.15rem; margin: 0 0 .75rem; }
h3 { font-size: 1rem; margin: 0 0 .5rem; }
p { margin: 0 0 .75rem; }
small, .muted { color: var(--muted); }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.center { text-align: center; }
.mt { margin-top: 1rem; }
.mb0 { margin-bottom: 0; }
.hidden { display: none !important; }

/* ---------- Barra superiore ---------- */
.topbar {
    background: var(--topbar);
    color: #fff;
    position: sticky;
    top: 0;
    z-index: 50;
    box-shadow: 0 2px 6px rgba(0, 0, 0, .15);
}
.topbar-inner {
    display: flex;
    align-items: center;
    gap: .5rem;
    padding: .4rem 1rem;
    max-width: 1500px;
    margin: 0 auto;
}
.brand { font-weight: 700; font-size: 1.1rem; color: #fff; margin-right: .75rem; white-space: nowrap; }
.brand:hover { text-decoration: none; }
.nav { display: flex; align-items: center; gap: .15rem; flex: 1; overflow-x: auto; scrollbar-width: none; }
.nav::-webkit-scrollbar { display: none; }
.nav a, .nav summary {
    color: #d5dae3;
    padding: .55rem .75rem;
    border-radius: 8px;
    white-space: nowrap;
    cursor: pointer;
    list-style: none;
    font-size: .95rem;
}
.nav summary::-webkit-details-marker { display: none; }
.nav a:hover, .nav summary:hover { background: rgba(255, 255, 255, .08); color: #fff; text-decoration: none; }
.nav a.active { background: rgba(255, 255, 255, .14); color: #fff; }
.nav a.nuova { background: var(--primary); color: #fff; font-weight: 600; }
.nav a.nuova:hover { background: var(--primary-dark); }
.dropdown { position: relative; }
.dropdown-menu {
    position: absolute;
    top: calc(100% + 6px);
    right: 0;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: 0 10px 30px rgba(0, 0, 0, .18);
    min-width: 220px;
    padding: .35rem;
    z-index: 60;
}
.nav .dropdown-menu { left: 0; right: auto; position: fixed; top: auto; margin-top: 6px; }
.dropdown-menu a {
    display: block;
    color: var(--text);
    padding: .6rem .8rem;
    border-radius: 6px;
}
.dropdown-menu a:hover { background: var(--bg); text-decoration: none; }
.dropdown-menu hr { border: 0; border-top: 1px solid var(--border); margin: .3rem 0; }
.dropdown-menu .who { padding: .5rem .8rem; color: var(--muted); font-size: .85rem; }
.top-actions { display: flex; align-items: center; gap: .35rem; }
.icon-btn {
    position: relative;
    background: transparent;
    border: 0;
    color: #fff;
    padding: .5rem .6rem;
    border-radius: 8px;
    cursor: pointer;
    font-size: 1.15rem;
    line-height: 1;
    list-style: none;
}
.icon-btn::-webkit-details-marker { display: none; }
.icon-btn:hover { background: rgba(255, 255, 255, .1); }
.badge-count {
    position: absolute;
    top: 0;
    right: 0;
    background: #e5484d;
    color: #fff;
    font-size: .7rem;
    font-weight: 700;
    border-radius: 999px;
    min-width: 1.2rem;
    height: 1.2rem;
    line-height: 1.2rem;
    text-align: center;
    padding: 0 .25rem;
}
.notif-list { width: min(420px, 92vw); max-height: 70vh; overflow-y: auto; }
.notif-item { display: block; padding: .6rem .75rem; border-radius: 6px; color: var(--text); font-size: .9rem; border-bottom: 1px solid var(--border); }
.notif-item:last-child { border-bottom: 0; }
.notif-item.unread { background: var(--primary-soft); }
.notif-item .quando { display: block; font-size: .75rem; color: var(--muted); margin-top: .15rem; }
.search-top input { width: 9rem; min-height: 38px; font-size: .9rem; padding: .35rem .6rem; border-radius: 8px; border: 0; }

/* ---------- Contenuto ---------- */
.container { max-width: 1500px; margin: 0 auto; padding: 1.25rem 1rem 3rem; }
.page-head {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    justify-content: space-between;
    gap: .75rem;
    margin-bottom: 1rem;
}
.page-head .actions { display: flex; flex-wrap: wrap; gap: .5rem; }

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 1.1rem 1.2rem;
    margin-bottom: 1.1rem;
}
.card-head {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: .5rem;
    margin-bottom: .85rem;
}
.card-head h2 { margin: 0; }
.section-anchor { scroll-margin-top: 70px; }

.grid { display: grid; gap: 1rem; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
@media (max-width: 900px) {
    .grid-3, .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 640px) {
    .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
}

/* ---------- KPI ---------- */
.kpi {
    display: block;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem 1.1rem;
    box-shadow: var(--shadow);
    color: var(--text);
    border-left: 5px solid var(--border);
}
.kpi:hover { text-decoration: none; border-color: var(--primary); }
.kpi .num { font-size: 2rem; font-weight: 700; line-height: 1.1; }
.kpi .lbl { color: var(--muted); font-size: .9rem; }
.kpi.k-accettazione { border-left-color: #8a63d2; }
.kpi.k-lavorazione { border-left-color: var(--primary); }
.kpi.k-pronta { border-left-color: var(--success); }
.kpi.k-consegnata { border-left-color: var(--warning); }

/* ---------- Pulsanti ---------- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: .4rem;
    min-height: 44px;
    padding: .55rem 1.05rem;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    font: inherit;
    font-weight: 600;
    font-size: .95rem;
    cursor: pointer;
    text-decoration: none;
    white-space: nowrap;
    transition: background .12s, border-color .12s;
}
.btn:hover { text-decoration: none; border-color: #b8c0cc; background: #f8f9fb; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); border-color: var(--primary-dark); }
.btn-success { background: var(--success); border-color: var(--success); color: #fff; }
.btn-success:hover { background: #17603c; border-color: #17603c; }
.btn-danger { background: var(--surface); border-color: #f1b8b3; color: var(--danger); }
.btn-danger:hover { background: var(--danger-soft); border-color: var(--danger); }
.btn-warning { background: var(--warning); border-color: var(--warning); color: #fff; }
.btn-big { min-height: 54px; font-size: 1.05rem; padding: .7rem 1.4rem; }
.btn-sm { min-height: 36px; padding: .3rem .7rem; font-size: .85rem; }
.btn-link { background: none; border: 0; color: var(--primary); padding: .25rem; min-height: 0; font-weight: 500; }
.btn-link:hover { background: none; text-decoration: underline; }
.btn-block { width: 100%; }
form.inline { display: inline; }

/* ---------- Moduli ---------- */
.field { margin-bottom: .9rem; }
.field label, .lbl-form { display: block; font-weight: 600; font-size: .9rem; margin-bottom: .3rem; }
.field .hint { font-size: .8rem; color: var(--muted); margin-top: .25rem; }
input[type=text], input[type=password], input[type=number], input[type=date], input[type=email],
input[type=tel], input[type=search], select, textarea {
    width: 100%;
    min-height: 46px;
    padding: .55rem .75rem;
    border: 1px solid #c9d0da;
    border-radius: 8px;
    background: #fff;
    color: var(--text);
    font: inherit;
    font-size: 1rem;
}
textarea { min-height: 90px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 3px solid rgba(28, 90, 166, .2); border-color: var(--primary); }
input[readonly], input:disabled, select:disabled, textarea:disabled, textarea[readonly] { background: #f2f4f7; color: #4a5565; }
input.num { text-align: right; font-variant-numeric: tabular-nums; }
.check { display: flex; align-items: center; gap: .55rem; font-weight: 500; cursor: pointer; min-height: 40px; }
.check input { width: 22px; height: 22px; accent-color: var(--primary); }
.form-actions { display: flex; flex-wrap: wrap; gap: .6rem; margin-top: .5rem; }
.code-input { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; }

/* Interruttore SÌ / NO */
.seg { display: inline-flex; border: 1px solid #c9d0da; border-radius: 8px; overflow: hidden; background: #fff; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg label {
    margin: 0;
    padding: .55rem .95rem;
    min-width: 3.2rem;
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-weight: 600;
    color: var(--muted);
    border-right: 1px solid #c9d0da;
    user-select: none;
}
.seg label:last-of-type { border-right: 0; }
.seg input:checked + label.si { background: var(--success); color: #fff; }
.seg input:checked + label.no { background: #6b7684; color: #fff; }
.seg input:checked + label.ko { background: var(--danger); color: #fff; }
.seg input:checked + label.nd { background: #e7eaee; color: var(--text); }
.seg input:disabled + label { cursor: not-allowed; opacity: .7; }

/* ---------- Tabelle ---------- */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table.table { width: 100%; border-collapse: collapse; font-size: .95rem; }
.table th {
    text-align: left;
    font-size: .78rem;
    text-transform: uppercase;
    letter-spacing: .03em;
    color: var(--muted);
    font-weight: 700;
    padding: .6rem .6rem;
    border-bottom: 2px solid var(--border);
    white-space: nowrap;
}
.table td { padding: .65rem .6rem; border-bottom: 1px solid var(--border); vertical-align: top; }
.table tr:last-child td { border-bottom: 0; }
.table tbody tr:hover { background: #fafbfc; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.table tfoot td { font-weight: 700; border-top: 2px solid var(--border); }
.table tr.inattivo td { color: #9aa3ae; }
.table .row-link { color: var(--text); font-weight: 600; }
.empty { text-align: center; color: var(--muted); padding: 1.5rem; }

/* ---------- Badge ---------- */
.badge {
    display: inline-block;
    font-size: .78rem;
    font-weight: 700;
    padding: .2rem .55rem;
    border-radius: 999px;
    background: #eef0f3;
    color: #3d4653;
    white-space: nowrap;
}
.st-accettazione { background: #f0eafb; color: #5b3aa0; }
.st-lavorazione { background: var(--primary-soft); color: var(--primary-dark); }
.st-pronta { background: var(--success-soft); color: var(--success); }
.st-consegnata { background: var(--warning-soft); color: var(--warning); }
.st-archiviata { background: #eceff3; color: #5f6b7a; }
.b-ok { background: var(--success-soft); color: var(--success); }
.b-ko { background: var(--danger-soft); color: var(--danger); }
.b-warn { background: var(--warning-soft); color: var(--warning); }
.b-urgente { background: var(--danger); color: #fff; }

/* ---------- Messaggi ---------- */
.flash { padding: .8rem 1rem; border-radius: 8px; margin-bottom: .8rem; border: 1px solid; font-weight: 500; }
.flash-ok { background: var(--success-soft); border-color: #a9dcc0; color: #145c39; }
.flash-errore { background: var(--danger-soft); border-color: #f3b9b4; color: #8f1d14; }
.flash-info { background: var(--primary-soft); border-color: #b9d0ee; color: var(--primary-dark); }
.alert { padding: .75rem 1rem; border-radius: 8px; margin-bottom: .8rem; background: var(--warning-soft); color: #7a4400; border: 1px solid #f5d29a; }
.alert-danger { background: var(--danger-soft); color: #8f1d14; border-color: #f3b9b4; }
.alert-info { background: var(--primary-soft); color: var(--primary-dark); border-color: #b9d0ee; }
.errori { margin: 0; padding-left: 1.2rem; }

/* ---------- Schede (tab) della commessa ---------- */
.subnav {
    display: flex;
    gap: .35rem;
    overflow-x: auto;
    position: sticky;
    top: 54px;
    z-index: 20;
    background: var(--bg);
    padding: .5rem 0;
    margin-bottom: .6rem;
    scrollbar-width: none;
}
.subnav::-webkit-scrollbar { display: none; }
.subnav a {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: .45rem .95rem;
    font-weight: 600;
    font-size: .9rem;
    color: var(--text);
    white-space: nowrap;
}
.subnav a:hover { border-color: var(--primary); text-decoration: none; }
.subnav .done::after { content: " ✓"; color: var(--success); }

.dl { display: grid; grid-template-columns: max-content 1fr; gap: .35rem 1rem; margin: 0; }
.dl dt { color: var(--muted); font-size: .9rem; }
.dl dd { margin: 0; font-weight: 600; }

/* Riepilogo economico */
.totale-box { background: var(--primary-soft); border-radius: 8px; padding: .8rem 1rem; display: flex; justify-content: space-between; align-items: center; font-size: 1.15rem; font-weight: 700; }

/* ---------- Firma ---------- */
.sig-wrap { position: relative; border: 2px dashed #b8c0cc; border-radius: 10px; background: #fff; touch-action: none; }
.sig-wrap canvas { display: block; width: 100%; height: 220px; border-radius: 10px; cursor: crosshair; touch-action: none; }
.sig-wrap .sig-line { position: absolute; left: 6%; right: 6%; bottom: 46px; border-bottom: 1px solid #ccd3dc; pointer-events: none; }
.sig-wrap .sig-hint { position: absolute; left: 6%; bottom: 20px; font-size: .8rem; color: #9aa3ae; pointer-events: none; }
.sig-img { max-width: 100%; max-height: 140px; border: 1px solid var(--border); border-radius: 8px; background: #fff; padding: .25rem; }
.sig-small { max-height: 48px; max-width: 150px; display: block; }
.testo-acc { background: #f8f9fb; border-left: 4px solid var(--primary); padding: .7rem .9rem; border-radius: 6px; font-size: .95rem; }

/* ---------- Finestre modali ---------- */
dialog {
    border: 0;
    border-radius: 14px;
    padding: 0;
    width: min(760px, 96vw);
    max-height: 94vh;
    box-shadow: 0 20px 60px rgba(0, 0, 0, .3);
}
dialog::backdrop { background: rgba(16, 24, 40, .55); }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 1rem 1.2rem; border-bottom: 1px solid var(--border); position: sticky; top: 0; background: #fff; z-index: 2; }
.modal-head h2 { margin: 0; }
.modal-body { padding: 1rem 1.2rem; }
.modal-foot { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: .5rem; padding: .9rem 1.2rem; border-top: 1px solid var(--border); position: sticky; bottom: 0; background: #fff; }
.close-x { background: none; border: 0; font-size: 1.6rem; cursor: pointer; color: var(--muted); line-height: 1; padding: .25rem .5rem; }

/* Calcolo riga */
.calc-box { background: #f8f9fb; border: 1px solid var(--border); border-radius: 10px; padding: .8rem 1rem; }
.calc-row { display: flex; justify-content: space-between; padding: .35rem 0; border-bottom: 1px solid var(--border); }
.calc-row:last-child { border-bottom: 0; }
.calc-row strong { font-variant-numeric: tabular-nums; }
.calc-row.tot { font-size: 1.15rem; }
.calc-err { color: var(--danger); font-weight: 600; }
.calc-warn { color: var(--warning); font-size: .88rem; }
.formula-tag { font-family: ui-monospace, Consolas, monospace; font-size: .82rem; background: #eef0f3; padding: .1rem .4rem; border-radius: 4px; }

/* Articolo: righe dinamiche campi/parametri */
.rep-row { display: grid; grid-template-columns: 1fr 1.3fr .8fr auto; gap: .5rem; margin-bottom: .5rem; align-items: start; }
.rep-row.param { grid-template-columns: 1fr .8fr 1.6fr auto; }
@media (max-width: 640px) { .rep-row, .rep-row.param { grid-template-columns: 1fr 1fr; } }
.var-chip { display: inline-block; background: var(--primary-soft); color: var(--primary-dark); border-radius: 6px; padding: .15rem .5rem; margin: .15rem; font-family: ui-monospace, Consolas, monospace; font-size: .85rem; cursor: pointer; border: 0; }

/* ---------- Calendario ---------- */
.cal { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 4px; }
.cal-h { text-align: center; font-weight: 700; color: var(--muted); font-size: .8rem; text-transform: uppercase; padding: .3rem 0; }
.cal-d { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; min-height: 110px; padding: .35rem; overflow: hidden; }
.cal-d.fuori { background: #f7f8fa; color: #a0a8b3; }
.cal-d.oggi { border: 2px solid var(--primary); }
.cal-n { font-weight: 700; font-size: .85rem; margin-bottom: .2rem; }
.cal-ev { display: block; font-size: .78rem; padding: .2rem .35rem; border-radius: 5px; margin-bottom: 3px; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cal-ev:hover { text-decoration: none; filter: brightness(.95); }
@media (max-width: 700px) {
    .cal { grid-template-columns: 1fr; }
    .cal-h, .cal-d.fuori.vuoto { display: none; }
    .cal-d { min-height: 0; }
}

/* ---------- Azioni ---------- */
.azione { display: flex; gap: .75rem; align-items: flex-start; padding: .7rem 0; border-bottom: 1px solid var(--border); }
.azione:last-child { border-bottom: 0; }
.azione .tick {
    width: 34px; height: 34px; border-radius: 50%; border: 2px solid #b8c0cc; background: #fff;
    cursor: pointer; flex: 0 0 34px; font-size: 1rem; color: var(--success); font-weight: 700;
}
.azione .tick:hover { border-color: var(--success); }
.azione.fatta .tick { background: var(--success); border-color: var(--success); color: #fff; }
.azione.fatta .testo { text-decoration: line-through; color: var(--muted); }
.azione .meta { font-size: .8rem; color: var(--muted); }

/* ---------- Login ---------- */
.login-page { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 1rem; background: linear-gradient(160deg, #1c2230 0%, #2b3a55 100%); }
.login-box { background: #fff; border-radius: 16px; padding: 2rem; width: min(400px, 100%); box-shadow: 0 20px 60px rgba(0, 0, 0, .35); }
.login-box h1 { margin-bottom: .2rem; }

.side-grid { display: grid; gap: 1rem; grid-template-columns: minmax(0, 1fr) 230px; align-items: start; }
.art-grid { display: grid; gap: 1rem; grid-template-columns: minmax(0, 1.5fr) minmax(0, 1fr); align-items: start; }
.art-grid aside { position: sticky; top: 70px; }
@media (max-width: 900px) {
    .side-grid, .art-grid { grid-template-columns: 1fr; }
    .art-grid aside { position: static; }
}
.qr-box { text-align: center; }
.qr-box svg { width: 180px; height: 180px; max-width: 100%; }

@media print {
    .topbar, .subnav, .no-print, .btn { display: none !important; }
    body { background: #fff; }
    .card { box-shadow: none; border-color: #ccc; }
}
