/* Componenti comuni: schede, tabelle, finestre, avvisi, filtri, navigazione mobile. */
/* --- CARDS / STATS --- */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 1rem; margin-bottom: 1.5rem; }
.stat-card { background: var(--surface); border-radius: var(--radius); border: 1px solid var(--border); padding: 1rem 1.25rem; }
.stat-card.stat-gray { border-top: 3px solid var(--border); }
.stat-card.stat-gray .stat-value { color: var(--text2) !important; font-size: 1.2rem; }
.stat-card .stat-label { font-size: 12px; color: var(--text2); font-weight: 500; margin-bottom: 6px; }
.stat-card .stat-value { font-size: 1.5rem; font-weight: 700; }
.stat-card .stat-sub { font-size: 12px; color: var(--text2); margin-top: 4px; }
.stat-green .stat-value { color: var(--green); }
.stat-red .stat-value { color: var(--red); }
.stat-blue .stat-value { color: var(--accent); }
.stat-amber .stat-value { color: var(--amber); }

/* --- TABLE --- */
.card { background: var(--surface); border-radius: var(--radius); border: 1px solid var(--border); box-shadow: var(--shadow); overflow: hidden; margin-bottom: 1.5rem; }
.card-header { padding: 1rem 1.25rem; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: .5rem; }
.card-header h3 { font-size: 15px; font-weight: 600; }
/* ── TABLE WRAP: scrollbar sempre presente ───────────────────────────── */
.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  /* Forza scrollbar visibile su tutti i browser */
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}
.table-wrap::-webkit-scrollbar { height: 6px; }
.table-wrap::-webkit-scrollbar-track { background: var(--surface2); border-radius: 3px; }
.table-wrap::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
.table-wrap::-webkit-scrollbar-thumb:hover { background: var(--text2); }
/* Tabelle del pannello "Stato del servizio": restano visibili anche su mobile
   (le .table-wrap delle pagine dati lì sono sostituite da schede). */
.ops-table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.ops-table-wrap table { min-width: 640px; }
.table-wrap table {
  width: 100%;
  border-collapse: collapse;
  min-width: 900px; /* forza scrollbar quando schermo è stretto */
}
.table-wrap td { white-space: nowrap; font-size: 13px; padding: 8px 10px; }
.table-wrap th { font-size: 12px; padding: 8px 10px; white-space: nowrap; }
.table-wrap td.col-title { white-space: normal; min-width: 140px; max-width: 220px; }
.table-wrap th.col-azioni, .table-wrap td.col-azioni   { width: 82px; }
.table-wrap th.col-data,   .table-wrap td.col-data     { width: 92px; }
.table-wrap th.col-stato,  .table-wrap td.col-stato    { width: 95px; }
.table-wrap th.col-quota,  .table-wrap td.col-quota    { width: 90px; text-align: right; }
.table-wrap th.col-allegati,.table-wrap td.col-allegati{ width: 72px; text-align: center; }
/* Su schermi larghi: niente scrollbar */

table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th { padding: 10px 12px; background: var(--surface2); font-weight: 600; text-align: left; font-size: 12px; color: var(--text2); text-transform: uppercase; letter-spacing: .04em; border-bottom: 1px solid var(--border); white-space: nowrap; }
td { padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tr:last-child td { border-bottom: none; }
tr:hover td { background: var(--surface2); }
.badge { display: inline-flex; align-items: center; gap: 4px; padding: 3px 9px; border-radius: 20px; font-size: 12px; font-weight: 500; white-space: nowrap; }
.badge-green { background: var(--green-light); color: var(--green); }
.badge-red { background: var(--red-light); color: var(--red); }
.badge-amber { background: var(--amber-light); color: var(--amber); }
.badge-blue { background: var(--accent-light); color: var(--accent); }
.badge-purple { background: var(--purple-light); color: var(--purple); }
.badge-gray { background: var(--surface2); color: var(--text2); }

/* --- MODAL --- */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.4); display: flex; align-items: center; justify-content: center; z-index: 1000; padding: 1rem; backdrop-filter: blur(2px); }
.modal { background: var(--surface); border-radius: 14px; box-shadow: var(--shadow-md); width: 100%; max-width: 540px; max-height: 90vh; overflow-y: auto; overflow-x: hidden; }
.modal-header { padding: 1.25rem 1.5rem 1rem; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; }
.modal-header h2 { font-size: 1.1rem; font-weight: 700; }
.modal-close { background: none; border: none; cursor: pointer; color: var(--text2); padding: 4px; border-radius: 4px; }
.modal-close:hover { background: var(--surface2); color: var(--text); }
.modal-body { padding: 1.25rem 1.5rem; }
.modal-footer { padding: .75rem 1.5rem 1.25rem; display: flex; flex-wrap: wrap; justify-content: flex-end; gap: .5rem; } /* a capo se i pulsanti non ci stanno (es. scheda del rendiconto) */
.modal-footer .btn { width: auto; } /* .btn-primary è largo 100%: qui andrebbe sempre su una riga sua */
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.form-row-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 1rem; }
.hint { font-size: 12px; color: var(--text2); margin-top: 4px; }

/* --- BALANCE BAR --- */
.balance-bar { display: flex; height: 8px; border-radius: 10px; overflow: hidden; margin: 6px 0; }
.balance-bar-in { background: var(--green); }
.balance-bar-out { background: var(--red); }

/* --- PROGRESS --- */
.progress-wrap { background: var(--surface2); border-radius: 10px; height: 6px; overflow: hidden; }
.progress-fill { height: 100%; border-radius: 10px; transition: width .3s; }

/* --- ALERT --- */
.alert { padding: .75rem 1rem; border-radius: var(--radius-sm); font-size: 13.5px; margin-bottom: 1rem; }
.alert-warning { background: var(--amber-light); color: var(--amber); border: 1px solid var(--amber-border); }
.alert-info { background: var(--accent-light); color: var(--info-text); border: 1px solid var(--accent-border); }
.alert-success { background: var(--green-light); color: var(--green); border: 1px solid var(--green-border); }
.alert-danger { background: var(--red-light); color: var(--red-strong); border: 1px solid var(--red-border); }

/* --- AMOUNT DIFF --- */
.amount-pos { color: var(--green); font-weight: 600; }
.amount-neg { color: var(--red); font-weight: 600; }

/* --- EMPTY STATE --- */
.empty { text-align: center; padding: 3rem 1rem; color: var(--text2); }
.empty svg { width: 48px; height: 48px; margin: 0 auto 1rem; opacity: .4; display: block; }
.empty p { font-size: 14px; }

/* --- CHIP FILTERS --- */
.chip-group { display: flex; flex-wrap: wrap; gap: .5rem; margin-bottom: 1rem; }
.chip { padding: 5px 14px; border-radius: 20px; border: 1px solid var(--border); background: var(--surface); font-size: 13px; cursor: pointer; transition: all .12s; color: var(--text2); }
.chip.active { background: var(--accent-fill); color: white; border-color: var(--accent); }

/* --- CONDOMINI GRID --- */
.condomini-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 1rem; }
.condomino-card { background: var(--surface); border-radius: var(--radius); border: 1px solid var(--border); padding: 1.25rem; }
.condomino-card .head { display: flex; align-items: center; gap: 10px; margin-bottom: 1rem; }
.condomino-card .name { font-weight: 600; font-size: 15px; }
.condomino-card .apt { font-size: 12px; color: var(--text2); }
.condomino-card .row { display: flex; justify-content: space-between; font-size: 13px; padding: 4px 0; border-bottom: 1px solid var(--border); }
.condomino-card .row:last-child { border-bottom: none; }

/* ════════════════════════════════════════
   MOBILE & TABLET — responsive completo
   ════════════════════════════════════════ */

/* Bottom nav (mobile) */
.bottom-nav {
  display: none;
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 200;
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 6px 0 max(6px, env(safe-area-inset-bottom));
  box-shadow: 0 -2px 12px rgba(0,0,0,.07);
}
.bottom-nav-inner { display: flex; justify-content: space-around; }
.bnav-item {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 6px 10px; border-radius: 10px; border: none; background: none;
  cursor: pointer; color: var(--text2); font-size: 10px; font-weight: 500;
  min-width: 52px; transition: all .15s;
}
.bnav-item svg { width: 22px; height: 22px; }
.bnav-item.active { color: var(--accent); background: var(--accent-light); }
.bnav-item .bnav-dot { width: 4px; height: 4px; border-radius: 50%; background: var(--accent-fill); margin-top: 1px; display: none; }
.bnav-item.active .bnav-dot { display: block; }

/* Topbar mobile */
.topbar {
  display: none;
  align-items: center; justify-content: space-between;
  padding: .65rem 1rem; padding-top: max(.65rem, env(safe-area-inset-top));
  background: var(--surface); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 150;
}
.topbar-left { display: flex; align-items: center; gap: 8px; }
.topbar-logo { font-weight: 800; font-size: 15px; letter-spacing: -.3px; }
.topbar-page { font-size: 13px; color: var(--text2); }
.hamburger { background: none; border: none; cursor: pointer; padding: 6px; color: var(--text); border-radius: 8px; }
.hamburger:active { background: var(--surface2); }
.topbar-right { display: flex; align-items: center; gap: 8px; }
.topbar-avatar { width: 32px; height: 32px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 12px; cursor: pointer; }

/* Card spese mobile — replace table with cards */
.mobile-card-list { display: none; flex-direction: column; gap: 10px; }
.spesa-mobile-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; }
.spesa-mobile-card .smc-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; margin-bottom: 6px; }
.spesa-mobile-card .smc-title { font-weight: 600; font-size: 14px; flex: 1; }
.spesa-mobile-card .smc-amount { font-weight: 700; color: var(--red); font-size: 15px; white-space: nowrap; }
.spesa-mobile-card .smc-meta { display: flex; flex-wrap: wrap; gap: 5px; align-items: center; margin-bottom: 6px; }
.spesa-mobile-card .smc-footer { display: flex; justify-content: space-between; align-items: center; padding-top: 6px; border-top: 1px solid var(--border); }
.spesa-mobile-card .smc-quota { font-size: 12px; color: var(--accent); font-weight: 500; }
.spesa-mobile-card .smc-actions { display: flex; gap: 4px; }

/* Card entrate mobile */
.entrata-mobile-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; display: flex; align-items: center; gap: 10px; }
.entrata-mobile-card .emc-info { flex: 1; min-width: 0; }
.entrata-mobile-card .emc-name { font-weight: 600; font-size: 14px; }
.entrata-mobile-card .emc-meta { font-size: 12px; color: var(--text2); margin-top: 1px; }
.entrata-mobile-card .emc-amount { font-weight: 700; color: var(--green); font-size: 15px; white-space: nowrap; }

/* FAB button */
.fab {
  display: none;
  position: fixed; bottom: calc(72px + max(0px, env(safe-area-inset-bottom))); right: 16px;
  width: 52px; height: 52px; border-radius: 50%; background: var(--accent-fill); color: white;
  border: none; cursor: pointer; font-size: 24px; z-index: 190;
  box-shadow: 0 4px 16px rgba(37,99,235,.4); align-items: center; justify-content: center;
  transition: transform .15s, box-shadow .15s;
}
.fab:active { transform: scale(.93); box-shadow: 0 2px 8px rgba(37,99,235,.3); }


/* ── Guida rapida (js/sezioni/guida.js) ──────────────────────────────
   Pulsante "? Guida" accanto al titolo di ogni pagina; pannello a destra
   che affianca la pagina sugli schermi larghi (non la copre), in
   sovrapposizione sugli schermi medi, dal basso sui telefoni. */
.btn-guida { position: relative; display: inline-flex; align-items: center; gap: 5px; vertical-align: middle; margin-left: 8px; padding: 3px 10px 3px 4px; border: 1px solid var(--border); border-radius: 999px; background: var(--surface); color: var(--accent); font-size: 12.5px; font-weight: 600; cursor: pointer; line-height: 1.2; }
.btn-guida:hover, .btn-guida.attivo { background: var(--accent-light); border-color: var(--accent); }
.btn-guida:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn-guida-icona { width: 20px; height: 20px; border-radius: 50%; background: var(--accent-fill); color: #fff; display: inline-flex; align-items: center; justify-content: center; font-size: 12px; font-weight: 800; }
.btn-guida-nuova { position: absolute; top: -3px; right: -3px; width: 9px; height: 9px; border-radius: 50%; background: #F59E0B; border: 2px solid var(--surface); }
.guida-sfondo { display: none; }
.guida-pannello { position: fixed; top: 0; right: 0; bottom: 0; width: 360px; max-width: 100%; z-index: 400; background: var(--surface); border-left: 1px solid var(--border); box-shadow: -6px 0 24px rgba(27,42,74,.10); display: flex; flex-direction: column; animation: guida-entra .18s ease-out; }
@keyframes guida-entra { from { transform: translateX(24px); opacity: 0; } to { transform: none; opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .guida-pannello { animation: none; } }
.guida-testa { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; padding: 1.1rem 1.25rem .9rem; border-bottom: 1px solid var(--border); }
.guida-etichetta { font-size: 11px; font-weight: 700; color: var(--accent); text-transform: uppercase; letter-spacing: .06em; }
.guida-testa h2 { font-size: 1.15rem; margin: 2px 0 0; }
.guida-chiudi { background: none; border: none; font-size: 18px; color: var(--text2); cursor: pointer; padding: 4px 8px; border-radius: 6px; }
.guida-chiudi:hover { background: var(--surface2); }
.guida-corpo { flex: 1; overflow-y: auto; padding: 1rem 1.25rem 1.5rem; font-size: 14px; line-height: 1.5; }
.guida-breve { font-size: 15px; color: var(--text); margin: 0 0 .5rem; }
.guida-corpo h3 { font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--text2); margin: 1.1rem 0 .45rem; }
.guida-lista { margin: 0; padding-left: 1.1rem; }
.guida-lista li { margin-bottom: .35rem; }
.guida-passi { list-style: none; margin: 0; padding: 0; }
.guida-passi li { display: flex; flex-direction: column; gap: 2px; padding: .55rem .7rem; margin-bottom: .45rem; background: var(--surface2); border-radius: var(--radius-sm); }
.guida-passi li span { color: var(--text2); font-size: 13.5px; }
.guida-sapere li { color: var(--text2); }
.guida-piede { margin-top: 1.25rem; padding-top: .75rem; border-top: 1px solid var(--border); font-size: 12.5px; color: var(--text2); }
/* Schermi larghi: la pagina si stringe e resta tutta visibile accanto alla guida. */
@media (min-width: 1100px) { .app.guida-aperta .main { margin-right: 360px; } }
/* Schermi medi: guida sopra la pagina, con sfondo che si tocca per chiudere. */
@media (max-width: 1099px) { .guida-sfondo { display: block; position: fixed; inset: 0; z-index: 390; background: rgba(27,42,74,.25); } }
/* Telefoni: pannello dal basso, sopra la barra di navigazione. */
@media (max-width: 768px) {
  .btn-guida { padding: 3px; margin-left: 6px; }
  .btn-guida-testo { display: none; }
  .btn-guida-icona { width: 22px; height: 22px; font-size: 13px; }
  .guida-pannello { top: auto; left: 0; width: 100%; max-height: 85vh; border-left: none; border-radius: 16px 16px 0 0; box-shadow: 0 -6px 24px rgba(27,42,74,.15); padding-bottom: env(safe-area-inset-bottom); animation-name: guida-sale; }
  @keyframes guida-sale { from { transform: translateY(24px); opacity: 0; } to { transform: none; opacity: 1; } }
}
.guida-corpo:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }

/* ── Filtro anni a scelta multipla (js/core/filtro-anni.js) ─────────── */
.filtro-anni { display: flex; flex-wrap: wrap; align-items: center; gap: .4rem; margin-bottom: .875rem; }
.filtro-anni-lbl { font-size: 12px; font-weight: 600; color: var(--text2); margin-right: .15rem; }
.chip-anno { display: inline-flex; align-items: center; gap: 4px; min-height: 32px; padding: 4px 12px; border-radius: 999px; border: 1px solid var(--border); background: var(--surface); color: var(--text); font-size: 13px; font-weight: 600; cursor: pointer; }
.chip-anno:hover { border-color: var(--accent); }
.chip-anno.attivo { background: var(--accent-fill); border-color: var(--accent); color: #fff; }
.chip-anno:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.chip-anno-spunta { font-size: 11px; min-width: 0; }
.chip-anno-spunta:empty { display: none; }
.filtro-anni-nota { font-size: 12px; color: var(--text2); margin-left: .25rem; }
.table-wrap:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ── Interruttore chiaro/scuro accanto alla Guida (js/core/tema.js) ── */
.tema-switch { position: relative; display: inline-flex; align-items: center; justify-content: space-between; vertical-align: middle; width: 52px; height: 28px; margin-left: 6px; padding: 0 7px; border-radius: 999px; border: 1px solid var(--border); background: var(--surface2); color: var(--text2); cursor: pointer; transition: background .2s, border-color .2s; }
.tema-switch:hover { border-color: var(--accent); }
.tema-switch:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.ts-icona { position: relative; z-index: 1; display: inline-flex; transition: color .2s, opacity .2s; }
.ts-pomello { position: absolute; top: 2px; left: 2px; width: 22px; height: 22px; border-radius: 50%; background: var(--surface); box-shadow: 0 1px 3px rgba(0,0,0,.25); transition: transform .22s ease; }
.tema-switch .ts-sole { color: var(--amber); }
.tema-switch .ts-luna { opacity: .55; }
.tema-switch.scuro { background: var(--accent-light); border-color: var(--accent-border); }
.tema-switch.scuro .ts-pomello { transform: translateX(24px); }
.tema-switch.scuro .ts-sole { opacity: .55; color: var(--text2); }
.tema-switch.scuro .ts-luna { opacity: 1; color: var(--accent); }
@media (prefers-reduced-motion: reduce) { .tema-switch, .ts-pomello, .ts-icona { transition: none; } }
@media (max-width: 768px) { .tema-switch { width: 48px; height: 28px; margin-left: 4px; } .tema-switch.scuro .ts-pomello { transform: translateX(20px); } }
