/* Stile coordinato con il sito Ecolit Ritiri (viraservice.it): Nunito, verdi brillanti, pillole e card arrotondate */
:root {
  --bg: #FBFDF8;
  --surface: #FFFFFF;
  --surface-2: #F5FBEF;
  --border: #EEF2EA;
  --border-2: #D5D9D2;
  --text: #222222;
  --muted: #6B6F6A;
  --green: #6AC610;
  --green-dk: #4E9A0A;
  --green-dd: #3E7A08;
  --mint: #EAF8DA;
  --band: linear-gradient(135deg, #5DB80C 0%, #7ED321 55%, #A6E24A 100%);
  --on-green: #FFFFFF;
  --on-green-soft: #F4FFE8;
  --hl: #FFF6C9;
  --red: #C0392B; --red-soft: #FDECEA; --red-line: #F5C6C0;
  --amber: #B87A00; --amber-soft: #FFF6DC; --amber-line: #F3DC9B;
  --blue: #1F6FB2; --blue-soft: #E6F1FA; --blue-line: #BFDBF0;
  --violet: #7A3FC4; --violet-soft: #F2EBFC; --violet-line: #DCCBF5;
  --foot: #1F2321;
  --radius: 20px;
  --f-head: "Nunito", "Trebuchet MS", Arial, sans-serif;
  --f-body: "Nunito", system-ui, Arial, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { font-family: var(--f-body); font-size: 15px; line-height: 1.5; background: var(--bg); color: var(--text); -webkit-font-smoothing: antialiased; }
a { color: var(--green-dk); }
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3 { font-family: var(--f-head); }
.loading { padding: 40px; text-align: center; color: var(--muted); }
.wrap { width: 100%; max-width: 1180px; margin: 0 auto; padding-left: max(24px, env(safe-area-inset-left, 0px)); padding-right: max(24px, env(safe-area-inset-right, 0px)); }

/* Testata con loghi */
.top { background: var(--surface); border-bottom: 1px solid var(--border); }
.top-in { display: flex; align-items: center; gap: 18px; padding-block: 10px; }
.logo img { height: 48px; width: auto; display: block; }
.top-tit { display: flex; flex-direction: column; line-height: 1.2; border-left: 2px solid var(--border); padding-left: 16px; }
.top-tit b { font-family: var(--f-head); font-weight: 900; font-size: 16px; }
.top-tit span { font-size: 13px; color: var(--muted); }
.top-r { margin-left: auto; display: flex; align-items: center; gap: 18px; }
.who { display: flex; align-items: center; gap: 10px; font-size: 14px; font-weight: 700; }
.who button { border: 2px solid var(--border-2); background: var(--surface); border-radius: 999px; padding: 4px 12px; font-weight: 800; font-size: 13px; cursor: pointer; }
.who button:hover { border-color: var(--green-dk); color: var(--green-dk); }
.vira { height: 44px; width: auto; display: block; }

/* Fascia verde con menu e titolo */
.band { background: var(--band); color: var(--on-green); padding-block: 16px 26px; border-radius: 0 0 32px 32px; }
.nav { display: flex; gap: 8px; flex-wrap: wrap; }
.nav a { display: inline-flex; align-items: center; gap: 7px; padding: 8px 15px; border-radius: 999px; background: var(--surface); color: var(--green-dd); text-decoration: none; font-weight: 800; font-size: 14px; }
.nav a:hover { background: var(--mint); }
.nav a.on { background: var(--green-dd); color: var(--on-green); }
.nav svg { width: 17px; height: 17px; flex: none; }
.nav .count { background: var(--red); color: var(--on-green); font-size: 12px; font-weight: 900; padding: 0 7px; border-radius: 99px; line-height: 19px; }
#band-head { margin-top: 22px; }
#band-head:empty { display: none; }
.head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.head h1 { margin: 0; font-size: 34px; font-weight: 900; line-height: 1.1; letter-spacing: -.01em; text-wrap: balance; }
.head p { margin: 6px 0 0; color: var(--on-green-soft); font-size: 16px; }
.band .head h1 { color: var(--on-green); }
.band .tag { background: var(--surface); border-color: var(--surface); color: var(--green-dd); }
.band .btn { background: var(--surface); border-color: var(--surface); color: var(--green-dd); }
.band .btn:hover { background: var(--mint); }
.band .btn.primary { background: var(--green-dd); border-color: var(--green-dd); color: var(--on-green); }
.band .btn.danger { color: var(--red); }
.back { display: inline-flex; gap: 6px; align-items: center; color: var(--on-green-soft); text-decoration: none; font-size: 14px; font-weight: 700; margin-bottom: 6px; }
.hl { color: var(--hl); }
.main { padding-block: 24px 60px; min-width: 0; }

/* Bottoni e form */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 2px solid var(--border-2); background: var(--surface); padding: 8px 16px; border-radius: 999px; font-weight: 800; font-size: 14px; cursor: pointer; text-decoration: none; color: var(--text); white-space: nowrap; font-family: var(--f-head); }
.btn:hover { border-color: var(--green-dk); }
.btn.primary { background: var(--green-dk); border-color: var(--green-dk); color: var(--on-green); }
.btn.primary:hover { background: var(--green-dd); border-color: var(--green-dd); }
.btn.danger { color: var(--red); }
.btn.small { padding: 5px 12px; font-size: 13px; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--surface-2); }
.btn:disabled { opacity: .5; cursor: default; }
.btn svg { width: 16px; height: 16px; }
.btn:focus-visible, .chip:focus-visible, .nav a:focus-visible { outline: 3px solid var(--green); outline-offset: 2px; }
.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.field > span { font-size: 13px; font-weight: 800; }
.field small { color: var(--muted); font-size: 12px; }
.input, select.input, textarea.input { width: 100%; border: 2px solid var(--border); background: var(--surface); border-radius: 14px; padding: 9px 12px; outline: none; }
.input:focus { border-color: var(--green); box-shadow: 0 0 0 4px var(--mint); }
textarea.input { min-height: 80px; resize: vertical; }
.check { display: flex; gap: 9px; align-items: flex-start; font-size: 14px; cursor: pointer; padding: 4px 0; font-weight: 600; }
.check input { width: 18px; height: 18px; margin: 2px 0 0; accent-color: var(--green-dk); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
.full { grid-column: 1 / -1; }
.hint { background: var(--mint); color: var(--green-dd); border-radius: 14px; padding: 10px 14px; font-size: 13px; }

/* Card */
.card { background: var(--surface); border: 2px solid var(--border); border-radius: var(--radius); }
.card-h { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 14px 20px; border-bottom: 2px solid var(--border); }
.card-h h2 { margin: 0; font-size: 17px; font-weight: 900; }
.card-b { padding: 16px 20px; }
.stack { display: flex; flex-direction: column; gap: 18px; }
.empty { padding: 28px 18px; text-align: center; color: var(--muted); }
.sub { color: var(--muted); font-size: 13px; }

/* KPI */
.kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 20px; }
.kpi { background: var(--surface); border: 2px solid var(--border); border-radius: var(--radius); padding: 14px 18px; }
.kpi b { display: block; font-family: var(--f-head); font-size: 32px; font-weight: 900; line-height: 1.1; font-variant-numeric: tabular-nums; }
.kpi span { color: var(--muted); font-size: 13px; font-weight: 700; }
.kpi.red { border-color: var(--red-line); } .kpi.red b { color: var(--red); }
.kpi.amber { border-color: var(--amber-line); background: var(--amber-soft); } .kpi.amber b { color: var(--amber); }
.kpi.green b { color: var(--green-dk); }

.banner { display: flex; gap: 10px; align-items: flex-start; border-radius: 16px; padding: 12px 16px; margin-bottom: 16px; font-size: 14px; }
.banner.warn { background: var(--amber-soft); color: #6B4700; border: 2px solid var(--amber-line); }
.banner.err { background: var(--red-soft); color: #7A271A; border: 2px solid var(--red-line); }
.banner a { color: inherit; font-weight: 800; }

/* Filtri */
.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 14px; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { border: 2px solid var(--border); background: var(--surface); padding: 5px 13px; border-radius: 999px; font-size: 13px; font-weight: 800; cursor: pointer; color: var(--muted); }
.chip:hover { border-color: var(--green); color: var(--green-dk); }
.chip.on { background: var(--green-dk); border-color: var(--green-dk); color: var(--on-green); }
.toolbar .spacer { flex: 1; }
.toolbar select.input { width: auto; border-radius: 999px; font-weight: 700; }
.search { position: relative; flex: 1; min-width: 220px; max-width: 460px; }
.search svg { position: absolute; left: 13px; top: 50%; transform: translateY(-50%); width: 17px; color: var(--muted); }
.search .input { padding-left: 38px; border-radius: 999px; }

/* Agenda */
.group-t { font-family: var(--f-head); font-size: 12px; font-weight: 900; text-transform: uppercase; letter-spacing: .08em; color: var(--green-dk); margin: 22px 0 8px 4px; }
.group-t:first-child { margin-top: 0; }
.ev { display: grid; grid-template-columns: 64px 1fr auto; gap: 14px; align-items: center; padding: 12px 18px 12px 12px; background: var(--surface); border: 2px solid var(--border); border-radius: var(--radius); margin-bottom: 8px; }
.ev.late { border-color: var(--red-line); background: var(--red-soft); }
.date { text-align: center; line-height: 1.1; border-radius: 14px; padding: 8px 0; background: var(--mint); color: var(--green-dd); }
.ev.scadenza .date { background: var(--blue-soft); color: var(--blue); }
.ev.offerta .date { background: var(--violet-soft); color: var(--violet); }
.ev.late .date { background: var(--surface); color: var(--red); }
.date b { display: block; font-family: var(--f-head); font-size: 24px; font-weight: 900; }
.date span { font-size: 11px; text-transform: uppercase; font-weight: 800; letter-spacing: .04em; }
.ev-t { min-width: 0; }
.ev-t .cli { font-weight: 900; font-family: var(--f-head); text-decoration: none; color: var(--text); font-size: 16px; }
.ev-t .cli:hover { color: var(--green-dk); }
.ev-t .what { margin-top: 1px; }
.ev-t .det { color: var(--muted); font-size: 13px; }
.ev-tags { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 7px; }
.ev-a { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.tag { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; font-weight: 800; padding: 2px 9px; border-radius: 99px; background: var(--surface-2); color: var(--muted); border: 1px solid var(--border); white-space: nowrap; }
.tag.red { background: var(--red-soft); color: var(--red); border-color: var(--red-line); }
.tag.amber { background: var(--amber-soft); color: var(--amber); border-color: var(--amber-line); }
.tag.green { background: var(--mint); color: var(--green-dd); border-color: #CDEBB0; }
.tag.blue { background: var(--blue-soft); color: var(--blue); border-color: var(--blue-line); }
.tag.violet { background: var(--violet-soft); color: var(--violet); border-color: var(--violet-line); }

/* Tabella clienti */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; }
.table th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); padding: 12px 18px; border-bottom: 2px solid var(--border); font-weight: 900; }
.table td { padding: 12px 18px; border-bottom: 1px solid var(--border); vertical-align: top; font-variant-numeric: tabular-nums; }
.table tr:last-child td { border-bottom: 0; }
.table tbody tr { cursor: pointer; }
.table tbody tr:hover td { background: var(--surface-2); }

/* Scheda cliente */
.info { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 12px 20px; }
.info div span { display: block; font-size: 12px; color: var(--muted); font-weight: 800; }
.info div b { font-weight: 600; word-break: break-word; }
.cols { display: grid; grid-template-columns: 1.35fr 1fr; gap: 18px; align-items: start; }
.item { padding: 14px 20px; border-bottom: 1px solid var(--border); }
.item:last-child { border-bottom: 0; }
.item-h { display: flex; justify-content: space-between; gap: 10px; align-items: flex-start; }
.item-h b { font-size: 15px; font-weight: 800; }
.item .det { color: var(--muted); font-size: 13px; margin-top: 2px; }
.item .acts { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 10px; }
.item.off { opacity: .6; }
.note { margin-top: 14px; white-space: pre-wrap; font-size: 14px; background: var(--surface-2); border-radius: 14px; padding: 10px 14px; }
.timeline { list-style: none; margin: 0; padding: 6px 20px 14px; }
.timeline li { position: relative; padding: 8px 0 8px 22px; font-size: 14px; border-left: 2px solid var(--border); margin-left: 5px; }
.timeline li::before { content: ""; position: absolute; left: -8px; top: 12px; width: 14px; height: 14px; border-radius: 50%; background: var(--surface); border: 3px solid var(--border-2); }
.timeline li.ritiro::before { border-color: var(--green); } .timeline li.contratto::before, .timeline li.convenzione::before { border-color: var(--blue); }
.timeline li.offerta::before { border-color: var(--violet); } .timeline li.avviso::before { border-color: var(--amber); }
.timeline time { display: block; font-size: 12px; color: var(--muted); font-weight: 800; }

/* Sezioni dei form */
.form-tit { display: flex; flex-direction: column; gap: 2px; border-top: 2px solid var(--border); padding-top: 14px; margin-top: 4px; }
.form-tit b { font-family: var(--f-head); font-weight: 900; font-size: 16px; }
.form-tit small { color: var(--muted); font-size: 12px; }
.srv { display: flex; flex-wrap: wrap; gap: 4px 16px; margin-top: 8px; font-size: 13px; background: var(--surface-2); border-radius: 12px; padding: 8px 12px; }
.srv b { font-weight: 800; color: var(--green-dd); margin-right: 3px; }

/* Programma ritiri */
.prog-bar { display: flex; justify-content: space-between; align-items: flex-end; gap: 14px; flex-wrap: wrap; padding: 14px 18px; margin-bottom: 18px; }
.prog-date { display: flex; gap: 10px; }
.prog-date .input { width: auto; }
.ps { background: var(--surface); border: 2px solid var(--border); border-radius: var(--radius); padding: 14px 18px; margin-bottom: 10px; break-inside: avoid; }
.ps.late { border-color: var(--red-line); background: var(--red-soft); }
.group-t.vuoto { color: var(--muted); font-weight: 800; margin: 12px 0 4px 4px; }
.ps.empty-day { color: var(--muted); padding: 10px 18px; border-style: dashed; }
.ps-h { display: flex; justify-content: space-between; gap: 12px; align-items: flex-start; flex-wrap: wrap; }
.ps .cli { font-weight: 900; font-family: var(--f-head); font-size: 17px; text-decoration: none; color: var(--text); }
.ps .what { margin-top: 1px; }
.ps .det { color: var(--muted); font-size: 13px; margin-top: 8px; white-space: pre-wrap; }
.ps-tags { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.pgrid { display: grid; grid-template-columns: 2fr 1.4fr 1.6fr 1fr 1fr; gap: 10px; margin-top: 12px; }
.pd { background: var(--surface-2); border-radius: 12px; padding: 8px 12px; min-width: 0; }
.pd span { display: block; font-size: 11px; font-weight: 800; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.pd b { font-weight: 700; font-size: 14px; word-break: break-word; }
.pd.si { background: var(--mint); } .pd.si b { color: var(--green-dd); font-weight: 900; }
.print-only { display: none; }

/* Convenzioni per comune (aziende) */
.toolbar[hidden], .item[hidden], .sub[hidden] { display: none; }
.conv-g .conv-cli { font-weight: 900; font-family: var(--f-head); font-size: 16px; text-decoration: none; color: var(--text); }
.conv-g .conv-cli:hover { color: var(--green-dk); }
.conv-r { display: flex; justify-content: space-between; gap: 10px; align-items: flex-start; margin-top: 8px; padding: 8px 12px; background: var(--surface-2); border-radius: 12px; font-size: 14px; }
.filtro-com { padding: 0 20px 12px; border-bottom: 1px solid var(--border); }
.filtro-com .search { max-width: none; }
.filtro-com #filtro-vuoto { margin-top: 10px; }

/* Foglio stampabile della scheda cliente (Stampa / PDF) */
#print-root { display: none; }
@media (max-width: 1000px) { .pgrid { grid-template-columns: 1fr 1fr; } }
@media print {
  @page { margin: 12mm; }
  body { background: #fff; font-size: 12px; }
  .top, .band, .mobile-bar, .no-print, #toast-root { display: none !important; }
  .print-only { display: block; }
  .print-title { font-size: 16px; margin-bottom: 10px; }
  .main { padding: 0; }
  .wrap { max-width: none; padding: 0; }
  .kpis { grid-template-columns: repeat(4, 1fr); }
  .kpi, .ps { border-width: 1px; }
  .pgrid { grid-template-columns: 2fr 1.4fr 1.6fr 1fr 1fr; }
  body.stampa-scheda #app, body.stampa-scheda #modal-root, body.stampa-scheda #toast-root { display: none !important; }
  body.stampa-scheda #print-root { display: block; color: #111; background: #fff; font-family: Nunito, Arial, sans-serif; }
  #print-root .pr-h { display: flex; justify-content: space-between; align-items: center; border-bottom: 2px solid #6AC610; padding-bottom: 8px; }
  #print-root .pr-h img { height: 42px; }
  #print-root .pr-h div { text-align: right; }
  #print-root .pr-h b { display: block; font-size: 15px; }
  #print-root .pr-h span { font-size: 11px; color: #555; }
  #print-root h1 { font-size: 20px; margin: 14px 0 2px; }
  #print-root .pr-sub { margin: 0 0 10px; color: #555; }
  #print-root table { width: 100%; border-collapse: collapse; font-size: 11px; }
  #print-root th { text-align: left; background: #EEF6E4; padding: 6px 8px; border-bottom: 1px solid #999; }
  #print-root td { padding: 6px 8px; border-bottom: 1px solid #ddd; vertical-align: top; }
  #print-root tr { break-inside: avoid; }
}

/* Accesso */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 20px; background: var(--band); }
.auth .card { width: 100%; max-width: 420px; padding: 28px; border: 0; box-shadow: 0 20px 50px rgba(30, 60, 0, .25); }
.auth-logos { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.auth-logos img { height: 52px; width: auto; }
.auth h1 { font-size: 28px; font-weight: 900; margin: 18px 0 2px; }
.auth h1 .hl { color: var(--green-dk); }
.auth p { color: var(--muted); margin: 0 0 20px; }
.auth form { display: flex; flex-direction: column; gap: 14px; }
.err-msg { color: var(--red); font-size: 14px; font-weight: 700; min-height: 1em; }

/* Modale */
.modal-bg { position: fixed; inset: 0; background: rgba(20, 35, 10, .5); display: flex; align-items: flex-start; justify-content: center; padding: 6vh 16px 16px; z-index: 50; overflow-y: auto; animation: fade .12s ease; }
.modal { background: var(--surface); border-radius: 24px; width: 100%; max-width: 620px; box-shadow: 0 24px 60px rgba(0, 0, 0, .25); }
.modal.sm { max-width: 440px; }
.modal-h { display: flex; justify-content: space-between; align-items: center; padding: 16px 22px; border-bottom: 2px solid var(--border); }
.modal-h h3 { margin: 0; font-size: 19px; font-weight: 900; }
.modal-b { padding: 18px 22px; display: flex; flex-direction: column; gap: 14px; }
.modal-f { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 22px; border-top: 2px solid var(--border); background: var(--surface-2); border-radius: 0 0 24px 24px; }
.x { border: 0; background: none; font-size: 24px; line-height: 1; cursor: pointer; color: var(--muted); padding: 4px 8px; }
@keyframes fade { from { opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .modal-bg, .toast { animation: none; } }

#toast-root { position: fixed; bottom: calc(20px + env(safe-area-inset-bottom, 0px)); left: 50%; transform: translateX(-50%); z-index: 80; display: flex; flex-direction: column; gap: 8px; align-items: center; }
.toast { background: var(--foot); color: var(--on-green); padding: 10px 18px; border-radius: 999px; font-size: 14px; font-weight: 700; box-shadow: 0 8px 24px rgba(0, 0, 0, .25); animation: fade .15s ease; max-width: 90vw; }
.toast.err { background: var(--red); }

.mobile-bar { display: none; }

@media (max-width: 900px) {
  .wrap { padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px)); }
  .top-tit, .who span { display: none; }
  .logo img { height: 38px; }
  .vira { height: 34px; }
  .band { padding-block: 18px 22px; border-radius: 0 0 24px 24px; }
  .band .nav { display: none; }
  #band-head { margin-top: 0; }
  .head h1 { font-size: 26px; }
  .main { padding-block: 18px 96px; }
  .mobile-bar { display: flex; position: fixed; bottom: 0; left: 0; right: 0; background: var(--surface); border-top: 2px solid var(--border); z-index: 30; padding-bottom: env(safe-area-inset-bottom, 0px); padding-left: env(safe-area-inset-left, 0px); padding-right: env(safe-area-inset-right, 0px); }
  .mobile-bar a { flex: 1; text-align: center; padding: 9px 4px 8px; font-size: 11px; font-weight: 800; color: var(--muted); text-decoration: none; display: flex; flex-direction: column; align-items: center; gap: 2px; position: relative; }
  .mobile-bar a.on { color: var(--green-dk); }
  .mobile-bar svg { width: 22px; height: 22px; }
  .mobile-bar .count { position: absolute; top: 4px; left: 54%; background: var(--red); color: var(--on-green); font-size: 10px; border-radius: 99px; padding: 0 5px; line-height: 16px; }
  .kpis { grid-template-columns: 1fr 1fr; }
  .cols { grid-template-columns: 1fr; }
  .grid2, .grid3 { grid-template-columns: 1fr; }
  .ev { grid-template-columns: 54px 1fr; padding: 12px; }
  .ev-a { grid-column: 1 / -1; justify-content: flex-start; }
  .table .hide-m { display: none; }
}

/* Anteprima dell'email dei promemoria */
.email-anteprima { max-height: 60vh; overflow: auto; border: 2px solid var(--border); border-radius: 14px; background: var(--surface-2); }
