:root {
  --bg: #f4f5f7;
  --card: #ffffff;
  --ink: #111827;
  --muted: #6b7280;
  --line: #e5e7eb;
  --brand: #111827;
  --accent: #f59e0b;
  --ok: #15803d; --ok-bg: #dcfce7;
  --warn: #b45309; --warn-bg: #fef3c7;
  --bad: #b91c1c; --bad-bg: #fee2e2;
  --info: #1d4ed8; --info-bg: #dbeafe;
  --radius: 16px;
  --nav-h: 64px;
  color-scheme: light;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--ink);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
}
button, input, select, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }
a { color: inherit; }
.muted { color: var(--muted); }
code { background: #eef0f3; padding: 1px 5px; border-radius: 5px; font-size: .92em; }

/* Pulsanti */
button { cursor: pointer; border-radius: 10px; border: 1px solid transparent; padding: 9px 14px; background: none; }
button:disabled { opacity: .55; cursor: default; }
.primary { background: var(--brand); color: #fff; font-weight: 600; }
.large { width: 100%; padding: 13px; font-size: 16px; }
.ghost { border-color: var(--line); background: #fff; }
.danger { color: var(--bad); }
.link { border: none; padding: 4px 0; color: var(--info); background: none; font-size: 14px; }
.btn-sm { font-size: 13px; padding: 7px 11px; border: 1px solid var(--line); background: #fff; }
.btn-ok { background: var(--ok); border-color: var(--ok); color: #fff; }
.btn-wa { background: #1f9d55; border-color: #1f9d55; color: #fff; }
.icon-btn { width: 40px; height: 40px; padding: 0; display: grid; place-items: center; color: #e5e7eb; border: 1px solid #374151; }
.icon-btn svg, .nav svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

.logo { width: 38px; height: 38px; border-radius: 10px; display: grid; place-items: center; background: #1f2937; color: var(--accent); font-weight: 800; flex: none; }

/* Accesso */
.accesso-wrap { min-height: 100dvh; display: grid; place-items: center; padding: 24px 16px; background: linear-gradient(160deg, #111827 0%, #1f2937 55%, #f4f5f7 55.1%); }
.accesso-card { width: 100%; max-width: 400px; background: #fff; border-radius: 20px; padding: 26px 22px; box-shadow: 0 20px 50px rgba(0,0,0,.18); display: grid; gap: 12px; }
.accesso-card h1 { margin: 4px 0 2px; font-size: 22px; }
.accesso-logo { display: flex; align-items: center; gap: 10px; }
.accesso-logo strong { display: block; font-size: 16px; }
.accesso-logo small { display: block; font-size: 10px; letter-spacing: .14em; color: var(--muted); }
.accesso-form { display: grid; gap: 12px; }
.accesso-link { display: flex; justify-content: space-between; flex-wrap: wrap; gap: 6px; }
.oppure { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 13px; }
.oppure::before, .oppure::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.google { display: flex; align-items: center; justify-content: center; gap: 10px; font-weight: 600; }
.errore { color: var(--bad); margin: 0; font-size: 14px; }
.ok { color: var(--ok); margin: 0; font-size: 14px; }

/* Struttura area */
.area { min-height: 100dvh; }
.top {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px; background: var(--brand); color: #fff;
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand strong { display: block; font-size: 18px; line-height: 1.1; }
.brand small { display: block; font-size: 10px; letter-spacing: .14em; color: #9ca3af; }
.top-actions { display: flex; gap: 6px; }

.nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: grid; grid-template-columns: repeat(6, 1fr);
  background: #fff; border-top: 1px solid var(--line);
  padding: 4px 2px calc(4px + env(safe-area-inset-bottom));
}
.nav a { display: grid; justify-items: center; gap: 2px; padding: 6px 0; text-decoration: none; color: var(--muted); font-size: 10.5px; border-radius: 10px; }
.nav a.on { color: var(--ink); font-weight: 700; }
.nav a.on svg { stroke: var(--accent); }
.nav-brand, .nav-foot { display: none; }

.contenuto { max-width: 1200px; margin: 0 auto; padding: 16px 16px calc(var(--nav-h) + 24px + env(safe-area-inset-bottom)); }
.sezione-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin: 6px 0 12px; flex-wrap: wrap; }
.sezione-head h2 { margin: 0; font-size: 20px; }
.sezione-head .azioni { display: flex; gap: 8px; flex-wrap: wrap; }
h3.blocco { margin: 22px 0 10px; font-size: 15px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }

/* Card e griglie */
.card { background: var(--card); border-radius: var(--radius); box-shadow: 0 1px 2px rgba(0,0,0,.05), 0 6px 20px rgba(0,0,0,.04); }
.pad { padding: 14px; }
.griglia { display: grid; gap: 12px; }
.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.stat { background: var(--card); border-radius: 14px; padding: 12px 14px; box-shadow: 0 1px 2px rgba(0,0,0,.05); text-decoration: none; display: block; }
.stat small { display: block; color: var(--muted); font-size: 12px; }
.stat strong { display: block; font-size: 22px; font-variant-numeric: tabular-nums; line-height: 1.25; }
.stat .sub { font-size: 12px; color: var(--muted); }
.stat.ok strong { color: var(--ok); } .stat.warn strong { color: var(--warn); } .stat.bad strong { color: var(--bad); }

.riquadri { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.riquadro { display: grid; gap: 6px; padding: 14px; text-decoration: none; }
.riquadro svg { width: 26px; height: 26px; fill: none; stroke: var(--ink); stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.riquadro strong { font-size: 15px; }
.riquadro span { font-size: 12.5px; color: var(--muted); }

.barra { display: grid; gap: 10px; margin-bottom: 14px; }
.barra input[type=search], .barra select { width: 100%; padding: 11px 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--card); }
.filtri { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; }
.filtri::-webkit-scrollbar { display: none; }
.filtri button { white-space: nowrap; border: 1px solid var(--line); background: var(--card); border-radius: 999px; padding: 7px 13px; font-size: 14px; }
.filtri button.on { background: var(--brand); border-color: var(--brand); color: #fff; }

.lista { display: grid; gap: 12px; }
.voce { padding: 14px; display: grid; gap: 10px; border-left: 5px solid var(--line); }
.voce.ok { border-left-color: #16a34a; } .voce.warn { border-left-color: #f59e0b; } .voce.bad { border-left-color: #dc2626; } .voce.off { border-left-color: #9ca3af; opacity: .8; }
.voce-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.voce-head h4 { margin: 0; font-size: 16px; line-height: 1.25; }
.voce-head .sotto { color: var(--muted); font-size: 13px; }
.chip { flex: none; font-size: 12px; font-weight: 600; padding: 4px 10px; border-radius: 999px; background: var(--ok-bg); color: var(--ok); white-space: nowrap; }
.chip.warn { background: var(--warn-bg); color: var(--warn); } .chip.bad { background: var(--bad-bg); color: var(--bad); }
.chip.info { background: var(--info-bg); color: var(--info); } .chip.off { background: #eef0f3; color: #4b5563; }
.info { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 12px; font-size: 13px; }
.info span { color: var(--muted); display: block; font-size: 11px; text-transform: uppercase; letter-spacing: .05em; }
.info b { font-weight: 600; word-break: break-word; }
.azioni-riga { display: flex; flex-wrap: wrap; gap: 6px; }
.vuoto { text-align: center; color: var(--muted); padding: 28px 10px; }

/* Righe compatte (scadenze, pagamenti, storico) */
.righe { display: grid; }
.riga { display: flex; align-items: center; gap: 10px; padding: 11px 14px; border-top: 1px solid var(--line); }
.riga:first-child { border-top: none; }
.riga .cosa { flex: 1; min-width: 0; }
.riga .cosa b { display: block; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.riga .cosa small { color: var(--muted); font-size: 12.5px; }
.riga .importo { font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.riga .x { border: none; color: var(--muted); padding: 4px 8px; font-size: 18px; }
.punto { width: 10px; height: 10px; border-radius: 50%; flex: none; background: #9ca3af; }
.punto.ok { background: #16a34a; } .punto.bad { background: #dc2626; } .punto.warn { background: #f59e0b; }

/* Grafico incassi */
.grafico { display: grid; grid-template-columns: repeat(12, 1fr); gap: 6px; align-items: end; height: 160px; padding: 14px 12px 0; }
.barra-mese { display: grid; align-items: end; height: 100%; position: relative; }
.barra-mese i { display: block; background: #111827; border-radius: 6px 6px 0 0; min-height: 2px; }
.barra-mese.oggi i { background: var(--accent); }
.mesi { display: grid; grid-template-columns: repeat(12, 1fr); gap: 6px; padding: 6px 12px 12px; font-size: 11px; color: var(--muted); text-align: center; }

/* Storico (timeline) */
.timeline { display: grid; }
.evento { display: grid; grid-template-columns: 14px 1fr; gap: 10px; padding: 10px 14px; border-top: 1px solid var(--line); }
.evento:first-child { border-top: none; }
.evento .pallino { width: 10px; height: 10px; border-radius: 50%; margin-top: 5px; background: #9ca3af; }
.evento.pagamento .pallino { background: #16a34a; } .evento.licenza .pallino { background: #1d4ed8; }
.evento.messaggio .pallino { background: #1f9d55; } .evento.contratto .pallino { background: #f59e0b; } .evento.blocco .pallino { background: #dc2626; }
.evento b { font-size: 14px; } .evento small { display: block; color: var(--muted); font-size: 12.5px; }

/* Schede cliente */
.tabs { display: flex; gap: 6px; overflow-x: auto; margin: 4px 0 12px; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tabs button { white-space: nowrap; border: 1px solid var(--line); background: #fff; border-radius: 999px; padding: 7px 13px; font-size: 14px; }
.tabs button.on { background: var(--brand); border-color: var(--brand); color: #fff; }

/* Messaggi */
.anteprima { white-space: pre-wrap; background: #e7f6ec; border-radius: 12px 12px 12px 2px; padding: 12px 14px; font-size: 14.5px; }

/* Finestre */
dialog { border: none; padding: 0; border-radius: 18px; width: min(580px, calc(100vw - 24px)); max-height: calc(100dvh - 24px); background: var(--card); color: var(--ink); box-shadow: 0 30px 80px rgba(0,0,0,.3); }
dialog::backdrop { background: rgba(17,24,39,.55); }
dialog > form { display: flex; flex-direction: column; max-height: calc(100dvh - 24px); }
.dlg-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 18px 8px; }
.dlg-head h2 { margin: 0; font-size: 18px; }
.x { font-size: 24px; line-height: 1; padding: 4px 10px; border: none; }
.dlg-body { padding: 4px 18px 12px; overflow-y: auto; display: grid; gap: 12px; }
.dlg-foot { display: flex; gap: 8px; align-items: center; padding: 12px 18px 16px; border-top: 1px solid var(--line); }
.spacer { flex: 1; }
fieldset { border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px 12px; margin: 0; display: grid; gap: 10px; }
legend { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); padding: 0 4px; }
label { display: grid; align-content: start; gap: 4px; font-size: 13px; font-weight: 600; }
label small { font-weight: 400; color: var(--muted); }
label.check { display: flex; align-items: center; gap: 8px; font-weight: 500; }
label.check input { width: auto; }
input, select, textarea { width: 100%; padding: 10px 12px; border: 1px solid #d1d5db; border-radius: 10px; background: #fff; font-weight: 400; }
input:focus, select:focus, textarea:focus { outline: 2px solid #93c5fd; outline-offset: 0; border-color: #60a5fa; }
.due { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
pre { white-space: pre-wrap; word-break: break-all; background: #0f172a; color: #e2e8f0; padding: 12px; border-radius: 10px; font-size: 13px; margin: 0; }
.nota { color: var(--muted); font-size: 13px; margin: 0; }

.toast { position: fixed; left: 50%; bottom: calc(var(--nav-h) + 18px + env(safe-area-inset-bottom)); transform: translate(-50%, 30px); background: #111827; color: #fff; padding: 11px 16px; border-radius: 12px; font-size: 14px; opacity: 0; pointer-events: none; transition: .2s; max-width: calc(100vw - 32px); z-index: 60; }
.toast.on { opacity: 1; transform: translate(-50%, 0); }

/* PC: menu laterale */
@media (min-width: 900px) {
  .area { display: grid; grid-template-columns: 240px 1fr; grid-template-rows: auto 1fr; }
  .nav {
    position: sticky; top: 0; grid-row: 1 / 3; height: 100dvh; display: flex; flex-direction: column; gap: 4px;
    border-top: none; border-right: 1px solid var(--line); padding: 16px 12px; background: #fff;
  }
  .nav-brand { display: flex; align-items: center; gap: 10px; padding: 4px 6px 16px; }
  .nav-brand strong { display: block; font-size: 15px; }
  .nav-brand small { display: block; font-size: 10px; letter-spacing: .14em; color: var(--muted); }
  .nav a { display: flex; align-items: center; gap: 12px; padding: 10px 12px; font-size: 15px; justify-items: start; }
  .nav a:hover { background: #f3f4f6; }
  .nav a.on { background: #f3f4f6; }
  .nav-foot { display: grid; gap: 6px; margin-top: auto; }
  .top { grid-column: 2; background: var(--bg); color: var(--ink); padding: 18px 28px 6px; position: static; }
  .top .logo, .top .brand small, .top-actions { display: none; }
  .brand strong { font-size: 24px; }
  .contenuto { grid-column: 2; width: 100%; padding: 10px 28px 40px; margin: 0; }
  .stats { grid-template-columns: repeat(4, 1fr); }
  .riquadri { grid-template-columns: repeat(5, 1fr); }
  .barra { grid-template-columns: 1fr auto; align-items: center; }
  .lista { grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); }
  .due-col { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; align-items: start; }
  .toast { bottom: 24px; }
}
@media (max-width: 380px) {
  .due, .info { grid-template-columns: 1fr; }
}
/* Il titolo della sezione è già nella barra in alto */
.sezione-head > h2 { display: none; }
.sezione-head:has(> h2) { justify-content: flex-end; }
.riga .cosa small { display: block; overflow-wrap: anywhere; }
@media (max-width: 520px) { .riga .chip { font-size: 11px; padding: 3px 8px; white-space: normal; text-align: center; max-width: 110px; } }
