/* Nuova dashboard · un solo foglio di stile (Fase 1). Tema NERO predefinito, bianco selezionabile (decisione 18/10).
   Palette neutra: ambra e rosso solo per le urgenze. Niente :has(), niente animazioni di vista, niente scroll smooth. */

:root,
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0b0b0c;
  --side: #111113;
  --surface: #18181b;
  --soft: #232327;
  --line: #2c2c31;
  --ink: #f4f4f5;
  --muted: #a1a1aa;
  --accent-bg: #f4f4f5;
  --accent-ink: #0b0b0c;
  --amber: #f5c26b;
  --amber-soft: rgba(245, 194, 107, .12);
  --red: #ff9b9b;
  --red-soft: rgba(255, 155, 155, .12);
  --focus: #8ab4ff;
  --backdrop: rgba(0, 0, 0, .62);
  --shadow: 0 16px 48px rgba(0, 0, 0, .45);
}
:root[data-theme="light"] {
  color-scheme: light;
  --bg: #ffffff;
  --side: #fafafa;
  --surface: #fafafa;
  --soft: #f1f1f3;
  --line: #e4e4e7;
  --ink: #0b0b0c;
  --muted: #52525b;
  --accent-bg: #0b0b0c;
  --accent-ink: #ffffff;
  --amber: #a15c00;
  --amber-soft: #fff4e0;
  --red: #b42318;
  --red-soft: #fdecea;
  --focus: #1d4ed8;
  --backdrop: rgba(11, 11, 12, .38);
  --shadow: 0 16px 48px rgba(11, 11, 12, .14);
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  margin: 0; min-height: 100vh; background: var(--bg); color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 15px; line-height: 1.45; overflow-x: hidden;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: default; opacity: .5; }
a { color: inherit; }
h1, h2, h3, p { margin: 0; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.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; }
.muted { color: var(--muted); font-size: 14px; }
noscript { display: block; padding: 16px; color: var(--red); background: var(--red-soft); }

/* ---------- Pulsanti, badge, card ---------- */
.button {
  display: inline-flex; align-items: center; justify-content: center; min-height: 44px; padding: 0 18px;
  border: 0; border-radius: 22px; background: var(--accent-bg); color: var(--accent-ink);
  font-weight: 700; font-size: 14px; text-decoration: none; white-space: nowrap;
}
.badge {
  display: inline-flex; align-items: center; min-height: 26px; padding: 2px 10px; border-radius: 13px;
  background: var(--soft); color: var(--ink); font-size: 12px; font-weight: 600; white-space: nowrap;
}
.badge-amber { background: var(--amber-soft); color: var(--amber); }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 16px 18px; }
.card h3 { font-size: 15px; font-weight: 700; margin-bottom: 6px; }
.notice { padding: 10px 14px; border-radius: 12px; background: var(--amber-soft); color: var(--amber); font-size: 14px; margin-bottom: 12px; }
.help { color: var(--muted); font-size: 14px; }
.help summary, .more summary { cursor: pointer; min-height: 44px; display: flex; align-items: center; }
.help p { padding: 0 0 8px; max-width: 760px; }

/* ---------- Accesso ---------- */
.auth-stage { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.theme-corner {
  position: fixed; top: 12px; right: 12px; width: 44px; height: 44px; border-radius: 22px;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink); font-size: 18px;
}
.login-card {
  width: 100%; max-width: 400px; padding: 28px 24px; display: flex; flex-direction: column; gap: 12px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 18px;
}
.login-brand {
  width: 44px; height: 44px; border-radius: 12px; display: grid; place-items: center;
  background: var(--accent-bg); color: var(--accent-ink); font-weight: 800; font-size: 13px;
}
.login-card h1 { font-size: 22px; letter-spacing: -.01em; }
.login-intro, .login-note { color: var(--muted); font-size: 14px; }
.login-form { display: grid; gap: 8px; margin-top: 4px; }
.login-form label { font-size: 14px; font-weight: 600; }
.login-form input {
  width: 100%; min-height: 46px; padding: 0 14px; border: 1px solid var(--line); border-radius: 12px;
  background: var(--bg); color: var(--ink); font-size: 16px;
}
.login-form input::placeholder { color: var(--muted); }
.login-form input:focus { border-color: var(--focus); outline: none; }
.login-submit {
  min-height: 46px; margin-top: 4px; border: 0; border-radius: 23px;
  background: var(--accent-bg); color: var(--accent-ink); font-weight: 700; font-size: 15px;
}
.login-submit:disabled { cursor: wait; }
.login-status { min-height: 20px; font-size: 14px; color: var(--muted); }
.login-status.is-error { color: var(--red); }
.login-status.is-success { color: var(--ink); }
.auth-stage--loading { color: var(--muted); }
.loading-card { font-size: 15px; }

/* ---------- Guscio ---------- */
.app-shell { display: grid; grid-template-columns: 220px minmax(0, 1fr); min-height: 100vh; }
html[data-sidebar="collapsed"] .app-shell { grid-template-columns: 68px minmax(0, 1fr); }
#appRoot[aria-busy="true"] .views { opacity: .82; }

.sidebar {
  position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; gap: 4px;
  padding: 18px 12px; background: var(--side); border-right: 1px solid var(--line); overflow-y: auto;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 2px 8px 18px; }
.brand-mark {
  flex: 0 0 auto; width: 32px; height: 32px; border-radius: 9px; display: grid; place-items: center;
  background: var(--accent-bg); color: var(--accent-ink); font-weight: 800; font-size: 11px;
}
.brand-name { font-weight: 700; font-size: 16px; }
.side-nav { display: flex; flex-direction: column; gap: 2px; }
.nav-item, .sidebar-toggle {
  display: flex; align-items: center; gap: 10px; width: 100%; min-height: 42px; padding: 0 10px;
  border: 0; border-radius: 10px; background: transparent; color: var(--ink); font-weight: 600; font-size: 15px; text-align: left;
}
.nav-item:hover, .sidebar-toggle:hover { background: var(--soft); }
.nav-item[aria-current="page"] { background: var(--soft); }
.nav-icon { flex: 0 0 22px; text-align: center; color: var(--muted); font-size: 15px; }
.nav-item[aria-current="page"] .nav-icon { color: var(--ink); }
.nav-text { flex: 1 1 auto; min-width: 0; }
.nav-badge {
  min-width: 22px; height: 22px; padding: 0 7px; border-radius: 11px; display: inline-flex; align-items: center; justify-content: center;
  background: var(--accent-bg); color: var(--accent-ink); font-size: 12px; font-weight: 700;
}
.nav-label { margin: 16px 10px 4px; color: var(--muted); font-size: 12px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; }
.sidebar-toggle { margin-top: auto; color: var(--muted); font-weight: 500; font-size: 14px; }
html[data-sidebar="collapsed"] .sidebar .nav-text,
html[data-sidebar="collapsed"] .sidebar .nav-label { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; }
html[data-sidebar="collapsed"] .sidebar .nav-badge { position: absolute; margin: -22px 0 0 26px; min-width: 18px; height: 18px; font-size: 11px; padding: 0 5px; }
html[data-sidebar="collapsed"] .nav-item, html[data-sidebar="collapsed"] .sidebar-toggle { justify-content: center; padding: 0; }
html[data-sidebar="collapsed"] .brand { justify-content: center; padding-inline: 0; }

.workspace { min-width: 0; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 10; min-height: 56px; display: flex; align-items: center; gap: 12px;
  padding: 6px 28px; background: var(--bg); border-bottom: 1px solid var(--line);
}
.topbar-title { flex: 1 1 auto; min-width: 0; font-size: 19px; font-weight: 700; letter-spacing: -.01em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.quote-slot { display: flex; flex: 0 1 auto; min-width: 0; }
.quote-slot .nav-item {
  width: auto; max-width: 100%; min-width: 0; min-height: 40px; padding: 4px 14px; border: 1px solid var(--line); border-radius: 20px; gap: 8px; font-size: 14px;
}
.quote-slot .nav-item .nav-icon { flex: 0 0 auto; }
.quote-slot .pca-chat-nav-copy { display: flex; flex-direction: column; min-width: 0; line-height: 1.2; }
.quote-slot .pca-chat-nav-copy > span, .quote-slot .pca-chat-nav-readiness { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.quote-slot .pca-chat-nav-readiness { font-size: 11px; color: var(--muted); font-weight: 500; }
.refresh-box { position: relative; display: flex; flex-direction: column; align-items: flex-end; }
.refresh-button {
  display: inline-flex; align-items: center; gap: 6px; min-height: 40px; padding: 0 12px;
  border: 1px solid var(--line); border-radius: 20px; background: transparent; color: var(--muted); font-size: 13px; white-space: nowrap;
}
.refresh-icon { color: var(--ink); font-size: 15px; }
/* Il motivo è scritto sotto ↻ senza allungare la topbar (la scheda agganciata parte a 57 px). */
.refresh-reason {
  position: absolute; right: 0; top: calc(100% + 4px); z-index: 12; width: max-content; max-width: 260px; padding: 4px 8px; border-radius: 8px;
  background: var(--surface); border: 1px solid var(--line); color: var(--amber); font-size: 12px; text-align: right;
}
.avatar-wrap { position: relative; }
.avatar-button { width: 40px; height: 40px; border-radius: 20px; border: 0; background: var(--soft); color: var(--ink); font-weight: 700; font-size: 13px; }
.avatar-menu {
  position: absolute; right: 0; top: calc(100% + 8px); z-index: 30; min-width: 230px; padding: 6px;
  display: flex; flex-direction: column; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow);
}
.avatar-menu-head { display: flex; flex-direction: column; padding: 8px 10px 10px; border-bottom: 1px solid var(--line); margin-bottom: 4px; }
.avatar-menu-head small { color: var(--muted); font-size: 13px; }
.avatar-menu button, .sheet-list button, .menu-link, .sheet-link {
  min-height: 44px; padding: 0 10px; border: 0; border-radius: 10px; background: transparent; color: var(--ink); text-align: left; font-size: 15px;
}
/* Link alla versione classica (fino al 01/11/2026): stesso aspetto delle voci, testo secondario. */
.menu-link, .sheet-link { display: flex; align-items: center; color: var(--muted); text-decoration: none; white-space: nowrap; }
.avatar-menu button:hover, .sheet-list button:hover, .menu-link:hover, .sheet-link:hover { background: var(--soft); }

.views { width: 100%; max-width: 1080px; padding: 24px 28px 56px; display: flex; flex-direction: column; gap: 18px; }
.view { display: none; }
.view.active { display: flex; flex-direction: column; gap: 16px; }
.view-head { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.view-head h2 { font-size: 22px; font-weight: 700; letter-spacing: -.02em; }
.numbers-tabs { display: flex; gap: 6px; flex-wrap: wrap; }
.tab {
  min-height: 38px; padding: 0 16px; border: 0; border-radius: 19px; background: transparent; color: var(--ink); font-weight: 600; font-size: 14px;
}
.tab:hover { background: var(--soft); }
.tab[aria-current="page"] { background: var(--accent-bg); color: var(--accent-ink); }

/* ---------- Oggi (Fase 3): saluto, una frase, chip e gruppi con la stessa card di Clienti ---------- */
.greeting { display: flex; flex-direction: column; gap: 4px; }
.greeting-title { font-size: 28px; font-weight: 700; letter-spacing: -.02em; }
.greeting-date { color: var(--muted); font-size: 16px; }
.greeting-date::first-letter { text-transform: uppercase; }
.today-summary { font-size: 17px; color: var(--muted); }
.today-chips { display: flex; flex-wrap: wrap; gap: 8px; }
.today-skeleton { display: flex; flex-direction: column; gap: 8px; }
.today-skeleton span { display: block; height: 76px; border-radius: 14px; background: var(--surface); border: 1px solid var(--line); }
/* Il chip porta al gruppo con uno scorrimento istantaneo: il titolo resta sotto la topbar fissa. */
.today-group { display: flex; flex-direction: column; gap: 8px; scroll-margin-top: 72px; }
.today-group-title { font-size: 13px; font-weight: 700; color: var(--muted); letter-spacing: .06em; text-transform: uppercase; }
.today-group-title:focus:not(:focus-visible) { outline: none; }
.today-list { display: flex; flex-direction: column; gap: 8px; }
/* Call di oggi già finita con l'esito da registrare: in grigio, il pulsante resta pieno. */
.lead-card.is-past { background: transparent; }
.lead-card.is-past .lead-when, .lead-card.is-past .lead-name { color: var(--muted); }
.today-tomorrow { margin-top: -8px; color: var(--muted); font-size: 14px; }
.today-tomorrow summary { display: inline-flex; align-items: center; min-height: 40px; cursor: pointer; font-weight: 600; }
.today-tomorrow-list { display: flex; flex-direction: column; gap: 6px; padding-bottom: 4px; }
.today-tomorrow-item {
  display: flex; align-items: baseline; gap: 10px; min-height: 44px; padding: 8px 14px; border: 1px solid var(--line); border-radius: 12px;
  background: transparent; color: var(--ink); font-size: 14px; text-align: left;
}
.today-tomorrow-item b { font-variant-numeric: tabular-nums; }
.today-tomorrow-item span { min-width: 0; flex: 1 1 auto; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.today-tomorrow-item small { color: var(--muted); font-size: 13px; white-space: nowrap; }
.today-all { align-self: flex-start; min-height: 44px; font-size: 15px; }

/* ---------- Comandi comuni della Fase 2 ---------- */
.link-button { min-height: 32px; padding: 0 2px; border: 0; background: none; color: var(--ink); font-weight: 600; font-size: 14px; text-decoration: underline; text-underline-offset: 3px; }
.button-ghost { display: inline-flex; align-items: center; justify-content: center; min-height: 44px; padding: 0 16px; border: 1px solid var(--line); border-radius: 22px; background: transparent; color: var(--ink); font-weight: 600; font-size: 14px; }
.chip-button { min-height: 38px; padding: 0 14px; border: 1px solid var(--line); border-radius: 19px; background: transparent; color: var(--ink); font-size: 14px; font-weight: 600; }
.toast.is-error { background: var(--red-soft); color: var(--red); }

/* ---------- Clienti: sezioni, strumenti e card essenziali (quando · nome · stato · un pulsante) ---------- */
.clients-head h2 { font-size: 22px; font-weight: 700; letter-spacing: -.02em; }
.clients-total { color: var(--muted); font-weight: 600; font-size: 17px; }
.clients-view-tabs { display: flex; flex-wrap: wrap; gap: 6px; padding-bottom: 12px; border-bottom: 1px solid var(--line); }
.clients-view-tab {
  display: inline-flex; align-items: center; gap: 6px; min-height: 38px; padding: 0 14px; border: 0; border-radius: 19px;
  background: transparent; color: var(--ink); font-weight: 600; font-size: 14px; white-space: nowrap;
}
.clients-view-tab:hover { background: var(--soft); }
.clients-view-tab.active { background: var(--accent-bg); color: var(--accent-ink); }
.tab-dot { width: 7px; height: 7px; border-radius: 4px; background: var(--amber); }
.clients-toolbar { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 10px 12px; }
.toolbar-field { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.toolbar-label { color: var(--muted); font-size: 12px; font-weight: 600; }
.toolbar-search { flex: 1 1 260px; }
.clients-search, .clients-service-filter, .clients-priority {
  min-height: 42px; padding: 0 12px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); color: var(--ink); font-size: 15px; max-width: 100%;
}
.clients-search { width: 100%; border-radius: 21px; padding: 0 16px; }
.clients-search:focus, .clients-service-filter:focus, .clients-priority:focus { border-color: var(--focus); outline: none; }
.clients-also { color: var(--muted); font-size: 14px; }
.clients-meta { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 14px; font-size: 14px; }
.clients-count { font-weight: 600; }
.clients-message { color: var(--muted); }
.clients-message.is-error { color: var(--red); }
.clients-empty { color: var(--muted); padding: 20px 0; }
.lead-list { display: flex; flex-direction: column; gap: 8px; }
.lead-card {
  display: grid; grid-template-columns: 76px minmax(0, 1fr) auto; align-items: center; gap: 4px 16px;
  padding: 12px 16px; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; cursor: pointer;
  content-visibility: auto; contain-intrinsic-size: auto 76px;
}
.lead-card:hover { border-color: var(--muted); }
.lead-card.is-selected { border-color: var(--ink); }
.lead-when { font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.lead-when.is-late { color: var(--red); }
.lead-body { min-width: 0; display: flex; flex-direction: column; gap: 1px; }
.lead-line { display: flex; align-items: center; gap: 8px; min-width: 0; }
.lead-name {
  min-width: 0; min-height: 28px; padding: 0; border: 0; background: none; color: var(--ink); font-weight: 650; font-size: 16px; text-align: left;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.lead-flag { flex: 0 0 auto; padding: 1px 8px; border-radius: 10px; background: var(--soft); color: var(--ink); font-size: 12px; font-weight: 600; white-space: nowrap; }
.lead-flag.is-amber { background: var(--amber-soft); color: var(--amber); }
.lead-flag.is-red { background: var(--red-soft); color: var(--red); }
.lead-status { color: var(--muted); font-size: 14px; }
.lead-meta { color: var(--muted); font-size: 13px; }
.lead-action {
  display: inline-flex; align-items: center; justify-content: center; min-height: 40px; padding: 0 16px; border: 1px solid var(--line); border-radius: 20px;
  background: transparent; color: var(--ink); font-weight: 600; font-size: 14px; white-space: nowrap; text-decoration: none;
}
.lead-action.is-primary { border-color: var(--accent-bg); background: var(--accent-bg); color: var(--accent-ink); font-weight: 700; }

/* ---------- Scheda cliente: un solo <dialog>, a destra (agganciato da 1280 px), a schermo intero sotto i 900 px ---------- */
/* Altezza sulla viewport dinamica (dvh): su Chrome Android e iOS Safari 100vh include la barra del browser
   e il piede «Annulla · Salva» finirebbe sotto di essa. 100vh resta come ripiego per i browser senza dvh. */
dialog.client-sheet {
  position: fixed; inset: 0 0 0 auto; margin: 0; width: min(440px, 100vw); max-width: 100vw;
  height: 100vh; height: 100dvh; max-height: 100vh; max-height: 100dvh;
  padding: 0; border: 0; border-left: 1px solid var(--line); background: var(--side); color: var(--ink); box-shadow: var(--shadow); overflow: hidden;
  contain: layout style; /* un cambio nella scheda non rifà il layout della pagina */
}
dialog.client-sheet[open] { display: flex; flex-direction: column; }
dialog.client-sheet::backdrop { background: var(--backdrop); }
dialog.client-sheet:not([data-modal]) { top: 57px; height: calc(100vh - 57px); height: calc(100dvh - 57px); z-index: 9; box-shadow: none; }
@media (min-width: 1280px) { #appRoot.has-sheet .views { width: auto; margin-right: 440px; } }
.sheet-scroll { flex: 1 1 auto; min-height: 0; overflow-y: auto; padding: 14px 22px 20px; display: flex; flex-direction: column; gap: 18px; contain: content; }
.sheet-head { display: flex; flex-direction: column; gap: 4px; }
.sheet-bar { display: flex; align-items: center; gap: 6px; }
.sheet-back { display: none; min-height: 40px; padding: 0 8px; border: 0; background: none; color: var(--ink); font-weight: 600; font-size: 15px; margin-right: auto; }
.sheet-step { width: 36px; height: 36px; border: 1px solid var(--line); border-radius: 18px; background: transparent; color: var(--ink); font-size: 16px; }
.sheet-position { color: var(--muted); font-size: 13px; margin-right: auto; }
.sheet-title { font-size: 22px; font-weight: 700; letter-spacing: -.01em; overflow-wrap: anywhere; }
.sheet-sub, .sheet-contact-line { color: var(--muted); font-size: 14px; overflow-wrap: anywhere; }
.sheet-contacts { display: flex; flex-wrap: wrap; gap: 8px; padding-top: 8px; }
.contact-link {
  display: inline-flex; align-items: center; min-height: 38px; padding: 0 14px; border: 1px solid var(--line); border-radius: 19px;
  color: var(--ink); text-decoration: none; font-size: 14px; font-weight: 600;
}
.sheet-contact-problems { color: var(--amber); font-size: 14px; }
.sheet-status { display: flex; flex-direction: column; gap: 4px; padding: 14px 16px; border: 1px solid var(--line); border-radius: 14px; background: var(--surface); }
.sheet-kicker { color: var(--muted); font-size: 12px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; }
.sheet-status-text { font-size: 15px; font-weight: 600; }
.sheet-status-meta { color: var(--muted); font-size: 13px; }
.sheet-heading { font-size: 15px; font-weight: 700; }
.sheet-subheading { font-size: 14px; font-weight: 700; margin: 4px 0 2px; }
.sheet-outcome, .sheet-notes, .sheet-quotes, .sheet-instant { display: flex; flex-direction: column; gap: 10px; }
.outcome-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.outcome-choice {
  min-height: 44px; padding: 8px 12px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); color: var(--ink);
  font-size: 14px; font-weight: 600; text-align: left;
}
.outcome-choice.is-danger { color: var(--red); }
.outcome-choice.is-picked { border-color: var(--accent-bg); background: var(--accent-bg); color: var(--accent-ink); }
.outcome-reason, .sheet-help { color: var(--muted); font-size: 13px; }
.sheet-help.is-reason, .confirm-reason.is-reason { color: var(--amber); }
.outcome-confirm { display: flex; flex-direction: column; gap: 8px; padding: 12px 14px; border: 1px solid var(--red); border-radius: 12px; background: var(--red-soft); }
.confirm-intro { color: var(--red); font-size: 13px; font-weight: 600; }
.confirm-box { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 8px; }
.confirm-button {
  min-height: 42px; padding: 0 14px; border: 1px solid var(--red); border-radius: 21px; background: transparent; color: var(--red); font-weight: 700; font-size: 14px;
}
.confirm-button.is-armed { background: var(--red); color: var(--bg); }
.confirm-reason { flex: 1 1 100%; color: var(--muted); font-size: 13px; }
.confirm-hint { color: var(--red); font-size: 13px; }
.sheet-status .confirm-button { border-color: var(--line); color: var(--ink); }
.sheet-status .confirm-button.is-armed { border-color: var(--red); background: var(--red); color: var(--bg); }
.sheet-field { display: flex; flex-direction: column; gap: 4px; }
.sheet-label { color: var(--muted); font-size: 13px; font-weight: 600; }
.client-sheet input:not([type="checkbox"]), .client-sheet select, .client-sheet textarea {
  min-height: 44px; padding: 0 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); color: var(--ink); font-size: 15px; max-width: 100%;
}
.client-sheet textarea { padding: 10px 12px; resize: vertical; min-height: 84px; }
.client-sheet input:focus, .client-sheet select:focus, .client-sheet textarea:focus { border-color: var(--focus); outline: none; }
.sheet-instant-row { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 10px; }
.sheet-inline { flex: 1 1 180px; }
.sheet-check { display: inline-flex; align-items: center; gap: 8px; min-height: 44px; font-size: 14px; }
.sheet-check input { width: 20px; height: 20px; }
.clients-quote-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.sheet-more { border-top: 1px solid var(--line); padding-top: 8px; }
.sheet-more summary { cursor: pointer; min-height: 44px; display: flex; align-items: center; color: var(--muted); font-size: 14px; }
.sheet-more-content { display: flex; flex-direction: column; gap: 14px; padding-top: 6px; }
.sheet-fields { display: grid; gap: 10px; }
.sheet-appointment { display: flex; flex-direction: column; gap: 2px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 12px; }
.clients-call-status, .clients-no-show-status, .clients-final-followup { color: var(--muted); font-size: 13px; }
.clients-info-answers { display: grid; grid-template-columns: minmax(0, 1fr); gap: 2px; margin: 0; font-size: 14px; }
.clients-info-answers dt { color: var(--muted); font-size: 13px; margin-top: 6px; }
.clients-info-answers dd { margin: 0; overflow-wrap: anywhere; }
.clients-history { display: flex; flex-direction: column; gap: 6px; padding-top: 8px; font-size: 13px; }
.clients-info-notes { white-space: pre-wrap; overflow-wrap: anywhere; }
.sheet-message { padding: 0 22px 6px; color: var(--muted); font-size: 13px; }
.sheet-message.is-error { color: var(--red); }
.sheet-foot {
  flex: 0 0 auto; display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding: 12px 22px calc(12px + env(safe-area-inset-bottom));
  background: var(--side); border-top: 1px solid var(--line);
}
.sheet-foot-text, .clients-row-state { flex: 1 1 140px; color: var(--muted); font-size: 14px; }
.clients-row-state.is-error { color: var(--red); }

/* ---------- Numeri · Giornata (classi .daily-* di daily-overview.js) ---------- */
.daily-overview { display: flex; flex-direction: column; gap: 16px; }
.daily-date { color: var(--muted); font-weight: 600; }
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 12px; }
.tile { display: flex; flex-direction: column; gap: 4px; padding: 14px 16px; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; }
.tile-label { color: var(--muted); font-size: 14px; }
.tile-value { font-size: 26px; font-weight: 700; letter-spacing: -.02em; line-height: 1.2; }
.tile-sub { font-size: 15px; font-weight: 600; color: var(--muted); letter-spacing: 0; }
.tile-note { color: var(--muted); font-size: 13px; }
.role-viewer [data-crm-tile] { display: none; }
.source-line { color: var(--muted); font-size: 14px; }
.source-mini b { color: var(--ink); font-weight: 600; }
.source-mini small { font-size: 14px; }
.source-mini i { display: none; }
.daily-status { color: var(--muted); font-size: 14px; min-height: 20px; }
.daily-credit-card { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 12px; padding: 16px 18px; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; }
.daily-credit-card h2 { font-size: 15px; font-weight: 700; }
.daily-credit-card p { color: var(--muted); font-size: 13px; }
.daily-credit-value { display: flex; flex-direction: column; align-items: flex-end; }
.daily-credit-label { color: var(--muted); font-size: 13px; }
.daily-credit-amount { font-size: 22px; font-weight: 700; }
#appRoot:not(.role-admin) .daily-credit-connect { display: none; }
.daily-credit-connect { font-size: 14px; }

/* ---------- Tabelle (Giornata e Campagne): card su telefono ---------- */
.table-wrap { overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.data-table th, .data-table td { padding: 10px 8px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: top; }
.data-table thead th { color: var(--muted); font-weight: 600; font-size: 13px; }
.data-table tbody tr:last-child > * { border-bottom: 0; }
.data-table tbody th { font-weight: 600; }
.data-table tbody th small { display: block; color: var(--muted); font-weight: 400; font-size: 12px; }
.data-table td:not(:first-child):not([colspan]), .daily-campaigns td:not([colspan]) { text-align: right; font-variant-numeric: tabular-nums; }
.data-table thead th:not(:first-child) { text-align: right; }
.data-table.ads-table td:nth-child(2):not([colspan]), .data-table.ads-table thead th:nth-child(2) { text-align: left; }

/* ---------- Landing ---------- */
.landing-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 12px; }
.landing-card { display: flex; flex-direction: column; gap: 12px; }
.landing-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.landing-head h3 { margin: 0; }
.landing-numbers { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin: 0; }
.landing-numbers div, .landing-more div { display: flex; flex-direction: column-reverse; }
.landing-numbers dt, .landing-more dt { color: var(--muted); font-size: 13px; }
.landing-numbers dd { margin: 0; font-size: 22px; font-weight: 700; }
.landing-links { display: flex; flex-wrap: wrap; gap: 6px 16px; font-size: 14px; }
.landing-links a { min-height: 32px; display: inline-flex; align-items: center; }
.more { color: var(--muted); font-size: 14px; }
.landing-more { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; margin: 0 0 8px; }
.landing-more dd { margin: 0; color: var(--ink); }

/* ---------- Automazioni (schedules-panel.js, presentazione compatta) ---------- */
.schedules-view .schedules-heading { display: none; }
.schedules-channel, .schedules-timing, .schedules-footnote { color: var(--muted); font-size: 14px; }
.schedules-channel { display: flex; gap: 6px; flex-wrap: wrap; }
.schedules-channel strong { color: var(--ink); font-weight: 600; }
.schedules-message { color: var(--muted); font-size: 14px; min-height: 20px; }
.schedules-message.is-error { color: var(--amber); }
.schedules-lead-alerts, .schedules-row { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 14px 16px; }
.schedules-lead-alerts { display: flex; flex-direction: column; gap: 8px; }
.schedules-alert-heading, .schedules-identity { display: flex; flex-wrap: wrap; align-items: baseline; gap: 6px 12px; }
.schedules-alert-heading h2, .schedules-identity h2 { font-size: 15px; font-weight: 700; }
.schedules-service { color: var(--muted); font-size: 13px; }
.schedules-alert-details { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: 14px; }
.schedules-alert-sources { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 8px; }
.schedules-alert-source { display: flex; flex-direction: column; color: var(--muted); font-size: 13px; }
.schedules-alert-source strong { color: var(--ink); font-size: 13px; }
.schedules-alert-note, .schedules-row-message, .schedules-observed, .schedules-run-info { color: var(--muted); font-size: 13px; }
.schedules-list { display: flex; flex-direction: column; gap: 8px; }
.schedules-row { display: flex; flex-direction: column; gap: 10px; }
.schedules-actual { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 10px; font-size: 14px; }
.schedules-actual small { color: var(--muted); }
.schedules-state { display: inline-flex; min-height: 24px; align-items: center; padding: 0 9px; border-radius: 12px; background: var(--soft); font-size: 12px; font-weight: 600; }
.schedules-state.is-paused { color: var(--amber); background: var(--amber-soft); }
.schedules-editor { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 10px 14px; }
.schedules-days { display: flex; flex-wrap: wrap; gap: 4px; border: 0; margin: 0; padding: 0; }
.schedules-days legend { color: var(--muted); font-size: 13px; padding: 0 0 4px; }
.schedules-day { position: relative; }
.schedules-day input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.schedules-day span {
  display: inline-flex; align-items: center; justify-content: center; min-width: 44px; min-height: 36px; padding: 0 8px;
  border: 1px solid var(--line); border-radius: 18px; font-size: 13px; color: var(--muted);
}
.schedules-day input:checked + span { background: var(--accent-bg); color: var(--accent-ink); border-color: var(--accent-bg); }
.schedules-day input:focus-visible + span { outline: 2px solid var(--focus); outline-offset: 2px; }
.schedules-day input:disabled + span { opacity: .5; }
.schedules-controls { display: flex; flex-wrap: wrap; gap: 10px; }
.schedules-control-label { display: flex; flex-direction: column; gap: 2px; color: var(--muted); font-size: 13px; }
.schedules-time, .schedules-enabled { min-height: 38px; padding: 0 10px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); color: var(--ink); }
.schedules-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.schedules-submit, .schedules-review { min-height: 40px; padding: 0 16px; border: 0; border-radius: 20px; background: var(--accent-bg); color: var(--accent-ink); font-weight: 700; font-size: 14px; }
.schedules-discard { min-height: 40px; padding: 0 14px; border: 1px solid var(--line); border-radius: 20px; background: transparent; color: var(--ink); font-size: 14px; }
.schedules-draft-state { color: var(--amber); font-size: 13px; }
.schedules-request { display: flex; flex-wrap: wrap; gap: 4px 10px; font-size: 13px; color: var(--muted); }
.schedules-request strong { color: var(--ink); }
.schedules-edit-error { color: var(--amber); }
.schedules-alert-link { font-size: 14px; }

/* ---------- Finestre (<dialog> nativi), menu e avvisi ---------- */
dialog.dialog {
  width: min(520px, calc(100vw - 32px)); max-height: calc(100vh - 48px); padding: 0; overflow: auto;
  border: 1px solid var(--line); border-radius: 16px; background: var(--surface); color: var(--ink); box-shadow: var(--shadow);
}
dialog.dialog::backdrop { background: var(--backdrop); }
.dialog-body { display: flex; flex-direction: column; gap: 12px; padding: 18px 20px 20px; }
.dialog-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.dialog-head h2 { font-size: 18px; font-weight: 700; }
.dialog-body h3 { font-size: 14px; font-weight: 700; margin-top: 4px; }
.dialog-close { width: 40px; height: 40px; border: 0; border-radius: 20px; background: var(--soft); color: var(--ink); font-size: 20px; line-height: 1; }
.source-list { display: flex; flex-direction: column; gap: 10px; margin: 0; }
.source-list dt { font-weight: 600; font-size: 14px; }
.source-list dd { margin: 0; color: var(--muted); font-size: 14px; }
.access-who { display: flex; flex-direction: column; }
.access-who small { color: var(--muted); }
.sheet-list { display: flex; flex-direction: column; }
.toast {
  position: fixed; left: 50%; bottom: 24px; z-index: 50; max-width: calc(100vw - 32px); padding: 10px 16px; border-radius: 12px;
  transform: translateX(-50%); background: var(--accent-bg); color: var(--accent-ink); font-size: 14px; box-shadow: var(--shadow);
  opacity: 0; pointer-events: none;
}
.toast.show { opacity: 1; }
.toast:empty { display: none; }
.dashboard-startup-error { padding: 10px 14px; border-radius: 12px; background: var(--amber-soft); color: var(--amber); font-size: 14px; }

/* ---------- Barra in basso (telefono) ---------- */
.bottom-bar { display: none; }

@media (max-width: 899.98px) {
  .app-shell, html[data-sidebar="collapsed"] .app-shell { grid-template-columns: minmax(0, 1fr); }
  .sidebar { display: none; }
  .topbar { padding: 6px 16px; gap: 8px; }
  .quote-slot { display: none; }
  .refresh-label { font-size: 12px; }
  .refresh-prefix { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; }
  .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .tile { padding: 12px 14px; }
  .tile-value { font-size: 22px; }
  .tile-sub { display: block; font-size: 13px; }
  .data-table.ads-table tr { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .views { padding: 16px 16px calc(80px + env(safe-area-inset-bottom)); }
  .greeting-title { font-size: 24px; }
  .clients-view-tabs { flex-wrap: nowrap; overflow-x: auto; margin: 0 -16px; padding: 0 16px 12px; }
  .clients-toolbar .toolbar-field:not(.toolbar-search) { flex: 1 1 140px; }
  .clients-service-filter, .clients-priority { width: 100%; }
  .lead-card { grid-template-columns: 62px minmax(0, 1fr); padding: 12px 14px; gap: 6px 12px; }
  .lead-action { grid-column: 2; justify-self: start; }
  dialog.client-sheet, dialog.client-sheet:not([data-modal]) { inset: 0; top: 0; width: 100vw; height: 100vh; height: 100dvh; max-height: 100vh; max-height: 100dvh; border-left: 0; }
  .sheet-back { display: inline-flex; align-items: center; }
  .sheet-close { display: none; }
  .sheet-scroll { padding: 10px 16px 20px; }
  .sheet-foot, .sheet-message { padding-left: 16px; padding-right: 16px; }
  .sheet-foot-text { flex-basis: 100%; }
  .bottom-bar {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; display: flex;
    height: calc(56px + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom);
    background: var(--side); border-top: 1px solid var(--line);
  }
  .bottom-bar button {
    flex: 1 1 0; display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 56px;
    border: 0; background: transparent; color: var(--muted); font-size: 14px; font-weight: 600;
  }
  .bottom-bar button[aria-current="page"] { color: var(--ink); font-weight: 700; }
  .bottom-bar .nav-badge { min-width: 20px; height: 20px; font-size: 11px; }
  .toast { bottom: calc(72px + env(safe-area-inset-bottom)); }
  dialog.sheet { width: 100%; max-width: 100%; margin: auto 0 0; border-radius: 16px 16px 0 0; border-bottom: 0; padding-bottom: env(safe-area-inset-bottom); }
  dialog.dialog { max-height: calc(100vh - 24px); }
  .data-table thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0, 0, 0, 0); }
  .data-table, .data-table tbody { display: block; }
  .data-table tr { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px 14px; padding: 12px 0; border-bottom: 1px solid var(--line); }
  .data-table tbody tr:last-child { border-bottom: 0; }
  .data-table th, .data-table td { padding: 0; border: 0; text-align: left; }
  .data-table td:not(:first-child):not([colspan]), .daily-campaigns td:not([colspan]) { text-align: left; }
  .data-table tbody th, .data-table td:first-child, .data-table td[colspan] { grid-column: 1 / -1; }
  .daily-campaigns tbody th + td { grid-column: auto; }
  .data-table td[data-label]::before, .daily-campaigns td:not([colspan])::before { display: block; color: var(--muted); font-size: 12px; }
  .data-table td[data-label]::before { content: attr(data-label); }
  .ads-table td[data-label="Campagna"] { font-weight: 600; }
  .ads-table td[data-label="Campagna"]::before { content: none; }
  .daily-campaigns td:not([colspan]):nth-of-type(1)::before { content: "Spesa"; }
  .daily-campaigns td:not([colspan]):nth-of-type(2)::before { content: "Impression"; }
  .daily-campaigns td:not([colspan]):nth-of-type(3)::before { content: "Clic"; }
  .daily-campaigns td:not([colspan]):nth-of-type(4)::before { content: "Lead Meta"; }
}

/* ---------- Preventivi (dialog esistenti) nella palette della nuova dashboard ---------- */
html[data-theme] .pca-quote-dialog { background: var(--surface); color: var(--ink); border-color: var(--line); box-shadow: var(--shadow); font-family: inherit; }
html[data-theme] .pca-quote-dialog::backdrop { background: var(--backdrop); backdrop-filter: none; }
html[data-theme] .pca-quote-close { background: var(--soft); color: var(--ink); border-radius: 20px; }
html[data-theme] :is(.pca-quote-form input:not([type="file"]), .pca-quote-form select, .pca-chat-dialog textarea, .pca-custom-scope-dialog textarea) { background: var(--bg); color: var(--ink); border-color: var(--line); }
html[data-theme] :is(.pca-quote-form input:focus, .pca-quote-form select:focus, .pca-chat-dialog textarea:focus) { border-color: var(--focus); box-shadow: none; }
html[data-theme] :is(.pca-quote-recipient, .pca-quote-summary, .pca-saved-meta, .pca-upload-drop span, .pca-chat-option-installments, .pca-chat-payment-note, .pca-chat-protected, .pca-chat-client span, .pca-chat-readiness) { color: var(--muted); }
html[data-theme] :is(.pca-quote-generate, .pca-quote-send:not(:disabled), .pca-chat-submit, .pca-chat-export, .pca-custom-scope-confirm:not(:disabled)) { background: var(--accent-bg); color: var(--accent-ink); border-color: var(--accent-bg); }
html[data-theme] :is(.pca-quote-cancel, .pca-quote-workflow button, .pca-saved-actions button, .pca-chat-client, .pca-quote-word, .pca-chat-approve, .pca-quote-technical:not(:disabled), .pca-quote-technical-word:not(:disabled)) { background: var(--surface); color: var(--ink); border-color: var(--line); }
html[data-theme] :is(.pca-saved-technical:not(:disabled), .pca-saved-technical-word:not(:disabled)) { background: var(--surface) !important; color: var(--ink) !important; border-color: var(--line) !important; }
html[data-theme] :is(.pca-quote-workflow, .pca-saved-entry, .pca-chat-preview, .pca-chat-option, .pca-chat-readiness) { border-color: var(--line); }
html[data-theme] :is(.pca-saved-state, .pca-chat-message, .pca-chat-message strong, .pca-chat-field > span, .pca-chat-option-total, .pca-upload-drop) { color: var(--ink); }
html[data-theme] :is(.pca-chat-message, .pca-chat-option, .pca-chat-readiness, .pca-upload-drop) { background: var(--soft); }
html[data-theme] .pca-chat-message-user { background: var(--surface); border-color: var(--line); }
html[data-theme] .pca-upload-drop { border-color: var(--line); }
html[data-theme] :is(.pca-saved-actions a, .pca-upload-preview a, .pca-chat-youtrust) { color: var(--ink); }
html[data-theme] :is(.pca-quote-error, .pca-chat-dialog [aria-invalid="true"]) { color: var(--red); background: var(--red-soft); border-color: var(--red); }
