/* ============================================================
   DRS Monitor – tema
   ============================================================ */
:root {
  --bg: #f3f5f8;
  --surface: #ffffff;
  --surface-2: #f7f9fb;
  --ink: #142232;
  --ink-2: #3d4c5e;
  --muted: #6b7a8c;
  --line: #e3e8ee;
  --line-2: #d3dae3;
  --accent: #0b6e79;
  --accent-2: #0e8a97;
  --accent-soft: #e3f2f3;
  --on-accent: #ffffff;

  --side: #0c1a29;
  --side-2: #152a3f;
  --side-3: #1d3650;
  --side-ink: #c5d1de;
  --side-muted: #7f93a8;
  --side-line: rgba(255, 255, 255, .08);
  --glow: #2bb0bd;

  --free: #94a3b3;   --free-soft: #f1f4f7;
  --dry: #2563c9;    --dry-soft: #e8f0fc;
  --store: #17804a;  --store-soft: #e6f4ec;
  --warn: #b45a09;   --warn-soft: #fdf1e2;
  --err: #c2283c;    --err-soft: #fce9ec;

  /* armadio: struttura in acciaio scuro con vani illuminati */
  --cab-frame: #243446;
  --cab-frame-2: #16222f;
  --cab-inner: #0e1823;
  --vano: #ffffff;
  --vano-2: #f3f6f9;

  --shadow-sm: 0 1px 2px rgba(16, 32, 48, .06);
  --shadow: 0 1px 2px rgba(16, 32, 48, .05), 0 4px 14px rgba(16, 32, 48, .06);
  --radius: 14px;
  --font: "Inter", "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0b131c; --surface: #111c27; --surface-2: #152230; --ink: #e5ecf3; --ink-2: #b8c5d3; --muted: #8497ab;
    --line: #1f2e3e; --line-2: #2a3c4f; --accent: #2bb0bd; --accent-2: #45c3cf; --accent-soft: #0f2d33; --on-accent: #04171a;
    --side: #050b12; --side-2: #0f1c29; --side-3: #172a3c;
    --free: #5f7185; --free-soft: #152230; --dry: #5b95ef; --dry-soft: #13243b; --store: #3cc07a; --store-soft: #10281c;
    --warn: #eea23c; --warn-soft: #2c210f; --err: #f0596c; --err-soft: #321820;
    --cab-frame: #1f3044; --cab-frame-2: #121e2b; --cab-inner: #070d14; --vano: #132130; --vano-2: #0f1b27;
    --shadow-sm: none; --shadow: 0 0 0 1px rgba(255,255,255,.02); color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0b131c; --surface: #111c27; --surface-2: #152230; --ink: #e5ecf3; --ink-2: #b8c5d3; --muted: #8497ab;
  --line: #1f2e3e; --line-2: #2a3c4f; --accent: #2bb0bd; --accent-2: #45c3cf; --accent-soft: #0f2d33; --on-accent: #04171a;
  --side: #050b12; --side-2: #0f1c29; --side-3: #172a3c;
  --free: #5f7185; --free-soft: #152230; --dry: #5b95ef; --dry-soft: #13243b; --store: #3cc07a; --store-soft: #10281c;
  --warn: #eea23c; --warn-soft: #2c210f; --err: #f0596c; --err-soft: #321820;
  --cab-frame: #1f3044; --cab-frame-2: #121e2b; --cab-inner: #070d14; --vano: #132130; --vano-2: #0f1b27;
  --shadow-sm: none; --shadow: 0 0 0 1px rgba(255,255,255,.02); color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 14px/1.5 var(--font); -webkit-font-smoothing: antialiased; font-feature-settings: "tnum" 1, "cv11" 1; }
svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
h1, h2, h3 { margin: 0; letter-spacing: -.01em; }
code { font: 12px var(--mono); background: var(--surface-2); border: 1px solid var(--line); padding: 0 5px; border-radius: 4px; }
a { color: var(--accent); }

/* ============================================================ shell */
/* cornice scura unica (barra laterale + intestazione) attorno a un "foglio" chiaro con i dati */
body { background: var(--side); }
.shell { display: grid; grid-template-columns: 240px minmax(0, 1fr); min-height: 100vh; background: radial-gradient(900px 500px at 0% 0%, rgba(43, 176, 189, .10), transparent 60%), var(--side); }
.sidebar { color: var(--side-ink); display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; padding: 18px 14px; }
.logo { display: flex; align-items: center; gap: 11px; padding: 4px 8px 26px; }
.logo-mark { width: 38px; height: 38px; border-radius: 11px; background: linear-gradient(145deg, #19b3c1, #0b5d67); display: grid; place-items: center; color: #fff; box-shadow: inset 0 1px 0 rgba(255,255,255,.25), 0 6px 18px rgba(25, 179, 193, .35); }
.logo-mark svg { width: 20px; height: 20px; }
.logo b { display: block; color: #fff; font-size: 15.5px; letter-spacing: -.01em; }
.logo small { color: var(--side-muted); font-size: 12px; }
.nav { display: flex; flex-direction: column; gap: 3px; }
.nav a { display: flex; align-items: center; gap: 11px; padding: 10px 12px; border-radius: 9px; color: var(--side-ink); text-decoration: none; font-weight: 500; font-size: 13.5px; transition: background .15s, color .15s; }
.nav a:hover { background: rgba(255,255,255,.05); color: #fff; }
.nav a.active { background: linear-gradient(90deg, rgba(43,176,189,.22), rgba(43,176,189,.06)); color: #fff; box-shadow: inset 0 0 0 1px rgba(69,195,207,.22); }
.nav a svg { color: var(--side-muted); }
.nav a.active svg { color: #5fd3de; }
.nav .count { margin-left: auto; min-width: 20px; padding: 0 6px; border-radius: 10px; background: var(--side-3); color: #fff; font-size: 11.5px; text-align: center; line-height: 19px; }
.nav .count.alarm { background: var(--err); }
.side-foot { margin-top: auto; }
.conn-card { background: rgba(255,255,255,.04); border: 1px solid var(--side-line); border-radius: 11px; padding: 11px 12px; }
.conn-row { display: flex; align-items: center; gap: 9px; color: #fff; font-size: 13px; }
.conn-row .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--side-muted); }
.conn-card.on .dot { background: #3cc07a; box-shadow: 0 0 0 3px rgba(60,192,122,.2); }
.conn-card.off .dot { background: #f0596c; box-shadow: 0 0 0 3px rgba(240,89,108,.2); }
.conn-meta { color: var(--side-muted); font-size: 12px; margin-top: 3px; line-height: 1.45; }
.side-ver { color: #4f6378; font-size: 11px; padding: 12px 4px 0; }

.main { min-width: 0; display: flex; flex-direction: column; }
.sheet { flex: 1; min-height: 0; display: flex; flex-direction: column; background: var(--bg); border-top-left-radius: 22px; box-shadow: -1px -1px 0 var(--side-line), inset 0 1px 0 color-mix(in srgb, var(--surface) 70%, transparent); }
.topbar { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 18px; padding: 14px 28px 14px 24px; color: #fff; }
.crumbs { flex: none; }
.crumbs small { color: var(--side-muted); font-size: 12px; }
.crumbs h1 { font-size: 19px; font-weight: 650; line-height: 1.2; color: #fff; }
.top-right { margin-left: auto; display: flex; align-items: center; gap: 8px; flex: none; }
.clock-chip { display: flex; align-items: center; gap: 9px; padding: 7px 12px; border: 1px solid var(--side-line); border-radius: 10px; background: rgba(255,255,255,.04); }
.clock-chip svg { color: #5fd3de; }
.clock-chip span { font: 600 15px var(--mono); color: #fff; }
.clock-chip small { color: var(--side-muted); font: 12px var(--mono); }
.icon-btn { width: 38px; height: 38px; display: grid; place-items: center; border: 1px solid var(--side-line); border-radius: 10px; background: rgba(255,255,255,.04); color: var(--side-ink); cursor: pointer; transition: background .15s, color .15s; }
.icon-btn:hover { background: rgba(255,255,255,.1); color: #fff; }
.only-mobile { display: none; }

/* schede armadi nell'intestazione */
.dev-tabs { display: flex; gap: 8px; min-width: 0; overflow-x: auto; scrollbar-width: none; padding: 2px; }
.dev-tabs::-webkit-scrollbar { display: none; }
.dev-tab { position: relative; display: flex; align-items: center; gap: 10px; padding: 6px 14px 6px 7px; border-radius: 12px; border: 1px solid var(--side-line); background: rgba(255,255,255,.035); color: var(--side-ink); font: inherit; text-align: left; cursor: pointer; white-space: nowrap; transition: background .15s, border-color .15s, box-shadow .15s; }
.dev-tab:hover { background: rgba(255,255,255,.08); color: #fff; }
.dev-tab.active { background: linear-gradient(135deg, rgba(43,176,189,.28), rgba(43,176,189,.08)); border-color: rgba(95,211,222,.45); color: #fff; box-shadow: 0 6px 20px rgba(0,0,0,.25), inset 0 1px 0 rgba(255,255,255,.08); }
.dev-ic { position: relative; width: 32px; height: 32px; border-radius: 9px; display: grid; place-items: center; background: rgba(255,255,255,.06); color: var(--side-ink); }
.dev-tab.active .dev-ic { background: linear-gradient(145deg, #19b3c1, #0b5d67); color: #fff; }
.dev-ic svg { width: 17px; height: 17px; }
.dev-ic .dot { position: absolute; right: -2px; bottom: -2px; width: 10px; height: 10px; border-radius: 50%; background: var(--side-muted); border: 2px solid var(--side); }
.dev-tab.on .dot { background: #3cc07a; }
.dev-tab.off .dot { background: #f0596c; animation: blink 1.2s infinite; }
.dev-tx b { display: block; font-size: 13px; font-weight: 600; line-height: 1.25; }
.dev-tx small { display: block; color: var(--side-muted); font-size: 11.5px; line-height: 1.3; }
.dev-tab.active .dev-tx small { color: #9fdce2; }
.dev-tab .count { min-width: 20px; padding: 0 6px; border-radius: 10px; background: var(--err); color: #fff; font-size: 11.5px; font-weight: 600; text-align: center; line-height: 19px; }

.content { padding: 24px 28px 48px; width: 100%; max-width: 1680px; }
.view { display: none; }
.view.active { display: block; animation: fade .18s ease-out; }
@keyframes fade { from { opacity: 0; transform: translateY(3px); } }

/* ============================================================ cards */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px 20px; margin-bottom: 20px; }
.card-h { display: flex; align-items: flex-start; justify-content: space-between; gap: 14px; margin-bottom: 16px; flex-wrap: wrap; }
.card-h h2 { font-size: 15px; font-weight: 650; }
.card-sub { margin: 2px 0 0; color: var(--muted); font-size: 12.5px; }
.link { font-size: 13px; font-weight: 500; text-decoration: none; }
.tag { font: 600 11px var(--mono); padding: 3px 8px; border-radius: 5px; background: var(--accent-soft); color: var(--accent); letter-spacing: .03em; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; margin-bottom: 20px; }
.grid-2 > .card { margin-bottom: 0; }

/* ============================================================ alerts */
.alerts:empty { display: none; }
.alerts { display: flex; flex-direction: column; gap: 8px; margin-bottom: 20px; }
.alert { display: flex; align-items: center; gap: 12px; padding: 11px 16px; border-radius: 9px; border: 1px solid; font-weight: 500; font-size: 13.5px; }
.alert.error { background: var(--err-soft); border-color: color-mix(in srgb, var(--err) 30%, transparent); color: var(--err); }
.alert.warn { background: var(--warn-soft); border-color: color-mix(in srgb, var(--warn) 30%, transparent); color: var(--warn); }
.alert b { color: var(--ink); font-weight: 600; }

/* ============================================================ KPI */
.kpis { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 16px; margin-bottom: 20px; }
.kpi { position: relative; overflow: hidden; background: linear-gradient(135deg, color-mix(in srgb, var(--s) 55%, var(--surface)), var(--surface) 55%); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px 18px; display: flex; gap: 14px; align-items: flex-start; }
.kpi::after { content: ""; position: absolute; right: -30px; top: -30px; width: 90px; height: 90px; border-radius: 50%; background: radial-gradient(circle, color-mix(in srgb, var(--c) 14%, transparent), transparent 70%); pointer-events: none; }
.kpi .ic { width: 42px; height: 42px; border-radius: 12px; display: grid; place-items: center; background: linear-gradient(145deg, color-mix(in srgb, var(--c) 80%, #fff), var(--c)); color: #fff; box-shadow: 0 6px 14px -4px color-mix(in srgb, var(--c) 60%, transparent); }
.kpi .ic svg { width: 20px; height: 20px; }
.kpi .l { color: var(--muted); font-size: 12.5px; font-weight: 500; }
.kpi .v { font-size: 26px; font-weight: 650; line-height: 1.15; letter-spacing: -.02em; }
.kpi .v small { font-size: 14px; color: var(--muted); font-weight: 500; }
.kpi .s { font-size: 12px; color: var(--muted); margin-top: 2px; }
.kpi .bar { height: 5px; border-radius: 3px; background: var(--line); margin-top: 8px; overflow: hidden; width: 100%; }
.kpi .bar i { display: block; height: 100%; background: var(--c); border-radius: 3px; transition: width .4s; }
.kpi > div:last-child { flex: 1; min-width: 0; }

/* ============================================================ overview */
.overview { display: grid; grid-template-columns: minmax(0, 1fr) 360px; gap: 20px; align-items: start; }

.seg { display: inline-flex; padding: 3px; background: var(--surface-2); border: 1px solid var(--line); border-radius: 8px; }
.seg button { border: 0; background: none; font: inherit; font-size: 12.5px; font-weight: 500; color: var(--muted); padding: 5px 12px; border-radius: 6px; cursor: pointer; }
.seg button.on { background: var(--surface); color: var(--ink); box-shadow: var(--shadow-sm), 0 0 0 1px var(--line); }

/* cabinet: struttura in acciaio scuro, vani come finestre illuminate */
.cabinet { position: relative; background: linear-gradient(180deg, var(--cab-frame), var(--cab-frame-2)); border-radius: 16px; padding: 10px 12px 12px; box-shadow: inset 0 1px 0 rgba(255,255,255,.10), inset 0 -1px 0 rgba(0,0,0,.4), 0 14px 34px -12px rgba(8, 18, 30, .45); }
.cabinet::after { content: ""; position: absolute; left: 22%; right: 22%; bottom: -6px; height: 6px; border-radius: 0 0 6px 6px; background: var(--cab-frame-2); opacity: .7; }
.cabinet-top { display: flex; justify-content: space-between; align-items: center; padding: 1px 4px 9px; font: 600 11px var(--mono); letter-spacing: .14em; text-transform: uppercase; color: #9fb2c6; }
.leds { display: flex; gap: 6px; }
.leds i { width: 7px; height: 7px; border-radius: 50%; background: #3cc07a; box-shadow: 0 0 8px #3cc07a; }
.leds i:nth-child(2) { background: #5b95ef; box-shadow: 0 0 8px #5b95ef; }
.leds i:nth-child(3) { background: #5fd3de; box-shadow: 0 0 8px #5fd3de; animation: blink 2.4s infinite; }
.cabinet.offline .leds i { background: #f0596c; box-shadow: 0 0 8px #f0596c; animation: blink 1s infinite; }
.cabinet.offline .slots { filter: grayscale(.7) opacity(.7); }
.slots { display: grid; grid-template-columns: repeat(var(--cols, 6), minmax(0, 1fr)); gap: 8px; background: var(--cab-inner); border-radius: 10px; padding: 8px; box-shadow: inset 0 3px 12px rgba(0,0,0,.55), inset 0 0 0 1px rgba(0,0,0,.4); }

.slot { --c: var(--free); --s: var(--free-soft); position: relative; display: flex; flex-direction: column; min-height: 250px; padding: 9px 10px 10px; border-radius: 9px; border: 0; background: linear-gradient(180deg, var(--vano), var(--vano-2)); text-align: left; font: inherit; color: inherit; cursor: pointer; overflow: hidden; box-shadow: inset 0 0 0 1px rgba(255,255,255,.05), 0 1px 0 rgba(255,255,255,.04); transition: transform .18s ease, box-shadow .18s ease, opacity .2s; }
/* striscia luminosa superiore del vano, colore della fase */
.slot::before { content: ""; position: absolute; left: 10px; right: 10px; top: 0; height: 3px; border-radius: 0 0 3px 3px; background: var(--c); box-shadow: 0 0 12px var(--c); }
.slot:hover { transform: translateY(-2px); box-shadow: 0 10px 22px -8px rgba(0,0,0,.5), inset 0 0 0 1px color-mix(in srgb, var(--c) 40%, transparent); }
.slot.sel { box-shadow: 0 0 0 2px var(--accent-2), 0 10px 26px -8px color-mix(in srgb, var(--accent) 70%, transparent); }
.slot.dim { opacity: .22; }
.slot.ph1 { --c: var(--dry); --s: var(--dry-soft); }
.slot.ph2 { --c: var(--store); --s: var(--store-soft); }
.slot.ph3 { --c: var(--warn); --s: var(--warn-soft); }
.slot.ph4, .slot.ph5 { --c: var(--err); --s: var(--err-soft); }
.slot.ph3, .slot.ph4, .slot.ph5 { animation: alarm-glow 1.6s ease-in-out infinite; }
@keyframes alarm-glow { 50% { box-shadow: inset 0 0 0 2px var(--c), 0 0 18px -2px var(--c); } }
.slot-h { position: relative; z-index: 1; display: flex; justify-content: space-between; align-items: center; gap: 6px; }
.slot-n { display: inline-grid; place-items: center; min-width: 26px; height: 22px; padding: 0 5px; border-radius: 6px; background: var(--c); color: #fff; font: 700 12px var(--mono); box-shadow: 0 2px 6px color-mix(in srgb, var(--c) 45%, transparent); }
.slot.empty .slot-n { background: transparent; color: var(--muted); box-shadow: inset 0 0 0 1px var(--line-2); }
.status { display: inline-flex; align-items: center; gap: 5px; min-width: 0; font-size: 11px; font-weight: 600; color: var(--c); background: var(--s); padding: 2px 8px; border-radius: 10px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.status::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; flex: none; }
.slot.ph1 .status::before { animation: blink 1.2s infinite; }
.slot.empty .status { background: transparent; color: var(--muted); }
@keyframes blink { 50% { opacity: .25; } }

/* vano con l'endoscopio appeso: alone luminoso del colore di fase */
.slot-art { position: relative; flex: 1 1 auto; min-height: 90px; margin: 7px -4px 6px; border-radius: 7px; overflow: hidden; background: radial-gradient(90% 70% at 50% 18%, color-mix(in srgb, var(--c) 22%, transparent), transparent 72%), linear-gradient(180deg, color-mix(in srgb, var(--c) 7%, transparent), transparent); }
.slot.empty .slot-art { background: repeating-linear-gradient(90deg, transparent 0 9px, color-mix(in srgb, var(--line) 55%, transparent) 9px 10px); }
.scope { position: absolute; inset: 4px 0 0; width: 100%; height: calc(100% - 4px); overflow: visible; color: var(--c); stroke-linecap: round; stroke-linejoin: round; filter: drop-shadow(0 3px 4px rgba(10, 20, 30, .22)); }
.sc-hook { fill: none; stroke: #8e9cad; stroke-width: 2.6; }
.sc-hook-pin { fill: #8e9cad; stroke: none; }
.sc-body { fill: currentColor; stroke: none; }
.sc-dark { fill: color-mix(in srgb, currentColor 62%, #0b1622); stroke: none; }
.sc-hl { fill: #fff; opacity: .38; stroke: none; }
.sc-btn { fill: #fff; opacity: .85; stroke: none; }
.sc-knob { fill: color-mix(in srgb, currentColor 40%, #0b1622); stroke: none; }
.sc-cable { fill: none; stroke: color-mix(in srgb, currentColor 55%, #7b8a9b); stroke-width: 3.4; }
.sc-tube { fill: none; stroke: currentColor; stroke-width: 4.6; }
.sc-tube-hl { fill: none; stroke: #fff; stroke-width: 1.2; opacity: .35; }
.sc-tip { fill: none; stroke: color-mix(in srgb, currentColor 55%, #0b1622); stroke-width: 4.8; }
.sc-lens { fill: #cfeff3; stroke: color-mix(in srgb, currentColor 50%, #0b1622); stroke-width: 1; }
.scope.ghost { filter: none; }
.sc-ghost { fill: none; stroke: var(--line-2); stroke-width: 1.6; stroke-dasharray: 3 4; }

/* flusso d'aria in asciugatura: bolle che salgono */
.air { position: absolute; inset: 0; pointer-events: none; }
.air i { position: absolute; bottom: -8px; width: 5px; height: 5px; border-radius: 50%; background: color-mix(in srgb, var(--dry) 60%, #fff); opacity: 0; animation: rise 2.8s linear infinite; }
.air i:nth-child(1) { left: 22%; animation-delay: 0s; }
.air i:nth-child(2) { left: 70%; animation-delay: .6s; width: 4px; height: 4px; }
.air i:nth-child(3) { left: 40%; animation-delay: 1.2s; }
.air i:nth-child(4) { left: 82%; animation-delay: 1.8s; width: 3px; height: 3px; }
.air i:nth-child(5) { left: 12%; animation-delay: 2.3s; width: 4px; height: 4px; }
@keyframes rise { 0% { transform: translateY(0); opacity: 0; } 15% { opacity: .9; } 100% { transform: translateY(-160px); opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .air, .slot { animation: none !important; } .slot:hover { transform: none; } }

.slot-info { position: relative; z-index: 1; min-width: 0; }
.slot-id { font-weight: 700; font-size: 14px; line-height: 1.25; letter-spacing: -.01em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.slot-m { color: var(--muted); font-size: 11.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.slot-op { display: flex; align-items: center; gap: 6px; color: var(--ink-2); font-size: 11.5px; font-weight: 600; margin-top: 5px; min-width: 0; }
.slot-op i { flex: none; width: 18px; height: 18px; border-radius: 50%; display: grid; place-items: center; color: #fff; font-style: normal; font-size: 8px; font-weight: 700; }
.slot-op span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.slot-f { position: relative; z-index: 1; margin-top: 7px; padding-top: 7px; border-top: 1px dashed var(--line-2); }
.slot-tr { display: flex; justify-content: space-between; align-items: center; font-size: 11px; color: var(--muted); }
.slot-tr span { display: inline-flex; align-items: center; gap: 4px; }
.slot-tr svg { width: 12px; height: 12px; }
.slot-tr b { font: 700 12.5px var(--mono); color: var(--ink); }
.slot.low .slot-tr b { color: var(--err); }
.meter { height: 5px; border-radius: 3px; background: color-mix(in srgb, var(--c) 14%, var(--line)); margin-top: 5px; overflow: hidden; }
.meter i { display: block; height: 100%; border-radius: 3px; background: linear-gradient(90deg, color-mix(in srgb, var(--c) 70%, #fff), var(--c)); box-shadow: 0 0 8px color-mix(in srgb, var(--c) 60%, transparent); transition: width .6s; }
.slot.low .meter i { background: var(--err); }
.slot.empty .slot-id { color: var(--muted); font-weight: 600; }
.slot.empty .slot-m { color: color-mix(in srgb, var(--muted) 70%, transparent); }

.legend { display: flex; flex-wrap: wrap; gap: 16px; margin-top: 14px; font-size: 12px; color: var(--muted); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 10px; height: 10px; border-radius: 3px; }

/* detail panel */
.detail-empty { text-align: center; color: var(--muted); padding: 18px 8px 10px; font-size: 13px; }
.detail-empty svg { width: 34px; height: 34px; color: var(--line-2); margin-bottom: 6px; }
.detail-h { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; margin-bottom: 14px; }
.detail-h small { color: var(--muted); font-size: 12px; }
.detail-h h3 { font-size: 20px; font-weight: 700; }
.detail .status { font-size: 12px; padding: 3px 9px; }
.detail .kv { grid-template-columns: 1fr 1.4fr; }
.detail-tr { background: var(--surface-2); border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; margin-bottom: 14px; }
.detail-tr .row { display: flex; justify-content: space-between; align-items: baseline; }
.detail-tr b { font: 650 20px var(--mono); }
.detail-tr small { color: var(--muted); font-size: 12px; }
.detail-tr .meter { height: 6px; margin-top: 8px; }

/* sensors */
.sensors { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.sensor { border: 1px solid var(--line); border-radius: 9px; padding: 10px 12px 8px; background: var(--surface-2); }
.sensor.wide { grid-column: span 2; }
.sensor .l { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 11.5px; font-weight: 500; }
.sensor .l svg { width: 14px; height: 14px; color: var(--accent); }
.sensor .v { font-size: 21px; font-weight: 650; letter-spacing: -.02em; line-height: 1.3; }
.sensor .v small { font-size: 12px; color: var(--muted); font-weight: 500; margin-left: 2px; }
.sensor .spark { display: block; width: 100%; height: 26px; margin-top: 2px; }
.spark path { fill: none; stroke: var(--accent); stroke-width: 1.5; vector-effect: non-scaling-stroke; }
.spark path.area { fill: color-mix(in srgb, var(--accent) 10%, transparent); stroke: none; }
.sensor .range { display: flex; justify-content: space-between; font-size: 10.5px; color: var(--muted); font-family: var(--mono); }

.acts { display: flex; flex-direction: column; }
.act { display: flex; align-items: center; justify-content: space-between; padding: 9px 2px; border-bottom: 1px solid var(--line); font-size: 13px; }
.act:last-child { border: 0; padding-bottom: 0; }
.act:first-child { padding-top: 0; }
.onoff { font-size: 11px; font-weight: 700; letter-spacing: .05em; padding: 2px 9px; border-radius: 10px; background: var(--free-soft); color: var(--muted); border: 1px solid var(--line); }
.onoff.on { background: var(--store-soft); color: var(--store); border-color: color-mix(in srgb, var(--store) 25%, transparent); }

/* timeline */
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { display: grid; grid-template-columns: 22px 150px minmax(0, 1fr); align-items: start; gap: 10px; padding: 9px 0; border-bottom: 1px solid var(--line); font-size: 13px; }
.timeline li:last-child { border: 0; }
.timeline .ev-ic { width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent); }
.timeline .ev-ic svg { width: 13px; height: 13px; stroke-width: 2.2; }
.timeline li.error .ev-ic { background: var(--err-soft); color: var(--err); }
.timeline li.warn .ev-ic { background: var(--warn-soft); color: var(--warn); }
.timeline li.load .ev-ic { background: var(--store-soft); color: var(--store); }
.timeline li.unload .ev-ic { background: var(--dry-soft); color: var(--dry); }
.timeline .ts { color: var(--muted); font-family: var(--mono); font-size: 12px; padding-top: 2px; }
.timeline li.error .tx { color: var(--err); }
.timeline li.empty { display: block; color: var(--muted); }

/* ============================================================ forms / buttons */
.btn { display: inline-flex; align-items: center; gap: 7px; height: 36px; padding: 0 14px; border-radius: 8px; border: 1px solid var(--accent); background: var(--accent); color: var(--on-accent); font: inherit; font-weight: 550; font-size: 13px; cursor: pointer; text-decoration: none; white-space: nowrap; justify-content: center; }
.btn svg { width: 16px; height: 16px; }
.btn:hover { background: var(--accent-2); border-color: var(--accent-2); }
.btn.ghost { background: var(--surface); color: var(--ink-2); border-color: var(--line-2); }
.btn.ghost:hover { border-color: var(--accent); color: var(--accent); }
.btn.danger { background: var(--surface); color: var(--err); border-color: color-mix(in srgb, var(--err) 40%, transparent); }
.btn.danger:hover { background: var(--err-soft); }
.btn.text { background: none; border-color: transparent; color: var(--muted); padding: 0 6px; }
.btn.text:hover { color: var(--accent); }
.btn:disabled { opacity: .55; cursor: progress; }
.actions { display: flex; gap: 10px; flex-wrap: wrap; }

.filters { display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-end; padding: 14px; background: var(--surface-2); border: 1px solid var(--line); border-radius: 9px; margin-bottom: 14px; }
.field { display: flex; flex-direction: column; gap: 4px; }
.field.grow { flex: 1; min-width: 220px; }
.field > span { font-size: 11.5px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
select, input[type=search], input[type=date] { height: 36px; font: inherit; font-size: 13px; color: var(--ink); background: var(--surface); border: 1px solid var(--line-2); border-radius: 8px; padding: 0 10px; min-width: 150px; }
select:focus, input:focus { outline: 2px solid color-mix(in srgb, var(--accent) 40%, transparent); outline-offset: 0; border-color: var(--accent); }
.input-icon { position: relative; }
.input-icon svg { position: absolute; left: 10px; top: 9px; color: var(--muted); }
.input-icon input { width: 100%; padding-left: 34px; }

.note { display: flex; gap: 10px; align-items: flex-start; padding: 10px 14px; border-radius: 8px; background: var(--accent-soft); color: var(--ink-2); font-size: 12.5px; margin-bottom: 14px; }
.note svg { color: var(--accent); margin-top: 1px; }
.note p { margin: 0; }

/* operator summary */
.op-summary { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 14px; margin-bottom: 20px; }
.op-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px 16px; display: flex; gap: 12px; align-items: center; cursor: pointer; text-align: left; font: inherit; color: inherit; }
.op-card:hover { border-color: var(--line-2); }
.op-card.sel { border-color: var(--accent); box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 30%, transparent); }
.avatar { width: 38px; height: 38px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; font-size: 12px; color: #fff; flex: none; }
.op-card b { display: block; font-size: 14px; }
.op-card small { color: var(--muted); font-size: 12px; }
.op-stats { margin-left: auto; display: flex; gap: 14px; text-align: center; }
.op-stats div { font-size: 17px; font-weight: 650; line-height: 1.1; }
.op-stats span { display: block; font-size: 10px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }

/* memories */
.mem-mode { display: grid; grid-template-columns: 170px minmax(0, 1fr) auto; gap: 14px; align-items: stretch; margin-bottom: 18px; }
.mem-pending { border: 1px solid var(--line); border-radius: 9px; padding: 12px 14px; background: var(--surface-2); display: flex; flex-direction: column; justify-content: center; }
.mem-pending span { color: var(--muted); font-size: 12px; }
.mem-pending b { font-size: 28px; font-weight: 650; }
.radio-cards { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.radio-cards label { display: flex; gap: 10px; align-items: flex-start; border: 1px solid var(--line-2); border-radius: 9px; padding: 11px 12px; cursor: pointer; background: var(--surface); }
.radio-cards label:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.radio-cards input { accent-color: var(--accent); margin-top: 3px; }
.radio-cards b { display: block; font-size: 13px; }
.radio-cards small { color: var(--muted); font-size: 11.5px; line-height: 1.35; display: block; }
.mem-actions { display: flex; flex-direction: column; gap: 8px; justify-content: center; }

/* tables */
.table-wrap { overflow: auto; border: 1px solid var(--line); border-radius: 12px; max-height: 640px; background: var(--surface); }
.table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 13px; }
.table th { position: sticky; top: 0; z-index: 1; background: color-mix(in srgb, var(--surface-2) 92%, var(--accent) 8%); color: var(--ink-2); font-size: 11px; font-weight: 650; text-transform: uppercase; letter-spacing: .05em; text-align: left; padding: 11px 14px; border-bottom: 1px solid var(--line-2); white-space: nowrap; user-select: none; }
.table th.sortable { cursor: pointer; }
.table th.sortable span { display: inline-flex; align-items: center; gap: 4px; }
.table th.sortable svg { width: 12px; height: 12px; opacity: .3; transition: opacity .15s, transform .15s; }
.table th.sortable:hover svg { opacity: .7; }
.table th.asc, .table th.desc { color: var(--accent); }
.table th.asc svg, .table th.desc svg { opacity: 1; }
.table th.desc svg { transform: scaleY(-1); }
.table td { padding: 9px 14px; border-bottom: 1px solid var(--line); white-space: nowrap; vertical-align: middle; }
.table tbody tr:nth-child(even) td { background: color-mix(in srgb, var(--surface-2) 55%, transparent); }
.table tr:last-child td { border-bottom: 0; }
.table tbody tr:hover td { background: color-mix(in srgb, var(--accent) 7%, var(--surface)); }
.table tr.click { cursor: pointer; }
.table tr.click td:first-child { box-shadow: inset 3px 0 0 transparent; transition: box-shadow .15s; }
.table tr.click:hover td:first-child { box-shadow: inset 3px 0 0 var(--accent); }
.table tr.alarm-row td { background: color-mix(in srgb, var(--err-soft) 70%, var(--surface)) !important; }
.table td.mono { font-family: var(--mono); font-size: 12.5px; }
.table .num { text-align: right; }
.table th.right, .table td.right { text-align: right; }
.table td.wrap { white-space: normal; min-width: 260px; }
.muted { color: var(--muted); }
.pad { padding: 14px; }
.table .strong { font-weight: 600; }
.table .sub { display: block; color: var(--muted); font-size: 11.5px; font-weight: 400; }
.table.compact td, .table.compact th { padding: 6px 12px; }
.table .empty-row td { text-align: center; color: var(--muted); padding: 36px; background: none !important; }
.op-pill { display: inline-flex; align-items: center; gap: 7px; font-weight: 600; }
.op-pill i { width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center; color: #fff; font-style: normal; font-size: 9px; font-weight: 700; }
.badge { display: inline-flex; align-items: center; gap: 5px; padding: 3px 10px; border-radius: 20px; font-size: 11.5px; font-weight: 650; white-space: nowrap; box-shadow: inset 0 0 0 1px color-mix(in srgb, currentColor 18%, transparent); }
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge.ok { background: var(--store-soft); color: var(--store); }
.badge.ko { background: var(--err-soft); color: var(--err); }
.badge.run { background: var(--dry-soft); color: var(--dry); }
.badge.wait { background: var(--warn-soft); color: var(--warn); }
.badge.free { background: var(--free-soft); color: var(--muted); }

/* diag */
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 0; margin: 0; font-size: 13px; }
.kv dt, .kv dd { padding: 7px 0; border-bottom: 1px solid var(--line); margin: 0; }
.kv dt { color: var(--muted); padding-right: 18px; }
.kv dd { font-weight: 500; word-break: break-word; }
.kv dt:last-of-type, .kv dd:last-of-type { border-bottom: 0; }
.code { margin: 0; white-space: pre-wrap; word-break: break-all; font: 12px/1.6 var(--mono); background: var(--side); color: #b9d7dc; padding: 14px 16px; border-radius: 9px; max-height: 300px; overflow: auto; }

.toast { position: fixed; right: 24px; bottom: 24px; z-index: 40; max-width: 380px; padding: 12px 16px; border-radius: 9px; background: var(--side); color: #fff; font-size: 13px; box-shadow: 0 10px 30px rgba(0,0,0,.2); opacity: 0; transform: translateY(8px); pointer-events: none; transition: .2s; }
.toast.show { opacity: 1; transform: none; }
.toast.err { background: var(--err); }

/* ============================================================ responsive */
@media (max-width: 1400px) { .kpis { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (max-width: 1200px) {
  .overview { grid-template-columns: 1fr; }
  .side-col { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 20px; margin-bottom: 20px; }
  .side-col .card { margin-bottom: 0; }
  .mem-mode { grid-template-columns: 1fr; }
  .mem-actions { flex-direction: row; }
}
@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: fixed; z-index: 30; left: 0; width: 260px; transform: translateX(-100%); transition: transform .2s; }
  .sidebar.open { transform: none; box-shadow: 0 0 40px rgba(0,0,0,.4); }
  .only-mobile { display: grid; }
  .topbar, .content { padding-left: 16px; padding-right: 16px; }
  .topbar { flex-wrap: wrap; row-gap: 10px; }
  .dev-tabs { order: 3; flex: 1 0 100%; }
  .sheet { border-top-right-radius: 22px; }
  .sidebar { background: var(--side); }
  .kpis { grid-template-columns: 1fr 1fr; }
  .grid-2, .radio-cards { grid-template-columns: 1fr; }
  .slots { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .timeline li { grid-template-columns: 22px minmax(0, 1fr); }
  .timeline .ts, .timeline .tx { grid-column: 2; padding: 0; }
}
@media (max-width: 520px) {
  .slots { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .clock-chip small { display: none; }
  .kpi .ic { display: none; }
  .top-right { gap: 6px; }
}

/* ============================================================
   Layout a schermo intero senza scroll (PC / monitor da parete)
   ============================================================ */
.pager { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding-top: 10px; font-size: 12.5px; color: var(--muted); }
.pager:empty { display: none; }
.pager .pg-btns { display: flex; gap: 6px; align-items: center; }
.pager button { height: 30px; min-width: 30px; padding: 0 10px; border: 1px solid var(--line-2); border-radius: 7px; background: var(--surface); color: var(--ink-2); font: inherit; font-size: 12.5px; cursor: pointer; }
.pager button:disabled { opacity: .4; cursor: default; }
.pager button:not(:disabled):hover { border-color: var(--accent); color: var(--accent); }
.table td { height: 41px; }
.table.compact td { height: 31px; }
.table-wrap.plain { border: 0; border-radius: 0; }

.env-card .acts { flex-direction: row; flex-wrap: wrap; gap: 6px; margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--line); }
.env-card .act { border: 1px solid var(--line); border-radius: 16px; padding: 3px 10px 3px 4px; gap: 7px; font-size: 12px; background: var(--surface-2); justify-content: flex-start; }
.env-card .act:first-child, .env-card .act:last-child { padding: 3px 10px 3px 4px; border: 1px solid var(--line); }
.env-card .act .onoff { padding: 1px 7px; font-size: 10px; }
.timeline.mini li { grid-template-columns: 22px 64px minmax(0, 1fr); padding: 7px 0; font-size: 12.5px; }
.timeline.mini .tx { overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.side-col { position: relative; }
.detail-close { width: 30px; height: 30px; border: 1px solid var(--line); border-radius: 7px; background: var(--surface); color: var(--muted); display: grid; place-items: center; cursor: pointer; flex: none; }
.detail-close svg { width: 15px; height: 15px; }
.diag { display: grid; grid-template-columns: 420px minmax(0, 1fr); gap: 20px; }
.diag-col .card:last-child { margin-bottom: 0; }

@media (min-width: 901px) {
  body { overflow: hidden; }
  .shell { height: 100vh; min-height: 0; }
  .main { height: 100vh; overflow: hidden; }
  .content { flex: 1; min-height: 0; display: flex; flex-direction: column; padding-top: 18px; padding-bottom: 18px; margin: 0 auto; }
  .view.active { flex: 1; min-height: 0; display: flex; flex-direction: column; gap: 16px; }
  .view .card, .kpis, .alerts, .grid-2, .op-summary { margin-bottom: 0; }

  /* panoramica */
  .alerts { flex: none; flex-direction: row; flex-wrap: nowrap; overflow: hidden; }
  .alert { flex: 0 1 auto; min-width: 0; padding: 8px 14px; white-space: nowrap; }
  .alert span { overflow: hidden; text-overflow: ellipsis; }
  .alert.more { flex: none; }
  .kpis { flex: none; gap: 14px; }
  .kpi { padding: 12px 16px; }
  .kpi .v { font-size: 23px; }
  .overview { flex: 1; min-height: 0; grid-template-rows: minmax(0, 1fr); gap: 16px; }
  .cabinet-card { height: 100%; display: flex; flex-direction: column; min-height: 0; padding: 16px 18px; }
  .cabinet-card .card-h { margin-bottom: 12px; }
  .cabinet { flex: 1; min-height: 0; display: flex; flex-direction: column; }
  .slots { flex: 1; min-height: 0; grid-auto-rows: minmax(0, 1fr); }
  .slot { min-height: 0; }
  .slot-art { min-height: 0; }
  .legend { margin-top: 10px; }
  .side-col { height: 100%; min-height: 0; display: flex; flex-direction: column; gap: 16px; }
  .env-card { flex: none; padding: 16px 18px; }
  .env-card .card-h { margin-bottom: 12px; }
  .activity { flex: 1; min-height: 0; overflow: hidden; display: flex; flex-direction: column; padding: 16px 18px; }
  .activity .card-h { margin-bottom: 6px; }
  .activity .timeline { overflow: hidden; }
  .detail { position: absolute; inset: 0; z-index: 3; margin: 0; overflow: hidden; display: flex; flex-direction: column; box-shadow: 0 12px 40px rgba(10, 20, 30, .18); animation: fade .15s ease-out; }
  .detail[hidden] { display: none; }

  /* viste con tabelle */
  .grow-card { flex: 1; min-height: 0; display: flex; flex-direction: column; }
  .fleet { flex: none; max-height: 34vh; overflow: auto; }
  .reports { flex: 1; min-height: 0; }
  .rep-form { overflow: auto; }
  .rep-view { min-height: 0; }
  .table-wrap { flex: 1; min-height: 0; max-height: none; overflow-x: auto; overflow-y: hidden; }
  .op-summary { flex: none; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); grid-auto-rows: auto; max-height: 150px; overflow: hidden; margin-bottom: 14px; }
  .op-card { padding: 11px 14px; }
  .filters, .note, .mem-mode { flex: none; }
  .filters { padding: 10px 12px; margin-bottom: 10px; }
  .note { margin-bottom: 10px; }

  /* diagnostica */
  .diag { flex: 1; min-height: 0; }
  .diag-col { display: flex; flex-direction: column; gap: 16px; min-height: 0; }
  .diag-col .card { margin: 0; }
  .raw-card { flex: none; }
  .raw-card .code { max-height: 170px; overflow: hidden; }
  .diag-col .grow { flex: 1; min-height: 0; display: flex; flex-direction: column; }
  .kv dt, .kv dd { padding: 6px 0; }
}
@media (min-width: 901px) and (max-width: 1200px) {
  .overview { grid-template-columns: minmax(0, 1fr) 300px; }
  .side-col { display: flex; }
  .kpis { grid-template-columns: repeat(5, minmax(0, 1fr)); }
  .kpi .ic { display: none; }
  .mem-mode { grid-template-columns: 150px minmax(0, 1fr); }
  .mem-actions { grid-column: 1 / -1; }
  .diag { grid-template-columns: 1fr 1fr; }
}
@media (min-width: 901px) and (max-width: 1400px) { .kpis { grid-template-columns: repeat(5, minmax(0, 1fr)); } }
@media (min-width: 901px) and (max-height: 820px) {
  .kpi .ic { display: none; }
  .kpi .bar { display: none; }
  .legend { display: none; }
  .sensor .spark { height: 18px; }
  .sensor, .sensor.wide { padding: 4px 10px; }
}
@media (max-width: 900px) { .diag { grid-template-columns: 1fr; } .detail { margin-top: 20px; } }

.detail { --c: var(--free); --s: var(--free-soft); }
.detail.ph1 { --c: var(--dry); --s: var(--dry-soft); }
.detail.ph2 { --c: var(--store); --s: var(--store-soft); }
.detail.ph3 { --c: var(--warn); --s: var(--warn-soft); }
.detail.ph4, .detail.ph5 { --c: var(--err); --s: var(--err-soft); }
.detail-h .status { margin: 4px 0 0 auto; }

/* sensori compatti su una riga (desktop) */
@media (min-width: 901px) {
  .sensors { grid-template-columns: 1fr; gap: 6px; }
  .sensor, .sensor.wide { grid-column: auto; display: grid; grid-template-columns: minmax(0, 1fr) auto 96px; align-items: center; gap: 10px; padding: 6px 10px; }
  .sensor .l { font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .sensor .v { font-size: 16px; line-height: 1.2; text-align: right; }
  .sensor .spark { height: 22px; margin: 0; }
  .sensor .range { display: none; }
  .env-card .acts { margin-top: 10px; padding-top: 10px; }
}

/* vani stretti: etichette adattate alla larghezza del vano */
.slot { container-type: inline-size; }
@container (max-width: 150px) {
  .slot .status { font-size: 10px; padding: 2px 6px; gap: 4px; }
  .slot .status::before { width: 5px; height: 5px; }
  .slot-id { font-size: 13px; }
}
@container (max-width: 96px) {
  .slot .status .t { display: none; }
  .slot .status { padding: 3px; }
  .slot-tr span { display: none; }
  .slot-tr { justify-content: flex-end; }
}

/* ---------- adattamento a schermi piccoli senza scroll ---------- */
@media (min-width: 901px) {
  .slot { container-type: size; }
  .side-col { overflow: hidden; }
  .activity { min-height: 90px; }
}
@container (max-height: 175px) { .slot .slot-art { flex: 1 1 0; margin: 4px -4px; } .slot .scope { height: 210%; } .slot .slot-m, .slot .slot-op { display: none; } .slot .slot-f { margin-top: 4px; padding-top: 4px; } }
@container (max-height: 104px) { .slot .slot-art { display: none; } .slot .slot-info { margin-top: auto; } }
@container (max-height: 92px) { .slot .meter { display: none; } }

/* barra laterale a sole icone sotto 1400px */
@media (min-width: 901px) and (max-width: 1400px) {
  .shell { grid-template-columns: 68px minmax(0, 1fr); }
  .sidebar { padding: 16px 10px; align-items: center; }
  .logo { padding: 2px 0 18px; }
  .logo > div, .side-ver, .conn-meta, .conn-row b { display: none; }
  .nav a { width: 46px; height: 42px; justify-content: center; padding: 0; font-size: 0; position: relative; }
  .nav a svg { width: 20px; height: 20px; }
  .nav .count { position: absolute; top: 3px; right: 1px; min-width: 16px; line-height: 16px; font-size: 10px; padding: 0 4px; }
  .conn-card { padding: 12px; display: grid; place-items: center; }
  .conn-row { gap: 0; }
  .conn-row .dot { width: 10px; height: 10px; }
  .content { padding-left: 20px; padding-right: 20px; }
  .topbar { padding-left: 16px; padding-right: 20px; gap: 14px; }
  .clock-chip small { display: none; }
  .dev-tab { padding-right: 12px; }
  .dev-tx small { max-width: 150px; overflow: hidden; text-overflow: ellipsis; }
}
@media (min-width: 901px) and (max-height: 760px) {
  .content { padding-top: 12px; padding-bottom: 12px; }
  .view.active { gap: 12px; }
  .kpi { padding: 8px 12px; }
  .kpi .v { font-size: 20px; }
  .kpi .s { display: none; }
  .topbar { padding-top: 8px; padding-bottom: 8px; }
  .crumbs small { display: none; }
  .cabinet-card, .env-card, .activity { padding: 12px 14px; }
  .cabinet-card .card-h, .env-card .card-h { margin-bottom: 8px; }
  .card-sub { display: none; }
  .alert { padding: 6px 12px; }
  .env-card .acts { margin-top: 8px; padding-top: 8px; }
}

/* righe a altezza fissa per la paginazione */
@media (min-width: 901px) {
  .timeline.full li { height: 41px; padding: 0; align-items: center; }
  .timeline.full .ts { padding-top: 0; }
  .timeline.full .tx { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
}
@media (min-width: 901px) and (max-height: 860px) {
  .note { display: none; }
  .filters { padding: 8px 10px; gap: 8px; }
  .field > span { display: none; }
  .op-summary { max-height: 62px; }
  .fleet { max-height: 150px; }
  .op-card { padding: 8px 12px; }
  .avatar { width: 32px; height: 32px; }
  .radio-cards small { display: none; }
  .radio-cards label { padding: 8px 10px; }
  .mem-pending { padding: 6px 12px; }
  .mem-pending b { font-size: 20px; }
  .mem-mode { margin-bottom: 10px; }
  .table td { height: 37px; padding-top: 0; padding-bottom: 0; }
  .table th { padding-top: 8px; padding-bottom: 8px; }
}

/* ============================================================
   Componenti aggiunti: lingua, menu armadi, live, cicli, report
   ============================================================ */
.lang-btn { height: 38px; display: inline-flex; align-items: center; gap: 6px; padding: 0 12px 0 10px; border: 1px solid var(--side-line); border-radius: 10px; background: rgba(255,255,255,.04); color: #fff; font: 700 12.5px var(--font); letter-spacing: .06em; cursor: pointer; transition: background .15s; }
.lang-btn:hover { background: rgba(255,255,255,.1); }
.lang-btn svg { width: 17px; height: 17px; color: #5fd3de; }

/* selettore armadi con menu a discesa (molti armadi) */
.dev-picker { min-width: 0; display: flex; }
.dev-drop-wrap { position: relative; }
.dev-drop { padding-right: 10px; }
.dev-drop > svg { width: 16px; height: 16px; color: #9fdce2; }
.dev-n { font: 600 11px var(--mono); color: #9fdce2; background: rgba(255,255,255,.08); padding: 2px 6px; border-radius: 6px; }
.dev-menu { position: absolute; top: calc(100% + 8px); left: 0; z-index: 50; width: 360px; max-height: 70vh; display: flex; flex-direction: column; background: var(--surface); color: var(--ink); border: 1px solid var(--line); border-radius: 14px; box-shadow: 0 24px 60px -12px rgba(8, 18, 30, .45); overflow: hidden; animation: fade .15s ease-out; }
.dev-menu-h { padding: 12px; border-bottom: 1px solid var(--line); display: flex; flex-direction: column; gap: 6px; }
.dev-menu-h input { width: 100%; }
.dev-menu-h small { color: var(--muted); font-size: 11.5px; }
.dev-menu-list { overflow: auto; padding: 6px; }
.dev-opt { width: 100%; display: flex; align-items: center; gap: 10px; padding: 9px 10px; border: 0; border-radius: 9px; background: none; font: inherit; color: inherit; text-align: left; cursor: pointer; }
.dev-opt:hover { background: var(--surface-2); }
.dev-opt.active { background: var(--accent-soft); box-shadow: inset 3px 0 0 var(--accent); }
.dev-opt .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--free); flex: none; }
.dev-opt.on .dot { background: var(--store); }
.dev-opt.off .dot { background: var(--err); }
.dev-opt .dev-tx { flex: 1; min-width: 0; }
.dev-opt .dev-tx b { color: var(--ink); }
.dev-opt .dev-tx small { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dev-opt .count { min-width: 20px; padding: 0 6px; border-radius: 10px; background: var(--err); color: #fff; font-size: 11.5px; font-weight: 600; text-align: center; line-height: 19px; }

/* timer di stoccaggio */
.cd { font-family: var(--mono); font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.cd.low { color: var(--err); }
.slot-cd { display: block; font-size: 13px; letter-spacing: -.02em; margin-top: 2px; }
.slot-exp { font-size: 10.5px; color: var(--muted); margin-top: 3px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.detail-tr .cd.big { font-size: 20px; }
.detail-tr > small { display: block; margin-top: 6px; font-size: 11px; }
.cd-cell { min-width: 150px; }
.cd-cell .cd { font-size: 13px; }
.meter.sm { height: 4px; margin-top: 4px; }
.meter.ph1 { --c: var(--dry); } .meter.ph2 { --c: var(--store); } .meter.ph3 { --c: var(--warn); } .meter.ph4, .meter.ph5 { --c: var(--err); }
.cab-cell { display: inline-flex; align-items: center; gap: 8px; }
.cab-cell .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--free); }
.cab-cell .dot.on { background: var(--store); }
.cab-cell .dot.off { background: var(--err); }
@container (max-height: 215px) { .slot .slot-exp { display: none; } }

/* live: flotta di armadi */
.fleet { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 12px; margin-bottom: 20px; }
.fleet-card { display: flex; flex-direction: column; gap: 6px; padding: 12px 14px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow); font: inherit; color: inherit; text-align: left; cursor: pointer; transition: transform .15s, box-shadow .15s, border-color .15s; }
.fleet-card:hover { transform: translateY(-2px); border-color: color-mix(in srgb, var(--accent) 40%, var(--line)); }
.fleet-card.active { border-color: var(--accent); box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 25%, transparent); }
.fc-h { display: flex; align-items: center; gap: 8px; }
.fc-h b { font-size: 14px; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fc-h .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--free); }
.fleet-card.on .fc-h .dot { background: var(--store); box-shadow: 0 0 0 3px color-mix(in srgb, var(--store) 20%, transparent); }
.fleet-card.off .fc-h .dot { background: var(--err); animation: blink 1.2s infinite; }
.fc-h .count { min-width: 20px; padding: 0 6px; border-radius: 10px; background: var(--err); color: #fff; font-size: 11px; font-weight: 700; line-height: 19px; text-align: center; }
.fleet-card small { color: var(--muted); font-size: 11.5px; }
.fc-grid { display: grid; grid-template-columns: repeat(var(--n), 1fr); gap: 3px; padding: 5px; border-radius: 7px; background: var(--cab-inner); }
.fc-grid i { height: 14px; border-radius: 3px; background: color-mix(in srgb, var(--free) 35%, var(--cab-frame)); }
.fc-grid i.ph1 { background: var(--dry); box-shadow: 0 0 6px var(--dry); }
.fc-grid i.ph2 { background: var(--store); box-shadow: 0 0 6px var(--store); }
.fc-grid i.ph3 { background: var(--warn); box-shadow: 0 0 6px var(--warn); }
.fc-grid i.ph4, .fc-grid i.ph5 { background: var(--err); box-shadow: 0 0 6px var(--err); animation: blink 1.2s infinite; }
.fc-stats { display: flex; gap: 12px; font-size: 12px; color: var(--muted); }
.fc-stats b { color: var(--ink); font-size: 15px; }
.fc-stats .dry { color: var(--dry); } .fc-stats .sto { color: var(--store); }
.live-pill { display: inline-flex; align-items: center; gap: 7px; padding: 4px 12px; border-radius: 20px; background: var(--err-soft); color: var(--err); font-size: 12px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; }
.live-pill i { width: 8px; height: 8px; border-radius: 50%; background: currentColor; animation: blink 1.2s infinite; }

/* filtri e mini KPI */
.field.narrow input { width: 80px; min-width: 0; }
.field.inline { flex-direction: row; align-items: center; gap: 8px; }
input[type=number], input[type=week] { height: 36px; font: inherit; font-size: 13px; color: var(--ink); background: var(--surface); border: 1px solid var(--line-2); border-radius: 8px; padding: 0 10px; }
.mini-kpis { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 12px; flex: none; }
.mk { display: flex; align-items: baseline; gap: 8px; padding: 7px 14px; border-radius: 10px; background: color-mix(in srgb, var(--c) 9%, var(--surface)); box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--c) 22%, transparent); }
.mk b { font-size: 18px; color: var(--c); letter-spacing: -.02em; }
.mk span { font-size: 12px; color: var(--muted); }
.btn.sm { height: 28px; font-size: 12px; }
.btn.disabled { opacity: .5; pointer-events: none; }
a.op-card { text-decoration: none; }
.ev-type { display: inline-flex; align-items: center; gap: 6px; font-weight: 600; font-size: 12.5px; color: var(--accent); }
.ev-type svg { width: 14px; height: 14px; }
.ev-type.error { color: var(--err); } .ev-type.warn { color: var(--warn); } .ev-type.load { color: var(--store); } .ev-type.unload { color: var(--dry); }

/* pannello laterale dettaglio ciclo */
.drawer-back { position: fixed; inset: 0; z-index: 60; background: rgba(6, 12, 20, .45); backdrop-filter: blur(2px); animation: fade .2s; }
.drawer { position: fixed; top: 0; right: 0; bottom: 0; z-index: 61; width: min(760px, 100vw); display: flex; flex-direction: column; background: var(--bg); box-shadow: -20px 0 60px rgba(6, 12, 20, .35); transform: translateX(100%); transition: transform .22s ease; }
.drawer.open { transform: none; }
.drawer-h { display: flex; justify-content: space-between; gap: 16px; padding: 20px 24px; background: var(--side); color: #fff; }
.drawer-h small { color: #9fdce2; font-size: 12px; }
.drawer-h h3 { font-size: 22px; margin: 2px 0; }
.drawer-h .muted { color: var(--side-muted); font-size: 13px; }
.drawer-hr { display: flex; align-items: flex-start; gap: 10px; }
.drawer-h .detail-close { background: rgba(255,255,255,.06); border-color: var(--side-line); color: #fff; }
.drawer-body { flex: 1; overflow: auto; padding: 20px 24px 30px; display: flex; flex-direction: column; gap: 18px; }
.drawer-body section { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.drawer-body h4 { margin: 0 0 10px; font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--accent); }
.dgrid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.table.env td { height: auto; }
.chart { margin-top: 6px; }
.chart svg { width: 100%; height: auto; display: block; }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .ax { font: 10px var(--font); fill: var(--muted); }
.chart .ax.r { fill: var(--dry); }
.chart polyline { fill: none; stroke-width: 2; vector-effect: non-scaling-stroke; stroke-linejoin: round; }
.chart polyline.dash { stroke-dasharray: 5 3; }
.chart-legend { display: flex; flex-wrap: wrap; gap: 14px; font-size: 12px; color: var(--ink-2); margin-top: 6px; }
.chart-legend i { display: inline-block; width: 14px; height: 3px; border-radius: 2px; margin-right: 6px; vertical-align: middle; }
.chart-empty { padding: 24px; text-align: center; color: var(--muted); background: var(--surface-2); border-radius: 8px; }

/* report */
.reports { display: grid; grid-template-columns: 360px minmax(0, 1fr); gap: 20px; }
.rep-form { display: flex; flex-direction: column; gap: 14px; margin: 0; }
.rep-form .card-h { margin-bottom: 0; }
.rep-field { display: flex; flex-direction: column; gap: 6px; }
.rep-field.two { flex-direction: row; gap: 10px; }
.rep-field.two label { flex: 1; display: flex; flex-direction: column; gap: 6px; }
.rep-field input, .rep-field select { width: 100%; min-width: 0; }
.lbl { font-size: 11.5px; font-weight: 650; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.seg.wide { display: flex; }
.seg.wide button { flex: 1; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { height: 28px; padding: 0 11px; border-radius: 14px; border: 1px solid var(--line-2); background: var(--surface); color: var(--ink-2); font: inherit; font-size: 12px; cursor: pointer; }
.chip:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }
.rep-period { display: flex; align-items: center; gap: 8px; padding: 10px 12px; border-radius: 10px; background: var(--accent-soft); color: var(--accent); font-weight: 600; font-size: 13px; }
.rep-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: auto; }
.rep-view { position: relative; margin: 0; padding: 0; overflow: hidden; display: flex; background: var(--cab-inner); border-color: var(--cab-frame); min-height: 520px; }
.rep-view iframe { flex: 1; width: 100%; border: 0; background: #525659; }
.rep-empty, .rep-loading { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; color: #9fb2c6; text-align: center; padding: 30px; }
.rep-empty svg { width: 56px; height: 56px; color: #3a5068; stroke-width: 1.3; }
.rep-empty b { color: #e5ecf3; font-size: 16px; }
.spinner { width: 34px; height: 34px; border-radius: 50%; border: 3px solid rgba(255,255,255,.15); border-top-color: #5fd3de; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
[hidden] { display: none !important; }

/* diagnostica: memorie */
.mem-pending { margin-bottom: 12px; }
.radio-cards { grid-template-columns: 1fr; margin-bottom: 12px; }
.mem-actions { flex-direction: row; flex-wrap: wrap; justify-content: flex-start; }

@media (max-width: 1200px) { .reports { grid-template-columns: 1fr; } .rep-view { min-height: 70vh; } }
@media (max-width: 900px) {
  .dgrid { grid-template-columns: 1fr; }
  .dev-picker { order: 3; flex: 1 0 100%; }
  .dev-menu { width: min(360px, calc(100vw - 32px)); }
  .lang-btn span { display: none; }
}
@media (min-width: 901px) and (max-width: 1400px) { .lang-btn { padding: 0 10px; } }
.drawer .kv { grid-template-columns: minmax(120px, auto) 1fr; }
.drawer .kv dd { text-align: right; }
.op-card > div:nth-child(2) { min-width: 0; flex: 1; }
.op-card small { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ============================================================
   Spiegazioni: allarmi ed eventi cliccabili
   ============================================================ */

/* L'allarme e' un pulsante, non piu' un riquadro muto: deve sembrarlo.
   Il "Perche'?" resta a destra, cosi' si capisce che c'e' altro da leggere. */
.alert { width: 100%; text-align: left; font-family: inherit; cursor: default; }
button.alert { cursor: pointer; transition: background .12s, border-color .12s, transform .06s; }
button.alert:hover { filter: brightness(.985); border-color: currentColor; }
button.alert:active { transform: translateY(1px); }
button.alert:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.alert svg { width: 17px; height: 17px; flex: none; }
.alert > span:not(.alert-why) { flex: 1; min-width: 0; }
.alert-why { flex: none; font-size: 12px; font-weight: 600; opacity: .75; text-decoration: underline;
  text-underline-offset: 3px; white-space: nowrap; }
.alert.more { cursor: default; }

/* Righe di registro cliccabili: la freccia compare all'avvicinarsi del mouse,
   per non riempire di frecce una colonna di quaranta righe. */
/* La freccia e' fuori dal flusso: la timeline ha tre griglie diverse (piena,
   mini, stretta) e aggiungere una colonna le romperebbe tutte e tre. */
.timeline li.click { cursor: pointer; position: relative; border-radius: 7px;
  padding-left: 6px; padding-right: 20px; margin-left: -6px; margin-right: -6px; }
.timeline li.click:hover { background: var(--surface-2); }
.timeline li.click:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.timeline .ev-go { position: absolute; right: 4px; top: 50%; transform: translateY(-50%);
  width: 14px; height: 14px; color: var(--muted); opacity: 0; transition: opacity .12s; }
.timeline .ev-go svg { width: 14px; height: 14px; transform: rotate(-90deg); }
.timeline li.click:hover .ev-go, .timeline li.click:focus-visible .ev-go { opacity: 1; }

/* Una spiegazione. La targhetta della provenienza e' la parte importante:
   dice se quel testo viene dal protocollo, dal monitor o dalla prassi. */
.spiega { border: 1px solid var(--line); border-left: 3px solid var(--accent); border-radius: 8px;
  padding: 11px 13px; margin-bottom: 10px; background: var(--surface-2); }
.spiega:last-child { margin-bottom: 0; }
.spiega.generica { border-left-color: var(--warn); }
.sp-h { display: flex; align-items: baseline; gap: 10px; justify-content: space-between; margin-bottom: 6px; }
.sp-h b { font-size: 14px; color: var(--ink); }
.spiega p { margin: 0 0 6px; font-size: 13px; line-height: 1.55; color: var(--ink-2); }
.spiega p:last-child { margin-bottom: 0; }
.spiega .azione { color: var(--ink); }
.spiega .azione b { color: var(--accent); }
.spiega .nota { font-size: 12px; color: var(--muted); border-top: 1px dashed var(--line-2); padding-top: 6px; }
.src { flex: none; font-size: 10.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em;
  padding: 2px 7px; border-radius: 20px; background: var(--free-soft); color: var(--muted); }
.src.src-proto { background: var(--store-soft); color: var(--store); }
.src.src-mon { background: var(--accent-soft); color: var(--accent); }
.src.src-loc { background: var(--dry-soft); color: var(--dry); }
.src.src-prassi { background: var(--warn-soft); color: var(--warn); }

/* Sensori e attuatori del momento, in fila */
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.chip { display: inline-flex; align-items: baseline; gap: 6px; font-size: 12.5px; font-weight: 600;
  padding: 4px 9px; border-radius: 20px; background: var(--surface-2); border: 1px solid var(--line); }
.chip i { font-style: normal; font-weight: 500; color: var(--muted); font-size: 11.5px; }
.chip.on { background: var(--store-soft); border-color: color-mix(in srgb, var(--store) 25%, transparent); color: var(--store); }

/* "Che cosa significa?" nel dettaglio del vano */
.why-btn { display: inline-flex; align-items: center; gap: 7px; margin-top: 12px; width: 100%;
  justify-content: center; padding: 9px 12px; border-radius: 8px; cursor: pointer; font-family: inherit;
  font-size: 13px; font-weight: 600; color: var(--accent); background: var(--accent-soft);
  border: 1px solid color-mix(in srgb, var(--accent) 22%, transparent); }
.why-btn:hover { background: color-mix(in srgb, var(--accent) 14%, var(--surface)); }
.why-btn svg { width: 15px; height: 15px; }

button.link { border: 0; background: none; padding: 0; cursor: pointer; color: var(--accent);
  font-family: inherit; font-size: 13px; font-weight: 600; text-decoration: underline; text-underline-offset: 3px; }

pre.raw { margin: 4px 0 0; padding: 9px 11px; background: var(--side); color: #b9d7dc; border-radius: 7px;
  font-family: var(--mono); font-size: 11.5px; line-height: 1.5; white-space: pre-wrap; word-break: break-all;
  max-height: 220px; overflow: auto; }

@media (max-width: 700px) {
  .alert-why { display: none; }
}

/* Pastiglia di stato ciclo cliccabile: stesso aspetto della pastiglia normale,
   con il segno che c'e' qualcosa da leggere sotto. */
button.badge.why { font-family: inherit; cursor: pointer; border: 0;
  text-decoration: underline dotted; text-underline-offset: 2px; }
button.badge.why:hover { filter: brightness(.95); text-decoration-style: solid; }
button.badge.why:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
