/* ==========================================================================
   Leonardo — Theme (design tokens + base + componenti)
   Identità visiva Leonardo · blu acciaio + accento arancione #F17300
   Unico punto di verità per colori, tipografia, forma e componenti UI.
   ========================================================================== */

:root {
    /* Palette Leonardo */
    --steel-azure:      #054A91;
    --steel-blue:       #3E7CB1;
    --wisteria-blue:    #81A4CD;
    --alice-blue:       #DBE4EE;
    --harvest-orange:   #F17300;

    /* Brand = blu acciaio (primario: bottoni, focus, fill) */
    --brand:            var(--steel-azure);
    --brand-strong:     #043D7A;  /* blu più scuro: link/hover (AA su chiaro) */
    --brand-tint:       var(--alice-blue);  /* sfondo tenue hover/selezione */
    --brand-tint-2:     #C6D6E8;  /* focus ring tenue */

    /* Accento = arancione raccolto (CTA e stato attivo) */
    --accent:           var(--harvest-orange);
    --accent-strong:    #C85E00;

    /* Testo su fill scuro (brand/accent) e sfondo sidebar */
    --on-brand:         #FFFFFF;
    --sidebar-bg:       #05305B;  /* blu acciaio profondo */

    /* Neutri */
    --ink:              #1B1F24;  /* testo principale */
    --ink-soft:         #3A424B;
    --muted:            #6B7280;  /* testo secondario */
    --line:             #E5E7EB;  /* bordi/divisori */
    --surface:          #FFFFFF;  /* card e superfici */
    --bg:               #F6F7F8;  /* sfondo app */

    /* Semantici (anche stati preventivo) */
    --success:          #16A34A;  /* Accettato */
    --success-tint:     #ECFDF3;
    --info:             #2563EB;  /* Inviato */
    --info-tint:        #EFF4FF;
    --warning:          #D97706;
    --warning-tint:     #FFFBEB;
    --danger:           #DC2626;  /* Rifiutato / errori */
    --danger-tint:      #FEF2F2;
    --neutral-badge:    #6B7280;  /* Bozza */

    /* Tipografia e forma */
    --font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    --radius: 10px;
    --radius-sm: 6px;
    --radius-pill: 999px;
    --shadow-sm: 0 1px 2px rgba(16,24,40,.06);
    --shadow:    0 4px 12px rgba(16,24,40,.08);
    --space-1:4px; --space-2:8px; --space-3:12px; --space-4:16px; --space-6:24px; --space-8:32px;

    /* Layout */
    --sidebar-w: 248px;
    --topbar-h: 60px;
}

/* ------------------------------------------------------------------ reset */
*, *::before, *::after { box-sizing: border-box; }

html, body {
    margin: 0;
    font-family: var(--font);
    font-size: 16px;
    line-height: 1.5;
    background: var(--bg);
    color: var(--ink);
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
}

h1, h2, h3, h4, p { margin: 0 0 var(--space-3); }
h1 { font-size: 1.875rem; font-weight: 700; letter-spacing: -.01em; }   /* 30 */
h2 { font-size: 1.25rem;  font-weight: 650; }                            /* 20 */
h3 { font-size: 1rem;     font-weight: 650; color: var(--ink-soft); }    /* 16 */
small { font-size: .8125rem; color: var(--muted); }

a { color: var(--brand-strong); text-decoration: none; }
a:hover { text-decoration: underline; }

:focus-visible {
    outline: 2px solid var(--brand);
    outline-offset: 2px;
    border-radius: var(--radius-sm);
}

/* ============================================================ APP SHELL */
.app-shell { display: flex; min-height: 100vh; }

.nav-toggle { display: none; }   /* checkbox hidden, controlla la sidebar su mobile */

.sidebar {
    width: var(--sidebar-w);
    flex-shrink: 0;
    background: var(--sidebar-bg);
    color: #fff;
    display: flex;
    flex-direction: column;
    padding: var(--space-4) var(--space-3);
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
}

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

.topbar {
    height: var(--topbar-h);
    background: var(--surface);
    border-bottom: 1px solid var(--line);
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: 0 var(--space-6);
    position: sticky;
    top: 0;
    z-index: 20;
}

.topbar-title { font-weight: 650; font-size: 1rem; color: var(--ink); }
.topbar-spacer { flex: 1; }

.nav-burger {
    display: none;
    font-size: 1.4rem;
    line-height: 1;
    cursor: pointer;
    color: var(--ink-soft);
    padding: var(--space-1) var(--space-2);
    border-radius: var(--radius-sm);
}
.nav-burger:hover { background: var(--bg); }

.content {
    flex: 1;
    padding: var(--space-6);
    width: 100%;
    max-width: 1180px;
    margin: 0 auto;
}

/* ------------------------------------------------------------- sidebar brand */
.brand {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-2) var(--space-2) var(--space-6);
}
.brand-logo { width: 34px; height: 34px; flex-shrink: 0; }
.brand-text { display: flex; flex-direction: column; line-height: 1.15; }
.brand-name { font-size: 1.15rem; font-weight: 700; color: #fff; }
.brand-sub  { font-size: .72rem; letter-spacing: .04em; text-transform: uppercase; color: rgba(255,255,255,.55); }

/* ------------------------------------------------------------- nav links */
.nav-menu { display: flex; flex-direction: column; gap: 2px; }
.nav-group-label {
    font-size: .68rem;
    text-transform: uppercase;
    letter-spacing: .06em;
    color: rgba(255,255,255,.4);
    padding: var(--space-4) var(--space-2) var(--space-1);
}

.nav-link {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    color: rgba(255,255,255,.78);
    text-decoration: none;
    padding: 10px var(--space-3);
    border-radius: var(--radius-sm);
    font-size: .9rem;
    font-weight: 500;
    border-left: 3px solid transparent;
    min-height: 40px;
}
.nav-link:hover { background: rgba(255,255,255,.07); color: #fff; text-decoration: none; }
.nav-link.active {
    background: rgba(241,115,0,.16);
    color: #fff;
    border-left-color: var(--accent);
    font-weight: 600;
}
.nav-link.disabled { opacity: .45; cursor: not-allowed; }
.nav-link.small { font-size: .8rem; padding: 6px var(--space-3); min-height: 0; }

/* --------------------------------------------------------- user menu (topbar) */
.user-menu { display: flex; align-items: center; gap: var(--space-3); }
.user-meta { display: flex; flex-direction: column; align-items: flex-end; line-height: 1.2; }
.user-name { font-weight: 600; font-size: .9rem; color: var(--ink); }
.user-role {
    font-size: .68rem;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: var(--muted);
}
.user-avatar {
    width: 36px; height: 36px;
    border-radius: 50%;
    background: var(--brand-tint);
    color: var(--brand-strong);
    display: grid; place-items: center;
    font-weight: 700; font-size: .85rem;
    flex-shrink: 0;
}

/* Legacy: vecchio blocco utente in sidebar (se ancora presente) */
.user-box {
    margin-top: auto;
    padding-top: var(--space-4);
    border-top: 1px solid rgba(255,255,255,.12);
    display: flex; flex-direction: column; gap: var(--space-1);
    font-size: .85rem; color: rgba(255,255,255,.85);
}

/* ================================================================= CARD */
.card, .ui-card {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: var(--space-6);
    box-shadow: var(--shadow-sm);
    margin-bottom: var(--space-4);
}
.card > h2:first-child, .ui-card > h2:first-child,
.card > h1:first-child { margin-top: 0; }

.ui-card-header {
    display: flex; align-items: center; justify-content: space-between;
    gap: var(--space-4);
    margin: calc(-1 * var(--space-2)) 0 var(--space-4);
}
.ui-card-header h2, .ui-card-header h3 { margin: 0; }
.ui-card-body > :last-child { margin-bottom: 0; }

/* =============================================================== BUTTONS */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    font-family: inherit;
    font-size: .9rem;
    font-weight: 600;
    line-height: 1;
    min-height: 40px;
    padding: 0 var(--space-4);
    border-radius: var(--radius-sm);
    border: 1px solid transparent;
    cursor: pointer;
    text-decoration: none;
    transition: background .12s, border-color .12s, color .12s, box-shadow .12s;
    white-space: nowrap;
}
.btn:hover { text-decoration: none; }
.btn:disabled, .btn.is-disabled { opacity: .55; cursor: not-allowed; pointer-events: none; }

.btn-primary {
    background: var(--brand);
    color: var(--on-brand);  /* testo bianco su blu acciaio: contrasto AA */
    border-color: var(--brand);
}
.btn-primary:hover { background: var(--brand-strong); border-color: var(--brand-strong); color: #fff; }

.btn-secondary {
    background: var(--surface);
    color: var(--ink-soft);
    border-color: var(--line);
}
.btn-secondary:hover { background: var(--bg); border-color: #d2d6db; }

.btn-subtle {
    background: transparent;
    color: var(--ink-soft);
    border-color: transparent;
}
.btn-subtle:hover { background: var(--bg); }

.btn-danger {
    background: var(--danger);
    color: #fff;
    border-color: var(--danger);
}
.btn-danger:hover { background: #b91c1c; border-color: #b91c1c; }

.btn-sm { min-height: 32px; padding: 0 var(--space-3); font-size: .82rem; }
.btn-block { width: 100%; }

/* spinner per stato loading */
.btn-spinner {
    width: 14px; height: 14px;
    border: 2px solid currentColor;
    border-right-color: transparent;
    border-radius: 50%;
    animation: spin .6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ----------- alias legacy: bottoni "nudi" nelle pagine non ancora migrate ----
   `:not(.btn)` evita di sovrascrivere il componente <Button> quando è annidato
   in questi contenitori (es. <Button> dentro .azioni / .paging). */
.azioni button:not(.btn),
.user-form button:not(.btn),
.paging button:not(.btn),
.form-actions button:not(.btn),
button.logout-btn:not(.btn) {
    font-family: inherit;
    font-weight: 600;
    cursor: pointer;
    border-radius: var(--radius-sm);
    border: 1px solid transparent;
    min-height: 38px;
    padding: 0 var(--space-3);
    font-size: .85rem;
    transition: background .12s, border-color .12s;
}
.azioni button:not(.btn),
.user-form button:not(.btn),
.form-actions button:not(.btn) {
    background: var(--brand);
    color: var(--on-brand);
    border-color: var(--brand);
}
.azioni button:not(.btn):hover,
.user-form button:not(.btn):hover,
.form-actions button:not(.btn):hover { background: var(--brand-strong); color: #fff; border-color: var(--brand-strong); }

.form-actions .secondary:not(.btn),
.user-form .secondary:not(.btn),
button.secondary:not(.btn) {
    background: var(--surface);
    color: var(--ink-soft);
    border-color: var(--line);
}
.form-actions .secondary:not(.btn):hover, button.secondary:not(.btn):hover { background: var(--bg); }

.paging button:not(.btn) {
    background: var(--surface);
    color: var(--ink-soft);
    border-color: var(--line);
}
.paging button:not(.btn):hover:not(:disabled) { background: var(--bg); }

.azioni button:not(.btn):disabled,
.user-form button:not(.btn):disabled,
.form-actions button:not(.btn):disabled,
.paging button:not(.btn):disabled { opacity: .5; cursor: not-allowed; }

/* =============================================================== FORMS */
label { font-size: .85rem; color: var(--ink-soft); }

.form-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
    gap: var(--space-4);
    margin-bottom: var(--space-4);
}
.form-row > label,
.user-form label,
.ui-field {
    display: flex;
    flex-direction: column;
    gap: var(--space-1);
    font-size: .85rem;
    font-weight: 500;
    color: var(--ink-soft);
}

input, select, textarea,
.user-form input, .user-form select,
td input, td select {
    font-family: inherit;
    font-size: .9rem;
    color: var(--ink);
    padding: 9px var(--space-3);
    border: 1px solid #cfd4da;
    border-radius: var(--radius-sm);
    background: var(--surface);
    min-height: 40px;
    transition: border-color .12s, box-shadow .12s;
}
textarea { min-height: 80px; resize: vertical; }

input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--brand);
    box-shadow: 0 0 0 3px var(--brand-tint-2);
}
input:disabled, select:disabled { background: var(--bg); opacity: .7; }

/* Tutte le checkbox del sito: annullano lo stile "box" ereditato dalla regola input generica
   e adottano il look brand (casella piena arancione, dimensione coerente, cursore a mano). */
input[type="checkbox"]:not(.nav-toggle) {
    appearance: none;
    -webkit-appearance: none;
    min-height: 0;
    width: 18px;
    height: 18px;
    padding: 0;
    margin: 0;
    flex: 0 0 auto;            /* niente stretch dentro le label flex */
    border: 1.5px solid #b9bfc7;
    border-radius: var(--radius-sm);
    background: var(--surface);
    display: inline-grid;
    place-content: center;
    cursor: pointer;
    vertical-align: middle;
    transition: background .12s ease, border-color .12s ease;
}
input[type="checkbox"]:not(.nav-toggle)::before {
    content: "";
    width: 10px;
    height: 10px;
    transform: scale(0);
    transition: transform .12s ease-in-out;
    box-shadow: inset 1em 1em var(--surface);
    clip-path: polygon(14% 44%, 0 65%, 50% 100%, 100% 16%, 80% 0%, 43% 62%);
}
input[type="checkbox"]:not(.nav-toggle):checked {
    background: var(--brand);
    border-color: var(--brand);
}
input[type="checkbox"]:not(.nav-toggle):checked::before { transform: scale(1); }
input[type="checkbox"]:not(.nav-toggle):focus-visible {
    outline: none;
    border-color: var(--brand);
    box-shadow: 0 0 0 3px var(--brand-tint-2);
}
input[type="checkbox"]:not(.nav-toggle):disabled { cursor: default; opacity: .6; }

.checkbox-label,
label.checkbox-label {
    flex-direction: row !important;
    align-items: center;
    gap: var(--space-2) !important;
}

/* Toggle "prezzo di vendita manuale" (Nuovo preventivo): box che si accende in brand quando attivo. */
.price-override {
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: var(--space-3) var(--space-4);
    background: var(--surface);
    transition: background .15s ease, border-color .15s ease, box-shadow .15s ease;
}
.price-override.is-on {
    border-color: var(--brand);
    background: var(--brand-tint);
    box-shadow: var(--shadow-sm);
}
.price-override .po-head {
    flex-direction: row !important;
    align-items: center;
    gap: var(--space-3) !important;
    margin: 0;
    font-weight: 600;
    cursor: pointer;
    user-select: none;
}
.price-override .po-head input[type="checkbox"] {
    min-height: 0;
    width: 22px; height: 22px;
    accent-color: var(--brand);
    cursor: pointer;
}

.ui-hint { font-size: .78rem; color: var(--muted); font-weight: 400; }
.ui-field-error,
.form-error { font-size: .8rem; margin: var(--space-1) 0 0; }

.form-actions { display: flex; gap: var(--space-2); flex-wrap: wrap; }

/* =============================================================== TABLES */
table {
    border-collapse: collapse;
    width: 100%;
    margin-top: var(--space-3);
    font-size: .9rem;
}
thead th {
    position: sticky;
    top: var(--topbar-h);
    background: var(--bg);
    text-align: left;
    font-weight: 600;
    font-size: .78rem;
    text-transform: uppercase;
    letter-spacing: .03em;
    color: var(--muted);
    padding: var(--space-2) var(--space-3);
    border-bottom: 1px solid var(--line);
    z-index: 1;
}
tbody td {
    padding: var(--space-3);
    border-bottom: 1px solid var(--line);
    vertical-align: middle;
}
tbody tr:nth-child(even) { background: #fafbfc; }
tbody tr:hover { background: var(--brand-tint); }
.riga-disattiva { opacity: .55; }

/* =============================================================== BADGES */
.badge {
    display: inline-flex;
    align-items: center;
    gap: var(--space-1);
    padding: 3px 10px;
    border-radius: var(--radius-pill);
    font-size: .75rem;
    font-weight: 600;
    line-height: 1.4;
    background: var(--bg);
    color: var(--ink-soft);
    border: 1px solid var(--line);
    white-space: nowrap;
}
.badge-grigio  { background: #f1f3f5; color: var(--neutral-badge); border-color: #e3e6ea; }
.badge-blu     { background: var(--info-tint);    color: var(--info);    border-color: #d6e0ff; }
.badge-verde   { background: var(--success-tint); color: var(--success); border-color: #c5ecd2; }
.badge-rosso   { background: var(--danger-tint);  color: var(--danger);  border-color: #f6d5d5; }
.badge-arancio { background: #FDECDD;             color: var(--accent-strong); border-color: #FBD8B6; }
.badge-viola   { background: #f3effc;             color: #6f42c1;        border-color: #e4d8f7; }

/* =============================================================== KPI */
.kpi-grid { display: flex; flex-wrap: wrap; gap: var(--space-4); margin-bottom: var(--space-4); }
.kpi-card {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: var(--space-4) var(--space-6);
    min-width: 170px;
    flex: 1 1 170px;
    box-shadow: var(--shadow-sm);
}
.kpi-card-warn { border-color: var(--warning); background: var(--warning-tint); }
.kpi-label { display: block; font-size: .78rem; color: var(--muted); margin-bottom: var(--space-1); }
.kpi-value { display: block; font-size: 1.65rem; font-weight: 700; color: var(--brand-strong); line-height: 1.1; }

/* barre statistiche */
.bar-bg   { height: 10px; background: var(--line); border-radius: var(--radius-pill); min-width: 80px; overflow: hidden; }
.bar-fill { height: 10px; background: var(--brand); border-radius: var(--radius-pill); transition: width .3s; }

/* =============================================================== ALERTS */
.alert {
    display: flex;
    gap: var(--space-3);
    padding: var(--space-3) var(--space-4);
    border-radius: var(--radius-sm);
    border: 1px solid var(--line);
    background: var(--surface);
    font-size: .88rem;
    margin-bottom: var(--space-4);
}
.alert-info    { background: var(--info-tint);    border-color: #d6e0ff; color: #1e40af; }
.alert-success { background: var(--success-tint); border-color: #c5ecd2; color: #166534; }
.alert-warning { background: var(--warning-tint); border-color: #fde68a; color: #92400e; }
.alert-danger  { background: var(--danger-tint);  border-color: #f6d5d5; color: #991b1b; }

.placeholder-note {
    background: var(--warning-tint);
    border: 1px solid #fde68a;
    border-radius: var(--radius-sm);
    padding: var(--space-2) var(--space-3);
    font-size: .85rem;
    color: #92400e;
}

/* riga di dettaglio espansa (registro stampatore) */
.log-detail {
    background: var(--bg);
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    padding: var(--space-4);
    font-size: .88rem;
}
.log-detail h3, .log-detail h4 { margin-top: 0; }

/* ===================================================== ROTAZIONE PICKER */
.rotazioni-picker {
    position: relative;
    width: 100%;
    max-width: 760px;
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    background: var(--surface);
    overflow: hidden;
}
.rotazioni-img { display: block; width: 100%; height: auto; user-select: none; pointer-events: none; }
.rotazione-hit {
    position: absolute;
    top: 0;
    height: 100%;
    margin: 0;
    padding: 0;
    border: 0;
    background: transparent;
    cursor: pointer;
    transition: background .1s;
}
.rotazione-hit:hover { background: rgba(243,146,0,.10); }
.rotazione-hit.is-selected {
    background: rgba(243,146,0,.16);
    box-shadow: inset 0 0 0 2px var(--brand);
}
.rotazioni-caption { margin: var(--space-2) 0 0; font-size: .85rem; }

/* =========================================================== EMPTY STATE */
.empty-state {
    text-align: center;
    padding: var(--space-8) var(--space-4);
    color: var(--muted);
}
.empty-state-icon { font-size: 2rem; opacity: .4; margin-bottom: var(--space-2); }

/* =============================================================== UTILITIES */
.ok  { color: var(--success); font-weight: 600; }
.ko  { color: var(--danger); }
.text-muted { color: var(--muted); }

.list-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: var(--space-4);
    flex-wrap: wrap;
    margin-bottom: var(--space-2);
}
.list-header h2 { margin: 0; }
.list-filters { display: flex; gap: var(--space-2); align-items: center; flex-wrap: wrap; }
.search-box { min-width: 260px; }
.filtri-ricerca { display: flex; gap: var(--space-3); align-items: flex-end; flex-wrap: wrap; margin-bottom: var(--space-4); }
.filtri-ricerca label { display: flex; flex-direction: column; gap: var(--space-1); font-size: 0.85rem; color: var(--ink-soft); }
.azioni { display: flex; gap: var(--space-2); align-items: center; flex-wrap: wrap; }
.azioni input { width: 130px; }
.paging { display: flex; align-items: center; gap: var(--space-3); margin-top: var(--space-4); }
.paging span { font-size: .85rem; color: var(--muted); }

/* ===================================================== Registro stampatore — form mobile-first */
.list-header h1 { margin: 0; }

.log-form { max-width: 640px; margin: 0 auto; padding-bottom: 96px; }
.log-form-head { display: flex; align-items: center; gap: var(--space-3); margin-bottom: var(--space-3); }
.log-form-head h1 { margin: 0; font-size: 1.4rem; }

.log-form .field { display: flex; flex-direction: column; gap: var(--space-1); margin-bottom: var(--space-3); font-size: .9rem; color: var(--ink-soft); }
.log-form .field > input,
.log-form .field > select { width: 100%; min-height: 44px; font-size: 1rem; box-sizing: border-box; }
.field-hint { font-weight: 400; color: var(--muted); font-size: .8rem; }

.tec-title { margin: var(--space-4) 0 var(--space-1); }
.tec-list { display: flex; flex-direction: column; gap: var(--space-3); }

.tec-card { border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; background: var(--surface); transition: border-color .15s, box-shadow .15s; }
.tec-card.attiva { border-color: var(--brand); box-shadow: 0 1px 6px rgba(0,0,0,.06); }
.tec-card-head { width: 100%; display: flex; align-items: center; gap: var(--space-3); min-height: 56px; padding: 0 var(--space-4); background: none; border: none; cursor: pointer; font-size: 1.05rem; font-weight: 600; color: var(--ink); text-align: left; }
.tec-card.attiva .tec-card-head { background: var(--bg); }
.tec-name { flex: 1; }
.tec-chevron { color: var(--muted); }
.tec-dot { width: 14px; height: 14px; border-radius: 50%; border: 2px solid var(--line); background: transparent; flex: 0 0 auto; }
.tec-dot.verde   { background: var(--success);      border-color: var(--success); }
.tec-dot.arancio { background: var(--brand-strong); border-color: var(--brand-strong); }
.tec-dot.viola   { background: #6f42c1;             border-color: #6f42c1; }
.tec-dot.blu     { background: var(--info);         border-color: var(--info); }
.tec-card-body { padding: var(--space-2) var(--space-4) var(--space-4); border-top: 1px solid var(--line); }

.colori-head { font-weight: 600; margin: var(--space-3) 0 var(--space-2); }
.colore-card { border: 1px solid var(--line); border-radius: var(--radius); padding: var(--space-3); margin-bottom: var(--space-3); background: var(--bg); }
.colore-card-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: var(--space-2); }

.save-bar { position: sticky; bottom: 0; display: flex; gap: var(--space-3); justify-content: flex-end; padding: var(--space-3) 0; margin-top: var(--space-4); background: var(--surface); border-top: 1px solid var(--line); }
.save-bar .btn { min-height: 48px; }

@media (max-width: 640px) {
    .save-bar { position: fixed; left: 0; right: 0; bottom: 0; padding: var(--space-3); z-index: 20; box-shadow: 0 -2px 8px rgba(0,0,0,.08); }
    .save-bar .btn { flex: 1; }
}

/* =============================================================== AUTH LAYOUT */
.auth-shell {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: var(--space-6);
    background:
        radial-gradient(1200px 500px at 50% -10%, var(--brand-tint), transparent),
        var(--bg);
}
.auth-card {
    width: 100%;
    max-width: 400px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: var(--space-8);
}
.auth-brand { display: flex; flex-direction: column; align-items: center; gap: var(--space-2); margin-bottom: var(--space-6); }
.auth-brand .brand-logo { width: 52px; height: 52px; }
.auth-brand h1 { font-size: 1.4rem; margin: 0; }
.auth-brand p { margin: 0; font-size: .85rem; color: var(--muted); }
.auth-card form { display: flex; flex-direction: column; gap: var(--space-4); }
.auth-card .ui-field input { min-height: 42px; }

/* ============================================================== STYLEGUIDE */
.sg-section { margin-bottom: var(--space-8); }
.sg-swatches { display: flex; flex-wrap: wrap; gap: var(--space-3); }
.sg-swatch { width: 150px; }
.sg-chip { height: 56px; border-radius: var(--radius-sm); border: 1px solid var(--line); }
.sg-swatch code { font-size: .72rem; color: var(--muted); display: block; margin-top: var(--space-1); }
.sg-row { display: flex; flex-wrap: wrap; gap: var(--space-3); align-items: center; margin-bottom: var(--space-3); }

/* =============================================================== RESPONSIVE */
@media (max-width: 860px) {
    .nav-burger { display: inline-flex; }
    .sidebar {
        position: fixed;
        z-index: 40;
        left: 0; top: 0;
        transform: translateX(-100%);
        transition: transform .2s ease;
        box-shadow: var(--shadow);
    }
    .nav-toggle:checked ~ .sidebar { transform: translateX(0); }
    .nav-toggle:checked ~ .nav-backdrop {
        position: fixed; inset: 0; z-index: 30;
        background: rgba(0,0,0,.35); display: block;
    }
    .nav-backdrop { display: none; }
    .content { padding: var(--space-4); }
    .user-meta { display: none; }   /* su mobile mostra solo l'avatar */
}

/* =============================================================== Reminder / Statistiche */
.page-sub { color: var(--muted); font-size: .9rem; margin-top: calc(-1 * var(--space-2)); }
.text-right { text-align: right; }
.field-check { flex-direction: row; align-items: center; gap: var(--space-2); }
.field-wide { flex: 1 1 100%; }
.breakdown-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: var(--space-4);
}

/* =============================================================== Scheda ticket (staff) */
.d-block { display: block; }

.td-topbar {
    display: flex; justify-content: space-between; align-items: flex-start;
    gap: var(--space-4); flex-wrap: wrap; margin-bottom: var(--space-4);
}
.td-topbar h1 { margin: 0; }
.td-topbar .sub { color: var(--muted); font-size: .85rem; }
.td-actions { display: flex; align-items: center; gap: var(--space-2); }
.td-actions-label { color: var(--muted); font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; }

/* Selettore di stato colorato (cambia lo stato al volo) */
.td-status {
    font-weight: 700; border-radius: var(--radius-pill); padding: .5rem 1.1rem;
    border: 2px solid transparent; cursor: pointer; font-size: .9rem; font-family: inherit;
    -webkit-appearance: none; appearance: none;
}
.td-status.is-info      { background: var(--info-tint);    color: var(--info);         border-color: #c7d7ff; }
.td-status.is-warning   { background: var(--warning-tint); color: var(--warning);      border-color: #fde68a; }
.td-status.is-danger    { background: var(--danger-tint);  color: var(--danger);       border-color: #f6d5d5; }
.td-status.is-success   { background: var(--success-tint); color: var(--success);      border-color: #c5ecd2; }
.td-status.is-secondary { background: var(--alice-blue);   color: var(--steel-azure);  border-color: var(--wisteria-blue); }

.td-grid { display: grid; grid-template-columns: minmax(0, 1fr) 330px; gap: var(--space-4); align-items: start; }
@media (max-width: 960px) { .td-grid { grid-template-columns: 1fr; } }

/* Card riutilizzabile della scheda */
.td-card {
    background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
    box-shadow: var(--shadow-sm); margin-bottom: var(--space-4); overflow: hidden;
}
.td-card > header {
    padding: .6rem 1rem; border-bottom: 1px solid var(--line); font-weight: 600;
    background: linear-gradient(0deg, #fafbfc, #fff);
}
.td-card > .body { padding: 1rem; }

.td-info { display: grid; grid-template-columns: auto 1fr; gap: .35rem 1rem; margin: 0; font-size: .9rem; }
.td-info dt { color: var(--muted); }
.td-info dd { margin: 0; font-weight: 500; }
.td-desc {
    margin-top: .8rem; padding: .75rem; background: var(--bg); border-radius: var(--radius-sm);
    border-left: 3px solid var(--wisteria-blue); white-space: pre-wrap;
}

/* Chat: cliente a sinistra (chiaro), tecnico a destra (blu), nota interna (gialla, tratteggiata) */
.chat { display: flex; flex-direction: column; gap: .7rem; }
.msg { max-width: 82%; padding: .55rem .8rem; border-radius: 14px; font-size: .9rem; }
.msg .meta { display: block; font-size: .72rem; margin-bottom: .2rem; font-weight: 700; opacity: .85; }
.msg .body { white-space: pre-wrap; }
.msg.cliente { align-self: flex-start; background: var(--alice-blue); border: 1px solid var(--wisteria-blue); border-bottom-left-radius: 3px; }
.msg.tecnico { align-self: flex-end; background: var(--steel-azure); color: #fff; border-bottom-right-radius: 3px; }
.msg.tecnico .meta { color: var(--alice-blue); }
.msg.interno { align-self: flex-end; background: var(--warning-tint); border: 1px dashed var(--warning); color: #7c4a03; }

.reply { margin-top: 1rem; border-top: 1px solid var(--line); padding-top: .75rem; display: flex; flex-direction: column; gap: .5rem; }
.reply textarea { width: 100%; border: 1px solid var(--line); border-radius: var(--radius-sm); padding: .5rem; font: inherit; resize: vertical; }
.reply .row { display: flex; justify-content: space-between; align-items: center; gap: .5rem; flex-wrap: wrap; }

.attach-list { list-style: none; margin: 0 0 .5rem; padding: 0; display: flex; flex-direction: column; gap: .35rem; }
.attach-list a { font-weight: 500; }

.log-table { width: 100%; border-collapse: collapse; font-size: .82rem; }
.log-table th, .log-table td { text-align: left; padding: .35rem .5rem; border-bottom: 1px solid var(--line); }
.log-table th { color: var(--muted); font-weight: 600; }

/* =============================================================== Notifiche (topbar) */
.notif { position: relative; }
.notif-bell {
    position: relative; background: transparent; border: none; cursor: pointer;
    font-size: 1.25rem; line-height: 1; padding: .35rem .5rem; border-radius: var(--radius-sm);
}
.notif-bell:hover { background: var(--brand-tint); }
.notif-badge {
    position: absolute; top: -2px; right: -2px; min-width: 18px; height: 18px; padding: 0 4px;
    background: var(--danger); color: #fff; font-size: .68rem; font-weight: 700; line-height: 18px;
    text-align: center; border-radius: var(--radius-pill); box-shadow: 0 0 0 2px var(--surface);
}
.notif-panel {
    position: absolute; top: calc(100% + 8px); right: 0; z-index: 60; width: 340px; max-width: 90vw;
    background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
    box-shadow: var(--shadow); overflow: hidden;
}
.notif-backdrop { position: fixed; inset: 0; z-index: 55; }
.notif-head {
    display: flex; justify-content: space-between; align-items: center;
    padding: .6rem .8rem; border-bottom: 1px solid var(--line); font-weight: 600;
}
.notif-clear { background: none; border: none; color: var(--brand-strong); cursor: pointer; font-size: .8rem; font-weight: 600; }
.notif-clear:hover { text-decoration: underline; }
.notif-empty { padding: 1rem .8rem; color: var(--muted); margin: 0; font-size: .88rem; }
.notif-list { list-style: none; margin: 0; padding: 0; max-height: 380px; overflow-y: auto; }
.notif-item {
    display: flex; gap: .6rem; align-items: flex-start; width: 100%; text-align: left;
    background: none; border: none; border-bottom: 1px solid var(--line); cursor: pointer;
    padding: .6rem .8rem; font: inherit;
}
.notif-item:hover { background: var(--brand-tint); }
.notif-ico { font-size: 1.05rem; line-height: 1.3; }
.notif-text { display: flex; flex-direction: column; flex: 1; min-width: 0; }
.notif-title { font-weight: 600; font-size: .84rem; }
.notif-sub { color: var(--muted); font-size: .8rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.notif-when { color: var(--muted); font-size: .72rem; white-space: nowrap; }

/* Rapporto tecnico */
.rt-sub { margin: 1rem 0 .4rem; font-size: .82rem; text-transform: uppercase; letter-spacing: .04em; color: var(--steel-blue); }
.rt-sub:first-child { margin-top: 0; }
.rt-textarea { width: 100%; min-height: 16rem; resize: vertical; padding: .6rem .75rem; border: 1px solid var(--line); border-radius: var(--radius-sm); font: inherit; line-height: 1.5; }
.rt-textarea:focus { outline: none; border-color: var(--steel-blue); box-shadow: 0 0 0 3px var(--alice-blue); }

/* Livelli inchiostri: cartucce con cursore verticale a step 10% */
.ink-row { display: flex; gap: 1.1rem; flex-wrap: wrap; align-items: flex-end; }
.ink { display: flex; flex-direction: column; align-items: center; gap: .3rem; width: 46px; }
.ink-label { font-weight: 700; font-size: .8rem; color: var(--muted); }
.ink-val { font-size: .78rem; font-weight: 600; color: var(--ink); }
.ink-cartridge {
    position: relative; width: 44px; height: 120px; border: 1px solid var(--wisteria-blue);
    border-radius: 6px 6px 4px 4px; background: #f3f5f8; overflow: hidden; box-shadow: inset 0 1px 2px rgba(0,0,0,.08);
}
.ink-fill { position: absolute; left: 0; right: 0; bottom: 0; transition: height .12s ease; }
.ink-fill.is-c { background: #00AEEF; }
.ink-fill.is-m { background: #EC008C; }
.ink-fill.is-y { background: #FFE500; }
.ink-fill.is-k { background: #23211F; }
.ink-fill.is-w { background: #ffffff; box-shadow: inset 0 0 0 1px #cfd6e0; }

/* Cursore verticale sovrapposto alla cartuccia (trasparente, thumb visibile) */
.ink-slider {
    position: absolute; inset: 0; margin: 0; width: 44px; height: 120px;
    writing-mode: vertical-lr; direction: rtl; /* min in basso, max in alto */
    -webkit-appearance: none; appearance: none; background: transparent; cursor: pointer;
}
.ink-slider::-webkit-slider-runnable-track { background: transparent; width: 44px; }
.ink-slider::-webkit-slider-thumb {
    -webkit-appearance: none; appearance: none; width: 40px; height: 8px; border-radius: 3px;
    background: rgba(5,74,145,.85); border: 1px solid #fff; box-shadow: 0 1px 2px rgba(0,0,0,.3);
}
.ink-slider::-moz-range-track { background: transparent; }
.ink-slider::-moz-range-thumb {
    width: 40px; height: 8px; border-radius: 3px; border: 1px solid #fff;
    background: rgba(5,74,145,.85); box-shadow: 0 1px 2px rgba(0,0,0,.3);
}

/* Colonna cliente */
.side-card .body { font-size: .88rem; }
.side-title { font-weight: 700; font-size: 1rem; margin: 0 0 .5rem; color: var(--brand); }
.side-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: .5rem; }
.side-list li { padding: .45rem .55rem; border-radius: var(--radius-sm); background: var(--bg); }
.side-list .name { font-weight: 600; }
.side-list .muted { color: var(--muted); font-size: .8rem; }
.printer-off { opacity: .55; }
