:root {
  --fundo: #f1f5f9; --cartao: #ffffff; --texto: #0f172a; --sutil: #64748b;
  --borda: #e2e8f0; --acento: #2563eb; --ligado: #f59e0b; --ligado-fundo: #fef3c7;
  --erro: #dc2626; --sombra: 0 1px 3px rgb(15 23 42 / .08);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --fundo: #0b1120; --cartao: #162033; --texto: #e2e8f0; --sutil: #94a3b8;
    --borda: #1e2b44; --acento: #60a5fa; --ligado: #fbbf24; --ligado-fundo: #3a2e10;
    --erro: #f87171; --sombra: none;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--fundo); color: var(--texto); min-height: 100dvh;
  padding: env(safe-area-inset-top) 16px env(safe-area-inset-bottom);
}
[hidden] { display: none !important; }
h1, h2, h3 { margin: 0; line-height: 1.2; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.15rem; }
.sutil { color: var(--sutil); margin: 2px 0 0; font-size: .9rem; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; border-radius: 10px; border: 0; padding: 9px 14px; }
.primario { background: var(--acento); color: #fff; font-weight: 600; }
.fantasma { background: transparent; color: var(--sutil); }
.fantasma:hover { color: var(--texto); }
input, select {
  width: 100%; padding: 10px 12px; margin-top: 4px; border-radius: 10px;
  border: 1px solid var(--borda); background: var(--fundo);
}
label { display: block; margin-bottom: 14px; font-size: .9rem; color: var(--sutil); }
.erro { color: var(--erro); min-height: 1.2em; margin: 0 0 10px; font-size: .9rem; }
.cartao { background: var(--cartao); border: 1px solid var(--borda); border-radius: 16px; box-shadow: var(--sombra); }

.login { min-height: 100dvh; display: grid; place-items: center; }
.login-cartao { width: min(360px, 100%); padding: 28px 24px; text-align: center; }
.login-cartao label { text-align: left; }
.login-cartao button { width: 100%; padding: 12px; }
.logo { width: 56px; height: 56px; margin-bottom: 10px; }
.login-cartao h1 { margin-bottom: 22px; font-size: 1.3rem; }

#tela-app { max-width: 960px; margin: 0 auto; padding-bottom: 32px; }
.topo { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 20px 0 16px; flex-wrap: wrap; }
.topo nav { display: flex; gap: 2px; }
.aviso { background: var(--ligado-fundo); border-radius: 10px; padding: 10px 14px; margin: 0 0 16px; }

.area { margin-bottom: 24px; }
.area h2 { font-size: .8rem; text-transform: uppercase; letter-spacing: .06em; color: var(--sutil); margin-bottom: 10px; }
.grade { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 10px; }
.disp {
  padding: 14px; display: flex; flex-direction: column; gap: 10px; min-height: 112px;
  text-align: left; transition: background .15s, border-color .15s;
}
button.disp { font-weight: 400; }
.disp.ligado { background: var(--ligado-fundo); border-color: var(--ligado); }
.disp.ocupado { opacity: .6; pointer-events: none; }
.disp.indisponivel { opacity: .5; }
.disp .icone { width: 28px; height: 28px; color: var(--sutil); }
.disp.ligado .icone { color: var(--ligado); }
.disp .nome { font-weight: 600; }
.disp .estado { color: var(--sutil); font-size: .85rem; }
.disp .linha { display: flex; gap: 6px; flex-wrap: wrap; }
.disp .linha button { background: var(--fundo); border: 1px solid var(--borda); padding: 6px 10px; flex: 1; }
.disp input[type=range] { padding: 0; margin: 0; accent-color: var(--ligado); }
.vazio { padding: 32px 20px; text-align: center; color: var(--sutil); }

dialog {
  border: 1px solid var(--borda); border-radius: 16px; background: var(--cartao); color: var(--texto);
  padding: 20px; width: min(420px, calc(100vw - 32px));
}
dialog::backdrop { background: rgb(0 0 0 / .45); }
#dlg-registro { width: min(760px, calc(100vw - 32px)); }
.dlg-topo { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
#dlg-senha h2 { margin-bottom: 16px; }
.botoes { display: flex; justify-content: flex-end; gap: 8px; }
.tabela-rolagem { max-height: 65vh; overflow: auto; }
table { width: 100%; border-collapse: collapse; font-size: .88rem; }
th, td { padding: 7px 8px; text-align: left; border-bottom: 1px solid var(--borda); vertical-align: top; }
th { color: var(--sutil); font-weight: 500; position: sticky; top: 0; background: var(--cartao); }
td.negado { color: var(--erro); }
.disp .alvo {
  background: none; padding: 0; margin: 0; border-radius: 0; text-align: left;
  display: flex; flex-direction: column; gap: 10px; flex: 1; width: 100%;
}
