:root {
  --bg: #f4f6f9; --surface: #ffffff; --surface-2: #f7f9fb; --surface-3: #eef2f6;
  --line: #e3e8ee; --line-strong: #cfd7e1;
  --ink: #0e1621; --ink-2: #334155; --muted: #64748b; --faint: #94a3b8;
  --accent: #2563eb; --accent-ink: #ffffff; --accent-soft: #e8efff;
  --ok: #15803d; --ok-soft: #e7f6ec; --warn: #b45309; --warn-soft: #fdf3e2;
  --bad: #c62828; --bad-soft: #fdeaea; --div: #7c3aed; --div-soft: #f1eafe;
  --shadow-1: 0 1px 2px rgba(14, 22, 33, .05), 0 1px 1px rgba(14, 22, 33, .03);
  --shadow-2: 0 12px 32px -14px rgba(14, 22, 33, .28), 0 2px 6px rgba(14, 22, 33, .06);
  --radius: 12px; --radius-sm: 8px;
  --font: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --top-h: 60px; --side-w: 228px;
  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #0b1017; --surface: #121a24; --surface-2: #16202c; --surface-3: #1c2733;
  --line: #233041; --line-strong: #2f3f52;
  --ink: #e6edf5; --ink-2: #c2cdd9; --muted: #8b9bb0; --faint: #5f6f84;
  --accent: #60a5fa; --accent-ink: #06121f; --accent-soft: #10243d;
  --ok: #4ade80; --ok-soft: #0f2a1b; --warn: #fbbf24; --warn-soft: #2d2410;
  --bad: #f87171; --bad-soft: #321718; --div: #a78bfa; --div-soft: #221a39;
  --shadow-1: 0 1px 2px rgba(0, 0, 0, .4);
  --shadow-2: 0 14px 34px -14px rgba(0, 0, 0, .75);
  color-scheme: dark;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0b1017; --surface: #121a24; --surface-2: #16202c; --surface-3: #1c2733;
    --line: #233041; --line-strong: #2f3f52;
    --ink: #e6edf5; --ink-2: #c2cdd9; --muted: #8b9bb0; --faint: #5f6f84;
    --accent: #60a5fa; --accent-ink: #06121f; --accent-soft: #10243d;
    --ok: #4ade80; --ok-soft: #0f2a1b; --warn: #fbbf24; --warn-soft: #2d2410;
    --bad: #f87171; --bad-soft: #321718; --div: #a78bfa; --div-soft: #221a39;
    --shadow-1: 0 1px 2px rgba(0, 0, 0, .4);
    --shadow-2: 0 14px 34px -14px rgba(0, 0, 0, .75);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--ink); font: 14px/1.5 var(--font); -webkit-font-smoothing: antialiased; }
svg { flex: none; }
h1 { font-size: 22px; line-height: 1.25; margin: 0; letter-spacing: -.01em; font-weight: 650; }
h2 { font-size: 14px; margin: 0 0 12px; font-weight: 600; color: var(--ink); letter-spacing: .005em; }
h3 { font-size: 13px; margin: 14px 0 6px; font-weight: 600; }
a { color: var(--accent); }
code, .mono { font-family: var(--mono); font-size: 12.5px; }
button, select, input { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- shell */
.app { display: grid; grid-template-columns: var(--side-w) 1fr; grid-template-rows: var(--top-h) 1fr; height: 100vh; height: 100dvh; }
.top { grid-column: 1 / -1; display: flex; align-items: center; gap: 18px; padding: 0 18px; background: var(--surface); border-bottom: 1px solid var(--line); min-width: 0; }
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--ink); width: calc(var(--side-w) - 18px); flex: none; }
.brand svg { width: 32px; height: 32px; }
.brand span { display: flex; flex-direction: column; line-height: 1.15; }
.brand b { font-size: 15px; letter-spacing: -.01em; }
.brand small { color: var(--muted); font-size: 11.5px; }
.snap { display: flex; align-items: center; gap: 8px; min-width: 0; }
.snap label { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .06em; font-weight: 600; }
.snap select { height: 34px; border: 1px solid var(--line-strong); background: var(--surface-2); border-radius: var(--radius-sm); padding: 0 30px 0 10px; min-width: 0; max-width: 420px; appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 15px) 15px, calc(100% - 10px) 15px; background-size: 5px 5px; background-repeat: no-repeat; cursor: pointer; }
.sched { color: var(--muted); font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.sched b { color: var(--ink-2); font-weight: 600; }
.top-actions { margin-left: auto; display: flex; align-items: center; gap: 10px; flex: none; }
.ro { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); padding: 4px 10px; border: 1px solid var(--line); border-radius: 999px; white-space: nowrap; }
.ro svg { width: 14px; height: 14px; fill: none; stroke: currentColor; stroke-width: 2; }

.btn { display: inline-flex; align-items: center; gap: 8px; height: 34px; padding: 0 14px; border-radius: var(--radius-sm); border: 1px solid var(--line-strong); background: var(--surface); cursor: pointer; font-weight: 550; white-space: nowrap; transition: background .15s, border-color .15s, transform .1s; }
.btn svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.btn:hover { background: var(--surface-3); }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.06); }
.btn.ghost { background: transparent; }
.btn.sm { height: 30px; padding: 0 10px; font-size: 13px; }
.btn[disabled] { opacity: .6; cursor: progress; }
.icon-btn { width: 34px; height: 34px; display: grid; place-items: center; border-radius: var(--radius-sm); border: 1px solid var(--line); background: transparent; cursor: pointer; }
.icon-btn svg { width: 17px; height: 17px; fill: none; stroke: currentColor; stroke-width: 2; }
.icon-btn:hover { background: var(--surface-3); }

.side { background: var(--surface); border-right: 1px solid var(--line); padding: 14px 10px; display: flex; flex-direction: column; gap: 2px; overflow-y: auto; }
.side a { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: var(--radius-sm); text-decoration: none; color: var(--ink-2); font-weight: 520; }
.side a svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; color: var(--muted); }
.side a:hover { background: var(--surface-3); }
.side a.on { background: var(--accent-soft); color: var(--accent); }
.side a.on svg { color: var(--accent); }
.nav-badge { margin-left: auto; font-size: 11px; font-weight: 650; padding: 0 7px; border-radius: 999px; line-height: 18px; }
.nav-badge:empty { display: none; }
.nav-badge.bad { background: var(--bad-soft); color: var(--bad); }
.nav-badge.warn { background: var(--warn-soft); color: var(--warn); }
.nav-badge.div { background: var(--div-soft); color: var(--div); }
.side-foot { margin-top: auto; padding: 12px 10px 4px; font-size: 11.5px; color: var(--faint); line-height: 1.5; }

main { overflow-y: auto; padding: 22px 26px 40px; min-width: 0; }
[hidden] { display: none !important; }
.view { display: flex; flex-direction: column; gap: 16px; max-width: 1480px; margin: 0 auto; }
.view-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.sub { margin: 4px 0 0; color: var(--muted); max-width: 820px; }
.banner { max-width: 1480px; margin: 0 auto 14px; padding: 10px 14px; border-radius: var(--radius-sm); background: var(--warn-soft); color: var(--warn); border: 1px solid color-mix(in srgb, var(--warn) 30%, transparent); }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow-1); min-width: 0; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }

/* ---------- KPIs */
.kpis { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 12px; }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow-1); text-decoration: none; color: inherit; display: block; transition: border-color .15s; }
a.kpi:hover { border-color: var(--line-strong); }
.kpi .k { font-size: 12px; color: var(--muted); font-weight: 550; }
.kpi .v { font-size: 26px; font-weight: 680; letter-spacing: -.02em; margin-top: 2px; font-variant-numeric: tabular-nums; }
.kpi .d { font-size: 12px; color: var(--muted); margin-top: 2px; }
.kpi.bad .v { color: var(--bad); } .kpi.warn .v { color: var(--warn); } .kpi.ok .v { color: var(--ok); } .kpi.div .v { color: var(--div); }

/* ---------- texto */
.prose { color: var(--ink-2); }
.prose p { margin: 0 0 10px; }
.prose ul { margin: 0 0 10px; padding-left: 18px; }
.prose li { margin: 3px 0; }
.prose b { color: var(--ink); font-weight: 600; }
.muted { color: var(--muted); }
.empty { color: var(--muted); padding: 18px 0; text-align: center; }

.chip { display: inline-flex; align-items: center; gap: 5px; font-size: 11.5px; font-weight: 600; padding: 1px 8px; border-radius: 999px; background: var(--surface-3); color: var(--ink-2); white-space: nowrap; line-height: 18px; }
.chip.ok { background: var(--ok-soft); color: var(--ok); }
.chip.bad { background: var(--bad-soft); color: var(--bad); }
.chip.warn { background: var(--warn-soft); color: var(--warn); }
.chip.div { background: var(--div-soft); color: var(--div); }
.chip.acc { background: var(--accent-soft); color: var(--accent); }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; background: currentColor; }

/* ---------- tabelas */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th { text-align: left; font-weight: 600; color: var(--muted); font-size: 11.5px; text-transform: uppercase; letter-spacing: .05em; padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: var(--surface-2); }
td.num { font-variant-numeric: tabular-nums; text-align: right; }
.dev { font-weight: 600; color: var(--ink); white-space: nowrap; }
.port { font-family: var(--mono); font-size: 12px; color: var(--muted); }
.ip { font-family: var(--mono); font-size: 12.5px; white-space: nowrap; }

/* ---------- diagramas */
.diagram-card { padding: 0; overflow: hidden; }
.toolbar { display: flex; align-items: center; gap: 14px; padding: 10px 14px; border-bottom: 1px solid var(--line); flex-wrap: wrap; background: var(--surface-2); }
.tb-sp { flex: 1; }
.switch { display: inline-flex; align-items: center; gap: 8px; font-size: 13px; color: var(--ink-2); cursor: pointer; user-select: none; }
.switch input { position: absolute; opacity: 0; pointer-events: none; }
.switch span { width: 30px; height: 18px; border-radius: 999px; background: var(--line-strong); position: relative; transition: background .15s; }
.switch span::after { content: ""; position: absolute; top: 2px; left: 2px; width: 14px; height: 14px; border-radius: 50%; background: #fff; box-shadow: 0 1px 2px rgba(0,0,0,.25); transition: transform .18s cubic-bezier(.22,1,.36,1); }
.switch input:checked + span { background: var(--accent); }
.switch input:checked + span::after { transform: translateX(12px); }
.switch input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }
.legend-inline, .legend { display: flex; gap: 12px; flex-wrap: wrap; font-size: 12px; color: var(--muted); align-items: center; }
.legend-inline i, .legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }
.diagram-wrap { display: grid; grid-template-columns: 1fr 300px; height: min(68vh, 720px); min-height: 420px; }
.cy { width: 100%; height: 100%; min-width: 0; background:
  radial-gradient(circle, var(--line) 1px, transparent 1.2px) 0 0 / 22px 22px; }
.det { border-left: 1px solid var(--line); padding: 16px; overflow-y: auto; background: var(--surface); font-size: 13px; }
.det h3 { margin-top: 0; font-size: 15px; display: flex; align-items: center; gap: 8px; }
.det .kv { display: grid; grid-template-columns: 92px 1fr; gap: 4px 10px; margin: 10px 0; }
.det .kv dt { color: var(--muted); }
.det .kv dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
.det ul { margin: 4px 0 10px; padding-left: 16px; }
.det .hint { color: var(--muted); }

/* ---------- caminhos */
.paths { display: grid; grid-template-columns: repeat(auto-fill, minmax(420px, 1fr)); gap: 12px; }
.path { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow-1); }
.path-h { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.path-h .arrow { color: var(--faint); }
.path-h .tail { margin-left: auto; display: flex; gap: 6px; }
.hops { display: flex; align-items: center; flex-wrap: wrap; gap: 4px; margin-top: 12px; }
.hop { border: 1px solid var(--line); background: var(--surface-2); border-radius: 8px; padding: 5px 8px; font-size: 12px; line-height: 1.3; }
.hop b { display: block; font-size: 12.5px; }
.hop .m { color: var(--muted); font-family: var(--mono); font-size: 11.5px; }
.hop.loss { border-color: color-mix(in srgb, var(--warn) 50%, transparent); background: var(--warn-soft); }
.hop.dead { border-color: color-mix(in srgb, var(--bad) 50%, transparent); background: var(--bad-soft); }
.hop-sep { color: var(--faint); }

/* ---------- linha do tempo */
.timeline { display: flex; flex-direction: column; gap: 12px; }
.tl { background: var(--surface); border: 1px solid var(--line); border-left: 3px solid var(--warn); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow-1); }
.tl.crit { border-left-color: var(--bad); }
.tl-h { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 8px; }
.tl-h .when { font-weight: 650; }
.tl ul { margin: 0; padding-left: 0; list-style: none; display: flex; flex-direction: column; gap: 6px; }
.tl li { display: grid; grid-template-columns: 70px 1fr; gap: 10px; align-items: start; }
.tl li .chip { justify-content: center; }
.tl details summary { cursor: pointer; color: var(--muted); margin-top: 6px; font-size: 13px; }
.seg { display: inline-flex; border: 1px solid var(--line-strong); border-radius: var(--radius-sm); overflow: hidden; background: var(--surface); }
.seg button { border: 0; background: transparent; padding: 6px 12px; cursor: pointer; font-size: 13px; }
.seg button + button { border-left: 1px solid var(--line); }
.seg button.on { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.search { height: 36px; border: 1px solid var(--line-strong); border-radius: var(--radius-sm); background: var(--surface); padding: 0 12px; min-width: 280px; }

/* ---------- gráfico de coletas */
.chart svg { width: 100%; height: auto; display: block; }
.chart text { fill: var(--muted); font-size: 10px; font-family: var(--font); }
.chart .grid { stroke: var(--line); }
.legend { margin-top: 8px; }

/* ---------- responsivo */
@media (max-width: 1180px) {
  .kpis { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .sched { display: none; }
}
@media (max-width: 920px) {
  .app { grid-template-columns: 1fr; grid-template-rows: auto auto 1fr; }
  .top { flex-wrap: wrap; gap: 10px; padding: 10px 16px; }
  .brand { width: auto; }
  .snap { order: 3; width: 100%; }
  .snap select { flex: 1; max-width: none; }
  .ro { display: none; }
  .btn.primary span { display: none; }
  .side { flex-direction: row; overflow-x: auto; padding: 6px 10px; border-right: 0; border-bottom: 1px solid var(--line); }
  .side a { white-space: nowrap; }
  .side-foot { display: none; }
  main { padding: 16px; }
  .grid-2 { grid-template-columns: 1fr; }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .diagram-wrap { grid-template-columns: 1fr; grid-template-rows: 60vh auto; height: auto; }
  .det { border-left: 0; border-top: 1px solid var(--line); }
  .paths { grid-template-columns: 1fr; }
  .search { min-width: 0; width: 100%; }
  .tl li { grid-template-columns: 1fr; gap: 2px; }
  .tl li .chip { justify-self: start; }
}

/* ---------- relatório (PDF) */
#offscreen { position: fixed; left: -20000px; top: 0; width: 1600px; height: 1000px; overflow: hidden; }
.report { display: none; }
@page { size: A4; margin: 14mm 13mm 16mm; @bottom-right { content: "Página " counter(page) " de " counter(pages); font: 9px system-ui, sans-serif; color: #64748b; } @bottom-left { content: "Net-Memory · relatório de topologia"; font: 9px system-ui, sans-serif; color: #64748b; } }
@page land { size: A4 landscape; margin: 12mm 13mm 14mm; }
@media print {
  :root, :root[data-theme="dark"] {
    --bg: #fff; --surface: #fff; --surface-2: #f7f9fb; --surface-3: #eef2f6; --line: #dfe5ec; --line-strong: #cfd7e1;
    --ink: #0e1621; --ink-2: #334155; --muted: #64748b; --faint: #94a3b8; --accent: #2563eb; --accent-soft: #e8efff;
    --ok: #15803d; --ok-soft: #e7f6ec; --warn: #b45309; --warn-soft: #fdf3e2; --bad: #c62828; --bad-soft: #fdeaea; --div: #7c3aed; --div-soft: #f1eafe;
    color-scheme: light;
  }
  html, body { height: auto; background: #fff; }
  body { font-size: 10.5px; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .app, #offscreen { display: none !important; }
  .report { display: block; color: var(--ink); }
  .rp-cover { border-bottom: 2px solid var(--accent); padding-bottom: 10px; margin-bottom: 14px; display: flex; justify-content: space-between; align-items: flex-end; gap: 20px; }
  .rp-cover h1 { font-size: 22px; }
  .rp-cover .meta { text-align: right; color: var(--muted); font-size: 10px; line-height: 1.6; }
  .rp-kpis { display: grid; grid-template-columns: repeat(6, 1fr); gap: 6px; margin: 10px 0 14px; }
  .rp-kpis div { border: 1px solid var(--line); border-radius: 6px; padding: 6px 8px; }
  .rp-kpis b { display: block; font-size: 16px; }
  .rp-kpis span { color: var(--muted); font-size: 9px; }
  .report h2 { font-size: 14px; margin: 18px 0 8px; padding-bottom: 4px; border-bottom: 1px solid var(--line); break-after: avoid; }
  .report h3 { font-size: 11.5px; margin: 10px 0 4px; break-after: avoid; }
  .report table { font-size: 9.5px; }
  .report th { font-size: 8.5px; padding: 4px 6px; }
  .report td { padding: 4px 6px; }
  .report tr { break-inside: avoid; }
  .report .prose { font-size: 10.5px; }
  .rp-land { page: land; break-before: page; }
  .rp-land img { width: 100%; max-height: 165mm; object-fit: contain; border: 1px solid var(--line); border-radius: 6px; }
  .rp-land figcaption { color: var(--muted); font-size: 9px; margin-top: 4px; }
  .rp-section { break-before: page; }
  .chip { font-size: 8.5px; padding: 0 5px; line-height: 14px; }
  .hop { padding: 2px 5px; font-size: 9px; }
}

/* ---------- login */
.login-body { display: grid; place-items: center; min-height: 100vh; padding: 16px;
  background: radial-gradient(1200px 600px at 20% -10%, var(--accent-soft), transparent 60%), var(--bg); }
.login { width: min(400px, 100%); display: flex; flex-direction: column; gap: 18px; }
.login-brand { display: flex; align-items: center; gap: 12px; }
.login-brand svg { width: 40px; height: 40px; }
.login-brand b { display: block; font-size: 18px; letter-spacing: -.01em; }
.login-brand small { color: var(--muted); }
.login-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 26px; box-shadow: var(--shadow-2); display: flex; flex-direction: column; gap: 8px; }
.login-card h1 { margin-bottom: 2px; }
.login-card .sub { margin: 0 0 10px; }
.login-card label { font-size: 13px; font-weight: 600; color: var(--ink-2); margin-top: 6px; }
.login-card input { height: 40px; border: 1px solid var(--line-strong); border-radius: var(--radius-sm); background: var(--surface-2); padding: 0 12px; }
.login-card input:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: var(--accent); }
.login-card .btn { height: 40px; justify-content: center; margin-top: 14px; }
.login-err { background: var(--bad-soft); color: var(--bad); border-radius: var(--radius-sm); padding: 8px 12px; font-size: 13px; }
.login-foot { text-align: center; color: var(--faint); font-size: 12px; margin: 0; }
.user { display: inline-flex; align-items: center; gap: 8px; font-size: 13px; color: var(--ink-2); white-space: nowrap; }
.user form { margin: 0; }
.agente-pub { margin-top: 12px; font-size: 12.5px; }
