:root {
  --bg: #0b1118; --panel: #121b26; --panel-2: #172332; --line: #223244; --text: #e6edf5; --muted: #8aa0b6;
  --accent: #38bdf8; --good: #34d399; --ok: #a3e635; --warn: #fbbf24; --bad: #f87171; --na: #64748b;
  --radius: 12px; --shadow: 0 1px 2px rgba(0,0,0,.35);
  color-scheme: dark;
}
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bg: #f3f6fa; --panel: #ffffff; --panel-2: #f1f5f9; --line: #d9e2ec; --text: #0f1b2a; --muted: #5b6f84;
    --accent: #0284c7; --good: #059669; --ok: #65a30d; --warn: #b45309; --bad: #dc2626; --na: #94a3b8;
    --shadow: 0 1px 2px rgba(15,27,42,.08); color-scheme: light;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, select, textarea { font: inherit; color: inherit; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .92em; }
.muted { color: var(--muted); }
.small { font-size: .85em; }
.right { margin-left: auto; }
.hidden { display: none !important; }

/* barra superior */
.topbar { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 6px; padding: 0 14px;
  height: 54px; background: var(--panel); border-bottom: 1px solid var(--line); overflow-x: auto; }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; letter-spacing: .2px; margin-right: 10px; color: var(--text); white-space: nowrap; }
.brand svg { width: 26px; height: 26px; }
.nav a { color: var(--muted); padding: 8px 11px; border-radius: 8px; white-space: nowrap; font-weight: 500; }
.nav a:hover { background: var(--panel-2); text-decoration: none; color: var(--text); }
.nav a.active { color: var(--text); background: var(--panel-2); }
.userbox { display: flex; align-items: center; gap: 8px; white-space: nowrap; }

main { max-width: 1280px; margin: 0 auto; padding: 18px 14px 60px; }
h1 { font-size: 1.35rem; margin: 0; }
h2 { font-size: 1.05rem; margin: 26px 0 10px; display: flex; align-items: center; gap: 8px; }
.pagehead { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }

/* componentes */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.pad { padding: 14px 16px; }
.btn { background: var(--panel-2); border: 1px solid var(--line); padding: 8px 13px; border-radius: 9px; cursor: pointer; font-weight: 600; }
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); color: #04121c; border-color: transparent; }
.btn.danger { color: var(--bad); }
.btn.sm { padding: 4px 9px; font-size: .85em; }
.btn:disabled { opacity: .55; cursor: wait; }
input, select, textarea { width: 100%; background: var(--panel-2); border: 1px solid var(--line); border-radius: 9px; padding: 9px 11px; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
input[type=checkbox] { width: auto; }
label.field { display: block; margin-bottom: 12px; }
label.field > span { display: block; font-size: .85em; color: var(--muted); margin-bottom: 4px; }
label.check { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; }
.help { font-size: .8em; color: var(--muted); margin-top: 3px; }
.search { max-width: 280px; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }
.stat { padding: 14px 16px; }
.stat .n { font-size: 2rem; font-weight: 700; line-height: 1.1; }
.stat .l { color: var(--muted); font-size: .85em; }
.stat.good .n { color: var(--good); } .stat.bad .n { color: var(--bad); } .stat.warn .n { color: var(--warn); }
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.chip { background: var(--panel); border: 1px solid var(--line); border-radius: 999px; padding: 4px 11px; font-size: .85em; color: var(--muted); }
.chip b { color: var(--text); }

.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; background: var(--na); flex: none; }
.dot.online { background: var(--good); box-shadow: 0 0 0 3px color-mix(in srgb, var(--good) 22%, transparent); }
.dot.offline { background: var(--bad); box-shadow: 0 0 0 3px color-mix(in srgb, var(--bad) 25%, transparent); animation: pulse 1.6s infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 0 6px color-mix(in srgb, var(--bad) 8%, transparent); } }
@media (prefers-reduced-motion: reduce) { .dot.offline { animation: none; } }

.badge { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: .75em; font-weight: 600; background: var(--panel-2);
  border: 1px solid var(--line); color: var(--muted); text-transform: uppercase; letter-spacing: .4px; }
.badge.good { color: var(--good); } .badge.bad { color: var(--bad); } .badge.warn { color: var(--warn); }

/* offline */
.alert { border-left: 4px solid var(--bad); }
.offline-item { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; padding: 12px 16px; border-top: 1px solid var(--line); }
.offline-item:first-child { border-top: 0; }
.offline-item .cause { grid-column: 2; color: var(--text); background: var(--panel-2); border-radius: 8px; padding: 8px 10px; font-size: .9em; }
.warn-item { padding: 8px 16px; border-top: 1px solid var(--line); display: flex; gap: 10px; align-items: baseline; flex-wrap: wrap; }
.warn-item:first-child { border-top: 0; }

/* setoriais */
.sectors { display: grid; grid-template-columns: repeat(auto-fill, minmax(330px, 1fr)); gap: 14px; }
.sector.stale { opacity: .72; }
.sector-head { display: flex; align-items: center; gap: 10px; padding: 12px 14px; border-bottom: 1px solid var(--line); }
.sector-head .title { font-weight: 700; }
.sector-body { max-height: 300px; overflow: auto; }
.client { display: grid; grid-template-columns: auto 1fr 120px; align-items: center; gap: 4px 10px; padding: 7px 14px; border-top: 1px solid var(--line); }
.client:first-child { border-top: 0; }
.client .nm { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.client.off { background: color-mix(in srgb, var(--bad) 7%, transparent); }
.empty { padding: 18px; color: var(--muted); text-align: center; }

.sig { display: flex; align-items: center; gap: 7px; font-variant-numeric: tabular-nums; min-width: 0; }
.sig .bar { flex: 1; height: 6px; background: var(--panel-2); border-radius: 3px; overflow: hidden; min-width: 34px; }
.sig .bar i { display: block; height: 100%; background: var(--na); }
.sig.good .bar i { background: var(--good); } .sig.ok .bar i { background: var(--ok); }
.sig.warn .bar i { background: var(--warn); } .sig.bad .bar i { background: var(--bad); }
.sig.good b { color: var(--good); } .sig.ok b { color: var(--ok); } .sig.warn b { color: var(--warn); } .sig.bad b { color: var(--bad); }
.sig b { font-weight: 600; white-space: nowrap; }

/* tabelas */
.tablewrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 9px 14px; border-top: 1px solid var(--line); vertical-align: middle; }
th { color: var(--muted); font-size: .78em; text-transform: uppercase; letter-spacing: .5px; border-top: 0; white-space: nowrap; }
tr.click { cursor: pointer; } tr.click:hover td { background: var(--panel-2); }
td.actions { white-space: nowrap; text-align: right; }
td.actions .btn { margin-left: 4px; }

.grid-devices { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 10px; }
.devtile { display: flex; align-items: center; gap: 10px; padding: 11px 14px; cursor: pointer; color: var(--text); }
.devtile:hover { border-color: var(--accent); text-decoration: none; }
.devtile .nm { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* detalhe */
.hero { display: flex; gap: 14px; align-items: center; flex-wrap: wrap; padding: 16px; }
.hero .name { font-size: 1.35rem; font-weight: 700; }
.kv { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 1px; background: var(--line); border-radius: var(--radius); overflow: hidden; border: 1px solid var(--line); }
.kv > div { background: var(--panel); padding: 10px 14px; }
.kv .k { color: var(--muted); font-size: .78em; text-transform: uppercase; letter-spacing: .4px; }
.kv .v { font-weight: 600; margin-top: 2px; word-break: break-word; }
.bigsig { padding: 16px; }
.bigsig .num { font-size: 2.4rem; font-weight: 800; line-height: 1; }
.hints { margin: 0; padding: 0; list-style: none; }
.hints li { padding: 10px 16px; border-top: 1px solid var(--line); display: flex; gap: 10px; }
.hints li:first-child { border-top: 0; }
.hints .ico { flex: none; width: 1.2em; text-align: center; }
.cols { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 14px; align-items: start; }
.tl { padding: 0; margin: 0; list-style: none; }
.tl li { padding: 8px 16px; border-top: 1px solid var(--line); display: flex; gap: 10px; }
.tl li:first-child { border-top: 0; }

/* login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login .box { width: 100%; max-width: 380px; padding: 26px; }
.login h1 { display: flex; align-items: center; gap: 10px; margin-bottom: 4px; }
.err { color: var(--bad); font-size: .9em; min-height: 1.3em; margin: 4px 0 10px; }

/* modal + toast */
dialog { border: 1px solid var(--line); border-radius: 14px; background: var(--panel); color: var(--text); padding: 0; width: min(560px, 94vw); max-height: 92vh; }
dialog::backdrop { background: rgba(2,8,14,.62); }
dialog form, dialog .dlg { padding: 18px 20px; max-height: 90vh; overflow: auto; }
dialog h3 { margin: 0 0 14px; }
.dlg-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 8px; }
.checklist { display: grid; gap: 6px; margin-bottom: 12px; max-height: 160px; overflow: auto; background: var(--panel-2); padding: 8px 10px; border-radius: 9px; border: 1px solid var(--line); }
#toast { position: fixed; left: 50%; bottom: 22px; transform: translateX(-50%) translateY(20px); background: var(--panel-2);
  border: 1px solid var(--line); padding: 10px 16px; border-radius: 10px; opacity: 0; pointer-events: none; transition: .25s; z-index: 50; max-width: 90vw; }
#toast.show { opacity: 1; transform: translateX(-50%); }
#toast.err { border-color: var(--bad); color: var(--bad); }
.progress { height: 6px; background: var(--panel-2); border-radius: 3px; overflow: hidden; margin-top: 6px; min-width: 120px; }
.progress i { display: block; height: 100%; background: var(--accent); transition: width .3s; }

@media (max-width: 640px) {
  main { padding: 12px 10px 50px; }
  .client { grid-template-columns: auto 1fr 100px; }
  th, td { padding: 8px 10px; }
  .stat .n { font-size: 1.6rem; }
}
