:root {
  --teal: #006b84; --teal-dark: #00566a; --green: #a6c953;
  --ok: #1a9a48; --err: #d32f2f; --warn: #ef9a00;
  --bg: #f3f6f7; --card: #fff; --text: #1d2a2e; --muted: #6b7b80; --line: #dce5e8;
}
* { box-sizing: border-box; }
/* L'attributo hidden deve vincere sui display impostati dalle classi (es. .result, .btn) */
[hidden] { display: none !important; }
body { margin: 0; font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif; background: var(--bg); color: var(--text); }
a { color: var(--teal); }
h1 { font-size: 1.5rem; margin: .2em 0 .6em; color: var(--teal); }
h2 { font-size: 1.15rem; margin: 1.2em 0 .5em; }
.card h2 { margin-top: 0; }
code, .mono { font-family: ui-monospace, Consolas, "Courier New", monospace; }
.muted { color: var(--muted); }

.top { background: var(--teal); color: #fff; padding: .6rem 1rem; display: flex; flex-wrap: wrap; gap: .5rem 1.5rem; align-items: center; border-bottom: 4px solid var(--green); }
.top nav { display: flex; flex-wrap: wrap; gap: .25rem; }
.top nav a { color: #fff; text-decoration: none; padding: .3rem .6rem; border-radius: 6px; }
.top nav a.active, .top nav a:hover { background: rgba(255,255,255,.18); }
.top nav a.logout { opacity: .8; }
main { max-width: 1100px; margin: 0 auto; padding: 1rem; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 1rem 1.2rem; margin: 0 0 1rem; }
.card.narrow { max-width: 380px; margin: 3rem auto; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 1rem; }
label { display: block; margin: 0 0 .8rem; font-weight: 600; font-size: .9rem; }
input, select { display: block; width: 100%; margin-top: .25rem; padding: .55rem .6rem; font: inherit; border: 1px solid #b9c7cb; border-radius: 6px; background: #fff; }
form.inline, .filters { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }
form.inline input, .filters input, .filters select { width: auto; flex: 1 1 180px; margin: 0; }
.actions form { display: flex; flex-wrap: wrap; gap: .3rem; }

.btn { display: inline-block; padding: .5rem .9rem; font: inherit; font-weight: 600; border: 1px solid #b9c7cb; border-radius: 6px; background: #fff; color: var(--text); cursor: pointer; text-decoration: none; }
.btn:hover { border-color: var(--teal); }
.btn.primary { background: var(--teal); border-color: var(--teal); color: #fff; }
.btn.primary:hover { background: var(--teal-dark); }
.btn.danger { color: var(--err); border-color: #e7b3b3; }
.btn.small { padding: .25rem .55rem; font-size: .85rem; }
.btn.big { padding: .8rem 1.4rem; font-size: 1.05rem; }
.btn:disabled { opacity: .5; cursor: default; }

.flash { padding: .6rem .9rem; border-radius: 6px; margin: 0 0 1rem; background: #e5f4ea; border: 1px solid #b7dfc3; white-space: pre-line; overflow-wrap: anywhere; }
.flash.error { background: #fdeaea; border-color: #f1b9b9; }
.flash.warn { background: #fff4df; border-color: #f3d193; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: .7rem; margin-bottom: .8rem; }
.stat { background: #fff; border: 1px solid var(--line); border-left: 5px solid var(--teal); border-radius: 8px; padding: .6rem .8rem; color: var(--muted); font-size: .85rem; }
.stat b { display: block; font-size: 1.8rem; color: var(--text); line-height: 1.1; }
.stat.green { border-left-color: var(--ok); } .stat.red { border-left-color: var(--err); }
.stat.orange { border-left-color: var(--warn); } .stat.grey { border-left-color: #a8b4b8; }

.table-wrap { overflow-x: auto; background: #fff; border: 1px solid var(--line); border-radius: 8px; margin-bottom: 1rem; }
table { border-collapse: collapse; width: 100%; }
th, td { text-align: left; padding: .5rem .6rem; border-bottom: 1px solid var(--line); vertical-align: top; }
th { background: #f7fafb; font-size: .85rem; color: var(--muted); }
.badge { display: inline-block; padding: .1rem .5rem; border-radius: 99px; font-size: .8rem; font-weight: 600; color: #fff; background: #93a1a5; white-space: nowrap; }
.badge.green { background: var(--ok); } .badge.red { background: var(--err); } .badge.orange { background: var(--warn); }
.pager { display: flex; flex-wrap: wrap; gap: .3rem; }
.progress { height: 10px; background: var(--line); border-radius: 99px; overflow: hidden; margin: 1rem 0 .5rem; }
.progress div { height: 100%; width: 0; background: var(--ok); transition: width .3s; }
.log { max-height: 260px; overflow: auto; background: #10272d; color: #d8f1e0; padding: .7rem; border-radius: 6px; font-size: .8rem; white-space: pre-wrap; }

/* ---------------------------------------------------------------- scanner */
body.scanner { background: #0d1f24; color: #fff; min-height: 100vh; }
body.scanner a { color: #9fd9e6; }
.scan-top { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; justify-content: space-between; gap: .5rem; padding: .5rem; background: var(--teal); border-bottom: 4px solid var(--green); }
body.mode-out .scan-top { background: #8a4b00; border-bottom-color: var(--warn); }
.modes { display: flex; gap: .3rem; }
.mode { font: 700 1rem system-ui, sans-serif; padding: .6rem .9rem; border-radius: 8px; border: 2px solid rgba(255,255,255,.5); background: transparent; color: #fff; }
.mode.active { background: #fff; color: var(--teal); border-color: #fff; }
body.mode-out .mode.active { color: #8a4b00; }
.counter { font-size: .9rem; text-align: right; }
.counter b { font-size: 1.3rem; }
#reader { width: 100%; max-width: 560px; margin: 0 auto; }
#reader video { border-radius: 0; }
.cam-msg { margin: 1rem; padding: .8rem; background: #5a1d1d; border-radius: 8px; }
#cam-start { display: block; margin: 1rem auto; }
.manual { max-width: 560px; margin: 0 auto; padding: .8rem; }
#manual-form { display: flex; gap: .4rem; }
#manual-form input { margin: 0; font-size: 1rem; }
#results { list-style: none; padding: 0; margin: .6rem 0; }
#results li { display: flex; justify-content: space-between; align-items: center; gap: .5rem; background: #183840; padding: .6rem; border-radius: 8px; margin-bottom: .4rem; }
#results small { color: #b7cdd2; }
.scan-foot { color: #9ab; font-size: .85rem; margin-top: 1.2rem; }

.result { position: fixed; inset: 0; z-index: 20; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; padding: 1.5rem; color: #fff; cursor: pointer; }
.result.ok { background: var(--ok); }
.result.error { background: var(--err); }
.result.warn { background: var(--warn); }
.r-mode { font-weight: 700; letter-spacing: .15em; opacity: .85; }
.r-title { font-size: clamp(2rem, 9vw, 3.4rem); font-weight: 800; line-height: 1.1; margin: .3rem 0 .8rem; }
.r-name { font-size: clamp(1.4rem, 6vw, 2.2rem); font-weight: 700; }
.r-msg { font-size: 1.15rem; margin-top: .6rem; max-width: 30em; }
.r-detail { font-size: .9rem; opacity: .85; margin-top: 1rem; }
.r-tap { position: absolute; bottom: 1.5rem; font-size: .85rem; opacity: .75; }
