/* Portale agenti.
   Pensato prima per il telefono e per chi non ama la tecnologia: una sola
   colonna, testi grandi, pulsanti larghi, niente che scorra di lato.
   Nessun file esterno (font, script): tutto è in questa cartella. */

:root {
    --navy-deep: #16203a;
    --navy: #233257;
    --navy-soft: #33456f;
    --sky: #56b0e4;
    --sky-deep: #1f74b8;
    --sky-soft: #e6f3fc;
    --gold: #ffb020;
    --bg: #f1f4f9;
    --card: #ffffff;
    --ink: #131c2e;
    --muted: #5a6880;
    --line: #dde4ee;
    --green: #1a9455;
    --green-deep: #137443;
    --green-soft: #e4f6ec;
    --amber: #b86a00;
    --amber-soft: #fff1d6;
    --red: #c23a2e;
    --red-deep: #a32d23;
    --red-soft: #fdeceb;
    --violet: #4b3a9c;
    --violet-soft: #ece9fb;
    --radius: 18px;
    --radius-sm: 14px;
    --shadow: 0 1px 2px rgba(19, 28, 46, 0.06), 0 8px 24px rgba(19, 28, 46, 0.07);
    --shadow-lift: 0 2px 4px rgba(19, 28, 46, 0.08), 0 14px 34px rgba(19, 28, 46, 0.13);
    --gutter: 16px;
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }

body {
    margin: 0;
    min-height: 100vh;
    min-height: 100dvh;
    background: var(--bg);
    color: var(--ink);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    font-size: 17px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    overflow-wrap: anywhere;
}

a { color: var(--sky-deep); }
h1, h2, p { margin: 0; }
img, svg { display: block; max-width: 100%; }
strong { font-weight: 700; }

.icon { width: 1.25em; height: 1.25em; flex: none; }

.visually-hidden {
    position: absolute; width: 1px; height: 1px; overflow: hidden;
    clip: rect(0 0 0 0); white-space: nowrap;
}

:focus-visible { outline: 3px solid var(--sky); outline-offset: 3px; border-radius: 8px; }

/* ---------- Pagine di lavoro: fascia blu in testa ---------- */

body.is-app { position: relative; display: flex; flex-direction: column; }
body.is-app::before {
    content: "";
    position: absolute; top: 0; left: 0; right: 0; height: 132px; z-index: 0;
    background:
        radial-gradient(120% 90% at 100% 0%, rgba(86, 176, 228, 0.34) 0%, rgba(86, 176, 228, 0) 60%),
        linear-gradient(160deg, var(--navy-deep) 0%, var(--navy) 62%, var(--navy-soft) 100%);
}
body.page-home::before { height: 268px; }
body.page-lead::before { height: 176px; }
body.page-stats::before { height: 206px; }
/* L'agenda non ha un riquadro a cavallo della fascia: la fascia finisce
   subito sotto il titolo, così i titoli dei gruppi stanno sul chiaro. */
body.page-agenda::before { height: 168px; }
body.page-agenda .page-title { margin-bottom: 36px; }

.topbar, .page, .footer { position: relative; z-index: 1; width: 100%; max-width: 720px; margin: 0 auto; }

.topbar { padding: max(12px, env(safe-area-inset-top)) var(--gutter) 8px; }
.topbar-inner { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 44px; }
.brand { display: inline-flex; align-items: center; gap: 10px; color: #fff; text-decoration: none; font-weight: 700; font-size: 17px; letter-spacing: -0.01em; min-width: 0; }
.brand img { height: 30px; width: auto; flex: none; }
.brand span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar-exit { margin: 0; flex: none; }
.exit-btn {
    display: inline-flex; align-items: center; gap: 8px;
    min-height: 44px; padding: 8px 14px;
    font: inherit; font-size: 15px; font-weight: 600; color: #fff;
    background: rgba(255, 255, 255, 0.12); border: 1px solid rgba(255, 255, 255, 0.22);
    border-radius: 999px; cursor: pointer;
}
.exit-btn:hover { background: rgba(255, 255, 255, 0.2); }

.page { flex: 1; padding: 8px var(--gutter) 32px; }

.footer {
    padding: 0 var(--gutter) max(28px, env(safe-area-inset-bottom));
    color: var(--muted); font-size: 14px; text-align: center;
    display: flex; flex-direction: column; gap: 4px;
}

/* ---------- Pulsanti ---------- */

.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 10px;
    min-height: 54px; padding: 12px 22px;
    font: inherit; font-size: 17px; font-weight: 700; line-height: 1.2; text-align: center; text-decoration: none;
    border: 1.5px solid transparent; border-radius: var(--radius-sm); cursor: pointer;
    transition: transform 0.08s ease, box-shadow 0.15s ease, background-color 0.15s ease;
    -webkit-tap-highlight-color: transparent;
}
.btn:active { transform: scale(0.985); }
/* Il testo dei pulsanti va a capo solo tra una parola e l'altra, mai a metà. */
.btn, .badge, .count-chip { overflow-wrap: normal; }
.btn-block { display: flex; width: 100%; }
.btn-primary { background: var(--navy); color: #fff; box-shadow: 0 6px 16px rgba(35, 50, 87, 0.28); }
.btn-primary:hover { background: var(--navy-deep); }
.btn-secondary { background: #fff; color: var(--navy); border-color: var(--line); }
.btn-secondary:hover { border-color: var(--navy-soft); }
.btn-call, .btn-success { background: var(--green); color: #fff; box-shadow: 0 6px 16px rgba(26, 148, 85, 0.3); }
.btn-call:hover, .btn-success:hover { background: var(--green-deep); }
.btn-danger { background: var(--red); color: #fff; box-shadow: 0 6px 16px rgba(194, 58, 46, 0.26); }
.btn-danger:hover { background: var(--red-deep); }
.btn-quiet { background: transparent; color: var(--muted); font-weight: 600; font-size: 16px; min-height: 48px; }
.btn-quiet:hover { color: var(--ink); background: rgba(19, 28, 46, 0.05); }

/* ---------- Campi ---------- */

label { display: block; font-size: 15px; font-weight: 700; color: var(--ink); margin-bottom: 6px; }
.optional, .required { font-weight: 600; font-size: 12px; padding: 2px 8px; border-radius: 999px; margin-left: 6px; vertical-align: 1px; white-space: nowrap; }
.optional { background: #eef1f6; color: var(--muted); }
.required { background: var(--red-soft); color: var(--red-deep); }

input[type="email"], input[type="password"], input[type="search"], input[type="date"], select, textarea {
    display: block; width: 100%; min-width: 0; max-width: 100%;
    min-height: 54px; padding: 13px 14px;
    font: inherit; font-size: 17px; color: var(--ink);
    background: #fff; border: 1.5px solid #cdd6e3; border-radius: var(--radius-sm);
    -webkit-appearance: none; appearance: none;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
input::placeholder, textarea::placeholder { color: #8a96a9; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--sky-deep); box-shadow: 0 0 0 4px rgba(86, 176, 228, 0.28); }
textarea { resize: vertical; min-height: 104px; line-height: 1.45; }
input[type="date"] { line-height: 1.3; text-align: left; }
input[type="date"]::-webkit-date-and-time-value { text-align: left; }
input[type="search"]::-webkit-search-cancel-button { -webkit-appearance: none; }
select {
    padding-right: 44px;
    background-image:
        linear-gradient(45deg, transparent 50%, var(--muted) 50%),
        linear-gradient(135deg, var(--muted) 50%, transparent 50%);
    background-position: calc(100% - 23px) 50%, calc(100% - 17px) 50%;
    background-size: 6px 6px, 6px 6px;
    background-repeat: no-repeat;
}

.stack > * + * { margin-top: 14px; }
.stack > label + * { margin-top: 0; }
.field { min-width: 0; }
.field-pair { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 12px; }

/* ---------- Avvisi ---------- */

.alert {
    display: flex; align-items: flex-start; gap: 12px;
    padding: 14px 16px; margin: 0 0 16px;
    border-radius: var(--radius-sm); font-size: 16px; line-height: 1.4;
    background: #fff; box-shadow: var(--shadow);
    border-left: 5px solid var(--muted);
}
.alert .icon { width: 22px; height: 22px; margin-top: 1px; }
.alert-success { border-left-color: var(--green); }
.alert-success .icon { color: var(--green); }
.alert-error { border-left-color: var(--red); }
.alert-error .icon { color: var(--red); }
.alert-info { border-left-color: var(--sky-deep); }
.alert-info .icon { color: var(--sky-deep); }
.alert-wait { border-left-color: var(--violet); }
.alert-wait .icon { color: var(--violet); }

.hint { color: var(--muted); font-size: 15px; line-height: 1.45; }

/* ---------- Pagine di accesso ---------- */

body.is-auth {
    position: relative; overflow-x: hidden;
    background: linear-gradient(160deg, var(--navy-deep) 0%, var(--navy) 55%, #2f5f9c 130%);
    display: flex; flex-direction: column;
}
.auth-motif { position: absolute; inset: 0; width: 100%; height: 100%; z-index: 0; pointer-events: none; }
.auth-shell {
    position: relative; z-index: 1; flex: 1;
    width: 100%; max-width: 440px; margin: 0 auto;
    padding: max(40px, env(safe-area-inset-top)) var(--gutter) max(32px, env(safe-area-inset-bottom));
    display: flex; flex-direction: column; justify-content: center;
}
.auth-logo { width: 210px; height: auto; margin: 0 auto; }
.auth-tagline {
    margin: 14px auto 26px; padding: 6px 16px;
    color: #fff; font-size: 13px; font-weight: 700; letter-spacing: 0.12em; text-transform: uppercase;
    background: rgba(255, 255, 255, 0.13); border: 1px solid rgba(255, 255, 255, 0.22); border-radius: 999px;
}
.auth-card { background: #fff; border-radius: 24px; padding: 28px 22px 24px; box-shadow: 0 24px 60px rgba(8, 14, 30, 0.45); }
.auth-card h1 { font-size: 27px; font-weight: 800; letter-spacing: -0.02em; line-height: 1.2; margin-bottom: 6px; }
.auth-card h1 + .hint, .auth-card .auth-sub { margin-bottom: 20px; }
.auth-sub { color: var(--muted); font-size: 16px; }
.auth-card h1 + form, .auth-card h1 + .alert { margin-top: 18px; }
.auth-card .alert { box-shadow: none; background: #f6f8fb; }
.auth-card .alert-error { background: var(--red-soft); }
.auth-card .alert-success { background: var(--green-soft); }
.auth-link { margin-top: 20px; text-align: center; font-size: 16px; }
.auth-link a { font-weight: 700; text-decoration: none; padding: 10px 6px; display: inline-block; }
.auth-link a:hover { text-decoration: underline; }
.auth-link-second { margin-top: 2px; font-size: 15px; color: var(--muted); }
.auth-support { margin-top: 22px; text-align: center; font-size: 14px; color: #c9d6ea; }
.auth-support a { color: #fff; font-weight: 600; }

/* ---------- Pagina principale ---------- */

.alert-flash { box-shadow: var(--shadow-lift); }

.hero { color: #fff; padding: 10px 2px 20px; }
.hero-hello { font-size: 17px; font-weight: 600; color: #bcd3ec; }
.hero-title { font-size: 28px; font-weight: 800; letter-spacing: -0.02em; line-height: 1.18; }
.hero-title strong { color: var(--gold); font-weight: 800; }

.tiles { display: grid; gap: 10px; margin-bottom: 22px; }
.tiles-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.tiles-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.tile {
    position: relative; display: flex; flex-direction: column; align-items: flex-start; gap: 0;
    min-height: 108px; padding: 12px 12px 12px;
    background: var(--card); color: var(--muted); text-decoration: none;
    border-radius: var(--radius); box-shadow: var(--shadow); border: 2px solid transparent;
    transition: transform 0.08s ease, box-shadow 0.15s ease;
    -webkit-tap-highlight-color: transparent;
}
.tile:active { transform: scale(0.98); }
.tile-icon {
    display: inline-flex; align-items: center; justify-content: center;
    width: 30px; height: 30px; border-radius: 10px; background: #eef2f7; color: var(--muted);
}
.tile-icon .icon { width: 17px; height: 17px; }
.tile-num { margin-top: 8px; font-size: 30px; font-weight: 800; line-height: 1; letter-spacing: -0.03em; color: var(--ink); font-variant-numeric: tabular-nums; }
.tile-label { margin-top: 5px; font-size: 14px; font-weight: 600; line-height: 1.2; }
.tile.is-active { border-color: var(--sky); box-shadow: var(--shadow-lift); color: var(--navy); }
.tile.is-active .tile-icon { background: var(--navy); color: #fff; }
.tile.is-active .tile-num { color: var(--navy); }
.tile.is-active::after {
    content: ""; position: absolute; left: 50%; bottom: -9px; width: 14px; height: 14px;
    background: var(--card); border-right: 2px solid var(--sky); border-bottom: 2px solid var(--sky);
    transform: translateX(-50%) rotate(45deg); border-bottom-right-radius: 3px;
}

/* Ricerca e filtri: la casella di testo è sempre visibile, gli altri filtri
   stanno in un riquadro che si apre, così l'elenco resta subito sotto. */
.finder { margin-bottom: 18px; }
.searchbar { display: flex; gap: 10px; margin-bottom: 10px; }
.filter-box { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); }
.filter-box[open] { box-shadow: var(--shadow-lift); }
.filter-toggle {
    display: flex; align-items: center; gap: 10px; min-height: 52px; padding: 10px 14px 10px 16px;
    font-size: 16px; font-weight: 700; color: var(--navy); cursor: pointer; list-style: none;
    -webkit-tap-highlight-color: transparent;
}
.filter-toggle::-webkit-details-marker { display: none; }
.filter-toggle > .icon:first-child { color: var(--sky-deep); width: 20px; height: 20px; }
.filter-toggle-text { flex: 1; }
.filter-toggle-arrow { width: 22px; height: 22px; color: #a9b4c5; transform: rotate(90deg); transition: transform 0.15s ease; }
.filter-box[open] .filter-toggle-arrow { transform: rotate(-90deg); }
.filter-box .filters { padding: 4px 16px 16px; }
.count-chip.count-chip-on { background: var(--navy); color: #fff; }

.choice-link { text-decoration: none; margin-bottom: 14px; }
.choice-link .choice-icon { background: var(--navy); color: #fff; }

.page-title { color: #fff; font-size: 26px; font-weight: 800; letter-spacing: -0.02em; line-height: 1.2; margin: 0 2px 18px; }

/* Con quattro sezioni i riquadri vanno due per riga sul telefono (quattro
   in fila sarebbero illeggibili), in una riga sola sugli schermi larghi. */
.tiles-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.tiles-4 .tile { min-height: 96px; }
.tile-badge {
    position: absolute; top: -8px; right: -6px;
    background: var(--gold); color: #3a2600;
    font-size: 13px; font-weight: 800; line-height: 1.2; white-space: nowrap;
    padding: 4px 10px; border-radius: 999px;
    border: 2px solid #fff; box-shadow: 0 4px 12px rgba(255, 176, 32, 0.5);
}
.tile-alert { border-color: var(--gold); }
.tile-alert .tile-icon { background: var(--gold); color: #3a2600; }

.hero-note {
    display: inline-flex; align-items: center; gap: 8px; margin-top: 12px;
    min-height: 40px; padding: 6px 10px 6px 12px;
    color: #fff; font-size: 15px; text-decoration: none;
    background: rgba(255, 255, 255, 0.13); border: 1px solid rgba(255, 255, 255, 0.24); border-radius: 999px;
}
.hero-note strong { color: var(--gold); }
.hero-note .icon { width: 18px; height: 18px; }
.hero-note .icon:last-child { width: 16px; height: 16px; opacity: 0.8; }

.searchbar-field { position: relative; flex: 1; min-width: 0; }
.searchbar-field .icon { position: absolute; left: 15px; top: 50%; width: 20px; height: 20px; margin-top: -10px; color: var(--muted); pointer-events: none; }
.searchbar-field input { padding-left: 44px; box-shadow: var(--shadow); border-color: transparent; }
.searchbar .btn { flex: none; padding-left: 18px; padding-right: 18px; }
.search-active { margin: 0 2px 18px; display: flex; flex-direction: column; gap: 4px; }
.search-active-text { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 8px; font-size: 15px; color: var(--muted); }
.search-active-label { margin-right: 2px; }
.filter-chip { display: inline-flex; align-items: center; background: var(--navy); color: #fff; font-size: 14px; font-weight: 600; line-height: 1.3; border-radius: 999px; padding: 4px 11px; }
.search-active-reset { align-self: flex-start; display: inline-flex; align-items: center; gap: 6px; min-height: 44px; font-size: 16px; font-weight: 700; text-decoration: none; }
.search-active-reset .icon { width: 18px; height: 18px; }

.lead-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.lead-group {
    margin: 10px 2px 0; font-size: 13px; font-weight: 800; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted);
}
.lead-group:first-child { margin-top: 0; }
.lead-card {
    display: flex; align-items: center; gap: 14px;
    padding: 14px 12px 14px 14px;
    background: var(--card); color: inherit; text-decoration: none;
    border-radius: var(--radius); box-shadow: var(--shadow);
    transition: transform 0.08s ease, box-shadow 0.15s ease;
    -webkit-tap-highlight-color: transparent;
}
.lead-card:hover { box-shadow: var(--shadow-lift); }
.lead-card:active { transform: scale(0.99); }
.lead-card-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.lead-card-name { font-size: 18px; font-weight: 700; line-height: 1.25; letter-spacing: -0.01em; }
.lead-card-line { font-size: 15px; color: var(--muted); line-height: 1.35; }
.lead-card-owner { display: inline-flex; align-items: center; gap: 6px; font-size: 14px; font-weight: 600; color: var(--navy-soft); margin-top: 2px; }
.lead-card-owner .icon { width: 15px; height: 15px; }
.lead-card-foot { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; margin-top: 7px; }
.lead-card-date { font-size: 13px; color: var(--muted); }
.lead-card-arrow { width: 22px; height: 22px; color: #a9b4c5; }
.sync-chip { font-size: 13px; font-weight: 600; color: var(--violet); }

.avatar {
    display: inline-flex; align-items: center; justify-content: center; flex: none;
    width: 48px; height: 48px; border-radius: 16px;
    font-size: 17px; font-weight: 800; letter-spacing: 0.01em;
    background: var(--sky-soft); color: var(--sky-deep);
}
.avatar-sm { width: 40px; height: 40px; border-radius: 13px; font-size: 15px; background: #e9edf5; color: var(--navy); }
.avatar-lg { width: 60px; height: 60px; border-radius: 20px; font-size: 21px; }
.avatar-in_trattativa { background: var(--amber-soft); color: var(--amber); }
.avatar-cliente { background: var(--green-soft); color: var(--green-deep); }
.avatar-respinto { background: #eef0f4; color: #7a8598; }

.badge { display: inline-flex; align-items: center; border-radius: 999px; padding: 4px 11px; font-size: 13px; font-weight: 700; line-height: 1.3; }
.badge-lead { background: var(--sky-soft); color: #14588f; }
.badge-in_trattativa { background: var(--amber-soft); color: #8a4f00; }
.badge-cliente { background: var(--green-soft); color: var(--green-deep); }
.badge-respinto { background: var(--red-soft); color: var(--red-deep); }
.badge-pending { background: var(--violet-soft); color: var(--violet); }

.empty { text-align: center; padding: 36px 20px 30px; }
.empty-card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); margin-top: 8px; }
.empty-icon {
    display: inline-flex; align-items: center; justify-content: center;
    width: 64px; height: 64px; border-radius: 22px; background: var(--sky-soft); color: var(--sky-deep); margin-bottom: 14px;
}
.empty-icon .icon { width: 30px; height: 30px; }
.empty-title { font-size: 20px; font-weight: 800; letter-spacing: -0.01em; margin-bottom: 4px; }
.empty-text { color: var(--muted); font-size: 16px; max-width: 32ch; margin: 0 auto; }
.empty .btn { margin-top: 20px; }

/* ---------- Sezioni e riquadri ---------- */

.section { margin-bottom: 26px; }
.section-title { font-size: 21px; font-weight: 800; letter-spacing: -0.015em; line-height: 1.25; margin: 0 2px 4px; }
.section-sub { color: var(--muted); font-size: 15px; margin: 0 2px 14px; }
.section-title + .rows, .section-title + .panel { margin-top: 12px; }
.section-title-list { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.count-chip { font-size: 14px; font-weight: 700; background: #e3e9f2; color: var(--navy); border-radius: 999px; padding: 2px 10px; letter-spacing: 0; }

.panel { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px 16px; margin-bottom: 26px; }
.section > .panel { margin-bottom: 0; }
.panel-title { display: flex; align-items: center; gap: 9px; font-size: 18px; font-weight: 800; letter-spacing: -0.01em; margin-bottom: 14px; }
.panel-title .icon { color: var(--sky-deep); }

.filters { display: flex; flex-direction: column; gap: 14px; }
.filters-actions { display: flex; flex-direction: column; gap: 4px; margin-top: 2px; }

/* ---------- Statistiche della rete ---------- */

.summary {
    display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0;
    background: linear-gradient(150deg, var(--navy-deep), var(--navy) 70%, var(--navy-soft));
    color: #fff; border-radius: var(--radius); padding: 16px 6px; margin-bottom: 12px;
    box-shadow: 0 10px 26px rgba(22, 32, 58, 0.28);
}
.summary-item { display: flex; flex-direction: column; align-items: center; text-align: center; padding: 0 6px; }
.summary-item + .summary-item { border-left: 1px solid rgba(255, 255, 255, 0.16); }
.summary-num { font-size: 28px; font-weight: 800; line-height: 1.1; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.summary-item:nth-child(3) .summary-num { color: var(--gold); }
.summary-label { font-size: 13px; color: #c3d4ea; line-height: 1.25; margin-top: 4px; }

.agent-stats { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.agent-stat {
    display: flex; flex-direction: column; gap: 12px;
    padding: 14px 14px 12px; background: var(--card); color: inherit; text-decoration: none;
    border-radius: var(--radius); box-shadow: var(--shadow);
    -webkit-tap-highlight-color: transparent;
}
.agent-stat:hover { box-shadow: var(--shadow-lift); }
.agent-stat-head { display: flex; align-items: center; gap: 12px; }
.agent-stat-name { flex: 1; min-width: 0; font-size: 17px; font-weight: 700; line-height: 1.25; }
.agent-stat-total { flex: none; font-size: 15px; font-weight: 700; color: var(--navy); background: #edf1f7; border-radius: 999px; padding: 3px 11px; white-space: nowrap; }
.bar { display: block; height: 10px; border-radius: 999px; overflow: hidden; background: #e9edf3; }
.bar svg { width: 100%; height: 100%; }
.legend { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 4px; }
.legend-item { display: flex; flex-direction: column; align-items: flex-start; padding-left: 9px; border-left: 3px solid var(--line); min-width: 0; }
.legend-lead { border-left-color: var(--sky); }
.legend-in_trattativa { border-left-color: #f5a524; }
.legend-cliente { border-left-color: #22a565; }
.legend-respinto { border-left-color: #d6594f; }
.legend-num { font-size: 19px; font-weight: 800; line-height: 1.1; font-variant-numeric: tabular-nums; }
.legend-label { font-size: 12.5px; color: var(--muted); line-height: 1.25; }
.agent-stat-foot { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 4px 12px; padding-top: 10px; border-top: 1px solid var(--line); font-size: 15px; color: var(--muted); }
.agent-stat-foot strong { color: var(--green-deep); font-size: 16px; }
.agent-stat-link { display: inline-flex; align-items: center; gap: 2px; color: var(--sky-deep); font-weight: 700; }
.agent-stat-link .icon { width: 18px; height: 18px; }
.agent-stat-empty { font-size: 15px; color: var(--muted); }

/* ---------- Scheda lead ---------- */

.back-link {
    display: inline-flex; align-items: center; gap: 8px; min-height: 44px; margin-bottom: 8px;
    color: #fff; font-size: 16px; font-weight: 600; text-decoration: none;
}
.back-link:hover { text-decoration: underline; }

.lead-hero { background: var(--card); border-radius: 22px; box-shadow: var(--shadow-lift); padding: 18px 16px; margin-bottom: 18px; }
.lead-hero-top { display: flex; align-items: center; gap: 14px; }
.lead-hero-id { min-width: 0; }
.lead-name { font-size: 23px; font-weight: 800; letter-spacing: -0.02em; line-height: 1.2; }
.lead-company { font-size: 15px; font-weight: 600; color: var(--navy-soft); margin-top: 2px; }
.lead-product { font-size: 15px; color: var(--muted); margin-top: 2px; }

.steps { list-style: none; margin: 18px 0 0; padding: 0; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); }
.step { position: relative; display: flex; flex-direction: column; align-items: center; gap: 6px; text-align: center; }
.step::before { content: ""; position: absolute; top: 15px; right: 50%; width: 100%; height: 3px; background: var(--line); z-index: 0; }
.step:first-child::before { display: none; }
.step.is-done::before, .step.is-current::before { background: var(--green); }
.step-dot {
    position: relative; z-index: 1; display: inline-flex; align-items: center; justify-content: center;
    width: 32px; height: 32px; border-radius: 50%;
    font-size: 14px; font-weight: 800; background: #fff; color: #9aa6b8; border: 3px solid var(--line);
}
.step-dot .icon { width: 16px; height: 16px; stroke-width: 3; }
.step-label { font-size: 13px; font-weight: 600; color: var(--muted); line-height: 1.2; padding: 0 2px; }
.step.is-done .step-dot { background: var(--green); border-color: var(--green); color: #fff; }
.step.is-current .step-dot { background: var(--navy); border-color: var(--navy); color: #fff; box-shadow: 0 0 0 5px rgba(86, 176, 228, 0.3); }
.step.is-current .step-label { color: var(--ink); font-weight: 800; }
.step.is-current:last-child .step-dot { background: var(--green); border-color: var(--green); box-shadow: 0 0 0 5px rgba(26, 148, 85, 0.22); }

.lead-closed { display: flex; align-items: center; gap: 10px; margin-top: 16px; padding: 12px 14px; border-radius: var(--radius-sm); background: var(--red-soft); color: var(--red-deep); font-weight: 700; font-size: 16px; }

.quick-actions { display: grid; grid-template-columns: repeat(auto-fit, minmax(0, 1fr)); gap: 10px; margin-top: 18px; }
.quick-actions .btn { padding-left: 12px; padding-right: 12px; }

.choices { display: flex; flex-direction: column; gap: 10px; }
.choices form { margin: 0; }
.choice {
    display: flex; align-items: center; gap: 14px; width: 100%;
    padding: 14px 12px 14px 14px; min-height: 76px;
    font: inherit; text-align: left; color: var(--ink);
    background: var(--card); border: 0; border-radius: var(--radius); box-shadow: var(--shadow);
    cursor: pointer; list-style: none;
    transition: transform 0.08s ease, box-shadow 0.15s ease;
    -webkit-tap-highlight-color: transparent;
}
.choice::-webkit-details-marker { display: none; }
.choice:hover { box-shadow: var(--shadow-lift); }
.choice:active { transform: scale(0.99); }
.choice-icon { display: inline-flex; align-items: center; justify-content: center; flex: none; width: 48px; height: 48px; border-radius: 16px; background: var(--sky-soft); color: var(--sky-deep); }
.choice-icon .icon { width: 24px; height: 24px; stroke-width: 2.4; }
.choice-text { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 1px; }
.choice-title { font-size: 18px; font-weight: 700; line-height: 1.25; letter-spacing: -0.01em; }
.choice-sub { font-size: 14.5px; color: var(--muted); line-height: 1.3; }
.choice-arrow { width: 22px; height: 22px; color: #a9b4c5; transition: transform 0.15s ease; }
.choice-win .choice-icon { background: var(--green-soft); color: var(--green-deep); }
.choice-lose .choice-icon { background: var(--red-soft); color: var(--red); }
.choice-box { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); }
.choice-box > .choice { box-shadow: none; background: transparent; }
.choice-box[open] { box-shadow: var(--shadow-lift); }
.choice-box[open] .choice-arrow { transform: rotate(90deg); }
.choice-form { padding: 4px 16px 18px; }
.choice-back .choice-icon { background: #eef0f4; color: #6b778b; }
.choice-form .hint { margin-top: 0; }

.alert-with-action { flex-wrap: wrap; }
.alert-with-action > span { flex: 1; min-width: 0; }
.alert-undo { flex: 1 1 100%; margin: 4px 0 0; }
.alert-undo .btn { min-height: 46px; padding: 8px 18px; font-size: 16px; }

.rows { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.row { display: flex; align-items: center; gap: 14px; padding: 14px 14px; color: inherit; text-decoration: none; }
.row + .row { border-top: 1px solid var(--line); }
.row-link:hover { background: #f7f9fc; }
.row-icon { display: inline-flex; align-items: center; justify-content: center; flex: none; width: 42px; height: 42px; border-radius: 14px; background: #eef2f7; color: var(--navy-soft); }
.row-icon .icon { width: 20px; height: 20px; }
.row-text { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.row-label { font-size: 13px; font-weight: 600; color: var(--muted); line-height: 1.3; }
.row-value { font-size: 17px; font-weight: 600; line-height: 1.35; }
.row-value-long { font-size: 15.5px; }
.row-cta { flex: none; font-size: 14px; font-weight: 700; color: var(--sky-deep); background: var(--sky-soft); border-radius: 999px; padding: 7px 13px; }

.thread { display: flex; flex-direction: column; gap: 10px; }
.thread:empty { display: none; }
.thread-empty { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 16px; }
.bubble { max-width: 88%; padding: 11px 14px 9px; border-radius: 18px; }
.bubble-backoffice { align-self: flex-start; background: #eef2f7; border-bottom-left-radius: 6px; }
.bubble-agent { align-self: flex-end; background: var(--navy); color: #fff; border-bottom-right-radius: 6px; }
.bubble-body { font-size: 16.5px; line-height: 1.4; }
.bubble-meta { font-size: 12px; margin-top: 5px; color: var(--muted); }
.bubble-agent .bubble-meta { color: #b9c9e2; }
.composer { margin-top: 18px; padding-top: 18px; border-top: 1px solid var(--line); }
.thread-empty + .thread + .composer { margin-top: 14px; }

/* ---------- Agenda ---------- */

.count-chip.count-chip-alert { background: var(--gold); color: #3a2600; }
.appt-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 12px; }
.appt {
    display: flex; flex-wrap: wrap; gap: 14px; padding: 14px;
    background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
    border: 2px solid transparent;
}
.appt-unseen { border-color: var(--gold); box-shadow: 0 2px 4px rgba(19, 28, 46, 0.06), 0 12px 30px rgba(255, 176, 32, 0.22); }
.appt-date {
    flex: none; width: 62px; align-self: flex-start;
    display: flex; flex-direction: column; align-items: center;
    padding: 8px 4px 9px; border-radius: 16px;
    background: var(--navy); color: #fff; line-height: 1.1;
}
.appt-date-week { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.08em; color: #b9c9e2; }
.appt-date-day { font-size: 26px; font-weight: 800; letter-spacing: -0.02em; margin: 2px 0 1px; font-variant-numeric: tabular-nums; }
.appt-date-month { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.08em; color: var(--gold); }
.appt-past .appt-date { background: #e9edf3; color: var(--navy); }
.appt-past .appt-date-week { color: var(--muted); }
.appt-past .appt-date-month { color: var(--muted); }
.appt-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.appt-flag { align-self: flex-start; font-size: 12px; font-weight: 800; letter-spacing: 0.06em; text-transform: uppercase; border-radius: 999px; padding: 3px 10px; margin-bottom: 3px; }
.appt-flag-new { background: var(--gold); color: #3a2600; }
.appt-flag-changed { background: var(--violet); color: #fff; }
.appt-body > .badge { align-self: flex-start; margin-bottom: 3px; }
.badge-appt-positivo { background: var(--green-soft); color: var(--green-deep); }
.badge-appt-negativo { background: var(--red-soft); color: var(--red-deep); }
.badge-appt-programmato { background: #eef1f6; color: var(--muted); }
.appt-when { display: flex; align-items: center; gap: 7px; font-size: 16px; color: var(--navy-soft); }
.appt-when .icon { width: 18px; height: 18px; color: var(--sky-deep); }
.appt-when strong { font-size: 19px; font-weight: 800; color: var(--ink); letter-spacing: -0.01em; }
.appt-title { margin: 2px 0 0; font-size: 19px; font-weight: 800; line-height: 1.25; letter-spacing: -0.015em; }
.appt-sub { font-size: 15px; color: var(--muted); line-height: 1.35; }
.appt-line { display: flex; align-items: flex-start; gap: 8px; font-size: 15.5px; line-height: 1.35; margin-top: 3px; }
.appt-line .icon { width: 17px; height: 17px; margin-top: 2px; color: var(--navy-soft); }
.appt-note { margin-top: 8px; padding: 10px 12px; border-radius: var(--radius-sm); background: #f3f6fa; font-size: 15.5px; line-height: 1.4; }
.appt-note-label { display: block; font-size: 12px; font-weight: 700; letter-spacing: 0.05em; text-transform: uppercase; color: var(--muted); margin-bottom: 2px; }
.appt-actions { flex: 1 1 100%; display: flex; flex-wrap: wrap; gap: 8px; }
.appt-actions .btn { flex: 1 1 0; min-width: 0; min-height: 48px; padding: 8px 10px; font-size: 15px; gap: 7px; }
.appt-actions .btn .icon { width: 18px; height: 18px; }
.appt-actions .btn-call { flex: 1 1 100%; font-size: 17px; gap: 10px; }
.appt-actions .btn-call .icon { width: 1.25em; height: 1.25em; }
.past-box { margin-bottom: 26px; }
.past-list { padding: 4px 14px 14px; }
.past-list .hint { margin-bottom: 12px; }
.past-list .appt { box-shadow: none; background: #f7f9fc; }

/* ---------- Pulsante "torna su" ----------
   Senza script. Il binario invisibile parte a 1,6 schermate dall'inizio
   della pagina e arriva fin sopra il piè di pagina; il pulsante sta in
   fondo al binario e resta agganciato al bordo basso dello schermo. Finché
   il binario non entra nello schermo (cioè finché non si è scorso di circa
   due terzi di schermata) il pulsante non si vede; da lì in poi accompagna
   la lettura. Su una pagina più corta il binario non ha altezza e il
   pulsante non esiste nemmeno per la tastiera. */
.to-top-track {
    position: absolute; z-index: 5;
    top: 160vh; bottom: 88px;
    right: max(16px, env(safe-area-inset-right));
    width: 54px;
    display: flex; flex-direction: column; justify-content: flex-end;
    pointer-events: none;
    container: totop / size;
}
.to-top {
    position: sticky; bottom: max(18px, env(safe-area-inset-bottom));
    display: flex; align-items: center; justify-content: center; flex: none;
    width: 54px; height: 54px; border-radius: 50%;
    background: var(--navy); color: #fff;
    border: 2px solid rgba(255, 255, 255, 0.9);
    box-shadow: 0 8px 22px rgba(22, 32, 58, 0.34);
    pointer-events: auto;
    transition: transform 0.08s ease, background-color 0.15s ease;
    -webkit-tap-highlight-color: transparent;
}
.to-top .icon { width: 24px; height: 24px; stroke-width: 2.4; }
.to-top:hover { background: var(--navy-deep); }
.to-top:active { transform: scale(0.94); }
.to-top:focus-visible { outline: 3px solid var(--sky); outline-offset: 3px; border-radius: 50%; }
@container totop (max-height: 53px) {
    .to-top { display: none; }
}
/* Browser molto vecchi, che non sanno misurare il binario: niente pulsante,
   piuttosto che un pulsante che allunga le pagine corte. */
@supports not (container-type: size) {
    .to-top-track { display: none; }
}
@media (min-width: 900px) {
    .to-top-track { right: calc(50% - 360px - 78px); }
}
@media (prefers-reduced-motion: no-preference) {
    html { scroll-behavior: smooth; }
}

/* ---------- Schermi larghi e accessibilità ---------- */

@media (min-width: 560px) {
    :root { --gutter: 24px; }
    .hero-title { font-size: 34px; }
    .page-title { font-size: 32px; }
    .tile { min-height: 116px; padding: 16px; }
    .tiles-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
    .tiles-4 .tile { min-height: 116px; }
    .appt-date { width: 72px; }
    body.page-agenda::before { height: 182px; }
    .appt-actions .btn-call { flex: 1 1 0; }
    .tile-num { font-size: 36px; }
    .tile-label { font-size: 16px; }
    .filters-actions { flex-direction: row; }
    .filters-actions .btn { flex: 1; }
    .auth-card { padding: 34px 32px 30px; }
    .auth-logo { width: 240px; }
    .lead-name { font-size: 28px; }
    .legend-label { font-size: 13.5px; }
    .bubble { max-width: 74%; }
}

@media (max-width: 359px) {
    body { font-size: 16px; }
    .tile-label { font-size: 13px; }
    .hero-title { font-size: 25px; }
    .legend { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px 4px; }
    .brand span { display: none; }
    .field-pair { grid-template-columns: minmax(0, 1fr); }
    .appt { gap: 12px; padding: 12px; }
    .appt-date { width: 54px; }
    .appt-date-day { font-size: 23px; }
    .appt-actions .btn { flex: 1 1 100%; }
    .quick-actions { grid-template-columns: minmax(0, 1fr); }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { transition: none !important; }
}
