:root {
  --bg: #f6f7f9; --surface: #fff; --text: #1b1f24; --muted: #5d6673;
  --line: #dfe3e8; --accent: #1f6feb; --ok: #1a7f37; --ok-bg: #dafbe1;
  --bad: #cf222e; --bad-bg: #ffebe9;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d1117; --surface: #161b22; --text: #e6edf3; --muted: #8b949e;
    --line: #30363d; --accent: #4493f8; --ok: #3fb950; --ok-bg: #12261e;
    --bad: #f85149; --bad-bg: #2d1416;
  }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text);
  font: 14px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif; }
code { font-family: var(--mono); font-size: 12.5px; }
a { color: var(--accent); }

/* ---------------------------------------------------------------- estrutura e menu lateral */
:root { --side-w: 232px; --side-bg: var(--surface); --side-hover: #eef1f5; --side-on: #e7effd; }
@media (prefers-color-scheme: dark) { :root { --side-hover: #1c2330; --side-on: #172a45; } }

.shell { min-height: 100vh; }
main { max-width: 1240px; margin: 0 auto; padding: 28px 32px 56px; }
.shell > main { margin-left: var(--side-w); margin-right: 0; max-width: none; }
.shell > main > * { max-width: 1240px; }
main.public { padding-top: 40px; }

.sidebar { position: fixed; inset: 0 auto 0 0; width: var(--side-w); display: flex; flex-direction: column;
  background: var(--side-bg); border-right: 1px solid var(--line); z-index: 30; }
.side-brand { display: flex; flex-direction: column; align-items: flex-start; gap: 6px; padding: 20px 20px 16px;
  text-decoration: none; color: var(--text); border-bottom: 1px solid var(--line); }
.side-brand .client-logo img { height: 32px; max-width: 188px; }
.side-wordmark { font-size: 18px; font-weight: 750; letter-spacing: -.01em; }
.side-product { font-size: 12px; color: var(--muted); font-weight: 600; }

.side-nav { flex: 1; overflow-y: auto; padding: 8px 12px 16px; }
.side-group { margin-top: 14px; }
.side-title { margin: 0 0 4px; padding: 0 10px; font-size: 12px; font-weight: 600; color: var(--muted); }
.side-link { display: flex; align-items: center; gap: 11px; padding: 7px 10px; margin: 1px 0; border-radius: 7px;
  color: var(--text); text-decoration: none; font-size: 14px; cursor: pointer; }
.side-link .icon { flex: none; color: var(--muted); }
.side-link:hover { background: var(--side-hover); }
.side-link.on { background: var(--side-on); color: var(--accent); font-weight: 600; }
.side-link.on .icon { color: var(--accent); }
.side-badge { margin-left: auto; min-width: 20px; padding: 0 6px; border-radius: 999px; background: var(--bad);
  color: #fff; font-size: 11.5px; font-weight: 700; line-height: 20px; text-align: center; }

.side-admin summary { list-style: none; }
.side-admin summary::-webkit-details-marker { display: none; }
.side-admin summary .icon:last-child { margin-left: auto; width: 15px; height: 15px; transition: transform .15s; }
.side-admin[open] summary .icon:last-child { transform: rotate(90deg); }
.side-admin summary.on { background: none; color: var(--text); }
.side-admin summary.on .icon { color: var(--accent); }
.side-sub { display: flex; flex-direction: column; margin: 2px 0 4px 19px; padding-left: 12px; border-left: 1px solid var(--line); }
.side-sub a { padding: 5px 10px; border-radius: 6px; color: var(--muted); text-decoration: none; font-size: 13.5px; }
.side-sub a:hover { background: var(--side-hover); color: var(--text); }
.side-sub a.on { color: var(--accent); background: var(--side-on); font-weight: 600; }

.side-me { display: flex; align-items: center; gap: 6px; padding: 12px; border-top: 1px solid var(--line); }
.side-me form { margin: 0; }
.side-user { flex: 1; min-width: 0; display: flex; align-items: center; gap: 10px; padding: 6px 8px; border-radius: 7px;
  color: var(--text); text-decoration: none; }
.side-user:hover, .side-user.on { background: var(--side-hover); }
.avatar { flex: none; width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center;
  background: var(--side-on); color: var(--accent); font-weight: 700; font-size: 13px; }
.who { display: flex; flex-direction: column; min-width: 0; line-height: 1.25; }
.who .name { font-weight: 600; font-size: 13.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.who .role { font-size: 12px; color: var(--muted); }
.side-logout { display: grid; place-items: center; width: 34px; height: 34px; padding: 0; border-radius: 7px;
  background: none; border: 0; color: var(--muted); cursor: pointer; }
.side-logout:hover { background: var(--side-hover); color: var(--bad); }
.side-link:focus-visible, .side-sub a:focus-visible, .side-user:focus-visible, .side-logout:focus-visible,
.menu-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

.nav-toggle { position: absolute; opacity: 0; pointer-events: none; }
.mobile-bar, .nav-scrim { display: none; }
@media (max-width: 960px) {
  .shell > main { margin-left: 0; padding: 20px 16px 48px; }
  .mobile-bar { display: flex; align-items: center; gap: 12px; height: 52px; padding: 0 12px; position: sticky; top: 0; z-index: 20;
    background: var(--surface); border-bottom: 1px solid var(--line); }
  .menu-btn { display: grid; place-items: center; width: 36px; height: 36px; border-radius: 7px; cursor: pointer; color: var(--text); }
  .menu-btn:hover { background: var(--side-hover); }
  .mobile-brand { display: flex; align-items: center; gap: 10px; color: var(--text); text-decoration: none; font-weight: 700; }
  .mobile-brand .client-logo img { height: 24px; }
  .sidebar { transform: translateX(-100%); transition: transform .2s ease; box-shadow: none; }
  .nav-toggle:checked ~ .shell .sidebar { transform: none; box-shadow: 0 0 40px rgba(0,0,0,.25); }
  .nav-toggle:checked ~ .shell .nav-scrim { display: block; position: fixed; inset: 0; z-index: 25; background: rgba(0,0,0,.35); }
}
@media (prefers-reduced-motion: reduce) { .sidebar, .side-admin summary .icon { transition: none; } }

.head h1 { margin: 0; font-size: 22px; }
h2 { font-size: 15px; margin: 28px 0 10px; }
.muted, .empty { color: var(--muted); }
.head .muted { margin: 4px 0 20px; }

.stats { display: flex; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: 8px;
  padding: 12px 16px; min-width: 150px; }
.stat .n { display: block; font-size: 26px; font-weight: 650; font-variant-numeric: tabular-nums; }
.stat .l { color: var(--muted); font-size: 12.5px; }
.stat.bad .n { color: var(--bad); }

.alert { background: var(--bad-bg); color: var(--bad); border-radius: 8px; padding: 10px 14px; margin-bottom: 14px; }
.alert code { color: inherit; word-break: break-all; }

.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 8px 12px; text-align: left; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { font-size: 12px; font-weight: 600; color: var(--muted); }
tbody tr:last-child td { border-bottom: 0; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
tr.off td { color: var(--muted); }

.pill { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.pill.ok { color: var(--ok); background: var(--ok-bg); }
.pill.bad { color: var(--bad); background: var(--bad-bg); }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 16px; margin-bottom: 20px; }
.form h2 { margin-top: 0; }
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; }
label { display: flex; flex-direction: column; gap: 4px; font-size: 12.5px; color: var(--muted); }
label.check { flex-direction: row; align-items: center; gap: 8px; margin: 12px 0; }
input { font: inherit; color: var(--text); background: var(--bg); border: 1px solid var(--line);
  border-radius: 6px; padding: 7px 9px; }
button { font: inherit; cursor: pointer; border: 0; border-radius: 6px; padding: 8px 14px;
  background: var(--accent); color: #fff; font-weight: 600; }
button.link { background: none; color: var(--accent); padding: 0; font-weight: 500; }

/* abas, dicas e formulários das telas de interfaces e tráfego */
.tabs { display: flex; gap: 4px; flex-wrap: wrap; border-bottom: 1px solid var(--line); margin-bottom: 12px; }
.tabs a { padding: 8px 12px; color: var(--muted); text-decoration: none; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs a.on { color: var(--text); border-bottom-color: var(--accent); }
.tabs .count { font-size: 12px; color: var(--muted); margin-left: 4px; font-variant-numeric: tabular-nums; }
.hint { color: var(--muted); font-size: 13px; margin: 0 0 14px; }
.small { font-size: 12px; }
.error { color: var(--bad); }
.suggestion { color: var(--accent); }
select { font: inherit; color: var(--text); background: var(--bg); border: 1px solid var(--line); border-radius: 6px; padding: 6px 8px; }
table.ifaces td { vertical-align: top; white-space: normal; }
table.ifaces td input, table.ifaces td select { padding: 5px 7px; }
.actions { white-space: nowrap; }
.actions button { padding: 6px 10px; }
.actions .link { margin-left: 8px; }
tr.saved td { background: var(--ok-bg); transition: background 1.5s; }

.filters { display: flex; gap: 24px; flex-wrap: wrap; }
.filters fieldset { border: 0; padding: 0; margin: 0; display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.filters legend { font-size: 12px; color: var(--muted); margin-bottom: 6px; width: 100%; }
.chip { flex-direction: row; align-items: center; gap: 6px; color: var(--text); font-size: 13px;
  border: 1px solid var(--line); border-radius: 999px; padding: 4px 10px; cursor: pointer; background: var(--bg); }
.chip:has(input:checked) { border-color: var(--accent); }
.chip input { margin: 0; }
.chart-card { padding: 12px 12px 4px; }
.chart { width: 100%; height: 380px; }
@media (max-width: 640px) { .chart { height: 300px; } }

/* página do router */
.crumbs { margin: 0 0 4px; font-size: 13px; color: var(--muted); }
.crumbs a { color: var(--muted); }
.table-wrap.compact { margin-bottom: 16px; }
.table-wrap + .table-wrap, .card + .table-wrap { margin-top: 0; }
.chart-card + .table-wrap { margin-bottom: 8px; }
table.router-ifaces td { vertical-align: top; white-space: normal; }
table.router-ifaces td:first-child { width: 28px; }

/* login, conta e usuários */
.notice { background: var(--ok-bg); color: var(--text); border-radius: 8px; padding: 10px 14px; margin-bottom: 14px; }
.auth-box { max-width: 380px; margin: 48px auto; padding: 24px; }
.auth-box h1 { font-size: 20px; margin: 0 0 16px; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.stack button { align-self: flex-start; }
.two-col { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 16px; }
.two-col .card { margin: 0; }
.two-col h2 { margin-top: 0; }
.qr { background: #fff; display: inline-block; padding: 8px; border-radius: 8px; }
.steps { padding-left: 18px; margin: 0 0 12px; }
.steps li { margin-bottom: 6px; }
code.secret { user-select: all; word-break: break-all; }
form.inline { display: inline; margin: 0; }
.actions form.inline + form.inline { margin-left: 10px; }
button.secondary { background: var(--bg); color: var(--text); border: 1px solid var(--line); }

/* administração */
.row-buttons { display: flex; gap: 8px; }
.issue-form { display: flex; align-items: center; gap: 12px; margin-top: 8px; }
.issue-form .waiting { display: none; }
.issue-form.busy .waiting { display: inline; }
.two-col + section.card { margin-top: 16px; }
section.card > h2:first-child { margin-top: 0; }

/* looking glass */
.lg-form .lg-fields { display: grid; grid-template-columns: minmax(200px, 1fr) minmax(220px, 1fr); gap: 12px; }
@media (max-width: 640px) { .lg-form .lg-fields { grid-template-columns: 1fr; } }
.lg-form input[name=ip] { font-family: var(--mono); }
.lg-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-top: 12px; }
.htmx-indicator { display: none; }
.htmx-request .htmx-indicator, .htmx-request.htmx-indicator { display: inline; }
#lg-result > .card, #lg-result > section { margin-top: 16px; }
.lg-summary h2 { margin: 0 0 4px; font-family: var(--mono); }
.lg-router { margin-top: 18px; }
.lg-router h3 { margin: 0 0 6px; font-size: 15px; }
.lg-answer { margin: 0 0 10px; font-size: 15px; }
table.lg-routes td { vertical-align: top; white-space: normal; }
.aspath { font-family: var(--mono); font-size: 12.5px; }
.aspath .asn + .asn::before { content: " › "; color: var(--muted); }
.lg-graph { width: 100%; min-height: 220px; margin: 8px 0 12px; }
tr.asn-change td { border-top: 2px solid var(--accent); }
.router-picks { border: 0; padding: 0; margin: 12px 0; display: flex; flex-wrap: wrap; gap: 6px; }
.router-picks legend { font-size: 12.5px; color: var(--muted); margin-bottom: 6px; }
details summary { cursor: pointer; color: var(--accent); }
.lg-why { margin: 0 0 10px; padding: 8px 12px; border-left: 3px solid var(--accent); background: var(--bg); font-size: 13px; }
.aspath > .muted:first-child + .asn::before { content: none; }

/* alertas */
.badge { display: inline-block; min-width: 18px; padding: 0 6px; border-radius: 999px; background: var(--bad); color: #fff; font-size: 11px; font-weight: 700; text-align: center; line-height: 18px; }
.pill.warn { color: #9a6700; background: #fff8c5; }
@media (prefers-color-scheme: dark) { .pill.warn { color: #d29922; background: #2b2111; } }
.ok-text { color: var(--ok); }
.kind-list { border: 0; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 8px; }
.kind-list label.check { align-items: flex-start; margin: 0; color: var(--text); }
.channels { list-style: none; padding: 0; margin: 0 0 12px; display: flex; flex-direction: column; gap: 8px; }
.pill:not(.ok):not(.bad):not(.warn) { color: var(--muted); background: var(--bg); border: 1px solid var(--line); }

/* comandos do MikroTik no looking glass */
details.cli { margin: 0 0 12px; border: 1px solid var(--line); border-radius: 8px; padding: 6px 12px; background: var(--bg); }
details.cli summary { font-size: 13px; font-weight: 600; }
details.cli[open] summary { margin-bottom: 6px; }
.cli-line { display: flex; align-items: center; gap: 10px; margin-top: 6px; }
.cli-line code { flex: 1; background: var(--surface); border: 1px solid var(--line); border-radius: 6px; padding: 6px 10px; overflow-x: auto; white-space: nowrap; user-select: all; }
.cli-help { margin: 2px 0 0; }

/* botões segmentados (ex.: IPv4 / IPv6 / Todas) */
.segmented { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; margin-bottom: 14px; background: var(--surface); }
.segmented a { padding: 6px 14px; color: var(--muted); text-decoration: none; font-size: 13px; border-left: 1px solid var(--line); }
.segmented a:first-child { border-left: 0; }
.segmented a.on { background: var(--accent); color: #fff; }
.segmented a .count { font-size: 11px; opacity: .8; margin-left: 4px; font-variant-numeric: tabular-nums; }
.filter-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-bottom: 14px; }
.filter-bar .segmented { margin-bottom: 0; }
.inline-select { margin: 0; }
.inline-select select { padding: 6px 10px; font-size: 13px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* inventário e datacenters */
table.inventory td { vertical-align: top; }
.warn-text { color: #9a6700; margin: 8px 0 0; }
@media (prefers-color-scheme: dark) { .warn-text { color: #d29922; } }
.dc-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 14px; }
.dc-card { display: block; color: var(--text); text-decoration: none; margin: 0; }
.dc-card:hover { border-color: var(--accent); }
.dc-card.has-problem { border-color: var(--bad); }
.dc-head { display: flex; align-items: center; justify-content: space-between; }
.dc-head h2 { margin: 0; font-size: 17px; }
.dc-facts { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 16px; margin: 12px 0 0; }
.dc-facts dt { font-size: 12px; color: var(--muted); }
.dc-facts dd { margin: 0; font-weight: 600; font-variant-numeric: tabular-nums; }
ul.plain { list-style: none; padding: 0; margin: 0 0 12px; }
ul.plain li { padding: 3px 0; }
a.badge { text-decoration: none; margin-left: 4px; }
.equip { margin: 6px 0 0; color: var(--text); }
table.inventory th, table.inventory td { padding: 8px 10px; }
table.inventory td.model { white-space: nowrap; }

/* fluxos */
.mono { font-family: var(--mono); font-size: 12.5px; }
.card .table-wrap.flat { border: 0; border-radius: 0; background: transparent; margin: 0 -4px; }
.card .table-wrap.flat th, .card .table-wrap.flat td { padding: 6px 8px; }
.three-col { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 16px; margin-top: 16px; }
.three-col .card { margin: 0; }
.three-col h2, .reception h2 { margin-top: 0; }
.active-filters { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin: 0 0 12px; color: var(--muted); font-size: 13px; }
a.pill { text-decoration: none; }
a.pill:hover { border-color: var(--accent); color: var(--text); }
section.card.reception { margin-top: 16px; }
td.trunc { max-width: 150px; overflow: hidden; text-overflow: ellipsis; }

/* backup de configuração */
.head-actions { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; flex-wrap: wrap; }
.head-actions form { margin-top: 8px; }
td.wrap { white-space: normal; max-width: 320px; }
td .err { margin-top: 4px; word-break: break-word; }
.small-btn { padding: 4px 10px; font-size: 12.5px; }
h1 .h-link { font-size: 13px; font-weight: 500; margin-left: 10px; vertical-align: middle; }
.config-layout { display: grid; grid-template-columns: 280px minmax(0, 1fr); gap: 16px; align-items: start; }
@media (max-width: 800px) { .config-layout { grid-template-columns: 1fr; } }
.config-layout .card { margin: 0; }
.config-layout h2 { margin-top: 0; font-size: 15px; }
.versions li { padding: 8px 10px; border-radius: 6px; }
.versions li.on { background: var(--bg); box-shadow: inset 3px 0 0 var(--accent); }
.versions .add, pre.diff .add { color: var(--ok); }
.versions .del, pre.diff .del { color: var(--bad); }
.versions .compare { display: flex; flex-wrap: wrap; gap: 8px; align-items: end; margin-top: 12px; border-top: 1px solid var(--line); padding-top: 12px; }
.versions .compare label { font-size: 12px; color: var(--muted); }
pre.diff, pre.config { font-family: var(--mono); font-size: 12px; line-height: 1.5; overflow-x: auto; margin: 0;
  max-height: 75vh; overflow-y: auto; background: var(--bg); border: 1px solid var(--line); border-radius: 6px; padding: 10px 12px; }
pre.diff span { display: block; }
pre.diff .add { background: var(--ok-bg); }
pre.diff .del { background: var(--bad-bg); }
pre.diff .hunk { color: var(--accent); margin-top: 6px; }
pre.diff .file { color: var(--muted); }

/* identidade do cliente */
.client-logo img { display: block; height: 28px; width: auto; max-width: 180px; object-fit: contain; }
.auth-logo { display: flex; justify-content: center; margin: 4px 0 20px; }
.auth-logo .client-logo img { height: 44px; max-width: 260px; }
@media (prefers-color-scheme: dark) {
  .client-logo.needs-plate img { background: #fff; border-radius: 4px; padding: 2px 6px; box-sizing: content-box; }
}
.branding-form { max-width: 640px; }
.branding-form .hint { display: block; margin: 4px 0 0; font-size: 12.5px; }
.logo-slot { display: grid; grid-template-columns: 200px 1fr auto; gap: 16px; align-items: center;
  border-top: 1px solid var(--line); padding-top: 14px; }
@media (max-width: 640px) { .logo-slot { grid-template-columns: 1fr; } }
.logo-preview { height: 72px; border: 1px dashed var(--line); border-radius: 6px; display: flex;
  align-items: center; justify-content: center; background: #fff; padding: 8px; }
.logo-preview.dark { background: #0d1117; }
.logo-preview img { max-height: 56px; max-width: 100%; object-fit: contain; }
