:root {
  --bg: #0d1218;
  --s1: #141b24;
  --s2: #1b2430;
  --s3: #243041;
  --borda: #2a3646;
  --texto: #e6edf3;
  --suave: #8b98a8;
  --azul: #3b82f6;
  --azul2: #2563eb;
  --verm: #ef4444;
  --verde: #22c55e;
  --amar: #f59e0b;
  --raio: 10px;
  --sombra: 0 6px 24px rgba(0,0,0,.35);
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--texto);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
a { color: var(--azul); text-decoration: none; }
h1, h2, h3 { margin: 0 0 .6em; line-height: 1.2; }
h1 { font-size: 1.4rem; } h2 { font-size: 1.15rem; } h3 { font-size: 1rem; }
.suave { color: var(--suave); }
.pequeno { font-size: .85rem; }
.linha { display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; }
.espaco { flex: 1; }
.oculto { display: none !important; }

/* botões e campos */
button, .botao { font: inherit; border: 1px solid var(--borda); background: var(--s2); color: var(--texto);
  padding: .5rem .9rem; border-radius: 8px; cursor: pointer; display: inline-flex; align-items: center; gap: .4rem; }
button:hover { background: var(--s3); }
button:disabled { opacity: .5; cursor: default; }
button.primario { background: var(--azul2); border-color: var(--azul2); color: #fff; }
button.primario:hover { background: var(--azul); }
button.perigo { background: #7f1d1d; border-color: #991b1b; color: #fff; }
button.perigo:hover { background: var(--verm); }
button.sucesso { background: #14532d; border-color: #166534; color: #fff; }
button.sucesso:hover { background: #15803d; }
button.fantasma { background: transparent; border-color: transparent; color: var(--suave); }
button.fantasma:hover { color: var(--texto); background: var(--s2); }
button.mini, .botao.mini { padding: .25rem .55rem; font-size: .85rem; }
input, select, textarea { font: inherit; background: var(--bg); color: var(--texto); border: 1px solid var(--borda);
  border-radius: 8px; padding: .5rem .65rem; width: 100%; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--azul2); border-color: transparent; }
input[type=checkbox] { width: auto; accent-color: var(--azul); }
label { display: block; font-size: .85rem; color: var(--suave); margin-bottom: .2rem; }
.campo { margin-bottom: .8rem; }
.grade-form { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 0 1rem; }

/* interruptor */
.chave { position: relative; width: 44px; height: 24px; flex: none; }
.chave input { opacity: 0; width: 0; height: 0; }
.chave span { position: absolute; inset: 0; background: var(--s3); border-radius: 24px; cursor: pointer; transition: .2s; }
.chave span::before { content: ""; position: absolute; width: 18px; height: 18px; left: 3px; top: 3px;
  background: #fff; border-radius: 50%; transition: .2s; }
.chave input:checked + span { background: var(--verde); }
.chave input:checked + span::before { transform: translateX(20px); }

/* cartões */
.cartao { background: var(--s1); border: 1px solid var(--borda); border-radius: var(--raio); padding: 1rem; }
.cartao + .cartao { margin-top: 1rem; }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: .8rem; margin-bottom: 1.2rem; }
.kpi { background: var(--s1); border: 1px solid var(--borda); border-radius: var(--raio); padding: .8rem 1rem; }
.kpi b { display: block; font-size: 1.5rem; }
.kpi span { color: var(--suave); font-size: .85rem; }

/* etiquetas */
.tag { display: inline-flex; align-items: center; gap: .3rem; font-size: .78rem; padding: .12rem .5rem;
  border-radius: 999px; background: var(--s3); color: var(--suave); white-space: nowrap; }
.tag.ok { background: rgba(34,197,94,.15); color: #4ade80; }
.tag.erro { background: rgba(239,68,68,.15); color: #f87171; }
.tag.aviso { background: rgba(245,158,11,.15); color: #fbbf24; }
.tag.info { background: rgba(59,130,246,.15); color: #60a5fa; }
.ponto { width: 8px; height: 8px; border-radius: 50%; background: currentColor; display: inline-block; }

/* tabelas */
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: .55rem .6rem; border-bottom: 1px solid var(--borda); vertical-align: middle; }
th { color: var(--suave); font-weight: 500; font-size: .85rem; }
tr.clicavel { cursor: pointer; }
tr.clicavel:hover td { background: var(--s2); }
.tabela-rolagem { overflow-x: auto; }

/* abas */
.abas { display: flex; gap: .2rem; border-bottom: 1px solid var(--borda); margin-bottom: 1rem; overflow-x: auto; }
.abas button { background: none; border: none; border-bottom: 2px solid transparent; border-radius: 0;
  color: var(--suave); padding: .6rem .9rem; white-space: nowrap; }
.abas button.ativa { color: var(--texto); border-bottom-color: var(--azul); }

/* alertas (cartões de evento) */
.alertas { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 1rem; }
.alerta { background: var(--s1); border: 1px solid var(--borda); border-radius: var(--raio); overflow: hidden; }
.alerta.pendente { border-color: #b91c1c; box-shadow: 0 0 0 1px #b91c1c inset; }
.alerta img { width: 100%; aspect-ratio: 16/9; object-fit: cover; display: block; background: #000; cursor: zoom-in; }
.alerta .corpo { padding: .7rem .8rem; }
.alerta .acoes { display: flex; gap: .5rem; margin-top: .6rem; }
.alerta .acoes { gap: .35rem; }
.alerta .acoes button { flex: 1; justify-content: center; padding: .6rem .3rem; font-weight: 600; font-size: .85rem; white-space: nowrap; }
button.autorizado { background: #1e3a8a; border-color: #1e40af; color: #fff; }
button.autorizado:hover { background: var(--azul2); }
.vazio { text-align: center; color: var(--suave); padding: 2.5rem 1rem; }
.vazio .grande { font-size: 2.2rem; display: block; margin-bottom: .3rem; }

/* modal */
.fundo-modal { position: fixed; inset: 0; background: rgba(0,0,0,.65); display: flex; align-items: center;
  justify-content: center; padding: 1rem; z-index: 50; }
.modal { background: var(--s1); border: 1px solid var(--borda); border-radius: 14px; width: min(560px, 100%);
  max-height: calc(100vh - 2rem); overflow: auto; box-shadow: var(--sombra); }
.modal.largo { width: min(1100px, 100%); }
.modal header { display: flex; align-items: center; padding: .9rem 1rem; border-bottom: 1px solid var(--borda);
  position: sticky; top: 0; background: var(--s1); z-index: 2; }
.modal header h2 { margin: 0; flex: 1; }
.modal .conteudo { padding: 1rem; }
.modal footer { display: flex; gap: .5rem; justify-content: flex-end; padding: .8rem 1rem; border-top: 1px solid var(--borda); }

/* aviso flutuante */
#avisos { position: fixed; bottom: 1rem; left: 50%; transform: translateX(-50%); z-index: 99; display: grid; gap: .5rem;
  width: min(420px, calc(100% - 2rem)); }
.aviso-flutuante { background: var(--s3); border: 1px solid var(--borda); padding: .7rem 1rem; border-radius: 10px;
  box-shadow: var(--sombra); animation: sobe .2s ease; }
.aviso-flutuante.erro { border-color: #991b1b; background: #3f1515; }
.aviso-flutuante.ok { border-color: #166534; background: #0f2e1a; }
@keyframes sobe { from { transform: translateY(10px); opacity: 0; } }

/* horários */
.faixa { display: grid; grid-template-columns: 1fr auto; gap: .5rem; padding: .7rem; border: 1px solid var(--borda);
  border-radius: 10px; margin-bottom: .6rem; }
.dias { display: flex; gap: .25rem; flex-wrap: wrap; }
.dias button { padding: .3rem .5rem; font-size: .8rem; min-width: 2.6rem; justify-content: center; }
.dias button.sel { background: var(--azul2); border-color: var(--azul2); color: #fff; }
.horas { display: flex; gap: .5rem; align-items: center; margin-top: .5rem; }
.horas input { width: 9rem; }

/* miniatura de câmera */
.mini-cam { width: 96px; aspect-ratio: 16/9; object-fit: cover; border-radius: 6px; background: var(--s3); display: block; }
.mini-cam.vazia { display: flex; align-items: center; justify-content: center; color: var(--suave); font-size: .7rem; }

/* editor de regras */
.editor { display: grid; grid-template-columns: 1fr 320px; gap: 1rem; }
.editor canvas { width: 100%; background: #000; border-radius: 8px; cursor: crosshair; display: block; touch-action: none; }
.regra-item { border: 1px solid var(--borda); border-radius: 10px; padding: .6rem; margin-bottom: .6rem; }
.regra-item.foco { border-color: var(--amar); }
@media (max-width: 860px) { .editor { grid-template-columns: 1fr; } }

.copiavel { font-family: ui-monospace, monospace; background: var(--bg); border: 1px dashed var(--borda);
  padding: .35rem .6rem; border-radius: 6px; cursor: pointer; user-select: all; }
td button + button { margin-left: .3rem; }

/* gráficos e servidor */
.grafico { background: var(--s1); border: 1px solid var(--borda); border-radius: var(--raio); padding: 1rem; }
.dica-grafico { position: absolute; top: 6px; background: var(--s3); border: 1px solid var(--borda); border-radius: 8px;
  padding: .45rem .6rem; font-size: .8rem; min-width: 150px; pointer-events: none; box-shadow: var(--sombra); }
.grade-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(420px, 1fr)); gap: 1rem; margin-bottom: 1rem; }
@media (max-width: 900px) { .grade-2 { grid-template-columns: 1fr; } }
.medidor { height: 8px; background: var(--s3); border-radius: 999px; overflow: hidden; margin-top: .4rem; }
.medidor i { display: block; height: 100%; border-radius: 999px; background: var(--azul); }
.medidor i.aviso { background: var(--amar); } .medidor i.erro { background: var(--verm); }
.servico { display: inline-flex; align-items: center; gap: .35rem; margin-right: .9rem; font-size: .9rem; }

/* revisão */
.revisao-grade { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: .8rem; }
.revisao-item { background: var(--s1); border: 1px solid var(--borda); border-radius: 10px; overflow: hidden; cursor: pointer; }
.revisao-item:hover { border-color: var(--azul); }
.revisao-item img { width: 100%; aspect-ratio: 16/9; object-fit: cover; display: block; background: #000; }
.revisao-item div { padding: .45rem .6rem; font-size: .82rem; }
.revisor canvas { max-width: 100%; max-height: 58vh; width: auto; height: auto; margin: 0 auto; display: block; background: #000; border-radius: 8px; touch-action: none; }
.atalho { font-size: .72rem; opacity: .7; border: 1px solid currentColor; border-radius: 4px; padding: 0 .3rem; margin-left: .3rem; }
.chips { display: flex; flex-wrap: wrap; gap: .35rem; }
.chips button.sel { background: var(--azul2); border-color: var(--azul2); color: #fff; }
