:root {
  --bg: #f4f5f7;
  --card: #ffffff;
  --ink: #1f2933;
  --muted: #5f6b7a;
  --line: #e1e5ea;
  --brand: #2f6f8f;
  --brand-ink: #ffffff;
  --brand-soft: #e3eff5;
  --ok: #2e7d4f;
  --ok-soft: #e4f3ea;
  --warn: #b26a00;
  --warn-soft: #fff3df;
  --err: #b3261e;
  --err-soft: #fbe7e5;
  --mal: #b3261e;
  --pr: #7a4fb3;
  --pnr: #8a6d3b;
  --str: #1d7a8c;
  --acc: #2e7d4f;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .1);
  font-size: 16px;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg); color: var(--ink); line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.35rem; margin: 0 0 .75rem; }
h2 { font-size: 1.1rem; margin: 1.25rem 0 .5rem; }
h3 { font-size: 1rem; margin: 1rem 0 .4rem; }
p { margin: .4rem 0; }
small, .muted { color: var(--muted); }
.small { font-size: .85rem; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.center { text-align: center; }
.mt { margin-top: 1rem; }
.mb { margin-bottom: 1rem; }
.hide-mobile { display: none; }
@media (min-width: 720px) { .hide-mobile { display: initial; } .hide-desktop { display: none !important; } }

/* Header */
.topbar {
  background: var(--brand); color: var(--brand-ink);
  position: sticky; top: 0; z-index: 10; box-shadow: var(--shadow);
}
.topbar .inner {
  max-width: 1100px; margin: 0 auto; padding: .55rem .9rem;
  display: flex; align-items: center; justify-content: space-between; gap: .75rem;
}
.topbar .brand { font-weight: 700; letter-spacing: .2px; color: #fff; font-size: 1.05rem; }
.topbar .brand small { display: block; font-weight: 400; font-size: .72rem; opacity: .85; color: #fff; }
.topbar .user { font-size: .85rem; opacity: .95; display: flex; gap: .6rem; align-items: center; }
.topbar .user form { margin: 0; }
.nav {
  background: #fff; border-bottom: 1px solid var(--line);
  overflow-x: auto; -webkit-overflow-scrolling: touch;
}
.nav .inner { max-width: 1100px; margin: 0 auto; padding: 0 .5rem; display: flex; gap: .15rem; white-space: nowrap; }
.nav a {
  display: inline-block; padding: .65rem .7rem; color: var(--muted); font-size: .92rem;
  border-bottom: 3px solid transparent;
}
.nav a.attivo { color: var(--brand); border-bottom-color: var(--brand); font-weight: 600; }
.nav a:hover { text-decoration: none; color: var(--brand); }

main { max-width: 1100px; margin: 0 auto; padding: 1rem .9rem 3rem; }

/* Cards & tables */
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1rem; margin-bottom: 1rem; }
.card.compact { padding: .75rem; }
.card h2:first-child, .card h1:first-child { margin-top: 0; }
.grid { display: grid; gap: 1rem; }
@media (min-width: 820px) { .grid.cols-2 { grid-template-columns: 1fr 1fr; } .grid.cols-3 { grid-template-columns: 1fr 1fr 1fr; } }

table { width: 100%; border-collapse: collapse; font-size: .93rem; }
th, td { padding: .5rem .5rem; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
th { font-weight: 600; color: var(--muted); font-size: .8rem; text-transform: uppercase; letter-spacing: .3px; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
tr.tot td { font-weight: 700; border-top: 2px solid var(--ink); }
.table-wrap { overflow-x: auto; }
tbody tr:hover { background: #fafbfc; }

/* Badges */
.badge {
  display: inline-block; padding: .1rem .5rem; border-radius: 999px; font-size: .75rem; font-weight: 600;
  background: var(--brand-soft); color: var(--brand); white-space: nowrap; vertical-align: middle;
}
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.err { background: var(--err-soft); color: var(--err); }
.badge.grey { background: #eceff3; color: var(--muted); }
.badge.mal { background: #fbe7e5; color: var(--mal); }
.badge.pr { background: #efe7fb; color: var(--pr); }
.badge.pnr { background: #f5efe3; color: var(--pnr); }
.badge.str { background: #e0f2f5; color: var(--str); }
.badge.acc { background: #e4f3ea; color: var(--acc); }

/* Flash */
.flash { padding: .7rem .9rem; border-radius: var(--radius); margin-bottom: .8rem; font-size: .95rem; border: 1px solid transparent; }
.flash.ok { background: var(--ok-soft); color: var(--ok); border-color: #bfe3cc; }
.flash.err { background: var(--err-soft); color: var(--err); border-color: #f1c2be; }
.flash.info { background: var(--brand-soft); color: var(--brand); border-color: #bcd6e3; }
.flash ul { margin: .3rem 0 0 1rem; padding: 0; }

/* Forms */
label { display: block; font-size: .85rem; color: var(--muted); margin: .6rem 0 .2rem; font-weight: 600; }
input[type=text], input[type=password], input[type=email], input[type=number], input[type=date], input[type=month], select, textarea {
  width: 100%; padding: .6rem .65rem; border: 1px solid #c9d1da; border-radius: 8px; font-size: 1rem; background: #fff; color: var(--ink);
}
textarea { min-height: 70px; resize: vertical; font-family: inherit; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand); outline-offset: 1px; border-color: var(--brand); }
.field-row { display: flex; gap: .6rem; flex-wrap: wrap; }
.field-row > * { flex: 1 1 140px; }
.check { display: flex; align-items: center; gap: .5rem; font-weight: 400; color: var(--ink); margin-top: .6rem; }
.check input { width: 1.1rem; height: 1.1rem; }

.btn {
  display: inline-block; padding: .6rem 1rem; border-radius: 8px; border: 1px solid var(--brand);
  background: var(--brand); color: #fff; font-size: .95rem; font-weight: 600; cursor: pointer; text-decoration: none;
  line-height: 1.2;
}
.btn:hover { filter: brightness(1.05); text-decoration: none; }
.btn.secondary { background: #fff; color: var(--brand); }
.btn.ok { background: var(--ok); border-color: var(--ok); }
.btn.warn { background: var(--warn); border-color: var(--warn); }
.btn.danger { background: #fff; color: var(--err); border-color: #e4b4b0; }
.btn.small { padding: .35rem .65rem; font-size: .82rem; }
.btn.block { display: block; width: 100%; text-align: center; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.actions { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; margin-top: .8rem; }
form.inline { display: inline; }

/* Chips per le ore rapide */
.chips { display: flex; gap: .4rem; flex-wrap: wrap; margin-top: .4rem; }
.chip { padding: .35rem .7rem; border-radius: 999px; border: 1px solid #c9d1da; background: #fff; font-size: .9rem; cursor: pointer; }
.chip:hover { border-color: var(--brand); color: var(--brand); }

/* Mese: intestazione e navigazione */
.mese-head { display: flex; align-items: center; justify-content: space-between; gap: .5rem; margin-bottom: .75rem; }
.mese-head h1 { margin: 0; }
.mese-head .navmese { display: flex; gap: .4rem; align-items: center; }
.kpi { display: grid; grid-template-columns: repeat(2, 1fr); gap: .5rem; }
@media (min-width: 720px) { .kpi { grid-template-columns: repeat(4, 1fr); } }
.kpi .box { background: #fff; border-radius: var(--radius); box-shadow: var(--shadow); padding: .65rem .8rem; }
.kpi .box .lbl { font-size: .72rem; color: var(--muted); text-transform: uppercase; letter-spacing: .3px; }
.kpi .box .val { font-size: 1.25rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.kpi .box .val small { font-size: .8rem; font-weight: 400; color: var(--muted); }

/* Elenco giorni del mese */
.giorni { list-style: none; margin: 0; padding: 0; }
.giorno {
  display: grid; grid-template-columns: 3.2rem 1fr auto; gap: .5rem; align-items: center;
  padding: .55rem .6rem; border-bottom: 1px solid var(--line); background: #fff;
}
.giorno:first-child { border-radius: var(--radius) var(--radius) 0 0; }
.giorno:last-child { border-radius: 0 0 var(--radius) var(--radius); border-bottom: 0; }
.giorno.weekend { background: #f8f9fb; }
.giorno.nolavoro .num, .giorno.nolavoro .dow { color: #a4adb8; }
.giorno.oggi .data { outline: 2px solid var(--brand); outline-offset: 2px; border-radius: 6px; }
.giorno .data { text-align: center; line-height: 1.1; }
.giorno .num { font-size: 1.15rem; font-weight: 700; display: block; }
.giorno .dow { font-size: .7rem; text-transform: uppercase; color: var(--muted); }
.giorno .info { min-width: 0; }
.giorno .info .tipo { font-size: .8rem; color: var(--muted); }
.giorno .regs { display: flex; flex-wrap: wrap; gap: .3rem; margin-top: .2rem; }
.giorno .ore { text-align: right; font-variant-numeric: tabular-nums; }
.giorno .ore .eff { font-weight: 700; font-size: 1.05rem; }
.giorno .ore .prev { font-size: .75rem; color: var(--muted); }
.giorno a.apri { display: block; color: inherit; }
.giorno a.apri:hover { text-decoration: none; }

/* Dashboard stato mesi */
.stato { display: inline-block; min-width: 2.2rem; text-align: center; padding: .15rem .35rem; border-radius: 6px; font-size: .75rem; font-weight: 700; white-space: nowrap; }
.stato.aperto { background: #eceff3; color: var(--muted); }
.stato.ritardo { background: var(--err-soft); color: var(--err); }
.stato.validato { background: var(--warn-soft); color: var(--warn); }
.stato.chiuso { background: var(--ok-soft); color: var(--ok); }
.stato.na { background: transparent; color: #c3cad3; }
.legenda { display: flex; gap: .8rem; flex-wrap: wrap; font-size: .82rem; color: var(--muted); margin-top: .5rem; }

/* Login */
.auth-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 1rem; }
.auth-card { background: #fff; border-radius: 14px; box-shadow: var(--shadow); padding: 1.5rem; width: 100%; max-width: 380px; }
.auth-card h1 { text-align: center; margin-bottom: .2rem; }
.auth-card .sub { text-align: center; color: var(--muted); margin-bottom: 1rem; font-size: .9rem; }

details summary { cursor: pointer; color: var(--brand); font-weight: 600; margin: .5rem 0; }
pre { white-space: pre-wrap; word-break: break-word; font-size: .8rem; background: #f6f7f9; padding: .6rem; border-radius: 8px; }
code { background: #f1f3f5; padding: .05rem .3rem; border-radius: 4px; font-size: .9em; }
.footer { text-align: center; color: var(--muted); font-size: .78rem; margin-top: 2rem; }
@media print {
  .topbar, .nav, .actions, .btn, .footer { display: none !important; }
  body { background: #fff; }
  .card { box-shadow: none; border: 1px solid #ccc; }
}
