/* Componenti propri del gestionale. Solo token (nessun colore fisso), nessuna ombra.
   Gli stili specifici di una schermata stanno in css/pagine/<nome>.css, non qui. */

/* ---- Guscio ------------------------------------------------ */
.skip-link {
  position: absolute;
  left: var(--space-2);
  top: -4rem;
  z-index: 10;
  padding: var(--space-3) var(--space-4);
  background: var(--surface-card);
  border: 2px solid var(--brand);
  border-radius: var(--radius-md);
  font-weight: 600;
}
.skip-link:focus { top: var(--space-2); }

.app-header {
  display: flex;
  align-items: center;
  gap: var(--space-4);
  flex-wrap: wrap;
  padding: var(--space-3) var(--gutter);
  background: var(--surface-card);
  border-bottom: 1px solid var(--border-subtle);
}
.brand { display: inline-flex; align-items: flex-end; gap: 1px; line-height: 1; color: var(--text-strong); }
.brand:hover { text-decoration: none; color: var(--text-strong); }
.brand__mark { width: 24px; height: auto; }
.brand__word { font-family: var(--font-display); font-weight: 700; letter-spacing: -0.03em; font-size: 22px; }
.brand__sub { margin-left: var(--space-3); font-size: var(--text-sm); font-weight: 600; color: var(--text-muted); align-self: center; }

.app-header__spazio { flex: 1; }
.app-header__utente { font-size: var(--text-sm); color: var(--text-muted); }

.nav { display: flex; gap: 0; flex-wrap: wrap; font-size: var(--text-sm); }
.nav a {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  padding: 0 var(--space-2);
  border-radius: var(--radius-md);
  color: var(--text-body);
  font-weight: 600;
}
.nav a:hover { background: var(--surface-sunken); text-decoration: none; }
.nav a[aria-current='page'] { background: var(--blue-wash); color: var(--blue-800); }
.nav-toggle { display: none; }
@media (max-width: 760px) {
  .nav-toggle { display: inline-flex; }
  .nav { display: none; width: 100%; flex-direction: column; }
  .nav[data-aperto='true'] { display: flex; }
}

.page {
  max-width: var(--container);
  margin: 0 auto;
  padding: var(--space-8) var(--gutter) var(--space-16);
}
.page > * + * { margin-top: var(--space-5); }
.page__intestazione { display: flex; flex-wrap: wrap; align-items: baseline; gap: var(--space-4); justify-content: space-between; }
.stato-dati { font-size: var(--text-sm); color: var(--text-muted); }

.griglia { display: grid; gap: var(--space-4); grid-template-columns: repeat(auto-fill, minmax(min(100%, 260px), 1fr)); }
.griglia--2 { grid-template-columns: repeat(auto-fit, minmax(min(100%, 320px), 1fr)); }
.pila > * + * { margin-top: var(--space-3); }
.riga-azioni { display: flex; flex-wrap: wrap; gap: var(--space-3); align-items: center; }

/* ---- Scheda ------------------------------------------------ */
.card {
  background: var(--surface-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
}
.card > * + * { margin-top: var(--space-3); }
.card__titolo { font-family: var(--font-display); font-weight: 700; font-size: var(--text-lg); color: var(--text-strong); }

/* ---- KPI (contatori della home) ---------------------------- */
.kpi {
  display: block;
  background: var(--surface-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
  color: var(--text-body);
}
a.kpi:hover { text-decoration: none; border-color: var(--brand); }
.kpi__valore { display: block; font-family: var(--font-display); font-weight: 700; font-size: 2.25rem; line-height: 1; color: var(--text-strong); }
.kpi__etichetta { display: block; margin-top: var(--space-2); font-size: var(--text-sm); }
.kpi[data-tono='attenzione'] .kpi__valore { color: var(--copper-600); }

/* ---- Tabella e schede -------------------------------------- */
.table-wrap { overflow-x: auto; position: relative; }
.table { width: 100%; border-collapse: collapse; background: var(--surface-card); }
.table caption { text-align: left; padding-bottom: var(--space-2); color: var(--text-muted); font-size: var(--text-sm); }
.table th, .table td { text-align: left; padding: var(--space-3); border-bottom: 1px solid var(--border-subtle); vertical-align: top; }
.table th { font-size: var(--text-sm); color: var(--text-muted); font-weight: 700; background: var(--surface-sunken); }
.table td.num, .table th.num { text-align: right; font-variant-numeric: tabular-nums; }

/* Da 640 px in giu' le righe diventano schede; l'intestazione di colonna e' ripetuta dall'attributo
   data-label (impostato dal JavaScript con setAttribute, mai con HTML). */
@media (max-width: 640px) {
  .list-cards, .list-cards tbody, .list-cards tr, .list-cards td { display: block; width: 100%; }
  .list-cards caption { display: block; }
  .list-cards thead { display: block; position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0, 0, 0, 0); }
  .list-cards tr { background: var(--surface-card); border: 1px solid var(--border-subtle); border-radius: var(--radius-lg); padding: var(--space-3); margin-bottom: var(--space-3); }
  .list-cards td { border: 0; padding: var(--space-1) 0; }
  .list-cards td::before { content: attr(data-label); display: block; font-size: var(--text-xs); font-weight: 700; color: var(--text-muted); }
  .list-cards td.num { text-align: left; }
}

/* ---- Modulo ------------------------------------------------ */
.field { display: flex; flex-direction: column; gap: var(--space-1); }
.field label, .field .field__label { font-weight: 700; font-size: var(--text-sm); color: var(--text-strong); }
.field__aiuto { font-size: var(--text-sm); color: var(--text-muted); }
.field__errore { font-size: var(--text-sm); color: var(--copper-700); font-weight: 600; }
.field input, .field select, .field textarea {
  min-height: var(--control-md);
  padding: var(--space-2) var(--space-3);
  font: inherit;
  color: var(--text-strong);
  background: var(--surface-card);
  border: 1.5px solid var(--neutral-500);
  border-radius: var(--radius-md);
}
.field input[aria-invalid='true'], .field select[aria-invalid='true'], .field textarea[aria-invalid='true'] { border-color: var(--copper-600); }

/* ---- Avvisi ------------------------------------------------ */
.alert {
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-md);
  border: 1.5px solid var(--border-subtle);
  background: var(--surface-sunken);
  color: var(--text-strong);
}
.alert > * + * { margin-top: var(--space-2); }
.alert__titolo { font-weight: 700; }
.alert[data-tono='info'] { background: var(--blue-wash); border-color: var(--blue-200); color: var(--blue-950); }
.alert[data-tono='attenzione'] { background: var(--sand-100); border-color: var(--copper-100); color: var(--copper-700); }
.alert[data-tono='errore'] { background: var(--copper-wash); border-color: var(--copper-600); color: var(--copper-700); }
.alert[data-tono='ok'] { background: var(--slate-50); border-color: var(--slate-300); color: var(--slate-900); }

/* ---- Scheletro --------------------------------------------- */
.skeleton {
  display: block;
  min-height: 1em;
  border-radius: var(--radius-sm);
  background: linear-gradient(90deg, var(--slate-100), var(--slate-50), var(--slate-100));
  background-size: 200% 100%;
  animation: skeleton-scorri 1.4s linear infinite;
}
@keyframes skeleton-scorri { to { background-position: -200% 0; } }
@media (prefers-reduced-motion: reduce) {
  .skeleton { animation: none; }
}

/* ---- Passi: anteprima -> conferma -> esito ----------------- */
.stepper { display: flex; gap: var(--space-2); flex-wrap: wrap; list-style: none; padding: 0; margin-bottom: 0; }
.stepper li {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-full);
  background: var(--slate-100);
  color: var(--slate-900);
  font-size: var(--text-sm);
  font-weight: 600;
}
.stepper li[aria-current='step'] { background: var(--brand); color: var(--brand-on); }
.stepper li[data-fatto='true'] { background: var(--blue-wash); color: var(--blue-800); }

.riepilogo { display: grid; grid-template-columns: max-content 1fr; gap: var(--space-2) var(--space-4); }
.riepilogo dt { font-weight: 700; color: var(--text-strong); }
@media (max-width: 480px) { .riepilogo { grid-template-columns: 1fr; } }

.page:empty { display: none; }

/* ---- Combobox ----------------------------------------------- */
.combobox { position: relative; }
.combobox__lista {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  z-index: 5;
  margin: 2px 0 0;
  padding: var(--space-1);
  list-style: none;
  max-height: 16rem;
  overflow-y: auto;
  background: var(--surface-card);
  border: 1.5px solid var(--neutral-500);
  border-radius: var(--radius-md);
}
.combobox__lista li { padding: var(--space-2) var(--space-3); border-radius: var(--radius-sm); cursor: pointer; }
.combobox__lista li[aria-selected='true'] { background: var(--blue-wash); color: var(--blue-950); }

.tecnico { overflow-x: auto; font-size: var(--text-xs); background: var(--surface-sunken); padding: var(--space-3); border-radius: var(--radius-md); }

/* ---- Barra inferiore (solo telefono): voci frequenti di ore e spese -------------------------- */
.barra-inferiore { display: none; }
@media (max-width: 640px) {
  .barra-inferiore {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 8; display: flex;
    background: var(--surface-card); border-top: 1px solid var(--border-subtle);
    padding-bottom: env(safe-area-inset-bottom, 0);
  }
  .barra-inferiore a {
    flex: 1; display: flex; align-items: center; justify-content: center; min-height: 56px;
    padding: 0 var(--space-1); font-size: var(--text-sm); font-weight: 700; text-align: center; color: var(--text-body);
  }
  .barra-inferiore a[aria-current='page'] { background: var(--blue-wash); color: var(--blue-800); }
  .barra-inferiore a:hover { text-decoration: none; }
  body { padding-bottom: calc(64px + env(safe-area-inset-bottom, 0px)); } /* il contenuto non resta sotto la barra */
}

/* "+ Spesa": pulsante nell'intestazione su PC, voce evidenziata nella barra su telefono */
@media (max-width: 640px) { .app-header__piu { display: none; } }
.barra-inferiore__piu { color: var(--brand) !important; }
