/*
 * ACV Triggiano — BI, shared visual theme.
 * Palette and component language matched to the Minia admin template
 * reference the client provided (violet primary, light lavender surfaces,
 * pill badges, soft-shadow cards). Every view links this file and keeps
 * only markup it truly needs of its own.
 */

:root {
    --font-sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    --primary: #7367f0;
    --primary-dark: #5e50ee;
    --primary-light: #eeedfc;
    --bg-page: #f7f7fb;
    --surface: #ffffff;
    --border: #ebe9f1;
    --text: #33334d;
    --text-muted: #6e6b7b;
    --text-faint: #b9b6c3;
    --success: #28c76f;
    --success-bg: #e0f8ea;
    --warning: #ff9f43;
    --warning-bg: #fff1e2;
    --danger: #ea5455;
    --danger-bg: #fde3e3;
    --info: #00a8c6;
    --info-bg: #e0f6fa;
    --radius-card: 14px;
    --radius-control: 8px;
    --shadow-card: 0 4px 18px rgba(31, 45, 61, 0.06);
}

* {
    box-sizing: border-box;
}

body {
    font-family: var(--font-sans);
    background: var(--bg-page);
    margin: 0;
    color: var(--text);
}

h1, h2, h3, h4 {
    color: var(--text);
    font-weight: 600;
}

a {
    color: var(--primary);
}

/* App shell: fixed sidebar + content area that fills the rest of the
   viewport. No centered max-width — pages use all available width. */

.app-shell {
    display: flex;
    align-items: stretch;
    min-height: 100vh;
}

.content-area {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
}

main {
    flex: 1;
    padding: 28px;
    width: 100%;
    box-sizing: border-box;
}

/* Sidebar */

.sidebar {
    width: 250px;
    flex-shrink: 0;
    background: var(--surface);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
    z-index: 100;
}

.sidebar-brand {
    padding: 22px 24px;
    font-weight: 700;
    color: var(--primary);
    font-size: 16px;
    letter-spacing: 0.2px;
    border-bottom: 1px solid var(--border);
}

.sidebar-nav {
    flex: 1;
    padding: 16px 12px;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.sidebar-nav a {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 14px;
    border-radius: var(--radius-control);
    color: var(--text-muted);
    text-decoration: none;
    font-size: 14px;
    font-weight: 500;
    transition: background 0.15s, color 0.15s;
}

.sidebar-nav a svg {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
}

.sidebar-nav a:hover {
    background: var(--primary-light);
    color: var(--primary);
}

.sidebar-nav a.active {
    background: var(--primary);
    color: #fff;
}

.sidebar-user {
    padding: 16px 22px;
    border-top: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    font-size: 13px;
    color: var(--text-muted);
}

.sidebar-user span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.sidebar-user a {
    color: var(--text-muted);
    display: flex;
    flex-shrink: 0;
}

.sidebar-user a svg {
    width: 18px;
    height: 18px;
}

.sidebar-user a:hover {
    color: var(--danger);
}

/* Mobile topbar + overlay: hidden on desktop, shown under the breakpoint */

.mobile-topbar {
    display: none;
}

.sidebar-overlay {
    display: none;
}

@media (max-width: 900px) {
    .sidebar {
        position: fixed;
        left: 0;
        top: 0;
        transform: translateX(-100%);
        transition: transform 0.2s ease;
        box-shadow: 4px 0 24px rgba(20, 18, 40, 0.15);
    }

    .sidebar.open {
        transform: translateX(0);
    }

    .mobile-topbar {
        display: flex;
        align-items: center;
        gap: 12px;
        background: var(--surface);
        border-bottom: 1px solid var(--border);
        padding: 12px 16px;
        position: sticky;
        top: 0;
        z-index: 60;
    }

    .mobile-topbar button {
        background: none;
        padding: 6px;
        color: var(--text);
        box-shadow: none;
        line-height: 0;
    }

    .mobile-topbar button:hover {
        background: var(--primary-light);
        box-shadow: none;
    }

    .mobile-topbar button svg {
        width: 22px;
        height: 22px;
    }

    .mobile-topbar strong {
        color: var(--primary);
        font-size: 15px;
    }

    .sidebar-overlay.open {
        display: block;
        position: fixed;
        inset: 0;
        background: rgba(20, 18, 40, 0.4);
        z-index: 90;
    }

    main {
        padding: 18px;
    }
}

/* Cards: `.box`, `.card`, `.grafico-box` are three names already in use
   across pages for the same visual treatment — unified here rather than
   renamed in markup, to keep this a styling pass, not a template rewrite. */

.box,
.card,
.grafico-box {
    background: var(--surface);
    border-radius: var(--radius-card);
    box-shadow: var(--shadow-card);
    padding: 22px;
}

.card .value {
    font-size: 26px;
    font-weight: 700;
    color: var(--text);
    overflow-wrap: break-word;
}

.card .label {
    font-size: 13px;
    color: var(--text-muted);
    margin-top: 2px;
}

.card .sub {
    font-size: 12px;
    color: var(--text-faint);
    margin-top: 4px;
}

.cards {
    display: flex;
    gap: 18px;
    flex-wrap: wrap;
    margin-bottom: 24px;
}

.cards .card {
    min-width: 180px;
    flex: 1;
}

.grafici {
    display: flex;
    gap: 18px;
    flex-wrap: wrap;
    margin-bottom: 24px;
}

.grafico-box {
    flex: 1;
    min-width: 400px;
}

.grafico-box h3 {
    margin-top: 0;
    font-size: 15px;
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 12px;
}

.grafico-box h3 .esporta-dati {
    font-size: 12px;
    font-weight: 500;
    color: var(--primary);
    text-decoration: none;
    white-space: nowrap;
}

.grafico-box h3 .esporta-dati:hover {
    text-decoration: underline;
}

/* Buttons */

.btn,
button,
input[type="submit"] {
    display: inline-block;
    padding: 9px 18px;
    background: var(--primary);
    color: #fff;
    border: none;
    border-radius: var(--radius-control);
    cursor: pointer;
    text-decoration: none;
    font-family: inherit;
    font-size: 14px;
    font-weight: 500;
    white-space: nowrap;
    transition: background 0.15s, box-shadow 0.15s;
}

.btn:hover,
button:hover,
input[type="submit"]:hover {
    background: var(--primary-dark);
    box-shadow: 0 4px 12px rgba(115, 103, 240, 0.35);
}

.btn-secondary {
    background: var(--text-muted);
}

.btn-secondary:hover {
    background: var(--text);
    box-shadow: none;
}

/* Forms */

label {
    display: block;
    font-size: 13px;
    margin-bottom: 4px;
    color: var(--text-muted);
}

input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
input[type="date"],
select,
textarea {
    width: 100%;
    padding: 9px 12px;
    box-sizing: border-box;
    border: 1px solid var(--border);
    border-radius: var(--radius-control);
    font-family: inherit;
    font-size: 14px;
    color: var(--text);
    background: var(--surface);
}

input:focus,
select:focus,
textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-light);
}

/* Tables */

table {
    width: 100%;
    border-collapse: collapse;
    background: var(--surface);
    border-radius: var(--radius-card);
    overflow: hidden;
    box-shadow: var(--shadow-card);
}

th, td {
    padding: 12px 16px;
    text-align: left;
    border-bottom: 1px solid var(--border);
    font-size: 14px;
    overflow-wrap: anywhere;
}

th {
    background: var(--bg-page);
    font-size: 12px;
    color: var(--text-muted);
    font-weight: 600;
}

tbody tr:hover {
    background: #fbfaff;
}

tbody tr:last-child td {
    border-bottom: none;
}

/* Tabella ordinabile/filtrabile lato browser (vedi tabella-interattiva.js):
   intestazioni cliccabili + riga di input di filtro per colonna. Usata da
   Clienti e dalla gestione gruppi newsletter. */

table.tabella-ordinabile th.ordinabile { cursor: pointer; user-select: none; white-space: nowrap; }
table.tabella-ordinabile th.ordinabile:hover { color: var(--primary); }
table.tabella-ordinabile th.ordinabile .freccia { display: inline-block; width: 12px; opacity: 0.4; }
table.tabella-ordinabile th.ordinabile.attivo .freccia { opacity: 1; color: var(--primary); }
table.tabella-ordinabile .riga-filtri th { padding: 6px 16px 10px; background: var(--surface); }
table.tabella-ordinabile .riga-filtri input { padding: 6px 8px; font-size: 13px; }

/* Indicatore di ordinamento in corso: su tabelle con molte righe il sort
   sincrono impiega un istante percepibile — senza feedback la pagina
   sembra bloccata e invita a ricliccare. thead in attesa + freccia che
   gira segnalano che il sistema sta lavorando. */
table.tabella-ordinabile.in-ordinamento thead { cursor: wait; opacity: 0.6; }
table.tabella-ordinabile.in-ordinamento th.ordinabile { pointer-events: none; }

table.tabella-ordinabile th.ordinabile .freccia.freccia-caricamento {
    width: 10px;
    height: 10px;
    opacity: 1;
    border: 2px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: freccia-gira 0.6s linear infinite;
    vertical-align: middle;
}

@keyframes freccia-gira {
    to { transform: rotate(360deg); }
}

/* Tabelle responsive: sotto una certa larghezza ogni riga diventa una
   scheda impilata (etichetta + valore) invece di scorrere di lato.
   Le tabelle che non sono liste di dati regolari (griglia oraria della
   heatmap) sono escluse via .tabella-scorrevole, che invece riceve uno
   scroll orizzontale confinato al proprio riquadro. */

@media (max-width: 680px) {
    table:not(.tabella-scorrevole):not(.tabella-lista) {
        box-shadow: none;
        background: transparent;
        overflow: visible;
    }

    table:not(.tabella-scorrevole):not(.tabella-lista) thead {
        display: none;
    }

    table:not(.tabella-scorrevole):not(.tabella-lista),
    table:not(.tabella-scorrevole):not(.tabella-lista) tbody,
    table:not(.tabella-scorrevole):not(.tabella-lista) tr,
    table:not(.tabella-scorrevole):not(.tabella-lista) td {
        display: block;
        width: 100%;
    }

    table:not(.tabella-scorrevole):not(.tabella-lista) tr {
        background: var(--surface);
        border-radius: var(--radius-card);
        box-shadow: var(--shadow-card);
        margin-bottom: 12px;
        overflow: hidden;
    }

    table:not(.tabella-scorrevole):not(.tabella-lista) td {
        display: flex;
        justify-content: space-between;
        align-items: center;
        gap: 12px;
        text-align: right;
        border-bottom: 1px solid var(--border);
    }

    table:not(.tabella-scorrevole):not(.tabella-lista) td:last-child {
        border-bottom: none;
    }

    table:not(.tabella-scorrevole):not(.tabella-lista) td::before {
        content: attr(data-etichetta);
        text-align: left;
        font-size: 12px;
        font-weight: 600;
        color: var(--text-muted);
        flex-shrink: 0;
    }

    table:not(.tabella-scorrevole):not(.tabella-lista) td:empty {
        display: none;
    }
}

.tabella-scorrevole-contenitore {
    overflow-x: auto;
}

.azioni a {
    margin-right: 12px;
    font-size: 13px;
    text-decoration: none;
}

/* Piu' pulsanti .btn nella stessa cella di tabella (es. "Apri scheda" +
   "Dettaglio" nelle liste clienti dei segmenti e di Clienti a rischio). */
td .btn + .btn {
    margin-left: 8px;
}

.azioni a:hover {
    text-decoration: underline;
}

/* Badges — pill-shaped status labels, Minia's invoice-status look */

.badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 600;
    background: var(--bg-page);
    color: var(--text-muted);
}

.badge.urgente,
.badge.disattivato {
    background: var(--danger-bg);
    color: var(--danger);
}

.badge.attivo {
    background: var(--success-bg);
    color: var(--success);
}

/* Toolbars, back-links, misc */

.toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 18px;
    gap: 12px;
}

.torna {
    display: inline-block;
    margin-bottom: 16px;
    font-size: 13px;
    text-decoration: none;
    color: var(--text-muted);
}

.torna:hover {
    color: var(--primary);
}

.hint {
    background: var(--primary-light);
    border-left: 3px solid var(--primary);
    padding: 10px 14px;
    margin-top: 12px;
    font-size: 12.5px;
    line-height: 1.5;
    color: var(--text-muted);
    border-radius: 0 8px 8px 0;
}

.hint b {
    color: var(--text);
}

.alert {
    background: var(--success-bg);
    border: 1px solid #b8ecce;
    color: #1f7a45;
    padding: 12px 16px;
    border-radius: var(--radius-control);
    margin-bottom: 18px;
    font-size: 14px;
}

.alert.alert-errore {
    background: var(--danger-bg);
    border-color: rgba(234, 84, 85, 0.35);
    color: var(--danger);
}

.riepilogo-filtri {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    align-items: center;
    margin-bottom: 24px;
    font-size: 13px;
    color: var(--text-muted);
}

.riepilogo-filtri .filtro-attivo {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: 5px 14px;
}

.riepilogo-filtri .filtro-attivo strong {
    color: var(--text);
}

.riepilogo-filtri .azzera-filtri {
    color: var(--danger);
    text-decoration: none;
    font-size: 13px;
    margin-left: 4px;
}

.riepilogo-filtri .azzera-filtri:hover {
    text-decoration: underline;
}

form.filtri {
    background: var(--surface);
    padding: 18px;
    border-radius: var(--radius-card);
    box-shadow: var(--shadow-card);
    display: flex;
    gap: 12px;
    align-items: stretch;
    margin-bottom: 24px;
}

form.filtri .filtri-righe {
    display: flex;
    flex-direction: column;
    gap: 12px;
    flex: 1;
}

form.filtri .filtri-riga {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
    align-items: flex-end;
}

form.filtri .filtri-riga > div,
form.filtri > div {
    display: flex;
    flex-direction: column;
}

/* Galleria "Nuovo segmento": card informative con nome regola, come
   funziona e obiettivo di marketing, prima del modulo con i parametri. */

.griglia-segmenti {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 18px;
}

.card-segmento {
    display: flex;
    flex-direction: column;
    background: var(--surface);
    border-radius: var(--radius-card);
    box-shadow: var(--shadow-card);
    padding: 22px;
}

.card-segmento h3 {
    margin: 0 0 10px;
    font-size: 16px;
}

.card-segmento p {
    margin: 0 0 12px;
    font-size: 13.5px;
    line-height: 1.5;
    color: var(--text-muted);
}

.card-segmento p.obiettivo {
    color: var(--text);
}

.card-segmento p.obiettivo b {
    color: var(--primary);
}

.card-segmento .btn {
    margin-top: auto;
    text-align: center;
}

/* Editor HTML minimale per il corpo dei messaggi in bacheca: barra
   comandi + area contenteditable via document.execCommand, senza
   librerie esterne — sufficiente per un messaggio semplice (grassetto,
   corsivo, elenchi, link), coerente con la scelta di non aggiungere
   dipendenze da CDN esterni nel resto dell'app. */

.editor-toolbar {
    display: flex;
    gap: 4px;
    flex-wrap: wrap;
    padding: 6px;
    border: 1px solid var(--border);
    border-bottom: none;
    border-radius: var(--radius-control) var(--radius-control) 0 0;
    background: var(--bg-page);
}

.editor-toolbar button {
    background: none;
    color: var(--text);
    box-shadow: none;
    padding: 6px 10px;
    font-size: 13px;
    font-weight: 600;
    margin: 0;
}

.editor-toolbar button:hover {
    background: var(--primary-light);
    color: var(--primary);
    box-shadow: none;
}

.editor-corpo {
    width: 100%;
    min-height: 160px;
    padding: 12px;
    box-sizing: border-box;
    border: 1px solid var(--border);
    border-radius: 0 0 var(--radius-control) var(--radius-control);
    font-family: inherit;
    font-size: 14px;
    line-height: 1.5;
    color: var(--text);
    background: var(--surface);
}

.editor-corpo:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-light);
}

.editor-corpo ul,
.editor-corpo ol {
    padding-left: 22px;
    margin: 8px 0;
}

/* Griglia a blocchi (es. scheda cliente): due colonne su desktop/tablet,
   una sola su mobile — stessa soglia di 680px usata per lo stacking delle
   tabelle, cosi' i due comportamenti responsive scattano insieme. */

.griglia-blocchi {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 20px;
    align-items: start;
}

/* Un blocco "alto" occupa 2 righe cosi' la colonna accanto puo' impilarci
   due blocchi piu' bassi (es. scheda cliente: dati anagrafici alti quanto
   "Accesso al portale" + "Invia password" impilati). */
.griglia-blocchi .blocco-alto {
    grid-row: span 2;
}

@media (max-width: 680px) {
    .griglia-blocchi {
        grid-template-columns: 1fr;
    }

    .griglia-blocchi .blocco-alto {
        grid-row: auto;
    }
}

/* Tab (es. gestione gruppo newsletter: sezioni Clienti associati /
   Aggiungi segmento / Aggiungi cliente sotto lo stesso box dati gruppo) */

.tab-nav {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    border-bottom: 1px solid var(--border);
    margin-bottom: 20px;
}

.tab-nav button {
    background: none;
    color: var(--text-muted);
    border-radius: var(--radius-control) var(--radius-control) 0 0;
    box-shadow: none;
    padding: 10px 18px;
    font-weight: 600;
    white-space: normal;
    border-bottom: 2px solid transparent;
    margin-bottom: -1px;
}

.tab-nav button:hover {
    background: var(--primary-light);
    box-shadow: none;
    color: var(--primary);
}

.tab-nav button.attivo {
    color: var(--primary);
    border-bottom-color: var(--primary);
}

.tab-pannello {
    display: none;
}

.tab-pannello.attivo {
    display: block;
}

/* Popup di dettaglio cliente, aperto dal tab "Clienti associati" */

dialog.popup-dettaglio {
    border: none;
    border-radius: var(--radius-card);
    box-shadow: var(--shadow-card);
    padding: 22px;
    width: min(560px, 92vw);
    max-height: 85vh;
    overflow-y: auto;
}

dialog.popup-dettaglio::backdrop {
    background: rgba(15, 12, 41, 0.45);
}

dialog.popup-dettaglio .popup-intestazione {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 14px;
}

dialog.popup-dettaglio .popup-intestazione h3 {
    margin: 0;
}

dialog.popup-dettaglio .popup-chiudi {
    background: none;
    color: var(--text-muted);
    box-shadow: none;
    padding: 4px 10px;
    font-size: 20px;
    line-height: 1;
}

dialog.popup-dettaglio .popup-chiudi:hover {
    background: var(--bg-page);
    box-shadow: none;
    color: var(--text);
}

dialog.popup-dettaglio table {
    box-shadow: none;
    border-radius: 0;
}

form.filtri button {
    align-self: stretch;
}
