/* Clima Vemer - sistema visivo unico: tema scuro, blu inchiostro, ambra.
   Nessun serif, nessuna ombra a timbro: solo bordi e tintine. */

:root {
  color-scheme: dark;

  --paper: #0b0f16;
  --surface: #131a26;
  --surface-2: #19212f;
  --ink: #e9edf5;
  --ink-2: #b6c0d0;
  --muted: #8b95a7;
  --line: rgba(233, 237, 245, 0.13);
  --line-strong: rgba(233, 237, 245, 0.3);
  --accent: #e0975f;
  --accent-ink: #f2bb8c;
  --ok: #4cbf8b;
  --warn: #e8775b;

  --chart-measured: #6ba8e0;
  --chart-setpoint: #e0975f;
  --chart-fill: rgba(107, 168, 224, 0.14);
  --chart-grid: rgba(233, 237, 245, 0.08);
  --tooltip-bg: #e9edf5;
  --tooltip-fg: #0b0f16;

  --radius: 14px;
  --radius-sm: 10px;
  --measure: 1180px;
  --pad: clamp(16px, 4vw, 40px);
  --sans: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto,
          "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 {
  margin: 0;
  font-weight: 680;
  letter-spacing: -0.022em;
  line-height: 1.15;
}

h1 { font-size: clamp(1.65rem, 1.1rem + 2.1vw, 2.6rem); }
h2 { font-size: clamp(1.15rem, 1rem + 0.7vw, 1.45rem); }
h3 { font-size: 1rem; letter-spacing: -0.01em; }

p { margin: 0; }

a { color: inherit; }

.wrap {
  width: min(var(--measure), 100% - (var(--pad) * 2));
  margin-inline: auto;
}

.skip {
  position: absolute;
  left: -9999px;
  top: 0;
  background: var(--ink);
  color: var(--paper);
  padding: 10px 16px;
  border-radius: 0 0 var(--radius-sm) 0;
  z-index: 20;
}
.skip:focus { left: 0; }

/* ---------- testata ---------- */
.top {
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}
.top-in {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 14px 0;
  flex-wrap: wrap;
}
.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  text-decoration: none;
  font-weight: 700;
  letter-spacing: -0.02em;
  font-size: 1.05rem;
}
.brand-mark {
  width: 30px;
  height: 30px;
  border-radius: 9px;
  background: var(--ink);
  color: var(--paper);
  display: grid;
  place-items: center;
  font-size: 0.95rem;
  font-weight: 700;
  flex: none;
}
.brand-sub {
  color: var(--muted);
  font-size: 0.86rem;
  margin-left: 2px;
}
.top-right {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 5px 12px;
  font-size: 0.82rem;
  color: var(--ink-2);
  background: var(--surface-2);
  white-space: nowrap;
}
.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--muted);
  flex: none;
}
.dot.ok { background: var(--ok); }
.dot.warn { background: var(--warn); }
.dot.pulse { animation: pulse 2.4s ease-in-out infinite; }
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.35; }
}

/* ---------- sezioni ---------- */
main { padding: clamp(24px, 4vw, 48px) 0 64px; }

.intro { max-width: 62ch; margin-bottom: clamp(24px, 3vw, 40px); }
.intro p {
  color: var(--ink-2);
  margin-top: 10px;
  font-size: 1.03rem;
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 300px), 1fr));
  gap: clamp(14px, 2vw, 22px);
}

/* ---------- scheda termostato ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  transition: border-color 0.18s ease, background-color 0.18s ease;
}
a.card { text-decoration: none; color: inherit; }
a.card:hover {
  border-color: var(--line-strong);
  background: color-mix(in srgb, var(--ink) 7%, var(--surface));
}
a.card:focus-visible,
button:focus-visible,
a:focus-visible,
input:focus-visible {
  outline: 2px solid var(--ink);
  outline-offset: 2px;
}

.card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}
.card-head h2 { font-size: 1.12rem; }
.card-sub {
  color: var(--muted);
  font-size: 0.84rem;
  margin-top: 2px;
}

.reading {
  display: flex;
  align-items: baseline;
  gap: 8px;
}
.reading b {
  font-size: clamp(2rem, 1.5rem + 2vw, 2.7rem);
  font-weight: 680;
  letter-spacing: -0.03em;
  line-height: 1;
}
.reading span { color: var(--muted); font-size: 1rem; }

.facts {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 18px;
  font-size: 0.9rem;
  color: var(--ink-2);
}
.facts b { font-weight: 620; color: var(--ink); }

.spark {
  height: 58px;
  position: relative;
}
.spark canvas { width: 100% !important; height: 58px !important; display: block; }

.card-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border-top: 1px solid var(--line);
  padding-top: 12px;
  font-size: 0.85rem;
  color: var(--muted);
}
.card-foot .go { color: var(--ink); font-weight: 600; text-decoration: none; }
.card-foot .go:hover { text-decoration: underline; text-underline-offset: 3px; }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border-radius: 999px;
  padding: 3px 10px;
  font-size: 0.78rem;
  font-weight: 600;
  border: 1px solid var(--line);
  color: var(--ink-2);
  background: var(--surface-2);
  white-space: nowrap;
}
.chip.on { color: var(--ok); border-color: color-mix(in srgb, var(--ok) 40%, transparent); }
.chip.warn { color: var(--warn); border-color: color-mix(in srgb, var(--warn) 40%, transparent); }
.chip.heat {
  color: var(--accent-ink);
  border-color: color-mix(in srgb, var(--accent) 50%, transparent);
  background: color-mix(in srgb, var(--accent) 16%, var(--surface));
}

/* ---------- pagina termostato ---------- */
.back {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--ink-2);
  text-decoration: none;
  font-size: 0.92rem;
  margin-bottom: 18px;
  min-height: 44px;
}
.back:hover { color: var(--ink); text-decoration: underline; text-underline-offset: 3px; }

.page-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 18px;
  flex-wrap: wrap;
  margin-bottom: 22px;
}
.page-head .meta { color: var(--muted); font-size: 0.9rem; margin-top: 6px; }

.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 180px), 1fr));
  gap: clamp(12px, 1.6vw, 18px);
  margin-bottom: 20px;
}
.stat {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
}
.stat .k {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}
.stat .v {
  font-size: clamp(1.4rem, 1.1rem + 1vw, 1.9rem);
  font-weight: 660;
  letter-spacing: -0.02em;
  margin-top: 4px;
}
.stat .v small { font-size: 0.85rem; color: var(--muted); font-weight: 500; }

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: clamp(14px, 2vw, 20px);
}
.panel + .panel { margin-top: clamp(14px, 2vw, 20px); }

/* ---------- comandi ---------- */
.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  margin-bottom: 16px;
}
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip-btn {
  font: inherit;
  font-size: 0.88rem;
  font-weight: 600;
  min-height: 44px;
  padding: 8px 14px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink-2);
  cursor: pointer;
  transition: border-color 0.18s ease, background-color 0.18s ease, color 0.18s ease;
}
.chip-btn:hover {
  border-color: var(--line-strong);
  background: color-mix(in srgb, var(--ink) 9%, var(--surface));
  color: var(--ink);
}
.chip-btn[aria-pressed="true"] {
  background: var(--ink);
  border-color: var(--ink);
  color: var(--paper);
}
.toolbar .spacer { flex: 1 1 auto; }

.btn {
  font: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  min-height: 44px;
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: border-color 0.18s ease, background-color 0.18s ease;
}
.btn:hover {
  border-color: var(--line-strong);
  background: color-mix(in srgb, var(--ink) 9%, var(--surface));
}
.btn:active { background: color-mix(in srgb, var(--ink) 15%, var(--surface)); }
.btn.primary {
  background: var(--ink);
  border-color: var(--ink);
  color: var(--paper);
}
.btn.primary:hover { background: color-mix(in srgb, var(--ink) 88%, #000); }
.btn[disabled] { opacity: 0.45; cursor: not-allowed; }

.date-field {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
  font-size: 0.88rem;
  color: var(--ink-2);
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 0 12px;
  background: var(--surface);
}
.date-field input {
  font: inherit;
  font-size: 0.88rem;
  border: 0;
  background: transparent;
  color: var(--ink);
  min-height: 44px;
  min-width: 0;
  width: 100%;
}

.range {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 6px 2px 0;
}
.range input[type="range"] {
  flex: 1 1 auto;
  min-width: 0;
  accent-color: var(--accent);
  height: 44px;
}
.range span {
  font-size: 0.82rem;
  color: var(--muted);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

/* ---------- grafici ---------- */
.chart-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}
.legend { display: flex; gap: 16px; flex-wrap: wrap; }
.legend span {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 0.85rem;
  color: var(--ink-2);
}
.legend i { width: 20px; height: 3px; border-radius: 2px; display: inline-block; }
.legend i.measured { background: var(--chart-measured); }
.legend i.setpoint {
  background: repeating-linear-gradient(90deg, var(--chart-setpoint) 0 7px, transparent 7px 12px);
}

.chart-wrap { position: relative; height: clamp(280px, 44vh, 460px); width: 100%; }
.chart-wrap canvas { width: 100% !important; height: 100% !important; display: block; }

.axis-note { color: var(--muted); font-size: 0.82rem; margin-top: 10px; }

.empty {
  padding: 40px 16px;
  text-align: center;
  color: var(--muted);
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius-sm);
}

@media (max-width: 640px) {
  .top-in { padding: 12px 0; }
  .brand-sub { display: none; }
  .toolbar .spacer { display: none; }
  .toolbar > * { flex: 1 1 auto; }
  .chips { width: 100%; }
  .chip-btn { flex: 1 1 auto; }
  .date-field { width: 100%; }
  .facts { gap: 6px 14px; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.001ms !important; transition-duration: 0.001ms !important; }
}
