/* ============================================================
   Look "app": mobile-first, icone morbide stile iOS, colori del logo.
   Caricato DOPO style.css: sovrascrive solo ciò che serve.
   ============================================================ */
:root {
    --brand: #07b762;
    --brand-dark: #04804a;
    --navy: #060c30;
    --blue: #1f3a8a;
    --sun: #f5b82e;
    --cream: #f3f5f9;
    --ink: #101636;
    --muted: #5d6580;
    --line: #e3e7f0;
    --radius: 20px;
    --shadow: 0 1px 2px rgba(6, 12, 48, .06), 0 8px 24px rgba(6, 12, 48, .07);
    --tabbar-h: 64px;
}

body { background: var(--cream); font-size: 16px; line-height: 1.45; -webkit-tap-highlight-color: transparent; }
.container { padding-bottom: calc(var(--tabbar-h) + 28px + env(safe-area-inset-bottom)); }

/* --- Testi e controlli più grandi, adatti al dito --- */
.page-title { font-size: 1.9rem; font-weight: 800; letter-spacing: -.02em; margin: .4rem 0 .25rem; }
.page-sub { color: var(--muted); margin: 0 0 1rem; }
h1 { letter-spacing: -.02em; }
input, select, textarea { font-size: 16px; }  /* 16px: evita lo zoom automatico di iOS */
input:not([type=checkbox]):not([type=radio]), select { min-height: 44px; border-radius: 12px; }
button, .btn-primary, .btn-small { min-height: 44px; border-radius: 12px; font-weight: 600; }
.btn-small { min-height: 40px; }
.card { border-radius: var(--radius); box-shadow: var(--shadow); border: 0; }
.flash { border-radius: 14px; }

/* --- Barra in alto: su telefono solo logo; il menu è la barra in basso --- */
@media (max-width: 859px) {
    .nav-toggle, .nav-links { display: none !important; }
    .topnav { background: var(--navy); border-bottom: 0; }
    .topnav-bar { padding: calc(.55rem + env(safe-area-inset-top)) 1rem .55rem; }
}

/* --- Barra in basso (solo telefono) --- */
.tabbar { display: none; }
@media (max-width: 859px) {
    .tabbar {
        display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
        height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
        padding: 6px 6px env(safe-area-inset-bottom);
        background: rgba(255, 255, 255, .92);
        -webkit-backdrop-filter: saturate(180%) blur(18px); backdrop-filter: saturate(180%) blur(18px);
        border-top: 1px solid var(--line);
    }
    .tabbar a {
        flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
        color: var(--muted); text-decoration: none; border-radius: 14px; font-size: .72rem; font-weight: 600;
    }
    .tabbar .tab-icon { font-size: 1.45rem; line-height: 1; filter: grayscale(.9) opacity(.75); }
    .tabbar a.active { color: var(--brand-dark); background: rgba(7, 183, 98, .12); }
    .tabbar a.active .tab-icon { filter: none; }
}

/* --- Home: intestazione --- */
.home-hero {
    margin: -1rem -1rem 1.1rem; padding: 1.1rem 1.25rem 2.6rem; color: white;
    background:
        radial-gradient(circle at 92% -10%, rgba(7, 183, 98, .65), transparent 55%),
        radial-gradient(circle at 0% 130%, rgba(90, 134, 255, .45), transparent 50%),
        linear-gradient(135deg, var(--navy) 0%, var(--blue) 100%);
    border-radius: 0 0 32px 32px;
}
.home-hero h1 { color: white; font-size: 2.1rem; font-weight: 800; margin: 0; }
.hero-date { margin: 0 0 .2rem; color: rgba(255, 255, 255, .78); font-size: .95rem; text-transform: capitalize; }
@media (min-width: 860px) { .home-hero { margin: 0 0 1.25rem; border-radius: 28px; padding: 1.7rem 2rem; } }

/* --- Home: "Ti stanno aspettando" --- */
.waiting-card {
    background: white; border-radius: var(--radius); box-shadow: var(--shadow);
    margin: -2.1rem 0 1.1rem; position: relative; overflow: hidden;
}
.waiting-card h2 { font-size: .95rem; font-weight: 700; color: var(--muted); margin: 0; padding: .95rem 1.1rem .6rem; }
.count-row {
    display: flex; align-items: center; gap: .9rem; padding: .85rem 1.1rem; min-height: 56px;
    color: var(--ink); text-decoration: none; border-top: 1px solid var(--line);
}
.count-row:active { background: var(--cream); }
.count-num { min-width: 2.2rem; font-size: 1.7rem; font-weight: 800; letter-spacing: -.02em; }
.count-label { flex: 1; font-size: 1.05rem; }
.num-alert { color: #c2410c; } .num-green { color: var(--brand-dark); }
.num-blue { color: var(--blue); } .num-amber { color: #b7791f; }
.count-row.zero .count-num { color: #b4bbcf; }
.count-row.zero .count-label { color: var(--muted); }
.chev { color: #b4bbcf; font-size: 1.6rem; line-height: 1; }

/* --- Elenco di voci con icona (stile schermata iOS) --- */
.app-list { background: white; border-radius: var(--radius); box-shadow: var(--shadow); margin: 0 0 1.1rem; overflow: hidden; }
.app-item {
    display: flex; align-items: center; gap: .95rem; padding: .8rem 1rem; text-decoration: none; color: var(--ink);
    border-top: 1px solid var(--line); min-height: 76px; width: 100%; background: none; text-align: left;
}
.app-item:first-child { border-top: 0; }
.app-item:active { background: var(--cream); }
.app-icon {
    flex: none; width: 54px; height: 54px; border-radius: 15px; display: grid; place-items: center; font-size: 1.7rem;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, .35), 0 3px 8px rgba(6, 12, 48, .18);
}
.app-text { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: .12rem; }
.app-text strong { font-size: 1.12rem; font-weight: 700; letter-spacing: -.01em; }
.app-text small { color: var(--muted); font-size: .88rem; line-height: 1.3; }
.app-item-form { margin: 0; }
.app-item-button { border: 0; border-top: 1px solid var(--line); border-radius: 0; color: var(--ink); font-weight: inherit; cursor: pointer; }
.app-item-button:hover { background: none; }

/* Tonalità: tutte derivate dal logo (verde, navy, blu, giallo) */
.tone-verde  { background: linear-gradient(145deg, #34d98d, #04804a); }
.tone-navy   { background: linear-gradient(145deg, #2c4cb8, #060c30); }
.tone-blu    { background: linear-gradient(145deg, #5a86ff, #1f3a8a); }
.tone-giallo { background: linear-gradient(145deg, #ffd56b, #e59d12); }
.tone-teal   { background: linear-gradient(145deg, #07b762, #1f3a8a); }
.tone-grigio { background: linear-gradient(145deg, #8b93ad, #4b5370); }

/* --- Pagina Prossime azioni --- */
.block { margin: 0 0 1.25rem; }
.block h2 { font-size: 1.25rem; font-weight: 800; letter-spacing: -.01em; margin: 0 0 .55rem; display: flex; align-items: center; gap: .5rem; }
.pill { font-size: .8rem; font-weight: 700; background: var(--ink); color: white; border-radius: 999px; padding: .1rem .55rem; }
.block-alert h2 { color: #c2410c; } .block-alert .pill { background: #c2410c; }
.empty { color: var(--muted); background: white; border-radius: 16px; padding: 1rem; box-shadow: var(--shadow); margin: 0; }
.task-list { display: flex; flex-direction: column; gap: .55rem; }
.task {
    display: flex; align-items: center; gap: .6rem; background: white; border-radius: 16px; padding: .75rem .85rem;
    box-shadow: var(--shadow); text-decoration: none; color: var(--ink); border-left: 5px solid var(--brand);
}
.task-scaduta { border-left-color: #c2410c; }
.task-link { border-left-color: var(--sun); }
.task-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: .1rem; text-decoration: none; color: inherit; }
.task-main strong { font-size: 1.05rem; }
.task-main span { font-size: .92rem; }
.task-main small { color: var(--muted); }
.task-actions { display: flex; align-items: center; gap: .2rem; }
.task-actions form { margin: 0; }

/* Dettagli della card azione: stato, segnalatore, azione, WhatsApp */
.task-meta { display: flex; flex-wrap: wrap; align-items: center; gap: .15rem .55rem; margin: .1rem 0 .15rem; }
.stato-chip { font-size: .78rem; font-weight: 700; background: #eef1f8; color: var(--navy); border-radius: 999px; padding: .12rem .6rem; }
.task-segnalato { font-size: .85rem; color: var(--muted); }
.task-main .task-azione { font-size: 1rem; font-weight: 600; color: var(--brand-dark); }
.task-senza { border-left-color: var(--sun); }
.btn-wa {
    flex: none; display: inline-grid; place-items: center; width: 44px; height: 44px; border-radius: 12px;
    background: #e9faf0; border: 1px solid #bfe9d2; text-decoration: none;
}
.btn-wa img { width: 26px; height: 26px; display: block; }
.btn-apri { display: inline-flex; align-items: center; justify-content: center; text-decoration: none; border-radius: 12px; font-weight: 600; font-size: .9rem; min-height: 44px; }

/* Pulsante "Fatto": cerchio con spunta verde */
.btn-check {
    flex: none; width: 44px; height: 44px; min-height: 44px; padding: 0; border-radius: 50%;
    display: inline-grid; place-items: center; cursor: pointer;
    background: #e9faf0; color: var(--brand-dark); border: 2px solid var(--brand);
}
.btn-check:hover, .btn-check:active { background: var(--brand); color: white; }
.btn-apri {
    display: inline-flex; align-items: center; justify-content: center; padding: 0 1rem; min-height: 40px;
    background: var(--brand); color: white; border-radius: 12px; font-weight: 600; font-size: .9rem; text-decoration: none;
}

/* Telefono: i pulsanti stanno in alto a destra, la card resta bassa e compatta */
@media (max-width: 859px) {
    .task { position: relative; display: block; padding: .7rem .8rem .75rem; }
    .task-main { display: flex; flex-direction: column; gap: .12rem; }
    .task-main strong { padding-right: 9.4rem; min-height: 44px; display: flex; align-items: center; }   /* spazio per i 3 pulsanti */
    .task-actions { position: absolute; top: .55rem; right: .6rem; gap: .35rem; }
    .task-actions .btn-icon-plain { width: 36px; height: 44px; min-height: 44px; padding: 0; }
    .task-senza .task-main strong { padding-right: 7.4rem; }
}

/* --- Banner Stato / chiudi (schede cliente e referral) --- */
.stato-banner { background: white; border-radius: var(--radius); box-shadow: var(--shadow); padding: .9rem 1rem; margin: 0 0 1rem; border-left: 6px solid var(--brand); }
.stato-banner.stato-chiuso { border-left-color: #8b93ad; }
.stato-head { display: flex; align-items: center; justify-content: space-between; gap: .75rem; }
.stato-info { display: flex; align-items: center; gap: .6rem; min-width: 0; }
.stato-label { color: var(--muted); font-size: .85rem; font-weight: 600; }
.stato-pill { font-size: 1.05rem; font-weight: 800; letter-spacing: -.01em; background: #eef1f8; color: var(--navy); border-radius: 999px; padding: .3rem .85rem; white-space: normal; text-align: center; }
.stato-azione { margin: 0; }
.stato-esito { margin: .55rem 0 0; color: var(--ink); }
.stato-esito small { display: block; color: var(--muted); margin-top: .1rem; }
.btn-stato {
    display: inline-flex; align-items: center; justify-content: center; min-height: 44px; padding: 0 1rem;
    border: 2px solid var(--brand); color: var(--brand-dark); background: white; border-radius: 12px;
    font-weight: 700; font-size: .95rem; cursor: pointer; list-style: none; white-space: nowrap;
}
.btn-stato::-webkit-details-marker { display: none; }
.btn-stato:hover { background: #e9faf0; }
.stato-dettagli { margin: 0; }
.stato-dettagli > summary { position: absolute; top: .9rem; right: 1rem; }
.stato-dettagli[open] > summary { background: #e9faf0; }
.stato-banner:has(.stato-dettagli) .stato-head { padding-right: 9.2rem; min-height: 44px; }
.stato-panel { display: grid; gap: 1rem; margin-top: .9rem; padding-top: .9rem; border-top: 1px solid var(--line); }
.stato-campo { display: flex; flex-direction: column; gap: .45rem; margin: 0; }
.stato-campo label { font-weight: 700; font-size: .9rem; }
.stato-campo select, .stato-campo input { width: 100%; border: 1px solid #c9cfdd; box-shadow: none; background: white; padding: 0 .8rem; }
.btn-chiudi { background: white; color: #c2410c; border: 2px solid #e8b9a4; }
.btn-chiudi:hover { background: #fdf0ea; }
.stato-banner { position: relative; }
@media (min-width: 860px) {
    .stato-panel { grid-template-columns: 1fr 1.4fr; gap: 1.75rem; align-items: start; }
    .stato-pill { font-size: 1.15rem; }
}


/* ============================================================
   Pagina Cerca
   ============================================================ */
[hidden] { display: none !important; }

.cerca-form { margin: 0 0 .9rem; }
.cerca-campo {
    display: flex; align-items: center; gap: .5rem; background: white; border-radius: 18px; box-shadow: var(--shadow);
    padding: .4rem .4rem .4rem 1rem; border: 2px solid transparent;
}
.cerca-campo:focus-within { border-color: rgba(7, 183, 98, .55); }
.cerca-icona { font-size: 1.25rem; }
.cerca-campo input[type=search] {
    flex: 1; min-width: 0; border: 0 !important; box-shadow: none !important; background: transparent !important;
    min-height: 46px; padding: 0 .2rem; font-size: 1.05rem; outline: none;
}
.btn-cerca { min-height: 46px; padding: 0 1.2rem; border-radius: 14px; }

.filtri-box { margin: .6rem 0 0; }
.btn-filtri {
    display: inline-flex; align-items: center; gap: .4rem; min-height: 40px; padding: 0 .9rem; cursor: pointer; list-style: none;
    color: var(--ink); background: white; border-radius: 999px; box-shadow: var(--shadow); font-weight: 600; font-size: .92rem;
}
.btn-filtri::-webkit-details-marker { display: none; }
.filtri-badge { background: var(--brand); color: white; border-radius: 999px; font-size: .75rem; padding: .05rem .5rem; }
.filtri-griglia {
    display: grid; gap: .8rem; margin-top: .6rem; padding: 1rem; background: white; border-radius: var(--radius); box-shadow: var(--shadow);
}
.filtri-griglia label { display: flex; flex-direction: column; gap: .3rem; font-weight: 600; font-size: .88rem; }
.filtri-griglia select { width: 100%; border: 1px solid #c9cfdd; background: white; padding: 0 .7rem; }
.filtri-griglia .filtri-check { flex-direction: row; align-items: center; gap: .6rem; font-weight: 500; font-size: .95rem; min-height: 44px; }
.link-reset { color: var(--brand-dark); font-weight: 600; text-decoration: none; padding: .4rem 0; }

.seg-barra { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem .75rem; margin: 1rem 0 .7rem; }
.seg { flex: 1 1 220px; min-width: 0; display: flex; background: #e4e8f1; border-radius: 14px; padding: 3px; gap: 3px; }
.seg-btn {
    flex: 1; min-width: 0; padding: 0 .3rem; min-height: 42px; background: transparent; color: var(--muted); border: 0; border-radius: 11px; font-weight: 700;
    display: inline-flex; align-items: center; justify-content: center; gap: .35rem; font-size: .95rem;
}
.seg-btn b { background: rgba(6, 12, 48, .08); border-radius: 999px; padding: .05rem .55rem; font-size: .8rem; }
.seg-btn.attivo { background: white; color: var(--ink); box-shadow: 0 1px 3px rgba(6, 12, 48, .15); }
.seg-btn.attivo b { background: var(--brand); color: white; }
.seg-btn:hover { background: transparent; }
.seg-btn.attivo:hover { background: white; }
.btn-seleziona { background: transparent; color: var(--brand-dark); border: 0; padding: 0 .4rem; min-height: 44px; }
.btn-seleziona:hover { background: transparent; text-decoration: underline; }

.seleziona-strumenti { background: white; border-radius: var(--radius); box-shadow: var(--shadow); padding: .9rem 1rem; margin: 0 0 .8rem; }
.seleziona-strumenti .rubrica-toolbar { display: flex; flex-direction: column; gap: .5rem; }

.chips-scroll { display: flex; gap: .45rem; overflow-x: auto; margin: 0 -1rem .8rem; padding: .1rem 1rem; scrollbar-width: none; }
.chips-scroll::-webkit-scrollbar { display: none; }
.chips-scroll .chip { flex: none; min-height: 40px; padding: 0 .9rem; border-radius: 999px; background: white; border: 0; box-shadow: var(--shadow); font-weight: 600; font-size: .9rem; color: var(--ink); }
.chips-scroll .chip.chip-active { background: var(--navy); color: white; }

.risultati h2 { font-size: 1.25rem; font-weight: 800; margin: 1.1rem 0 .5rem; display: flex; align-items: center; gap: .5rem; }

.person-list { background: white; border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.person-row {
    display: flex; align-items: center; gap: .8rem; padding: .75rem .9rem; border-top: 1px solid var(--line); cursor: pointer; min-height: 76px;
}
.person-row:first-child { border-top: 0; }
.person-row:active, .person-row:focus-visible { background: var(--cream); }
.person-check { display: none; align-items: center; }
body.modalita-selezione .person-check { display: flex; }
.person-check input { width: 24px; height: 24px; accent-color: var(--brand); }
.avatar {
    flex: none; width: 46px; height: 46px; border-radius: 50%; display: grid; place-items: center; color: white; font-weight: 800; font-size: .95rem; letter-spacing: .02em;
}
.av-referral             { background: linear-gradient(145deg, #a2a9c0, #6c7492); }
.av-contattato           { background: linear-gradient(145deg, #ffd56b, #d9930f); }
.av-appuntamento_fissato { background: linear-gradient(145deg, #5a86ff, #1f3a8a); }
.av-incontrato           { background: linear-gradient(145deg, #2c4cb8, #060c30); }
.av-follow_up            { background: linear-gradient(145deg, #07b762, #1f3a8a); }
.av-cliente              { background: linear-gradient(145deg, #34d98d, #04804a); }
.av-opportunita_attivita { background: linear-gradient(145deg, #34d98d, #1f3a8a); }
.av-chiuso               { background: linear-gradient(145deg, #8b93ad, #4b5370); }
.person-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: .12rem; }
.person-nome { font-size: 1.05rem; font-weight: 700; letter-spacing: -.01em; }
.person-meta { display: flex; flex-wrap: wrap; align-items: center; gap: .15rem .5rem; }
.person-meta .dot { display: inline-flex; align-items: center; gap: .35rem; font-size: .82rem; font-weight: 700; background: transparent; padding: 0; }
.person-meta .dot::before { content: ""; width: .55rem; height: .55rem; border-radius: 50%; background: currentColor; }
.person-meta .dot.stato-grigio { color: #7c849f; }
.person-meta .dot.stato-rosso { color: #c2410c; }
.person-meta .dot.stato-ambra { color: #b7791f; }
.person-meta .dot.stato-verde { color: var(--brand-dark); }
.person-sub { color: var(--muted); font-size: .85rem; }
.person-sub a { color: var(--brand-dark); font-weight: 600; text-decoration: none; }
.person-row .btn-wa { width: 42px; height: 42px; }

@media (min-width: 860px) {
    .filtri-griglia { grid-template-columns: repeat(3, 1fr) auto; align-items: end; }
    .filtri-griglia .link-reset { grid-column: 1 / -1; }
    .seg { max-width: 360px; }
    .seg-barra { justify-content: space-between; }
    .seleziona-strumenti .rubrica-toolbar { flex-direction: row; flex-wrap: wrap; align-items: center; }
    .chips-scroll { margin: 0 0 .8rem; padding: 0; flex-wrap: wrap; overflow: visible; }
    .person-list { display: grid; grid-template-columns: 1fr 1fr; gap: 1px; background: var(--line); }
    .person-row { background: white; border-top: 0; }
    .person-row:hover { background: #f7f9fc; }
}

/* --- Pagine interne: link, titoli, intestazione scheda --- */
.container a:not([class]) { color: var(--brand-dark); text-decoration: none; font-weight: 600; }
.container a:not([class]):hover { text-decoration: underline; }
.back-link {
    display: inline-flex; align-items: center; min-height: 40px; padding: 0 .9rem 0 .7rem; margin: 0 0 .4rem; border-radius: 999px;
    background: white; box-shadow: var(--shadow); color: var(--ink); font-weight: 700; font-size: .92rem; text-decoration: none;
}
.profilo-head { display: flex; align-items: center; gap: .8rem; margin: .3rem 0 1rem; font-size: 1.6rem; font-weight: 800; letter-spacing: -.02em; }
.profilo-nome { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.profilo-azioni { display: flex; gap: .1rem; flex: none; }
.avatar-lg { width: 54px; height: 54px; font-size: 1.1rem; }
.cerca-standalone { margin: 0 0 .9rem; }
.person-attesa { color: #c2410c; font-weight: 600; }
.person-alert { background: #fff8f2; }
.person-row .truncate { max-width: 100%; }

/* --- Card azioni nella scheda, Suggerimenti, ritocchi globali --- */
.task-list-compact { margin-bottom: .8rem; }
.task-compact { box-shadow: none; background: var(--cream); }
.task-compact .task-main small { color: var(--muted); }
.task-conclusa { opacity: .6; border-left-color: #b4bbcf; }
.stato-azione { font-weight: 700; }
.stato-azione.scaduta { color: #c2410c; }
@media (max-width: 859px) { .task-compact .task-main strong { padding-right: 5.6rem; } }
.azione-form { display: grid; grid-template-columns: 1fr 1fr; gap: .5rem; }
.azione-form .span-2 { grid-column: 1 / -1; }
.azione-form input, .azione-form select { width: 100%; min-width: 0; }

.sugg-list { display: flex; flex-direction: column; gap: .8rem; }
.sugg { background: white; border-radius: var(--radius); box-shadow: var(--shadow); padding: .95rem 1rem; display: flex; flex-direction: column; gap: .35rem; }
.sugg-head { display: flex; align-items: center; justify-content: space-between; gap: .6rem; }
.sugg-nome { font-size: 1.1rem; font-weight: 800; color: var(--ink) !important; letter-spacing: -.01em; }
.sugg-meta { color: var(--muted); }
.sugg-testo { margin: .15rem 0 .4rem; padding: .75rem .9rem; background: var(--cream); border-radius: 14px; line-height: 1.45; }
.btn-invia { width: 100%; background: var(--brand); color: white; border: 0; }
@media (min-width: 860px) { .sugg-list { display: grid; grid-template-columns: 1fr 1fr; } .btn-invia { width: auto; padding: 0 1.6rem; } }

.container > h1:not(.profilo-head):not(.page-title) { font-size: 1.9rem; font-weight: 800; letter-spacing: -.02em; margin: .4rem 0 .6rem; }
.container > h2 { font-size: 1.25rem; font-weight: 800; letter-spacing: -.01em; }
.hint { color: var(--muted); }
.persona-card { border: 0 !important; border-radius: var(--radius); box-shadow: var(--shadow); padding: .95rem 1rem; background: white; }
.badge { border-radius: 999px; font-weight: 700; }
.data-table a:not([class]) { color: var(--brand-dark); font-weight: 600; text-decoration: none; }
.data-table th { background: #eef1f8; color: var(--navy); }
.data-table th, .data-table td { padding: .6rem .7rem; }
.stat-box { border: 0 !important; border-radius: var(--radius); box-shadow: var(--shadow); }
.table-responsive { border-radius: var(--radius); }

/* Campi uniformi in tutta l'app */
input:not([type=checkbox]):not([type=radio]):not([type=search]):not([type=file]):not([type=submit]), select, textarea {
    border: 1px solid #c9cfdd; box-shadow: none; background-color: white;
}
input:focus, select:focus, textarea:focus { outline: 3px solid rgba(7, 183, 98, .35); outline-offset: 0; border-color: var(--brand); }

/* Griglie di numeri: su telefono 2 colonne, l'ultimo riquadro dispari occupa tutta la riga */
@media (max-width: 859px) { .stat-grid-3 > :last-child:nth-child(odd) { grid-column: 1 / -1; } }

/* Tabelle che non entrano: diventano card con etichette (vedi script in base.html) */
.data-table.stacked, .data-table.stacked tbody, .data-table.stacked tr, .data-table.stacked td { display: block; width: 100%; }
.data-table.stacked thead { display: none; }
.data-table.stacked tr { background: var(--cream); border-radius: 14px; padding: .55rem .85rem; margin-bottom: .6rem; }
.data-table.stacked td { display: flex; justify-content: space-between; align-items: center; gap: 1rem; border: 0; padding: .3rem 0; text-align: right; white-space: normal; }
.data-table.stacked td::before { content: attr(data-label); color: var(--muted); font-weight: 600; font-size: .85rem; text-align: left; flex: none; }
.data-table.stacked td[data-label=""]::before { display: none; }
.data-table.stacked td[colspan] { display: block; text-align: left; }

/* Testi lunghi (link, URL, note): vanno a capo invece di allargare la pagina o finire tagliati */
.timeline li { overflow-wrap: anywhere; }
.person-sub, .task-main, .sugg-testo, .persona-card, .board-item-testo { overflow-wrap: anywhere; }
@media (max-width: 859px) {
    .truncate { white-space: normal; overflow-wrap: anywhere; max-width: none; text-overflow: clip; }
    .stato-info { flex-wrap: wrap; }
}

/* Slot dell'agenda: a capo se serve, motivo dell'occupato visibile al tocco */
.cella-orari { display: flex; flex-wrap: wrap; gap: .3rem; }
.data-table.stacked td.cella-orari { flex-wrap: wrap; justify-content: flex-end; }
.chip-occupato { cursor: pointer; }
.motivo-slot { flex: 1 1 100%; font-size: .85rem; color: #c2410c; font-weight: 600; margin-top: .2rem; text-align: left; }
select { max-width: 100%; }
code { overflow-wrap: anywhere; }

/* Tasti filtro di Prossime azioni */
.chips-azioni { margin-bottom: 1rem; }
.chips-scroll .chip.chip-alert { color: #c2410c; }
.chips-scroll .chip.chip-alert.chip-active { background: #c2410c; color: white; }

/* ============================================================
   Agenda
   ============================================================ */
.sync-card {
    display: flex; align-items: center; gap: .9rem; background: white; border-radius: var(--radius); box-shadow: var(--shadow);
    padding: .85rem 1rem; margin: 0 0 1rem; border-left: 6px solid var(--blue);
}
.sync-testo { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: .12rem; }
.sync-testo strong { font-size: 1.02rem; }
.sync-testo span { color: var(--muted); font-size: .9rem; }
.sync-testo .sync-avviso { color: #b7791f; font-weight: 600; }
.sync-testo .sync-errore { color: #c2410c; font-weight: 600; }
.btn-sync {
    flex: none; display: inline-flex; align-items: center; gap: .4rem; min-height: 44px; padding: 0 1rem; border-radius: 12px;
    background: var(--brand); color: white; font-weight: 700; font-size: .95rem; text-decoration: none; border: 0; cursor: pointer;
}
.btn-sync:hover { background: var(--brand-dark); }
.btn-sync:disabled { opacity: .7; cursor: progress; }
.btn-sync.in-corso .sync-icona { display: inline-block; animation: gira .8s linear infinite; }
@keyframes gira { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .btn-sync.in-corso .sync-icona { animation: none; } }

.nuovo-app { padding: 0; margin: 0 0 1rem; }
.nuovo-app-titolo {
    display: flex; align-items: center; min-height: 56px; padding: 0 1.1rem; font-weight: 800; font-size: 1.08rem; cursor: pointer;
    list-style: none; color: var(--brand-dark);
}
.nuovo-app-titolo::-webkit-details-marker { display: none; }
.nuovo-app[open] .nuovo-app-titolo { border-bottom: 1px solid var(--line); }
.nuovo-app-form { display: grid; grid-template-columns: 1fr 1fr; gap: .6rem; padding: 1rem 1.1rem .4rem; }
.nuovo-app-form .span-2 { grid-column: 1 / -1; }
.nuovo-app-form input { width: 100%; min-width: 0; }
.nuovo-app .hint { padding: 0 1.1rem 1rem; margin: .4rem 0 0; }

.slot-card h2 { margin: 0 0 .3rem; font-size: 1.25rem; font-weight: 800; }
.slot-card h2 small { font-size: .85rem; font-weight: 600; color: var(--muted); margin-left: .35rem; }
.slot-giorni { display: flex; flex-direction: column; margin-top: .6rem; }
.slot-giorno { display: flex; flex-wrap: wrap; align-items: center; gap: .4rem .8rem; padding: .65rem 0; border-top: 1px solid var(--line); }
.slot-giorno:first-child { border-top: 0; }
.slot-giorno.oggi { background: #f4fbf7; margin: 0 -.5rem; padding-left: .5rem; padding-right: .5rem; border-radius: 12px; }
.slot-etichetta { flex: 0 0 8.6rem; display: flex; flex-direction: column; line-height: 1.2; }
.slot-etichetta small { color: var(--brand-dark); font-weight: 700; }
.slot-giorno .cella-orari { flex: 1; min-width: 12rem; }
.slot-giorno .chip { min-height: 36px; display: inline-flex; align-items: center; padding: 0 .85rem; border-radius: 999px; font-size: .92rem; }
.slot-giorno .motivo-slot { flex-basis: 100%; }

.seg-link { margin: 0 0 1rem; display: flex; }
.seg-link a.seg-btn { text-decoration: none; display: inline-flex; align-items: center; justify-content: center; }
.agenda-nav { display: flex; align-items: center; justify-content: space-between; gap: .6rem; margin: 0 0 .8rem; }
.agenda-nav-titolo { display: flex; flex-direction: column; align-items: center; text-align: center; line-height: 1.25; }
.agenda-nav-titolo strong { font-size: 1.05rem; }
.agenda-nav-titolo a { font-size: .85rem; }
.btn-nav {
    width: 44px; height: 44px; border-radius: 50%; display: grid; place-items: center; background: white; box-shadow: var(--shadow);
    color: var(--ink); font-size: 1.6rem; line-height: 1; text-decoration: none;
}
.card .btn-nav { background: var(--cream); box-shadow: none; }

.vista-periodo h2 { font-size: 1.25rem; font-weight: 800; display: flex; align-items: center; gap: .5rem; margin: .4rem 0 .6rem; }
.app-lista { display: flex; flex-direction: column; gap: .6rem; margin-bottom: 1rem; }
.app-card {
    display: grid; grid-template-columns: auto 1fr; gap: .4rem .9rem; align-items: center; background: white; border-radius: var(--radius);
    box-shadow: var(--shadow); padding: .8rem .9rem; border-left: 5px solid var(--brand);
}
.app-card.app-completato { border-left-color: #8b93ad; }
.app-card.app-annullato, .app-card.app-no_show { border-left-color: #d6a38a; }
.app-card.app-annullato .app-corpo strong { text-decoration: line-through; color: var(--muted); }
.app-data {
    width: 58px; padding: .35rem 0; border-radius: 14px; background: linear-gradient(145deg, #2c4cb8, #060c30); color: white;
    display: flex; flex-direction: column; align-items: center; line-height: 1.1;
}
.app-data b { font-size: 1.35rem; } .app-data span { font-size: .7rem; text-transform: uppercase; letter-spacing: .06em; opacity: .85; }
.app-data small { margin-top: .2rem; font-size: .8rem; font-weight: 700; background: rgba(255, 255, 255, .18); border-radius: 999px; padding: 0 .45rem; }
.app-completato .app-data, .app-annullato .app-data, .app-no_show .app-data { background: linear-gradient(145deg, #a2a9c0, #6c7492); }
.app-corpo { min-width: 0; display: flex; flex-direction: column; gap: .15rem; }
.app-corpo strong { font-size: 1.05rem; overflow-wrap: anywhere; }
.app-con { color: var(--muted); font-size: .9rem; }
.app-azioni { grid-column: 1 / -1; display: flex; align-items: center; gap: .45rem; padding-top: .35rem; border-top: 1px solid var(--line); }
.app-azioni form { margin: 0; }
.btn-icona {
    width: 44px; height: 44px; min-height: 44px; padding: 0; border-radius: 12px; display: inline-grid; place-items: center; text-decoration: none;
    background: var(--cream); color: var(--ink); border: 0; font-size: 1.05rem; cursor: pointer;
}
.btn-icona:hover { background: #e7ebf3; }
.app-azioni form:last-child, .app-azioni > .btn-icona:last-of-type { margin-left: auto; }
.stato-app-programmato { background: #e6efff; color: #1f3a8a; }
.stato-app-completato { background: #e9faf0; color: var(--brand-dark); }
.stato-app-annullato, .stato-app-no_show { background: #fdeee6; color: #c2410c; }
.stato-app-da_chiudere { background: #fff3d6; color: #8a5a00; }
.app-card.app-da-chiudere { border-left-color: var(--sun); }
.app-da-chiudere .app-data { background: linear-gradient(145deg, #ffd56b, #d9930f); color: #4a3200; }
.app-corpo .stato-chip { align-self: flex-start; }
.passati { margin-top: .6rem; }
.passati > summary { display: flex; align-items: center; gap: .5rem; min-height: 48px; font-weight: 800; cursor: pointer; list-style: none; }
.passati > summary::-webkit-details-marker { display: none; }
.passati > summary::before { content: "›"; font-size: 1.4rem; transition: transform .15s; }
.passati[open] > summary::before { transform: rotate(90deg); }

.sett-giorni { display: flex; flex-direction: column; gap: .6rem; }
.sett-giorno { background: white; border-radius: var(--radius); box-shadow: var(--shadow); padding: .7rem .9rem; }
.sett-giorno.oggi { border-left: 5px solid var(--brand); }
.sett-giorno header { display: flex; align-items: center; gap: .5rem; margin-bottom: .2rem; }
.sett-giorno header small { color: var(--brand-dark); font-weight: 700; }
.sett-libero { color: #b4bbcf; font-size: .9rem; }
.sett-app { display: grid; grid-template-columns: auto 1fr; gap: .1rem .7rem; padding: .5rem 0; border-top: 1px solid var(--line); text-decoration: none; color: var(--ink); }
.sett-app b { font-size: 1rem; color: var(--blue); }
.sett-app .stato-chip { grid-column: 2; justify-self: start; }
.sett-app.app-annullato span:first-of-type, .sett-app.app-no_show span:first-of-type { text-decoration: line-through; color: var(--muted); }

.mese-punti { display: none; }
.mese-punti i { display: inline-block; width: 7px; height: 7px; border-radius: 50%; margin: 0 1px; background: var(--brand); }
.mese-punti i.punto-completato { background: #8b93ad; }
.mese-punti i.punto-annullato, .mese-punti i.punto-no_show { background: #d6a38a; }
@media (max-width: 859px) {
    .mese-giorno-evento, .mese-giorno-altri { display: none; }
    .mese-punti { display: flex; justify-content: center; margin-top: .15rem; min-height: 9px; }
    .mese-giorno { min-height: 48px; align-items: center; }
    .mese-giorno.con-app { background: #f4fbf7; }
    .mese-giorno.oggi { outline: 2px solid var(--brand); }
}

.cella-sync { display: flex; flex-direction: column; gap: .1rem; }
.cella-sync small { color: var(--muted); }
.cella-sync .sync-errore { color: #c2410c; font-weight: 600; }
.data-table.stacked .cella-sync { align-items: flex-end; text-align: right; }

/* --- Desktop: stessa larghezza e stessi margini per menu, intestazione e contenuti --- */
@media (min-width: 860px) {
    .topnav { padding-left: max(1.5rem, calc((100% - 1100px) / 2 + 1.5rem)); padding-right: max(1.5rem, calc((100% - 1100px) / 2 + 1.5rem)); }
    .nav-links { gap: 1.05rem; margin-left: 1.1rem; }
    .nav-links a, .nav-dropdown-toggle { white-space: nowrap; font-size: .92rem; }
    .nav-links .nav-cta { padding: .5rem .95rem; }
    .nav-links .nav-icon { margin-right: .25rem; }
    .container { padding-bottom: 2rem; }
    .page-title { font-size: 2.1rem; }

    /* Home: contatori in una riga da 4, voci su due colonne */
    .waiting-card { margin: 0 0 1.25rem; }
    .waiting-card h2 { padding: 1.1rem 1.4rem .7rem; }
    .count-rows { display: grid; grid-template-columns: repeat(4, 1fr); }
    .count-row { flex-direction: column; align-items: flex-start; gap: .1rem; padding: 1rem 1.4rem 1.2rem; border-left: 1px solid var(--line); }
    .count-row:first-child { border-left: 0; }
    .count-row .chev { display: none; }
    .count-num { font-size: 2.6rem; }
    .count-label { flex: none; font-size: 1rem; }

    .app-list { display: grid; grid-template-columns: 1fr 1fr; gap: 1px; background: var(--line); }
    .app-item { background: white; border-top: 0; }
    .app-item:hover, .count-row:hover { background: #f7f9fc; }
    .app-item:last-child:nth-child(odd) { grid-column: 1 / -1; }
    .app-item-form { display: contents; }
    .app-item-button { border-top: 0; }

    .stat-grid-3 { grid-template-columns: repeat(3, 1fr); }

    /* Elenco azioni: due colonne */
    .task-list { display: grid; grid-template-columns: 1fr 1fr; gap: .75rem; }
}

@media (prefers-reduced-motion: no-preference) {
    .app-item, .count-row, .tabbar a { transition: background .15s ease; }
}
:focus-visible { outline: 3px solid rgba(7, 183, 98, .55); outline-offset: 2px; }

/* Schede cliente/referral: ogni riquadro ha il bordo colorato a sinistra come la barra dello stato */
.scheda .card { border-left: 6px solid var(--brand); border-radius: var(--radius); box-shadow: var(--shadow); }
.scheda .card.card-my-wellness { border-left-color: var(--brand-dark); }
/* Storico messaggi comprimibile (chiuso di default, si apre a mano) */
.storico-comprimibile > summary { list-style: none; cursor: pointer; display: flex; align-items: center; justify-content: space-between; gap: .75rem; }
.storico-comprimibile > summary::-webkit-details-marker { display: none; }
.storico-comprimibile > summary h3 { margin: 0; }
.storico-comprimibile > summary::after {
    content: "Mostra"; flex: none; font-size: .85rem; font-weight: 700; color: var(--brand-dark);
    border: 2px solid var(--brand); border-radius: 12px; padding: .3rem .8rem; background: white;
}
.storico-comprimibile[open] > summary::after { content: "Comprimi"; }
.storico-comprimibile[open] > summary { margin-bottom: .75rem; }

/* Ancoraggi sotto la barra dello stato */
html { scroll-behavior: smooth; }
.scheda [id^="sez-"] { scroll-margin-top: 1rem; }
.scheda-nav { display: flex; gap: .45rem; overflow-x: auto; padding: 0 0 .6rem; margin: 0 0 1rem; scrollbar-width: thin; }
.scheda-nav-link {
    flex: none; text-decoration: none; font-weight: 700; font-size: .88rem; color: var(--brand-dark);
    background: white; border: 2px solid var(--brand); border-radius: 999px; padding: .35rem .85rem; white-space: nowrap;
}
.scheda-nav-link:hover { background: #e9faf0; }

/* Pulsante rotondo «torna in cima» (in basso a destra, sopra la barra dei tab sul telefono) */
.vai-in-alto {
    position: fixed; right: 1rem; bottom: 1.25rem; z-index: 40;
    width: 3rem; height: 3rem; min-height: 0; padding: 0; margin: 0; border: 0; border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    background: var(--brand); color: white; cursor: pointer;
    box-shadow: 0 6px 16px rgba(6, 12, 48, .28);
}
.vai-in-alto:hover { background: var(--brand-dark); }
.vai-in-alto[hidden] { display: none; }
@media (max-width: 859px) { .vai-in-alto { bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 1rem); } }
