/* =============================================
   eCentrica MechHuman — Design System
   Style: Data-Dense Dashboard + Real-Time Monitoring + LIGHT Professional
   Typography: Fira Code (numbers) + Fira Sans (text)
   Layout: Dark sidebar/topbar + Light content area
   ============================================= */

@import url('https://fonts.googleapis.com/css2?family=Fira+Code:wght@400;500;600;700&family=Fira+Sans:wght@300;400;500;600;700&display=swap');

/* =============================================
   CSS VARIABLES — Light Professional Theme
   ============================================= */
:root {
    /* Background & Surfaces */
    --ec-bg: #F1F5F9;
    --ec-card-bg: #FFFFFF;
    --ec-surface-elevated: #1E3B6E;
    --ec-border: #E2E8F0;

    /* Text */
    --ec-heading: #0F172A;
    --ec-text: #475569;
    --ec-text-muted: #94A3B8;

    /* Actions */
    --ec-primary: #2563EB;
    --ec-secondary: #4F46E5;
    --ec-brand: #2563EB;

    /* Machine States */
    --ec-success: #16A34A;
    --ec-warning: #D97706;
    --ec-info: #2563EB;
    --ec-danger: #DC2626;
    --ec-critical: #B91C1C;
    --ec-neutral: #64748B;

    /* Spacing (Data-Dense) */
    --space-xs: 4px;
    --space-sm: 8px;
    --space-md: 12px;
    --space-lg: 16px;
    --space-xl: 24px;

    /* Layout */
    --sidebar-width: 250px;
    --sidebar-collapsed: 70px;
    --header-height: 56px;
    --footer-height: 40px;
    --table-row-height: 36px;
    --card-radius: 0.5rem;

    /* Shadows (light mode — soft, subtle) */
    --ec-shadow: 0 1px 2px rgba(0,0,0,0.05);
    --ec-shadow-md: 0 4px 6px -1px rgba(0,0,0,0.07), 0 2px 4px -2px rgba(0,0,0,0.05);
    --ec-shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.08), 0 4px 6px -4px rgba(0,0,0,0.05);
    --ec-shadow-glow: 0 0 0 3px rgba(37,99,235,0.15);

    /* Legacy compat */
    --primary-color: #152C54;
    --primary-dark: #0E1F3D;
    --secondary-color: #1E3B6E;
    --accent-color: #2563EB;
}

/* =============================================
   RESET & BASE
   ============================================= */
html, body {
    font-family: 'Fira Sans', -apple-system, BlinkMacSystemFont, sans-serif;
    font-size: 14px;
    font-weight: 400;
    color: var(--ec-text);
    background-color: var(--ec-bg);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

h1, h2, h3, h4, h5, h6, .h1, .h2, .h3, .h4, .h5, .h6 {
    color: var(--ec-heading);
    font-family: 'Fira Sans', sans-serif;
    font-weight: 600;
}

.monospace, code, .kpi-value, .data-number {
    font-family: 'Fira Code', monospace;
}

a, .btn-link {
    color: var(--ec-primary);
    transition: color 200ms ease-out;
}

a:hover, .btn-link:hover {
    color: #1D4ED8;
}

h1:focus {
    outline: none;
}

/* =============================================
   PAGE LAYOUT
   ============================================= */
.page {
    display: flex;
    min-height: 100vh;
    position: relative;
    background-color: var(--ec-bg);
}

main {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    background-color: var(--ec-bg);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

main > article {
    flex: 1;
}

.content {
    padding: var(--space-lg);
    padding-top: var(--space-lg);
}

/* =============================================
   SIDEBAR — Dark (contrasto con contenuto light)
   ============================================= */
.sidebar {
    flex: 0 0 var(--sidebar-width);
    min-height: 100vh;
    position: relative;
    background-color: var(--ec-surface-elevated);
    border-right: none;
    box-shadow: 2px 0 8px rgba(0,0,0,0.1);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 1000;
}

.sidebar.collapsed {
    flex: 0 0 var(--sidebar-collapsed) !important;
    min-width: var(--sidebar-collapsed);
    max-width: var(--sidebar-collapsed);
}

.sidebar-header {
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    background-color: var(--ec-surface-elevated) !important;
}

.nav-link {
    color: rgba(255, 255, 255, 0.7) !important;
    white-space: nowrap;
    overflow: hidden;
    display: flex;
    align-items: center;
    padding: 0.625rem 1rem;
    transition: all 200ms ease-out;
    border-radius: var(--card-radius);
    margin: 2px 0.5rem;
    font-size: 0.875rem;
    cursor: pointer;
}

.nav-link:hover {
    color: #FFFFFF !important;
    background-color: rgba(255, 255, 255, 0.1);
}

.nav-link.active {
    background-color: var(--ec-primary) !important;
    color: white !important;
}

.sidebar.collapsed .nav-link {
    padding: 0.625rem 0.5rem !important;
    text-align: center !important;
    justify-content: center;
    margin: 2px 0.125rem;
}

.sidebar.collapsed .nav-link i {
    margin-right: 0 !important;
    font-size: 1.2rem;
}

.sidebar.collapsed .sidebar-header .h6,
.sidebar.collapsed .sidebar-header small {
    display: none;
}

/* Sidebar tooltips (collapsed) */
.sidebar.collapsed .nav-link {
    position: relative;
}

.sidebar.collapsed .nav-link:hover::after {
    content: attr(title);
    position: absolute;
    left: calc(100% + 12px);
    top: 50%;
    transform: translateY(-50%);
    background: var(--ec-card-bg);
    color: var(--ec-heading);
    padding: 0.5rem 0.75rem;
    border-radius: var(--card-radius);
    border: 1px solid var(--ec-border);
    white-space: nowrap;
    z-index: 1050;
    font-size: 0.8125rem;
    font-weight: 500;
    box-shadow: var(--ec-shadow-md);
    animation: tooltipFadeIn 150ms ease-out;
}

.sidebar.collapsed .nav-link:hover::before {
    content: "";
    position: absolute;
    left: calc(100% + 4px);
    top: 50%;
    transform: translateY(-50%);
    border: 6px solid transparent;
    border-right-color: var(--ec-border);
    z-index: 1051;
}

@keyframes tooltipFadeIn {
    from { opacity: 0; transform: translateY(-50%) translateX(-4px); }
    to { opacity: 1; transform: translateY(-50%) translateX(0); }
}

/* =============================================
   TOP BAR — Dark (match sidebar)
   ============================================= */
.top-row {
    height: var(--header-height);
    display: flex;
    align-items: center;
    background-color: #152C54 !important;
    border-bottom: none;
    box-shadow: 0 1px 3px rgba(0,0,0,0.12);
}

.navbar-brand {
    font-size: 1.1rem;
    font-weight: 600;
    color: #FFFFFF;
}

.navbar-text {
    color: rgba(255,255,255,0.6);
    font-family: 'Fira Code', monospace;
    font-size: 0.8125rem;
}

.btn-outline-light {
    border-color: rgba(255,255,255,0.2);
    color: rgba(255,255,255,0.8);
}

.btn-outline-light:hover {
    background-color: rgba(255, 255, 255, 0.1);
    border-color: rgba(255,255,255,0.4);
    color: #FFFFFF;
}

/* =============================================
   CARDS — White, clean, readable
   ============================================= */
.card, .ec-card {
    background: var(--ec-card-bg);
    border: 1px solid var(--ec-border);
    border-radius: var(--card-radius);
    box-shadow: var(--ec-shadow);
    transition: box-shadow 200ms ease-out;
    color: var(--ec-text);
}

.card:hover, .ec-card:hover {
    box-shadow: var(--ec-shadow-md);
}

.card-header {
    background-color: #F8FAFC;
    border-bottom: 1px solid var(--ec-border);
    color: var(--ec-heading);
    padding: var(--space-md);
    font-weight: 600;
}

.card-body {
    padding: var(--space-md);
}

/* KPI Cards */
.ec-kpi-card {
    background: var(--ec-card-bg);
    border: 1px solid var(--ec-border);
    border-radius: var(--card-radius);
    box-shadow: var(--ec-shadow);
    padding: var(--space-md) var(--space-lg);
    display: flex;
    flex-direction: column;
    gap: var(--space-xs);
    transition: box-shadow 200ms ease-out, border-color 200ms ease-out;
}

.ec-kpi-card:hover {
    box-shadow: var(--ec-shadow-md);
    border-color: var(--ec-primary);
}

.ec-kpi-card .ec-kpi-label {
    font-size: 0.75rem;
    color: var(--ec-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-weight: 500;
}

.ec-kpi-card .ec-kpi-value {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--ec-heading);
    font-family: 'Fira Code', monospace;
    line-height: 1.2;
}

/* =============================================
   BORDER-LEFT ACCENT CARDS
   ============================================= */
.border-left-primary {
    border-left: 3px solid var(--ec-primary) !important;
}

.border-left-success {
    border-left: 3px solid var(--ec-success) !important;
}

.border-left-info {
    border-left: 3px solid var(--ec-info) !important;
}

.border-left-warning {
    border-left: 3px solid var(--ec-warning) !important;
}

.border-left-danger {
    border-left: 3px solid var(--ec-danger) !important;
}

.border-left-secondary {
    border-left: 3px solid var(--ec-neutral) !important;
}

/* =============================================
   PAGE HEADER
   ============================================= */
.ec-page-header {
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
    margin-bottom: 1.25rem;
}

.ec-page-header .ec-page-header-icon {
    flex-shrink: 0;
    width: 2.75rem;
    height: 2.75rem;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--ec-primary);
    color: white;
    border-radius: var(--card-radius);
    font-size: 1.1rem;
}

.ec-page-header .ec-page-header-title {
    font-size: 1.375rem;
    font-weight: 600;
    color: var(--ec-heading);
    margin: 0 0 0.125rem 0;
}

.ec-page-header .ec-page-header-subtitle {
    font-size: 0.8125rem;
    color: var(--ec-text);
    margin: 0;
}

/* =============================================
   STATUS BADGES
   ============================================= */
.ec-badge-attivo {
    background-color: #DCFCE7;
    color: #166534;
    padding: 0.2rem 0.5rem;
    border-radius: var(--card-radius);
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.ec-badge-completato {
    background-color: #DBEAFE;
    color: #1E40AF;
    padding: 0.2rem 0.5rem;
    border-radius: var(--card-radius);
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
}

.ec-badge-sospeso {
    background-color: #FEF3C7;
    color: #92400E;
    padding: 0.2rem 0.5rem;
    border-radius: var(--card-radius);
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
}

.ec-badge-attrezzaggio {
    background-color: #EDE9FE;
    color: #5B21B6;
    padding: 0.2rem 0.5rem;
    border-radius: var(--card-radius);
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
}

/* =============================================
   TOOLBAR
   ============================================= */
.ec-toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.75rem;
    padding: 0.5rem 0;
    margin-bottom: 1rem;
    border-bottom: 1px solid var(--ec-border);
}

/* =============================================
   TABLES — Dense, readable on light bg
   ============================================= */
.table {
    color: var(--ec-text);
    font-size: 0.8125rem;
}

.table th {
    background-color: #F8FAFC;
    color: var(--ec-heading);
    font-weight: 600;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    border-bottom: 2px solid var(--ec-border);
    padding: var(--space-sm) var(--space-md);
}

.table td {
    vertical-align: middle;
    padding: var(--space-sm) var(--space-md);
    border-bottom: 1px solid #F1F5F9;
    color: var(--ec-heading);
}

.table-hover tbody tr:hover {
    background-color: #EFF6FF;
}

.table-striped tbody tr:nth-of-type(odd) {
    background-color: #FAFBFC;
}

/* =============================================
   BUTTONS
   ============================================= */
.btn-primary {
    background-color: var(--ec-primary);
    border-color: var(--ec-primary);
    color: white;
    font-weight: 500;
    transition: all 200ms ease-out;
    cursor: pointer;
}

.btn-primary:hover {
    background-color: #1D4ED8;
    border-color: #1D4ED8;
}

.btn-outline-primary {
    color: var(--ec-primary);
    border-color: var(--ec-primary);
}

.btn-outline-primary:hover {
    background-color: var(--ec-primary);
    color: white;
}

.text-primary {
    color: var(--ec-primary) !important;
}

.bg-primary {
    background-color: var(--ec-primary) !important;
}

.border-primary {
    border-color: var(--ec-primary) !important;
}

.progress-bar {
    background-color: var(--ec-primary);
}

.progress-sm {
    height: 0.5rem;
    background-color: #E2E8F0;
    border-radius: 0.25rem;
}

/* =============================================
   FORMS & INPUTS
   ============================================= */
.form-control, .form-select {
    background-color: var(--ec-card-bg);
    border: 1px solid var(--ec-border);
    color: var(--ec-heading);
    transition: border-color 200ms ease-out, box-shadow 200ms ease-out;
}

.form-control:focus, .form-select:focus {
    background-color: var(--ec-card-bg);
    border-color: var(--ec-primary);
    color: var(--ec-heading);
    box-shadow: var(--ec-shadow-glow);
}

.form-control::placeholder {
    color: var(--ec-text-muted);
}

.btn:focus, .btn:active:focus, .btn-link.nav-link:focus,
.form-control:focus, .form-check-input:focus {
    box-shadow: 0 0 0 2px white, 0 0 0 4px var(--ec-primary);
}

.valid.modified:not([type=checkbox]) {
    outline: 1px solid var(--ec-success);
}

.invalid {
    outline: 1px solid var(--ec-danger);
}

.validation-message {
    color: var(--ec-danger);
    font-size: 0.8125rem;
}

/* =============================================
   REAL-TIME MONITORING — Status Indicators
   ============================================= */
.iot-status-indicator {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    display: inline-block;
    margin-right: 0.5rem;
    transition: background-color 200ms ease-out;
}

.iot-status-online {
    background-color: var(--ec-success);
    box-shadow: 0 0 0 3px rgba(22, 163, 74, 0.2);
}

.iot-status-online.live {
    animation: pulse-green 2s infinite;
}

.iot-status-offline {
    background-color: var(--ec-danger);
}

.iot-status-slow {
    background-color: var(--ec-warning);
}

@keyframes pulse-green {
    0%, 100% { box-shadow: 0 0 0 3px rgba(22,163,74,0.2); }
    50% { box-shadow: 0 0 0 6px rgba(22,163,74,0.08); }
}

@keyframes pulse-red {
    0%, 100% { box-shadow: 0 0 0 3px rgba(220,38,38,0.25); }
    50% { box-shadow: 0 0 0 6px rgba(220,38,38,0.08); }
}

@keyframes pulse-blue {
    0%, 100% { box-shadow: 0 0 0 3px rgba(37,99,235,0.2); }
    50% { box-shadow: 0 0 0 6px rgba(37,99,235,0.08); }
}

@keyframes pulse-amber {
    0%, 100% { box-shadow: 0 0 0 3px rgba(217,119,6,0.25); }
    50% { box-shadow: 0 0 0 6px rgba(217,119,6,0.08); }
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

.pulse { animation: pulse 1.5s ease-in-out infinite; }

/* Machine state classes */
.state-in-ciclo { color: var(--ec-success); }
.state-mst { color: var(--ec-warning); }
.state-idle { color: var(--ec-info); }
.state-allarme { color: var(--ec-danger); }
.state-manuale { color: var(--ec-neutral); }
.state-fermo { color: var(--ec-critical); }

.bg-in-ciclo { background-color: var(--ec-success); }
.bg-mst { background-color: var(--ec-warning); }
.bg-idle { background-color: var(--ec-info); }
.bg-allarme { background-color: var(--ec-danger); }
.bg-manuale { background-color: var(--ec-neutral); }
.bg-fermo { background-color: var(--ec-critical); }

/* =============================================
   SKELETON LOADING
   ============================================= */
.skeleton {
    background: linear-gradient(90deg,
        #E2E8F0 25%,
        #F1F5F9 50%,
        #E2E8F0 75%
    );
    background-size: 200% 100%;
    animation: skeleton-shimmer 1.5s ease-in-out infinite;
    border-radius: var(--card-radius);
}

@keyframes skeleton-shimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* =============================================
   SHADOW UTILITIES
   ============================================= */
.shadow {
    box-shadow: var(--ec-shadow) !important;
}

.shadow-md {
    box-shadow: var(--ec-shadow-md) !important;
}

.shadow-lg {
    box-shadow: var(--ec-shadow-lg) !important;
}

/* =============================================
   TEXT UTILITIES
   ============================================= */
.text-gray-300 {
    color: var(--ec-text-muted) !important;
}

.text-gray-800 {
    color: var(--ec-heading) !important;
}

/* =============================================
   FOOTER — Light, subtle
   ============================================= */
.app-footer {
    background-color: var(--ec-card-bg);
    color: var(--ec-text-muted);
    padding: 8px 24px;
    margin-top: auto;
    border-top: 1px solid var(--ec-border);
    height: var(--footer-height);
}

.footer-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    max-width: 100%;
    font-size: 0.8rem;
    height: 100%;
}

.footer-copyright {
    color: var(--ec-text-muted);
}

.footer-copyright a {
    color: var(--ec-primary);
    text-decoration: none;
    font-weight: 500;
    transition: color 200ms ease-out;
}

.footer-copyright a:hover {
    color: #1D4ED8;
}

.powered-text {
    font-size: 0.7rem;
    color: var(--ec-text-muted);
    margin-right: 0.5rem;
    text-transform: lowercase;
}

.footer-brand {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.app-footer .footer-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.app-footer .footer-brand {
    display: flex;
    align-items: center;
    min-width: 140px;
}

.app-footer .footer-brand img {
    flex-shrink: 0;
    opacity: 0.5;
    transition: opacity 200ms ease-out;
}

.app-footer .footer-brand img:hover {
    opacity: 0.8;
}

/* =============================================
   BLAZOR UI
   ============================================= */
#blazor-error-ui {
    background: #FEF2F2;
    border-top: 2px solid var(--ec-danger);
    bottom: 0;
    box-shadow: 0 -2px 8px rgba(0,0,0,0.1);
    display: none;
    left: 0;
    padding: 0.6rem 1.25rem 0.7rem 1.25rem;
    position: fixed;
    width: 100%;
    z-index: 1000;
    color: var(--ec-heading);
}

#blazor-error-ui .dismiss {
    cursor: pointer;
    position: absolute;
    right: 0.75rem;
    top: 0.5rem;
}

.blazor-error-boundary {
    background: var(--ec-danger);
    padding: 1rem 1rem 1rem 3.7rem;
    color: white;
    border-radius: var(--card-radius);
}

.blazor-error-boundary::after {
    content: "Si è verificato un errore.";
}

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

/* =============================================
   RESPONSIVE
   ============================================= */
@media (max-width: 768px) {
    .sidebar {
        position: fixed;
        left: calc(var(--sidebar-width) * -1);
        z-index: 1050;
        transition: left 0.3s ease;
    }

    .sidebar.show {
        left: 0;
    }

    .sidebar.collapsed {
        left: calc(var(--sidebar-collapsed) * -1);
    }

    .sidebar.collapsed.show {
        left: 0;
        flex: 0 0 var(--sidebar-collapsed);
    }

    main {
        margin-left: 0;
    }

    .h5 {
        font-size: 1rem;
    }

    .card-body {
        padding: var(--space-sm);
    }

    .table-responsive {
        font-size: 0.8125rem;
    }

    .btn-group-sm > .btn, .btn-sm {
        padding: 0.25rem 0.5rem;
        font-size: 0.75rem;
    }

    .ec-kpi-card .ec-kpi-value {
        font-size: 1.25rem;
    }
}

@media (max-width: 576px) {
    .container-fluid {
        padding-left: 0.5rem;
        padding-right: 0.5rem;
    }

    .card-header h6 {
        font-size: 0.8125rem;
    }

    .badge {
        font-size: 0.65em;
    }

    .sidebar {
        width: 100%;
        left: -100%;
    }

    .sidebar.show {
        left: 0;
    }

    .footer-content {
        flex-direction: column;
        gap: 4px;
        text-align: center;
    }
}

/* =============================================
   BOOTSTRAP LIGHT OVERRIDES
   ============================================= */
.modal-content {
    background-color: var(--ec-card-bg);
    border: 1px solid var(--ec-border);
    color: var(--ec-text);
    box-shadow: var(--ec-shadow-lg);
}

.modal-header {
    border-bottom-color: var(--ec-border);
    color: var(--ec-heading);
}

.modal-footer {
    border-top-color: var(--ec-border);
}

.dropdown-menu {
    background-color: var(--ec-card-bg);
    border: 1px solid var(--ec-border);
    box-shadow: var(--ec-shadow-lg);
}

.dropdown-item {
    color: var(--ec-text);
}

.dropdown-item:hover, .dropdown-item:focus {
    background-color: #EFF6FF;
    color: var(--ec-heading);
}

.badge.bg-info {
    background-color: var(--ec-info) !important;
}

.badge.bg-success {
    background-color: var(--ec-success) !important;
}

.badge.bg-warning {
    background-color: var(--ec-warning) !important;
    color: white;
}

.badge.bg-danger {
    background-color: var(--ec-danger) !important;
}

.border-secondary {
    border-color: var(--ec-border) !important;
}

/* =============================================
   SYNCFUSION / MUDBLAZOR LIGHT INTEGRATION
   ============================================= */
.mud-typography {
    color: var(--ec-text);
}

.mud-typography-h5, .mud-typography-h6 {
    color: var(--ec-heading);
}

.e-grid .e-headercell {
    background-color: #F8FAFC;
    color: var(--ec-heading);
    font-weight: 600;
}

.e-grid .e-row:hover .e-rowcell {
    background-color: #EFF6FF;
}

/* =============================================
   HELP BUTTON — Top Bar
   ============================================= */
.btn-help-topbar {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: rgba(255,255,255,0.12);
    color: rgba(255,255,255,0.85);
    font-size: 1.15rem;
    text-decoration: none;
    transition: all 0.2s ease;
    border: 1px solid rgba(255,255,255,0.15);
}

.btn-help-topbar:hover {
    background: rgba(255,255,255,0.22);
    color: #fff;
    transform: scale(1.08);
    border-color: rgba(255,255,255,0.3);
}

/* =============================================
   MANUALE OPERATIVO — Full Page Styles
   ============================================= */
.manuale-operativo {
    max-width: 1100px;
    margin: 0 auto;
    padding-bottom: 3rem;
}

.manuale-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 2rem;
    padding-bottom: 1.5rem;
    border-bottom: 2px solid var(--ec-border);
}

.manuale-header h1 {
    font-size: 1.8rem;
    font-weight: 700;
    color: var(--ec-heading);
    margin: 0;
}

.manuale-header .subtitle {
    color: var(--ec-text-muted);
    font-size: 0.95rem;
    margin: 0.25rem 0 0;
}

.manuale-version {
    text-align: right;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 4px;
}

.badge-version {
    display: inline-block;
    background: var(--ec-primary);
    color: #fff;
    padding: 3px 12px;
    border-radius: 12px;
    font-size: 0.8rem;
    font-weight: 600;
}

/* TOC */
.manuale-toc {
    background: var(--ec-card-bg);
    border: 1px solid var(--ec-border);
    border-radius: var(--card-radius);
    padding: 1.25rem 1.5rem;
    margin-bottom: 2rem;
    box-shadow: var(--ec-shadow);
}

.manuale-toc h5 {
    font-weight: 700;
    color: var(--ec-heading);
    margin-bottom: 0.75rem;
    font-size: 1rem;
}

.manuale-toc ul {
    list-style: none;
    padding: 0;
    margin: 0;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 6px;
}

.manuale-toc ul li a {
    display: block;
    padding: 6px 12px;
    color: var(--ec-primary);
    text-decoration: none;
    border-radius: 6px;
    font-size: 0.9rem;
    transition: all 0.15s ease;
}

.manuale-toc ul li a:hover {
    background: #EFF6FF;
    color: var(--ec-secondary);
}

/* Sections */
.manuale-section {
    background: var(--ec-card-bg);
    border: 1px solid var(--ec-border);
    border-radius: var(--card-radius);
    padding: 1.75rem 2rem;
    margin-bottom: 1.5rem;
    box-shadow: var(--ec-shadow);
}

.manuale-section h2 {
    font-size: 1.35rem;
    font-weight: 700;
    color: var(--ec-heading);
    margin: 0 0 1rem;
    padding-bottom: 0.75rem;
    border-bottom: 2px solid var(--ec-border);
}

.manuale-section h2 i {
    color: var(--ec-primary);
}

.manuale-section h4 {
    font-size: 1.05rem;
    font-weight: 600;
    color: var(--ec-heading);
    margin: 1.25rem 0 0.5rem;
}

.manuale-section p {
    color: var(--ec-text);
    line-height: 1.7;
    margin-bottom: 0.75rem;
}

.manuale-section code {
    background: #F1F5F9;
    padding: 2px 8px;
    border-radius: 4px;
    font-family: 'Fira Code', monospace;
    font-size: 0.85rem;
    color: var(--ec-secondary);
}

/* Feature Grid (intro) */
.feature-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 1rem;
    margin-top: 1rem;
}

.feature-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    background: #F8FAFC;
    border-radius: 8px;
    border: 1px solid var(--ec-border);
}

.feature-icon {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    background: var(--ec-primary);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    flex-shrink: 0;
}

.feature-item strong {
    display: block;
    font-size: 0.9rem;
    color: var(--ec-heading);
}

.feature-item span {
    font-size: 0.8rem;
    color: var(--ec-text-muted);
}

/* Steps */
.steps-list {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    margin-top: 0.75rem;
}

.step {
    display: flex;
    align-items: flex-start;
    gap: 14px;
}

.step-number {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--ec-primary);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 0.9rem;
    flex-shrink: 0;
}

.step strong {
    display: block;
    color: var(--ec-heading);
    margin-bottom: 2px;
}

.step p {
    margin: 0;
    font-size: 0.9rem;
}

/* Info Boxes */
.info-box {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    background: #EFF6FF;
    border: 1px solid #BFDBFE;
    border-radius: 8px;
    padding: 12px 16px;
    margin-top: 1rem;
    font-size: 0.9rem;
    color: #1E40AF;
}

.info-box i {
    font-size: 1.1rem;
    margin-top: 2px;
    flex-shrink: 0;
}

.info-box-energy {
    background: #FFFBEB;
    border-color: #FDE68A;
    color: #92400E;
}

/* Doc Tables */
.doc-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 0.75rem;
    font-size: 0.9rem;
}

.doc-table th {
    background: #F1F5F9;
    font-weight: 600;
    color: var(--ec-heading);
    padding: 8px 12px;
    text-align: left;
    border-bottom: 2px solid var(--ec-border);
}

.doc-table td {
    padding: 8px 12px;
    border-bottom: 1px solid var(--ec-border);
    color: var(--ec-text);
}

.doc-table tr:hover td {
    background: #F8FAFC;
}

/* Doc Lists */
.doc-list {
    padding-left: 1.25rem;
    margin-top: 0.5rem;
}

.doc-list li {
    margin-bottom: 6px;
    font-size: 0.9rem;
    line-height: 1.6;
    color: var(--ec-text);
}

/* KPI Docs Grid */
.kpi-docs-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 0.75rem;
    margin-top: 0.75rem;
}

.kpi-doc-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    padding: 16px;
    border-radius: 8px;
    gap: 6px;
}

.kpi-doc-item i {
    font-size: 1.5rem;
    margin-bottom: 4px;
}

.kpi-doc-item strong {
    font-size: 0.9rem;
    color: var(--ec-heading);
}

.kpi-doc-item span {
    font-size: 0.8rem;
    color: var(--ec-text-muted);
}

.kpi-doc-blue { background: #EFF6FF; border: 1px solid #BFDBFE; }
.kpi-doc-blue i { color: #2563EB; }
.kpi-doc-green { background: #F0FDF4; border: 1px solid #BBF7D0; }
.kpi-doc-green i { color: #16A34A; }
.kpi-doc-purple { background: #FAF5FF; border: 1px solid #E9D5FF; }
.kpi-doc-purple i { color: #7C3AED; }
.kpi-doc-orange { background: #FFFBEB; border: 1px solid #FDE68A; }
.kpi-doc-orange i { color: #D97706; }

/* Period Chips (doc) */
.period-chips-doc {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin: 0.5rem 0 1rem;
}

.chip-doc {
    padding: 5px 14px;
    border-radius: 20px;
    font-size: 0.8rem;
    font-weight: 600;
    background: #F1F5F9;
    color: var(--ec-text);
    border: 1px solid var(--ec-border);
}

.chip-all { background: #F1F5F9; }
.chip-green { background: #F0FDF4; color: #16A34A; border-color: #BBF7D0; }
.chip-blue { background: #EFF6FF; color: #2563EB; border-color: #BFDBFE; }
.chip-yellow { background: #FFFBEB; color: #D97706; border-color: #FDE68A; }
.chip-purple { background: #FAF5FF; color: #7C3AED; border-color: #E9D5FF; }

/* Stati Macchina Grid */
.stati-grid {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    margin-top: 1rem;
}

.stato-item {
    display: flex;
    align-items: flex-start;
    gap: 14px;
    padding: 12px 16px;
    border-radius: 8px;
    border: 1px solid var(--ec-border);
    background: #FAFAFA;
}

.stato-badge {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    flex-shrink: 0;
    color: #fff;
}

.stato-item strong {
    display: block;
    font-size: 0.95rem;
    color: var(--ec-heading);
}

.stato-item p {
    margin: 2px 0 0;
    font-size: 0.85rem;
}

.color-dot {
    display: inline-block;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    vertical-align: middle;
    margin: 0 2px;
}

.stato-allarme .stato-badge { background: #8B5CF6; }
.stato-inciclo .stato-badge { background: #16A34A; }
.stato-mst .stato-badge { background: #D97706; }
.stato-idle .stato-badge { background: #2563EB; }
.stato-manuale .stato-badge { background: #94A3B8; }
.stato-fermo .stato-badge { background: #DC2626; }

/* Responsive */
@media (max-width: 768px) {
    .manuale-header {
        flex-direction: column;
        gap: 1rem;
    }

    .manuale-version {
        align-items: flex-start;
    }

    .manuale-section {
        padding: 1.25rem;
    }

    .manuale-toc ul {
        grid-template-columns: 1fr;
    }

    .feature-grid {
        grid-template-columns: 1fr;
    }

    .kpi-docs-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

/* Print PDF Button */
.manuale-actions {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 8px;
}

.btn-print-pdf {
    display: inline-flex;
    align-items: center;
    padding: 8px 20px;
    background: #DC2626;
    color: #fff;
    border: none;
    border-radius: 8px;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: 0 2px 4px rgba(220,38,38,0.25);
}

.btn-print-pdf:hover {
    background: #B91C1C;
    transform: translateY(-1px);
    box-shadow: 0 4px 8px rgba(220,38,38,0.3);
}

.btn-print-pdf i {
    font-size: 1.05rem;
}

/* =============================================
   PRINT / PDF — Media Queries
   ============================================= */
@media print {
    @page {
        size: A4;
        margin: 15mm 12mm;
    }

    body {
        font-size: 11pt;
        color: #000 !important;
        background: #fff !important;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }

    .sidebar,
    .top-row,
    .app-footer,
    .btn-print-pdf,
    .manuale-actions .btn-print-pdf,
    .btn-help-topbar {
        display: none !important;
    }

    main {
        margin-left: 0 !important;
        padding: 0 !important;
    }

    .content {
        padding: 0 !important;
    }

    .manuale-operativo {
        max-width: 100%;
        padding: 0;
    }

    .manuale-header {
        margin-bottom: 12pt;
        padding-bottom: 10pt;
    }

    .manuale-header h1 {
        font-size: 18pt;
    }

    .manuale-toc {
        break-inside: avoid;
        border: 1px solid #ccc;
        padding: 10pt;
        margin-bottom: 14pt;
    }

    .manuale-toc ul {
        grid-template-columns: repeat(3, 1fr);
        gap: 3pt;
    }

    .manuale-toc ul li a {
        color: #000 !important;
        font-size: 9pt;
        padding: 2pt 6pt;
    }

    .manuale-section {
        break-inside: avoid;
        border: 1px solid #ddd;
        padding: 12pt 14pt;
        margin-bottom: 10pt;
        box-shadow: none;
        page-break-inside: avoid;
    }

    .manuale-section h2 {
        font-size: 14pt;
        border-bottom: 1pt solid #ccc;
        padding-bottom: 6pt;
    }

    .manuale-section h4 {
        font-size: 11pt;
    }

    .manuale-section p,
    .doc-list li,
    .doc-table td,
    .doc-table th {
        font-size: 10pt;
    }

    .feature-grid,
    .kpi-docs-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 6pt;
    }

    .feature-item,
    .kpi-doc-item {
        padding: 6pt 8pt;
    }

    .info-box {
        padding: 8pt 10pt;
    }

    .step-number {
        width: 24pt;
        height: 24pt;
        font-size: 9pt;
    }

    .stato-badge {
        width: 28pt;
        height: 28pt;
    }

    .stati-grid {
        gap: 4pt;
    }

    .stato-item {
        padding: 6pt 10pt;
    }

    .doc-table {
        font-size: 9pt;
    }

    .period-chips-doc {
        gap: 4pt;
    }

    .chip-doc {
        font-size: 8pt;
        padding: 2pt 8pt;
    }

    a {
        text-decoration: none !important;
        color: #000 !important;
    }

    code {
        border: 1px solid #ddd;
        background: #f5f5f5 !important;
    }
}
