:root {
  --bg: #f4f5f7;
  --card: #ffffff;
  --text: #17202b;
  --muted: #5d6b7a;
  --line: #e2e6eb;
  --accent: #0f766e;
  --accent-ink: #ffffff;
  --accent-soft: #e6f4f2;
  --warn: #b45309;
  --warn-soft: #fef3e2;
  --bad: #b42318;
  --bad-soft: #fdecea;
  --ok: #157347;
  --ok-soft: #e7f5ec;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 1px 3px rgba(16, 24, 40, 0.08);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1418;
    --card: #182027;
    --text: #e8edf2;
    --muted: #9aa8b5;
    --line: #2a343d;
    --accent: #2bb3a3;
    --accent-ink: #062320;
    --accent-soft: #143430;
    --warn: #f0a849;
    --warn-soft: #3a2a12;
    --bad: #f2867a;
    --bad-soft: #3b1c19;
    --ok: #5fcf8f;
    --ok-soft: #15301f;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

html, body { margin: 0; }

body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 20px;
  background: var(--card);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 5;
}

.brand { display: flex; align-items: center; gap: 10px; font-weight: 650; letter-spacing: -0.01em; }
.brand img { width: 28px; height: 28px; }
.topbar .muted { font-size: 14px; }

main { max-width: 720px; margin: 0 auto; padding: 20px 16px 64px; display: grid; gap: 16px; }
main.wide { max-width: 1100px; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
}
.card.narrow { max-width: 440px; margin: 6vh auto 0; width: 100%; }
.card h1 { font-size: 22px; margin: 0 0 6px; letter-spacing: -0.01em; }
.card h2 { font-size: 17px; margin: 0 0 12px; }
.card h3 { font-size: 15px; margin: 16px 0 8px; }

.muted { color: var(--muted); }
.small { font-size: 14px; }
.center { text-align: center; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.stack { display: grid; gap: 12px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 560px) { .grid2 { grid-template-columns: 1fr; } }

label { display: grid; gap: 6px; font-size: 14px; font-weight: 550; }
label.inline { display: flex; align-items: center; gap: 8px; font-weight: 450; }

input[type="text"], input[type="email"], input[type="password"], input[type="date"], input[type="time"],
input[type="number"], input[type="url"], select, textarea {
  font: inherit;
  color: inherit;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  width: 100%;
  min-height: 44px;
}
textarea { min-height: 80px; resize: vertical; }
input:focus, select:focus, textarea:focus, button:focus-visible, a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}
input[type="checkbox"], input[type="radio"] { width: 18px; height: 18px; accent-color: var(--accent); }
input:disabled { opacity: 0.6; }

button, .btn {
  font: inherit;
  font-weight: 600;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--text);
  border-radius: 10px;
  padding: 10px 16px;
  min-height: 44px;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}
button:hover, .btn:hover { border-color: var(--muted); }
button.primary, .btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
button.danger { color: var(--bad); }
button.link { background: none; border: none; padding: 0; min-height: 0; color: var(--accent); font-weight: 550; }
button:disabled { opacity: 0.55; cursor: default; }
button.small, .btn.small { padding: 6px 12px; min-height: 36px; font-size: 14px; }

.notice { border-radius: 10px; padding: 12px 14px; font-size: 15px; }
.notice.info { background: var(--accent-soft); }
.notice.warn { background: var(--warn-soft); color: var(--text); border-left: 4px solid var(--warn); }
.notice.bad { background: var(--bad-soft); border-left: 4px solid var(--bad); }
.notice.ok { background: var(--ok-soft); border-left: 4px solid var(--ok); }

.badge {
  display: inline-block;
  font-size: 12px;
  font-weight: 650;
  border-radius: 999px;
  padding: 2px 9px;
  background: var(--bg);
  border: 1px solid var(--line);
  white-space: nowrap;
}
.badge.ok { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.badge.warn { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.badge.bad { background: var(--bad-soft); color: var(--bad); border-color: transparent; }
.badge.info { background: var(--accent-soft); color: var(--accent); border-color: transparent; }

/* Blocco principale con il pulsante */
.hero { text-align: center; padding: 28px 20px; }
.hero .who { font-weight: 600; }
.clock { font-size: 56px; font-weight: 700; letter-spacing: -0.03em; font-variant-numeric: tabular-nums; margin: 6px 0 0; }
.date { color: var(--muted); margin-bottom: 18px; text-transform: capitalize; }

.punch-btn {
  width: 168px;
  height: 168px;
  border-radius: 50%;
  border: none;
  background: var(--accent);
  color: var(--accent-ink);
  font-size: 22px;
  font-weight: 700;
  margin: 6px auto 4px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  box-shadow: 0 8px 24px rgba(15, 118, 110, 0.28);
  transition: transform 0.08s ease;
}
.punch-btn small { font-size: 13px; font-weight: 550; opacity: 0.9; }
.punch-btn:active { transform: scale(0.97); }
.punch-btn:disabled { box-shadow: none; }
.punch-state { max-width: 440px; margin: 12px auto 0; text-align: left; }
.punch-state .big { font-size: 20px; font-weight: 700; }
.spinner {
  width: 22px; height: 22px; border-radius: 50%;
  border: 3px solid currentColor; border-right-color: transparent;
  animation: spin 0.8s linear infinite; display: inline-block; vertical-align: middle;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Elenchi */
.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 11px 0; border-top: 1px solid var(--line); }
.list li:first-child { border-top: none; }
.list .main { display: grid; gap: 2px; min-width: 0; }
.list .title { font-weight: 600; }
.list .sub { color: var(--muted); font-size: 14px; }
.empty { color: var(--muted); font-size: 15px; padding: 6px 0; }

table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 9px 8px; border-top: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-weight: 600; border-top: none; font-size: 13px; }
td.num, th.num { font-variant-numeric: tabular-nums; white-space: nowrap; }
.table-wrap { overflow-x: auto; }

/* Pannello admin */
.tabs { display: flex; gap: 4px; flex-wrap: wrap; border-bottom: 1px solid var(--line); margin-bottom: 4px; }
.tabs button { border: none; background: none; border-radius: 0; border-bottom: 2px solid transparent; padding: 10px 12px; color: var(--muted); }
.tabs button.active { color: var(--text); border-bottom-color: var(--accent); }

.checklist { list-style: none; padding: 0; margin: 0; display: grid; gap: 10px; }
.checklist li { display: flex; gap: 10px; align-items: flex-start; }
.dot { width: 10px; height: 10px; border-radius: 50%; margin-top: 7px; flex: none; background: var(--line); }
.dot.ok { background: var(--ok); }
.dot.warn { background: var(--warn); }
.dot.bad { background: var(--bad); }

.days { display: flex; gap: 6px; flex-wrap: wrap; }
.days label {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 46px; min-height: 40px; border: 1px solid var(--line); border-radius: 10px;
  cursor: pointer; font-weight: 600; user-select: none; padding: 0 8px;
}
.days input { position: absolute; opacity: 0; pointer-events: none; }
.days label:has(input:checked) { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.days label:has(input:focus-visible) { outline: 2px solid var(--accent); }

.slot-row { display: grid; grid-template-columns: 1.4fr 1fr 1fr auto; gap: 8px; align-items: end; }
@media (max-width: 560px) { .slot-row { grid-template-columns: 1fr 1fr; } .slot-row .slot-label { grid-column: 1 / -1; } }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { display: inline-flex; align-items: center; gap: 6px; background: var(--bg); border: 1px solid var(--line); border-radius: 999px; padding: 3px 4px 3px 10px; font-size: 14px; }
.chip button { min-height: 0; padding: 0 6px; border: none; background: none; font-size: 16px; line-height: 1; }

.rule-card { border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; display: grid; gap: 6px; }
.rule-card.off { opacity: 0.65; }
.rule-card .meta { color: var(--muted); font-size: 14px; }

.copybox { display: flex; gap: 8px; }
.copybox input { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px; }

.toast {
  position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px;
  font-size: 15px; max-width: calc(100% - 32px); z-index: 20; box-shadow: 0 6px 20px rgba(0, 0, 0, 0.2);
}

.hidden { display: none !important; }
hr { border: none; border-top: 1px solid var(--line); margin: 16px 0; }
a { color: var(--accent); }

.lbl { font-size: 14px; font-weight: 550; margin-bottom: 6px; }
.section-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.section-head h2 { margin: 0; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 4px 14px; font-size: 14px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
input.w-num { width: 84px; min-width: 0; display: inline-block; }
.grow { flex: 1; min-width: 220px; width: auto; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.92em; background: var(--bg); padding: 1px 5px; border-radius: 6px; }
.row > input[type="date"] { width: auto; flex: 0 1 220px; }
#ex-list { margin-top: 8px; }
