:root {
  --blue: #141414;            /* colore principale (nero) */
  --blue-dark: #000000;
  --yellow: #ffd200;
  --bg: #f3f5f8;
  --card: #ffffff;
  --text: #1c2430;
  --muted: #667085;
  --line: #e2e6ec;
  --ok: #2e9e5b;
  --ok-bg: #e3f5ea;
  --warn: #c77700;
  --warn-bg: #fff3d6;
  --bad: #c62f2f;
  --bad-bg: #fde7e7;
  --vac: #1f7fd1;
  --vac-bg: #e1effc;
  --school: #7a4cc2;
  --school-bg: #efe7fb;
  --off-bg: #eceff3;
  --radius: 12px;
  --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(--blue); }
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(--blue); color: #fff;
  padding: calc(env(safe-area-inset-top) + 10px) 16px 10px;
  display: flex; align-items: center; gap: 10px;
}
header.top .brand { font-weight: 700; font-size: 18px; flex: 1; }
header.top .brand { display: flex; align-items: center; gap: 8px; }
header.top .hlogo { width: 38px; height: 38px; }
header.top .who { font-size: 13px; opacity: .85; }
main { padding: 12px 12px calc(var(--tabbar) + env(safe-area-inset-bottom) + 16px); max-width: 760px; 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: 10.5px; 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(--blue); font-weight: 600; }
nav.tabs a.active::before { content: ""; position: absolute; top: 0; left: 25%; right: 25%; height: 3px; border-radius: 0 0 3px 3px; background: var(--yellow); }
.badge {
  position: absolute; top: 4px; left: 50%; margin-left: 8px;
  background: var(--bad); color: #fff; border-radius: 10px; font-size: 11px;
  min-width: 18px; padding: 0 5px; line-height: 18px; font-weight: 700;
}

/* 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); }
.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; }

/* Moduli */
label { display: block; font-size: 14px; color: var(--muted); margin: 10px 0 4px; }
input, select, textarea {
  width: 100%; font: inherit; font-size: 16px; padding: 11px 12px; border: 1px solid #cfd5dd;
  border-radius: 10px; background: #fff; color: var(--text); -webkit-appearance: none; appearance: none;
}
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: 70px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--blue); border-color: transparent; }
.check { display: flex; align-items: center; gap: 10px; color: var(--text); font-size: 16px; margin: 12px 0; }
.check input { width: 22px; height: 22px; -webkit-appearance: checkbox; appearance: auto; flex: none; }

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

.segmented { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-top: 6px; }
.segmented button { background: #eef1f5; color: var(--text); font-weight: 500; padding: 12px 6px; font-size: 15px; }
.segmented button.on { background: var(--blue); color: #fff; }

/* Calendario */
.cal-head { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.cal-head h2 { flex: 1; text-align: center; margin: 0; font-size: 18px; }
.cal-head button { padding: 8px 14px; font-size: 18px; }
.grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.grid .dow { text-align: center; font-size: 12px; color: var(--muted); padding: 2px 0; }
.day {
  background: #fff; border-radius: 8px; min-height: 56px; padding: 4px; font-size: 12px;
  display: flex; flex-direction: column; align-items: center; justify-content: flex-start;
  text-decoration: none; color: var(--text); border: 2px solid transparent; overflow: hidden;
}
.day .n { font-weight: 700; font-size: 15px; }
.day .t { font-size: 10.5px; line-height: 1.15; text-align: center; margin-top: 2px; word-break: break-word; }
.day.blank { background: transparent; }
.day.off { background: var(--off-bg); color: #8a94a3; }
.day.ok { background: var(--ok-bg); }
.day.part { background: var(--warn-bg); }
.day.sick { background: var(--bad-bg); }
.day.vac { background: var(--vac-bg); }
.day.pend { background: repeating-linear-gradient(45deg, #fff, #fff 5px, var(--vac-bg) 5px, var(--vac-bg) 10px); }
.day.school { background: var(--school-bg); }
.day.closure { background: #e4e4e4; color: var(--blue); }
.day.missing { background: #fff; border-color: #f2b8b8; }
.day.today { border-color: var(--blue); }
.day .dots { display: flex; gap: 2px; margin-top: auto; padding-top: 2px; }
.day .dots i, .legend i.dot { width: 7px; height: 7px; border-radius: 50%; display: inline-block; }
.dots i.approved, .legend i.dot.approved { background: var(--vac); }
.dots i.pending, .legend i.dot.pending { background: #fff; border: 1.5px solid var(--vac); }
.legend i.dot { width: 9px; height: 9px; vertical-align: 0; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 12px; font-size: 12px; color: var(--muted); margin-top: 10px; }
.legend i { display: inline-block; width: 12px; height: 12px; border-radius: 3px; vertical-align: -2px; margin-right: 4px; }

/* Liste */
.list { list-style: none; margin: 0; padding: 0; }
.list li { padding: 12px 0; border-bottom: 1px solid var(--line); }
.list li:last-child { border-bottom: 0; }
.list a.item { display: flex; gap: 10px; align-items: center; text-decoration: none; color: var(--text); }
.pill { display: inline-block; font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 20px; background: #eef1f5; color: var(--muted); }
.pill.pending { background: var(--warn-bg); color: var(--warn); }
.pill.approved { background: var(--ok-bg); color: var(--ok); }
.pill.rejected { background: var(--bad-bg); color: var(--bad); }
.pill.cancelled { background: #eee; color: #888; text-decoration: line-through; }
.pill.admin { background: #fff4cc; color: #8a6200; }

/* Numeri */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(100px, 1fr)); gap: 8px; }
.stat { background: #f6f8fb; border-radius: 10px; padding: 10px; }
.stat .v { font-size: 22px; font-weight: 700; }
.stat .l { font-size: 12px; color: var(--muted); }
.stat.big .v { color: var(--blue); }
.pos { color: var(--ok); }
.neg { color: var(--bad); }

/* Tabelle */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; margin: 0 -14px; padding: 0 14px; }
table { border-collapse: collapse; width: 100%; font-size: 14px; }
th, td { padding: 8px 6px; border-bottom: 1px solid var(--line); text-align: right; white-space: nowrap; }
th:first-child, td:first-child { text-align: left; }
th { font-size: 12px; color: var(--muted); font-weight: 600; }
tfoot td { font-weight: 700; border-top: 2px solid var(--line); }

.msug { margin-top: 6px; border: 1px solid var(--line); border-radius: 10px; max-height: 260px; overflow-y: auto; background: var(--card, #fff); }
.msug button { display: block; width: 100%; text-align: left; background: none; color: inherit; border: 0; border-bottom: 1px solid var(--line); border-radius: 0; padding: 8px 10px; font-weight: normal; margin: 0; }
.msug button:last-child { border-bottom: 0; }
.msug button b { display: block; font-weight: 600; }
.photos { display: grid; grid-template-columns: repeat(auto-fill, minmax(90px, 1fr)); gap: 6px; }
.photos img { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 8px; display: block; background: var(--off-bg); }
.photos .ph { position: relative; }
.photos .ph button { position: absolute; top: 4px; right: 4px; padding: 2px 7px; font-size: 13px; background: rgba(0,0,0,.6); border-radius: 12px; }
.info { display: flex; flex-wrap: wrap; gap: 6px; margin: 6px 0; }
.calc { background: #f6f8fb; border-radius: 10px; padding: 10px 12px; margin-top: 12px; font-size: 15px; }

/* 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: 24px; }
.login .logo img { width: 110px; height: 110px; border-radius: 24px; background: #fff; box-shadow: 0 2px 8px rgba(0,0,0,.08); }
.login .logo h1 { font-size: 22px; 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: 50; font-size: 15px; max-width: 90%;
  box-shadow: 0 4px 14px rgba(0,0,0,.25);
}
#toast.err { background: var(--bad); }
