:root {
  --bg: #f4f6fa; --panel: #ffffff; --text: #18202f; --muted: #667085; --line: #e3e7ee;
  --side: #111827; --side-text: #cbd5e1; --side-active: #1f2937;
  --primary: #2563eb; --primary-ink: #fff;
  --ok: #15803d; --ok-bg: #dcfce7; --bad: #b91c1c; --bad-bg: #fee2e2;
  --warn: #a16207; --warn-bg: #fef3c7; --info: #1d4ed8; --info-bg: #dbeafe;
  --sec: #7c3aed; --sec-bg: #ede9fe; --mutedbg: #eef1f5;
  --radius: 10px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1020; --panel: #121a2b; --text: #e6eaf2; --muted: #93a0b5; --line: #24304a;
    --side: #0a0f1c; --side-active: #18223a;
    --ok: #4ade80; --ok-bg: #12301f; --bad: #f87171; --bad-bg: #3a1518;
    --warn: #facc15; --warn-bg: #352a0c; --info: #93c5fd; --info-bg: #172a4d;
    --sec: #c4b5fd; --sec-bg: #2a2150; --mutedbg: #1b2438;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, Ubuntu, sans-serif; background: var(--bg); color: var(--text); }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
code, .mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .92em; }
.small { font-size: .85em; } .muted { color: var(--muted); } .nowrap { white-space: nowrap; }
.ok-text { color: var(--ok); } .err-text { color: var(--bad); }
h1 { font-size: 1.35rem; margin: 0; display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; }
h2 { font-size: 1.05rem; margin: 0 0 .8rem; }

/* Layout */
.app { display: grid; grid-template-columns: 240px 1fr; min-height: 100vh; }
.sidebar { background: var(--side); color: var(--side-text); display: flex; flex-direction: column; padding: 1rem .75rem; position: sticky; top: 0; height: 100vh; }
.brand { display: flex; align-items: center; gap: .6rem; font-size: 1.05rem; color: #fff; padding: .25rem .5rem 1.2rem; }
.brand img { width: 28px; height: 28px; }
.brand.big { justify-content: center; font-size: 1.3rem; color: var(--text); padding-bottom: 1rem; }
.sidebar nav { display: flex; flex-direction: column; gap: .15rem; flex: 1; }
.sidebar nav a { color: var(--side-text); padding: .55rem .75rem; border-radius: 8px; }
.sidebar nav a:hover { background: var(--side-active); text-decoration: none; color: #fff; }
.sidebar nav a.active { background: var(--primary); color: #fff; }
.logout { display: flex; align-items: center; justify-content: space-between; gap: .5rem; border-top: 1px solid #1f2937; padding-top: .8rem; }
.who { font-size: .85rem; overflow: hidden; text-overflow: ellipsis; }
.content { padding: 1.25rem 1.5rem 3rem; min-width: 0; }
.topbar { display: flex; align-items: center; gap: 1rem; margin-bottom: 1.1rem; flex-wrap: wrap; }
.topbar .actions { margin-left: auto; display: flex; gap: .5rem; }
.nav-toggle, .hamburger, .nav-backdrop { display: none; }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.1rem 1.2rem; margin-bottom: 1.1rem; }
.card.narrow { max-width: 720px; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 1.1rem; }
.grid2 > .card { margin-bottom: 0; } .grid2 { margin-bottom: 1.1rem; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 1rem; margin-bottom: 1.1rem; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem 1.1rem; display: flex; flex-direction: column; }
.stat .label { color: var(--muted); font-size: .85rem; }
.stat .value { font-size: 2rem; font-weight: 650; line-height: 1.2; }
.stat .value.ok { color: var(--ok); }
.stat .sub { color: var(--muted); font-size: .82rem; }

/* Tabelas */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: .6rem .55rem; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: .8rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); font-weight: 600; }
tbody tr:last-child td { border-bottom: 0; }
.row-actions { display: flex; gap: .35rem; flex-wrap: wrap; }
.row-actions form { margin: 0; }
.checks { white-space: nowrap; }

/* Componentes */
.badge { display: inline-block; padding: .12rem .55rem; border-radius: 999px; font-size: .78rem; font-weight: 600; white-space: nowrap; }
.badge.ok { background: var(--ok-bg); color: var(--ok); } .badge.bad { background: var(--bad-bg); color: var(--bad); }
.badge.warn { background: var(--warn-bg); color: var(--warn); } .badge.info { background: var(--info-bg); color: var(--info); }
.badge.sec { background: var(--sec-bg); color: var(--sec); } .badge.muted { background: var(--mutedbg); color: var(--muted); }
.dot { display: inline-block; width: 11px; height: 11px; border-radius: 50%; margin-right: .45rem; }
.dot.on { background: var(--ok); } .dot.off { background: var(--bad); } .dot.unknown { background: var(--line); }
.flash { padding: .7rem .9rem; border-radius: 8px; margin-bottom: 1rem; background: var(--info-bg); color: var(--info); }
.flash.ok { background: var(--ok-bg); color: var(--ok); } .flash.error { background: var(--bad-bg); color: var(--bad); }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: .35rem; border: 1px solid var(--line); background: var(--panel); color: var(--text); padding: .5rem .9rem; border-radius: 8px; font: inherit; cursor: pointer; white-space: nowrap; }
.btn:hover { text-decoration: none; border-color: var(--muted); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
.btn.danger { color: var(--bad); border-color: var(--bad-bg); }
.btn.danger:hover { background: var(--bad-bg); }
.btn.ghost { background: transparent; }
.btn.small { padding: .25rem .6rem; font-size: .85rem; }
.sidebar .btn.ghost { color: var(--side-text); border-color: #374151; }

form { margin: 0 0 .8rem; }
.stack { display: flex; flex-direction: column; gap: .9rem; }
.inline { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }
.inline input { flex: 1; min-width: 200px; }
.row2 { display: grid; grid-template-columns: 2fr 1fr; gap: .9rem; }
label { display: flex; flex-direction: column; gap: .3rem; font-weight: 550; font-size: .92rem; }
label.checkbox { flex-direction: row; align-items: flex-start; gap: .55rem; font-weight: 400; }
label.checkbox input { margin-top: .25rem; }
input, select, textarea { font: inherit; padding: .5rem .65rem; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); color: var(--text); width: 100%; }
label.checkbox input { width: auto; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary); outline-offset: 0; border-color: transparent; }
.hint { font-weight: 400; font-size: .82rem; color: var(--muted); }
.field-error { font-weight: 500; font-size: .84rem; color: var(--bad); }
.buttons { display: flex; gap: .6rem; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: .4rem 1rem; margin: 0; }
.kv dt { color: var(--muted); } .kv dd { margin: 0; word-break: break-all; }
.events, .alerts { list-style: none; padding: 0; margin: 0 0 .6rem; }
.events li, .alerts li { padding: .45rem 0; border-bottom: 1px solid var(--line); }
.events li:last-child, .alerts li:last-child { border-bottom: 0; }
.when { color: var(--muted); font-size: .82rem; margin: 0 .35rem; }
.copybox { display: flex; gap: .5rem; align-items: stretch; background: var(--mutedbg); border-radius: 8px; padding: .6rem; }
.copybox code { flex: 1; word-break: break-all; align-self: center; user-select: all; cursor: text; }
.steps { padding-left: 1.2rem; } .steps li { margin-bottom: 1.2rem; }
.waiting { display: flex; align-items: center; gap: .6rem; font-weight: 600; }
.spinner { width: 16px; height: 16px; border: 2px solid var(--line); border-top-color: var(--primary); border-radius: 50%; animation: spin 1s linear infinite; }
.waiting.done .spinner { display: none; }
@keyframes spin { to { transform: rotate(360deg); } }
.pager { display: flex; gap: .8rem; align-items: center; justify-content: flex-end; margin-top: .8rem; }

/* Login */
.auth { display: grid; place-items: center; min-height: 100vh; padding: 1rem; }
.auth-card { width: 100%; max-width: 420px; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 2rem; }
.auth-card h2 { margin-top: 0; }

/* Celular */
@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: fixed; z-index: 20; left: 0; top: 0; width: 250px; transform: translateX(-100%); transition: transform .2s; }
  .nav-toggle:checked ~ .sidebar { transform: none; }
  .nav-toggle:checked ~ .nav-backdrop { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 10; }
  .hamburger { display: flex; flex-direction: column; gap: 4px; cursor: pointer; padding: .4rem; }
  .hamburger span { width: 22px; height: 2px; background: var(--text); }
  .content { padding: 1rem; }
  .row2 { grid-template-columns: 1fr; }
  .topbar .actions { margin-left: 0; width: 100%; }
}

/* ---- v1.1: gráficos, recursos, filtros, etiquetas, testes ---- */
.chart { width: 100%; height: auto; display: block; }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .axis { fill: var(--muted); font-size: 10px; font-family: inherit; }
.chart .bar-in { fill: var(--primary); }
.chart .bar-out { fill: #14b8a6; }
.legend { color: var(--muted); font-size: .82rem; margin: .4rem 0 0; }
.legend .sw { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin: 0 .25rem 0 .6rem; }
.legend .sw.in { background: var(--primary); }
.legend .sw.out { background: #14b8a6; }
.meters { min-width: 150px; }
.meters.big { display: flex; flex-direction: column; gap: .5rem; margin-bottom: .9rem; max-width: 420px; }
.meter-row { display: flex; align-items: center; gap: .5rem; font-size: .8rem; margin: .1rem 0; }
.meter-row .ml { width: 3.2rem; color: var(--muted); }
.meter-row .mv { width: 2.6rem; text-align: right; }
.meter-row meter { flex: 1; min-width: 70px; height: 10px; }
.tag, .group { display: inline-block; padding: .05rem .5rem; border-radius: 6px; font-size: .74rem; margin: 0 .2rem .15rem 0; background: var(--mutedbg); color: var(--muted); }
.group { background: var(--info-bg); color: var(--info); }
.filters { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; margin-bottom: .9rem; }
.filters input[type="search"], .filters input[type="text"] { flex: 1; min-width: 200px; }
.filters select, .filters input[type="date"] { width: auto; }
.inline-label { flex-direction: row; align-items: center; gap: .4rem; font-weight: 500; }
.inline-label input { width: auto; }
input.short { width: 7rem; }
.inline-form { display: inline; margin: 0; }
.actions-grid { display: flex; flex-direction: column; gap: .7rem; }
.actions-grid form { margin: 0; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; margin-bottom: .6rem; }
.card-head h2 { margin: 0; }
.tabs { display: flex; gap: .25rem; flex-wrap: wrap; }
.tabs a { padding: .25rem .7rem; border-radius: 8px; color: var(--muted); border: 1px solid var(--line); }
.tabs a.active { background: var(--primary); border-color: var(--primary); color: #fff; text-decoration: none; }
.kind-tabs { margin-bottom: 1rem; }
.sub-grid { margin: 1rem 0 0; }
.sub-grid h3 { margin: 0 0 .6rem; font-size: .95rem; }
fieldset.group { border: 1px solid var(--line); border-radius: 10px; padding: .8rem 1rem; margin: 0; display: flex; flex-direction: column; gap: .6rem; background: transparent; color: inherit; font-size: inherit; }
fieldset.group legend { padding: 0 .4rem; font-weight: 600; font-size: .88rem; }
.logview { background: #0b1020; color: #d6deeb; padding: 1rem; border-radius: 8px; overflow: auto; max-height: 70vh; font-size: .8rem; line-height: 1.45; white-space: pre-wrap; word-break: break-all; }
.qr-card { text-align: center; }
.qr { border-radius: 8px; background: #fff; padding: 4px; }
.steps-result { list-style: none; padding: 0; margin: .5rem 0 0; }
.steps-result li { display: flex; gap: .7rem; padding: .5rem 0; border-bottom: 1px solid var(--line); }
.steps-result li:last-child { border-bottom: 0; }
.steps-result .mark { width: 1.4rem; font-weight: 700; text-align: center; }
.steps-result .ok .mark { color: var(--ok); }
.steps-result .bad .mark { color: var(--bad); }
.steps-result .skip .mark { color: var(--muted); }
.stat .value small { font-size: .9rem; font-weight: 500; color: var(--muted); }
.row-hidden { display: none; }

/* ---- atualização ao vivo ---- */
.live-indicator { display: inline-flex; align-items: center; gap: .4rem; font-size: .78rem; color: var(--muted); padding: .15rem .6rem; border: 1px solid var(--line); border-radius: 999px; white-space: nowrap; }
.live-indicator[hidden] { display: none; }
.live-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.live-indicator.on .live-dot { background: var(--ok); animation: live-pulse 2s ease-in-out infinite; }
.live-indicator.warn .live-dot { background: var(--warn); }
.live-indicator.off .live-dot, .live-indicator.expired .live-dot { background: var(--bad); }
.live-indicator.expired { color: var(--bad); }
@keyframes live-pulse { 0%, 100% { opacity: 1; } 50% { opacity: .3; } }
@media (prefers-reduced-motion: reduce) { .live-indicator.on .live-dot { animation: none; } }
[data-live]:empty { display: none; }
.live-banner a { color: inherit; text-decoration: underline; font-weight: 600; }
.picked-summary { margin: .4rem 0 .8rem; display: flex; flex-wrap: wrap; align-items: center; gap: .4rem .6rem; }

.auth-card.wide { max-width: 680px; }
.center { text-align: center; }
.auth-card .copybox code { white-space: pre-wrap; word-break: break-all; }

.chart .up-ok { fill: var(--ok); } .chart .up-part { fill: var(--warn); } .chart .up-bad { fill: var(--bad); }
.chart .up-none { fill: var(--mutedbg); }
.chart .line { fill: none; stroke-width: 1.6; stroke-linejoin: round; }
.chart .line-lat { stroke: var(--primary); } .chart .line-max { stroke: var(--warn); stroke-dasharray: 4 3; }
.chart .line-cpu { stroke: var(--primary); } .chart .line-mem { stroke: #14b8a6; }
.chart .dot.line-lat, .chart .dot.line-cpu { fill: var(--primary); } .chart .dot.line-max { fill: var(--warn); } .chart .dot.line-mem { fill: #14b8a6; }
.chart .hit { fill: transparent; }
.sw.up-ok { background: var(--ok); } .sw.up-part { background: var(--warn); } .sw.up-bad { background: var(--bad); } .sw.up-none { background: var(--mutedbg); border: 1px solid var(--line); }
.sw.lat, .sw.cpu { background: var(--primary); } .sw.max { background: var(--warn); } .sw.mem { background: #14b8a6; }
.uptime-summary { display: flex; flex-wrap: wrap; gap: .6rem; align-items: baseline; margin: 0 0 .6rem; }
.uptime-summary > b { font-size: 1.5rem; }
.chip { background: var(--mutedbg); border-radius: 999px; padding: .1rem .6rem; font-size: .8rem; }
