:root {
  --bg: #0b1020;
  --panel: #131a2e;
  --panel2: #1a2340;
  --line: #26304f;
  --text: #e6eaf5;
  --muted: #8b95b3;
  --up: #22c55e;
  --slow: #f59e0b;
  --down: #ef4444;
  --pending: #64748b;
  --accent: #38bdf8;
  --card: 240px;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text);
  font: 14px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
button, input, select { font: inherit; color: inherit; }

/* ---------- header ---------- */
.top { position: sticky; top: 0; z-index: 10; display: flex; flex-wrap: wrap; gap: 12px 20px;
  align-items: center; padding: 12px 20px; background: rgba(11,16,32,.92);
  backdrop-filter: blur(8px); border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 10px; }
.brand h1 { font-size: 17px; margin: 0; font-weight: 650; letter-spacing: .2px; }
.dot-live { width: 10px; height: 10px; border-radius: 50%; background: var(--up);
  box-shadow: 0 0 0 0 rgba(34,197,94,.6); animation: live 2s infinite; }
.dot-live.bad { background: var(--down); box-shadow: 0 0 0 0 rgba(239,68,68,.6); }
@keyframes live { 70% { box-shadow: 0 0 0 8px rgba(0,0,0,0); } 100% { box-shadow: 0 0 0 0 rgba(0,0,0,0); } }

.counters { display: flex; gap: 6px; flex-wrap: wrap; }
.pill { border: 1px solid var(--line); background: var(--panel); border-radius: 999px;
  padding: 4px 12px; cursor: pointer; color: var(--muted); }
.pill b { color: var(--text); margin-right: 2px; }
.pill.up b { color: var(--up); } .pill.slow b { color: var(--slow); } .pill.down b { color: var(--down); }
.pill.active { border-color: var(--accent); color: var(--text); }
.pill.down.alert { background: rgba(239,68,68,.15); border-color: var(--down); }

.tools { margin-left: auto; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.tools input[type=search], .tools select { background: var(--panel); border: 1px solid var(--line);
  border-radius: 8px; padding: 6px 10px; min-width: 0; }
.tools input[type=search] { width: 160px; }
.next { color: var(--muted); font-variant-numeric: tabular-nums; min-width: 72px; text-align: right; }
.size { display: flex; align-items: center; gap: 6px; color: var(--muted); }
.size svg { width: 14px; fill: currentColor; }
.size input { width: 90px; accent-color: var(--accent); }
button.icon, .btn, dialog button { background: var(--panel); border: 1px solid var(--line);
  border-radius: 8px; padding: 6px 10px; cursor: pointer; text-decoration: none; }
button.icon:hover, .btn:hover, dialog button:hover { border-color: var(--accent); }
button.icon.off { opacity: .45; }
button.primary { background: var(--accent); color: #04121c; border: 0; border-radius: 8px;
  padding: 7px 14px; font-weight: 600; cursor: pointer; }
button.danger { color: var(--down); }

/* ---------- grid ---------- */
main { padding: 18px 20px 40px; }
.grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fill, minmax(var(--card), 1fr)); }
.card { position: relative; background: var(--panel); border: 1px solid var(--line);
  border-radius: 12px; overflow: hidden; transition: border-color .2s, transform .15s; }
.card:hover { transform: translateY(-2px); }
.card.dragging { opacity: .4; }
.card.drop { outline: 2px dashed var(--accent); }
.card::before { content: ""; position: absolute; inset: 0 0 auto 0; height: 3px; background: var(--pending); z-index: 2; }
.card.up::before { background: var(--up); }
.card.slow::before { background: var(--slow); }
.card.down { border-color: var(--down); animation: pulse 1.6s infinite; }
.card.down::before { background: var(--down); }
.card.disabled { opacity: .5; }
@keyframes pulse { 50% { box-shadow: 0 0 0 4px rgba(239,68,68,.25); } }

.thumb { position: relative; aspect-ratio: 16/9; background: #0a0f1d center/cover no-repeat;
  display: block; cursor: pointer; }
.thumb img { width: 100%; height: 100%; object-fit: cover; object-position: top; display: block; }
.thumb .noimg { position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted); font-size: 12px; }
.card.down .thumb img { filter: grayscale(1) brightness(.5); }
.down-overlay { position: absolute; inset: 0; display: none; place-items: center; text-align: center;
  color: #fff; font-weight: 700; padding: 8px; }
.card.down .down-overlay { display: grid; }
.down-overlay small { display: block; font-weight: 400; opacity: .85; margin-top: 2px; }

.badge { position: absolute; top: 8px; left: 8px; z-index: 3; font-size: 11px; font-weight: 700;
  padding: 2px 8px; border-radius: 999px; background: var(--pending); color: #fff; letter-spacing: .3px; }
.up .badge { background: var(--up); color: #052e14; }
.slow .badge { background: var(--slow); color: #3a2300; }
.down .badge { background: var(--down); }

.hover-actions { position: absolute; top: 6px; right: 6px; z-index: 3; display: flex; gap: 4px; opacity: 0; transition: opacity .15s; }
.card:hover .hover-actions { opacity: 1; }
.hover-actions button { background: rgba(10,15,29,.85); border: 1px solid var(--line); color: var(--text);
  border-radius: 6px; width: 26px; height: 26px; cursor: pointer; font-size: 13px; line-height: 1; }
.hover-actions button:hover { border-color: var(--accent); }

.info { padding: 8px 10px 10px; }
.name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.host { color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.host .grp { color: var(--accent); }
.metrics { display: flex; justify-content: space-between; gap: 8px; margin-top: 6px; font-size: 12px;
  color: var(--muted); font-variant-numeric: tabular-nums; }
.metrics b { color: var(--text); font-weight: 600; }
.spark { display: flex; align-items: flex-end; gap: 1px; height: 22px; margin-top: 6px; }
.spark i { flex: 1; min-width: 1px; background: var(--up); border-radius: 1px; opacity: .85; }
.spark i.s { background: var(--slow); }
.spark i.d { background: var(--down); height: 100% !important; }
.spark i.e { background: var(--line); height: 20% !important; }

/* tamanhos compactos: esconde detalhes */
.compact .host, .compact .spark { display: none; }
.compact .info { padding: 6px 8px 8px; }
.compact .name { font-size: 13px; }

.empty { text-align: center; color: var(--muted); padding: 80px 0; }

/* ---------- dialogs ---------- */
dialog { background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: 14px;
  padding: 0; width: min(480px, calc(100vw - 32px)); }
dialog::backdrop { background: rgba(0,0,0,.6); }
dialog form { padding: 20px; display: grid; gap: 12px; }
dialog h2 { margin: 0 0 4px; font-size: 17px; }
dialog label { display: grid; gap: 4px; color: var(--muted); font-size: 13px; }
dialog input:not([type=checkbox]), dialog select { background: var(--bg); border: 1px solid var(--line);
  border-radius: 8px; padding: 8px 10px; color: var(--text); }
dialog input:focus, dialog select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
dialog label.chk { display: flex; align-items: center; gap: 8px; color: var(--text); }
dialog details { border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; display: grid; gap: 10px; }
dialog details[open] { padding-bottom: 12px; }
dialog details > label { margin-top: 10px; }
dialog summary { cursor: pointer; color: var(--muted); }
.actions { display: flex; gap: 8px; margin-top: 6px; }
.spacer { flex: 1; }
.err { color: var(--down); margin: 0; min-height: 1em; font-size: 13px; }
.io { display: flex; gap: 8px; flex-wrap: wrap; }

.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--panel2);
  border: 1px solid var(--line); padding: 10px 16px; border-radius: 10px; z-index: 50; }

/* modo TV */
body.tv .tools > :not(#btnTv):not(.next) { display: none; }
body.tv main { padding: 12px; }

@media (max-width: 720px) {
  .top { padding: 10px 16px; }
  main { padding: 14px 16px 30px; }
  .tools { margin-left: 0; width: 100%; }
  .tools input[type=search] { flex: 1 1 140px; width: auto; }
  .tools select { flex: 1 1 140px; }
  .size { display: none; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(min(var(--card), 100%), 1fr)); }
}
