/* Look ported from r5portal statistics_style.html (demo branch). */

    :root {
        --st-page: #f5f6f8;
        --st-surface: #ffffff;
        --st-ink: #191919;
        --st-ink-2: #666666;
        --st-hairline: rgba(11, 11, 11, 0.10);
        --st-grid: #e7e7e7;
        --st-axis: #c2c2c2;
        --st-accent: #257de0;
        --st-accent-soft: #e8f1fc;
        /* status colours: always paired with an icon + label, never colour alone */
        --st-good: #0aac23;
        --st-good-text: #006c10;
        --st-good-soft: #e6f6e9;
        --st-critical: #dc3c3d;
        --st-critical-soft: #fcebeb;
        --st-warning: #fbb315;
        --st-radius: 12px;
        --st-shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 1px 3px rgba(16, 24, 40, 0.08);
        --st-shadow-hover: 0 8px 24px rgba(16, 24, 40, 0.12);
    }

    body { background: var(--st-page); }
    .stat-page {
        max-width: 1600px; margin: 0 auto; padding: 20px 24px 40px;
        color: var(--st-ink); font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    }

    /* ---------- header ---------- */
    .crumb { margin-bottom: 8px; }
    .crumb a { color: var(--st-ink-2); text-decoration: none; font-size: 14px; }
    .crumb a:hover { color: var(--st-accent); }
    .page-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 20px; }
    .title-block { display: flex; align-items: center; gap: 14px; }
    .page-head h1 { font-size: 26px; font-weight: 700; margin: 0; line-height: 1.2; }
    .page-head .sub { color: var(--st-ink-2); font-size: 14px; margin-top: 2px; }

    .m-icon {
        display: inline-flex; align-items: center; justify-content: center; flex: none;
        width: 40px; height: 40px; border-radius: 10px;
        background: var(--st-accent-soft); color: var(--st-accent); font-size: 18px;
    }
    .m-icon.lg { width: 52px; height: 52px; border-radius: 14px; font-size: 24px; }

    .text-good { color: var(--st-good); }
    .text-critical { color: var(--st-critical); }

    /* ---------- pills ---------- */
    .pill {
        display: inline-flex; align-items: center; gap: 6px; white-space: nowrap;
        padding: 4px 10px; border-radius: 999px; font-size: 12px; font-weight: 600;
    }
    .pill i { font-size: 10px; }
    .pill .dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
    .pill-good { background: var(--st-good-soft); color: var(--st-good-text); }
    .pill-good .dot { background: var(--st-good); box-shadow: 0 0 0 0 rgba(10, 172, 35, .5); animation: st-pulse 2s infinite; }
    .pill-muted { background: #eef0f3; color: var(--st-ink-2); }
    .pill-critical { background: var(--st-critical-soft); color: var(--st-critical); }
    @keyframes st-pulse { 70% { box-shadow: 0 0 0 6px rgba(10, 172, 35, 0); } 100% { box-shadow: 0 0 0 0 rgba(10, 172, 35, 0); } }
    @media (prefers-reduced-motion: reduce) { .pill-good .dot { animation: none; } }

    /* ---------- surfaces ---------- */
    .surface {
        background: var(--st-surface); border: 1px solid var(--st-hairline);
        border-radius: var(--st-radius); box-shadow: var(--st-shadow);
    }

    /* ---------- overview: summary strip ---------- */
    .summary-strip {
        display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
        background: var(--st-surface); border: 1px solid var(--st-hairline);
        border-radius: var(--st-radius); box-shadow: var(--st-shadow); margin-bottom: 24px;
    }
    .sum-item { padding: 16px 20px; border-left: 1px solid var(--st-hairline); }
    .sum-item:first-child { border-left: none; }
    .sum-item .label { font-size: 13px; color: var(--st-ink-2); display: flex; align-items: center; gap: 6px; }
    .sum-item .value { font-size: 28px; font-weight: 700; margin-top: 2px; }
    .sum-item .of { font-size: 16px; color: var(--st-ink-2); font-weight: 500; }

    /* ---------- overview: machine cards ---------- */
    .machine-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 16px; }
    .m-card {
        display: flex; flex-direction: column; gap: 14px; padding: 18px;
        background: var(--st-surface); border: 1px solid var(--st-hairline); border-radius: var(--st-radius);
        box-shadow: var(--st-shadow); color: var(--st-ink); text-decoration: none;
        transition: box-shadow .2s ease, transform .2s ease, border-color .2s ease;
    }
    .m-card:hover, .m-card:focus-visible { color: var(--st-ink); box-shadow: var(--st-shadow-hover); transform: translateY(-2px); border-color: rgba(37, 125, 224, .35); }
    .m-card:focus-visible { outline: 2px solid var(--st-accent); outline-offset: 2px; }
    .m-head { display: flex; align-items: center; gap: 12px; }
    .m-title { flex: 1; min-width: 0; }
    .m-name { font-weight: 700; font-size: 17px; }
    .m-sub { font-size: 12px; color: var(--st-ink-2); }
    .m-hero { display: flex; align-items: baseline; gap: 8px; }
    .hero-num { font-size: 36px; font-weight: 700; line-height: 1; }
    .hero-unit { color: var(--st-ink-2); font-size: 14px; }

    .split-bar { display: flex; gap: 2px; height: 8px; border-radius: 4px; overflow: hidden; background: #eef0f3; }
    .split-bar .seg { min-width: 4px; }
    .seg-ok { background: var(--st-good); }
    .seg-ko { background: var(--st-critical); }
    .seg-neutral { background: #9aa4b1; }

    .m-legend { display: flex; flex-wrap: wrap; gap: 6px 16px; font-size: 13px; color: var(--st-ink-2); }
    .m-legend b { color: var(--st-ink); font-weight: 600; }
    .m-yield { margin-left: auto; }
    .m-foot {
        display: flex; justify-content: space-between; align-items: center;
        padding-top: 12px; border-top: 1px solid var(--st-hairline); font-size: 13px; color: var(--st-ink-2);
    }
    .m-foot .go { color: var(--st-accent); font-weight: 600; opacity: 0; transition: opacity .2s ease; }
    .m-card:hover .go, .m-card:focus-visible .go { opacity: 1; }
    .footnote { color: var(--st-ink-2); font-size: 12px; margin-top: 16px; }

    .empty-state { text-align: center; padding: 60px 20px; color: var(--st-ink-2); }
    .empty-state i { font-size: 40px; margin-bottom: 12px; opacity: .5; }
    .empty-state .hint { font-size: 14px; }
    .notice { background: #eef0f3; border-radius: 10px; padding: 10px 14px; color: var(--st-ink-2); font-size: 14px; }

    /* plant tabs on the overview */
    .group-tabs { margin: 0 0 18px; }
    .group-tabs a {
        display: inline-flex; align-items: center; gap: 8px; padding: 7px 16px; border-radius: 8px;
        color: var(--st-ink-2); font-size: 15px; font-weight: 600; text-decoration: none;
        transition: background .15s ease, color .15s ease;
    }
    .group-tabs a:hover { color: var(--st-ink); }
    .group-tabs a[aria-current="page"] { background: var(--st-surface); color: var(--st-accent); box-shadow: var(--st-shadow); }
    .group-tabs .count {
        min-width: 22px; padding: 0 7px; border-radius: 999px; background: rgba(0,0,0,.07);
        font-size: 12px; line-height: 20px; text-align: center;
    }
    .group-tabs a[aria-current="page"] .count { background: var(--st-accent-soft); }

    /* ---------- machine page: toolbar ---------- */
    .toolbar { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 16px 24px; padding: 14px 16px; margin-bottom: 20px; }
    .tb-group { display: flex; flex-direction: column; gap: 6px; }
    .tb-label { font-size: 12px; font-weight: 600; color: var(--st-ink-2); text-transform: uppercase; letter-spacing: .04em; }
    .tb-row { display: flex; gap: 6px; align-items: center; }
    .tb-row .form-control { height: 34px; font-size: 14px; }
    .tb-row .btn { height: 34px; font-size: 14px; display: inline-flex; align-items: center; gap: 6px; }

    .seg-control { display: inline-flex; background: #eef0f3; border-radius: 10px; padding: 3px; }
    .seg-control button, .seg-control a[aria-pressed] { text-decoration: none;
        border: 0; background: transparent; color: var(--st-ink-2); font-size: 14px; font-weight: 600;
        padding: 5px 14px; border-radius: 8px; transition: background .15s ease, color .15s ease;
    }
    .seg-control button:hover, .seg-control a[aria-pressed]:hover { color: var(--st-ink); }
    .seg-control button[aria-pressed="true"], .seg-control a[aria-pressed="true"] { background: var(--st-surface); color: var(--st-accent); box-shadow: var(--st-shadow); }

    .chip {
        display: inline-flex; align-items: center; gap: 6px; padding: 3px 4px 3px 10px; border-radius: 999px;
        background: var(--st-accent-soft); color: var(--st-accent); font-size: 13px; font-weight: 600;
    }
    .chip button { border: 0; background: transparent; color: inherit; padding: 0 6px; }

    /* ---------- machine page: KPI tiles ---------- */
    .kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 16px; margin-bottom: 20px; }
    .kpi { padding: 16px 18px; display: flex; flex-direction: column; gap: 6px; }
    .kpi .label { font-size: 13px; color: var(--st-ink-2); font-weight: 600; display: flex; align-items: center; gap: 6px; }
    .kpi .value { font-size: 32px; font-weight: 700; line-height: 1.1; }
    .kpi .value small { font-size: 15px; color: var(--st-ink-2); font-weight: 500; }
    .kpi .split { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: 13px; color: var(--st-ink-2); }
    .kpi .split b { color: var(--st-ink); font-weight: 600; }
    .kpi .yield { font-size: 13px; color: var(--st-ink-2); }
    .kpi .yield b { color: var(--st-ink); }
    .kpi.kpi-target.good { border-color: rgba(10, 172, 35, .45); }
    .kpi.kpi-target.bad { border-color: rgba(220, 60, 61, .45); }
    .progress-track { height: 8px; border-radius: 4px; background: #eef0f3; overflow: hidden; }
    .progress-fill { height: 100%; border-radius: 4px; background: var(--st-accent); width: 0; transition: width .4s ease; }
    .kpi-target.good .progress-fill { background: var(--st-good); }
    .kpi-target.bad .progress-fill { background: var(--st-critical); }

    /* ---------- machine page: chart cards ---------- */
    .chart-grid { display: grid; grid-template-columns: 1fr; gap: 20px; }
    .chart-card { padding: 16px 18px 8px; }
    .chart-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; flex-wrap: wrap; margin-bottom: 4px; }
    .chart-head h2 { font-size: 17px; font-weight: 700; margin: 0; }
    .chart-head .desc { font-size: 13px; color: var(--st-ink-2); margin-top: 2px; }
    .chart-stats { display: flex; gap: 18px; flex-wrap: wrap; font-size: 13px; color: var(--st-ink-2); }
    .chart-stats b { color: var(--st-ink); font-size: 16px; }
    .chart { width: 100%; height: 400px; position: relative; }
    .chart.loading::after {
        content: "Caricamento…"; position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
        color: var(--st-ink-2); background: linear-gradient(90deg, #fafbfc 25%, #f0f2f5 50%, #fafbfc 75%);
        background-size: 200% 100%; animation: st-shimmer 1.4s infinite; border-radius: 8px;
    }
    @keyframes st-shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }
    .chart-note { font-size: 12px; color: var(--st-ink-2); padding: 0 0 8px; }
    .chart.chart-tall { height: 460px; }
    .stops-summary { border-top: 1px solid var(--st-hairline); padding: 10px 0 2px; }

    /* headline figures above the throughput chart */
    .rate-kpis {
        display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 0;
        background: #f7f8fa; border: 1px solid var(--st-hairline); border-radius: 10px; margin: 12px 0 4px;
    }
    .rate-kpis > div { padding: 12px 16px; border-left: 1px solid var(--st-hairline); }
    .rate-kpis > div:first-child { border-left: none; }
    .rate-kpis .label { font-size: 13px; color: var(--st-ink-2); }
    .rate-kpis .value { font-size: 28px; font-weight: 600; line-height: 1.2; }
    .rate-kpis .value small { font-size: 14px; color: var(--st-ink-2); font-weight: 500; margin-left: 2px; }

    details.data-table { border-top: 1px solid var(--st-hairline); padding: 8px 0; }
    details.data-table summary { cursor: pointer; font-size: 13px; color: var(--st-accent); font-weight: 600; }
    details.data-table table { width: 100%; margin-top: 8px; font-size: 13px; font-variant-numeric: tabular-nums; }
    details.data-table th { color: var(--st-ink-2); font-weight: 600; border-bottom: 1px solid var(--st-hairline); padding: 6px 8px; }
    details.data-table td { padding: 5px 8px; border-bottom: 1px solid #f0f1f3; }
    details.data-table td.n, details.data-table th.n { text-align: right; }
    .table-scroll { max-height: 320px; overflow: auto; }

    .back-row { text-align: center; margin-top: 28px; }

    @media (max-width: 576px) {
        .stat-page { padding: 14px 12px 30px; }
        .page-head h1 { font-size: 21px; }
        .sum-item { border-left: none; border-top: 1px solid var(--st-hairline); }
        .chart { height: 320px; }
    }

/* Neo Systems dark theme on top of the r5portal look */
:root {
    --st-page: #060a14; --st-surface: #0d1426; --st-ink: #e6ecf5; --st-ink-2: #8d99b0;
    --st-hairline: rgba(255, 255, 255, 0.09); --st-accent: #6d8dff; --st-accent-soft: rgba(47, 123, 255, 0.16);
    --st-good-soft: rgba(10, 172, 35, 0.16); --st-good-text: #5fe07a; --st-critical-soft: rgba(220, 60, 61, 0.16);
    --st-shadow: 0 1px 3px rgba(0, 0, 0, 0.4); --st-shadow-hover: 0 10px 30px rgba(91, 108, 255, 0.25);
}
.seg-control, .split-bar, .pill-muted, .notice, .group-tabs .count { background: rgba(255, 255, 255, 0.06); }
.split-bar .seg-ok { background: linear-gradient(90deg, #2f7bff, #8b5cf6); }
