﻿/*
 * TexHub - Foglio di stile unico
 *
 * Identita': "sala controllo". Navigazione laterale scura, area di lavoro
 * chiara, angoli piccoli, bordi da 1px invece di ombre, tabelle dense.
 * Un solo tema per tutti: il colore non dipende piu' dal livello dell'utente.
 *
 * I nomi dei token restano quelli Material 3 usati dal resto del foglio:
 * cambiando i valori qui cambia l'aspetto di tutta l'applicazione.
 */

/* ========================================
   Token di progetto
   ======================================== */

:root {
    /* --- marchio --- */
    --accent: #14b8a6;
    --accent-strong: #0d9488;
    --accent-deep: #0f766e;
    --accent-soft: #ccfbf1;
    --accent-rgb: 20, 184, 166;

    /* --- navigazione laterale --- */
    --nav-bg: #0f172a;
    --nav-bg-deep: #0a1120;
    --nav-hover: rgba(148, 163, 184, 0.10);
    --nav-active: rgba(var(--accent-rgb), 0.16);
    --nav-text: #93a3b8;
    --nav-text-strong: #e2e8f0;
    --nav-line: rgba(148, 163, 184, 0.14);
    --nav-w: 252px;
    --nav-w-min: 64px;
    --top-h: 56px;

    /* --- area di lavoro --- */
    --page-bg: #f6f8fa;
    --card-bg: #ffffff;
    --line: #e3e8ef;
    --line-soft: #eef2f6;
    --ink: #0f172a;
    --ink-2: #475569;
    --ink-3: #7a8899;

    /* --- superfici (nomi M3) --- */
    --md-sys-color-surface: #f6f8fa;
    --md-sys-color-surface-dim: #e9eff5;
    --md-sys-color-surface-bright: #ffffff;
    --md-sys-color-surface-container-lowest: #ffffff;
    --md-sys-color-surface-container-low: #ffffff;
    --md-sys-color-surface-container: #f1f5f9;
    --md-sys-color-surface-container-high: #e9eff5;
    --md-sys-color-surface-container-highest: #e3e8ef;
    --md-sys-color-on-surface: #0f172a;
    --md-sys-color-on-surface-variant: #5b6676;

    --md-ref-palette-neutral0: #000000;
    --md-ref-palette-neutral10: #0f172a;
    --md-ref-palette-neutral20: #1e293b;
    --md-ref-palette-neutral30: #334155;
    --md-ref-palette-neutral40: #475569;
    --md-ref-palette-neutral50: #64748b;
    --md-ref-palette-neutral60: #7a8899;
    --md-ref-palette-neutral70: #94a3b8;
    --md-ref-palette-neutral80: #cbd5e1;
    --md-ref-palette-neutral90: #e3e8ef;
    --md-ref-palette-neutral95: #f1f5f9;
    --md-ref-palette-neutral99: #f6f8fa;
    --md-ref-palette-neutral100: #ffffff;

    --md-sys-color-outline: #94a3b8;
    --md-sys-color-outline-variant: #e3e8ef;
    --md-sys-color-shadow: rgba(15, 23, 42, 0.10);
    --md-sys-color-scrim: rgba(15, 23, 42, 0.45);

    /* --- colori d'azione --- */
    --md-sys-color-primary: #0d9488;
    --md-sys-color-primary-rgb: 13, 148, 136;
    --md-sys-color-primary-hover: #0f766e;
    --md-sys-color-on-primary: #ffffff;
    --md-sys-color-primary-container: #ccfbf1;
    --md-sys-color-on-primary-container: #0f766e;
    --md-sys-color-secondary: #0f766e;
    --md-sys-color-on-secondary: #ffffff;
    --md-sys-color-secondary-container: #d8f3ef;
    --md-sys-color-on-secondary-container: #115e59;
    --md-sys-color-tertiary: #0284c7;
    --md-sys-color-on-tertiary: #ffffff;
    --md-sys-color-tertiary-container: #dbeafe;
    --md-sys-color-on-tertiary-container: #075985;

    /* --- stati --- */
    --md-sys-color-success: #157f4a;
    --md-sys-color-success-container: #d6f5e3;
    --md-sys-color-warning: #b45309;
    --md-sys-color-warning-container: #fdf0d5;
    --md-sys-color-error: #b42318;
    --md-sys-color-error-container: #fde8e6;
    --md-sys-color-info: #0369a1;
    --md-sys-color-info-container: #dbeafe;

    /* --- bottoni e avatar (nomi usati dal resto del foglio) --- */
    --btn-primary: #0d9488;
    --btn-primary-hover: #0f766e;
    --btn-on-primary: #ffffff;
    --avatar-bg: #0f172a;
    --avatar-text: #ffffff;
    --sidebar-bg: var(--nav-bg);
    --sidebar-border: var(--nav-line);

    /* --- tipografia --- */
    --font-ui: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
    --font-mono: 'JetBrains Mono', ui-monospace, 'SF Mono', Consolas, monospace;

    --md-sys-typescale-headline-large: 650 1.75rem/2.125rem var(--font-ui);
    --md-sys-typescale-headline-medium: 650 1.5rem/1.875rem var(--font-ui);
    --md-sys-typescale-headline-small: 650 1.25rem/1.625rem var(--font-ui);
    --md-sys-typescale-title-large: 600 1.125rem/1.5rem var(--font-ui);
    --md-sys-typescale-title-medium: 600 0.9375rem/1.375rem var(--font-ui);
    --md-sys-typescale-title-small: 600 0.8125rem/1.25rem var(--font-ui);
    --md-sys-typescale-body-large: 400 0.9375rem/1.5rem var(--font-ui);
    --md-sys-typescale-body-medium: 400 0.875rem/1.375rem var(--font-ui);
    --md-sys-typescale-body-small: 400 0.75rem/1.125rem var(--font-ui);
    --md-sys-typescale-label-large: 550 0.8125rem/1.125rem var(--font-ui);
    --md-sys-typescale-label-medium: 550 0.75rem/1rem var(--font-ui);
    --md-sys-typescale-label-small: 550 0.6875rem/0.9375rem var(--font-ui);

    /* --- forma: angoli piccoli, niente pillole --- */
    --md-sys-shape-corner-none: 0;
    --md-sys-shape-corner-extra-small: 3px;
    --md-sys-shape-corner-small: 4px;
    --md-sys-shape-corner-medium: 6px;
    --md-sys-shape-corner-large: 8px;
    --md-sys-shape-corner-extra-large: 10px;
    /* Volutamente NON 9999px: le pillole appartengono all'aspetto precedente.
       Per i pochi elementi davvero circolari c'e' --shape-pill. */
    --md-sys-shape-corner-full: 6px;
    --shape-pill: 999px;
    --r: 6px;

    /* --- profondita': bordi prima delle ombre --- */
    --md-sys-elevation-level0: none;
    --md-sys-elevation-level1: 0 1px 2px rgba(15, 23, 42, 0.04);
    --md-sys-elevation-level2: 0 1px 3px rgba(15, 23, 42, 0.06);
    --md-sys-elevation-level3: 0 4px 12px rgba(15, 23, 42, 0.08);
    --md-sys-elevation-level4: 0 8px 24px rgba(15, 23, 42, 0.10);
    --md-sys-elevation-level5: 0 16px 40px rgba(15, 23, 42, 0.12);

    /* --- movimento --- */
    --md-sys-motion-duration-short4: 140ms;
    --md-sys-motion-duration-medium2: 220ms;
    --md-sys-motion-easing-standard: cubic-bezier(0.2, 0, 0.2, 1);
    --md-sys-motion-easing-emphasized: cubic-bezier(0.16, 1, 0.3, 1);

    /* --- alias storici --- */
    --primary: var(--btn-primary);
    --bg: var(--page-bg);
    --card: var(--card-bg);
    --muted: var(--ink-3);
    --success: var(--md-sys-color-success);
    --danger: var(--md-sys-color-error);
}

/* ========================================
   Base
   ======================================== */
*, *::before, *::after { box-sizing: border-box; }

html {
    font-family: var(--font-ui);
    font-size: 16px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    margin: 0;
    background: var(--page-bg);
    color: var(--ink);
    line-height: 1.5;
}

a { color: var(--accent-deep); text-decoration: none; }
a:hover { color: var(--accent-strong); }

:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

/* Barre di scorrimento sottili: in una pagina densa contano */
* {
    scrollbar-width: thin;
    scrollbar-color: var(--md-ref-palette-neutral80) transparent;
}
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-thumb {
    background: var(--md-ref-palette-neutral80);
    border: 3px solid transparent;
    background-clip: content-box;
    border-radius: 999px;
}
*::-webkit-scrollbar-thumb:hover { background-color: var(--md-ref-palette-neutral70); }

@keyframes spin { to { transform: rotate(360deg); } }

/* ========================================
   Schermata di avvio
   ======================================== */
.boot {
    position: fixed;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 20px;
    background: var(--nav-bg);
    z-index: 9999;
}

.boot-mark {
    display: grid;
    place-items: center;
    width: 52px;
    height: 52px;
    border-radius: var(--r);
    background: var(--accent);
    color: #04211d;
    font: var(--md-sys-typescale-title-large);
    letter-spacing: 0.04em;
}

.boot-bar {
    position: relative;
    width: 140px;
    height: 2px;
    background: var(--nav-line);
    overflow: hidden;
}
.boot-bar::after {
    content: '';
    position: absolute;
    inset: 0;
    width: 40%;
    background: var(--accent);
    animation: boot-slide 1.1s var(--md-sys-motion-easing-standard) infinite;
}
@keyframes boot-slide {
    0% { transform: translateX(-110%); }
    100% { transform: translateX(320%); }
}

/* ========================================
   Impianto: navigazione + area di lavoro
   ======================================== */
.shell {
    display: grid;
    grid-template-columns: var(--nav-w) minmax(0, 1fr);
    min-height: 100vh;
    background: var(--page-bg);
    /* La riduzione della sidebar e' istantanea: animare grid-template-columns
       fra una traccia fissa e una in fr da risultati incoerenti fra browser,
       e per un comando che si usa una volta al giorno lo scatto va benissimo. */
}
.shell.nav-collapsed { grid-template-columns: var(--nav-w-min) minmax(0, 1fr); }

.shell-nav {
    display: flex;
    flex-direction: column;
    background: var(--nav-bg);
    border-right: 1px solid var(--nav-bg-deep);
    position: sticky;
    top: 0;
    height: 100vh;
    z-index: 40;
}

.shell-main {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.shell-body {
    flex: 1;
    padding: 20px 24px 40px;
    min-width: 0;
}

/* ---------- marchio ---------- */
.shell-brand {
    display: flex;
    align-items: center;
    gap: 8px;
    height: var(--top-h);
    padding: 0 10px 0 14px;
    border-bottom: 1px solid var(--nav-line);
    flex: 0 0 auto;
}

.brand {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
    flex: 1;
    color: var(--nav-text-strong);
}
.brand:hover { color: #fff; }

.brand-mark {
    display: grid;
    place-items: center;
    flex: 0 0 auto;
    width: 30px;
    height: 30px;
    border-radius: 5px;
    background: var(--accent);
    color: #04211d;
    font: var(--md-sys-typescale-label-large);
    letter-spacing: 0.03em;
}

.brand-name {
    font: var(--md-sys-typescale-title-small);
    letter-spacing: 0.14em;
    text-transform: uppercase;
    white-space: nowrap;
    overflow: hidden;
}

.tx-nav-pin {
    flex: 0 0 auto;
    display: grid;
    place-items: center;
    width: 26px;
    height: 26px;
    border: 0;
    border-radius: 4px;
    background: transparent;
    color: var(--nav-text);
    cursor: pointer;
    font-size: 0.75rem;
}
.tx-nav-pin:hover { background: var(--nav-hover); color: var(--nav-text-strong); }

/* ---------- voci ---------- */
.tx-nav-scroll {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 10px 8px 16px;
    display: flex;
    flex-direction: column;
    gap: 1px;
}

.tx-nav-link,
.tx-nav-child {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 8px 10px;
    border: 0;
    border-radius: 5px;
    background: transparent;
    color: var(--nav-text);
    font: var(--md-sys-typescale-label-large);
    text-align: left;
    cursor: pointer;
    position: relative;
    white-space: nowrap;
}

.tx-nav-link > i:first-child,
.tx-nav-child > i:first-child {
    flex: 0 0 auto;
    width: 18px;
    font-size: 0.9375rem;
    text-align: center;
}

.tx-nav-label {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
}

.tx-nav-link:hover,
.tx-nav-child:hover { background: var(--nav-hover); color: var(--nav-text-strong); }

/* La voce attiva ha una barretta a sinistra: si trova con la coda dell'occhio */
.tx-nav-link.is-active,
.tx-nav-child.is-active {
    background: var(--nav-active);
    color: #fff;
}
.tx-nav-link.is-active::before,
.tx-nav-child.is-active::before {
    content: '';
    position: absolute;
    left: -8px;
    top: 6px;
    bottom: 6px;
    width: 3px;
    border-radius: 0 2px 2px 0;
    background: var(--accent);
}
.tx-nav-link.is-active > i:first-child,
.tx-nav-child.is-active > i:first-child { color: var(--accent); }

.tx-nav-quit { margin-top: 6px; color: #f0a3a3; }
.tx-nav-quit:hover { background: rgba(180, 35, 24, 0.18); color: #ffc9c4; }

/* ---------- sezioni con sottomenu ---------- */
/* Contenitore normale, non display:contents: con contents il gruppo non genera
   una scatola, i figli finiscono direttamente nel flex della barra e la voce
   padre poteva restare senza testo. */
.tx-nav-group {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.tx-nav-caret {
    flex: 0 0 auto;
    font-size: 0.6875rem;
    opacity: 0.7;
    transition: transform var(--md-sys-motion-duration-short4) var(--md-sys-motion-easing-standard);
}
.tx-nav-group.is-open .tx-nav-caret { transform: rotate(180deg); }

/* Chiuso di default, si apre in altezza. Il tetto di max-height e'
   volutamente generoso: serve solo ad animare, il contenuto reale e' corto. */
.tx-nav-children {
    overflow: hidden;
    max-height: 0;
    transition: max-height var(--md-sys-motion-duration-medium2) var(--md-sys-motion-easing-standard);
}
.tx-nav-children-inner {
    display: flex;
    flex-direction: column;
    gap: 1px;
    padding-bottom: 3px;
}
.tx-nav-group.is-open .tx-nav-children { max-height: 1000px; }

.tx-nav-child {
    padding-left: 34px;
    font: var(--md-sys-typescale-body-small);
    color: #8494a8;
    position: relative;
}
.tx-nav-child > i:first-child {
    position: absolute;
    left: 14px;
    width: 14px;
    font-size: 0.75rem;
    opacity: 0.85;
}
.tx-nav-child.is-active { font-weight: 600; }

/* ---------- stella dei preferiti ---------- */
.fav-star {
    flex: 0 0 auto;
    display: grid;
    place-items: center;
    width: 22px;
    height: 22px;
    border: 0;
    border-radius: 4px;
    background: transparent;
    color: inherit;
    opacity: 0;
    cursor: pointer;
    font-size: 0.75rem;
    transition: opacity var(--md-sys-motion-duration-short4) linear;
}
.tx-nav-link:hover .fav-star,
.tx-nav-child:hover .fav-star,
.tile:hover .fav-star,
.section-links li:hover .fav-star,
.fav-star:focus-visible { opacity: 0.7; }
.fav-star:hover { background: var(--nav-hover); opacity: 1; }
.fav-star.is-on { opacity: 1; color: #fbbf24; }

/* ---------- coda della sidebar ---------- */
.shell-nav-foot {
    flex: 0 0 auto;
    padding: 10px 16px;
    border-top: 1px solid var(--nav-line);
}
.tx-nav-version {
    font: var(--md-sys-typescale-label-small);
    color: #64748b;
    letter-spacing: 0.08em;
}

/* ---------- sidebar ridotta ---------- */
.nav-collapsed .brand-name,
.nav-collapsed .tx-nav-label,
.nav-collapsed .tx-nav-caret,
.nav-collapsed .fav-star,
.nav-collapsed .tx-nav-version { display: none; }

.nav-collapsed .shell-brand { padding: 0 8px; justify-content: center; }
.nav-collapsed .brand { justify-content: center; }
.nav-collapsed .tx-nav-pin { position: absolute; left: 50%; transform: translateX(-50%); top: 58px; }
.nav-collapsed .tx-nav-link,
.nav-collapsed .tx-nav-child { justify-content: center; padding: 9px 0; }
.nav-collapsed .tx-nav-children { max-height: 0; }
.nav-collapsed .tx-nav-child > i:first-child { position: static; }
.nav-collapsed .tx-nav-scroll { padding-top: 34px; }

.tx-nav-scrim { display: none; }

/* ========================================
   Barra superiore
   ======================================== */
.shell-top {
    position: sticky;
    top: 0;
    z-index: 30;
    display: flex;
    align-items: center;
    gap: 12px;
    height: var(--top-h);
    padding: 0 20px;
    background: rgba(255, 255, 255, 0.92);
    backdrop-filter: blur(8px);
    border-bottom: 1px solid var(--line);
}

.top-burger {
    display: none;
    width: 34px;
    height: 34px;
    border: 1px solid var(--line);
    border-radius: 5px;
    background: #fff;
    color: var(--ink-2);
    cursor: pointer;
}

.top-where {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
    flex: 1;
    overflow: hidden;
}
.where-main {
    font: var(--md-sys-typescale-title-small);
    color: var(--ink);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.where-up {
    font: var(--md-sys-typescale-label-medium);
    color: var(--ink-3);
    white-space: nowrap;
}
.where-sep { font-size: 0.625rem; color: var(--md-ref-palette-neutral80); }

.top-actions {
    display: flex;
    align-items: center;
    gap: 6px;
    flex: 0 0 auto;
}

/* ---------- campanella ---------- */
.bell { position: relative; }

.bell-btn {
    position: relative;
    width: 34px;
    height: 34px;
    border: 1px solid transparent;
    border-radius: 5px;
    background: transparent;
    color: var(--ink-2);
    cursor: pointer;
    font-size: 1rem;
}
.bell-btn:hover, .bell-btn.is-open {
    background: var(--md-sys-color-surface-container);
    border-color: var(--line);
    color: var(--ink);
}

.bell-dot {
    position: absolute;
    top: -3px;
    right: -3px;
    min-width: 17px;
    height: 17px;
    padding: 0 4px;
    display: grid;
    place-items: center;
    border-radius: 999px;
    background: var(--ink-3);
    color: #fff;
    font: var(--md-sys-typescale-label-small);
    font-size: 0.625rem;
}
.bell-dot.is-unread { background: var(--md-sys-color-error); }

.bell-backdrop, .who-backdrop {
    position: fixed;
    inset: 0;
    z-index: 60;
}

.bell-panel {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    z-index: 61;
    width: 380px;
    max-width: calc(100vw - 24px);
    background: var(--card-bg);
    border: 1px solid var(--line);
    border-radius: var(--r);
    box-shadow: var(--md-sys-elevation-level4);
    overflow: hidden;
}

.bell-panel-head, .bell-panel-foot {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 10px 14px;
    font: var(--md-sys-typescale-label-medium);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--ink-3);
}
.bell-panel-head { border-bottom: 1px solid var(--line-soft); }
.bell-panel-foot { border-top: 1px solid var(--line-soft); justify-content: center; }

.bell-list { list-style: none; margin: 0; padding: 0; max-height: 60vh; overflow-y: auto; }

.bell-item {
    display: flex;
    gap: 10px;
    padding: 10px 14px;
    border-bottom: 1px solid var(--line-soft);
    border-left: 3px solid transparent;
}
.bell-item:last-child { border-bottom: 0; }
.bell-item.is-unread { background: #fbfdfd; }
.bell-item.sev-warning { border-left-color: var(--md-sys-color-warning); }
.bell-item.sev-critical { border-left-color: var(--md-sys-color-error); }
.bell-item.sev-info { border-left-color: var(--accent); }

.bell-check, .todo-check {
    flex: 0 0 auto;
    width: 22px;
    height: 22px;
    margin-top: 1px;
    border: 0;
    border-radius: 4px;
    background: transparent;
    color: var(--ink-3);
    cursor: pointer;
    font-size: 0.9375rem;
}
.bell-check:hover, .todo-check:hover { color: var(--md-sys-color-success); background: var(--md-sys-color-success-container); }

.bell-item-body { flex: 1; min-width: 0; cursor: pointer; display: grid; gap: 2px; }
.bell-item-title { font: var(--md-sys-typescale-label-large); color: var(--ink); }
.bell-item-text { font: var(--md-sys-typescale-body-small); color: var(--ink-2); }
.bell-item-due { font: var(--md-sys-typescale-label-small); color: var(--ink-3); }
.bell-item-due.is-late { color: var(--md-sys-color-error); }

.bell-empty, .todo-empty, .panel-hint {
    display: grid;
    place-items: center;
    gap: 8px;
    padding: 28px 20px;
    color: var(--ink-3);
    text-align: center;
    font: var(--md-sys-typescale-body-small);
}
.bell-empty i, .todo-empty i, .panel-hint i { font-size: 1.5rem; opacity: 0.5; }
.panel-hint p, .todo-empty p { margin: 0; max-width: 42ch; }

/* ---------- menu utente ---------- */
.who { position: relative; }

.who-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    height: 34px;
    padding: 0 8px;
    border: 1px solid transparent;
    border-radius: 5px;
    background: transparent;
    color: var(--ink);
    cursor: pointer;
    font: var(--md-sys-typescale-label-large);
}
.who-btn:hover, .who.is-open .who-btn {
    background: var(--md-sys-color-surface-container);
    border-color: var(--line);
}
.who-btn > i { font-size: 0.6875rem; color: var(--ink-3); }

.who-avatar {
    display: grid;
    place-items: center;
    width: 26px;
    height: 26px;
    border-radius: 5px;
    background: var(--nav-bg);
    color: #fff;
    font: var(--md-sys-typescale-label-small);
    letter-spacing: 0.02em;
}
.who-avatar.lg { width: 36px; height: 36px; font: var(--md-sys-typescale-label-large); }

.who-name { max-width: 180px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.who-menu {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    z-index: 61;
    width: 262px;
    padding: 6px;
    background: var(--card-bg);
    border: 1px solid var(--line);
    border-radius: var(--r);
    box-shadow: var(--md-sys-elevation-level4);
}

.who-menu-head {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 10px 12px;
}
.who-menu-head strong { display: block; font: var(--md-sys-typescale-label-large); }
.who-menu-head span { font: var(--md-sys-typescale-body-small); color: var(--ink-3); }

.who-item {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 8px 10px;
    border: 0;
    border-radius: 5px;
    background: transparent;
    color: var(--ink);
    font: var(--md-sys-typescale-body-medium);
    text-align: left;
    cursor: pointer;
}
.who-item:hover { background: var(--md-sys-color-surface-container); color: var(--ink); }
.who-item > i { width: 16px; color: var(--ink-3); }
.who-item.is-quit { color: var(--md-sys-color-error); }
.who-item.is-quit:hover { background: var(--md-sys-color-error-container); }
.who-item.is-quit > i { color: inherit; }

.who-sep { height: 1px; margin: 6px 4px; background: var(--line-soft); }

.who-langs { display: flex; gap: 4px; padding: 2px 4px; }
.who-lang {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 6px 8px;
    border: 1px solid var(--line);
    border-radius: 5px;
    background: #fff;
    color: var(--ink-2);
    cursor: pointer;
    font: var(--md-sys-typescale-label-small);
}
.who-lang img { width: 16px; height: 12px; object-fit: cover; border-radius: 1px; }
.who-lang:hover { border-color: var(--md-ref-palette-neutral80); }
.who-lang.is-active {
    border-color: var(--accent-strong);
    background: var(--accent-soft);
    color: var(--accent-deep);
}

/* ========================================
   Pannelli
   ======================================== */
.panel {
    background: var(--card-bg);
    border: 1px solid var(--line);
    border-radius: var(--r);
    margin-bottom: 16px;
}

.panel-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 12px 16px;
    border-bottom: 1px solid var(--line-soft);
}
.panel-head h2 {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 0;
    font: var(--md-sys-typescale-label-medium);
    text-transform: uppercase;
    letter-spacing: 0.09em;
    color: var(--ink-2);
}
.panel-head h2 > i { color: var(--accent-strong); font-size: 0.875rem; }
.panel-head-actions { display: flex; align-items: center; gap: 4px; }

.link-btn {
    border: 0;
    background: transparent;
    color: var(--accent-deep);
    cursor: pointer;
    padding: 2px 4px;
    font: var(--md-sys-typescale-label-small);
    text-transform: none;
    letter-spacing: 0;
}
.link-btn:hover { text-decoration: underline; }

.icon-btn {
    display: grid;
    place-items: center;
    width: 28px;
    height: 28px;
    border: 1px solid var(--line);
    border-radius: 5px;
    background: #fff;
    color: var(--ink-2);
    cursor: pointer;
}
.icon-btn:hover:not(:disabled) { background: var(--md-sys-color-surface-container); color: var(--ink); }
.icon-btn:disabled { opacity: 0.5; cursor: default; }
.icon-btn .spin { animation: spin 0.8s linear infinite; }

.btn-accent {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    height: 34px;
    padding: 0 14px;
    border: 1px solid var(--accent-strong);
    border-radius: 5px;
    background: var(--accent-strong);
    color: #fff;
    cursor: pointer;
    font: var(--md-sys-typescale-label-large);
    white-space: nowrap;
}
.btn-accent:hover:not(:disabled) { background: var(--accent-deep); border-color: var(--accent-deep); }
.btn-accent:disabled { opacity: 0.45; cursor: default; }

/* ========================================
   Home
   ======================================== */
/* Nessun max-width: su schermi larghi la pagina deve riempire lo spazio,
   non lasciare una fascia vuota a destra. */
.home { width: 100%; }

.home-hero {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 16px;
    margin: 4px 0 18px;
}
.home-hero h1 {
    margin: 2px 0 0;
    font: var(--md-sys-typescale-headline-small);
    color: var(--ink);
}
.home-hero h1 span { color: var(--accent-deep); }
.hero-when {
    margin: 0;
    font: var(--md-sys-typescale-label-small);
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--ink-3);
}

/* Preferiti e piu' usati affiancati; su schermi stretti uno sotto l'altro. */
.home-cols {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(420px, 1fr));
    gap: 16px;
    align-items: start;
}
.home-cols > * { min-width: 0; }

.home-loading, .todo-loading {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 24px;
    color: var(--ink-3);
    font: var(--md-sys-typescale-body-small);
}

/* pallino pulsante: attesa discreta, senza rotelle */
.dot-pulse {
    width: 8px;
    height: 8px;
    border-radius: 999px;
    background: var(--accent);
    animation: dot-pulse 1s ease-in-out infinite;
}
@keyframes dot-pulse {
    0%, 100% { opacity: 0.25; transform: scale(0.8); }
    50% { opacity: 1; transform: scale(1.15); }
}

/* ---------- tile ---------- */
.tiles {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
    gap: 10px;
    padding: 14px 16px 16px;
}

.tile {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: var(--r);
    background: #fff;
    color: var(--ink);
    position: relative;
    transition: border-color var(--md-sys-motion-duration-short4) linear,
                box-shadow var(--md-sys-motion-duration-short4) linear;
}
.tile:hover {
    border-color: var(--accent);
    box-shadow: var(--md-sys-elevation-level2);
    color: var(--ink);
}

.tile-icon {
    display: grid;
    place-items: center;
    flex: 0 0 auto;
    width: 36px;
    height: 36px;
    border-radius: 5px;
    background: var(--md-sys-color-surface-container);
    color: var(--accent-deep);
    font-size: 1rem;
}
.tile:hover .tile-icon { background: var(--accent-soft); }

.tile-text { display: grid; gap: 1px; min-width: 0; flex: 1; }
.tile-text strong {
    font: var(--md-sys-typescale-label-large);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.tile-text small {
    font: var(--md-sys-typescale-body-small);
    color: var(--ink-3);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.tile .fav-star { color: var(--ink-3); }
.tile .fav-star:hover { background: var(--md-sys-color-surface-container); }

/* ---------- elenco sezioni ---------- */
.sections {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 12px;
    padding: 14px 16px 16px;
    /* Ogni card alta quanto il suo contenuto, senza stirarsi fino alla piu'
       alta della riga. */
    align-items: start;
}

.section-card {
    border: 1px solid var(--line);
    border-radius: var(--r);
    overflow: hidden;
    background: #fff;
}

.section-head {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px;
    background: var(--md-sys-color-surface-container);
    border-bottom: 1px solid var(--line);
    color: var(--ink);
}
.section-head:hover { background: var(--accent-soft); color: var(--accent-deep); }

.section-icon {
    display: grid;
    place-items: center;
    width: 30px;
    height: 30px;
    border-radius: 5px;
    background: var(--nav-bg);
    color: var(--accent);
    font-size: 0.875rem;
}
.section-name { display: grid; min-width: 0; }
.section-name strong { font: var(--md-sys-typescale-label-large); }
.section-name small { font: var(--md-sys-typescale-body-small); color: var(--ink-3); }

.section-links { list-style: none; margin: 0; padding: 4px; display: grid; gap: 1px; }
.section-links li { display: flex; align-items: center; border-radius: 4px; }
.section-links li:hover { background: var(--md-sys-color-surface-container); }
.section-links li > a {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
    padding: 6px 8px;
    color: var(--ink-2);
    font: var(--md-sys-typescale-body-small);
}
.section-links li > a:hover { color: var(--accent-deep); }
.section-links li > a > i { width: 14px; font-size: 0.75rem; color: var(--ink-3); }
.section-links li > a > span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.section-links .fav-star { color: var(--ink-3); margin-right: 4px; }

/* ========================================
   Todo list
   ======================================== */
.todo-add {
    display: flex;
    gap: 6px;
    padding: 12px 16px;
    border-bottom: 1px solid var(--line-soft);
    /* Su un monitor largo un campo di testo da 1500px e' sgraziato e difficile
       da leggere: la riga si ferma a una misura da modulo. */
    max-width: 760px;
}
.todo-input, .todo-date {
    height: 34px;
    padding: 0 10px;
    border: 1px solid var(--line);
    border-radius: 5px;
    background: #fff;
    color: var(--ink);
    font: var(--md-sys-typescale-body-medium);
    font-family: var(--font-ui);
}
.todo-input { flex: 1; min-width: 0; }
.todo-date { flex: 0 0 auto; width: 130px; color: var(--ink-2); }
.todo-input:focus, .todo-date:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(var(--accent-rgb), 0.14);
}

/* Le voci si dispongono in colonne che si adattano alla larghezza: su un
   monitor grande stanno tre o quattro per riga invece di incolonnarsi in una
   striscia stretta. */
.todo-grid {
    list-style: none;
    margin: 0;
    padding: 12px 16px 16px;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(360px, 1fr));
    gap: 10px;
}

.todo-item {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 11px 12px 11px 10px;
    border: 1px solid var(--line);
    border-left-width: 3px;
    border-left-color: transparent;
    border-radius: var(--r);
    background: #fff;
}
.todo-item:hover { border-color: var(--md-ref-palette-neutral80); border-left-color: var(--accent); }
.todo-item.is-unread { background: #fbfefe; }
.todo-item.sev-info { border-left-color: var(--accent); }
.todo-item.sev-warning { border-left-color: var(--md-sys-color-warning); }
.todo-item.sev-critical { border-left-color: var(--md-sys-color-error); }
.todo-item.is-done { opacity: 0.55; }
.todo-item.is-done .todo-title { text-decoration: line-through; }
.todo-item.is-done .todo-check { color: var(--md-sys-color-success); }

.todo-body { flex: 1; min-width: 0; display: grid; gap: 2px; }
.todo-line { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.todo-icon { font-size: 0.8125rem; color: var(--ink-3); }
.todo-title { font: var(--md-sys-typescale-label-large); color: var(--ink); }
.todo-title.is-link { color: var(--ink); }
.todo-title.is-link:hover { color: var(--accent-deep); text-decoration: underline; }
.todo-text { margin: 0; font: var(--md-sys-typescale-body-small); color: var(--ink-2); }

.todo-tag {
    padding: 1px 6px;
    border-radius: 3px;
    background: var(--md-sys-color-surface-container-highest);
    color: var(--ink-3);
    font: var(--md-sys-typescale-label-small);
    font-size: 0.625rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

.todo-meta {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    margin-top: 2px;
}

.todo-due {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font: var(--md-sys-typescale-label-small);
    color: var(--ink-3);
}

.todo-tag.is-from {
    background: var(--accent-soft);
    color: var(--accent-deep);
}

.todo-more {
    padding: 0 16px 14px;
    text-align: center;
}
.todo-more a {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font: var(--md-sys-typescale-label-medium);
    color: var(--accent-deep);
}
.todo-more a:hover { text-decoration: underline; }

.panel-count {
    font: var(--md-sys-typescale-label-small);
    color: var(--ink-3);
    text-transform: none;
    letter-spacing: 0;
    margin-right: 4px;
}

.btn-ghost {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    height: 28px;
    padding: 0 10px;
    border: 1px solid var(--line);
    border-radius: 5px;
    background: #fff;
    color: var(--ink-2);
    font: var(--md-sys-typescale-label-small);
    white-space: nowrap;
}
.btn-ghost:hover {
    background: var(--accent-soft);
    border-color: var(--accent);
    color: var(--accent-deep);
}
.todo-due.is-today { color: var(--accent-deep); font-weight: 600; }
.todo-due.is-late { color: var(--md-sys-color-error); font-weight: 600; }

.todo-del {
    flex: 0 0 auto;
    width: 22px;
    height: 22px;
    border: 0;
    border-radius: 4px;
    background: transparent;
    color: var(--ink-3);
    cursor: pointer;
    opacity: 0;
    font-size: 0.75rem;
}
.todo-item:hover .todo-del { opacity: 1; }
.todo-del:hover { background: var(--md-sys-color-error-container); color: var(--md-sys-color-error); }

/* ========================================
   Stati generici (usati anche dalle pagine)
   ======================================== */
.empty-state {
    display: grid;
    place-items: center;
    gap: 10px;
    padding: 40px 20px;
    color: var(--ink-3);
    text-align: center;
}
.empty-state i { font-size: 2rem; opacity: 0.45; }
.empty-state p { margin: 0; font: var(--md-sys-typescale-body-medium); }

.spinner {
    width: 34px;
    height: 34px;
    border: 3px solid var(--md-sys-color-surface-container-highest);
    border-top-color: var(--accent-strong);
    border-radius: 999px;
    animation: spin 0.8s linear infinite;
}

/* ========================================
   Schermi stretti
   ======================================== */
@media (max-width: 900px) {
    .todo-grid { grid-template-columns: minmax(0, 1fr); }
    .home-cols { grid-template-columns: minmax(0, 1fr); }
}

@media (max-width: 900px) {
    .shell { grid-template-columns: minmax(0, 1fr); }
    .shell.nav-collapsed { grid-template-columns: minmax(0, 1fr); }

    /* La navigazione esce di scena e rientra sopra il contenuto */
    .shell-nav {
        position: fixed;
        top: 0;
        left: 0;
        width: var(--nav-w);
        transform: translateX(-100%);
        transition: transform var(--md-sys-motion-duration-medium2) var(--md-sys-motion-easing-emphasized);
        z-index: 70;
    }
    .shell.nav-open .shell-nav { transform: translateX(0); }
    .shell.nav-open .tx-nav-scrim {
        display: block;
        position: fixed;
        inset: 0;
        background: var(--md-sys-color-scrim);
        z-index: 65;
    }

    .tx-nav-pin { display: none; }
    .top-burger { display: grid; place-items: center; }
    .shell-body { padding: 16px 14px 32px; }
    .who-name { display: none; }
}

/* ========================================
   Page Headers
   ======================================== */
.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 8px;
}

.page-header h1,
.page-header h2 {
    margin: 0;
}

.page-header h1 {
    font: var(--md-sys-typescale-headline-medium);
    color: var(--md-ref-palette-neutral10);
    display: flex;
    align-items: center;
    gap: 12px;
}

.page-header h2 {
    color: #1e293b;
    font-size: 1.5rem;
    font-weight: 600;
}

.page-header h1 i {
    color: var(--btn-primary);
    font-size: 1.5rem;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 16px;
}

.header-buttons {
    display: flex;
    align-items: center;
    gap: 12px;
}

.btn-import {
    height: 44px;
    padding: 0 20px;
}

.btn-info-modern {
    background: var(--md-sys-color-info) !important;
    color: white !important;
}

.btn-info-modern:hover {
    background: #0369a1 !important;
}

.last-refresh-label {
    font-size: 0.85rem;
    color: var(--md-sys-color-outline);
    white-space: nowrap;
}

.import-running-label {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-size: 0.85rem;
    color: var(--md-sys-color-info, #0284c7);
    background: var(--md-sys-color-info-container, #e0f2fe);
    padding: 6px 14px;
    border-radius: var(--md-sys-shape-corner-full, 9999px);
    white-space: nowrap;
    animation: pulse-opacity 2s ease-in-out infinite;
}

@keyframes pulse-opacity {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.6; }
}

.record-count {
    font: var(--md-sys-typescale-label-large);
    color: var(--md-sys-color-outline);
    background: var(--md-sys-color-surface-container-highest);
    padding: 6px 14px;
    border-radius: var(--md-sys-shape-corner-full);
}

/* ========================================
   Panels & Cards
   ======================================== */
.panel,
.card-modern,
.filters-card,
.grid-card {
    background: var(--md-sys-color-surface-container-low);
    border-radius: var(--md-sys-shape-corner-medium);
    box-shadow: var(--md-sys-elevation-level1);
    overflow: hidden;
}

.panel-body {
    padding: 20px;
}

/* ========================================
   Filters
   ======================================== */
.filters-card {
    padding: 20px 24px;
}

.filters-row {
    display: flex;
    flex-wrap: wrap;
    gap: 16px;
    align-items: flex-end;
}

.filter-item {
    flex: 1;
    min-width: 160px;
    max-width: 220px;
}

.filter-input {
    width: 100%;
}

.filter-actions {
    display: flex;
    gap: 8px;
    margin-left: auto;
}

/* ========================================
   Buttons
   ======================================== */
.m3-button,
.btn-primary-modern,
.btn-add,
.btn-save,
.btn-action,
.btn-search {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 48px;
    height: auto;
    padding: 12px 28px;
    border: none;
    border-radius: var(--md-sys-shape-corner-full);
    font: var(--md-sys-typescale-label-large);
    font-size: 0.95rem;
    cursor: pointer;
    transition: all var(--md-sys-motion-duration-short4) var(--md-sys-motion-easing-standard);
    background: var(--btn-primary);
    color: var(--btn-on-primary);
    box-shadow: var(--md-sys-elevation-level1);
    text-decoration: none;
}

.m3-button:hover,
.btn-primary-modern:hover,
.btn-add:hover,
.btn-save:hover,
.btn-action:hover,
.btn-search:hover {
    background: var(--btn-primary-hover);
    box-shadow: var(--md-sys-elevation-level2);
    transform: translateY(-1px);
}

.btn-add {
    height: 44px;
    padding: 0 24px;
}

/* Outlined Button */
.m3-button-outlined,
.btn-outline-modern,
.btn-clear,
.btn-cancel {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 48px;
    height: auto;
    padding: 12px 28px;
    background: transparent;
    border: 1px solid var(--md-sys-color-outline);
    border-radius: var(--md-sys-shape-corner-full);
    font: var(--md-sys-typescale-label-large);
    font-size: 0.95rem;
    color: var(--btn-primary);
    cursor: pointer;
    transition: all var(--md-sys-motion-duration-short4) var(--md-sys-motion-easing-standard);
}

.m3-button-outlined:hover,
.btn-outline-modern:hover,
.btn-clear:hover,
.btn-cancel:hover {
    background: var(--md-sys-color-primary-container);
    border-color: var(--btn-primary);
}

.btn-clear {
    width: 44px;
    height: 44px;
    padding: 0;
    color: var(--md-sys-color-outline);
}

.btn-clear:hover {
    background: var(--md-sys-color-surface-container-highest);
    border-color: var(--md-ref-palette-neutral10);
    color: var(--md-ref-palette-neutral10);
}

/* Grid Links */
.grid-link {
    color: var(--md-sys-color-primary);
    text-decoration: none;
    cursor: pointer;
}

.grid-link:hover {
    text-decoration: underline;
    color: var(--md-sys-color-primary);
}

/* Icon Buttons */
.btn-icon {
    width: 40px;
    height: 40px;
    border: none;
    border-radius: var(--md-sys-shape-corner-full);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: all var(--md-sys-motion-duration-short4) var(--md-sys-motion-easing-standard);
    background: transparent;
    color: var(--md-sys-color-on-surface-variant, #49454f);
}

.btn-icon:hover {
    background: var(--md-sys-color-surface-container-highest);
}

.btn-edit {
    background: var(--md-sys-color-primary-container);
    color: var(--btn-primary);
}

.btn-edit:hover {
    background: var(--md-sys-color-secondary-container);
    color: var(--btn-primary-hover);
}

.btn-delete {
    background: transparent;
    color: var(--md-sys-color-outline);
}

.btn-delete:hover {
    background: var(--md-sys-color-error-container);
    color: var(--md-sys-color-error);
}

/* Priority Cell */
.priority-cell {
    display: inline-flex;
    align-items: center;
    gap: 2px;
}

.priority-cell .btn-priority {
    width: 28px;
    height: 28px;
    border: none;
    border-radius: var(--md-sys-shape-corner-full);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s ease;
    background: transparent;
    color: var(--md-sys-color-on-surface-variant, #49454f);
    padding: 0;
    font-size: 0.85rem;
}

.priority-cell .btn-priority:hover:not(:disabled) {
    background: var(--md-sys-color-primary-container);
    color: var(--md-sys-color-primary);
}

.priority-cell .btn-priority:disabled {
    opacity: 0.3;
    cursor: default;
}

.priority-cell .priority-value {
    min-width: 28px;
    text-align: center;
    font-weight: 600;
    font-size: 0.9rem;
    color: var(--md-sys-color-on-surface-variant);
}

.priority-cell .priority-value.priority-high {
    color: var(--md-sys-color-primary);
    font-weight: 700;
}

/* Login Button */
.btn-login {
    width: 100%;
    height: 48px;
    padding: 16px 0;
    border-radius: var(--md-sys-shape-corner-full);
    font: var(--md-sys-typescale-label-large);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    background: var(--btn-primary);
    color: var(--btn-on-primary);
    border: none;
    cursor: pointer;
    box-shadow: var(--md-sys-elevation-level1);
    transition: all var(--md-sys-motion-duration-short4) var(--md-sys-motion-easing-standard);
}

.btn-login:hover:not(:disabled) {
    background: var(--btn-primary-hover);
    box-shadow: var(--md-sys-elevation-level2);
    transform: translateY(-2px);
}

.btn-login:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

/* Action buttons for tracking */
.btn-start {
    background: var(--md-sys-color-success) !important;
    color: white !important;
}

.btn-start:hover {
    background: #15803d !important;
}

.btn-stop {
    background: var(--btn-primary) !important;
}

.btn-pause {
    background: var(--md-sys-color-warning) !important;
    color: #1e293b !important;
}

.btn-pause:hover {
    background: #ca8a04 !important;
}

.btn-resume {
    background: var(--md-sys-color-tertiary) !important;
}

/* ========================================
   Inputs & Form Controls
   ======================================== */
input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
input[type="search"] {
    height: 56px;
    padding: 16px;
    border: 1px solid var(--md-sys-color-outline);
    border-radius: var(--md-sys-shape-corner-extra-small);
    background: transparent;
    font: var(--md-sys-typescale-body-large);
    color: var(--md-ref-palette-neutral10);
    transition: all var(--md-sys-motion-duration-short4) var(--md-sys-motion-easing-standard);
    outline: none;
}

input:hover {
    border-color: var(--md-ref-palette-neutral10);
}

input:focus {
    border-color: var(--btn-primary);
    border-width: 2px;
}

input::placeholder {
    color: var(--md-sys-color-outline);
}

input[type=checkbox] {
    width: 18px;
    height: 18px;
    accent-color: var(--btn-primary);
}

.form-group {
    margin-bottom: 0;
}

.form-group label {
    display: block;
    margin-bottom: 6px;
    font-weight: 500;
    color: #475569;
    font-size: 0.875rem;
}

.form-field {
    margin-bottom: 24px;
}

.form-field label {
    display: flex;
    align-items: center;
    gap: 10px;
    font: var(--md-sys-typescale-label-large);
    color: var(--md-ref-palette-neutral30);
    margin-bottom: 10px;
}

.form-field label i {
    color: var(--btn-primary);
    font-size: 1.125rem;
}

.form-field input {
    width: 100%;
}

.form-actions {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
}

.required { color: #dc2626; }
.text-danger { color: #dc2626; font-size: 0.8rem; display: block; margin-top: 4px; }
.text-required {
    color: #dc2626;
    font-size: 0.8rem;
    display: inline;
    margin-top: 4px;
}
.text-muted { color: #94a3b8; font-size: 0.9rem; font-style: italic; }

/* ========================================
   Alerts
   ======================================== */
.alert {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px;
    border-radius: var(--md-sys-shape-corner-small);
    font: var(--md-sys-typescale-body-medium);
    margin-bottom: 24px;
}

.alert-error { background: var(--md-sys-color-error-container); color: var(--md-sys-color-error); border: none; }
.alert-success { background: var(--md-sys-color-success-container); color: var(--md-sys-color-success); }
.alert-warning { background: var(--md-sys-color-warning-container); color: #854d0e; }
.alert-info { background: var(--md-sys-color-info-container); color: var(--md-sys-color-info); }

/* ========================================
   Login Page
   ======================================== */
.login-page {
    min-height: 100vh;
    /* Fondo navy con una velatura teal: la pagina di accesso e' la prima cosa
       che il cliente vede, e deve dire subito di che prodotto si tratta. */
    background:
        radial-gradient(1100px 520px at 15% -10%, rgba(var(--accent-rgb), 0.20), transparent 60%),
        linear-gradient(160deg, var(--nav-bg-deep) 0%, var(--nav-bg) 55%, #16233c 100%);
    display: flex;
    flex-direction: column;
}

.login-wrapper {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 48px 24px;
}

.login-logo {
    margin-bottom: 40px;
}

.login-logo img {
    height: 84px;
    transition: transform var(--md-sys-motion-duration-medium2) var(--md-sys-motion-easing-emphasized);
}

.login-logo:hover img {
    transform: scale(1.05);
}

.login-card {
    background: var(--card-bg);
    border: 1px solid rgba(255, 255, 255, 0.10);
    border-radius: var(--md-sys-shape-corner-extra-large);
    box-shadow: var(--md-sys-elevation-level5);
    width: 100%;
    max-width: 420px;
    overflow: hidden;
}

.login-header {
    padding: 34px 40px 26px;
    text-align: center;
    border-bottom: 1px solid var(--line);
}

.login-header h1 {
    font: var(--md-sys-typescale-headline-medium);
    color: var(--md-ref-palette-neutral10);
    margin: 0 0 12px 0;
}

.login-header p {
    color: var(--ink-3);
    margin: 0;
    font: var(--md-sys-typescale-body-medium);
}

.login-form {
    padding: 40px;
}

.login-links {
    display: flex;
    justify-content: space-between;
    margin-top: 24px;
}

.login-links a {
    color: var(--btn-primary);
    text-decoration: none;
    font: var(--md-sys-typescale-label-large);
    transition: color var(--md-sys-motion-duration-short4);
}

.login-links a:hover {
    color: var(--btn-primary-hover);
}

.forgot-link {
    display: block;
    text-align: right;
    margin-top: 16px;
    margin-bottom: 24px;
    font: var(--md-sys-typescale-body-medium);
    color: var(--btn-primary);
    text-decoration: none;
    transition: all var(--md-sys-motion-duration-short4) var(--md-sys-motion-easing-standard);
}

.forgot-link:hover {
    color: var(--btn-primary-hover);
    text-decoration: underline;
}

.back-link {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    margin-top: 24px;
    font: var(--md-sys-typescale-body-medium);
    color: var(--btn-primary);
    text-decoration: none;
    transition: all var(--md-sys-motion-duration-short4) var(--md-sys-motion-easing-standard);
}

.back-link:hover {
    color: var(--btn-primary-hover);
    text-decoration: underline;
}

.back-link i {
    font-size: 1.1rem;
    transition: transform var(--md-sys-motion-duration-short4) var(--md-sys-motion-easing-standard);
}

.back-link:hover i {
    transform: translateX(-4px);
}

.btn-back {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    padding: 12px 24px;
    background: var(--btn-primary);
    color: var(--btn-on-primary);
    border: none;
    border-radius: var(--md-sys-shape-corner-full);
    font: var(--md-sys-typescale-label-large);
    text-decoration: none;
    cursor: pointer;
    transition: all var(--md-sys-motion-duration-short4) var(--md-sys-motion-easing-standard);
    box-shadow: var(--md-sys-elevation-level1);
}

.btn-back:hover {
    background: var(--btn-primary-hover);
    box-shadow: var(--md-sys-elevation-level2);
    transform: translateY(-1px);
}

.btn-back i {
    font-size: 1.2rem;
    transition: transform var(--md-sys-motion-duration-short4) var(--md-sys-motion-easing-standard);
}

.btn-back:hover i {
    transform: translateX(-4px);
}

.login-footer {
    padding: 16px 24px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: rgba(0,0,0,0.32);
    backdrop-filter: blur(10px);
    gap: 16px;
}

.login-footer span {
    color: rgba(255,255,255,0.75);
    font: var(--md-sys-typescale-body-small);
    flex: 1;
}

.login-footer img {
    height: 28px;
    max-width: 180px;
    object-fit: contain;
    opacity: 0.8;
    transition: opacity var(--md-sys-motion-duration-short4);
}

.login-footer img:hover {
    opacity: 1;
}

/* ========================================
   Telerik Grid Overrides
   ======================================== */
.k-grid.m3-grid,
.m3-grid {
    border: none !important;
    border-radius: var(--md-sys-shape-corner-medium) !important;
    overflow: hidden;
}

.k-grid.m3-grid .k-grid-header,
.m3-grid .k-grid-header {
    background: var(--md-sys-color-surface-container) !important;
    border-bottom: 1px solid var(--md-sys-color-outline-variant) !important;
    width: 100% !important;
}

.k-grid.m3-grid .k-grid-header-wrap,
.m3-grid .k-grid-header-wrap {
    width: 100% !important;
}

.k-grid.m3-grid .k-grid-header th,
.m3-grid .k-grid-header th {
    font: var(--md-sys-typescale-title-small) !important;
    color: var(--md-sys-color-on-surface-variant, #49454f) !important;
    padding: 16px !important;
    border: none !important;
    background: transparent !important;
    vertical-align: middle !important;
}

.k-grid.m3-grid .k-grid-content,
.m3-grid .k-grid-content {
    background: var(--md-sys-color-surface) !important;
}

.k-grid.m3-grid .k-grid-content td,
.m3-grid .k-grid-content td {
    font: var(--md-sys-typescale-body-medium) !important;
    padding: 16px !important;
    border-bottom: 1px solid var(--md-sys-color-surface-container-high) !important;
    color: var(--md-ref-palette-neutral10) !important;
    vertical-align: middle !important;
    white-space: normal !important;
    word-break: break-word !important;
}

.k-grid.m3-grid .k-grid-table,
.m3-grid .k-grid-table {
    width: 100% !important;
    table-layout: auto !important;
}

.k-grid.m3-grid .k-grid-content tr:hover,
.m3-grid .k-grid-content tr:hover {
    background: var(--md-sys-color-surface-container) !important;
}

.k-grid.m3-grid .k-grid-content tr.k-selected,
.k-grid.m3-grid .k-grid-content tr.k-state-selected,
.m3-grid .k-grid-content tr.k-selected,
.m3-grid .k-grid-content tr.k-state-selected {
    background: var(--md-sys-color-primary-container) !important;
}

/* Pagination */
.k-grid.m3-grid .k-pager-wrap,
.m3-grid .k-pager-wrap {
    background: var(--md-sys-color-surface-container-low) !important;
    border-top: 1px solid var(--md-sys-color-outline-variant) !important;
    padding: 12px 16px !important;
}

.k-grid.m3-grid .k-pager-numbers .k-link,
.m3-grid .k-pager-numbers .k-link {
    border-radius: var(--md-sys-shape-corner-full) !important;
    min-width: 40px !important;
    height: 40px !important;
}

.k-grid.m3-grid .k-pager-numbers .k-link:hover,
.m3-grid .k-pager-numbers .k-link:hover {
    background: var(--md-sys-color-surface-container-highest) !important;
}

.k-grid.m3-grid .k-pager-numbers .k-selected,
.m3-grid .k-pager-numbers .k-selected {
    background: var(--btn-primary) !important;
    color: var(--btn-on-primary) !important;
    border-radius: var(--md-sys-shape-corner-full) !important;
}

/* Grid with smaller text */
.grid-small-text .k-grid-header th,
.grid-small-text .k-grid-content td {
    font-size: 0.875rem !important;
    padding: 8px 12px !important;
}

.grid-small-text .k-grid-header th {
    font-weight: 500 !important;
}

/* Row highlighting for import status */
.k-grid .k-grid-content tr.row-new,
.k-grid .k-grid-content tr.row-new td {
    background-color: #d4edda !important; /* Verde chiaro */
}

.k-grid .k-grid-content tr.row-new:hover,
.k-grid .k-grid-content tr.row-new:hover td {
    background-color: #c3e6cb !important;
}

.k-grid .k-grid-content tr.row-modified,
.k-grid .k-grid-content tr.row-modified td {
    background-color: #fff3cd !important; /* Giallo chiaro */
}

.k-grid .k-grid-content tr.row-modified:hover,
.k-grid .k-grid-content tr.row-modified:hover td {
    background-color: #ffeeba !important;
}

/* Row highlighting for orders without active BOM */
.k-grid .k-grid-content tr.row-no-bom,
.k-grid .k-grid-content tr.row-no-bom td {
    background-color: #fce4ec !important; /* Rosa chiaro */
}

.k-grid .k-grid-content tr.row-no-bom:hover,
.k-grid .k-grid-content tr.row-no-bom:hover td {
    background-color: #f8bbd0 !important;
}

/* ========================================
   Telerik Inputs
   ======================================== */
/* Altezza dei controlli Telerik.
   Solo i controlli a UNA riga hanno un'altezza fissa: area di testo e
   multiselezione devono crescere col contenuto. La regola precedente imponeva
   height:44px a tutto, .k-textarea compresa, e schiacciava l'area di testo a
   una riga tagliandone il contenuto. */
.k-textbox,
.k-numerictextbox,
.k-autocomplete,
.k-dropdown,
.k-dropdownlist,
.k-combobox,
.k-datepicker,
.k-timepicker,
.k-datetimepicker,
.k-input:not(.k-textarea):not(.k-multiselect),
.k-picker {
    border-radius: var(--r) !important;
    border-color: var(--line) !important;
    min-height: 36px !important;
    height: 36px !important;
    box-sizing: border-box !important;
}

/* Multiselezione: parte dell'altezza di un campo singolo ma si allunga
   quando i valori scelti vanno a capo. */
.k-multiselect {
    border-radius: var(--r) !important;
    border-color: var(--line) !important;
    min-height: 36px !important;
    height: auto !important;
    box-sizing: border-box !important;
}

/* Area di testo: l'altezza la decidono le righe richieste. */
.k-textarea {
    border-radius: var(--r) !important;
    border-color: var(--line) !important;
    height: auto !important;
    min-height: 0 !important;
}
.k-textarea .k-input-inner {
    height: auto !important;
    min-height: 0 !important;
    padding: 8px 10px !important;
    line-height: 1.5 !important;
    resize: vertical;
}

.user-password {
    height: 36px !important;
}

.k-dropdown-wrap,
.k-picker-wrap,
.k-dropdownlist .k-input-inner,
.k-dropdown .k-input-inner,
.k-combobox .k-input-inner,
.k-datepicker .k-input-inner,
.k-textbox .k-input-inner {
    min-height: 34px !important;
    height: 34px !important;
    box-sizing: border-box !important;
    font-size: 0.875rem !important;
    line-height: 1.5 !important;
    font-family: var(--font-ui) !important;
    font-weight: 400 !important;
}

.k-combobox .k-input-button,
.k-combobox .k-clear-value,
.k-dropdownlist .k-input-button,
.k-datepicker .k-input-button {
    min-height: 34px !important;
    height: 34px !important;
    width: 30px !important;
    padding: 0 !important;
}

.k-combobox .k-input-button .k-icon,
.k-combobox .k-clear-value .k-icon,
.k-dropdownlist .k-input-button .k-icon,
.k-dropdownlist .k-clear-value .k-icon {
    font-size: 1rem !important;
}

.k-input:hover,
.k-textbox:hover,
.k-dropdown:hover,
.k-dropdownlist:hover,
.k-combobox:hover {
    border-color: var(--md-ref-palette-neutral10) !important;
}

.k-input:focus,
.k-input.k-focus,
.k-textbox:focus,
.k-dropdown.k-focus,
.k-dropdownlist.k-focus,
.k-combobox.k-focus {
    border-color: var(--btn-primary) !important;
    box-shadow: none !important;
}

/* Dropdown popup */
.k-popup,
.k-list-container {
    border-radius: var(--md-sys-shape-corner-medium) !important;
    box-shadow: var(--md-sys-elevation-level3) !important;
    border: 1px solid var(--md-sys-color-outline-variant) !important;
}

.k-list-item:hover,
.k-list-item.k-hover {
    background: var(--md-sys-color-surface-container-highest) !important;
}

.k-list-item.k-selected {
    background: var(--md-sys-color-primary-container) !important;
    color: var(--md-sys-color-on-primary-container) !important;
}

/* ========================================
   Telerik Buttons
   ======================================== */
.k-button {
    border-radius: var(--md-sys-shape-corner-full) !important;
    font: var(--md-sys-typescale-label-large) !important;
    transition: all var(--md-sys-motion-duration-short4) var(--md-sys-motion-easing-standard) !important;
}

.k-button.k-primary,
.k-button.k-button-solid-primary {
    background: var(--btn-primary) !important;
    border-color: var(--btn-primary) !important;
    color: var(--btn-on-primary) !important;
    border-radius: var(--md-sys-shape-corner-full) !important;
}

.k-button.k-primary:hover,
.k-button.k-button-solid-primary:hover {
    background: var(--btn-primary-hover) !important;
    border-color: var(--btn-primary-hover) !important;
}

/* ========================================
   Telerik Dialog
   ======================================== */
.k-dialog,
.k-window {
    border-radius: var(--md-sys-shape-corner-extra-large) !important;
    box-shadow: var(--md-sys-elevation-level5) !important;
    background: var(--md-sys-color-surface-container-high) !important;
}

.k-dialog-titlebar,
.k-window-titlebar {
    background: transparent !important;
    border: none !important;
    padding: 24px 24px 16px !important;
    font: var(--md-sys-typescale-headline-small) !important;
}

.k-dialog-content,
.k-window-content {
    padding: 0 24px !important;
}

.k-dialog-buttongroup,
.k-dialog-actions {
    padding: 24px !important;
    border: none !important;
    gap: 8px !important;
}

/* Notification */
.k-notification {
    border-radius: var(--md-sys-shape-corner-medium) !important;
    box-shadow: var(--md-sys-elevation-level3) !important;
}

/* ========================================
   Permissions & Checkbox Lists
   ======================================== */
.permissions-list,
.checkbox-list {
    max-height: 400px;
    overflow-y: auto;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    padding: 12px;
    background: #f8fafc;
}

.permission-item,
.checkbox-item {
    display: flex;
    align-items: center;
    padding: 8px 0;
    border-bottom: 1px solid #e2e8f0;
}

.permission-item:last-child,
.checkbox-item:last-child {
    border-bottom: none;
}

/* Supplier/phase lists for macro level */
.supplier-list, .phase-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-height: 340px;
    overflow: auto;
    padding: 12px;
    border-radius: var(--md-sys-shape-corner-medium);
    background: var(--md-sys-color-surface-container-low);
    border: 1px solid var(--md-sys-color-outline-variant);
}

.supplier-item, .phase-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    border-radius: var(--md-sys-shape-corner-small);
    font-size: 0.9rem;
    transition: background 200ms;
}

.supplier-item:hover, .phase-item:hover {
    background: var(--md-sys-color-surface-container-highest);
}

/* ========================================
   Tracking Page
   ======================================== */
.timer-card {
    background: var(--md-sys-color-surface-container-low);
    border-radius: var(--md-sys-shape-corner-extra-large);
    box-shadow: var(--md-sys-elevation-level1);
}

.timer-card.active {
    background: var(--md-sys-color-success-container);
    border: 2px solid var(--md-sys-color-success);
}

.timer-card.paused {
    background: var(--md-sys-color-warning-container);
    border: 2px solid var(--md-sys-color-warning);
}

.timer-value {
    font: var(--md-sys-typescale-headline-large);
    font-size: 3rem;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
}

.input-card,
.product-info-card,
.actions-card {
    background: var(--md-sys-color-surface-container-low);
    border-radius: var(--md-sys-shape-corner-medium);
    box-shadow: var(--md-sys-elevation-level1);
}

/* Delete confirmation dialog */
.delete-confirm-content {
    text-align: center;
    padding: 16px 0;
}

.warning-icon {
    font-size: 4rem;
    color: var(--md-sys-color-warning);
    margin-bottom: 20px;
}

.delete-confirm-content p {
    margin: 0;
    font: var(--md-sys-typescale-body-large);
    color: var(--md-ref-palette-neutral30);
}

.user-to-delete {
    margin-top: 12px !important;
    color: var(--md-ref-palette-neutral10) !important;
}

/* ========================================
   Breadcrumb
   ======================================== */
.breadcrumb {
    height: 48px;
    padding: 0 16px;
    background-color: var(--md-sys-color-surface-container);
    margin-bottom: 0;
    display: flex;
    align-items: center;
    border-radius: var(--md-sys-shape-corner-small);
}

/* ========================================
   Utility Classes
   ======================================== */

.wrap-lines {
    white-space: pre-line;
}

.m3-grid .btn-icon {
    margin: 0 auto;
}
.mb-3 { margin-bottom: 1rem; }
.my-4 { margin-top: 1.5rem; margin-bottom: 1.5rem; }
.py-4 { padding-top: 1.5rem; padding-bottom: 1.5rem; }
.text-center { text-align: center; }
.me-1 { margin-right: 0.25rem; }
.ms-2 { margin-left: 0.5rem; }

.m3-surface { background: var(--md-sys-color-surface); }
.m3-surface-container { background: var(--md-sys-color-surface-container); }
.m3-text-primary { color: var(--btn-primary); }
.m3-text-error { color: var(--md-sys-color-error); }
.m3-text-success { color: var(--md-sys-color-success); }

.m3-elevation-1 { box-shadow: var(--md-sys-elevation-level1); }
.m3-elevation-2 { box-shadow: var(--md-sys-elevation-level2); }
.m3-elevation-3 { box-shadow: var(--md-sys-elevation-level3); }

.m3-rounded-small { border-radius: var(--md-sys-shape-corner-small); }
.m3-rounded-medium { border-radius: var(--md-sys-shape-corner-medium); }
.m3-rounded-large { border-radius: var(--md-sys-shape-corner-large); }
.m3-rounded-full { border-radius: var(--md-sys-shape-corner-full); }

/* ========================================
   Scrollbar
   ======================================== */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--md-sys-color-outline-variant);
    border-radius: var(--md-sys-shape-corner-full);
}

::-webkit-scrollbar-thumb:hover {
    background: var(--md-sys-color-outline);
}

/* Selection */
::selection {
    background: var(--md-sys-color-primary-container);
    color: var(--md-sys-color-on-primary-container);
}

/* ========================================
   Tiles override (ensure not overridden by button styles)
   ======================================== */
.tiles-grid .tile,
.tiles-grid .tile-modern {
    display: flex !important;
    align-items: center !important;
    justify-content: flex-start !important;
    gap: 16px !important;
    padding: 22px 18px !important;
    background: var(--btn-primary) !important;
    border-radius: 20px !important;
    border: none !important;
    text-decoration: none !important;
    transition: all var(--md-sys-motion-duration-medium2) var(--md-sys-motion-easing-emphasized) !important;
    box-shadow: var(--md-sys-elevation-level2) !important;
    min-height: 120px !important;
    text-align: left !important;
}

.tiles-grid .tile:hover,
.tiles-grid .tile-modern:hover {
    background: var(--btn-primary-hover) !important;
    box-shadow: var(--md-sys-elevation-level4) !important;
    transform: translateY(-1px) !important;
}

.tiles-grid .tile .tile-icon,
.tiles-grid .tile-modern .tile-icon,
.tiles-grid .tile .tile-icon-modern,
.tiles-grid .tile-modern .tile-icon-modern {
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    width: 56px !important;
    height: 56px !important;
    min-width: 56px !important;
    background: rgba(255, 255, 255, 0.2) !important;
    border-radius: 12px !important;
    color: white !important;
    font-size: 2rem !important;
}

.tiles-grid .tile .tile-content,
.tiles-grid .tile-modern .tile-content {
    display: flex !important;
    flex-direction: column !important;
    align-items: flex-start !important;
    text-align: left !important;
}

.tiles-grid .tile .tile-content h3,
.tiles-grid .tile-modern .tile-content h3 {
    margin: 0 0 4px 0 !important;
    font: 600 1.32rem/1.58rem 'Inter', system-ui, sans-serif !important;
    color: white !important;
    text-align: left !important;
}

.tiles-grid .tile .tile-content p,
.tiles-grid .tile-modern .tile-content p {
    margin: 0 !important;
    font: 400 1.05rem/1.40rem 'Inter', system-ui, sans-serif !important;
    color: rgba(255, 255, 255, 0.9) !important;
    text-align: left !important;
}

/* Tile disabilitato (modulo non ancora attivo) */
.tiles-grid .tile-disabled {
    background: #6b7280 !important;
    border-color: #4b5563 !important;
    opacity: 0.65;
    cursor: default;
    pointer-events: none;
    position: relative;
}

.tiles-grid .tile-disabled:hover {
    transform: none !important;
    box-shadow: none !important;
}

.tiles-grid .tile-disabled .tile-icon-modern {
    background: rgba(255, 255, 255, 0.15) !important;
}

.tiles-grid .tile-disabled .tile-content h3,
.tiles-grid .tile-disabled .tile-content p {
    color: rgba(255, 255, 255, 0.7) !important;
}

.tile-badge {
    position: absolute;
    top: 8px;
    right: 8px;
    background: #f59e0b;
    color: #1f2937;
    font-size: 0.7rem;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: 4px;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

/* ========================================
   Responsive
   ======================================== */
@media (max-width: 992px) {
    .filter-item {
        min-width: 140px;
        max-width: none;
        flex: 1 1 calc(50% - 16px);
    }

    .filter-actions {
        width: 100%;
        justify-content: flex-end;
        margin-top: 8px;
    }
}

@media (max-width: 768px) {
    .filters-row {
        flex-direction: column;
        align-items: stretch;
    }
}

@media (max-width: 576px) {
    .page-header {
        flex-direction: column;
        align-items: stretch;
        gap: 12px;
    }

    .header-left {
        flex-direction: column;
        align-items: flex-start;
        gap: 8px;
    }

    .filter-item {
        flex: 1 1 100%;
        max-width: none;
    }

    .btn-add {
        width: 100%;
        justify-content: center;
    }

    .filters-card {
        padding: 16px;
    }
}

@media (max-width: 480px) {
    .login-wrapper {
        padding: 32px 16px;
    }

    .login-logo img {
        height: 44px;
    }

    .login-footer {
        padding: 16px;
        flex-direction: column;
        gap: 12px;
        text-align: center;
    }

    .login-links {
        flex-direction: column;
        align-items: center;
        gap: 12px;
    }
}

/* ========================================
   Custom Notifications - Snackbar Style
   ======================================== */
.custom-notification .k-notification {
    min-width: 320px;
    max-width: 568px;
    padding: 16px 24px !important;
    border-radius: var(--md-sys-shape-corner-medium) !important;
    box-shadow: var(--md-sys-elevation-level4) !important;
    border: none !important;
    font: var(--md-sys-typescale-body-large) !important;
    display: flex !important;
    align-items: center !important;
    gap: 12px !important;
}

.custom-notification .k-notification-content {
    font-size: 1rem !important;
    line-height: 1.5 !important;
    font-weight: 500 !important;
    padding: 0 !important;
}

/* Success notification */
.custom-notification .k-notification-success {
    background: var(--md-sys-color-success) !important;
    color: white !important;
    border-left: 4px solid #15803d !important;
}

.custom-notification .k-notification-success::before {
    content: "\f058";
    font-family: "bootstrap-icons";
    font-size: 1.5rem;
    margin-right: 8px;
}

/* Error notification */
.custom-notification .k-notification-error {
    background: var(--md-sys-color-error) !important;
    color: white !important;
    border-left: 4px solid #991b1b !important;
}

.custom-notification .k-notification-error::before {
    content: "\f057";
    font-family: "bootstrap-icons";
    font-size: 1.5rem;
    margin-right: 8px;
}

/* Warning notification */
.custom-notification .k-notification-warning {
    background: var(--md-sys-color-warning) !important;
    color: #1e293b !important;
    border-left: 4px solid #ca8a04 !important;
}

.custom-notification .k-notification-warning::before {
    content: "\f071";
    font-family: "bootstrap-icons";
    font-size: 1.5rem;
    margin-right: 8px;
}

/* Info notification */
.custom-notification .k-notification-info {
    background: var(--md-sys-color-info) !important;
    color: white !important;
    border-left: 4px solid #0369a1 !important;
}

.custom-notification .k-notification-info::before {
    content: "\f05a";
    font-family: "bootstrap-icons";
    font-size: 1.5rem;
    margin-right: 8px;
}

/* Animation for notification appearance */
@keyframes slideInRight {
    from {
        transform: translateX(100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

@keyframes slideOutRight {
    from {
        transform: translateX(0);
        opacity: 1;
    }
    to {
        transform: translateX(100%);
        opacity: 0;
    }
}

.custom-notification .k-notification {
    animation: slideInRight 0.3s var(--md-sys-motion-easing-emphasized) !important;
}

.custom-notification .k-notification.k-notification-hide {
    animation: slideOutRight 0.2s var(--md-sys-motion-easing-standard) !important;
}

/* ========================================
   Tracking Supplier - Station Cards
   ======================================== */
.station-workstation {
    margin-top: 4px;
    line-height: 1.4;
}

.station-workstation .workstation-group {
    font-size: 0.9rem;
    color: var(--md-sys-color-on-surface-variant);
    font-weight: 400;
}

.station-workstation .workstation-name {
    font-size: 1.15rem;
    font-weight: 700;
    color: var(--md-sys-color-primary);
    margin-left: 4px;
}

.station-phases {
    margin-top: 6px;
    color: var(--md-sys-color-outline);
    font-size: 0.85rem;
    line-height: 1.3;
}

/* ========================================
   Info Box (Item -> Work Instructions link)
   ======================================== */
.work-instructions-link-section {
    margin-top: 24px;
}

.info-box {
    display: flex;
    align-items: center;
    gap: 20px;
    padding: 20px 24px;
    background: var(--md-sys-color-surface-container);
    border-radius: var(--md-sys-shape-corner-large);
    border-left: 4px solid var(--md-sys-color-primary);
    box-shadow: var(--md-sys-elevation-level1);
}

.info-box .info-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 56px;
    height: 56px;
    min-width: 56px;
    background: var(--md-sys-color-primary-container);
    color: var(--md-sys-color-primary);
    border-radius: var(--md-sys-shape-corner-medium);
    font-size: 1.8rem;
}

.info-box .info-content {
    flex: 1;
}

.info-box .info-content h4 {
    margin: 0 0 4px 0;
    font: var(--md-sys-typescale-title-medium);
    color: var(--md-ref-palette-neutral10);
}

.info-box .info-content p {
    margin: 0;
    font: var(--md-sys-typescale-body-medium);
    color: var(--md-sys-color-outline);
}

.info-box .info-action {
    flex-shrink: 0;
}

/* ========================================
   Main Content - Station Page (detailed)
   ======================================== */
.station-details-page {
    display: flex;
    flex-direction: column;
    gap: 24px;
}

.station-details-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
}

.station-details-header h1 {
    margin: 0;
    font: var(--md-sys-typescale-headline-medium);
    color: var(--md-ref-palette-neutral10);
}

.station-details-header .record-count {
    font: var(--md-sys-typescale-label-large);
    color: var(--md-sys-color-outline);
    background: var(--md-sys-color-surface-container-highest);
    padding: 6px 14px;
    border-radius: var(--md-sys-shape-corner-full);
}

.station-info-cards {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 16px;
}

.station-info-card {
    background: var(--md-sys-color-surface-container-low);
    border-radius: var(--md-sys-shape-corner-large);
    padding: 16px;
    box-shadow: var(--md-sys-elevation-level1);
}

.station-info-card h3 {
    margin: 0 0 8px 0;
    font: var(--md-sys-typescale-title-small);
    color: var(--md-ref-palette-neutral10);
}

.station-info-card p {
    margin: 0;
    font: var(--md-sys-typescale-body-medium);
    color: var(--md-sys-color-outline);
}

/* Expandable details section */
.station-details-content {
    background: var(--md-sys-color-surface);
    border-radius: var(--md-sys-shape-corner-medium);
    padding: 16px;
    box-shadow: var(--md-sys-elevation-level1);
    margin-top: 8px;
}

.details-section {
    margin: 0;
    padding: 0;
    list-style: none;
}

.details-section li {
    padding: 8px 0;
    border-bottom: 1px solid var(--md-sys-color-outline-variant);
}

.details-section li:last-child {
    border-bottom: none;
}

/* Toggle button for details */
.details-toggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    cursor: pointer;
    padding: 12px 16px;
    border-radius: var(--md-sys-shape-corner-medium);
    background: var(--md-sys-color-surface-container-low);
    transition: background var(--md-sys-motion-duration-short4);
}

.details-toggle:hover {
    background: var(--md-sys-color-surface-container-highest);
}

.details-toggle i {
    margin-left: 8px;
    transition: transform var(--md-sys-motion-duration-short4);
}

.details-toggle.expanded i {
    transform: rotate(180deg);
}

/* Button Delete BOM - Circolare e pi� largo */
.btn-delete-bom {
    min-width: 45px;
    width: 45px;
    padding: 0 !important;
    border-radius: 50% !important;
    display: flex;
    align-items: center;
    justify-content: center;
}

    .btn-delete-bom i {
        font-size: 18px;
    }

/* ========================================
   BOM ACTIVE BADGE
   ======================================== */
.badge-bom-active {
    display: inline-flex;
    align-items: center;
    padding: 3px 10px;
    border-radius: 12px;
    font-weight: 600;
    font-size: 0.78rem;
    background-color: #e8f5e9;
    color: #2e7d32;
    white-space: nowrap;
}

/* ========================================
   ORDER STATUS BADGES
   ======================================== */
.badge-status {
    display: inline-block;
    padding: 4px 12px;
    border-radius: 12px;
    font-weight: 600;
    font-size: 0.85rem;
    text-align: center;
}

.badge-status.status-todo {
    background-color: #e3f2fd;
    color: #1565c0;
}

.badge-status.status-inprogress {
    background-color: #ff9800;
    color: #fff;
}

.badge-status.status-completed {
    background-color: #43a047;
    color: #fff;
}

.badge-status.status-forceclosed {
    background-color: #ef6c00;
    color: #fff;
}

/* ========================================
   ORDER VIEW BUTTON (eye icon)
   ======================================== */
.btn-icon.btn-view {
    color: #1976d2;
}

.btn-icon.btn-view:hover {
    color: #0d47a1;
    background-color: #e3f2fd;
}

/* ========================================
   PRODUCTS GRID - Row Colors by Status
   ======================================== */

/* In Lavorazione - Celeste chiaro */
.products-grid tbody tr.row-product-working {
    background-color: #e1f5fe !important;
}

.products-grid tbody tr.row-product-working:hover {
    background-color: #b3e5fc !important;
}

/* Prossima Stazione (completato su una WS, deve andare su un'altra) - Lilla */
.products-grid tbody tr.row-product-next-ws {
    background-color: #ede7f6 !important;
}

.products-grid tbody tr.row-product-next-ws:hover {
    background-color: #d1c4e9 !important;
}

/* In Pausa - Giallo */
.products-grid tbody tr.row-product-paused {
    background-color: #fff9c4 !important;
}

.products-grid tbody tr.row-product-paused:hover {
    background-color: #fff59d !important;
}

/* Errore - Rosso */
.products-grid tbody tr.row-product-error {
    background-color: #ffcdd2 !important;
}

.products-grid tbody tr.row-product-error:hover {
    background-color: #ef9a9a !important;
}

/* Completato - Verde */
.products-grid tbody tr.row-product-completed {
    background-color: #c8e6c9 !important;
}

.products-grid tbody tr.row-product-completed:hover {
    background-color: #a5d6a7 !important;
}

/* ========================================
   PRODUCT STATUS BADGES
   ======================================== */
.badge-product-status {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 10px;
    font-weight: 600;
    font-size: 0.8rem;
    white-space: nowrap;
}

.badge-product-status.badge-todo {
    background-color: #eceff1;
    color: #546e7a;
}

.badge-product-status.badge-working {
    background-color: #039be5;
    color: #fff;
}

.badge-product-status.badge-next-ws {
    background-color: #7e57c2;
    color: #fff;
}

.badge-product-status.badge-paused {
    background-color: #fbc02d;
    color: #333;
}

.badge-product-status.badge-error {
    background-color: #e53935;
    color: #fff;
}

.badge-product-status.badge-completed {
    background-color: #43a047;
    color: #fff;
}

/* ========================================
   SERIAL NUMBER CLICKABLE
   ======================================== */
.serial-clickable {
    cursor: pointer;
    transition: color 0.2s;
}

.serial-clickable:hover {
    color: #1976d2;
    text-decoration: underline;
}

.serial-clickable:hover i {
    opacity: 1 !important;
}

/* ========================================
   SERIAL NUMBER EDIT DIALOG
   ======================================== */
.serial-dialog {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: #fff;
    border-radius: 16px;
    padding: 0;
    width: 400px;
    max-width: 90vw;
    z-index: 1001;
    box-shadow: 0 8px 32px rgba(0,0,0,0.25);
    display: flex;
    flex-direction: column;
}

.serial-dialog-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px;
    border-bottom: 1px solid #e0e0e0;
}

.serial-dialog-header h5 {
    margin: 0;
    font-weight: 700;
    font-size: 1.1rem;
}

.serial-dialog-body {
    padding: 20px;
}

.serial-dialog-footer {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    padding: 12px 20px;
    border-top: 1px solid #e0e0e0;
}

.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.4);
    z-index: 1000;
    backdrop-filter: blur(2px);
}

/* ========================================
   PRODUCT NOTES EDIT DIALOG
   ======================================== */
.notes-dialog {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: #fff;
    border-radius: 16px;
    padding: 0;
    width: 600px;
    max-width: 90vw;
    z-index: 1001;
    box-shadow: 0 8px 32px rgba(0,0,0,0.25);
    display: flex;
    flex-direction: column;
}

.notes-dialog-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px;
    border-bottom: 1px solid #e0e0e0;
}

.notes-dialog-header h5 {
    margin: 0;
    font-weight: 700;
    font-size: 1.1rem;
}

.notes-dialog-body {
    padding: 20px;
}

.notes-dialog-footer {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    padding: 12px 20px;
    border-top: 1px solid #e0e0e0;
}

/* ========================================
   PRODUCT COMPONENTS DIALOG
   ======================================== */
.components-dialog {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: #fff;
    border-radius: 16px;
    padding: 0;
    width: 1000px;
    max-width: 95vw;
    max-height: 90vh;
    z-index: 1001;
    box-shadow: 0 8px 32px rgba(0,0,0,0.25);
    display: flex;
    flex-direction: column;
}

.components-dialog-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px;
    border-bottom: 1px solid #e0e0e0;
}

.components-dialog-header h5 {
    margin: 0;
    font-weight: 700;
    font-size: 1.1rem;
}

.components-dialog-close {
    background: transparent;
    border: none;
    color: #6c757d;
    font-size: 1.1rem;
    line-height: 1;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 50%;
}

.components-dialog-close:hover {
    background: #f0f0f0;
    color: #333;
}

.components-dialog-body {
    padding: 16px 20px;
    overflow-y: auto;
}

.components-dialog-footer {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    padding: 12px 20px;
    border-top: 1px solid #e0e0e0;
}

.components-dialog .cf-control {
    min-height: 56px;
}

/* Annotazioni */
.cf-annotations {
    margin-bottom: 16px;
}

.cf-annotations label {
    display: block;
    font-size: 0.78rem;
    font-weight: 600;
    color: #6c757d;
    margin-bottom: 4px;
}

.cf-annotations-box {
    border: 1px solid #dee2e6;
    border-radius: 6px;
    padding: 8px 10px;
    background: #f8f9fa;
    min-height: 38px;
    white-space: pre-wrap;
}

/* Filtri */
.cf-filters {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: 12px;
    margin-bottom: 16px;
}

.cf-item {
    display: flex;
    flex-direction: column;
    flex: 1 1 220px;
    min-width: 180px;
}

.cf-item-narrow {
    flex: 0 1 160px;
    min-width: 140px;
}

.cf-item label {
    font-size: 0.78rem;
    font-weight: 600;

/* Shipments grid - compact table like Intranet2020 */
.shipments-grid .k-grid-table {
    font-size: 0.78rem;
}
.shipments-grid .k-grid-table th {
    font-size: 0.72rem;
    padding: 4px 6px;
    white-space: nowrap;
}
.shipments-grid .k-grid-table td {
    padding: 2px 6px;
    white-space: nowrap;
}
.shipments-grid .k-checkbox {
    width: 16px !important;
    height: 16px !important;
}
    color: #6c757d;
    margin-bottom: 4px;
}

.cf-control {
    height: 38px;
    border: 1px solid #ced4da;
    border-radius: 6px;
    padding: 6px 10px;
    font-size: 0.9rem;
    font-family: inherit;
    width: 100%;
    background: #fff;
    box-sizing: border-box;
}

.cf-control:focus {
    outline: none;
    border-color: #86b7fe;
    box-shadow: 0 0 0 0.2rem rgba(13,110,253,0.15);
}

.cf-clear {
    height: 56px;
    width: 56px;
    flex: 0 0 auto;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 1px solid #ced4da;
    border-radius: 6px;
    background: #fff;
    color: #6c757d;
    cursor: pointer;
}

.cf-clear i {
    font-size: 1.25rem;
}

.cf-clear:hover {
    background: #f0f0f0;
    color: #dc3545;
}

/* =============================================
   SEZIONE TESORERIA
   ============================================= */

/* Tabella Cash Flow */
.cf-table {
    border-collapse: collapse;
    min-width: 1200px;
    width: 100%;
    font-size: 0.85rem;
}
.cf-table th, .cf-table td {
    padding: 6px 10px;
    white-space: nowrap;
    text-align: right;
}
.cf-table th:first-child, .cf-table td:first-child {
    text-align: left;
}
.cf-header-months th {
    background: var(--md-sys-color-primary);
    color: #000000;
    text-align: center;
    font-weight: 600;
}
.cf-header-decades th {
    background: var(--md-sys-color-surface-container-high);
    text-align: center;
    font-size: 0.8rem;
}
.cf-row-total {
    background: var(--md-sys-color-primary-container);
    font-weight: 700;
}
.cf-row-saldo {
    background: var(--md-sys-color-tertiary-container);
    font-weight: 700;
}
.cf-row-group-header {
    background: var(--md-sys-color-surface-container-high);
    font-weight: 600;
}
.cf-row-detail:nth-child(even) {
    background: var(--md-sys-color-surface-container-low);
}

/* Drillable rows (bank breakdown drill-down) */
.cf-row-drillable {
    cursor: pointer;
}
.cf-row-drillable:hover {
    filter: brightness(0.95);
}
.cf-row-drillable .cf-label-col {
    cursor: pointer;
}
/* Bank breakdown sub-rows */
.cf-row-bank-detail {
    background: #F8FAFC;
}
.cf-row-bank-detail:nth-child(even) {
    background: #F1F5F9;
}
.cf-row-bank-detail .cf-label-col {
    font-size: 0.82rem;
    font-weight: 400;
    color: var(--md-sys-color-on-surface-variant);
}
.cf-cell-positive {
    color: #1A5C1A;
}
.cf-cell-negative {
    color: #C8102E;
}
.cf-cell-zero {
    color: var(--md-sys-color-outline);
}

/* Filtri tesoreria */
.filter-row {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 8px;
    align-items: center;
}
.filter-check {
    display: flex;
    align-items: center;
    gap: 6px;
    white-space: nowrap;
    font-size: 0.875rem;
    cursor: pointer;
}
.filter-disabled {
    opacity: 0.38;
}
.filter-date-group {
    display: flex;
    align-items: center;
    gap: 4px;
}
.filter-action {
    justify-self: end;
}
.filter-checks {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

/* Alternating month columns - per row type */
/* Normal rows */
.cf-row-detail .cf-month-even,
.cf-row-group-header .cf-month-even {
    background-color: #FFFFFF;
}
.cf-row-detail .cf-month-odd,
.cf-row-group-header .cf-month-odd {
    background-color: #F1F5F9;
}
/* Total rows */
.cf-row-total .cf-month-even {
    background-color: #DBEAFE;
}
.cf-row-total .cf-month-odd {
    background-color: #BFDBFE;
}
.cf-scroll-container .cf-table .cf-row-total .cf-scaduto-cell {
    background: #DBEAFE;
}
.cf-scroll-container .cf-table .cf-row-total .cf-label-col {
    background: #DBEAFE;
}
/* Saldo rows */
.cf-row-saldo .cf-month-even {
    background-color: #DBEAFE;
}
.cf-row-saldo .cf-month-odd {
    background-color: #BFDBFE;
}
.cf-scroll-container .cf-table .cf-row-saldo .cf-scaduto-cell {
    background: #DBEAFE;
}
.cf-scroll-container .cf-table .cf-row-saldo .cf-label-col {
    background: #DBEAFE;
}
/* Month header cells (alternating) */
.cf-header-months .cf-month-even,
.cf-header-decades .cf-month-even {
    background-color: #E2E8F0;
}
.cf-header-months .cf-month-odd,
.cf-header-decades .cf-month-odd {
    background-color: #CBD5E1;
}
/* Scroll container with sticky header/footer */
.cf-scroll-container {
    max-height: 68vh;
    overflow: auto;
    border: 1px solid var(--md-sys-color-outline-variant);
    border-radius: 8px;
    background: #FFFFFF;
}
.cf-scroll-container .cf-table thead {
    position: sticky;
    top: 0;
    z-index: 3;
}
.cf-scroll-container .cf-table tfoot {
    position: sticky;
    bottom: 0;
    z-index: 3;
}
/* Make sure label column also sticks */
.cf-scroll-container .cf-table .cf-label-col {
    position: sticky;
    left: 0;
    z-index: 1;
    background: #FFFFFF;
}
.cf-scroll-container .cf-table thead .cf-label-col {
    z-index: 4;
}
.cf-scroll-container .cf-table tfoot .cf-label-col {
    z-index: 4;
    font-weight: 700;
}

/* Table section label */
.cf-table-label {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--md-sys-color-primary);
    padding: 8px 0 4px 0;
    margin-top: 8px;
}
.cf-table thead .cf-month-even,
.cf-table thead .cf-month-odd {
    text-align: center;
}
/* Scaduto and label columns */
.cf-table .cf-scaduto-hdr {
    background: #FFF7ED;
    text-align: center;
    font-size: 0.8rem;
    font-weight: 600;
}
.cf-table .cf-scaduto-cell {
    background: #FFF7ED;
}
.cf-table .cf-total-hdr {
    background: #E0E7FF;
    text-align: center;
    font-size: 0.8rem;
    font-weight: 600;
}
.cf-table .cf-total-cell {
    background: #EEF2FF;
    font-weight: 600;
}
.cf-table .cf-label-col {
    min-width: 260px;
    position: sticky;
    left: 0;
    z-index: 1;
    background: #FFFFFF;
    border-right: 2px solid var(--md-sys-color-outline-variant);
    text-align: left;
    font-weight: 500;
}
.cf-label-indented {
    padding-left: 20px !important;
}
.cf-hdr-label {
    text-align: left;
    font-weight: 600;
    background: var(--md-sys-color-primary);
    color: var(--md-sys-color-on-primary);
}
.cf-table .cf-subhdr {
    text-align: center;
    font-size: 0.78rem;
    font-weight: 400;
    color: var(--md-sys-color-on-surface);
}

/* Righe spostate (manovra) */
.row-spostata {
    background-color: #FEF3C7 !important;
}

/* Split layout: Partite Aperte (left) + Ordini Aperti (right) */
.treasury-split {
    display: flex;
    gap: 12px;
    width: 100%;
}
.treasury-split-left,
.treasury-split-right {
    flex: 1;
    min-width: 0;
}
.treasury-split-left .cf-scroll-container,
.treasury-split-right .cf-scroll-container {
    max-height: 56vh;
}
.treasury-split-left .filter-row,
.treasury-split-right .filter-row {
    grid-template-columns: repeat(4, 1fr);
}

/* Treasury tabs: tighter filter card padding */
.treasury-filters {
    padding: 12px 24px !important;
}

/* Tab navigation */
.treasury-tabs {
    display: flex;
    gap: 4px;
    margin-bottom: 16px;
    border-bottom: 2px solid var(--md-sys-color-outline-variant);
    padding-bottom: 0;
}
.treasury-tab {
    padding: 8px 20px;
    border: none;
    background: transparent;
    cursor: pointer;
    font-weight: 500;
    color: var(--md-sys-color-on-surface-variant);
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    transition: all 0.2s;
}
.treasury-tab:hover {
    color: var(--md-sys-color-on-surface);
}
.treasury-tab.active {
    color: var(--md-sys-color-primary);
    border-bottom-color: var(--md-sys-color-primary);
}

/* Manovra panel */
.manovra-panel {
    display: flex;
    gap: 16px;
    align-items: flex-end;
    flex-wrap: wrap;
    padding: 12px 16px;
    background: var(--md-sys-color-surface-container-low);
    border-radius: 8px;
    margin-bottom: 12px;
}
.manovra-actions {
    display: flex;
    gap: 8px;
}

/* Compact button for filter row */
.btn-small-nowrap {
    white-space: nowrap !important;
    flex-shrink: 0;
}

/* Small round icon button (e.g. "latest elaboration" reset) */
.btn-icon-circle {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: 1px solid var(--md-sys-color-outline);
    background: var(--md-sys-color-surface);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    color: var(--md-sys-color-on-surface);
    font-size: 0.85rem;
    transition: background 0.15s;
}
.btn-icon-circle:hover {
    background: var(--md-sys-color-surface-container-highest);
}

/* Drag & Drop move cell highlight */
.cf-cell-moved-from {
    background-color: #DBEAFE !important;
    outline: 2px dashed #3B82F6 !important;
    outline-offset: -2px;
}
.cf-cell-moved-fwd {
    background-color: #DCFCE7 !important;
    outline: 2px dashed #22C55E !important;
    outline-offset: -2px;
}
.cf-cell-moved-bwd {
    background-color: #DBEAFE !important;
    outline: 2px dashed #3B82F6 !important;
    outline-offset: -2px;
}
.cf-cell-moved-to {
    background-color: #DCFCE7 !important;
    outline: 2px dashed #22C55E !important;
    outline-offset: -2px;
}

/* Selected source cell for click-to-move */
.cf-cell-selected {
    outline: 3px solid var(--md-sys-color-primary) !important;
    outline-offset: -3px;
}

/* Today's loaded maneuvers: blue border + light bg */
.cf-cell-maneuver-today {
    box-shadow: inset 0 0 0 2px #1E40AF !important;
    background-color: #EFF6FF !important;
}
.cf-cell-maneuver-from {
    text-decoration: line-through;
    opacity: 0.7;
}

/* Manual Data dialog */
.manual-data-dialog .k-window-content {
    max-height: 70vh;
    overflow-y: auto;
}

/* Cell detail popup */
.cell-detail-dialog .k-window-content {
    max-height: 75vh;
    overflow: hidden;
}
.cell-detail-table {
    min-width: 700px;
    font-size: 0.82rem;
}
.cell-detail-table thead th {
    background: var(--md-sys-color-surface-container-high);
    font-weight: 600;
    font-size: 0.78rem;
    position: sticky;
    top: 0;
    z-index: 1;
}
.cell-detail-table tbody tr:nth-child(even) {
    background: var(--md-sys-color-surface-container-low);
}
.cell-detail-table td {
    padding: 4px 8px;
}


/* ========================================
   Griglie e controlli Telerik: aspetto "sala controllo"
   In fondo al foglio di proposito: queste regole devono vincere su quelle
   piu' vecchie e specifiche scritte per il tema precedente.
   ======================================== */
.k-grid {
    border: 1px solid var(--line) !important;
    border-radius: var(--r) !important;
    background: var(--card-bg) !important;
    font-family: var(--font-ui) !important;
}

.k-grid .k-grid-header,
.k-grid .k-grid-header-wrap,
.k-grid .k-grid-header th {
    background: var(--md-sys-color-surface-container) !important;
    border-color: var(--line) !important;
}

/* Intestazioni in maiuscoletto: si distinguono dai dati senza usare grassetti pesanti */
.k-grid .k-grid-header th,
.k-grid .k-grid-header th .k-link,
.k-grid .k-table-thead .k-table-th {
    font: var(--md-sys-typescale-label-small) !important;
    text-transform: uppercase !important;
    letter-spacing: 0.07em !important;
    color: var(--ink-2) !important;
    padding-top: 7px !important;
    padding-bottom: 7px !important;
}

.k-grid td,
.k-grid .k-table-td {
    border-color: var(--line-soft) !important;
    color: var(--ink) !important;
}

.k-grid tbody tr:hover td,
.k-grid .k-table-row:hover > td {
    background: #f2fbfa !important;
}

.k-grid tbody tr.k-selected td,
.k-grid .k-table-row.k-selected > td {
    background: var(--accent-soft) !important;
    color: var(--accent-deep) !important;
}

/* Numeri incolonnati: la lettura di una colonna di importi e' il 90% del lavoro */
.k-grid td.k-table-td[style*="text-align: right"],
.k-grid .text-end,
.k-grid .num {
    font-variant-numeric: tabular-nums;
}

.k-pager,
.k-grid .k-pager-wrap {
    background: var(--md-sys-color-surface-container) !important;
    border-top: 1px solid var(--line) !important;
    color: var(--ink-2) !important;
    font: var(--md-sys-typescale-body-small) !important;
}

/* --- campi e bottoni --- */
.k-input,
.k-picker,
.k-textbox,
.k-combobox,
.k-dropdownlist,
.k-datepicker,
.k-numerictextbox {
    border-radius: var(--r) !important;
    border-color: var(--line) !important;
    font-family: var(--font-ui) !important;
}

.k-input:focus-within,
.k-picker:focus-within,
.k-input.k-focus,
.k-picker.k-focus {
    border-color: var(--accent) !important;
    box-shadow: 0 0 0 3px rgba(var(--accent-rgb), 0.14) !important;
}

.k-button {
    border-radius: 5px !important;
    font-family: var(--font-ui) !important;
    font-weight: 550 !important;
}

.k-button-solid-base {
    background: #fff !important;
    border-color: var(--line) !important;
    color: var(--ink) !important;
}
.k-button-solid-base:hover {
    background: var(--md-sys-color-surface-container) !important;
    border-color: var(--md-ref-palette-neutral80) !important;
}

/* --- finestre e menu --- */
.k-window,
.k-dialog,
.k-animation-container .k-popup,
.k-menu-popup {
    border-radius: var(--r) !important;
    border-color: var(--line) !important;
    box-shadow: var(--md-sys-elevation-level4) !important;
}

.k-window-titlebar,
.k-dialog-titlebar {
    background: var(--nav-bg) !important;
    color: #fff !important;
    border-bottom: 0 !important;
    padding: 10px 14px !important;
}
.k-window-title,
.k-dialog-title {
    font: var(--md-sys-typescale-title-small) !important;
}

/* --- barre di sezione delle pagine (Tesoreria, CFO) --- */
.treasury-tabs,

.treasury-tab,
.treasury-tab:hover,
.cfo-tab:hover { background: rgba(255, 255, 255, 0.7); color: var(--ink); }

.treasury-tab.active,
.cfo-tab.active {
    background: var(--card-bg);
    color: var(--accent-deep);
    box-shadow: var(--md-sys-elevation-level1);
}

/* --- intestazione di pagina --- */
.page-header h1 {
    font: var(--md-sys-typescale-headline-small) !important;
    display: flex;
    align-items: center;
    gap: 10px;
}
.page-header h1 > i { color: var(--accent-strong); font-size: 1.125rem; }

/* ========================================
   Pagine di lavoro: gestione notifiche, messaggi
   ======================================== */
.work-page { width: 100%; }

/* Il filtro con la spunta deve stare in linea con i campi accanto */
.filter-item-check { display: flex; align-items: center; }
.filter-item-check label {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font: var(--md-sys-typescale-body-small);
    color: var(--ink-2);
    white-space: nowrap;
    cursor: pointer;
}

/* Due righe in una cella: titolo e sottotitolo */
.cell-stack { display: grid; gap: 1px; }
.cell-stack strong { font: var(--md-sys-typescale-label-large); }
.cell-stack small {
    font: var(--md-sys-typescale-body-small);
    color: var(--ink-3);
    display: block;
    max-width: 60ch;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.sev-badge {
    display: inline-block;
    white-space: nowrap;
    padding: 2px 8px;
    border-radius: 3px;
    font: var(--md-sys-typescale-label-small);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}
.sev-badge.sev-info { background: var(--accent-soft); color: var(--accent-deep); }
.sev-badge.sev-warning { background: var(--md-sys-color-warning-container); color: var(--md-sys-color-warning); }
.sev-badge.sev-critical { background: var(--md-sys-color-error-container); color: var(--md-sys-color-error); }

.text-late { color: var(--md-sys-color-error); font-weight: 600; }

/* Righe della griglia: completate smorzate, scadute segnalate */
.k-grid tr.row-done td { opacity: 0.55; }
.k-grid tr.row-late td { background: #fff8f7 !important; }

/* --- moduli nei dialog --- */
.form-grid { display: grid; gap: 14px; }
.form-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 14px; }
.form-field { display: grid; gap: 4px; min-width: 0; }
.form-field > label {
    font: var(--md-sys-typescale-label-medium);
    color: var(--ink-2);
}
.field-hint { font: var(--md-sys-typescale-body-small); color: var(--ink-3); }
.form-error {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 9px 12px;
    border-radius: 5px;
    background: var(--md-sys-color-error-container);
    color: var(--md-sys-color-error);
    font: var(--md-sys-typescale-body-small);
}

/* ========================================
   Messaggistica interna
   ======================================== */
/* Tre colonne: cartelle, elenco, lettura. Il riquadro di lettura prende lo
   spazio che resta, cosi' su schermi larghi si legge senza righe strette. */
.mail-layout {
    display: grid;
    grid-template-columns: 220px minmax(300px, 380px) minmax(0, 1fr);
    gap: 14px;
    align-items: stretch;
    min-height: 60vh;
}

.mail-folders {
    display: flex;
    flex-direction: column;
    gap: 3px;
    padding: 10px;
    background: var(--card-bg);
    border: 1px solid var(--line);
    border-radius: var(--r);
    align-self: start;
}

.mail-folder {
    display: flex;
    align-items: center;
    gap: 9px;
    padding: 9px 10px;
    border: 0;
    border-radius: 5px;
    background: transparent;
    color: var(--ink-2);
    cursor: pointer;
    font: var(--md-sys-typescale-label-large);
    text-align: left;
}
.mail-folder:hover { background: var(--md-sys-color-surface-container); color: var(--ink); }
.mail-folder.is-active {
    background: var(--accent-soft);
    color: var(--accent-deep);
}
.mail-folder > span:first-of-type { flex: 1; }

.mail-badge {
    min-width: 20px;
    padding: 1px 6px;
    border-radius: 999px;
    background: var(--md-sys-color-error);
    color: #fff;
    font: var(--md-sys-typescale-label-small);
    text-align: center;
}

.mail-filter {
    display: grid;
    gap: 8px;
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px solid var(--line-soft);
}
.mail-check {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font: var(--md-sys-typescale-body-small);
    color: var(--ink-2);
    cursor: pointer;
}

.mail-list {
    background: var(--card-bg);
    border: 1px solid var(--line);
    border-radius: var(--r);
    overflow-y: auto;
    max-height: 72vh;
}

.mail-row {
    display: grid;
    gap: 2px;
    padding: 11px 13px;
    border-bottom: 1px solid var(--line-soft);
    border-left: 3px solid transparent;
    cursor: pointer;
}
.mail-row:last-child { border-bottom: 0; }
.mail-row:hover { background: var(--md-sys-color-surface-container); }
.mail-row.is-selected { border-left-color: var(--accent); background: var(--accent-soft); }
.mail-row.is-unread .mail-subject { font-weight: 700; }
.mail-row.is-unread .mail-who { color: var(--ink); font-weight: 600; }

.mail-row-top { display: flex; justify-content: space-between; gap: 8px; }
.mail-who {
    font: var(--md-sys-typescale-label-medium);
    color: var(--ink-2);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.mail-when { font: var(--md-sys-typescale-label-small); color: var(--ink-3); flex: 0 0 auto; }
.mail-subject {
    font: var(--md-sys-typescale-label-large);
    color: var(--ink);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.mail-preview {
    font: var(--md-sys-typescale-body-small);
    color: var(--ink-3);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.mail-reader {
    background: var(--card-bg);
    border: 1px solid var(--line);
    border-radius: var(--r);
    display: flex;
    flex-direction: column;
    min-height: 300px;
}

.mail-head {
    padding: 16px 18px;
    border-bottom: 1px solid var(--line-soft);
}
.mail-head h2 { margin: 0 0 8px; font: var(--md-sys-typescale-title-medium); }
.mail-head-meta {
    display: flex;
    gap: 16px;
    flex-wrap: wrap;
    font: var(--md-sys-typescale-body-small);
    color: var(--ink-2);
}
.mail-head-meta strong { color: var(--ink-3); font-weight: 550; }
.mail-head-actions { display: flex; gap: 8px; margin-top: 12px; }

/* Il testo arriva da una textarea: gli invii vanno rispettati */
.mail-body {
    flex: 1;
    padding: 18px;
    white-space: pre-wrap;
    font: var(--md-sys-typescale-body-medium);
    color: var(--ink);
    overflow-y: auto;
}

@media (max-width: 1200px) {
    .mail-layout { grid-template-columns: 200px minmax(0, 1fr); }
    .mail-reader { grid-column: 1 / -1; }
}

@media (max-width: 900px) {
    .mail-layout { grid-template-columns: minmax(0, 1fr); }
    .mail-list { max-height: 45vh; }
}

/* ========================================
   Dialog: intestazione, corpo, pulsanti
   ======================================== */
.k-dialog-titlebar .k-dialog-titlebar-actions .k-button,
.k-window-titlebar .k-window-titlebar-actions .k-button {
    background: transparent !important;
    border-color: transparent !important;
    color: rgba(255, 255, 255, 0.75) !important;
}
.k-dialog-titlebar .k-dialog-titlebar-actions .k-button:hover,
.k-window-titlebar .k-window-titlebar-actions .k-button:hover {
    background: rgba(255, 255, 255, 0.14) !important;
    color: #fff !important;
}

.k-dialog-content,
.k-window-content { padding: 18px 20px !important; }

/* I pulsanti stanno a destra e larghi quanto il testo.
   La classe del piede e' .k-actions (non .k-dialog-buttongroup), e il
   modificatore .k-actions-stretched e' cio' che li allargava a mezza finestra
   ciascuno. */
.k-dialog-actions,
.k-window-actions,
.k-actions.k-actions-stretched {
    display: flex !important;
    justify-content: flex-end !important;
    gap: 8px !important;
    padding: 12px 20px !important;
    margin: 0 !important;
    border-top: 1px solid var(--line-soft) !important;
    background: var(--md-sys-color-surface-container) !important;
}
.k-dialog-actions > .k-button,
.k-window-actions > .k-button,
.k-actions.k-actions-stretched > .k-button {
    flex: 0 0 auto !important;
    width: auto !important;
    min-width: 118px;
    justify-content: center;
}

/* Pulsanti alti quanto i campi: 28 contro 36 e' lo squilibrio che si notava. */
.k-button-md,
.k-dialog-actions .k-button,
.k-window-actions .k-button,
.page-header .k-button,
.filters-row .k-button,
.form-grid .k-button {
    min-height: 34px !important;
    padding-block: 0 !important;
    padding-inline: 14px !important;
}
.k-button.k-icon-button { padding-inline: 0 !important; }
/* Il pulsante di chiusura in barra titolo resta piccolo */
.k-window-titlebar-actions .k-button { min-height: 24px !important; }

/* --- multiselezione: un solo riquadro, alto come un campo normale --- */
.k-multiselect .k-input-values {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 3px;
    padding: 3px 4px !important;
    min-height: 34px;
}
.k-multiselect .k-input-inner {
    height: 26px !important;
    min-height: 26px !important;
    padding: 0 4px !important;
    border: 0 !important;
    background: transparent !important;
    box-shadow: none !important;
    flex: 1 1 80px;
    min-width: 80px;
}
.k-multiselect .k-chip {
    height: 24px;
    border-radius: 4px;
    background: var(--accent-soft);
    border-color: var(--accent);
    color: var(--accent-deep);
}
.k-multiselect .k-chip .k-chip-content { padding-inline: 6px; }

/* ========================================
   Messaggistica: rifiniture
   ======================================== */
/* Riquadri della giusta altezza: non due grandi vuoti bianchi */
.mail-list { max-height: 64vh; min-height: 220px; }
.mail-reader { min-height: 220px; }
.mail-layout { min-height: 0; align-items: start; }

.mail-list .empty-state,
.mail-reader .empty-state { padding: 48px 20px; }

/* Riga della posta: iniziali del mittente, come in un client di posta */
.mail-row { grid-template-columns: 34px minmax(0, 1fr); align-items: start; column-gap: 10px; }
.mail-row > .mail-avatar { grid-row: 1 / span 3; }
.mail-avatar {
    display: grid;
    place-items: center;
    width: 34px;
    height: 34px;
    border-radius: var(--r);
    background: var(--md-sys-color-surface-container-highest);
    color: var(--ink-2);
    font: var(--md-sys-typescale-label-small);
}
.mail-row.is-unread .mail-avatar { background: var(--accent-soft); color: var(--accent-deep); }
.mail-row.is-selected .mail-avatar { background: #fff; color: var(--accent-deep); }

/* Pallino del non letto accanto all'oggetto */
.mail-dot {
    display: inline-block;
    width: 7px;
    height: 7px;
    border-radius: 999px;
    background: var(--accent);
    margin-right: 6px;
    vertical-align: middle;
}

.mail-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 9px 13px;
    border-bottom: 1px solid var(--line);
    background: var(--md-sys-color-surface-container);
    font: var(--md-sys-typescale-label-small);
    text-transform: uppercase;
    letter-spacing: 0.07em;
    color: var(--ink-3);
}

/* Il messaggio letto: intestazione compatta, corpo che respira */
.mail-head { padding: 14px 18px; }
.mail-head-top { display: flex; align-items: flex-start; gap: 12px; }
.mail-head-top .mail-avatar { width: 40px; height: 40px; font: var(--md-sys-typescale-label-large); }
.mail-head h2 { margin: 0 0 4px; font: var(--md-sys-typescale-title-small); }

.mail-count {
    text-transform: none;
    letter-spacing: 0;
    font: var(--md-sys-typescale-label-small);
    color: var(--ink-3);
}

/* Corpo del messaggio in colonna leggibile, non righe da 900px */
.mail-body { max-width: 78ch; }

/* Fuoco visibile sulle voci di menu.
   Serve anche a difendersi da fogli di terze parti: Bootstrap definisce una
   .nav-link con :focus a specificita' piu' alta, ed e' il motivo per cui le
   classi della barra sono prefissate tx-. */
.tx-nav-link:focus-visible,
.tx-nav-child:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: -2px;
    color: var(--nav-text-strong);
}
.tx-nav-link:focus,
.tx-nav-child:focus { color: var(--nav-text-strong); }
.tx-nav-link.is-active:focus,
.tx-nav-child.is-active:focus { color: #fff; }

/* Anteprima della nota che si sta assegnando */
.assign-preview {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 11px 12px;
    border: 1px solid var(--line);
    border-left: 3px solid var(--accent);
    border-radius: var(--r);
    background: var(--md-sys-color-surface-container);
}
.assign-preview > i { color: var(--accent-deep); margin-top: 2px; }
.assign-preview strong { display: block; font: var(--md-sys-typescale-label-large); }
.assign-preview small { font: var(--md-sys-typescale-body-small); color: var(--ink-2); }


/* ========================================
   Virtual CFO
   Cinque schermate dense. La gerarchia e' sempre la stessa: verdetto in una riga,
   tessere, il grafico piu' grande, i confronti affiancati, le eccezioni in tabella.
   ======================================== */

.cfo {
    display: flex;
    flex-direction: column;
    gap: 14px;
    width: 100%;
}

/* --- barra delle sezioni --- */
.cfo-nav {
    display: flex;
    gap: 2px;
    border-bottom: 1px solid var(--line);
    background: var(--card-bg);
    border: 1px solid var(--line);
    border-radius: 6px;
    padding: 4px;
    overflow-x: auto;
}

.cfo-nav-item {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    padding: 8px 14px;
    border: 0;
    background: transparent;
    border-radius: 4px;
    font: var(--md-sys-typescale-label-large);
    color: var(--ink-2);
    cursor: pointer;
    white-space: nowrap;
    transition: background .12s, color .12s;
}

.cfo-nav-item:hover { background: var(--md-sys-color-surface-container); color: var(--ink); }
.cfo-nav-item.is-active { background: var(--ink); color: #fff; }
.cfo-nav-item.is-active:hover { background: var(--ink); color: #fff; }
.cfo-nav-item > i { font-size: .95rem; }

/* --- intestazione con data del dato --- */
.cfo-head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 16px;
    flex-wrap: wrap;
}

.cfo-head h2 {
    margin: 0;
    font-size: 1.05rem;
    font-weight: 650;
    letter-spacing: -.01em;
    color: var(--ink);
}

.cfo-head .cfo-asof {
    font: var(--md-sys-typescale-label-medium);
    color: var(--ink-3);
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

/* --- riga del verdetto --- */
.cfo-verdict {
    display: flex;
    align-items: flex-start;
    gap: 11px;
    padding: 13px 16px;
    border: 1px solid var(--line);
    border-left: 3px solid var(--accent-strong);
    border-radius: 6px;
    background: var(--card-bg);
    font: var(--md-sys-typescale-body-medium);
    color: var(--ink);
    line-height: 1.5;
}

.cfo-verdict.is-bad { border-left-color: #dc2626; }
.cfo-verdict.is-warning { border-left-color: #d97706; }
.cfo-verdict > i { font-size: 1.05rem; color: var(--accent-deep); margin-top: 1px; }
.cfo-verdict.is-bad > i { color: #dc2626; }
.cfo-verdict.is-warning > i { color: #d97706; }
.cfo-verdict b { font-weight: 650; }

/* --- tessere --- */
.cfo-tiles {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
    gap: 10px;
}

.cfo-tile {
    position: relative;
    display: flex;
    flex-direction: column;
    gap: 5px;
    padding: 13px 15px 14px;
    background: var(--card-bg);
    border: 1px solid var(--line);
    border-radius: 6px;
    text-decoration: none;
    color: inherit;
    transition: border-color .12s, box-shadow .12s;
    overflow: hidden;
}

a.cfo-tile:hover { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent-soft); }

/* La salute e' una barra sottile in alto: non colora tutto il riquadro. */
.cfo-tile::before {
    content: "";
    position: absolute;
    inset: 0 0 auto 0;
    height: 2px;
    background: var(--line);
}

.cfo-tile.h-good::before { background: #16a34a; }
.cfo-tile.h-warning::before { background: #d97706; }
.cfo-tile.h-bad::before { background: #dc2626; }

.cfo-tile-label {
    font: var(--md-sys-typescale-label-small);
    text-transform: uppercase;
    letter-spacing: .04em;
    color: var(--ink-3);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.cfo-tile-value {
    font-size: 1.4rem;
    font-weight: 650;
    letter-spacing: -.02em;
    color: var(--ink);
    font-variant-numeric: tabular-nums;
    line-height: 1.1;
}

.cfo-tile-value.is-negative { color: #dc2626; }

.cfo-tile-foot {
    display: flex;
    align-items: center;
    gap: 6px;
    font: var(--md-sys-typescale-label-small);
    color: var(--ink-3);
    min-height: 16px;
}

.cfo-delta {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    font-weight: 650;
    font-variant-numeric: tabular-nums;
}

.cfo-delta.is-up { color: #16a34a; }
.cfo-delta.is-down { color: #dc2626; }

/* --- pannelli --- */
.cfo-panel {
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 15px 16px 16px;
    background: var(--card-bg);
    border: 1px solid var(--line);
    border-radius: 6px;
    min-width: 0;
}

.cfo-panel-head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
}

.cfo-panel-title {
    margin: 0;
    font: var(--md-sys-typescale-title-small);
    font-weight: 650;
    color: var(--ink);
    display: inline-flex;
    align-items: center;
    gap: 7px;
}

.cfo-panel-title > i { color: var(--accent-deep); }
.cfo-panel-note { font: var(--md-sys-typescale-label-small); color: var(--ink-3); }

/* Due pannelli affiancati, in colonna sotto i 1100px. */
.cfo-split {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(430px, 1fr));
    gap: 12px;
    align-items: start;
}

.cfo-split-2-1 {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: 12px;
    align-items: start;
}

@media (max-width: 1100px) {
    .cfo-split-2-1 { grid-template-columns: 1fr; }
}

/* --- legenda --- */
.cfo-legend {
    display: flex;
    gap: 16px;
    flex-wrap: wrap;
    font: var(--md-sys-typescale-label-small);
    color: var(--ink-2);
}

.cfo-legend span { display: inline-flex; align-items: center; gap: 6px; }

.cfo-legend i {
    width: 10px;
    height: 10px;
    border-radius: 2px;
    display: inline-block;
}

/* --- eccezioni --- */
.cfo-alerts { display: flex; flex-direction: column; gap: 8px; }

.cfo-alert {
    display: flex;
    align-items: flex-start;
    gap: 11px;
    padding: 11px 13px;
    border: 1px solid var(--line);
    border-radius: 5px;
    background: var(--md-sys-color-surface-container-lowest);
    text-decoration: none;
    color: inherit;
    transition: border-color .12s;
}

.cfo-alert:hover { border-color: var(--accent); }
.cfo-alert > i { font-size: 1rem; margin-top: 1px; }
.cfo-alert.sev-bad > i { color: #dc2626; }
.cfo-alert.sev-warning > i { color: #d97706; }
.cfo-alert.sev-good > i { color: #16a34a; }
.cfo-alert-body { min-width: 0; }

.cfo-alert-body strong {
    display: block;
    font: var(--md-sys-typescale-label-large);
    color: var(--ink);
}

.cfo-alert-body span {
    display: block;
    font: var(--md-sys-typescale-body-small);
    color: var(--ink-2);
    margin-top: 1px;
}

.cfo-empty {
    padding: 22px;
    text-align: center;
    font: var(--md-sys-typescale-body-small);
    color: var(--ink-3);
}

/* --- barra dei filtri --- */
.cfo-controls {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.cfo-controls label {
    font: var(--md-sys-typescale-label-small);
    text-transform: uppercase;
    letter-spacing: .04em;
    color: var(--ink-3);
}

/* --- segmenti (orizzonte 3/6/12 mesi) --- */
.cfo-seg {
    display: inline-flex;
    border: 1px solid var(--line);
    border-radius: 5px;
    overflow: hidden;
}

.cfo-seg button {
    border: 0;
    background: var(--card-bg);
    padding: 6px 13px;
    font: var(--md-sys-typescale-label-medium);
    color: var(--ink-2);
    cursor: pointer;
    border-right: 1px solid var(--line);
}

.cfo-seg button:last-child { border-right: 0; }
.cfo-seg button:hover { background: var(--md-sys-color-surface-container); }
.cfo-seg button.is-active { background: var(--ink); color: #fff; }

/* --- misure secondarie in riga --- */
.cfo-stats {
    display: flex;
    gap: 26px;
    flex-wrap: wrap;
    padding: 2px 0;
}

.cfo-stat { display: flex; flex-direction: column; gap: 2px; min-width: 96px; }

.cfo-stat dt {
    font: var(--md-sys-typescale-label-small);
    text-transform: uppercase;
    letter-spacing: .04em;
    color: var(--ink-3);
}

.cfo-stat dd {
    margin: 0;
    font-size: 1.02rem;
    font-weight: 650;
    color: var(--ink);
    font-variant-numeric: tabular-nums;
}

.cfo-stat dd.is-negative { color: #dc2626; }
.cfo-stat dd small { font-weight: 500; font-size: .72rem; color: var(--ink-3); }

/* --- anzianita' crediti come barra unica --- */
.cfo-aging { display: flex; flex-direction: column; gap: 9px; }

.cfo-aging-bar {
    display: flex;
    height: 26px;
    border-radius: 4px;
    overflow: hidden;
    background: var(--line-soft);
}

.cfo-aging-bar > span {
    display: block;
    min-width: 2px;
    transition: filter .12s;
}

.cfo-aging-bar > span:hover { filter: brightness(1.12); }
.cfo-aging-rows { display: flex; flex-direction: column; gap: 1px; }

.cfo-aging-row {
    display: grid;
    grid-template-columns: 12px 1fr auto auto;
    align-items: center;
    gap: 9px;
    padding: 5px 2px;
    font: var(--md-sys-typescale-body-small);
    border-bottom: 1px solid var(--line-soft);
}

.cfo-aging-row:last-child { border-bottom: 0; }
.cfo-aging-row i { width: 10px; height: 10px; border-radius: 2px; }
.cfo-aging-row .cfo-aging-name { color: var(--ink-2); }

.cfo-aging-row .cfo-aging-amount {
    font-weight: 650;
    color: var(--ink);
    font-variant-numeric: tabular-nums;
}

.cfo-aging-row .cfo-aging-share {
    color: var(--ink-3);
    font-variant-numeric: tabular-nums;
    min-width: 46px;
    text-align: right;
}

/* --- profilo di stagionalita' --- */
.cfo-season {
    display: grid;
    grid-template-columns: repeat(12, 1fr);
    gap: 4px;
    align-items: end;
    height: 108px;
}

.cfo-season-col {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    height: 100%;
    justify-content: flex-end;
}

.cfo-season-bar {
    width: 100%;
    background: var(--accent-strong);
    border-radius: 2px 2px 0 0;
    min-height: 2px;
}

.cfo-season-bar.is-low { background: #d97706; }
.cfo-season-col span { font-size: .62rem; color: var(--ink-3); }
.cfo-season-col b { font-size: .64rem; color: var(--ink-2); font-weight: 600; }

/* --- avviso sui dati dimostrativi --- */
.cfo-demo {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 11px 14px;
    border: 1px dashed #d97706;
    border-radius: 6px;
    background: #fffbeb;
    font: var(--md-sys-typescale-body-small);
    color: #78350f;
}

.cfo-demo > i { color: #d97706; margin-top: 1px; }
.cfo-demo strong { display: block; margin-bottom: 1px; }

/* --- griglia finanziaria periodo per periodo --- */
.cfo-matrix-wrap { overflow-x: auto; }

.cfo-matrix {
    border-collapse: collapse;
    width: 100%;
    min-width: 720px;
    font: var(--md-sys-typescale-body-small);
    font-variant-numeric: tabular-nums;
}

.cfo-matrix th,
.cfo-matrix td {
    padding: 6px 10px;
    text-align: right;
    white-space: nowrap;
    border-bottom: 1px solid var(--line-soft);
}

.cfo-matrix thead th {
    position: sticky;
    top: 0;
    background: var(--md-sys-color-surface-container);
    color: var(--ink-2);
    font: var(--md-sys-typescale-label-small);
    text-transform: uppercase;
    letter-spacing: .03em;
    border-bottom: 1px solid var(--line);
    z-index: 2;
}

/* La prima colonna resta visibile scorrendo i mesi. */
.cfo-matrix th:first-child,
.cfo-matrix td:first-child {
    text-align: left;
    position: sticky;
    left: 0;
    background: var(--card-bg);
    z-index: 1;
    font-weight: 500;
    color: var(--ink-2);
}

.cfo-matrix thead th:first-child { background: var(--md-sys-color-surface-container); z-index: 3; }
.cfo-matrix tbody tr:hover td { background: var(--md-sys-color-surface-container-lowest); }
.cfo-matrix tbody tr:hover td:first-child { background: var(--md-sys-color-surface-container); }

.cfo-matrix tr.is-total td {
    font-weight: 650;
    color: var(--ink);
    background: var(--md-sys-color-surface-container);
    border-top: 1px solid var(--line);
}

.cfo-matrix tr.is-total td:first-child { background: var(--md-sys-color-surface-container); color: var(--ink); }
.cfo-matrix td.is-negative { color: #dc2626; }
.cfo-matrix td.is-min { background: #fef2f2 !important; font-weight: 650; }
.cfo-matrix .cfo-group-row td {
    background: var(--md-sys-color-surface-container-high);
    font: var(--md-sys-typescale-label-small);
    text-transform: uppercase;
    letter-spacing: .04em;
    color: var(--ink-2);
}

/* --- simulatore: leve --- */
.cfo-levers { display: flex; flex-direction: column; gap: 2px; }

.cfo-lever {
    display: grid;
    /* La prima colonna tiene il codice del mastro piu' la descrizione: con i nomi
       veri del piano dei conti sotto i 210px va a capo tre volte. */
    grid-template-columns: 210px 1fr 62px 108px;
    align-items: center;
    gap: 12px;
    padding: 7px 0;
    border-bottom: 1px solid var(--line-soft);
}

.cfo-lever:last-child { border-bottom: 0; }

.cfo-lever-name {
    font: var(--md-sys-typescale-body-medium);
    color: var(--ink);
    font-weight: 500;
}

.cfo-lever-delta {
    text-align: right;
    font-weight: 650;
    font-variant-numeric: tabular-nums;
    font-size: .84rem;
}

.cfo-lever-delta.is-up { color: #16a34a; }
.cfo-lever-delta.is-down { color: #dc2626; }

.cfo-lever-base {
    text-align: right;
    font: var(--md-sys-typescale-label-small);
    color: var(--ink-3);
    font-variant-numeric: tabular-nums;
}

@media (max-width: 720px) {
    .cfo-lever { grid-template-columns: 1fr 56px; grid-template-areas: "name delta" "slider slider" "base base"; }
    .cfo-lever-name { grid-area: name; }
    .cfo-lever-delta { grid-area: delta; }
    .cfo-lever-base { grid-area: base; text-align: left; }
}

/* --- esiti del simulatore --- */
.cfo-outcomes {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(124px, 1fr));
    gap: 8px;
}

.cfo-outcome {
    padding: 10px 12px;
    border: 1px solid var(--line);
    border-radius: 5px;
    background: var(--md-sys-color-surface-container-lowest);
}

.cfo-outcome dt {
    font: var(--md-sys-typescale-label-small);
    text-transform: uppercase;
    letter-spacing: .04em;
    color: var(--ink-3);
    margin-bottom: 3px;
}

.cfo-outcome dd {
    margin: 0;
    font-size: 1rem;
    font-weight: 650;
    color: var(--ink);
    font-variant-numeric: tabular-nums;
}

.cfo-outcome dd.is-negative { color: #dc2626; }

.cfo-outcome-delta {
    display: block;
    font-size: .72rem;
    font-weight: 650;
    margin-top: 2px;
}

.cfo-outcome-delta.is-up { color: #16a34a; }
.cfo-outcome-delta.is-down { color: #dc2626; }

/* --- carte degli scenari del goalseek --- */
.cfo-scenarios {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
    gap: 10px;
}

.cfo-scenario {
    padding: 13px 15px;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: var(--card-bg);
    cursor: pointer;
    text-align: left;
    transition: border-color .12s, box-shadow .12s;
}

.cfo-scenario:hover { border-color: var(--accent); }

.cfo-scenario.is-best {
    border-color: var(--accent-strong);
    box-shadow: 0 0 0 1px var(--accent-soft);
}

.cfo-scenario-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 9px;
}

.cfo-scenario-head strong { font: var(--md-sys-typescale-label-large); color: var(--ink); }

.cfo-badge {
    font-size: .62rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .05em;
    padding: 2px 7px;
    border-radius: 9px;
    background: var(--accent-strong);
    color: #fff;
}

.cfo-scenario-row {
    display: flex;
    justify-content: space-between;
    gap: 10px;
    padding: 3px 0;
    font: var(--md-sys-typescale-body-small);
    color: var(--ink-2);
}

.cfo-scenario-row b { font-variant-numeric: tabular-nums; }
.cfo-scenario-row b.is-up { color: #16a34a; }
.cfo-scenario-row b.is-down { color: #dc2626; }

/* Il grafico Telerik non deve sfondare la colonna della griglia. */
.cfo-panel .k-chart { max-width: 100%; }

/* Codice del mastro accanto al nome della leva: distingue ricavi da costi
   senza aggiungere una colonna. */
.cfo-badge-sec {
    display: inline-block;
    min-width: 26px;
    text-align: center;
    padding: 1px 5px;
    margin-right: 7px;
    border-radius: 3px;
    font-size: .68rem;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
}

.cfo-badge-sec.is-ric { background: var(--accent-soft); color: var(--accent-deep); }
.cfo-badge-sec.is-cos { background: #fee2e2; color: #b91c1c; }

/* --- tooltip dei grafici: i numeri con i separatori delle migliaia --- */
.cfo-tip { min-width: 190px; font: var(--md-sys-typescale-body-small); }

.cfo-tip-cat {
    font: var(--md-sys-typescale-label-small);
    text-transform: uppercase;
    letter-spacing: .04em;
    opacity: .75;
    margin-bottom: 5px;
    padding-bottom: 4px;
    border-bottom: 1px solid rgba(255, 255, 255, .18);
}

.cfo-tip-row {
    display: grid;
    grid-template-columns: 9px 1fr auto;
    align-items: center;
    gap: 7px;
    padding: 1px 0;
}

.cfo-tip-dot { width: 9px; height: 9px; border-radius: 2px; }
.cfo-tip-name { opacity: .88; }

.cfo-tip-val {
    font-weight: 650;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

/* --- conto economico a scalare --- */
.cfo-scalare {
    border-collapse: collapse;
    width: 100%;
    min-width: 340px;
    font: var(--md-sys-typescale-body-small);
    font-variant-numeric: tabular-nums;
}

.cfo-scalare th,
.cfo-scalare td {
    padding: 5px 10px;
    text-align: right;
    white-space: nowrap;
    border-bottom: 1px solid var(--line-soft);
}

.cfo-scalare thead th {
    font: var(--md-sys-typescale-label-small);
    text-transform: uppercase;
    letter-spacing: .03em;
    color: var(--ink-2);
    border-bottom: 1px solid var(--line);
}

.cfo-scalare th:first-child,
.cfo-scalare td:first-child { text-align: left; color: var(--ink-2); }

.cfo-scalare tr.is-total td {
    font-weight: 650;
    color: var(--ink);
    background: var(--md-sys-color-surface-container);
    border-top: 1px solid var(--line);
}

.cfo-scalare tr.is-total td:first-child { text-transform: uppercase; letter-spacing: .03em; }
.cfo-scalare tr.is-total small { margin-left: 6px; font-weight: 500; color: var(--ink-3); }
.cfo-scalare td.is-negative { color: #dc2626; }
.cfo-scalare td.is-up { color: #16a34a; }
.cfo-scalare td.is-down { color: #dc2626; }

/* --- leve raggruppate per classe --- */
.cfo-levers-head {
    margin: 12px 0 2px;
    padding-bottom: 3px;
    font: var(--md-sys-typescale-label-small);
    text-transform: uppercase;
    letter-spacing: .04em;
    color: var(--ink-3);
    border-bottom: 1px solid var(--line);
}

.cfo-levers-head:first-child { margin-top: 0; }

/* --- classificazione del piano dei conti --- */
.cfo-matrix.cfo-config td { padding: 4px 10px; }
.cfo-matrix.cfo-config td:nth-child(2) { text-align: left; white-space: normal; }
.cfo-matrix.cfo-config td:last-child,
.cfo-matrix.cfo-config thead th:last-child { text-align: left; }

/* La proposta dell'euristica: un colpo per accettarla, nessuno per ignorarla. */
.cfo-chip-suggest {
    margin-left: 7px;
    padding: 2px 8px;
    border: 1px dashed var(--line);
    border-radius: 999px;
    background: transparent;
    color: var(--ink-3);
    font: var(--md-sys-typescale-label-small);
    cursor: pointer;
}

.cfo-chip-suggest:hover { border-color: var(--accent); color: var(--accent-deep); background: var(--accent-soft); }

/* Un mese ancora da chiudere: il numero e' una previsione, non un consuntivo. */
.cfo-matrix tr.is-forecast td { color: var(--ink-3); font-style: italic; }

/* L'etichetta accanto al mese: previsione, oppure mese in corso. */
.cfo-matrix td:first-child small {
    margin-left: 6px;
    font-style: normal;
    text-transform: uppercase;
    letter-spacing: .04em;
    font-size: .64rem;
    opacity: .8;
}

/* Tabella dentro un pannello a mezza larghezza: senza min-width l'ultima
   colonna finiva tagliata invece di far scorrere. */
.cfo-matrix.cfo-compact { min-width: 0; }
.cfo-matrix.cfo-compact th,
.cfo-matrix.cfo-compact td { padding: 6px 8px; }

/* --- flag "usa come leva" nella configurazione --- */
.cfo-check-leva {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin-left: 10px;
    font: var(--md-sys-typescale-label-small);
    text-transform: none;
    letter-spacing: 0;
    color: var(--ink-2);
    cursor: pointer;
}

/* Un mastro fuori dalle leve: resta leggibile ma si vede che non si tocca. */
.cfo-lever.is-fissa { opacity: .68; }

.cfo-lever-fissa {
    font: var(--md-sys-typescale-label-small);
    text-transform: uppercase;
    letter-spacing: .04em;
    color: var(--ink-3);
    border: 1px dashed var(--line);
    border-radius: 999px;
    padding: 2px 9px;
    justify-self: start;
}

/* --- consultazione dei saldi banche --- */
/* Divisa e nome banca si leggono da sinistra: solo gli importi vanno a destra. */
.cfo-matrix.cfo-banche td:nth-child(2),
.cfo-matrix.cfo-banche th:nth-child(2) { text-align: left; }

.cfo-matrix.cfo-banche td:nth-child(2) small { margin-left: 8px; color: var(--ink-3); }

.cfo-link-banca {
    border: 0;
    background: transparent;
    padding: 0;
    font: inherit;
    font-weight: 600;
    color: var(--accent-deep);
    cursor: pointer;
    text-align: left;
}

.cfo-link-banca:hover { text-decoration: underline; }

.cfo-banca-affid td { border-bottom: 0; color: var(--ink-3); }
.cfo-banca-saldo td { font-weight: 500; }
.cfo-banca-saldo.is-rettificata td,
.cfo-banca-affid.is-rettificata td { background: var(--md-sys-color-surface-container-lowest); }

.cfo-rettifica {
    display: block;
    font: var(--md-sys-typescale-label-small);
    font-weight: 500;
    color: var(--ink-3);
    text-transform: none;
    letter-spacing: 0;
}

/* Dettaglio dei conti di una banca: la descrizione puo' andare a capo, le date no. */
.k-window .cfo-matrix.cfo-compact td:nth-child(2) { white-space: normal; text-align: left; }
.k-window .cfo-matrix.cfo-compact td:last-child,
.k-window .cfo-matrix.cfo-compact th:last-child { white-space: nowrap; min-width: 96px; }

/* --- legami fra le leve --- */
.cfo-lever-indotto {
    display: block;
    font: var(--md-sys-typescale-label-small);
    font-weight: 500;
    color: var(--ink-3);
    white-space: nowrap;
}

.cfo-lever-base small {
    display: block;
    font-size: .64rem;
    color: var(--ink-3);
    opacity: .85;
}

.cfo-matrix.cfo-compact td .k-dropdownlist,
.cfo-matrix.cfo-compact td .k-numerictextbox { vertical-align: middle; }

/* Un legame che non potra' essere salvato: si vede prima, non dopo. */
.cfo-matrix tr.is-invalido td { background: #fef2f2; }
.cfo-matrix tr.is-invalido td small { display: block; }


/* ---------- riconciliazione: avvisi sull'estrazione e righe rifiutate ---------- */
/* Un avviso qui non e' decorazione: dice che il documento potrebbe essere stato
   letto male, e va visto prima che l'utente prema Salva. Colori dai token, cosi'
   ogni installazione resta con la propria grafica. */
.recon-avvisi {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    margin: 0 0 16px;
    padding: 12px 16px;
    border-radius: var(--md-sys-shape-corner-small);
    font: var(--md-sys-typescale-body-medium);
}

.recon-avvisi > i {
    flex: 0 0 auto;
    margin-top: 2px;
    font-size: 1.05rem;
}

.recon-avvisi > div { min-width: 0; }
.recon-avvisi > div > div + div { margin-top: 4px; }
.recon-avvisi strong { display: block; margin-bottom: 4px; }

.recon-avvisi-nota {
    margin-top: 8px;
    font: var(--md-sys-typescale-body-small);
    opacity: .85;
}


/* ---------- configurazione dei motori AI ---------- */
/* Tutto dai token: la pagina prende i colori del tema per ruolo come le altre. */
.ai-ruoli {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 16px;
    margin-bottom: 16px;
}

.ai-ruolo { padding: 16px 20px; }
.ai-ruolo-vuoto { opacity: .72; }

.ai-ruolo-testa {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 8px;
}

.ai-ruolo-motore { font: var(--md-sys-typescale-body-large); }

.ai-ruolo-endpoint {
    font: var(--md-sys-typescale-body-small);
    color: var(--md-ref-palette-neutral40);
    word-break: break-all;
}

.ai-ruolo-flag {
    display: flex;
    gap: 12px;
    margin-top: 8px;
    font: var(--md-sys-typescale-label-medium);
    color: var(--md-ref-palette-neutral40);
}

.ai-chiave { font-variant-numeric: tabular-nums; letter-spacing: .04em; }
.ai-chiave-assente { color: var(--md-sys-color-error); font-weight: 600; }
.ai-attivo { color: var(--md-sys-color-success); font-size: 1.1rem; }

.ai-suggerito {
    margin-left: 8px;
    color: var(--btn-primary);
    text-decoration: none;
    border-bottom: 1px dotted var(--btn-primary);
}
.ai-suggerito:hover { color: var(--btn-primary-hover); }

.ai-esito {
    margin-top: 12px;
    padding: 12px 16px;
    border-radius: var(--md-sys-shape-corner-small);
    font: var(--md-sys-typescale-body-medium);
}
.ai-esito > div + div { margin-top: 4px; }
.ai-esito-errore { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .8rem; word-break: break-word; }

.ai-consumi { width: 100%; margin-top: 12px; border-collapse: collapse; font-size: .85rem; }
.ai-consumi th,
.ai-consumi td { padding: 6px 10px; border-bottom: 1px solid var(--md-sys-color-outline-variant); }
.ai-consumi th { text-align: left; font-weight: 600; }
.ai-consumi .num { text-align: right; font-variant-numeric: tabular-nums; }
.ai-consumi .ai-errori { color: var(--md-sys-color-error); font-weight: 600; }

/* =========================================================================
   Revisione righe di fattura spedizioniere
   -------------------------------------------------------------------------
   Un blocco solo, identico nei due progetti, scritto sui token e mai su un
   colore letterale: cosi' segue il tema per ruolo del fork e la tavolozza
   unica del prodotto senza doverlo scrivere due volte.

   La scelta grafica che conta e' una: i tre stati - non agganciate, da
   guardare, agganciate - hanno colori diversi e stanno sempre nello stesso
   ordine, quello del lavoro che resta da fare. Chi apre la pagina deve
   capire in un secondo quanto manca, e quali righe sono sue.
   ========================================================================= */

.rev-page .rev-numero {
    font: var(--md-sys-typescale-title-medium);
    color: var(--ink-2);
    margin-left: 8px;
}

/* --- barra degli stati e avanzamento ------------------------------------ */

.rev-stato {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
}

.rev-gruppi {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.rev-gruppo {
    display: flex;
    align-items: baseline;
    gap: 8px;
    padding: 8px 14px;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: transparent;
    cursor: pointer;
    transition: background .15s, border-color .15s;
}

.rev-gruppo:hover:not(:disabled) { background: var(--md-sys-color-surface-container-low); }

.rev-gruppo:disabled,
.rev-gruppo.is-vuoto {
    opacity: .4;
    cursor: default;
}

.rev-gruppo-n {
    font: var(--md-sys-typescale-title-medium);
    font-weight: 700;
}

.rev-gruppo-t {
    font: var(--md-sys-typescale-body-small);
    color: var(--ink-2);
}

/* Il colore lo porta il pallino del conteggio, non tutto il bottone: una
   fila di bottoni pieni si legge peggio, e qui il conteggio e' il dato. */
.rev-gruppo.rev-bad  .rev-gruppo-n { color: var(--md-sys-color-error); }
.rev-gruppo.rev-warn .rev-gruppo-n { color: #b45309; }
.rev-gruppo.rev-ok   .rev-gruppo-n { color: var(--md-sys-color-success); }
.rev-gruppo.rev-off  .rev-gruppo-n { color: var(--ink-3); }

.rev-gruppo.is-active {
    border-color: var(--btn-primary);
    background: var(--md-sys-color-surface-container-low);
    box-shadow: inset 0 0 0 1px var(--btn-primary);
}

.rev-gruppo.rev-tutte { border-style: dashed; }

.rev-avanzamento {
    display: flex;
    flex-direction: column;
    gap: 6px;
    min-width: 260px;
    flex: 1;
    max-width: 420px;
}

.rev-barra {
    height: 8px;
    border-radius: 999px;
    background: var(--line-soft);
    overflow: hidden;
}

.rev-barra-riempita {
    height: 100%;
    background: var(--btn-primary);
    transition: width .25s;
}

.rev-avanzamento-testo {
    font: var(--md-sys-typescale-body-small);
    color: var(--ink-2);
}

.rev-impedimenti ul {
    margin: 4px 0 0;
    padding-left: 18px;
}

/* --- griglia: fattura a sinistra, sistema a destra ---------------------- */

.rev-pill {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 999px;
    font: var(--md-sys-typescale-label-small);
    font-weight: 600;
    white-space: nowrap;
}

.rev-pill.rev-bad  { background: var(--md-sys-color-error-container);   color: var(--md-sys-color-error); }
.rev-pill.rev-warn { background: var(--md-sys-color-warning-container); color: #854d0e; }
.rev-pill.rev-ok   { background: var(--md-sys-color-success-container); color: var(--md-sys-color-success); }
.rev-pill.rev-off  { background: var(--line-soft);                      color: var(--ink-3); }

.rev-mano {
    margin-left: 6px;
    color: var(--btn-primary);
}

.rev-lato {
    display: flex;
    flex-direction: column;
    line-height: 1.25;
}

.rev-rif, .rev-ddt {
    font-weight: 600;
    color: var(--ink);
}

.rev-piu {
    margin-left: 6px;
    padding: 1px 6px;
    border-radius: 999px;
    background: var(--line-soft);
    font: var(--md-sys-typescale-label-small);
    color: var(--ink-2);
}

.rev-sub {
    font: var(--md-sys-typescale-body-small);
    color: var(--ink-2);
}

/* Il destinatario di fattura e quello di bolla non si somigliano. Non e' un
   errore di per se' - il conto terzi funziona cosi' - ma e' la prima cosa da
   guardare quando si dubita di un aggancio, quindi si vede. */
.rev-sub.rev-diverso {
    color: #b45309;
    text-decoration: underline dotted;
    text-underline-offset: 3px;
}

.rev-nessuno {
    font: var(--md-sys-typescale-body-small);
    color: var(--ink-3);
    font-style: italic;
}

.rev-importo {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    line-height: 1.3;
}

.rev-importo .is-negative { color: var(--md-sys-color-error); }

.rev-delta {
    font: var(--md-sys-typescale-label-small);
    font-weight: 600;
}

.rev-delta.is-piu  { color: var(--md-sys-color-error); }
.rev-delta.is-meno { color: #0369a1; }

.rev-residuo {
    font: var(--md-sys-typescale-label-small);
    color: var(--md-sys-color-error);
}

.rev-azioni {
    display: flex;
    gap: 2px;
    justify-content: center;
}

.rev-azioni .btn-icon {
    width: 32px;
    height: 32px;
}

.rev-az-ok:hover        { color: var(--md-sys-color-success); }
.rev-az-riassegna:hover { color: var(--btn-primary); }
.rev-az-spezza:hover    { color: var(--btn-primary); }
.rev-az-scarta:hover    { color: var(--md-sys-color-error); }
.rev-az-riapri:hover    { color: var(--ink-2); }

/* --- dettaglio della riga ----------------------------------------------- */

.rev-dettaglio {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
    gap: 20px;
    padding: 16px 18px;
    background: var(--md-sys-color-surface-container-low);
}

.rev-dettaglio > div > strong {
    display: block;
    margin-bottom: 8px;
    font: var(--md-sys-typescale-label-large);
    color: var(--ink-2);
    text-transform: uppercase;
    letter-spacing: .04em;
}

.rev-dettaglio-motivo p {
    margin: 0 0 8px;
    color: var(--ink);
}

.rev-chiave {
    display: inline-block;
    padding: 2px 8px;
    border: 1px solid var(--line);
    border-radius: var(--r, 10px);
    font: var(--md-sys-typescale-label-small);
    color: var(--ink-2);
}

.rev-dettaglio-dati dl {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 2px 12px;
    margin: 0;
}

.rev-dettaglio-dati dt {
    font: var(--md-sys-typescale-body-small);
    color: var(--ink-3);
}

.rev-dettaglio-dati dd {
    margin: 0;
    font: var(--md-sys-typescale-body-small);
    color: var(--ink);
}

.rev-dettaglio-dati dd small { color: var(--ink-3); }

.rev-grezzo { margin-top: 10px; }

.rev-grezzo summary {
    cursor: pointer;
    font: var(--md-sys-typescale-body-small);
    color: var(--btn-primary);
}

.rev-grezzo pre {
    margin: 6px 0 0;
    padding: 8px;
    background: var(--card-bg);
    border: 1px solid var(--line);
    border-radius: 6px;
    font-size: .75rem;
    white-space: pre-wrap;
    word-break: break-all;
    max-height: 160px;
    overflow: auto;
}

.rev-alloc-table {
    width: 100%;
    border-collapse: collapse;
    font: var(--md-sys-typescale-body-small);
}

.rev-alloc-table td {
    padding: 4px 8px 4px 0;
    border-bottom: 1px solid var(--line-soft);
}

.rev-alloc-table tr.is-spenta {
    opacity: .45;
    text-decoration: line-through;
}

.rev-alloc-quota { text-align: right; font-weight: 600; }

.rev-origine {
    padding: 1px 6px;
    border-radius: 999px;
    background: var(--line-soft);
    font: var(--md-sys-typescale-label-small);
    color: var(--ink-2);
}

.rev-storia {
    margin: 0;
    padding: 0;
    list-style: none;
    font: var(--md-sys-typescale-body-small);
}

.rev-storia li {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding: 3px 0;
    border-bottom: 1px solid var(--line-soft);
}

.rev-storia-quando { color: var(--ink-3); font-variant-numeric: tabular-nums; }
.rev-storia-cosa   { font-weight: 600; }
.rev-storia-chi    { color: var(--ink-2); }
.rev-storia-perche { color: var(--ink-3); flex-basis: 100%; }

/* --- divisione su piu' bolle -------------------------------------------- */

.rev-spezza-table {
    width: 100%;
    border-collapse: collapse;
    margin: 12px 0;
}

.rev-spezza-table th {
    text-align: left;
    padding: 6px 8px;
    border-bottom: 2px solid var(--line);
    font: var(--md-sys-typescale-label-medium);
    color: var(--ink-2);
}

.rev-spezza-table td {
    padding: 6px 8px;
    border-bottom: 1px solid var(--line-soft);
}

.rev-spezza-table .rev-num { text-align: right; }

.rev-spezza-totale {
    display: flex;
    align-items: baseline;
    gap: 8px;
    padding: 10px 12px;
    border-radius: var(--r, 10px);
    background: var(--md-sys-color-surface-container-low);
}

.rev-spezza-totale.is-ok strong { color: var(--md-sys-color-success); }
.rev-spezza-totale.is-ko strong { color: var(--md-sys-color-error); }

.rev-spezza-azioni {
    display: flex;
    gap: 8px;
    margin-top: 12px;
}

/* --- selettore di spedizioni -------------------------------------------- */

.rev-picker-filtri {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: 12px;
    margin-bottom: 12px;
}

.rev-picker-filtri .filter-item {
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-width: 150px;
}

.rev-picker-filtri label {
    font: var(--md-sys-typescale-body-small);
    color: var(--ink-2);
}

.rev-picker-testo { flex: 1; min-width: 240px; }

.rev-picker-vettore { align-self: center; }

.rev-picker-avviso { margin-bottom: 12px; }

.rev-picker-elenco {
    max-height: 46vh;
    overflow: auto;
    border: 1px solid var(--line);
    border-radius: var(--r, 10px);
}

/* Una riga sola per spedizione, a colonne fisse: chi cerca scorre con gli
   occhi lungo una colonna, e colonne che ballano da riga a riga rendono lo
   scorrimento inutile. */
.rev-picker-riga {
    display: grid;
    grid-template-columns: 92px 92px 1fr 150px 130px 110px;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 8px 12px;
    border: 0;
    border-bottom: 1px solid var(--line-soft);
    background: transparent;
    text-align: left;
    cursor: pointer;
}

.rev-picker-riga:hover { background: var(--md-sys-color-surface-container-low); }
.rev-picker-riga:last-child { border-bottom: 0; }

.rev-picker-ddt { font-weight: 700; color: var(--ink); }

.rev-picker-data,
.rev-picker-vett,
.rev-picker-misure {
    font: var(--md-sys-typescale-body-small);
    color: var(--ink-2);
}

.rev-picker-dest {
    display: flex;
    flex-direction: column;
    line-height: 1.2;
    min-width: 0;
}

.rev-picker-dest strong,
.rev-picker-vett {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.rev-picker-dest small { color: var(--ink-3); }

.rev-picker-importo { text-align: right; }

.rev-picker-gia {
    font: var(--md-sys-typescale-label-small);
    font-weight: 600;
    color: #b45309;
}

.rev-picker-riga.is-presa { background: var(--md-sys-color-warning-container); }
.rev-picker-riga.is-presa:hover { filter: brightness(.97); }

.rev-picker-troppi {
    margin: 8px 0 0;
    font: var(--md-sys-typescale-body-small);
}

@media (max-width: 900px) {
    .rev-picker-riga {
        grid-template-columns: 1fr 1fr;
        row-gap: 2px;
    }
    .rev-stato { flex-direction: column; align-items: stretch; }
    .rev-avanzamento { max-width: none; }
}

/* --- elenco documenti e caricamento ------------------------------------- */

.rec-carica .filters-row { align-items: flex-end; }

.rec-carica .filter-item {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.rec-carica label {
    font: var(--md-sys-typescale-body-small);
    color: var(--ink-2);
}

.rec-file { flex: 1; min-width: 280px; }

/* Il campo file nudo del browser e' alto e sgraziato accanto ai controlli
   Telerik: qui si allinea alla loro altezza e prende il bordo del tema. */
.rec-input-file {
    width: 100%;
    padding: 6px 10px;
    border: 1px solid var(--line);
    border-radius: var(--r, 10px);
    background: var(--card-bg);
    font: var(--md-sys-typescale-body-small);
    line-height: 1.6;
}

.rec-input-file::file-selector-button {
    margin-right: 10px;
    padding: 4px 12px;
    border: 0;
    border-radius: 999px;
    background: var(--btn-primary);
    color: var(--btn-on-primary);
    cursor: pointer;
}

.rec-lavoro {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-top: 12px;
    font: var(--md-sys-typescale-body-small);
    color: var(--ink-2);
}

.rec-nota {
    margin: 10px 0 0;
    font: var(--md-sys-typescale-body-small);
}

.rec-gia {
    display: flex;
    gap: 8px;
    margin-top: 10px;
}

.rec-avanzamento {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

/* --- qualita' della riconciliazione ------------------------------------- */

.qual-tiles { margin-bottom: 12px; }

.qual-tiles .cfo-tile {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.qual-tile-t {
    font: var(--md-sys-typescale-label-medium);
    color: var(--ink-2);
    text-transform: uppercase;
    letter-spacing: .04em;
}

.qual-tile-n {
    font: var(--md-sys-typescale-headline-medium);
    font-weight: 700;
    color: var(--ink);
    line-height: 1.1;
}

.qual-tile-s {
    font: var(--md-sys-typescale-body-small);
    color: var(--ink-3);
}

.qual-barra-riga {
    display: flex;
    align-items: center;
    gap: 10px;
}

.qual-barra-riga .rev-barra { flex: 1; }

/* Le soglie non sono decorative: sotto la meta' il vettore chiede lavoro a
   mano su piu' di una riga su due, ed e' il segnale da vedere per primo. */
.rev-barra-riempita.is-buona  { background: var(--md-sys-color-success); }
.rev-barra-riempita.is-media  { background: #d97706; }
.rev-barra-riempita.is-scarsa { background: var(--md-sys-color-error); }

.qual-tolleranza {
    display: inline-flex;
    align-items: baseline;
    gap: 6px;
    padding: 4px 10px;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: transparent;
    font: var(--md-sys-typescale-body-small);
    color: var(--ink);
    cursor: pointer;
}

.qual-tolleranza:hover { border-color: var(--btn-primary); }
.qual-tolleranza small { color: var(--ink-3); }

.qual-proposte { margin-top: 12px; }

.qual-proposte h2 {
    font: var(--md-sys-typescale-title-large);
    margin: 0 0 4px;
}

.qual-proposte h2 i { color: var(--btn-primary); margin-right: 8px; }

.qual-proposta {
    padding: 12px 14px;
    margin-top: 10px;
    border-left: 3px solid var(--btn-primary);
    border-radius: 0 var(--r, 10px) var(--r, 10px) 0;
    background: var(--md-sys-color-surface-container-low);
}

.qual-proposta-testa {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 10px;
}

.qual-proposta-cosa {
    margin: 6px 0 0;
    color: var(--ink);
}

.qual-esempi {
    margin: 6px 0 0;
    padding-left: 18px;
    font: var(--md-sys-typescale-body-small);
    color: var(--ink-2);
}

.qual-tolleranze-form {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 14px;
    margin: 14px 0;
}

.qual-tolleranze-form .form-group {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.qual-tolleranze-form label {
    font: var(--md-sys-typescale-body-small);
    color: var(--ink-2);
}

.qual-tolleranze-form small { color: var(--ink-3); }

.qual-esempio-banda { margin-top: 6px; }

/* ===========================================================================
   Finestre di dialogo: i bottoni devono restare raggiungibili
   ---------------------------------------------------------------------------
   Una TelerikWindow si dimensiona sul contenuto e non ha un tetto: il form dei
   motori AI, con dieci campi, cresceva oltre l'altezza dello schermo e il pie'
   di pagina con Salva e Annulla finiva fuori, senza modo di arrivarci - la
   finestra e' modale, quindi non si puo' nemmeno scorrere la pagina sotto.

   La regola vale per tutte le finestre e non solo per quella: e' un limite del
   componente, non un difetto di una pagina. Il titolo e il pie' restano fermi,
   scorre solo il corpo.
   =========================================================================== */
.k-window {
    max-height: 92vh;
    max-width: 96vw;
    display: flex;
    flex-direction: column;
}

.k-window > .k-window-content {
    overflow: auto;
    /* senza questo il contenuto in flex non si lascia rimpicciolire e il
       tetto di 92vh non ha effetto */
    min-height: 0;
}

.k-window > .k-window-titlebar,
.k-window > .k-window-actions,
.k-window > .k-actions {
    flex: 0 0 auto;
}

/* Il pie' di pagina raccoglie i bottoni a destra, con Salva per ultimo. */
.k-window > .k-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    padding: 12px 16px;
    border-top: 1px solid var(--line);
}

/* In una riga di filtri l'etichetta di una casella non deve andare a capo, ma
   dentro un dialog stretto quel nowrap sfonda la larghezza e fa comparire la
   barra di scorrimento orizzontale: "Supporta output JSON con schema" non ci
   sta in un terzo di 720px. */
.k-window .filter-check {
    white-space: normal;
    align-items: flex-start;
}

.k-window .filter-check label { line-height: 1.25; }

/* ===========================================================================
   Bilancio gestionale
   ---------------------------------------------------------------------------
   Riusa la matrice del CFO (.cfo-matrix): stessa densita', stessa prima colonna
   che resta ferma scorrendo. Qui si aggiunge solo cio' che il foglio Excel non
   sapeva dire, cioe' DA DOVE VIENE un numero.
   =========================================================================== */

/* La colonna del residuo e quella del totale si staccano dalle altre: la prima
   perche' cio' che ci finisce dentro e' da attribuire, la seconda perche' e' il
   numero che si legge per primo. */
.bal-matrix th.bal-col-residuo { color: var(--md-sys-color-error); }
.bal-matrix td.bal-col-residuo,
.bal-matrix th.bal-col-totale,
.bal-matrix td.bal-col-totale {
    border-left: 1px solid var(--line);
    font-weight: 600;
    color: var(--ink);
}

/* Una cella scritta a mano si vede, senza gridare: sfondo appena caldo e una
   matita. Serve a distinguere a colpo d'occhio il consuntivo dalla stima. */
.bal-matrix td.bal-cella-manuale { background: var(--md-sys-color-tertiary-container); }
.bal-manuale { font-size: .62rem; margin-left: 4px; opacity: .55; vertical-align: super; }

/* Quando lo scritto si allontana di oltre un quinto dal proposto, la cella si
   sottolinea: non e' per forza un errore - gli ammortamenti mensili sono una
   quota e la contabilita' li registra a fine anno - ma non deve passare
   inosservato. */
.bal-matrix td.bal-scostata { box-shadow: inset 0 -2px 0 var(--md-sys-color-error); }

.bal-matrix td.bal-vuota { color: var(--ink-3); }
.bal-matrix tr.bal-risultato td { border-top: 2px solid var(--line); }

.bal-legenda {
    display: flex;
    flex-wrap: wrap;
    gap: 16px;
    padding: 8px 4px 0;
    font: var(--md-sys-typescale-body-small);
    color: var(--ink-3);
}

.bal-legenda-auto::before {
    content: "";
    display: inline-block;
    width: 12px; height: 12px;
    margin-right: 6px;
    vertical-align: -2px;
    border: 1px solid var(--line);
    background: var(--card-bg);
}

/* I reparti industriali stanno affiancati finche' ci stanno: sono prospetti
   corti e uno sotto l'altro sprecherebbero mezzo schermo. */
.bal-reparti {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
    gap: 16px;
}

.bal-reparto h4 {
    font: var(--md-sys-typescale-label-large);
    color: var(--ink-2);
    margin: 0 0 6px;
}

.bal-matrix-stretta { min-width: 0; }
.bal-nota { font: var(--md-sys-typescale-body-small); color: var(--ink-2); margin: 0 4px 8px; }
.bal-descr { text-align: left !important; white-space: normal; max-width: 420px; }

.bal-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 2px 10px;
    border-radius: 999px;
    font: var(--md-sys-typescale-label-small);
}

.bal-chip-chiuso {
    background: var(--md-sys-color-surface-container-high);
    color: var(--ink-2);
    border: 1px solid var(--line);
}

/* --- bilancio: le celle che si possono scrivere --- */
/* Un prospetto in cui alcune celle si aprono e altre no deve dirlo prima del
   clic: il puntatore cambia e il fondo si accende passandoci sopra. Sui
   subtotali non succede niente, ed e' giusto: sono la somma delle loro parti. */
.bal-cella-clic { cursor: pointer; }
.bal-cella-clic:hover { outline: 2px solid var(--btn-primary); outline-offset: -2px; }

.bal-modifica .bal-proposto { padding: 8px 0; font: var(--md-sys-typescale-body-medium); }
.bal-modifica .bal-quote { border-top: 1px solid var(--line); margin-top: 8px; padding-top: 12px; }
.bal-modifica .bal-quote-testa { display: flex; justify-content: space-between; align-items: baseline; }
.bal-quote-errore { color: var(--md-sys-color-error); font-weight: 600; }

/* -------------------------------------------------------------------------
   Bilancio gestionale: la scheda di configurazione

   Le tre viste - voci, regole, business unit - condividono una testata con il
   selettore a segmenti e la ricerca. Il resto e' segnaletica: una voce spenta,
   una riga dichiarata fuori dal prospetto e un codice sotto la descrizione
   devono distinguersi senza colore da solo, perche' il colore da solo non si
   legge in stampa e non si legge a tutti.
   ------------------------------------------------------------------------- */
.bal-schema-testa { display: flex; justify-content: space-between; align-items: center;
                    gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.bal-schema-azioni { margin-bottom: 12px; }

/* Il codice sotto la descrizione: si legge quando serve, non ruba la riga. */
.bal-codice { font: var(--md-sys-typescale-body-small); color: var(--md-sys-color-on-surface-variant);
              font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; }

/* Spenta e fuori dal prospetto sono due cose diverse: la prima e' sbiadita,
   la seconda ha una barra a sinistra. Il testo dice comunque quale delle due. */
.bal-riga-spenta   { opacity: .5; }
.bal-riga-esclusa td:first-child { border-left: 3px solid var(--md-sys-color-outline); padding-left: 9px; }

.bal-schema .text-right { text-align: right; }
.bal-schema code { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace;
                   background: var(--md-sys-color-surface-variant); padding: 2px 6px; border-radius: 4px; }

/* La fonte di una voce, a colpo d'occhio. Le automatiche hanno un fondo pieno,
   le altre no: e' la distinzione che conta quando un numero non torna. */
.bal-chip-contabilita   { background: var(--md-sys-color-info-container);    color: var(--md-sys-color-info); }
.bal-chip-analitica     { background: var(--md-sys-color-info-container);    color: var(--md-sys-color-info); }
.bal-chip-venduto       { background: var(--md-sys-color-info-container);    color: var(--md-sys-color-info); }
.bal-chip-manuale       { background: var(--md-sys-color-warning-container); color: #854d0e; }
.bal-chip-calcolata     { background: transparent; color: var(--md-sys-color-on-surface-variant);
                          border: 1px solid var(--line); }
.bal-chip-ribaltamento  { background: transparent; color: var(--md-sys-color-on-surface-variant);
                          border: 1px solid var(--line); }
.bal-chip-totale_sezione{ background: transparent; color: var(--md-sys-color-on-surface-variant);
                          border: 1px solid var(--line); }

/* La testata della configurazione, e le tabelle che non devono allungare la
   pagina: 183 voci e 165 regole una sotto l'altra fanno undicimila pixel, e a
   quel punto per confrontare due righe si scorre avanti e indietro. Corpo che
   scorre da solo, intestazione appiccicata in cima. */
.bal-schema-cerca { display: flex; align-items: center; gap: 8px; }
.bal-schema .cfo-matrix-wrap { max-height: 62vh; overflow-y: auto; }
.bal-schema .cfo-matrix thead th { position: sticky; top: 0; z-index: 4; }

/* Qui le colonne sono quasi tutte testo: l'allineamento a destra della matrice
   dei numeri le renderebbe illeggibili. Si torna a sinistra, e solo le due
   colonne di conteggio restano a destra. */
.bal-schema .cfo-matrix th,
.bal-schema .cfo-matrix td { text-align: left; white-space: normal; }
.bal-schema .cfo-matrix th.text-right,
.bal-schema .cfo-matrix td.text-right { text-align: right; }
.bal-schema .cfo-matrix td:first-child { position: static; }

/*  Portato da TexhubPointex. Le classi sono le stesse perche' le pagine
    sono le stesse: quello che cambia sono i TOKEN sotto, che qui non
    hanno i tre temi per ruolo. --btn-primary, --ink, --line, --card-bg e
    --accent-strong esistono in tutti e due i progetti, ed e' il motivo per
    cui questo blocco si copia senza toccarlo.  */
/* ==========================================================================
   CRM
   --------------------------------------------------------------------------
   Solo token, nessun colore letterale: l'accento e' --btn-primary, che segue
   il tema per ruolo, cosi' la stessa schermata resta blu per il commerciale e
   rossa per l'amministratore senza una riga in piu'.

   Le classi qui sotto servono a tre schermate che il resto del progetto non
   aveva: la scheda cliente a 360 gradi (una griglia di riquadri che si
   riordina da sola quando lo schermo si stringe), l'imbuto delle trattative, e
   la schermata d'invio di una campagna, dove la cosa piu' importante e' che si
   VEDA quanti destinatari escono e perche'.
   ========================================================================== */

/* --- la scheda a 360 gradi ------------------------------------------------ */
.crm-scheda { display: grid; gap: 12px; grid-template-columns: repeat(12, 1fr); }
.crm-scheda > .crm-blocco { grid-column: span 12; }
@media (min-width: 1100px) {
    .crm-scheda > .crm-blocco.meta  { grid-column: span 6; }
    .crm-scheda > .crm-blocco.terzo { grid-column: span 4; }
}

.crm-blocco {
    background: var(--card-bg);
    border-radius: var(--md-sys-shape-corner-medium);
    box-shadow: var(--md-sys-elevation-level1);
    overflow: hidden;
}
.crm-blocco > h2 {
    font: var(--md-sys-typescale-title-small);
    margin: 0; padding: 12px 16px;
    border-bottom: 1px solid var(--line);
    display: flex; align-items: center; gap: 8px;
}
.crm-blocco > h2 i { color: var(--btn-primary); }
.crm-blocco > .corpo { padding: 12px 16px; }

/* Le cifre della testata. Sono grandi perche' sono la risposta alla domanda
   con cui si apre la scheda: quanto vale questo cliente, e come sta. */
.crm-cifre { display: flex; flex-wrap: wrap; gap: 12px; }
.crm-cifra {
    flex: 1 1 150px; min-width: 130px;
    padding: 12px 14px; border-radius: var(--r);
    background: var(--md-sys-color-surface-container-low);
    border-left: 3px solid var(--btn-primary);
}
/* display:block e non inline: l'etichetta e il valore sono <span>, e da
   inline si attaccano - «CODICE CLIENTE1601115» invece di due righe. Il
   margin-top su un elemento inline, per giunta, non ha nessun effetto. */
.crm-cifra .etichetta {
    display: block;
    font: var(--md-sys-typescale-label-small);
    color: var(--ink-3); text-transform: uppercase; letter-spacing: .04em;
    line-height: 1.3;
}
.crm-cifra .valore {
    display: block;
    font: var(--md-sys-typescale-title-medium);
    color: var(--ink); font-weight: 600; margin-top: 2px;
    overflow-wrap: anywhere;
}
.crm-cifra .nota { font-size: .78rem; color: var(--ink-3); margin-top: 2px; }
.crm-cifra.su   { border-left-color: var(--md-sys-color-success); }
.crm-cifra.giu  { border-left-color: var(--md-sys-color-error); }
.crm-cifra.muta { border-left-color: var(--line); }

/* Il dato che non c'e' non e' uno zero: si scrive, e si scrive in grigio. */
.crm-nd { color: var(--ink-3); font-style: italic; }

/* --- l'imbuto ------------------------------------------------------------- */
.crm-imbuto { display: flex; flex-direction: column; gap: 6px; }
.crm-imbuto-fase {
    display: grid; grid-template-columns: 1fr auto auto; gap: 10px;
    align-items: center; padding: 8px 12px; border-radius: var(--r);
    background: var(--md-sys-color-surface-container-low);
    position: relative; overflow: hidden;
}
/* La barra e' proporzionale al valore PESATO, non al valore pieno: e' l'unico
   numero che ha senso sommare su un imbuto. */
.crm-imbuto-fase .barra {
    position: absolute; inset: 0 auto 0 0;
    background: color-mix(in srgb, var(--btn-primary) 16%, transparent);
    z-index: 0;
}
.crm-imbuto-fase > * { position: relative; z-index: 1; }
.crm-imbuto-fase .nome { font-weight: 600; }
.crm-imbuto-fase .conteggio { color: var(--ink-2); font-size: .85rem; }
.crm-imbuto-fase .valore { font-weight: 600; font-variant-numeric: tabular-nums; }

/* --- pastiglie di stato --------------------------------------------------- */
.crm-chip {
    display: inline-flex; align-items: center; gap: 5px;
    padding: 2px 9px; border-radius: var(--md-sys-shape-corner-full);
    font-size: .76rem; font-weight: 600; white-space: nowrap;
}
.crm-chip.neutro   { background: var(--md-sys-color-surface-container-high); color: var(--ink-2); }
.crm-chip.buono    { background: var(--md-sys-color-success-container); color: var(--md-sys-color-success); }
.crm-chip.avviso   { background: var(--md-sys-color-warning-container); color: var(--md-sys-color-warning); }
.crm-chip.male     { background: var(--md-sys-color-error-container); color: var(--md-sys-color-error); }
.crm-chip.accento  { background: var(--md-sys-color-primary-container); color: var(--md-sys-color-primary); }

/* --- il diario ------------------------------------------------------------ */
.crm-diario { display: flex; flex-direction: column; }
.crm-diario-riga {
    display: grid; grid-template-columns: 92px 1fr; gap: 12px;
    padding: 10px 0; border-bottom: 1px solid var(--line-soft);
}
.crm-diario-riga:last-child { border-bottom: none; }
.crm-diario-riga .quando {
    font-size: .8rem; color: var(--ink-3); font-variant-numeric: tabular-nums;
}
.crm-diario-riga .cosa .titolo { font-weight: 600; }
.crm-diario-riga .cosa .testo {
    font-size: .87rem; color: var(--ink-2); margin-top: 3px;
    white-space: pre-wrap; overflow-wrap: anywhere;
}
.crm-diario-riga.scaduta .quando { color: var(--md-sys-color-error); font-weight: 600; }

/* --- la schermata d'invio ------------------------------------------------- */
/* Il conteggio degli ammessi e degli esclusi e' la cosa piu' importante della
   pagina: un numero di destinatari piu' basso del previsto va spiegato PRIMA
   di mandare, non scoperto dopo. */
.crm-verdetto { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 12px; }
.crm-verdetto .voce {
    flex: 1 1 140px; padding: 10px 14px; border-radius: var(--r);
    background: var(--md-sys-color-surface-container-low);
}
.crm-verdetto .voce .n {
    font: var(--md-sys-typescale-title-medium); font-weight: 700;
    font-variant-numeric: tabular-nums;
}
.crm-verdetto .voce .et { font-size: .78rem; color: var(--ink-3); }
.crm-verdetto .voce.blocca { background: var(--md-sys-color-error-container); }
.crm-verdetto .voce.blocca .n { color: var(--md-sys-color-error); }

.crm-impedimenti { list-style: none; margin: 0 0 12px; padding: 0;
                   display: flex; flex-direction: column; gap: 6px; }
.crm-impedimenti li {
    padding: 8px 12px 8px 32px; position: relative; border-radius: var(--r);
    background: var(--md-sys-color-error-container);
    color: var(--md-sys-color-error); font-size: .87rem;
}
.crm-impedimenti li::before {
    content: "\26A0"; position: absolute; left: 12px; top: 8px; font-weight: 700;
}

/* L'anteprima del messaggio sta in un iframe e non in un innerHTML: e' HTML che
   viene da fuori, e non lo si lascia girare dentro la pagina. */
.crm-anteprima {
    width: 100%; height: 520px; border: 1px solid var(--line);
    border-radius: var(--r); background: #ffffff;
}

/* --- filtri del CRM ------------------------------------------------------- */
.crm-filtri { display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-end; }
.crm-filtro { display: flex; flex-direction: column; gap: 4px; }
.crm-filtro > label {
    font: var(--md-sys-typescale-label-small); color: var(--ink-3);
}
.crm-num { font-variant-numeric: tabular-nums; }
.crm-muted { color: var(--ink-3); font-size: .84rem; }

/* =============================================================
   CRM - l'avanzamento del campione, e le cifre che si aprono
   =============================================================
   Una cifra su cui si puo' cliccare deve DIRLO prima del clic, o nessuno ci
   prova: il cursore e il bordo che si accende sono tutta la differenza fra un
   cruscotto e un foglio di numeri. Il colore viene dai token, come sempre.  */
.crm-cifra.cliccabile {
    cursor: pointer;
    transition: border-color .15s ease, background-color .15s ease;
}
.crm-cifra.cliccabile:hover {
    border-left-color: var(--btn-primary);
    background-color: var(--card-bg);
}
.crm-cifra.cliccabile:focus-visible {
    outline: 2px solid var(--btn-primary);
    outline-offset: 2px;
}

/* Il giallo dell'avviso: usato dall'esposizione quando il fido e' quasi
   esaurito, che non e' ancora un problema ma non e' piu' una tranquillita'. */
.crm-cifra.avviso { border-left-color: var(--md-sys-color-warning, #b8860b); }
.crm-chip.avviso {
    background: color-mix(in srgb, var(--md-sys-color-warning, #b8860b) 14%, transparent);
    color: var(--md-sys-color-warning, #b8860b);
}
.crm-chip.neutro {
    background: color-mix(in srgb, var(--ink-3) 12%, transparent);
    color: var(--ink-2);
}

/* La riga di un passo dell'avanzamento porta i bottoni a destra: senza questo
   finiscono sotto il testo e la colonna delle date si disallinea. */
.crm-diario-riga .header-buttons { margin-left: auto; align-self: center; }

/* Il titolo di una griglia dentro una .grid-card: la configurazione ne ha due
   una sotto l'altra e senza un'intestazione non si capisce dove finisce la
   prima. Prende la stessa tipografia degli altri titoli di blocco. */
.crm-blocco-titolo {
    font: var(--md-sys-typescale-title-small);
    color: var(--ink); margin: 0 0 8px 0; padding: 0;
}

/* ===========================================================================
   Texi, l'assistente dati

   Portato da TexhubPointex insieme al motore, e con una differenza sola
   nell'intestazione: li' il pannello sta dentro `.app-layout` perche' il tema
   PER RUOLO - blu utente, verde direzione, rosso amministratore - e' una
   classe su quel div, e appeso a `:root` il pulsante sarebbe rimasto blu anche
   per un amministratore.

   Qui la tavolozza e' una sola, «sala controllo», e quel problema non esiste.
   Il pannello sta dentro `.shell` lo stesso, per un motivo piu' banale ma
   altrettanto vero: e' `.shell` a definire il contesto di posizionamento e a
   portare le variabili di colore, e appeso fuori il pannello prenderebbe i
   valori di ripiego.

   Le regole qui sotto passano tutte dai token, `--btn-primary` compreso, che
   nei due progetti esiste in tutt'e due i fogli e vale colori diversi. Percio'
   il blocco si copia senza toccarlo: si vestira' da solo.
   =========================================================================== */

.texi-radice {
    position: fixed;
    right: 20px;
    bottom: 20px;
    z-index: 1200;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 10px;
    font-size: .86rem;
}

.texi-icona { width: 1.5em; height: 1.5em; display: block; flex: 0 0 auto; }

/* --- il pulsante --- */
.texi-pulsante {
    width: 54px;
    height: 54px;
    border-radius: 50%;
    border: none;
    background: var(--btn-primary);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.35rem;
    cursor: pointer;
    box-shadow: 0 4px 14px rgba(0, 0, 0, .22);
    transition: transform .15s ease, box-shadow .15s ease, background .15s ease;
}
.texi-pulsante:hover { background: var(--btn-primary-hover); transform: translateY(-2px); box-shadow: 0 6px 18px rgba(0,0,0,.28); }
.texi-pulsante:active { transform: translateY(0); }
.texi-pulsante.texi-aperto { font-size: 1.1rem; }

/* --- il pannello --- */
.texi-pannello {
    width: 420px;
    max-width: calc(100vw - 40px);
    height: 620px;
    max-height: calc(100vh - 120px);
    background: var(--card-bg);
    border: 1px solid var(--line);
    border-radius: 14px;
    box-shadow: 0 12px 40px rgba(0, 0, 0, .22);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.texi-testa {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 12px;
    background: var(--btn-primary);
    color: #fff;
    flex: 0 0 auto;
}
.texi-marchio { display: flex; align-items: center; gap: 7px; font-weight: 600; font-size: .98rem; }
.texi-sottotitolo { font-size: .74rem; opacity: .8; }
.texi-testa-azioni { margin-left: auto; display: flex; align-items: center; gap: 2px; }
.texi-azione {
    background: transparent; border: none; color: #fff; opacity: .85;
    width: 28px; height: 28px; border-radius: 6px; cursor: pointer;
    display: flex; align-items: center; justify-content: center; text-decoration: none;
}
.texi-azione:hover { background: rgba(255,255,255,.18); opacity: 1; color: #fff; }
.texi-azione:disabled { opacity: .4; cursor: default; }

/* --- i messaggi --- */
.texi-corpo {
    flex: 1 1 auto;
    overflow-y: auto;
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    background: var(--bg);
}

.texi-messaggio { display: flex; }
.texi-messaggio.texi-mio { justify-content: flex-end; }
.texi-messaggio.texi-suo { justify-content: flex-start; }

.texi-bolla {
    max-width: 92%;
    padding: 9px 12px;
    border-radius: 12px;
    line-height: 1.5;
    word-break: break-word;
}
.texi-mio .texi-bolla { background: var(--btn-primary); color: #fff; border-bottom-right-radius: 4px; }
.texi-suo .texi-bolla {
    background: var(--card-bg);
    color: var(--ink);
    border: 1px solid var(--line);
    border-bottom-left-radius: 4px;
}

.texi-bolla p { margin: 0 0 .5em; }
.texi-bolla p:last-child { margin-bottom: 0; }
.texi-bolla ul, .texi-bolla ol { margin: .3em 0 .5em; padding-left: 1.2em; }
.texi-bolla code { background: color-mix(in srgb, var(--ink) 8%, transparent); padding: 1px 4px; border-radius: 4px; font-size: .92em; }
.texi-titolo { font-weight: 600; margin: .4em 0 .2em; }

/*  Le tabelle scorrono dentro il loro contenitore. Una classifica con sei
    colonne dentro un pannello da 420 pixel non ci sta, e lasciarla allargare
    il pannello vorrebbe dire un pannello che cambia larghezza a ogni
    risposta.  */
.texi-tabella { overflow-x: auto; margin: .4em 0; }
.texi-tabella table { border-collapse: collapse; font-size: .8rem; width: 100%; }
.texi-tabella th, .texi-tabella td { padding: 4px 8px; border-bottom: 1px solid var(--line); text-align: left; white-space: nowrap; }
.texi-tabella th { font-weight: 600; color: var(--ink-2); border-bottom: 2px solid var(--line); }
.texi-tabella td.num { text-align: right; font-variant-numeric: tabular-nums; }

/* --- l'etichetta dell'esito --- */
.texi-etichetta {
    display: inline-flex; align-items: center; gap: 5px;
    font-size: .72rem; font-weight: 600; padding: 2px 8px;
    border-radius: 999px; margin-bottom: 6px;
}
.texi-nonso  { background: color-mix(in srgb, var(--warning, #e0a800) 16%, transparent); color: var(--warning, #a07800); }
.texi-errore { background: color-mix(in srgb, var(--danger) 14%, transparent); color: var(--danger); }

/*  La riga delle fonti e il blocco dell'SQL: sono la ragione per cui a una
    risposta si puo' credere. Piccoli, ma sempre presenti.  */
.texi-fonti {
    margin-top: 8px; padding-top: 6px; border-top: 1px dashed var(--line);
    font-size: .72rem; color: var(--ink-3); display: flex; align-items: center; gap: 5px;
}
.texi-sql { margin-top: 6px; font-size: .74rem; }
.texi-sql summary { cursor: pointer; color: var(--accent-strong); user-select: none; }
.texi-sql pre {
    margin: 6px 0 0; padding: 8px; border-radius: 6px; overflow-x: auto;
    background: color-mix(in srgb, var(--ink) 6%, transparent);
    font-size: .72rem; line-height: 1.4; white-space: pre;
}

.texi-pollici { margin-top: 6px; display: flex; gap: 4px; align-items: center; }
.texi-pollice {
    background: transparent; border: 1px solid var(--line); border-radius: 6px;
    width: 26px; height: 24px; cursor: pointer; color: var(--ink-3);
    display: flex; align-items: center; justify-content: center; font-size: .78rem;
}
.texi-pollice:hover { border-color: var(--accent-strong); color: var(--accent-strong); }
.texi-grazie { font-size: .72rem; color: var(--ink-3); font-style: italic; }

/* --- mentre lavora --- */
/*  I puntini e la frase stanno insieme: la frase dice COSA sta facendo -
    «cerco il cliente...», «interrogo il venduto...» - e in una query che ci
    mette cinque secondi e' la differenza fra sembrare bloccato e sembrare al
    lavoro.  */
.texi-lavoro { display: flex; align-items: center; gap: 9px; color: var(--ink-3); }
.texi-attivita { font-size: .8rem; font-style: italic; }
.texi-puntini { display: inline-flex; gap: 3px; }
.texi-puntini span {
    width: 6px; height: 6px; border-radius: 50%;
    background: var(--accent-strong); opacity: .4;
    animation: texi-pulsa 1.2s infinite ease-in-out;
}
.texi-puntini span:nth-child(2) { animation-delay: .16s; }
.texi-puntini span:nth-child(3) { animation-delay: .32s; }
@keyframes texi-pulsa {
    0%, 80%, 100% { opacity: .25; transform: scale(.8); }
    40%           { opacity: 1;   transform: scale(1); }
}

/* --- il benvenuto --- */
.texi-benvenuto { text-align: center; padding: 28px 14px; color: var(--ink-2); }
.texi-benvenuto .texi-icona { width: 46px; height: 46px; margin: 0 auto 12px; color: var(--accent-strong); }
.texi-benvenuto p { margin: 0 0 8px; }
.texi-nota { font-size: .78rem; color: var(--ink-3); line-height: 1.5; }
.texi-suggerimenti { display: flex; flex-direction: column; gap: 6px; margin-top: 16px; }
.texi-suggerimento {
    background: var(--card-bg); border: 1px solid var(--line); border-radius: 10px;
    padding: 7px 11px; font-size: .78rem; color: var(--ink); cursor: pointer; text-align: left;
}
.texi-suggerimento:hover { border-color: var(--accent-strong); color: var(--accent-strong); }

/* --- la casella --- */
.texi-piede {
    flex: 0 0 auto; display: flex; align-items: flex-end; gap: 8px;
    padding: 10px; border-top: 1px solid var(--line); background: var(--card-bg);
}
/*  La casella e' un textarea e non un input: le domande vere sono lunghe una
    riga e mezza, e un input le fa scorrere orizzontalmente mentre si scrive.
    Maiusc+Invio va a capo, Invio manda.  */
.texi-casella {
    flex: 1 1 auto; resize: none; border: 1px solid var(--line); border-radius: 10px;
    padding: 8px 10px; font: inherit; color: var(--ink); background: var(--bg);
    min-height: 38px; max-height: 120px; line-height: 1.4;
}
.texi-casella:focus { outline: none; border-color: var(--accent-strong); }
.texi-invia {
    flex: 0 0 auto; width: 38px; height: 38px; border-radius: 10px; border: none;
    background: var(--btn-primary); color: #fff; cursor: pointer;
    display: flex; align-items: center; justify-content: center;
}
.texi-invia:hover:not(:disabled) { background: var(--btn-primary-hover); }
.texi-invia:disabled { opacity: .45; cursor: default; }

/*  Sul telefono il pannello prende quasi tutto lo schermo: un riquadro da 420
    pixel su un telefono da 360 sarebbe uscito dai bordi.  */
@media (max-width: 520px) {
    .texi-radice { right: 12px; bottom: 12px; left: 12px; align-items: stretch; }
    .texi-pannello { width: auto; height: calc(100vh - 100px); }
    .texi-pulsante { align-self: flex-end; }
}

/* ---------------------------------------------------------------------------
   La sezione amministrativa di Texi

   Le schede sono .cfo-tabs / .cfo-tab, le stesse della tesoreria e del CFO:
   la convenzione del progetto e' un <button> vero, non un TelerikTabStrip.
   Qui c'e' solo quello che le schede di Texi hanno in piu'.
   --------------------------------------------------------------------------- */

/*  Il riquadro della freschezza sta in cima e non in fondo, e non e' una
    scelta estetica: davanti a un numero strano si guarda PRIMA se il dato e'
    arrivato. Una tabella ferma significa caricamento non passato, non un bug
    di Texi - la stessa regola della tesoreria.  */
.texi-freschezza { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.texi-fresca, .texi-stantia {
    display: flex; flex-direction: column; gap: 2px;
    padding: 7px 11px; border-radius: 8px; border: 1px solid var(--line);
    background: var(--card-bg); font-size: .74rem; min-width: 150px;
}
.texi-fresca strong, .texi-stantia strong { font-size: .8rem; color: var(--ink); }
.texi-fresca span, .texi-stantia span { color: var(--ink-3); }
.texi-stantia {
    border-color: var(--warning, #e0a800);
    background: color-mix(in srgb, var(--warning, #e0a800) 10%, var(--card-bg));
}
.texi-stantia span { color: var(--warning, #a07800); font-weight: 600; }

/*  Le quattro cifre in cima all'andamento. Quella che conta e' la percentuale
    di «non so»: le domande al giorno dicono solo che qualcuno prova, il «non
    so» che scende dice che il dizionario sta migliorando.  */
.texi-cifre { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 14px; }
.texi-cifra {
    flex: 1 1 140px; padding: 12px 14px; border-radius: 10px;
    border: 1px solid var(--line); background: var(--card-bg);
}
.texi-cifra dt { font-size: .72rem; color: var(--ink-3); margin: 0 0 4px; }
.texi-cifra dd { margin: 0; font-size: 1.5rem; font-weight: 600; color: var(--ink); font-variant-numeric: tabular-nums; }
.texi-cifra dd small { display: block; font-size: .7rem; font-weight: 400; color: var(--ink-3); margin-top: 2px; }
.texi-cifra.texi-attenzione { border-color: var(--warning, #e0a800); }
.texi-cifra.texi-attenzione dd { color: var(--warning, #a07800); }

.texi-domanda-testo { max-width: 460px; white-space: normal; line-height: 1.4; }
.texi-sql-cella {
    font-family: ui-monospace, Consolas, monospace; font-size: .72rem;
    max-width: 380px; white-space: pre-wrap; word-break: break-all; color: var(--ink-2);
}
.texi-badge {
    display: inline-block; padding: 1px 7px; border-radius: 999px;
    font-size: .7rem; font-weight: 600;
}
.texi-badge-risposta    { background: color-mix(in srgb, var(--success) 14%, transparent); color: var(--success); }
.texi-badge-chiarimento { background: color-mix(in srgb, var(--btn-primary) 14%, transparent); color: var(--accent-strong); }
.texi-badge-nonso       { background: color-mix(in srgb, var(--warning, #e0a800) 18%, transparent); color: var(--warning, #a07800); }
.texi-badge-errore,
.texi-badge-negato      { background: color-mix(in srgb, var(--danger) 14%, transparent); color: var(--danger); }

/* ==========================================================================
   Texi: schermo intero, voce, tabelle e grafici
   --------------------------------------------------------------------------
   Aggiunte al pannello che c'era gia'. Tre gruppi:

   LA PAGINA INTERA riusa .users-page e non ridefinisce niente di suo: la
   conversazione e' lo stesso componente del pannello, e l'unica differenza e'
   che qui puo' respirare. Il corpo prende l'altezza dello schermo meno la
   testata e il piede, se no si scorre due volte - una nella pagina e una nella
   conversazione - che e' il modo piu' rapido di far perdere il segno.

   LA RIGA DELL'ASCOLTO sta fuori dalla casella e ha un id: il testo parziale
   lo scrive il JavaScript direttamente li' dentro, senza passare dal server.
   E' la ragione per cui la dettatura non sembra a scatti su una VPN.

   LA TABELLA sotto una risposta ha la sua testata con il conteggio e i bottoni.
   L'avviso «elenco parziale» e' in evidenza apposta: una tabella tagliata che
   sembra intera e' un numero sbagliato con un'altra faccia.
   ========================================================================== */

.texi-pagina .page-header h1 { display: flex; align-items: center; gap: 10px; }
.texi-pagina .page-header h1 .texi-icona { width: 30px; height: 30px; }

.texi-pagina-conversazione {
    display: flex;
    flex-direction: column;
    /* la testata della pagina, il piede dell'applicazione e i margini */
    height: calc(100vh - 210px);
    min-height: 380px;
    padding: 0;
    overflow: hidden;
}

.texi-corpo-largo { padding: 18px 22px; }
.texi-corpo-largo .texi-bolla { max-width: 74ch; }
.texi-corpo-largo .texi-messaggio { margin-bottom: 16px; }

/* --- la voce --- */
.texi-ascolto {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 14px 0;
    font-size: .82rem;
    color: var(--ink);
    opacity: .85;
    min-height: 26px;
}
.texi-ascolto-spento { display: none; }
.texi-ascolto-fase { font-weight: 600; color: var(--accent-strong); white-space: nowrap; }
.texi-parziale { color: var(--ink); opacity: .7; font-style: italic; }

.texi-onda { display: inline-flex; align-items: flex-end; gap: 2px; height: 14px; }
.texi-onda span {
    width: 3px; height: 4px; border-radius: 2px;
    background: var(--btn-primary);
    animation: texi-onda 1s ease-in-out infinite;
}
.texi-onda span:nth-child(2) { animation-delay: .15s; }
.texi-onda span:nth-child(3) { animation-delay: .3s; }
@keyframes texi-onda { 0%,100% { height: 4px; } 50% { height: 14px; } }

.texi-microfono {
    background: none;
    border: 1px solid var(--line);
    border-radius: 10px;
    width: 38px; height: 38px;
    color: var(--ink);
    cursor: pointer;
    flex: 0 0 auto;
    transition: background .15s, color .15s, border-color .15s;
}
.texi-microfono:hover:not(:disabled) { border-color: var(--btn-primary); color: var(--btn-primary); }
.texi-microfono-acceso {
    background: var(--btn-primary);
    border-color: var(--btn-primary);
    color: #fff;
}
/*  Il microfono impossibile resta VISIBILE e spento, con il motivo nel title:
    un bottone che sparisce senza spiegazione diventa una segnalazione
    all'assistenza il giorno stesso.  */
.texi-microfono-spento { opacity: .4; cursor: not-allowed; }

/* --- tabella e grafico sotto una risposta --- */
.texi-tabella {
    margin: 10px 0 4px;
    border: 1px solid var(--line);
    border-radius: 10px;
    overflow: hidden;
    background: var(--card-bg);
}
.texi-tabella-testa {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 6px 10px;
    border-bottom: 1px solid var(--line);
    font-size: .78rem;
}
.texi-tabella-conta { color: var(--ink); opacity: .7; }
.texi-parziale-avviso { color: var(--danger); opacity: 1; }
.texi-tabella-azioni { display: flex; gap: 4px; }

.texi-azione-piccola {
    background: none;
    border: 1px solid transparent;
    border-radius: 7px;
    width: 28px; height: 28px;
    color: var(--ink);
    opacity: .65;
    cursor: pointer;
}
.texi-azione-piccola:hover {
    opacity: 1;
    border-color: var(--line);
    color: var(--btn-primary);
}

.texi-tabella .k-grid { border: none; font-size: .82rem; }
.texi-tabella .k-grid td, .texi-tabella .k-grid th { padding: 5px 8px; }

/* ==========================================================================
   Texi: la sezione amministrativa, drill-down e dettaglio
   --------------------------------------------------------------------------
   Le cifre in cima erano <dd> di testo puro. Adesso sono <button>, e la
   differenza non e' estetica: cliccare sul «33% non lo so» porta all'elenco
   filtrato su quella condizione, con la cifra e le righe che vengono dalla
   stessa query - cosi' non possono raccontare due cose diverse.

   Il pannello di dettaglio mostra IL RAGIONAMENTO, non solo il risultato. Un
   passo «Rifiutata» e' la riga piu' interessante di tutte: nel testo della
   risposta non compare mai, perche' il modello poi si corregge e racconta solo
   il tentativo riuscito.
   ========================================================================== */

.texi-cifra-cliccabile {
    text-align: left;
    border: 1px solid var(--line);
    background: var(--card-bg);
    cursor: pointer;
    font: inherit;
    color: inherit;
    transition: border-color .15s, transform .1s;
}
.texi-cifra-cliccabile:hover {
    border-color: var(--btn-primary);
    transform: translateY(-1px);
}
.texi-cifra-cliccabile:active { transform: none; }

/* Le cifre senza fonte: se non sono zero, si vedono da lontano. */
.texi-cifra.texi-allarme { border-color: var(--danger); }
.texi-cifra.texi-allarme dd { color: var(--danger); }

.filter-item-wide { flex: 1 1 260px; }

.texi-costo { font-variant-numeric: tabular-nums; opacity: .8; }

/* --- il pannello di dettaglio --- */
.texi-dett-riga {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 12px;
    padding-bottom: 10px;
    border-bottom: 1px solid var(--line);
    font-size: .85rem;
}
.texi-dett-tema {
    padding: 2px 8px;
    border-radius: 10px;
    background: color-mix(in srgb, var(--btn-primary) 12%, transparent);
    color: var(--accent-strong);
}
.texi-dett-blocco { margin-top: 14px; }
.texi-dett-blocco h4 {
    font-size: .78rem;
    text-transform: uppercase;
    letter-spacing: .04em;
    opacity: .6;
    margin: 0 0 6px;
}
.texi-dett-domanda { font-size: 1.02rem; font-weight: 600; margin: 0; }
.texi-dett-risposta { font-size: .9rem; line-height: 1.5; }
.texi-dett-risposta table { width: 100%; border-collapse: collapse; margin: 8px 0; }
.texi-dett-risposta th, .texi-dett-risposta td {
    border: 1px solid var(--line); padding: 4px 8px; font-size: .82rem;
}

/*  I passi, in ordine. Il colore dice l'esito a colpo d'occhio: una query
    rifiutata in mezzo a una risposta riuscita e' la cosa da notare per prima.  */
.texi-passi { margin: 0; padding-left: 20px; }
.texi-passo { margin-bottom: 8px; font-size: .84rem; }
.texi-passo-nome { font-weight: 600; }
.texi-passo-arg { opacity: .75; margin-left: 6px; }
.texi-passo-esito {
    margin-left: 8px; padding: 1px 7px; border-radius: 9px; font-size: .74rem;
    background: color-mix(in srgb, var(--btn-primary) 12%, transparent);
    color: var(--accent-strong);
}
.texi-passo-rifiutata .texi-passo-esito { background: color-mix(in srgb, var(--danger) 14%, transparent); color: var(--danger); }
.texi-passo-errore   .texi-passo-esito { background: color-mix(in srgb, var(--danger) 14%, transparent); color: var(--danger); }
.texi-passo-vuoto    .texi-passo-esito { background: color-mix(in srgb, var(--warning, #e0a800) 16%, transparent); color: var(--warning, #a07800); }
.texi-passo-righe, .texi-passo-ms { margin-left: 8px; opacity: .55; font-size: .76rem; }
.texi-passo-sql {
    margin: 5px 0 0;
    padding: 6px 9px;
    background: color-mix(in srgb, var(--ink) 5%, transparent);
    border-radius: 6px;
    font-size: .76rem;
    white-space: pre-wrap;
    max-height: 160px;
    overflow: auto;
}

.texi-dett-misure {
    display: flex;
    flex-wrap: wrap;
    gap: 16px;
    padding-top: 10px;
    border-top: 1px solid var(--line);
    font-size: .82rem;
    opacity: .85;
}
.texi-pollice-su  { color: var(--btn-primary); }
.texi-pollice-giu { color: var(--danger); }

/*  Una finestra non ha un tetto d'altezza suo: senza questo, un dettaglio con
    dieci passi esce dallo schermo e il piede diventa irraggiungibile. E' la
    stessa trappola gia' pagata sulle finestre del configuratore prezzi.  */
.texi-dettaglio .k-window-content { max-height: 68vh; overflow-y: auto; }

/* ==========================================================================
   TEXI - IL COSTRUTTORE DI QUERY
   --------------------------------------------------------------------------
   «Deve essere un sistema sempre da utilizzare anche per chi non sa scrivere
    sql.»

   Quello che questo foglio deve ottenere e' una cosa sola: che la persona
   guardi le cose nell'ordine giusto. L'SQL sta in un <details> chiuso e la
   spiegazione in italiano sta aperta e grande - l'inverso di come lo
   disegnerebbe uno sviluppatore, e il motivo per cui la pagina e' usabile da
   chi l'SQL non lo legge.

   Nessun colore letterale: tutto passa dai token, e l'accento da --btn-primary
   cosi' segue il tema per ruolo (blu utente, verde direzione, rosso admin).
   ========================================================================== */

.texi-costruttore { display: flex; flex-direction: column; gap: 12px; }

/* --- la barra dei passi ---------------------------------------------------
   Un passo bloccato resta VISIBILE e spento, non sparisce: vedere che ci sono
   cinque passi e che al terzo si e' fermi spiega dove si e' arrivati. Un passo
   che compare solo quando e' raggiungibile fa credere ogni volta di essere
   all'ultimo.                                                              */
.texi-passi {
    display: flex; gap: 8px; flex-wrap: wrap;
    padding: 10px 12px; border-radius: 12px;
    background: var(--card-bg); border: 1px solid var(--line);
}
.texi-passo {
    display: flex; align-items: center; gap: 8px;
    padding: 7px 14px 7px 8px; border-radius: 999px;
    border: 1px solid var(--line); background: transparent;
    color: var(--ink); font-size: .86rem; cursor: pointer;
    transition: background .15s, border-color .15s, opacity .15s;
}
.texi-passo:hover:not(.bloccato) { border-color: var(--btn-primary); }
.texi-passo.attivo {
    border-color: var(--btn-primary);
    background: color-mix(in srgb, var(--btn-primary) 12%, transparent);
    font-weight: 600;
}
.texi-passo.bloccato { opacity: .42; cursor: not-allowed; }
.texi-passo-numero {
    display: inline-flex; align-items: center; justify-content: center;
    width: 22px; height: 22px; border-radius: 50%;
    background: color-mix(in srgb, var(--ink) 12%, transparent);
    font-size: .78rem; font-weight: 700;
}
.texi-passo.fatto .texi-passo-numero { background: var(--btn-primary); color: #fff; }
.texi-passo.attivo .texi-passo-numero { background: var(--btn-primary); color: #fff; }

/* --- i campi -------------------------------------------------------------- */
.texi-riga-campi { display: flex; gap: 16px; flex-wrap: wrap; align-items: flex-start; }
.texi-campo, .texi-campo-largo { display: flex; flex-direction: column; gap: 4px; }
.texi-campo-largo { width: 100%; }
.texi-campo label, .texi-campo-largo label {
    font-size: .8rem; font-weight: 600; color: var(--ink);
}
.texi-campo small, .texi-campo-largo small { max-width: 640px; line-height: 1.45; }

/* --- la spiegazione, che e' il pezzo che conta ----------------------------
   Grande e in evidenza. E' l'unica cosa su cui chi non legge l'SQL puo' dire
   «no, non e' questo che volevo», ed e' quindi il vero contenuto della
   pagina - non un contorno del codice.                                     */
.texi-spiegazione {
    padding: 14px 16px; border-radius: 10px;
    background: color-mix(in srgb, var(--btn-primary) 8%, var(--card-bg));
    border-left: 4px solid var(--btn-primary);
}
.texi-spiegazione h4 { margin: 0 0 6px; font-size: .82rem; text-transform: uppercase;
                       letter-spacing: .04em; opacity: .75; }
.texi-spiegazione p { margin: 0; font-size: 1.02rem; line-height: 1.55; }

/* --- il numero atteso ----------------------------------------------------- */
.texi-attesa {
    padding: 14px 16px; border-radius: 10px;
    border: 1px dashed var(--line); background: var(--card-bg);
    display: flex; flex-direction: column; gap: 10px;
}
.texi-attesa h4 { margin: 0; font-size: .95rem; }

/* --- l'SQL, chiuso per difetto -------------------------------------------- */
.texi-sql { border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px;
            background: var(--card-bg); }
.texi-sql > summary { cursor: pointer; font-size: .86rem; opacity: .8; user-select: none; }
.texi-sql-testo textarea {
    font-family: Consolas, "Courier New", monospace !important;
    font-size: .84rem !important; line-height: 1.45 !important;
}

/* --- le tabelle disponibili ----------------------------------------------- */
.texi-tabelle-elenco { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }
.texi-tabella-chip {
    display: flex; flex-direction: column; gap: 2px;
    padding: 6px 12px; border-radius: 8px;
    border: 1px solid var(--line); background: var(--card-bg); font-size: .8rem;
}
.texi-tabella-chip span { opacity: .65; font-size: .74rem; }

/* --- l'esito della prova -------------------------------------------------- */
.texi-prova-esito { padding: 10px 14px; border-radius: 8px; margin-bottom: 10px; }
.texi-prova-esito.buona  { background: var(--md-sys-color-success-container);
                           color: var(--md-sys-color-success); }
.texi-prova-esito.cattiva { background: var(--md-sys-color-error-container);
                            color: var(--md-sys-color-error); }

/* --- l'anteprima delle righe ---------------------------------------------
   Una tabella nuda e non una TelerikGrid: qui si guardano quindici righe per
   capire se sono i dati giusti, non si pagina, non si ordina e non si
   esporta. Una griglia vera prometterebbe cose che a questo passo non
   servono.                                                                 */
.texi-anteprima { width: 100%; border-collapse: collapse; font-size: .82rem; }
.texi-anteprima th, .texi-anteprima td {
    padding: 5px 10px; border-bottom: 1px solid var(--line); text-align: left;
    white-space: nowrap; max-width: 280px; overflow: hidden; text-overflow: ellipsis;
}
.texi-anteprima th { font-weight: 600; opacity: .8; position: sticky; top: 0;
                     background: var(--card-bg); }

/* --- da dove viene il livello --------------------------------------------
   «query» e' l'unico che deve saltare all'occhio: sono i calcoli, quelli su
   cui nessuna regola puo' decidere e che vanno guardati a mano. Gli altri due
   sono conferme, e una conferma che grida quanto un allarme insegna a
   ignorare gli allarmi.                                                    */
.texi-fonte {
    display: inline-block; padding: 1px 8px; border-radius: 999px;
    font-size: .7rem; text-transform: lowercase; border: 1px solid var(--line);
}
.texi-fonte.dizionario { opacity: .7; }
.texi-fonte.persona    { opacity: .7; }
.texi-fonte.query      { border-color: var(--md-sys-color-warning);
                         background: var(--md-sys-color-warning-container); color: #854d0e; }
.texi-fonte.predefinito { border-color: var(--md-sys-color-error);
                          background: var(--md-sys-color-error-container);
                          color: var(--md-sys-color-error); }

/* --- il verdetto ---------------------------------------------------------- */
.texi-verdetto { font-size: 1.05rem; font-weight: 600; padding: 10px 14px;
                 border-radius: 8px; margin-bottom: 10px; }
.texi-verdetto.buono   { background: var(--md-sys-color-success-container);
                         color: var(--md-sys-color-success); }
.texi-verdetto.cattivo { background: var(--md-sys-color-warning-container); color: #854d0e; }
.texi-verdetto-cattivo { color: var(--md-sys-color-error); font-weight: 600; }

.texi-controlli { list-style: none; padding: 0; margin: 0; display: flex;
                  flex-direction: column; gap: 6px; }
.texi-controlli li { padding-left: 26px; position: relative; font-size: .88rem; }
.texi-controlli li::before {
    position: absolute; left: 0; top: 0; font-weight: 700;
}
.texi-controlli li.si::before { content: "\2713"; color: var(--md-sys-color-success); }
.texi-controlli li.no::before { content: "\2717"; color: var(--md-sys-color-error); }
.texi-controlli li.no { color: var(--md-sys-color-error); }

/* --- il semaforo nell'elenco ---------------------------------------------- */
.texi-semaforo { display: inline-block; width: 11px; height: 11px; border-radius: 50%; }
.texi-semaforo.verde  { background: var(--md-sys-color-success); }
.texi-semaforo.giallo { background: var(--md-sys-color-warning); }
.texi-semaforo.rosso  { background: var(--md-sys-color-error); }
.texi-semaforo.grigio { background: color-mix(in srgb, var(--ink) 28%, transparent); }

.texi-ricontrollo-riga {
    font-size: .84rem; padding: 4px 0; border-bottom: 1px solid var(--line);
    font-family: Consolas, "Courier New", monospace;
}
.texi-ricontrollo-riga:last-child { border-bottom: none; }

/* ==========================================================================
   CRM
   --------------------------------------------------------------------------
   Solo token, nessun colore letterale: l'accento e' --btn-primary, che segue
   il tema per ruolo, cosi' la stessa schermata resta blu per il commerciale e
   rossa per l'amministratore senza una riga in piu'.

   Le classi qui sotto servono a tre schermate che il resto del progetto non
   aveva: la scheda cliente a 360 gradi (una griglia di riquadri che si
   riordina da sola quando lo schermo si stringe), l'imbuto delle trattative, e
   la schermata d'invio di una campagna, dove la cosa piu' importante e' che si
   VEDA quanti destinatari escono e perche'.
   ========================================================================== */

/* --- la scheda a 360 gradi ------------------------------------------------ */
.crm-scheda { display: grid; gap: 12px; grid-template-columns: repeat(12, 1fr); }
.crm-scheda > .crm-blocco { grid-column: span 12; }
@media (min-width: 1100px) {
    .crm-scheda > .crm-blocco.meta  { grid-column: span 6; }
    .crm-scheda > .crm-blocco.terzo { grid-column: span 4; }
}

.crm-blocco {
    background: var(--card-bg);
    border-radius: var(--md-sys-shape-corner-medium);
    box-shadow: var(--md-sys-elevation-level1);
    overflow: hidden;
}
.crm-blocco > h2 {
    font: var(--md-sys-typescale-title-small);
    margin: 0; padding: 12px 16px;
    border-bottom: 1px solid var(--line);
    display: flex; align-items: center; gap: 8px;
}
.crm-blocco > h2 i { color: var(--btn-primary); }
.crm-blocco > .corpo { padding: 12px 16px; }

/* Le cifre della testata. Sono grandi perche' sono la risposta alla domanda
   con cui si apre la scheda: quanto vale questo cliente, e come sta. */
.crm-cifre { display: flex; flex-wrap: wrap; gap: 12px; }
.crm-cifra {
    flex: 1 1 150px; min-width: 130px;
    padding: 12px 14px; border-radius: var(--r);
    background: var(--md-sys-color-surface-container-low);
    border-left: 3px solid var(--btn-primary);
}
/* display:block e non inline: l'etichetta e il valore sono <span>, e da
   inline si attaccano - «CODICE CLIENTE1601115» invece di due righe. Il
   margin-top su un elemento inline, per giunta, non ha nessun effetto. */
.crm-cifra .etichetta {
    display: block;
    font: var(--md-sys-typescale-label-small);
    color: var(--ink-3); text-transform: uppercase; letter-spacing: .04em;
    line-height: 1.3;
}
.crm-cifra .valore {
    display: block;
    font: var(--md-sys-typescale-title-medium);
    color: var(--ink); font-weight: 600; margin-top: 2px;
    overflow-wrap: anywhere;
}
.crm-cifra .nota { font-size: .78rem; color: var(--ink-3); margin-top: 2px; }
.crm-cifra.su   { border-left-color: var(--md-sys-color-success); }
.crm-cifra.giu  { border-left-color: var(--md-sys-color-error); }
.crm-cifra.muta { border-left-color: var(--line); }

/* Il dato che non c'e' non e' uno zero: si scrive, e si scrive in grigio. */
.crm-nd { color: var(--ink-3); font-style: italic; }

/* --- l'imbuto ------------------------------------------------------------- */
.crm-imbuto { display: flex; flex-direction: column; gap: 6px; }
.crm-imbuto-fase {
    display: grid; grid-template-columns: 1fr auto auto; gap: 10px;
    align-items: center; padding: 8px 12px; border-radius: var(--r);
    background: var(--md-sys-color-surface-container-low);
    position: relative; overflow: hidden;
}
/* La barra e' proporzionale al valore PESATO, non al valore pieno: e' l'unico
   numero che ha senso sommare su un imbuto. */
.crm-imbuto-fase .barra {
    position: absolute; inset: 0 auto 0 0;
    background: color-mix(in srgb, var(--btn-primary) 16%, transparent);
    z-index: 0;
}
.crm-imbuto-fase > * { position: relative; z-index: 1; }
.crm-imbuto-fase .nome { font-weight: 600; }
.crm-imbuto-fase .conteggio { color: var(--ink-2); font-size: .85rem; }
.crm-imbuto-fase .valore { font-weight: 600; font-variant-numeric: tabular-nums; }

/* --- pastiglie di stato --------------------------------------------------- */
.crm-chip {
    display: inline-flex; align-items: center; gap: 5px;
    padding: 2px 9px; border-radius: var(--md-sys-shape-corner-full);
    font-size: .76rem; font-weight: 600; white-space: nowrap;
}
.crm-chip.neutro   { background: var(--md-sys-color-surface-container-high); color: var(--ink-2); }
.crm-chip.buono    { background: var(--md-sys-color-success-container); color: var(--md-sys-color-success); }
.crm-chip.avviso   { background: var(--md-sys-color-warning-container); color: var(--md-sys-color-warning); }
.crm-chip.male     { background: var(--md-sys-color-error-container); color: var(--md-sys-color-error); }
.crm-chip.accento  { background: var(--md-sys-color-primary-container); color: var(--md-sys-color-primary); }

/* --- il diario ------------------------------------------------------------ */
.crm-diario { display: flex; flex-direction: column; }
.crm-diario-riga {
    display: grid; grid-template-columns: 92px 1fr; gap: 12px;
    padding: 10px 0; border-bottom: 1px solid var(--line-soft);
}
.crm-diario-riga:last-child { border-bottom: none; }
.crm-diario-riga .quando {
    font-size: .8rem; color: var(--ink-3); font-variant-numeric: tabular-nums;
}
.crm-diario-riga .cosa .titolo { font-weight: 600; }
.crm-diario-riga .cosa .testo {
    font-size: .87rem; color: var(--ink-2); margin-top: 3px;
    white-space: pre-wrap; overflow-wrap: anywhere;
}
.crm-diario-riga.scaduta .quando { color: var(--md-sys-color-error); font-weight: 600; }

/* --- la schermata d'invio ------------------------------------------------- */
/* Il conteggio degli ammessi e degli esclusi e' la cosa piu' importante della
   pagina: un numero di destinatari piu' basso del previsto va spiegato PRIMA
   di mandare, non scoperto dopo. */
.crm-verdetto { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 12px; }
.crm-verdetto .voce {
    flex: 1 1 140px; padding: 10px 14px; border-radius: var(--r);
    background: var(--md-sys-color-surface-container-low);
}
.crm-verdetto .voce .n {
    font: var(--md-sys-typescale-title-medium); font-weight: 700;
    font-variant-numeric: tabular-nums;
}
.crm-verdetto .voce .et { font-size: .78rem; color: var(--ink-3); }
.crm-verdetto .voce.blocca { background: var(--md-sys-color-error-container); }
.crm-verdetto .voce.blocca .n { color: var(--md-sys-color-error); }

.crm-impedimenti { list-style: none; margin: 0 0 12px; padding: 0;
                   display: flex; flex-direction: column; gap: 6px; }
.crm-impedimenti li {
    padding: 8px 12px 8px 32px; position: relative; border-radius: var(--r);
    background: var(--md-sys-color-error-container);
    color: var(--md-sys-color-error); font-size: .87rem;
}
.crm-impedimenti li::before {
    content: "\26A0"; position: absolute; left: 12px; top: 8px; font-weight: 700;
}

/* L'anteprima del messaggio sta in un iframe e non in un innerHTML: e' HTML che
   viene da fuori, e non lo si lascia girare dentro la pagina. */
.crm-anteprima {
    width: 100%; height: 520px; border: 1px solid var(--line);
    border-radius: var(--r); background: #ffffff;
}

/* --- filtri del CRM ------------------------------------------------------- */
.crm-filtri { display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-end; }
.crm-filtro { display: flex; flex-direction: column; gap: 4px; }
.crm-filtro > label {
    font: var(--md-sys-typescale-label-small); color: var(--ink-3);
}
.crm-num { font-variant-numeric: tabular-nums; }
.crm-muted { color: var(--ink-3); font-size: .84rem; }

/* =============================================================
   CRM - l'avanzamento del campione, e le cifre che si aprono
   =============================================================
   Una cifra su cui si puo' cliccare deve DIRLO prima del clic, o nessuno ci
   prova: il cursore e il bordo che si accende sono tutta la differenza fra un
   cruscotto e un foglio di numeri. Il colore viene dai token, come sempre.  */
.crm-cifra.cliccabile {
    cursor: pointer;
    transition: border-color .15s ease, background-color .15s ease;
}
.crm-cifra.cliccabile:hover {
    border-left-color: var(--btn-primary);
    background-color: var(--card-bg);
}
.crm-cifra.cliccabile:focus-visible {
    outline: 2px solid var(--btn-primary);
    outline-offset: 2px;
}

/* Il giallo dell'avviso: usato dall'esposizione quando il fido e' quasi
   esaurito, che non e' ancora un problema ma non e' piu' una tranquillita'. */
.crm-cifra.avviso { border-left-color: var(--md-sys-color-warning, #b8860b); }
.crm-chip.avviso {
    background: color-mix(in srgb, var(--md-sys-color-warning, #b8860b) 14%, transparent);
    color: var(--md-sys-color-warning, #b8860b);
}
.crm-chip.neutro {
    background: color-mix(in srgb, var(--ink-3) 12%, transparent);
    color: var(--ink-2);
}

/* La riga di un passo dell'avanzamento porta i bottoni a destra: senza questo
   finiscono sotto il testo e la colonna delle date si disallinea. */
.crm-diario-riga .header-buttons { margin-left: auto; align-self: center; }

/* Il titolo di una griglia dentro una .grid-card: la configurazione ne ha due
   una sotto l'altra e senza un'intestazione non si capisce dove finisce la
   prima. Prende la stessa tipografia degli altri titoli di blocco. */
.crm-blocco-titolo {
    font: var(--md-sys-typescale-title-small);
    color: var(--ink); margin: 0 0 8px 0; padding: 0;
}

/* =============================================================
   CRM - la pagina di feedback, che la vede un cliente
   =============================================================
   E' l'unica schermata del progetto che apre qualcuno che non e' un utente
   dell'intranet, e va trattata come tale: piu' larga della scheda di login,
   perche' undici bottoni in fila su un telefono devono starci, e senza niente
   che somigli a un pannello di amministrazione. */
.feedback-card { max-width: 560px; }

.feedback-scala {
    display: flex; flex-wrap: wrap; gap: 6px;
    justify-content: center; margin: 18px 0 4px 0;
}

/* Il bottone del voto e' grande abbastanza da premersi col pollice: 44px e' il
   minimo che le linee guida di accessibilita' danno per un'area toccabile, e
   sotto quella misura si sbaglia numero. */
.feedback-voto {
    min-width: 44px; min-height: 44px;
    border: 1px solid var(--line); border-radius: 8px;
    background: var(--card-bg); color: var(--ink);
    font: var(--md-sys-typescale-title-small);
    cursor: pointer; transition: background-color .12s ease, border-color .12s ease;
}
.feedback-voto:hover { border-color: var(--btn-primary); }
.feedback-voto.scelto {
    background: var(--btn-primary); border-color: var(--btn-primary); color: #fff;
}
.feedback-voto:focus-visible { outline: 2px solid var(--btn-primary); outline-offset: 2px; }

/* Gli estremi della scala sotto i bottoni: senza, «0» e «10» non dicono in
   quale verso vada letta la domanda, e c'e' chi risponde 0 intendendo 10. */
.feedback-estremi {
    display: flex; justify-content: space-between;
    color: var(--ink-3); font-size: .82rem; margin-bottom: 14px;
}

/* ===========================================================================
   I reclami: le code e la scheda

   Poco CSS, e non per pigrizia: quasi tutto quello che serve esiste gia' -
   .crm-cifre per i riquadri, .crm-chip per le etichette di stato, .crm-nd per
   il «non disponibile». Qui c'e' solo quello che le due schermate nuove
   aggiungono davvero.

   Tutto passa dai token: --btn-primary segue il tema per ruolo, e un colore
   letterale qui dentro resterebbe blu anche per un amministratore.
   =========================================================================== */

/*  Un riquadro di coda si preme: e' il gesto principale dell'elenco, e deve
    sembrarlo prima di essere provato.  */
.coda-cliccabile { cursor: pointer; transition: transform .12s ease, box-shadow .12s ease; }
.coda-cliccabile:hover { transform: translateY(-2px); box-shadow: 0 4px 14px rgba(0,0,0,.10); }
.coda-cliccabile:focus-visible { outline: 2px solid var(--btn-primary); outline-offset: 2px; }

/*  I bottoni del passo avanti, uno per riga con accanto scritto dove porta.
    In colonna e non in fila: sono decisioni, non una barra di strumenti, e
    leggerle una per una e' esattamente il ritmo giusto.  */
.crm-azioni { display: flex; flex-direction: column; gap: 10px; }
.crm-azione { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.crm-azione .crm-muted { font-size: .85rem; }

/*  La griglia dei campi della scheda: due colonne su schermo largo, una sola
    quando non ci sta. `auto-fit` invece di un numero fisso perche' i blocchi
    hanno da due a sei campi e un numero fisso lascerebbe buchi.  */
.crm-scheda-griglia {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
    gap: 10px 24px;
    margin: 12px 0 18px;
}
.crm-campo { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.crm-campo > .etichetta {
    font-size: .78rem; text-transform: uppercase; letter-spacing: .04em;
    color: var(--ink-3);
}
.crm-campo > .valore { font-size: .98rem; color: var(--ink); word-break: break-word; }

/*  Il testo del reclamo e' quello che il cliente ha scritto, e va letto:
    a capo conservati, larghezza limitata perche' una riga lunga tutto lo
    schermo non si segue con gli occhi.  */
.crm-testo-lungo {
    white-space: pre-wrap;
    max-width: 88ch;
    line-height: 1.55;
    color: var(--ink);
    margin: 6px 0 16px;
}

/*  Dentro un riquadro .crm-cifra il valore e' pensato per un numero: quando e'
    un nome di stato o una ragione sociale va rimpicciolito, o esce dal box.  */
.crm-cifra .crm-valore-testo {
    font-size: 1.05rem;
    font-weight: 600;
    line-height: 1.3;
    word-break: break-word;
}

/*  Il ritardo si vede senza doverlo cercare, ed e' l'unica evidenza forte
    dell'elenco: tutto il resto e' neutro di proposito.  */
.crm-ritardo { color: var(--md-sys-color-error, #b3282d); font-weight: 600; }

/*  Una spunta con la sua etichetta dentro la riga dei filtri. TelerikCheckBox
    non ha una Label sua: l'idioma di casa e' un <label> vero attorno.  */
.crm-spunta { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; }
.crm-spunta > span { font-size: .9rem; color: var(--ink); }
