/* ════════════════════════════════════════════════════════════
   Dashboard KPI (pagina "Analytics") — layout, tab e grafici custom
   Riusa le variabili di style.css: nessun colore hard-coded.
   ════════════════════════════════════════════════════════════ */

/* ── Toolbar filtri ─────────────────────────────────────────── */
.an-toolbar {
    display: flex;
    align-items: center;
    gap: 18px;
    flex-wrap: wrap;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 12px 18px;
    margin-bottom: 20px;
    box-shadow: var(--shadow-card);
}
.an-toolbar-label {
    font-size: .72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .07em;
    color: var(--text-muted);
}
.an-check {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    font-size: .82rem;
    font-weight: 500;
    color: var(--text-secondary);
    cursor: pointer;
    user-select: none;
}
.an-check input { cursor: pointer; accent-color: var(--accent); width: 15px; height: 15px; }
.an-check-count {
    font-size: .68rem;
    font-weight: 700;
    color: var(--text-muted);
    background: var(--bg-card-alt);
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: 1px 7px;
}
.an-toolbar-spacer { flex: 1 1 auto; }
.an-toolbar-updated {
    font-size: .75rem;
    color: var(--text-muted);
    display: inline-flex;
    align-items: center;
    gap: 6px;
}
.an-toolbar-updated svg { width: 13px; height: 13px; stroke: currentColor; stroke-width: 2; fill: none; }

/* ── Tab bar ────────────────────────────────────────────────── */
.an-tabs {
    display: flex;
    gap: 4px;
    flex-wrap: wrap;
    border-bottom: 1px solid var(--border);
    margin-bottom: 24px;
}
.an-tab {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    padding: 10px 14px;
    margin-bottom: -1px;
    font-family: var(--font);
    font-size: .85rem;
    font-weight: 600;
    color: var(--text-muted);
    cursor: pointer;
    transition: all var(--transition);
    white-space: nowrap;
}
.an-tab svg { width: 15px; height: 15px; stroke: currentColor; stroke-width: 2; fill: none; }
.an-tab:hover { color: var(--text); background: var(--bg-hover); border-radius: var(--radius-xs) var(--radius-xs) 0 0; }
.an-tab.active { color: var(--accent); border-bottom-color: var(--accent); }
.an-tab-badge {
    font-size: .62rem;
    font-weight: 800;
    background: var(--red);
    color: #fff;
    border-radius: 999px;
    min-width: 17px;
    padding: 1px 5px;
    text-align: center;
    line-height: 1.4;
}
.an-panel { display: none; }
.an-panel.active { display: block; animation: pageIn .3s ease; }

/* ── Griglie ────────────────────────────────────────────────── */
.an-grid   { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; margin-bottom: 24px; }
.an-grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 20px; margin-bottom: 24px; }
.an-grid-full { display: grid; grid-template-columns: 1fr; gap: 20px; margin-bottom: 24px; }
@media (max-width: 1100px) { .an-grid-3 { grid-template-columns: 1fr 1fr; } }
@media (max-width: 900px)  { .an-grid, .an-grid-3 { grid-template-columns: 1fr; } }

/* ── Card ───────────────────────────────────────────────────── */
.an-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px 22px;
    box-shadow: var(--shadow-card);
    min-width: 0;
    overflow: hidden;
}
.an-card-head { margin-bottom: 14px; }
.an-card-title {
    font-size: .74rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: .07em;
    display: flex;
    align-items: center;
    gap: 8px;
}
.an-card-title svg { width: 14px; height: 14px; stroke: currentColor; stroke-width: 2; fill: none; }
.an-card-sub {
    font-size: .75rem;
    color: var(--text-muted);
    margin-top: 5px;
    line-height: 1.45;
}
.an-card-sub strong { color: var(--text-secondary); font-weight: 600; }

/* Altezze grafici */
.an-wrap      { position: relative; height: 260px; }
.an-wrap-sm   { position: relative; height: 200px; }
.an-wrap-md   { position: relative; height: 320px; }
.an-wrap-lg   { position: relative; height: 420px; }
.an-wrap-xl   { position: relative; height: 520px; }

/* ── Privacy: offusca i grafici in € ────────────────────────── */
.an-currency { transition: filter .18s ease; }
[data-privacy="on"] .an-currency {
    filter: blur(9px);
    -webkit-filter: blur(9px);
    pointer-events: none;
}

/* ── KPI tiles compatte ─────────────────────────────────────── */
.an-kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 14px;
    margin-bottom: 24px;
}
.an-kpi {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-left: 3px solid var(--border-hover);
    border-radius: var(--radius);
    padding: 15px 17px;
    box-shadow: var(--shadow-card);
    transition: all var(--transition);
}
.an-kpi:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }
.an-kpi-label {
    font-size: .68rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .07em;
    color: var(--text-muted);
    margin-bottom: 7px;
    display: flex;
    align-items: center;
    gap: 5px;
}
.an-kpi-label svg { width: 12px; height: 12px; stroke: currentColor; stroke-width: 2; fill: none; flex-shrink: 0; }
.an-kpi-value { font-size: 1.55rem; font-weight: 700; letter-spacing: -.03em; line-height: 1.1; }
.an-kpi-unit  { font-size: .8rem; font-weight: 600; color: var(--text-muted); margin-left: 3px; }
.an-kpi-sub   { font-size: .72rem; color: var(--text-muted); margin-top: 5px; }
.an-kpi.red    { border-left-color: var(--red); }
.an-kpi.red    .an-kpi-value { color: var(--red); }
.an-kpi.amber  { border-left-color: var(--amber); }
.an-kpi.amber  .an-kpi-value { color: var(--amber); }
.an-kpi.green  { border-left-color: var(--green); }
.an-kpi.green  .an-kpi-value { color: var(--green); }
.an-kpi.accent { border-left-color: var(--accent); }
.an-kpi.accent .an-kpi-value { color: var(--accent); }
.an-kpi.purple { border-left-color: var(--purple); }
.an-kpi.purple .an-kpi-value { color: var(--purple); }
.an-kpi.blue   { border-left-color: var(--blue); }
.an-kpi.blue   .an-kpi-value { color: var(--blue); }

/* ── Banner nota / avvertenza ───────────────────────────────── */
.an-note {
    display: flex;
    gap: 10px;
    align-items: flex-start;
    font-size: .78rem;
    line-height: 1.5;
    color: var(--text-secondary);
    background: var(--bg-card-alt);
    border: 1px solid var(--border);
    border-left: 3px solid var(--text-muted);
    border-radius: var(--radius-sm);
    padding: 11px 14px;
    margin-bottom: 16px;
}
.an-note svg { width: 15px; height: 15px; stroke: currentColor; stroke-width: 2; fill: none; flex-shrink: 0; margin-top: 1px; }
.an-note strong { color: var(--text); font-weight: 600; }
.an-note.warn   { border-left-color: var(--amber); background: var(--amber-bg); }
.an-note.danger { border-left-color: var(--red);   background: var(--red-bg); }
.an-note.info   { border-left-color: var(--accent); background: var(--accent-soft); }
.an-note ul { margin: 6px 0 0; padding-left: 18px; }
.an-note li { margin-bottom: 3px; }

/* ── Empty state per card ───────────────────────────────────── */
.an-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 130px;
    color: var(--text-muted);
    font-size: .82rem;
    text-align: center;
    padding: 20px;
}
.an-empty svg { width: 26px; height: 26px; stroke: currentColor; stroke-width: 1.6; fill: none; opacity: .5; }

/* ── Heatmap carico ─────────────────────────────────────────── */
.an-heat-scroll { overflow-x: auto; padding-bottom: 6px; }
.an-heat { border-collapse: separate; border-spacing: 3px; font-size: .72rem; }
.an-heat th {
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: .04em;
    font-size: .64rem;
    padding: 4px 6px;
    white-space: nowrap;
    text-align: center;
}
.an-heat th.an-heat-name-col {
    text-align: left;
    position: sticky;
    left: 0;
    background: var(--bg-card);
    z-index: 2;
    min-width: 148px;
}
.an-heat td.an-heat-name {
    position: sticky;
    left: 0;
    background: var(--bg-card);
    z-index: 2;
    font-size: .76rem;
    font-weight: 500;
    color: var(--text);
    white-space: nowrap;
    padding-right: 10px;
    max-width: 170px;
    overflow: hidden;
    text-overflow: ellipsis;
}
.an-heat-cell {
    width: 42px;
    height: 30px;
    border-radius: var(--radius-xs);
    text-align: center;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    color: var(--text);
    cursor: default;
    transition: transform .12s ease;
}
.an-heat-cell:hover { transform: scale(1.12); }
.an-heat-cell.zero { color: var(--text-muted); opacity: .35; }
.an-heat-now { box-shadow: inset 0 0 0 2px var(--accent); }
.an-heat-tot {
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    color: var(--text-secondary);
    padding-left: 8px;
    white-space: nowrap;
}
.an-heat-scale {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 12px;
    font-size: .7rem;
    color: var(--text-muted);
}
.an-heat-scale-bar {
    flex: 0 0 130px;
    height: 8px;
    border-radius: 4px;
}

/* ── Bullet chart (soglie R&D) ──────────────────────────────── */
.an-bullet-row { margin-bottom: 18px; }
.an-bullet-row:last-child { margin-bottom: 4px; }
.an-bullet-head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 6px;
}
.an-bullet-name { font-size: .85rem; font-weight: 600; color: var(--text); }
.an-bullet-name .an-mini-badge { margin-left: 6px; }
.an-bullet-pct { font-size: .82rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.an-bullet-track {
    position: relative;
    height: 20px;
    background: var(--bg-input);
    border-radius: var(--radius-xs);
    overflow: visible;
}
.an-bullet-zone {
    position: absolute;
    top: 0; bottom: 0;
    border-radius: var(--radius-xs) 0 0 var(--radius-xs);
    opacity: .16;
}
.an-bullet-fill {
    position: absolute;
    top: 3px; bottom: 3px; left: 0;
    border-radius: 3px;
    transition: width .4s ease;
}
.an-bullet-mark {
    position: absolute;
    top: -4px; bottom: -4px;
    width: 3px;
    border-radius: 2px;
    background: var(--text);
}
.an-bullet-meta {
    display: flex;
    gap: 14px;
    flex-wrap: wrap;
    margin-top: 6px;
    font-size: .72rem;
    color: var(--text-muted);
}
.an-bullet-meta b { color: var(--text-secondary); font-weight: 600; font-variant-numeric: tabular-nums; }

/* ── Scadenzario proroghe ───────────────────────────────────── */
.an-deadline-list { display: flex; flex-direction: column; gap: 10px; }
.an-deadline {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 11px 14px;
    background: var(--bg-card-alt);
    border: 1px solid var(--border);
    border-left: 3px solid var(--text-muted);
    border-radius: var(--radius-sm);
}
.an-deadline.overdue { border-left-color: var(--red);   background: var(--red-bg); }
.an-deadline.urgent  { border-left-color: var(--amber); background: var(--amber-bg); }
.an-deadline.soon    { border-left-color: var(--blue);  background: var(--blue-bg); }
.an-deadline.ok      { border-left-color: var(--green); background: var(--green-bg); }
.an-deadline-body { flex: 1 1 auto; min-width: 0; }
.an-deadline-name {
    font-size: .85rem;
    font-weight: 600;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.an-deadline-meta { font-size: .72rem; color: var(--text-muted); margin-top: 2px; }
.an-deadline-days {
    font-size: .95rem;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
    text-align: right;
}
.an-deadline.overdue .an-deadline-days { color: var(--red); }
.an-deadline.urgent  .an-deadline-days { color: var(--amber); }
.an-deadline.soon    .an-deadline-days { color: var(--blue); }
.an-deadline.ok      .an-deadline-days { color: var(--green); }

/* ── Treemap ────────────────────────────────────────────────── */
.an-treemap {
    position: relative;
    width: 100%;
    height: 420px;
    border-radius: var(--radius-sm);
    overflow: hidden;
}
.an-tm-tile {
    position: absolute;
    border: 2px solid var(--bg-card);
    border-radius: 3px;
    overflow: hidden;
    padding: 6px 8px;
    cursor: default;
    transition: filter .15s ease;
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
}
.an-tm-tile:hover { filter: brightness(1.08); }
.an-tm-name {
    font-size: .72rem;
    font-weight: 700;
    line-height: 1.15;
    color: var(--text-inverse);
    text-shadow: 0 1px 2px rgba(0,0,0,.35);
    word-break: break-word;
}
.an-tm-val {
    font-size: .68rem;
    font-weight: 600;
    color: var(--text-inverse);
    opacity: .9;
    text-shadow: 0 1px 2px rgba(0,0,0,.35);
    margin-top: 2px;
}
.an-tm-tile.tiny { padding: 2px 3px; }
.an-tm-tile.tiny .an-tm-name, .an-tm-tile.tiny .an-tm-val { display: none; }

/* ── Gantt ──────────────────────────────────────────────────── */
.an-gantt-scroll { overflow-x: auto; padding-bottom: 6px; }
.an-gantt { min-width: 720px; position: relative; }
.an-gantt-head {
    display: flex;
    border-bottom: 1px solid var(--border);
    padding-bottom: 6px;
    margin-bottom: 8px;
}
.an-gantt-label-col { flex: 0 0 190px; }
.an-gantt-track-col { flex: 1 1 auto; position: relative; min-width: 0; }
.an-gantt-tick {
    position: absolute;
    top: 0;
    font-size: .62rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: var(--text-muted);
    transform: translateX(-50%);
    white-space: nowrap;
}
.an-gantt-row {
    display: flex;
    align-items: center;
    height: 27px;
}
.an-gantt-row:hover { background: var(--bg-hover); }
.an-gantt-name {
    flex: 0 0 190px;
    font-size: .76rem;
    font-weight: 500;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    padding-right: 10px;
}
.an-gantt-track {
    flex: 1 1 auto;
    position: relative;
    height: 100%;
    min-width: 0;
    border-left: 1px solid var(--border);
}
.an-gantt-grid {
    position: absolute;
    top: 0; bottom: 0;
    width: 1px;
    background: var(--border);
}
.an-gantt-bar {
    position: absolute;
    top: 6px;
    height: 15px;
    border-radius: 3px;
    min-width: 3px;
    overflow: hidden;
}
.an-gantt-today {
    position: absolute;
    top: 0; bottom: 0;
    width: 2px;
    background: var(--red);
    opacity: .65;
    z-index: 3;
}
.an-gantt-today-lbl {
    position: absolute;
    top: -2px;
    font-size: .6rem;
    font-weight: 700;
    color: var(--red);
    transform: translateX(-50%);
    white-space: nowrap;
}
.an-gantt-legend {
    display: flex;
    gap: 16px;
    flex-wrap: wrap;
    margin-top: 12px;
    font-size: .72rem;
    color: var(--text-muted);
}
.an-gantt-legend-item { display: inline-flex; align-items: center; gap: 6px; }
.an-gantt-legend-swatch { width: 12px; height: 8px; border-radius: 2px; }

/* ── Mini badge (tipo progetto, stato) ──────────────────────── */
.an-mini-badge {
    font-size: .58rem;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: .06em;
    padding: 2px 6px;
    border-radius: 999px;
    white-space: nowrap;
    vertical-align: middle;
}
.an-mini-badge.commessa { background: var(--green-bg); color: var(--green); }
.an-mini-badge.rd       { background: var(--blue-bg);  color: var(--blue); }
.an-mini-badge.danger   { background: var(--red-bg);   color: var(--red); }
.an-mini-badge.warn     { background: var(--amber-bg); color: var(--amber); }

/* ── Tooltip condiviso per i grafici custom ─────────────────── */
.an-tip {
    position: fixed;
    z-index: 9999;
    display: none;
    max-width: 300px;
    background: var(--bg-card);
    border: 1px solid var(--border-hover);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-lg);
    padding: 9px 12px;
    font-size: .76rem;
    color: var(--text);
    pointer-events: none;
    line-height: 1.45;
}
.an-tip-title { font-weight: 700; margin-bottom: 4px; }
.an-tip-row { display: flex; justify-content: space-between; gap: 14px; }
.an-tip-row span:last-child { font-weight: 600; font-variant-numeric: tabular-nums; }
.an-tip small { color: var(--text-muted); }

/* ── Select interno alle card ───────────────────────────────── */
.an-card-select {
    font-family: var(--font);
    font-size: .8rem;
    padding: 6px 10px;
    background: var(--bg-input);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: var(--radius-xs);
    max-width: 100%;
    margin-top: 8px;
}
.an-card-select:focus { outline: none; border-color: var(--border-focus); }

/* ── Tabella compatta (dettaglio ritardi) ───────────────────── */
.an-table-wrap { max-height: 340px; overflow-y: auto; }
.an-table { width: 100%; border-collapse: collapse; font-size: .78rem; }
.an-table th {
    text-align: left;
    font-size: .64rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .06em;
    color: var(--text-muted);
    padding: 7px 10px;
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    background: var(--bg-card);
    z-index: 1;
}
.an-table td {
    padding: 7px 10px;
    border-bottom: 1px solid var(--border);
    color: var(--text-secondary);
    vertical-align: middle;
}
.an-table tbody tr:hover { background: var(--bg-hover); }
.an-table td.num { text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }
.an-table .an-late { color: var(--red); font-weight: 700; }
.an-table-link { color: var(--text); font-weight: 600; cursor: pointer; text-decoration: none; }
.an-table-link:hover { color: var(--accent); text-decoration: underline; }

/* Contenitori riempiti via JS: invisibili quando vuoti */
.an-note:empty, .an-card-sub:empty { display: none; }

/* ── Timeline: istogramma dei progetti in parallelo ───────── */
/* Condivide la mappatura orizzontale con le barre sottostanti, quindi usa
   la stessa coppia label-col / track-col del resto del Gantt. */
.an-gantt-hist-row {
    display: flex;
    align-items: stretch;
    margin-bottom: 10px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--border);
}
.an-gantt-hist-axis {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    justify-content: space-between;
    padding-right: 10px;
    text-align: right;
}
.an-gantt-hist-val {
    font-size: .62rem;
    font-weight: 700;
    color: var(--an-muted, var(--text-muted));
    line-height: 1;
}
.an-gantt-hist-cap {
    font-size: .6rem;
    font-weight: 600;
    color: var(--an-muted, var(--text-muted));
    text-transform: uppercase;
    letter-spacing: .05em;
    line-height: 1.2;
    max-width: 92px;
}
.an-gantt-hist-track { border-left: 1px solid var(--border); }

.an-gantt-hist-col {
    position: absolute;
    bottom: 0;
    top: 0;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;   /* i segmenti si impilano dal basso */
    padding: 0 1px;
    cursor: default;
    z-index: 1;
}
.an-gantt-hist-col:hover { filter: brightness(1.15); }
.an-gantt-hist-seg {
    width: 100%;
    border-radius: 1px 1px 0 0;
    transition: height .3s cubic-bezier(.4,0,.2,1);
}
.an-gantt-hist-seg + .an-gantt-hist-seg { border-radius: 0; }

/* Barra che prosegue oltre la finestra dei 12 mesi: bordo tratteggiato sul
   lato tagliato, così non si legge come inizio o fine reale del progetto. */
.an-gantt-bar-cut-l {
    border-radius: 0 3px 3px 0;
    border-left: 2px dashed currentColor;
}
.an-gantt-bar-cut-r {
    border-radius: 3px 0 0 3px;
    border-right: 2px dashed currentColor;
}
.an-gantt-bar-cut-l.an-gantt-bar-cut-r { border-radius: 0; }

/* Con 12 etichette mensili serve più respiro in testa alla timeline */
.an-gantt-head { padding-bottom: 8px; }
.an-gantt-tick { font-size: .58rem; letter-spacing: .02em; }

/* Mese senza alcun progetto lavorato: si mostra la base, non il vuoto */
.an-gantt-hist-zero::after {
    content: '';
    position: absolute;
    left: 1px; right: 1px; bottom: 0;
    height: 2px;
    background: var(--border);
    border-radius: 1px;
}
