/* Quadro strumenti: carta calda, inchiostro scuro, numeri grandi e stretti. */
:root {
  --scale: 1;
  --bg: #f4efe6;
  --card: #fffdf8;
  --ink: #1a1a17;
  --muted: #55524a;
  --line: #d6cdbc;
  --sole: #a85f00;   --sole-fill: #f2a900;
  --casa: #1c56ad;   --casa-fill: #3b82f6;
  --batt: #256b2a;   --batt-fill: #43a047;
  --rete: #4d5158;   --rete-fill: #8a9099;
  --err: #a4161a;
  --text: "Avenir Next", "Avenir", "Segoe UI", "Helvetica Neue", sans-serif;
  --num: "Avenir Next Condensed", "DIN Condensed", "Arial Narrow", "Avenir Next", sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12140f;
    --card: #1d2019;
    --ink: #f5f1e6;
    --muted: #b9b4a6;
    --line: #3a3d33;
    --sole: #ffc233;  --sole-fill: #ffc233;
    --casa: #8cbcff;  --casa-fill: #6aa6ff;
    --batt: #86da86;  --batt-fill: #66c466;
    --rete: #c3c8d0;  --rete-fill: #9aa0a9;
    --err: #ff8a8a;
  }
}

html { font-size: calc(18px * var(--scale)); -webkit-text-size-adjust: 100%; }
* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--text);
  font-size: 1rem;
  line-height: 1.35;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
[hidden] { display: none !important; }
h1 { font-size: 1.5rem; margin: 0; letter-spacing: -0.01em; }
h2 {
  font-size: 1.15rem; margin: 1.6rem 0 0.6rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.08em;
  display: flex; align-items: center; gap: 0.6rem;
}
h2::after { content: ""; flex: 1; height: 3px; background: var(--ink); }
h3 { font-size: 1.1rem; margin: 0 0 0.5rem; }
h3.loose { margin-top: 1.2rem; }

button, input { font: inherit; color: inherit; }
button {
  min-height: 3rem; min-width: 3rem; padding: 0 0.9rem;
  background: var(--card); border: 2px solid var(--ink); border-radius: 0.6rem;
  font-weight: 700; cursor: pointer; touch-action: manipulation;
}
button:active { transform: translateY(1px); }
button:disabled { opacity: 0.35; cursor: default; }
button.primary { background: var(--ink); color: var(--bg); width: 100%; font-size: 1.15rem; }
:focus-visible { outline: 3px solid var(--casa-fill); outline-offset: 2px; }

.top {
  display: flex; justify-content: space-between; align-items: center; gap: 0.75rem;
  padding: 0.9rem 16px 0.2rem; max-width: 1100px; margin: 0 auto;
}
.updated { margin: 0.1rem 0 0; color: var(--muted); font-size: 1rem; }
.top-actions { display: flex; gap: 0.5rem; }
#refresh { font-size: 1.5rem; line-height: 1; }
#refresh.busy { animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
#text-size { font-size: 0.9rem; }
#text-size span { font-size: 1.4rem; }

.layout { padding: 0 16px 1rem; max-width: 1100px; margin: 0 auto; }
.card {
  background: var(--card); border: 2px solid var(--line); border-radius: 0.9rem;
  padding: 0.9rem; margin-bottom: 0.8rem;
}

/* Stato attuale: schema dei flussi */
.flow { padding: 0.4rem; min-height: 12rem; }
.flow svg { display: block; width: 100%; max-width: 520px; margin: 0 auto; }
.flow text { text-anchor: middle; fill: var(--ink); font-family: var(--text); }
.flow .fv { font-family: var(--num); font-weight: 700; font-size: 40px; font-variant-numeric: tabular-nums; }
.flow .fu { font-size: 17px; font-weight: 700; }
.flow .fc { font-size: 19px; font-weight: 700; }
.flow .ring { fill: color-mix(in srgb, var(--c-fill) 16%, var(--card)); stroke: var(--c-fill); stroke-width: 5; }
.flow .icon { fill: none; stroke: var(--c); stroke-width: 2.5; stroke-linecap: round; stroke-linejoin: round; }
.flow .icon .level { fill: var(--c); stroke: none; }
.flow .idle .ring { fill: var(--card); stroke: var(--line); }
.flow .idle .icon { stroke: var(--muted); }
.flow .idle text { fill: var(--muted); }
.flow .inverter rect { fill: var(--ink); }
.flow .inverter .display { fill: var(--card); }
.flow .inverter path { stroke: var(--card); stroke-width: 3; stroke-linecap: round; }
.flowline { fill: none; stroke: var(--line); stroke-width: 7; stroke-linecap: round; stroke-dasharray: 0.1 14; }
.flowline.on { stroke: var(--c-fill); animation: flow 0.8s linear infinite; }
@keyframes flow { from { stroke-dashoffset: 14.1; } to { stroke-dashoffset: 0; } }
@media (prefers-reduced-motion: reduce) { .flowline.on { animation: none; } }
.now { display: grid; grid-template-columns: 1fr 1fr; gap: 0.6rem; }
.tile {
  background: var(--card); border: 2px solid var(--line); border-left: 0.55rem solid var(--c-fill);
  border-radius: 0.9rem; padding: 0.6rem 0.75rem; display: flex; flex-direction: column; min-width: 0;
}
.tile .label { font-size: 1.05rem; font-weight: 700; color: var(--c); text-transform: uppercase; letter-spacing: 0.06em; }
.tile .value {
  font-family: var(--num); font-weight: 700; font-size: 3.3rem; line-height: 1.05;
  font-variant-numeric: tabular-nums; white-space: nowrap;
}
.tile .value small { font-size: 0.45em; font-weight: 600; margin-left: 0.15em; }
.tile .sub { font-size: 1.05rem; font-weight: 600; color: var(--muted); }
.c-sole { --c: var(--sole); --c-fill: var(--sole-fill); }
.c-casa { --c: var(--casa); --c-fill: var(--casa-fill); }
.c-batt { --c: var(--batt); --c-fill: var(--batt-fill); }
.c-rete { --c: var(--rete); --c-fill: var(--rete-fill); }

/* Totali */
.totals { display: grid; grid-template-columns: 1fr 1fr; gap: 0.6rem; }
.totals .tile .value { font-size: 2.3rem; }
.totals .tile .label { font-size: 0.95rem; letter-spacing: 0.03em; }

/* Navigazione tra i giorni */
.daynav { display: flex; gap: 0.5rem; margin-bottom: 0.8rem; flex-wrap: wrap; }
.daynav #prev, .daynav #next { font-size: 1.8rem; line-height: 1; padding-bottom: 0.2rem; }
.daynav input {
  flex: 1; min-width: 9.5rem; min-height: 3rem; padding: 0 0.6rem; text-align: center;
  background: var(--card); border: 2px solid var(--ink); border-radius: 0.6rem; font-weight: 700; font-size: 1.1rem;
}

/* Grafici */
.chips { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-bottom: 0.4rem; }
.chip {
  min-height: 2.7rem; border-color: var(--c-fill); border-width: 2px;
  display: inline-flex; align-items: center; gap: 0.45rem; font-size: 1rem;
}
.chip::before { content: ""; width: 0.9rem; height: 0.9rem; border-radius: 50%; background: var(--c-fill); }
.chip[aria-pressed="false"] { opacity: 0.45; border-style: dashed; }
.chip[aria-pressed="false"]::before { background: transparent; box-shadow: inset 0 0 0 2px var(--c-fill); }
.readout { display: flex; flex-wrap: wrap; column-gap: 0.9em; margin: 0 0 0.3rem; min-height: 2.8em; font-size: 1.05rem; font-weight: 600; font-variant-numeric: tabular-nums; }
.readout b { font-family: var(--num); font-size: 1.25em; }
.readout .k { white-space: nowrap; }
.chart { height: 300px; touch-action: pan-y; position: relative; }
.chart.short { height: 220px; }
.chart svg { display: block; width: 100%; height: 100%; }
.chart text { fill: var(--muted); font-family: var(--text); font-size: 15px; font-weight: 600; }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .zero { stroke: var(--ink); stroke-width: 1.5; }
.chart .limit { stroke: var(--err); stroke-width: 1; }
.chart .cursor { stroke: var(--ink); stroke-width: 2; stroke-dasharray: 4 4; }
.chart .empty { font-size: 18px; text-anchor: middle; }

.error { color: var(--err); font-weight: 700; }
.banner { margin: 0.6rem 16px; padding: 0.7rem 0.9rem; border: 2px solid var(--err); border-radius: 0.6rem; }

/* Accesso */
#login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login { width: 100%; max-width: 26rem; display: grid; gap: 0.8rem; }
.login label { display: grid; gap: 0.3rem; font-weight: 700; }
.login input { min-height: 3.2rem; padding: 0 0.7rem; border: 2px solid var(--ink); border-radius: 0.6rem; background: var(--bg); font-size: 1.1rem; }
.login p { margin: 0; }
.note { color: var(--muted); font-size: 0.9rem; }

footer { padding: 0.5rem 16px 2rem; max-width: 1100px; margin: 0 auto; }

@media (min-width: 900px) {
  .now, .totals { grid-template-columns: repeat(4, 1fr); }
  .totals { grid-template-columns: repeat(3, 1fr); }
  .chart { height: 380px; }
}
@media (prefers-reduced-motion: reduce) { #refresh.busy { animation: none; } }
