/* Reset, tipografia, focus, utility, view transitions */

*, *::before, *::after { box-sizing: border-box; }
* { margin: 0; }

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  font-family: var(--font-sans);
  font-size: 16px;
  font-feature-settings: "cv11", "ss01", "ss03";
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  background: var(--bg);
  color: var(--text);
}

body {
  min-height: 100dvh;
  font-size: var(--fs-md);
  line-height: var(--lh);
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
}

img, svg, video { display: block; max-width: 100%; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: 0; padding: 0; }
a { color: inherit; text-decoration: none; }
h1, h2, h3, h4 { font-weight: 600; line-height: var(--lh-tight); letter-spacing: -0.015em; }
h1 { font-size: var(--fs-2xl); letter-spacing: -0.025em; }
h2 { font-size: var(--fs-xl); }
h3 { font-size: var(--fs-lg); }
p { color: var(--text-2); }
table { border-collapse: collapse; width: 100%; }
[hidden] { display: none !important; }
::selection { background: var(--accent-soft-2); }

.icon {
  width: 18px;
  height: 18px;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.icon--sm { width: 15px; height: 15px; }
.icon--lg { width: 22px; height: 22px; }
.icon--xl { width: 28px; height: 28px; }

:focus { outline: none; }
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--r-sm);
}

.skip-link {
  position: fixed;
  top: 8px;
  left: 8px;
  z-index: 1000;
  padding: 8px 14px;
  background: var(--accent);
  color: var(--text-inverse);
  border-radius: var(--r);
  transform: translateY(-160%);
  transition: transform var(--d) var(--ease-out);
}
.skip-link:focus { transform: none; }

.sr-only {
  position: absolute !important;
  width: 1px; height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* Scrollbar sobrie */
* { scrollbar-width: thin; scrollbar-color: var(--border-strong) transparent; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 10px; border: 3px solid transparent; background-clip: padding-box; }
::-webkit-scrollbar-track { background: transparent; }

/* Utility */
.muted { color: var(--text-3); }
.text-2 { color: var(--text-2); }
.mono { font-family: var(--font-mono); font-size: 0.92em; }
.nowrap { white-space: nowrap; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.row { display: flex; align-items: center; gap: var(--sp-2); }
.row-3 { display: flex; align-items: center; gap: var(--sp-3); }
.stack { display: flex; flex-direction: column; gap: var(--sp-3); }
.stack-2 { display: flex; flex-direction: column; gap: var(--sp-2); }
.stack-4 { display: flex; flex-direction: column; gap: var(--sp-4); }
.grow { flex: 1; min-width: 0; }
.spacer { flex: 1; }
.tnum { font-variant-numeric: tabular-nums; }
.fw-600 { font-weight: 600; }
.fs-xs { font-size: var(--fs-xs); }
.fs-sm { font-size: var(--fs-sm); }

/* ---------------------------------------------------------------------
   View Transitions: cambio pagina con fade + leggero slide
   --------------------------------------------------------------------- */
@view-transition { navigation: none; }

::view-transition-old(root),
::view-transition-new(root) { animation: none; }

::view-transition-old(page) {
  animation: vt-out 140ms var(--ease-in) both;
}
::view-transition-new(page) {
  animation: vt-in var(--d-slower) var(--ease-out) 40ms both;
}
::view-transition-group(*) { animation-duration: var(--d-slow); animation-timing-function: var(--ease-out); }

@keyframes vt-out { to { opacity: 0; transform: translateY(-3px); } }
@keyframes vt-in { from { opacity: 0; transform: translateY(6px); } }

/* Passaggio tema: rivelazione circolare dal pulsante */
::view-transition-old(theme), ::view-transition-new(theme) { animation: none; mix-blend-mode: normal; }
.theme-transition::view-transition-old(root),
.theme-transition::view-transition-new(root) { animation: none; mix-blend-mode: normal; }

@keyframes fade-in { from { opacity: 0; } }
@keyframes fade-out { to { opacity: 0; } }
@keyframes rise-in { from { opacity: 0; transform: translateY(8px); } }
@keyframes pop-in { from { opacity: 0; transform: scale(0.96); } }
@keyframes shake {
  10%, 90% { transform: translateX(-1px); }
  20%, 80% { transform: translateX(2px); }
  30%, 50%, 70% { transform: translateX(-4px); }
  40%, 60% { transform: translateX(4px); }
}
@keyframes shimmer { to { transform: translateX(100%); } }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes pulse-ring {
  0% { box-shadow: 0 0 0 0 var(--accent-ring); }
  100% { box-shadow: 0 0 0 10px transparent; }
}

.anim-rise { animation: rise-in var(--d-slow) var(--ease-out) both; }

/* Le animazioni d'ingresso valgono solo per la prima apparizione della pagina:
   quando i dati cambiano il contenuto si aggiorna sul posto, senza "rientrare". */
.is-settled :is(.anim-rise, .kpi, .dash-grid > .card, .cal-ev, .col, .tl-item, .tag, .wf-card, .map-row, .wh-step) { animation: none; }
.shake { animation: shake 420ms var(--ease-out); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 1ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 1ms !important;
    scroll-behavior: auto !important;
  }
  ::view-transition-group(*), ::view-transition-old(*), ::view-transition-new(*) { animation: none !important; }
}
