/* ==========================================================================
   Radar Appalto — componenti condivisi (redesign 09/2026)
   Richiede tokens.css. Usato da home, pagine SEO, guide e dashboard.
   Nomi BEM corti: .blocco, .blocco__parte, .blocco--variante, stato .is-*.
   Un componente = un blocco di regole, in quest'ordine: base → layout → componenti → utilità.
   ========================================================================== */

/* ---------- base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { font-size: 17px; -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font-family: var(--font-sans); font-size: var(--fs-2); line-height: var(--lh);
  -webkit-font-smoothing: antialiased; overflow-x: hidden;
}
h1, h2, h3, h4 { font-family: var(--font-head); line-height: var(--lh-tight); margin: 0 0 var(--sp-3); color: var(--ink); letter-spacing: -0.01em; }
h1 { font-size: var(--fs-6); font-weight: var(--w-bold); }
h2 { font-size: var(--fs-5); font-weight: var(--w-bold); }
h3 { font-size: var(--fs-4); font-weight: var(--w-bold); }
p { margin: 0 0 var(--sp-4); }
a { color: var(--cta); text-decoration: underline; text-decoration-thickness: 1px; text-underline-offset: 2px; }
a:hover { color: var(--cta-hover); }
img, svg { max-width: 100%; display: block; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; border-radius: var(--r-sm); }
::selection { background: var(--accent); color: var(--accent-ink); }
.skip-link { position: absolute; left: -999px; top: 0; background: var(--ink); color: var(--bg); padding: var(--sp-2) var(--sp-4); z-index: var(--z-toast); }
.skip-link:focus { left: var(--sp-4); }

/* ---------- layout ---------- */
.wrap { width: 100%; max-width: var(--wrap); margin: 0 auto; padding: 0 var(--sp-4); }
.wrap--narrow { max-width: var(--wrap-narrow); }
.section { padding: var(--sp-7) 0; }
.section--tight { padding: var(--sp-5) 0; }
.section--band { background: var(--surface-2); }
.stack > * + * { margin-top: var(--sp-4); }
.stack--sm > * + * { margin-top: var(--sp-2); }
.row { display: flex; flex-wrap: wrap; gap: var(--sp-3); align-items: center; }
.row--between { justify-content: space-between; }
.grid { display: grid; gap: var(--sp-4); grid-template-columns: 1fr; }
@media (min-width: 48em) { .grid--2 { grid-template-columns: 1fr 1fr; } .grid--3 { grid-template-columns: repeat(3, 1fr); } }
.sep { border: 0; border-top: 1px solid var(--line); margin: var(--sp-5) 0; }

/* ---------- tipografia di servizio ---------- */
.kicker { display: inline-block; font-size: var(--fs-0); font-weight: var(--w-bold); letter-spacing: 0.08em; text-transform: uppercase; color: var(--ink-3); margin-bottom: var(--sp-2); }
.lead { font-size: var(--fs-3); color: var(--ink-2); }
.small { font-size: var(--fs-1); color: var(--ink-3); }
.note { font-size: var(--fs-0); color: var(--ink-3); }
.num { font-family: var(--font-num); font-variant-numeric: tabular-nums lining-nums; }
.hl { background: var(--accent); color: var(--accent-ink); padding: 0 0.2em; border-radius: 4px; box-decoration-break: clone; }
.eyebrow { font-size: var(--fs-1); color: var(--ink-3); margin: 0 0 var(--sp-1); }
.h-sec { display: flex; align-items: baseline; justify-content: space-between; gap: var(--sp-3); margin: 0 0 var(--sp-4); }
.h-sec h2, .h-sec h3 { margin: 0; }

/* ---------- bottoni ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--sp-2);
  min-height: var(--tap); padding: 0 var(--sp-5); border-radius: var(--r-md);
  border: 1.5px solid var(--ink); background: var(--surface); color: var(--ink);
  font-weight: var(--w-bold); font-size: var(--fs-2); line-height: 1.2; text-decoration: none;
  cursor: pointer; white-space: nowrap; transition: background .15s, border-color .15s, transform .05s;
}
.btn:hover { background: var(--surface-2); color: var(--ink); }
.btn:active { transform: translateY(1px); }
.btn:disabled, .btn[aria-disabled="true"] { opacity: .55; cursor: not-allowed; }
.btn--primary { background: var(--cta); border-color: var(--cta); color: var(--cta-ink); }
.btn--primary:hover { background: var(--cta-hover); border-color: var(--cta-hover); color: var(--cta-ink); }
.btn--ghost { border-color: transparent; background: transparent; color: var(--cta); text-decoration: underline; text-underline-offset: 3px; padding: 0 var(--sp-2); }
.btn--ghost:hover { background: var(--accent); color: var(--accent-ink); }
@media (max-width: 47.99em) { .btn { white-space: normal; text-align: center; line-height: 1.25; } }   /* su telefono un'etichetta lunga va a capo invece di sbordare dallo schermo */
.btn--sm { min-height: 2.25rem; padding: 0 var(--sp-3); font-size: var(--fs-1); border-radius: var(--r-sm); }
.btn--block { display: flex; width: 100%; }
.btn--icon { width: var(--tap); min-height: var(--tap); padding: 0; border-radius: var(--r-pill); }   /* anche con .btn--sm: la x di chiusura resta toccabile */
.btn--lg { min-height: 3.25rem; font-size: var(--fs-3); padding: 0 var(--sp-6); }

/* ---------- chip (filtro / stato) e badge (etichetta) ---------- */
.chip {
  display: inline-flex; align-items: center; gap: var(--sp-1); min-height: 2.25rem; padding: 0 var(--sp-3);
  border-radius: var(--r-pill); border: 1.5px solid var(--line); background: var(--surface);
  color: var(--ink-2); font-size: var(--fs-1); font-weight: var(--w-medium); cursor: pointer; white-space: nowrap;
}
.chip:hover { border-color: var(--ink-3); }
.chip.is-on { background: var(--ink); border-color: var(--ink); color: var(--bg); }
.chip__x { margin-left: var(--sp-1); opacity: .7; }
.chips { display: flex; gap: var(--sp-2); overflow-x: auto; padding-bottom: var(--sp-1); scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.badge {
  display: inline-flex; align-items: center; gap: .3em; padding: .15em .6em; border-radius: var(--r-sm);
  font-size: var(--fs-0); font-weight: var(--w-bold); line-height: 1.5; white-space: nowrap;
  background: var(--surface-2); color: var(--ink-2);
}
.badge--ok { background: var(--ok-bg); color: var(--ok); }
.badge--warn { background: var(--warn-bg); color: var(--warn); }
.badge--danger { background: var(--danger); color: #fff; }   /* pieno: e' l'unico badge che deve saltare all'occhio, senza lampeggiare */
.badge--accent { background: var(--accent); color: var(--accent-ink); }

/* ---------- card ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); padding: var(--sp-5); box-shadow: var(--shadow-1); }
.card--flat { box-shadow: none; }
.card--band { background: var(--surface-2); border-color: transparent; box-shadow: none; }
.card--brand { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
.card--brand h2, .card--brand h3, .card--brand a { color: inherit; }
.card__title { font-size: var(--fs-3); font-weight: var(--w-bold); margin: 0 0 var(--sp-1); }
.card__meta { font-size: var(--fs-1); color: var(--ink-3); }

/* ---------- statistica (numero + etichetta) ---------- */
.stat { display: flex; flex-direction: column; gap: 0.1rem; }
.stat__n { font-family: var(--font-num); font-variant-numeric: tabular-nums; font-size: var(--fs-5); font-weight: var(--w-bold); line-height: 1.1; color: var(--ink); }
.stat__n--xl { font-size: var(--fs-7); }
.stat__l { font-size: var(--fs-1); color: var(--ink-3); }
.stats { display: flex; gap: var(--sp-3); overflow-x: auto; scroll-snap-type: x proximity; padding-bottom: var(--sp-1); scrollbar-width: none; }
.stats::-webkit-scrollbar { display: none; }
.stats > .card { flex: 0 0 10.5rem; scroll-snap-align: start; padding: var(--sp-4); }
@media (min-width: 48em) { .stats { display: grid; grid-template-columns: repeat(4, 1fr); overflow: visible; } .stats > .card { flex: initial; } }

/* ---------- card gara (condivisa: home, dashboard, pagine SEO) ---------- */
.gara {
  position: relative; display: grid; gap: var(--sp-2); padding: var(--sp-4);
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg);
  text-decoration: none; color: inherit;
}
.gara:hover { border-color: var(--ink-3); }
.gara.is-key { border-color: var(--cta); box-shadow: 0 0 0 3px var(--accent); }
.gara__top { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--sp-2); min-width: 0; }
.gara__top .badge { flex: 0 1 auto; min-width: min-content; white-space: normal; text-align: right; line-height: 1.3; }   /* puo' andare a capo ma mai piu' stretto della parola piu' lunga: 'Urgente' sbordava dalla card */
.gara__ente { font-size: var(--fs-1); color: var(--ink-3); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1 1 auto; min-width: 0; }
.gara__ogg { font-weight: var(--w-bold); font-size: var(--fs-2); line-height: 1.3; margin: 0; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.gara__meta { display: flex; flex-wrap: wrap; gap: var(--sp-2) var(--sp-4); font-size: var(--fs-1); color: var(--ink-2); align-items: center; }
.gara__val { font-family: var(--font-num); font-variant-numeric: tabular-nums; font-weight: var(--w-bold); color: var(--ink); }
.gara__scad { display: inline-flex; align-items: center; gap: .35em; }
.gara__scad::before { content: ""; width: .6em; height: .6em; border-radius: 50%; background: currentColor; }
.gara__scad--urg { color: var(--danger); font-weight: var(--w-bold); }
.gara__scad--soon { color: var(--warn); font-weight: var(--w-bold); }
.gara__scad--ok { color: var(--ok); }
.gara__why { display: flex; flex-wrap: wrap; gap: var(--sp-1); }
.gara__act { display: flex; gap: var(--sp-2); align-items: center; justify-content: space-between; margin-top: var(--sp-1); }
.gara__act .btn { flex: 1; min-height: var(--tap); }   /* i due bottoni della card sono i piu' toccati: area piena */
@media (min-width: 48em) { .gara__act .btn { flex: initial; } }
.gare { display: grid; gap: var(--sp-3); }
.gare > *, .grid > *, .stack > * { min-width: 0; }

/* ---------- tabella → card impilate sotto md ---------- */
.rows { width: 100%; border-collapse: collapse; font-size: var(--fs-1); }
.rows th { text-align: left; font-size: var(--fs-0); font-weight: var(--w-bold); letter-spacing: .06em; text-transform: uppercase; color: var(--ink-3); padding: var(--sp-2) var(--sp-3); border-bottom: 1px solid var(--line); }
.rows td { padding: var(--sp-3); border-bottom: 1px solid var(--line); vertical-align: top; }
.rows td.num, .rows th.num { text-align: right; font-family: var(--font-num); font-variant-numeric: tabular-nums; white-space: nowrap; }
.rows tr.is-key td { background: var(--accent); }
@media (max-width: 47.99em) {
  .rows thead { display: none; }
  .rows tr { display: grid; gap: var(--sp-1); padding: var(--sp-3) 0; border-bottom: 1px solid var(--line); }
  .rows td { display: block; padding: 0; border: 0; }
  .rows td.num { text-align: left; }
  .rows td[data-label]::before { content: attr(data-label); display: block; font-size: var(--fs-0); color: var(--ink-3); text-transform: uppercase; letter-spacing: .06em; }
  /* righe toccabili: su telefono diventano card con bordo e l'azione "Apri" in fondo */
  .rows--tap tr[role="button"] { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md); padding: var(--sp-3) var(--sp-4); margin-bottom: var(--sp-2); }
  .rows--tap tr[role="button"]:active { background: var(--surface-2); }
  .rows--tap .rows__go { text-align: left; margin-top: var(--sp-1); }
}
.rows--tap tr[role="button"] { cursor: pointer; }
.rows--tap tr[role="button"]:hover td { background: var(--surface-2); }
.rows__go { text-align: right; white-space: nowrap; }
.rows__go .btn { pointer-events: none; }

/* ---------- form ---------- */
.field { display: grid; gap: var(--sp-1); }
.field__label { font-size: var(--fs-1); font-weight: var(--w-bold); color: var(--ink-2); }
.field__hint { font-size: var(--fs-0); color: var(--ink-3); }
.input, .field select, .field input:not([type="checkbox"]):not([type="radio"]), .field textarea {
  width: 100%; min-height: var(--tap); padding: 0 var(--sp-3); border: 1.5px solid var(--line); border-radius: var(--r-md);
  background: var(--surface); color: var(--ink); font-size: var(--fs-2);
}
.field textarea { padding: var(--sp-2) var(--sp-3); min-height: 6rem; }
.field select:focus, .field input:focus, .input:focus { border-color: var(--ink); outline: 3px solid var(--focus); outline-offset: 1px; }
.field--inline { display: flex; gap: var(--sp-2); align-items: stretch; }
.field--inline .input { flex: 1; min-width: 0; }
@media (max-width: 29.99em) { .field--inline { flex-wrap: wrap; } .field--inline .btn { flex: 1 1 100%; } }
.check { display: flex; gap: var(--sp-2); align-items: flex-start; font-size: var(--fs-1); color: var(--ink-2); }
.check input { width: 1.25rem; height: 1.25rem; margin-top: .15rem; accent-color: var(--cta); }

/* ---------- sheet: bottom sheet su telefono, modale centrata da md ---------- */
.sheet { position: fixed; top: 0; right: 0; bottom: 0; left: 0; margin: 0; border: 0; padding: 0; background: transparent; width: 100%; height: 100%; max-width: 100%; max-height: 100%; transform: none; overflow: hidden; }
.sheet::backdrop { background: var(--scrim); }
.sheet[open] { display: grid; align-items: end; justify-items: center; }
.sheet__card { width: 100%; max-width: 100%; min-width: 0; max-height: 92vh; overflow: auto; overflow-x: hidden; background: var(--surface); border-radius: var(--r-lg) var(--r-lg) 0 0; box-shadow: var(--shadow-2); }
.sheet__head { position: sticky; top: 0; display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3); padding: var(--sp-3) var(--sp-4); background: var(--surface); border-bottom: 1px solid var(--line); }
.sheet__head h2, .sheet__head h3 { margin: 0; font-size: var(--fs-3); }
.sheet__body { padding: var(--sp-4); min-width: 0; overflow-x: hidden; overflow-wrap: anywhere; }
.sheet__foot { position: sticky; bottom: 0; padding: var(--sp-3) var(--sp-4); background: var(--surface); border-top: 1px solid var(--line); display: flex; gap: var(--sp-2); }
.sheet__foot > .input { flex: 1; min-width: 0; width: auto; }   /* input + bottone nella stessa riga senza sfondare */
@media (min-width: 48em) {
  .sheet[open] { align-items: center; }
  .sheet__card { max-width: 44rem; max-height: 88vh; border-radius: var(--r-lg); }
}

/* ---------- tab bar (mobile in basso) / tab in alto (desktop) ---------- */
.tabbar { position: fixed; left: 0; right: 0; bottom: 0; z-index: var(--z-sticky); display: grid; grid-auto-flow: column; background: var(--surface); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); }
.tabbar__item { display: grid; justify-items: center; gap: 2px; padding: var(--sp-2) 0 var(--sp-2); min-height: 3.5rem; color: var(--ink-3); text-decoration: none; font-size: var(--fs-0); font-weight: var(--w-medium); border: 0; background: none; cursor: pointer; }
.tabbar__item svg { width: 1.5rem; height: 1.5rem; }
.tabbar__item.is-active { color: var(--cta); font-weight: var(--w-bold); }
.has-tabbar { padding-bottom: 4.5rem; }
@media (min-width: 48em) {
  .tabbar { position: static; grid-auto-flow: column; justify-content: start; gap: var(--sp-2); border: 0; border-bottom: 1px solid var(--line); background: transparent; padding: 0; }
  .tabbar__item { grid-auto-flow: column; align-items: center; gap: var(--sp-2); padding: var(--sp-3) var(--sp-3); min-height: 0; font-size: var(--fs-2); border-bottom: 3px solid transparent; }
  .tabbar__item.is-active { border-bottom-color: var(--cta); color: var(--ink); }
  .tabbar__item svg { width: 1.15rem; height: 1.15rem; }
  .has-tabbar { padding-bottom: 0; }
}

/* ---------- header sito ---------- */
.header { position: sticky; top: 0; z-index: var(--z-sticky); background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(10px); border-bottom: 1px solid var(--line); }
.header__in { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-4); min-height: 3.5rem; }
.header__logo { display: inline-flex; align-items: center; gap: var(--sp-2); font-weight: var(--w-bold); font-size: var(--fs-3); color: var(--brand); text-decoration: none; font-family: var(--font-head); }
.header__nav { display: flex; gap: var(--sp-4); align-items: center; }
.header__nav a { color: var(--ink-2); text-decoration: none; font-weight: var(--w-medium); }
.header__nav a:hover { color: var(--ink); }
.header__nav .hide-sm { display: none; }
@media (min-width: 48em) { .header__nav .hide-sm { display: inline; } }

/* ---------- stati vuoti, skeleton, toast, fab ---------- */
.empty { text-align: center; padding: var(--sp-6) var(--sp-4); border: 1.5px dashed var(--line); border-radius: var(--r-lg); color: var(--ink-2); }
.empty__title { font-weight: var(--w-bold); color: var(--ink); margin: 0 0 var(--sp-2); }
.skeleton { display: block; height: 1em; border-radius: var(--r-sm); background: linear-gradient(90deg, var(--surface-2) 25%, var(--line) 50%, var(--surface-2) 75%); background-size: 200% 100%; animation: sk 1.2s infinite; }
@keyframes sk { to { background-position: -200% 0; } }
@media (prefers-reduced-motion: reduce) { .skeleton { animation: none; } }
.toasts { position: fixed; left: var(--sp-4); right: var(--sp-4); bottom: calc(var(--sp-4) + 4rem); z-index: var(--z-toast); display: grid; gap: var(--sp-2); pointer-events: none; }
.toast { pointer-events: auto; margin: 0 auto; max-width: 30rem; padding: var(--sp-3) var(--sp-4); border-radius: var(--r-md); background: var(--ink); color: var(--bg); box-shadow: var(--shadow-2); font-size: var(--fs-1); }
.toast--ok { background: var(--ok); color: #fff; }
.toast--warn { background: var(--warn); color: #fff; }
.fab { position: fixed; right: var(--sp-4); bottom: calc(var(--sp-4) + 4rem); z-index: var(--z-sticky); min-height: var(--tap); padding: 0 var(--sp-4); border-radius: var(--r-pill); background: var(--ink); color: var(--bg); border: 0; font-weight: var(--w-bold); box-shadow: var(--shadow-2); display: inline-flex; align-items: center; gap: var(--sp-2); cursor: pointer; }
@media (min-width: 48em) { .fab { bottom: var(--sp-5); } .toasts { bottom: var(--sp-5); } }

/* ---------- blocco oscurato (anteprima pubblica) ---------- */
.locked { position: relative; border: 1px solid var(--line); border-radius: var(--r-lg); overflow: hidden; }
.locked__list { filter: blur(5px); user-select: none; pointer-events: none; padding: var(--sp-4); opacity: .85; }
.locked__box { position: relative; margin: calc(-1 * var(--sp-6)) var(--sp-4) var(--sp-4); background: var(--surface); border: 1.5px solid var(--cta); border-radius: var(--r-lg); padding: var(--sp-5); box-shadow: var(--shadow-2); }
.locked__what { display: grid; gap: var(--sp-1); margin: 0 0 var(--sp-4); padding: 0; list-style: none; font-size: var(--fs-1); color: var(--ink-2); }
.locked__what li::before { content: "✓ "; color: var(--ok); font-weight: var(--w-bold); }

/* ---------- checklist attivazione ---------- */
.todo { display: grid; gap: var(--sp-2); margin: 0; padding: 0; list-style: none; }
.todo__item { display: flex; gap: var(--sp-3); align-items: center; padding: var(--sp-3) var(--sp-4); border: 1px solid var(--line); border-radius: var(--r-md); background: var(--surface); }
.todo__item.is-done { color: var(--ink-3); text-decoration: line-through; }
.todo__mark { width: 1.5rem; height: 1.5rem; border-radius: 50%; border: 2px solid var(--line); flex: none; display: grid; place-items: center; font-size: .8rem; }
.todo__item.is-done .todo__mark { background: var(--ok); border-color: var(--ok); color: #fff; }
.todo__item .btn { margin-left: auto; }

/* ---------- utilità ---------- */
.mt-0 { margin-top: 0 !important; } .mb-0 { margin-bottom: 0 !important; }
.center { text-align: center; }
.muted { color: var(--ink-3); }
.sr-only { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
[hidden] { display: none !important; }
