:root {
  --bg: #faf8f5;
  --bg-card: #ffffff;
  --text: #2d2a26;
  --text-muted: #797167;
  --border: #e6e0d8;
  --primary: #d97706;
  --primary-hover: #b45309;
  --accent: #2563eb;
  --red: #dc2626;
  --red-bg: #fee2e2;
  --green: #16a34a;
  --green-bg: #dcfce7;
  --shadow: 0 1px 3px rgba(0,0,0,0.05);
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background-color: var(--bg);
  color: var(--text);
  line-height: 1.4;
  padding: 12px;
  max-width: 500px;
  margin: 0 auto;
}

header {
  margin-bottom: 12px;
}

h1 {
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--text);
}

.eta-dati {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 2px;
}

.avviso-rosso {
  background-color: var(--red-bg);
  color: var(--red);
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 0.85rem;
  font-weight: 600;
  margin-bottom: 14px;
  display: none;
}

.stato-box {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px;
  margin-bottom: 12px;
  box-shadow: var(--shadow);
}

.stato-titolo {
  font-size: 1.2rem;
  font-weight: 700;
  margin-bottom: 2px;
}

.stato-acceso { color: var(--green); }
.stato-spento { color: var(--text-muted); }
.stato-attesa { color: var(--primary); }
.stato-non-lo-so { color: var(--red); }

.tessere-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 12px;
}

.tessera {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 4px;
  text-align: center;
  box-shadow: var(--shadow);
  overflow: hidden;
}

.tessera-nome {
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  margin-bottom: 2px;
}

.tessera-valore {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--text);
  white-space: nowrap;
}

.tessera-sub {
  font-size: 0.65rem;
  color: var(--text-muted);
  margin-top: 2px;
}

.decisione-box {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
  margin-bottom: 12px;
  box-shadow: var(--shadow);
}

.decisione-titolo {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.decisione-motivo {
  font-size: 0.9rem;
  color: var(--text);
  margin-bottom: 4px;
  overflow-wrap: break-word;
}

.decisione-spegnimento {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--primary);
}

.controlli-box {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
  margin-bottom: 12px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  box-shadow: var(--shadow);
}

.automazione-riga {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.automazione-label {
  font-weight: 600;
  font-size: 0.9rem;
  white-space: nowrap;
}

.tri-switch {
  display: flex;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 2px;
}

@media (max-width: 440px) {
  body {
    padding: 10px;
  }
  .automazione-riga {
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
  }
  .tri-switch {
    width: 100%;
    display: flex;
  }
  .tri-btn {
    flex: 1;
    text-align: center;
    padding: 6px 2px;
    font-size: 0.75rem;
  }
  .tessere-grid {
    gap: 6px;
  }
  .tessera-valore {
    font-size: 0.95rem;
  }
}

.tri-btn {
  border: none;
  background: none;
  padding: 5px 8px;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-muted);
  border-radius: 16px;
  cursor: pointer;
  transition: all 0.2s;
}

.tri-btn.active {
  background: var(--bg-card);
  color: var(--text);
  box-shadow: 0 1px 2px rgba(0,0,0,0.1);
}

.btn-premi {
  width: 100%;
  padding: 11px;
  background-color: var(--primary);
  color: #fff;
  border: none;
  border-radius: 10px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: background-color 0.2s;
}

.btn-premi:hover {
  background-color: var(--primary-hover);
}

.btn-notifiche {
  width: 100%;
  padding: 9px;
  background-color: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  margin-bottom: 12px;
  display: none;
}

.grafici-sezione {
  margin-top: 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.grafico-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
  box-shadow: var(--shadow);
}

.grafico-titolo {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 6px;
}

.grafico-svg {
  width: 100%;
  height: 100px;
  display: block;
}

.moduli-batteria {
  margin-top: 8px;
  padding-top: 6px;
  border-top: 1px dashed var(--border);
  font-size: 0.75rem;
  color: var(--text-muted);
  display: flex;
  justify-content: space-between;
}

.moduli-titolo {
  font-weight: 600;
}

/* Modale Conferma */
.modale-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0,0,0,0.4);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 100;
}

.modale-contenuto {
  background: #ffffff;
  border-radius: 14px;
  padding: 20px;
  max-width: 360px;
  width: 100%;
  box-shadow: 0 4px 16px rgba(0,0,0,0.15);
}

.modale-testo {
  font-size: 0.95rem;
  color: var(--text);
  margin-bottom: 20px;
  line-height: 1.4;
}

.modale-azioni {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.btn-annulla {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 8px 16px;
  border-radius: 8px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
}

.btn-conferma {
  background: var(--primary);
  border: none;
  color: #fff;
  padding: 8px 16px;
  border-radius: 8px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
}

/* La modalità scelta deve saltare all'occhio */
.tri-btn.active {
  background: #d97706;
  color: #fff;
}
