:root {
  --bg: #f4f6f8;
  --card: #fff;
  --text: #1d2733;
  --muted: #6b7785;
  --line: #dfe4ea;
  --primary: #1f5fa8;
  --primary-d: #174a85;
  --danger: #b42318;
  --ok: #18794e;
  --warn: #9a6700;
  --radius: 10px;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--text); }
a { color: var(--primary); }
h1 { font-size: 1.5rem; margin: .4rem 0 1rem; }
h2 { font-size: 1.15rem; margin: 1.6rem 0 .7rem; }
.card h2:first-child { margin-top: 0; }
.mb0 { margin-bottom: 0; }
.mt { margin-top: 1rem; }
.wrap { max-width: 1100px; margin: 0 auto; padding: 0 16px; }
main.wrap { padding-top: 18px; padding-bottom: 48px; }

.top { background: #fff; border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; }
.top-in { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 56px; flex-wrap: wrap; }
.brand { font-weight: 700; text-decoration: none; color: var(--text); }
.top nav { display: flex; gap: 4px; flex-wrap: wrap; align-items: center; }
.top nav a, .linkbtn { padding: 6px 10px; border-radius: 8px; text-decoration: none; color: var(--text); font-size: .93rem; }
.top nav a.on, .top nav a:hover { background: #eaf1fa; color: var(--primary); }
.linkbtn { background: none; border: 0; cursor: pointer; font: inherit; color: var(--muted); }
form.inline { display: inline; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; margin: 0 0 18px; }
.card.narrow { max-width: 620px; }
.card.highlight { border-color: #b9d0ec; background: #f7fbff; }
details.card summary { cursor: pointer; }
details.card[open] summary { margin-bottom: 12px; }

.row { display: flex; gap: 12px; align-items: flex-start; }
.between { justify-content: space-between; }
.wrapflex { flex-wrap: wrap; }
.big { font-size: 1.35rem; font-weight: 600; }
.r { text-align: right; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.nowrap { white-space: nowrap; }
.count { display: inline-block; min-width: 1.6em; padding: 0 .4em; font-size: .85rem; text-align: center; border-radius: 99px; background: #e4e9ef; vertical-align: middle; }

label { display: block; margin: 0 0 14px; font-weight: 500; }
label.check { font-weight: 400; display: flex; gap: 8px; align-items: flex-start; margin-bottom: 8px; }
label.check.inline { display: inline-flex; margin-right: 14px; }
input[type=text], input[type=email], input[type=password], input[type=date], input[type=number], select, textarea {
  display: block; width: 100%; margin-top: 4px; padding: 10px 12px; font: inherit; color: inherit;
  border: 1px solid #c8d0da; border-radius: 8px; background: #fff;
}
input[type=file] { display: block; margin-top: 6px; max-width: 100%; }
input:focus, select:focus, textarea:focus { outline: 2px solid #9cc2ef; border-color: var(--primary); }
input.w80 { width: 80px; }
fieldset { border: 1px solid var(--line); border-radius: 8px; margin: 0 0 14px; padding: 10px 12px 4px; }
legend { padding: 0 4px; font-weight: 500; }
.err { display: block; color: var(--danger); font-size: .85rem; font-weight: 400; margin-top: 3px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0 14px; }
.calc { background: #eef5ec; border-radius: 8px; padding: 10px 12px; }
.preview { margin-bottom: 14px; }
.preview img { max-width: 220px; max-height: 260px; border: 1px solid var(--line); border-radius: 6px; display: block; margin-bottom: 4px; }

.btn { display: inline-block; padding: 9px 16px; border-radius: 8px; border: 1px solid #c8d0da; background: #fff; color: var(--text);
  font: inherit; font-weight: 500; text-decoration: none; cursor: pointer; line-height: 1.3; }
.btn:hover { background: #f0f3f6; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-d); }
.btn.danger { color: var(--danger); border-color: #f0c2bd; }
.btn.danger:hover { background: #fdf0ee; }
.btn.ghost { border-color: transparent; }
.btn.small { padding: 5px 10px; font-size: .85rem; }
.btn.full { width: 100%; }
.btn:disabled { opacity: .6; cursor: wait; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin: 12px 0 16px; }

.flash { padding: 10px 14px; border-radius: 8px; margin: 0 0 14px; border: 1px solid; }
.flash.ok { background: #ecf8f1; border-color: #b3e0c6; color: #0e5a38; }
.flash.error { background: #fdf0ee; border-color: #f2c4be; color: #8a1c12; }
.flash.info { background: #fff8e6; border-color: #f0d89a; color: #6b4a00; }

.badge { display: inline-block; padding: 2px 9px; border-radius: 99px; font-size: .78rem; font-weight: 600; vertical-align: middle; white-space: nowrap; }
.st-draft { background: #e9edf1; color: #4a5562; }
.st-submitted { background: #e3effc; color: #1a5394; }
.st-approved { background: #e2f5ea; color: #136c43; }
.st-rejected { background: #fde8e6; color: #a5251a; }
.st-paid { background: #ede7fb; color: #5b3aa6; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; margin: 16px 0; }
.stat { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; }
.stat span { display: block; font-size: .8rem; color: var(--muted); }
.stat strong { font-size: 1.2rem; }
.stat.accent { border-color: #b9d0ec; background: #f2f8ff; }

.filters { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; margin-bottom: 8px; }
.filters label { margin: 0; min-width: 140px; }

.tablewrap { overflow-x: auto; background: #fff; border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 18px; }
table.list { width: 100%; border-collapse: collapse; }
table.list th, table.list td { padding: 10px 12px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
table.list th { font-size: .8rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); background: #fafbfc; }
table.list th.r, table.list td.r { text-align: right; }
table.list tr:last-child td { border-bottom: 0; }
table.list tr.dim td { color: var(--muted); }
table.list input[type=text] { margin: 0; }
code { background: #eef1f4; padding: 1px 6px; border-radius: 4px; }

.history { list-style: none; padding: 0; margin: 0; }
.history li { padding: 6px 0; border-bottom: 1px dashed var(--line); }
.checks { list-style: none; padding: 0; }
.checks .ok { color: var(--ok); }
.checks .ko { color: var(--danger); }

@media (max-width: 720px) {
  body { font-size: 16px; }
  .grid2, .grid3 { grid-template-columns: 1fr; }
  .stats { grid-template-columns: 1fr 1fr; }
  .top-in { padding: 8px 16px; }
  /* Tabelle come schede su smartphone */
  table.list thead { display: none; }
  table.list, table.list tbody, table.list tr, table.list td { display: block; width: 100%; }
  table.list tr { border-bottom: 1px solid var(--line); padding: 8px 0; }
  table.list td { border: 0; padding: 4px 12px; text-align: left !important; }
  table.list td[data-l]::before { content: attr(data-l); display: block; font-size: .72rem; color: var(--muted); text-transform: uppercase; }
  .tablewrap { overflow: visible; }
}

/* Lettura automatica scontrini */
.scanstatus { padding: 9px 12px; border-radius: 8px; margin: -4px 0 14px; font-size: .92rem; }
.scanstatus.wait { background: #eef4fb; color: #1a5394; }
.scanstatus.ok { background: #ecf8f1; color: #0e5a38; }
.scanstatus.warn { background: #fff8e6; color: #6b4a00; }
.autofilled { background: #fffbe0 !important; }
.st-authorized { background: #fff1d6; color: #8a5300; }
.strike { text-decoration: line-through; color: var(--muted); font-weight: 400; }
.adminnote { display: block; font-size: .82rem; color: #8a5300; margin-top: 3px; }
input.w100 { width: 110px; }

/* Logo */
.brand { display: flex; align-items: center; gap: 12px; }
.brandlogo { height: 40px; width: auto; display: block; }
.brand span { font-size: .95rem; color: var(--muted); font-weight: 600; border-left: 1px solid var(--line); padding-left: 12px; }
.card.login { margin: 24px auto; text-align: left; }
.loginlogo { display: block; width: 240px; max-width: 80%; height: auto; margin: 4px auto 18px; }
@media (max-width: 720px) {
  .brandlogo { height: 32px; }
  .brand span { display: none; }
}
.scanstatus.alert { background: #fff1d6; color: #7a4100; border: 1px solid #f0c66b; }
.warnline { display: block; font-size: .82rem; color: #8a3b00; background: #fff1d6; border-radius: 6px; padding: 2px 8px; margin-top: 4px; width: fit-content; }
