/* Gestionale Cagliero Legna. Operate surface, pensato per il telefono (SPEC §9).
   Colori presi da public/styles/design-system.css del sito (stessa marca): fondo neutro,
   testo quasi nero, accento legno. Per i bottoni si usa l'accento scuro (#7d5411) perché
   l'accento chiaro del sito (#b68235) su bianco non arriva a 4.5:1.
   Interfaccia in sans di sistema (leggibile al sole, nessun download); Cormorant Garamond
   solo per il nome dell'azienda nella testata. */
@font-face {
  font-family: "Cormorant Garamond";
  font-style: normal;
  font-weight: 400 600;
  font-display: swap;
  src: url("/static/fonts/cormorant-garamond.woff2") format("woff2");
}

:root {
  --bg: #f3f2f2;
  --surface: #ffffff;
  --surface-2: #eae7e7;
  --line: #d7d3d3;
  --text: #201f1d;
  --text-2: #5c5957; /* 6.4:1 su --bg */
  --accent: #7d5411;
  --accent-press: #5a3b0a;
  --accent-soft: #fff3e4;
  --accent-line: #e1ad66;
  --ok: #2f6b34;
  --ok-soft: #e6f2e4;
  --warn: #8a4b00;
  --warn-soft: #fdebd3;
  --danger: #a12c22;
  --danger-soft: #fbe6e3;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 6px 24px rgb(58 39 13 / 0.12), 0 1px 3px rgb(58 39 13 / 0.08);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --brand: "Cormorant Garamond", Georgia, serif;
  --nav-h: 64px;
  --ease: cubic-bezier(0.16, 1, 0.3, 1);
  color-scheme: light;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 400 1rem/1.5 var(--font);
  min-height: 100dvh;
}
::selection { background: var(--accent-line); color: var(--text); }
a { color: var(--accent); text-underline-offset: 3px; }
:focus-visible { outline: 3px solid var(--accent-line); outline-offset: 2px; border-radius: 6px; }
h1, h2, h3 { line-height: 1.2; margin: 0; text-wrap: balance; }
h1 { font-size: 1.5rem; font-weight: 700; }
h2 { font-size: 1.125rem; font-weight: 700; }
h3 { font-size: 1rem; font-weight: 700; }
p { margin: 0; }
.muted { color: var(--text-2); }
.num { font-variant-numeric: tabular-nums; }
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- testata ---------- */
.top {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 10px;
  padding: 10px 16px;
  padding-top: max(10px, env(safe-area-inset-top));
  background: rgb(243 242 242 / 0.94);
  border-bottom: 1px solid var(--line);
  backdrop-filter: saturate(160%) blur(8px);
}
.top img { width: 32px; height: 32px; border-radius: 8px; }
.brand { font-family: var(--brand); font-weight: 600; font-size: 1.375rem; letter-spacing: 0.01em; line-height: 1; }
.top .back {
  display: inline-flex; align-items: center; gap: 6px; min-height: 44px; padding: 0 12px 0 4px;
  color: var(--accent); text-decoration: none; font-weight: 600;
}
.top .back::before { content: ""; width: 10px; height: 10px; border-left: 2.5px solid currentColor; border-bottom: 2.5px solid currentColor; transform: rotate(45deg); margin-left: 6px; }
.top .title { font-weight: 700; font-size: 1.0625rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

main { padding: 16px 16px calc(var(--nav-h) + 96px + env(safe-area-inset-bottom)); max-width: 760px; margin: 0 auto; }

/* ---------- barra in basso ---------- */
.nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: grid; grid-template-columns: repeat(4, 1fr);
  height: calc(var(--nav-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--surface);
  border-top: 1px solid var(--line);
}
.nav a {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  color: var(--text-2); text-decoration: none; font-size: 0.8125rem; font-weight: 600;
}
.nav a svg { width: 24px; height: 24px; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.nav a[aria-current="page"] { color: var(--accent); }
.nav a[aria-current="page"] svg { stroke-width: 2.2; }

/* ---------- bottoni ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 48px; padding: 0 18px; border-radius: var(--radius);
  border: 1px solid var(--accent); background: var(--accent); color: #fff;
  font: 600 1rem/1 var(--font); text-decoration: none; cursor: pointer;
  transition: background 160ms var(--ease), transform 120ms var(--ease);
  -webkit-tap-highlight-color: transparent;
}
.btn:hover { background: var(--accent-press); }
.btn:active { transform: scale(0.98); }
.btn[disabled], .btn[aria-disabled="true"], .btn.ghost[aria-disabled="true"], .btn.danger[disabled] { background: var(--surface-2); border-color: var(--line); color: var(--text-2); cursor: not-allowed; transform: none; }
.btn.ghost { background: var(--surface); color: var(--accent); border-color: var(--line); }
.btn.ghost:hover { background: var(--accent-soft); }
.btn.danger { background: var(--surface); color: var(--danger); border-color: var(--line); }
.btn.ok { background: var(--ok); border-color: var(--ok); }
.btn.block { width: 100%; }
.btn.busy { position: relative; color: transparent; }
.btn.busy::after { content: ""; position: absolute; width: 18px; height: 18px; border-radius: 50%; border: 2.5px solid rgb(255 255 255 / 0.45); border-top-color: #fff; animation: spin 700ms linear infinite; }
.btn.ghost.busy::after { border-color: var(--line); border-top-color: var(--accent); }
@keyframes spin { to { transform: rotate(360deg); } }

.actions3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.actions3 .btn { padding: 0 8px; flex-direction: column; gap: 2px; min-height: 64px; font-size: 0.9375rem; }
.actions3 .btn small { font-weight: 500; font-size: 0.75rem; }

.fab {
  position: fixed; right: 16px; bottom: calc(var(--nav-h) + 16px + env(safe-area-inset-bottom)); z-index: 25;
  box-shadow: var(--shadow); border-radius: 999px; min-height: 56px; padding: 0 22px; font-size: 1.0625rem;
}

/* ---------- moduli ---------- */
label.f { display: grid; gap: 6px; font-weight: 600; }
label.f > span small { font-weight: 400; color: var(--text-2); }
input, select, textarea {
  width: 100%; min-height: 48px; padding: 10px 12px;
  border: 1px solid #a8a3a3; border-radius: var(--radius-sm);
  background: var(--surface); color: var(--text); font: 400 1rem/1.4 var(--font);
}
textarea { min-height: 96px; resize: vertical; }
input::placeholder, textarea::placeholder { color: #767270; }
input:focus, select:focus, textarea:focus { outline: 3px solid var(--accent-line); outline-offset: 0; border-color: var(--accent); }
[aria-invalid="true"] { border-color: var(--danger); background: var(--danger-soft); }
.err { color: var(--danger); font-weight: 600; font-size: 0.9375rem; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.stack { display: grid; gap: 16px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  min-height: 44px; padding: 0 14px; border-radius: 999px; border: 1px solid var(--line);
  background: var(--surface); color: var(--text); font: 600 0.9375rem/1 var(--font); cursor: pointer;
}
.chip[aria-pressed="true"] { background: var(--accent); color: #fff; border-color: var(--accent); }

/* ---------- blocchi ---------- */
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.panel + .panel { margin-top: 12px; }
.panel h2 { margin-bottom: 12px; }
.section-gap { margin-top: 24px; }
.row-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }

/* contatori in alto: tre numeri che si toccano */
.counts { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 16px; }
.count {
  display: grid; gap: 2px; padding: 12px; border-radius: var(--radius); border: 1px solid var(--line);
  background: var(--surface); text-align: left; cursor: pointer; font: inherit; color: inherit; min-height: 72px;
}
.count b { font-size: 1.75rem; line-height: 1; font-variant-numeric: tabular-nums; }
.count span { font-size: 0.875rem; color: var(--text-2); font-weight: 600; }
.count[aria-pressed="true"] { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.count.alert b { color: var(--warn); }

/* linguette */
.tabs { display: flex; gap: 4px; overflow-x: auto; scrollbar-width: none; margin: 0 -16px 12px; padding: 0 16px; }
.tabs::-webkit-scrollbar { display: none; }
.tab {
  flex: none; min-height: 44px; padding: 0 14px; border-radius: 999px; border: 1px solid transparent;
  background: transparent; color: var(--text-2); font: 600 0.9375rem/1 var(--font); cursor: pointer;
}
.tab[aria-selected="true"] { background: var(--text); color: #fff; }
.search { margin-bottom: 12px; }
.search input { background: var(--surface); }

/* elenco consegne */
.list { display: grid; gap: 8px; list-style: none; margin: 0; padding: 0; }
.item {
  display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 8px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  transition: opacity 220ms var(--ease), transform 220ms var(--ease);
}
.item.leaving { opacity: 0; transform: translateX(24px); }
.item > a { display: grid; gap: 4px; padding: 12px 0 12px 14px; color: inherit; text-decoration: none; min-width: 0; }
.item .l1 { display: flex; gap: 8px; align-items: baseline; min-width: 0; }
.item .when { font-weight: 700; font-variant-numeric: tabular-nums; flex: none; }
.item .who { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .l2 { color: var(--text-2); font-size: 0.9375rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 0.8125rem; font-weight: 700; background: var(--surface-2); color: var(--text-2); }
.badge.richiesta { background: var(--warn-soft); color: var(--warn); }
.badge.confermata { background: var(--accent-soft); color: var(--accent); }
.badge.consegnata { background: var(--ok-soft); color: var(--ok); }
.badge.annullata { background: var(--surface-2); color: var(--text-2); text-decoration: line-through; }
.badge.late { background: var(--danger-soft); color: var(--danger); }

/* cerchio da spuntare */
.tick {
  width: 56px; height: 56px; margin-right: 6px; border: 0; background: none; cursor: pointer; display: grid; place-items: center;
  -webkit-tap-highlight-color: transparent;
}
.tick span {
  width: 32px; height: 32px; border-radius: 50%; border: 2.5px solid #8f8a88; display: grid; place-items: center;
  transition: background 160ms var(--ease), border-color 160ms var(--ease);
}
.tick span::after { content: ""; width: 12px; height: 7px; border-left: 3px solid transparent; border-bottom: 3px solid transparent; transform: translateY(-2px) rotate(-45deg); }
.tick:hover span { border-color: var(--ok); }
.tick:hover span::after { border-color: var(--ok); }
.tick.done span { background: var(--ok); border-color: var(--ok); }
.tick.done span::after { border-color: #fff; }

/* vuoto, caricamento, errore */
.empty { text-align: left; padding: 24px 16px; border: 1px dashed #bab6b6; border-radius: var(--radius); background: rgb(255 255 255 / 0.5); display: grid; gap: 12px; }
.empty h2 { font-size: 1.0625rem; }
.skel { height: 68px; border-radius: var(--radius); background: linear-gradient(90deg, var(--surface-2) 25%, #f4f2f2 50%, var(--surface-2) 75%); background-size: 200% 100%; animation: shimmer 1.2s ease-in-out infinite; }
@keyframes shimmer { to { background-position: -200% 0; } }
.notice { padding: 14px 16px; border-radius: var(--radius); background: var(--warn-soft); color: var(--warn); display: grid; gap: 10px; }
.notice.bad { background: var(--danger-soft); color: var(--danger); }

/* dettaglio */
.hero-d { display: grid; gap: 6px; margin-bottom: 16px; }
.hero-d h1 { font-size: 1.625rem; }
.kv { display: grid; grid-template-columns: 1fr; gap: 2px; }
.kv dt { font-size: 0.875rem; color: var(--text-2); font-weight: 600; }
.kv dd { margin: 0 0 10px; }
.edit-row { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.edit-row h2 { margin: 0; }
.linkbtn { background: none; border: 0; color: var(--accent); font: 600 1rem var(--font); min-height: 44px; padding: 0 4px; cursor: pointer; }
.history { list-style: none; padding: 0; margin: 0; display: grid; gap: 8px; font-size: 0.9375rem; }
.history li { display: grid; gap: 0; }
.history time { color: var(--text-2); font-size: 0.8125rem; }

/* agenda */
.weekbar { display: grid; grid-template-columns: 48px 1fr 48px; align-items: center; gap: 8px; margin-bottom: 12px; }
.weekbar .btn { padding: 0; }
.weekbar strong { text-align: center; }
.day { margin-bottom: 16px; }
.day h2 { font-size: 1rem; margin-bottom: 8px; display: flex; gap: 8px; align-items: baseline; }
.day.today h2 { color: var(--accent); }
.day .free { color: var(--text-2); padding: 10px 14px; border-radius: var(--radius); background: rgb(255 255 255 / 0.5); border: 1px dashed var(--line); }

/* contatti */
.prov { font-size: 0.8125rem; font-weight: 700; color: var(--text-2); }
.totals { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.totals div { padding: 12px; border-radius: var(--radius); background: var(--surface-2); }
.totals b { display: block; font-size: 1.25rem; font-variant-numeric: tabular-nums; }

/* foglio pagamento (dialog dal basso) */
dialog.sheet {
  border: 0; padding: 0; margin: auto auto 0; width: 100%; max-width: 560px;
  border-radius: 20px 20px 0 0; background: var(--surface); color: var(--text); box-shadow: var(--shadow);
}
dialog.sheet::backdrop { background: rgb(32 31 29 / 0.45); }
dialog.sheet[open] { animation: up 240ms var(--ease); }
@keyframes up { from { transform: translateY(40px); opacity: 0.6; } }
.sheet-in { padding: 20px 16px calc(20px + env(safe-area-inset-bottom)); display: grid; gap: 16px; }
.sheet-in .grid2 .btn, .sheet-in .grid3 .btn { min-height: 56px; font-size: 1.0625rem; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }

/* toast */
.toast {
  position: fixed; left: 16px; right: 16px; bottom: calc(var(--nav-h) + 16px + env(safe-area-inset-bottom)); z-index: 40;
  max-width: 560px; margin: 0 auto; display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 10px 10px 16px; min-height: 56px; border-radius: var(--radius);
  background: var(--text); color: #fff; box-shadow: var(--shadow); font-weight: 600;
  animation: up 220ms var(--ease);
}
.toast.bad { background: var(--danger); }
.toast button { background: none; border: 1px solid rgb(255 255 255 / 0.5); color: #fff; border-radius: var(--radius-sm); min-height: 40px; padding: 0 14px; font: 700 0.9375rem var(--font); cursor: pointer; }

/* accesso */
.login { min-height: 100dvh; display: grid; align-content: center; padding: 24px 20px; max-width: 440px; margin: 0 auto; gap: 24px; }
.login .mark { display: flex; align-items: center; gap: 12px; }
.login .mark img { width: 52px; height: 52px; border-radius: 12px; }
.login .mark .brand { font-size: 1.875rem; }
.login h1 { font-size: 1.5rem; }
.login form { display: grid; gap: 14px; }
.login .sent { display: grid; gap: 10px; padding: 16px; border-radius: var(--radius); background: var(--ok-soft); color: var(--ok); }
.login .sent p { color: var(--text); }

@media (min-width: 900px) {
  main { padding-top: 24px; }
  .nav { left: 50%; right: auto; transform: translateX(-50%); width: 560px; bottom: 16px; border: 1px solid var(--line); border-radius: 16px; box-shadow: var(--shadow); height: var(--nav-h); padding: 0; }
  .fab { right: calc(50% - 380px); bottom: calc(var(--nav-h) + 32px); }
  .toast { bottom: calc(var(--nav-h) + 32px); }
  .grid-detail { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; align-items: start; }
  .grid-detail .panel + .panel { margin-top: 0; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 1ms !important; transition-duration: 1ms !important; }
}

/* utilità (niente stili inline: la CSP li blocca) */
.stack.tight { gap: 8px; }
.btn.big { min-height: 56px; font-size: 1.125rem; }
.notice h1 { font-size: 1.25rem; }
.linkbtn.inline { padding: 0; min-height: auto; font-size: inherit; text-decoration: underline; text-underline-offset: 3px; }
/* un bottone che sta lavorando resta del suo colore, con la rotellina */
.btn.busy[disabled] { background: var(--accent); border-color: var(--accent); color: transparent; cursor: progress; }
.btn.ok.busy[disabled] { background: var(--ok); border-color: var(--ok); }
.btn.ghost.busy[disabled], .btn.danger.busy[disabled] { background: var(--surface); border-color: var(--line); }
