:root {
    --bg: #f4f6f8; --card: #fff; --text: #1d2733; --muted: #6b7785; --line: #dde3ea;
    --primary: #1f6feb; --primary-d: #1859c0; --danger: #c93a3a; --ok: #1a7f4b; --warn: #b7791f;
}
* { box-sizing: border-box; }
body { margin: 0; font: 14px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif; background: var(--bg); color: var(--text); }
a { color: var(--primary); }
h1 { font-size: 22px; margin: 0 0 16px; }
main { max-width: 1400px; margin: 0 auto; padding: 20px; }

.topbar { display: flex; align-items: center; gap: 24px; background: #17202b; color: #fff; padding: 0 20px; height: 52px; }
.topbar a { color: #cfd8e3; text-decoration: none; }
.topbar .brand { font-weight: 700; color: #fff; }
.topbar nav { display: flex; gap: 4px; flex: 1; }
.topbar nav a { padding: 6px 12px; border-radius: 6px; }
.topbar nav a.active, .topbar nav a:hover { background: #2a3746; color: #fff; }
.topbar .user { font-size: 13px; color: #9fb0c3; }
.topbar .user a { margin-left: 8px; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 20px; margin-bottom: 20px; }
.card.narrow { max-width: 360px; margin: 60px auto; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.card.narrow-form { max-width: 420px; }
td .form-inline { flex-wrap: nowrap; }

label { display: flex; flex-direction: column; gap: 4px; font-weight: 600; font-size: 13px; }
input, select, textarea { font: inherit; padding: 7px 9px; border: 1px solid var(--line); border-radius: 6px; background: #fff; }
input:focus, select:focus, textarea:focus { outline: 2px solid #b5d0fb; border-color: var(--primary); }
small { font-weight: 400; color: var(--muted); }

.btn { display: inline-block; font: inherit; padding: 7px 14px; border: 1px solid var(--line); background: #fff; color: var(--text); border-radius: 6px; cursor: pointer; text-decoration: none; }
.btn:hover { background: #eef2f6; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-d); }
.btn.danger { background: #fff; border-color: var(--danger); color: var(--danger); }
.btn.danger:hover { background: var(--danger); color: #fff; }
.btn.ghost { background: transparent; }
.btn.small { padding: 3px 9px; font-size: 12px; }
.btn:disabled { opacity: .45; cursor: not-allowed; }

.flash { padding: 10px 14px; border-radius: 6px; margin-bottom: 14px; border: 1px solid; }
.flash.ok { background: #e7f6ee; border-color: #a6dcc0; color: #11593a; }
.flash.error { background: #fdeaea; border-color: #f1b3b3; color: #8e2424; }

.filters { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 12px; margin-bottom: 16px; }
.toolbar { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }

.table-wrap { overflow-x: auto; background: var(--card); border: 1px solid var(--line); border-radius: 10px; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { background: #f0f3f7; font-size: 12px; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); }
tbody tr:hover { background: #fafcff; }
td.empty { text-align: center; color: var(--muted); padding: 30px; }
.muted { color: var(--muted); }

ul.items { list-style: none; margin: 0; padding: 0; }
ul.items li { margin-bottom: 4px; }
ul.items small { display: block; }
.qty { font-weight: 700; color: var(--primary); }

.badge { display: inline-block; padding: 2px 9px; border-radius: 99px; font-size: 12px; font-weight: 600; }
.badge.non_spedito { background: #fff4de; color: var(--warn); }
.badge.spedito { background: #e0f4ea; color: var(--ok); }

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-grid .span2 { grid-column: 1 / -1; }
.form-inline { display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-end; }
.form-inline .grow { flex: 1; min-width: 220px; }
.form-actions { display: flex; gap: 10px; }
.danger-zone { margin-top: 10px; }
fieldset { border: 1px solid var(--line); border-radius: 8px; padding: 14px; }
legend { font-weight: 700; padding: 0 6px; }
.item-table { margin: 12px 0; }
.item-table td { padding: 4px; border: 0; }
.item-table input { width: 100%; }
.item-table .qty-input { width: 70px; }

.picker { position: relative; }
.picker input { width: 100%; }
.results { position: absolute; z-index: 5; left: 0; right: 0; margin: 2px 0 0; padding: 0; list-style: none; background: #fff; border: 1px solid var(--line); border-radius: 6px; box-shadow: 0 6px 20px rgba(0,0,0,.12); max-height: 280px; overflow-y: auto; }
.results li { padding: 8px 12px; cursor: pointer; border-bottom: 1px solid var(--line); }
.results li:hover, .results li.hl { background: #eef4ff; }
.results small { margin-left: 6px; }

dialog { border: 0; border-radius: 12px; padding: 24px; max-width: 460px; box-shadow: 0 20px 60px rgba(0,0,0,.3); }
dialog::backdrop { background: rgba(10, 20, 30, .5); }
dialog h2 { margin: 0 0 8px; }
.dialog-actions { display: flex; flex-direction: column; gap: 8px; margin-top: 16px; }

/* Borderò stampabile */
.print-page { background: #fff; padding: 24px; }
.print-bar { margin-bottom: 16px; display: flex; gap: 8px; }
.print-page .meta { color: #333; }
table.print th, table.print td { border: 1px solid #999; font-size: 12px; }
.signatures { display: flex; justify-content: space-between; margin-top: 60px; }
@media print {
    .no-print { display: none !important; }
    .print-page { padding: 0; }
    table.print { page-break-inside: auto; }
    table.print tr { page-break-inside: avoid; }
}

@media (max-width: 700px) {
    .form-grid { grid-template-columns: 1fr; }
    .topbar { flex-wrap: wrap; height: auto; padding: 8px 12px; gap: 8px; }
}
