/* ===== Header: brand, badge aggiornamento, switch lingua ===== */
.site-header {
  position: sticky;
  top: 0;
  z-index: var(--z-header);
  background: rgba(18, 16, 14, 0.92);
  border-bottom: 1px solid var(--line);
}

.header-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  column-gap: var(--s3);
  row-gap: var(--s1);
  min-height: 56px;
  padding-block: var(--s2);
}

.brand {
  font-family: var(--font-display);
  font-size: var(--text-lg);
  font-weight: 700;
}

#updated-badge {
  margin-left: auto;
  min-height: 1.6em;
  font-size: var(--text-xs);
  color: var(--muted);
  text-align: right;
}

.lang-switch {
  display: inline-flex;
  gap: var(--s1);
}

.lang-switch button {
  padding: 0.35em 0.8em;
  font-family: var(--font-body);
  font-size: var(--text-sm);
  color: var(--ink);
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: 999px;
  cursor: pointer;
}

.lang-switch button:hover {
  border-color: var(--muted);
}

.lang-switch button[aria-pressed="true"] {
  border-color: var(--gold);
  color: var(--gold);
  font-weight: 600;
}

/* Il badge riempito non deve far crescere l'header sticky (CLS): su schermi
   stretti occupa da subito una riga propria ad altezza fissa. */
@media (max-width: 640px) {
  #updated-badge {
    order: 3;
    flex-basis: 100%;
    margin-left: 0;
    text-align: left;
  }

  .lang-switch {
    margin-left: auto;
  }
}

/* ===== Selettori a discesa (finestra correlazione, prodotto forbice) ===== */
.field {
  display: inline-flex;
  align-items: center;
  gap: var(--s2);
  margin-bottom: var(--s4);
  font-size: var(--text-sm);
}

.field > span {
  color: var(--muted);
}

.field select {
  padding: 0.35em 0.6em;
  font-family: var(--font-body);
  font-size: var(--text-sm);
  color: var(--ink);
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: var(--r1);
}

/* ===== Target touch >= 44px su puntatori grezzi (WCAG 2.5.8) ===== */
@media (pointer: coarse) {
  .btn-group button,
  .pill-btn,
  .lang-switch button,
  .field select,
  .check,
  .what summary {
    min-height: 44px;
  }

  .check input {
    width: 1.25rem;
    height: 1.25rem;
  }
}

/* ===== Skeleton shimmer (mountLazy: fino a buildFn risolta) ===== */
.skeleton {
  position: absolute;
  inset: 0;
  background:
    linear-gradient(100deg, transparent 32%, rgba(232, 196, 122, 0.09) 50%, transparent 68%)
    var(--bg-sunken);
  background-size: 220% 100%;
  animation: skeleton-shimmer 1.4s linear infinite;
}

@keyframes skeleton-shimmer {
  from {
    background-position: 180% 0;
  }

  to {
    background-position: -80% 0;
  }
}

/* ===== Banner errore caricamento globale ===== */
.load-error {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: var(--s3);
  padding: var(--s3) var(--s4);
  background: var(--bg-elev);
  border-bottom: 2px solid var(--danger);
}

.load-error p {
  color: var(--danger);
  font-weight: 600;
}

.load-error[hidden] {
  display: none;
}

/* ===== Stat cards (hero, correlazione, forbice) ===== */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: var(--s3);
  margin-block: var(--s5);
}

.stat-card {
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: var(--r1);
  padding: var(--s3) var(--s4);
}

.stat-card dt {
  font-size: var(--text-xs);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.stat-card dd {
  margin: 0;
  font-family: var(--font-mono);
  font-size: var(--text-lg);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

/* ===== Verdetto hero =====
   min-height riserva chip + subriga PRIMA dei dati: zero CLS al caricamento. */
.verdict {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  column-gap: var(--s3);
  row-gap: var(--s2);
  min-height: 4em;
  margin-block: var(--s4) 0;
}

/* Su mobile chip + subriga vanno a capo: riservo l'altezza reale perche'
   l'arrivo del verdetto non sposti il resto della pagina (CLS). */
@media (max-width: 640px) {
  .verdict {
    min-height: 8.5em;
  }

  .note-line {
    min-height: 3.2em;
  }
}

.verdict-chip {
  display: inline-flex;
  align-items: center;
  padding: 0.35em 0.9em;
  border: 1px solid currentColor;
  border-radius: 999px;
  font-size: var(--text-sm);
  font-weight: 600;
  line-height: 1.35;
}

.verdict-high {
  color: var(--ok);
}

.verdict-partial {
  color: var(--gold);
}

.verdict-low {
  color: var(--danger);
}

.verdict-sub {
  flex-basis: 100%;
  color: var(--muted);
  font-size: var(--text-sm);
}

/* ===== Sparkline hero =====
   aspect-ratio via ID (batte .chart-host e il fallback mobile 4/5): lo spazio e'
   riservato dal CSS prima dei dati, nessun shift al mount del canvas. */
#hero-chart {
  aspect-ratio: 21 / 9;
}

#hero-chart.draw-in {
  clip-path: inset(0 100% 0 0);
  transition: clip-path 900ms var(--ease);
}

#hero-chart.draw-in.is-shown {
  clip-path: inset(0 0 0 0);
}

/* ===== CTA hero ===== */
.btn-cta {
  margin-top: var(--s5);
  padding: 0.65em 1.4em;
  font-family: var(--font-body);
  font-size: var(--text-md);
  font-weight: 600;
  color: var(--bg-sunken);
  background: var(--gold);
  border: 0;
  border-radius: var(--r1);
  cursor: pointer;
}

.btn-cta:hover {
  filter: brightness(1.08);
}

.btn-cta:active {
  transform: translateY(1px);
}

/* ===== Toolbar esplora =====
   Layout flex-wrap: su mobile i gruppi vanno a capo senza overflow. */
.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--s2) var(--s3);
  margin-bottom: var(--s4);
}

.btn-group {
  display: inline-flex;
  flex-wrap: wrap;
  gap: var(--s2);
}

.btn-group button,
.pill-btn {
  padding: 0.35em 0.9em;
  font-family: var(--font-body);
  font-size: var(--text-sm);
  color: var(--ink);
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: 999px;
  cursor: pointer;
}

.btn-group button:hover,
.pill-btn:hover {
  border-color: var(--muted);
}

.btn-group button.is-active {
  border-color: var(--gold);
  color: var(--gold);
  font-weight: 600;
}

.check-group {
  display: inline-flex;
  flex-wrap: wrap;
  gap: var(--s3);
}

.check {
  display: inline-flex;
  align-items: center;
  gap: 0.45em;
  font-size: var(--text-sm);
  cursor: pointer;
}

.check input {
  accent-color: var(--gold);
}
