﻿/*
 * TexHub - Unified Stylesheet
 * Material Design 3 (M3) Theme
 * User (Blue-Indigo) | Manager (Teal-Emerald) | Admin (Rose-Coral)
 */

/* ========================================
   M3 Design Tokens - Core
   ======================================== */

:root {
    /* M3 Reference Palette - Neutral */
    --md-ref-palette-neutral0: #000000;
    --md-ref-palette-neutral10: #1a1c1e;
    --md-ref-palette-neutral20: #2f3033;
    --md-ref-palette-neutral30: #46474a;
    --md-ref-palette-neutral40: #5e5e62;
    --md-ref-palette-neutral50: #76777a;
    --md-ref-palette-neutral60: #909094;
    --md-ref-palette-neutral70: #ababae;
    --md-ref-palette-neutral80: #c6c6c9;
    --md-ref-palette-neutral90: #e2e2e5;
    --md-ref-palette-neutral95: #f1f0f4;
    --md-ref-palette-neutral99: #fdfbff;
    --md-ref-palette-neutral100: #ffffff;

    /* M3 Surface Tones */
    --md-sys-color-surface: #fdfbff;
    --md-sys-color-surface-dim: #ddd9de;
    --md-sys-color-surface-bright: #fdfbff;
    --md-sys-color-surface-container-lowest: #ffffff;
    --md-sys-color-surface-container-low: #f7f5f9;
    --md-sys-color-surface-container: #f1eff3;
    --md-sys-color-surface-container-high: #eceaee;
    --md-sys-color-surface-container-highest: #e6e4e8;

    /* M3 Common */
    --md-sys-color-outline: #79747e;
    --md-sys-color-outline-variant: #cac4cf;
    --md-sys-color-shadow: rgba(0, 0, 0, 0.15);
    --md-sys-color-scrim: rgba(0, 0, 0, 0.32);

    /* Status Colors */
    --md-sys-color-success: #1b873f;
    --md-sys-color-success-container: #c3f7d1;
    --md-sys-color-warning: #e5a000;
    --md-sys-color-warning-container: #fff0c7;
    --md-sys-color-error: #ba1a1a;
    --md-sys-color-error-container: #ffdad6;
    --md-sys-color-info: #0061a4;
    --md-sys-color-info-container: #d1e4ff;

    /* Typography */
    --md-sys-typescale-headline-large: 600 2rem/2.5rem 'Inter', system-ui, sans-serif;
    --md-sys-typescale-headline-medium: 600 1.75rem/2.25rem 'Inter', system-ui, sans-serif;
    --md-sys-typescale-headline-small: 600 1.5rem/2rem 'Inter', system-ui, sans-serif;
    --md-sys-typescale-title-large: 500 1.375rem/1.75rem 'Inter', system-ui, sans-serif;
    --md-sys-typescale-title-medium: 500 1rem/1.5rem 'Inter', system-ui, sans-serif;
    --md-sys-typescale-title-small: 500 0.875rem/1.25rem 'Inter', system-ui, sans-serif;
    --md-sys-typescale-body-large: 400 1rem/1.5rem 'Inter', system-ui, sans-serif;
    --md-sys-typescale-body-medium: 400 0.875rem/1.25rem 'Inter', system-ui, sans-serif;
    --md-sys-typescale-body-small: 400 0.75rem/1rem 'Inter', system-ui, sans-serif;
    --md-sys-typescale-label-large: 500 0.875rem/1.25rem 'Inter', system-ui, sans-serif;
    --md-sys-typescale-label-medium: 500 0.75rem/1rem 'Inter', system-ui, sans-serif;
    --md-sys-typescale-label-small: 500 0.6875rem/1rem 'Inter', system-ui, sans-serif;

    /* Shape */
    --md-sys-shape-corner-none: 0;
    --md-sys-shape-corner-extra-small: 4px;
    --md-sys-shape-corner-small: 8px;
    --md-sys-shape-corner-medium: 12px;
    --md-sys-shape-corner-large: 16px;
    --md-sys-shape-corner-extra-large: 28px;
    --md-sys-shape-corner-full: 9999px;

    /* Elevation */
    --md-sys-elevation-level0: none;
    --md-sys-elevation-level1: 0 1px 3px 1px rgba(0,0,0,0.08), 0 1px 2px 0 rgba(0,0,0,0.04);
    --md-sys-elevation-level2: 0 2px 6px 2px rgba(0,0,0,0.08), 0 1px 2px 0 rgba(0,0,0,0.04);
    --md-sys-elevation-level3: 0 4px 8px 3px rgba(0,0,0,0.08), 0 1px 3px 0 rgba(0,0,0,0.04);
    --md-sys-elevation-level4: 0 6px 10px 4px rgba(0,0,0,0.08), 0 2px 3px 0 rgba(0,0,0,0.04);
    --md-sys-elevation-level5: 0 8px 12px 6px rgba(0,0,0,0.08), 0 4px 4px 0 rgba(0,0,0,0.04);

    /* Animation */
    --md-sys-motion-duration-short4: 200ms;
    --md-sys-motion-duration-medium2: 300ms;
    --md-sys-motion-easing-standard: cubic-bezier(0.2, 0, 0, 1);
    --md-sys-motion-easing-emphasized: cubic-bezier(0.2, 0, 0, 1);

    /* Legacy compatibility aliases */
    --primary: var(--btn-primary, #4f46e5);
    --accent: var(--md-sys-color-tertiary, #06b6d4);
    --bg: var(--md-sys-color-surface, #fdfbff);
    --card: var(--md-sys-color-surface-container-low, #f7f5f9);
    --muted: var(--md-sys-color-outline, #79747e);
    --success: var(--md-sys-color-success, #1b873f);
    --danger: var(--md-sys-color-error, #ba1a1a);
}

/* ========================================
   THEME: User Level (Blue) - Default
   Colors from Intranet2020 "utente" theme
   ======================================== */
.theme-blue, :root {
    --md-sys-color-primary: #3498db;
    --md-sys-color-primary-hover: #278bce;
    --md-sys-color-on-primary: #ffffff;
    --md-sys-color-primary-container: #d7e9fc;
    --md-sys-color-on-primary-container: #1d6fa5;
    --md-sys-color-secondary: #2980b9;
    --md-sys-color-on-secondary: #ffffff;
    --md-sys-color-secondary-container: #d7e9fc;
    --md-sys-color-on-secondary-container: #1d6fa5;
    --md-sys-color-tertiary: #1abc9c;
    --md-sys-color-on-tertiary: #ffffff;
    --md-sys-color-tertiary-container: #d1f2eb;
    --md-sys-color-on-tertiary-container: #0e6251;

    --sidebar-bg: #1d6fa5;
    --sidebar-bg-hover: rgba(255, 255, 255, 0.08);
    --sidebar-bg-active: rgba(52, 152, 219, 0.24);
    --sidebar-text: rgba(255, 255, 255, 0.87);
    --sidebar-text-muted: rgba(255, 255, 255, 0.6);
    --sidebar-accent: #85c1e9;
    --sidebar-border: rgba(255, 255, 255, 0.08);

    --btn-primary: #3498db;
    --btn-primary-hover: #278bce;
    --btn-on-primary: #ffffff;
    --avatar-bg: #3498db;
    --avatar-text: #ffffff;
    --accent: #3498db;
    --accent-light: #aed6f1;
}

/* ========================================
   THEME: Direzione Level (Green)
   Colors from Intranet2020 "manager" theme
   ======================================== */
.theme-green {
    --md-sys-color-primary: #62bc55;
    --md-sys-color-primary-hover: #4ca83f;
    --md-sys-color-on-primary: #ffffff;
    --md-sys-color-primary-container: #d5f5d0;
    --md-sys-color-on-primary-container: #2d6b23;
    --md-sys-color-secondary: #70ca63;
    --md-sys-color-on-secondary: #ffffff;
    --md-sys-color-secondary-container: #e5f2da;
    --md-sys-color-on-secondary-container: #3d8b3d;
    --md-sys-color-tertiary: #27ae60;
    --md-sys-color-on-tertiary: #ffffff;
    --md-sys-color-tertiary-container: #d5f5e3;
    --md-sys-color-on-tertiary-container: #145a32;

    --sidebar-bg: #3d8b3d;
    --sidebar-bg-hover: rgba(255, 255, 255, 0.08);
    --sidebar-bg-active: rgba(98, 188, 85, 0.24);
    --sidebar-text: rgba(255, 255, 255, 0.87);
    --sidebar-text-muted: rgba(255, 255, 255, 0.6);
    --sidebar-accent: #a8e6a1;
    --sidebar-border: rgba(255, 255, 255, 0.08);

    --btn-primary: #62bc55;
    --btn-primary-hover: #4ca83f;
    --btn-on-primary: #ffffff;
    --avatar-bg: #62bc55;
    --avatar-text: #ffffff;
    --accent: #70ca63;
    --accent-light: #c8f0c4;
}

/* ========================================
   THEME: Admin Level (Red)
   Colors from Intranet2020 "administrator/administration" theme
   ======================================== */
.theme-red {
    --md-sys-color-primary: #e7604a;
    --md-sys-color-primary-hover: #d95944;
    --md-sys-color-on-primary: #ffffff;
    --md-sys-color-primary-container: #fde8e4;
    --md-sys-color-on-primary-container: #b02913;
    --md-sys-color-secondary: #ec7063;
    --md-sys-color-on-secondary: #ffffff;
    --md-sys-color-secondary-container: #fadbd8;
    --md-sys-color-on-secondary-container: #922b21;
    --md-sys-color-tertiary: #e67e22;
    --md-sys-color-on-tertiary: #ffffff;
    --md-sys-color-tertiary-container: #fdebd0;
    --md-sys-color-on-tertiary-container: #7d3c0c;

    --sidebar-bg: #b02913;
    --sidebar-bg-hover: rgba(255, 255, 255, 0.08);
    --sidebar-bg-active: rgba(231, 96, 74, 0.24);
    --sidebar-text: rgba(255, 255, 255, 0.87);
    --sidebar-text-muted: rgba(255, 255, 255, 0.6);
    --sidebar-accent: #f5b7b1;
    --sidebar-border: rgba(255, 255, 255, 0.08);

    --btn-primary: #e7604a;
    --btn-primary-hover: #d95944;
    --btn-on-primary: #ffffff;
    --avatar-bg: #e7604a;
    --avatar-text: #ffffff;
    --accent: #e7604a;
    --accent-light: #f5b7b1;
}

/* ========================================
   Base Styles
   ======================================== */
*, *::before, *::after {
    box-sizing: border-box;
}

html {
    font-family: 'Inter', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    font-size: 16px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    margin: 0;
    background: var(--md-sys-color-surface);
    color: var(--md-ref-palette-neutral10);
    line-height: 1.5;
}

/* ========================================
   App Layout
   ======================================== */
.loading-overlay {
    position: fixed;
    inset: 0;
    background: var(--md-sys-color-surface);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
}

.loading-spinner {
    width: 48px;
    height: 48px;
    border: 4px solid var(--md-sys-color-surface-container-highest);
    border-top-color: var(--btn-primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.app-layout {
    display: flex;
    min-height: 100vh;
    background: var(--md-sys-color-surface);
}

/* ========================================
   Sidebar
   ======================================== */
.sidebar,
.sidebar.app-sidebar,
.app-sidebar {
    width: 240px;
    min-width: 240px;
    background-color: var(--sidebar-bg) !important;
    background-image: none !important;
    display: flex;
    flex-direction: column;
    transition: width var(--md-sys-motion-duration-medium2) var(--md-sys-motion-easing-emphasized),
                min-width var(--md-sys-motion-duration-medium2) var(--md-sys-motion-easing-emphasized);
    z-index: 100;
    flex-shrink: 0;
}

.sidebar.collapsed,
.app-layout.sidebar-collapsed .sidebar,
.app-layout.sidebar-collapsed .app-sidebar {
    width: 60px;
    min-width: 60px;
    overflow: hidden;
    background-color: var(--sidebar-bg) !important;
    background-image: none !important;
}

.sidebar-header {
    padding: 24px 20px;
    border-bottom: 1px solid var(--sidebar-border);
    display: flex;
    align-items: center;
}

.sidebar.collapsed .sidebar-header,
.app-layout.sidebar-collapsed .sidebar-header {
    padding: 16px 8px;
    justify-content: center;
}

.logo {
    margin: 0 auto;
    padding: 0;
    width: auto;
    text-align: center;
}

.logo img {
    max-width: 100%;
    max-height: 72px;
    width: auto;
    height: auto;
    transition: all var(--md-sys-motion-duration-short4) var(--md-sys-motion-easing-standard);
}

.sidebar.collapsed .logo img,
.app-layout.sidebar-collapsed .logo img {
    height: 28px;
    width: 28px;
    object-fit: contain;
}

.sidebar-nav {
    flex: 1;
    padding: 16px 8px;
    overflow-y: auto;
    overflow-x: hidden;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 16px;
    margin: 4px 8px;
    border-radius: var(--md-sys-shape-corner-full);
    color: rgba(255,255,255,0.8);
    text-decoration: none;
    transition: background var(--md-sys-motion-duration-short4), color var(--md-sys-motion-duration-short4);
    background: transparent;
    border: none;
    cursor: pointer;
    width: calc(100% - 16px);
    text-align: left;
}

.nav-item i {
    font-size: 1.2rem;
    flex-shrink: 0;
    width: 24px;
    text-align: center;
}

.nav-item:hover {
    background: rgba(255,255,255,0.10);
    color: #fff;
}

.nav-item.active {
    background: rgba(255,255,255,0.16);
    color: #fff;
}

/* Collapsed sidebar: hide text, show only icons */
.sidebar.collapsed .nav-text,
.app-layout.sidebar-collapsed .nav-text {
    display: none;
}

.sidebar.collapsed .nav-item,
.app-layout.sidebar-collapsed .nav-item {
    justify-content: center;
    padding: 12px;
    margin: 4px;
    width: calc(100% - 8px);
}

.sidebar.collapsed .sidebar-nav,
.app-layout.sidebar-collapsed .sidebar-nav {
    padding: 8px 4px;
}

/* ========================================
   Main Wrapper & Topbar
   ======================================== */
.main-wrapper {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.topbar {
    height: 56px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 12px;
    border-bottom: 1px solid var(--md-sys-color-outline-variant);
    background: var(--md-sys-color-surface);
    position: sticky;
    top: 0;
    z-index: 50;
}

.topbar-title {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--md-sys-color-on-surface);
    margin-left: 16px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.menu-toggle {
    width: 44px;
    height: 44px;
    border: none;
    border-radius: var(--md-sys-shape-corner-full);
    background: var(--md-sys-color-surface-container-low);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background var(--md-sys-motion-duration-short4);
    z-index: 70;
    position: relative;
}

.menu-toggle:hover {
    background: var(--md-sys-color-surface-container-highest);
}

.menu-toggle:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.menu-toggle i {
    font-size: 1.5rem;
    color: var(--md-ref-palette-neutral10);
    pointer-events: none;
}

.topbar-right {
    display: flex;
    align-items: center;
    gap: 12px;
}

/* ========================================
   User Menu (Critical z-index fix)
   ======================================== */
.user-menu {
    position: relative;
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    padding: 8px 12px;
    border-radius: var(--md-sys-shape-corner-full);
    background: var(--md-sys-color-surface-container-low);
    z-index: 1001;
    transition: background var(--md-sys-motion-duration-short4);
}

.user-menu:hover {
    background: var(--md-sys-color-surface-container-highest);
}

.user-avatar {
    width: 32px;
    height: 32px;
    border-radius: var(--md-sys-shape-corner-full);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: var(--avatar-bg);
    color: var(--avatar-text);
}

.user-name {
    color: var(--md-ref-palette-neutral10);
    font: var(--md-sys-typescale-title-small);
}

.user-dropdown {
    position: absolute;
    right: 0;
    top: calc(100% + 10px);
    min-width: 240px;
    background: var(--md-sys-color-surface);
    border: 1px solid var(--md-sys-color-outline-variant);
    border-radius: var(--md-sys-shape-corner-medium);
    box-shadow: var(--md-sys-elevation-level3);
    z-index: 1002;
    overflow: hidden;
}

.user-dropdown .dropdown-item {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 14px;
    background: transparent;
    border: none;
    text-decoration: none;
    color: var(--md-ref-palette-neutral10);
    cursor: pointer;
    transition: background var(--md-sys-motion-duration-short4);
}

.user-dropdown .dropdown-item:hover {
    background: var(--md-sys-color-surface-container-low);
}

.dropdown-divider {
    height: 1px;
    background: var(--md-sys-color-outline-variant);
    margin: 6px 0;
}

/* Language submenu */
.lang-dropdown-toggle {
    position: relative;
}

.lang-chevron {
    margin-left: auto;
    transition: transform var(--md-sys-motion-duration-short4);
}

.lang-chevron.rotated {
    transform: rotate(90deg);
}

.lang-submenu {
    background: var(--md-sys-color-surface-container-low);
    padding: 4px 0;
}

.lang-option {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 16px 10px 28px;
    background: transparent;
    border: none;
    color: var(--md-ref-palette-neutral10);
    cursor: pointer;
    transition: background var(--md-sys-motion-duration-short4);
}

.lang-option:hover {
    background: var(--md-sys-color-surface-container-highest);
}

.lang-option.active {
    color: var(--btn-primary);
}

.lang-flag {
    width: 20px;
    height: 15px;
    border-radius: 2px;
}

/* Overlay - must be under user-menu completely */
.overlay {
    position: fixed;
    inset: 0;
    background: transparent;
    z-index: 999;
}

/* ========================================
   Main Content
   ======================================== */
.main-content {
    flex: 1;
    padding: 12px;
    overflow: auto;
}

.content-container {
    margin: 0 auto;
}

/* ========================================
   Footer
   ======================================== */
.app-footer {
    padding: 12px 16px;
    border-top: 1px solid var(--md-sys-color-outline-variant);
    background: var(--md-sys-color-surface-container-low);
    display: flex;
    justify-content: space-between;
    align-items: center;
    font: var(--md-sys-typescale-body-small);
    color: var(--md-sys-color-outline);
}

/* ========================================
   Home Page
   ======================================== */
.home-container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 24px;
}

.home-header {
    margin-bottom: 40px;
    text-align: left;
}

.home-header h1 {
    font: var(--md-sys-typescale-headline-large);
    color: var(--md-ref-palette-neutral10);
    margin: 0 0 12px 0;
}

.home-header h1 span {
    color: var(--btn-primary);
}

.home-header p {
    color: var(--md-sys-color-outline);
    margin: 0;
    font: var(--md-sys-typescale-body-large);
}

.loading-state,
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 100px 20px;
    gap: 20px;
    color: var(--md-sys-color-outline);
}

.empty-state i {
    font-size: 4rem;
    opacity: 0.5;
}

.spinner {
    width: 48px;
    height: 48px;
    border: 4px solid var(--md-sys-color-surface-container-highest);
    border-top-color: var(--btn-primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

/* ========================================
   Tiles Grid (Home Page)
   ======================================== */
.tiles-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 16px;
}

.tile {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: 16px;
    padding: 24px 20px;
    background: var(--btn-primary);
    border-radius: var(--md-sys-shape-corner-extra-large);
    border: none;
    text-decoration: none;
    transition: all var(--md-sys-motion-duration-medium2) var(--md-sys-motion-easing-emphasized);
    box-shadow: var(--md-sys-elevation-level2);
    min-height: 120px;
    text-align: left;
}

.tile:hover {
    background: var(--btn-primary-hover);
    box-shadow: var(--md-sys-elevation-level4);
    transform: translateY(-2px);
}

.tile-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    min-width: 40px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: var(--md-sys-shape-corner-medium);
    color: white;
    font-size: 1.35rem;
    transition: all var(--md-sys-motion-duration-short4) var(--md-sys-motion-easing-standard);
}

.tile:hover .tile-icon {
    transform: scale(1.06);
    background: rgba(255, 255, 255, 0.25);
}

.tile-content h3 {
    margin: 0 0 4px 0;
    font: 600 1.05rem/1.3rem 'Inter', system-ui, sans-serif;
    color: white;
    font-weight: 600;
    text-align: left;
}

.tile-content p {
    margin: 0;
    font: 400 0.92rem/1.25rem 'Inter', system-ui, sans-serif;
    color: rgba(255, 255, 255, 0.9);
    text-align: left;
}

.tile-content {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    text-align: left;
}

/* ========================================
   Tracking Supplier
   ======================================== */
.tracking-supplier-page {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.tracking-header .page-subtitle {
    display: block;
    color: var(--md-sys-color-outline);
    font: var(--md-sys-typescale-body-medium);
}

.tracking-filters-row {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.tracking-filters {
    border: 1px solid var(--md-sys-color-outline-variant);
    border-radius: var(--md-sys-shape-corner-large);
    box-shadow: var(--md-sys-elevation-level1);
    background: var(--md-sys-color-surface-container-low);
}

.tracking-content {
    background: var(--md-sys-color-surface-container-low);
    border: 1px solid var(--md-sys-color-outline-variant);
    border-radius: var(--md-sys-shape-corner-large);
    padding: 20px;
    box-shadow: var(--md-sys-elevation-level1);
}

.stations-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 16px;
}

.station-card {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 18px;
    border-radius: var(--md-sys-shape-corner-large);
    border: 1px solid var(--md-sys-color-outline-variant);
    background: var(--md-sys-color-surface);
    box-shadow: var(--md-sys-elevation-level1);
    cursor: pointer;
    transition: all var(--md-sys-motion-duration-short4) var(--md-sys-motion-easing-standard);
}

.station-card:hover {
    box-shadow: var(--md-sys-elevation-level3);
    transform: translateY(-2px);
}

.station-card-left {
    display: flex;
    gap: 12px;
    align-items: center;
}

.station-badge {
    width: 44px;
    height: 44px;
    border-radius: 12px;
    background: var(--md-sys-color-primary-container);
    color: var(--md-sys-color-on-primary-container);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
}

.station-content {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.station-supplier {
    font: 600 1rem/1.3rem 'Inter', system-ui, sans-serif;
    color: var(--md-ref-palette-neutral10);
}

.station-macrolevel {
    font: 500 0.95rem/1.2rem 'Inter', system-ui, sans-serif;
    color: var(--md-sys-color-outline);
}

.station-phase {
    font: 500 0.95rem/1.2rem 'Inter', system-ui, sans-serif;
    color: var(--btn-primary);
}

.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);
}

/* ========================================
   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;
    background: linear-gradient(135deg, var(--sidebar-bg) 0%, #1e293b 50%, var(--md-ref-palette-neutral30) 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: 112px;
    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(--md-sys-color-surface);
    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: 40px 40px 32px;
    text-align: center;
    border-bottom: 1px solid var(--md-sys-color-outline-variant);
}

.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(--md-sys-color-outline);
    margin: 0;
    font: var(--md-sys-typescale-body-large);
}

.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
   ======================================== */
.k-input,
.k-textbox,
.k-textarea,
.k-numerictextbox,
.k-autocomplete,
.k-dropdown,
.k-dropdownlist,
.k-combobox {
    border-radius: var(--md-sys-shape-corner-extra-small) !important;
    border-color: var(--md-sys-color-outline) !important;
    transition: all var(--md-sys-motion-duration-short4) var(--md-sys-motion-easing-standard) !important;
    min-height: 44px !important;
    height: 44px !important;
    box-sizing: border-box !important;
}

.user-password {
    height: 38px !important;
}

.k-dropdown-wrap,
.k-picker-wrap,
.k-dropdownlist .k-input-inner,
.k-dropdown .k-input-inner,
.k-combobox .k-input-inner {
    min-height: 42px !important;
    height: 42px !important;
    box-sizing: border-box !important;
    font-size: 1rem !important;
    line-height: 1.5 !important;
    font-family: inherit !important;
    font-weight: 400 !important;
}

.k-combobox .k-input-button,
.k-combobox .k-clear-value {
    min-height: 42px !important;
    height: 42px !important;
    width: 28px !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;
}



/* ========================================
   Virtual CFO
   Portato dal prodotto TexHub. Le sette schermate sono dense: la gerarchia e'
   sempre la stessa - verdetto in una riga, tessere, il grafico piu' grande,
   i confronti affiancati, le eccezioni in tabella.

   I colori e i raggi arrivano dai token di questa installazione, non da quelli
   del prodotto: gli alias qui sotto sono il ponte, e passando da --btn-primary
   seguono i tre temi per ruolo (blu utente, verde direzione, rosso admin).

   La barra delle sezioni non e' qui: si usano .cfo-tabs / .cfo-tab.active di
   cfo-dashboard.css, gli stessi della tesoreria.
   ======================================== */

:root {
    --ink: var(--md-ref-palette-neutral10);
    --ink-2: var(--md-ref-palette-neutral40);
    --ink-3: var(--md-ref-palette-neutral50);
    --line: var(--md-sys-color-outline-variant);
    --line-soft: var(--md-ref-palette-neutral90);
    --card-bg: var(--md-sys-color-surface);
    --accent-strong: var(--btn-primary);
    --accent-deep: var(--btn-primary-hover);
    --accent-soft: var(--md-sys-color-primary-container);
    --r: var(--md-sys-shape-corner-small);
}

.cfo {
    display: flex;
    flex-direction: column;
    gap: 14px;
    width: 100%;
}

/* --- 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: var(--md-sys-color-error); }
.cfo-verdict.is-warning { border-left-color: var(--md-sys-color-warning); }
.cfo-verdict > i { font-size: 1.05rem; color: var(--accent-deep); margin-top: 1px; }
.cfo-verdict.is-bad > i { color: var(--md-sys-color-error); }
.cfo-verdict.is-warning > i { color: var(--md-sys-color-warning); }
.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: var(--md-sys-color-success); }
.cfo-tile.h-warning::before { background: var(--md-sys-color-warning); }
.cfo-tile.h-bad::before { background: var(--md-sys-color-error); }

.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: var(--md-sys-color-error); }

.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: var(--md-sys-color-success); }
.cfo-delta.is-down { color: var(--md-sys-color-error); }

/* --- 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: var(--md-sys-color-error); }
.cfo-alert.sev-warning > i { color: var(--md-sys-color-warning); }
.cfo-alert.sev-good > i { color: var(--md-sys-color-success); }
.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: var(--md-sys-color-error); }
.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: var(--md-sys-color-warning); }
.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 var(--md-sys-color-warning);
    border-radius: 6px;
    background: var(--md-sys-color-warning-container);
    font: var(--md-sys-typescale-body-small);
    color: #78350f;
}

.cfo-demo > i { color: var(--md-sys-color-warning); 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: var(--md-sys-color-error); }
.cfo-matrix td.is-min { background: var(--md-sys-color-error-container) !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: var(--md-sys-color-success); }
.cfo-lever-delta.is-down { color: var(--md-sys-color-error); }

.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: var(--md-sys-color-error); }

.cfo-outcome-delta {
    display: block;
    font-size: .72rem;
    font-weight: 650;
    margin-top: 2px;
}

.cfo-outcome-delta.is-up { color: var(--md-sys-color-success); }
.cfo-outcome-delta.is-down { color: var(--md-sys-color-error); }

/* --- 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: var(--md-sys-color-success); }
.cfo-scenario-row b.is-down { color: var(--md-sys-color-error); }

/* 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: var(--md-sys-color-error-container); color: var(--md-sys-color-error); }

/* --- 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: var(--md-sys-color-error); }
.cfo-scalare td.is-up { color: var(--md-sys-color-success); }
.cfo-scalare td.is-down { color: var(--md-sys-color-error); }

/* --- 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: var(--md-sys-color-error-container); }
.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; }

/* ==========================================================================
   Configuratore Prezzi (/PriceQuotes, /PriceQuote, /PriceQuoteParams)

   La pagina che c'era prima si portava un foglio suo di 983 righe, copiato dal
   mockup del consulente, con la sua tavolozza e i suoi tipi di carattere: era
   un corpo estraneo in mezzo a cinquanta schermate e non seguiva i temi per
   ruolo. Qui restano solo le cose che quel mockup aveva ragione di avere - i
   riquadri grandi del prezzo e la barra che mostra dove va ogni euro - riscritte
   sui token, quindi blu per l'utente, verdi per la direzione, rosse per
   l'amministratore come tutto il resto.
   ========================================================================== */

/* Due colonne: a sinistra cosa si vende, a destra quanto deve costare. Sotto i
   1200px si impilano, perche' affiancate diventerebbero due strisce strette. */
.pq-layout { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; align-items: start; }
.pq-col    { display: flex; flex-direction: column; gap: 12px; min-width: 0; }
@media (max-width: 1200px) { .pq-layout { grid-template-columns: 1fr; } }

.pq-card   { padding: 0; overflow: hidden; }
.pq-card-h { display: flex; align-items: center; justify-content: space-between; gap: 8px;
             padding: 10px 14px; border-bottom: 1px solid var(--line); }
.pq-card-h h2 { margin: 0; font-size: 15px; font-weight: 600; color: var(--ink); }
.pq-card-b { padding: 14px; }

.pq-row    { margin-bottom: 14px; }
.pq-row:last-child { margin-bottom: 0; }
.pq-row-2  { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.pq-row-3  { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.pq-lab    { display: block; margin-bottom: 4px; font-size: 12px; font-weight: 600;
             color: var(--md-sys-color-on-surface-variant); }
.pq-req    { color: var(--danger); }
.pq-hint   { margin-top: 5px; font-size: 12px; line-height: 1.45; color: var(--ink); }
.pq-muted  { color: var(--muted); }
.pq-sub    { margin: 8px 0; font-size: 12px; }

/* I segmenti agente/spedizione riusano .cfo-seg: qui serve solo che non
   provino a stare sulla stessa riga dell'etichetta. */
.pq-seg    { display: inline-flex; }

/* I riquadri del prezzo. Il minimo e' l'unico numero grande della pagina:
   e' la risposta alla domanda per cui la schermata esiste. */
.pq-kpis     { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 10px; }
.pq-kpi      { border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px;
               background: var(--card-bg); }
.pq-kpi-lab  { font-size: 11px; text-transform: uppercase; letter-spacing: .04em;
               color: var(--muted); margin-bottom: 4px; }
.pq-kpi-val  { font-size: 20px; font-weight: 700; color: var(--ink);
               font-variant-numeric: tabular-nums; }
.pq-kpi-lead .pq-kpi-val { font-size: 28px; color: var(--accent-strong); }
.pq-kpi-sub  { margin-top: 4px; font-size: 12px; color: var(--muted);
               display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }

.pq-num      { font-variant-numeric: tabular-nums; }

.pq-chip       { display: inline-flex; align-items: center; gap: 4px; padding: 1px 8px;
                 border-radius: 999px; font-size: 11px; font-weight: 600; white-space: nowrap; }
.pq-chip-ok    { background: color-mix(in srgb, var(--success) 14%, transparent); color: var(--success); }
.pq-chip-no    { background: color-mix(in srgb, var(--danger) 14%, transparent);  color: var(--danger); }
.pq-chip-draft { background: color-mix(in srgb, var(--btn-primary) 12%, transparent); color: var(--accent-strong); }
.pq-chip-lock  { background: color-mix(in srgb, var(--muted) 16%, transparent); color: var(--ink); }

/* La sezione riservata: un filo di bordo accentato basta a dire che quello che
   c'e' dentro non lo vedono tutti, senza urlare. */
.pq-master { border-left: 3px solid var(--accent-strong); }

.pq-facts        { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
                   gap: 6px 14px; margin-bottom: 10px; }
.pq-facts > div  { display: flex; justify-content: space-between; gap: 8px;
                   padding: 4px 0; border-bottom: 1px dashed var(--line); font-size: 13px; }
.pq-facts span   { color: var(--muted); }
.pq-facts b      { color: var(--ink); font-variant-numeric: tabular-nums; }

/* Dove va ogni euro del prezzo proposto. Le tinte sono derivate dai token, non
   scelte a mano: cosi' seguono il tema per ruolo. */
.pq-bar    { display: flex; height: 18px; border-radius: 6px; overflow: hidden;
             border: 1px solid var(--line); margin: 10px 0 6px; }
.pq-bar > div { height: 100%; }
.pq-seg-ci    { background: color-mix(in srgb, var(--ink) 62%, transparent); }
.pq-seg-provv { background: color-mix(in srgb, var(--ink) 38%, transparent); }
.pq-seg-trasp { background: color-mix(in srgb, var(--ink) 22%, transparent); }
.pq-seg-oneri { background: color-mix(in srgb, var(--danger) 45%, transparent); }
.pq-seg-marg  { background: color-mix(in srgb, var(--success) 55%, transparent); }

.pq-legend      { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: 11px; color: var(--muted); }
.pq-legend i    { display: inline-flex; align-items: center; gap: 5px; font-style: normal; }
.pq-legend b    { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }

/* La scheda costo: le stesse colonne della schermata «Valore Corrente» di
   italfabrics, cosi' i due numeri si confrontano senza tradurre niente. */
.pq-costsheet-h { display: flex; align-items: center; justify-content: space-between;
                  gap: 8px; margin: 14px 0 6px; }
.pq-costsheet-h h3 { margin: 0; font-size: 13px; font-weight: 600; color: var(--ink); }

.pq-sheet          { width: 100%; border-collapse: collapse; font-size: 12px; }
.pq-sheet th       { text-align: left; font-weight: 600; color: var(--muted);
                     border-bottom: 1px solid var(--line); padding: 5px 6px; white-space: nowrap; }
.pq-sheet td       { padding: 4px 6px; border-bottom: 1px solid var(--line); color: var(--ink); }
.pq-sheet th.r,
.pq-sheet td.r     { text-align: right; font-variant-numeric: tabular-nums; }
.pq-sheet-tot td   { font-weight: 600; background: color-mix(in srgb, var(--ink) 5%, transparent); }
.pq-sheet-grand td { font-size: 13px; border-top: 2px solid var(--line); }

/* Una riga che il motore non ha saputo risolvere, o una zona con un'incidenza
   fuori scala: si segnala, non si nasconde dietro uno zero. */
.pq-unresolved td { background: color-mix(in srgb, var(--danger) 8%, transparent); }

.pq-notes      { margin: 0; font-size: 12px; line-height: 1.55; }
.pq-notes dt   { font-weight: 600; color: var(--ink); margin-top: 8px; }
.pq-notes dt:first-child { margin-top: 0; }
.pq-notes dd   { margin: 2px 0 0; color: var(--muted); }
.pq-notes code { background: color-mix(in srgb, var(--ink) 7%, transparent);
                 padding: 1px 5px; border-radius: 4px; font-size: 11px; }

/* TelerikTextArea ignora Rows: l'altezza la detta il guscio, che il tema tiene
   basso quanto una casella di testo. Le annotazioni uscivano alte una riga
   sola, e in una riga nessuno scrive una nota. Va alzato il guscio, non solo il
   textarea dentro. */
.pq-row .k-textarea.k-input,
.pq-card-b .k-textarea.k-input { height: auto !important; min-height: 88px !important; }
.pq-row .k-textarea textarea,
.pq-row textarea.k-input-inner,
.pq-card-b textarea.k-input-inner { min-height: 84px; height: 84px; resize: vertical; }

/* I filtri dell'elenco: cliente, articolo e colore sono tre caselle distinte,
   e la fila deve stare allineata. Prima la casella di ricerca era alta 40px e i
   bottoni dello stato 28: due altezze diverse sulla stessa riga si vedono. */
.pq-filters { align-items: flex-end; gap: 12px; flex-wrap: wrap; }
.pq-filters .pq-filter { display: flex; flex-direction: column; gap: 4px; }
.pq-filters label { font-size: 11px; text-transform: uppercase; letter-spacing: .04em;
                    color: var(--muted); margin: 0; }
/* Telerik da' 44px alle sue caselle e .cfo-seg ne fa 36: due altezze sulla
   stessa riga si vedono. L'altezza non sta sul contenitore ma sull'input
   dentro, che il tema fa alto 40 di padding: e' quello che va pareggiato,
   altrimenti si stringe il guscio e il contenuto lo rigonfia. */
/* Il foglio di Telerik e' caricato dopo questo e mette 44px di min-height sul
   guscio delle sue caselle. Ne' una classe in piu' ne' una regola piu' lunga lo
   scavalcano, quindi qui serve !important: e' l'unico in tutto il file, vale
   solo dentro .pq-filters, e la ragione e' quella. */
.pq-filters .k-textbox.k-input,
.pq-filters .k-input.filter-input,
.pq-filters .cfo-seg,
.pq-filters .k-button {
    height: 36px !important; min-height: 36px !important; box-sizing: border-box;
}
.pq-filters .k-input-inner {
    height: 34px; min-height: 34px; line-height: 34px;
    padding-top: 0; padding-bottom: 0; box-sizing: border-box;
}
.pq-filters .cfo-seg { display: inline-flex; align-items: stretch; }
.pq-filters .cfo-seg button { height: 100%; padding-top: 0; padding-bottom: 0; }

/* Cursori. La dilazione e lo sconto si negoziano a scatti, e il punto di
   guardarli su un cursore e' vedere il prezzo minimo muoversi mentre si
   trascina: e' il motivo per cui questa schermata esiste. */
.pq-lab-riga { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.pq-lab-val  { font-size: 13px; font-weight: 700; color: var(--accent-strong);
               font-variant-numeric: tabular-nums; }
.pq-row .k-slider-horizontal { margin: 2px 0 0; }

.pq-chips    { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 6px; }
.pq-chipbtn  { border: 1px solid var(--line); background: transparent; color: var(--muted);
               border-radius: 999px; padding: 2px 10px; font-size: 11px; font-weight: 600;
               cursor: pointer; line-height: 1.6; }
.pq-chipbtn:hover:not(:disabled) { border-color: var(--accent-strong); color: var(--accent-strong); }
.pq-chipbtn.is-active { background: var(--accent-strong); border-color: var(--accent-strong); color: #fff; }
.pq-chipbtn:disabled  { opacity: .45; cursor: default; }

/* Il prezzo proposto: cursore piu' casella. La scala parte dal minimo perche'
   sotto non ha senso proporre, e arriva al doppio perche' una scala un estremo
   lo deve avere e il listino qui non esiste. La casella accetta comunque
   qualunque cifra: una trattativa e' una trattativa. */
.pq-proposta   { border-top: 1px solid var(--line); margin-top: 12px; padding-top: 12px; }
.pq-proposta-b { display: flex; align-items: center; gap: 10px; margin-top: 6px; flex-wrap: wrap;
                 font-size: 12px; }

/* Sotto il minimo il riquadro del netto si segnala da solo: e' l'unica cosa
   della schermata che nessuno deve poter non vedere. */
.pq-kpi-no { border-color: var(--danger);
             background: color-mix(in srgb, var(--danger) 6%, var(--card-bg)); }
.pq-kpi-no .pq-kpi-val { color: var(--danger); }

/* Le due letture che servono a chi tratta: quanto costa concedere giorni, e
   quanto spazio c'e' fra il prezzo minimo e il listino. Erano nel prototipo del
   consulente ed erano la parte che valeva la pena tenere: un numero grande e
   una frase che dice cosa vuol dire. */
.pq-insights   { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
                 gap: 10px; margin-top: 12px; }
.pq-insight    { border: 1px solid var(--line); border-left: 3px solid var(--accent-strong);
                 border-radius: 10px; padding: 10px 12px; background: var(--card-bg); }
.pq-insight-band { border-left-color: var(--success); }
.pq-insight-lab { font-size: 11px; text-transform: uppercase; letter-spacing: .04em;
                  color: var(--muted); margin-bottom: 3px; }
.pq-insight-val { font-size: 22px; font-weight: 700; color: var(--ink);
                  font-variant-numeric: tabular-nums; }
.pq-insight-band .pq-insight-val { color: var(--success); }
.pq-insight-txt { margin-top: 4px; font-size: 12px; line-height: 1.45; color: var(--muted); }
.pq-badge      { display: inline-block; padding: 0 6px; border-radius: 999px; font-weight: 600;
                 background: color-mix(in srgb, var(--success) 14%, transparent); color: var(--success); }

/* ===========================================================================
   Configuratore Prezzi: le due tabelle configurabili di /PriceQuoteParams

   Il margine per settore e l'incidenza forzata a mano si modificano dentro la
   tabella, non in una finestra: sono quarantacinque righe e trenta zone, e
   aprire un dialogo per cambiare un numero e' piu' lavoro del numero. La
   casella dentro la cella va quindi stretta e bassa, altrimenti la riga
   diventa alta come un modulo.

   La percentuale calcolata di una zona forzata resta a video barrata: serve a
   vedere di quanto ci si e' scostati, e a ricordarsi perche' la forzatura
   c'era. Il colore lo mette .pq-muted, qui c'e' solo la riga sopra.
   =========================================================================== */
.pq-sheet .k-input.filter-input { min-height: 30px !important; height: 30px !important; }
.pq-sheet .k-input.filter-input .k-input-inner { padding: 2px 6px; font-size: 12px; }

/*  inline-FLEX, non inline-block: la casella numerica di Telerik e' un flex
    con l'input a sinistra e le due frecce a destra, e mettendola a block le
    frecce andavano a capo sotto l'input, dove la cella le tagliava. Si vedeva
    solo la punta di quella di sopra. */
.pq-forzatura      { white-space: nowrap; }
.pq-forzatura .k-input.filter-input { display: inline-flex; vertical-align: middle; }
.pq-mini.k-button  { min-width: 28px; padding: 2px 6px; margin-left: 4px; vertical-align: middle; }

.pq-barrato        { text-decoration: line-through; }

/* ---------------------------------------------------------------------------
   La provvigione fra le condizioni di vendita

   La casella e la sua nota stanno su due colonne: a sinistra il numero, a
   destra da dove viene o - se l'ha scritta una persona - quanto diceva il
   calcolo. La nota si allinea in basso, alla stessa altezza della casella,
   se no galleggia sopra l'etichetta.
   --------------------------------------------------------------------------- */
.pq-provvigione-note { display: flex; flex-direction: column; justify-content: flex-end;
                       gap: 4px; font-size: 12px; line-height: 1.4; padding-bottom: 2px; }
.pq-provvigione-note .k-button { align-self: flex-start; }
.pq-provvigione { margin-top: 10px; }

/* ---------------------------------------------------------------------------
   Il cestino sulle bozze

   Buttare via una scheda e' l'unica azione distruttiva di queste pagine, e
   deve sembrarlo: il bottone della finestra e' rosso pieno, quello in griglia
   resta un'icona e si accende solo quando ci passi sopra, se no una colonna di
   cestini rossi fa piu' paura di quanta gliene serva.
   --------------------------------------------------------------------------- */
.btn-icon-modern.k-button { min-width: 32px; padding: 4px 8px; background: transparent;
                            border: 1px solid var(--line); color: var(--ink); }
.btn-icon-modern.k-button:hover { background: color-mix(in srgb, var(--ink) 7%, transparent); }

.pq-cestino.k-button { margin-left: 4px; color: var(--danger); }
.pq-cestino.k-button:hover { background: color-mix(in srgb, var(--danger) 12%, transparent);
                             border-color: var(--danger); }

.btn-danger-modern.k-button { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger-modern.k-button:hover { filter: brightness(0.92); }

/* ===========================================================================
   Texi, l'assistente dati

   Il pannello sta dentro .app-layout, non fuori. Il tema per ruolo - blu
   utente, verde direzione, rosso amministratore - e' una classe su quel div,
   e i colori qui sotto passano tutti da --btn-primary: appeso a :root il
   pulsante sarebbe rimasto blu anche per un amministratore, che e' la stessa
   trappola gia' pagata con i popup di Telerik.

   Il pulsante e il pannello sono fixed, non absolute: devono restare in basso
   a destra mentre la pagina sotto scorre, e .main-content ha un padding suo
   che li avrebbe spostati.

   z-index 1200: sopra la barra e la barra laterale, sotto le finestre
   Telerik, che stanno a 10000. Una finestra modale aperta deve poter coprire
   Texi, non il contrario.
   =========================================================================== */

.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); }
