/* ═══════════════════════════════════════════════════════════════
   COPIA ALLINEATA di WmsDashboard.Web/wwwroot/css/app.css
   (sezioni comuni: token, shell, sidebar, topbar, tabelle, badge,
   controlli, login, contesto, export, spinner).
   Non modificare qui: ogni ritocco va fatto in entrambi i progetti,
   cosi Arsenale Dashboard e Arsenale Ordini Web restano identici.
   Gli adattamenti propri di Ordini Web stanno in wwwroot/app.css.
   ═══════════════════════════════════════════════════════════════ */

/* ═══════════════════════════════════════════════════════════════
   WMS Dashboard — Design System
   Tema: Arsenale Dark
   Palette: #B80815 rosso Arsenale · Notte blu-scura · Testo avorio
   ═══════════════════════════════════════════════════════════════ */

@import url('https://fonts.googleapis.com/css2?family=Space+Mono:ital,wght@0,400;0,700;1,400&family=DM+Sans:ital,opsz,wght@0,9..40,300;0,9..40,400;0,9..40,500;0,9..40,600;1,9..40,300&display=swap');

/* ── CSS Variables ────────────────────────────────────────────── */
:root {
    /* Background — progressione blu-notte */
    --bg: #0D1117;
    --bg-card: #131B27;
    --bg-card2: #1C2A3F;
    --bg-hover: #1F3050;
    --border: #253350;
    --border-hi: #2E4168;
    /* Testo */
    --text: #E8E0D5;
    --text-muted: #8A99B0;
    --text-dim: #3A4D6A;
    /* Accent principale — Rosso Arsenale */
    --accent: #B80815;
    --accent-hi: #D94454;
    --accent-deep: #8C060F;
    --accent-glow: rgba(184,8,21,.14);
    /* Colori funzionali */
    --green: #2DBF8A;
    --orange: #F5A623;
    --red: #D94454;
    --blue: #4A9EDB;
    /* Layout */
    --sidebar-w: 240px;
    --topbar-h: 56px;
    --radius: 10px;
    --radius-sm: 6px;
    --font-ui: 'DM Sans', system-ui, sans-serif;
    --font-mono: 'Space Mono', monospace;
    --shadow: 0 4px 24px rgba(0,0,0,.5);
    --shadow-sm: 0 2px 8px rgba(0,0,0,.4);
    /* Scrollbar — stessa progressione blu-notte dei bordi */
    --scroll-size: 10px;
    --scroll-track: transparent;
    --scroll-thumb: #2A3B5C;
    --scroll-thumb-hover: #40598A;
    --scroll-thumb-active: var(--accent);
}

/* ── Reset & Base ─────────────────────────────────────────────── */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html, body {
    height: 100%;
    background: var(--bg);
    color: var(--text);
    font-family: var(--font-ui);
    font-size: 14px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

a {
    color: inherit;
    text-decoration: none;
}

button {
    cursor: pointer;
    font-family: inherit;
}

input, select {
    font-family: inherit;
}

code {
    font-family: var(--font-mono);
}

/* ── Scrollbar ────────────────────────────────────────────────────
   Le barre native chiare stonavano sul tema scuro. Regola globale su
   tutti i contenitori scrollabili: traccia trasparente, cursore nella
   stessa gamma blu-notte dei bordi, rosso Arsenale mentre si trascina.
   Le eccezioni (es. .contesto-picker su mobile) restano più avanti nel
   file e vincono per specificità.
   ─────────────────────────────────────────────────────────────── */

/* Firefox — non conosce ::-webkit-scrollbar e si accontenta delle proprietà
   standard. Va isolato: da Chromium 121 basta dichiarare scrollbar-width o
   scrollbar-color per disattivare tutto lo styling ::-webkit-scrollbar,
   perdendo angoli arrotondati, stacco dal bordo e stati hover/active. */
@supports not selector(::-webkit-scrollbar) {
    * {
        scrollbar-width: thin;
        scrollbar-color: var(--scroll-thumb) var(--scroll-track);
    }
}

/* WebKit / Chromium / Edge */
*::-webkit-scrollbar {
    width: var(--scroll-size);
    height: var(--scroll-size);
}

*::-webkit-scrollbar-track {
    background: var(--scroll-track);
    border-radius: var(--radius-sm);
}

*::-webkit-scrollbar-thumb {
    background: var(--scroll-thumb);
    border-radius: var(--radius-sm);
    /* Il bordo trasparente + background-clip stacca il cursore dal bordo
       del contenitore: sembra più sottile senza ridurre l'area cliccabile. */
    border: 2px solid transparent;
    background-clip: padding-box;
    transition: background-color .15s ease;
}

*::-webkit-scrollbar-thumb:hover {
    background: var(--scroll-thumb-hover);
    background-clip: padding-box;
}

*::-webkit-scrollbar-thumb:active {
    background: var(--scroll-thumb-active);
    background-clip: padding-box;
}

/* Incrocio fra barra orizzontale e verticale */
*::-webkit-scrollbar-corner {
    background: transparent;
}

/* Le frecce native stonano con il resto: rimosse */
*::-webkit-scrollbar-button {
    display: none;
    width: 0;
    height: 0;
}

/* ── App Shell ────────────────────────────────────────────────── */
.app-shell {
    display: flex;
    height: 100vh;
    overflow: hidden;
}

/* ── Sidebar ──────────────────────────────────────────────────── */
.sidebar {
    width: var(--sidebar-w);
    background: var(--bg-card);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    transition: width .25s cubic-bezier(.4,0,.2,1), transform .25s cubic-bezier(.4,0,.2,1);
    overflow: hidden;
}

.sidebar-closed .sidebar {
    width: 64px;
}

.sidebar-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 20px 16px 16px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.logo-text {
    display: flex;
    flex-direction: column;
    overflow: hidden;
    white-space: nowrap;
    transition: opacity .2s;
}

.sidebar-closed .logo-text {
    opacity: 0;
    width: 0;
}

.logo-title {
    font-family: var(--font-mono);
    font-size: 15px;
    font-weight: 700;
    color: var(--text);
    letter-spacing: .05em;
}

.logo-sub {
    font-size: 10px;
    color: var(--text-muted);
    letter-spacing: .1em;
    text-transform: uppercase;
}

.sidebar-nav {
    flex: 1;
    padding: 16px 8px;
    overflow-y: auto;
    overflow-x: hidden;
}

.nav-section-label {
    font-size: 9px;
    font-weight: 600;
    letter-spacing: .12em;
    color: var(--text-dim);
    padding: 0 8px 8px;
    white-space: nowrap;
    overflow: hidden;
    transition: opacity .2s;
}

.sidebar-closed .nav-section-label {
    opacity: 0;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 10px;
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    transition: background .15s, color .15s;
    white-space: nowrap;
    overflow: hidden;
    margin-bottom: 2px;
}

    .nav-item:hover {
        background: var(--bg-hover);
        color: var(--text);
    }

    .nav-item.active {
        background: var(--accent-glow);
        color: var(--accent-hi);
        border-left: 2px solid var(--accent);
    }

.nav-icon {
    flex-shrink: 0;
    display: flex;
}

.nav-label {
    font-size: 13px;
    font-weight: 500;
    transition: opacity .2s;
}

.sidebar-closed .nav-label {
    opacity: 0;
    width: 0;
}

.sidebar-footer {
    padding: 12px 8px;
    border-top: 1px solid var(--border);
    flex-shrink: 0;
}

.user-info {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 6px;
    overflow: hidden;
}

.user-avatar {
    width: 32px;
    height: 32px;
    background: var(--accent-glow);
    border: 1px solid var(--accent);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: var(--font-mono);
    font-size: 11px;
    font-weight: 700;
    color: var(--accent-hi);
    flex-shrink: 0;
}

.user-details {
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: opacity .2s;
    flex: 1;
}

.sidebar-closed .user-details {
    opacity: 0;
    width: 0;
}

.user-name {
    font-size: 12px;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.user-code {
    font-size: 10px;
    color: var(--text-muted);
    font-family: var(--font-mono);
}

.btn-logout {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    transition: background .15s, color .15s;
    flex-shrink: 0;
}

    .btn-logout:hover {
        background: rgba(184,8,21,.15);
        color: var(--accent-hi);
    }

/* ── Main Content ─────────────────────────────────────────────── */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.topbar {
    height: var(--topbar-h);
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    flex-shrink: 0;
}

.sidebar-toggle {
    background: transparent;
    border: none;
    color: var(--text-muted);
    padding: 6px;
    border-radius: var(--radius-sm);
    transition: background .15s, color .15s;
}

    .sidebar-toggle:hover {
        background: var(--bg-hover);
        color: var(--text);
    }

.topbar-right {
    display: flex;
    align-items: center;
    gap: 16px;
}

.topbar-clock {
    font-family: var(--font-mono);
    font-size: 11px;
    color: var(--text-muted);
    letter-spacing: .05em;
}

.page-wrapper {
    flex: 1;
    overflow-y: auto;
    padding: 28px 32px;
}

/* ── Page Header ──────────────────────────────────────────────── */
.page-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    margin-bottom: 28px;
    gap: 16px;
}

.page-title {
    font-size: 22px;
    font-weight: 600;
    letter-spacing: -.02em;
    color: var(--text);
}

.page-subtitle {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 3px;
}

.page-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

/* ── KPI Grid ─────────────────────────────────────────────────── */
.kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.kpi-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    position: relative;
    overflow: hidden;
    transition: border-color .2s, transform .2s;
}

    .kpi-card:hover {
        border-color: var(--border-hi);
        transform: translateY(-1px);
    }

    .kpi-card::before {
        content: '';
        position: absolute;
        top: 0;
        left: 0;
        right: 0;
        height: 2px;
        background: var(--border);
    }

/* Barra colorata in alto alla card: dichiara di che natura è il numero.
   accent = il dato principale · alert = richiede intervento ·
   warning = da tenere d'occhio · info = stato in corso, nessuna azione.
   warning e info erano usate da cinque pagine ma non erano mai state
   definite, quindi quelle card restavano con la barra grigia neutra. */
.kpi-accent::before {
    background: var(--accent);
}

.kpi-alert::before {
    background: var(--accent-hi);
}

.kpi-warning::before {
    background: var(--orange);
}

.kpi-info::before {
    background: var(--blue);
}

.kpi-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
}

.kpi-label {
    font-size: 10px;
    font-weight: 600;
    letter-spacing: .1em;
    text-transform: uppercase;
    color: var(--text-muted);
}

.kpi-icon {
    display: flex;
    color: var(--text-dim);
}

.kpi-value {
    font-family: var(--font-mono);
    font-size: 28px;
    font-weight: 700;
    color: var(--text);
    letter-spacing: -.02em;
    line-height: 1;
    margin-bottom: 6px;
}

.kpi-sub {
    font-size: 11px;
    color: var(--text-muted);
}

/* Sottotitolo a più voci dentro una KPI card: una riga per voce, etichetta a
   sinistra e valore a destra. Serve dove la frase unica andrebbe a capo a metà. */
.kpi-dettaglio {
    display: flex;
    flex-direction: column;
    gap: 2px;
    margin-top: 2px;
}

.kpi-dettaglio-riga {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 8px;
    font-size: 11px;
    line-height: 1.35;
}

.kpi-dettaglio-val {
    font-family: var(--font-mono);
    font-weight: 600;
    color: var(--text);
    white-space: nowrap;
}

/* ── Variazione di periodo (estremi di una serie storica) ─────── */
.variazione-periodo {
    display: flex;
    align-items: center;
    gap: 16px;
    flex-wrap: wrap;
    padding: 10px 14px;
    margin-bottom: 12px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
}

.variazione-estremo {
    display: flex;
    flex-direction: column;
    gap: 1px;
}

.variazione-label {
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: .08em;
    color: var(--text-muted);
}

.variazione-valore {
    font-family: var(--font-mono);
    font-size: 17px;
    font-weight: 700;
    color: var(--text);
    line-height: 1.1;
}

.variazione-data {
    font-size: 10px;
    color: var(--text-muted);
}

.variazione-freccia {
    color: var(--text-muted);
    flex-shrink: 0;
}

.variazione-delta {
    display: flex;
    flex-direction: column;
    gap: 1px;
    margin-left: auto;
    text-align: right;
}

.variazione-delta-val {
    font-family: var(--font-mono);
    font-size: 17px;
    font-weight: 700;
    line-height: 1.1;
}

.variazione-delta-perc {
    font-family: var(--font-mono);
    font-size: 11px;
    opacity: .85;
}

@media (max-width: 640px) {
    .variazione-delta {
        margin-left: 0;
        text-align: left;
    }
}

.sub-green {
    color: var(--green) !important;
}

.sub-orange {
    color: var(--orange) !important;
}

.sub-red {
    color: var(--accent-hi) !important;
}

/* ── Charts ───────────────────────────────────────────────────── */
.charts-grid-2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    margin-bottom: 24px;
}

/* Quando una card viene nascosta perché il WMS non popola quel dato, la griglia
   si stringe sulle card rimaste invece di lasciare colonne vuote. */
.charts-grid-2:has(> :first-child:last-child),
.charts-grid-3:has(> :first-child:last-child) {
    grid-template-columns: 1fr;
}

.charts-grid-3:has(> :nth-child(2):last-child) {
    grid-template-columns: 1fr 1fr;
}

.charts-grid-3 {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 16px;
    margin-bottom: 24px;
}

.chart-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    overflow: hidden;
}

.chart-card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
    margin-bottom: 16px;
}

/* Comandi a destra del titolo di una chart-card (selettore periodo + badge). */
.chart-card-tools {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.chart-title {
    font-size: 13px;
    font-weight: 600;
    color: var(--text);
}

.chart-badge {
    font-size: 10px;
    font-family: var(--font-mono);
    color: var(--text-muted);
    background: var(--bg);
    border: 1px solid var(--border);
    padding: 2px 8px;
    border-radius: 99px;
}

/* ── Top List ─────────────────────────────────────────────────── */
.top-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.top-list-item {
    display: grid;
    grid-template-columns: 24px 1fr auto;
    align-items: center;
    gap: 10px;
}

.top-rank {
    font-family: var(--font-mono);
    font-size: 10px;
    color: var(--text-dim);
    text-align: center;
    width: 20px;
}

/* Variante per le liste che al posto del rank mostrano un'etichetta: un orario
   come "08:00" a 12px non sta nei 24px previsti per un numero e finisce
   addosso al testo della colonna successiva. */
.top-list-etichetta .top-list-item {
    grid-template-columns: 56px 1fr auto;
    gap: 14px;
}

.top-list-etichetta .top-rank {
    width: auto;
    text-align: left;
    color: var(--text);
}

.top-info {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.top-code {
    font-family: var(--font-mono);
    font-size: 11px;
    color: var(--text);
}

.top-desc {
    font-size: 10px;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.top-bar-wrap {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100px;
}

.top-bar {
    height: 4px;
    background: var(--accent);
    border-radius: 2px;
    min-width: 2px;
    flex: 1;
    opacity: .85;
    transition: width .3s ease;
}

.top-val {
    font-family: var(--font-mono);
    font-size: 11px;
    color: var(--text-muted);
    min-width: 28px;
    text-align: right;
}

/* ── Tables ───────────────────────────────────────────────────── */
.table-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    margin-bottom: 16px;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
}

    .data-table thead tr {
        background: var(--bg-card2);
        border-bottom: 1px solid var(--border);
    }

    .data-table th {
        padding: 10px 14px;
        font-size: 10px;
        font-weight: 600;
        letter-spacing: .08em;
        text-transform: uppercase;
        color: var(--text-muted);
        text-align: left;
        white-space: nowrap;
        user-select: none;
    }

        .data-table th.sortable {
            cursor: pointer;
        }

            .data-table th.sortable:hover {
                color: var(--text);
            }

        .data-table th.sort-asc::after {
            content: ' ▲';
            color: var(--accent);
        }

        .data-table th.sort-desc::after {
            content: ' ▼';
            color: var(--accent);
        }

        .data-table th.num {
            text-align: right;
        }

    .data-table tbody tr {
        border-bottom: 1px solid var(--border);
        transition: background .12s;
    }

        .data-table tbody tr:last-child {
            border-bottom: none;
        }

        .data-table tbody tr:hover {
            background: var(--bg-hover);
        }

        .data-table tbody tr.row-warn {
            background: rgba(184,8,21,.05);
        }

            .data-table tbody tr.row-warn:hover {
                background: rgba(184,8,21,.09);
            }

    .data-table td {
        padding: 10px 14px;
        font-size: 13px;
        color: var(--text);
        vertical-align: middle;
    }

        .data-table td.num {
            text-align: right;
            font-family: var(--font-mono);
            font-size: 12px;
        }

        .data-table td.muted {
            color: var(--text-muted);
        }

        .data-table td.desc-cell {
            max-width: 280px;
            overflow: hidden;
            text-overflow: ellipsis;
            white-space: nowrap;
        }

/* L'indirizzo è "via — città (PR)" più l'eventuale chip della destinazione:
   nei 280px della desc-cell finiva quasi sempre tagliato. */
.data-table td.cella-indirizzo {
    max-width: 460px;
    white-space: normal;
}

/* ── Mini Stats ───────────────────────────────────────────────── */
.mini-stats {
    display: flex;
    gap: 0;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    margin-bottom: 20px;
}

.mini-stat {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 14px 16px;
    border-right: 1px solid var(--border);
    transition: background .15s;
}

    .mini-stat:last-child {
        border-right: none;
    }

    .mini-stat:hover {
        background: var(--bg-hover);
    }

.mini-stat-warn {
    background: rgba(184,8,21,.05);
}

.mini-stat-val {
    font-family: var(--font-mono);
    font-size: 20px;
    font-weight: 700;
    color: var(--text);
    line-height: 1;
    margin-bottom: 4px;
}

.mini-stat-lbl {
    font-size: 10px;
    color: var(--text-muted);
    letter-spacing: .05em;
    text-transform: uppercase;
}

/* ── Badges & Tags ────────────────────────────────────────────── */
.code-cell {
    font-family: var(--font-mono);
    font-size: 11px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 2px 6px;
    color: var(--accent-hi);
    white-space: nowrap;
}

.badge-cell {
    font-family: var(--font-mono);
    font-size: 10px;
    background: var(--bg-card2);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 2px 6px;
    color: var(--text-muted);
}

.tag {
    font-size: 11px;
    background: var(--bg-card2);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 2px 8px;
    color: var(--text);
}

/* ── Aree della consolle: vendita vs produzione (TIPIDOC.console) ──────────
   Il bordo sinistro sulla riga separa le due tipologie a colpo d'occhio senza
   aggiungere una colonna; il badge ripete il colore sul tipo documento.       */
.area-vendita    { box-shadow: inset 3px 0 0 0 #4F9BFF; }
.area-produzione { box-shadow: inset 3px 0 0 0 #C77DFF; }
.area-altro      { box-shadow: inset 3px 0 0 0 var(--border); }

.area-badge {
    display: inline-block;
    font-size: 11px;
    padding: 1px 7px;
    border-radius: 4px;
    border: 1px solid transparent;
    box-shadow: none;          /* il badge colora bordo e testo, non il lato */
    white-space: nowrap;
}
.area-badge.area-vendita    { color: #4F9BFF; border-color: rgba(79,155,255,.35);  background: rgba(79,155,255,.10); }
.area-badge.area-produzione { color: #C77DFF; border-color: rgba(199,125,255,.35); background: rgba(199,125,255,.10); }
.area-badge.area-altro      { color: var(--text-muted); border-color: var(--border); }

/* Chip di contorno accanto a un testo: destinazione del documento, ecc. */
.tag-sm {
    font-size: 10px;
    padding: 1px 6px;
    margin-left: 6px;
    color: var(--text-muted);
    white-space: nowrap;
}

.status-badge {
    display: inline-block;
    font-size: 10px;
    font-weight: 600;
    letter-spacing: .06em;
    text-transform: uppercase;
    padding: 3px 8px;
    border-radius: 99px;
}

.status-ok {
    background: rgba(45,191,138,.12);
    color: var(--green);
}

.status-pending {
    background: rgba(245,166,35,.12);
    color: var(--orange);
}

.status-obsoleto {
    background: rgba(138,153,176,.10);
    color: var(--text-muted);
}

.badge-abc {
    display: inline-block;
    font-family: var(--font-mono);
    font-size: 11px;
    font-weight: 700;
    width: 24px;
    height: 24px;
    line-height: 24px;
    text-align: center;
    border-radius: 4px;
}

.badge-abc-a {
    background: rgba(184,8,21,.18);
    color: var(--accent-hi);
}

.badge-abc-b {
    background: rgba(245,166,35,.15);
    color: var(--orange);
}

.badge-abc-c {
    background: rgba(74,158,219,.15);
    color: var(--blue);
}

/* ── Pagination ───────────────────────────────────────────────── */
.pagination {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 0;
}

.page-info {
    font-size: 12px;
    color: var(--text-muted);
    font-family: var(--font-mono);
}

.page-buttons {
    display: flex;
    gap: 4px;
}

.btn-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 32px;
    height: 32px;
    padding: 0 8px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    font-size: 12px;
    font-family: var(--font-mono);
    transition: all .15s;
}

    .btn-page:hover:not(:disabled) {
        background: var(--bg-hover);
        color: var(--text);
        border-color: var(--border-hi);
    }

    .btn-page.active {
        background: var(--accent);
        border-color: var(--accent);
        color: white;
    }

    .btn-page:disabled {
        opacity: .3;
        cursor: not-allowed;
    }

/* ── Filter Pills ─────────────────────────────────────────────── */
.filter-pills {
    display: flex;
    gap: 6px;
    margin-bottom: 20px;
    flex-wrap: wrap;
    align-items: center;
}

/* Azioni (es. export) in coda alle pill, spinte a destra */
.pill-actions {
    margin-left: auto;
    display: flex;
    gap: 6px;
}

.pill {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 99px;
    padding: 5px 14px;
    font-size: 12px;
    color: var(--text-muted);
    transition: all .15s;
}

    .pill:hover {
        background: var(--bg-hover);
        color: var(--text);
    }

    .pill.active {
        background: var(--accent-glow);
        border-color: var(--accent);
        color: var(--accent-hi);
    }

/* ── Inputs & Controls ────────────────────────────────────────── */
.search-wrap {
    position: relative;
    display: flex;
    align-items: center;
}

.search-icon {
    position: absolute;
    left: 10px;
    color: var(--text-muted);
    pointer-events: none;
}

.search-input {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
    padding: 7px 12px 7px 32px;
    font-size: 13px;
    width: 240px;
    transition: border-color .15s;
    outline: none;
}

    .search-input:focus {
        border-color: var(--accent);
    }

    .search-input::placeholder {
        color: var(--text-dim);
    }

.select-sm {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
    padding: 7px 28px 7px 10px;
    font-size: 12px;
    outline: none;
    cursor: pointer;
    -webkit-appearance: none;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg width='10' height='6' viewBox='0 0 10 6' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M1 1L5 5L9 1' stroke='%238A99B0' stroke-width='1.5' stroke-linecap='round'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 8px center;
    transition: border-color .15s;
}

    .select-sm:focus {
        border-color: var(--accent);
    }

.btn-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    transition: all .15s;
}

    .btn-icon:hover {
        background: var(--bg-hover);
        color: var(--text);
        border-color: var(--border-hi);
    }

.btn-primary {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 7px 14px;
    background: var(--accent);
    border: none;
    border-radius: var(--radius-sm);
    color: white;
    font-size: 13px;
    font-weight: 500;
    transition: background .15s, transform .1s;
}

    .btn-primary:hover {
        background: var(--accent-deep);
        transform: translateY(-1px);
    }

/* ── Loading ──────────────────────────────────────────────────── */
.loading-wrap {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 60px 20px;
    gap: 16px;
}

    .loading-wrap.compact {
        padding: 24px;
    }

.loading-dots {
    display: flex;
    gap: 8px;
}

    .loading-dots span {
        width: 8px;
        height: 8px;
        background: var(--accent);
        border-radius: 50%;
        animation: dot-pulse 1.4s infinite ease-in-out;
    }

        .loading-dots span:nth-child(2) {
            animation-delay: .2s;
        }

        .loading-dots span:nth-child(3) {
            animation-delay: .4s;
        }

@keyframes dot-pulse {
    0%, 80%, 100% {
        transform: scale(.6);
        opacity: .4;
    }

    40% {
        transform: scale(1);
        opacity: 1;
    }
}

.loading-msg {
    font-size: 12px;
    color: var(--text-muted);
}

/* ── Empty States ─────────────────────────────────────────────── */
.empty-chart {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px 20px;
    gap: 12px;
    color: var(--text-muted);
    font-size: 12px;
}

.empty-state {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 60px 20px;
    text-align: center;
    color: var(--text-muted);
    font-size: 13px;
}

/* ── Utilities ────────────────────────────────────────────────── */
.text-green {
    color: var(--green);
}

.text-orange {
    color: var(--orange);
}

.text-red {
    color: var(--accent-hi);
}

.fw-600 {
    font-weight: 600;
}

/* ── Login Page ───────────────────────────────────────────────── */
.login-shell {
    min-height: 100vh;
    background: var(--bg);
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    overflow: hidden;
}

.login-bg {
    position: absolute;
    inset: 0;
    background: radial-gradient(ellipse 70% 50% at 50% -5%, rgba(184,8,21,.18) 0%, transparent 65%);
}

.login-grid {
    position: absolute;
    inset: 0;
    background-image: linear-gradient(var(--border) 1px, transparent 1px), linear-gradient(90deg, var(--border) 1px, transparent 1px);
    background-size: 40px 40px;
    mask-image: radial-gradient(ellipse 70% 70% at 50% 50%, black 0%, transparent 100%);
    opacity: .35;
}

.login-card {
    position: relative;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 40px;
    width: 100%;
    max-width: 400px;
    box-shadow: 0 32px 64px rgba(0,0,0,.6), 0 0 0 1px rgba(184,8,21,.12);
}

.login-logo {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 28px;
}

.login-logo-text {
    font-family: var(--font-mono);
    font-size: 14px;
    font-weight: 700;
    color: var(--text);
    letter-spacing: .05em;
}

.login-title {
    font-size: 24px;
    font-weight: 600;
    letter-spacing: -.02em;
    margin-bottom: 6px;
}

.login-subtitle {
    font-size: 13px;
    color: var(--text-muted);
    margin-bottom: 28px;
}

.form-group {
    margin-bottom: 16px;
}

.form-label {
    display: block;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: .06em;
    text-transform: uppercase;
    color: var(--text-muted);
    margin-bottom: 6px;
}

.form-input {
    width: 100%;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
    padding: 10px 12px;
    font-size: 14px;
    outline: none;
    transition: border-color .15s, box-shadow .15s;
}

    .form-input:focus {
        border-color: var(--accent);
        box-shadow: 0 0 0 3px var(--accent-glow);
    }

    .form-input::placeholder {
        color: var(--text-dim);
    }

.btn-login {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 11px 20px;
    background: var(--accent);
    border: none;
    border-radius: var(--radius-sm);
    color: white;
    font-size: 14px;
    font-weight: 500;
    margin-top: 8px;
    transition: background .15s, transform .1s;
}

    .btn-login:hover:not(:disabled) {
        background: var(--accent-deep);
        transform: translateY(-1px);
    }

    .btn-login:disabled {
        opacity: .6;
        cursor: not-allowed;
    }

.alert-error {
    display: flex;
    align-items: center;
    gap: 8px;
    background: rgba(184,8,21,.1);
    border: 1px solid rgba(184,8,21,.3);
    border-radius: var(--radius-sm);
    padding: 10px 12px;
    font-size: 13px;
    color: var(--accent-hi);
    margin-bottom: 20px;
}

.spinner {
    width: 14px;
    height: 14px;
    border: 2px solid rgba(255,255,255,.3);
    border-top-color: white;
    border-radius: 50%;
    animation: spin .6s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* ── 404 ──────────────────────────────────────────────────────── */
.not-found {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 60vh;
    text-align: center;
    gap: 12px;
}

    .not-found h1 {
        font-family: var(--font-mono);
        font-size: 72px;
        color: var(--text-dim);
    }

/* ── Responsive ───────────────────────────────────────────────── */
@media (max-width: 1200px) {
    .charts-grid-3 {
        grid-template-columns: 1fr 1fr;
    }
}

@media (max-width: 900px) {
    .charts-grid-2,
    .charts-grid-3 {
        grid-template-columns: 1fr;
    }

    .page-wrapper {
        padding: 20px 16px;
    }

    .kpi-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 640px) {
    /* ── Sidebar: overlay drawer ──────────────────────────────── */
    /* Override anche .sidebar-closed .sidebar (specificità 2 cls) */
    .sidebar-closed .sidebar,
    .sidebar {
        position: fixed;
        left: 0; top: 0; bottom: 0;
        z-index: 1000;
        width: 240px;
        transform: translateX(-100%);
        transition: transform .25s cubic-bezier(.4,0,.2,1);
    }

    .sidebar-open .sidebar {
        transform: translateX(0) !important;
        width: 240px;
        box-shadow: 4px 0 32px rgba(0,0,0,.7);
    }

    /* Backdrop semitrasparente — chiude la sidebar col tap */
    .sidebar-backdrop {
        display: none;
    }

    .sidebar-open .sidebar-backdrop {
        display: block;
        position: fixed;
        inset: 0;
        z-index: 999;
        background: rgba(0,0,0,.55);
    }

    /* ── Topbar ───────────────────────────────────────────────── */
    .topbar {
        padding: 0 10px;
        gap: 4px;
    }

    .topbar-right {
        display: none;
    }

    /* ── Layout ───────────────────────────────────────────────── */
    .kpi-grid {
        grid-template-columns: 1fr 1fr;
    }

    .page-header {
        flex-direction: column;
        gap: 12px;
    }

    .search-input {
        width: 180px;
    }
}

/* ═══════════════════════════════════════════════════════════════
   CONTESTO — Selettore Logistica / Committente (topbar)
   ═══════════════════════════════════════════════════════════════ */

.contesto-picker {
    display: flex;
    align-items: center;
    gap: 10px;
    flex: 1;
    padding: 0 16px;
    overflow: hidden;
}

.contesto-group {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
}

.contesto-label {
    font-size: 9px;
    font-weight: 600;
    letter-spacing: .1em;
    text-transform: uppercase;
    color: var(--text-dim);
    white-space: nowrap;
}

.contesto-select {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
    padding: 5px 28px 5px 10px;
    font-size: 12px;
    font-family: var(--font-ui);
    outline: none;
    cursor: pointer;
    min-width: 160px;
    max-width: 240px;
    -webkit-appearance: none;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg width='10' height='6' viewBox='0 0 10 6' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M1 1L5 5L9 1' stroke='%238A99B0' stroke-width='1.5' stroke-linecap='round'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 8px center;
    transition: border-color .15s;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

    .contesto-select:focus {
        border-color: var(--accent);
        box-shadow: 0 0 0 2px var(--accent-glow);
    }

    .contesto-select.select-placeholder {
        color: var(--text-muted);
        border-color: var(--border-hi);
    }

    .contesto-select.select-disabled {
        opacity: .4;
        cursor: not-allowed;
    }

.contesto-sep {
    color: var(--text-dim);
    font-size: 16px;
    margin-top: 12px;
    flex-shrink: 0;
}

.contesto-badge {
    display: flex;
    align-items: center;
    gap: 5px;
    font-size: 10px;
    font-weight: 600;
    letter-spacing: .06em;
    color: var(--green);
    background: rgba(45,191,138,.1);
    border: 1px solid rgba(45,191,138,.25);
    border-radius: 99px;
    padding: 4px 10px;
    margin-top: 12px;
    white-space: nowrap;
    flex-shrink: 0;
}

.contesto-loading {
    display: flex;
    align-items: center;
    padding: 0 8px;
}

/* ─── Placeholder "Seleziona logistica" ─────────────────────── */
.contesto-required {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 60vh;
}

.contesto-required-inner {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    padding: 48px 40px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 16px;
    max-width: 440px;
}

/* ── Contesto mobile (dopo le regole base per vincere la cascata) */
@media (max-width: 640px) {
    .contesto-picker {
        padding: 0 4px;
        gap: 4px;
        overflow-x: auto;
        overflow-y: hidden;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
        flex-wrap: nowrap;
    }

    .contesto-picker::-webkit-scrollbar { display: none; }

    .contesto-group {
        flex-shrink: 0;
    }

    .contesto-label {
        font-size: 8px;
    }

    .contesto-select {
        min-width: 0;
        width: 105px;
        max-width: 105px;
        font-size: 11px;
        padding: 4px 18px 4px 7px;
    }

    .contesto-sep {
        display: none;
    }

    .contesto-badge {
        display: none;
    }
}

/* ═══════════════════════════════════════════════════════════════
   EXPORT BUTTON
   ═══════════════════════════════════════════════════════════════ */

.btn-export {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 14px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    font-size: 12px;
    font-family: var(--font-ui);
    font-weight: 500;
    transition: all .15s;
    white-space: nowrap;
}

    .btn-export:hover:not(:disabled) {
        background: rgba(45,191,138,.08);
        border-color: rgba(45,191,138,.4);
        color: var(--green);
    }

    .btn-export.loading {
        opacity: .7;
        cursor: wait;
    }

    .btn-export:disabled {
        opacity: .35;
        cursor: not-allowed;
    }

/* ─── Spinner ────────────────────────────────────────────────── */
.dot-spin {
    width: 18px;
    height: 18px;
    border: 2px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin .6s linear infinite;
}

.dot-spin-sm {
    width: 12px;
    height: 12px;
    border: 1.5px solid rgba(255,255,255,.3);
    border-top-color: currentColor;
    border-radius: 50%;
    animation: spin .6s linear infinite;
}
