:root {
  --bg: #030913;
  --bg-soft: #091320;
  --panel: #0f1826;
  --panel-2: #152233;
  --text: #eef7ff;
  --muted: #9bb0c7;
  --border: rgba(125, 175, 214, 0.14);
  --accent: #53cfff;
  --accent-2: #1f78ff;
  --good: #31d07e;
  --warn: #ffb020;
  --danger: #ff5a69;
  --shadow: 0 12px 28px rgba(0, 0, 0, 0.24);
}

* {
  box-sizing: border-box;
}

html {
  font-family: Arial, Helvetica, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-text-size-adjust: 100%; /* Chrome, Safari, Opera */
  -moz-text-size-adjust: 100%;    /* Firefox */
  text-size-adjust: 100%;         /* Standard */
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;

  background:
    radial-gradient(circle at top, rgba(83, 207, 255, 0.10) 0%, transparent 42%),
    linear-gradient(180deg, #09111d 0%, #050b14 100%);
  color: var(--text);
  position: relative;
}

html, body {
  margin: 0;
  padding: 0;
  overflow-x: hidden;
}

.scroll-btn {
  position: fixed;
  /* Posizionamento comune a destra */
  right: calc(env(safe-area-inset-right, 0px) + 16px);
  
  width: 48px;
  height: 48px;
  border-radius: 50%;
  
  /* Uso i colori delle tue variabili per coerenza */
  background: linear-gradient(180deg, rgba(26, 39, 57, 0.45) 0%, rgba(12, 20, 31, 0.48) 100%);
  border: 1px solid var(--border);
  color: var(--accent);
  
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 99999;
  
  /* Reset per Firefox Mobile */
  -moz-appearance: none;
  appearance: none;
  
  /* Transizioni fluide */
  transition: opacity 0.3s ease, transform 0.2s ease !important;
  box-shadow: var(--shadow);
}

/* Freccia SU: la mettiamo più in alto */
.scroll-btn.top {
  bottom: calc(env(safe-area-inset-bottom, 16px) + 70px);
}

/* Freccia GIÙ: la mettiamo vicino al bordo inferiore */
.scroll-btn.bottom {
  bottom: calc(env(safe-area-inset-bottom, 16px) + 10px);
}

.scroll-btn:active {
  transform: scale(0.92);
}

img {
  display: block;
  max-width: 100%;
}

h1,
h2,
p {
  margin-top: 0;
}

.app-shell {
  max-width: 1240px;
  margin: 0 auto;
  padding: 10px;
}

.topbar,
.panel {
  position: relative;
  overflow: visible;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: linear-gradient(180deg, rgba(26, 39, 57, 0.96) 0%, rgba(12, 20, 31, 0.98) 100%);
  box-shadow: var(--shadow);
}

.topbar::before,
.panel::before {
  content: "";
  position: absolute;
  inset: 0 0 auto 0;
  height: 2px;
  background: linear-gradient(90deg, rgba(83, 207, 255, 0) 0%, rgba(83, 207, 255, 0.78) 18%, rgba(83, 207, 255, 0.24) 56%, rgba(83, 207, 255, 0) 100%);
  pointer-events: none;
}

.topbar {
  display: grid;
  gap: 14px;
  padding: 14px;
}

.brand-block {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
}

.brand-logo {
  width: clamp(96px, 18vw, 150px);
  height: auto;
}

.brand-copy {
  flex: 1 1 280px;
}

.eyebrow {
  margin-bottom: 6px;
  font-size: 0.76rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--accent);
}

h1 {
  margin-bottom: 4px;
  font-size: clamp(1.2rem, 2vw, 1.8rem);
  font-weight: 700;
  letter-spacing: 0.02em;
  color: #f7fbff;
}

.subtitle {
  margin-bottom: 0;
  max-width: 52ch;
  color: #a8b9cb;
  line-height: 1.4;
  font-size: 0.9rem;
}

.top-status {
  display: grid;
  gap: 10px;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
}

.status-card {
  padding: 9px 10px;
  border-radius: 12px;
  border: 1px solid rgba(120, 170, 215, 0.16);
  background: linear-gradient(180deg, rgba(22, 33, 49, 0.95) 0%, rgba(12, 18, 28, 0.95) 100%);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.03);
}

.status-title {
  display: block;
  margin-bottom: 5px;
  font-size: 0.68rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: #8fb7d8;
}

.status-label {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 2px 8px;
  border-radius: 8px;
  border: 1px solid rgba(111, 171, 219, 0.2);
  background: linear-gradient(180deg, rgba(7, 16, 26, 0.96) 0%, rgba(4, 11, 19, 0.96) 100%);
  color: #dcecff;
  font-size: 0.74rem;
  font-weight: 300;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.03);
}

.status-label.ready {
  background: rgba(49, 208, 126, 0.16);
  border-color: rgba(49, 208, 126, 0.35);
  color: #d9ffe9;
}

.status-label.running {
  background: rgba(45, 178, 255, 0.18);
  border-color: rgba(45, 178, 255, 0.36);
  color: #dff3ff;
}

.status-label.off {
  background: rgba(255, 176, 32, 0.12);
  border-color: rgba(255, 176, 32, 0.3);
  color: #ffe3b0;
}

.status-label.alarm {
  background: rgba(255, 90, 105, 0.16);
  border-color: rgba(255, 90, 105, 0.34);
  color: #ffe3e8;
}

.dashboard-grid {
  display: grid;
  gap: 12px;
  margin-top: 12px;
}

.panel {
  padding: 14px;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}

.panel-header h2 {
  margin-bottom: 0;
  font-size: 0.98rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #f3fbff;
}

.panel-note {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 4px 10px;
  border-radius: 8px;
  border: 1px solid rgba(84, 193, 255, 0.24);
  background: linear-gradient(180deg, rgba(9, 21, 34, 0.96) 0%, rgba(5, 12, 20, 0.96) 100%);
  color: #8fd4ff;
  font-size: 0.72rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  white-space: nowrap;
}

.panel-header-actions {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
}

.lang-select {
  min-height: 28px;
  padding: 4px 8px;
  border-radius: 8px;
  border: 1px solid rgba(84, 193, 255, 0.24);
  background: linear-gradient(180deg, rgba(9, 21, 34, 0.96) 0%, rgba(5, 12, 20, 0.96) 100%);
  color: #8fd4ff;
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.lang-select:focus {
  outline: none;
  border-color: rgba(84, 193, 255, 0.55);
  box-shadow: 0 0 0 2px rgba(84, 193, 255, 0.14);
}

.control-hero {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 16px;
  align-items: end;
}

.panel-header-control {
  margin-bottom: 10px;
}

.control-copy {
  display: flex;
  flex-direction: column;
  gap: 6px;
  align-self: stretch;
  min-height: 56px;
  text-align: left;
}

.hero-kicker {
  margin: 0 0 8px;
  font-size: 0.8rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--accent);
  text-align: center;
}

.hero-description {
  margin-bottom: 0;
  color: var(--muted);
  line-height: 1.35;
  font-size: 0.76rem;
}

.hero-description.is-hidden {
  display: none;
}

.wash-timer {
  display: flex;
  align-items: baseline;
  justify-content: flex-start;
  gap: 8px;
  margin-top: 2px;
}

.wash-timer.is-hidden {
  display: none;
}

.wash-timer-label {
  color: var(--muted);
  font-size: 0.72rem;
  line-height: 1.2;
}

.wash-timer-value {
  color: #f3fbff;
  font-size: 1rem;
  font-weight: 700;
  line-height: 1.1;
}

.hero-counter-row {
  display: grid;
  grid-template-columns: max-content minmax(0, 1fr);
  gap: 10px;
  align-items: center;
  justify-content: start;
  width: 100%;
  margin-top: auto;
  padding-top: 6px;
}

.hero-counter-label {
  white-space: nowrap;
}

.hero-counter-output {
  min-width: 0;
  width: 100%;
}

.control-button-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-self: end;
  gap: 8px;
  min-width: 120px;
}

.control-headstack {
  display: grid;
  gap: 10px;
  width: 100%;
  justify-items: center;
}

.brand-logo-inline {
  width: clamp(110px, 16vw, 150px);
  height: auto;
}

.control-status {
  width: 100%;
  grid-template-columns: repeat(2, minmax(180px, 1fr));
}

.control-status-wide {
  margin-bottom: 12px;
}

.control-status .status-card {
  width: 100%;
}

.button-caption {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 6px;
  margin: 0;
  min-height: 1.2em;
  font-size: clamp(0.7rem, 1.15vw, 0.82rem);
  font-weight: 700;
  letter-spacing: 0.005em;
  line-height: 1.15;
  color: #f3fbff;
  text-align: left;
}

.button-caption .button-caption-text {
  display: inline-block;
  flex: 0 1 auto;
}

.button-caption .wait-icon {
  display: none;
  width: 0.88rem;
  height: 0.88rem;
  flex: 0 0 auto;
  margin-left: 2px;
  border-radius: 50%;
  border: 2px solid rgba(143, 212, 255, 0.22);
  border-top-color: #8fd4ff;
}

.button-caption.is-waiting .wait-icon {
  display: inline-block;
  animation: waitSpin 0.9s linear infinite;
}

.button {
  --button-fill-1: #ffffff;
  --button-fill-2: #ffffff;
  box-sizing: border-box;
  padding: 2px;
  appearance: none;
  -webkit-appearance: none;
  border-radius: 50%;
  background-color: var(--button-fill-1);
  background-image: url('A_Pulsante_trasparenze04.png');
  background-repeat: no-repeat;
  background-position: center;
  background-size: 112% 112%;
  background-origin: content-box;
  background-clip: content-box;
  height: 96px;
  width: 96px;
  border: 2px solid #7fdaff;
  outline: none;
  opacity: 1;
  color: transparent;
  cursor: not-allowed;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.05),
    0 0 0 1px rgba(127, 218, 255, 0.18),
    0 0 10px rgba(127, 218, 255, 0.10);
  transition: background-color 0.15s ease, transform 0.15s ease, filter 0.15s ease;
}

.button:disabled {
  opacity: 1;
}

.button.state-not-ready {
  --button-fill-1: #ffffff;
  --button-fill-2: #ffffff;
}

.button.state-wifi-error {
  --button-fill-1: #1ed16c;
  --button-fill-2: #101b28;
  animation: buttonBlinkState 0.95s steps(1, end) infinite;
}

.button.state-ready,
.button.state-discharge,
.button.state-production,
.button.state-wash {
  cursor: pointer;
}

.button.state-ready {
  --button-fill-1: #1ed16c;
  --button-fill-2: #1ed16c;
}

.button.state-discharge {
  --button-fill-1: #1f78ff;
  --button-fill-2: #101b28;
  animation: buttonBlinkState 0.85s steps(1, end) infinite;
}

.button.state-production {
  --button-fill-1: #1f78ff;
  --button-fill-2: #1f78ff;
}

.button.state-wash {
  --button-fill-1: #1f78ff;
  --button-fill-2: #1ed16c;
  animation: buttonBlinkState 0.9s steps(1, end) infinite;
}

.button.state-alarm {
  --button-fill-1: #ff3f4d;
  --button-fill-2: #101b28;
  animation: buttonBlinkState 0.75s steps(1, end) infinite;
}

.button:hover {
  filter: brightness(1.08);
}

.button:active {
  transform: scale(0.97);
}

.gauges-grid {
  display: grid;
  gap: 12px;
  align-items: start;
  overflow-anchor: none;
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.gauge-card {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 190px;
  padding: 10px;
  overflow: hidden;
  contain: layout paint;
  isolation: auto;
  border-radius: 12px;
  border: 1px solid rgba(120, 170, 215, 0.16);
  background: linear-gradient(180deg, rgba(20, 31, 46, 0.96) 0%, rgba(8, 15, 24, 0.98) 100%);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.03);
}

.gauge-card canvas {
  display: block;
  flex: 0 0 auto;
  max-width: 100%;
  height: auto;
  overflow-anchor: none;
}

.settings-grid {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
}

.setting-card {
  padding: 12px;
  border-radius: 12px;
  border: 1px solid rgba(120, 170, 215, 0.16);
  background: linear-gradient(180deg, rgba(20, 31, 46, 0.96) 0%, rgba(8, 15, 24, 0.98) 100%);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.03);
}

.setting-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.setting-title {
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 0.88rem;
}

.setting-value {
  margin-bottom: 0;
  color: #ffffff;
  font-size: 1.45rem;
  font-weight: 700;
}

.setting-value small {
  font-size: 0.8rem;
  color: var(--muted);
}

.setting-card-production {
  display: grid;
  gap: 12px;
}

.setting-head {
  display: grid;
  gap: 10px;
}

.setting-head-inline {
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  justify-content: start;
  column-gap: 12px;
}

.setting-head-production-split {
  align-items: center;
}

.setting-title-inline {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 5px;
}

.setting-title-strong {
  margin: 0;
  color: var(--muted);
  font-size: 0.92rem;
  font-weight: 400;
}

.toggle-wrap {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--text);
  font-size: 0.88rem;
  white-space: nowrap;
}

.toggle-wrap-binary {
  gap: 10px;
}

.toggle-side {
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 400;
  letter-spacing: 0.03em;
}

.toggle-side-on {
  color: var(--muted);
}

.production-panel {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
  align-items: start;
}

.production-readout {
  display: grid;
  grid-template-columns: auto minmax(96px, 1fr);
  gap: 10px;
  align-items: center;
}

.production-label {
  color: var(--muted);
  font-size: 0.92rem;
  font-weight: 400;
}

.production-output {
  display: inline-flex;
  align-items: baseline;
  justify-content: center;
  min-height: 42px;
  padding: 8px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: #08101b;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.03);
}

.production-output span {
  color: #ffffff;
  font-size: 1.24rem;
  font-weight: 700;
}

.production-output small {
  margin-left: 6px;
  font-size: 0.78rem;
  color: var(--muted);
}

.production-output-resettable {
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.production-output-main {
  display: inline-flex;
  align-items: baseline;
  min-width: 0;
}

.production-reset-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  padding: 0;
  border: 1px solid rgba(84, 193, 255, 0.24);
  border-radius: 999px;
  background: linear-gradient(180deg, rgba(12, 29, 45, 0.96) 0%, rgba(6, 15, 25, 0.96) 100%);
  color: #8fd4ff;
  cursor: pointer;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.04);
  transition: transform 0.12s ease, border-color 0.12s ease, background 0.12s ease, color 0.12s ease;
}

.production-reset-btn:hover {
  border-color: rgba(84, 193, 255, 0.5);
  background: linear-gradient(180deg, rgba(19, 42, 63, 0.98) 0%, rgba(8, 20, 32, 0.98) 100%);
  color: #dff3ff;
}

.production-reset-btn:active {
  transform: scale(0.95);
}

.production-reset-btn span {
  font-size: 0.88rem;
  line-height: 1;
}

.production-readout.is-hidden {
  display: none;
}

.input-row {
  display: grid;
  grid-template-columns: 1fr minmax(82px, 92px) auto;
  gap: 8px;
  align-items: center;
}

.input-row-threshold-compact {
  display: grid;
  gap: 6px;
  min-width: 130px;
}

.input-row-threshold-compact label {
  text-align: right;
}

.threshold-input-wrap {
  display: inline-grid;
  grid-template-columns: minmax(78px, 88px) auto;
  gap: 6px;
  align-items: center;
}

.threshold-input-wrap-inline {
  margin: 0;
  grid-template-columns: minmax(74px, 82px);
}

.threshold-input-wrap-inline input {
  min-width: 74px;
}

.input-row label,
.toggle-text,
.unit {
  color: var(--muted);
  font-size: 0.88rem;
}

.unit {
  text-align: right;
  min-width: 54px;
}

input[type='number'] {
  width: 100%;
  min-height: 40px;
  padding: 8px 10px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: #08101b;
  color: #ffffff;
  text-align: center;
  font-size: 1rem;
}

input[type='number']:focus {
  outline: none;
  border-color: rgba(45, 178, 255, 0.6);
  box-shadow: 0 0 0 2px rgba(45, 178, 255, 0.15);
}

input[type='number']:disabled {
  opacity: 0.5;
}

input[type='checkbox'] {
  cursor: pointer;
}

.switch {
  position: relative;
  vertical-align: middle;
  height: 1.45rem;
  width: 2.8rem;
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  border-radius: 9999px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  background-color: rgba(100, 116, 139, 0.35);
  transition: all 0.25s ease;
}

.switch:checked {
  background-color: rgba(49, 208, 126, 0.75);
}

.switch::before {
  position: absolute;
  content: "";
  left: -0.05rem;
  top: -0.1rem;
  display: block;
  height: 1.5rem;
  width: 1.5rem;
  border-radius: 9999px;
  background-color: #ffffff;
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.28);
  transition: all 0.25s ease;
}

.switch:checked::before {
  transform: translateX(1.25rem);
}

@keyframes buttonBlinkState {
  0%, 49.9% {
    background-color: var(--button-fill-1);
  }

  50%, 100% {
    background-color: var(--button-fill-2);
  }
}

@keyframes waitSpin {
  from {
    transform: rotate(0deg);
  }

  to {
    transform: rotate(360deg);
  }
}

@media (min-width: 920px) {
  .dashboard-grid {
    grid-template-columns: 0.9fr 1.1fr;
  }

  .panel-settings {
    grid-column: 1 / -1;
  }
}

@media (max-width: 900px) {
  .gauges-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 720px) {
  .app-shell {
    padding: 10px;
  }

  .panel,
  .topbar {
    padding: 12px;
    border-radius: 16px;
  }

  .panel-header-actions {
    width: 100%;
    justify-content: space-between;
  }

  .brand-block,
  .control-hero {
    grid-template-columns: 1fr;
    flex-direction: column;
    align-items: flex-start;
  }

  .control-button-wrap {
    width: 100%;
  }

  .hero-counter-row {
    grid-template-columns: 1fr;
  }

  .control-status {
    grid-template-columns: 1fr;
  }

  .button {
    width: 96px;
    height: 96px;
  }

  .input-row {
    grid-template-columns: 1fr;
  }

  .unit {
    text-align: left;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation: none !important;
    transition: none !important;
  }
}