:root {
  --main: #1f6f5c;          /* verde bosco */
  --main-dark: #17574a;
  --accent: #f4b942;
  --bg: #f4f3ef;
  --card: #ffffff;
  --text: #1f2a2a;
  --muted: #66736f;
  --line: #e4e2dc;
  --ok: #2e8b57;
  --ok-bg: #e2f3e9;
  --warn: #b26a00;
  --warn-bg: #fff2d6;
  --bad: #c0392b;
  --bad-bg: #fbe5e2;
  --soft: #f1f0ea;
  --radius: 14px;
  --tabbar: 64px;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg); color: var(--text); font-size: 16px; line-height: 1.4;
  -webkit-text-size-adjust: 100%; -webkit-tap-highlight-color: transparent;
}
a { color: var(--main); }
h1, h2, h3 { margin: 0 0 8px; line-height: 1.2; }
h2 { font-size: 20px; }
h3 { font-size: 16px; }
.loading { padding: 40px; text-align: center; color: var(--muted); }

/* Testata e barra in basso */
header.top {
  position: sticky; top: 0; z-index: 10; background: var(--main); color: #fff;
  padding: calc(env(safe-area-inset-top) + 10px) 14px 10px; display: flex; align-items: center; gap: 10px;
}
header.top .brand { font-weight: 700; font-size: 19px; flex: 1; display: flex; align-items: center; gap: 8px; color: #fff; text-decoration: none; }
header.top .hlogo { width: 34px; height: 34px; border-radius: 9px; }
header.top .who { font-size: 13px; opacity: .85; }
header.top .gear { font-size: 22px; text-decoration: none; padding: 2px 4px; }
main { padding: 12px 12px calc(var(--tabbar) + env(safe-area-inset-bottom) + 20px); max-width: 720px; margin: 0 auto; }
nav.tabs {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 10; background: #fff; border-top: 1px solid var(--line);
  display: flex; padding-bottom: env(safe-area-inset-bottom);
}
nav.tabs a {
  flex: 1; text-align: center; text-decoration: none; color: var(--muted); font-size: 11px; min-width: 0;
  white-space: nowrap; padding: 8px 0 6px; height: var(--tabbar); position: relative;
}
nav.tabs a .ico { display: block; font-size: 22px; line-height: 28px; }
nav.tabs a.active { color: var(--main); font-weight: 700; }
nav.tabs a.active::before { content: ""; position: absolute; top: 0; left: 25%; right: 25%; height: 3px; border-radius: 0 0 3px 3px; background: var(--accent); }

/* Schede */
.card { background: var(--card); border-radius: var(--radius); padding: 14px; margin-bottom: 12px; box-shadow: 0 1px 2px rgba(0,0,0,.05); }
.card.error { background: var(--bad-bg); color: var(--bad); }
.card.hint { background: #fff8e6; }
.muted { color: var(--muted); font-size: 14px; }
.small { font-size: 13px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row > * { flex: 1; min-width: 0; }
.spacer { flex: 1; }
.right { text-align: right; }
.center { text-align: center; }
.head-row { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.head-row h2, .head-row h3 { flex: 1; margin: 0; }

/* Moduli */
label { display: block; font-size: 14px; color: var(--muted); margin: 12px 0 4px; }
input, select, textarea {
  width: 100%; font: inherit; font-size: 16px; padding: 11px 12px; border: 1px solid #d3d0c8;
  border-radius: 10px; background: #fff; color: var(--text); -webkit-appearance: none; appearance: none;
}
input.big { font-size: 26px; font-weight: 700; padding: 10px 12px; }
select { background-image: linear-gradient(45deg, transparent 50%, #888 50%), linear-gradient(135deg, #888 50%, transparent 50%);
  background-position: calc(100% - 18px) 50%, calc(100% - 13px) 50%; background-size: 5px 5px; background-repeat: no-repeat; padding-right: 32px; }
textarea { min-height: 64px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--main); border-color: transparent; }
.check { display: flex; align-items: center; gap: 10px; color: var(--text); font-size: 16px; margin: 10px 0; }
.check input { width: 22px; height: 22px; -webkit-appearance: checkbox; appearance: auto; flex: none; accent-color: var(--main); }
.check small { color: var(--muted); display: block; }

button, .btn {
  font: inherit; font-weight: 600; border: 0; border-radius: 10px; padding: 12px 16px; cursor: pointer;
  background: var(--main); color: #fff; display: inline-block; text-align: center; text-decoration: none;
}
button:active, .btn:active { opacity: .8; }
button[disabled] { opacity: .5; }
.btn-block { width: 100%; margin-top: 14px; display: block; }
.btn-light { background: var(--soft); color: var(--main); }
.btn-ok { background: var(--ok); color: #fff; }
.btn-bad { background: var(--bad); color: #fff; }
.btn-small { padding: 7px 11px; font-size: 14px; }
.btn-link { background: none; color: var(--main); padding: 6px 4px; font-weight: 500; }
.btns { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.btns > * { flex: 1; }

.seg { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 4px; }
.seg button { flex: 1; background: var(--soft); color: var(--text); font-weight: 500; padding: 11px 8px; font-size: 15px; min-width: 90px; }
.seg button.on { background: var(--main); color: #fff; }
.seg3 { display: flex; gap: 6px; padding: 0 10px 8px; }
.seg3 button { flex: 1; background: #333; color: #fff; font-size: 13px; padding: 8px 4px; font-weight: 500; }
.seg3 button.on { background: #ffd21f; color: #111; }

/* Mese */
.month { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.month h2 { flex: 1; text-align: center; margin: 0; font-size: 18px; }
.month .btn { padding: 8px 16px; font-size: 18px; }

/* Liste */
.list { list-style: none; margin: 0; padding: 0; }
.list li { border-bottom: 1px solid var(--line); }
.list li:last-child { border-bottom: 0; }
.list .day-h { font-size: 13px; color: var(--muted); font-weight: 600; padding: 12px 0 4px; border-bottom: 0; }
a.item { display: flex; gap: 12px; align-items: center; text-decoration: none; color: var(--text); padding: 11px 0; }
a.item .ic { font-size: 22px; width: 40px; height: 40px; border-radius: 12px; background: var(--soft); display: flex; align-items: center; justify-content: center; flex: none; }
a.item .tx { flex: 1; min-width: 0; }
a.item .tx b { display: block; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
a.item .tx span { font-size: 13px; color: var(--muted); }
a.item .am { text-align: right; font-weight: 700; white-space: nowrap; }
a.item .am small { display: block; font-weight: 400; font-size: 12px; color: var(--muted); }
.pill { display: inline-block; font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 20px; background: var(--soft); color: var(--muted); }
.pill.warn { background: var(--warn-bg); color: var(--warn); }
.pill.ok { background: var(--ok-bg); color: var(--ok); }
.pill.bad { background: var(--bad-bg); color: var(--bad); }
.pill.grp { background: #e3efec; color: var(--main); }

/* Numeri */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); gap: 8px; }
.stat { background: var(--soft); border-radius: 12px; padding: 10px; }
.stat .v { font-size: 20px; font-weight: 700; }
.stat .l { font-size: 12px; color: var(--muted); }
.stat.big { background: var(--main); color: #fff; }
.stat.big .l { color: #d9ebe6; }
.pos { color: var(--ok); }
.neg { color: var(--bad); }
.bal { font-size: 18px; font-weight: 700; margin: 4px 0; }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 6px; vertical-align: 0; }

/* Barre del riepilogo */
.bars .b { margin: 10px 0; }
.bars .b .t { display: flex; justify-content: space-between; font-size: 15px; gap: 8px; }
.bars .b .t span:last-child { font-weight: 700; white-space: nowrap; }
.bars .b .bg { height: 10px; border-radius: 6px; background: var(--soft); margin-top: 4px; overflow: hidden; }
.bars .b .bg i { display: block; height: 100%; background: var(--main); border-radius: 6px; }
.chart { display: flex; align-items: flex-end; gap: 4px; height: 120px; margin-top: 10px; }
.chart a { flex: 1; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; height: 100%; text-decoration: none; color: var(--muted); font-size: 10px; }
.chart a i { display: block; width: 100%; background: #bcd8d0; border-radius: 4px 4px 0 0; min-height: 2px; }
.chart a.on i { background: var(--main); }
.chart a.on { color: var(--text); font-weight: 700; }

/* Foto */
.photos { display: grid; grid-template-columns: repeat(auto-fill, minmax(90px, 1fr)); gap: 8px; margin-top: 8px; }
.photos .ph { position: relative; }
.photos img { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 10px; display: block; background: var(--soft); }
.photos .ph button { position: absolute; top: 4px; right: 4px; padding: 2px 8px; font-size: 13px; background: rgba(0,0,0,.6); border-radius: 12px; }
.pdfbox { display: flex; flex-direction: column; align-items: center; justify-content: center; aspect-ratio: 1; background: var(--soft); border-radius: 10px; text-decoration: none; color: var(--text); font-size: 30px; }
.pdfbox span { font-size: 11px; }

/* Bottone + */
.fab {
  position: fixed; right: 16px; bottom: calc(var(--tabbar) + env(safe-area-inset-bottom) + 16px); z-index: 9;
  border-radius: 30px; padding: 14px 20px; font-size: 16px; box-shadow: 0 4px 14px rgba(0,0,0,.25); background: var(--accent); color: #2b2200;
}

/* Schede secondarie */
.tabs2 { display: flex; gap: 6px; margin: 0 0 12px; overflow-x: auto; }
.tabs2 a { flex: 1; text-align: center; white-space: nowrap; padding: 9px 10px; border-radius: 20px; background: #fff; color: var(--text); text-decoration: none; font-size: 14px; box-shadow: 0 1px 2px rgba(0,0,0,.05); }
.tabs2 a.on { background: var(--main); color: #fff; font-weight: 600; }

.linkbox { background: var(--soft); border-radius: 10px; padding: 10px; word-break: break-all; font-size: 14px; margin: 8px 0; user-select: all; }
.steps { padding-left: 22px; margin: 6px 0; }
.steps li { margin: 6px 0; }

/* Login */
.login { max-width: 380px; margin: 0 auto; padding: calc(env(safe-area-inset-top) + 40px) 20px 40px; }
.login .logo { text-align: center; margin-bottom: 20px; }
.login .logo img { width: 96px; height: 96px; border-radius: 24px; box-shadow: 0 2px 8px rgba(0,0,0,.1); }
.login .logo h1 { font-size: 24px; margin-top: 10px; }

#toast {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--tabbar) + env(safe-area-inset-bottom) + 14px);
  background: #222; color: #fff; padding: 10px 16px; border-radius: 20px; z-index: 2000; font-size: 15px; max-width: 90%;
  box-shadow: 0 4px 14px rgba(0,0,0,.25);
}
#toast.err { background: var(--bad); }

/* Scansione */
.scanov { position: fixed; inset: 0; z-index: 1000; background: #111; color: #fff; display: flex; flex-direction: column; padding-top: env(safe-area-inset-top); padding-bottom: env(safe-area-inset-bottom); }
.scanov .bar { display: flex; gap: 8px; padding: 10px; align-items: center; flex-wrap: wrap; }
.scanov .bar .sp { flex: 1; }
.scanov .stage { flex: 1; position: relative; overflow: hidden; touch-action: none; }
.scanov canvas { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); max-width: 100%; max-height: 100%; }
.scanov .hint { font-size: 13px; opacity: .8; padding: 0 12px 6px; }
.scanov button { margin: 0; }
