/* WorkManager — Console Ufficio.
 *
 * A tool, not a page: it is read at a glance by someone on the phone with a
 * customer while an operaio is halfway through a giro. Density, stable
 * meanings for colour, and state you can see without reading — in that order.
 * The teal identity is shared with the tablet app; the two must look like
 * siblings.
 */

:root {
  /* ── palette ──────────────────────────────────────────────────────
     Neutrals carry a slight teal bias so white surfaces read as lifted
     off the ground rather than punched out of it. */
  --accent: #0e7c86;
  --accent-hover: #0a656d;
  --accent-weak: #dcedef;
  --accent-ink: #075a62;
  --on-accent: #ffffff;          /* text that sits on a filled accent */

  --bg: #eef3f4;
  --surface: #ffffff;
  --surface-2: #f2f6f7;
  --surface-3: #e6eef0;
  --border: #dae4e6;
  --border-strong: #bfced2;

  --ink: #10222a;
  --ink-2: #3d545c;
  --muted: #5c7178;
  --faint: #6f858c;

  --good: #1d7f4c;   --good-bg: #dcf0e4;   --good-ink: #14603a;
  --warn: #96620a;   --warn-bg: #f8ecd6;   --warn-ink: #7a4f06;
  --crit: #b8382f;   --crit-bg: #fae0dd;   --crit-ink: #93291f;
  --info: #1f6296;   --info-bg: #dfecf7;   --info-ink: #17507c;

  /* ── spacing: a 4px grid, named by use, not by size ─────────────── */
  --s-1: 4px;  --s-2: 8px;  --s-3: 12px; --s-4: 16px;
  --s-5: 20px; --s-6: 24px; --s-8: 32px; --s-10: 40px;

  /* ── type ───────────────────────────────────────────────────────── */
  --text-3xs: 11px; --text-2xs: 12px; --text-xs: 13px; --text-sm: 14px;
  --text-md: 15px;  --text-lg: 17px;  --text-xl: 20px; --text-2xl: 26px;
  --text-3xl: 32px;
  /* The system UI face, chosen on purpose: the console has to paint
     instantly over the workshop's connection and the printed report must
     render with no network at all. A webfont would add a failure mode and
     buy nothing a tool like this can use. */
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;

  --radius: 10px; --radius-sm: 7px; --radius-lg: 14px;

  /* Shadows: real offset, soft blur — never a zero-offset halo. */
  --e1: 0 1px 2px rgba(13, 41, 51, .06);
  --e2: 0 1px 2px rgba(13, 41, 51, .05), 0 4px 12px -2px rgba(13, 41, 51, .07);
  --e3: 0 12px 32px -8px rgba(13, 41, 51, .28), 0 2px 6px rgba(13, 41, 51, .12);

  --focus: 0 0 0 2px var(--surface), 0 0 0 4px var(--accent);
  --dur: 150ms;
  --ease: cubic-bezier(.2, .7, .2, 1);
}

@media (prefers-color-scheme: dark) {
  :root {
    --accent: #35c1ca; --accent-hover: #58d4dc; --accent-weak: #12383c; --accent-ink: #7fe2e8;
    --on-accent: #04252a;
    --bg: #0c1214; --surface: #151e21; --surface-2: #1b262a; --surface-3: #223034;
    --border: #263438; --border-strong: #384c51;
    --ink: #e9f1f2; --ink-2: #b6c7cb; --muted: #93a6ab; --faint: #6d8288;
    --good: #52c47f; --good-bg: #16301f; --good-ink: #7ad8a0;
    --warn: #e0a545; --warn-bg: #33270f; --warn-ink: #efc37f;
    --crit: #f0776d; --crit-bg: #3a1c19; --crit-ink: #f6a49d;
    --info: #63a7de; --info-bg: #16283a; --info-ink: #9cc8ec;
    --e1: 0 1px 2px rgba(0, 0, 0, .4);
    --e2: 0 1px 2px rgba(0, 0, 0, .35), 0 6px 16px -4px rgba(0, 0, 0, .45);
    --e3: 0 16px 40px -10px rgba(0, 0, 0, .7), 0 2px 8px rgba(0, 0, 0, .5);
  }
}

/* The in-page theme toggle has to win over the OS preference in both
   directions, so both themes are restated here. */
:root[data-theme="light"] {
  --accent: #0e7c86; --accent-hover: #0a656d; --accent-weak: #dcedef; --accent-ink: #075a62;
  --on-accent: #ffffff;
  --bg: #eef3f4; --surface: #ffffff; --surface-2: #f2f6f7; --surface-3: #e6eef0;
  --border: #dae4e6; --border-strong: #bfced2;
  --ink: #10222a; --ink-2: #3d545c; --muted: #5c7178; --faint: #6f858c;
  --good: #1d7f4c; --good-bg: #dcf0e4; --good-ink: #14603a;
  --warn: #96620a; --warn-bg: #f8ecd6; --warn-ink: #7a4f06;
  --crit: #b8382f; --crit-bg: #fae0dd; --crit-ink: #93291f;
  --info: #1f6296; --info-bg: #dfecf7; --info-ink: #17507c;
  --e1: 0 1px 2px rgba(13, 41, 51, .06);
  --e2: 0 1px 2px rgba(13, 41, 51, .05), 0 4px 12px -2px rgba(13, 41, 51, .07);
  --e3: 0 12px 32px -8px rgba(13, 41, 51, .28), 0 2px 6px rgba(13, 41, 51, .12);
}
:root[data-theme="dark"] {
  --accent: #35c1ca; --accent-hover: #58d4dc; --accent-weak: #12383c; --accent-ink: #7fe2e8;
  --on-accent: #04252a;
  --bg: #0c1214; --surface: #151e21; --surface-2: #1b262a; --surface-3: #223034;
  --border: #263438; --border-strong: #384c51;
  --ink: #e9f1f2; --ink-2: #b6c7cb; --muted: #93a6ab; --faint: #6d8288;
  --good: #52c47f; --good-bg: #16301f; --good-ink: #7ad8a0;
  --warn: #e0a545; --warn-bg: #33270f; --warn-ink: #efc37f;
  --crit: #f0776d; --crit-bg: #3a1c19; --crit-ink: #f6a49d;
  --info: #63a7de; --info-bg: #16283a; --info-ink: #9cc8ec;
  --e1: 0 1px 2px rgba(0, 0, 0, .4);
  --e2: 0 1px 2px rgba(0, 0, 0, .35), 0 6px 16px -4px rgba(0, 0, 0, .45);
  --e3: 0 16px 40px -10px rgba(0, 0, 0, .7), 0 2px 8px rgba(0, 0, 0, .5);
}

/* ── base ─────────────────────────────────────────────────────────── */
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; font-family: var(--font); background: var(--bg); color: var(--ink);
  font-size: var(--text-sm); line-height: 1.5; -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
h1, h2, h3, h4 { margin: 0; text-wrap: balance; font-weight: 600; letter-spacing: -.01em; }
p { margin: 0; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent-ink); text-underline-offset: 2px; }
a:hover { text-decoration-thickness: 2px; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .92em; }

.tnum { font-variant-numeric: tabular-nums; }
.hidden { display: none !important; }
.icon { flex: none; display: block; }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* One focus treatment for everything that takes focus. */
:focus { outline: none; }
:focus-visible { outline: none; box-shadow: var(--focus); border-radius: var(--radius-sm); }
input:focus-visible, select:focus-visible, textarea:focus-visible { box-shadow: none; }

/* ── layout helpers (these replace ~200 inline style attributes) ──── */
.stack   { display: flex; flex-direction: column; }
.cluster { display: flex; align-items: center; gap: var(--s-2); flex-wrap: wrap; }
.grow    { flex: 1; min-width: 0; }
.mt-2 { margin-top: var(--s-2); }  .mt-3 { margin-top: var(--s-3); }  .mt-4 { margin-top: var(--s-4); }
.mt-6 { margin-top: var(--s-6); }  .mt-8 { margin-top: var(--s-8); }
.mb-2 { margin-bottom: var(--s-2); } .mb-3 { margin-bottom: var(--s-3); } .mb-4 { margin-bottom: var(--s-4); }
.mb-6 { margin-bottom: var(--s-6); } .mb-8 { margin-bottom: var(--s-8); }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.muted { color: var(--muted); }
.meta  { color: var(--muted); font-size: var(--text-2xs); }
.text-good { color: var(--good-ink); } .text-crit { color: var(--crit-ink); }

/* ── login ────────────────────────────────────────────────────────── */
.login-wrap { min-height: 100dvh; display: grid; place-items: center; padding: var(--s-6); }
.login-card {
  width: min(400px, 100%); background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); box-shadow: var(--e2); padding: var(--s-8);
}
.login-card .brand { display: flex; align-items: center; gap: var(--s-3); margin-bottom: var(--s-2); }
.login-card h1 { font-size: var(--text-xl); }
.login-card p.sub { color: var(--muted); margin: 0 0 var(--s-6); font-size: var(--text-xs); }
.login-card .field:last-of-type { margin-bottom: var(--s-5); }
.logo {
  width: 36px; height: 36px; border-radius: var(--radius-sm); background: var(--accent);
  color: var(--on-accent); display: grid; place-items: center; font-weight: 700; font-size: var(--text-md);
  flex: none; letter-spacing: 0;
}

/* ── shell ────────────────────────────────────────────────────────── */
.app { display: grid; grid-template-columns: 236px 1fr; min-height: 100dvh; }
.sidebar {
  background: var(--surface); border-right: 1px solid var(--border); padding: var(--s-4) var(--s-3);
  display: flex; flex-direction: column; gap: 2px; position: sticky; top: 0; height: 100dvh;
}
.sidebar .brand { display: flex; align-items: center; gap: var(--s-3); padding: var(--s-1) var(--s-2) var(--s-5); }
.sidebar .brand b { font-size: var(--text-sm); display: block; letter-spacing: -.01em; }
.sidebar .brand span { display: block; font-size: var(--text-2xs); color: var(--muted); }
.nav-item {
  display: flex; align-items: center; gap: var(--s-3); padding: 8px 10px; border-radius: var(--radius-sm);
  color: var(--ink-2); text-decoration: none; cursor: pointer; font-size: var(--text-sm);
  border: none; background: none; width: 100%; text-align: left;
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease);
}
.nav-item .icon { color: var(--faint); transition: color var(--dur) var(--ease); }
.nav-item:hover { background: var(--surface-2); color: var(--ink); }
.nav-item:hover .icon { color: var(--muted); }
.nav-item.active { background: var(--accent-weak); color: var(--accent-ink); font-weight: 600; }
.nav-item.active .icon { color: var(--accent); }
.sidebar .spacer { flex: 1; }
.sidebar .foot {
  padding: var(--s-3) var(--s-2) 0; font-size: var(--text-2xs); color: var(--muted);
  border-top: 1px solid var(--border); margin-top: var(--s-2);
}
.sidebar .foot b { color: var(--ink); font-weight: 600; display: block; }

.main { min-width: 0; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 5;
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border); padding: var(--s-3) var(--s-6);
  display: flex; align-items: center; gap: var(--s-4); min-height: 60px;
}
.topbar h2 { font-size: var(--text-lg); }
.topbar .sub { color: var(--muted); font-size: var(--text-2xs); margin-top: 1px; }
.content { padding: var(--s-6) var(--s-6) var(--s-10); max-width: 1180px; width: 100%; }
.content.wide { max-width: 1560px; }

/* ── buttons ──────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 8px 13px; border-radius: var(--radius-sm); border: 1px solid var(--border-strong);
  background: var(--surface); color: var(--ink); cursor: pointer;
  font-size: var(--text-xs); font-weight: 600; white-space: nowrap;
  transition: background var(--dur) var(--ease), border-color var(--dur) var(--ease), color var(--dur) var(--ease);
}
.btn .icon { color: var(--muted); transition: color var(--dur) var(--ease); }
.btn:hover { background: var(--surface-2); border-color: var(--faint); }
.btn:hover .icon { color: var(--ink); }
.btn:active { background: var(--surface-3); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn.primary .icon { color: currentColor; }
.btn.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn.ghost { border-color: transparent; background: transparent; color: var(--ink-2); }
.btn.ghost:hover { background: var(--surface-2); border-color: transparent; color: var(--ink); }
.btn.danger { color: var(--crit-ink); border-color: transparent; background: transparent; }
.btn.danger .icon { color: currentColor; }
.btn.danger:hover { background: var(--crit-bg); border-color: transparent; color: var(--crit-ink); }
.btn.sm { padding: 5px 9px; font-size: var(--text-2xs); gap: 5px; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn:disabled:hover { background: var(--surface); border-color: var(--border-strong); }
.btn.busy { position: relative; color: transparent; }
.btn.busy .icon { color: transparent; }
.btn.busy::after {
  content: ''; position: absolute; inset: 0; margin: auto; width: 13px; height: 13px;
  border: 2px solid currentColor; border-top-color: transparent; border-radius: 50%;
  color: var(--muted); animation: spin .7s linear infinite;
}
.btn.primary.busy::after { color: var(--on-accent); }
@keyframes spin { to { transform: rotate(360deg); } }

.icon-btn {
  border: 1px solid transparent; background: none; cursor: pointer; padding: 5px;
  border-radius: var(--radius-sm); color: var(--muted); line-height: 0;
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease);
}
.icon-btn:hover { background: var(--surface-2); color: var(--ink); }
.icon-btn.danger:hover { background: var(--crit-bg); color: var(--crit-ink); }
.icon-btn:disabled { opacity: .35; cursor: default; }
.icon-btn:disabled:hover { background: none; color: var(--muted); }

/* ── un operaio per volta, in Chiusura giornata ────────────────────── */
/* Rivedere è un lavoro per persona: la barra dice chi si sta guardando, a
   che punto è la fila, e chi è già stato fatto. I pallini non sono un
   ornamento — sono l'unico posto dove si vede quanto manca. */
.carosello {
  display: flex; align-items: center; gap: var(--s-2); flex-wrap: wrap;
  padding: var(--s-2) var(--s-3); margin-bottom: var(--s-4);
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--e1);
}
.carosello .chi { min-width: 0; font-size: var(--text-sm); margin-right: auto; }
.carosello .chi b { font-weight: 700; }
.carosello .chi .muted { color: var(--muted); font-size: var(--text-2xs); font-variant-numeric: tabular-nums; }
.carosello .pallini { display: flex; gap: 6px; margin-left: var(--s-2); }
.carosello .pallino {
  width: 10px; height: 10px; padding: 0; border-radius: 50%; cursor: pointer;
  border: 1px solid var(--border-strong); background: var(--surface-2);
  transition: background var(--dur) var(--ease), border-color var(--dur) var(--ease);
}
.carosello .pallino:hover { border-color: var(--accent); }
.carosello .pallino.fatto { background: var(--good); border-color: var(--good); }
/* Dove sei adesso: l'anello si vede su entrambi, già rivisto o no. */
.carosello .pallino.qui { box-shadow: 0 0 0 3px var(--accent-weak); border-color: var(--accent); }
.carosello .pallino.qui:not(.fatto) { background: var(--accent); }

/* ── forms ────────────────────────────────────────────────────────── */
label.field { display: block; margin-bottom: var(--s-3); }
label.field > span {
  display: block; font-size: var(--text-2xs); color: var(--muted);
  margin-bottom: var(--s-1); font-weight: 600;
}
input[type=text], input[type=password], input[type=date], input[type=time],
input[type=number], input[type=file], select, textarea {
  width: 100%; padding: 8px 11px; border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm); background: var(--surface); color: var(--ink);
  font-size: var(--text-sm); transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}
input::placeholder, textarea::placeholder { color: var(--faint); }
input:focus, select:focus, textarea:focus {
  border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 20%, transparent);
}
input[type=file] { padding: 6px; cursor: pointer; font-size: var(--text-xs); color: var(--muted); }
input[type=file]::file-selector-button {
  font: inherit; font-weight: 600; margin-right: var(--s-3); padding: 5px 11px; cursor: pointer;
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  background: var(--surface-2); color: var(--ink);
}
input[type=file]::file-selector-button:hover { background: var(--surface-3); }
input[type=color] { padding: 3px; height: 38px; cursor: pointer; }
textarea { resize: vertical; min-height: 64px; line-height: 1.5; }
.row { display: flex; gap: var(--s-3); flex-wrap: wrap; }
.row > * { flex: 1; min-width: 150px; }
.row.tight > * { flex: 0 0 auto; min-width: 0; }
.check { display: inline-flex; align-items: center; gap: var(--s-2); cursor: pointer; font-size: var(--text-xs); padding: var(--s-1) 0; }
.check input { width: 16px; height: 16px; flex: none; accent-color: var(--accent); cursor: pointer; }
/* Checkboxes that qualify the field above them: kept together, and given
   room before the next field so they do not read as its label. */
.checkgroup {
  display: flex; flex-wrap: wrap; gap: var(--s-2) var(--s-5);
  padding: var(--s-2) var(--s-3); margin: 0 0 var(--s-4);
  background: var(--surface-2); border-radius: var(--radius-sm);
}

/* ── surfaces ─────────────────────────────────────────────────────── */
.grid { display: grid; gap: var(--s-4); }
.grid.cols-3 { grid-template-columns: repeat(3, 1fr); }
.grid.cols-2 { grid-template-columns: repeat(2, 1fr); }
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--e1); padding: var(--s-4);
}
.card h3 { font-size: var(--text-sm); }

.section-head {
  display: flex; align-items: center; gap: var(--s-3); flex-wrap: wrap;
  margin: var(--s-6) 0 var(--s-3); min-height: 30px;
}
.section-head h3 { white-space: nowrap; }
/* Niente margine SOLO in cima alla pagina. Scritto `:first-child` e basta,
   la regola colpiva anche il primo titolo dentro un contenitore qualsiasi:
   una sezione avvolta in un div — perché si aggiorna da sola, per dire —
   perdeva lo stacco e si incollava a quella sopra. Il div era invisibile,
   lo spazio mancante no. */
#view > .section-head:first-child { margin-top: 0; }
.section-head h3 { font-size: var(--text-md); letter-spacing: -.015em; }
.section-head .count { color: var(--faint); font-weight: 500; font-variant-numeric: tabular-nums; }
/* A hint used to carry a negative top margin so it would tuck under a section
   heading. Anywhere else that margin pulled it up over whatever came before —
   it was overlapping the list above it. The tightening belongs to that one
   position, not to every hint on the page. */
.hint { color: var(--muted); font-size: var(--text-xs); margin: 0 0 var(--s-3); max-width: 76ch; }
.section-head + .hint { margin-top: calc(var(--s-2) * -1); }
.card .list + .hint, .card dl + .hint { margin-top: var(--s-4); margin-bottom: 0; }

.empty {
  text-align: center; color: var(--muted); padding: var(--s-8) var(--s-5);
  border: 1px dashed var(--border-strong); border-radius: var(--radius); font-size: var(--text-xs);
}
.empty b { display: block; color: var(--ink); font-size: var(--text-sm); margin-bottom: var(--s-1); }
.empty.error { border-color: var(--crit); background: var(--crit-bg); color: var(--crit-ink); }
.empty.error b { color: var(--crit-ink); }

/* Skeleton: navigating should not blank the screen out. */
.skeleton { display: flex; flex-direction: column; gap: var(--s-3); }
.skeleton i {
  display: block; height: 56px; border-radius: var(--radius); background: var(--surface-2);
  border: 1px solid var(--border); position: relative; overflow: hidden;
}
.skeleton i:first-child { height: 30px; width: 40%; }
.skeleton i::after {
  content: ''; position: absolute; inset: 0;
  background: linear-gradient(90deg, transparent, color-mix(in srgb, var(--surface) 70%, transparent), transparent);
  animation: sweep 1.3s var(--ease) infinite;
}
@keyframes sweep { from { transform: translateX(-100%); } to { transform: translateX(100%); } }

/* ── list rows ────────────────────────────────────────────────────── */
.list { display: flex; flex-direction: column; gap: 6px; }
.item {
  display: flex; align-items: center; gap: var(--s-3); padding: 10px var(--s-3);
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm);
  text-align: left; width: 100%; color: inherit;
}
.item .t { font-weight: 600; font-size: var(--text-xs); }
.item .d { color: var(--muted); font-size: var(--text-2xs); }
/* Una nota già letta resta leggibile, ma smette di chiedere attenzione:
   si arriva alla dashboard per quello che manca da vedere. */
.item.letta { background: var(--surface-2); }
.item.letta .t { font-weight: 500; color: var(--muted); }
.item.clickable { cursor: pointer; transition: background var(--dur) var(--ease), border-color var(--dur) var(--ease); }
.item.clickable:hover { border-color: var(--border-strong); background: var(--surface-2); }
button.item { font: inherit; }
/* A row whose text is the link, so the buttons beside it stay clickable. */
button.linkish {
  font: inherit; text-align: left; background: none; border: 0; padding: 0; color: inherit; cursor: pointer;
}
button.linkish:hover .t { color: var(--accent-ink); text-decoration: underline; text-underline-offset: 2px; }

/* ── clienti → impianti, one list ─────────────────────────────────── */
/* A site only exists inside its customer: nesting says so without repeating
   the customer's name on every row. */
.tree { gap: 2px; }
.tree .item.cliente { margin-top: var(--s-3); }
.tree .item.cliente:first-child { margin-top: 0; }
.tree .item.sub {
  /* width:auto, or the inherited width:100% plus this margin overflows the page */
  margin-left: var(--s-6); width: auto; background: var(--surface-2); border-style: dashed;
  padding-top: 7px; padding-bottom: 7px;
}
.tree .item.sub::before {
  content: ""; position: absolute; left: calc(var(--s-6) * -1 + 9px); width: 9px; height: 1px; background: var(--border-strong);
}
.tree .item.sub { position: relative; }

/* Something a person wrote, quoted back: the worker's report. A hairline
   rule, the way a quotation has been marked for centuries — not a coloured
   rail, which would read as decoration on a card. */
.quote {
  border-left: 1px solid var(--border-strong); padding: var(--s-1) var(--s-4);
  font-size: var(--text-xs); line-height: 1.55; color: var(--ink);
}

/* ── chips ────────────────────────────────────────────────────────── */
.chip {
  display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 999px;
  font-size: var(--text-3xs); font-weight: 600; line-height: 1.6; white-space: nowrap;
  background: var(--surface-3); color: var(--ink-2); border: 1px solid transparent;
}
.chip .icon { width: 12px; height: 12px; }
.chip.accent { background: var(--accent-weak); color: var(--accent-ink); }
.chip.good   { background: var(--good-bg); color: var(--good-ink); }
.chip.warn   { background: var(--warn-bg); color: var(--warn-ink); }
.chip.crit   { background: var(--crit-bg); color: var(--crit-ink); }
.chip.info   { background: var(--info-bg); color: var(--info-ink); }
.chip.quiet  { background: transparent; border-color: var(--border-strong); color: var(--muted); }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; flex: none; }
.dot.good { background: var(--good); } .dot.warn { background: var(--warn); } .dot.crit { background: var(--crit); }

/* ── figures band (dashboard / export summary) ────────────────────
   Deliberately not three cards: the numbers belong to one statement about
   one day, so they sit in one band and are separated by rules, not boxes. */
.figures {
  display: flex; flex-wrap: wrap; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--e1); overflow: hidden;
}
.figures .fig { padding: var(--s-4) var(--s-5); flex: 1 1 0; min-width: 150px; border-left: 1px solid var(--border); }
.figures .fig:first-child { border-left: none; }
.figures .fig .n {
  font-size: 23px; font-weight: 700; letter-spacing: -.02em;
  font-variant-numeric: tabular-nums; line-height: 1.1; display: flex; align-items: baseline; gap: 6px;
}
.figures .fig .n small { font-size: var(--text-sm); font-weight: 600; color: var(--muted); }
.figures .fig .l { color: var(--muted); font-size: var(--text-2xs); margin-top: 3px; }
.figures .fig.alert .n { color: var(--crit-ink); }
.figures .fig.done .n { color: var(--good-ink); }
.figures .foot {
  flex-basis: 100%; border-top: 1px solid var(--border); padding: var(--s-3) var(--s-5);
  color: var(--muted); font-size: var(--text-2xs); background: var(--surface-2);
}

/* ── worker cards ─────────────────────────────────────────────────── */
.op-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--e1); padding: var(--s-4); display: flex; flex-direction: column; gap: var(--s-3);
}
.op-card.working { border-color: color-mix(in srgb, var(--accent) 45%, var(--border)); }
.op-card .head { display: flex; align-items: center; gap: var(--s-3); }
.op-card .avatar {
  width: 36px; height: 36px; border-radius: 50%; background: var(--surface-3); color: var(--ink-2);
  display: grid; place-items: center; font-weight: 700; font-size: var(--text-2xs); flex: none;
}
.op-card.working .avatar { background: var(--accent-weak); color: var(--accent-ink); }
.op-card .nome { font-weight: 600; font-size: var(--text-sm); }
.op-card .sub { color: var(--muted); font-size: var(--text-2xs); }

.progress { height: 6px; border-radius: 999px; background: var(--surface-3); overflow: hidden; }
.progress i {
  display: block; height: 100%; width: 100%; border-radius: 999px; background: var(--accent);
  transform-origin: left; transform: scaleX(var(--p, 0)); transition: transform .45s var(--ease);
}
.progress.done i { background: var(--good); }
@media (prefers-reduced-motion: reduce) { .progress i { transition: none; } }

/* Cosa non è salito sul furgone: una banda sotto i chip, prima del giro.
   Sta accanto al percorso perché è la stessa domanda — cosa può andare storto
   oggi — e va letta prima di telefonare all'operaio. */
.carico {
  display: flex; flex-direction: column; gap: 2px;
  padding: var(--s-2); border-radius: var(--radius-sm);
  background: color-mix(in srgb, var(--warn) 8%, transparent);
  border: 1px solid color-mix(in srgb, var(--warn) 22%, transparent);
}
.carico-riga { display: flex; align-items: center; gap: var(--s-2); font-size: var(--text-xs); }

.timeline { display: flex; flex-direction: column; gap: 2px; }
.tl-row {
  display: flex; align-items: center; gap: var(--s-2); font-size: var(--text-xs);
  padding: 6px var(--s-2); border-radius: var(--radius-sm); border: 1px solid transparent;
  width: 100%; text-align: left; background: none; cursor: pointer; color: inherit;
  transition: background var(--dur) var(--ease);
}
.tl-row:hover { background: var(--surface-2); }
.tl-row.corrente { background: var(--accent-weak); border-color: color-mix(in srgb, var(--accent) 30%, transparent); }
.tl-row.corrente:hover { background: color-mix(in srgb, var(--accent-weak) 80%, var(--accent)); }
.tl-row .n {
  width: 19px; height: 19px; border-radius: 5px; background: var(--surface-3); display: grid;
  place-items: center; font-size: var(--text-3xs); font-weight: 700; color: var(--muted); flex: none;
}
.tl-row.done .n { background: var(--good-bg); color: var(--good-ink); }
.tl-row.done .grow { color: var(--muted); }

.pulse {
  width: 7px; height: 7px; border-radius: 50%; background: var(--good); flex: none;
  box-shadow: 0 0 0 0 color-mix(in srgb, var(--good) 55%, transparent); animation: pulse 2.4s infinite;
}
@keyframes pulse { 70% { box-shadow: 0 0 0 6px transparent; } 100% { box-shadow: 0 0 0 0 transparent; } }
@media (prefers-reduced-motion: reduce) { .pulse { animation: none; } }

/* ── step / workflow editor ───────────────────────────────────────── */
.group-block { border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: var(--s-3); overflow: hidden; background: var(--surface); }
.group-head {
  display: flex; align-items: center; gap: var(--s-2); padding: 9px var(--s-3);
  background: var(--surface-2); font-weight: 600; font-size: var(--text-xs);
  border-bottom: 1px solid var(--border);
}
.group-head .icon { color: var(--muted); }
.step {
  display: flex; align-items: flex-start; gap: var(--s-2); padding: 10px var(--s-3);
  border-top: 1px solid var(--border); background: var(--surface);
}
.step:first-child { border-top: none; }
.step .num {
  width: 22px; height: 22px; flex: none; border-radius: 6px; background: var(--surface-3);
  display: grid; place-items: center; font-size: var(--text-3xs); font-weight: 700;
  color: var(--muted); margin-top: 1px; font-variant-numeric: tabular-nums;
}
.step .body { flex: 1; min-width: 0; }
.step .body .t { font-weight: 600; font-size: var(--text-xs); }
.step .body .flags { display: flex; gap: var(--s-1); flex-wrap: wrap; margin-top: 6px; }
.step .acts { display: flex; gap: 1px; opacity: .72; transition: opacity var(--dur) var(--ease); }
.step:hover .acts, .step:focus-within .acts { opacity: 1; }
.flag-toggle {
  display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 999px;
  font-size: var(--text-3xs); font-weight: 600; border: 1px solid var(--border-strong);
  background: var(--surface); color: var(--muted); cursor: pointer;
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease), border-color var(--dur) var(--ease);
}
.flag-toggle .icon { width: 12px; height: 12px; }
.flag-toggle:hover { border-color: var(--faint); color: var(--ink); }
.flag-toggle.on { background: var(--accent-weak); color: var(--accent-ink); border-color: transparent; }
.flag-toggle.on.foto { background: var(--warn-bg); color: var(--warn-ink); }
.flag-toggle.on.warn { background: var(--crit-bg); color: var(--crit-ink); }
.flag-static { cursor: default; }

/* ── drag & drop ──────────────────────────────────────────────────── */
.dz { min-height: 8px; }
.dz.empty-dz {
  min-height: 44px; display: grid; place-items: center; color: var(--muted);
  font-size: var(--text-2xs); border: 1px dashed var(--border-strong);
  border-radius: var(--radius-sm); margin: var(--s-2) var(--s-3);
}
.dz.over { background: var(--accent-weak); }
.grip { cursor: grab; color: var(--faint); padding: 3px 2px; line-height: 0; touch-action: none; }
.grip:hover { color: var(--muted); }
.grip:active { cursor: grabbing; }
[draggable="true"].dragging { opacity: .4; }
.wf-root > .step { border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: 6px; }
.wf-root { padding-bottom: var(--s-1); }
.group-block .dz > .step:first-child { border-top: 1px solid var(--border); }

/* ── calendar board ───────────────────────────────────────────────── */
.cal-scroll { overflow-x: auto; overscroll-behavior-x: contain; padding-bottom: var(--s-1); }
.cal {
  display: grid; gap: 1px; background: var(--border); border: 1px solid var(--border);
  border-radius: var(--radius); overflow: hidden; min-width: 760px;
}
.cal .hcell { background: var(--surface-2); padding: var(--s-2) var(--s-3); font-size: var(--text-2xs); font-weight: 600; }
.cal .hcell small { display: block; color: var(--muted); font-weight: 500; font-variant-numeric: tabular-nums; }
.cal .hcell.oggi { background: var(--accent-weak); color: var(--accent-ink); }
.cal .hcell.oggi small { color: var(--accent-ink); opacity: .8; }
.cal .opcell {
  background: var(--surface-2); padding: var(--s-3); font-size: var(--text-xs); font-weight: 600;
  display: flex; flex-direction: column; gap: 1px;
}
.cal .opcell small { color: var(--muted); font-weight: 500; font-size: var(--text-3xs); }
.cal .cell { background: var(--surface); padding: 5px; min-height: 78px; display: flex; flex-direction: column; gap: 5px; }
.cal .cell.oggi { background: color-mix(in srgb, var(--accent-weak) 30%, var(--surface)); }
.cal .cell.over { background: var(--accent-weak); box-shadow: inset 0 0 0 2px var(--accent); }

/* The intervention type used to be a 4px colour rail down the side of every
   block. It read as decoration and fought the status. Now the type is a dot,
   exactly as in the legend below the board, and the block keeps one hairline. */
.blocco {
  border: 1px solid var(--border); background: var(--surface-2); border-radius: 6px;
  padding: 5px 7px; font-size: var(--text-2xs); cursor: grab; text-align: left; width: 100%;
  color: inherit; transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}
.blocco:hover { border-color: var(--faint); box-shadow: var(--e1); }
.blocco:active { cursor: grabbing; }
.blocco .when { display: flex; gap: 5px; align-items: center; margin-bottom: 1px; }
.blocco .when .tipo { width: 7px; height: 7px; border-radius: 50%; flex: none; }
.blocco .when .ora { color: var(--muted); font-variant-numeric: tabular-nums; font-size: var(--text-3xs); }
/* The client name gets its own line and may wrap to two: truncating it to
   "Camping ..." told the office nothing about which job this is. */
.blocco .t { font-weight: 600; line-height: 1.3; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.blocco .d { color: var(--muted); font-size: var(--text-3xs); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.blocco .bar { height: 3px; border-radius: 2px; background: var(--surface-3); margin-top: 5px; overflow: hidden; }
.blocco .bar i { display: block; height: 100%; background: var(--accent); border-radius: 2px; }
.blocco.completo { background: var(--good-bg); border-color: color-mix(in srgb, var(--good) 30%, transparent); }
.legenda { display: flex; gap: var(--s-3); flex-wrap: wrap; margin-top: var(--s-4); align-items: center; }
.legenda .chip { background: transparent; border-color: var(--border); color: var(--muted); }

/* ── gallery / detail ─────────────────────────────────────────────── */
.gallery { display: flex; gap: var(--s-2); flex-wrap: wrap; }
.gallery a { display: block; border: 1px solid var(--border); border-radius: var(--radius-sm); overflow: hidden; line-height: 0; }
.gallery a:hover { border-color: var(--accent); }
.gallery img { width: 128px; height: 128px; object-fit: cover; display: block; background: var(--surface-2); }
.thumb { width: 44px; height: 44px; object-fit: cover; border-radius: 6px; display: block; background: var(--surface-2); }
/* A signature is ink on paper: it stays on white in both themes. */
.firma-box { border: 1px solid var(--border); border-radius: var(--radius-sm); background: #fff; padding: 6px; display: inline-block; }
.firma-box img { max-width: 300px; display: block; }
.tabs { display: flex; gap: var(--s-1); border-bottom: 1px solid var(--border); margin-bottom: var(--s-4); flex-wrap: wrap; }
.tab {
  padding: 7px 12px; border: none; background: none; cursor: pointer; color: var(--muted);
  font-size: var(--text-xs); font-weight: 600; border-bottom: 2px solid transparent; margin-bottom: -1px;
  transition: color var(--dur) var(--ease), border-color var(--dur) var(--ease);
}
.tab:hover { color: var(--ink); }
.tab.active { color: var(--accent-ink); border-bottom-color: var(--accent); }

.kv { margin-top: var(--s-3); }
.kv > dt { color: var(--muted); font-size: var(--text-3xs); text-transform: uppercase; letter-spacing: .05em; font-weight: 600; }
.kv > dd { margin: 1px 0 0; font-size: var(--text-xs); }

/* ── modal ────────────────────────────────────────────────────────── */
.modal-back {
  position: fixed; inset: 0; background: color-mix(in srgb, #04161b 55%, transparent);
  backdrop-filter: blur(2px); display: grid; place-items: center; padding: var(--s-5); z-index: 50;
  animation: fade .15s var(--ease);
}
.modal {
  width: min(520px, 100%); background: var(--surface); border-radius: var(--radius-lg);
  box-shadow: var(--e3); border: 1px solid var(--border); max-height: 90dvh;
  display: flex; flex-direction: column; animation: rise .2s var(--ease);
}
@keyframes fade { from { opacity: 0; } }
@keyframes rise { from { opacity: 0; transform: translateY(8px) scale(.99); } }
@media (prefers-reduced-motion: reduce) { .modal-back, .modal { animation: none; } }
.modal .m-head { padding: var(--s-4) var(--s-5); border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: var(--s-3); }
.modal .m-head h3 { font-size: var(--text-md); flex: 1; }
.modal .m-body { padding: var(--s-5); overflow: auto; }
.modal .m-foot { padding: var(--s-3) var(--s-5); border-top: 1px solid var(--border); display: flex; gap: var(--s-2); justify-content: flex-end; }

/* ── toast ────────────────────────────────────────────────────────── */
.toast-wrap {
  position: fixed; bottom: var(--s-5); left: 50%; transform: translateX(-50%); z-index: 100;
  display: flex; flex-direction: column; gap: var(--s-2); align-items: center; pointer-events: none;
}
.toast {
  background: var(--ink); color: var(--bg); padding: 9px var(--s-4); border-radius: 999px;
  font-size: var(--text-xs); font-weight: 500; box-shadow: var(--e3);
  display: flex; align-items: center; gap: 6px; animation: pop .2s var(--ease);
}
.toast .icon { color: currentColor; }
.toast.err { background: var(--crit); color: #fff; }
@keyframes pop { from { transform: translateY(10px); opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .toast { animation: none; } }

/* ── table ────────────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
table { width: 100%; border-collapse: collapse; font-size: var(--text-xs); }
th {
  text-align: left; font-size: var(--text-3xs); text-transform: uppercase; letter-spacing: .05em;
  color: var(--muted); padding: 9px var(--s-3); border-bottom: 1px solid var(--border);
  font-weight: 600; white-space: nowrap; background: var(--surface-2);
}
td { padding: 9px var(--s-3); border-bottom: 1px solid var(--border); vertical-align: middle; }
tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--surface-2); }

/* ── responsive ───────────────────────────────────────────────────── */
.menu-btn { display: none; }
.scrim { position: fixed; inset: 0; background: rgba(4, 16, 20, .45); z-index: 39; }

@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; z-index: 40; left: 0; top: 0; width: 250px;
    transform: translateX(-100%); transition: transform .22s var(--ease); box-shadow: var(--e3);
  }
  .sidebar.open { transform: none; }
  .grid.cols-3, .grid.cols-2 { grid-template-columns: 1fr; }
  .menu-btn { display: inline-flex !important; }
  .content { padding: var(--s-4) var(--s-4) var(--s-10); }
  .topbar { padding: var(--s-3) var(--s-4); gap: var(--s-2); }
  .topbar #crumb { min-width: 0; }
  .topbar h2, .topbar .sub { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .cal .opcell { position: sticky; left: 0; z-index: 1; box-shadow: 1px 0 0 var(--border); }

  /* Dense rows are built for a desk. On a phone they wrap instead of
     pushing the page sideways: the label keeps a whole line, the state
     and the actions follow underneath. */
  .item, .tl-row { flex-wrap: wrap; }
  .item > .grow, .tl-row > .grow { flex-basis: 100%; }
  .tl-row > .grow { white-space: normal; overflow: visible; }
  .item .cluster { flex-wrap: wrap !important; }
  .figures .fig { flex-basis: 50%; min-width: 0; }
  .figures .fig:nth-child(odd) { border-left: none; }
  .figures .fig:nth-child(n + 3) { border-top: 1px solid var(--border); }
}
@media (prefers-reduced-motion: reduce) {
  .sidebar { transition: none; }
  .skeleton i::after { animation: none; }
}

/* ── print: whatever is on screen has to survive on paper ─────────── */
@media print {
  .sidebar, .topbar, .toast-wrap, .btn, .icon-btn, .scrim, .tabs, .grip, .step .acts { display: none !important; }
  .app { display: block; }
  .content, .content.wide { max-width: none; padding: 0; }
  body { background: #fff; color: #000; font-size: 11pt; }
  .card, .item, .op-card, .figures, .table-wrap { box-shadow: none; border-color: #bbb; break-inside: avoid; }
  .chip { border: 1px solid #999; background: transparent !important; color: #000 !important; }
}
