/* ==========================================================================
   Tema: bianco / rosso ABB / viola
   ========================================================================== */
:root {
    --red: #FF000F;
    --red-dark: #C8000C;
    --purple: #5B21B6;
    --purple-mid: #7C3AED;
    --purple-light: #EDE9FE;
    --purple-soft: #F7F4FE;
    --ink: #1F1235;
    --text: #3A3450;
    --muted: #7A7490;
    --line: #E4DFF2;
    --bg: #FAF9FD;
    --white: #FFFFFF;
    --radius: 14px;
    --shadow: 0 6px 24px rgba(59, 7, 100, .08);
    --shadow-sm: 0 2px 8px rgba(59, 7, 100, .06);
}

* { box-sizing: border-box; }

body {
    font-family: 'Poppins', sans-serif;
    background: var(--bg);
    color: var(--text);
    margin: 0;
}
main { max-width: 1320px; margin: 0 auto; padding: 24px 32px 48px; }
body.home main { max-width: none; padding: 0; }

h1, h2, h3 { color: var(--ink); line-height: 1.2; }
h2 { font-size: 19px; margin: 0 0 16px; }
a { color: var(--purple); text-decoration: none; }
a:hover { text-decoration: underline; }
.muted { color: var(--muted); font-size: 14px; }

/* Header -------------------------------------------------------------- */
.site-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 14px 32px;
    background: var(--white);
    border-bottom: 1px solid var(--line);
    position: sticky;
    top: 0;
    z-index: 20;
}
.logo { height: 38px; width: auto; display: block; }
.site-header nav { display: flex; gap: 6px; }
.site-header nav a {
    padding: 8px 14px;
    border-radius: 999px;
    color: var(--text);
    font-weight: 500;
}
.site-header nav a:hover { background: var(--purple-soft); text-decoration: none; }
.site-header nav a.active { background: var(--purple-light); color: var(--purple); }

/* Pulsanti ------------------------------------------------------------- */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-family: inherit;
    font-size: 14px;
    font-weight: 600;
    padding: 10px 20px;
    border-radius: 999px;
    border: 1px solid transparent;
    cursor: pointer;
    transition: transform .15s, box-shadow .15s, background .15s;
}
.btn:hover { text-decoration: none; transform: translateY(-1px); }
.btn-primary {
    background: linear-gradient(90deg, var(--red), var(--purple-mid));
    color: #fff;
    box-shadow: 0 6px 18px rgba(124, 58, 237, .28);
}
.btn-primary:hover { box-shadow: 0 10px 26px rgba(124, 58, 237, .36); }
.btn-ghost { background: var(--white); color: var(--purple); border-color: var(--line); }
.btn-ghost:hover { background: var(--purple-soft); }
.btn-lg { font-size: 17px; padding: 15px 30px; }

/* Home: hero ------------------------------------------------------------ */
.hero {
    position: relative;
    overflow: hidden;
    min-height: calc(100vh - 67px);
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    background: linear-gradient(180deg, #FFFFFF 0%, #FBF9FF 55%, #F3EEFE 100%);
}
.hero-glow { position: absolute; inset: 0; pointer-events: none; }
.glow { position: absolute; border-radius: 50%; filter: blur(70px); opacity: .35; }
.glow-red { width: 420px; height: 420px; background: #FF5A64; top: -120px; right: 8%; animation: float 14s ease-in-out infinite; }
.glow-purple { width: 520px; height: 520px; background: #A78BFA; top: 60px; left: -160px; animation: float 18s ease-in-out infinite reverse; }
@keyframes float {
    0%, 100% { transform: translate(0, 0); }
    50% { transform: translate(40px, 30px); }
}
.hero-content {
    position: relative;
    z-index: 2;
    max-width: 880px;
    margin: 0 auto;
    padding: 56px 24px 8px;
    text-align: center;
}
.kicker {
    display: inline-block;
    margin: 0 0 14px;
    padding: 6px 14px;
    border-radius: 999px;
    background: var(--white);
    border: 1px solid var(--line);
    color: var(--red);
    font-weight: 600;
    font-size: 13px;
    letter-spacing: .08em;
    text-transform: uppercase;
}
.hero h1 { font-size: clamp(30px, 4.6vw, 54px); font-weight: 700; margin: 0 0 16px; }
.grad {
    background: linear-gradient(90deg, var(--red), var(--purple-mid));
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
}
.lead { font-size: 18px; color: var(--muted); margin: 0 auto 30px; max-width: 640px; }
.hero-scene { position: relative; z-index: 1; width: 100%; height: auto; display: block; max-height: 52vh; overflow: visible; }
.scene-label { font-family: 'Poppins', sans-serif; font-size: 16px; font-weight: 600; fill: #3B0764; text-anchor: middle; }
.flows path { stroke-dasharray: 2 10; animation: dash 1.2s linear infinite; }
@keyframes dash { to { stroke-dashoffset: -12; } }

@media (max-width: 640px) {
    .hero { min-height: calc(100svh - 57px); }
    .hero-content { padding: 36px 20px 16px; }
    .lead { font-size: 16px; }
    .hero-scene { width: 140%; margin-left: -20%; max-height: none; }
}

@media (prefers-reduced-motion: reduce) {
    .glow, .flows path { animation: none; }
}

/* Statistics: intestazione e riquadro a rotazione ---------------------- */
.page-head { margin-bottom: 16px; }
.page-head h1 { margin: 0 0 4px; font-size: 28px; }
.page-head p { margin: 0; }

.insight {
    position: relative;
    overflow: hidden;
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 16px 22px;
    margin-bottom: 20px;
    border-radius: var(--radius);
    background: linear-gradient(90deg, var(--red) 0%, var(--purple-mid) 100%);
    color: #fff;
    box-shadow: var(--shadow);
}
.insight-icon { font-size: 22px; }
.insight-text { margin: 0; font-size: 17px; font-weight: 500; transition: opacity .45s, transform .45s; }
.insight-text.fade { opacity: 0; transform: translateY(6px); }
.insight-progress { position: absolute; left: 0; right: 0; bottom: 0; height: 3px; background: rgba(255, 255, 255, .25); }
.insight-progress span { display: block; height: 100%; width: 0; background: #fff; }
.insight-progress span.run { animation: progress 10s linear forwards; }
@keyframes progress { to { width: 100%; } }

/* Pannelli, campi, filtri -------------------------------------------------- */
.panel {
    background: var(--white);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    padding: 20px 22px;
    margin-bottom: 20px;
}
.controls { display: flex; flex-direction: column; gap: 18px; }
.controls-row { display: flex; flex-wrap: wrap; gap: 28px; align-items: flex-start; }
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field > label { font-weight: 600; font-size: 13px; color: var(--ink); }
.hint { font-size: 12px; color: var(--muted); }

.period { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.period input {
    width: 100px;
    font: inherit;
    padding: 8px 12px;
    border: 1px solid var(--line);
    border-radius: 10px;
}
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
    font: inherit;
    font-size: 13px;
    padding: 6px 12px;
    border-radius: 999px;
    border: 1px solid var(--line);
    background: var(--white);
    color: var(--text);
    cursor: pointer;
}
.chip:hover { border-color: var(--purple-mid); }
.chip.active { background: var(--purple); border-color: var(--purple); color: #fff; }

.select, .period input {
    font-family: inherit;
    font-size: 14px;
    background: var(--white);
    color: var(--text);
}
.select { padding: 8px 12px; border: 1px solid var(--line); border-radius: 10px; min-width: 220px; }
.select:focus, .period input:focus { outline: 2px solid var(--purple-light); border-color: var(--purple-mid); }

.filters { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; }
@media (max-width: 1100px) { .filters { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 640px) {
    .filters { grid-template-columns: 1fr; }
    main { padding: 16px; }
    .site-header { padding: 12px 16px; }
    .logo { height: 28px; }
}
.actions { display: flex; gap: 12px; align-items: center; }

/* Multiselect stile filtro Excel (creato da multiselect.js) ---------------- */
.ms { position: relative; }
.ms-toggle {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    font: inherit;
    font-size: 14px;
    text-align: left;
    padding: 8px 12px;
    background: var(--white);
    border: 1px solid var(--line);
    border-radius: 10px;
    cursor: pointer;
    color: var(--text);
}
.ms-toggle:hover, .ms.open .ms-toggle { border-color: var(--purple-mid); }
.ms-toggle .ms-value { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ms-toggle .ms-caret { color: var(--muted); flex: none; }
.ms.filtered .ms-toggle { border-color: var(--purple); background: var(--purple-soft); color: var(--purple); font-weight: 600; }
.ms-panel {
    display: none;
    position: absolute;
    z-index: 30;
    top: calc(100% + 6px);
    left: 0;
    width: max(100%, 280px);
    background: var(--white);
    border: 1px solid var(--line);
    border-radius: 12px;
    box-shadow: var(--shadow);
    padding: 10px;
}
.ms.open .ms-panel { display: block; }
.ms-search {
    width: 100%;
    font: inherit;
    font-size: 14px;
    padding: 7px 10px;
    border: 1px solid var(--line);
    border-radius: 8px;
    margin-bottom: 8px;
}
.ms-list { max-height: 240px; overflow-y: auto; border-top: 1px solid var(--line); padding-top: 6px; }
.ms-item { display: flex; align-items: center; gap: 8px; padding: 5px 6px; border-radius: 6px; font-size: 13px; cursor: pointer; }
.ms-item:hover { background: var(--purple-soft); }
.ms-item input { accent-color: var(--purple); }
.ms-item[hidden], .ms-empty[hidden] { display: none; }
.ms-all { font-weight: 600; border-bottom: 1px solid var(--line); border-radius: 6px 6px 0 0; margin-bottom: 4px; }
.ms-empty { padding: 8px 6px; font-size: 13px; color: var(--muted); }
.ms-foot { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-top: 8px; }
.ms-foot .ms-count { font-size: 12px; color: var(--muted); }
.ms-foot button { font: inherit; font-size: 13px; padding: 5px 14px; border-radius: 999px; border: 1px solid var(--line); background: var(--white); cursor: pointer; }
.ms-foot button.ms-ok { background: var(--purple); border-color: var(--purple); color: #fff; }

/* Card ----------------------------------------------------------------------- */
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 14px; margin-bottom: 20px; }
.card {
    background: var(--white);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    padding: 14px 18px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    border-top: 4px solid var(--purple-light);
}
.card.accent-red { border-top-color: var(--red); }
.card.accent-purple { border-top-color: var(--purple-mid); }
.card-label { font-size: 13px; color: var(--muted); }
.card-value { font-size: 28px; font-weight: 700; color: var(--ink); font-variant-numeric: tabular-nums; }
.card-value.small { font-size: 14px; font-weight: 500; line-height: 1.6; }

/* Grafico e tabelle ------------------------------------------------------------- */
.chart-scroll { overflow-x: auto; }
.chart-inner { position: relative; height: 460px; }
.no-data {
    padding: 70px 20px;
    text-align: center;
    font-size: 18px;
    font-weight: 600;
    color: var(--red);
    border-radius: 10px;
    background: repeating-linear-gradient(135deg, var(--purple-soft), var(--purple-soft) 14px, #F1ECFD 14px, #F1ECFD 16px);
}
.details { margin-top: 14px; }
.details summary { cursor: pointer; font-weight: 600; color: var(--purple); }
.panel > .details:first-child { margin-top: 0; }
.table-wrap { overflow-x: auto; }
table { border-collapse: collapse; margin-top: 12px; background: var(--white); font-size: 14px; }
th, td { padding: 7px 12px; border-bottom: 1px solid var(--line); text-align: left; }
th { background: var(--purple-soft); color: var(--ink); font-weight: 600; }
td.num { text-align: right; font-variant-numeric: tabular-nums; }
