:root {
  --bg: #f5f6f8;
  --card: #ffffff;
  --text: #1d2330;
  --muted: #6b7385;
  --accent: #1f9d55;
  --off: #c9ced8;
  --error: #c0392b;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12151c;
    --card: #1c212b;
    --text: #e8ebf1;
    --muted: #8d95a8;
    --off: #3a4150;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px;
  max-width: 640px;
  margin: 0 auto;
}

h1 { margin: 0; font-size: 1.6rem; }
h1 span { color: var(--accent); }

main { max-width: 640px; margin: 0 auto; padding: 0 16px 32px; }

#message { color: var(--muted); min-height: 1.2em; }
#message.error { color: var(--error); }

#devices { list-style: none; padding: 0; margin: 0; display: grid; gap: 12px; }

.device {
  display: grid;
  gap: 12px;
  padding: 16px;
  background: var(--card);
  border-radius: 12px;
  box-shadow: 0 1px 3px rgb(0 0 0 / 0.08);
}

.info { display: grid; gap: 2px; min-width: 0; }
.info small { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

button {
  font: inherit;
  border: 0;
  border-radius: 999px;
  padding: 8px 16px;
  cursor: pointer;
  background: var(--off);
  color: var(--text);
}

button:disabled { opacity: 0.6; cursor: wait; }

.power { min-width: 96px; font-weight: 600; }
.power[aria-pressed="true"] { background: var(--accent); color: #fff; }

/* Linha de título dos cartões */
.row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }

/* Controlador de temperatura */
.readings {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 8px;
}

.reading {
  display: grid;
  gap: 2px;
  padding: 10px 12px;
  border-radius: 8px;
  background: var(--bg);
}

.reading .label { font-size: 0.8rem; color: var(--muted); }
.reading .value { font-size: 1.4rem; font-weight: 600; font-variant-numeric: tabular-nums; }
.reading .value.on { color: var(--accent); }

.alerts {
  margin: 0;
  padding: 8px 12px;
  border-radius: 8px;
  color: #fff;
  background: var(--error);
}

details summary { cursor: pointer; color: var(--muted); }

form { display: grid; gap: 12px; margin-top: 12px; }

fieldset {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 8px;
  margin: 0;
  padding: 8px 12px 12px;
  border: 1px solid var(--off);
  border-radius: 8px;
}

legend { padding: 0 4px; font-weight: 600; font-size: 0.9rem; }

label { display: grid; gap: 4px; font-size: 0.85rem; color: var(--muted); }

input {
  font: inherit;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--off);
  border-radius: 6px;
  padding: 6px 8px;
  width: 100%;
}

.save { justify-self: start; background: var(--accent); color: #fff; }

.footer { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.footer small { color: var(--muted); }

button.link { background: none; padding: 4px 0; color: var(--accent); }

/* Botões no topo do cartão (engrenagem + liga/desliga) */
.actions { display: flex; align-items: center; gap: 8px; }

.gear {
  display: inline-grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  color: var(--muted);
  background: var(--bg);
  text-decoration: none;
}

.gear:hover, .gear:focus-visible { color: var(--accent); }

/* Página de configuração */
.back { color: var(--accent); text-decoration: none; font-weight: 600; }

.config #message { margin: 0; }

.form-actions { display: flex; align-items: center; gap: 16px; }
.form-actions .save:disabled { opacity: 0.5; cursor: default; }

/* ===================== Configuração do controlador de temperatura ===================== */
:root { --mode: #c0392b; --value: #16a085; }
@media (prefers-color-scheme: dark) { :root { --mode: #ff7b6b; --value: #3ddbb5; } }

header .title { display: grid; text-align: right; }
header .title small { color: var(--muted); }

.thermo-config {
  display: grid;
  gap: 28px;
  padding-top: 8px;
  text-align: center;
}

.modes, .buttons.two, .grid.two { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.grid.three { display: grid; grid-template-columns: repeat(3, 1fr); gap: 20px 8px; }

.modes span { color: var(--mode); font-size: 1.05rem; }

/* Botões redondos (liga/desliga, modo, alarme) */
.round {
  display: grid;
  justify-items: center;
  gap: 8px;
  padding: 0;
  background: none;
  color: var(--text);
  font-size: 0.9rem;
}

.round .circle {
  display: grid;
  place-items: center;
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: #5f6368;
  color: #fff;
  transition: background 0.2s;
}

.round[aria-pressed="true"] .circle { background: var(--accent); }

.round svg,
.thermo-config .value svg {
  width: 30px;
  height: 30px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* Estado dos sensores */
.status .label { display: block; color: var(--muted); margin-bottom: 6px; }
.status .state { color: var(--value); font-size: 1.05rem; }
.status .state.fault { color: var(--error); font-weight: 600; }

/* Valores ajustáveis */
.thermo-config .value {
  display: grid;
  justify-items: center;
  align-content: start;
  gap: 6px;
  padding: 8px 4px;
  border-radius: 12px;
  background: none;
  color: var(--text);
}

.thermo-config .value:hover, .thermo-config .value:focus-visible { background: var(--card); }
.thermo-config .value svg { width: 24px; height: 24px; }
.thermo-config .value .label { color: var(--muted); font-size: 0.9rem; line-height: 1.25; min-height: 2.5em; }
.thermo-config .value strong { color: var(--value); font-size: 1.35rem; font-variant-numeric: tabular-nums; }

/* Janelas (edição de valor / modo) */
dialog {
  border: 0;
  border-radius: 16px;
  padding: 20px;
  width: min(340px, calc(100vw - 32px));
  background: var(--card);
  color: var(--text);
}

dialog::backdrop { background: rgb(0 0 0 / 0.45); }
dialog h2 { margin: 0 0 16px; font-size: 1.1rem; }
dialog form { margin: 0; display: grid; gap: 12px; }

.stepper { display: grid; grid-template-columns: 44px 1fr auto 44px; align-items: center; gap: 8px; }
.stepper button { width: 44px; height: 44px; padding: 0; font-size: 1.4rem; }
.stepper input { text-align: center; font-size: 1.3rem; }

.options { display: grid; gap: 10px; }
.options label { display: flex; align-items: center; gap: 10px; font-size: 1rem; color: var(--text); }
.options input { width: auto; }

.dialog-actions { display: flex; justify-content: flex-end; gap: 16px; }
p.error { margin: 0; min-height: 1.2em; color: var(--error); font-size: 0.9rem; }

body > #message { max-width: 640px; margin: 16px auto; padding: 0 16px; text-align: center; }

/* Temperaturas ao vivo */
.live-panel { display: grid; gap: 12px; }
.status .temp {
  display: block;
  color: var(--value);
  font-size: 1.6rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.status .state { display: block; margin-top: 4px; font-size: 0.85rem; }

.live-indicator {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  margin: 0;
  font-size: 0.8rem;
  color: var(--muted);
}
.device .live-indicator { justify-content: flex-start; }

.live-indicator .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  animation: pulse 2s ease-in-out infinite;
}
.live-indicator.offline .dot { background: var(--error); animation: none; }

@keyframes pulse { 50% { opacity: 0.3; } }
@media (prefers-reduced-motion: reduce) { .live-indicator .dot { animation: none; } }

/* ===================== Disjuntor ===================== */
/* Selo de estado — mesmo formato do botão "Ligado", mas sem ação */
.badge {
  display: inline-block;
  min-width: 96px;
  padding: 8px 16px;
  border-radius: 999px;
  text-align: center;
  font-weight: 600;
  background: var(--off);
  color: var(--text);
  white-space: nowrap;
}
.badge.on { background: var(--accent); color: #fff; }

.breaker-config { display: grid; gap: 28px; padding-top: 8px; }
.breaker-config h2 { margin: 0 0 12px; font-size: 1rem; color: var(--muted); font-weight: 600; }

.hero { display: grid; justify-items: center; gap: 6px; text-align: center; }
.hero .label { color: var(--muted); }
.hero strong { font-size: 2.6rem; color: var(--value); font-variant-numeric: tabular-nums; }
.load-state { color: var(--muted); }
.load-state.on { color: var(--accent); font-weight: 600; }

table.phases {
  width: 100%;
  border-collapse: collapse;
  font-variant-numeric: tabular-nums;
  background: var(--card);
  border-radius: 12px;
  overflow: hidden;
}
table.phases th, table.phases td { padding: 10px 8px; text-align: right; }
table.phases thead th { font-size: 0.8rem; color: var(--muted); font-weight: 600; }
table.phases tbody th { text-align: left; color: var(--muted); }
table.phases tbody tr { border-top: 1px solid var(--bg); }
table.phases td { color: var(--value); font-weight: 600; }

.breaker-config .status { text-align: center; }
.breaker-config .status .temp { font-size: 1.3rem; }
.breaker-config .status .temp.fault { color: var(--error); }

.commands { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.command { padding: 12px 8px; font-weight: 600; border-radius: 10px; }
.command.on { background: var(--accent); color: #fff; }
.command.off { background: var(--error); color: #fff; }
.command.test { background: var(--off); }

.hint { margin: 12px 0 0; color: var(--muted); font-size: 0.85rem; line-height: 1.45; }

button.danger { background: var(--error); color: #fff; }
