/* Quadro — grigio quadro elettrico (RAL 7035), grafite e caratteri Barlow. */

@font-face { font-family: "Barlow"; src: url("/fonts/Barlow-Regular.woff") format("woff"); font-weight: 400; font-display: swap; }
@font-face { font-family: "Barlow"; src: url("/fonts/Barlow-Medium.woff") format("woff"); font-weight: 500; font-display: swap; }
@font-face { font-family: "Barlow"; src: url("/fonts/Barlow-SemiBold.woff") format("woff"); font-weight: 600; font-display: swap; }
@font-face { font-family: "Barlow Semi Condensed"; src: url("/fonts/BarlowSemiCondensed-Medium.woff") format("woff"); font-weight: 500; font-display: swap; }
@font-face { font-family: "Barlow Semi Condensed"; src: url("/fonts/BarlowSemiCondensed-SemiBold.woff") format("woff"); font-weight: 600; font-display: swap; }

:root {
  color-scheme: light;
  --bg: #e2e6e1;
  --panel: #f7f8f5;
  --panel-2: #edf0eb;
  --sunk: #d9ded8;
  --ink: #1d2421;
  --ink-2: #4f5954;
  --ink-3: #7a847f;
  --line: #d2d8d2;
  --line-soft: #e1e6e0;
  --gridline: #e3e7e2;
  --shadow: 0 1px 2px rgba(24, 34, 29, .07), 0 4px 14px rgba(24, 34, 29, .05);
  --on: #1f8a55;
  --on-soft: #d4ecdd;
  --off: #a2aaa5;
  --warn: #a15f00;
  --warn-soft: #f6e5c6;
  --bad: #bf3a30;
  --bad-soft: #f6dcd8;
  --focus: #2a78d6;

  /* flussi di energia: area (identità) e linea (contrasto) */
  --c-pv: #eda100;
  --c-pv-line: #b27700;
  --c-grid: #2a78d6;
  --c-batt: #008300;
  --c-casa: #cf3f7a;
  --c-pdc: #eb6834;
  --c-other: #a9b1ac;
  /* riempimenti dei grafici di energia, già miscelati con lo sfondo della scheda */
  --f-self: color-mix(in srgb, var(--c-pv) 82%, var(--panel));
  /* immessa in rete: tratteggio giallo (si distingue dall'autoconsumo pieno anche di notte e per i daltonici) */
  --f-export: color-mix(in srgb, var(--c-pv) 22%, var(--panel));
  --f-export-line: color-mix(in srgb, var(--c-pv) 75%, var(--panel));
  --f-prod: color-mix(in srgb, var(--c-pv) 38%, var(--panel));
  --f-charge: color-mix(in srgb, var(--c-batt) 32%, var(--panel));
  --f-batt: color-mix(in srgb, var(--c-batt) 68%, var(--panel));
  --f-import: color-mix(in srgb, var(--c-grid) 58%, var(--panel));
  /* dispositivi nei grafici */
  /* 0 blu, 1 arancio (pompa di calore), 2 acqua, 3 giallo, 4 rosa, 5 verde, 6 prugna (resistenze), 7 rosso:
     le coppie più frequenti (pompa, resistenze e i primi dispositivi) restano distinguibili anche per i daltonici */
  --d0: #2a78d6; --d1: #eb6834; --d2: #1baf7a; --d3: #d4b020;
  --d4: #d85c9e; --d5: #4d8a1c; --d6: #8e3a8e; --d7: #b3313f;
  /* colori dei comandi accesi */
  --a-green: #1f8a55; --a-amber: #efae00; --a-orange: #d9581f; --a-blue: #2a78d6; --a-teal: #12846a;
  --a-ink-dark: #2b2100;

  --font: "Barlow", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-cond: "Barlow Semi Condensed", "Barlow", system-ui, sans-serif;
  --r-card: 20px;
  --r-tile: 18px;
  --r-control: 12px;
  --gutter: 16px;
  --tabs-h: 66px;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #101412; --panel: #1b201d; --panel-2: #232925; --sunk: #151917;
    --ink: #e8ede9; --ink-2: #a8b1ac; --ink-3: #78827d;
    --line: #2d3430; --line-soft: #252b27; --gridline: #242a26;
    --shadow: 0 1px 2px rgba(0, 0, 0, .35);
    --on: #3dbd7c; --on-soft: #17372a; --off: #57605b;
    --warn: #e2a43c; --warn-soft: #3a2e17; --bad: #ef7a6e; --bad-soft: #3e201d; --focus: #6aa6ee;
    --c-pv: #d9a520; --c-pv-line: #ecc04a; --c-grid: #3987e5; --c-batt: #2e9e2e; --c-casa: #e46a9a; --c-pdc: #d95926; --c-other: #505953;
    --d0: #3987e5; --d1: #d95926; --d2: #199e70; --d3: #e0c43d;
    --d4: #f07cb4; --d5: #6cba4f; --d6: #a45fc0; --d7: #c9405e;
    --a-green: #2f9e66; --a-amber: #d9a21a; --a-orange: #d4541f; --a-blue: #3a82de; --a-teal: #17937a;
    --f-export: color-mix(in srgb, var(--c-pv) 16%, var(--panel)); --f-export-line: color-mix(in srgb, var(--c-pv) 80%, var(--panel)); --f-charge: color-mix(in srgb, var(--c-batt) 48%, var(--panel)); --f-prod: color-mix(in srgb, var(--c-pv) 45%, var(--panel));
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #101412; --panel: #1b201d; --panel-2: #232925; --sunk: #151917;
  --ink: #e8ede9; --ink-2: #a8b1ac; --ink-3: #78827d;
  --line: #2d3430; --line-soft: #252b27; --gridline: #242a26;
  --shadow: 0 1px 2px rgba(0, 0, 0, .35);
  --on: #3dbd7c; --on-soft: #17372a; --off: #57605b;
  --warn: #e2a43c; --warn-soft: #3a2e17; --bad: #ef7a6e; --bad-soft: #3e201d; --focus: #6aa6ee;
  --c-pv: #d9a520; --c-pv-line: #ecc04a; --c-grid: #3987e5; --c-batt: #2e9e2e; --c-casa: #e46a9a; --c-pdc: #d95926; --c-other: #505953;
  --d0: #3987e5; --d1: #d95926; --d2: #199e70; --d3: #e0c43d;
  --d4: #f07cb4; --d5: #6cba4f; --d6: #a45fc0; --d7: #c9405e;
  --a-green: #2f9e66; --a-amber: #d9a21a; --a-orange: #d4541f; --a-blue: #3a82de; --a-teal: #17937a;
  --f-export: color-mix(in srgb, var(--c-pv) 16%, var(--panel)); --f-export-line: color-mix(in srgb, var(--c-pv) 80%, var(--panel)); --f-charge: color-mix(in srgb, var(--c-batt) 48%, var(--panel)); --f-prod: color-mix(in srgb, var(--c-pv) 45%, var(--panel));
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; background: var(--bg); }
body {
  margin: 0; min-height: 100dvh; background: var(--bg); color: var(--ink);
  font: 400 16px/1.45 var(--font); font-feature-settings: "lnum";
  -webkit-tap-highlight-color: transparent; overscroll-behavior-y: none;
}
button, input, select { font: inherit; color: inherit; }
button { -webkit-user-select: none; user-select: none; }
a { color: inherit; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: 8px; }
[hidden] { display: none !important; }
svg { display: block; }
.num { font-variant-numeric: tabular-nums; }
.ico { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- struttura ---------- */
.app { max-width: 1240px; margin: 0 auto; padding-bottom: calc(var(--tabs-h) + var(--safe-b) + 28px); }
.top {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: flex-end; justify-content: space-between; gap: 12px;
  padding: calc(var(--safe-t) + 16px) var(--gutter) 12px;
  background: color-mix(in srgb, var(--bg) 90%, transparent);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
}
.top h1 { margin: 0; font: 600 29px/1.05 var(--font-cond); letter-spacing: -0.01em; }
.top-sub { margin: 3px 0 0; color: var(--ink-2); font-size: 14.5px; }
.link-state { display: flex; align-items: center; gap: 7px; color: var(--ink-2); font-size: 13px; padding: 0 0 4px; white-space: nowrap; }
.link-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--off); }
.link-state[data-state="live"] .link-dot { background: var(--on); box-shadow: 0 0 0 3px color-mix(in srgb, var(--on) 22%, transparent); }
.link-state[data-state="down"] .link-dot { background: var(--warn); }

main { padding: 2px var(--gutter) 0; outline: none; }
.screen { display: grid; gap: 22px; }
.screen > *, #view > * { min-width: 0; }
.col { display: grid; gap: 22px; align-content: start; min-width: 0; }
@media (min-width: 900px) {
  .screen.split { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); align-items: start; }
  .screen.split.wide-left { grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr); }
}

.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: grid; grid-template-columns: repeat(4, 1fr);
  height: calc(var(--tabs-h) + var(--safe-b)); padding-bottom: var(--safe-b);
  background: color-mix(in srgb, var(--panel) 94%, transparent); border-top: 1px solid var(--line);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
}
.tabs a {
  position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  text-decoration: none; color: var(--ink-3); font: 500 13px/1 var(--font-cond);
}
.tabs a .ico { width: 24px; height: 24px; }
.tabs a[aria-current="page"] { color: var(--ink); }
.tabs a[aria-current="page"]::before {
  content: ""; position: absolute; top: 9px; width: 56px; height: 32px; border-radius: 16px;
  background: var(--sunk); z-index: -1;
}
.tabs a[aria-current="page"] .ico { stroke-width: 2.1; }
@media (min-width: 900px) {
  .app { padding-left: 100px; padding-bottom: 40px; }
  .tabs { top: 0; right: auto; width: 88px; height: 100dvh; grid-template-columns: 1fr; grid-auto-rows: 78px; align-content: center; border-top: 0; border-right: 1px solid var(--line); padding: 0; }
  .tabs a[aria-current="page"]::before { top: 11px; }
}

/* ---------- carte e sezioni ---------- */
.card { background: var(--panel); border-radius: var(--r-card); padding: 18px; box-shadow: var(--shadow); min-width: 0; }
.card.flush { padding: 0; overflow: hidden; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; }
.card-head h2, .card-head h3 { margin: 0; font: 600 19px/1.2 var(--font-cond); display: flex; align-items: center; gap: 9px; min-width: 0; }
.card-head .aside { color: var(--ink-2); font-size: 14px; white-space: nowrap; }
.section-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 0 2px 10px; min-height: 32px; }
.section-head h2 { margin: 0; font: 600 13.5px/1.2 var(--font-cond); letter-spacing: .09em; text-transform: uppercase; color: var(--ink-2); }
.section-head .aside { color: var(--ink-2); font-size: 14px; }
.muted { color: var(--ink-2); }
.faint { color: var(--ink-3); }
.small { font-size: 14px; }
.empty { padding: 22px 18px; border: 1.5px dashed var(--line); border-radius: var(--r-card); color: var(--ink-2); }
.empty p { margin: 0 0 12px; }
.empty p:last-child { margin-bottom: 0; }
.swatch { width: 10px; height: 10px; border-radius: 3px; flex: none; display: inline-block; }
.swatch.line { height: 3px; width: 14px; border-radius: 2px; }
.hatch-bg { background: repeating-linear-gradient(135deg, var(--f-export-line) 0 1.6px, var(--f-export) 1.6px 4px) !important; }
.swatch.dash { height: 0; width: 14px; border-top: 2px dashed currentColor; border-radius: 0; background: none !important; }

/* ---------- comandi ---------- */
.cmd-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
@media (min-width: 560px) { .cmd-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (min-width: 900px) { .cmd-grid { grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); } }
.cmd {
  --acc: var(--a-green); --acc-ink: #fff;
  position: relative; display: grid; grid-template-columns: 46px minmax(0, 1fr); align-items: center; gap: 11px;
  min-height: 78px; padding: 12px 12px 12px 12px; border: 0; border-radius: var(--r-tile);
  background: var(--panel); box-shadow: var(--shadow); text-align: left; cursor: pointer;
  transition: background-color .2s ease, transform .08s ease;
  touch-action: manipulation;
}
.cmd:active { transform: scale(.975); }
.cmd .knob {
  position: relative; width: 46px; height: 46px; border-radius: 50%; display: grid; place-items: center;
  background: var(--panel-2); color: var(--ink-2); transition: background-color .2s ease, color .2s ease;
}
.cmd .knob .ico { width: 24px; height: 24px; }
.cmd .txt { min-width: 0; display: grid; gap: 1px; }
.cmd .name { font: 600 16.5px/1.15 var(--font-cond); overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow-wrap: anywhere; hyphens: auto; }
.cmd .state { font-size: 13.5px; color: var(--ink-2); font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cmd[aria-pressed="true"] { background: color-mix(in srgb, var(--acc) 14%, var(--panel)); }
.cmd[aria-pressed="true"] .knob { background: var(--acc); color: var(--acc-ink); }
.cmd[aria-pressed="true"] .state { color: var(--ink); font-weight: 500; }
.cmd.busy:not(.pulse) .knob::after {
  content: ""; position: absolute; inset: -4px; border-radius: 50%;
  border: 2.5px solid var(--acc); border-right-color: transparent; animation: spin .9s linear infinite;
}
.cmd .ring { position: absolute; inset: -5px; width: 56px; height: 56px; transform: rotate(-90deg); pointer-events: none; }
.cmd .ring circle { fill: none; stroke: var(--acc); stroke-width: 3; stroke-linecap: round; }
.cmd.pulse .knob { box-shadow: inset 0 0 0 2px var(--line); background: var(--panel); }
.cmd.pulse.firing { background: color-mix(in srgb, var(--acc) 14%, var(--panel)); }
.cmd.pulse.firing .knob { background: var(--acc); color: var(--acc-ink); box-shadow: none; }
.cmd.offline { cursor: default; opacity: .6; }
.cmd.offline .state { color: var(--warn); }
.cmd .timer { position: absolute; top: 8px; right: 10px; color: var(--ink-2); }
.cmd .timer .ico { width: 15px; height: 15px; }
.acc-amber { --acc: var(--a-amber); --acc-ink: var(--a-ink-dark); }
.acc-orange { --acc: var(--a-orange); }
.acc-blue { --acc: var(--a-blue); }
.acc-teal { --acc: var(--a-teal); }
@media (prefers-reduced-motion: reduce) { .cmd, .cmd .knob { transition: none; } .cmd:active { transform: none; } }

/* ---------- flusso di energia ---------- */
.flow-card { padding: 14px 12px 12px; }
.flowsvg { width: 100%; max-width: 440px; margin: 0 auto; overflow: visible; }
.flowsvg .fl-base { fill: none; stroke: var(--line); stroke-width: 2; }
.flowsvg .fl-dots { fill: none; stroke-width: 5.5; stroke-linecap: round; stroke-dasharray: 0 15; opacity: 0; }
.flowsvg .on .fl-base { stroke-opacity: .35; }
.flowsvg .on .fl-dots { opacity: 1; animation: flowdash var(--dur, 1.2s) linear infinite; }
.flowsvg .rev .fl-dots { animation-direction: reverse; }
@keyframes flowdash { to { stroke-dashoffset: -15; } }
@media (prefers-reduced-motion: reduce) { .flowsvg .on .fl-dots { animation: none; } }
.flowsvg .node-bg { fill: var(--panel); }
.flowsvg .node-ring { fill: none; stroke-width: 3.5; }
.flowsvg .node-track { fill: none; stroke: var(--line); stroke-width: 3.5; }
.flowsvg .node-val { font: 600 14px var(--font); fill: var(--ink); text-anchor: middle; font-variant-numeric: tabular-nums; }
.flowsvg .node-cap { font: 600 13px var(--font-cond); fill: var(--ink-2); text-anchor: middle; letter-spacing: .02em; }
.flowsvg .node-note { font: 500 12.5px var(--font); fill: var(--ink-2); text-anchor: middle; font-variant-numeric: tabular-nums; }
.flowsvg .node-ico { fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.flowsvg .dim .node-ring { stroke: var(--line) !important; }
.flowsvg .dim .node-ico { opacity: .45; }
.flowsvg .dim .node-val { fill: var(--ink-2); }
.flow-foot { display: flex; flex-wrap: wrap; justify-content: center; gap: 4px 16px; margin: 6px 0 2px; font-size: 13.5px; color: var(--ink-2); }
.flow-foot b { color: var(--ink); font-weight: 600; }

/* ---------- pompa di calore ---------- */
.hp-top { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; }
.hp-now { font: 500 36px/1 var(--font); letter-spacing: -0.01em; font-variant-numeric: tabular-nums; }
.hp-now small { font-size: 17px; color: var(--ink-2); margin-left: 3px; }
.hp-side { display: grid; justify-items: end; gap: 2px; font-size: 13.5px; color: var(--ink-2); text-align: right; }
.hp-side span { display: inline-flex; align-items: center; gap: 5px; }
.hp-side .ico { width: 17px; height: 17px; }
.warn-text { color: var(--warn); font-weight: 600; }
.temps { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; margin: 16px 0 0; }
@media (max-width: 400px) { .temps { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.temps div { background: var(--panel-2); border-radius: 12px; padding: 8px 10px; }
.temps span { display: block; font-size: 12.5px; color: var(--ink-2); }
.temps b { font: 600 17px/1.2 var(--font); font-variant-numeric: tabular-nums; }
.temps b.word { font: 600 16px/1.2 var(--font-cond); }
.facts { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; margin: 16px 0 0; }
.facts dt { color: var(--ink-2); font-size: 13px; }
.facts dd { margin: 1px 0 0; font: 600 18.5px/1.2 var(--font); font-variant-numeric: tabular-nums; }
.facts dd small { font-weight: 500; font-size: 13.5px; color: var(--ink-2); margin-left: 2px; }
.facts dd .sub { display: block; font: 400 13px/1.3 var(--font); color: var(--ink-2); margin-top: 1px; }
.row-btn {
  display: flex; align-items: center; gap: 12px; width: 100%; margin: 16px 0 0; padding: 12px 0 0;
  border: 0; border-top: 1px solid var(--line); background: none; text-align: left; cursor: pointer;
}
.row-btn + .row-btn { margin-top: 12px; }
.row-btn .grow { flex: 1; min-width: 0; display: grid; gap: 1px; }
.row-btn b { font-weight: 600; }
.row-btn .grow span { font-size: 13.5px; color: var(--ink-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 99px; font: 500 14px/1.2 var(--font-cond); background: var(--panel-2); color: var(--ink-2); white-space: nowrap; }
.pill.on { background: var(--on-soft); color: var(--ink); }
.pill.on::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--on); }
.pill.warn { background: var(--warn-soft); color: var(--ink); }
.pill.hot { background: color-mix(in srgb, var(--c-pdc) 18%, var(--panel)); color: var(--ink); }
.pill.hot::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--c-pdc); }

/* ---------- oggi ---------- */
.today-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px 16px; margin: 0; }
@media (min-width: 560px) { .today-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
.today-grid dt { display: flex; align-items: center; gap: 7px; color: var(--ink-2); font-size: 13.5px; }
.today-grid dd { margin: 2px 0 0; font: 600 21px/1.15 var(--font); font-variant-numeric: tabular-nums; }
.today-grid dd small { font-size: 13.5px; font-weight: 500; color: var(--ink-2); margin-left: 3px; }
.mini-chart { margin: 4px -4px 14px; height: 74px; }
.mini-chart svg { width: 100%; height: 74px; }
.more { display: flex; align-items: center; justify-content: flex-end; gap: 4px; margin-top: 12px; color: var(--ink); font-weight: 600; font-size: 15px; text-decoration: none; }
.more .ico { width: 18px; height: 18px; }

/* ---------- controlli ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 48px; padding: 0 20px; border-radius: 14px; border: 0; cursor: pointer;
  background: var(--ink); color: var(--panel); font-weight: 600; font-size: 16px; text-decoration: none;
}
.btn.secondary { background: var(--panel); color: var(--ink); box-shadow: inset 0 0 0 1px var(--line); }
.btn.quiet { background: none; color: var(--ink); padding: 0 8px; min-height: 40px; }
.btn.danger { background: var(--bad-soft); color: var(--bad); }
.btn.small { min-height: 38px; padding: 0 14px; font-size: 14.5px; border-radius: 11px; }
.btn.block { width: 100%; }
.btn[disabled] { opacity: .5; cursor: default; }
.btn .ico { width: 19px; height: 19px; stroke-width: 2; }
.btn-row { display: flex; flex-wrap: wrap; gap: 10px; }
.icon-btn { width: 40px; height: 40px; border-radius: 50%; border: 0; background: var(--panel); box-shadow: var(--shadow); display: grid; place-items: center; cursor: pointer; flex: none; color: var(--ink); }
.icon-btn .ico { width: 20px; height: 20px; stroke-width: 2; }
.icon-btn[disabled] { opacity: .35; cursor: default; }
.link-btn { border: 0; background: none; padding: 6px 4px; color: var(--ink); font-weight: 600; font-size: 15px; cursor: pointer; display: inline-flex; align-items: center; gap: 6px; }
.link-btn .ico { width: 18px; height: 18px; }

.seg { display: flex; padding: 3px; gap: 2px; border-radius: 13px; background: var(--sunk); }
.seg button { flex: 1; min-height: 38px; border: 0; border-radius: 10px; background: none; color: var(--ink-2); font: 500 15.5px/1 var(--font-cond); cursor: pointer; white-space: nowrap; padding: 0 6px; }
.seg button[aria-pressed="true"] { background: var(--panel); color: var(--ink); box-shadow: 0 1px 2px rgba(0, 0, 0, .12); }

.datenav { display: grid; grid-template-columns: 40px minmax(0, 1fr) 40px; align-items: center; gap: 8px; }
.datenav .when { position: relative; border: 0; background: none; cursor: pointer; text-align: center; padding: 4px 0; min-width: 0; }
.datenav .when b { display: block; font: 600 18px/1.2 var(--font-cond); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.datenav .when span { font-size: 13px; color: var(--ink-2); }
.datenav input[type="date"], .datenav input[type="month"] { position: absolute; inset: 0; opacity: 0; pointer-events: none; }
.controls { display: grid; gap: 12px; }
@media (min-width: 900px) { .controls { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); align-items: center; } }

.chips { display: flex; gap: 8px; overflow-x: auto; padding: 2px 2px 8px; margin: 0 -2px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  display: inline-flex; align-items: center; gap: 8px; flex: none;
  min-height: 38px; padding: 0 14px; border-radius: 99px; border: 0; cursor: pointer;
  background: var(--panel); color: var(--ink); box-shadow: inset 0 0 0 1px var(--line); font-weight: 500; font-size: 15px;
}
.chip i { width: 10px; height: 10px; border-radius: 50%; }
.chip[aria-pressed="true"] { background: var(--ink); color: var(--panel); box-shadow: none; }

.field { display: grid; gap: 6px; }
.field > span { font-size: 14px; color: var(--ink-2); font-weight: 500; }
.field input, .field select {
  width: 100%; min-height: 48px; padding: 0 14px; border-radius: var(--r-control);
  border: 1px solid var(--line); background: var(--panel); outline: none; font-size: 16px;
}
.field input:focus, .field select:focus { border-color: var(--focus); box-shadow: 0 0 0 3px color-mix(in srgb, var(--focus) 22%, transparent); }
.field .hint { font-size: 13px; color: var(--ink-3); }
.pw-wrap { position: relative; }
.pw-wrap input { padding-right: 50px; }
.pw-wrap button { position: absolute; right: 4px; top: 50%; transform: translateY(-50%); width: 42px; height: 42px; border: 0; background: none; border-radius: 10px; display: grid; place-items: center; color: var(--ink-2); cursor: pointer; }
.fields { display: grid; gap: 14px; }
.fields.two { grid-template-columns: 1fr 1fr; }
.switch { display: flex; align-items: center; justify-content: space-between; gap: 14px; min-height: 48px; cursor: pointer; }
.switch input { appearance: none; -webkit-appearance: none; width: 48px; height: 29px; border-radius: 99px; background: var(--off); position: relative; cursor: pointer; flex: none; transition: background .15s; margin: 0; }
.switch input::after { content: ""; position: absolute; top: 3px; left: 3px; width: 23px; height: 23px; border-radius: 50%; background: #fff; transition: transform .15s; box-shadow: 0 1px 2px rgba(0, 0, 0, .3); }
.switch input:checked { background: var(--on); }
.switch input:checked::after { transform: translateX(19px); }
.check-row { display: flex; align-items: center; gap: 10px; min-height: 44px; cursor: pointer; font-size: 15px; }
.check-row input { width: 20px; height: 20px; accent-color: var(--ink); margin: 0; }
.radio-cards { display: grid; gap: 8px; }
.radio-cards label { display: grid; grid-template-columns: auto 1fr; gap: 2px 10px; padding: 12px 14px; border-radius: var(--r-control); box-shadow: inset 0 0 0 1px var(--line); cursor: pointer; background: var(--panel); }
.radio-cards input { margin: 3px 0 0; accent-color: var(--ink); grid-row: span 2; }
.radio-cards label:has(input:checked) { box-shadow: inset 0 0 0 2px var(--ink); }
.radio-cards small { color: var(--ink-2); font-size: 13.5px; }

.note { padding: 12px 14px; border-radius: var(--r-control); background: var(--panel-2); color: var(--ink-2); font-size: 14px; }
.note b { color: var(--ink); }
.note.warn { background: var(--warn-soft); color: var(--ink); }
.note.bad { background: var(--bad-soft); color: var(--ink); }
.note p { margin: 0; }
.note p + p { margin-top: 6px; }
.note ol { margin: 6px 0 0; padding-left: 20px; }
.banner { display: flex; gap: 12px; align-items: center; justify-content: space-between; padding: 12px 16px; border-radius: var(--r-card); background: var(--panel-2); font-size: 14.5px; color: var(--ink-2); }
.banner b { color: var(--ink); }

/* ---------- elenchi ---------- */
.list { list-style: none; margin: 0; padding: 0; background: var(--panel); border-radius: var(--r-card); box-shadow: var(--shadow); }
.list li + li { border-top: 1px solid var(--line-soft); }
.row {
  display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 12px;
  width: 100%; min-height: 62px; padding: 11px 16px; border: 0; background: none; text-align: left; cursor: pointer; text-decoration: none; color: inherit;
}
.row.static { cursor: default; }
.row.lead { grid-template-columns: auto minmax(0, 1fr) auto; }
.row:not(.static):active { background: var(--panel-2); }
.list li:first-child .row { border-radius: var(--r-card) var(--r-card) 0 0; }
.list li:last-child .row { border-radius: 0 0 var(--r-card) var(--r-card); }
.list li:only-child .row { border-radius: var(--r-card); }
.row-main { min-width: 0; }
.row-title { display: flex; align-items: center; gap: 8px; font-weight: 500; }
.row-title span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-sub { display: block; font-size: 13.5px; color: var(--ink-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-end { text-align: right; font-variant-numeric: tabular-nums; display: flex; align-items: center; gap: 8px; }
.row-end .stack-v { display: grid; justify-items: end; }
.row-end strong { font-weight: 600; }
.row-end span { font-size: 13.5px; color: var(--ink-2); }
.row .badge-ico { width: 38px; height: 38px; border-radius: 50%; display: grid; place-items: center; background: var(--panel-2); color: var(--ink-2); }
.row .badge-ico .ico { width: 20px; height: 20px; }
.dot { width: 9px; height: 9px; border-radius: 50%; flex: none; background: var(--off); }
.dot.ok { background: var(--on); }
.dot.bad { background: var(--bad); }
.badge { font: 600 12px/1 var(--font-cond); padding: 4px 8px; border-radius: 99px; background: var(--warn-soft); color: var(--warn); white-space: nowrap; }
.badge.plain { background: var(--panel-2); color: var(--ink-2); }
.chev { width: 18px; height: 18px; fill: none; stroke: var(--ink-3); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }

/* ---------- energia ---------- */
.stat-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
@media (min-width: 700px) { .stat-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
.stat { background: var(--panel); border-radius: 16px; padding: 12px 14px; box-shadow: var(--shadow); min-width: 0; }
.stat dt { display: flex; align-items: center; gap: 7px; font-size: 13.5px; color: var(--ink-2); }
.stat dd { margin: 3px 0 0; font: 600 22px/1.15 var(--font); font-variant-numeric: tabular-nums; }
.stat dd small { font-size: 14px; font-weight: 500; color: var(--ink-2); margin-left: 3px; }
.stat .sub { margin: 3px 0 0; font-size: 13px; color: var(--ink-2); }
.stat.big dd { font-size: 30px; }
.balance { display: grid; gap: 14px; }
.balance h4 { margin: 0 0 6px; display: flex; justify-content: space-between; gap: 8px; font: 500 14.5px/1.2 var(--font); color: var(--ink-2); }
.balance h4 b { color: var(--ink); font-weight: 600; }
.bar { display: flex; height: 12px; gap: 2px; border-radius: 6px; overflow: hidden; background: var(--panel-2); }
.bar span { height: 100%; min-width: 2px; transition: flex-grow .5s ease; }
.bar-legend { display: flex; flex-wrap: wrap; gap: 4px 14px; margin-top: 7px; font-size: 13.5px; color: var(--ink-2); }
.bar-legend span { display: inline-flex; align-items: center; gap: 6px; }
.bar-legend b { color: var(--ink); font-weight: 600; }
.chart-box { position: relative; touch-action: pan-y; user-select: none; -webkit-user-select: none; }
.chart-box svg { width: 100%; overflow: visible; }
.chart-box .axis { fill: var(--ink-3); font: 500 12px var(--font-cond); font-variant-numeric: tabular-nums; }
.chart-box .axis.r { fill: var(--c-batt); }
.chart-box .grid { stroke: var(--gridline); stroke-width: 1; shape-rendering: crispEdges; }
.chart-box .base { stroke: var(--line); stroke-width: 1; shape-rendering: crispEdges; }
.chart-box .xhair { stroke: var(--ink-2); stroke-width: 1; stroke-dasharray: 3 3; }
.chart-box .now { stroke: var(--ink-3); stroke-width: 1; stroke-dasharray: 2 3; }
.chart-box .hot { fill: var(--ink); fill-opacity: .06; }
.chart-box .empty-msg { fill: var(--ink-3); font: 500 14px var(--font); text-anchor: middle; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; margin: 12px 0 0; padding: 0; list-style: none; font-size: 13.5px; color: var(--ink-2); }
.legend li { display: flex; align-items: center; gap: 7px; }
.chart-hint { margin: 8px 0 0; font-size: 13px; color: var(--ink-3); }
.dimmed { opacity: .45; transition: opacity .2s; }
table.data { width: 100%; border-collapse: collapse; margin-top: 12px; font-size: 14px; font-variant-numeric: tabular-nums; }
table.data th, table.data td { padding: 8px 4px; border-top: 1px solid var(--line-soft); text-align: right; white-space: nowrap; }
table.data th { font: 600 13px var(--font-cond); color: var(--ink-2); border-top: 0; }
table.data th:first-child, table.data td:first-child { text-align: left; }
table.data td:first-child { color: var(--ink-2); }
table.data tr.link { cursor: pointer; }
table.data tr.link:active td { background: var(--panel-2); }
.table-wrap { overflow-x: auto; margin: 0 -4px; padding: 0 4px; }
.derived { margin: 10px 0 0; font-size: 13px; color: var(--ink-3); }

/* ---------- consumi ---------- */
.rank .row { grid-template-columns: auto minmax(0, 1fr) auto; min-height: 64px; }
.rank .share { display: block; height: 4px; border-radius: 2px; background: var(--panel-2); margin-top: 5px; overflow: hidden; }
.rank .share i { display: block; height: 100%; border-radius: 2px; }
.rank .row[aria-pressed="true"] { background: var(--panel-2); }
.delta { font-size: 13.5px; color: var(--ink-2); margin: 4px 0 0; }
.bignum { margin: 2px 0 0; font: 600 28px/1.1 var(--font); font-variant-numeric: tabular-nums; }
.bignum small { font-size: 15px; font-weight: 500; color: var(--ink-2); margin-left: 4px; }
.delta b { font-weight: 600; color: var(--ink); }

/* ---------- controllo sicurezza ---------- */
.checks { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
.check { display: grid; grid-template-columns: 24px 1fr auto; gap: 4px 10px; align-items: start; padding: 10px 0; border-top: 1px solid var(--line-soft); }
.check:first-child { border-top: 0; }
.check .ck { width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center; margin-top: 1px; }
.check .ck svg { width: 14px; height: 14px; fill: none; stroke: currentColor; stroke-width: 2.6; stroke-linecap: round; stroke-linejoin: round; }
.check.ok .ck { background: var(--on-soft); color: var(--on); }
.check.ko .ck { background: var(--warn-soft); color: var(--warn); }
.check.opt .ck { background: var(--panel-2); color: var(--ink-3); }
.check b { font-weight: 600; }
.check p { margin: 1px 0 0; font-size: 13.5px; color: var(--ink-2); }
.check .inline-pw { grid-column: 2 / -1; display: flex; gap: 8px; margin-top: 8px; }
.check .inline-pw input { flex: 1; min-height: 40px; padding: 0 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--panel); }

/* ---------- foglio (bottom sheet) ---------- */
.sheet-layer { position: fixed; inset: 0; z-index: 30; display: flex; align-items: flex-end; justify-content: center; }
.sheet-backdrop { position: absolute; inset: 0; background: rgba(10, 14, 12, .5); animation: fade .2s ease; }
.sheet {
  position: relative; width: 100%; max-width: 640px; max-height: 92dvh; overflow: auto; overscroll-behavior: contain;
  background: var(--bg); border-radius: 24px 24px 0 0; padding: 8px 18px calc(22px + var(--safe-b));
  animation: rise .26s cubic-bezier(.2, .8, .2, 1);
}
@media (min-width: 900px) { .sheet-layer { align-items: center; } .sheet { border-radius: 24px; max-height: 88dvh; } }
.sheet-grip { width: 40px; height: 5px; border-radius: 3px; background: var(--line); margin: 4px auto 12px; }
.sheet h2 { margin: 0; font: 600 25px/1.1 var(--font-cond); }
.sheet-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
.sheet-head p { margin: 4px 0 0; color: var(--ink-2); font-size: 14px; }
.sheet section { margin-top: 22px; }
.sheet section > h3 { margin: 0 0 10px; font: 600 13.5px/1.2 var(--font-cond); letter-spacing: .08em; text-transform: uppercase; color: var(--ink-2); }
.sheet .card { padding: 16px; }
.close { width: 40px; height: 40px; border-radius: 50%; border: 0; background: var(--panel); display: grid; place-items: center; cursor: pointer; flex: none; box-shadow: var(--shadow); }
.close svg { width: 18px; height: 18px; stroke: var(--ink); stroke-width: 2.2; fill: none; stroke-linecap: round; }
.sheet-actions { position: sticky; bottom: calc(-22px - var(--safe-b)); margin: 22px -18px calc(-22px - var(--safe-b)); padding: 12px 18px calc(12px + var(--safe-b)); background: var(--bg); border-top: 1px solid var(--line); display: flex; gap: 10px; z-index: 2; }
.sheet-actions .btn { flex: 1; }
.channel { display: grid; gap: 12px; padding: 14px 0; border-top: 1px solid var(--line-soft); }
.channel:first-of-type { border-top: 0; padding-top: 2px; }
.channel-head { display: flex; justify-content: space-between; gap: 8px; font-size: 13.5px; color: var(--ink-2); }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 7px 16px; margin: 0; font-size: 14.5px; }
.kv dt { color: var(--ink-2); }
.kv dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.icon-pick { display: grid; grid-template-columns: repeat(auto-fill, minmax(46px, 1fr)); gap: 6px; }
.icon-pick button { height: 46px; border: 0; border-radius: 12px; background: var(--panel); box-shadow: inset 0 0 0 1px var(--line); display: grid; place-items: center; cursor: pointer; color: var(--ink-2); }
.icon-pick button[aria-pressed="true"] { box-shadow: inset 0 0 0 2px var(--ink); color: var(--ink); background: var(--panel-2); }
.order-list { list-style: none; margin: 0; padding: 0; background: var(--panel); border-radius: var(--r-card); box-shadow: var(--shadow); }
.order-list li { display: grid; grid-template-columns: 40px minmax(0, 1fr) auto auto; align-items: center; gap: 10px; padding: 8px 10px 8px 14px; border-top: 1px solid var(--line-soft); min-height: 60px; }
.order-list li:first-child { border-top: 0; }
.order-list li.off .o-name { color: var(--ink-3); }
.order-list .badge-ico { width: 38px; height: 38px; border-radius: 50%; display: grid; place-items: center; background: var(--panel-2); color: var(--ink-2); }
.order-list .o-name { font-weight: 500; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.order-list .o-name small { display: block; font-weight: 400; font-size: 13px; color: var(--ink-3); }
.order-list .moves { display: flex; gap: 4px; }
.order-list .moves button { width: 36px; height: 36px; border-radius: 10px; border: 0; background: var(--panel-2); display: grid; place-items: center; cursor: pointer; color: var(--ink); }
.order-list .moves button[disabled] { opacity: .3; cursor: default; }
.order-list .moves .ico { width: 18px; height: 18px; stroke-width: 2.1; }
.order-list .switch { min-height: 0; }
.quick { display: grid; gap: 16px; }
.quick-top { display: flex; align-items: center; gap: 14px; }
.quick-top .cmd { flex: none; width: 100%; }
.quick-times { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }
.quick-times button { min-height: 44px; border: 0; border-radius: 12px; background: var(--panel); box-shadow: inset 0 0 0 1px var(--line); cursor: pointer; font-weight: 600; }

@keyframes rise { from { transform: translateY(40px); opacity: 0; } }
@keyframes fade { from { opacity: 0; } }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .sheet, .sheet-backdrop { animation: none; } }

/* ---------- tooltip, toast ---------- */
.tip {
  position: fixed; z-index: 40; pointer-events: none; min-width: 120px; max-width: min(300px, calc(100vw - 16px));
  padding: 9px 12px; border-radius: 12px; background: var(--ink); color: var(--panel);
  font-size: 13.5px; line-height: 1.35; box-shadow: 0 8px 22px rgba(0, 0, 0, .25);
}
.tip .t-h { font: 600 14px/1.3 var(--font-cond); opacity: .85; margin-bottom: 4px; }
.tip .t-r { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 8px; }
.tip .t-r b { font-weight: 600; font-variant-numeric: tabular-nums; text-align: right; }
.tip .t-r .swatch { width: 9px; height: 9px; }
.tip .t-r .swatch.line { height: 3px; width: 12px; }
.tip .t-r.sub { opacity: .75; font-size: 12.5px; padding-left: 17px; grid-template-columns: 1fr auto; }
.tip .t-sep { height: 1px; background: currentColor; opacity: .15; margin: 5px 0; }
.toast {
  position: fixed; left: 50%; bottom: calc(var(--tabs-h) + var(--safe-b) + 14px); z-index: 50; transform: translateX(-50%);
  max-width: calc(100% - 32px); padding: 12px 16px; border-radius: 14px; background: var(--ink); color: var(--panel);
  font-size: 15px; box-shadow: 0 8px 22px rgba(0, 0, 0, .25); animation: rise .2s ease;
}
.toast.bad { background: var(--bad); color: #fff; }
.spinner { width: 18px; height: 18px; border-radius: 50%; border: 2.5px solid currentColor; border-right-color: transparent; animation: spin .8s linear infinite; display: inline-block; vertical-align: -3px; }

/* ---------- accesso ---------- */
.auth { min-height: 100dvh; display: grid; place-items: center; padding: calc(var(--safe-t) + 24px) 20px calc(var(--safe-b) + 24px); }
.auth-card { width: 100%; max-width: 400px; }
.auth-logo { width: 64px; height: 64px; border-radius: 18px; margin: 0 0 18px; box-shadow: var(--shadow); }
.auth h1 { margin: 0; font: 600 32px/1.05 var(--font-cond); }
.auth .lead { margin: 6px 0 22px; color: var(--ink-2); }
.auth form { display: grid; gap: 14px; }
.auth .fine { margin: 18px 0 0; font-size: 13px; color: var(--ink-3); }
body.locked .app, body.locked .tabs { display: none; }

/* ---------- azione rapida (scorciatoia) ---------- */
.action { min-height: calc(100dvh - 180px); display: grid; place-items: center; text-align: center; }
.action-in { display: grid; justify-items: center; gap: 18px; }
.big-btn {
  --acc: var(--a-green); --acc-ink: #fff;
  position: relative; width: 196px; height: 196px; border-radius: 50%; border: 0; cursor: pointer;
  background: var(--panel); color: var(--ink); box-shadow: var(--shadow), inset 0 0 0 2px var(--line);
  display: grid; place-items: center; transition: background-color .2s, transform .08s;
}
.big-btn:active { transform: scale(.97); }
.big-btn .ico { width: 64px; height: 64px; stroke-width: 1.5; }
.big-btn[aria-pressed="true"], .big-btn.firing { background: var(--acc); color: var(--acc-ink); box-shadow: var(--shadow); }
.big-btn svg.ring { position: absolute; inset: -8px; width: 212px; height: 212px; transform: rotate(-90deg); }
.big-btn svg.ring circle { fill: none; stroke: var(--acc); stroke-width: 5; stroke-linecap: round; }
.action h2 { margin: 0; font: 600 28px/1.1 var(--font-cond); }
.action p { margin: 0; color: var(--ink-2); }
