:root {
  --page: #f9f9f7;
  --surface: #ffffff;
  --surface-2: #f3f2ee;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #898781;
  --line: #e1e0d9;
  --line-strong: #c3c2b7;
  --accent: #1c5cab;
  --accent-hover: #184f95;
  --accent-soft: #e8f1fd;
  --good: #0ca30c;
  --good-text: #006300;
  --good-soft: #e9f7e9;
  --critical: #d03b3b;
  --critical-soft: #fdecec;
  --warning-soft: #fff5dc;
  --warning-line: #fab219;
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --series-3: #1baf7a;
  --series-4: #eda100;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(11, 11, 11, .06), 0 1px 1px rgba(11, 11, 11, .04);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--page); color: var(--ink);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; margin: 0 0 4px; line-height: 1.25; }
h2 { font-size: 16px; margin: 0 0 12px; }
p { margin: 0 0 12px; }
.muted { color: var(--ink-2); }
.small { font-size: 13px; }
.num { font-variant-numeric: tabular-nums; }
[hidden] { display: none !important; }

/* --- barra superiore --- */
.topbar {
  background: var(--surface); border-bottom: 1px solid var(--line);
  display: flex; align-items: center; gap: 8px 20px; flex-wrap: wrap; padding: 10px 20px;
}
.brand { font-weight: 700; color: var(--ink); white-space: nowrap; }
.brand span { font-weight: 400; color: var(--ink-2); }
.nav { display: flex; gap: 2px; flex-wrap: wrap; flex: 1; }
.nav a, .nav summary {
  padding: 6px 10px; border-radius: 6px; color: var(--ink-2); cursor: pointer; list-style: none;
  white-space: nowrap;
}
.nav summary::-webkit-details-marker { display: none; }
.nav a:hover, .nav summary:hover { background: var(--surface-2); text-decoration: none; color: var(--ink); }
.nav a.on, .nav details.on > summary { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.nav details { position: relative; }
.nav .menu {
  position: absolute; z-index: 20; top: calc(100% + 4px); left: 0; min-width: 190px; padding: 6px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 8px;
  box-shadow: 0 8px 24px rgba(11, 11, 11, .12); display: grid;
}
.nav-sep { width: 1px; background: var(--line); margin: 4px 6px; }
.who { display: flex; align-items: center; gap: 12px; font-size: 13px; color: var(--ink-2); }
.who button { background: none; border: 0; padding: 0; color: var(--accent); cursor: pointer; font: inherit; }
.who button:hover { text-decoration: underline; }

.wrap { max-width: 1180px; margin: 0 auto; padding: 22px 20px 60px; }
.wrap.narrow { max-width: 720px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px 20px; flex-wrap: wrap; margin-bottom: 18px; }
.page-head p { margin: 0; }

/* --- componenti --- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; }
.card + .card { margin-top: 16px; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; cursor: pointer;
  font: inherit; font-weight: 600; padding: 8px 14px; border-radius: 8px; white-space: nowrap;
  border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink);
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-hover); }
.btn.danger { color: var(--critical); border-color: #e9b4b4; }
.btn.danger:hover { background: var(--critical-soft); }
.btn.big { padding: 12px 22px; font-size: 16px; }
.btn.sm { padding: 4px 10px; font-size: 13px; font-weight: 500; }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.chip {
  display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12.5px; font-weight: 600;
  background: var(--surface-2); color: var(--ink-2); white-space: nowrap;
}
.chip.accent { background: var(--accent-soft); color: var(--accent); }
.chip.warn { background: var(--warning-soft); color: #6b4a00; }

.messages { list-style: none; padding: 0; margin: 0 0 16px; display: grid; gap: 8px; }
.messages li { padding: 10px 14px; border-radius: 8px; border: 1px solid var(--line); background: var(--surface); }
.messages li.success { background: var(--good-soft); border-color: #bfe5bf; color: var(--good-text); }
.messages li.error { background: var(--critical-soft); border-color: #f0c2c2; color: #8f1f1f; }

table { border-collapse: collapse; width: 100%; }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 12.5px; font-weight: 600; color: var(--ink-2); white-space: nowrap; }
td.r, th.r { text-align: right; }
tbody tr:last-child td { border-bottom: 0; }
tr.inactive td { color: var(--muted); }
tr.clickable:hover td { background: var(--surface-2); }
.table-scroll { overflow-x: auto; }
.empty { padding: 26px 10px; text-align: center; color: var(--ink-2); }

/* --- form --- */
label { font-weight: 600; font-size: 13.5px; display: block; margin-bottom: 4px; }
input[type=text], input[type=password], input[type=email], input[type=number], input[type=date],
input[type=time], input[type=search], select, textarea {
  width: 100%; font: inherit; color: var(--ink); background: var(--surface);
  border: 1px solid var(--line-strong); border-radius: 8px; padding: 8px 10px;
}
input:focus, select:focus, textarea:focus, button:focus-visible, a:focus-visible, summary:focus-visible {
  outline: 2px solid var(--series-1); outline-offset: 1px;
}
.field { margin-bottom: 14px; }
.field .help { font-size: 12.5px; color: var(--ink-2); margin-top: 4px; }
.field .errorlist, .errorlist { list-style: none; padding: 0; margin: 4px 0 0; color: var(--critical); font-size: 13px; }
.field.check label { display: flex; gap: 8px; align-items: center; font-weight: 500; }
.field.check input { width: auto; }
.field ul { list-style: none; padding: 0; margin: 0; }
.checks > div, .checks ul { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 4px 14px; }
.checks label { display: flex; gap: 8px; align-items: center; font-weight: 400; margin: 0; }
.checks input { width: auto; }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 0 14px; }
.form-error { background: var(--critical-soft); border: 1px solid #f0c2c2; color: #8f1f1f; padding: 10px 14px; border-radius: 8px; margin-bottom: 14px; }
.form-error ul { list-style: none; margin: 0; padding: 0; }

/* --- accesso --- */
.login { max-width: 400px; margin: 8vh auto 0; padding: 0 20px; }
.login.wide { max-width: 760px; }
.login h1 { text-align: center; margin-bottom: 4px; }
.login .sub { text-align: center; color: var(--ink-2); margin-bottom: 20px; }
.people { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.person {
  font: inherit; cursor: pointer; padding: 16px 10px; border-radius: var(--radius); text-align: center;
  border: 1px solid var(--line-strong); background: var(--surface);
}
.person strong { display: block; font-size: 17px; }
.person span { font-size: 12.5px; color: var(--ink-2); }
.person:hover { background: var(--surface-2); }
.person.on { border-color: var(--accent); background: var(--accent-soft); box-shadow: inset 0 0 0 1px var(--accent); }
.pin-box { max-width: 260px; margin: 18px auto 0; text-align: center; }
.pin-box input { text-align: center; font-size: 26px; letter-spacing: .4em; }

/* --- timer dipendente --- */
.identity { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; margin-bottom: 14px; }
.identity h1 { margin: 0; font-size: 26px; }
.now {
  display: grid; grid-template-columns: 1fr auto; gap: 8px 20px; align-items: center;
  border-left: 4px solid var(--line-strong);
}
.now.running { border-left-color: var(--good); }
.now .state { font-size: 12.5px; font-weight: 600; color: var(--ink-2); display: flex; align-items: center; gap: 6px; }
.now.running .state { color: var(--good-text); }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--good); animation: pulse 2s infinite; }
@keyframes pulse { 50% { opacity: .35; } }
@media (prefers-reduced-motion: reduce) { .dot { animation: none; } }
.now .what { font-size: 22px; font-weight: 700; line-height: 1.25; margin: 2px 0 6px; }
.now .meta { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; color: var(--ink-2); font-size: 13.5px; }
.clock { font-size: 40px; font-weight: 600; font-variant-numeric: tabular-nums; line-height: 1; text-align: right; }
.now .side { display: grid; gap: 10px; justify-items: end; }
@media (max-width: 620px) {
  .now { grid-template-columns: 1fr; }
  .now .side { justify-items: start; }
  .clock { text-align: left; }
}
.section-title { font-size: 12.5px; font-weight: 600; color: var(--ink-2); margin: 22px 0 8px; }
.acts { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 10px; }
.acts form { display: contents; }
.act {
  font: inherit; font-weight: 600; font-size: 15.5px; text-align: left; cursor: pointer; min-height: 64px;
  padding: 12px 14px; border-radius: var(--radius); border: 1px solid var(--line-strong);
  background: var(--surface); color: var(--ink); box-shadow: var(--shadow);
  display: flex; flex-direction: column; justify-content: center; gap: 3px;
}
.act:hover { border-color: var(--accent); background: var(--accent-soft); }
.act small { font-weight: 400; font-size: 12.5px; color: var(--ink-2); }
.act.current { border-color: var(--good); box-shadow: inset 0 0 0 1px var(--good); background: var(--good-soft); }
.act:disabled { opacity: .55; cursor: not-allowed; }
.stale { background: var(--warning-soft); border-color: var(--warning-line); }
.stale form { display: flex; gap: 10px; align-items: end; flex-wrap: wrap; margin-top: 10px; }
.stale input { width: 130px; }

.day-total { display: flex; align-items: baseline; gap: 8px; }
.day-total strong { font-size: 22px; font-variant-numeric: tabular-nums; }
.week { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; margin-bottom: 16px; }
.week a, .week span {
  display: block; text-align: center; padding: 8px 4px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--surface); color: var(--ink); font-size: 13px;
}
.week a:hover { background: var(--surface-2); text-decoration: none; }
.week .on { border-color: var(--accent); background: var(--accent-soft); font-weight: 600; }
.week .off { color: var(--muted); background: transparent; }
.week b { display: block; font-variant-numeric: tabular-nums; min-height: 1.45em; }

/* --- dialog attività --- */
dialog { border: 0; border-radius: 12px; padding: 0; width: min(460px, calc(100vw - 32px)); box-shadow: 0 20px 60px rgba(11, 11, 11, .3); }
dialog::backdrop { background: rgba(11, 11, 11, .45); }
dialog .body { padding: 20px; }
dialog h2 { font-size: 19px; margin-bottom: 14px; }
.seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 8px; }
.seg label { margin: 0; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg span {
  display: block; text-align: center; padding: 12px; border-radius: 8px; font-weight: 600; cursor: pointer;
  border: 1px solid var(--line-strong); background: var(--surface);
}
.seg input:checked + span { background: var(--accent); border-color: var(--accent); color: #fff; }
.seg input:focus-visible + span { outline: 2px solid var(--series-1); outline-offset: 1px; }
.suggest { position: relative; }
.suggest-list {
  position: absolute; z-index: 30; left: 0; right: 0; top: calc(100% + 2px); background: var(--surface);
  border: 1px solid var(--line-strong); border-radius: 8px; box-shadow: 0 8px 24px rgba(11, 11, 11, .12);
  max-height: 220px; overflow: auto;
}
.suggest-list button { display: block; width: 100%; text-align: left; font: inherit; padding: 8px 10px; border: 0; background: none; cursor: pointer; }
.suggest-list button:hover, .suggest-list button.on { background: var(--accent-soft); }
.suggest-hint { font-size: 12.5px; color: var(--ink-2); margin-top: 4px; min-height: 1.4em; }
.recent { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.recent button { font: inherit; font-size: 12.5px; border: 1px solid var(--line-strong); background: var(--surface); border-radius: 999px; padding: 3px 10px; cursor: pointer; }
.recent button:hover { background: var(--accent-soft); border-color: var(--accent); }
.kiosk-bar { position: fixed; left: 0; right: 0; bottom: 0; background: var(--ink); color: #fff; padding: 10px 20px; display: flex; gap: 14px; justify-content: center; align-items: center; z-index: 40; }
.kiosk-bar button { font: inherit; background: #fff; color: var(--ink); border: 0; border-radius: 6px; padding: 5px 12px; cursor: pointer; font-weight: 600; }

/* --- gestione: filtri, tile, grafici --- */
.filters { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px 12px; align-items: end; }
.filters .field { margin: 0; }
.filters label { font-size: 12.5px; color: var(--ink-2); }
.period { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 14px; }
.period .tabs { display: flex; border: 1px solid var(--line-strong); border-radius: 8px; overflow: hidden; background: var(--surface); }
.period .tabs a { padding: 6px 12px; color: var(--ink-2); border-right: 1px solid var(--line); }
.period .tabs a:last-child { border-right: 0; }
.period .tabs a.on { background: var(--accent); color: #fff; font-weight: 600; }
.period .tabs a:hover { text-decoration: none; }
.period .label { font-weight: 700; font-size: 17px; min-width: 150px; text-align: center; }
.period .spacer { flex: 1; }

.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(165px, 1fr)); gap: 12px; margin: 16px 0; }
.tile { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.tile .k { font-size: 12.5px; color: var(--ink-2); display: flex; align-items: center; gap: 6px; }
.tile .v { font-size: 28px; font-weight: 600; line-height: 1.2; margin-top: 2px; }
.tile .s { font-size: 12.5px; color: var(--ink-2); }
.swatch { width: 10px; height: 10px; border-radius: 3px; display: inline-block; flex: none; }
.s1 { background: var(--series-1); } .s2 { background: var(--series-2); }
.s3 { background: var(--series-3); } .s4 { background: var(--series-4); }

.charts { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 440px), 1fr)); gap: 16px; }
.charts .card + .card { margin-top: 0; }
.charts .wide { grid-column: 1 / -1; }
.card h2 small { font-weight: 400; color: var(--ink-2); font-size: 13px; margin-left: 6px; }
.card .q { color: var(--ink-2); font-size: 13px; margin: -8px 0 12px; }
.bars { display: grid; gap: 2px; }
.bar-row {
  display: grid; grid-template-columns: minmax(110px, 34%) 1fr auto; gap: 10px; align-items: center;
  padding: 5px 6px; border-radius: 6px; color: var(--ink);
}
a.bar-row:hover { background: var(--surface-2); text-decoration: none; }
.bar-row .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13.5px; }
.bar-row .track { height: 14px; display: flex; gap: 2px; }
.bar-row .fill { height: 100%; background: var(--series-1); border-radius: 0 4px 4px 0; min-width: 2px; }
.bar-row .fill.s2 { background: var(--series-2); }
.bar-row .track .fill:not(:last-child) { border-radius: 0; }
.bar-row .val { font-variant-numeric: tabular-nums; font-size: 13.5px; white-space: nowrap; text-align: right; min-width: 92px; }
.bar-row .val span { color: var(--muted); font-size: 12.5px; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 13px; color: var(--ink-2); margin-bottom: 8px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.chart-box { position: relative; height: 240px; }
details.table-view { margin-top: 10px; font-size: 13px; }
details.table-view summary { cursor: pointer; color: var(--ink-2); }
details.table-view td, details.table-view th { padding: 5px 8px; }

.live { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 10px; }
.live > div { border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; background: var(--surface); }
.live strong { display: block; }
.live .t { font-variant-numeric: tabular-nums; color: var(--ink-2); font-size: 13px; }
.pager { display: flex; gap: 12px; align-items: center; justify-content: center; margin-top: 14px; }
.diff { font-size: 13px; }
.diff del { color: var(--critical); text-decoration-thickness: 1px; }
.diff ins { color: var(--good-text); text-decoration: none; font-weight: 600; }
.inline-form { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.inline-form input[type=text], .inline-form select { width: auto; min-width: 180px; padding: 5px 8px; }

.projects .inline-form { flex-wrap: nowrap; }
.projects input[name=name] { min-width: 230px; }
.projects select { min-width: 0 !important; max-width: 190px; }
.projects th, .projects td { padding-left: 7px; padding-right: 7px; }
.projects td { vertical-align: middle; }
@media (max-width: 620px) {
  .topbar { padding: 8px 14px; }
  .nav { flex: 1 1 100%; order: 3; }
  .who { margin-left: auto; }
  .wrap { padding: 16px 14px 70px; }
  .acts { grid-template-columns: repeat(2, 1fr); gap: 8px; }
  .act { font-size: 14.5px; padding: 10px 12px; }
  .clock { font-size: 34px; }
}
