:root {
  --bg: #f4f6f9;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --border: #e2e7ee;
  --border-strong: #cfd7e2;
  --text: #17202b;
  --text-2: #4a5a6c;
  --text-3: #7a8899;
  --brand: #1f4e79;
  --brand-2: #2b6cb0;
  --brand-soft: #e8f1fa;
  --ok: #1e7d46;      --ok-soft: #e4f4ea;
  --warn: #9a5b00;    --warn-soft: #fdf1dc;
  --bad: #b42318;     --bad-soft: #fde8e6;
  --idle: #5b6878;    --idle-soft: #edf0f4;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  --mono: ui-monospace, "Cascadia Mono", "SFMono-Regular", Consolas, monospace;
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
}
* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; }
a { color: var(--brand-2); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; font-weight: 600; }
h1 { font-size: 22px; }
h2 { font-size: 16px; }
h3 { font-size: 14px; color: var(--text-2); }
button, input, select, textarea { font: inherit; color: inherit; }
.mono { font-family: var(--mono); font-size: 12.5px; }
.muted { color: var(--text-3); }
.small { font-size: 12px; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.hidden { display: none !important; }
.mt { margin-top: 16px; }
.center { text-align: center; }
.grow { flex: 1; min-width: 0; }
.modal.wide { max-width: 760px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* ---------- Layout ---------- */
.shell { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; }
.sidebar { background: #13293f; color: #c9d6e3; display: flex; flex-direction: column; padding: 18px 12px; position: sticky; top: 0; height: 100vh; }
.brand { display: flex; align-items: center; gap: 10px; color: #fff; font-weight: 600; font-size: 15px; padding: 4px 8px 18px; }
.brand img { width: 26px; height: 26px; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a { color: #c9d6e3; padding: 9px 10px; border-radius: 8px; display: flex; align-items: center; gap: 10px; }
.nav a:hover { background: rgba(255,255,255,.07); text-decoration: none; color: #fff; }
.nav a.active { background: rgba(255,255,255,.12); color: #fff; font-weight: 600; }
.nav .sep { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: #7f93a8; padding: 16px 10px 6px; }
.sidebar .foot { margin-top: auto; border-top: 1px solid rgba(255,255,255,.1); padding: 12px 8px 0; font-size: 12.5px; }
.sidebar .foot .who { color: #fff; font-weight: 600; }
.sidebar .foot select { width: 100%; margin: 8px 0; background: #1b3753; color: #fff; border: 1px solid #2c4c6c; border-radius: 6px; padding: 5px; }
.sidebar .foot button { background: none; border: 0; color: #9fb4c9; padding: 0; cursor: pointer; }
.sidebar .foot button:hover { color: #fff; text-decoration: underline; }
.main { padding: 24px 28px 48px; min-width: 0; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 18px; flex-wrap: wrap; }
.page-head p { margin: 4px 0 0; color: var(--text-2); }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* ---------- Cards ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-h { display: flex; justify-content: space-between; align-items: center; padding: 14px 16px; border-bottom: 1px solid var(--border); gap: 10px; }
.card-b { padding: 16px; }
.grid { display: grid; gap: 16px; align-items: start; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
@media (max-width: 1100px) { .grid-2, .grid-3 { grid-template-columns: 1fr; } }

.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi { display: block; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); color: var(--text); border-left: 4px solid var(--border-strong); }
.kpi:hover { text-decoration: none; border-color: var(--brand-2); }
.kpi .label { color: var(--text-2); font-size: 12.5px; display: flex; align-items: center; gap: 6px; }
.kpi .value { font-size: 28px; font-weight: 600; margin-top: 4px; font-variant-numeric: tabular-nums; }
.kpi.ok { border-left-color: var(--ok); }
.kpi.warn { border-left-color: #d08a12; }
.kpi.bad { border-left-color: var(--bad); }
.kpi.idle { border-left-color: var(--idle); }
.kpi.brand { border-left-color: var(--brand); }

/* ---------- Status ---------- */
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 2px 9px 2px 7px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; flex: none; }
.st-online { background: var(--ok-soft); color: var(--ok); } .st-online .dot, .dot.st-online { background: var(--ok); }
.st-sem_comunicacao { background: var(--warn-soft); color: var(--warn); } .st-sem_comunicacao .dot, .dot.st-sem_comunicacao { background: #d08a12; }
.st-offline { background: var(--bad-soft); color: var(--bad); } .st-offline .dot, .dot.st-offline { background: var(--bad); }
.st-desligado { background: #e7e9ee; color: #3d4757; } .st-desligado .dot, .dot.st-desligado { background: #3d4757; }
.st-aguardando { background: var(--idle-soft); color: var(--idle); } .st-aguardando .dot, .dot.st-aguardando { background: var(--idle); }
.tag { display: inline-block; padding: 1px 8px; border-radius: 6px; background: var(--idle-soft); color: var(--text-2); font-size: 12px; margin: 0 4px 2px 0; }
.tag.warn { background: var(--warn-soft); color: var(--warn); }
.tag.bad { background: var(--bad-soft); color: var(--bad); }
.tag.info { background: var(--brand-soft); color: var(--brand); }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 9px 12px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-size: 12px; font-weight: 600; color: var(--text-2); background: var(--surface-2); white-space: nowrap; position: sticky; top: 0; }
th button.sort { background: none; border: 0; padding: 0; font-weight: 600; color: inherit; cursor: pointer; }
th button.sort:hover { color: var(--brand-2); }
tbody tr:hover { background: #fafcff; }
tr.clickable { cursor: pointer; }
td.trunc { max-width: 230px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
td.num { text-align: right; font-variant-numeric: tabular-nums; }
.empty { padding: 40px 16px; text-align: center; color: var(--text-3); }
dl.kv { display: grid; grid-template-columns: 210px 1fr; margin: 0; }
dl.kv dt { color: var(--text-2); padding: 7px 0; border-bottom: 1px solid var(--border); }
dl.kv dd { margin: 0; padding: 7px 0; border-bottom: 1px solid var(--border); word-break: break-word; }
.na { color: var(--text-3); font-style: italic; }

/* ---------- Forms ---------- */
.btn { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--border-strong); background: var(--surface); padding: 7px 13px; border-radius: 8px; cursor: pointer; font-weight: 500; white-space: nowrap; color: var(--text); }
.btn:hover { border-color: var(--brand-2); text-decoration: none; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: #193f63; }
.btn.danger { color: var(--bad); border-color: #f0b9b3; }
.btn.danger:hover { background: var(--bad-soft); }
.btn.sm { padding: 4px 9px; font-size: 12.5px; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.field { display: flex; flex-direction: column; gap: 5px; margin-bottom: 12px; }
.field label { font-size: 12.5px; color: var(--text-2); font-weight: 500; }
.field .hint { font-size: 12px; color: var(--text-3); }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=date], input[type=search], select, textarea {
  border: 1px solid var(--border-strong); border-radius: 8px; padding: 7px 10px; background: #fff; min-width: 0; }
input:focus, select:focus, textarea:focus, .btn:focus-visible, a:focus-visible { outline: 2px solid #9cc3ea; outline-offset: 1px; }
textarea { min-height: 80px; resize: vertical; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 16px; }
@media (max-width: 800px) { .form-grid { grid-template-columns: 1fr; } }
.filters { display: flex; flex-wrap: wrap; gap: 8px; padding: 12px 16px; border-bottom: 1px solid var(--border); align-items: center; }
.filters input[type=search] { width: 280px; }
.filters select, .filters input { padding: 6px 8px; }
.filters input.ram { width: 92px; }
.check { display: inline-flex; align-items: center; gap: 6px; color: var(--text-2); white-space: nowrap; }
.status-filter { display: inline-flex; border: 1px solid var(--border-strong); border-radius: 8px; overflow: hidden; }
.status-filter button { border: 0; background: #fff; padding: 6px 10px; cursor: pointer; border-right: 1px solid var(--border); display: inline-flex; align-items: center; gap: 6px; }
.status-filter button:last-child { border-right: 0; }
.status-filter button[aria-pressed=true] { background: var(--brand-soft); color: var(--brand); font-weight: 600; }
.pager { display: flex; justify-content: space-between; align-items: center; padding: 10px 16px; color: var(--text-2); }

/* ---------- Detail ---------- */
.detail-head { display: flex; gap: 16px; align-items: center; flex-wrap: wrap; }
.detail-head .meta { display: flex; gap: 18px; flex-wrap: wrap; color: var(--text-2); margin-top: 6px; }
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); margin: 18px 0 16px; overflow-x: auto; }
.tabs button { background: none; border: 0; padding: 10px 14px; cursor: pointer; color: var(--text-2); border-bottom: 2px solid transparent; font-weight: 500; white-space: nowrap; }
.tabs button[aria-selected=true] { color: var(--brand); border-bottom-color: var(--brand); }
.notice { border-radius: var(--radius); padding: 12px 14px; margin-bottom: 14px; display: flex; gap: 12px; align-items: flex-start; border: 1px solid; }
.notice.info { background: var(--brand-soft); border-color: #c6dbf0; color: #1b426a; }
.notice.warn { background: var(--warn-soft); border-color: #f2d49f; color: #6f4200; }
.notice.bad { background: var(--bad-soft); border-color: #f4c2bc; color: #8a1c12; }
.notice .grow { flex: 1; }
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { display: grid; grid-template-columns: 170px 1fr; gap: 14px; padding: 11px 16px; border-bottom: 1px solid var(--border); }
.timeline li:last-child { border-bottom: 0; }
.timeline .when { color: var(--text-2); font-size: 12.5px; }
.timeline .what { font-weight: 500; }
.changes { margin: 6px 0 0; padding: 0; list-style: none; font-size: 12.5px; color: var(--text-2); }
.changes li { display: block; padding: 2px 0; border: 0; }
.changes .old { color: var(--bad); text-decoration: line-through; }
.changes .new { color: var(--ok); }
.bar { height: 8px; background: var(--idle-soft); border-radius: 99px; overflow: hidden; min-width: 80px; }
.bar > span { display: block; height: 100%; background: var(--brand-2); border-radius: 99px; }
.bar.ok > span { background: var(--ok); }
.bar.warn > span { background: #d08a12; }
.bar.bad > span { background: var(--bad); }

/* ---------- Auth ---------- */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: linear-gradient(160deg, #13293f 0%, #1f4e79 100%); }
.auth .card { width: 100%; max-width: 400px; }
.auth .card-b { padding: 28px; }
.auth h1 { margin-bottom: 4px; }
.auth p.lead { margin: 0 0 20px; color: var(--text-2); }
.auth .btn.primary { width: 100%; justify-content: center; padding: 10px; }
.qr { display: flex; justify-content: center; margin: 12px 0; }
.qr { background: #fff; padding: 8px; }
.qr svg { width: 220px; height: 220px; }
.code-box { font-family: var(--mono); font-size: 20px; letter-spacing: .08em; padding: 14px; background: var(--surface-2); border: 1px dashed var(--border-strong); border-radius: 8px; text-align: center; user-select: all; }
pre.cmd { background: #0f1b28; color: #d6e2ee; padding: 12px 14px; border-radius: 8px; overflow-x: auto; font-family: var(--mono); font-size: 12.5px; white-space: pre-wrap; word-break: break-all; }
.err { color: var(--bad); margin: 8px 0; font-size: 13px; }

/* ---------- Toast / modal ---------- */
.toast { position: fixed; right: 20px; bottom: 20px; background: #17202b; color: #fff; padding: 11px 16px; border-radius: 8px; box-shadow: 0 6px 20px rgba(0,0,0,.2); z-index: 50; max-width: 420px; }
.toast.error { background: var(--bad); }
.modal-bg { position: fixed; inset: 0; background: rgba(15, 25, 40, .45); display: grid; place-items: center; z-index: 40; padding: 16px; }
.modal { background: #fff; border-radius: 12px; width: 100%; max-width: 520px; box-shadow: 0 20px 50px rgba(0,0,0,.25); max-height: 90vh; overflow: auto; }
.modal .card-b { padding: 20px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; padding: 0 20px 20px; }
.refresh-note { font-size: 12px; color: var(--text-3); }

@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; }
  .main { padding: 16px; }
  dl.kv { grid-template-columns: 1fr; }
  dl.kv dt { border-bottom: 0; padding-bottom: 0; }
  .timeline li { grid-template-columns: 1fr; gap: 2px; }
}
