/*
 * Stile gestionale La gabbianella — light/dark, minimal moderno.
 * I colori vivono in variabili: il tema si cambia su <html data-theme="...">.
 */

:root {
  --topbar-height: 5rem;
  --bg: #fcfcfe;       /* canvas quasi bianco: righe bianche appena staccate + bordo */
  --surface: #ffffff;
  --surface-2: #eceef6;
  --row-bg: var(--surface);   /* righe bianche che spiccano sul canvas grigio */
  --text: #2c3557;
  --muted: #7078a0;
  --border: #e3e5f1;
  --accent: #526496;          /* indaco/periwinkle del brand (dal logo) */
  --accent-contrast: #ffffff;
  --indigo: #606aa3;          /* periwinkle della striscia alta del sito */
  --danger: #b42318;
  --danger-bg: #fdecea;
  --ok: #1a7f47;
  --ok-bg: #e7f4ec;
  --radius: 10px;
  --font-display: "Playfair Display", Georgia, "Times New Roman", serif;
  --shadow: 0 1px 2px rgba(34, 42, 82, .06), 0 1px 3px rgba(34, 42, 82, .05);
  /* Tema light: navbar del colore principale, logo su tessera bianca. */
  --topbar-bg: var(--accent);
  --topbar-text: #ffffff;
  --brand-bg: #ffffff;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1e1e1e;
    --surface: #252526;
    --surface-2: #2d2d30;
    --row-bg: var(--surface);   /* dark: riga come le altre superfici (già staccata dal fondo) */
    --text: #ffffff;
    --muted: #9a9aa5;
    --border: #3a3a3d;
    --accent: #d4d4d8;
    --accent-contrast: #1e1e1e;
    --indigo: #d4d4d8;
    --danger: #ff7b72;
    --danger-bg: #2d1715;
    --ok: #56d364;
    --ok-bg: #11261a;
    --shadow: 0 1px 2px rgba(0, 0, 0, .45);
    --topbar-bg: var(--surface);
    --topbar-text: #ffffff;
    --brand-bg: transparent;
  }
}

:root[data-theme="dark"] {
  --bg: #1e1e1e;
  --surface: #252526;
  --surface-2: #2d2d30;
  --row-bg: var(--surface);
  --text: #ffffff;
  --muted: #9a9aa5;
  --border: #3a3a3d;
  --accent: #d4d4d8;
  --accent-contrast: #1e1e1e;
  --indigo: #d4d4d8;
  --danger: #ff7b72;
  --danger-bg: #2d1715;
  --ok: #56d364;
  --ok-bg: #11261a;
  --shadow: 0 1px 2px rgba(0, 0, 0, .45);
  --topbar-bg: var(--surface);
  --topbar-text: #ffffff;
  --brand-bg: transparent;
}

* { box-sizing: border-box; }

html { color-scheme: light dark; }
/* Segue il toggle manuale, non solo la preferenza di sistema: altrimenti
   con OS in dark mode i controlli nativi (checkbox, radio) restano scuri
   anche quando l'utente ha forzato il tema chiaro (e viceversa), risultando
   poco visibili sullo sfondo del tema attivo. */
:root[data-theme="light"] { color-scheme: light; }
:root[data-theme="dark"] { color-scheme: dark; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Inter", system-ui, -apple-system, "Segoe UI", Helvetica, Arial, sans-serif;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* ---- Topbar ---- */
.topbar {
  display: flex;
  align-items: center;
  gap: 1.5rem;
  padding: .6rem 1.5rem;
  background: var(--topbar-bg);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand {
  display: inline-flex;
  align-items: center;
  text-decoration: none;
  background: var(--brand-bg);
  padding: .3rem .55rem;
  border-radius: var(--radius);
}

/* Wordmark ufficiale (uccellino + logotipo). Su tema scuro lo schiariamo
   perché è indaco su trasparente e sparirebbe. */
.brand-logo {
  display: block;
  height: 48px;
  width: auto;
  border-radius: 0;
}

:root[data-theme="dark"] .brand-logo { filter: brightness(0) invert(1) brightness(1.1); }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .brand-logo { filter: brightness(0) invert(1) brightness(1.1); }
}

.nav {
  display: flex;
  gap: 1.5rem;
  flex: 1;
}

.nav a {
  color: var(--topbar-text);
  text-decoration: none;
  font-size: .95rem;
  font-weight: 600;
  letter-spacing: .02em;
}

.nav a:hover { opacity: .75; }

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 1.1rem;
}

/* Rotella impostazioni: icona sobria nella topbar, stesso colore delle voci. */
.icon-btn {
  display: inline-flex;
  align-items: center;
  color: var(--topbar-text);
  line-height: 0;
  opacity: .85;
}
.icon-btn:hover { opacity: 1; }

/* Bolla "Indietro": pill appena sotto la topbar, a sinistra. `fixed` (ancorata al
   viewport, fuori dal flusso) così, comparendo solo dopo un redirect, non spinge in
   giù il contenuto. top ≈ altezza topbar (logo 48px + padding). z-index sopra la
   topbar (10) ma sotto i flash (60). ponytail: top fisso, ritoccare se cambia la navbar. */
.back-bubble {
  position: fixed;
  top: calc(var(--topbar-height) + .2rem);
  left: 1.5rem;
  z-index: 20;
  display: inline-flex;
  align-items: center;
  gap: .3rem;
  padding: .35rem .8rem .35rem .55rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  box-shadow: var(--shadow);
  color: var(--muted);
  font: inherit;
  font-size: .85rem;
  font-weight: 600;
  cursor: pointer;
}
.back-bubble:hover { color: var(--text); border-color: var(--accent); }

/* Bottone Esci nella topbar: leggibile sia su fondo colorato (light) che scuro. */
.topbar .btn-ghost {
  color: var(--topbar-text);
  border-color: color-mix(in srgb, var(--topbar-text) 45%, transparent);
}
.topbar .btn-ghost:hover {
  color: var(--topbar-text);
  border-color: var(--topbar-text);
  background: color-mix(in srgb, var(--topbar-text) 12%, transparent);
}

/* Interruttore tema: slider minimale (knob a sinistra=chiaro, destra=scuro). */
.theme-switch {
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
  line-height: 0;
}
.theme-switch-track {
  display: inline-block;
  width: 38px;
  height: 20px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--topbar-text) 30%, transparent);
  border: 1px solid color-mix(in srgb, var(--topbar-text) 45%, transparent);
  position: relative;
}
.theme-switch-knob {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--topbar-text);
  transition: transform .15s ease;
}
:root[data-theme="dark"] .theme-switch-knob { transform: translateX(18px); }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .theme-switch-knob { transform: translateX(18px); }
}

/* ---- Layout ---- */
.container {
  max-width: 960px;
  margin: 0 auto;
  padding: 1.5rem 1.25rem 4rem;
}

h1 {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 2rem;
  letter-spacing: -.01em;
  margin: .2rem 0 1rem;
}
h2 {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 1.35rem;
  margin: 2rem 0 .75rem;
}

a { color: var(--accent); }

.muted { color: var(--muted); }

/* ---- Tabelle ---- */
table {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
}

th, td {
  text-align: left;
  padding: .6rem .75rem;
  border-bottom: 1px solid var(--border);
  font-size: .95rem;
}

th {
  background: var(--surface-2);
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  font-size: .75rem;
  letter-spacing: .03em;
}

tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: var(--surface-2); }

/* Azioni per riga (Modifica/Elimina): in linea e compatte. */
.row-actions { display: flex; align-items: center; gap: .6rem; white-space: nowrap; }
.row-actions form { margin: 0; }
.row-actions .btn-ghost { padding: .2rem .55rem; font-size: .85rem; }

/* Pill uniforme per le etichette d'azione/stato (es. Scarico: "Storna" e "chiuso"). */
.pill {
  display: inline-block;
  padding: .2rem .65rem;
  border-radius: 999px;
  border: 1px solid transparent;
  font-size: .75rem;
  font-weight: 600;
  line-height: 1.35;
}
.pill-muted { background: var(--surface-2); color: var(--muted); }
button.pill-action {
  background: transparent;
  color: var(--danger);
  border-color: color-mix(in srgb, var(--danger) 35%, transparent);
  cursor: pointer;
}
button.pill-action:hover { background: var(--danger-bg); }

/* ---- Liste descrittive ---- */
dl {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: .4rem 1.25rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
  box-shadow: var(--shadow);
}

dt { color: var(--muted); }
dd { margin: 0; font-weight: 500; }

/* ---- Form ---- */
form { max-width: 520px; }

.field { margin-bottom: 1rem; }

label { display: block; font-size: .9rem; color: var(--muted); margin-bottom: .3rem; }

input[type="text"],
input[type="search"],
input[type="password"],
input[type="number"],
input[type="datetime-local"],
input[type="file"],
select {
  width: 100%;
  padding: .55rem .65rem;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font: inherit;
}

input:focus, select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 25%, transparent);
}

fieldset {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  margin: 0 0 1rem;
}

legend { color: var(--muted); font-size: .85rem; padding: 0 .4rem; }

fieldset label {
  display: inline-flex;
  align-items: center;
  gap: .35rem;
  margin: 0 1rem .4rem 0;
  color: var(--text);
}

fieldset input[type="checkbox"] { width: auto; }

/* ---- Bottoni ---- */
input[type="submit"], .btn-primary, button {
  cursor: pointer;
  font: inherit;
}

input[type="submit"], .btn-primary {
  background: var(--accent);
  color: var(--accent-contrast);
  border: 0;
  border-radius: var(--radius);
  padding: .6rem 1.1rem;
  font-weight: 600;
}

input[type="submit"]:hover, .btn-primary:hover { filter: brightness(1.05); }

/* Variante distruttiva (es. "Elimina selezionate"). Selettore combinato per
   battere la specificità di input[type="submit"]. */
input[type="submit"].btn-danger, .btn-danger { background: var(--danger); color: #fff; }

.btn-ghost {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: .4rem .8rem;
}

.btn-ghost:hover { color: var(--text); border-color: var(--accent); }

.btn-secondary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: .55rem .9rem;
  font-weight: 600;
  text-decoration: none;
}

.btn-secondary:hover { border-color: var(--accent); color: var(--text); }

/* Il display dei pulsanti non deve prevalere sullo stato del prompt PWA. */
[data-pwa-install] [hidden] { display: none !important; }

/* button_to genera un form: niente margine extra */
.topbar-actions form { margin: 0; }

/* ---- Ricerca ---- */
form.search {
  display: flex;
  gap: .5rem;
  align-items: center;
  max-width: none;
  margin-bottom: 1rem;
}

form.search input[type="text"] { flex: 1; }
form.search .btn-primary { white-space: nowrap; }

/* ---- Flash ---- */
.flashes {
  position: fixed;
  left: 50%;
  bottom: 1.5rem;
  transform: translateX(-50%);
  z-index: 60;
  width: min(92vw, 34rem);
  display: flex;
  flex-direction: column;
  gap: .5rem;
  pointer-events: none;   /* i click passano alla pagina; solo i toast li ricevono */
}
.flash {
  padding: .7rem 1rem;
  border-radius: var(--radius);
  margin: 0;
  font-size: .95rem;
  border: 1px solid transparent;
  box-shadow: var(--shadow);
  pointer-events: auto;
}

.flash-notice { background: var(--ok-bg); color: var(--ok); border-color: color-mix(in srgb, var(--ok) 30%, transparent); }
.flash-alert { background: var(--danger-bg); color: var(--danger); border-color: color-mix(in srgb, var(--danger) 30%, transparent); }

/* I notice spariscono da soli; gli alert (errori) restano visibili */
.flash-notice { animation: flash-vanish .5s ease 4s forwards; }
@keyframes flash-vanish {
  to { opacity: 0; visibility: hidden; display: none; }
}
@media (prefers-reduced-motion: reduce) {
  .flash-notice { animation-duration: 0s; }
}

/* ---- Errori di form ---- */
form ul {
  background: var(--danger-bg);
  color: var(--danger);
  border: 1px solid color-mix(in srgb, var(--danger) 30%, transparent);
  border-radius: var(--radius);
  padding: .6rem 1rem .6rem 2rem;
  margin: 0 0 1rem;
}

/* ---- Card login ---- */
.auth-card {
  max-width: 380px;
  margin: 4rem auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2rem;
  box-shadow: var(--shadow);
}

.auth-logo { height: auto; width: min(220px, 70%); margin: 0 auto 1.5rem; }
.auth-card h1 { margin-top: 0; }
.auth-card form { max-width: none; }

/* ---- Form nuovo prodotto: anagrafica + carico iniziale in una sola scheda ---- */
.product-form-header {
  margin: 0 0 .75rem;
  padding: 0 .15rem;
}

.product-form-header .detail-eyebrow { margin-bottom: .1rem; }
.product-form-header h1 { margin: 0; }
.product-form-header .muted { margin: .25rem 0 0; }
.product-form { max-width: none; }
.product-form-sections {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: .7rem;
}

.product-form-section {
  min-width: 0;
  margin: 0;
  padding: .75rem;
  background: var(--surface);
}

.product-form-section legend {
  color: var(--text);
  font-size: .8rem;
  font-weight: 700;
  letter-spacing: .05em;
  text-transform: uppercase;
}

.product-form-section-intro {
  margin: -.1rem 0 .65rem;
  color: var(--muted);
  font-size: .82rem;
}

.product-form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: .65rem .75rem;
}

.product-form .field { min-width: 0; margin: 0; }
.product-form .field > label { display: block; margin-bottom: .22rem; color: var(--muted); font-size: .78rem; font-weight: 600; }
.product-form-field-wide { grid-column: 1 / -1; }
.product-form-opening { border-color: color-mix(in srgb, var(--accent) 35%, var(--border)); background: color-mix(in srgb, var(--accent) 5%, var(--surface)); }
.product-form-opening input[type="number"] { font-weight: 650; }
.field-hint { display: block; margin-top: .22rem; color: var(--muted); font-size: .72rem; line-height: 1.35; }
.form-upload-retry { color: var(--danger); }
.product-form-price-note { align-self: end; margin: 0; padding: .55rem .65rem; border-radius: calc(var(--radius) - 2px); background: var(--surface-2); color: var(--muted); font-size: .78rem; line-height: 1.4; }
.product-form-images { grid-column: 1 / -1; }
.product-form-images .field { width: 100%; }
.product-form-submit { width: 100%; margin-top: .7rem; }

/* ---- Registro carichi e form di movimento ---- */
.stock-register-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
}

.stock-register-header h1 { margin: .1rem 0 .15rem; }
.stock-register-header p { margin: 0; overflow-wrap: anywhere; }
.stock-register-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: .5rem; }
.stock-register-filters { display: flex; flex-wrap: wrap; align-items: flex-end; gap: .65rem; max-width: none; margin: 0 0 1rem; }
.stock-register-filters .field { flex: 1 1 13rem; min-width: 10rem; max-width: 24rem; margin: 0; }
.stock-register-filters .field label { display: block; margin-bottom: .22rem; font-size: .78rem; font-weight: 600; }
.stock-register-filters .btn-secondary,
.stock-register-filters .btn-ghost { white-space: nowrap; }
.stock-register { table-layout: fixed; }
.stock-register th,
.stock-register td { overflow-wrap: anywhere; }
.stock-register-code { display: block; margin-top: .1rem; font-size: .74rem; overflow-wrap: anywhere; }
.stock-register .row-actions { flex-wrap: wrap; }

@media (min-width: 641px) {
  /* A 7 colonne la tabella non deve distribuire lo spazio uniformemente:
     descrizione e azioni hanno bisogno di respiro, i valori numerici no. */
  .stock-register th:nth-child(1), .stock-register td:nth-child(1) { width: 10%; }
  .stock-register th:nth-child(2), .stock-register td:nth-child(2) { width: 28%; }
  .stock-register th:nth-child(3), .stock-register td:nth-child(3) { width: 14%; }
  .stock-register th:nth-child(4), .stock-register td:nth-child(4) { width: 12%; }
  .stock-register th:nth-child(5), .stock-register td:nth-child(5) { width: 11%; }
  .stock-register th:nth-child(6), .stock-register td:nth-child(6) { width: 10%; }
  .stock-register th:nth-child(7), .stock-register td:nth-child(7) { width: 15%; }
  .stock-register td:nth-child(4),
  .stock-register td:nth-child(5),
  .stock-register td:nth-child(6) { white-space: nowrap; }
}

@media (min-width: 641px) and (max-width: 900px) {
  .stock-register th {
    padding-inline: .4rem;
    font-size: .68rem;
    overflow-wrap: normal;
    word-break: normal;
    hyphens: none;
  }
  .stock-register th:nth-child(2), .stock-register td:nth-child(2) { width: 27%; }
  .stock-register th:nth-child(5), .stock-register td:nth-child(5) { width: 12%; }
}

.movement-page { max-width: 720px; margin: 0 auto; }
.movement-header { margin-bottom: 1rem; }
.movement-back { display: inline-block; margin-bottom: .8rem; font-size: .88rem; font-weight: 600; }
.movement-header h1 { margin: .1rem 0 .15rem; }
.movement-header > .muted { margin: 0; }
.movement-stock { display: inline-flex; flex-wrap: wrap; align-items: baseline; gap: .4rem .7rem; margin: 1rem 0 0; padding: .6rem .75rem; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface-2); }
.movement-stock span { color: var(--muted); font-size: .78rem; }
.movement-stock strong { font-size: 1.05rem; }
.movement-form { max-width: none; }
.movement-section { margin: 0; padding: .85rem; background: var(--surface); }
.movement-section legend { color: var(--text); font-weight: 700; }
.movement-form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .7rem .8rem; }
.movement-form .field { min-width: 0; margin: 0; }
.movement-form .field > label { display: block; margin-bottom: .22rem; color: var(--muted); font-size: .78rem; font-weight: 600; }
.movement-field-date { grid-column: 1 / -1; max-width: calc(50% - .4rem); }
.movement-form-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: .6rem; margin-top: .75rem; }

/* ---- Catalogo a tutta larghezza (esce dal contenitore da 960px). La scheda
   (drawer destro) resta un overlay: da aperta riserva la sua larghezza (+ linguetta),
   da chiusa solo la metà, così la tabella non le finisce sotto. I filtri invece
   sono un box in linea sopra la ricerca: niente spazio da riservare a sinistra. ---- */
.catalog {
  --catalog-gutter: clamp(1rem, calc((100vw - 1100px) / 2), 20%);
  position: relative;
  margin-inline: calc(50% - 50vw);
  padding-inline: var(--catalog-gutter);
  transition: padding .2s ease;
}
/* Il catalogo prodotti occupa già tutta la viewport: il contenitore esterno
   non deve aggiungere padding che, con la scrollbar, crea overflow orizzontale. */
.container:has(> .catalog.products-catalog) { max-width: none; padding-inline: 0; }
.catalog.products-catalog { margin-inline: 0; }
/* A scheda aperta il padding destro sale a coprire la larghezza del drawer
   (+ linguetta), così la tabella non le finisce sotto. */
:root[data-detail="open"] .catalog:not(.products-catalog) { padding-right: max(var(--catalog-gutter), calc(440px + 4.5rem)); }
.catalog-main { container-type: inline-size; }

/* Drawer dettaglio: scorre da destra SOPRA il contenuto (come i filtri da
   sinistra), senza resize della tabella né oscurare la pagina. Si apre quando si
   clicca un prodotto (turbo-frame caricato), si chiude con la × o Esc. */
.detail-drawer {
  position: fixed;
  top: var(--topbar-height);
  right: 0;
  bottom: 0;
  z-index: 30;
  width: 440px;
  max-width: 92vw;
  transform: translateX(100%);
  transition: transform .2s ease;
  background: var(--surface);
  border-left: 1px solid var(--border);
  box-shadow: -6px 0 18px rgba(0, 0, 0, .18);
  overflow-y: auto;
  padding: 1.1rem 1.25rem 2rem;
}
:root[data-detail="open"] .detail-drawer { transform: translateX(0); }

/* Linguetta con freccia, agganciata al bordo destro: apre/chiude il dettaglio
   (specchio della linguetta filtri a sinistra). */
.detail-handle {
  position: fixed;
  top: 50%;
  right: 0;
  transform: translateY(-50%);
  z-index: 31;
  min-width: 40px;
  min-height: 150px;
  padding: .55rem .3rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: .1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-right: 0;
  border-radius: var(--radius) 0 0 var(--radius);
  box-shadow: -3px 0 10px rgba(15, 18, 40, .14);
  color: var(--muted);
  font: inherit;
  cursor: pointer;
  transition: right .2s ease, color .15s ease;
}
.detail-handle:hover { color: var(--text); }
.detail-handle::before { content: "‹"; font-size: 1.4rem; line-height: 1; }
.detail-handle-label { font-size: .62rem; font-weight: 600; letter-spacing: .02em; }
:root[data-detail="open"] .detail-handle { right: min(440px, 92vw); }
:root[data-detail="open"] .detail-handle::before { content: "›"; }

.detail-drawer h1 { font-size: 1.4rem; margin: .2rem 0 .6rem; }
.detail-drawer h2 { font-size: 1.05rem; }
.detail-empty { margin: 0; }

/* Immagini della scheda adattate alla larghezza del drawer. */
.detail-drawer .gallery-main { max-width: 100%; height: auto; }
.detail-drawer span.gallery-main {
  display: flex;
  align-items: center;
  justify-content: center;
  aspect-ratio: 1;
  border-radius: var(--radius);
  color: #fff;
  font-weight: 700;
  font-size: 1.1rem;
}

/* Scheda anagrafica modificabile in loco: la tabella dei dettagli (.detail-fields)
   è essa stessa il blocco visivo (bordo, colonna etichette ombreggiata, righe
   separate), come la tabella delle righe della fattura. */
.detail-edit { max-width: none; margin: 0 0 .9rem; }
.detail-fields { width: 100%; margin: 0; }
.detail-fields th, .detail-fields td { vertical-align: middle; }
.detail-fields th {
  text-align: left; font-weight: normal; text-transform: none; letter-spacing: 0;
  color: var(--muted); font-size: .9rem; white-space: nowrap; width: 1%;
}
.detail-fields td.ro { font-weight: 500; }
.detail-fields input { width: 100%; margin: 0; }
/* Salva: nascosto finché non si modifica un campo (form "sporco"). */
.detail-edit .form-errors { margin-bottom: .6rem; }
.detail-edit .detail-save { margin-top: .7rem; display: none; }
.detail-edit.is-dirty .detail-save { display: block; }

/* ---- Scheda prodotto: gerarchia compatta e leggibile ---- */
.detail-hero {
  grid-area: hero;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 1rem;
  padding: .85rem 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: linear-gradient(135deg, var(--surface) 0%, var(--surface-2) 100%);
}
.detail-identity { min-width: 0; }
.detail-eyebrow {
  margin: 0 0 .15rem;
  color: var(--muted);
  font-size: .7rem;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
}
.detail-identity h1 {
  margin: 0;
  overflow-wrap: anywhere;
  font-family: var(--font-display);
  font-size: clamp(1.25rem, 2.2vw, 1.8rem);
  line-height: 1.15;
}
.detail-code { margin: .25rem 0 0; color: var(--muted); font-size: .82rem; }
.detail-code strong { color: var(--text); font-weight: 600; }
.detail-metrics { display: flex; flex: 0 0 auto; gap: .55rem; }
.detail-metric {
  display: flex;
  min-width: 7rem;
  flex-direction: column;
  gap: .05rem;
  padding: .5rem .65rem;
  border-left: 1px solid var(--border);
}
.detail-metric > span:first-child {
  color: var(--muted);
  font-size: .7rem;
  font-weight: 700;
  letter-spacing: .06em;
  text-transform: uppercase;
}
.detail-metric strong { font-size: 1.08rem; line-height: 1.2; white-space: nowrap; }
.detail-metric small { color: var(--muted); font-size: .7rem; }
.detail-metric .badge { align-self: flex-start; margin: .15rem 0 0; }
.detail-metric-price strong { color: var(--accent); }

.detail-edit .detail-fields { display: flex; flex-direction: column; gap: .65rem; }
.detail-fieldset { min-width: 0; margin: 0; padding: .7rem .75rem .8rem; }
.detail-fieldset legend { color: var(--text); font-size: .78rem; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; }
.detail-form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .6rem .75rem; }
.detail-field { min-width: 0; }
.detail-field-wide { grid-column: 1 / -1; }
.detail-field > label,
.detail-field > .detail-label {
  display: block;
  margin: 0 0 .22rem;
  color: var(--muted);
  font-size: .74rem;
  font-weight: 600;
}
.detail-field input { width: 100%; margin: 0; }
.detail-field-readonly {
  padding: .4rem .55rem;
  border: 1px solid var(--border);
  border-radius: calc(var(--radius) - 3px);
  background: var(--surface-2);
}
.detail-field-readonly .detail-label { margin-bottom: .08rem; }
.detail-value { display: block; min-height: 1.4rem; font-weight: 600; overflow-wrap: anywhere; }
.detail-value small { color: var(--muted); font-size: .7rem; font-weight: 500; }

/* Immagini e storico restano compatti finché non servono. */
.image-fields,
.detail-history {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}
.image-fields { margin: .7rem 0 0; }
.image-fields > summary,
.detail-history > summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .75rem;
  padding: .6rem .75rem;
  color: var(--text);
  cursor: pointer;
  list-style: none;
  user-select: none;
}
.image-fields > summary::-webkit-details-marker,
.detail-history > summary::-webkit-details-marker { display: none; }
.image-fields > summary::after,
.detail-history > summary::after {
  content: "▸";
  color: var(--muted);
  font-size: .8rem;
  transition: transform .15s ease;
}
.image-fields[open] > summary::after,
.detail-history[open] > summary::after { transform: rotate(90deg); }
.image-fields > summary small,
.detail-history > summary small { margin-left: auto; color: var(--muted); font-size: .74rem; }
.image-fields > .field { margin: 0; padding: .7rem .75rem 0; }
.image-fields > .form-gallery { padding: 0 .75rem .75rem; }
.detail-history { grid-area: history; overflow: hidden; }
.detail-history-body { padding: 0 .75rem .75rem; }

/* Barra d'azione persistente: compare solo quando il form è sporco. */
.detail-save-bar {
  position: sticky;
  bottom: 0;
  z-index: 3;
  display: none;
  align-items: center;
  justify-content: space-between;
  gap: .75rem;
  margin: .7rem -.1rem -.1rem;
  padding: .55rem .65rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: color-mix(in srgb, var(--surface) 94%, transparent);
  box-shadow: 0 -5px 16px rgba(15, 18, 40, .08);
  backdrop-filter: blur(8px);
}
.detail-edit.is-dirty .detail-save-bar { display: flex; }
.detail-edit .detail-save { display: block; margin: 0; }
.detail-save-hint { color: var(--muted); font-size: .78rem; }

/* Bottoni sotto la scheda (Scarica, Etichetta, Archivia). */
.detail-actions { display: flex; flex-wrap: wrap; gap: .6rem; margin: 1.4rem 0; }
.detail-actions form { margin: 0; }

/* Riga con interruttore (checkbox) + testo, es. impostazioni. */

/* Modale <dialog> (es. Scarico): finestra centrata sopra la pagina. */
.modal {
  width: min(460px, 92vw);
  max-width: none;
  padding: 1rem 1.25rem 1.4rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 18px 48px rgba(15, 18, 40, .3);
}
.modal::backdrop { background: rgba(15, 18, 40, .45); }
.modal .modal-close-row { margin: 0; display: flex; justify-content: flex-end; }
.modal .modal-close {
  padding: 0 .2rem;
  background: none;
  border: 0;
  color: var(--muted);
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
}
.modal .modal-close:hover { color: var(--text); }
.modal .modal-title { margin: 0 0 .2rem; }

/* Quantità scarico: controllo compatto con −/+; lo spinner nativo è nascosto. */
.quantity-stepper {
  display: grid;
  grid-template-columns: 2.75rem minmax(5rem, 1fr) 2.75rem;
  align-items: stretch;
}
.quantity-stepper input {
  min-width: 0;
  margin: 0;
  border-radius: 0;
  text-align: center;
  font-variant-numeric: tabular-nums;
  -moz-appearance: textfield;
}
.quantity-stepper input::-webkit-inner-spin-button,
.quantity-stepper input::-webkit-outer-spin-button {
  margin: 0;
  -webkit-appearance: none;
}
.quantity-stepper-button {
  margin: 0;
  padding: .45rem;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-size: 1.3rem;
  line-height: 1;
  cursor: pointer;
}
.quantity-stepper-button:first-child {
  border-radius: var(--radius) 0 0 var(--radius);
  border-right: 0;
}
.quantity-stepper-button:last-child {
  border-radius: 0 var(--radius) var(--radius) 0;
  border-left: 0;
}
.quantity-stepper-button:hover { background: var(--border); }
.quantity-stepper-button:focus-visible { position: relative; z-index: 1; }

/* Dialog di conferma (sostituisce il popup nativo di Turbo). */
.confirm-message { margin: 0 0 .3rem; }
.confirm-actions { display: flex; justify-content: flex-end; gap: .6rem; margin-top: 1.1rem; }

/* Modale largo per l'anteprima del documento PDF: iframe a tutta larghezza. */
.modal-wide { width: min(900px, 95vw); max-width: 95vw; padding: 0; }
.modal-doc-bar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 1rem; padding: .55rem .8rem;
}
.modal-doc-frame { width: 100%; height: 75vh; border: 0; display: block; }

/* Selettore e anteprima dei tre layout DYMO, generati dal documento di stampa. */
.label-format-picker {
  display: grid; grid-template-columns: 1fr 1fr; gap: .45rem;
  width: 100%; margin: .8rem 0; padding: 0; border: 0;
}
.label-format-picker legend { margin-bottom: .35rem; font-weight: 600; }
.label-format-picker label {
  display: grid; grid-template-columns: auto 1fr; column-gap: .45rem;
  align-items: center; margin: 0; padding: .55rem;
  border: 1px solid var(--border); border-radius: 8px; cursor: pointer;
}
.label-format-picker label:has(input:checked) {
  border-color: var(--accent); background: var(--surface-2);
}
.label-format-picker input { grid-row: 1 / span 2; margin: 0; width: auto; }
.label-format-picker span { font-size: .88rem; font-weight: 600; }
.label-format-picker small { color: var(--muted); }
.label-roll-hint {
  width: 100%; margin: 0; padding: .65rem .8rem;
  border-left: 4px solid var(--accent); background: var(--surface-2);
}
.label-previews {
  min-height: 38mm; width: 100%;
  display: grid; place-items: center; margin: .5rem 0 1rem;
}
.label-preview { display: none; max-width: 100%; justify-content: center; align-items: center; }
.label-preview.is-active { display: flex; }
.label-preview [data-dymo-rendered-preview] {
  display: block; width: 100%; height: auto; max-width: 100%;
  object-fit: contain; background: #fff;
}
.label-preview[data-label-preview="piccola"] { width: 25mm; }
.label-preview[data-label-preview="media"] { width: 51mm; }
.label-preview[data-label-preview="grande"] { width: 89mm; }
.label-preview [data-dymo-rendered-preview][hidden],
.label-preview-fallback[hidden] { display: none; }
.label-preview-fallback {
  width: 100%; margin: -.35rem 0 .8rem; color: var(--muted); font-size: .78rem;
  text-align: center;
}
.etichetta-print {
  display: flex; flex-wrap: wrap; align-items: center;
  gap: .8rem; margin: 0; max-width: none;
}
.etichetta-print > label {
  display: flex; align-items: center; gap: .4rem; margin: 0; color: var(--text);
}
.etichetta-print input { width: 4rem; margin: 0; }
.etichetta-print .label-format-picker input { width: auto; }
.etichetta-print [type="submit"] { flex: none; width: max-content; }
.dymo-print-status { flex-basis: 100%; margin: 0; }
.dymo-status[data-state="success"],
.dymo-print-status[data-state="success"] { color: var(--success, #16803a); font-weight: 600; }
.dymo-status[data-state="warning"],
.dymo-print-status[data-state="warning"] { color: #b7791f; font-weight: 600; }
.dymo-status[data-state="error"],
.dymo-print-status[data-state="error"] { color: var(--danger, #b42318); font-weight: 600; }
.dymo-setup {
  max-width: 48rem; margin-top: 2rem; padding: 1.2rem;
  border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface);
}
.dymo-setup h2 { margin-top: 0; }
.dymo-setup h3 { margin-top: 0; }
.dymo-setup-actions { display: flex; gap: .7rem; align-items: center; flex-wrap: wrap; }
.dymo-setup-actions select { min-width: 18rem; width: auto; margin: 0; }
.dymo-print-tests {
  margin-top: 1.4rem; padding-top: 1.2rem; border-top: 1px solid var(--border);
}
.dymo-print-tests > p { margin-top: -.35rem; }
.dymo-print-test-grid {
  display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: .75rem;
}
.dymo-print-test {
  display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center;
  padding: .9rem; border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--bg);
}
.dymo-print-test strong,
.dymo-print-test small { display: block; }
.dymo-print-test small { margin-top: .15rem; color: var(--muted); }
.dymo-print-test .dymo-print-status { grid-column: 1 / -1; }
.dymo-diagnosis { margin-top: 1.4rem; padding-top: 1.2rem; border-top: 1px solid var(--border); }
.dymo-diagnosis textarea { width: 100%; max-width: 100%; font-family: monospace; font-size: .85rem; }
.dymo-diagnosis [hidden] { display: none; }
.settings-tabs {
  display: flex; gap: .35rem; margin-bottom: 1.5rem;
  overflow-x: auto; border-bottom: 1px solid var(--border);
}
.settings-tabs a {
  padding: .7rem 1rem; color: var(--muted); text-decoration: none;
  white-space: nowrap; border-bottom: 3px solid transparent;
}
.settings-tabs a.is-active {
  color: var(--text); font-weight: 700; border-bottom-color: var(--accent);
}
.dymo-config-redirect {
  flex-basis: 100%; padding: .85rem 1rem;
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--bg);
}
.dymo-config-redirect[hidden] { display: none; }
.dymo-config-redirect p { margin: 0 0 .7rem; }
@media (max-width: 600px) {
  .label-format-picker { grid-template-columns: 1fr; }
  .label-preview .label--grande { transform: scale(.82); }
  .dymo-print-test-grid { grid-template-columns: 1fr; }
}

/* Le tabelle secondarie (movimenti, cronologia) nel drawer stretto: niente
   scroll orizzontale, le righe diventano schede etichettate (data-label).
   Container query: succede solo dove il contenitore è stretto (il drawer),
   non a pagina piena. */
.detail-tables { container-type: inline-size; }
@container (max-width: 520px) {
  .detail-tables table { border: 0; box-shadow: none; background: transparent; }
  .detail-tables thead { display: none; }
  .detail-tables tbody tr {
    display: block;
    padding: .5rem .7rem;
    margin-bottom: .6rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
  }
  .detail-tables tbody tr:hover td { background: transparent; }
  .detail-tables td {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    gap: .4rem 1rem;
    padding: .2rem 0;
    border: 0;
  }
  .detail-tables td::before {
    content: attr(data-label);
    color: var(--muted);
    font-weight: 600;
  }
  .detail-tables td.row-actions { justify-content: flex-start; }
  .detail-tables td.row-actions::before { display: none; }
}

/* Righe fattura nel drawer: tabella classica compatta, numeri a destra, scorre
   in orizzontale se il drawer è troppo stretto. */
.invoice-head { margin-bottom: 1.4rem; }
.load-register { width: 100%; table-layout: fixed; }
.load-register th:first-child { width: 8rem; }
.load-register th:nth-child(3) { width: 5rem; }
.load-register th:last-child { width: 9rem; }
.load-register th, .load-register td { overflow-wrap: anywhere; }
.load-register [data-load-row] { cursor: pointer; }
.load-register [data-load-row]:hover { background: var(--surface-2); }
.load-toggle { display: flex; align-items: center; gap: .55rem; width: 100%; padding: .3rem 0; border: 0; background: transparent; color: var(--text); text-align: left; font: inherit; font-weight: 600; box-shadow: none; }
.load-toggle::before { content: "›"; flex: 0 0 auto; font-size: 1.2rem; }
.load-toggle[aria-expanded="true"]::before { transform: rotate(90deg); }
.load-panel[hidden] { display: none !important; }
.load-panel > td { padding: .75rem; background: var(--surface-2); }
.load-detail { min-width: 0; }
.load-detail table { width: 100%; table-layout: fixed; margin: 0; }
.load-detail th, .load-detail td { overflow-wrap: anywhere; }
.load-detail th:first-child { width: 36%; }
.load-detail th:last-child { width: 20%; }
.load-detail .row-actions { flex-wrap: wrap; }
.load-detail-footer { display: flex; justify-content: space-between; align-items: center; gap: .75rem; flex-wrap: wrap; padding-top: .8rem; }
@media (max-width: 640px) {
  .load-register .load-panel > td { display: block; padding: .5rem; }
  .load-register .load-panel > td::before { display: none; }
  .load-register .load-panel { padding: 0; border: 0; box-shadow: none; }
  .load-detail .responsive-table td { gap: .3rem; }
  .load-detail .row-actions { justify-content: flex-end; }
  .load-toggle { width: auto; max-width: 100%; }
}
.detail-righe { overflow-x: auto; }
.detail-righe th, .detail-righe td { padding: .45rem .55rem; }
.detail-righe .num { text-align: right; white-space: nowrap; }

/* Prodotto selezionato: resta evidenziato anche a drawer chiuso. */
.product-item.selected { border-color: var(--accent); box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 40%, transparent); }

/* Col dettaglio aperto il FAB "aggiungi" sparisce, per non coprirlo. */
:root[data-detail="open"] .fab { display: none; }

/* Box filtri (<details>) sotto la barra di ricerca: si apre/chiude cliccando
   l'intestazione; la × chiude. Da aperto i blocchi vanno in riga (orizzontale). */
.filters-box {
  margin: 0 0 .6rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}
.filters-summary {
  list-style: none;
  cursor: pointer;
  user-select: none;
  display: flex;
  align-items: center;
  gap: .4rem;
  padding: .5rem .9rem;
  font-size: .9rem;
  color: var(--text);
}
.filters-summary::-webkit-details-marker { display: none; }
.filters-summary::after {
  content: "▸";
  color: var(--muted);
  font-size: .8rem;
  transition: transform .15s ease;
}
.filters-box[open] .filters-summary::after { transform: rotate(90deg); }
.filters-body {
  position: relative;
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  gap: .75rem 2rem;
  padding: .25rem 2.2rem .85rem 1rem;
  border-top: 1px solid var(--border);
}
.filters-close {
  position: absolute;
  top: .4rem;
  right: .5rem;
  background: none;
  border: 0;
  color: var(--muted);
  font-size: 1.4rem;
  line-height: 1;
  cursor: pointer;
  padding: 0 .2rem;
}
.filters-close:hover { color: var(--text); }

.filter-block { display: flex; flex-direction: column; gap: .4rem; }
.filter-label { color: var(--muted); font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; font-weight: 600; }

.filter-select { margin: 0; max-width: none; }
.filter-select select {
  font-size: .85rem;
  padding: .35rem .6rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  background: transparent;
}

.chip-group { display: flex; gap: .4rem; }
.chip-group a {
  font-size: .85rem;
  padding: .35rem .75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--muted);
  text-decoration: none;
}
.chip-group a:hover { border-color: var(--accent); color: var(--text); }
.chip-group a.active {
  background: var(--accent);
  color: var(--accent-contrast);
  border-color: var(--accent);
}

.chip-reset { font-size: .85rem; color: var(--muted); text-decoration: underline; }
.chip-reset:hover { color: var(--text); }

/* ---- Catalogo: ricerca; sotto, il box filtri e la barra vista/ordinamento. ---- */
.catalog-toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: .75rem; margin: 0 0 .6rem; }
.catalog-toolbar .search { flex: 1 1 260px; margin: 0; }

.view-bar { margin: 0 0 1rem; display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .75rem; }
.view-icons { display: flex; gap: .35rem; }

/* Ordinamento e risultati per pagina raggruppati, a destra delle icone vista. */
.list-controls { display: flex; flex-wrap: wrap; align-items: center; justify-content: flex-end; gap: .5rem; }
.sort-form { margin: 0; display: flex; align-items: center; gap: .4rem; font-size: .82rem; color: var(--muted); }
.sort-form label, .perpage-form label {
  display: flex; align-items: center; gap: .4rem; margin: 0;
}
.sort-form select, .perpage-form select { width: auto; font-size: .82rem; padding: .35rem .5rem; }
.sort-dir-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--muted);
  text-decoration: none;
  font-size: 1rem;
  line-height: 1;
}
.sort-dir-btn:hover { border-color: var(--accent); color: var(--text); }
.perpage-form { margin: 0; display: flex; align-items: center; gap: .4rem; font-size: .82rem; color: var(--muted); }

/* ---- Feedback di caricamento durante le navigazioni Turbo ----
   Barra in alto per le visite piene (menu, filtri, cambio vista); leggera
   sbiadita del frame mentre carica (ricerca, ordinamento, paginazione, scheda):
   risposte veloci non lampeggiano, quelle lente segnalano subito l'attesa. */
.turbo-progress-bar { height: 3px; background: var(--accent); }
/* I turbo-frame sono inline di default: da blocco l'opacità (sotto) fa effetto e
   il box contiene bene i figli a blocco. */
turbo-frame { display: block; }
turbo-frame[aria-busy="true"] { opacity: .6; transition: opacity .12s ease; }
#catalog[aria-busy="true"] { cursor: progress; }
.view-icons a {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 32px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--muted);
}
.view-icons a:hover { border-color: var(--accent); color: var(--text); }
.view-icons a.active { background: var(--accent); color: var(--accent-contrast); border-color: var(--accent); }
.view-icons svg { display: block; }

/* Intestazioni colonne sopra la lista (lista / foto piccole). */
/* Stessa gap/padding delle righe (+ bordo trasparente che compensa il bordo da
   1px delle righe) così le colonne dell'intestazione si allineano con i dati. */
.list-head { display: flex; align-items: center; gap: 1rem; padding: .1rem .9rem .35rem; border: 1px solid transparent; }
.list-head-thumb { flex: 0 0 56px; }
.list-head .product-info {
  flex: 1;
  font-size: .78rem;
  text-transform: uppercase;
  letter-spacing: .04em;
  font-weight: 600;
  color: var(--muted);
}

.product-item { color: var(--text); text-decoration: none; }
.product-thumb { display: block; }
.product-thumb img { display: block; }
.product-code { color: var(--muted); font-size: .8rem; }
.product-desc { font-weight: 600; }
.product-company { max-width: 100%; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.product-price { font-weight: 600; white-space: nowrap; }
.product-cost, .product-markup { white-space: nowrap; }

/* Modalità a righe: lista e foto piccole. Colonne a larghezza fissa → si allineano fra righe. */
.view-lista, .view-mini { display: flex; flex-direction: column; gap: .4rem; }
.view-lista .product-item, .view-mini .product-item {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: .7rem .9rem;
  background: var(--row-bg);
  border: 1px solid var(--border);
  border-radius: 0;
  font-size: 1.02rem;
}
.view-lista .product-item:hover, .view-mini .product-item:hover { border-color: var(--accent); }
.view-mini .product-thumb {
  flex: 0 0 56px;
  width: 56px;
  height: 56px;
  border-radius: 8px;
  overflow: hidden;
  background: var(--surface-2);
}
.view-mini .product-thumb img { width: 56px; height: 56px; object-fit: cover; }
/* Griglia colonne condivisa da intestazione e righe: larghezze fisse così le
   colonne si allineano tra le righe. */
.list-head .product-info,
.view-lista .product-info, .view-mini .product-info {
  flex: 1;
  min-width: 0;
  display: grid;
  grid-template-columns: 110px minmax(140px, 1fr) 150px 130px 95px 105px 90px;
  column-gap: 0;
  row-gap: .1rem;
  align-items: center;
}
.product-info > * { padding-right: 1rem; min-width: 0; }

/* Modalità griglia: foto grandi. Le colonne seguono lo spazio reale del catalogo,
   compreso quando il drawer è aperto, evitando card illeggibili su viewport piccoli. */
.view-foto {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 180px), 1fr));
  gap: 1rem;
}
.view-foto .product-item {
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
}
.view-foto .product-item:hover { border-color: var(--accent); }
.view-foto .product-thumb { width: 100%; aspect-ratio: 1; background: var(--surface-2); }
.view-foto .product-thumb img { width: 100%; height: 100%; object-fit: cover; }
.view-foto .product-info { display: flex; flex-direction: column; gap: .2rem; padding: .65rem .8rem; }

/* La lista reagisce alla larghezza del catalogo, non solo a quella della finestra:
   vale quindi anche su laptop quando il drawer dettaglio occupa la parte destra. */
@container (max-width: 960px) {
  .view-lista .product-info, .view-mini .product-info {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: .1rem;
  }
  .list-head { display: none; }  /* le colonne si impilano: l'intestazione non allinea più */
  .product-code::before { content: "Codice: "; color: var(--muted); font-weight: 400; }
  .product-desc::before { content: "Descrizione: "; color: var(--muted); font-weight: 400; }
  .product-company::before { content: "Azienda: "; color: var(--muted); font-weight: 400; }
  .product-stock::before { content: "Giacenza: "; color: var(--muted); font-weight: 400; }
  .product-cost::before { content: "Costo: "; color: var(--muted); font-weight: 400; }
  .product-price::before { content: "Prezzo: "; color: var(--muted); font-weight: 400; }
  .product-markup::before { content: "Ricarico: "; color: var(--muted); font-weight: 400; }
}

/* Impaginazione del catalogo. */
.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  margin: 1.25rem 0 .5rem;
}
.pagination .page-link {
  padding: .4rem .8rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  text-decoration: none;
}
.pagination .page-link:hover { border-color: var(--accent); }
.pagination .page-link.disabled { color: var(--muted); opacity: .5; pointer-events: none; }
.pagination .page-info { color: var(--muted); font-size: .9rem; }

/* Segnaposto per i prodotti senza foto: tessera colorata (nessun testo). */
.thumb-placeholder { display: block; width: 100%; height: 100%; }

/* Galleria sulla scheda prodotto. */
.gallery-main { width: 100%; max-width: 320px; }

/* Slideshow stile Instagram: una foto per volta, frecce laterali e pallini sotto. */
.slideshow { position: relative; }
.slides { position: relative; width: 100%; aspect-ratio: 1; background: var(--surface-2); border-radius: var(--radius); overflow: hidden; }
.slide { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; opacity: 0; transition: opacity .2s ease; border-radius: 0; cursor: zoom-in; pointer-events: none; }
.slide.is-active { opacity: 1; pointer-events: auto; }
.slide-nav {
  position: absolute; top: 50%; transform: translateY(-50%);
  width: 34px; height: 34px; display: flex; align-items: center; justify-content: center;
  font-size: 1.5rem; line-height: 1; color: var(--text);
  background: color-mix(in srgb, var(--surface) 82%, transparent);
  border: 1px solid var(--border); border-radius: 999px; cursor: pointer;
}
.slide-nav:hover { border-color: var(--accent); }
.slide-prev { left: .5rem; }
.slide-next { right: .5rem; }
.slide-dots { display: flex; justify-content: center; gap: .4rem; margin-top: .6rem; }
.slide-dot { width: 8px; height: 8px; padding: 0; border: 0; border-radius: 999px; background: var(--border); cursor: pointer; }
.slide-dot.is-active { background: var(--accent); }

/* Galleria nel form: anteprime con azioni principale/elimina. */
.form-gallery { display: flex; flex-wrap: wrap; gap: .75rem; margin-top: .75rem; }
.form-gallery-item {
  display: flex;
  flex-direction: column;
  gap: .2rem;
  padding: .4rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.form-gallery-item img { width: 100px; height: 100px; object-fit: cover; }
.form-gallery-item label { display: inline-flex; align-items: center; gap: .3rem; margin: 0; color: var(--text); font-size: .8rem; }

/* ---- Caricamento immagini in blocco: bubble cliccabile (label), niente pulsanti
   dentro. Le miniature scelte si spuntano/eliminano prima di caricarle. ---- */
.dropzone {
  position: relative;
  display: block;
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  margin: 0;
  text-align: center;
  color: var(--muted);
  cursor: pointer;
}
.dropzone.is-over { border-color: var(--accent); background: var(--surface-2); }
.dropzone-input {
  position: absolute; top: 0; left: 0;
  width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}
.dropzone-previews {
  display: none;
  grid-template-columns: repeat(auto-fill, minmax(64px, 1fr));
  gap: .5rem;
  margin-top: .75rem;
  text-align: left;
  /* Con molte immagini la bolla non cresce all'infinito: scrolla al suo interno. */
  max-height: 40vh;
  overflow-y: auto;
}
.dropzone-thumb {
  position: relative;
  border: 2px solid var(--accent);
  border-radius: 6px;
  overflow: hidden;
  cursor: pointer;
}
.dropzone-thumb.is-off { border-color: var(--border); opacity: .45; }
.dropzone-thumb img { display: block; width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 0; }
.dropzone-thumb-del {
  position: absolute; top: 2px; right: 2px; z-index: 2;
  width: 18px; height: 18px; padding: 0; line-height: 16px;
  border: 0; border-radius: 50%;
  background: rgba(0, 0, 0, .65); color: #fff; font-size: .85rem; cursor: pointer;
}


/* ---- Badge giacenza ---- */
.badge {
  display: inline-block;
  font-size: .7rem;
  font-weight: 600;
  padding: .1rem .45rem;
  border-radius: 999px;
  margin-left: .35rem;
  vertical-align: middle;
}
.badge-out { background: var(--danger-bg); color: var(--danger); }

/* ---- Immagini prodotto ---- */
img { border-radius: var(--radius); max-width: 100%; height: auto; }

/* ---- Banco di lavoro immagini: foto (60%) a sinistra, prodotti (40%) a destra.
   Esce dal contenitore da 960px come il catalogo, per avere spazio ai due pannelli. ---- */
.img-workbench {
  max-width: none;
  margin-inline: calc(50% - 50vw);
  padding-inline: clamp(1rem, 4vw, 3rem);
  display: grid;
  grid-template-columns: 60% 40%;
  gap: 1.5rem;
  align-items: start;
}
@media (max-width: 900px) { .img-workbench { grid-template-columns: 1fr; } }
/* In "scollega" il pannello prodotti non c'è: le foto occupano tutta la larghezza. */
.img-workbench.solo-foto { grid-template-columns: 1fr; }

/* Interruttore modalità (collega / scollega): due voci in un pill, l'attiva evidenziata. */
.mode-toggle {
  display: inline-flex; gap: .25rem;
  margin: 0 0 1.2rem; padding: .25rem;
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 999px;
}
.mode-toggle a {
  padding: .4rem 1.1rem; border-radius: 999px;
  font-size: .9rem; font-weight: 600;
  color: var(--muted); text-decoration: none;
}
.mode-toggle a.active { background: var(--accent); color: var(--accent-contrast); }

/* Pannello foto: griglia di tessere spuntabili. Come .pick-list a destra, scrolla
   al proprio interno oltre una certa altezza invece di far scrollare tutta la
   pagina. L'altezza è calcolata sottraendo a 100vh gli ingombri fissi sopra
   (topbar 78px + padding del container 24px) e sotto (padding container 64px +
   filtro/paginazione ~114px), così la griglia usa tutto lo spazio verticale
   davvero disponibile invece di fermarsi a metà schermo. */
.photo-toolbar { margin: 0 0 .8rem; }
.photo-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: .9rem;
  margin-bottom: 1rem;
  max-height: calc(100vh - 300px);
  overflow-y: auto;
}
.photo-card {
  position: relative;
  display: block;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--surface);
  cursor: pointer;
}
.photo-card:has(.photo-check:checked) {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 40%, transparent);
}
.photo-card img { display: block; width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 0; }
.photo-check { position: absolute; top: .5rem; left: .5rem; width: 20px; height: 20px; z-index: 2; cursor: pointer; }
/* Unica azione sulla tessera: la lente, centrata sull'immagine e visibile al
   passaggio. Il contenitore resta click-through (pointer-events: none) così cliccare
   la foto continua a spuntare la checkbox del <label>; solo il bottone è cliccabile. */
.photo-actions {
  position: absolute; inset: 0; z-index: 2;
  display: flex; align-items: center; justify-content: center;
  opacity: 0; pointer-events: none;
  transition: opacity .15s;
}
.photo-card:hover .photo-actions { opacity: 1; }
.photo-zoom {
  pointer-events: auto;
  display: inline-flex; align-items: center; justify-content: center;
  width: 40px; height: 40px; cursor: pointer;
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border);
  border-radius: 999px;
}
.photo-zoom:hover { background: var(--surface-2); }

/* Lightbox: <dialog> nativo per l'ingrandimento, si apre in sovrapposizione. */
.lightbox {
  padding: 0; border: 0; background: transparent; max-width: 96vw; max-height: 90vh;
}
.lightbox[open] { display: flex; align-items: center; justify-content: center; gap: .6rem; }
.lightbox::backdrop { background: rgba(0, 0, 0, .75); }
.lightbox > img { display: block; max-width: 82vw; max-height: 90vh; border-radius: var(--radius); }
.lightbox-nav {
  flex: none; width: 44px; height: 44px; border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, .45); background: rgba(0, 0, 0, .4);
  color: #fff; font-size: 1.6rem; line-height: 1; cursor: pointer;
}
.lightbox-nav:hover { background: rgba(0, 0, 0, .7); }
.lightbox-grid {
  display: none;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: .75rem;
  width: min(70vw, 900px); max-height: 85vh; overflow-y: auto;
  padding: 1rem; background: var(--surface); border-radius: var(--radius);
}
.lightbox-grid img { display: block; width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: var(--radius); }
.lightbox-empty { grid-column: 1 / -1; margin: 0; }

/* Pannello prodotti: elenco cercabile e paginato; spunta radio + foto poi "Collega". */
.pick-search-form { margin: 0 0 .6rem; max-width: none; }
.pick-search { width: 100%; }
/* Griglia colonne condivisa da intestazione e righe: stesse larghezze fisse così
   codice/descrizione si allineano tra le righe (come il catalogo). */
.pick-head, .pick-item {
  display: grid;
  grid-template-columns: 20px 56px 100px minmax(0, 1fr);
  align-items: center; gap: .6rem;
}
.pick-head {
  padding: .1rem .6rem .35rem;
  font-size: .72rem; text-transform: uppercase; letter-spacing: .04em; font-weight: 600;
  color: var(--muted);
}
/* Stesso ragionamento di .photo-grid: 100vh meno gli ingombri fissi sopra (102px)
   e sotto (padding container 64px + intestazione/paginazione ~211px). */
.pick-list {
  display: flex; flex-direction: column; gap: .35rem;
  max-height: calc(100vh - 395px); overflow-y: auto;
}
.pick-item {
  padding: .45rem .5rem;
  background: var(--row-bg); border: 1px solid var(--border); border-radius: var(--radius);
  cursor: pointer;
}
.pick-item:hover { border-color: var(--accent); }
.pick-item:has(.pick-radio:checked) {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 40%, transparent);
}
.pick-radio { width: 18px; height: 18px; cursor: pointer; }
.pick-thumb {
  position: relative;
  width: 56px; height: 56px;
  border-radius: 8px; overflow: hidden; background: var(--surface-2);
}
.pick-thumb img { display: block; width: 100%; height: 100%; object-fit: cover; }
.pick-item .product-code,
.pick-item .product-desc { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
/* Il tasto "vedi foto" sta sopra la miniatura, come lo zoom nella galleria a
   sinistra: appare solo al passaggio del mouse, ed è del tutto assente (non
   solo disabilitato) quando il prodotto non ha ancora foto da mostrare. */
.pick-view {
  position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);
  display: inline-flex; align-items: center; justify-content: center;
  width: 32px; height: 32px; cursor: pointer;
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border); border-radius: 999px;
  opacity: 0; pointer-events: none; transition: opacity .15s;
}
.pick-view:hover { background: var(--surface-2); }
.pick-item:hover .pick-view { opacity: 1; pointer-events: auto; }
.pick-view:disabled { display: none; }
/* Fisso in basso a destra, alla stessa quota di "Carica immagini" (in basso a
   sinistra): stessa coppia di azioni primarie della pagina, stesso trattamento,
   invece di lasciare che "Collega" galleggi dove capita in base al contenuto
   della lista. */
.pick-footer {
  position: fixed; right: 1.5rem; bottom: 1.5rem; z-index: 40;
  display: flex; align-items: center; gap: .75rem;
}
.selection-count { white-space: nowrap; }

/* ---- Uploader FAB: pulsante fisso in basso a sinistra, pannello che apre in su ---- */
.upload-fab { position: fixed; left: 1.5rem; bottom: 1.5rem; z-index: 40;
  display: flex; align-items: center; gap: .6rem; }
.upload-fab-button {
  display: inline-flex; align-items: center; gap: .5rem;
  padding: .7rem 1.2rem; border-radius: 999px;
  background: var(--accent); color: var(--accent-contrast);
  font-weight: 600; cursor: pointer;
  box-shadow: 0 4px 14px rgba(0, 0, 0, .28);
  list-style: none;
}
.upload-fab-button::-webkit-details-marker { display: none; }
.upload-fab-button::before { content: "＋"; font-size: 1.1rem; line-height: 1; }
.upload-fab[open] .upload-fab-button::before,
.import-fab-menu[open] .upload-fab-button::before { content: "×"; }
.upload-fab-row {
  position: absolute; left: 0; bottom: 3.5rem;
  display: flex; align-items: flex-start; gap: .6rem;
}
.upload-fab-panel {
  width: min(24rem, 90vw);
  margin: 0;
  padding: 1rem 1.1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.upload-submit { display: none; white-space: nowrap; }
input[type="submit"].upload-confirm { background: var(--ok); color: #fff; }

/* ---- Micro-interazioni: transizioni morbide sugli elementi interattivi ---- */
a, .product-item, .view-icons a, .btn-primary, .btn-ghost,
input[type="submit"], input[type="text"], input[type="password"],
input[type="search"], input[type="number"], input[type="datetime-local"], select {
  transition: border-color .15s ease, background-color .15s ease,
              color .15s ease, box-shadow .15s ease, filter .15s ease;
}

/* ---- FAB "aggiungi" (basso a destra nel catalogo) ---- */
.fab {
  position: fixed;
  right: 1.5rem;
  bottom: 1.5rem;
  z-index: 40;
}
.fab-button {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 3.25rem;
  height: 3.25rem;
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-contrast);
  font-size: 1.9rem;
  font-weight: 300;
  line-height: 1;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(0, 0, 0, .28);
  list-style: none;              /* nasconde il triangolino del <summary> */
}
.fab-button::-webkit-details-marker { display: none; }
.fab[open] .fab-button { transform: rotate(45deg); }  /* + diventa × */
.fab-menu {
  position: absolute;
  right: 0;
  bottom: 4rem;
  display: flex;
  flex-direction: column;
  min-width: 12rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.fab-menu a,
.fab-menu button {
  padding: .7rem 1rem;
  color: var(--text);
  text-decoration: none;
  font-size: .95rem;
  white-space: nowrap;
}
.fab-menu button {
  border: 0; background: none; text-align: left; cursor: pointer; font-family: inherit;
}
.fab-menu a:hover,
.fab-menu button:hover { background: var(--surface-2); }

/* "Importa fattura": stesso FAB del caricamento foto (upload-fab-*), ma in basso
   a destra e con il pannello che si allinea a destra. Si nasconde col drawer aperto. */
.import-fab-menu { position: fixed; right: 1.5rem; bottom: 1.5rem; z-index: 40;
  display: flex; align-items: center; gap: .6rem; flex-direction: row-reverse; }
.import-fab-menu .upload-fab-row { left: auto; right: 0; }
:root[data-detail="open"] .import-fab-menu { display: none; }

/* Righe fattura: cliccabili, aprono il dettaglio nel drawer. */
.invoice-row { cursor: pointer; }
.invoice-row:hover { background: var(--surface-2); }
.invoice-row.selected { background: color-mix(in srgb, var(--accent) 12%, transparent); }

/* ---- Layout adattivo ---- */
@media (max-width: 960px) {
  /* Sotto questa soglia riservare 512px al drawer lascerebbe il catalogo troppo
     stretto: la scheda passa quindi sopra il contenuto. */
  :root[data-detail="open"] .catalog:not(.products-catalog) { padding-right: var(--catalog-gutter); }
}

@media (max-width: 760px) {
  :root { --topbar-height: 6rem; }

  .topbar {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: .45rem .75rem;
    padding: .5rem .75rem;
  }
  .brand { justify-self: start; }
  .brand-logo { height: 36px; }
  .nav {
    grid-column: 1 / -1;
    gap: .35rem;
    min-width: 0;
  }
  .nav a {
    flex: 1 1 0;
    padding: .2rem .35rem;
    text-align: center;
    white-space: nowrap;
  }
  .topbar-actions { justify-content: flex-end; gap: .75rem; }

  .container { padding: 1rem .75rem 4.5rem; }
  h1 { font-size: clamp(1.55rem, 7vw, 2rem); }
  h2 { font-size: 1.2rem; }
  .back-bubble { left: .75rem; }

  .detail-drawer {
    width: calc(100vw - 2.75rem);
    max-width: none;
    padding: .9rem .85rem 2rem;
  }
  :root[data-detail="open"] .detail-handle { right: calc(100vw - 2.75rem); }

  .filters-body { flex-direction: column; gap: .8rem; padding-right: 2rem; }
  .chip-group { flex-wrap: wrap; }
  .view-bar { align-items: flex-start; }
  .list-controls { flex: 1 1 100%; justify-content: space-between; }
  form.search input[type="text"] { min-width: 0; }

  .responsive-table,
  .responsive-table tbody,
  .responsive-table tr,
  .responsive-table td { display: block; width: 100%; }
  .responsive-table { border: 0; box-shadow: none; background: transparent; }
  .responsive-table thead { display: none; }
  .responsive-table tr {
    margin-bottom: .75rem;
    padding: .55rem .7rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    box-shadow: var(--shadow);
  }
  .responsive-table td,
  .responsive-table td.row-actions {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    gap: .35rem 1rem;
    padding: .25rem 0;
    border: 0;
    white-space: normal;
  }
  .responsive-table td::before {
    content: attr(data-label);
    color: var(--muted);
    font-weight: 600;
  }

  .dymo-setup { padding: .9rem; }
  .dymo-setup-actions select { width: 100%; min-width: 0; max-width: 100%; }
  .modal-doc-frame { height: 70vh; }
}

@media (max-width: 480px) {
  .brand-logo { height: 30px; }
  .topbar .btn-ghost { padding: .3rem .55rem; }
  .nav a { font-size: .85rem; }

  form.search { align-items: stretch; }
  form.search .btn-primary { padding-inline: .75rem; }
  .sort-form label, .perpage-form label { gap: .25rem; }
  .pagination { gap: .35rem; }
  .pagination .page-link { padding: .35rem .5rem; }
  .pagination .page-info { font-size: .8rem; }

  .detail-actions { flex-wrap: wrap; }
  .modal { width: calc(100vw - 1rem); padding-inline: .85rem; }
  .modal-wide { max-width: calc(100vw - 1rem); }
  .label-preview .label--grande { transform: scale(.72); }

  .fab, .import-fab-menu, .pick-footer { right: .75rem; bottom: .75rem; }
  .upload-fab { left: .75rem; bottom: .75rem; }
  .upload-fab-panel { width: calc(100vw - 1.5rem); }
  .lightbox > img { max-width: calc(100vw - 5.5rem); }
  .lightbox-nav { width: 36px; height: 36px; }
}

@media (max-width: 900px) and (min-width: 761px) {
  .topbar { gap: .9rem; padding-inline: 1rem; }
  .nav { gap: .85rem; }
  .nav a { font-size: .88rem; }
  .topbar-actions { gap: .7rem; }
}

@media (max-width: 760px) {
  .stock-register-header { flex-direction: column; }
  .stock-register-actions { justify-content: flex-start; }
}

@media (max-width: 600px) {
  .product-form-sections { grid-template-columns: minmax(0, 1fr); }
  .product-form-images { grid-column: auto; }
  .product-form-grid,
  .movement-form-grid { grid-template-columns: minmax(0, 1fr); }
  .product-form-field-wide,
  .movement-field-date { grid-column: auto; }
  .movement-field-date { max-width: none; }
  .movement-form-actions { justify-content: stretch; }
  .movement-form-actions > * { flex: 1 1 9rem; text-align: center; }
}

/* Dettaglio prodotto: modale a ogni risoluzione, catalogo invariato sotto. */
body:has(#product-detail-dialog[open]) { overflow: hidden; }
.product-detail-dialog {
  width: min(900px, calc(100vw - 1.5rem));
  max-height: calc(100dvh - 1.5rem);
  margin: auto;
  padding: 0;
  overflow: auto;
  overscroll-behavior: contain;
}
.product-detail-header {
  position: sticky; top: 0; z-index: 2;
  display: flex; align-items: center; justify-content: space-between;
  gap: 1rem; padding: .65rem 1rem;
  background: var(--surface); border-bottom: 1px solid var(--border);
}
.product-detail-header h2 { margin: 0; font-size: 1.1rem; }
.product-detail-header form { margin: 0; }
.product-detail-header .modal-close { min-width: 36px; min-height: 36px; }
.product-detail-dialog #dettaglio { display: block; padding: 1rem; }
.product-detail-dialog .product-detail-content {
  display: grid; grid-template-columns: minmax(160px, 30%) minmax(0, 1fr);
  grid-template-areas: "hero hero" "sidebar fields" "history history";
  gap: .75rem 1.2rem; align-items: start;
}
.product-detail-dialog .detail-hero { min-width: 0; }
.product-detail-dialog .detail-sidebar {
  grid-area: sidebar;
  display: flex;
  min-width: 0;
  flex-direction: column;
  gap: .75rem;
}
.product-detail-dialog .gallery { min-width: 0; }
.product-detail-dialog .gallery .slides { max-height: 38dvh; }
.product-detail-dialog .gallery-main {
  display: block; width: 100%; height: min(230px, 30dvh);
  border-radius: var(--radius);
}
.product-detail-dialog .detail-actions { margin: 0; }
.product-detail-dialog .detail-edit { grid-area: fields; min-width: 0; margin: 0; }
.product-detail-dialog .detail-tables { grid-area: history; min-width: 0; overflow-wrap: anywhere; }
.product-detail-dialog .detail-fields { min-width: 0; }
.product-detail-dialog input { min-width: 0; max-width: 100%; }
@media (max-width: 600px) {
  .product-detail-dialog .product-detail-content {
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas: "hero" "sidebar" "fields" "history";
  }
  .detail-hero { align-items: stretch; flex-direction: column; gap: .65rem; }
  .detail-metrics { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .detail-metric { min-width: 0; border-left: 0; border-top: 1px solid var(--border); }
  .product-detail-dialog .gallery { width: min(160px, 40vw); justify-self: center; }
  .product-detail-dialog .gallery-main { height: min(130px, 22dvh); }
  .product-detail-dialog #dettaglio { padding: .65rem; }
}

@media (max-height: 650px) and (min-width: 601px) {
  .product-detail-dialog .gallery .slides {
    height: 180px;
    max-height: 180px;
    aspect-ratio: auto;
  }
}

@media (max-width: 420px) {
  .detail-form-grid { grid-template-columns: minmax(0, 1fr); }
  .detail-field-wide { grid-column: auto; }
  .detail-save-bar { align-items: stretch; flex-direction: column; }
  .detail-save-bar .detail-save { width: 100%; }
}

/* Rispetta chi preferisce meno movimento: niente transizioni né view-transition. */
@media (prefers-reduced-motion: reduce) {
  *, ::before, ::after { transition: none !important; animation: none !important; }
  ::view-transition-group(*), ::view-transition-old(*), ::view-transition-new(*) {
    animation: none !important;
  }
}

.size-grid { display: grid; gap: .5rem; }
.size-row { display: grid; grid-template-columns: 5rem minmax(0, 1fr); align-items: center; gap: .75rem; }
.size-row label { display: flex; align-items: center; gap: .5rem; }
.size-row input[type="checkbox"] { width: auto; }
.size-row input[type="number"] { width: 100%; min-width: 0; }
[data-single-stock][hidden], [data-size-total-row][hidden] { display: none; }

[data-size-options][hidden] { display: none; }
.size-mode { display: flex; align-items: center; gap: .5rem; }
.size-mode input[type="checkbox"] { width: auto; }
