/*
 * Customer Console — tema chiaro "pannello industriale".
 * Portato da ../plc_console.jsx (prototipo React) a CSS puro: stesse scelte visive
 * (rack LED su fondo scuro, KPI, striscia piattaforme, tabella, slide-over, modale),
 * zero dipendenze: nessun framework, nessun CDN, font self-hostati (vedi fonts.css).
 *
 * NB: l'App cliente usa theme.css (tema scuro white-label). Questo file è SOLO per la
 * Console del proprietario: i due frontend non condividono la palette apposta.
 */

:root {
  --bg: #E7EAEE;
  --panel: #FFFFFF;
  --panel2: #F4F6F8;
  --ink: #171A1F;
  --muted: #616B76;
  --faint: #8A94A0;
  --line: #D5DAE0;
  --line2: #E4E8EC;
  --blue: #2557D6;
  --blue-ink: #1B3E96;
  --green: #1F9D57;
  --amber: #DE8C08;
  --red: #D23B3B;
  --led-off: #C3C9D0;
  --siemens: #0F8C8C;
  --rockwell: #6B4FC4;
  --beckhoff: #4A6785;
  --display: 'Space Grotesk', system-ui, sans-serif;
  --mono: 'IBM Plex Mono', ui-monospace, Menlo, monospace;
  --sans: 'IBM Plex Sans', system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--sans);
  color: var(--ink);
  background: var(--bg);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

/* le safe-area coprono notch e barra home quando l'app gira installata a schermo intero
   su iOS (display: standalone nel manifest); su desktop valgono 0 e non cambiano nulla */
.wrap {
  max-width: 1180px;
  margin: 0 auto;
  padding: calc(22px + env(safe-area-inset-top)) calc(22px + env(safe-area-inset-right))
           calc(60px + env(safe-area-inset-bottom)) calc(22px + env(safe-area-inset-left));
}

/* ---------- top bar ---------- */
.top { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding-bottom: 18px; }
.brand { display: flex; align-items: center; gap: 12px; }
.logo {
  width: 34px; height: 34px; border-radius: 8px;
  background: linear-gradient(135deg, #1E232B 0%, #0B0D10 100%);
  display: grid; place-items: center;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.08), 0 0 10px -2px rgba(31,157,87,.45);
}
.brand h1 { font-family: var(--display); font-size: 16px; font-weight: 600; margin: 0; letter-spacing: -.01em; }
.brand p { font-family: var(--mono); font-size: 10.5px; color: var(--faint); margin: 2px 0 0; text-transform: uppercase; letter-spacing: .12em; }

.btn {
  font-family: var(--sans); font-weight: 600; font-size: 13.5px; border: none; cursor: pointer;
  background: var(--blue); color: #fff; padding: 10px 16px; border-radius: 8px;
  display: inline-flex; align-items: center; gap: 8px; box-shadow: 0 1px 2px rgba(37,87,214,.35);
}
.btn:hover { background: var(--blue-ink); }
.btn:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-ghost { background: var(--panel); color: var(--ink); box-shadow: inset 0 0 0 1px var(--line); }
.btn-ghost:hover { background: var(--panel2); }
.btn-sm { padding: 6px 11px; font-size: 12px; }

/* ---------- signal rack ---------- */
.rack {
  background: var(--ink); border-radius: 12px; padding: 14px 16px; margin-bottom: 14px;
  box-shadow: 0 1px 0 rgba(255,255,255,.04) inset, 0 6px 20px -12px rgba(0,0,0,.5);
}
.rack-hd { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 11px; gap: 12px; }
.rack-hd b { font-family: var(--mono); font-size: 10.5px; color: #AEB7C2; font-weight: 500; text-transform: uppercase; letter-spacing: .14em; }
.rack-hd em { font-family: var(--mono); font-size: 11px; color: #7E8894; font-style: normal; }
.leds { display: flex; gap: 6px; flex-wrap: wrap; }
.led-cell {
  flex: 1 1 46px; min-width: 46px; height: 40px; border-radius: 6px; background: #20252C;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.05);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 5px;
  cursor: pointer; transition: background .12s; border: none;
}
.led-cell:hover { background: #2A313A; }
.led { width: 9px; height: 9px; border-radius: 50%; background: var(--led-off); display: inline-block; }
.led-cell small { font-family: var(--mono); font-size: 8.5px; color: #8A94A0; max-width: 42px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.led-running { background: var(--green); box-shadow: 0 0 7px 1px rgba(31,157,87,.7); }
.led-warning { background: var(--amber); box-shadow: 0 0 7px 1px rgba(222,140,8,.7); }
.led-fault { background: var(--red); box-shadow: 0 0 7px 1px rgba(210,59,59,.75); animation: blink 1.1s steps(1) infinite; }
.led-provisioning { background: var(--blue); box-shadow: 0 0 7px 1px rgba(37,87,214,.7); animation: pulse 1.4s ease-in-out infinite; }
@keyframes blink { 50% { opacity: .25; } }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: .4; } }

/* ---------- KPI ---------- */
.kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 14px; }
.kpi { background: var(--panel); border-radius: 11px; padding: 15px 16px; box-shadow: inset 0 0 0 1px var(--line2); }
.kpi label { font-family: var(--mono); font-size: 10px; color: var(--faint); text-transform: uppercase; letter-spacing: .11em; display: block; margin-bottom: 9px; }
.kpi .v { font-family: var(--mono); font-size: 26px; font-weight: 600; letter-spacing: -.02em; line-height: 1; }
.kpi .v small { font-size: 14px; color: var(--muted); font-weight: 500; }
.kpi .sub { font-family: var(--mono); font-size: 11px; color: var(--muted); margin-top: 7px; }
.kpi .sub b { color: var(--green); font-weight: 600; }
.kpi .sub b.neg { color: var(--red); }

/* ---------- platform strip ---------- */
.strip { background: var(--panel); border-radius: 11px; padding: 14px 16px; margin-bottom: 18px; box-shadow: inset 0 0 0 1px var(--line2); }
.strip label { font-family: var(--mono); font-size: 10px; color: var(--faint); text-transform: uppercase; letter-spacing: .11em; display: block; margin-bottom: 10px; }
.pbar { display: flex; height: 12px; border-radius: 6px; overflow: hidden; background: var(--panel2); }
.pseg { height: 100%; }
.legend { display: flex; gap: 18px; margin-top: 11px; flex-wrap: wrap; }
.legend span { font-family: var(--mono); font-size: 11px; color: var(--muted); display: flex; align-items: center; gap: 7px; }
.legend i { width: 9px; height: 9px; border-radius: 2px; display: inline-block; }
.legend b { color: var(--ink); font-weight: 600; }

/* ---------- table ---------- */
.table { background: var(--panel); border-radius: 12px; box-shadow: inset 0 0 0 1px var(--line2); overflow: hidden; }
.thead, .row { display: grid; grid-template-columns: 26px 1.7fr .8fr .7fr .8fr .8fr .8fr .6fr; gap: 10px; align-items: center; }
.thead { padding: 12px 18px; border-bottom: 1px solid var(--line2); }
.thead span { font-family: var(--mono); font-size: 9.5px; color: var(--faint); text-transform: uppercase; letter-spacing: .1em; }
.ta-r { text-align: right; }
.row { padding: 13px 18px; cursor: pointer; border-bottom: 1px solid var(--line2); transition: background .1s; background: none; border-left: none; border-right: none; border-top: none; width: 100%; text-align: left; font: inherit; color: inherit; }
.row:last-child { border-bottom: none; }
.row:hover { background: var(--panel2); }
.row.sel { background: #EFF3FF; box-shadow: inset 2px 0 0 var(--blue); }
.cust b { font-family: var(--sans); font-weight: 600; font-size: 13.5px; display: block; }
.cust small { font-family: var(--mono); font-size: 10px; color: var(--faint); }
.plan { font-family: var(--mono); font-size: 10.5px; padding: 3px 8px; border-radius: 5px; background: var(--panel2); color: var(--muted); box-shadow: inset 0 0 0 1px var(--line2); display: inline-block; }
.num { font-family: var(--mono); font-size: 13px; text-align: right; }
.num.pos { color: var(--green); font-weight: 600; }
.num.neg { color: var(--red); font-weight: 600; }
.err { font-family: var(--mono); font-size: 12px; text-align: right; font-weight: 600; }
.err.zero { color: var(--faint); font-weight: 400; }
.err.some { color: var(--amber); }
.err.many { color: var(--red); }
.dot-cell { display: flex; align-items: center; justify-content: center; }
.dot { width: 10px; height: 10px; border-radius: 50%; }

.foot { font-family: var(--mono); font-size: 10.5px; color: var(--faint); margin-top: 14px; text-align: center; }
.empty-state { padding: 40px 18px; text-align: center; color: var(--muted); font-size: 13px; }

/* ---------- slide-over ---------- */
.scrim { position: fixed; inset: 0; background: rgba(15,18,22,.34); z-index: 40; animation: fade .16s ease; border: none; }
@keyframes fade { from { opacity: 0; } }
.over {
  position: fixed; top: 0; right: 0; height: 100%; width: 460px; max-width: 94vw; z-index: 41;
  background: var(--bg); box-shadow: -14px 0 40px -18px rgba(0,0,0,.4); overflow-y: auto;
  animation: slide .22s cubic-bezier(.2,.7,.2,1); padding: 22px;
}
@keyframes slide { from { transform: translateX(24px); opacity: .4; } }
.over-hd { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 20px; gap: 12px; }
.over-hd h2 { font-family: var(--display); font-size: 19px; margin: 0 0 6px; letter-spacing: -.01em; }
.status-pill { display: inline-flex; align-items: center; gap: 7px; font-family: var(--mono); font-size: 11px; padding: 4px 10px; border-radius: 20px; background: var(--panel); box-shadow: inset 0 0 0 1px var(--line); }
.x { border: none; background: var(--panel); width: 32px; height: 32px; border-radius: 8px; cursor: pointer; color: var(--muted); font-size: 17px; box-shadow: inset 0 0 0 1px var(--line); flex: 0 0 auto; }
.x:hover { background: var(--panel2); color: var(--ink); }
.card { background: var(--panel); border-radius: 11px; padding: 15px 16px; box-shadow: inset 0 0 0 1px var(--line2); margin-bottom: 12px; }
.card h3 { font-family: var(--mono); font-size: 10px; color: var(--faint); text-transform: uppercase; letter-spacing: .11em; margin: 0 0 12px; font-weight: 500; }
.mgrid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px 12px; }
.metric label { font-family: var(--mono); font-size: 10px; color: var(--faint); display: block; margin-bottom: 4px; }
.metric .m { font-family: var(--mono); font-size: 19px; font-weight: 600; letter-spacing: -.01em; }
.metric .m small { font-size: 12px; color: var(--muted); font-weight: 400; }
.metric .m.green { color: var(--green); }
.metric .m.red { color: var(--red); }

.prow { display: flex; align-items: center; gap: 10px; margin-bottom: 9px; }
.prow:last-child { margin-bottom: 0; }
.prow b { font-family: var(--mono); font-size: 11.5px; width: 74px; font-weight: 500; }
.prow .track { flex: 1; height: 8px; background: var(--panel2); border-radius: 5px; overflow: hidden; }
.prow .fill { height: 100%; border-radius: 5px; }
.prow em { font-family: var(--mono); font-size: 12px; font-style: normal; color: var(--ink); width: 26px; text-align: right; }

.rec { display: flex; gap: 10px; align-items: baseline; padding: 9px 0; border-bottom: 1px solid var(--line2); }
.rec:last-child { border-bottom: none; }
.rec time { font-family: var(--mono); font-size: 10.5px; color: var(--faint); flex: 0 0 auto; width: 84px; }
.rec .what { flex: 1; font-size: 12.5px; line-height: 1.35; }
.rec .what small { display: block; font-family: var(--mono); font-size: 10px; color: var(--faint); }
.pbadge { font-family: var(--mono); font-size: 9px; padding: 2px 6px; border-radius: 4px; color: #fff; text-transform: uppercase; letter-spacing: .04em; flex: 0 0 auto; }
.errline { display: flex; gap: 10px; align-items: baseline; padding: 9px 0; border-bottom: 1px solid var(--line2); font-size: 12.5px; }
.errline:last-child { border-bottom: none; }
.errline time { font-family: var(--mono); font-size: 10.5px; color: var(--faint); flex: 0 0 auto; }
.ok-empty { font-family: var(--mono); font-size: 12px; color: var(--green); padding: 6px 0; }
.muted-empty { font-family: var(--mono); font-size: 12px; color: var(--muted); padding: 6px 0; }

/* sparkline SVG (sostituisce recharts del prototipo: nessuna libreria) */
.spark { width: 100%; height: 96px; display: block; overflow: visible; }
.spark-note { font-family: var(--mono); font-size: 10px; color: var(--faint); margin-top: 6px; }

/* ---------- modal ---------- */
.modal { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; padding: 20px; background: rgba(15,18,22,.4); animation: fade .16s ease; overflow-y: auto; }
.dialog { background: var(--bg); border-radius: 14px; width: 460px; max-width: 100%; padding: 24px; box-shadow: 0 24px 60px -20px rgba(0,0,0,.5); animation: pop .2s cubic-bezier(.2,.7,.2,1); }
@keyframes pop { from { transform: scale(.97); opacity: .5; } }
.dialog h2 { font-family: var(--display); font-size: 19px; margin: 0 0 4px; }
.dialog .lead { font-size: 13px; color: var(--muted); margin: 0 0 20px; }
.field { margin-bottom: 15px; }
.field label { font-family: var(--mono); font-size: 10.5px; color: var(--muted); text-transform: uppercase; letter-spacing: .09em; display: block; margin-bottom: 7px; }
.input { width: 100%; font-family: var(--sans); font-size: 14px; padding: 10px 12px; border-radius: 8px; border: none; background: var(--panel); box-shadow: inset 0 0 0 1px var(--line); color: var(--ink); }
.input:focus { outline: none; box-shadow: inset 0 0 0 2px var(--blue); }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.seg { display: flex; gap: 6px; }
.seg button { flex: 1; font-family: var(--sans); font-size: 12.5px; font-weight: 500; padding: 9px 6px; border: none; border-radius: 8px; cursor: pointer; background: var(--panel); box-shadow: inset 0 0 0 1px var(--line); color: var(--muted); }
.seg button.on { background: var(--ink); color: #fff; box-shadow: none; }
.iso-note { font-family: var(--sans); font-size: 11.5px; color: var(--muted); margin-top: 7px; line-height: 1.5; }
.iso-note b { color: var(--ink); }
.check { display: flex; align-items: flex-start; gap: 9px; font-size: 13px; color: var(--ink); }
.check input { margin-top: 2px; }
.check span small { display: block; color: var(--muted); font-size: 11.5px; margin-top: 2px; line-height: 1.45; }
.actions { display: flex; gap: 10px; margin-top: 22px; }
.actions .btn { flex: 1; justify-content: center; }

.error-box { background: rgba(210,59,59,.08); box-shadow: inset 0 0 0 1px var(--red); color: #8E2020; padding: 10px 12px; border-radius: 8px; font-size: 12.5px; margin: 10px 0; }
.hint-box { background: rgba(37,87,214,.06); box-shadow: inset 0 0 0 1px var(--blue); padding: 10px 12px; border-radius: 8px; font-size: 12.5px; margin: 10px 0; }
.hint-box a { color: var(--blue-ink); }

/* login */
.login { max-width: 420px; margin: 90px auto; }
.login .card { padding: 24px; }
.login h1 { font-family: var(--display); font-size: 20px; margin: 0 0 6px; }
.login p.lead { font-size: 13px; color: var(--muted); margin: 0 0 18px; }

.spinner { display: inline-block; width: 12px; height: 12px; border: 2px solid var(--line); border-top-color: var(--blue); border-radius: 50%; animation: spin .7s linear infinite; vertical-align: middle; }
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 760px) {
  .kpis { grid-template-columns: 1fr 1fr; }
  .thead { display: none; }
  .row { grid-template-columns: 22px 1fr auto; row-gap: 4px; padding: 14px 16px; }
  .row .m-hide { display: none; }
  .over { width: 100%; }
}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; } }
