/* Modali "a finestra" v2 (form e conferme) - vale SOLO sotto body.test-environment, quindi in produzione il sito resta identico.
   Cambia testata, scrim, raggio/ombra, pulsante di chiusura, vassoio azioni e layout delle conferme; i colori dei pulsanti
   e i font NON sono toccati. Usa i token del sito (--primary*, --border, --surface-soft, --text, --muted, --danger, --danger-soft, --radius).
   Non modifica site.css: per tornare indietro basta togliere questo file (e il link in App.razor) oppure fare git revert.
   Specifica e motivazioni: docs/AnalisiGraficaModali.md. */

/* L'icona delle conferme esiste nel markup ma resta nascosta fuori dall'ambiente di test. */
.nh-confirm-icon {
  display: none;
}

/* ---------- scrim ---------- */
/* Lo sfondo sta sullo pseudo-elemento, MAI su .editor-modal: backdrop-filter sulla modale romperebbe i popup position:fixed dei DxDateEdit. */
body.test-environment .editor-modal::before,
body.test-environment .confirm-modal::before {
  background: rgba(15, 23, 42, .42);
  backdrop-filter: blur(2px);
  animation: nh-modal-fade .16s linear backwards;
}

/* ---------- finestra ---------- */
/* "backwards": a fine animazione non resta alcun transform sul dialog (non crea un containing block per i popup fixed). */
body.test-environment .editor-dialog,
body.test-environment .confirm-dialog {
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: 0 1px 2px rgba(15, 23, 42, .08), 0 28px 56px -18px rgba(15, 23, 42, .45);
  max-height: calc(100dvh - 48px);
  animation: nh-modal-rise .2s cubic-bezier(.16, 1, .3, 1) backwards;
}

/* ---------- testata ---------- */
body.test-environment .editor-dialog .surface-head {
  display: flex;
  flex-direction: row;
  flex-wrap: nowrap;
  grid-template-columns: none;
  justify-content: space-between;
  justify-items: normal;
  align-items: center;
  gap: 12px;
  padding: 16px 16px 16px 20px;
  border-bottom: 1px solid var(--border);
  background: #fff;
  color: var(--text);
  text-align: left;
}

/* Titolo a sinistra e chiusura a destra sulla stessa riga anche su schermi stretti (site.css li metterebbe in colonna). */
body.test-environment .editor-dialog .surface-head > div:first-child {
  flex: 1 1 auto;
  min-width: 0;
  margin: 0;
}

body.test-environment .editor-dialog .surface-head > .surface-actions {
  display: flex;
  flex: none;
  align-items: center;
  gap: 8px;
  margin-left: auto;
}

body.test-environment .editor-dialog .surface-head h2 {
  margin: 0;
  color: var(--text);
  font-size: 17px;
  font-weight: 700;
  letter-spacing: -.01em;
  line-height: 1.3;
  text-wrap: balance;
  opacity: 1;
}

body.test-environment .editor-dialog .surface-head p {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 13px;
  font-weight: 500;
  line-height: 1.4;
  text-wrap: pretty;
  opacity: 1;
}

body.test-environment .editor-dialog .surface-head .eyebrow {
  display: none;
}

/* ---------- chiusura (ghost 32x32) ---------- */
body.test-environment .editor-dialog .modal-shell-close-button {
  display: inline-grid;
  place-items: center;
  flex: 0 0 auto;
  flex: 0 0 32px;
  width: 32px;
  height: 32px;
  min-width: 0;
  padding: 0;
  border: 0;
  border-radius: 8px;
  background: transparent;
  box-shadow: none;
  color: var(--muted);
  font-size: 20px;
  line-height: 1;
}

body.test-environment .editor-dialog .modal-shell-close-button:hover {
  background: var(--surface-soft);
  color: var(--text);
}

body.test-environment .editor-dialog .modal-shell-close-button:focus-visible {
  outline: 0;
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 28%, #fff);
}

/* ---------- corpo e vassoio azioni ---------- */
/* Il dialog "Impostazioni tabella" ha un proprio layout a sidebar con padding 0: resta fuori. */
body.test-environment .editor-dialog:not(.smart-table-settings-dialog) .editor-body {
  padding: 20px;
  scrollbar-width: thin;
  scrollbar-color: color-mix(in srgb, var(--primary) 32%, #fff) transparent;
}

/* Rifiniture: selezione con la tinta primaria, anello di focus coerente, cifre allineate nei campi. */
body.test-environment .editor-dialog ::selection {
  background: color-mix(in srgb, var(--primary) 22%, #fff);
}

body.test-environment .editor-dialog .btn:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

body.test-environment .editor-dialog :is(input, textarea, select, table) {
  font-variant-numeric: tabular-nums;
}

/* Hover/active dei pulsanti senza toccarne i colori: solo ombra e spostamento minimo. */
body.test-environment .editor-dialog .modal-form-actions .btn {
  transition: transform .12s ease, box-shadow .12s ease;
}

body.test-environment .editor-dialog .modal-form-actions .btn:hover:not(:disabled) {
  box-shadow: 0 1px 2px rgba(15, 23, 42, .14);
}

body.test-environment .editor-dialog .modal-form-actions .btn:active:not(:disabled) {
  transform: translateY(1px);
  box-shadow: none;
}

body.test-environment .editor-dialog .modal-form-actions .btn:disabled:not(.is-busy) {
  cursor: not-allowed;
}

/* Barra fissa in fondo al corpo che scorre; la riga delle impostazioni tabella ha un proprio layout e resta fuori. */
body.test-environment .editor-dialog:not(.smart-table-settings-dialog) .modal-form-actions {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  position: sticky;
  bottom: -20px;
  z-index: 2;
  margin: 16px -20px -20px;
  padding: 12px 20px;
  border-top: 1px solid var(--border);
  background: var(--surface-soft);
  box-shadow: 0 -10px 16px -14px rgba(15, 23, 42, .22);
}

/* Elimina resta a sinistra (solo form in visualizzazione) */
body.test-environment .editor-dialog:not(.smart-table-settings-dialog) .modal-form-actions.has-danger {
  justify-content: space-between;
}

body.test-environment .editor-dialog:not(.smart-table-settings-dialog) .modal-form-actions .btn,
body.test-environment .editor-dialog:not(.smart-table-settings-dialog) .modal-form-actions.has-danger .modal-form-main-actions .btn,
body.test-environment .editor-dialog:not(.smart-table-settings-dialog) .modal-form-actions.has-danger > .btn-danger {
  min-width: 96px;
}

/* Absences: il footer ha un proprio bordo/margine che si sommava a quello del vassoio; con "contents" il vassoio diventa figlio diretto del corpo. */
body.test-environment .editor-dialog .absences-modal-footer {
  display: contents;
}

/* Timbrature del giorno: il corpo ha un'altezza minima e il vassoio e' al suo interno, quindi resta in fondo al corpo. */
body.test-environment .report-day-editor-body {
  display: flex;
  flex-direction: column;
}

body.test-environment .editor-dialog .report-day-editor-body .modal-form-actions {
  margin-top: auto;
}

/* Catena di contenitori fino al form di modifica timbratura: il vassoio, figlio diretto di .report-day-editor-form, scende in fondo.
   Nelle schede Ore/Piano il vassoio sta dentro una griglia di campi e segue il contenuto (limite noto). */
body.test-environment .report-day-editor-body > .report-day-editor-section,
body.test-environment .report-day-editor-section > .report-day-editor-form {
  display: flex;
  flex: 1 1 auto;
  flex-direction: column;
}

/* site.css fa width:100% del vassoio dentro .modal-footer e perde lo sbordo di -20px: qui torna a larghezza automatica. */
body.test-environment .editor-dialog .absences-modal-footer > .modal-form-actions {
  flex: none;
  width: auto;
}

/* Schede Ore e Piano: il vassoio e' dentro la griglia dei campi. Lo ancoro in fondo alla sezione (che riempie il corpo)
   e riservo lo spazio sotto ai campi; sbordo di -20px come il vassoio standard. */
body.test-environment .report-day-editor-section:has(> .settings-form-grid > .modal-form-actions) {
  position: relative;
  padding-bottom: 76px;
}

body.test-environment .editor-dialog .report-day-editor-section > .settings-form-grid > .modal-form-actions {
  position: absolute;
  right: -20px;
  bottom: -20px;
  left: -20px;
  margin: 0;
}

/* ---------- conferme (stile C per tutti i toni) ---------- */
/* Testata della shell tinta col tono, icona 52px sopra il titolo, titolo e messaggio centrati, due pulsanti uguali.
   Il tono arriva da .nh-confirm-{danger|warning|neutral|success}. Le form e le conferme inline (.nh-confirm-inline) non sono toccate. */
body.test-environment .editor-dialog:has(.nh-confirm-danger) {
  --nh-tone: var(--danger);
  --nh-tone-soft: var(--danger-soft);
}

body.test-environment .editor-dialog:has(.nh-confirm-warning) {
  --nh-tone: #b45309;
  --nh-tone-soft: #fffbeb;
}

body.test-environment .editor-dialog:has(.nh-confirm-success) {
  --nh-tone: var(--success);
  --nh-tone-soft: var(--success-soft);
}

body.test-environment .editor-dialog:has(.nh-confirm-neutral) {
  --nh-tone: var(--primary);
  --nh-tone-soft: color-mix(in srgb, var(--primary) 8%, #fff);
}

body.test-environment .editor-dialog:has(.nh-confirm) {
  position: relative;
  width: min(440px, 100%);
}

body.test-environment .editor-dialog:has(.nh-confirm) .surface-head {
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  gap: 4px;
  padding: 88px 24px 14px;
  border-bottom: 0;
  background: var(--nh-tone-soft);
  text-align: center;
}

body.test-environment .editor-dialog:has(.nh-confirm) .surface-head > div:first-child {
  flex: none;
  width: 100%;
}

body.test-environment .editor-dialog:has(.nh-confirm) .surface-head h2 {
  font-size: 18px;
  font-weight: 700;
  text-wrap: balance;
}

/* La chiusura passa da Esc, dal pulsante di rinuncia e dal clic sullo sfondo (gestiti da site.js). */
body.test-environment .editor-dialog:has(.nh-confirm) .surface-head > .surface-actions,
body.test-environment .editor-dialog:has(.nh-confirm) .modal-shell-close-button {
  display: none;
}

body.test-environment .editor-dialog:has(.nh-confirm) .editor-body {
  padding: 16px 20px 0;
}

/* Icona nel corpo ma ancorata in alto al centro del dialog, sopra la testata */
body.test-environment .editor-dialog .nh-confirm .nh-confirm-icon {
  position: absolute;
  top: 22px;
  left: 50%;
  z-index: 3;
  display: grid;
  place-items: center;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: #fff;
  color: var(--nh-tone);
  box-shadow: 0 0 0 6px color-mix(in srgb, var(--nh-tone) 12%, transparent);
  transform: translateX(-50%);
}

body.test-environment .nh-confirm-icon:empty {
  display: none;
}

body.test-environment .nh-confirm-icon .button-icon-svg {
  display: block;
  width: 24px;
  height: 24px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
}

/* Enfasi d'ingresso dell'icona di una conferma distruttiva: una volta sola, all'apertura. */
body.test-environment .editor-dialog .nh-confirm-danger .nh-confirm-icon {
  animation: nh-confirm-icon-pop-c .34s cubic-bezier(.16, 1, .3, 1) .1s backwards;
}

body.test-environment .nh-confirm-row {
  display: block;
  margin: 0;
}

/* Il messaggio diventa testo normale, centrato, qualunque sia la variante (warning/success/error). */
body.test-environment .nh-confirm .status-strip {
  justify-content: center;
  min-height: 0;
  max-width: 65ch;
  margin: 0 auto;
  padding: 0;
  border: 0;
  background: transparent;
  color: #334155;
  font-size: 13.5px;
  font-weight: 500;
  line-height: 1.5;
  text-align: center;
  text-wrap: pretty;
}

/* Contenuto extra (es. campo commento): a tutta larghezza, allineato a sinistra anche nel tono centrato */
body.test-environment .nh-confirm .nh-confirm-extra {
  margin: 14px 0 0;
  text-align: left;
}

body.test-environment .nh-confirm .nh-confirm-extra > *,
body.test-environment .nh-confirm .nh-confirm-extra :is(textarea, input, select) {
  width: 100%;
  max-width: none;
}

/* Pulsanti: due colonne uguali, rinuncia a sinistra e azione a destra (con "contents" i figli di main-actions entrano nella griglia;
   l'ordine DOM/Tab resta quello del markup, cambia solo l'ordine visivo) */
body.test-environment .editor-dialog .nh-confirm .modal-form-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  position: static;
  margin: 16px -20px 0;
  padding: 12px 16px 16px;
  border-top: 0;
  background: transparent;
  box-shadow: none;
}

body.test-environment .editor-dialog .nh-confirm .modal-form-actions .modal-form-main-actions {
  display: contents;
}

body.test-environment .editor-dialog .nh-confirm .modal-form-actions .btn {
  width: 100%;
  min-width: 0;
  height: 42px;
  min-height: 42px;
  order: 1;
  /* azzera le colonne esplicite di site.css (grid-column 1/2/3) */
  grid-column: auto;
  justify-self: stretch;
}

body.test-environment .editor-dialog .nh-confirm .modal-form-actions > .btn-danger,
body.test-environment .editor-dialog .nh-confirm .modal-form-actions .modal-form-main-actions .btn:not(.btn-outline-secondary) {
  order: 2;
}

/* ---------- mobile: fogli ancorati in basso ---------- */
@media (max-width: 640px) {
  body.test-environment .editor-modal,
  body.test-environment .confirm-modal {
    place-items: end stretch;
    padding: 0;
  }

  body.test-environment .editor-dialog,
  body.test-environment .confirm-dialog,
  body.test-environment .editor-dialog:has(.nh-confirm) {
    width: 100%;
    max-width: none;
    max-height: 92dvh;
    border-width: 1px 0 0;
    border-radius: 16px 16px 0 0;
    box-shadow: 0 -16px 40px -14px rgba(15, 23, 42, .4);
    animation: nh-modal-up .3s cubic-bezier(.16, 1, .3, 1) backwards;
  }

  body.test-environment .editor-dialog:not(.smart-table-settings-dialog) .modal-form-actions {
    padding-bottom: calc(12px + env(safe-area-inset-bottom));
  }

  body.test-environment .editor-dialog .btn {
    min-height: 44px;
  }

  /* Area di tocco 44x44 per la chiusura; il negativo la tiene allineata al bordo della testata. */
  body.test-environment .editor-dialog .modal-shell-close-button {
    flex: 0 0 44px;
    width: 44px;
    min-width: 44px;
    height: 44px;
    margin-right: -8px;
  }

  /* Conferme: una colonna, azione in alto (ordine invertito rispetto al desktop) */
  body.test-environment .editor-dialog .nh-confirm .modal-form-actions {
    grid-template-columns: 1fr;
    padding-bottom: calc(16px + env(safe-area-inset-bottom));
  }

  body.test-environment .editor-dialog .nh-confirm .modal-form-actions .btn {
    height: 46px;
    min-height: 46px;
    order: 2;
  }

  body.test-environment .editor-dialog .nh-confirm .modal-form-actions > .btn-danger,
  body.test-environment .editor-dialog .nh-confirm .modal-form-actions .modal-form-main-actions .btn:not(.btn-outline-secondary) {
    order: 1;
  }
}

@keyframes nh-modal-fade {
  from {
    opacity: 0;
  }
}

@keyframes nh-modal-rise {
  from {
    opacity: 0;
    transform: translateY(10px) scale(.985);
  }
}

@keyframes nh-confirm-icon-pop-c {
  from {
    opacity: 0;
    transform: translateX(-50%) scale(.7);
  }
}

@keyframes nh-modal-up {
  from {
    transform: translateY(100%);
  }
}

@media (prefers-reduced-motion: reduce) {
  body.test-environment .editor-modal::before,
  body.test-environment .confirm-modal::before,
  body.test-environment .editor-dialog,
  body.test-environment .confirm-dialog,
  body.test-environment .editor-dialog .nh-confirm-danger .nh-confirm-icon {
    animation: none !important;
  }

  body.test-environment .editor-dialog .modal-form-actions .btn {
    transition: none;
  }
}

/* ---------- modale Giornata, tab Ore: registro ore + aggiungi assenza (solo ambiente di test) ---------- */
/* Nome e giorno stanno accanto al titolo, in tono attenuato, al posto dei due campi disabilitati. */
body.test-environment .report-day-editor-v2 .surface-head > div:first-child {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0 10px;
}

body.test-environment .report-day-editor-v2 .surface-head p {
  margin: 0;
  font-size: 13px;
}

body.test-environment .nh-day-hours {
  gap: 16px;
}

body.test-environment .nh-day-reg-head,
body.test-environment .nh-day-reg-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 88px 116px;
  align-items: center;
  gap: 12px;
}

body.test-environment .nh-day-reg-head {
  padding: 0 0 6px;
  border-bottom: 1px solid var(--border);
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}

body.test-environment .nh-day-reg-head span:not(:first-child) {
  padding-right: 4px;
  text-align: right;
}

body.test-environment .nh-day-reg-row {
  min-height: 48px;
  padding: 6px 0;
  border-bottom: 1px solid color-mix(in srgb, var(--border) 55%, transparent);
}

body.test-environment .nh-day-reg-name {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0 8px;
  min-width: 0;
  color: var(--text);
  overflow-wrap: anywhere;
}

body.test-environment .nh-day-reg-was {
  color: var(--muted);
  font-size: 12px;
}

body.test-environment .nh-day-reg-rec {
  padding-right: 4px;
  color: var(--muted);
  text-align: right;
  font-variant-numeric: tabular-nums;
}

body.test-environment .nh-day-reg-field {
  margin: 0;
}

body.test-environment .nh-day-reg-field .form-control {
  min-height: 36px;
}

body.test-environment .nh-day-reg-field input {
  padding-right: 10px;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

body.test-environment .nh-day-reg-head span:last-child {
  padding-right: 11px;
}

/* Voce modificata rispetto al valore di partenza */
body.test-environment .nh-day-reg-row.is-changed .nh-day-reg-field .form-control {
  border-color: var(--primary);
  background: color-mix(in srgb, var(--primary) 8%, #fff);
}

/* "Altre voci": azione testuale, non un pulsante pieno */
body.test-environment .nh-day-reg .btn.nh-day-more {
  justify-content: flex-start;
  min-height: 40px;
  margin-top: 4px;
  padding: 8px 0;
  border: 0;
  background: transparent;
  color: var(--primary);
  font-weight: 600;
  box-shadow: none;
}

body.test-environment .nh-day-reg .btn.nh-day-more:hover {
  background: transparent;
  text-decoration: underline;
}

/* Aggiungi assenza */
body.test-environment .nh-day-abs {
  margin-top: 0;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}

body.test-environment .nh-day-abs-title {
  margin: 0 0 10px;
  font-size: 13px;
  font-weight: 700;
}

body.test-environment .nh-day-abs-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 120px;
  align-items: end;
  gap: 10px 12px;
}

body.test-environment .nh-day-abs-grid .nh-day-abs-note {
  grid-column: 1 / -1;
}

body.test-environment .nh-day-abs-foot {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 12px;
}

/* Senza campo Ore (giornata intera) la causale occupa tutta la riga */
body.test-environment .nh-day-abs-grid.is-full {
  grid-template-columns: minmax(0, 1fr);
}

/* Esito dentro il vassoio sticky: il messaggio occupa una riga sopra "Salva ore" solo quando c'e'; vuoto non ha ingombro (resta nel DOM per i lettori di schermo). */
body.test-environment .editor-dialog .modal-form-actions:has(.nh-day-live) .modal-form-main-actions {
  flex: 1 1 auto;
  flex-wrap: wrap;
  justify-content: flex-end;
  row-gap: 0;
}

body.test-environment .nh-day-live {
  height: 0;
  margin: 0;
}

body.test-environment .modal-form-main-actions > .nh-day-live {
  order: -1;
  flex: 1 0 100%;
  min-width: 0;
  height: 0;
  margin: 0;
}

body.test-environment .nh-day-live:has(*) {
  height: auto;
  margin-bottom: 10px;
}

body.test-environment .nh-day-live > * {
  margin: 0;
}

@media (max-width: 620px) {
  body.test-environment .nh-day-reg-head,
  body.test-environment .nh-day-reg-row {
    grid-template-columns: minmax(0, 1fr) 60px 96px;
    gap: 8px;
  }

  body.test-environment .nh-day-abs-grid {
    grid-template-columns: minmax(0, 1fr);
  }

  body.test-environment .nh-day-reg-field .form-control,
  body.test-environment .nh-day-reg .btn.nh-day-more {
    min-height: 44px;
  }
}
