:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --ink: #0f172a;
  --muted: #64748b;
  --line: #e2e8f0;
  --accent: #0f766e;
  --accent-ink: #ffffff;
  --danger: #b91c1c;
  --ok: #15803d;
  --radius: 14px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.5;
  overflow-x: hidden;
}

h1, h2, h3 { margin: 0 0 0.5rem; line-height: 1.2; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.2rem; }
h3 { font-size: 1rem; margin-top: 0.5rem; }
p { margin: 0 0 0.75rem; }
code { background: var(--bg); padding: 0.1rem 0.3rem; border-radius: 4px; }

.muted { color: var(--muted); }
.hint { color: var(--muted); font-size: 0.85rem; margin: 0; }
.fine { color: var(--muted); font-size: 0.8rem; text-align: center; }
.center { text-align: center; align-items: center; }
.error-text { color: var(--danger); }
[hidden] { display: none !important; }

.brand { font-weight: 700; letter-spacing: -0.01em; color: var(--accent); }

/* Layout */
.stack { display: flex; flex-direction: column; gap: 0.85rem; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 0.75rem; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; align-items: start; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.25rem; }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 0.75rem; margin-bottom: 1rem; }
.list-head { display: flex; justify-content: space-between; align-items: center; gap: 0.75rem; flex-wrap: wrap; }

/* Pannello */
.topbar {
  display: flex; justify-content: space-between; align-items: center; gap: 1rem;
  padding: 0.9rem 1.25rem; background: var(--surface); border-bottom: 1px solid var(--line);
}
.topbar-right { display: flex; align-items: center; gap: 0.75rem; min-width: 0; }
.topbar-right span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tabs {
  display: flex; gap: 0.25rem; padding: 0.5rem 1.25rem; background: var(--surface);
  border-bottom: 1px solid var(--line); overflow-x: auto;
}
.tabs a {
  padding: 0.45rem 0.8rem; border-radius: 999px; color: var(--muted); text-decoration: none;
  white-space: nowrap; font-weight: 500;
}
.tabs a.active { background: var(--ink); color: #fff; }
.view { padding: 1.25rem; max-width: 1080px; margin: 0 auto; display: flex; flex-direction: column; gap: 1rem; }
.notice { padding: 0.6rem 1rem; background: #fef9c3; color: #713f12; border-radius: 10px; font-size: 0.9rem; }
.notice.success { background: #dcfce7; color: #14532d; }
.callout { padding: 0.9rem 1rem; background: #ecfdf5; border: 1px solid #a7f3d0; border-radius: 10px; }

.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem; display: flex; flex-direction: column; }
.kpi strong { font-size: 1.8rem; line-height: 1.1; }
.kpi span { font-weight: 600; margin-top: 0.25rem; }
.kpi small { color: var(--muted); }

.bars { display: flex; align-items: flex-end; gap: 0.4rem; height: 180px; padding-top: 0.5rem; }
.bar-col { flex: 1; height: 100%; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; gap: 0.3rem; min-width: 0; }
.bar { width: 100%; background: var(--accent); border-radius: 6px 6px 2px 2px; min-height: 2px; position: relative; }
.bar span { position: absolute; top: -1.2rem; left: 0; right: 0; text-align: center; font-size: 0.75rem; color: var(--muted); }
.bar-col small { font-size: 0.7rem; color: var(--muted); }

/* Form */
.field { display: flex; flex-direction: column; gap: 0.3rem; font-size: 0.9rem; font-weight: 500; }
.field span { color: var(--muted); font-size: 0.82rem; }
input, select, textarea {
  font: inherit; font-size: 0.95rem; color: var(--ink); background: #fff;
  border: 1px solid var(--line); border-radius: 10px; padding: 0.6rem 0.75rem; width: 100%;
}
input[type="color"] { height: 2.6rem; padding: 0.2rem; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: transparent; }
textarea { resize: vertical; }
.check { display: flex; gap: 0.5rem; align-items: flex-start; font-size: 0.9rem; }
.check input { width: auto; margin-top: 0.25rem; }
.inline { display: flex; gap: 0.5rem; flex: 1; min-width: 240px; }
.inline input { flex: 1; text-transform: uppercase; letter-spacing: 0.08em; }
.scan-row { display: flex; gap: 0.75rem; flex-wrap: wrap; align-items: center; }
.copy-row { display: flex; gap: 0.5rem; }
.copy-row input { flex: 1; }
#scanner video { width: 100%; max-width: 420px; border-radius: 12px; background: #000; }
#scanner { display: flex; flex-direction: column; gap: 0.5rem; }

/* Bottoni */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.4rem;
  font: inherit; font-weight: 600; font-size: 0.92rem; padding: 0.6rem 1rem; border-radius: 10px;
  border: 1px solid var(--line); background: #fff; color: var(--ink); cursor: pointer; text-decoration: none;
  white-space: nowrap;
}
.btn:hover { filter: brightness(0.97); }
.btn:disabled { opacity: 0.55; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.ghost { background: transparent; }
.btn.accent { background: #fef3c7; border-color: #fcd34d; }
.btn.danger { color: var(--danger); }
.btn.small { padding: 0.35rem 0.6rem; font-size: 0.8rem; }
.btn.block { width: 100%; }
.link { background: none; border: 0; color: var(--accent); font: inherit; cursor: pointer; padding: 0.5rem 0; text-align: left; }

/* Tabella */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 0.92rem; }
th, td { text-align: left; padding: 0.6rem 0.5rem; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { color: var(--muted); font-weight: 500; font-size: 0.8rem; }
td small { color: var(--muted); display: block; }
td .actions { display: flex; gap: 0.35rem; flex-wrap: wrap; justify-content: flex-end; }
.bullets { padding-left: 1.1rem; margin: 0; display: flex; flex-direction: column; gap: 0.4rem; }

/* Tessera (anteprima, pagina cliente) */
.stamps { display: grid; grid-template-columns: repeat(auto-fill, minmax(22px, 1fr)); gap: 0.45rem; margin: 0.75rem 0; }
.stamp { aspect-ratio: 1; border-radius: 50%; border: 2px solid var(--stamp, #fff); background: transparent; max-width: 34px; }
.stamp.on { background: var(--stamp, #fff); }
.pass-card {
  border-radius: 16px; padding: 1.1rem 1.25rem; box-shadow: 0 10px 30px rgba(15, 23, 42, 0.18);
  display: flex; flex-direction: column;
}
.pass-card.big { padding: 1.5rem; }
.pass-name { font-weight: 700; font-size: 1.1rem; }
.pass-label { font-size: 0.7rem; letter-spacing: 0.12em; opacity: 0.75; margin-top: 0.75rem; }
.pass-value { font-size: 2rem; font-weight: 700; line-height: 1.1; }
.pass-foot { font-size: 0.9rem; margin-top: 0.25rem; }
.pass-foot span { font-size: 0.7rem; letter-spacing: 0.12em; opacity: 0.75; margin-right: 0.4rem; }
.qr { width: 240px; max-width: 100%; height: auto; border-radius: 12px; background: #fff; padding: 0.5rem; border: 1px solid var(--line); }
.wallet-buttons { display: flex; flex-direction: column; gap: 0.6rem; width: 100%; max-width: 320px; }
.wallet {
  display: block; text-align: center; text-decoration: none; font-weight: 600; padding: 0.8rem 1rem;
  border-radius: 10px; border: 1px solid #111; background: #000; color: #fff;
}
.wallet.google { background: #fff; color: #111; border-color: #dadce0; }

/* Pagine pubbliche */
body.public { padding: 1rem; }
.public-main { max-width: 480px; margin: 0 auto; display: flex; flex-direction: column; gap: 1rem; }
.join-card {
  border-radius: 18px; padding: 1.5rem; background: var(--brand, #0f766e); color: var(--brand-text, #fff);
  box-shadow: 0 10px 30px rgba(15, 23, 42, 0.18);
}
.join-name { font-size: 1.5rem; font-weight: 700; }
.join-sub { opacity: 0.8; font-size: 0.9rem; }
.join-reward { margin-top: 1rem; font-size: 0.95rem; }
.scratch { position: relative; width: 100%; aspect-ratio: 16 / 10; border-radius: 16px; overflow: hidden; background: #fff; }
.scratch-prize { position: absolute; inset: 0; display: flex; flex-direction: column; justify-content: center; align-items: center; gap: 0.3rem; padding: 1rem; text-align: center; }
.scratch-prize strong { font-size: 1.4rem; }
.scratch canvas { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; cursor: crosshair; }

/* Toast */
.toast {
  position: fixed; left: 50%; bottom: 1.25rem; transform: translate(-50%, 140%);
  background: var(--ink); color: #fff; padding: 0.7rem 1rem; border-radius: 12px; max-width: calc(100% - 2rem);
  font-size: 0.92rem; transition: transform 0.25s ease; z-index: 10;
}
.toast.show { transform: translate(-50%, 0); }
.toast.error { background: var(--danger); }

/* Auth */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 1rem; }
.auth-card { background: var(--surface); border: 1px solid var(--line); border-radius: 18px; padding: 2rem; width: 100%; max-width: 400px; }
.auth-card .stack { margin: 1rem 0; }

@media (max-width: 760px) {
  .two-col, .row { grid-template-columns: 1fr; }
  .view { padding: 1rem; }
  .topbar { padding: 0.8rem 1rem; }
  .topbar-right span { display: none; }
  .qr { width: 200px; }
}
