:root {
  --bg: #f4f6f8;
  --card: #ffffff;
  --ink: #1f2933;
  --muted: #647382;
  --line: #e2e8f0;
  --brand: #1d4ed8;
  --brand-d: #1e3aa8;
  --done: #15803d;
  --accent: #2563eb;
  --gold: #b7791f;    /* giallo scuro: etichette dei form */
  --magenta: #c2185b; /* rosso magenta: titoli, accenti card, focus */
}
* { box-sizing: border-box; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}
header.topbar {
  display: flex; align-items: center; justify-content: space-between;
  background: #fff; color: var(--ink); padding: 10px 22px;
  border-bottom: 1px solid var(--line);
}
header.topbar .brand { display: flex; align-items: center; gap: 12px; }
header.topbar .logo { height: 36px; width: auto; display: block; }
header.topbar .brandtitle {
  font-size: 15px; font-weight: 600; color: var(--brand);
  border-left: 1px solid var(--line); padding-left: 12px;
}
header.topbar .ver { font-size: 11px; color: var(--muted); background: var(--bg); border: 1px solid var(--line); border-radius: 99px; padding: 1px 8px; align-self: center; }
header.topbar .who { font-size: 16px; color: var(--muted); display: flex; gap: 14px; align-items: center; }
header.topbar .who button.ghost { font-size: 16px; padding: 8px 16px; }
main { max-width: 1280px; margin: 24px auto; padding: 0 18px; }
h2 { color: var(--magenta); }
button {
  font: inherit; border: 0; border-radius: 8px; padding: 8px 14px;
  background: var(--brand); color: #fff; cursor: pointer;
}
button.secondary { background: #fff; color: var(--ink); border: 1px solid var(--line); }
button.ghost { background: transparent; color: var(--brand); border: 1px solid var(--line); }
.dash-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 14px; }
button.dash-open { display: flex; align-items: center; gap: 12px; justify-content: flex-start; text-align: left; padding: 20px 22px; font-size: 16px; font-weight: 700; border-radius: 12px; }
button.dash-open .dash-ico { font-size: 24px; line-height: 1; }
button:hover { filter: brightness(.96); }
button:disabled { opacity: .5; cursor: default; }
.card { background: var(--card); border: 1px solid var(--line); border-top: 4px solid var(--magenta); border-radius: 12px; padding: 18px; margin-bottom: 16px; }
.row { display: flex; gap: 14px; align-items: center; }
.between { justify-content: space-between; }
.muted { color: var(--muted); }
.center { text-align: center; }
a.link { color: var(--accent); cursor: pointer; text-decoration: none; }
input, select, textarea {
  font: inherit; padding: 8px 10px; border: 1px solid var(--line);
  border-radius: 8px; width: 100%; font-weight: 400;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--magenta); box-shadow: 0 0 0 3px rgba(194, 24, 91, .15); }
textarea { resize: vertical; min-height: 64px; line-height: 1.4; }
label { display: block; font-size: 13px; font-weight: 700; color: var(--gold); margin: 10px 0 4px; }
table.cases { width: 100%; border-collapse: collapse; }
table.cases th, table.cases td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--line); }
table.cases tr:hover td { background: #f9fafb; }
table.cases tr.rowdone td { opacity: .6; }
table.cases th.nowrap, table.cases td.nowrap { white-space: nowrap; }
.progress { background: var(--line); border-radius: 99px; height: 8px; width: 140px; overflow: hidden; }
.progress > i { display: block; height: 100%; background: var(--brand); }
.badge { font-size: 12px; padding: 2px 8px; border-radius: 99px; background: #eef2f7; color: var(--muted); }
.badge.open { background: #fef9c3; color: #854d0e; }
.badge.completed { background: #dcfce7; color: var(--done); }
.badge.act { background: #fee2e2; color: #b91c1c; font-weight: 600; }
.act-warn { color: #b91c1c; font-size: 12px; font-weight: 600; margin-top: 3px; }
.section-title { margin: 22px 0 8px; font-size: 15px; font-weight: 700; color: var(--brand-d); }
.task { display: flex; gap: 12px; align-items: flex-start; padding: 10px 8px; border-bottom: 1px solid var(--line); }
.task input[type=checkbox] { width: 20px; height: 20px; margin-top: 2px; flex: 0 0 auto; }
.task .cosa { font-weight: 500; }
.task.done .cosa { text-decoration: line-through; color: var(--muted); }
.task .meta { font-size: 12px; color: var(--muted); margin-top: 2px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.toast { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); background: #1f2933; color: #fff; padding: 10px 16px; border-radius: 8px; opacity: 0; transition: opacity .2s; }
.toast.show { opacity: .95; }
.toast.err { background: #b91c1c; }
.hidden { display: none; }

/* ===== Mobile / smartphone (<= 640px) ===== */
@media (max-width: 640px) {
  body { font-size: 16px; overflow-x: hidden; } /* font: evita lo zoom iOS sui campi */
  main { margin: 14px auto; padding: 0 12px; }
  h2 { font-size: 19px; }

  /* Intestazioni "titolo + pulsanti": impilate in colonna (evita overflow flex). */
  .row.between { flex-direction: column; align-items: stretch; gap: 10px; }
  .row.between h2 { font-size: 18px; }

  /* Topbar: il logo resta in alto, la navigazione va a capo su una riga propria. */
  header.topbar { flex-wrap: wrap; padding: 8px 12px; gap: 8px; }
  header.topbar .brandtitle { padding-left: 8px; font-size: 14px; }
  header.topbar .who { width: 100%; flex-wrap: wrap; gap: 6px; font-size: 14px; justify-content: flex-start; }
  header.topbar .who button.ghost { font-size: 14px; padding: 6px 10px; }
  header.topbar .who span { width: 100%; font-size: 13px; } /* nome·ruolo su riga propria */

  /* Le righe flettono a capo invece di sforare in orizzontale. */
  .row { flex-wrap: wrap; }
  .grid2 { grid-template-columns: 1fr; } /* form a colonna singola */

  /* Toast a tutta larghezza, leggibile. */
  .toast { left: 12px; right: 12px; bottom: 12px; transform: none; text-align: center; }

  /* Tabella pratiche → schede impilate (ogni riga diventa una card etichettata). */
  table.cases, table.cases tbody, table.cases tr, table.cases td { display: block; width: 100%; }
  table.cases thead { display: none; }
  table.cases tr { border: 1px solid var(--line); border-radius: 10px; margin-bottom: 12px; padding: 4px 6px; }
  table.cases tr:hover td { background: transparent; }
  table.cases td { border: 0; padding: 7px 8px; display: flex; align-items: center; justify-content: space-between; gap: 12px; text-align: right; min-width: 0; }
  table.cases td > *:last-child { min-width: 0; overflow-wrap: anywhere; } /* valori lunghi a capo */
  table.cases td::before {
    content: attr(data-label); color: var(--muted); font-size: 12px; font-weight: 600;
    text-align: left; flex: 0 0 auto;
  }
  table.cases td[data-label=""] { justify-content: flex-end; }
  table.cases td[data-label=""]::before { content: none; }
  table.cases td .progress { width: 100px; } /* barra avanzamento compatta */

  /* Task del dettaglio: pulsanti azione vanno a capo invece di stringere il testo. */
  .task { flex-wrap: wrap; }
  .task .undo-action, .task .del-task { margin-top: 6px; }
}
