/* ============================================================
   Cleaf Support Portal — app.css v2
   Sidebar layout · Inter font · Orange brand · Dark mode
   ============================================================ */

/* Inter self-hosted: il servizio e' usato dalla Cina continentale, dove Google Fonts e' bloccato o lento. */
@font-face{font-family:'Inter';font-style:normal;font-weight:300;font-display:swap;src:url('../fonts/inter-latin-ext-300-normal.woff2') format('woff2');unicode-range:U+0100-02AF,U+0304,U+0308,U+0329,U+1E00-1E9F,U+1EF2-1EFF,U+2020,U+20A0-20AB,U+20AD-20CF,U+2113,U+2C60-2C7F,U+A720-A7FF}
@font-face{font-family:'Inter';font-style:normal;font-weight:300;font-display:swap;src:url('../fonts/inter-latin-300-normal.woff2') format('woff2');unicode-range:U+0000-00FF,U+0131,U+0152-0153,U+02BB-02BC,U+02C6,U+02DA,U+02DC,U+0304,U+0308,U+0329,U+2000-206F,U+20AC,U+2122,U+2191,U+2193,U+2212,U+2215,U+FEFF,U+FFFD}
@font-face{font-family:'Inter';font-style:normal;font-weight:400;font-display:swap;src:url('../fonts/inter-latin-ext-400-normal.woff2') format('woff2');unicode-range:U+0100-02AF,U+0304,U+0308,U+0329,U+1E00-1E9F,U+1EF2-1EFF,U+2020,U+20A0-20AB,U+20AD-20CF,U+2113,U+2C60-2C7F,U+A720-A7FF}
@font-face{font-family:'Inter';font-style:normal;font-weight:400;font-display:swap;src:url('../fonts/inter-latin-400-normal.woff2') format('woff2');unicode-range:U+0000-00FF,U+0131,U+0152-0153,U+02BB-02BC,U+02C6,U+02DA,U+02DC,U+0304,U+0308,U+0329,U+2000-206F,U+20AC,U+2122,U+2191,U+2193,U+2212,U+2215,U+FEFF,U+FFFD}
@font-face{font-family:'Inter';font-style:normal;font-weight:500;font-display:swap;src:url('../fonts/inter-latin-ext-500-normal.woff2') format('woff2');unicode-range:U+0100-02AF,U+0304,U+0308,U+0329,U+1E00-1E9F,U+1EF2-1EFF,U+2020,U+20A0-20AB,U+20AD-20CF,U+2113,U+2C60-2C7F,U+A720-A7FF}
@font-face{font-family:'Inter';font-style:normal;font-weight:500;font-display:swap;src:url('../fonts/inter-latin-500-normal.woff2') format('woff2');unicode-range:U+0000-00FF,U+0131,U+0152-0153,U+02BB-02BC,U+02C6,U+02DA,U+02DC,U+0304,U+0308,U+0329,U+2000-206F,U+20AC,U+2122,U+2191,U+2193,U+2212,U+2215,U+FEFF,U+FFFD}
@font-face{font-family:'Inter';font-style:normal;font-weight:600;font-display:swap;src:url('../fonts/inter-latin-ext-600-normal.woff2') format('woff2');unicode-range:U+0100-02AF,U+0304,U+0308,U+0329,U+1E00-1E9F,U+1EF2-1EFF,U+2020,U+20A0-20AB,U+20AD-20CF,U+2113,U+2C60-2C7F,U+A720-A7FF}
@font-face{font-family:'Inter';font-style:normal;font-weight:600;font-display:swap;src:url('../fonts/inter-latin-600-normal.woff2') format('woff2');unicode-range:U+0000-00FF,U+0131,U+0152-0153,U+02BB-02BC,U+02C6,U+02DA,U+02DC,U+0304,U+0308,U+0329,U+2000-206F,U+20AC,U+2122,U+2191,U+2193,U+2212,U+2215,U+FEFF,U+FFFD}
@font-face{font-family:'Inter';font-style:normal;font-weight:700;font-display:swap;src:url('../fonts/inter-latin-ext-700-normal.woff2') format('woff2');unicode-range:U+0100-02AF,U+0304,U+0308,U+0329,U+1E00-1E9F,U+1EF2-1EFF,U+2020,U+20A0-20AB,U+20AD-20CF,U+2113,U+2C60-2C7F,U+A720-A7FF}
@font-face{font-family:'Inter';font-style:normal;font-weight:700;font-display:swap;src:url('../fonts/inter-latin-700-normal.woff2') format('woff2');unicode-range:U+0000-00FF,U+0131,U+0152-0153,U+02BB-02BC,U+02C6,U+02DA,U+02DC,U+0304,U+0308,U+0329,U+2000-206F,U+20AC,U+2122,U+2191,U+2193,U+2212,U+2215,U+FEFF,U+FFFD}

/* ---- Custom properties: light ---- */
:root {
    --brand-50:  #fff7ed;
    --brand-100: #ffedd5;
    --brand-200: #fed7aa;
    --brand-300: #fdba74;
    --brand-400: #fca052;
    --brand-500: #f97316;
    --brand-600: #f68d29;
    --brand-700: #e07620;
    --brand-800: #c2610d;
    --brand-900: #3b1f00;

    --color-primary:    var(--brand-600);
    --color-primary-dk: var(--brand-700);
    --color-success:    #16a34a;
    --color-warning:    #d97706;
    --color-danger:     #dc2626;
    --color-info:       #0891b2;

    --color-bg:         #f9fafb;
    /* Sfondo pagina 1:1 col portale (Tailwind gray-200); distinto da --color-bg
       (usato anche per hover/badge tenui) per non alterare quegli elementi. */
    --color-page:       #e5e7eb;
    --color-surface:    #ffffff;
    --color-border:     #e5e7eb;
    --color-text:       #111827;
    --color-text-muted: #6b7280;
    --color-text-light: #9ca3af;

    /* La sidebar usa sempre i colori del tema scuro, anche in tema chiaro */
    --sidebar-bg:     #0f172a;
    --sidebar-border: #1e293b;
    --sidebar-muted:  #94a3b8;
    --sidebar-width:  230px;
    --header-height:  56px;

    --color-badge-open:             #dbeafe;
    --color-badge-open-text:        #1e40af;
    --color-badge-progress:         #fef9c3;
    --color-badge-progress-text:    #92400e;
    --color-badge-hold:             #f1f5f9;
    --color-badge-hold-text:        #475569;
    --color-badge-resolved:         #dcfce7;
    --color-badge-resolved-text:    #166534;
    --color-badge-closed:           #f0fdf4;
    --color-badge-closed-text:      #15803d;

    --radius-sm:  4px;
    --radius-md:  8px;
    --radius-lg:  12px;
    --radius-xl:  16px;
    --radius-2xl: 20px;
    --radius-full:9999px;

    --shadow-sm:  0 1px 2px rgba(0,0,0,.05);
    --shadow-md:  0 4px 6px -1px rgba(0,0,0,.07), 0 2px 4px -1px rgba(0,0,0,.04);
    --shadow-lg:  0 10px 15px -3px rgba(0,0,0,.08), 0 4px 6px -2px rgba(0,0,0,.04);
    --shadow-2xl: 0 25px 50px -12px rgba(0,0,0,.25);

    --font: 'Inter', system-ui, -apple-system, 'PingFang SC', 'Microsoft YaHei', 'Noto Sans CJK SC', sans-serif;
}

/* ---- Dark mode ---- */
html.dark {
    --color-bg:         #1e293b;
    --color-page:       #1e293b; /* dark: già uguale al portale (slate-800) */
    --color-surface:    #273548;
    /* --sidebar-bg / --sidebar-border: invariati (già impostati nel :root sui colori scuri) */
    --color-border:     #334155;
    --color-text:       #f1f5f9;
    --color-text-muted: #94a3b8;
    --color-text-light: #64748b;

    --color-badge-open:             #1e3a5f;
    --color-badge-open-text:        #93c5fd;
    --color-badge-progress:         #451a03;
    --color-badge-progress-text:    #fcd34d;
    --color-badge-hold:             #1e293b;
    --color-badge-hold-text:        #94a3b8;
    --color-badge-resolved:         #14532d;
    --color-badge-resolved-text:    #86efac;
    --color-badge-closed:           #052e16;
    --color-badge-closed-text:      #6ee7b7;
}

/* ---- Reset ---- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; }
/* Mobile: testo leggermente più grande (scala tutto in proporzione, niente scroll orizzontale) */
@media (max-width: 768px) { html { font-size: 17.5px; } }
body {
    font-family: var(--font);
    background: var(--color-page);
    color: var(--color-text);
    line-height: 1.6;
    min-height: 100vh;
    min-height: 100dvh; /* adatta l'altezza alle barre dinamiche del browser mobile */
    /* Niente -webkit-font-smoothing: vale solo su macOS e il Portale non la imposta
       (misurato), quindi su un Mac il testo qui usciva piu' sottile che di la'. */
}

/* ================================================================
   APP LAYOUT
   ================================================================ */
.app-layout {
    display: flex;
    height: 100vh;
    height: 100dvh; /* mobile: segue l'area realmente visibile (no scroll "rotto") */
    overflow: hidden;
}
/* Fallback robusto: --appvh = window.innerHeight (impostata da app.js, classe
   js-vh). Vale anche dove i dvh non esistono (Chrome vecchio/MDM): lì 100vh
   sarebbe il viewport con barra URL nascosta e taglierebbe il fondo. */
:root.js-vh .app-layout { height: var(--appvh); }
:root.js-vh .sidebar    { height: var(--appvh); }

/* ---- Sidebar ---- */
.sidebar {
    width: var(--sidebar-width);
    flex-shrink: 0;
    background: var(--sidebar-bg);
    border-right: 1px solid var(--sidebar-border);
    /* line-height 1.5 come il body del portale (Tailwind base), non l'1.6 dell'app:
       da qui ereditano label e testi della sidebar. */
    line-height: 1.5;
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
    z-index: 40;
    transition: transform .3s ease-in-out;
}

.sidebar-header {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    padding: 1.25rem 1rem 1rem;
    border-bottom: 1px solid var(--sidebar-border);
    gap: .25rem; /* logo↔sottotitolo come il portale (gap-1 = 4px) */
    flex-shrink: 0;
}

.sidebar-logo-link { display: inline-flex; align-items: center; text-decoration: none; }
.sidebar-logo { height: 32px; width: auto; }

.sidebar-logo-text {
    font-size: 1.125rem;
    font-weight: 700;
    color: #fff;
    letter-spacing: -.01em;
    line-height: 1.2;
}

.sidebar-subtitle {
    font-size: 11px;
    color: var(--sidebar-muted);
}

.sidebar-close {
    display: none;
    position: absolute;
    top: .75rem; right: .75rem;
    padding: .375rem;
    border-radius: var(--radius-md);
    background: none; border: none;
    color: var(--sidebar-muted);
    cursor: pointer;
    transition: color .15s, background .15s;
    align-items: center; justify-content: center;
}
.sidebar-close:hover { color: #fff; background: var(--brand-600); }
.sidebar-close svg { width: 16px; height: 16px; display: block; }

.sidebar-nav {
    flex: 1;
    overflow-y: auto;
    padding: .75rem;
    display: flex;
    flex-direction: column;
    gap: 1px;
}

.sidebar-section-label {
    /* Allineato al portale: text-[10px] tracking-wider (.05em). */
    font-size: .625rem;
    font-weight: 600;
    color: #64748b;
    text-transform: uppercase;
    letter-spacing: .05em;
    margin-top: 1.1rem;
    margin-bottom: .375rem; /* 6px come il mb-1.5 del portale */
    /* padding-left .25rem → testo del label a 16px dal bordo (nav .75rem + .25rem),
       come il portale (px-3 + px-1). Prima .75rem lo portava a 24px, allineato con
       l'icona invece che leggermente a sinistra. */
    padding: 0 .25rem;
}
.sidebar-section-label:first-child { margin-top: 0; }
.sidebar-sep { height: 1px; background: var(--sidebar-border); margin: .5rem 0; }

.sidebar-link {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    /* font-family: la voce puo' essere un <a> (che eredita) oppure un <button>
       (che NON eredita e renderizzerebbe in Arial): senza inherit "APP Cleaf"
       usciva con metriche diverse dalle altre voci — piu' magro. */
    font-family: inherit;
    /* Allineato 1:1 al portale: py-2 px-3 (8px/12px), text-sm (14px/20px, h=36),
       text-slate-300. */
    padding: .5rem .75rem;
    border-radius: var(--radius-md);
    font-size: .875rem;
    line-height: 1.25rem;
    font-weight: 500;
    color: #cbd5e1;
    text-decoration: none;
    border: none;
    background: none;
    cursor: pointer;
    transition: background .15s, color .15s;
    white-space: nowrap;
}
.sidebar-link:hover  { background: var(--brand-600); color: #fff; }
.sidebar-link.active { background: var(--brand-600); color: #fff; }

.sidebar-link-sub { padding-left: 1.75rem; font-size: .8375rem; opacity: .88; }
.sidebar-link-sub .sidebar-link-inner svg { width: 12px; height: 12px; }

/* gap icona-testo e icone allineati al portale: gap-2.5 (10px), w-4 h-4 (16px). */
.sidebar-link-inner { display: flex; align-items: center; gap: .625rem; }
.sidebar-link svg   { width: 16px; height: 16px; flex-shrink: 0; }

.nav-badge {
    font-size: .65rem;
    border-radius: var(--radius-full);
    padding: .1rem .45rem;
    background: rgba(255,255,255,.1);
    color: rgba(255,255,255,.5);
    line-height: 1.4;
}
.sidebar-link.active .nav-badge,
.sidebar-link:hover  .nav-badge { background: rgba(255,255,255,.2); color: #fff; }

.sidebar-footer {
    /* p-3 + space-y-1 come il footer del portale (gap verticale 4px). */
    padding: .75rem;
    display: flex;
    flex-direction: column;
    gap: .25rem;
    flex-shrink: 0;
}
/* Come il border-t del footer portale: stesso colore, a tutta larghezza (margini
   negativi per bucare il padding), 12px di aria sopra e sotto (8px + gap 4px). */
.sidebar-footer-sep { height: 1px; background: rgba(255,255,255,.06); margin: .5rem -.75rem; }
/* Desktop: il wrapper è trasparente (tema/logout restano impilati come prima).
   Ordine verticale: cambio tema → nome utente → logout. */
.sidebar-footer-row { display: contents; }
.sidebar-footer .sidebar-user { order: 1; }
.sidebar-footer-row form { order: 2; }

.sidebar-user {
    display: flex;
    align-items: center;
    gap: .5rem;
    /* px-2 py-1 come la riga utente del portale (h=36 con avatar 28). */
    padding: .25rem .5rem;
}

.sidebar-avatar {
    width: 28px; height: 28px;
    border-radius: var(--radius-full);
    /* Pieno brand + text-xs bold, come l'avatar del portale. */
    background: var(--brand-600);
    color: #fff;
    font-size: .75rem; font-weight: 700;
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0;
}

.sidebar-username {
    /* text-sm (14px/20px) come il nome utente del portale. */
    font-size: .875rem; line-height: 1.25rem; font-weight: 500;
    color: #fff;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

/* Il profilo utente è un link ai manuali del proprio ruolo */
a.sidebar-user {
    border-radius: var(--radius-md);
    text-decoration: none;
    transition: background .15s;
}
a.sidebar-user:hover,
a.sidebar-user.active { background: var(--brand-600); }
.sidebar-user-manuals {
    margin-left: auto;
    flex-shrink: 0;
    color: rgba(255,255,255,.55);
    transition: color .15s;
}
a.sidebar-user:hover .sidebar-user-manuals,
a.sidebar-user.active .sidebar-user-manuals { color: #fff; }

.sidebar-action {
    display: flex;
    align-items: center;
    gap: .5rem;
    width: 100%;
    padding: .375rem .75rem;
    border-radius: var(--radius-md);
    /* font-family: i <button> NON ereditano il font (renderizzano in Arial):
       senza inherit il testo esce con metriche diverse dal portale. */
    font-family: inherit;
    /* text-xs (12px/16px) text-white/70 come i pulsanti del footer portale (h=28). */
    font-size: .75rem; line-height: 1rem; font-weight: 500;
    color: rgba(255,255,255,.7);
    background: none; border: none;
    cursor: pointer;
    text-decoration: none;
    transition: color .15s, background .15s;
    position: relative;
}
.sidebar-action:hover { color: #fff; background: var(--brand-600); }
/* Esci: text-white/60 come il portale. */
.sidebar-action.danger { color: rgba(255,255,255,.6); }
.sidebar-action.danger:hover { color: #fff; background: #dc2626; }

/* Sezioni dentro il footer: stessi respiri del blocco Amministrazione del portale
   (label mb-1.5=6px e link impilati a 2px, al netto del gap 4px del flex). */
.sidebar-footer .sidebar-section-label { margin-bottom: .125rem; }
.sidebar-footer .sidebar-link + a.sidebar-link { margin-top: -.125rem; }
.sidebar-action svg { width: 14px; height: 14px; flex-shrink: 0; }

.sidebar-notif-badge {
    margin-left: auto;
    background: #dc2626; color: #fff;
    font-size: .6rem; font-weight: 700;
    border-radius: var(--radius-full);
    padding: .05rem .35rem;
    line-height: 1.5;
}

/* Profilo utente in cima al menu: solo mobile */
.sidebar-mobile-profile { display: none; }
@keyframes sidebarItemIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ---- Main area ---- */
.app-main {
    flex: 1;
    /* Sfondo opaco: .app-main e' il contenitore che scorre, quindi il browser gli
       da' un livello grafico proprio. Un livello TRASPARENTE viene composto senza
       un colore di base e su alcune GPU/driver, nell'istante prima della prima
       pittura, esce come un blocco di memoria non inizializzata (una banda
       violacea/magenta) — un artefatto che non finisce in nessuna cattura dello
       schermo, quindi non si vede negli screenshot ne' nelle registrazioni.
       Dandogli lo stesso colore del body il livello nasce gia' opaco: l'aspetto
       non cambia di un pixel (dietro c'era esattamente questo colore). */
    background: var(--color-page);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch; /* scroll con inerzia su iOS */
    /* ATTENZIONE: qui dentro NON ci vanno elementi `position: fixed` che devono
       restare agganciati allo schermo. Questo e' il contenitore che scorre e su
       iPhone WebKit li aggancia al CONTENUTO: finiscono in fondo alla pagina,
       fuori dalla vista. E' successo alla barra di navigazione inferiore
       (.mnav), che infatti ora sta fuori da .app-layout, figlia di <body>. */
    overscroll-behavior-y: contain;    /* evita lo scroll-chaining sul body fisso */
    scrollbar-width: none;
    display: flex;
    flex-direction: column;
    min-width: 0;
}

/* ---- Mobile hamburger (dentro app-header) ---- */
.mobile-hamburger {
    display: none;
    background: none; border: none; cursor: pointer;
    padding: .35rem; border-radius: var(--radius-md);
    color: var(--color-text-muted); transition: background .15s;
}
.mobile-hamburger:hover { background: var(--color-bg); }
.mobile-hamburger svg { width: 20px; height: 20px; display: block; }

/* ---- Sidebar backdrop ---- */
.sidebar-backdrop {
    display: none;
    position: fixed; inset: 0; z-index: 30;
    background: rgba(0,0,0,.4);
}

/* ---- Content ---- */
.main-content { padding: 1.5rem 0; flex: 1; }
.container    { padding: 0 1.5rem; }

/* spazio per l'header fisso */
.app-main { padding-top: calc(var(--header-height) + .75rem); }
.app-main::-webkit-scrollbar { display: none; }

/* (Rimossa la maschera .app-main::before: serviva col vecchio header flottante a
   isola. Ora l'header è una striscia piena (top:0, da sidebar a destra, sfondo
   --color-page opaco) che copre già il contenuto sotto: la maschera era più alta
   dell'header e il suo lembo #f9fafb creava una riga bianca sotto l'header.) */

/* ---- Flash alerts ---- */
.alert {
    display: flex; align-items: center; justify-content: space-between;
    padding: .7rem 1.5rem; font-size: .875rem;
}
.alert-success { background: #dcfce7; color: #166534; border-bottom: 1px solid #bbf7d0; }
.alert-error   { background: #fee2e2; color: #991b1b; border-bottom: 1px solid #fecaca; }
.alert-info    { background: #e0f2fe; color: #075985; border-bottom: 1px solid #bae6fd; }
html.dark .alert-success { background: #14532d; color: #86efac; border-color: #166534; }
html.dark .alert-error   { background: #7f1d1d; color: #fca5a5; border-color: #991b1b; }
html.dark .alert-info    { background: #0c4a6e; color: #7dd3fc; border-color: #0369a1; }
.alert-close { background: none; border: none; cursor: pointer; font-size: 1.2rem; opacity: .6; line-height: 1; color: inherit; }
/* Chiusura automatica (4s) degli avvisi del layout: si sgonfiano invece di sparire di
   colpo, altrimenti il contenuto sotto salterebbe su di un blocco. */
.alert[data-auto-chiudi] { overflow: hidden; transition: opacity .2s ease, max-height .28s ease, padding .28s ease; }
.alert[data-auto-chiudi].alert-via { opacity: 0; max-height: 0 !important; padding-top: 0; padding-bottom: 0; }

/* ================================================================
   COMPONENTS
   ================================================================ */

/* ---- Cards ---- */
.card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
    transition: border-color .2s, box-shadow .2s;
}
.card-header {
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--color-border);
    display: flex; align-items: center; justify-content: space-between;
}
.card-title { font-size: .9375rem; font-weight: 600; }
.card-body  { padding: 1.25rem; }

/* ---- Buttons ---- */
.btn {
    display: inline-flex; align-items: center; gap: .4rem;
    padding: .5rem 1rem;
    border-radius: var(--radius-md);
    font-size: .875rem; font-weight: 500;
    cursor: pointer; text-decoration: none;
    border: 1px solid transparent;
    transition: background .15s, opacity .15s;
    line-height: 1.4; font-family: inherit;
}
.btn:disabled { opacity: .5; cursor: not-allowed; pointer-events: none; }

.btn-primary { background: var(--brand-600); color: #fff; }
.btn-primary:hover { background: var(--brand-700); }
html.dark .btn-primary { background: var(--brand-700); }
html.dark .btn-primary:hover { background: var(--brand-800); }

.btn-secondary {
    background: var(--color-surface); color: var(--color-text);
    border-color: var(--color-border);
}
.btn-secondary:hover { background: var(--color-bg); }
html.dark .btn-secondary { background: #334155; color: #e2e8f0; border-color: #475569; }
html.dark .btn-secondary:hover { background: #475569; }

.btn-danger  { background: #dc2626; color: #fff; }
.btn-danger:hover  { background: #b91c1c; }
.btn-success { background: #16a34a; color: #fff; }
.btn-success:hover { background: #15803d; }

.btn-azure {
    background: #0078d4; color: #fff;
    width: 100%; justify-content: center;
    padding: .65rem 1rem; font-size: .9375rem;
    border-radius: var(--radius-lg);
}
.btn-azure:hover { background: #106ebe; }
.btn-sm    { padding: .3rem .65rem; font-size: .8rem; }
.btn-block { width: 100%; justify-content: center; }

/* ---- Forms ---- */
.form-group { margin-bottom: 1.1rem; }
.form-group label, .form-label {
    display: block; font-size: .8rem; font-weight: 600;
    margin-bottom: .35rem; color: var(--color-text-muted);
    text-transform: uppercase; letter-spacing: .04em;
}

/* ---- Universal input style ---- */
input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
input[type="search"],
input[type="tel"],
input[type="url"],
input[type="date"],
select,
textarea {
    width: 100%;
    padding: .65rem .9rem;
    border: 1.5px solid var(--color-border);
    border-radius: var(--radius-md);
    font-size: .875rem;
    font-family: inherit;
    color: var(--color-text);
    background-color: var(--color-surface);
    transition: border-color .18s, box-shadow .18s, background .18s;
    outline: none;
    -webkit-appearance: none;
    appearance: none;
}
input[type="text"]:hover,
input[type="email"]:hover,
input[type="password"]:hover,
input[type="number"]:hover,
input[type="search"]:hover,
input[type="tel"]:hover,
input[type="url"]:hover,
input[type="date"]:hover,
select:hover {
    border-color: #c9d1d9;
}
input[type="text"]:focus,
input[type="email"]:focus,
input[type="password"]:focus,
input[type="number"]:focus,
input[type="search"]:focus,
input[type="tel"]:focus,
input[type="url"]:focus,
input[type="date"]:focus,
select:focus,
textarea:focus {
    border-color: var(--brand-600);
    box-shadow: 0 0 0 3.5px rgba(246,141,41,.18);
    background-color: var(--color-surface);
}
input::placeholder,
textarea::placeholder { color: var(--color-text-light); }

html.dark input[type="text"],
html.dark input[type="email"],
html.dark input[type="password"],
html.dark input[type="number"],
html.dark input[type="search"],
html.dark input[type="tel"],
html.dark input[type="url"],
html.dark input[type="date"],
html.dark select,
html.dark textarea {
    /*background: #1e2d3d;*/
    border-color: #334155;
    color: #f1f5f9;
}
html.dark input:hover,
html.dark select:hover { border-color: #475569; }
html.dark input::placeholder,
html.dark textarea::placeholder { color: #475569; }
html.dark input:focus,
html.dark select:focus,
html.dark textarea:focus {
    border-color: var(--brand-600);
    background-color: #1e2d3d;
    box-shadow: 0 0 0 3.5px rgba(246,141,41,.14);
}

textarea { min-height: 120px; resize: vertical; }
/* ---- Select: stato chiuso stilizzato (freccia moderna + hover/focus) ---- */
select {
    cursor: pointer;
    padding-right: 2.6rem;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='18' height='18' viewBox='0 0 24 24' fill='none' stroke='%236b7280' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right .8rem center;
    background-size: 18px;
}
select:hover {
    border-color: color-mix(in srgb, var(--brand-600) 45%, var(--color-border));
}
select:focus { /* freccia in tinta brand quando attiva */
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='18' height='18' viewBox='0 0 24 24' fill='none' stroke='%23f68d29' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
}
html.dark select {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='18' height='18' viewBox='0 0 24 24' fill='none' stroke='%2394a3b8' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
}

.form-error { color: var(--color-danger); font-size: .8rem; margin-top: .3rem; }
.form-hint  { color: var(--color-text-muted); font-size: .8rem; margin-top: .3rem; }

/* ---- Status badges ---- */
.badge-status {
    display: inline-flex; align-items: center; gap: .3rem;
    padding: .2rem .55rem; border-radius: var(--radius-full);
    font-size: .75rem; font-weight: 600; white-space: nowrap;
}
/* Ticket "bozza": salvataggio provvisorio del flusso reperibilità, da completare */
.draft-badge {
    display: inline-flex; align-items: center;
    padding: .1rem .45rem; border-radius: var(--radius-full);
    font-size: .68rem; font-weight: 700; letter-spacing: .03em; text-transform: uppercase;
    background: #fef3c7; color: #92400e; white-space: nowrap;
}
html.dark .draft-badge { background: #422006; color: #fcd34d; }
.badge-open        { background: var(--color-badge-open);     color: var(--color-badge-open-text); }
.badge-in_progress { background: var(--color-badge-progress); color: var(--color-badge-progress-text); }
.badge-on_hold     { background: var(--color-badge-hold);     color: var(--color-badge-hold-text); }
.badge-resolved    { background: var(--color-badge-resolved); color: var(--color-badge-resolved-text); }
.badge-closed      { background: var(--color-badge-closed);   color: var(--color-badge-closed-text); }

.badge-assignment {
    display: inline-flex; align-items: center; gap: .3rem;
    padding: .2rem .55rem; border-radius: var(--radius-full);
    font-size: .75rem; font-weight: 600;
}
.badge-assignment.unassigned { background: #f1f5f9; color: #6b7280; }
.badge-assignment.assigned   { background: #dbeafe; color: #1e40af; }
html.dark .badge-assignment.unassigned { background: #1e293b; color: #94a3b8; }
html.dark .badge-assignment.assigned   { background: #1e3a5f; color: #93c5fd; }

.collab-badge { display:inline-flex; align-items:center; padding:.15rem .5rem; background:color-mix(in srgb,var(--color-primary) 10%,transparent); border:1px solid color-mix(in srgb,var(--color-primary) 22%,transparent); border-radius:999px; font-size:.78rem; font-weight:600; color:var(--color-primary); margin-right:.3rem; margin-bottom:.2rem; }

.badge-priority {
    display: inline-flex; align-items: center; gap: .3rem;
    padding: .2rem .55rem; border-radius: var(--radius-full);
    font-size: .75rem; font-weight: 600;
}
.badge-normal   { background: #f1f5f9; color: #475569; }
.badge-urgent   { background: var(--brand-50); color: var(--brand-700); }
.badge-blocking { background: #fee2e2; color: #991b1b; animation: pulse-red 1.5s infinite; }
@keyframes pulse-red { 0%,100%{opacity:1} 50%{opacity:.7} }

/* notification count badge (inline) */
.badge {
    position: absolute; top: 2px; right: 2px;
    background: #dc2626; color: #fff;
    font-size: .65rem; font-weight: 700;
    min-width: 16px; height: 16px;
    border-radius: var(--radius-full);
    display: flex; align-items: center; justify-content: center;
    padding: 0 4px;
}

/* ---- Ticket list ---- */
.ticket-list { display: flex; flex-direction: column; gap: .5rem; }
.ticket-row {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    padding: .9rem 1rem;
    display: grid; gap: .5rem;
    text-decoration: none; color: var(--color-text);
    transition: box-shadow .15s, border-color .15s;
    cursor: pointer;
}
.ticket-row:hover { box-shadow: var(--shadow-md); border-color: var(--brand-400); }
.ticket-row.is-blocking { border-left: 4px solid #dc2626; }
.ticket-row-header { display: flex; align-items: center; gap: .75rem; flex-wrap: wrap; }
.ticket-id    { color: var(--color-text-muted); font-size: .8rem; flex-shrink: 0; }
.ticket-title { font-weight: 600; flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ticket-meta  { display: flex; gap: .75rem; align-items: center; flex-wrap: wrap; font-size: .8rem; color: var(--color-text-muted); }

/* ---- Stats ---- */
.stats-grid {
    display: grid; gap: 1rem;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
}
.stat-card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    padding: 1.2rem; box-shadow: var(--shadow-sm);
    border-left: 3px solid transparent;
}
.stat-blue   { border-left-color: #3b82f6; }
.stat-yellow { border-left-color: var(--brand-500); }
.stat-green  { border-left-color: #16a34a; }
.stat-red    { border-left-color: #dc2626; }
.stat-value  { font-size: 2rem; font-weight: 700; line-height: 1; }
.stat-label  { font-size: .85rem; color: var(--color-text-muted); margin-top: .4rem; }

/* ---- Charts ---- */
.charts-row { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
@media (max-width: 900px) { .charts-row { grid-template-columns: 1fr; } }

/* ---- Dept tabs ---- */
.dept-tabs { display: flex; gap: .375rem; flex-wrap: wrap; }
.dept-tab {
    padding: .3rem .8rem; border-radius: var(--radius-full);
    font-size: .8rem; font-weight: 500; text-decoration: none;
    border: 1px solid var(--color-border);
    color: var(--color-text-muted); background: var(--color-surface);
    transition: all .15s;
}
.dept-tab:hover  { border-color: var(--brand-400); color: var(--brand-600); }
.dept-tab.active { background: var(--brand-600); border-color: var(--brand-600); color: #fff; }

/* ---- Blocking alert ---- */
.blocking-alert {
    background: #fee2e2; border: 1px solid #fecaca;
    border-radius: var(--radius-md);
    padding: .75rem 1rem; font-size: .875rem; color: #991b1b;
}
.blocking-link { color: #991b1b; font-weight: 600; margin-left: .5rem; }

/* ---- Kanban ---- */
.kanban-board { display: flex; gap: 1rem; overflow-x: auto; padding-bottom: 1rem; }
.kanban-col {
    flex: 0 0 280px; background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg); padding: .75rem;
}
.kanban-col-header { font-weight: 600; font-size: .875rem; margin-bottom: .75rem; padding: .25rem .5rem; }
.kanban-cards { display: flex; flex-direction: column; gap: .5rem; min-height: 60px; }

/* ---- Tables ---- */
.table-th { padding: .75rem 1rem; text-align: left; font-size: .75rem; font-weight: 600; color: var(--color-text-muted); text-transform: uppercase; letter-spacing: .05em; }
.table-td { padding: .75rem 1rem; font-size: .875rem; color: var(--color-text); }

/* ---- App header bar ---- */
.app-header {
    position: fixed;
    top: 0;
    left: var(--sidebar-width);
    right: 0;
    z-index: 50;
    background: transparent; /* la fascia la disegna ::before (sfumatura come il portale) */
    transition: left .18s ease;
}
/* Schiarimento verso l'alto, 1:1 col portale: sopra la topbar il fondo pagina
   (--color-page, gray-200) sfuma in --color-bg (gray-50) e torna trasparente in
   80px, così il contenuto che scorre sotto si dissolve invece di essere tagliato.
   In tema scuro le due tinte coincidono (slate-800): resta solo la dissolvenza.
   Equivale al div `h-20 bg-gradient-to-b from-gray-50 to-transparent` del portale. */
.app-header::before {
    content: '';
    position: absolute;
    left: 0; right: 0; top: 0;
    height: 80px;
    background: linear-gradient(to bottom, var(--color-bg), transparent);
    pointer-events: none;
    z-index: -1;
}
/* Contenuto della topbar limitato e centrato, con gli stessi breakpoint del portale
   (max-w-5xl / xl:max-w-7xl / 2xl:max-w-[1400px], px-6 / xl:px-8). */
.app-header-inner {
    display: flex;
    align-items: center;
    gap: .5rem;
    width: 100%;
    max-width: 64rem;
    margin: 0 auto;
    padding: 12px 24px; /* py-3 px-6 come il portale: l'altezza dell'header viene dal contenuto */
}
@media (min-width: 1280px) { .app-header-inner { max-width: 80rem; padding: 12px 32px; } }
@media (min-width: 1536px) { .app-header-inner { max-width: 1400px; } }
.app-header > * { pointer-events: auto; }

.app-header-left  { display: flex; align-items: center; gap: .5rem; flex: 1; min-width: 0; }
/* gap-2 (8px) anche tra campanella e data, come nel portale (topbar a gap unico):
   con 6px la campanella slittava e la ricerca risultava 2px più larga. */
.app-header-right { display: flex; align-items: center; gap: .5rem; flex-shrink: 0; }

/* Search bar — pill moderno, un solo bordo (l'input interno è completamente resettato) */
.header-search {
    /* Barra di ricerca 1:1 col portale: box bianco, bordo gray-200, rounded-lg (8px),
       px-3 py-2, icona 16px, testo 14px. In dark: slate-600, bordo trasparente. */
    position: relative;
    display: flex;
    align-items: center;
    gap: .5rem;
    flex: 1;
    min-width: 0;
    background: #ffffff;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    padding: 8px 12px;
}
html.dark .header-search { background: #475569; border-color: transparent; }
.header-search svg { width: 16px; height: 16px; color: #9ca3af; flex-shrink: 0; }
html.dark .header-search svg { color: #64748b; }
/* Reset totale dell'input: niente bordo/padding/anello propri dal CSS globale dei form */
.header-search input,
.header-search input:hover,
.header-search input:focus {
    flex: 1; min-width: 0;
    border: none; background: transparent; outline: none;
    padding: 0; border-radius: 0; box-shadow: none;
    font-size: .875rem; line-height: 1.25rem; font-family: inherit; color: #374151;
}
html.dark .header-search input { color: #d1d5db; }
.header-search input::placeholder { color: #9ca3af; }
html.dark .header-search input::placeholder { color: #64748b; }
.header-search-clear {
    background: none; border: none; cursor: pointer; padding: 0; line-height: 0;
    color: #9ca3af; transition: color .15s;
    display: none;
}
.header-search-clear:hover { color: var(--color-text); }
.header-search-clear svg { width: 13px; height: 13px; }
.header-search.has-value .header-search-clear { display: block; }

/* ── Tendina risultati istantanei della ricerca ── */
.header-search-results {
    position: fixed; z-index: 320;
    max-height: 60vh; overflow-y: auto;
    background: var(--color-surface); border: 1px solid var(--color-border);
    border-radius: var(--radius-md); box-shadow: 0 12px 32px rgba(0,0,0,.16); padding: .3rem;
}
.hsr-item {
    display: flex; flex-direction: column; gap: .1rem;
    padding: .5rem .6rem; border-radius: 6px; text-decoration: none; color: var(--color-text);
}
.hsr-item:hover, .hsr-item.is-active { background: var(--color-bg); }
.hsr-title { font-size: .875rem; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hsr-sub { font-size: .78rem; color: var(--color-text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hsr-empty { padding: .6rem; font-size: .82rem; color: var(--color-text-muted); text-align: center; }
.hsr-group { padding: .4rem .6rem .2rem; font-size: .68rem; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--color-text-muted); }
.hsr-cat { flex-direction: row; align-items: center; gap: .5rem; }
.hsr-cat svg { flex: 0 0 auto; color: var(--color-text-muted); }
.hsr-cat .hsr-title { flex: 0 1 auto; }
.hsr-cat .hsr-sub { margin-left: auto; padding-left: .5rem; }

/* Tasto indietro nell'header: visibile solo su mobile (vedi media query) */
.app-header-back {
    display: none;
    align-items: center; justify-content: center;
    width: 36px; height: 36px; border-radius: 50%;
    color: var(--color-text); text-decoration: none; flex-shrink: 0;
    margin-left: -.25rem;
    background: none; border: none; cursor: pointer; padding: 0;
}

/* Nome pagina nell'header: visibile solo su mobile (vedi media query) */
.app-header-title {
    display: none;
    font-size: 1.05rem; font-weight: 700; color: var(--color-text);
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
    min-width: 0;
}

/* Toggle ricerca: visibile solo su mobile (vedi media query) */
.header-search-toggle {
    display: none;
    align-items: center; justify-content: center;
    width: 40px; height: 40px;
    border: none; background: none; cursor: pointer;
    color: var(--color-text-muted); border-radius: var(--radius-md);
    flex-shrink: 0;
}

.header-date {
    /* text-sm (14px/20px) come la data del portale */
    font-size: .875rem;
    line-height: 1.25rem;
    font-weight: 600;
    color: #374151;
    white-space: nowrap;
    pointer-events: none;
}
html.dark .header-date { color: #e2e8f0; }

/* Bell button */
#bell-btn {
    position: relative;
    padding: 8px;
    border: none;
    background: transparent;
    cursor: pointer;
    border-radius: 12px;
    color: #9ca3af;
    transition: background .15s, color .15s;
    line-height: 0;
    /* il font del badge (i <button> non ereditano il font della pagina) */
    font-family: inherit;
}
html.dark #bell-btn { color: #64748b; } /* dark:text-slate-500 come il portale */
#bell-btn:hover { background: rgba(0,0,0,.05); color: #4b5563; }
html.dark #bell-btn:hover { background: rgba(255,255,255,.10); color: #fff; }
.bell-icon { width: 28px; height: 28px; display: block; }

.bell-badge {
    position: absolute;
    top: -4px; right: -4px;
    min-width: 22px; height: 22px;
    padding: 0 4px; /* come il badge del portale */
    border-radius: 999px;
    background: #f43f5e; /* rose-500, come il badge del portale */
    color: #fff;
    font-size: 11px;
    font-weight: 700;
    line-height: 22px;
    text-align: center;
    display: none;
}
.bell-badge:not(.hidden) { display: block; }

/* Notification dropdown */
.notif-dropdown {
    position: fixed;
    width: 320px;
    z-index: 9999;
    border-radius: var(--radius-xl);
    overflow: hidden;
    background: rgba(255,255,255,.95);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid rgba(0,0,0,.1);
    box-shadow: 0 20px 60px rgba(0,0,0,.14);
}
html.dark .notif-dropdown {
    background: rgba(30,41,59,.96);
    border-color: rgba(255,255,255,.08);
}
.notif-dropdown.hidden { display: none; }

.notif-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: .75rem 1rem;
    border-bottom: 1px solid rgba(0,0,0,.08);
    font-size: .875rem;
    font-weight: 600;
}
html.dark .notif-header { border-color: rgba(255,255,255,.07); color: #f1f5f9; }
.notif-header button {
    font-size: .75rem;
    color: var(--brand-600);
    background: none; border: none; cursor: pointer;
    font-family: inherit;
}
.notif-header button:hover { text-decoration: underline; }

/* Invito ad attivare le web push: compare solo finché il permesso non è dato. */
.notif-push-enable {
    display: block;
    width: 100%;
    padding: .625rem 1rem;
    text-align: left;
    font-family: inherit;
    font-size: .8125rem;
    font-weight: 500;
    color: var(--brand-600);
    background: rgba(246,141,41,.08);
    border: none;
    border-bottom: 1px solid rgba(0,0,0,.05);
    cursor: pointer;
}
.notif-push-enable:hover { background: rgba(246,141,41,.16); }
html.dark .notif-push-enable { border-color: rgba(255,255,255,.07); }

#notif-list button {
    width: 100%;
    text-align: left;
    padding: .75rem 1rem;
    display: flex;
    gap: .75rem;
    align-items: flex-start;
    background: none; border: none; cursor: pointer;
    border-bottom: 1px solid rgba(0,0,0,.05);
    font-size: .875rem;
    transition: background .15s;
    font-family: inherit;
    color: var(--color-text);
}
#notif-list button:hover { background: rgba(0,0,0,.04); }
html.dark #notif-list button { border-color: rgba(255,255,255,.05); }
html.dark #notif-list button:hover { background: rgba(255,255,255,.05); }

.notif-body  { flex: 1; min-width: 0; }
.notif-title { font-weight: 500; line-height: 1.4; }
.notif-time  { font-size: .75rem; color: var(--color-text-muted); margin-top: .2rem; }
.notif-dot   {
    width: 8px; height: 8px; border-radius: 50%;
    background: var(--brand-600);
    flex-shrink: 0; margin-top: .35rem;
}

#notif-empty {
    padding: 1.5rem 1rem;
    text-align: center;
    font-size: .875rem;
    color: var(--color-text-muted);
}
#notif-empty.hidden { display: none; }

/* ---- Notification drawer ---- */
.notification-drawer {
    position: fixed; right: 0; top: 0; bottom: 0;
    width: 360px; max-width: 100vw;
    background: var(--color-surface); border-left: 1px solid var(--color-border);
    box-shadow: var(--shadow-lg); z-index: 300;
    display: flex; flex-direction: column;
}
.drawer-header {
    padding: 1rem 1.25rem; border-bottom: 1px solid var(--color-border);
    display: flex; align-items: center; justify-content: space-between; font-weight: 600;
}
.drawer-header button { background: none; border: none; cursor: pointer; font-size: 1.3rem; color: var(--color-text-muted); }
.drawer-body   { flex: 1; overflow-y: auto; padding: .75rem; }
.drawer-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.3); z-index: 299; }

/* ---- Chatbot ---- */
.chatbot-widget { position: fixed; bottom: 1.5rem; right: 1.5rem; z-index: 400; }
.chatbot-toggle {
    width: 52px; height: 52px; border-radius: var(--radius-full);
    background: var(--brand-600); color: #fff; border: none; cursor: pointer;
    box-shadow: var(--shadow-lg); display: flex; align-items: center; justify-content: center;
    transition: transform .2s, background .15s;
}
.chatbot-toggle:hover { transform: scale(1.08); background: var(--brand-700); }
.chatbot-toggle svg { width: 24px; height: 24px; }
.chatbot-panel {
    position: absolute; bottom: 64px; right: 0;
    width: 320px; max-height: 480px;
    background: var(--color-surface); border: 1px solid var(--color-border);
    border-radius: var(--radius-xl); box-shadow: var(--shadow-lg);
    display: flex; flex-direction: column; overflow: hidden;
}
.chatbot-header {
    padding: .75rem 1rem; background: var(--brand-600); color: #fff;
    display: flex; align-items: center; justify-content: space-between; font-weight: 600;
}
.chatbot-header button { background: none; border: none; color: #fff; cursor: pointer; font-size: 1.2rem; }
.chatbot-messages { flex: 1; overflow-y: auto; padding: .75rem; display: flex; flex-direction: column; gap: .5rem; }
.chatbot-footer { padding: .5rem; border-top: 1px solid var(--color-border); display: flex; gap: .5rem; }
.chatbot-footer input { flex: 1; }
.chatbot-actions { padding: .5rem; border-top: 1px solid var(--color-border); }
.msg-bubble { max-width: 85%; padding: .5rem .75rem; border-radius: var(--radius-lg); font-size: .875rem; line-height: 1.5; }
.msg-user { background: var(--brand-600); color: #fff; align-self: flex-end; border-bottom-right-radius: 4px; }
.msg-bot  { background: var(--color-bg); color: var(--color-text); align-self: flex-start; border-bottom-left-radius: 4px; }

/* ---- Login page ---- */
.login-page {
    min-height: 100vh;
    background: linear-gradient(135deg, #0f172a 0%, #1e293b 100%);
    display: flex; align-items: center; justify-content: center;
    padding: 1rem;
}
.login-container { width: 100%; max-width: 380px; }
.login-card {
    background: #ffffff;
    border-radius: var(--radius-2xl);
    box-shadow: var(--shadow-2xl);
    padding: 2rem;
}
html.dark .login-card { background: #1e293b; }
.login-header { text-align: center; margin-bottom: 1.75rem; }
.login-icon {
    display: inline-flex; align-items: center; justify-content: center;
    width: 56px; height: 56px;
    border-radius: var(--radius-2xl);
    background: var(--brand-600);
    margin-bottom: 1rem;
    box-shadow: var(--shadow-md);
}
.login-icon svg { width: 28px; height: 28px; color: #fff; }
.login-header h1 { font-size: 1.5rem; font-weight: 700; color: #111827; }
html.dark .login-header h1 { color: #f1f5f9; }
.login-header p { color: #9ca3af; font-size: .875rem; margin-top: .25rem; }
.login-sso { margin-bottom: .75rem; }
.login-divider { display: flex; align-items: center; gap: .75rem; margin: 1.25rem 0; }
.login-divider::before,
.login-divider::after { content: ''; flex: 1; height: 1px; background: #e5e7eb; }
html.dark .login-divider::before,
html.dark .login-divider::after { background: #334155; }
.login-divider span { color: #9ca3af; font-size: .8rem; }
.login-footer { text-align: center; margin-top: 1.5rem; color: #9ca3af; font-size: .8rem; }
.lang-switch { background: none; border: none; cursor: pointer; color: var(--brand-600); font-size: .8rem; }
.ms-icon { width: 20px; height: 20px; flex-shrink: 0; }

/* ---- Modal overlay ---- */
.modal-overlay {
    display: none;
    position: fixed; inset: 0; z-index: 1000;
    background: rgba(0,0,0,.45);
    padding: 1rem;
    animation: modalFadeIn .15s ease;
}
.modal-overlay:not([hidden]) { display: flex; align-items: center; justify-content: center; }
@keyframes modalFadeIn { from { opacity: 0; } to { opacity: 1; } }

.modal {
    background: var(--color-surface);
    border-radius: var(--radius-xl);
    box-shadow: 0 20px 60px rgba(0,0,0,.25);
    width: 100%; max-width: 500px;
    max-height: calc(100vh - 2rem);
    display: flex; flex-direction: column;
    animation: modalSlideIn .15s ease;
}
@keyframes modalSlideIn { from { transform: translateY(-12px); opacity: 0; } to { transform: none; opacity: 1; } }
.modal-lg  { max-width: 640px; }
.modal-xl  { max-width: 720px; }

.modal-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 1.1rem 1.4rem;
    border-bottom: 1px solid var(--color-border);
    flex-shrink: 0;
}
.modal-title { font-size: 1rem; font-weight: 700; }
.modal-close {
    width: 28px; height: 28px; border: none; background: none; cursor: pointer;
    border-radius: var(--radius-sm); display: flex; align-items: center; justify-content: center;
    color: var(--color-text-muted); font-size: 1.2rem; line-height: 1;
    transition: background .1s, color .1s;
}
.modal-close:hover { background: var(--color-border); color: var(--color-text); }
.modal-body { padding: 1.25rem 1.4rem; overflow-y: auto; flex: 1; min-height: 0; }
/* Quando un <form> avvolge body+footer, deve propagare la colonna flex: senza questo il
   body non scorre e il footer (Salva) finisce fuori schermo su display piccoli. */
.modal > form { display: flex; flex-direction: column; flex: 1; min-height: 0; overflow: hidden; }
.modal-footer {
    display: flex; align-items: center; justify-content: flex-end; gap: .5rem;
    padding: .9rem 1.4rem; border-top: 1px solid var(--color-border); flex-shrink: 0;
}
html.dark .modal { box-shadow: 0 20px 60px rgba(0,0,0,.55); }

/* ---- Error pages ---- */
.error-page { display: flex; align-items: center; justify-content: center; min-height: 100vh; }
.error-container { text-align: center; padding: 2rem; }
.error-code { font-size: 6rem; font-weight: 800; color: var(--color-text-light); line-height: 1; }
.error-msg  { font-size: 1.1rem; margin: 1rem 0 2rem; color: var(--color-text-muted); }

/* ---- Utilities ---- */
.flex            { display: flex; }
.flex-col        { flex-direction: column; }
.gap-1           { gap: .25rem; }
.gap-2           { gap: .5rem; }
.gap-4           { gap: 1rem; }
.items-center    { align-items: center; }
.justify-between { justify-content: space-between; }
.text-muted      { color: var(--color-text-muted); }
.text-sm         { font-size: .875rem; }
.text-xs         { font-size: .75rem; }
.font-bold       { font-weight: 700; }
.mt-1 { margin-top: .25rem; } .mt-2 { margin-top: .5rem; } .mt-4 { margin-top: 1rem; }
.mb-4 { margin-bottom: 1rem; } .mb-5 { margin-bottom: 1.25rem; } .mb-6 { margin-bottom: 1.5rem; }
.p-4  { padding: 1rem; }
.w-full  { width: 100%; }
.empty-state { text-align: center; color: var(--color-text-muted); padding: 2rem; font-size: .9rem; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0,0,0,0); }

/* ================================================================
   RESPONSIVE
   ================================================================ */
@media (max-width: 768px) {
    /* ── Menu: bottom sheet che sale dal basso (la barra è la nav primaria) ── */
    .sidebar {
        position: fixed;
        left: 0; right: 0; bottom: 0; top: auto;
        width: 100%;
        max-width: 100%;
        height: auto;
        max-height: 85vh; max-height: 85dvh;
        transform: translateY(100%);
        border-radius: 1.25rem 1.25rem 0 0;
        box-shadow: 0 -10px 40px rgba(0,0,0,.32);
        z-index: 200;
        transition: transform .32s cubic-bezier(.22,1,.36,1);
    }
    .sidebar.open { transform: translateY(0); }
    /* Maniglia in cima al foglio */
    .sidebar-header::before {
        content: '';
        position: absolute; top: 8px; left: 50%; transform: translateX(-50%);
        width: 38px; height: 4px; border-radius: 2px;
        background: var(--sidebar-muted); opacity: .5;
    }
    .sidebar.open .sidebar-mobile-profile,
    .sidebar.open .sidebar-nav > *,
    .sidebar.open .sidebar-footer > * { animation: sidebarItemIn .32s ease both; }
    .sidebar.open .sidebar-nav > *:nth-child(1)  { animation-delay: .04s; }
    .sidebar.open .sidebar-nav > *:nth-child(2)  { animation-delay: .08s; }
    .sidebar.open .sidebar-nav > *:nth-child(3)  { animation-delay: .12s; }
    .sidebar.open .sidebar-nav > *:nth-child(4)  { animation-delay: .16s; }
    .sidebar.open .sidebar-nav > *:nth-child(5)  { animation-delay: .20s; }
    .sidebar.open .sidebar-nav > *:nth-child(n+6){ animation-delay: .24s; }

    /* Header: nasconde logo desktop, mostra il profilo grande */
    .sidebar-header { padding: 1.5rem 1.25rem 1.1rem; gap: 0; }
    .sidebar-logo-link, .sidebar-subtitle { display: none; }
    .sidebar-mobile-profile {
        display: flex; align-items: center; gap: .85rem;
        padding-top: .25rem; padding-right: 2.5rem;
    }
    .smp-avatar {
        width: 48px; height: 48px; border-radius: var(--radius-full);
        background: var(--brand-600); color: #fff;
        font-size: 1.25rem; font-weight: 700;
        display: flex; align-items: center; justify-content: center;
        flex-shrink: 0;
    }
    .smp-meta { display: flex; flex-direction: column; min-width: 0; gap: .1rem; }
    .smp-name  { font-size: 1.05rem; font-weight: 600; color: #fff; line-height: 1.2;
                 white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
    .smp-email { font-size: .8rem; color: var(--sidebar-muted);
                 white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
    a.sidebar-mobile-profile { text-decoration: none; }
    .smp-manuals { margin-left: auto; flex-shrink: 0; color: var(--sidebar-muted); }

    /* Nav: voci grandi, spaziate, con chevron a destra */
    .sidebar-nav { padding: 1rem 1rem; gap: .35rem; justify-content: flex-start; }
    .sidebar-link {
        padding: .95rem 1rem;
        font-size: 1.05rem;
        border-radius: var(--radius-lg);
    }
    .sidebar-link .sidebar-link-inner { gap: .85rem; }
    .sidebar-link svg { width: 20px; height: 20px; }
    .sidebar-nav .sidebar-link::after {
        content: '›';
        font-size: 1.4rem; line-height: 1;
        color: var(--sidebar-muted);
        opacity: .55;
        margin-left: auto;
    }
    .sidebar-nav .sidebar-link:hover::after,
    .sidebar-nav .sidebar-link.active::after { color: #fff; opacity: .9; }
    .sidebar-section-label { font-size: .72rem; margin-top: 1.4rem; padding: 0 1rem; }

    /* Footer: profilo già in alto → tema + logout affiancati */
    .sidebar-footer { padding: 1rem 1.25rem max(1rem, env(safe-area-inset-bottom)); }
    .sidebar-footer-sep { margin-left: -1.25rem; margin-right: -1.25rem; }
    .sidebar-user { display: none; }
    .sidebar-footer form { width: auto !important; flex: 1; }
    .sidebar-footer .sidebar-action {
        font-size: .9rem; padding: .8rem 1rem;
        border-radius: var(--radius-lg);
        justify-content: center;
    }
    .sidebar-footer #themeToggle { flex: 1; }
    .sidebar-footer-row {
        display: flex; gap: .6rem; align-items: stretch;
    }
    .sidebar-close { display: flex; top: 1rem; right: 1rem; padding: .5rem; }
    .sidebar-close svg { width: 20px; height: 20px; }
    /* L'hamburger sparisce: la navigazione vive nella barra in basso */
    .mobile-hamburger { display: none; }
    /* Lo scrim del menu copre header (50) e barra inferiore (90), sotto il foglio (200) */
    .sidebar-backdrop { z-index: 150; animation: modalFadeIn .2s ease; }

    /* ── App header ── */
    /* Glassmorphism: header full-bleed e trasparente che lascia intravedere
       il contenuto sfocato sotto, così non sembra una fascia piena. */
    .app-header {
        top: 0;
        left: 0;
        right: 0;
        border-radius: 0;
        padding-left: .75rem;
        padding-right: .75rem;
        background: color-mix(in srgb, var(--color-bg) 55%, transparent);
        -webkit-backdrop-filter: blur(22px) saturate(180%);
        backdrop-filter: blur(22px) saturate(180%);
    }
    /* Su mobile la fascia è vetro sfocato: la sfumatura del desktop non serve */
    .app-header::before { display: none; }
    /* Su mobile l'header resta a tutta larghezza (niente cap/centratura desktop);
       padding verticale .375rem → header ~56px (var(--header-height)), come prima. */
    .app-header-inner { max-width: none; padding: .375rem .75rem; }
    /* Sfuma il bordo inferiore: dissolvenza morbida invece di un taglio netto */
    .app-header::after {
        content: '';
        position: absolute; left: 0; right: 0; bottom: -14px; height: 14px;
        background: linear-gradient(to bottom, color-mix(in srgb, var(--color-bg) 35%, transparent), transparent);
        pointer-events: none;
    }
    /* l'header non è più staccato dall'alto: niente extra-gap */
    .app-main { padding-top: var(--header-height); }
    /* header a tutta larghezza (top:0): niente varchi, la maschera non serve */
    .app-main::before { display: none; }
    .header-date { display: none; }
    /* Nome pagina + tasto indietro a sinistra nell'header */
    .app-header-title { display: block; }
    .app-header-back { display: flex; }
    .app-header.search-open .app-header-title,
    .app-header.search-open .app-header-back { display: none; }

    /* ── Ricerca a scomparsa, con apertura animata ── */
    .header-search-toggle { display: flex; transition: transform .2s ease, color .15s; }
    .app-header.search-open .header-search-toggle { color: var(--color-primary); }
    /* Resta nel DOM (niente display:none) così può animarsi: si svela da destra */
    .header-search {
        position: absolute;
        top: 50%; left: .6rem; right: 3.1rem;
        transform: translateY(-50%);
        max-width: none;
        z-index: 6;
        clip-path: inset(0 0 0 100% round 9px);
        opacity: 0;
        pointer-events: none;
        box-shadow: 0 6px 18px rgba(0,0,0,.14);
        transition: clip-path .32s cubic-bezier(.22,1,.36,1), opacity .22s ease;
    }
    .app-header.search-open .header-search {
        clip-path: inset(0 0 0 0 round 9px);
        opacity: 1;
        pointer-events: auto;
    }
    /* In modalità ricerca lascia spazio: via hamburger e campanella */
    .app-header.search-open .mobile-hamburger,
    .app-header.search-open #bell-btn { display: none; }
    /* Su mobile la X interna al campo è ridondante: per cancellare/chiudere c'è la X esterna
       (il toggle). Nascondiamo quella interna. */
    .header-search-clear { display: none !important; }

    /* ── Notifications ── */
    .notif-dropdown { width: calc(100vw - 2rem); left: 1rem !important; right: auto !important; }
    .chatbot-panel { width: calc(100vw - 2rem); right: -1rem; }
    .notification-drawer { width: 100vw; }

    /* ── Stats ── */
    .stats-grid { grid-template-columns: repeat(2, 1fr); }

    /* ── Charts ── */
    .charts-row { grid-template-columns: 1fr; }

    /* ── Kanban ── */
    .kanban-board { padding-bottom: 1.5rem; }

    /* ── Forms ── */
    .modal { margin: .5rem; max-height: calc(100vh - 1rem); }

    /* ── Tables ── */
    .table-responsive { border-radius: var(--radius-md); }

    /* ── Container ── */
    .container { padding: 0 .875rem; }
    .main-content { padding-top: .75rem; padding-bottom: 1rem; }

    /* ── Target di tocco più generosi ── */
    .btn   { min-height: 40px; }
    .btn-sm{ min-height: 36px; }
    .btn-xs{ min-height: 32px; padding: .35rem .6rem; }
}

@media (max-width: 480px) {
    .stats-grid { grid-template-columns: 1fr 1fr; }
    .login-card { padding: 1.5rem 1rem; }
    .container  { padding: 0 .75rem; }
    .btn { font-size: .8rem; padding: .4rem .75rem; min-height: 40px; }
    .btn-sm { padding: .28rem .55rem; font-size: .75rem; min-height: 36px; }
}

/* ── Barra di navigazione inferiore (solo mobile) ──────────────────
   Il markup sta FUORI da .app-layout (figlia diretta di <body>): dentro
   .app-main, che e' il contenitore che scorre, su iPhone il `fixed` si
   aggancia al contenuto e la barra sparisce in fondo alla pagina. */
.mnav { display: none; }
@media (max-width: 768px) {
    .mnav {
        display: flex; align-items: flex-end; justify-content: space-around;
        position: fixed; left: 0; right: 0; bottom: 0;
        z-index: 90;
        height: calc(58px + env(safe-area-inset-bottom, 0px));
        padding: 0 .25rem env(safe-area-inset-bottom, 0px);
        background: color-mix(in srgb, var(--color-bg) 85%, transparent);
        -webkit-backdrop-filter: blur(20px) saturate(180%);
        backdrop-filter: blur(20px) saturate(180%);
        border-top: 1px solid var(--color-border);
        overflow: visible;
    }
    .mnav-item {
        flex: 1; min-width: 0;
        display: flex; flex-direction: column; align-items: center; justify-content: center;
        gap: 2px; height: 58px;
        border: none; background: none; cursor: pointer; font-family: inherit;
        color: var(--color-text-muted); text-decoration: none;
        font-size: .7rem; font-weight: 600;
        transition: color .15s;
    }
    .mnav-item svg { width: 22px; height: 22px; }
    .mnav-item span { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
    .mnav-item.active { color: var(--color-primary); }
    .mnav-item:active { opacity: .7; }

    /* Voce centrale "Nuovo" in risalto (FAB integrato nella barra) */
    .mnav-fab { color: var(--color-primary); }
    .mnav-fab-circle {
        display: flex; align-items: center; justify-content: center;
        width: 50px; height: 50px; border-radius: 50%;
        margin-top: -22px; margin-bottom: 1px;
        background: var(--color-primary); color: #fff;
        box-shadow: 0 5px 16px color-mix(in srgb, var(--color-primary) 45%, transparent);
        border: 3px solid var(--color-bg);
    }
    .mnav-fab .mnav-fab-circle svg { width: 24px; height: 24px; }
    .mnav-fab:active .mnav-fab-circle { transform: scale(.93); }

    /* Spazio per la barra inferiore fissa (.mnav).
       NON si può ottenere con padding-bottom su .app-main: quest'ultimo è il
       contenitore di scroll (flex column + overflow-y:auto) e Chrome/Safari
       ignorano il padding-bottom di un flex-scroller nell'area scrollabile,
       quindi l'ultima card finiva sotto la barra.
       Soluzione robusta e indipendente dal bug: RESTRINGO l'area di scroll
       togliendo spazio dal genitore .app-layout (height:100dvh, overflow:hidden,
       NON è uno scroller) → .app-main (flex:1) termina sopra la barra. */
    body:not(.page-ticket-show) .app-layout {
        padding-bottom: calc(58px + env(safe-area-inset-bottom, 0px));
    }
    /* Sul dettaglio ticket c'è già la barra di risposta: niente barra nav */
    body.page-ticket-show .mnav { display: none; }

    /* Voci di menu che su mobile sarebbero doppioni della barra inferiore
       (oggi: "Nuovo ticket", che in barra è il FAB centrale). Sul dettaglio
       ticket la barra non c'è (c'è la reply-bar), quindi lì la voce resta:
       altrimenti da quella pagina non si potrebbe più aprire un ticket. */
    body:not(.page-ticket-show) .sidebar-no-mobile { display: none !important; }
}

/* ── Tabella ticket ───────────────────────────────────────────
   Condivisa fra l'elenco ticket (views/tickets/index.php) e la bacheca del
   televisore (views/tv/board.php): stessa grafica in entrambi i posti, un solo
   punto da toccare. Le parti interattive (ordinamento colonne, kanban) restano
   nella pagina elenco. */
.table-responsive{overflow-x:auto;border:1px solid var(--color-border);border-radius:var(--radius-lg);background:var(--color-surface)}
.ticket-table{width:100%;border-collapse:collapse;font-size:.875rem}
.ticket-table thead tr{border-bottom:1px solid var(--color-border)}
.ticket-table th{padding:.6rem 1rem;font-size:.75rem;font-weight:600;text-transform:uppercase;letter-spacing:.04em;color:var(--color-text-muted);white-space:nowrap;text-align:left}
.ticket-table td{padding:.7rem 1rem;border-bottom:1px solid var(--color-border);vertical-align:middle}
.ticket-table tbody tr:last-child td{border-bottom:none}
.ticket-tr{cursor:pointer;transition:background .12s}
.ticket-tr:hover td{background:color-mix(in srgb,var(--color-primary) 4%,transparent)}
.ticket-tr.is-blocking{border-left:3px solid #ef4444}
.ticket-tr.is-blocking td:first-child{padding-left:.75rem}
.ticket-tr.sla-breached td{background:rgba(245,158,11,.05)}
.ticket-code{font-family:monospace;font-weight:700;font-size:.9rem;letter-spacing:.03em;color:var(--color-primary)}
.ticket-code-cell{white-space:nowrap}
.nowrap{white-space:nowrap}
.ml-1{margin-left:.3rem}
.sla-warning{color:#f59e0b;font-size:.85rem;margin-left:.25rem}
.interdept-badge{background:#e0f2fe;color:#0369a1;padding:.1rem .35rem;border-radius:var(--radius-sm);font-size:.72rem;font-weight:500}
html.dark .interdept-badge{background:#0c4a6e;color:#7dd3fc}

/* ── Admin setting cards ─────────────────────────────────────── */
/* ── Intestazione pagina admin riutilizzabile (back tondo + icona + titolo + azioni) ── */
.adm-phead{display:flex;align-items:center;justify-content:space-between;gap:1rem;flex-wrap:wrap;margin-bottom:2rem}
.adm-phead-left{display:flex;align-items:center;gap:.85rem;min-width:0}
.adm-phead-right{display:flex;align-items:center;gap:.75rem;flex-shrink:0}
.adm-phead-back{display:flex;align-items:center;justify-content:center;width:32px;height:32px;border-radius:var(--radius-md);border:1px solid var(--color-border);background:var(--color-surface);color:var(--color-text-muted);text-decoration:none;flex-shrink:0;transition:border-color .15s,color .15s}
.adm-phead-back:hover{border-color:var(--color-primary);color:var(--color-primary)}
.adm-phead-back svg{width:15px;height:15px}
.adm-phead-icon{width:44px;height:44px;border-radius:var(--radius-lg);flex-shrink:0;background:linear-gradient(135deg,var(--color-primary),color-mix(in srgb,var(--color-primary) 70%,#000));display:flex;align-items:center;justify-content:center;box-shadow:0 2px 10px color-mix(in srgb,var(--color-primary) 30%,transparent)}
.adm-phead-icon svg{width:22px;height:22px;stroke:#fff}
.adm-phead-title{font-size:1.35rem;font-weight:800;letter-spacing:-.02em;line-height:1.2}
.adm-phead-sub{font-size:.8rem;color:var(--color-text-muted);margin-top:.15rem}
.adm-phead-pill{display:inline-flex;align-items:center;gap:.35rem;padding:.3rem .7rem;border-radius:var(--radius-full);background:var(--color-bg);border:1px solid var(--color-border);font-size:.78rem;font-weight:600;color:var(--color-text-muted)}
.adm-phead-pill svg{width:12px;height:12px}
/* Su mobile il titolo è nell'header globale: via il gruppo sinistro;
   se non ci sono azioni a destra si nasconde tutta l'intestazione. */
@media(max-width:768px){
    .adm-phead-left{display:none}
    .adm-phead:not(:has(.adm-phead-right)){display:none}
}

.admin-config-section{max-width:800px;margin:2rem auto 0}
.admin-section-header{display:flex;align-items:center;gap:.75rem;margin-bottom:1rem}
.admin-section-label{font-size:.7rem;font-weight:700;text-transform:uppercase;letter-spacing:.12em;color:var(--color-text-muted);white-space:nowrap;margin:0}
.admin-section-line{flex:1;height:1px;background:var(--color-border)}
.admin-config-grid{display:grid;grid-template-columns:repeat(auto-fill,minmax(260px,1fr));gap:1rem}
.setting-card{display:flex;flex-direction:column;gap:.75rem;background:var(--color-surface);border-radius:var(--radius-lg);border:1px solid var(--color-border);padding:1.25rem;text-decoration:none;color:var(--color-text);transition:border-color .15s,box-shadow .15s}
.setting-card:hover{border-color:var(--color-primary);box-shadow:var(--shadow-md)}
.setting-card:hover .setting-card-title{color:var(--color-primary)}
.setting-card-top{display:flex;align-items:flex-start;justify-content:space-between}
.setting-card-icon{width:2.5rem;height:2.5rem;border-radius:.75rem;background:color-mix(in srgb,var(--color-primary) 10%,transparent);display:flex;align-items:center;justify-content:center;flex-shrink:0;color:var(--color-primary)}
.setting-card-arrow{color:var(--color-border)}
.setting-card-title{font-size:.875rem;font-weight:600;margin:0}
.setting-card-desc{font-size:.75rem;color:var(--color-text-muted);margin:.2rem 0 0}
.setting-card-tags{display:flex;flex-wrap:wrap;gap:.375rem;margin-top:auto}
.setting-tag{font-size:.688rem;font-weight:500;color:var(--color-text-muted);background:var(--color-bg);padding:.125rem .5rem;border-radius:9999px}
.setting-card-warn{border-color:var(--color-danger)}
.setting-card-warn:hover{border-color:var(--color-danger)}
.setting-card-icon-warn{background:color-mix(in srgb,var(--color-danger) 10%,transparent);color:var(--color-danger)}

/* ── Operator avatar chips ───────────────────────────────────── */
.op-chips{display:flex;align-items:center;gap:3px;flex-wrap:wrap}
.op-chip{display:inline-flex;align-items:center;justify-content:center;width:26px;height:26px;border-radius:50%;color:#fff;font-size:.65rem;font-weight:700;flex-shrink:0;cursor:default;letter-spacing:.02em}

/* ── Modern filter bar (fbar) ───────────────────────────────────────── */
.fbar{display:flex;flex-wrap:wrap;gap:.5rem;align-items:center;margin-bottom:2rem}
.fbar-group{position:relative}
.fbar-btn{
    display:inline-flex;align-items:center;gap:.45rem;
    padding:.5rem .9rem;
    border:1px solid var(--color-border);border-radius:var(--radius-md);
    background:var(--color-surface);color:var(--color-text);
    font-size:.82rem;font-weight:600;cursor:pointer;white-space:nowrap;line-height:1.3;
    box-shadow:0 1px 2px rgba(0,0,0,.04);
    transition:border-color .15s,background .15s,box-shadow .15s,color .15s;
}
.fbar-btn svg.fbar-chevron{width:12px;height:12px;opacity:.5;flex-shrink:0;transition:transform .18s,opacity .18s}
.fbar-btn.fbar-open svg.fbar-chevron{transform:rotate(180deg);opacity:.9}
.fbar-btn:hover{border-color:var(--color-primary);box-shadow:0 2px 10px rgba(0,0,0,.08)}
.fbar-btn.fbar-open{border-color:var(--color-primary)}
.fbar-btn.fbar-active{border-color:var(--color-primary);background:color-mix(in srgb,var(--color-primary) 10%,transparent);color:var(--color-primary)}
html.dark .fbar-btn{background:#1e2d3d;border-color:#334155}
.fbar-badge{display:inline-flex;align-items:center;justify-content:center;min-width:18px;height:18px;padding:0 5px;border-radius:999px;background:var(--color-primary);color:#fff;font-size:.66rem;font-weight:700}
.fbar-lbl-val{max-width:120px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;font-size:.8rem;font-weight:700}
.fbar-panel{
    position:absolute;top:calc(100% + .5rem);left:0;min-width:212px;
    background:var(--color-surface);border:1px solid var(--color-border);
    border-radius:var(--radius-lg);box-shadow:0 12px 32px rgba(0,0,0,.16);
    padding:.4rem;z-index:300;max-height:300px;overflow-y:auto;
    animation:fbarPop .15s ease-out;
}
@keyframes fbarPop{from{opacity:0;transform:translateY(-6px)}to{opacity:1;transform:translateY(0)}}
.fbar-panel-right{left:auto;right:0}
html.dark .fbar-panel{background:#1e2d3d;border-color:#334155}
/* Pannello largo (percorsi categoria lunghi) */
.fbar-panel-wide{min-width:300px;max-width:380px}
/* Campo di ricerca in cima al pannello (resta visibile durante lo scroll) */
.fbar-search{
    position:sticky;top:0;z-index:1;
    width:100%;margin-bottom:.3rem;
    padding:.45rem .6rem !important;
    border:1.5px solid var(--color-border) !important;
    border-radius:var(--radius-md) !important;
    background:var(--color-surface) !important;
    font-size:.85rem !important;box-shadow:none !important;
}
html.dark .fbar-search{background:#1e2d3d !important}
.fbar-opt{display:flex;align-items:center;gap:.55rem;padding:.45rem .6rem;border-radius:var(--radius-md);cursor:pointer;font-size:.85rem;color:var(--color-text);user-select:none;transition:background .12s,color .12s}
.fbar-opt[hidden]{display:none}
.fbar-opt:hover{background:color-mix(in srgb,var(--color-primary) 9%,transparent);color:var(--color-primary)}
.fbar-opt.fbar-sel{background:color-mix(in srgb,var(--color-primary) 12%,transparent);color:var(--color-primary);font-weight:700}
.fbar-opt input{width:15px;height:15px;accent-color:var(--color-primary);cursor:pointer;flex-shrink:0;margin:0}
.fbar-dates{padding:.55rem .65rem;display:flex;flex-direction:column;gap:.6rem;min-width:232px}
.fbar-dates-row{display:flex;flex-direction:column;gap:.3rem}
.fbar-dates label{font-size:.7rem;font-weight:700;color:var(--color-text-muted);text-transform:uppercase;letter-spacing:.05em}
.fbar-dates input[type="number"]{padding:.5rem .7rem;border:1.5px solid var(--color-border);border-radius:var(--radius-md);background:var(--color-surface);color:var(--color-text);font-size:.85rem;width:100%}
.fbar-reset{background:transparent;border:1px solid var(--color-border);color:var(--color-text-muted);font-size:.8rem;padding:.5rem .85rem;border-radius:var(--radius-md);cursor:pointer;font-weight:600;transition:border-color .15s,color .15s,background .15s}
.fbar-reset:hover{border-color:var(--color-danger);color:var(--color-danger);background:color-mix(in srgb,var(--color-danger) 8%,transparent)}

/* ── Mobile: i pannelli filtro (incl. il calendario) diventano bottom sheet a
   tutta larghezza, così non finiscono mai fuori dallo schermo ── */
@media (max-width: 768px) {
    .fbar-panel,
    .fbar-panel-right {
        position: fixed;
        left: 0; right: 0; bottom: 0; top: auto;
        width: 100%; min-width: 0; max-width: 100%;
        max-height: 78vh; overflow-y: auto;
        border-radius: 1.25rem 1.25rem 0 0;
        padding: .9rem .9rem max(1rem, env(safe-area-inset-bottom, 1rem));
        box-shadow: 0 -10px 40px rgba(0,0,0,.28);
        animation: fbarSheetUp .26s cubic-bezier(.22,1,.36,1);
    }
    .fbar-dates { min-width: 0; }
    .dp-inline { width: 100%; }   /* il calendario riempie la larghezza del foglio */
}
@keyframes fbarSheetUp { from { transform: translateY(100%); } to { transform: translateY(0); } }

/* ── Mobile: titolo e back sono nell'header globale → niente doppioni in pagina ──
   !important perché le pagine definiscono queste classi nel proprio <style> inline,
   che viene caricato DOPO app.css e altrimenti vincerebbe per ordine di sorgente. */
@media (max-width: 768px) {
    /* Page-header standard (utenti, categorie, periodici…): se non ha un'azione
       (btn-primary) si toglie tutto, altrimenti si toglie solo il titolo. */
    .page-header:not(:has(.btn-primary)) { display: none !important; }
    .page-header h2 { display: none !important; }

    /* Form builder: via titolo e back (restano i pulsanti Salva/Aggiungi e le tab sede). */
    .fb-page-title,
    .fb-page-header .dd-back { display: none !important; }

    /* Link "indietro" testuali generici. */
    .back-link { display: none !important; }
}

/* ── Custom colour picker (CPW) ─────────────────────────────────────────── */
.cpw{position:relative;display:inline-flex;align-items:center;flex-shrink:0}
.cpw-swatch{width:34px;height:34px;border-radius:var(--radius-md);border:2px solid var(--color-border);cursor:pointer;flex-shrink:0;transition:border-color .15s,transform .1s}
.cpw-swatch:hover{border-color:var(--color-primary);transform:scale(1.08)}
.cpw-drop{display:none;position:fixed;z-index:9999;background:var(--color-surface);border:1px solid var(--color-border);border-radius:var(--radius-lg);box-shadow:var(--shadow-lg);padding:.75rem;flex-direction:column;gap:.625rem;width:196px}
.cpw-drop.open{display:flex}
.cpw-palette{display:grid;grid-template-columns:repeat(5,1fr);gap:6px}
.cpw-chip{width:100%;aspect-ratio:1;border-radius:6px;border:2px solid transparent;cursor:pointer;transition:transform .1s,border-color .1s}
.cpw-chip:hover{transform:scale(1.15);border-color:rgba(0,0,0,.25)}
.cpw-chip-active{border-color:var(--color-primary) !important;transform:scale(1.12)}
.cpw-hex-row{display:flex;align-items:center;gap:0;border:1px solid var(--color-border);border-radius:var(--radius-md);overflow:hidden}
.cpw-hex-hash{padding:0 .4rem;font-family:monospace;font-size:.875rem;color:var(--color-text-muted);background:var(--color-bg);line-height:34px}
.cpw-hex{flex:1;font-family:monospace;font-size:.875rem;padding:.4rem .5rem;border:none;outline:none;background:var(--color-surface);color:var(--color-text)}

/* ── Drag-to-sort ────────────────────────────────────────────────────────── */
.drag-handle{cursor:grab;padding:0 .45rem 0 0;color:var(--color-text-muted);display:inline-flex;align-items:center;flex-shrink:0;opacity:.55;transition:opacity .15s}
.drag-handle:hover{opacity:1}
.drag-handle:active{cursor:grabbing}
[draggable=true].drag-ghost{opacity:.3}
.drag-over{outline:2px dashed var(--color-primary);outline-offset:-2px;border-radius:var(--radius-md)}

/* ============================================================
   Custom date picker (global) — enhances every <input type="date">
   ============================================================ */
.dp { position:relative; }
.dp-trigger {
    display:flex; align-items:center; gap:.6rem; width:100%;
    padding:.6rem .9rem; border:1.5px solid var(--color-border);
    border-radius:var(--radius-md); background:var(--color-surface);
    color:var(--color-text); font-family:inherit; font-size:.875rem; font-weight:600;
    cursor:pointer; text-align:left; transition:border-color .18s, box-shadow .18s;
}
.dp-trigger:hover { border-color:#c9d1d9; }
.dp.dp-open .dp-trigger { border-color:var(--brand-600); box-shadow:0 0 0 3.5px rgba(246,141,41,.18); }
.dp-ico { display:inline-flex; color:var(--color-text-muted); flex-shrink:0; }
.dp-ico svg { width:17px; height:17px; }
.dp-text { flex:1; min-width:0; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
.dp.is-empty .dp-text { color:var(--color-text-light); font-weight:500; }
.dp-clear {
    display:inline-flex; align-items:center; justify-content:center;
    width:20px; height:20px; border-radius:50%; flex-shrink:0;
    color:var(--color-text-muted); background:var(--color-bg);
}
.dp-clear svg { width:12px; height:12px; }
.dp-clear:hover { color:var(--color-danger); background:color-mix(in srgb,var(--color-danger) 12%,transparent); }
.dp.is-empty .dp-clear { display:none; }
html.dark .dp-trigger { border-color:#334155; color:#f1f5f9; }
html.dark .dp.dp-open .dp-trigger { background:#1e2d3d; }

.dp-pop {
    position:fixed; z-index:1200; width:268px;
    background:var(--color-surface); border:1px solid var(--color-border);
    border-radius:var(--radius-lg); box-shadow:0 12px 32px rgba(0,0,0,.16);
    padding:.65rem; user-select:none;
}
html.dark .dp-pop { background:#1e2d3d; border-color:#334155; }
.dp-head { display:flex; align-items:center; justify-content:space-between; margin-bottom:.5rem; }
.dp-title { font-size:.86rem; font-weight:700; color:var(--color-text); text-transform:capitalize; }
.dp-nav {
    width:30px; height:30px; display:inline-flex; align-items:center; justify-content:center;
    border:1px solid var(--color-border); border-radius:var(--radius-md);
    background:var(--color-surface); color:var(--color-text-muted);
    font-size:1.1rem; line-height:1; cursor:pointer; transition:all .12s;
}
.dp-nav:hover { border-color:var(--color-primary); color:var(--color-primary); }
html.dark .dp-nav { border-color:#334155; background:transparent; }
.dp-dow { display:grid; grid-template-columns:repeat(7,1fr); gap:.15rem; margin-bottom:.2rem; }
.dp-dow span { text-align:center; font-size:.68rem; font-weight:700; color:var(--color-text-light); text-transform:uppercase; padding:.2rem 0; }
.dp-grid { display:grid; grid-template-columns:repeat(7,1fr); gap:.15rem; }
.dp-cell {
    aspect-ratio:1/1; display:inline-flex; align-items:center; justify-content:center;
    border:1px solid transparent; border-radius:var(--radius-md);
    background:transparent; color:var(--color-text);
    font-size:.8rem; font-weight:600; cursor:pointer; font-family:inherit; transition:all .1s;
}
.dp-cell:hover { background:color-mix(in srgb,var(--color-primary) 12%,transparent); color:var(--color-primary); }
.dp-cell.today { border-color:var(--color-primary); color:var(--color-primary); }
.dp-cell.selected { background:var(--color-primary); border-color:var(--color-primary); color:#fff; box-shadow:0 2px 6px color-mix(in srgb,var(--color-primary) 35%,transparent); }
.dp-cell[disabled] { color:var(--color-text-light); cursor:not-allowed; opacity:.4; }
.dp-cell[disabled]:hover { background:transparent; color:var(--color-text-light); }
.dp-empty-cell { cursor:default; }
.dp-foot { display:flex; justify-content:space-between; gap:.5rem; margin-top:.5rem; padding-top:.5rem; border-top:1px solid var(--color-border); }
html.dark .dp-foot { border-top-color:#334155; }
.dp-link { background:none; border:none; cursor:pointer; font-family:inherit; font-size:.78rem; font-weight:600; color:var(--color-primary); padding:.2rem .35rem; border-radius:var(--radius-sm); }
.dp-link:hover { background:color-mix(in srgb,var(--color-primary) 12%,transparent); }

/* Inline range calendar (e.g. dashboard "Periodo" filter — pick start+end on one calendar) */
.dp-inline { width:250px; user-select:none; }
.dp-cell.in-range { background:color-mix(in srgb,var(--color-primary) 15%,transparent); color:var(--color-primary); border-radius:4px; }
.dp-cell.range-end { background:var(--color-primary); border-color:var(--color-primary); color:#fff; box-shadow:0 2px 6px color-mix(in srgb,var(--color-primary) 35%,transparent); }
.dp-range-hint { font-size:.72rem; color:var(--color-text-muted); text-align:center; padding:.35rem 0 .1rem; min-height:1rem; }

/* ── Time picker (enhancement di input[type=time]) ── */
.tp { display:inline-block; width:auto; vertical-align:middle; }
.tp .dp-trigger { min-width:120px; }
.tp-pop { width:auto; min-width:140px; padding:.4rem; }
.tp-cols { display:flex; gap:.3rem; }
.tp-col { display:flex; flex-direction:column; gap:.12rem; max-height:212px; overflow-y:auto; padding-right:.15rem; }
.tp-col::-webkit-scrollbar { width:7px; }
.tp-col::-webkit-scrollbar-thumb { background:color-mix(in srgb,var(--color-text-muted) 35%,transparent); border-radius:4px; }
.tp-opt { background:none; border:none; cursor:pointer; font-family:inherit; font-size:.84rem; font-weight:600; padding:.32rem .85rem; border-radius:var(--radius-sm); color:var(--color-text); text-align:center; }
.tp-opt:hover { background:color-mix(in srgb,var(--color-primary) 12%,transparent); color:var(--color-primary); }
.tp-opt.selected { background:var(--color-primary); color:#fff; box-shadow:0 2px 6px color-mix(in srgb,var(--color-primary) 35%,transparent); }

/* ── Impostazioni dipartimento: griglia su desktop (sfrutta lo spazio laterale) ── */


/* ══════════════════════════════════════════════════════════════════════════
   Select "custom" ricercabile (.csel*): avvolge una <select> nativa, che resta la
   sorgente dati, e mostra una tendina con ricerca e descrizione accanto al nome.
   Nata nell'apertura ticket (categoria/priorita'), condivisa dal 2026-08-03 con il
   calendario pulizie: e' il motivo per cui sta qui e non nella singola vista.
   ══════════════════════════════════════════════════════════════════════════ */
.csel { position:relative; }
.csel-native { display:none !important; }
.csel-btn {
    width:100%; display:flex; align-items:baseline; gap:.5rem;
    text-align:left; cursor:pointer;
    padding:.65rem .9rem;
    border:1.5px solid var(--color-border); border-radius:var(--radius-md);
    font-size:.875rem; font-family:inherit; color:var(--color-text);
    background-color:var(--color-surface);
    transition:border-color .18s, box-shadow .18s;
}
.csel-btn:hover { border-color:color-mix(in srgb, var(--brand-600) 45%, var(--color-border)); }
.csel.is-open .csel-btn, .csel-btn:focus {
    border-color:var(--brand-600); box-shadow:0 0 0 3.5px rgba(246,141,41,.18); outline:none;
}
.csel.is-error .csel-btn { border-color:var(--color-danger); }
/* Campi obbligatori che il browser non sa controllare da se' (data, scelte
   multiple): il controllo e' in app.js, qui c'e' solo come si vedono. */
.dp.is-error .dp-trigger { border-color: var(--color-danger); }
.ms.is-error .ms-control { border-color: var(--color-danger); }
input.is-error, select.is-error, textarea.is-error { border-color: var(--color-danger); }
.cf-radio-group.is-error {
    border: 1px solid var(--color-danger);
    border-radius: var(--radius-md);
    padding: .4rem .6rem;
    margin: -.4rem -.6rem;
}
.csel.is-disabled .csel-btn { opacity:.55; cursor:not-allowed; }
.csel-cur { flex:1 1 auto; min-width:0; display:flex; align-items:baseline; gap:.5rem; flex-wrap:wrap; }
.csel-cur-name { color:var(--color-text); }
.csel-cur-name.is-placeholder { color:var(--color-text-light); }
.csel-cur-desc { font-size:.78rem; color:var(--color-text-muted); font-style:italic; }
.csel-caret {
    flex:0 0 auto; margin-left:auto; width:9px; height:9px; align-self:center;
    border-right:2px solid var(--color-text-muted); border-bottom:2px solid var(--color-text-muted);
    transform:rotate(45deg) translateY(-2px); transition:transform .18s;
}
.csel.is-open .csel-caret { transform:rotate(-135deg) translateY(2px); }
/* Dentro una modale il pannello va fixed (vedi .csel-fixed): altrimenti l'overflow del
   contenitore lo ritaglia e la tendina sembra "chiusa dentro" il riquadro. */
.csel.csel-fixed .csel-panel { position:fixed; right:auto; z-index:1100; }
.csel-panel {
    position:absolute; z-index:60; left:0; right:0; top:calc(100% + 4px);
    max-height:320px; overflow-y:auto;
    background:var(--color-surface); border:1.5px solid var(--color-border);
    border-radius:var(--radius-md); box-shadow:0 12px 32px rgba(0,0,0,.14); padding:.3rem;
}
.csel-opt { padding:.5rem .6rem; border-radius:6px; cursor:pointer; line-height:1.35; }
.csel-opt:hover, .csel-opt.is-active { background:var(--color-bg); }
.csel-opt[aria-selected="true"] { background:color-mix(in srgb, var(--brand-600) 12%, transparent); }
.csel-opt-name { color:var(--color-text); font-size:.9rem; }
.csel-opt-desc { display:block; font-size:.78rem; color:var(--color-text-muted); font-style:italic; margin-top:.1rem; }
.csel-empty { padding:.6rem; font-size:.82rem; color:var(--color-text-muted); text-align:center; }
/* Combobox: la select stessa è il campo di ricerca */
.csel-combo { position:relative; display:flex; align-items:center; }
.csel-input {
    width:100%; box-sizing:border-box; padding:.65rem 2.1rem .65rem .9rem;
    border:1.5px solid var(--color-border); border-radius:var(--radius-md);
    font-size:.875rem; font-family:inherit; color:var(--color-text);
    background-color:var(--color-surface); cursor:text;
    transition:border-color .18s, box-shadow .18s;
}
.csel-input::placeholder { color:var(--color-text-light); }
.csel-input:hover { border-color:color-mix(in srgb, var(--brand-600) 45%, var(--color-border)); }
.csel.is-open .csel-input, .csel-input:focus { border-color:var(--brand-600); box-shadow:0 0 0 3.5px rgba(246,141,41,.18); outline:none; }
.csel-combo .csel-caret { position:absolute; right:.8rem; margin:0; cursor:pointer; }
/* ── Selettore di lingua nel footer della sidebar ──────────────────────────
   1:1 col portale (.sb-lang in intranet/includes/sidebar.php): stesse misure,
   stesso font, stessa bandiera. Passando da un'app all'altra non si deve vedere
   nessuna differenza — chi le usa deve pensare che la sidebar sia la stessa.
   Valori copiati da la': gap .25rem, padding .3rem .4rem, 11px/1.2 peso 600,
   bandiera 18x12, inattivo bianco 55% su bianco 5%. */
.tk-lang { display: flex; gap: .25rem; }
.tk-lang-btn {
    flex: 1 1 0; min-width: 0;
    display: flex; align-items: center; justify-content: center; gap: .4rem;
    padding: .3rem .4rem; border-radius: 8px;
    border: none; cursor: pointer;
    /* font-family: i <button> non ereditano il font (uscirebbero in Arial). */
    font-family: inherit;
    font-size: 11px; font-weight: 600; line-height: 1.2;
    color: rgba(255,255,255,0.55); background: rgba(255,255,255,0.05);
    transition: background .15s, color .15s;
}
.tk-lang-btn:hover { background: rgba(255,255,255,0.12); color: #fff; }
.tk-lang-btn.is-active { background: #f68d29; color: #fff; }
.tk-lang-btn .sidebar-action-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tk-lang-flag {
    width: 18px; height: 12px; border-radius: 2px; flex-shrink: 0;
    box-shadow: 0 0 0 1px rgba(0,0,0,0.25);
}

/* ── Multi-select a tendina (elenco di caselle) ───────────────────────────────
   Campo con «selezione multipla» dei moduli di reparto. Stava dentro
   views/tickets/create.php: da qui lo usano anche il modulo dei ticket
   periodici e «Registra intervento» (views/periodic/_campi.php), che prima
   mostravano quegli stessi campi a selezione singola. */
/* Multi-select dropdown (checkbox list) */
.ms { position: relative; }
.ms-control {
    display: flex; align-items: center; justify-content: space-between; gap: .5rem;
    width: 100%; padding: .65rem .9rem; cursor: pointer;
    background: var(--color-surface); border: 1.5px solid var(--color-border);
    border-radius: var(--radius-md); font-size: .875rem; color: var(--color-text);
}
.ms-control:hover { border-color: #c9d1d9; }
.ms-control:focus { outline: none; border-color: var(--brand-600); }
.ms-summary { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ms-summary.ms-empty { color: var(--color-text-muted); }
.ms-chevron { flex-shrink: 0; transition: transform .15s; color: var(--color-text-muted); }
.ms-open .ms-chevron { transform: rotate(180deg); }
.ms-panel {
    position: absolute; z-index: 50; left: 0; right: 0; top: calc(100% + 4px);
    background: var(--color-surface); border: 1.5px solid var(--color-border);
    border-radius: var(--radius-md); box-shadow: var(--shadow-lg);
    max-height: 240px; overflow-y: auto; padding: .25rem;
}
.ms-opt { display: flex; align-items: center; gap: .55rem; padding: .45rem .55rem; border-radius: var(--radius-sm); cursor: pointer; font-size: .875rem; }
.ms-opt:hover { background: var(--color-bg); }
.ms-opt input { width: 16px; height: 16px; flex-shrink: 0; margin: 0; cursor: pointer; }

