/* ─────────────────────────────────────────────────────
   Caccia al Tesoro — Dashboard
   Editorial × adventure / earth + brass
   ───────────────────────────────────────────────────── */

:root {
  --bg:           oklch(0.965 0.012 80);
  --bg-tint:      oklch(0.945 0.018 75);
  --paper:        #ffffff;
  --paper-soft:   oklch(0.985 0.006 80);
  --ink:          oklch(0.20 0.018 60);
  --ink-soft:     oklch(0.40 0.018 65);
  --ink-mute:     oklch(0.58 0.015 70);
  --line:         oklch(0.88 0.018 75);
  --line-soft:    oklch(0.93 0.014 75);

  --brass:        oklch(0.66 0.13 75);
  --brass-deep:   oklch(0.50 0.13 70);
  --brass-tint:   oklch(0.95 0.04 80);

  --terracotta:   oklch(0.62 0.15 40);
  --terracotta-tint: oklch(0.95 0.04 50);

  --ok:           oklch(0.55 0.13 145);
  --ok-tint:      oklch(0.94 0.05 145);
  --err:          oklch(0.56 0.18 25);
  --err-tint:     oklch(0.95 0.04 30);
  --warn:         oklch(0.70 0.15 65);
  --warn-tint:    oklch(0.95 0.05 75);
  --info:         oklch(0.55 0.12 240);
  --info-tint:    oklch(0.94 0.04 240);

  --radius-sm: 6px;
  --radius:    10px;
  --radius-lg: 16px;
  --radius-xl: 22px;

  --shadow-1: 0 1px 0 oklch(0.85 0.02 75 / 0.6), 0 4px 14px -8px oklch(0.30 0.05 60 / 0.18);
  --shadow-2: 0 1px 0 oklch(0.85 0.02 75 / 0.6), 0 18px 40px -22px oklch(0.30 0.05 60 / 0.28);

  --font-display: 'Newsreader', 'Iowan Old Style', Georgia, serif;
  --font-ui:      'Geist', ui-sans-serif, sans-serif;
  --font-mono:    'JetBrains Mono', ui-monospace, Menlo, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

body {
  background-image:
    radial-gradient(1200px 600px at 100% -10%, oklch(from var(--brass) l c h / 0.06), transparent 60%),
    radial-gradient(900px 500px at -10% 100%, oklch(from var(--terracotta) l c h / 0.05), transparent 60%);
  min-height: 100vh;
}

button, input, textarea, select { font: inherit; color: inherit; }
a { color: inherit; text-decoration: none; }
img { display: block; max-width: 100%; }
::selection { background: oklch(from var(--brass) l c h / 0.30); }

/* ───── App shell ───── */

.app {
  display: grid;
  grid-template-columns: 260px 1fr;
  min-height: 100vh;
}

.sidebar {
  border-right: 1px solid var(--line);
  background: var(--paper-soft);
  padding: 22px 18px;
  display: flex;
  flex-direction: column;
  gap: 22px;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand {
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 4px 6px 0;
}
.brand-mark {
  width: 38px; height: 38px;
  border-radius: 50%;
  background: var(--paper);
  display: grid; place-items: center;
  color: var(--paper);
  box-shadow: inset 0 0 0 1px oklch(from var(--brass-deep) l c h / 0.22), 0 1px 0 rgba(255,255,255,0.4);
  flex-shrink: 0;
  overflow: hidden;
}
.brand-mark img { width: 100%; height: 100%; object-fit: cover; }
.brand-text { line-height: 1.15; }
.brand-text .b1 {
  font-family: var(--font-display);
  font-size: 19px;
  font-weight: 600;
  letter-spacing: -0.01em;
}
.brand-text .b2 {
  font-size: 11px;
  color: var(--ink-mute);
  text-transform: uppercase;
  letter-spacing: 0.12em;
  margin-top: 2px;
}

.event-pill {
  display: flex; gap: 10px; align-items: center;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px 12px;
  font-size: 12.5px;
}
.event-pill .live {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--ok);
  box-shadow: 0 0 0 4px oklch(from var(--ok) l c h / 0.18);
  animation: pulse 2.2s ease-in-out infinite;
  flex-shrink: 0;
}
@keyframes pulse {
  50% { box-shadow: 0 0 0 7px oklch(from var(--ok) l c h / 0.04); }
}
.event-pill .ev-date { font-weight: 600; }
.event-pill .ev-sub { color: var(--ink-mute); font-size: 11.5px; margin-top: 1px; }

.nav-section-label {
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--ink-mute);
  padding: 0 6px 6px;
}

.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a {
  display: flex; align-items: center; gap: 11px;
  padding: 9px 12px;
  border-radius: 8px;
  color: var(--ink-soft);
  font-size: 14px;
  font-weight: 500;
  border: 1px solid transparent;
  transition: background .15s, color .15s, border-color .15s;
  cursor: pointer;
}
.nav a:hover { background: var(--bg-tint); color: var(--ink); }
.nav a.active {
  background: var(--paper);
  border-color: var(--line);
  color: var(--ink);
  box-shadow: var(--shadow-1);
}
.nav a svg { width: 17px; height: 17px; opacity: 0.78; flex-shrink: 0; }
.nav a .label { flex: 1; }
.nav a .nav-badge {
  font-size: 11px;
  font-weight: 600;
  background: var(--terracotta);
  color: white;
  padding: 1px 7px;
  border-radius: 999px;
  min-width: 20px; text-align: center;
}
.nav a .nav-badge.hint { background: var(--warn); }

.sidebar-foot {
  margin-top: auto;
  display: flex; flex-direction: column; gap: 8px;
  font-size: 12px;
  color: var(--ink-mute);
  padding: 12px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.sidebar-foot .row { display: flex; justify-content: space-between; }
.sidebar-foot .ok { color: var(--ok); font-weight: 600; }
.logout-form {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--line-soft);
}
.logout-form .btn { padding: 5px 9px; font-size: 12px; }

/* ───── Login ───── */

.login-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
}
.login-shell {
  width: min(420px, calc(100vw - 32px));
}
.login-panel {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-2);
  padding: 26px;
}
.login-brand {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 22px;
}
.login-brand img {
  width: 58px;
  height: 58px;
  border-radius: 16px;
  border: 1px solid var(--line);
  box-shadow: var(--shadow-1);
}
.login-title {
  font-family: var(--font-display);
  font-size: 28px;
  font-weight: 600;
  line-height: 1;
}
.login-subtitle {
  color: var(--ink-mute);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  margin-top: 5px;
}
.login-form {
  display: flex;
  flex-direction: column;
  gap: 13px;
}
.login-form label {
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: 12px;
  font-weight: 600;
  color: var(--ink-soft);
}
.login-error {
  background: var(--err-tint);
  color: var(--err);
  border: 1px solid oklch(from var(--err) l c h / 0.22);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 13px;
}
.login-submit {
  justify-content: center;
  margin-top: 4px;
}

/* ───── Page chrome ───── */

.main {
  display: flex; flex-direction: column;
  min-width: 0;
}
.topbar {
  position: sticky; top: 0; z-index: 20;
  background: oklch(from var(--bg) l c h / 0.85);
  backdrop-filter: saturate(1.5) blur(10px);
  -webkit-backdrop-filter: saturate(1.5) blur(10px);
  border-bottom: 1px solid var(--line);
  padding: 14px 32px;
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px;
}
.crumbs { font-size: 12px; color: var(--ink-mute); }
.crumbs b { color: var(--ink-soft); font-weight: 600; }
.topbar h1 {
  font-family: var(--font-display);
  font-size: 22px;
  font-weight: 600;
  letter-spacing: -0.01em;
  margin: 2px 0 0;
}

.page {
  padding: 24px 32px 56px;
  max-width: 1400px;
  width: 100%;
  margin: 0 auto;
}

/* ───── Buttons + inputs ───── */

.btn {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 8px 14px;
  background: var(--paper);
  border: 1px solid var(--line);
  color: var(--ink);
  border-radius: 8px;
  font-size: 13.5px;
  font-weight: 500;
  cursor: pointer;
  transition: background .15s, border-color .15s, color .15s, transform .05s;
  white-space: nowrap;
  text-decoration: none;
}
.btn:hover { background: var(--bg-tint); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn svg { width: 14px; height: 14px; }

.btn-primary { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.btn-primary:hover { background: oklch(from var(--ink) calc(l + 0.06) c h); }
.btn-ok { background: var(--ok); border-color: var(--ok); color: white; }
.btn-ok:hover { background: oklch(from var(--ok) calc(l - 0.05) c h); }
.btn-danger { background: var(--err); border-color: var(--err); color: white; }
.btn-danger:hover { background: oklch(from var(--err) calc(l - 0.05) c h); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--ink-soft); }
.btn-ghost:hover { background: var(--bg-tint); color: var(--ink); }

.input, .textarea, .select {
  width: 100%;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 12px;
  font-size: 14px;
  color: var(--ink);
  font-family: inherit;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.input:focus, .textarea:focus, .select:focus {
  border-color: var(--brass);
  box-shadow: 0 0 0 3px oklch(from var(--brass) l c h / 0.15);
}
.textarea { resize: vertical; min-height: 80px; line-height: 1.5; }

/* ───── Cards ───── */

.card {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-1);
}
.card-head {
  padding: 16px 20px;
  border-bottom: 1px solid var(--line-soft);
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px;
}
.card-head h2 {
  font-family: var(--font-display);
  font-size: 17px;
  font-weight: 600;
  margin: 0;
  letter-spacing: -0.005em;
}
.card-head .sub { font-size: 12.5px; color: var(--ink-mute); }
.card-body { padding: 18px 20px; }
.card-body.flush { padding: 0; }

/* ───── KPI tiles ───── */

.kpi-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
  margin-bottom: 22px;
}
.kpi {
  position: relative;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 16px 18px;
  box-shadow: var(--shadow-1);
  overflow: hidden;
}
.kpi .label {
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--ink-mute);
  font-weight: 600;
}
.kpi .value {
  font-family: var(--font-display);
  font-size: 36px;
  font-weight: 600;
  letter-spacing: -0.02em;
  line-height: 1;
  margin-top: 8px;
}
.kpi .value .of { color: var(--ink-mute); font-weight: 400; font-size: 22px; }
.kpi .delta {
  margin-top: 9px;
  font-size: 11.5px;
  color: var(--ink-mute);
  display: flex; align-items: center; gap: 6px;
}
.kpi .icon {
  position: absolute; right: 14px; top: 14px;
  width: 32px; height: 32px;
  border-radius: 9px;
  background: var(--bg-tint);
  color: var(--ink-mute);
  display: grid; place-items: center;
}
.kpi.alert .icon { background: var(--err-tint); color: var(--err); }
.kpi.alert .value { color: var(--err); }
.kpi.warn .icon { background: var(--warn-tint); color: oklch(from var(--warn) calc(l - 0.15) c h); }
.kpi.warn .value { color: oklch(from var(--warn) calc(l - 0.15) c h); }
.kpi.ok .icon { background: var(--ok-tint); color: var(--ok); }

/* ───── Two-column dashboard split ───── */

.dash-grid {
  display: grid;
  grid-template-columns: 1.5fr 1fr;
  gap: 18px;
  align-items: start;
}

/* ───── Team badge ───── */

.team-badge {
  width: 36px; height: 36px;
  border-radius: 10px;
  display: grid; place-items: center;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 14px;
  color: white;
  flex-shrink: 0;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,0.15), inset 0 -8px 12px -10px rgba(0,0,0,0.25);
  letter-spacing: -0.01em;
}
.team-badge.sm { width: 26px; height: 26px; font-size: 11px; border-radius: 7px; }
.team-badge.lg { width: 48px; height: 48px; font-size: 17px; border-radius: 12px; }

/* ───── Classifica ───── */

.leaderboard { display: flex; flex-direction: column; }
.lb-row {
  display: grid;
  grid-template-columns: 38px 46px 1fr auto;
  gap: 14px;
  align-items: center;
  padding: 12px 20px;
  border-bottom: 1px solid var(--line-soft);
  position: relative;
}
.lb-row:last-child { border-bottom: 0; }
.lb-row.done { background: oklch(from var(--ok) l c h / 0.04); }

.lb-rank {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 18px;
  color: var(--ink-mute);
  text-align: center;
}
.lb-rank.top {
  display: grid; place-items: center;
  width: 32px; height: 32px;
  border-radius: 50%;
  background: var(--brass-tint);
  color: var(--brass-deep);
  margin: 0 auto;
  font-size: 14px;
  border: 1px solid oklch(from var(--brass) l c h / 0.3);
}
.lb-rank.gold { background: oklch(0.88 0.12 90); border-color: oklch(0.68 0.14 85); color: oklch(0.35 0.10 80); }
.lb-rank.silver { background: oklch(0.92 0.01 250); border-color: oklch(0.75 0.01 250); color: oklch(0.40 0.01 250); }
.lb-rank.bronze { background: oklch(0.85 0.08 50); border-color: oklch(0.62 0.12 45); color: oklch(0.35 0.10 40); }

.lb-meta { min-width: 0; }
.lb-meta .name {
  font-weight: 600;
  font-size: 14.5px;
  letter-spacing: -0.005em;
}
.lb-meta .name .team-link {
  color: inherit;
  text-decoration: none;
}
.lb-meta .name .team-link:hover {
  color: var(--brass-deep);
  text-decoration: underline;
  text-underline-offset: 3px;
}
.lb-meta .status {
  margin-top: 3px;
  font-size: 12px;
  color: var(--ink-mute);
  display: flex; align-items: center; gap: 6px;
}
.lb-meta .status .dot {
  width: 6px; height: 6px; border-radius: 50%; background: var(--ink-mute);
}
.lb-meta .status.live .dot { background: var(--ok); }
.lb-meta .status.done .dot { background: var(--brass); }
.lb-meta .status.idle .dot { background: var(--line); }

.lb-right { text-align: right; }
.lb-right .count {
  font-family: var(--font-display);
  font-size: 18px;
  font-weight: 600;
  letter-spacing: -0.01em;
}
.lb-right .of { color: var(--ink-mute); font-weight: 400; }
.lb-right .when { color: var(--ink-mute); font-size: 11.5px; margin-top: 2px; font-variant-numeric: tabular-nums; }
.lb-right .hints-used {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin-top: 4px;
  font-size: 11px;
  font-weight: 600;
  color: oklch(from var(--warn) calc(l - 0.18) c h);
  font-variant-numeric: tabular-nums;
}

.progress-track {
  display: flex;
  gap: 3px;
  margin-top: 10px;
  height: 6px;
}
.progress-seg {
  flex: 1;
  background: var(--line-soft);
  border-radius: 2px;
  height: 100%;
}
.progress-seg.done { background: var(--brass); }
.progress-seg.current {
  background: var(--brass-tint);
  background-image: linear-gradient(90deg, var(--brass) 0%, var(--brass) 50%, transparent 50%, transparent 100%);
  background-size: 6px 6px;
  animation: stripe 1.4s linear infinite;
}
@keyframes stripe { to { background-position: 12px 0; } }

.lb-row .progress-track { grid-column: 3 / 5; }

/* ───── Pills ───── */

.pill {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 600;
}
.pill .dot { width: 6px; height: 6px; border-radius: 50%; }
.pill.live { background: var(--ok-tint); color: oklch(from var(--ok) calc(l - 0.1) c h); }
.pill.live .dot { background: var(--ok); }
.pill.idle { background: var(--bg-tint); color: var(--ink-mute); }
.pill.idle .dot { background: var(--ink-mute); }
.pill.done { background: var(--brass-tint); color: var(--brass-deep); }
.pill.done .dot { background: var(--brass); }
.pill.warn { background: var(--warn-tint); color: oklch(from var(--warn) calc(l - 0.18) c h); }
.pill.warn .dot { background: var(--warn); }

/* ───── Feed / activity ───── */

.feed { display: flex; flex-direction: column; }
.feed-item {
  display: grid;
  grid-template-columns: 26px 1fr auto;
  gap: 10px;
  padding: 10px 20px;
  border-bottom: 1px solid var(--line-soft);
  align-items: center;
  font-size: 13px;
}
.feed-item:last-child { border-bottom: 0; }
.feed-item .when {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--ink-mute);
  text-align: right;
}
.feed-icon {
  width: 26px; height: 26px;
  border-radius: 7px;
  display: grid; place-items: center;
}
.feed-icon.ok    { background: var(--ok-tint);    color: var(--ok); }
.feed-icon.err   { background: var(--err-tint);   color: var(--err); }
.feed-icon.hint  { background: var(--warn-tint);  color: oklch(from var(--warn) calc(l - 0.18) c h); }
.feed-icon.pend  { background: var(--info-tint);  color: var(--info); }
.feed-icon svg { width: 13px; height: 13px; }

.feed-item .who { font-weight: 600; }
.feed-item .what { color: var(--ink-soft); }

/* ───── Empty state ───── */

.empty-state {
  padding: 48px 24px;
  text-align: center;
  color: var(--ink-mute);
}
.empty-state h3 {
  font-family: var(--font-display);
  font-size: 18px;
  color: var(--ink);
  margin: 8px 0 4px;
  font-weight: 600;
}
.empty-state svg { width: 40px; height: 40px; opacity: 0.5; margin: 0 auto 4px; }

/* ───── Code chip ───── */

.code-chip {
  font-family: var(--font-mono);
  background: var(--brass-tint);
  color: var(--brass-deep);
  padding: 3px 8px;
  border-radius: 5px;
  font-size: 12.5px;
  font-weight: 600;
  letter-spacing: 0.08em;
  display: inline-flex; align-items: center; gap: 6px;
}

/* ───── Page head ───── */

.page-head {
  display: flex; justify-content: space-between; align-items: flex-end;
  gap: 18px;
  margin-bottom: 22px;
}
.page-head .ttl {
  font-family: var(--font-display);
  font-size: 30px;
  font-weight: 600;
  letter-spacing: -0.015em;
  line-height: 1.1;
  margin: 0;
}
.page-head .sub {
  margin-top: 6px;
  color: var(--ink-mute);
  font-size: 13.5px;
  max-width: 60ch;
}

h1, h2, h3 { font-family: var(--font-display); letter-spacing: -0.01em; font-weight: 600; }
h1 { font-size: 30px; line-height: 1.1; margin-top: 0; }
h2 { font-size: 19px; }
h3 { font-size: 16px; }

/* ───── Field labels ───── */

.field-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--ink-soft);
  letter-spacing: 0.01em;
  display: block;
  margin-bottom: 5px;
}
.field-hint { font-size: 11.5px; color: var(--ink-mute); margin-top: 4px; }

form.stack { display: flex; flex-direction: column; gap: 12px; }
form.stack label { display: flex; flex-direction: column; gap: 5px; font-size: 12px; font-weight: 600; color: var(--ink-soft); letter-spacing: 0.01em; }
form.stack input[type=text],
form.stack textarea {
  width: 100%;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 12px;
  font-size: 14px;
  color: var(--ink);
  font-family: inherit;
  outline: none;
  font-weight: 400;
  letter-spacing: normal;
  transition: border-color .15s, box-shadow .15s;
}
form.stack input[type=text]:focus,
form.stack textarea:focus {
  border-color: var(--brass);
  box-shadow: 0 0 0 3px oklch(from var(--brass) l c h / 0.15);
}
form.stack textarea { resize: vertical; min-height: 80px; line-height: 1.5; }
form.inline { display: inline; }
form.inline-form { display: flex; gap: 8px; margin-bottom: 18px; }
form.inline-form input[type=text] {
  flex: 1;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 12px;
  font-size: 14px;
}
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-top: 8px; }

.muted { color: var(--ink-mute); font-size: 13px; }
.mono { font-family: var(--font-mono); font-size: 12.5px; }

/* ───── Tables (squadre) ───── */

.tbl {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 13.5px;
}
.tbl th, .tbl td {
  padding: 11px 16px;
  text-align: left;
  border-bottom: 1px solid var(--line-soft);
}
.tbl th {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.10em;
  color: var(--ink-mute);
  background: var(--paper-soft);
}
.tbl tr:last-child td { border-bottom: 0; }
.tbl tr.row-hover:hover td { background: oklch(from var(--brass) l c h / 0.04); cursor: pointer; }
.tbl td .team-row { display: flex; align-items: center; gap: 10px; }

/* ───── Stage timeline (team detail) ───── */

.stages {
  list-style: none;
  padding: 0; margin: 0;
  display: flex; flex-direction: column;
}
.stage-item {
  display: grid;
  grid-template-columns: 44px 1fr auto;
  gap: 14px;
  padding: 14px 20px;
  border-bottom: 1px solid var(--line-soft);
  align-items: flex-start;
  position: relative;
}
.stage-item:last-child { border-bottom: 0; }
.stage-num {
  width: 32px; height: 32px;
  border-radius: 50%;
  border: 1.5px solid var(--line);
  background: var(--paper);
  display: grid; place-items: center;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 13px;
  color: var(--ink-mute);
  position: relative;
}
.stage-item.done .stage-num {
  background: var(--ok);
  border-color: var(--ok);
  color: white;
}
.stage-item.current .stage-num {
  background: var(--brass);
  border-color: var(--brass);
  color: white;
  box-shadow: 0 0 0 4px oklch(from var(--brass) l c h / 0.18);
}
.stage-item .stage-line {
  position: absolute;
  top: 46px; left: 28px;
  width: 1.5px;
  height: calc(100% - 32px);
  background: var(--line);
}
.stage-item.done .stage-line { background: var(--ok); }
.stage-item:last-child .stage-line { display: none; }

.stage-title { font-weight: 600; font-size: 14.5px; letter-spacing: -0.005em; }
.stage-title .opt { color: var(--ink-mute); font-weight: 400; margin-left: 6px; }
.stage-clue { color: var(--ink-soft); font-size: 13px; margin-top: 5px; line-height: 1.5; }
.stage-sol  { color: var(--ink-mute); font-size: 12px; margin-top: 4px; font-style: italic; }
.stage-actions { display: flex; gap: 4px; align-items: flex-start; }

/* Edit form expanded inside a stage item */
.stage-edit {
  grid-column: 2 / -1;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px dashed var(--line);
}

/* ───── Validations focus mode ───── */

.val-layout {
  display: grid;
  grid-template-columns: 1fr 320px;
  gap: 20px;
  align-items: start;
}
.val-stage {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-2);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.val-stage[hidden] { display: none; }
.val-stage-head {
  padding: 18px 24px;
  display: flex; gap: 14px; align-items: center;
  border-bottom: 1px solid var(--line-soft);
}
.val-stage-head .info { flex: 1; min-width: 0; }
.val-stage-head .team-name { font-weight: 600; font-size: 16px; letter-spacing: -0.005em; }
.val-stage-head .stage-ref { color: var(--ink-mute); font-size: 12.5px; margin-top: 2px; }
.val-stage-head .timestamp {
  font-family: var(--font-mono);
  font-size: 11.5px;
  color: var(--ink-mute);
}

.val-body { padding: 22px 24px; flex: 1; }
.val-expected {
  display: flex; gap: 10px;
  background: var(--bg-tint);
  border-left: 3px solid var(--brass);
  padding: 12px 14px;
  border-radius: 6px;
  font-size: 13px;
  color: var(--ink-soft);
  margin-bottom: 18px;
}
.val-expected .lbl {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.10em;
  color: var(--brass-deep);
  font-weight: 700;
  margin-right: 6px;
}

.val-answer-text {
  font-family: var(--font-display);
  font-size: 22px;
  line-height: 1.4;
  padding: 22px 24px;
  background: var(--paper-soft);
  border: 1px dashed var(--line);
  border-radius: 12px;
  color: var(--ink);
}
.val-answer-photo {
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid var(--line);
  background: var(--bg-tint);
  position: relative;
}
.val-answer-photo a { display: block; position: relative; }
.val-answer-photo a:hover img { opacity: 0.96; }
.val-answer-photo img { width: 100%; height: auto; display: block; transition: opacity .15s; }
.val-answer-photo .open-hint {
  position: absolute;
  top: 12px; right: 12px;
  background: oklch(0.18 0.018 60 / 0.78);
  color: white;
  padding: 5px 10px;
  border-radius: 8px;
  font-size: 11.5px;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  opacity: 0;
  transition: opacity .15s;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  pointer-events: none;
}
.val-answer-photo a:hover .open-hint { opacity: 1; }
.val-answer-caption {
  margin-top: 10px;
  font-size: 12.5px;
  color: var(--ink-mute);
}

.val-actions {
  padding: 16px 24px;
  border-top: 1px solid var(--line-soft);
  display: flex; gap: 12px; align-items: center;
  background: var(--paper-soft);
}
.val-actions .kbd-hint {
  margin-left: auto;
  display: flex; gap: 14px;
  align-items: center;
  font-size: 11.5px;
  color: var(--ink-mute);
}

kbd.k {
  display: inline-block;
  font-family: var(--font-mono);
  font-size: 10.5px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: 4px;
  padding: 1px 6px;
  color: var(--ink-soft);
  margin: 0 3px;
}

.val-queue {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-1);
  overflow: hidden;
}
.val-queue-head {
  padding: 13px 16px;
  border-bottom: 1px solid var(--line-soft);
  display: flex; justify-content: space-between; align-items: center;
}
.val-queue-head h3 {
  font-family: var(--font-display);
  font-size: 14px;
  margin: 0;
  font-weight: 600;
}
.q-count { font-size: 11.5px; color: var(--ink-mute); font-variant-numeric: tabular-nums; }
.q-list { display: flex; flex-direction: column; max-height: 560px; overflow: auto; }
.q-item {
  display: grid;
  grid-template-columns: 28px 1fr auto;
  gap: 10px;
  padding: 11px 16px;
  /* Reset esplicito del border (i <button> hanno border di sistema su tutti i lati) */
  border: 0;
  border-bottom: 1px solid var(--line-soft);
  border-left: 3px solid transparent;
  align-items: center;
  cursor: pointer;
  font-size: 12.5px;
  transition: background .12s;
  background: transparent;
  text-align: left;
  width: 100%;
  font-family: inherit;
  color: inherit;
  outline: none;
}
.q-item:focus-visible { box-shadow: inset 0 0 0 2px oklch(from var(--brass) l c h / 0.4); }
.q-item:hover { background: var(--bg-tint); }
.q-item.active {
  background: oklch(from var(--brass) l c h / 0.07);
  border-left-color: var(--brass);
}
.q-item .q-team { font-weight: 600; }
.q-item .q-stage { color: var(--ink-mute); font-size: 11.5px; margin-top: 1px; }
.q-item .q-when { font-family: var(--font-mono); font-size: 10.5px; color: var(--ink-mute); }
.q-item .q-kind {
  font-size: 9.5px; text-transform: uppercase; letter-spacing: 0.10em;
  padding: 1px 6px; border-radius: 4px;
  background: var(--bg-tint); color: var(--ink-mute); font-weight: 700;
}
.q-item .q-kind.photo { background: var(--info-tint); color: var(--info); }

.val-empty {
  padding: 60px 40px;
  text-align: center;
}
.val-empty .icon-big {
  width: 64px; height: 64px;
  border-radius: 50%;
  background: var(--ok-tint);
  color: var(--ok);
  display: grid; place-items: center;
  margin: 0 auto 14px;
}
.val-empty .icon-big svg { width: 28px; height: 28px; }
.val-empty h3 { font-family: var(--font-display); font-size: 22px; margin: 0 0 6px; font-weight: 600; }
.val-empty p { color: var(--ink-mute); margin: 0; }

/* ───── Hint cards ───── */

.hint-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(360px, 1fr));
  gap: 18px;
}
.hint-card {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-1);
  padding: 18px 20px;
  display: flex; flex-direction: column; gap: 12px;
}
.hint-card .head {
  display: flex; align-items: center; gap: 12px;
}
.hint-card .head .info { flex: 1; }
.hint-card .head .team { font-weight: 600; font-size: 14.5px; }
.hint-card .head .stage { color: var(--ink-mute); font-size: 12px; margin-top: 1px; }
.hint-card .ref {
  font-size: 12.5px;
  padding: 10px 12px;
  background: var(--bg-tint);
  border-radius: 8px;
  border-left: 3px solid var(--warn);
  color: var(--ink-soft);
}
.hint-card .ref .lbl {
  font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.10em;
  font-weight: 700; color: oklch(from var(--warn) calc(l - 0.18) c h);
  display: block; margin-bottom: 3px;
}
.hint-card .ref em { font-style: italic; color: var(--ink); }
.hint-card .meta {
  display: flex; align-items: center; gap: 10px;
  font-size: 11.5px; color: var(--ink-mute);
}
.hint-card .actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 4px; }

.hint-recent { margin-top: 36px; }
.hint-recent h2 { margin-bottom: 10px; }
.hint-recent-item {
  display: grid;
  grid-template-columns: 36px 1fr auto;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--line-soft);
  align-items: flex-start;
}
.hint-recent-item:last-child { border-bottom: 0; }
.hint-recent-item .body { font-size: 13px; }
.hint-recent-item .body .who { font-weight: 600; }
.hint-recent-item .body .src { color: var(--ink-mute); font-size: 11.5px; }
.hint-recent-item .body .txt { margin-top: 5px; line-height: 1.45; }
.hint-recent-item .when { font-family: var(--font-mono); font-size: 11px; color: var(--ink-mute); }

/* ───── Team history ───── */

.history-list {
  display: flex;
  flex-direction: column;
  gap: 18px;
}
.history-card .card-head {
  align-items: flex-start;
}
.history-ref {
  display: flex;
  gap: 10px;
  background: var(--bg-tint);
  border-left: 3px solid var(--brass);
  padding: 10px 12px;
  border-radius: 6px;
  font-size: 13px;
  color: var(--ink-soft);
  margin-bottom: 16px;
}
.history-ref .lbl {
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.10em;
  color: var(--brass-deep);
  font-weight: 700;
  flex-shrink: 0;
}
.history-columns {
  display: grid;
  grid-template-columns: 1.2fr 1fr;
  gap: 22px;
  align-items: start;
}
.history-title {
  margin: 0 0 10px;
  font-size: 15px;
  display: flex;
  align-items: center;
  gap: 7px;
}
.history-items {
  display: flex;
  flex-direction: column;
  gap: 0;
  border: 1px solid var(--line-soft);
  border-radius: 10px;
  overflow: hidden;
  background: var(--paper);
}
.history-item {
  border: 0;
  border-bottom: 1px solid var(--line-soft);
  border-radius: 0;
  padding: 12px 14px;
  background: var(--paper-soft);
}
.history-item:last-child {
  border-bottom: 0;
}
.history-item-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
}
.history-body {
  font-size: 13.5px;
  color: var(--ink);
  line-height: 1.45;
  overflow-wrap: anywhere;
}
.history-meta {
  margin-top: 6px;
  font-size: 11.5px;
  color: var(--ink-mute);
}
.history-photo-link {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: var(--info);
  font-weight: 600;
}
.history-photo-thumb {
  display: inline-block;
  width: 110px;
  max-width: 100%;
  padding: 5px;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: var(--paper);
  color: var(--info);
  font-weight: 600;
  box-shadow: 0 1px 0 oklch(0.85 0.02 75 / 0.45);
  margin: 2px 0 4px;
}
.history-photo-thumb img {
  width: 98px;
  height: 74px;
  max-width: none;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  display: block;
  background: var(--bg-tint);
  border-radius: 5px;
}
.history-photo-thumb span {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  padding: 5px 2px 0;
  font-size: 10.5px;
}
.history-photo-thumb:hover img {
  opacity: 0.92;
}

/* ───── Bot message templates ───── */

.bot-template-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(360px, 1fr));
  gap: 18px;
}
.bot-template-card textarea {
  min-height: 130px;
}
.template-vars {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 12px;
  font-size: 12px;
  color: var(--ink-mute);
}
.template-default {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  background: var(--paper-soft);
  border: 1px solid var(--line-soft);
  border-radius: 8px;
  padding: 10px 12px;
  color: var(--ink-soft);
  font-size: 12px;
}

/* ───── Broadcast ───── */

.broadcast-result {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.broadcast-result > div {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--line-soft);
  padding-bottom: 8px;
}
.broadcast-result > div:last-child {
  border-bottom: 0;
  padding-bottom: 0;
}
.broadcast-result b {
  font-family: var(--font-display);
  font-size: 22px;
}

/* ───── Photo placeholder ───── */

.photo-placeholder {
  width: 100%;
  aspect-ratio: 4/3;
  background:
    repeating-linear-gradient(45deg,
      oklch(from var(--brass) l c h / 0.05) 0 12px,
      oklch(from var(--brass) l c h / 0.10) 12px 24px);
  display: flex; align-items: center; justify-content: center;
  font-family: var(--font-mono);
  color: var(--ink-mute);
  font-size: 12px;
  letter-spacing: 0.05em;
  flex-direction: column;
  gap: 8px;
}

/* ───── Native buttons (form senza classe esplicita) ───── */
/* Quasi tutti i form usano .btn esplicitamente; questo è il fallback. */
button:not(.btn):not(.q-item) {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 8px 14px;
  background: var(--ink);
  border: 1px solid var(--ink);
  color: var(--paper);
  border-radius: 8px;
  font-size: 13.5px;
  font-weight: 500;
  cursor: pointer;
  transition: background .15s, border-color .15s, color .15s, transform .05s;
}
button:not(.btn):not(.q-item):hover { background: oklch(from var(--ink) calc(l + 0.06) c h); }
button:not(.btn):not(.q-item):disabled { opacity: 0.5; cursor: not-allowed; }
button.danger { background: var(--err) !important; border-color: var(--err) !important; color: white !important; }
button.danger:hover { background: oklch(from var(--err) calc(l - 0.05) c h) !important; }
button.ok { background: var(--ok) !important; border-color: var(--ok) !important; color: white !important; }
button.ok:hover { background: oklch(from var(--ok) calc(l - 0.05) c h) !important; }
button.link { background: transparent !important; border-color: transparent !important; color: var(--ink-soft) !important; padding: 0 !important; font-size: 13px !important; text-decoration: underline; }
button.link:hover { background: transparent !important; color: var(--ink) !important; }
button.link.danger { color: var(--err) !important; background: transparent !important; }

.tag {
  font-size: 10.5px;
  padding: 1px 8px;
  border-radius: 999px;
  margin-left: 6px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.tag.ok { background: var(--ok-tint); color: oklch(from var(--ok) calc(l - 0.1) c h); }
.tag.cur { background: var(--brass-tint); color: var(--brass-deep); }

.code {
  font-family: var(--font-mono);
  background: var(--brass-tint);
  color: var(--brass-deep);
  padding: 3px 8px;
  border-radius: 5px;
  font-size: 12.5px;
  font-weight: 600;
  letter-spacing: 0.08em;
}

/* Responsive */
@media (max-width: 1100px) {
  .kpi-row { grid-template-columns: repeat(2, 1fr); }
  .dash-grid { grid-template-columns: 1fr; }
  .val-layout { grid-template-columns: 1fr; }
  .history-columns { grid-template-columns: 1fr; }
}
@media (max-width: 760px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: relative; height: auto; }
  .page { padding: 16px; }
  .topbar { padding: 14px 16px; }
}
