/* Dashboard (design A): riquadri a bordo sottile, numeri in IBM Plex Mono, una sparkline per misura.
   Colori dal tema MudBlazor (--mud-palette-*) e dagli stati di app.css (--lt-ok, --lt-alarm…). */
.dash {
  --d-surface: var(--mud-palette-surface); --d-line: var(--mud-palette-lines-default); --d-soft: var(--mud-palette-background-gray);
  --d-ink: var(--mud-palette-text-primary); --d-muted: var(--mud-palette-text-secondary); --lt-grid: var(--lt-chart-grid);
  display: flex; flex-direction: column; gap: 20px; padding-bottom: 32px; color: var(--d-ink);
}
.dash .mono { font-family: 'IBM Plex Mono', ui-monospace, Menlo, monospace; font-variant-numeric: tabular-nums; }
.dash .muted { color: var(--d-muted); }
.dash h1 { margin: 0; font-size: 1.375rem; font-weight: 700; }
.dash h2 { margin: 0; font-size: 1.0625rem; font-weight: 700; }
.dash-loading { padding: 48px 0; color: var(--d-muted); }

/* ── Riquadri di stato ── */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; }
.tile { background: var(--d-surface); border: 1px solid var(--d-line); border-radius: 12px; padding: 16px 18px; min-width: 0; color: inherit; text-decoration: none; }
.tile-link:hover { border-color: var(--d-muted); }
.tile-label { font-size: 0.8125rem; color: var(--d-muted); }
.tile-main { display: flex; align-items: baseline; gap: 8px; margin-top: 6px; }
.tile-num { font-size: 2rem; font-weight: 600; line-height: 1.1; }
.tile-of { color: var(--d-muted); }
.tile-note { font-size: 0.8125rem; color: var(--d-muted); margin-top: 8px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tile.alarm { background: var(--lt-alarm-bg); }
.tile.alarm .tile-label { color: var(--lt-alarm); font-weight: 600; }
.tile.alarm .tile-num { color: var(--lt-alarm); }
.tile-bar { display: flex; gap: 4px; margin-top: 10px; }
.tile-bar .seg { flex: 1; height: 6px; border-radius: 3px; background: var(--lt-ok); }
.tile-bar .seg.warn { background: var(--lt-warn); }
.tile-bar .seg.off { background: var(--lt-off); opacity: 0.6; }

/* ── Pannelli ── */
.panel { background: var(--d-surface); border: 1px solid var(--d-line); border-radius: 14px; overflow: hidden; }
.panel-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; padding: 12px 18px; border-bottom: 1px solid var(--d-line); }
.panel-title { display: flex; align-items: center; gap: 10px; font-weight: 600; }
.panel-title .bell { color: var(--lt-alarm); }
.panel-more { width: 100%; border: 0; background: var(--d-soft); color: var(--d-ink); font: inherit; font-size: 0.875rem; font-weight: 600; padding: 10px; cursor: pointer; }
.panel .pad { padding: 12px 18px; margin: 0; }
.panel.empty { padding: 32px; text-align: center; }
.panel.empty .btn { display: inline-block; margin-top: 12px; padding: 10px 16px; border-radius: 8px; background: var(--d-ink); color: var(--d-surface); text-decoration: none; font-weight: 600; }

/* ── Allarmi ── */
.alarm-row { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 20px; padding: 12px 18px; border-bottom: 1px solid var(--d-line); }
.alarm-row:last-of-type { border-bottom: 0; }
.alarm-row .when { color: var(--d-muted); font-size: 0.875rem; min-width: 64px; }
.alarm-row .what { font-weight: 600; flex: 1 1 220px; min-width: 0; }
.alarm-row .what .muted { font-weight: 400; }
.alarm-row .val { font-size: 0.9375rem; }
.alarm-row .since { font-size: 0.8125rem; }
.badge { font-weight: 600; font-size: 0.75rem; padding: 4px 10px; border-radius: 999px; white-space: nowrap; }
.badge.high, .badge.low { background: var(--lt-alarm-bg); color: var(--lt-alarm); }
.badge.comm { background: var(--lt-off-bg); color: var(--d-ink); }

/* ── Intestazione macchine + periodo ── */
.section-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; }
.segmented { display: flex; background: var(--d-surface); border: 1px solid var(--d-line); border-radius: 10px; padding: 3px; }
.segmented button { min-height: 38px; padding: 0 14px; border: 0; border-radius: 8px; background: transparent; color: var(--d-muted); font: inherit; font-size: 0.875rem; cursor: pointer; }
.segmented button[aria-pressed="true"] { background: var(--d-ink); color: var(--d-surface); font-weight: 600; }

/* ── Schede ── */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(360px, 1fr)); gap: 16px; grid-auto-flow: row dense; align-items: start; }
.d-card { background: var(--d-surface); border: 1px solid var(--d-line); border-radius: 14px; overflow: hidden; display: flex; flex-direction: column; }
.d-card.off { opacity: 0.78; }
@media (min-width: 1100px) { .d-card.wide { grid-column: span 2; } }
.d-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; padding: 14px 16px 10px; }
.d-title { min-width: 0; }
.d-title h2 { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.d-sub { font-size: 0.75rem; color: var(--d-muted); margin-top: 3px; }
.d-head-right { display: flex; align-items: center; gap: 8px; flex: none; }
.d-icon { width: 34px; height: 34px; display: grid; place-items: center; border: 1px solid var(--d-line); border-radius: 8px; background: transparent; color: var(--d-muted); cursor: pointer; }
.d-icon:hover, .d-icon.on { color: var(--d-ink); background: var(--d-soft); }
.d-icon.small { width: 28px; height: 28px; border: 0; }
.pill { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; font-size: 0.75rem; font-weight: 600; padding: 5px 10px; border-radius: 999px; background: var(--lt-ok-bg); color: var(--lt-ok); }
.pill .dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.pill.warn { background: var(--lt-warn-bg); color: var(--lt-warn); }
.pill.off { background: var(--lt-off-bg); color: var(--lt-off); }
.d-image { padding: 0 16px 12px; }

.d-kpis { padding: 0 16px 6px; display: flex; flex-direction: column; }
.kpi { display: grid; grid-template-columns: minmax(0, 1fr) 128px; align-items: center; gap: 12px; padding: 10px 0; border-top: 1px solid var(--d-line); }
.kpi-label { display: flex; align-items: center; gap: 6px; font-size: 0.8125rem; color: var(--d-muted); min-width: 0; }
.kpi-label span:first-child { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.badge-alarm { background: var(--lt-alarm-bg); color: var(--lt-alarm); font-weight: 700; font-size: 0.6875rem; padding: 2px 7px; border-radius: 999px; flex: none; }
.kpi-value { display: flex; align-items: baseline; gap: 6px; margin-top: 2px; flex-wrap: wrap; }
.kpi-value .v { font-size: 1.625rem; font-weight: 600; line-height: 1.15; }
.kpi-value .u { font-size: 0.875rem; color: var(--d-muted); }
.kpi-value .t { font-size: 0.8125rem; color: var(--d-muted); margin-left: 4px; }
.kpi-range { font-size: 0.75rem; color: var(--d-muted); min-height: 1em; }
.kpi.alarm .v { color: var(--lt-alarm); }
.kpi.stale .v { color: var(--lt-off); }
.kpi-spark { overflow: visible; }

/* tutte le misure */
.d-all { border-top: 1px solid var(--d-line); padding: 4px 16px 8px; }
.d-group + .d-group { border-top: 1px solid var(--d-line); }
.d-group-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.d-group-toggle { flex: 1; min-width: 0; display: flex; align-items: center; gap: 8px; padding: 10px 0; border: 0; background: transparent; color: inherit; font: inherit; cursor: pointer; text-align: left; }
.d-group-toggle .swatch { width: 10px; height: 10px; border-radius: 3px; flex: none; }
.d-group-name { font-size: 0.75rem; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; }
.d-group-meta { font-size: 0.75rem; color: var(--d-muted); }
.d-rows { display: flex; flex-direction: column; padding-bottom: 6px; }
.d-row { display: grid; grid-template-columns: minmax(0, 1fr) auto 96px; align-items: center; gap: 12px; padding: 5px 0; font-size: 0.875rem; }
.d-row-label { color: var(--d-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.d-row-value { font-weight: 600; text-align: right; }
.d-row-value small { font-family: 'IBM Plex Sans', sans-serif; font-weight: 400; color: var(--d-muted); margin-left: 4px; }
.d-row.alarm .d-row-value { color: var(--lt-alarm); }

.d-foot { margin-top: auto; display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 6px; padding: 10px 16px; background: var(--d-soft); border-top: 1px solid var(--d-line); font-size: 0.75rem; color: var(--d-muted); }
.d-link { border: 0; background: transparent; padding: 0; color: var(--d-ink); font: inherit; font-weight: 600; cursor: pointer; }
.d-link:hover { color: var(--lt-accent); }

/* ── Grafico + eventi ── */
/* andamento a tutta larghezza, eventi del giorno sotto, in fondo alla pagina */
.bottom { display: flex; flex-direction: column; gap: 16px; }
.chart-panel { min-width: 0; }
.chart-panel .trend { padding: 12px 18px 16px; }
.events { min-width: 0; }
.event { display: grid; grid-template-columns: 52px 12px minmax(0, 1fr); gap: 10px; align-items: start; padding: 9px 18px; border-top: 1px solid var(--d-line); font-size: 0.875rem; }
.event:first-of-type { border-top: 0; }
.event .dot { width: 10px; height: 10px; border-radius: 50%; margin-top: 4px; background: var(--lt-ok); }
.event .dot.alarm { background: var(--lt-alarm); }
.event .dot.off { background: var(--lt-off); }
.select { min-height: 36px; padding: 0 10px; border: 1px solid var(--d-line); border-radius: 8px; background: var(--d-surface); color: var(--d-ink); font: inherit; font-size: 0.875rem; max-width: 100%; }

.trend-legend { display: flex; flex-wrap: wrap; gap: 6px 16px; font-size: 0.8125rem; color: var(--d-muted); margin-bottom: 8px; }
.trend-key { display: inline-flex; align-items: center; gap: 6px; border: 0; background: transparent; padding: 2px 0; color: inherit; font: inherit; cursor: pointer; }
.trend-key:hover { color: var(--d-ink); }
.trend-key.off { opacity: 0.45; }
.trend-key.off .trend-swatch { background: var(--d-muted) !important; }
.trend-key b { color: var(--d-ink); font-weight: 600; }
.trend-key small { font-family: 'IBM Plex Sans', sans-serif; font-weight: 400; color: var(--d-muted); margin-left: 3px; }
.trend-swatch { width: 10px; height: 10px; border-radius: 50%; flex: none; }
.trend-note { margin: 0 0 8px; font-size: 0.75rem; font-style: italic; color: var(--d-muted); }
/* assi a sinistra · grafico · assi a destra; sotto, le ore allineate al grafico */
.trend-plot { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; column-gap: 10px; padding-top: 8px; }
.trend-side { display: flex; gap: 10px; }
.trend-ax { display: flex; align-items: stretch; gap: 4px; }
.trend-title { writing-mode: vertical-rl; text-align: center; font-size: 0.6875rem; font-weight: 600; color: var(--d-muted); white-space: nowrap; }
.trend-side.left .trend-title { transform: rotate(180deg); }
.trend-y { position: relative; font-family: 'IBM Plex Mono', monospace; font-size: 0.6875rem; color: var(--d-muted); }
.trend-y span { position: absolute; right: 0; transform: translateY(-50%); line-height: 1; white-space: nowrap; }
.trend-y.right span { right: auto; left: 0; }
.trend-svg { width: 100%; display: block; cursor: crosshair; touch-action: pan-y; }
.trend-axis { display: flex; justify-content: space-between; font-size: 0.75rem; color: var(--d-muted); margin-top: 8px; }
.trend { container-type: inline-size; }
/* grafico stretto: un'ora sì e una no, altrimenti si sovrappongono */
@container (max-width: 460px) { .trend-axis span:nth-child(even) { visibility: hidden; } }
/* tooltip del grafico (window.latoriTrend): fuori dall'albero di Blazor, sopra tutto */
.lt-tip { position: fixed; z-index: 2000; pointer-events: none; min-width: 160px; padding: 8px 12px; border-radius: 8px; background: rgba(17, 19, 18, 0.94); color: #f1efe9; font-size: 0.8125rem; box-shadow: 0 8px 24px rgba(0,0,0,.35); }
.lt-tip b { display: block; padding-bottom: 6px; margin-bottom: 6px; border-bottom: 1px solid rgba(255,255,255,.12); font-family: 'IBM Plex Mono', monospace; font-weight: 500; }
.lt-tip div { display: flex; align-items: center; gap: 8px; padding: 2px 0; white-space: nowrap; }
.lt-tip i { width: 9px; height: 9px; border-radius: 50%; flex: none; }
.lt-tip span { margin-left: auto; padding-left: 12px; font-family: 'IBM Plex Mono', monospace; font-weight: 600; }
.lt-cross { position: fixed; z-index: 1999; pointer-events: none; width: 0; border-left: 1px dashed var(--d-muted, #8a938c); }
.lt-mark { position: fixed; z-index: 1999; pointer-events: none; width: 10px; height: 10px; margin: -5px 0 0 -5px; border-radius: 50%; border: 2px solid var(--mud-palette-surface, #1b1f1d); }
.d-group .trend { padding: 4px 0 10px; }

@media (max-width: 599px) {
  .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .tile { padding: 12px 14px; }
  .tile-num { font-size: 1.5rem; }
  .cards { grid-template-columns: 1fr; }
  .kpi { grid-template-columns: minmax(0, 1fr) 96px; }
  .kpi-spark { width: 96px; }
  .segmented button { padding: 0 10px; }
}

.tile.warn { background: var(--lt-warn-bg); }
.tile.warn .tile-label { color: var(--lt-warn); font-weight: 600; }
.segmented.small { padding: 2px; }
.segmented.small button { min-height: 30px; padding: 0 10px; font-size: 0.8125rem; }
.section-head .muted { font-size: 0.875rem; }
