/* =========================================================
   WTG Remote Control \2013  Elmi S.r.l.
   Foglio di stile unico (sostituisce style, wtg, led, toastr,
   meteo, ctrlpanel, login, normalize, setup)
   ========================================================= */

:root {
  --bg: #0d1117;
  --bg-2: #111722;
  --card: #161d29;
  --card-2: #1c2433;
  --line: #34425a;
  --bc: #38bdf8;          /* colore bordo riquadri */
  --text: #ffffff;
  --muted: #c3cedd;
  --faint: #9aa7ba;

  --accent: #38bdf8;     /* vento / blu */
  --power: #f97316;      /* potenza / arancio */
  --ok: #22c55e;
  --warn: #facc15;
  --alarm: #ef4444;
  --off: #475569;

  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 1px 0 rgba(255,255,255,.03) inset, 0 8px 24px rgba(0,0,0,.25);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", Consolas, "Roboto Mono", monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: radial-gradient(1200px 600px at 10% -10%, #15243a 0%, transparent 60%), var(--bg);
  background-attachment: fixed;
  color: var(--text);
  font: 14px/1.45 var(--font);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); }
h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: -.01em; }
.num { font-family: var(--mono); font-variant-numeric: tabular-nums; }

/* ---------- Header / navigazione ---------- */
.topbar {
  position: sticky; top: 0; z-index: 50;
  background: rgba(13,17,23,.85);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.topbar__inner {
  max-width: 1400px; margin: 0 auto;
  display: flex; align-items: center; gap: 20px;
  padding: 10px 20px;
}
.brand { display: flex; align-items: center; gap: 12px; text-decoration: none; color: var(--text); min-width: 0; }
.brand__logo {
  width: 38px; height: 38px; border-radius: 10px;
  background: var(--card-2); border: 1px solid var(--line);
  display: grid; place-items: center; flex: none;
}
.brand__logo img { width: 28px; height: 28px; object-fit: contain; }
.brand__text { display: flex; flex-direction: column; min-width: 0; }
.brand__title { font-weight: 650; font-size: 15px; white-space: nowrap; }
.brand__sub { color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.nav { display: flex; gap: 4px; margin-left: 12px; }
.nav a {
  color: var(--muted); text-decoration: none;
  padding: 8px 14px; border-radius: 8px; font-weight: 500;
  transition: background .15s, color .15s;
}
.nav a:hover { background: var(--card-2); color: var(--text); }
.nav a[aria-current="page"] { background: var(--card-2); color: var(--text); box-shadow: inset 0 -2px 0 var(--accent); }

.topbar__right { margin-left: auto; display: flex; align-items: center; gap: 14px; }
.clock { color: var(--muted); font-family: var(--mono); font-size: 13px; }
.conn {
  display: inline-flex; align-items: center; gap: 7px;
  font-size: 12px; font-weight: 600; padding: 5px 10px;
  border-radius: 999px; border: 1px solid var(--line); background: var(--card);
  color: var(--muted);
}
.conn::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--off); }
.conn.is-online { color: var(--ok); }
.conn.is-online::before { background: var(--ok); box-shadow: 0 0 0 3px rgba(34,197,94,.18); }
.conn.is-offline { color: var(--alarm); }
.conn.is-offline::before { background: var(--alarm); animation: blink 1s steps(2) infinite; }

.menu-btn {
  display: none; margin-left: auto;
  background: var(--card); border: 1px solid var(--line); color: var(--text);
  border-radius: 8px; width: 40px; height: 40px; cursor: pointer;
}
.menu-btn span, .menu-btn span::before, .menu-btn span::after {
  display: block; width: 18px; height: 2px; background: currentColor; margin: 0 auto; position: relative; content: "";
}
.menu-btn span::before { position: absolute; top: -6px; }
.menu-btn span::after { position: absolute; top: 6px; }

/* ---------- Layout ---------- */
main { flex: 1; width: 100%; max-width: 1400px; margin: 0 auto; padding: 20px; }
.page-head { display: flex; align-items: end; justify-content: space-between; gap: 16px; margin: 4px 0 18px; flex-wrap: wrap; }
.page-head h1 { font-size: 22px; }
.page-head p { margin: 2px 0 0; color: var(--muted); }

.grid { display: grid; gap: 16px; }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-main { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); }
.mt { margin-top: 16px; }

.card {
  background: linear-gradient(180deg, var(--card-2), var(--card));
  border: 1.5px solid var(--bc);
  box-shadow: 0 0 0 1px rgba(0,0,0,.2), 0 0 14px color-mix(in srgb, var(--bc) 35%, transparent), 0 8px 24px rgba(0,0,0,.25) !important;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px 18px;
  min-width: 0;
}
.card__head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; }
.card__title { font-size: 13px; font-weight: 700; color: var(--bc); text-transform: uppercase; letter-spacing: .06em; }

/* ---------- Status chips ---------- */
.status-strip { display: grid; grid-template-columns: repeat(5, minmax(0,1fr)); gap: 12px; margin-bottom: 16px; }
.chip {
  display: flex; align-items: center; gap: 12px;
  background: var(--card); border: 1.5px solid var(--off); border-radius: var(--radius-sm);
  padding: 12px 14px; min-width: 0;
  transition: border-color .2s, background .2s;
}
.chip__dot { width: 12px; height: 12px; border-radius: 50%; background: var(--off); flex: none; }
.chip__body { min-width: 0; }
.chip__label { color: var(--muted); font-size: 12px; }
.chip__value { font-weight: 650; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.chip[data-state="ok"] { border-color: var(--ok); box-shadow: 0 0 12px rgba(34,197,94,.3); }
.chip[data-state="idle"] { border-color: #64748b; }
.chip[data-state="ok"]   .chip__dot { background: var(--ok);    box-shadow: 0 0 10px rgba(34,197,94,.6); }
.chip[data-state="idle"] .chip__dot { background: var(--off); }
.chip[data-state="warn"] { border-color: var(--warn); box-shadow: 0 0 12px rgba(250,204,21,.35); background: rgba(250,204,21,.06); }
.chip[data-state="warn"] .chip__dot { background: var(--warn); animation: blink 1s steps(2) infinite; box-shadow: 0 0 10px rgba(250,204,21,.7); }
.chip[data-state="warn"] .chip__value { color: var(--warn); }
.chip[data-state="alarm"] { border-color: var(--alarm); box-shadow: 0 0 12px rgba(239,68,68,.4); background: rgba(239,68,68,.08); }
.chip[data-state="alarm"] .chip__dot { background: var(--alarm); animation: blink 1s steps(2) infinite; box-shadow: 0 0 10px rgba(239,68,68,.8); }
.chip[data-state="alarm"] .chip__value { color: #fca5a5; }

@keyframes blink { 50% { opacity: .25; } }

/* ---------- Gauge ---------- */
.gauge-card { display: flex; flex-direction: column; align-items: center; padding-bottom: 12px; }
.gauge-card .card__head { width: 100%; margin-bottom: 4px; }
.gauge { width: 100%; max-width: 240px; }
.gauge svg { display: block; width: 100%; height: auto; overflow: visible; }
.gauge__track { fill: none; stroke: #2f3b50; stroke-linecap: round; }
.gauge__bar { fill: none; stroke-linecap: round; transition: stroke-dashoffset .6s ease, d .6s ease; }
.gauge__needle { transition: transform .6s ease; }
.gauge__value { fill: var(--text); font: 650 34px var(--mono); }
.gauge__unit { fill: var(--muted); font: 500 12px var(--font); }
.gauge__minmax { fill: var(--faint); font: 500 11px var(--mono); }

/* ---------- Key/value lists ---------- */
.kv { list-style: none; margin: 0; padding: 0; }
.kv li { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; padding: 10px 0; border-bottom: 1px dashed var(--line); }
.kv li:last-child { border-bottom: 0; }
.kv .k { color: var(--muted); }
.kv .v { font-family: var(--mono); font-weight: 600; font-size: 15px; white-space: nowrap; }
.kv .v small { color: var(--muted); font-family: var(--font); font-weight: 500; font-size: 12px; margin-left: 3px; }

.big-stat { display: flex; flex-direction: column; gap: 2px; }
.big-stat .v { font: 650 26px var(--mono); }
.big-stat .v small { font: 500 13px var(--font); color: var(--muted); margin-left: 4px; }
.big-stat .k { color: var(--muted); font-size: 12px; }

/* ---------- Chart ---------- */
.chart-box { position: relative; height: 300px; }
.legend { display: flex; gap: 14px; font-size: 12px; color: var(--muted); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }

/* ---------- Meteo ---------- */
.weather { display: flex; flex-direction: column; gap: 14px; height: 100%; }
.weather__main { display: flex; align-items: center; gap: 14px; }
.weather__main img { width: 64px; height: 64px; object-fit: contain; }
.weather__temp { font: 650 36px var(--mono); line-height: 1; }
.weather__city { color: var(--muted); margin-top: 4px; }
.weather__grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.weather__item { background: var(--bg-2); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 10px 12px; }
.weather__item .k { color: var(--muted); font-size: 12px; }
.weather__item .v { font: 600 16px var(--mono); }
.wind-arrow { display: inline-block; transition: transform .6s; color: var(--accent); }

/* ---------- Allarmi ---------- */
.alarm-list { list-style: none; margin: 0; padding: 0; max-height: 260px; overflow: auto; }
.alarm-list li {
  display: grid; grid-template-columns: auto 1fr; gap: 10px; align-items: center;
  padding: 9px 10px; border-radius: 8px; margin-bottom: 6px;
  background: rgba(239,68,68,.08); border: 1px solid rgba(239,68,68,.25);
}
.alarm-list .code { font: 700 12px var(--mono); color: #fca5a5; background: rgba(239,68,68,.18); padding: 2px 7px; border-radius: 6px; }
.empty { color: var(--muted); text-align: center; padding: 24px 8px; }
.empty::before { content: "\2713 "; display: block; font-size: 22px; color: var(--ok); margin-bottom: 4px; }
.badge { font: 700 11px var(--mono); padding: 2px 8px; border-radius: 999px; background: var(--card-2); color: var(--muted); border: 1px solid var(--line); }
.badge.is-alarm { background: var(--alarm); color: #fff; border-color: var(--alarm); }

/* ---------- Bottoni ---------- */
.btn {
  appearance: none; border: 1px solid var(--line); background: var(--card-2); color: var(--text);
  font: 600 14px var(--font); padding: 9px 16px; border-radius: 9px; cursor: pointer;
  transition: filter .15s, transform .05s, background .15s;
}
.btn:hover { filter: brightness(1.15); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .4; cursor: not-allowed; filter: none; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #04121c; }

.cmd-grid { display: grid; grid-template-columns: repeat(3, minmax(0,1fr)); gap: 16px; }
.cmd {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px;
  min-height: 150px; border-radius: var(--radius); cursor: pointer;
  font: 700 20px var(--font); letter-spacing: .08em; color: #fff;
  border: 1px solid transparent; transition: filter .15s, transform .08s, box-shadow .2s;
}
.cmd svg { width: 38px; height: 38px; }
.cmd:hover:not(:disabled) { filter: brightness(1.1); }
.cmd:active:not(:disabled) { transform: scale(.98); }
.cmd:disabled { opacity: .35; cursor: not-allowed; filter: grayscale(.6); }
.cmd small { font: 500 12px var(--font); letter-spacing: 0; opacity: .8; }
.cmd--start { background: linear-gradient(180deg, #16a34a, #15803d); box-shadow: 0 10px 30px rgba(22,163,74,.25); }
.cmd--stop  { background: linear-gradient(180deg, #dc2626, #b91c1c); box-shadow: 0 10px 30px rgba(220,38,38,.25); }
.cmd--reset { background: linear-gradient(180deg, #d97706, #b45309); box-shadow: 0 10px 30px rgba(217,119,6,.25); }

/* ---------- Login (form iniettato dal PLC) ---------- */
#WebserverIFrame { display: none; }
.login-card { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.login-state { display: flex; align-items: center; gap: 12px; }
.login-state .icon {
  width: 40px; height: 40px; border-radius: 10px; display: grid; place-items: center;
  background: rgba(250,204,21,.12); color: var(--warn);
}
.login-state.is-in .icon { background: rgba(34,197,94,.12); color: var(--ok); }
.login-state b { display: block; }
.login-state span { color: var(--muted); font-size: 13px; }
#loginBox { color: var(--text); }
#loginBox form { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin: 0; }
#loginBox table, #loginBox tbody, #loginBox tr, #loginBox td { display: contents; }
#loginBox label, #loginBox .Login_Area_Label { color: var(--muted); font-size: 13px; }
#loginBox input[type="text"], #loginBox input[type="password"] {
  background: var(--bg-2); border: 1px solid var(--line); color: var(--text);
  border-radius: 8px; padding: 8px 10px; font: 14px var(--font); width: 150px;
}
#loginBox input[type="text"]:focus, #loginBox input[type="password"]:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: transparent; }
#loginBox input[type="submit"], #loginBox input[type="button"], #loginBox button, #loginBox .Logout_Button {
  background: var(--accent); border: 0; color: #04121c; font: 600 14px var(--font);
  border-radius: 8px; padding: 8px 16px; cursor: pointer; width: auto;
}
#loginBox .Logout_Button, #loginBox #logout_form input[type="submit"] { background: var(--card-2); color: var(--text); border: 1px solid var(--line); }
#loginBox a { color: var(--accent); }
#loginBox img { display: none; }

/* ---------- Storico ---------- */
.filter-bar { display: flex; align-items: end; gap: 12px; flex-wrap: wrap; }
.field { display: flex; flex-direction: column; gap: 4px; }
.field label { font-size: 12px; color: var(--muted); }
.field input {
  background: var(--bg-2); border: 1px solid var(--line); color: var(--text);
  border-radius: 8px; padding: 8px 10px; font: 14px var(--font); color-scheme: dark;
}
.presets { display: flex; gap: 6px; flex-wrap: wrap; }
.presets .btn { padding: 8px 12px; font-size: 13px; }

.tabs { display: inline-flex; background: var(--bg-2); border: 1px solid var(--line); border-radius: 10px; padding: 3px; }
.tabs button {
  background: transparent; border: 0; color: var(--muted); font: 600 13px var(--font);
  padding: 7px 14px; border-radius: 7px; cursor: pointer;
}
.tabs button[aria-selected="true"] { background: var(--card-2); color: var(--text); box-shadow: 0 1px 2px rgba(0,0,0,.4); }

.table-wrap { max-height: 420px; overflow: auto; border: 1px solid var(--bc); border-radius: var(--radius-sm); }
table.data { width: 100%; border-collapse: collapse; font-size: 13px; }
table.data th, table.data td { padding: 8px 12px; text-align: right; white-space: nowrap; }
table.data th:first-child, table.data td:first-child { text-align: left; }
table.data thead th {
  position: sticky; top: 0; background: var(--card-2); color: var(--muted);
  font-weight: 600; font-size: 12px; border-bottom: 1px solid var(--line); z-index: 1;
}
table.data tbody td { font-family: var(--mono); color: var(--text); border-bottom: 1px solid rgba(52,66,90,.7); }
table.data tbody tr:hover td { background: rgba(56,189,248,.06); }
table.data tfoot td { position: sticky; bottom: 0; background: var(--card-2); font-weight: 700; font-family: var(--mono); border-top: 1px solid var(--line); }

.loader { display: flex; align-items: center; justify-content: center; gap: 10px; color: var(--muted); padding: 40px; }
.loader::before { content: ""; width: 18px; height: 18px; border: 2px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Toast ---------- */
.toasts { position: fixed; top: 74px; right: 16px; z-index: 200; display: flex; flex-direction: column; gap: 8px; width: min(360px, calc(100vw - 32px)); }
.toast {
  display: grid; grid-template-columns: 4px 1fr auto; gap: 12px; align-items: start;
  background: #1b2331; border: 1px solid var(--line); border-radius: 10px; padding: 12px 12px 12px 0;
  box-shadow: 0 12px 30px rgba(0,0,0,.45); animation: toast-in .25s ease;
  overflow: hidden;
}
.toast::before { content: ""; align-self: stretch; margin: -12px 0; background: var(--accent); }
.toast.success::before { background: var(--ok); }
.toast.warning::before { background: var(--warn); }
.toast.error::before { background: var(--alarm); }
.toast b { display: block; font-size: 13px; }
.toast span { color: var(--muted); font-size: 13px; }
.toast button { background: none; border: 0; color: var(--muted); cursor: pointer; font-size: 16px; line-height: 1; padding: 0 2px; }
.toast.is-leaving { animation: toast-out .2s ease forwards; }
@keyframes toast-in { from { opacity: 0; transform: translateX(20px); } }
@keyframes toast-out { to { opacity: 0; transform: translateX(20px); } }

/* ---------- Dialog conferma ---------- */
dialog.confirm {
  border: 1px solid var(--line); border-radius: var(--radius); background: var(--card-2); color: var(--text);
  padding: 22px; width: min(420px, calc(100vw - 32px)); box-shadow: 0 30px 60px rgba(0,0,0,.6);
}
dialog.confirm::backdrop { background: rgba(0,0,0,.6); backdrop-filter: blur(2px); }
dialog.confirm h3 { font-size: 18px; margin-bottom: 6px; }
dialog.confirm p { color: var(--muted); margin: 0 0 20px; }
dialog.confirm .actions { display: flex; justify-content: flex-end; gap: 10px; }

/* ---------- Stato offline ---------- */
body.is-offline [data-live] { opacity: .45; transition: opacity .3s; }

/* ---------- Footer ---------- */
.footer { border-top: 1px solid var(--line); color: var(--faint); font-size: 12px; }
.footer__inner { max-width: 1400px; margin: 0 auto; padding: 14px 20px; display: flex; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.footer a { color: var(--muted); text-decoration: none; }

/* ---------- Responsive ---------- */
@media (max-width: 1100px) {
  .grid-4 { grid-template-columns: repeat(2, minmax(0,1fr)); }
  .grid-main, .grid-3 { grid-template-columns: minmax(0,1fr); }
  .status-strip { grid-template-columns: repeat(3, minmax(0,1fr)); }
}
@media (max-width: 760px) {
  main { padding: 14px; }
  .topbar__inner { flex-wrap: wrap; padding: 10px 14px; gap: 10px; }
  .menu-btn { display: block; }
  .nav { display: none; order: 10; width: 100%; flex-direction: column; margin: 0; }
  .nav.is-open { display: flex; }
  .topbar__right { order: 5; margin-left: 0; width: 100%; justify-content: space-between; }
  .status-strip { grid-template-columns: repeat(2, minmax(0,1fr)); }
  .cmd-grid { grid-template-columns: minmax(0,1fr); }
  .cmd { min-height: 96px; flex-direction: row; }
  .chart-box { height: 240px; }
  .gauge__value { font-size: 30px; }
}
@media (max-width: 420px) {
  .grid-4 { gap: 10px; }
  .grid-4 .card { padding: 12px; }
  .gauge-card .card__title { font-size: 11px; }
}

/* ---------- Colori bordo dei riquadri ---------- */
.grid-4 > .gauge-card:nth-child(1) { --bc: #fb923c; }   /* potenza */
.grid-4 > .gauge-card:nth-child(2) { --bc: #38bdf8; }   /* vento */
.grid-4 > .gauge-card:nth-child(3) { --bc: #a78bfa; }   /* allineamento */
.grid-4 > .gauge-card:nth-child(4) { --bc: #facc15; }   /* rotore */
.card--power  { --bc: #fb923c; }
.card--wind   { --bc: #38bdf8; }
.card--green  { --bc: #4ade80; }
.card--violet { --bc: #a78bfa; }
.card--yellow { --bc: #facc15; }
.card--red    { --bc: #f87171; }
.card--pink   { --bc: #f472b6; }

/* Comandi nascosti finche' non si fa il login */
[hidden] { display: none !important; }
.empty-lock { text-align: center; color: var(--muted); padding: 28px 10px; font-size: 15px; }

/* Numero turbina (wtgNum) in alto */
.wtg-num {
  display: inline-block; margin-left: 10px; vertical-align: 1px;
  font: 800 15px var(--mono); letter-spacing: .06em; color: #4ade80;
  padding: 2px 10px; border-radius: 7px;
  border: 1.5px solid #4ade80; background: rgba(74,222,128,.12);
  box-shadow: 0 0 12px rgba(74,222,128,.45);
  text-shadow: 0 0 8px rgba(74,222,128,.6);
}
.wtg-num:empty { display: none; }
@media (max-width: 760px) { .wtg-num { font-size: 13px; margin-left: 6px; } .brand__title { white-space: normal; } }

/* ---------- Bussola direzione vento / navicella ---------- */
.compass-box { width: 100%; max-width: 230px; margin: 0 auto; }
.compass { display: block; width: 100%; height: auto; }
.cp-tick { stroke: #7c8aa0; stroke-width: 1.2; }
.cp-tick-big { stroke: #e6ebf2; stroke-width: 2; }
.cp-label { fill: #c3cedd; font: 500 13px var(--mono); }
.cp-north { fill: #ffffff; font: 800 24px var(--font); }
.cp-rot { transition: transform .8s ease; will-change: transform; }
.cp-axis { stroke: #ef4444; stroke-width: 2.5; stroke-dasharray: 6 5; }
.cp-body { fill: #4b5563; stroke: #9ca3af; stroke-width: 1.5; }
.cp-blade { fill: #374151; stroke: #9ca3af; stroke-width: 1.2; }
.cp-hub { fill: #6b7280; stroke: #d1d5db; stroke-width: 1.2; }
.cp-inst { fill: #22d3ee; stroke: rgba(34,211,238,.35); stroke-width: 4; stroke-linejoin: round; paint-order: stroke; }
.cp-avg { fill: #3b82f6; stroke: rgba(59,130,246,.35); stroke-width: 5; stroke-linejoin: round; paint-order: stroke; }
.cp-legend { list-style: none; margin: 6px 0 0; padding: 0; width: 100%; display: grid; grid-template-columns: 1fr 1fr; gap: 3px 12px; font-size: 12px; color: var(--muted); }
.cp-legend li { display: flex; align-items: center; gap: 6px; white-space: nowrap; }
.cp-legend b { margin-left: auto; color: var(--text); font-family: var(--mono); }
.sw { display: inline-block; width: 12px; height: 10px; flex: none; }
.sw-nac { height: 0; border-top: 2.5px dashed #ef4444; }
.sw-inst { background: #22d3ee; clip-path: polygon(0 0, 100% 0, 50% 100%); }
.sw-avg { background: #3b82f6; clip-path: polygon(0 0, 100% 0, 50% 100%); }
.sw-err { background: #a78bfa; border-radius: 50%; width: 9px; height: 9px; }
@media (max-width: 760px) {
  .compass-card { grid-column: 1 / -1; }
  .compass-box { max-width: 260px; }
  .cp-legend { max-width: 320px; }
}

/* Riga indicatori: Potenza, Velocita' vento, Direzione vento (3 colonne) */
.grid-gauges { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-gauges > .gauge-card:nth-child(1) { --bc: #fb923c; }
.grid-gauges > .gauge-card:nth-child(2) { --bc: #38bdf8; }
.grid-gauges > .gauge-card:nth-child(3) { --bc: #a78bfa; }
.grid-gauges .gauge-card { justify-content: flex-start; }
.grid-gauges .gauge { margin-top: auto; margin-bottom: auto; }
.grid-gauges .compass-box { max-width: 250px; }
@media (max-width: 760px) {
  .grid-gauges { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .grid-gauges .card { padding: 12px; }
}

/* Turbina vista dall'alto (bussola) */
.cp-shadow  { fill: rgba(0,0,0,.30); }
.cp-nacelle { fill: url(#cpGradNac); stroke: #5b6474; stroke-width: 1.2; }
.cp-detail  { stroke: #7b8594; stroke-width: 1; }
.cp-hatch   { fill: none; stroke: #7b8594; stroke-width: 1; }
.cp-sensor  { fill: #cfd5de; stroke: #5b6474; stroke-width: .8; }
.cp-blade   { fill: url(#cpGradBlade); stroke: #5b6474; stroke-width: 1; }
.cp-hubring { fill: #b8c0cc; stroke: #5b6474; stroke-width: 1; }
.cp-spinner { fill: url(#cpGradSpin); stroke: #5b6474; stroke-width: 1.2; }

/* Bussola piu' grande, posizione navicella in alto a destra */
.grid-gauges .compass-box { max-width: 330px; }
.compass-card .card__head { margin-bottom: 0; }
.cp-nacpos { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); white-space: nowrap; }
.cp-nacpos b { color: var(--text); font: 700 16px var(--mono); }
@media (max-width: 760px) { .grid-gauges .compass-box { max-width: 340px; } }

/* ---------- Storico: torte produzione annuale ---------- */
.year-nav { display: flex; align-items: center; gap: 10px; }
.year-nav .btn { padding: 7px 13px; font-size: 14px; line-height: 1; }
.year-range { font: 700 16px var(--mono); color: var(--text); min-width: 120px; text-align: center; }
.pie-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 24px; }
.pie-col { display: flex; flex-direction: column; align-items: center; min-width: 0; }
.pie-year { font: 800 22px var(--mono); color: #4ade80; margin-bottom: 8px; }
.pie-box { position: relative; width: 100%; max-width: 320px; height: 280px; }
.pie-empty { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; color: var(--muted); border: 1px dashed var(--line); border-radius: 50%; margin: 20px; }
.pie-total { margin-top: 10px; font: 700 26px var(--mono); }
.pie-total small { font: 500 13px var(--font); color: var(--muted); margin-left: 5px; }
.pie-note { font-size: 13px; color: var(--muted); min-height: 20px; }
.pie-note.up { color: #4ade80; font-weight: 600; }
.pie-note.down { color: #f87171; font-weight: 600; }
.pie-legend { list-style: none; margin: 16px 0 0; padding: 12px 0 0; border-top: 1px dashed var(--line); display: flex; flex-wrap: wrap; justify-content: center; gap: 6px 16px; font-size: 13px; color: var(--muted); }
.pie-legend li { display: flex; align-items: center; gap: 6px; }
.pie-legend i { width: 11px; height: 11px; border-radius: 3px; display: inline-block; }
@media (max-width: 760px) {
  .pie-grid { grid-template-columns: minmax(0, 1fr); }
  .pie-box { height: 240px; }
}

/* Telefono in orizzontale / tablet stretto: menu a pulsante, cosi' non si
   sovrappone al numero turbina */
@media (min-width: 761px) and (max-width: 1320px) {
  .topbar__inner { flex-wrap: wrap; }
  .menu-btn { display: block; margin-left: 0; }
  .nav { display: none; order: 10; width: 100%; margin: 0; }
  .nav.is-open { display: flex; }
  .topbar__right { margin-left: auto; }
}

/* Riga degli stati: 6 riquadri (aggiunto Distacco RiGeDi) */
.status-strip { grid-template-columns: repeat(6, minmax(0,1fr)); }
@media (max-width: 1100px) { .status-strip { grid-template-columns: repeat(3, minmax(0,1fr)); } }
@media (max-width: 760px)  { .status-strip { grid-template-columns: repeat(2, minmax(0,1fr)); } }

/* ---------- Curva di velocita' (parametri) ---------- */
.par-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.par-grid--wide { grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); }
.par {
  background: var(--bg-2); border: 1px solid var(--line); border-radius: var(--radius-sm);
  padding: 9px 11px; display: flex; flex-direction: column; gap: 4px; transition: border-color .15s, box-shadow .15s;
}
.par__label { color: var(--muted); font-size: 12px; font-weight: 600; }
.par__nowrow { color: var(--faint); font-size: 12px; }
.par__now { color: var(--accent); font: 700 13px var(--mono); }
.par__row { display: flex; align-items: center; gap: 6px; }
.par__unit { color: var(--muted); font-size: 12px; }
.par__input {
  width: 100%; min-width: 0; background: var(--card); border: 1px solid var(--line); color: var(--text);
  border-radius: 7px; padding: 6px 8px; font: 700 15px var(--mono);
}
.par__input:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: transparent; }
.par__input:disabled { color: var(--muted); background: transparent; border-color: transparent; padding-left: 0; }
.par__err { color: #fca5a5; font-size: 11px; min-height: 0; }
.par__err:empty { display: none; }
.par.is-changed { border-color: var(--power); box-shadow: 0 0 10px rgba(249,115,22,.3); }
.par.is-changed .par__input { color: #fdba74; }
.par.is-error { border-color: var(--alarm); box-shadow: 0 0 10px rgba(239,68,68,.35); }
.par__switch {
  appearance: none; -webkit-appearance: none; width: 46px; height: 26px; border-radius: 999px; margin: 2px 0;
  background: var(--off); position: relative; cursor: pointer; transition: background .15s;
}
.par__switch::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%;
  background: #fff; transition: transform .15s;
}
.par__switch:checked { background: var(--ok); }
.par__switch:checked::after { transform: translateX(20px); }
.par__switch:disabled { opacity: .6; cursor: not-allowed; }
.par-ro { display: flex; gap: 22px; flex-wrap: wrap; margin-top: 12px; color: var(--muted); font-size: 13px; }
.par-ro b { color: var(--text); font-family: var(--mono); }
.par-actions { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; position: sticky; bottom: 10px; z-index: 5; }
.par-actions__msg { color: var(--muted); }
.par-actions__btns { display: flex; gap: 10px; }
#chg-count.is-alarm { background: var(--power); border-color: var(--power); color: #1a0d03; }
dialog.confirm p { white-space: pre-line; }
body.is-sending .par-actions { cursor: progress; }
.nav a, .conn { white-space: nowrap; }
.par.is-warn { border-color: var(--warn); }
.par.is-warn .par__err { color: var(--warn); }


/* ---------- Login Web API (versione web app) ---------- */
.user-btn {
  background: var(--card-2); border: 1px solid var(--line); color: var(--text);
  border-radius: 999px; padding: 5px 12px; font: 600 13px var(--font); cursor: pointer; white-space: nowrap;
}
.user-btn:hover { border-color: var(--accent); }
.user-btn.is-in { color: var(--ok); border-color: rgba(34,197,94,.5); }
dialog.login-dlg form { display: flex; flex-direction: column; gap: 12px; }
dialog.login-dlg label { display: flex; flex-direction: column; gap: 5px; color: var(--muted); font-size: 13px; }
dialog.login-dlg input {
  background: var(--bg-2); border: 1px solid var(--line); color: var(--text);
  border-radius: 8px; padding: 9px 11px; font: 15px var(--font);
}
dialog.login-dlg input:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: transparent; }
dialog.login-dlg .login-err { color: var(--alarm); font-size: 13px; font-weight: 600; }
dialog.login-dlg .actions { margin-top: 6px; }

/* pagina nascosta finche' non si fa il login */
html.need-login body > *:not(dialog):not(.toasts):not(.login-gate) { visibility: hidden; }
.login-gate { position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%); font-size: 16px; padding: 12px 28px; }

/* ---------- Comandi compatti + imbardata ---------- */
.cmd-grid { gap: 12px; }
.cmd { min-height: 84px; gap: 6px; font-size: 16px; flex-direction: column; }
.cmd svg { width: 26px; height: 26px; }
.cmd small { font-size: 11px; }
.cmd--yaw { background: linear-gradient(180deg, #0284c7, #0369a1); box-shadow: 0 8px 22px rgba(2,132,199,.22); }
.cmd--yawstop { background: linear-gradient(180deg, #475569, #334155); box-shadow: 0 8px 22px rgba(71,85,105,.25); }
.cmd-sub { margin: 18px 0 10px; color: var(--muted); font-size: 12px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; }
.yaw-time { display: flex; align-items: center; flex-wrap: wrap; gap: 8px 10px; margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--line); }
.yaw-time label { font-weight: 600; }
.yaw-time__now { color: var(--muted); font-size: 13px; margin-right: 6px; }
.yaw-time__now b { color: var(--text); font-family: var(--mono); }
.yaw-time input {
  width: 80px; background: var(--bg-2); border: 1px solid var(--line); color: var(--text);
  border-radius: 8px; padding: 8px 10px; font: 15px var(--mono); text-align: right;
}
.yaw-time input:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: transparent; }
.yaw-time input.is-bad { border-color: var(--alarm); outline-color: var(--alarm); }
.yaw-time__unit { color: var(--muted); }
.yaw-time__hint { color: var(--muted); font-size: 12px; flex-basis: 100%; }
@media (max-width: 760px) {
  .cmd-grid { grid-template-columns: repeat(3, minmax(0,1fr)); gap: 8px; }
  .cmd { min-height: 72px; flex-direction: column; font-size: 13px; letter-spacing: .03em; }
  .cmd small { display: none; }
}

/* stato imbardata + azimut */
.yaw-status { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 12px; margin-bottom: 12px; }
.chip[data-state="yaw"] { border-color: #38bdf8; box-shadow: 0 0 12px rgba(56,189,248,.35); background: rgba(56,189,248,.07); }
.chip[data-state="yaw"] .chip__dot { background: #38bdf8; animation: blink 1s steps(2) infinite; box-shadow: 0 0 10px rgba(56,189,248,.8); }
.chip[data-state="yaw"] .chip__value { color: #7dd3fc; }
.yaw-az { border-color: #64748b; }
.yaw-az__dial { width: 34px; height: 34px; flex: none; color: var(--muted); }
.yaw-az__needle { transform-origin: 20px 20px; transition: transform .6s ease; }
.yaw-az .chip__value { font-family: var(--mono); }
@media (max-width: 420px) { .yaw-status { grid-template-columns: minmax(0,1fr); } }

/* codice di sblocco comandi */
.unlock { display: flex; align-items: center; flex-wrap: wrap; gap: 8px 12px; margin: 0 0 14px; padding: 10px 12px;
  border: 1px solid var(--line); border-radius: 10px; background: rgba(250,204,21,.05); }
.unlock.is-open { background: rgba(34,197,94,.07); border-color: rgba(34,197,94,.5); }
.unlock__icon { font-size: 18px; }
.unlock__state { font-weight: 650; color: var(--warn); margin-right: auto; }
.unlock.is-open .unlock__state { color: var(--ok); }
.unlock__box { display: inline-flex; gap: 8px; }
.unlock__box[hidden] { display: none; }
.unlock input {
  width: 130px; background: var(--bg-2); border: 1px solid var(--line); color: var(--text);
  border-radius: 8px; padding: 8px 10px; font: 15px var(--mono);
}
.unlock input:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: transparent; }
.yaw-time input:disabled, .yaw-time .btn:disabled { opacity: .4; cursor: not-allowed; }

/* allarme CPU in STOP */
.cpu-stop { display: flex; align-items: center; flex-wrap: wrap; gap: 6px 12px; margin: 12px auto 0; max-width: 1360px;
  width: calc(100% - 40px); padding: 12px 16px; border-radius: 12px; border: 1px solid var(--alarm);
  background: rgba(239,68,68,.14); box-shadow: 0 0 18px rgba(239,68,68,.35); color: #fecaca; }
.cpu-stop b { color: #fff; letter-spacing: .04em; }
.cpu-stop span:last-child { font-size: 13px; }
.cpu-stop__dot { width: 12px; height: 12px; border-radius: 50%; background: var(--alarm); animation: blink 1s steps(2) infinite; box-shadow: 0 0 10px rgba(239,68,68,.9); }
body.cpu-stopped [data-live] { opacity: .55; }

.app-ver { color: var(--muted); opacity: .6; font-family: var(--mono); font-size: 11px; }
