/* Palette (vedi GUIDELINES.md): https://coolors.co/22223b-4a4e69-9a8c98-c9ada7-f2e9e4
   Space cadet #22223b · Ultra violet #4a4e69 · Rose quartz #9a8c98 · Pale dogwood #c9ada7 · Isabelline #f2e9e4
   Le altre tinte sono mescolanze di questi cinque. */
:root {
  color-scheme: light;    /* solo tema chiaro */
  --bg: #f2e9e4;           /* isabelline */
  --card: #fdfaf8;         /* isabelline schiarito */
  --text: #22223b;         /* space cadet */
  --muted: #6e6b80;        /* ultra violet → rose quartz */
  --line: #e3d6d0;         /* pale dogwood su isabelline */
  --accent: #4a4e69;       /* ultra violet */
  --accent-soft: #e7e1e6;  /* rose quartz molto chiaro */
  --error: #9b2c2c;
  --error-soft: #f5dfdc;
  --warn: #22223b;         /* avvisi di stato: space cadet su pale dogwood */
  --warn-soft: #e3cdc8;
  --radius: 14px;
}

* { box-sizing: border-box; }

html { overflow-x: clip; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 17px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

main { max-width: 34rem; margin: 0 auto; padding: 1.25rem 1rem 4rem; }
main.with-dock { padding-bottom: calc(6rem + env(safe-area-inset-bottom)); }

h1 { font-size: 1.6rem; margin: 0 0 .25rem; }
h2 {
  margin: 2rem 0 .6rem;
  font-size: .8rem;
  font-weight: 600;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--muted);
}
a { color: inherit; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.center { text-align: center; }

/* Layout */
header.top { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: .75rem 1rem; margin-bottom: 1.5rem; }

/* Intestazione scheda: titolo e sottotitolo a sinistra, azione piccola a destra */
.card-head { min-height: 3.6rem; }
.card-head .small { margin-top: .1rem; }

/* Home cliente: due box (ordine, storico) */
/* Box con titolo dentro (maiuscolo, con icona) e lista sotto: home cliente, ordini, scheda cliente */
.split.boxes { margin-top: 1rem; align-items: start; }
.box > .card-head { min-height: 3.9rem; gap: .5rem; }
/* Titoli dei due box in maiuscolo, stesso font e peso degli altri titoli */
.box > .card-head strong { text-transform: uppercase; font-size: min(1.05rem, 3.6vw); white-space: nowrap; }
.card-head .btn { flex: none; }
.card-head strong svg { width: 1.2em; height: 1.2em; margin-right: .4em; vertical-align: -.2em; }
@media (max-width: 26rem) {
  .box > .card-head .btn { padding: .5rem .75rem; }
}
.entry { align-items: flex-start; padding: .75rem 0; }
.entry .btn { margin-top: .1rem; }
.entry-body { min-width: 0; }
.entry-items { display: flex; flex-wrap: wrap; gap: .1rem .9rem; margin-top: .3rem; font-size: .92rem; }
.entry-items b { font-weight: 600; }

/* Scadenza ordini: avviso di stato, volutamente diverso da schede e bottoni */
.deadline {
  display: inline-flex;
  align-items: center;
  gap: .5rem;
  margin: 0;
  padding: .45rem .9rem .45rem .7rem;
  border-radius: 999px;
  background: var(--warn-soft);
  color: var(--warn);
  font-size: .9rem;
}
.deadline svg { flex: none; width: 1.1rem; height: 1.1rem; }
.sticky-head .deadline { flex: none; white-space: nowrap; }
/* Testo visibile solo da schermi larghi */
.wide-only { display: none; }
@media (min-width: 30rem) { .wide-only { display: inline; } }

/* Titolo delle sottopagine, con il bottone rotondo "indietro" a sinistra */
.page-title { display: flex; align-items: center; gap: .75rem; margin-bottom: .25rem; }
.page-title h1 { margin: 0; }
/* Testata fissa dei moduli: resta sopra il contenuto quando si scorre */
.sticky-head {
  position: sticky;
  top: 0;
  z-index: 5;
  margin: -1.25rem -1rem .25rem;
  padding: calc(.75rem + env(safe-area-inset-top)) 1rem .75rem;
}
/* Sfondo e ombra a tutta larghezza dello schermo, anche se il contenuto è centrato */
.sticky-head::before {
  content: "";
  position: absolute;
  z-index: -1;
  top: 0;
  bottom: 0;
  left: 50%;
  width: 100vw;
  transform: translateX(-50%);
  background: var(--bg);
  transition: box-shadow .2s;
}
.sticky-head h1 { flex: 1; min-width: 0; font-size: 1.3rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sticky-head h1 svg { width: 1.1em; height: 1.1em; margin-right: .35em; vertical-align: -.15em; }
.sticky-head .page-title { margin: 0; min-height: 2.75rem; }
.sticky-head .page-title .btn { flex: none; padding: .7rem 1.1rem; font-size: .95rem; }
.sticky-head.scrolled::before { box-shadow: 0 1px 0 var(--line), 0 6px 14px -10px rgb(34 34 59 / .35); }
/* Codice sulla stessa riga dell'etichetta */
.code-field { display: flex; align-items: center; gap: .75rem; margin-top: .75rem; }
.code-field span { flex: none; font-weight: 500; }
.code-field input { flex: 1; min-width: 0; }
.back {
  display: grid;
  place-items: center;
  flex: none;
  width: 2.75rem;
  height: 2.75rem;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--card);
  color: var(--text);
  box-shadow: 0 1px 3px rgb(0 0 0 / .06);
  transition: transform .08s, filter .15s;
}
.back svg { width: 1.35rem; height: 1.35rem; margin-left: -2px; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0 1rem;
  margin-bottom: .75rem;
}
.row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  min-height: 3.2rem;
  padding: .5rem 0;
  border-bottom: 1px solid var(--line);
}
.row:last-child { border-bottom: 0; }

/* Riga intera cliccabile, con freccia a destra */
a.row { color: inherit; text-decoration: none; font-weight: 500; }
a.row::after { content: "\203A"; margin-left: auto; font-size: 1.5rem; line-height: 1; color: var(--muted); }
.card-actions { display: flex; justify-content: flex-end; gap: .5rem; padding: .6rem 0; }
.qty { font-weight: 600; font-variant-numeric: tabular-nums; }

.actions { display: grid; grid-template-columns: 1fr 1fr; gap: .75rem; margin: 1rem 0; }
.pager { display: flex; justify-content: space-between; align-items: center; gap: .5rem; }
.stack > * + * { margin-top: .9rem; }
.inline { display: flex; gap: .5rem; margin: 1rem 0; }
.inline input { flex: 1; }
.inline .btn { width: auto; }

/* Elementi */
.btn {
  display: block;
  width: 100%;
  padding: .9rem 1rem;
  border: 1px solid transparent;
  border-radius: var(--radius);
  background: var(--accent);
  color: var(--bg);
  font: inherit;
  font-weight: 600;
  text-align: center;
  text-decoration: none;
  cursor: pointer;
  transition: transform .08s, filter .15s;
}
.btn.secondary { background: var(--accent-soft); color: var(--accent); }
.btn.danger { background: var(--error-soft); color: var(--error); }
.btn.quiet { background: transparent; color: var(--muted); border-color: var(--line); }
.btn.small { display: inline-block; width: auto; padding: .5rem .9rem; font-size: .9rem; white-space: nowrap; }

/* Feedback al tocco e al passaggio del mouse */
.btn:active, .back:active, .stepper button:active { transform: scale(.96); filter: brightness(.93); }
a.row:active { opacity: .6; }
@media (hover: hover) {
  .btn:hover, .back:hover, .stepper button:hover { filter: brightness(.96); }
  a.row:hover::after { color: var(--accent); }
}
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.field { display: block; }
.field > span { display: block; margin-bottom: .35rem; font-weight: 500; }

input[type=text], input[type=password] {
  width: 100%;
  padding: .85rem 1rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--card);
  color: var(--text);
  font: inherit;
}

.stepper { display: flex; align-items: center; gap: .25rem; }
.stepper button {
  width: 2.6rem;
  height: 2.6rem;
  border: 0;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 1.4rem;
  font-weight: 600;
  line-height: 1;
  cursor: pointer;
  transition: transform .08s;
}
.stepper input {
  width: 3rem;
  border: 0;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-weight: 600;
  text-align: center;
  -moz-appearance: textfield;
}
.stepper input::-webkit-inner-spin-button,
.stepper input::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }

.notice {
  margin-bottom: 1rem;
  padding: .8rem 1rem;
  border-radius: var(--radius);
  background: var(--accent-soft);
  color: var(--accent);
}
.notice.error { background: var(--error-soft); color: var(--error); }

/* Notifica a comparsa: in sovrimpressione in alto, sparisce da sola */
.toast {
  position: fixed;
  z-index: 20;
  top: calc(.75rem + env(safe-area-inset-top));
  left: 50%;
  display: flex;
  align-items: center;
  gap: .5rem;
  max-width: calc(100% - 2rem);
  padding: .65rem 1.1rem;
  border-radius: 999px;
  background: var(--text);
  color: var(--bg);
  font-size: .95rem;
  font-weight: 600;
  box-shadow: 0 10px 30px rgb(34 34 59 / .25);
  pointer-events: none;
  animation: toast-in .3s ease-out both, toast-out .4s ease-in 2.6s forwards;
}
.toast svg { flex: none; width: 1.1rem; height: 1.1rem; }
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, -1rem); } to { opacity: 1; transform: translate(-50%, 0); } }
@keyframes toast-out { to { opacity: 0; transform: translate(-50%, -1rem); visibility: hidden; } }

.switch {
  position: relative;
  flex: none;
  width: 3rem;
  height: 1.75rem;
  padding: 0;
  border: 0;
  border-radius: 999px;
  background: var(--line);
  cursor: pointer;
  transition: background .2s;
}
.switch::after {
  content: "";
  position: absolute;
  top: .2rem;
  left: .2rem;
  width: 1.35rem;
  height: 1.35rem;
  border-radius: 50%;
  background: var(--card);
  box-shadow: 0 1px 3px rgb(34 34 59 / .25);
  transition: transform .2s;
}
.switch[aria-checked="true"] { background: var(--accent); }
.switch[aria-checked="true"]::after { transform: translateX(1.25rem); }

.tag {
  padding: .05rem .5rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: .75rem;
  color: var(--muted);
}

/* Barra di navigazione in basso: pillola bianca, voce attiva a pillola --- */
.dock {
  position: fixed;
  z-index: 10;
  left: 50%;
  bottom: calc(.75rem + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  display: flex;
  align-items: stretch;
  gap: .15rem;
  padding: .3rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--card);
  box-shadow: 0 10px 30px rgb(0 0 0 / .10), 0 1px 3px rgb(0 0 0 / .06);
}
.dock form { display: contents; }
.dock a, .dock button {
  display: flex;
  flex: 1;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: .15rem;
  min-width: 5.5rem;
  padding: .4rem .9rem .35rem;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: .72rem;
  font-weight: 500;
  line-height: 1.1;
  white-space: nowrap;
  text-decoration: none;
  cursor: pointer;
  transition: background .15s, color .15s, transform .08s;
}
.dock svg { width: 1.3rem; height: 1.3rem; }
.dock [aria-current] svg { stroke-width: 2; }
.dock [aria-current] { background: var(--accent-soft); color: var(--text); font-weight: 700; }
.dock a:active, .dock button:active { transform: scale(.95); }
.dock-sep { flex: none; width: 1px; margin: .55rem .1rem; background: var(--line); }
@media (hover: hover) {
  .dock a:not([aria-current]):hover, .dock button:hover { background: var(--bg); color: var(--text); }
}
@media (min-width: 48rem) {
  .dock a, .dock button { min-width: 6.5rem; font-size: .78rem; }
  .dock svg { width: 1.4rem; height: 1.4rem; }
}
/* Sfumatura sotto la barra: il contenuto che scorre dietro si opacizza
   e sfoca progressivamente verso il basso */
.dock-fade {
  position: fixed;
  z-index: 9;
  left: 0;
  right: 0;
  bottom: 0;
  height: calc(6.5rem + env(safe-area-inset-bottom));
  pointer-events: none;
  background: linear-gradient(to bottom, rgb(242 233 228 / 0), rgb(242 233 228 / .85) 75%);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
  -webkit-mask-image: linear-gradient(to bottom, transparent, #000 70%);
  mask-image: linear-gradient(to bottom, transparent, #000 70%);
}

/* Schermi larghi (PC, anche con finestra a metà schermo) ----------------- */
@media (min-width: 50rem) {
  main.wide { max-width: 62rem; padding-top: 2rem; padding-left: 2rem; padding-right: 2rem; }
  main.wide .sticky-head { margin: -2rem -2rem .25rem; padding: 1rem 2rem; }
  .sticky-head h1 { font-size: 1.6rem; }
  .code-field input { flex: none; width: 16rem; }

  /* Due colonne affiancate; il primo titolo di ogni colonna si allinea in alto */
  .split { display: grid; grid-template-columns: 1fr 1fr; gap: 0 2rem; align-items: start; margin-top: 1.75rem; }
  header.top + .split, .notice + .split, .toast + .split { margin-top: 0; }
  .split > section > h2:first-child { margin-top: 0; }

  /* Ordini della settimana: totale e "senza ordine" a sinistra, clienti a destra */
  .split.week { grid-template-areas: "a b" "c b"; grid-template-rows: auto 1fr; }
  .split.week > section { align-self: start; }
  .area-a { grid-area: a; }
  .area-b { grid-area: b; }
  .area-c { grid-area: c; }

  /* Titolo e campo "aggiungi" sulla stessa riga */
  .page-head { display: flex; justify-content: space-between; align-items: center; gap: 2rem; margin-bottom: 1.25rem; }
  .page-head h1 { margin: 0; }
  .page-head .inline { margin: 0; width: 24rem; }

  /* Elenchi (clienti, prodotti, moduli): ogni voce diventa una scheda separata */
  .tiles {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(17rem, 1fr));
    gap: .75rem;
    padding: 0;
    border: 0;
    background: transparent;
  }
  .tiles > .row {
    padding: .6rem 1rem;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--card);
  }
  .tiles > .row:last-child { border-bottom: 1px solid var(--line); }
  .tiles > .row.muted { grid-column: 1 / -1; }
  @media (hover: hover) {
    .tiles > a.row { transition: border-color .15s, box-shadow .15s; }
    .tiles > a.row:hover { border-color: var(--accent); box-shadow: 0 2px 8px rgb(0 0 0 / .06); }
  }

  /* Moduli: +/- vicino al nome */
  .qty-list > .row { padding-right: .6rem; }
  .qty-list > .row label { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .qty-list .stepper { flex: none; }
  .qty-list .stepper button { width: 2.3rem; height: 2.3rem; font-size: 1.25rem; }
  .qty-list .stepper input { width: 2.6rem; }
}
