:root {
  box-sizing: border-box;
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
  background: var(--brand);
  --brand: #d4202c; --brand-dark: #a8141e; --brand-soft: #fde9eb; --on-brand: #ffffff;
  --bg: #ffffff; --card: #ffffff; --field: #fff5f5; --text: #231f20; --muted: #7b6f70; --line: #f1d0d3;
  --shadow: 0 6px 18px rgba(212, 32, 44, .12);
  --red: #b3141f; --red-bg: #fde9eb; --green: #2e6b3a; --green-bg: #e7f2e9; --amber: #8a5a00; --amber-bg: #fbf1dc;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --brand: #c9222d; --brand-dark: #e5484f; --brand-soft: #3a1c1f; --on-brand: #ffffff;
    --bg: #1a1415; --card: #261d1e; --field: #1a1415; --text: #f4eeee; --muted: #b3a5a6; --line: #4a2d30;
    --shadow: 0 6px 18px rgba(0, 0, 0, .35);
    --red: #ff8f95; --red-bg: #3a1c1f; --green: #7fc48c; --green-bg: #213325; --amber: #e6b85c; --amber-bg: #38301d;
  }
}
:root[data-theme="dark"] {
  --brand: #c9222d; --brand-dark: #e5484f; --brand-soft: #3a1c1f; --on-brand: #ffffff;
  --bg: #1a1415; --card: #261d1e; --field: #1a1415; --text: #f4eeee; --muted: #b3a5a6; --line: #4a2d30;
  --shadow: 0 6px 18px rgba(0, 0, 0, .35);
  --red: #ff8f95; --red-bg: #3a1c1f; --green: #7fc48c; --green-bg: #213325; --amber: #e6b85c; --amber-bg: #38301d;
}
html { scroll-padding-top: env(safe-area-inset-top, 0px); }
* { box-sizing: border-box; }
body {
  margin: 0; background: var(--bg); color: var(--text); min-height: 100vh;
  font: 16px/1.45 "Trebuchet MS", "Avenir Next", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  padding-bottom: 104px;
}

/* Testata */
.hero {
  position: relative; overflow: hidden;
  background: var(--brand); color: var(--on-brand);
  padding: 20px 18px 40px; border-radius: 0 0 40px 40px;
  display: flex; align-items: center; gap: 14px;
}
.hero::before, .hero::after {
  content: ""; position: absolute; border-radius: 50%; background: rgba(255,255,255,.12);
}
.hero::before { width: 120px; height: 120px; right: -30px; top: -40px; }
.hero::after { width: 70px; height: 70px; right: 60px; bottom: -34px; }
.logo { flex: none; animation: bob 3.2s ease-in-out infinite; filter: drop-shadow(0 4px 6px rgba(0,0,0,.18)); }
@keyframes bob { 0%,100% { transform: translateY(0); } 50% { transform: translateY(-5px); } }
@media (prefers-reduced-motion: reduce) { .logo { animation: none; } }
h1 { font-size: 30px; margin: 0; letter-spacing: .5px; line-height: 1.05; }
.sub { margin: 4px 0 0; font-size: 15px; opacity: .95; }

.wrap { max-width: 620px; margin: -22px auto 0; padding: 0 14px; position: relative; }

/* Schede */
.card {
  background: var(--card); border: 2px solid var(--line); border-radius: 26px;
  padding: 16px; margin-bottom: 14px; box-shadow: var(--shadow);
}
label.q, .q { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 17px; margin: 0 0 10px; }
.step {
  flex: none; width: 28px; height: 28px; border-radius: 50%; background: var(--brand); color: var(--on-brand);
  display: inline-flex; align-items: center; justify-content: center; font-size: 15px; font-weight: 800;
}
.n { color: var(--muted); font-weight: 400; font-size: 13px; }

input[type=text], input[type=password], textarea, select {
  width: 100%; padding: 14px 16px; font-size: 16px; border: 2px solid var(--line); border-radius: 18px;
  background: var(--field); color: var(--text); font-family: inherit; outline: none;
}
input[type=text]:focus, input[type=password]:focus, textarea:focus, select:focus { border-color: var(--brand); }
input.big {
  font-family: "Courier New", ui-monospace, monospace; font-size: 34px; font-weight: 800;
  letter-spacing: 4px; text-align: center; color: var(--brand-dark); background: var(--brand-soft);
  border: 3px solid var(--brand); border-radius: 18px; padding: 16px 10px;
}
textarea { min-height: 84px; resize: vertical; }
.row { display: flex; gap: 8px; flex-wrap: wrap; }
button { font-family: inherit; font-size: 16px; cursor: pointer; }

.btn {
  padding: 13px 18px; border-radius: 999px; border: 2px solid var(--brand); background: var(--card);
  color: var(--brand-dark); font-weight: 700;
}
.btn.primary {
  background: var(--brand); color: var(--on-brand); border-color: var(--brand);
  width: 100%; padding: 17px; font-size: 18px; letter-spacing: .3px;
  box-shadow: 0 8px 18px rgba(212, 32, 44, .35);
}
.btn.primary:active { transform: translateY(2px); box-shadow: 0 3px 8px rgba(212, 32, 44, .35); }
.btn:disabled { opacity: .5; }

.seg { display: flex; gap: 8px; }
.seg button {
  flex: 1; padding: 12px 6px; border: 2px solid var(--line); border-radius: 999px;
  background: var(--field); color: var(--text); font-weight: 600;
}
.seg button.on { border-color: var(--brand); background: var(--brand); color: var(--on-brand); }

.hint { font-size: 13px; color: var(--muted); margin: 8px 0 0; }
.msg { padding: 12px 14px; border-radius: 18px; font-size: 14px; margin-bottom: 12px; font-weight: 600; }
.msg.err { background: var(--red-bg); color: var(--red); }
.msg.ok { background: var(--green-bg); color: var(--green); }
.msg.warn { background: var(--amber-bg); color: var(--amber); }

.thumb { width: 100%; max-height: 200px; object-fit: cover; border-radius: 18px; margin-top: 10px; border: 2px solid var(--line); }

/* Letture */
.card.rec { border-left: 10px solid var(--brand); }
.rec-head { display: flex; justify-content: space-between; gap: 8px; align-items: flex-start; }
.rec-name { font-weight: 800; font-size: 18px; }
.rec-when { color: var(--muted); font-size: 12px; text-align: right; flex: none; }
.rec-val { font-family: "Courier New", ui-monospace, monospace; font-size: 30px; font-weight: 800; color: var(--brand-dark); margin: 6px 0 0; }
.rec-delta {
  display: inline-block; background: var(--brand-soft); color: var(--brand-dark);
  border-radius: 999px; padding: 4px 12px; font-size: 13px; font-weight: 700; margin: 6px 0;
}
.rec-who { color: var(--muted); font-size: 14px; margin: 2px 0 6px; }
.rec-text { white-space: pre-wrap; margin: 0 0 6px; }
.tag {
  display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: 12px; font-weight: 700;
  background: var(--brand); color: var(--on-brand); margin-left: 6px; vertical-align: middle;
}
.links { margin-top: 10px; display: flex; gap: 16px; flex-wrap: wrap; font-size: 14px; }
.links a, .links button { color: var(--brand-dark); background: none; border: none; padding: 0; text-decoration: underline; font-size: 14px; font-weight: 700; }
.links .del { color: var(--red); }

.empty { text-align: center; color: var(--muted); padding: 30px 10px; }
.empty svg { display: block; margin: 0 auto 8px; }
.bar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; gap: 8px; }
.bar select { width: auto; flex: 1; }
.count { color: var(--muted); font-size: 14px; font-weight: 700; }
.hidden { display: none !important; }

/* Barra in basso */
.nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 5;
  display: flex; justify-content: center; padding: 8px 12px calc(10px + env(safe-area-inset-bottom, 0px));
  pointer-events: none;
}
.nav-in {
  pointer-events: auto; display: flex; gap: 6px; width: 100%; max-width: 440px;
  background: var(--card); border: 2px solid var(--line); border-radius: 999px; padding: 6px;
  box-shadow: 0 10px 28px rgba(0,0,0,.18);
}
.tab {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 8px 4px; border: none; background: transparent; color: var(--muted);
  border-radius: 999px; font-size: 12px; font-weight: 700;
}
.tab svg { width: 22px; height: 22px; }
.tab.on { background: var(--brand); color: var(--on-brand); }

.overlay { position: fixed; inset: 0; background: rgba(0,0,0,.85); display: flex; align-items: center; justify-content: center; padding: 12px; z-index: 10; }
.overlay img { max-width: 100%; max-height: 100%; border-radius: 18px; }

/* ===== Versione per uso in reparto: testi, numeri e tasti grandi ===== */
body { font-size: 20px; padding-bottom: 132px; }
h1 { font-size: 38px; }
.sub { font-size: 19px; }
.hero { padding: 22px 18px 44px; }
label.q, .q { font-size: 23px; line-height: 1.2; }
.step { width: 42px; height: 42px; font-size: 24px; }
.n { font-size: 16px; }
input[type=text], input[type=password], textarea, select { font-size: 22px; padding: 18px; border-radius: 20px; }
input.big { font-size: 58px; padding: 22px 10px; letter-spacing: 6px; }
textarea { min-height: 120px; }
.btn { min-height: 68px; font-size: 22px; padding: 16px 24px; }
.btn.primary { min-height: 88px; font-size: 27px; }
.seg button { min-height: 68px; font-size: 22px; }
.hint { font-size: 17px; }
#lastHint { font-size: 20px; font-weight: 700; color: var(--brand-dark); }
.msg { font-size: 19px; padding: 16px; }
.card { padding: 18px; }
.rec-name { font-size: 26px; }
.rec-when { font-size: 15px; }
.rec-val { font-size: 46px; }
.rec-delta { font-size: 19px; padding: 6px 16px; }
.rec-who { font-size: 18px; }
.rec-text { font-size: 20px; }
.tag { font-size: 15px; }
.count { font-size: 19px; }
.links { gap: 12px; }
.links a, .links button {
  font-size: 18px; min-height: 54px; display: inline-flex; align-items: center; padding: 0 18px;
  border: 2px solid var(--line); border-radius: 999px; text-decoration: none; background: var(--card);
}
.nav-in { max-width: 540px; }
.tab { font-size: 15px; min-height: 74px; padding: 10px 4px; }
.tab svg { width: 32px; height: 32px; }
.mbtns { display: flex; flex-direction: column; gap: 10px; }
.mbtn {
  width: 100%; min-height: 78px; padding: 14px 20px; border: 3px solid var(--line); border-radius: 22px;
  background: var(--field); color: var(--text); font-size: 25px; font-weight: 800;
  display: flex; justify-content: space-between; align-items: center; text-align: left;
}
.mbtn small { font-size: 16px; font-weight: 700; color: var(--muted); }
.mbtn.on { border-color: var(--brand); background: var(--brand); color: var(--on-brand); }
.mbtn.on small { color: var(--on-brand); }

/* ===== Produzione: accesso, utenze, letture in coda senza rete ===== */
.view { margin-top: 30px; }
.mt10 { margin-top: 10px; }
.full { width: 100%; }
.count { margin-bottom: 10px; }
.account {
  position: absolute; top: 12px; right: 12px; z-index: 1;
  max-width: 42%; min-height: 48px; padding: 8px 16px; border-radius: 999px;
  border: 2px solid rgba(255, 255, 255, .75); background: rgba(255, 255, 255, .16); color: var(--on-brand);
  font-size: 17px; font-weight: 800; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.lbl { display: block; font-weight: 700; font-size: 19px; margin: 16px 0 8px; }
.q + .lbl, .hint + .lbl { margin-top: 4px; }
.linkbtn {
  background: none; border: none; padding: 14px 0 2px; color: var(--brand-dark);
  font-weight: 700; font-size: 17px; text-decoration: underline;
}
.msg .btn { display: block; margin-top: 12px; }
.secret {
  margin: 12px 0; padding: 14px 10px; text-align: center; word-break: break-all;
  font-family: "Courier New", ui-monospace, monospace; font-size: 30px; font-weight: 800; letter-spacing: 2px;
  color: var(--brand-dark); background: var(--card); border: 3px dashed var(--brand); border-radius: 18px;
  -webkit-user-select: all; user-select: all;
}
.tag.soft { background: var(--brand-soft); color: var(--brand-dark); }
.tag.off { background: var(--line); color: var(--muted); }
.card.rec.pending { border-left-color: var(--amber); }
.rec-err { color: var(--red); font-weight: 700; margin: 4px 0 6px; }
.links button:disabled { opacity: .5; }
.tab span { line-height: 1.1; text-align: center; }
.nav-in.four { gap: 4px; }
.nav-in.four .tab { font-size: 13px; padding: 8px 2px; }
.nav-in.four .tab svg { width: 28px; height: 28px; }
