/* admin.css — stile backoffice Gestionale Farmacia.
   Design system: FarmaHUB (verde farmacia scuro + accenti amber/red/blue).
   Font: Manrope (testo), Sora (headings + numeri).
   Niente librerie esterne. Variabili CSS per palette consistente. */

/* F-025: tema light (default) + dark via [data-theme="dark"] sull'html.
   Toggle persistente in localStorage('theme'), rispetto prefers-color-scheme
   come default per nuovi utenti. */

:root, html[data-theme="light"] {
    /* --- FarmaHUB brand palette --- */
    --green-900:   #0B4A39;
    --green-700:   #0E5C46;
    --green-500:   #178A62;
    --green-100:   #E3F2EB;
    --green-50:    #F2F9F5;
    --amber:       #B96A15;
    --amber-bg:    #FBF0DF;
    --red:         #B3372E;
    --red-bg:      #FBE9E7;
    --blue:        #20627E;
    --blue-bg:     #E4F0F5;

    /* --- Semantic mapping (usate dai ~330 selectors legacy) --- */
    --c-bg:        var(--green-50);
    --c-bg-alt:    #FFFFFF;
    --c-surface:   #FFFFFF;
    --c-card:      #FFFFFF;
    --c-border:    #DCE8E2;
    --c-text:      #1B2B26;
    --c-text-muted:#5E7169;
    --c-muted:     #5E7169;
    --c-primary:   var(--green-700);
    --c-primary-d: var(--green-900);
    --c-accent:    var(--amber);
    --c-success:   var(--green-500);
    --c-success-bg: var(--green-100);
    --c-warning:   var(--amber);
    --c-warning-bg: var(--amber-bg);
    --c-error:     var(--red);
    --c-error-bg:  var(--red-bg);
    --c-info:      var(--blue);
    --c-info-bg:   var(--blue-bg);
    --radius:      14px;
    --shadow-sm:   0 1px 3px rgba(11,74,57,.06);
    --shadow:      0 2px 10px rgba(11,74,57,.08);

    /* --- Typography --- */
    --font-testo:   'Manrope', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
    --font-display: 'Sora', 'Manrope', system-ui, sans-serif;
}

html[data-theme="dark"] {
    /* Adattamento dark: green-900 diventa background, testi chiari. */
    --green-900:   #072D22;
    --green-700:   #158B6A;
    --green-500:   #2DAE85;
    --green-100:   #113D30;
    --green-50:    #0B211A;
    --amber:       #E9A155;
    --amber-bg:    #3E2C13;
    --red:         #F4736A;
    --red-bg:      #3E1E1B;
    --blue:        #64B0CE;
    --blue-bg:     #10303D;

    --c-bg:        #0B211A;
    --c-bg-alt:    #113D30;
    --c-surface:   #113D30;
    --c-card:      #133E31;
    --c-border:    #1E5A47;
    --c-text:      #E4F1EC;
    --c-text-muted:#8FA79F;
    --c-muted:     #8FA79F;
    --c-primary:   var(--green-500);
    --c-primary-d: var(--green-700);
    --c-accent:    var(--amber);
    --c-success:   var(--green-500);
    --c-success-bg: var(--green-100);
    --c-warning:   var(--amber);
    --c-warning-bg: var(--amber-bg);
    --c-error:     var(--red);
    --c-error-bg:  var(--red-bg);
    --c-info:      var(--blue);
    --c-info-bg:   var(--blue-bg);
    --shadow-sm:   0 1px 2px rgba(0,0,0,.3);
    --shadow:      0 2px 12px rgba(0,0,0,.4);
}

/* Auto-dark se l'utente NON ha mai scelto manualmente */

@media (prefers-color-scheme: dark) {
    html:not([data-theme]) {
        --green-900:   #072D22;
        --green-700:   #158B6A;
        --green-500:   #2DAE85;
        --green-100:   #113D30;
        --green-50:    #0B211A;
        --amber:       #E9A155;
        --amber-bg:    #3E2C13;
        --red:         #F4736A;
        --red-bg:      #3E1E1B;
        --blue:        #64B0CE;
        --blue-bg:     #10303D;
        --c-bg:        #0B211A;
        --c-surface:   #113D30;
        --c-card:      #133E31;
        --c-border:    #1E5A47;
        --c-text:      #E4F1EC;
        --c-muted:     #8FA79F;
        --c-primary:   #2DAE85;
        --c-primary-d: #158B6A;
        --c-success:   #2DAE85;
        --c-success-bg: #113D30;
        --c-warning:   #E9A155;
        --c-error:     #F4736A;
        --c-error-bg:  #3E1E1B;
        --c-info-bg:   #10303D;
        --shadow-sm:   0 1px 2px rgba(0,0,0,.3);
        --shadow:      0 2px 12px rgba(0,0,0,.4);
    }
}

/* Bottone toggle theme (anche per pwa) */

.theme-toggle {
    background: transparent;
    border: 1px solid var(--c-border);
    color: var(--c-muted);
    cursor: pointer;
    border-radius: 50%;
    width: 36px;
    height: 36px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    margin-left: 0.5rem;
    transition: background 0.15s, color 0.15s;
}

.theme-toggle:hover { background: var(--c-bg); color: var(--c-text); }

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    font-family: var(--font-testo, 'Manrope', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif);
    font-size: 15px;
    line-height: 1.5;
    color: var(--c-text);
    background: var(--c-bg);
    min-height: 100vh;
}

/* Headings con font display (Sora) */

h1, h2, h3, h4, h5, h6 {
    font-family: var(--font-display, 'Sora', 'Manrope', sans-serif);
    letter-spacing: -.01em;
}

/* Numeri tabellari uniformi per KPI / valori */

.dash-value, .kpi-value, .kpi-valore, .kpi .num,
td.num, th.num, .num, .qty {
    font-variant-numeric: tabular-nums;
}

html[data-theme="dark"] body.logged-out,
html:not([data-theme]) body.logged-out {
    /* fallback nel dark mode: nessun gradient lavanda chiaro */
}

html[data-theme="dark"] body.logged-out {
    background: linear-gradient(135deg, #1a1625 0%, #2d1b2e 100%);
}

@media (prefers-color-scheme: dark) {
    html:not([data-theme]) body.logged-out {
        background: linear-gradient(135deg, #1a1625 0%, #2d1b2e 100%);
    }
}

h1, h2, h3 { margin: 0 0 0.5em; color: var(--c-text); }

h1 { font-size: 1.75rem; }

h2 { font-size: 1.25rem; }

.muted { color: var(--c-muted); margin: 0; }

a { color: var(--c-primary); text-decoration: none; }

a:hover { text-decoration: underline; }

/* ── Layout container ─────────────────────────────────────── */

/* .container: definizione FarmaHUB in fondo file (max-width 1100px) */

body.logged-out .container {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* ── Navigazione ──────────────────────────────────────────── */

.app-brand:hover { text-decoration: none; }

.brand-mark {
    background: var(--c-primary);
    color: #fff;
    width: 32px;
    height: 32px;
    border-radius: var(--radius);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 0.875rem;
}

.brand-mark.big {
    width: 56px;
    height: 56px;
    font-size: 1.5rem;
    margin: 0 auto 1rem;
}

.brand-text { font-weight: 600; }

/* Logo Farmacia: barra di navigazione (ogni pagina) e login. */

.brand-logo { height: 36px; width: auto; display: block; }

.auth-logo { display: block; width: 100%; max-width: 240px; height: auto; margin: 0 auto 1rem; }

.menu-item.is-active:hover { background: var(--c-primary-d); }

.menu-item.is-soon { opacity: 0.55; cursor: help; }

.menu-item .badge {
    font-size: 0.65rem;
    background: var(--c-border);
    color: var(--c-muted);
    padding: 1px 5px;
    border-radius: 3px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.user-info {
    font-size: 0.85rem;
    text-align: right;
    line-height: 1.2;
}

.user-role {
    display: block;
    color: var(--c-muted);
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

/* ── Footer ───────────────────────────────────────────────── */

.app-footer {
    text-align: center;
    color: var(--c-muted);
    padding: 2rem 1rem;
    font-size: 0.8rem;
}

/* ── Bottoni ──────────────────────────────────────────────── */

/* .btn-primary + .btn-block: definizioni FarmaHUB in fondo file */

/* ── Form ─────────────────────────────────────────────────── */

/* .auth-card: definizione FarmaHUB in fondo file (con .login-card alias) */

.auth-header { text-align: center; margin-bottom: 1.5rem; }

.auth-header h1 { font-size: 1.4rem; margin-bottom: 0.25rem; }

.auth-form { display: flex; flex-direction: column; gap: 1rem; }

.auth-form label { display: flex; flex-direction: column; gap: 0.35rem; }

.auth-form label span { font-size: 0.85rem; color: var(--c-muted); }

.auth-form input {
    padding: 0.7rem 0.85rem;
    border: 1px solid var(--c-border);
    border-radius: var(--radius);
    font-size: 0.95rem;
    transition: border 0.15s, box-shadow 0.15s;
}

.auth-form input:focus {
    outline: none;
    border-color: var(--c-primary);
    box-shadow: 0 0 0 3px rgba(109,40,217,0.15);
}

/* ── Alert ────────────────────────────────────────────────── */

/* ── Dashboard ────────────────────────────────────────────── */

/* .page-header: definizione FarmaHUB in fondo file (display:flex justify-between) */

.kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 1rem;
    margin-bottom: 2rem;
}

.kpi-card {
    background: var(--c-surface);
    border: 1px solid var(--c-border);
    border-radius: var(--radius);
    padding: 1.25rem;
    box-shadow: var(--shadow-sm);
}

.kpi-card.kpi-placeholder { opacity: 0.6; }

/* .kpi-label: definizione FarmaHUB in fondo file */

/* .kpi-value: definizione FarmaHUB in fondo file (Sora font, green-700) */

.kpi-note {
    font-size: 0.75rem;
    color: var(--c-muted);
    margin-top: 0.25rem;
}

.roadmap-card {
    background: var(--c-surface);
    border: 1px solid var(--c-border);
    border-radius: var(--radius);
    padding: 1.5rem;
    box-shadow: var(--shadow-sm);
}

.roadmap-list {
    list-style: none;
    padding: 0;
    margin: 1rem 0 0;
}

.roadmap-list li {
    padding: 0.6rem 0;
    border-bottom: 1px solid var(--c-border);
    color: var(--c-muted);
}

.roadmap-list li:last-child { border-bottom: none; }

.roadmap-list li.done {
    color: var(--c-success);
    font-weight: 500;
}

.roadmap-list li.done::before { content: "✓ "; }

.roadmap-list li:not(.done)::before { content: "○ "; color: var(--c-border); }

/* ── Pagina errore ────────────────────────────────────────── */

.error-page {
    text-align: center;
    padding: 4rem 1rem;
}

.error-page h1 {
    font-size: 5rem;
    color: var(--c-primary);
    margin-bottom: 0.5rem;
}

/* ── Page header con azioni a destra ──────────────────────── */

/* ── Filtri lista ─────────────────────────────────────────── */

.filters {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1rem;
    flex-wrap: wrap;
}

.filters input[type="search"],
.filters select {
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--c-border);
    border-radius: var(--radius);
    font-size: 0.9rem;
    background: var(--c-surface);
}

.filters input[type="search"] {
    flex: 1;
    min-width: 220px;
}

/* ── Tabelle dati ─────────────────────────────────────────── */

.table-card {
    background: var(--c-surface);
    border: 1px solid var(--c-border);
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: var(--shadow-sm);
    margin-bottom: 1rem;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
}

.data-table thead th {
    text-align: left;
    padding: 0.75rem 1rem;
    background: #fafafa;
    border-bottom: 1px solid var(--c-border);
    font-weight: 600;
    color: var(--c-muted);
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.data-table tbody td {
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--c-border);
    vertical-align: middle;
}

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

.data-table .row-inactive { opacity: 0.55; }

.data-table .row-inactive:hover { background: #f5f5f5; }

.data-table .empty {
    text-align: center;
    color: var(--c-muted);
    padding: 2rem !important;
}

.data-table .num { text-align: right; font-variant-numeric: tabular-nums; }

.data-table code {
    background: #f3f4f6;
    padding: 0.1rem 0.4rem;
    border-radius: 3px;
    font-size: 0.85em;
}

.row-actions { text-align: right; white-space: nowrap; }

.cell-thumb { width: 56px; }

.cell-thumb img {
    width: 48px; height: 48px; object-fit: cover;
    border-radius: 4px; border: 1px solid var(--c-border);
}

.thumb-placeholder {
    display: inline-block; width: 48px; height: 48px;
    background: #f3f4f6; border-radius: 4px;
    text-align: center; line-height: 48px; color: var(--c-muted);
}

/* ── Badge ────────────────────────────────────────────────── */

/* .badge-success: definizione FarmaHUB in fondo file */

/* ── Form entità ──────────────────────────────────────────── */

.entity-form fieldset {
    background: var(--c-surface);
    border: 1px solid var(--c-border);
    border-radius: var(--radius);
    padding: 1.25rem 1.5rem;
    margin: 0 0 1rem;
    box-shadow: var(--shadow-sm);
}

.entity-form legend {
    padding: 0 0.5rem;
    font-weight: 600;
    color: var(--c-muted);
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 1rem;
}

.form-grid label {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
}

.form-grid label > span,
.form-grid .field-label {
    font-size: 0.8rem;
    color: var(--c-muted);
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.form-grid input,
.form-grid select,
.form-grid textarea {
    padding: 0.55rem 0.75rem;
    border: 1px solid var(--c-border);
    border-radius: var(--radius);
    font-size: 0.95rem;
    background: var(--c-surface);
    font-family: inherit;
}

.form-grid input:focus,
.form-grid select:focus,
.form-grid textarea:focus {
    outline: none;
    border-color: var(--c-primary);
    box-shadow: 0 0 0 3px rgba(109,40,217,0.12);
}

.form-grid input[readonly] { background: #f9fafb; color: var(--c-muted); }

.form-grid .span-1 { grid-column: span 1; }

.form-grid .span-2 { grid-column: span 2; }

.form-grid .span-3 { grid-column: span 3; }

.form-grid .span-4 { grid-column: span 4; }

.form-grid .span-6 { grid-column: span 6; }

.checkbox-row {
    flex-direction: row !important;
    align-items: center;
    gap: 0.5rem !important;
}

.checkbox-row input[type="checkbox"] { width: auto; }

.form-hint { color: var(--c-muted); font-size: 0.85rem; align-self: end; }

.article-preview {
    max-width: 140px; max-height: 140px;
    border: 1px solid var(--c-border); border-radius: var(--radius);
    object-fit: cover;
}

.form-actions {
    display: flex;
    gap: 0.5rem;
    align-items: center;
    margin-top: 0.5rem;
}

/* .btn-danger: definizione FarmaHUB in fondo file (rosa+rosso soft). Nota: la
   vecchia def aveva 'margin-left:auto' per push-right; le view che ne hanno
   bisogno possono aggiungere la utility class '.ml-auto' esplicitamente. */

/* ── Alert (success / warning / info) ─────────────────────── */

/* ── Paginazione ──────────────────────────────────────────── */

.pagination {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0.5rem 0;
    font-size: 0.85rem;
    color: var(--c-muted);
}

.pagination .pg-info { flex: 1; text-align: center; }

.pagination a {
    padding: 0.4rem 0.8rem;
    border: 1px solid var(--c-border);
    border-radius: var(--radius);
    background: var(--c-surface);
}

.pagination a:hover {
    background: var(--c-primary);
    color: #fff;
    text-decoration: none;
}

/* ── Editor listino ──────────────────────────────────────── */

.editor-actions {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: 1rem;
    margin: 1rem 0 2rem;
}

.add-row-form, .bulk-action {
    background: var(--c-surface);
    border: 1px solid var(--c-border);
    border-radius: var(--radius);
    padding: 1.25rem;
    box-shadow: var(--shadow-sm);
}

.add-row-form h3,
.bulk-action h3 {
    margin: 0 0 0.75rem;
    font-size: 0.95rem;
    color: var(--c-muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.bulk-action {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    gap: 0.75rem;
}

.inline-row-form {
    display: flex;
    gap: 0.4rem;
    align-items: center;
}

.inline-row-form input[type="number"],
.inline-row-form input[type="text"] {
    padding: 0.35rem 0.5rem;
    border: 1px solid var(--c-border);
    border-radius: 4px;
    font-size: 0.85rem;
    width: 100px;
}

.inline-row-form input[name="prezzo"]            { width: 110px; }

.inline-row-form input[name="sconto_percentuale"] { width: 75px; }

.inline-row-form input[name="note"]              { flex: 1; min-width: 120px; width: auto; }

.btn-danger-soft {
    color: var(--c-error);
    border-color: var(--c-border);
    background: transparent;
    padding: 0.25rem 0.5rem;
    font-weight: 700;
}

.btn-danger-soft:hover { background: var(--c-error-bg); }

@media (max-width: 1100px) {
    .editor-actions { grid-template-columns: 1fr; }
}

/* ── Stato ordini: badge addizionali ────────────────────── */

/* .badge-error: definizione FarmaHUB in fondo file */

/* ── Card riassunto ordine ─────────────────────────────── */

.ordine-summary {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 2rem;
    background: var(--c-surface);
    border: 1px solid var(--c-border);
    border-radius: var(--radius);
    padding: 1.5rem;
    margin-bottom: 1.5rem;
    box-shadow: var(--shadow-sm);
}

.ordine-summary-main {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 2rem;
    grid-column: 1 / -1;
}

.ordine-summary h2 { margin: 0.25rem 0; font-size: 1.3rem; }

.ordine-summary .muted small { font-size: 0.85rem; }

.ordine-stato { text-align: right; display: flex; flex-direction: column; gap: 0.35rem; align-items: flex-end; }

.ordine-totali {
    grid-column: 1 / -1;
    display: flex;
    gap: 2rem;
    padding-top: 1rem;
    border-top: 1px solid var(--c-border);
}

.ordine-totali > div {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.ordine-totali strong { font-size: 1.1rem; font-variant-numeric: tabular-nums; }

.ordine-totale-lordo { margin-left: auto; text-align: right; }

.ordine-totale-lordo strong { font-size: 1.5rem; color: var(--c-primary); }

/* ── Pannello firma OTP ────────────────────────────────── */

.firma-panel {
    background: var(--c-surface);
    border: 1px solid var(--c-border);
    border-left: 4px solid var(--c-primary);
    border-radius: var(--radius);
    padding: 1.25rem;
    box-shadow: var(--shadow-sm);
}

.firma-panel h3 {
    margin: 0 0 0.5rem;
    font-size: 1rem;
    color: var(--c-primary);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.firma-form {
    display: flex;
    gap: 0.75rem;
    align-items: end;
    margin: 1rem 0;
    flex-wrap: wrap;
}

.firma-form label { display: flex; flex-direction: column; gap: 0.3rem; flex: 1; min-width: 200px; }

.firma-form label > span { font-size: 0.8rem; color: var(--c-muted); }

.firma-form input {
    padding: 0.55rem 0.75rem;
    border: 1px solid var(--c-border);
    border-radius: var(--radius);
    font-size: 1rem;
    font-family: ui-monospace, monospace;
    letter-spacing: 0.15em;
}

.firma-form input[name="codice"] {
    text-align: center;
    font-size: 1.5rem;
    letter-spacing: 0.4em;
}

/* ── Hash firma card ──────────────────────────────────── */

.hash-card {
    background: #f9fafb;
    border: 1px dashed var(--c-border);
    border-radius: var(--radius);
    padding: 1.25rem;
    margin: 1.5rem 0;
}

.hash-card h3 { margin: 0 0 0.5rem; font-size: 0.9rem; color: var(--c-muted); text-transform: uppercase; }

.hash-mono {
    display: block;
    font-family: ui-monospace, "SF Mono", Menlo, monospace;
    font-size: 0.8rem;
    word-break: break-all;
    background: var(--c-surface);
    padding: 0.5rem;
    border-radius: 4px;
    margin: 0.5rem 0;
}

.hash-meta {
    list-style: none;
    padding: 0;
    margin: 0.75rem 0 0;
    font-size: 0.85rem;
    color: var(--c-muted);
}

.hash-meta li { padding: 0.15rem 0; }

/* ── Riga ordine: valori calcolati read-only ────────── */

.num-readonly {
    display: inline-block;
    min-width: 65px;
    padding: 0.35rem 0.5rem;
    text-align: right;
    font-variant-numeric: tabular-nums;
    color: var(--c-text);
}

@media (max-width: 900px) {
    .ordine-summary, .ordine-summary-main { grid-template-columns: 1fr; }
    .ordine-stato { text-align: left; align-items: flex-start; }
    .ordine-totali { flex-direction: column; gap: 0.75rem; }
    .ordine-totale-lordo { margin-left: 0; text-align: left; }
}

/* ── Import / Export ──────────────────────────────────────── */

.import-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 1rem;
    margin: 1rem 0;
}

.import-grid .card { margin: 0; }

.import-grid .card h3 { font-size: 1.05rem; }

.import-grid input[type="file"] {
    margin: 0.5rem 0;
    width: 100%;
}

.errors-list {
    background: #fffbeb;
    border: 1px solid #fde68a;
    border-radius: var(--radius);
    padding: 0.75rem 1rem 0.75rem 2rem;
    margin: 0.5rem 0;
    max-height: 240px;
    overflow-y: auto;
    font-size: 0.85rem;
    color: #92400e;
}

.csv-sample {
    background: #f9fafb;
    border: 1px solid var(--c-border);
    border-radius: var(--radius);
    padding: 0.75rem;
    font-family: ui-monospace, "SF Mono", Menlo, monospace;
    font-size: 0.78rem;
    overflow-x: auto;
    white-space: pre-wrap;
    word-break: break-all;
}

.card { margin-bottom: 1rem; }

.card h3 { margin-top: 0; }

/* ── Dashboard direzionale (Fase 2.4) ────────────────────── */

.period-switch {
    display: flex; gap: 0.25rem; flex-wrap: wrap;
}

.period-btn {
    padding: 0.4rem 0.75rem;
    border: 1px solid var(--c-border);
    border-radius: var(--radius);
    background: var(--c-surface);
    color: var(--c-muted);
    font-size: 0.85rem;
    text-decoration: none;
}

.period-btn:hover { background: var(--c-bg); text-decoration: none; }

.period-btn.is-active { background: var(--c-primary); color: #fff; border-color: var(--c-primary); }

.dash-kpi {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 1rem;
    margin: 1rem 0 1.5rem;
}

.dash-card {
    background: var(--c-surface);
    border: 1px solid var(--c-border);
    border-radius: var(--radius);
    padding: 1.25rem;
    box-shadow: var(--shadow-sm);
}

.dash-card h3 {
    margin: 0 0 1rem; font-size: 0.95rem;
    color: var(--c-muted); text-transform: uppercase; letter-spacing: 0.04em;
}

.dash-card-primary {
    border-color: var(--c-primary);
    background: linear-gradient(135deg, #faf5ff 0%, #ffffff 60%);
}

.dash-card-warn {
    border-left: 4px solid var(--c-warning);
}

.dash-label {
    font-size: 0.8rem; color: var(--c-muted);
    text-transform: uppercase; letter-spacing: 0.05em;
    margin-bottom: 0.4rem;
}

.dash-value {
    font-size: 1.7rem; font-weight: 700; color: var(--c-text);
    font-variant-numeric: tabular-nums;
    margin-bottom: 0.25rem;
}

.dash-card-primary .dash-value { color: var(--c-primary); }

.dash-meta {
    font-size: 0.8rem; color: var(--c-muted);
    margin-bottom: 0.5rem;
}

.trend-up   { color: var(--c-success); font-weight: 600; }

.trend-down { color: var(--c-error); font-weight: 600; }

.trend-flat { color: var(--c-muted); }

.sparkline { display: block; width: 100%; height: 40px; }

/* .dash-grid-2: definizione FarmaHUB in fondo file (auto-fit responsive) */

/* ── Bar list (distribuzione) ─────────────── */

/* ── Top list (clienti / articoli / agenti) ──── */

.top-list { list-style: none; padding: 0; margin: 0; counter-reset: top; }

.top-list li {
    counter-increment: top;
    display: grid;
    grid-template-columns: 1fr auto;
    grid-template-areas: "name val" "meta val";
    padding: 0.5rem 0 0.5rem 2rem;
    border-bottom: 1px solid var(--c-border);
    position: relative;
    font-size: 0.9rem;
}

.top-list li:last-child { border-bottom: none; }

.top-list li::before {
    content: counter(top);
    position: absolute; left: 0; top: 50%;
    transform: translateY(-50%);
    background: var(--c-primary); color: #fff;
    width: 22px; height: 22px; border-radius: 50%;
    display: inline-flex; align-items: center; justify-content: center;
    font-size: 0.75rem; font-weight: 700;
}

.top-list li a, .top-list li strong { grid-area: name; font-weight: 600; }

.top-list li small { grid-area: meta; color: var(--c-muted); font-size: 0.75rem; }

.top-val { grid-area: val; align-self: center; font-variant-numeric: tabular-nums; font-weight: 600; }

/* ── Event list (ultimi ordini) ──────────────── */

.event-list { list-style: none; padding: 0; margin: 0; }

.event-list li {
    display: grid;
    grid-template-columns: 1fr auto;
    grid-template-areas: "name meta" "info meta";
    padding: 0.5rem 0;
    border-bottom: 1px solid var(--c-border);
    font-size: 0.85rem;
}

.event-list li:last-child { border-bottom: none; }

.event-list li a { grid-area: name; font-weight: 600; }

.event-list li small { grid-area: info; color: var(--c-muted); }

.event-meta { grid-area: meta; align-self: center; display: flex; flex-direction: column; align-items: flex-end; gap: 0.25rem; }

@media (max-width: 1000px) {
    .dash-grid-2, .dash-grid-3 { grid-template-columns: 1fr; }
}

/* ── Score predittivo ────────────────────────────────────── */

.score-bar {
    position: relative;
    background: #f3f4f6;
    border-radius: 4px;
    height: 24px;
    overflow: hidden;
    min-width: 100px;
}

.score-bar .score-fill {
    height: 100%;
    transition: width 0.3s;
}

.score-bar span {
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    display: flex; align-items: center; justify-content: center;
    font-weight: 700; font-size: 0.85rem;
    color: var(--c-text);
}

.alert-list {
    list-style: none;
    padding: 0;
    margin: 0.5rem 0 0;
}

.alert-list .alert {
    margin: 0.25rem 0;
}

/* ── Responsive ───────────────────────────────────────────── */

@media (max-width: 900px) {
    .form-grid { grid-template-columns: repeat(2, 1fr); }
    .form-grid [class*="span-"] { grid-column: span 2; }
}

@media (max-width: 768px) {
    .app-nav-inner { flex-direction: column; align-items: flex-start; gap: 0.75rem; }
    .app-menu { width: 100%; }
    .app-user { width: 100%; justify-content: space-between; }
    .container { padding: 1rem; }
}

/* ── F-025: overrides specifici per dark mode ─────────────── */

/* Tabelle, badge, alert: invertiamo le palette pastello chiare in versione dark. */

html[data-theme="dark"] .data-table thead,
html[data-theme="dark"] .data-table tbody tr:nth-child(even) { background: #232733; }

html[data-theme="dark"] .data-table tbody tr:hover { background: #2d3748; }

html[data-theme="dark"] .data-table .row-inactive { color: var(--c-muted); background: #1a1f2a; }

html[data-theme="dark"] .data-table .row-warn { background: #3a2a14; }

html[data-theme="dark"] code,
html[data-theme="dark"] pre { background: #232733; color: var(--c-text); }

html[data-theme="dark"] .menu-item:not(.is-active):hover { background: #2d2640; color: var(--c-text); }

html[data-theme="dark"] .alert-success { background: #064e3b; color: #d1fae5; border-color: #047857; }

html[data-theme="dark"] .alert-warning { background: #78350f; color: #fef3c7; border-color: #b45309; }

html[data-theme="dark"] .alert-info    { background: #1e3a8a; color: #dbeafe; border-color: #2563eb; }

html[data-theme="dark"] .alert-error   { background: #7f1d1d; color: #fee2e2; border-color: #b91c1c; }

html[data-theme="dark"] .badge-success-dark { background: #d1fae5; color: #065f46; }

html[data-theme="dark"] .badge-warn         { background: #78350f; color: #fef3c7; border-color: #b45309; }

html[data-theme="dark"] input,
html[data-theme="dark"] select,
html[data-theme="dark"] textarea {
    background: var(--c-surface);
    color: var(--c-text);
    border-color: var(--c-border);
}

html[data-theme="dark"] input::placeholder { color: var(--c-muted); }

/* Stessa logica anche con prefers-color-scheme: dark se utente non ha scelto */

@media (prefers-color-scheme: dark) {
    html:not([data-theme]) .data-table thead,
    html:not([data-theme]) .data-table tbody tr:nth-child(even) { background: #232733; }
    html:not([data-theme]) .data-table tbody tr:hover { background: #2d3748; }
    html:not([data-theme]) code,
    html:not([data-theme]) pre { background: #232733; color: var(--c-text); }
    html:not([data-theme]) input,
    html:not([data-theme]) select,
    html:not([data-theme]) textarea {
        background: var(--c-surface); color: var(--c-text); border-color: var(--c-border);
    }
    html:not([data-theme]) .alert-success { background: #064e3b; color: #d1fae5; border-color: #047857; }
    html:not([data-theme]) .alert-warning { background: #78350f; color: #fef3c7; border-color: #b45309; }
    html:not([data-theme]) .alert-info    { background: #1e3a8a; color: #dbeafe; border-color: #2563eb; }
    html:not([data-theme]) .alert-error   { background: #7f1d1d; color: #fee2e2; border-color: #b91c1c; }
    html:not([data-theme]) .badge-success { background: #064e3b; color: #d1fae5; }
    html:not([data-theme]) .badge-warning { background: #78350f; color: #fef3c7; }
    html:not([data-theme]) .badge-info    { background: #1e3a8a; color: #dbeafe; }
}

/* ── F-023: stile stampa / PDF (browser print → save as PDF) ───── */

@media print {
    /* Reset colori per stampa (no dark mode in print) */
    html, body { background: white !important; color: #000 !important; font-size: 11pt; }

    /* Nasconde elementi UI non utili per la stampa */
    .app-nav, .app-footer, .no-print,
    .filters, .form-actions, .back-link,
    .theme-toggle, .app-user, .btn,
    nav, .breadcrumb {
        display: none !important;
    }

    .print-only { display: block !important; }
    body:not(.has-print-block) .print-only { display: none; }

    /* Header titolo: visibile in print con prefisso azienda */
    h1.print-only::before { content: "Farmacia — "; color: #666; font-weight: normal; }

    /* Container occupa tutta la pagina */
    .container { max-width: none !important; padding: 0 !important; margin: 0 !important; }
    main.container { padding: 1cm !important; }

    /* Card: niente shadow, bordo sottile per separazione */
    .card, .hash-card, section.card {
        box-shadow: none !important;
        background: white !important;
        border: 1px solid #ccc !important;
        padding: 0.5cm !important;
        margin-bottom: 0.5cm !important;
        page-break-inside: avoid;
    }

    /* Tabelle: ottimizzate per A4, evita break a metà riga */
    .data-table {
        width: 100% !important;
        font-size: 9.5pt !important;
        border-collapse: collapse !important;
    }
    .data-table th, .data-table td {
        padding: 4px 6px !important;
        border: 1px solid #ddd !important;
        color: #000 !important;
    }
    .data-table thead { background: #f0f0f0 !important; }
    .data-table tbody tr { page-break-inside: avoid; }
    .data-table tr:nth-child(even) { background: #fafafa !important; }

    /* Badge & alert in B/N */
    .badge { background: white !important; color: #333 !important; border: 1px solid #999 !important; }
    .alert { background: #f5f5f5 !important; color: #000 !important; border: 1px solid #999 !important; }

    /* Link: mostra URL accanto al testo (utile per documenti firmati) */
    a[href]:not(.btn)::after {
        content: " (" attr(href) ")";
        font-size: 9pt;
        color: #666;
    }
    a[href^="#"]::after, a[href^="javascript:"]::after { content: ""; }

    /* Hash + codice fissati monospace per leggibilità */
    code, pre { background: #f5f5f5 !important; color: #000 !important; border: 1px solid #ddd !important; }

    /* Pagina A4, margini ridotti */
    @page { size: A4; margin: 1.5cm 1.2cm; }

    /* Page break in punti naturali */
    h1, h2, h3 { page-break-after: avoid; }
    section { page-break-inside: avoid; }
}

/* .print-only nascosto a video, mostrato solo in print */

.print-only { display: none; }

/* ── F-085: fix grafica/responsività audit Round 8 ──────── */

/* Disabled state per tutti i bottoni (era mancante) */

.btn:disabled,
.btn[aria-disabled="true"] {
    opacity: 0.55;
    cursor: not-allowed;
    pointer-events: none;
    filter: grayscale(20%);
}

/* Focus visibile per navigazione tastiera (WCAG 2.1 SC 2.4.7) */

.menu-item:focus-visible,
.btn:focus-visible,
.data-table a:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
    outline: 2px solid var(--c-primary);
    outline-offset: 2px;
    border-radius: 3px;
}

/* Touch target min 44px (WCAG 2.5.5) anche per btn-sm */

@media (hover: none) and (pointer: coarse) {
    /* device touch-only: alza touch target a 44px */
    .btn, .btn-sm, .menu-item, .pagination a {
        min-height: 44px;
    }
}

/* Zebra stripe tabelle anche light (era solo dark) */

.data-table tbody tr:nth-child(even) {
    background: var(--c-bg-alt);
}

.data-table tbody tr:hover {
    background: rgba(109, 40, 217, 0.05);
}

/* Reduce motion preference (WCAG 2.3.3) */

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}

/* Dark mode coverage per componenti mancanti (B-118) */

html[data-theme="dark"] .data-table thead {
    background: var(--c-surface);
    color: var(--c-text);
}

html[data-theme="dark"] .data-table code,
html[data-theme="dark"] code {
    background: var(--c-bg-alt);
    color: var(--c-text);
}

html[data-theme="dark"] .hash-card,
html[data-theme="dark"] .hash-mono {
    background: var(--c-bg-alt);
    color: var(--c-text);
}

html[data-theme="dark"] .form-grid input[readonly],
html[data-theme="dark"] input[readonly] {
    background: var(--c-bg-alt);
    color: var(--c-muted);
}

html[data-theme="dark"] .help-tip {
    background: var(--c-bg-alt);
    color: var(--c-text-muted);
}

/* Mobile menu hamburger visibility (era nascosto sempre) */

@media (max-width: 768px) {
    #mobile-menu-toggle { display: inline-flex; align-items: center; gap: 0.4rem; }
    .app-menu { display: none; }
    .app-menu.is-mobile-open {
        display: flex !important;
        flex-direction: column;
        position: absolute;
        top: 100%; left: 0; right: 0;
        background: var(--c-surface);
        border-top: 1px solid var(--c-border);
        padding: 0.5rem;
        z-index: 50;
    }
}

/* AI card priority borders via CSS vars (no hardcoded) */

/* Pagination touch-friendly mobile */

@media (max-width: 640px) {
    .pagination a {
        padding: 0.5rem 0.75rem;
        font-size: 0.85rem;
        min-width: 44px;
        text-align: center;
    }
    .pagination .muted.small { display: none; } /* nascondi "Pagina X di Y" su mobile */
}

/* Print stylesheet: standardizza margin a 1cm uniforme */

@media print {
    @page { size: A4; margin: 1cm; }
    /* fix per skip-link printing */
    .skip-link { display: none !important; }
}

/* F-106: form grid responsive uniforme (era inconsistente span-N mobile) */

@media (max-width: 768px) {
    .form-grid {
        grid-template-columns: 1fr !important;
    }
    .form-grid [class*="span-"] {
        grid-column: 1 / -1 !important;
    }
}

/* F-107: focus trap visivo modali (#fh-search-overlay, #fh-ai-overlay) */

#fh-search-overlay:focus-within .fh-search-box,
#fh-ai-overlay:focus-within .fh-ai-panel {
    outline: 3px solid var(--c-primary);
    outline-offset: -3px;
}

/* F-108: stato loading universale via aria-busy */

[aria-busy="true"] {
    opacity: 0.7;
    cursor: progress;
    position: relative;
}

[aria-busy="true"]::after {
    content: "";
    position: absolute;
    top: 0; right: 0; bottom: 0; left: 0;
    background: repeating-linear-gradient(
        45deg,
        transparent, transparent 10px,
        rgba(109, 40, 217, 0.05) 10px, rgba(109, 40, 217, 0.05) 20px
    );
    animation: ariaBusyStripe 1s linear infinite;
    pointer-events: none;
}

@keyframes ariaBusyStripe {
    from { background-position: 0 0; }
    to   { background-position: 40px 0; }
}

@media (prefers-reduced-motion: reduce) {
    [aria-busy="true"]::after { animation: none; }
}

/* F-109: better contrast su badge in dark mode */

html[data-theme="dark"] .badge-info    { background: #1e3a8a; color: #dbeafe; }

html[data-theme="dark"] .badge-success { background: #064e3b; color: #d1fae5; }

html[data-theme="dark"] .badge-warning { background: #78350f; color: #fef3c7; }

html[data-theme="dark"] .badge-error   { background: #7f1d1d; color: #fecaca; }

html[data-theme="dark"] .badge-muted   { background: #374151; color: #d1d5db; }

/* F-110: input/select consistency height (era 32-40px misti) */

.form-grid input:not([type="checkbox"]):not([type="radio"]),
.form-grid select,
.form-grid textarea,
.filters input, .filters select {
    min-height: 40px;
    box-sizing: border-box;
}

/* Skip to main content link (WCAG 2.4.1) */

/* ── F-082: tooltip help inline ─────────────────────────── */

.help-tip {
    display: inline-block;
    width: 18px; height: 18px;
    border-radius: 50%;
    background: var(--c-bg-alt, #e5e7eb);
    color: var(--c-text-muted, #666);
    font-size: 12px; font-weight: 600;
    text-align: center; line-height: 18px;
    cursor: help;
    position: relative;
    margin-left: 0.3rem;
}

.help-tip:hover { background: var(--c-primary); color: #fff; }

.help-tip::after {
    content: attr(data-tip);
    position: absolute; bottom: calc(100% + 8px); left: 50%;
    transform: translateX(-50%);
    background: #1f2937; color: #f9fafb;
    padding: 0.5rem 0.7rem;
    border-radius: 4px;
    font-size: 0.8rem; font-weight: 400;
    line-height: 1.4;
    white-space: normal;
    min-width: 180px; max-width: 280px;
    text-align: left;
    z-index: 100;
    opacity: 0; pointer-events: none;
    transition: opacity 0.15s;
}

.help-tip:hover::after { opacity: 1; }

/* ── F-083: empty states più ricchi ─────────────────────── */

.empty-state-text { color: var(--c-text-muted, #666); margin-bottom: 1rem; }

/* ── F-084: mobile responsive data-table accordion ──────── */

@media (max-width: 640px) {
    .data-table.mobile-cards { display: block; }
    .data-table.mobile-cards thead { display: none; }
    .data-table.mobile-cards tbody { display: block; }
    .data-table.mobile-cards tr {
        display: block;
        border: 1px solid var(--c-border);
        border-radius: 6px;
        padding: 0.6rem;
        margin-bottom: 0.6rem;
        background: var(--c-card, #fff);
    }
    .data-table.mobile-cards td {
        display: flex; justify-content: space-between; align-items: baseline;
        border: 0;
        padding: 0.25rem 0;
        font-size: 0.9rem;
    }
    .data-table.mobile-cards td::before {
        content: attr(data-label);
        font-weight: 600;
        color: var(--c-text-muted, #666);
        margin-right: 0.5rem;
        flex-shrink: 0;
    }
}

/* ── F-053: dashboard agente AI suggestions ─────────────── */

.ai-suggestions .ai-cards {
    display: flex; flex-direction: column; gap: 0.6rem;
}

.ai-card {
    display: flex; align-items: center; gap: 1rem;
    background: var(--c-card, #fff);
    border: 1px solid var(--c-border);
    border-left: 4px solid var(--c-primary);
    border-radius: 8px;
    padding: 0.8rem 1rem;
}

.ai-card[data-priority="1"] { border-left-color: #ef4444; }

.ai-card[data-priority="2"] { border-left-color: #f97316; }

.ai-card[data-priority="3"] { border-left-color: #3b82f6; }

.ai-card[data-priority="4"] { border-left-color: #eab308; }

.ai-card[data-priority="5"] { border-left-color: #10b981; }

.ai-card[data-priority="6"] { border-left-color: #64748b; }

.ai-card-icon { font-size: 1.6rem; flex: 0 0 auto; }

.ai-card-body { flex: 1; min-width: 0; }

.ai-card-title { font-weight: 600; }

.ai-card-detail { font-size: 0.9rem; margin-top: 0.15rem; }

@media (max-width: 640px) {
    .ai-card { flex-wrap: wrap; }
    .ai-card-body { flex-basis: 100%; }
}

/* ── F-064: AI assistant overlay (Cmd+J/Ctrl+J) ──────── */

#fh-ai-overlay {
    position: fixed; inset: 0; z-index: 9998;
    background: rgba(0,0,0,0.3);
    display: none;
}

#fh-ai-overlay.is-open { display: block; }

.fh-ai-panel {
    position: absolute; top: 0; right: 0; bottom: 0;
    width: 420px; max-width: 100vw;
    background: var(--c-bg); color: var(--c-text);
    box-shadow: -8px 0 30px rgba(0,0,0,0.2);
    display: flex; flex-direction: column;
}

.fh-ai-header {
    padding: 0.8rem 1rem;
    border-bottom: 1px solid var(--c-border);
    display: flex; flex-direction: column; gap: 0.2rem;
    position: relative;
}

.fh-ai-header small { color: var(--c-text-muted, #666); font-size: 0.75rem; }

.fh-ai-close {
    position: absolute; top: 0.6rem; right: 0.7rem;
    background: transparent; border: 0; cursor: pointer;
    font-size: 1.2rem; padding: 0.2rem 0.5rem;
    color: var(--c-text);
}

.fh-ai-history {
    flex: 1; overflow-y: auto;
    padding: 0.8rem 1rem;
}

.fh-ai-hint {
    color: var(--c-text-muted, #888);
    font-size: 0.85rem;
    padding: 0.5rem 0;
}

.fh-ai-msg {
    margin: 0.5rem 0; padding: 0.5rem 0.7rem;
    border-radius: 6px;
    font-size: 0.9rem; line-height: 1.4;
    white-space: pre-wrap; word-wrap: break-word;
}

.fh-ai-msg-user { background: var(--c-primary); color: #fff; }

.fh-ai-msg-assistant { background: var(--c-bg-alt, #f5f5f5); }

.fh-ai-msg-thinking { color: var(--c-text-muted, #888); font-style: italic; }

.fh-ai-msg-error { background: #fee; color: #c00; }

.fh-ai-form {
    border-top: 1px solid var(--c-border);
    padding: 0.6rem;
    display: flex; gap: 0.5rem; align-items: end;
}

.fh-ai-form textarea {
    flex: 1; resize: vertical; min-height: 50px;
    padding: 0.4rem 0.6rem; font: inherit;
    background: var(--c-bg); color: var(--c-text);
    border: 1px solid var(--c-border); border-radius: 4px;
}

.fh-ai-form button {
    padding: 0.5rem 0.9rem;
    background: var(--c-primary); color: #fff;
    border: 0; border-radius: 4px; cursor: pointer;
    font: inherit;
}

.fh-ai-form button:hover { opacity: 0.9; }

@media (max-width: 480px) {
    .fh-ai-panel { width: 100vw; }
}

/* ── F-051: search globale ⌘K overlay ──────────────────── */

#fh-search-overlay {
    position: fixed; inset: 0; z-index: 9999;
    background: rgba(0,0,0,0.5);
    display: none; align-items: flex-start; justify-content: center;
    padding-top: 12vh;
}

#fh-search-overlay.is-open { display: flex; }

.fh-search-box {
    width: 100%; max-width: 600px;
    background: var(--c-bg); color: var(--c-text);
    border-radius: 12px; box-shadow: 0 25px 50px rgba(0,0,0,0.3);
    overflow: hidden;
}

#fh-search-input {
    width: 100%; padding: 1.2rem 1.4rem;
    font-size: 1.1rem; border: 0; outline: 0;
    background: transparent; color: inherit;
    border-bottom: 1px solid var(--c-border);
}

#fh-search-results { max-height: 60vh; overflow-y: auto; }

.fh-search-group {
    padding: 0.5rem 1.4rem; font-size: 0.8rem;
    color: var(--c-text-muted, #666); background: var(--c-bg-alt, #fafafa);
    font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em;
}

.fh-search-item {
    display: block; padding: 0.7rem 1.4rem;
    text-decoration: none; color: var(--c-text);
    border-bottom: 1px solid var(--c-border);
}

.fh-search-item:hover, .fh-search-item.is-selected {
    background: var(--c-primary); color: #fff;
}

.fh-search-item:hover .fh-search-meta, .fh-search-item.is-selected .fh-search-meta {
    color: rgba(255,255,255,0.85);
}

.fh-search-item strong { display: block; }

.fh-search-meta { font-size: 0.85rem; color: var(--c-text-muted, #666); }

.fh-search-hint, .fh-search-err {
    padding: 1.5rem; text-align: center; color: var(--c-text-muted, #888);
}

.fh-search-err { color: #ef4444; }

.fh-search-footer {
    display: flex; gap: 1rem; justify-content: center;
    padding: 0.6rem 1.4rem; font-size: 0.8rem;
    color: var(--c-text-muted, #888);
    background: var(--c-bg-alt, #fafafa);
    border-top: 1px solid var(--c-border);
}

.fh-search-footer kbd {
    background: #fff; border: 1px solid var(--c-border);
    border-radius: 4px; padding: 0.1rem 0.4rem; font-size: 0.75rem;
    color: var(--c-text);
}

/* ── F-050: mobile responsive (≤768px) backoffice ─────── */

@media (max-width: 768px) {
    /* Tabelle dati: scroll orizzontale invece di overflow page */
    .data-table {
        display: block;
        overflow-x: auto;
        white-space: nowrap;
        -webkit-overflow-scrolling: touch;
    }
    .data-table th, .data-table td {
        white-space: nowrap;
        padding: 0.5rem 0.6rem;
        font-size: 0.85rem;
    }

    /* Container più stretto */
    .container { padding: 0.75rem !important; }

    /* Page header in colonna */
    .page-header-actions {
        flex-direction: column;
        align-items: stretch !important;
        gap: 0.75rem;
    }
    .page-header-actions > div { width: 100%; }
    h1 { font-size: 1.4rem; }
    h2 { font-size: 1.1rem; }

    /* Filtri in colonna */
    .filters {
        flex-direction: column;
        align-items: stretch;
    }
    .filters > * { width: 100%; }

    /* Form grid: tutto in singola colonna su mobile */
    .form-grid {
        grid-template-columns: 1fr !important;
    }
    .form-grid [class*="span-"] {
        grid-column: span 1 !important;
    }

    /* KPI cards mobile: 1 colonna piena */
    .dash-kpi, .portale-kpi {
        grid-template-columns: 1fr !important;
    }

    /* Nav top con menu hamburger collassabile */
    .app-nav-inner {
        flex-direction: column;
        align-items: stretch;
        gap: 0.5rem;
    }
    .app-menu {
        display: none;
        flex-direction: column;
        gap: 0.25rem;
        padding-top: 0.5rem;
        border-top: 1px solid var(--c-border);
    }
    .app-menu.is-mobile-open {
        display: flex !important;
        position: static;
    }
    .app-menu .menu-item {
        padding: 0.6rem 0.75rem;
        border-radius: 4px;
    }
    .app-user {
        flex-wrap: wrap;
        gap: 0.5rem;
    }
    /* Hamburger button injection */
    #mobile-menu-toggle {
        display: inline-flex !important;
        background: transparent;
        border: 1px solid var(--c-border);
        color: var(--c-text);
        font-size: 1.2rem;
        padding: 0.4rem 0.7rem;
        border-radius: 6px;
        cursor: pointer;
        align-items: center;
        gap: 0.3rem;
    }
}

/* ── Menu raggruppato con dropdown (Lotto 42) ─────────── */

.menu-group .caret { font-size: 0.7rem; opacity: 0.7; }

/* Mobile: i dropdown diventano sub-list inline (no positioning) */

@media (max-width: 768px) {
    .menu-group { display: block; width: 100%; }
    .menu-group-btn { width: 100%; text-align: left; padding: 0.6rem 0.75rem; }
    .menu-dropdown { position: static; box-shadow: none; border-left: 3px solid var(--c-border); margin-left: 1rem; }
}

/* ============================================================
   FarmaHUB design system — componenti nuovi + override layout.
   Applicati SOPRA i selettori legacy (cascade wins).
   ============================================================ */

/* ── Topbar (header con brand + user switch) ──────────── */

.topbar {
    background: var(--green-900);
    color: #fff;
    padding: .8rem 1.2rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    flex-wrap: wrap;
    position: sticky;
    top: 0;
    z-index: 50;
    box-shadow: var(--shadow);
}

.topbar a { color: #fff; text-decoration: none; }

.topbar .brand {
    display: flex; align-items: center; gap: .65rem;
}

.topbar .brand-cross {
    width: 34px; height: 34px; border-radius: 9px;
    background: #fff; position: relative; flex-shrink: 0;
}

.topbar .brand-cross::before, .topbar .brand-cross::after {
    content: ""; position: absolute;
    background: var(--green-700); border-radius: 2px;
}

.topbar .brand-cross::before { width: 18px; height: 6px; left: 8px; top: 14px; }

.topbar .brand-cross::after  { width: 6px; height: 18px; left: 14px; top: 8px; }

.topbar .brand-title {
    font-family: var(--font-display);
    font-size: 1.15rem; font-weight: 700;
    letter-spacing: .2px; margin: 0;
    color: #fff;
}

.topbar .brand-tag {
    display: block; font-size: .66rem; font-weight: 500;
    opacity: .75; letter-spacing: .6px; text-transform: uppercase;
}

.topbar .badge-role {
    background: rgba(255,255,255,.15); border-radius: 99px;
    padding: .25rem .7rem; font-size: .68rem; font-weight: 700;
    letter-spacing: .4px; text-transform: uppercase; color: #fff;
}

.topbar .user-info {
    display: flex; align-items: center; gap: .5rem;
    font-size: .82rem; flex-wrap: wrap;
}

.topbar .user-info form { display: inline; margin: 0; }

.topbar .user-info button, .topbar .user-info a.btn-topbar {
    background: rgba(255,255,255,.12);
    color: #fff;
    border: 1px solid rgba(255,255,255,.28);
    border-radius: 8px;
    padding: .38rem .7rem;
    font-family: inherit;
    font-size: .78rem;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
}

.topbar .user-info button:hover, .topbar .user-info a.btn-topbar:hover {
    background: rgba(255,255,255,.22);
}

/* ── Tabs sticky (sostituisce app-menu / menu principale) ── */

.tabs-nav {
    display: flex;
    gap: .25rem;
    background: var(--c-surface);
    border-bottom: 1px solid var(--c-border);
    padding: 0 .8rem;
    overflow-x: auto;
    position: sticky;
    top: 58px;
    z-index: 40;
}

.tabs-nav a, .tabs-nav button {
    border: none;
    background: none;
    font-family: inherit;
    font-size: .85rem;
    font-weight: 700;
    color: var(--c-muted);
    padding: .85rem .9rem;
    cursor: pointer;
    border-bottom: 3px solid transparent;
    white-space: nowrap;
    text-decoration: none;
    display: inline-flex; align-items: center; gap: .35rem;
}

.tabs-nav a:hover, .tabs-nav button:hover { color: var(--green-700); }

.tabs-nav a.is-active, .tabs-nav .is-active {
    color: var(--green-700);
    border-bottom-color: var(--green-700);
}

.tabs-nav .pill {
    background: var(--red); color: #fff;
    border-radius: 99px; font-size: .62rem;
    padding: .1rem .42rem; margin-left: .3rem; vertical-align: 1px;
}

/* ── Container principale (main) ──────────────────────── */

.container, main.container {
    max-width: 1100px;
    margin: 0 auto;
    padding: 1.2rem 1rem 4rem;
}

@media (min-width: 1200px) {
    .container-wide { max-width: 1400px; }
}

/* ── View helpers (compatibili col mock) ─────────────── */

.view-title { font-size: 1.25rem; margin-bottom: .2rem; font-weight: 700; }

.view-sub   { color: var(--c-muted); font-size: .85rem; margin-bottom: 1.1rem; }

/* ── KPI cards (FarmaHUB) — allineate a .dash-card legacy ── */

.kpi, .dash-card, .kpi-card {
    background: var(--c-card);
    border-radius: var(--radius);
    padding: .95rem 1rem;
    box-shadow: var(--shadow);
    border: 1px solid var(--c-border);
}

.kpi-value, .dash-value, .kpi-valore, .kpi .num {
    font-family: var(--font-display);
    font-size: 1.55rem; font-weight: 700;
    color: var(--green-700);
    margin: 0;
    line-height: 1.2;
}

.kpi.warn .num, .dash-card.warn .dash-value,
.kpi-value.text-warning, .dash-value.text-warning { color: var(--amber); }

.kpi.danger .num, .dash-card.danger .dash-value,
.kpi-value.text-error, .dash-value.text-error { color: var(--red); }

.kpi.success .num, .dash-card.success .dash-value,
.kpi-value.text-success, .dash-value.text-success { color: var(--green-500); }

.kpi-label, .dash-label {
    font-size: .7rem; font-weight: 700;
    color: var(--c-muted);
    text-transform: uppercase; letter-spacing: .5px;
    margin-top: .15rem;
}

.kpi-meta, .dash-meta {
    font-size: .78rem; color: var(--c-muted); margin-top: .3rem;
}

/* Grid KPI */

.kpis, .dash-grid, .dash-grid-kpi, .kpi-griglia {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: .8rem;
    margin-bottom: 1.2rem;
}

.dash-grid-2, .colonne-2 {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(340px, 1fr));
    gap: 1rem;
    margin-bottom: 1.2rem;
}

.dash-grid-3 {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 1rem;
    margin-bottom: 1.2rem;
}

/* ── Panel / Card (contenitori sezione) ─────────────── */

.panel, .card {
    background: var(--c-card);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 1rem;
    margin-bottom: 1.2rem;
    border: 1px solid var(--c-border);
}

.panel h3, .card h3 {
    font-size: .95rem;
    margin: 0 0 .7rem 0;
    display: flex;
    align-items: center;
    gap: .5rem;
    flex-wrap: wrap;
    font-weight: 700;
}

/* ── Chips (filtri a pillola) ─────────────────────────── */

.chips { display: flex; gap: .45rem; flex-wrap: wrap; margin-bottom: 1rem; }

.chip {
    border: 1.5px solid var(--c-border);
    background: var(--c-card);
    border-radius: 99px;
    padding: .42rem .85rem;
    font-family: inherit; font-size: .75rem; font-weight: 700;
    color: var(--c-muted);
    cursor: pointer;
    text-decoration: none;
    display: inline-flex; align-items: center; gap: .3rem;
}

.chip:hover { border-color: var(--green-500); color: var(--green-700); }

.chip.is-active, .chip.on {
    background: var(--green-700);
    border-color: var(--green-700);
    color: #fff;
}

.chip .n { opacity: .75; font-weight: 800; }

/* ── Bottoni (FarmaHUB style) — override legacy .btn ── */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: .4rem;
    border: none;
    border-radius: 9px;
    padding: .5rem .85rem;
    font-family: inherit;
    font-weight: 700;
    font-size: .82rem;
    cursor: pointer;
    text-decoration: none;
    background: var(--c-card);
    color: var(--c-text);
    border: 1.5px solid var(--c-border);
    transition: transform .1s ease, filter .15s ease;
    white-space: nowrap;
    min-height: 36px;
}

.btn:hover { filter: brightness(.97); border-color: var(--green-500); }

.btn:active { transform: scale(.98); }

.btn:focus-visible { outline: 2px solid var(--green-900); outline-offset: 2px; }

.btn[disabled] { opacity: .55; cursor: not-allowed; }

.btn-primary, .btn-green, .btn-primario {
    background: var(--green-700); color: #fff; border-color: var(--green-700);
}

.btn-primary:hover, .btn-green:hover, .btn-primario:hover {
    background: var(--green-900); border-color: var(--green-900); filter: none;
}

.btn-ghost {
    background: var(--green-100);
    color: var(--green-700);
    border-color: transparent;
}

.btn-ghost:hover { background: var(--green-100); filter: brightness(.95); }

.btn-danger, .btn-danger-soft, .btn-pericolo {
    background: var(--red-bg); color: var(--red); border-color: transparent;
}

.btn-danger:hover, .btn-pericolo:hover { background: var(--red); color: #fff; }

.btn-blue { background: var(--blue); color: #fff; border-color: var(--blue); }

.btn-blue:hover { filter: brightness(.9); }

.btn-sm { padding: .38rem .65rem; font-size: .72rem; min-height: 30px; }

.btn-block, .btn-largo { width: 100%; }

/* ── Badge / stato (FarmaHUB pills) ─────────────────── */

.badge {
    display: inline-block;
    border-radius: 99px;
    padding: .18rem .55rem;
    font-size: .68rem;
    font-weight: 700;
    line-height: 1.4;
    background: var(--c-bg);
    color: var(--c-muted);
    text-transform: none;
    letter-spacing: 0;
}

.badge-success, .badge-ok { background: var(--green-100); color: var(--green-700); }

.badge-warning     { background: var(--amber-bg); color: var(--amber); }

.badge-error, .badge-danger { background: var(--red-bg); color: var(--red); }

.badge-info        { background: var(--blue-bg); color: var(--blue); }

.badge-muted       { background: var(--c-bg); color: var(--c-muted); }

.badge-success-dark { background: var(--green-700); color: #fff; }

/* Badges "stato" (per farmacia: scaduto, critico, ok) — pill con dot */

.exp {
    display: inline-flex;
    align-items: center;
    gap: .35rem;
    border-radius: 99px;
    padding: .2rem .55rem;
    font-size: .7rem;
    font-weight: 700;
    white-space: nowrap;
}

.exp::before {
    content: "";
    width: 8px; height: 8px;
    border-radius: 50%;
}

.exp.ok    { background: var(--green-100); color: var(--green-700); }

.exp.ok::before   { background: var(--green-500); }

.exp.soon  { background: var(--amber-bg); color: var(--amber); }

.exp.soon::before { background: var(--amber); }

.exp.crit  { background: var(--red-bg); color: var(--red); }

.exp.crit::before { background: var(--red); }

.st {
    display: inline-block; border-radius: 99px;
    padding: .2rem .55rem; font-size: .62rem;
    font-weight: 800; text-transform: uppercase; letter-spacing: .3px;
    white-space: nowrap;
}

.st.ok, .st.confermato { background: var(--green-100); color: var(--green-700); }

.st.warn, .st.near     { background: var(--amber-bg); color: var(--amber); }

.st.danger, .st.offlow, .st.annullato { background: var(--red-bg); color: var(--red); }

/* ── Tabelle (override legacy .data-table) ─────────── */

.data-table, .tabella, table {
    width: 100%;
    border-collapse: collapse;
    font-variant-numeric: tabular-nums;
    font-size: .87rem;
}

.data-table th, .tabella th, table th {
    text-align: left;
    font-size: .66rem;
    text-transform: uppercase;
    letter-spacing: .5px;
    color: var(--c-muted);
    padding: .5rem .65rem;
    border-bottom: 2px solid var(--c-border);
    font-weight: 800;
    background: transparent;
}

.data-table td, .tabella td, table td {
    padding: .6rem .65rem;
    border-bottom: 1px solid var(--c-border);
    vertical-align: middle;
}

.data-table tr:last-child td, .tabella tr:last-child td { border-bottom: 0; }

.data-table tbody tr:hover, .tabella tbody tr:hover { background: var(--green-50); }

td.num, th.num, td.r, th.r { text-align: right; }

.table-wrap { overflow-x: auto; }

/* ── Form inputs (FarmaHUB) ─────────────────────────── */

input[type=text], input[type=tel], input[type=email], input[type=password],
input[type=number], input[type=date], input[type=time], input[type=datetime-local],
input[type=search], input[type=url], select, textarea {
    font: 15px var(--font-testo);
    color: var(--c-text);
    background: var(--c-card);
    border: 1.5px solid var(--c-border);
    border-radius: 9px;
    padding: .5rem .7rem;
    min-height: 38px;
    width: 100%;
}

textarea { resize: vertical; min-height: 80px; }

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

/* ── Alert (banner colorati) ───────────────────────── */

.alert {
    padding: .75rem 1rem;
    border-radius: 12px;
    font-size: .87rem;
    margin-bottom: 1rem;
    background: var(--green-100);
    color: var(--green-700);
    border: 0;
}

.alert-error   { background: var(--red-bg); color: var(--red); }

.alert-warning { background: var(--amber-bg); color: var(--amber); }

.alert-success { background: var(--green-100); color: var(--green-700); }

.alert-info    { background: var(--blue-bg); color: var(--blue); }

/* ── Insight box (suggerimenti AI stile FarmaHUB) ── */

.insight, .ai-card {
    background: var(--green-100);
    border-radius: 12px;
    padding: .9rem 1rem;
    font-size: .87rem;
    line-height: 1.5;
    margin-top: 1rem;
    color: var(--c-text);
    border: 0;
}

.insight b, .ai-card b { color: var(--green-700); }

.insight .tag {
    display: inline-block;
    background: var(--green-700);
    color: #fff;
    font-size: .6rem;
    font-weight: 800;
    letter-spacing: .6px;
    text-transform: uppercase;
    border-radius: 99px;
    padding: .18rem .6rem;
    margin-bottom: .4rem;
}

/* ── Empty state (già presente ma allineato) ────────── */

.empty-state {
    text-align: center;
    padding: 3rem 1rem;
    color: var(--c-muted);
}

.empty-state-icon { font-size: 2.5rem; margin-bottom: .5rem; }

.empty-state-title { font-size: 1.1rem; font-weight: 700; color: var(--c-text); margin-bottom: .3rem; }

/* ── Auth pages (login / recupera / reset) ─────────── */

.auth-card, .login-card {
    background: var(--c-card);
    border: 1px solid var(--c-border);
    border-radius: 18px;
    padding: 2rem 1.75rem;
    max-width: 400px;
    margin: 3rem auto;
    box-shadow: 0 22px 60px rgba(11,74,57,.14);
}

/* NB: .auth-header e .auth-logo sono già stilate ~riga 300 con text-align:center
   per la login corrente (logo SVG largo). Non le sovrascrivo qui per non rompere.
   Se un domani si vuole la testata login FarmaHUB stile (croce a sinistra + testo),
   usare la classe .auth-logo-cross esplicita al posto dell'img. */

.auth-logo-cross {
    display: inline-block;
    width: 40px; height: 40px; border-radius: 10px;
    background: var(--green-700); position: relative; flex-shrink: 0;
    vertical-align: middle;
}

.auth-logo-cross::before, .auth-logo-cross::after {
    content: ""; position: absolute; background: #fff; border-radius: 2px;
}

.auth-logo-cross::before { width: 22px; height: 7px; left: 9px; top: 17px; }

.auth-logo-cross::after  { width: 7px; height: 22px; left: 17px; top: 9px; }

body.logged-out {
    background: var(--green-50);
    background-image:
      radial-gradient(900px 500px at 85% -10%, rgba(198, 137, 47, .10), transparent 60%),
      radial-gradient(800px 520px at 0% 110%, rgba(11, 74, 57, .12), transparent 55%);
    background-attachment: fixed;
}

/* ── Progress bar (bar-track/bar-fill legacy) ──────── */

.bar-track {
    height: 10px;
    background: var(--green-100);
    border-radius: 99px;
    overflow: hidden;
    position: relative;
    flex: 1;
}

.bar-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--green-500), var(--green-700));
    border-radius: 99px;
    transition: width .5s ease;
}

.bar-list { list-style: none; padding: 0; margin: 0; }

.bar-list li { display: flex; align-items: center; gap: .7rem; margin: .5rem 0; font-size: .82rem; }

.bar-label { width: 100px; font-weight: 700; flex-shrink: 0; }

.bar-value { width: 90px; text-align: right; font-weight: 800; font-size: .78rem; color: var(--c-muted); }

/* ── Legacy nav wrapper: nascondi la sidebar/menu-old
     se stiamo usando .topbar + .tabs-nav ─────────────── */

.uses-topbar .app-nav, .uses-topbar nav.app-nav,
.uses-topbar .app-menu { display: none; }

/* ── Skip link (accessibility) ─────────────────────── */

.skip-link {
    position: absolute; left: -9999px; top: auto;
    background: var(--green-700); color: #fff; padding: .5rem 1rem;
    border-radius: 0 0 8px 0; z-index: 1000;
}

.skip-link:focus { left: 0; top: 0; }

/* ============================================================
   Alias FarmaHUB per il nav esistente (.app-nav / .app-menu)
   Overrides finali — no cambi HTML richiesti.
   ============================================================ */

.app-nav {
    background: var(--green-900);
    color: #fff;
    position: sticky;
    top: 0;
    z-index: 50;
    box-shadow: var(--shadow);
    padding: 0;
    border-bottom: 0;
}

.app-nav-inner {
    max-width: 1400px;
    margin: 0 auto;
    padding: .55rem 1rem;
    display: flex;
    align-items: center;
    gap: .8rem;
    flex-wrap: wrap;
}

.app-nav a { color: #DCE8E2; text-decoration: none; }

.app-nav a:hover { color: #fff; }

.app-brand {
    display: flex; align-items: center; gap: .5rem;
    padding: .35rem .4rem;
    text-decoration: none;
    flex-shrink: 0;
}

.app-brand::before {
    content: "";
    width: 32px; height: 32px;
    border-radius: 8px;
    background: #fff;
    position: relative;
    display: inline-block;
    background-image:
      linear-gradient(var(--green-700), var(--green-700)),
      linear-gradient(var(--green-700), var(--green-700));
    background-size: 16px 6px, 6px 16px;
    background-position: center;
    background-repeat: no-repeat;
    flex-shrink: 0;
}

.app-brand .brand-logo { display: none; }

/* logo SVG nascosto: usiamo la croce disegnata sopra */

.app-brand .brand-text { color: #fff; font-family: var(--font-display); font-weight: 700; font-size: 1.05rem; }

.app-brand .brand-mark { color: #fff; font-family: var(--font-display); font-weight: 700; font-size: 1.05rem; }

/* Il menu principale ora è la barra tabs subito sotto la brand */

.app-menu {
    display: flex;
    gap: .1rem;
    flex: 1;
    flex-wrap: wrap;
    align-items: center;
    min-width: 0;
}

.menu-item {
    color: #C4D6D3;
    background: transparent;
    border: 0;
    padding: .55rem .7rem;
    font-family: inherit;
    font-size: .82rem;
    font-weight: 600;
    cursor: pointer;
    border-radius: 8px;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: .35rem;
    white-space: nowrap;
    line-height: 1.2;
}

.menu-item:hover { background: rgba(255,255,255,.09); color: #fff; }

.menu-item.is-active {
    background: var(--green-700);
    color: #fff;
}

.menu-group { position: relative; }

.menu-group.is-active > .menu-group-btn { background: var(--green-700); color: #fff; }

.menu-group-btn { border: 0; }

.menu-group-btn .caret { font-size: .7em; opacity: .7; margin-left: .1rem; }

.menu-dropdown {
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    min-width: 220px;
    background: #fff;
    color: var(--c-text);
    border: 1px solid var(--c-border);
    border-radius: 12px;
    padding: .4rem;
    box-shadow: 0 12px 30px rgba(11,74,57,.18);
    display: none;
    z-index: 100;
    flex-direction: column;
    gap: 2px;
}

.menu-group.is-open .menu-dropdown,
.menu-group:hover .menu-dropdown { display: flex; }

.menu-dropdown .menu-item {
    color: var(--c-text);
    padding: .5rem .7rem;
    font-size: .82rem;
    font-weight: 600;
    display: flex;
}

.menu-dropdown .menu-item:hover {
    background: var(--green-100);
    color: var(--green-700);
}

.menu-dropdown .menu-item.is-active {
    background: var(--green-700); color: #fff;
}

/* User area (right side of topbar) */

.app-user {
    display: flex; align-items: center; gap: .45rem;
    margin-left: auto;
    flex-wrap: wrap;
}

.app-user select {
    background: rgba(255,255,255,.12);
    color: #fff;
    border: 1px solid rgba(255,255,255,.28);
    border-radius: 8px;
    padding: .35rem .55rem;
    font-family: inherit;
    font-size: .78rem;
    font-weight: 600;
    cursor: pointer;
    min-height: 32px;
    width: auto;
}

.app-user select option { color: var(--c-text); background: #fff; }

.app-user .theme-toggle {
    background: rgba(255,255,255,.12);
    border: 1px solid rgba(255,255,255,.28);
    color: #fff;
    width: 32px; height: 32px;
    margin: 0;
}

.app-user .theme-toggle:hover { background: rgba(255,255,255,.22); color: #fff; }

.app-user .user-info {
    color: #fff;
    padding: .35rem .6rem;
    border-radius: 8px;
    background: rgba(255,255,255,.08);
    text-decoration: none;
    font-size: .78rem;
    font-weight: 600;
    display: inline-flex; flex-direction: column; line-height: 1.15;
}

.app-user .user-info:hover { background: rgba(255,255,255,.18); }

.app-user .user-role {
    font-size: .6rem;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: .5px;
    opacity: .8;
}

.app-user .btn {
    background: rgba(255,255,255,.12);
    color: #fff;
    border: 1px solid rgba(255,255,255,.28);
    font-size: .78rem;
    padding: .35rem .7rem;
    min-height: 32px;
}

.app-user .btn:hover { background: rgba(255,255,255,.22); }

#mobile-menu-toggle {
    display: none;
    background: rgba(255,255,255,.12);
    color: #fff;
    border: 1px solid rgba(255,255,255,.28);
    border-radius: 8px;
    padding: .4rem .7rem;
    font-size: .82rem;
    font-weight: 600;
    cursor: pointer;
}

/* ── Responsive ──────────────────────────────────────── */

@media (max-width: 960px) {
    .app-nav-inner { padding: .55rem .7rem; }
    #mobile-menu-toggle { display: inline-flex; align-items: center; gap: .35rem; }
    .app-menu {
        display: none;
        width: 100%;
        flex-direction: column;
        gap: 2px;
        background: var(--green-900);
        padding: .5rem 0;
        margin-top: .3rem;
    }
    .app-menu.is-mobile-open { display: flex; }
    .app-user { margin-left: auto; }
    .menu-group { width: 100%; }
    .menu-group-btn { width: 100%; text-align: left; justify-content: space-between; }
    .menu-dropdown {
        position: static; box-shadow: none;
        background: rgba(0,0,0,.2);
        border: 0; border-radius: 0;
        padding-left: 1.5rem;
    }
    .menu-dropdown .menu-item { color: #DCE8E2; }
    .menu-dropdown .menu-item:hover { background: rgba(255,255,255,.09); color: #fff; }
}

/* Titoli pagina (page-header) — allineato al mock */

.page-header, .testata {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    flex-wrap: wrap;
    margin-bottom: 1.2rem;
}

.page-header h1, .page-header h2, .testata h1 {
    margin: 0;
    font-family: var(--font-display);
    font-size: 1.35rem;
    font-weight: 700;
    line-height: 1.2;
}

.page-header .muted, .page-header p {
    color: var(--c-muted);
    font-size: .85rem;
    margin: .2rem 0 0;
}

.page-header-actions {
    display: flex; gap: .5rem; align-items: center; flex-wrap: wrap;
    margin-left: auto;
}

.back-link {
    color: var(--c-muted); font-size: .82rem;
    text-decoration: none; font-weight: 600;
    display: inline-flex; align-items: center; gap: .3rem;
    padding: .35rem .5rem; border-radius: 6px;
}

.back-link:hover { background: var(--c-bg); color: var(--green-700); }

/* ============================================================
   PORTALE CLIENTI — stili migrati da views/portale/_header.php
   (PR-L2 post-rebrand audit). Adattati al design FarmaHUB.
   ============================================================ */

.portale-nav {
    background: var(--green-900);
    color: #fff;
    padding: .75rem 1.5rem;
    box-shadow: var(--shadow);
}

.portale-nav-inner {
    max-width: 960px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
}

.portale-nav a {
    color: #fff;
    text-decoration: none;
    padding: .4rem .8rem;
    border-radius: 8px;
    font-weight: 600;
    font-size: .82rem;
}

.portale-nav a:hover { background: rgba(255,255,255,.12); }

.portale-nav .brand {
    font-family: var(--font-display);
    font-weight: 700;
    font-size: 1.1rem;
    margin-right: 1.5rem;
}

.portale-nav .menu { display: flex; gap: .5rem; flex-wrap: wrap; }

.portale-nav .user {
    display: flex; align-items: center; gap: .5rem;
    font-size: .85rem; opacity: .95;
    flex-shrink: 0;
}

.portale-nav .user form { display: inline; margin: 0; }

.portale-nav .user button {
    background: rgba(255,255,255,.15);
    border: 1px solid rgba(255,255,255,.28);
    color: #fff;
    padding: .35rem .7rem;
    border-radius: 8px;
    cursor: pointer;
    font-family: inherit;
    font-size: .78rem;
    font-weight: 600;
}

.portale-nav .user button:hover { background: rgba(255,255,255,.22); }

.portale-main {
    max-width: 960px;
    margin: 1.5rem auto;
    padding: 0 1.5rem;
}

.portale-kpi {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 1rem;
    margin: 1rem 0 2rem;
}

.portale-kpi .kpi, .portale-kpi > .kpi {
    background: var(--c-card);
    border: 1px solid var(--c-border);
    border-radius: var(--radius);
    padding: 1rem;
    box-shadow: var(--shadow-sm);
}

.portale-kpi .kpi .label {
    color: var(--c-muted);
    font-size: .7rem;
    text-transform: uppercase;
    letter-spacing: .05em;
    font-weight: 700;
}

.portale-kpi .kpi .value {
    font-family: var(--font-display);
    font-size: 1.6rem;
    font-weight: 700;
    color: var(--green-700);
    margin: .3rem 0 0;
}

.portale-kpi .kpi.warn .value { color: var(--red); }

/* Responsive mobile portale (era in _header.php inline) */

@media (max-width: 768px) {
    .portale-nav { padding: .6rem 1rem; }
    .portale-nav-inner {
        flex-direction: column;
        align-items: stretch;
        gap: .5rem;
    }
    .portale-nav-inner > div:first-child {
        flex-direction: column;
        align-items: stretch;
    }
    .portale-nav .brand { margin-right: 0; margin-bottom: .4rem; }
    .portale-nav .menu { flex-wrap: wrap; justify-content: center; }
    .portale-nav .menu a { padding: .5rem .7rem; } /* touch target ≥ 44px */
    .portale-nav .user { justify-content: space-between; }
    .portale-main { padding: 0 1rem; }
}