*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  background: #0a0a0a;
  color: #d0d0d0;
  font-family: 'Courier New', Courier, monospace;
  font-size: 13px;
  min-height: 100vh;
  padding: 12px;
}

#macchina {
  max-width: 1300px;
  margin: 0 auto;
  border: 2px solid #555;
  background: #111;
}

/* HEADER */
#header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 14px;
  border-bottom: 2px solid #555;
  background: #0a0a0a;
}

#header h1 {
  font-size: 15px;
  letter-spacing: 3px;
  color: #fff;
  font-weight: bold;
}

#header-right {
  display: flex;
  align-items: center;
  gap: 20px;
}

#stato-label {
  font-size: 12px;
  letter-spacing: 2px;
}

#stato-label span {
  color: #555;
}

#stato-label span.on { color: #00ff88; }
#stato-label span.warn { color: #ffaa00; }
#stato-label span.alarm { color: #ff3333; animation: blink 0.5s infinite; }

#allarmi-btn {
  border: 1px solid #555;
  background: #1a1a1a;
  color: #888;
  font-family: inherit;
  font-size: 12px;
  padding: 3px 10px;
  cursor: pointer;
  letter-spacing: 1px;
}

#allarmi-btn.active {
  border-color: #ff3333;
  color: #ff3333;
  animation: blink 0.5s infinite;
}

@keyframes blink { 50% { opacity: 0.3; } }

/* SEZIONI PANNELLO */
#pannello {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  border-bottom: 2px solid #555;
}

.sezione {
  border-right: 1px solid #333;
  padding: 10px;
  position: relative;
}

.sezione:last-child { border-right: none; }

.sezione-header {
  font-size: 11px;
  letter-spacing: 2px;
  color: #fff;
  border-bottom: 1px solid #333;
  padding-bottom: 5px;
  margin-bottom: 8px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.sezione-status {
  font-size: 10px;
  letter-spacing: 1px;
}

.sezione-status.inattiva { color: #444; }
.sezione-status.attiva   { color: #00ff88; }
.sezione-status.warning  { color: #ffaa00; }
.sezione-status.alarm    { color: #ff3333; }

/* overlay quando sezione inattiva */
.sezione.locked::after {
  content: '';
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.55);
  pointer-events: none;
  z-index: 5;
}

/* SWITCH */
.switch-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}

.switch-label {
  font-size: 11px;
  color: #aaa;
  min-width: 70px;
}

.switch-btn {
  width: 36px;
  height: 18px;
  border: 1px solid #555;
  background: #1a1a1a;
  cursor: pointer;
  position: relative;
  flex-shrink: 0;
}

.switch-btn::after {
  content: '';
  position: absolute;
  top: 2px; left: 2px;
  width: 12px; height: 12px;
  background: #444;
  transition: left 0.1s, background 0.1s;
}

.switch-btn.on::after {
  left: 20px;
  background: #00ff88;
}

.switch-btn.disabled { opacity: 0.3; cursor: not-allowed; }

.switch-indicator {
  font-size: 10px;
  color: #444;
}
.switch-indicator.on { color: #00ff88; }

/* GAUGE LETTURA */
.gauge-row {
  display: flex;
  justify-content: space-between;
  margin-top: 10px;
  border-top: 1px solid #222;
  padding-top: 6px;
  gap: 6px;
}

.gauge-item {
  flex: 1;
  text-align: center;
}

.gauge-label {
  font-size: 10px;
  color: #555;
  letter-spacing: 1px;
  display: block;
  margin-bottom: 2px;
}

.gauge-value {
  font-size: 14px;
  color: #ccc;
  font-weight: bold;
  display: block;
}

.gauge-value.ok   { color: #00ff88; }
.gauge-value.warn { color: #ffaa00; }
.gauge-value.crit { color: #ff3333; }
.gauge-value.off  { color: #333; }

/* SLIDER LEVA */
.control-row {
  margin-bottom: 8px;
}

.control-label {
  font-size: 10px;
  color: #777;
  letter-spacing: 1px;
  display: flex;
  justify-content: space-between;
  margin-bottom: 3px;
}

.control-label span { color: #aaa; }

input[type=range] {
  width: 100%;
  height: 14px;
  -webkit-appearance: none;
  appearance: none;
  background: #222;
  outline: none;
  border: 1px solid #444;
  cursor: pointer;
}

input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 10px;
  height: 14px;
  background: #aaa;
  cursor: pointer;
}

input[type=range]:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

/* KNOB (frecce + valore) */
.knob-row {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 8px;
}

.knob-label {
  font-size: 10px;
  color: #777;
  letter-spacing: 1px;
  min-width: 55px;
}

.knob-ctrl {
  display: flex;
  align-items: center;
  gap: 4px;
  flex: 1;
}

.knob-btn {
  width: 18px; height: 18px;
  border: 1px solid #555;
  background: #1a1a1a;
  color: #aaa;
  font-size: 12px;
  cursor: pointer;
  line-height: 16px;
  text-align: center;
  user-select: none;
  flex-shrink: 0;
}

.knob-btn:active { background: #2a2a2a; }
.knob-btn.disabled { opacity: 0.3; cursor: not-allowed; }

.knob-display {
  flex: 1;
  text-align: center;
  font-size: 13px;
  color: #ccc;
  border: 1px solid #333;
  background: #0d0d0d;
  padding: 1px 0;
}

/* FASE SELECTOR */
.fase-row {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-bottom: 8px;
}

.fase-label {
  font-size: 10px;
  color: #777;
  letter-spacing: 1px;
  min-width: 40px;
}

.fase-btn {
  flex: 1;
  padding: 3px 0;
  border: 1px solid #444;
  background: #1a1a1a;
  color: #666;
  font-family: inherit;
  font-size: 12px;
  cursor: pointer;
  letter-spacing: 1px;
}

.fase-btn.selected {
  background: #222;
  color: #fff;
  border-color: #aaa;
}

.fase-btn.disabled { opacity: 0.3; cursor: not-allowed; }

/* BARRA USCITA */
#uscita-section {
  padding: 10px 14px;
  border-bottom: 1px solid #333;
}

#uscita-title {
  font-size: 11px;
  letter-spacing: 2px;
  color: #888;
  margin-bottom: 6px;
  display: flex;
  justify-content: space-between;
}

#uscita-title span { color: #fff; }

#uscita-bar-outer {
  width: 100%;
  height: 20px;
  border: 1px solid #444;
  background: #0d0d0d;
  position: relative;
}

#uscita-bar-inner {
  height: 100%;
  width: 0%;
  background: #00ff88;
  transition: width 0.3s, background 0.3s;
}

#uscita-bar-inner.warn { background: #ffaa00; }
#uscita-bar-inner.crit { background: #ff3333; }

#uscita-stats {
  display: flex;
  justify-content: space-between;
  margin-top: 4px;
  font-size: 11px;
  color: #555;
}

#uscita-stats span { color: #888; }

/* LOG */
#log-section {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0;
}

#log-area {
  padding: 8px 12px;
  border-right: 1px solid #333;
  min-height: 120px;
  max-height: 160px;
  overflow-y: auto;
}

#log-area::-webkit-scrollbar { width: 4px; }
#log-area::-webkit-scrollbar-track { background: #111; }
#log-area::-webkit-scrollbar-thumb { background: #444; }

.log-line {
  font-size: 11px;
  line-height: 1.6;
  color: #777;
}

.log-line .ts { color: #444; margin-right: 6px; }
.log-line.info { color: #777; }
.log-line.warn { color: #ffaa00; }
.log-line.alarm { color: #ff3333; font-weight: bold; }
.log-line.ok    { color: #00ff88; }

#log-controls {
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  justify-content: center;
  align-items: flex-end;
  min-width: 160px;
}

#btn-reset {
  border: 1px solid #666;
  background: #1a1a1a;
  color: #aaa;
  font-family: inherit;
  font-size: 11px;
  letter-spacing: 2px;
  padding: 6px 14px;
  cursor: pointer;
  width: 100%;
}

#btn-reset:hover { border-color: #ff3333; color: #ff3333; }

#btn-storico {
  border: 1px solid #333;
  background: #0d0d0d;
  color: #555;
  font-family: inherit;
  font-size: 10px;
  letter-spacing: 1px;
  padding: 4px 10px;
  cursor: pointer;
  width: 100%;
}

#btn-storico:hover { color: #888; }

/* STORICO */
#storico-section {
  border-top: 1px solid #222;
  padding: 8px 14px;
  display: none;
}

#storico-section.visible { display: block; }

#storico-title {
  font-size: 10px;
  color: #444;
  letter-spacing: 2px;
  margin-bottom: 6px;
}

.storico-item {
  font-size: 11px;
  color: #555;
  border-left: 2px solid #333;
  padding-left: 8px;
  margin-bottom: 6px;
  line-height: 1.5;
}

.storico-item .storico-ts { color: #ff3333; }

/* Animazione shutdown */
body.shutdown-anim #macchina {
  animation: shutdownFlicker 1.5s forwards;
}

@keyframes shutdownFlicker {
  0%   { opacity: 1; filter: brightness(1); }
  20%  { opacity: 0.3; filter: brightness(0.2); }
  35%  { opacity: 0.9; filter: brightness(0.8); }
  50%  { opacity: 0.1; filter: brightness(0.05); }
  70%  { opacity: 0.6; filter: brightness(0.4); }
  100% { opacity: 1; filter: brightness(1); }
}
