:root {
  --bg: #0b1220;
  --bg-2: #0f1829;
  --card: #131e33;
  --card-2: #18253d;
  --line: #22314d;
  --text: #e6edf7;
  --muted: #8a9bb8;
  --faint: #5d6f8f;
  --accent: #38bdf8;
  --rx: #38bdf8;
  --tx: #c084fc;
  --ok: #22c55e;
  --warn: #f59e0b;
  --crit: #ef4444;
  --unk: #64748b;
  --radius: 14px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  min-height: 100vh;
}
a { color: inherit; text-decoration: none; }
button, input, textarea { font: inherit; color: inherit; }
.boot { display: grid; place-items: center; min-height: 100vh; color: var(--muted); }

/* ---------- topo ---------- */
.top {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 10px;
  padding: calc(12px + var(--safe-top)) 16px 12px;
  background: rgba(11, 18, 32, .88);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}
.top h1 { font-size: 17px; margin: 0; font-weight: 650; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.brand { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 0; }
.brand img { width: 28px; height: 28px; border-radius: 8px; }
.brand h1 { flex: none; }
.icon-btn {
  display: inline-grid; place-items: center; width: 38px; height: 38px; flex: none;
  border-radius: 10px; border: 1px solid var(--line); background: var(--card); cursor: pointer;
}
.icon-btn svg { width: 20px; height: 20px; stroke: var(--text); fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.conn { font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 6px; flex: none; }
.conn .dot { width: 8px; height: 8px; }

main { max-width: 980px; margin: 0 auto; padding: 16px 16px calc(32px + var(--safe-bottom)); }

/* ---------- elementos ---------- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.section-title { font-size: 12px; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); margin: 22px 2px 10px; font-weight: 600; }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.small { font-size: 13px; }
.row { display: flex; align-items: center; gap: 8px; }
.grow { flex: 1; min-width: 0; }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mono { font-variant-numeric: tabular-nums; }

.dot { width: 10px; height: 10px; border-radius: 50%; flex: none; background: var(--unk); }
.dot.ok { background: var(--ok); box-shadow: 0 0 0 4px rgba(34, 197, 94, .15); }
.dot.crit { background: var(--crit); box-shadow: 0 0 0 4px rgba(239, 68, 68, .18); animation: pulse 1.4s infinite; }
.dot.warn { background: var(--warn); }
@keyframes pulse { 50% { box-shadow: 0 0 0 7px rgba(239, 68, 68, 0); } }

.chip {
  display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px;
  border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap;
  background: var(--card-2); color: var(--muted); border: 1px solid var(--line);
}
.chip.ok { color: #86efac; background: rgba(34, 197, 94, .12); border-color: rgba(34, 197, 94, .3); }
.chip.crit { color: #fca5a5; background: rgba(239, 68, 68, .14); border-color: rgba(239, 68, 68, .35); }
.chip.warn { color: #fcd34d; background: rgba(245, 158, 11, .12); border-color: rgba(245, 158, 11, .3); }
.chip.accent { color: #7dd3fc; background: rgba(56, 189, 248, .12); border-color: rgba(56, 189, 248, .3); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 10px 16px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--card-2); cursor: pointer; font-weight: 600; min-height: 42px;
}
.btn:hover { border-color: #33476b; }
.btn.primary { background: var(--accent); color: #04223a; border-color: var(--accent); }
.btn.danger { color: #fca5a5; border-color: rgba(239, 68, 68, .4); background: transparent; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .5; cursor: default; }
.btns { display: flex; gap: 8px; flex-wrap: wrap; }

label.field { display: block; margin-bottom: 12px; }
label.field span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
input[type=text], input[type=password], textarea {
  width: 100%; padding: 11px 12px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--bg-2); outline: none;
}
input:focus, textarea:focus { border-color: var(--accent); }

/* ---------- login ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.login .card { width: 100%; max-width: 360px; padding: 24px; }
.login .logo { display: flex; align-items: center; gap: 12px; margin-bottom: 20px; }
.login .logo img { width: 44px; height: 44px; border-radius: 12px; }
.login h1 { margin: 0; font-size: 20px; }
.err { color: #fca5a5; font-size: 13px; min-height: 18px; margin: 4px 0 10px; }

/* ---------- lista de RBs ---------- */
.rb-list { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); }
.rb-card { display: block; transition: border-color .15s, transform .15s; }
.rb-card:hover { border-color: #33476b; }
.rb-card:active { transform: scale(.99); }
.rb-card h2 { font-size: 17px; margin: 0; }
.rb-card .meta { font-size: 12px; margin: 4px 0 12px; }
.link-pills { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }
.exit { display: flex; align-items: center; gap: 10px; padding-top: 12px; border-top: 1px solid var(--line); font-size: 13px; }
.rates { display: flex; gap: 12px; font-size: 13px; }
.rates .rx { color: var(--rx); }
.rates .tx { color: var(--tx); }
.empty { text-align: center; padding: 40px 20px; }
.empty p { color: var(--muted); }

/* ---------- detalhe ---------- */
.banner .rates { margin-left: auto; }
.banner { flex-wrap: wrap; }
.banner > .grow { min-width: 180px; }
.banner { display: flex; align-items: center; gap: 12px; padding: 14px; border-radius: var(--radius); border: 1px solid var(--line); background: var(--card); }
.banner.crit { border-color: rgba(239, 68, 68, .5); background: linear-gradient(0deg, rgba(239, 68, 68, .1), rgba(239, 68, 68, .1)), var(--card); }
.banner .big { font-size: 16px; font-weight: 650; }

.links-grid { display: grid; gap: 10px; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); }
.link-card { display: flex; align-items: center; gap: 12px; }
.link-card .name { font-weight: 650; }
.link-card.down { border-color: rgba(239, 68, 68, .5); }

.if-grid { display: grid; gap: 10px; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.if-card { cursor: pointer; transition: border-color .15s; }
.if-card.sel { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent) inset; }
.if-card .title { font-weight: 650; }
.if-card .rates { margin: 8px 0 6px; font-size: 15px; font-weight: 600; }
.if-card canvas { display: block; width: 100%; height: 42px; }

.chart-card { padding: 12px 12px 8px; }
.chart-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 8px; }
.chart-head .title { font-weight: 650; flex: 1; min-width: 140px; }
.tabs { display: inline-flex; background: var(--bg-2); border: 1px solid var(--line); border-radius: 10px; padding: 3px; }
.tabs button { border: 0; background: transparent; padding: 6px 12px; border-radius: 8px; cursor: pointer; color: var(--muted); font-weight: 600; font-size: 13px; }
.tabs button.on { background: var(--card-2); color: var(--text); }
.chart-wrap { position: relative; height: 230px; }
.chart-wrap canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
.legend { display: flex; gap: 16px; font-size: 12px; color: var(--muted); padding: 6px 4px 0; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }

.info-grid { display: grid; gap: 10px; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }
.info-grid .card { padding: 12px 14px; }
.info-grid .k { font-size: 12px; color: var(--muted); }
.info-grid .v { font-size: 18px; font-weight: 650; margin-top: 2px; }

.events { list-style: none; margin: 0; padding: 0; }
.events li { display: flex; gap: 12px; padding: 11px 2px; border-bottom: 1px solid var(--line); align-items: flex-start; }
.events li:last-child { border-bottom: 0; }
.events .dot { margin-top: 6px; }
.events time { font-size: 12px; color: var(--muted); white-space: nowrap; }

/* ---------- configuracoes ---------- */
.cfg-item { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.cfg-item:last-child { border-bottom: 0; }
pre.script {
  max-height: 340px; overflow: auto; margin: 0 0 12px; padding: 12px; border-radius: 10px;
  background: #070c16; border: 1px solid var(--line); font-size: 12px; line-height: 1.5; white-space: pre;
}
.hint { font-size: 13px; color: var(--muted); background: var(--bg-2); border: 1px dashed var(--line); border-radius: 10px; padding: 10px 12px; margin: 10px 0; }

/* ---------- modal / toast ---------- */
.modal-bg { position: fixed; inset: 0; z-index: 50; background: rgba(3, 7, 15, .7); display: grid; place-items: end center; padding: 16px; }
@media (min-width: 640px) { .modal-bg { place-items: center; } }
.modal { width: 100%; max-width: 720px; max-height: calc(100vh - 32px); overflow: auto; }
.modal h3 { margin: 0 0 6px; }

#toasts { position: fixed; z-index: 60; left: 50%; transform: translateX(-50%); bottom: calc(16px + var(--safe-bottom)); display: grid; gap: 8px; width: min(440px, calc(100vw - 32px)); }
.toast { padding: 12px 14px; border-radius: 12px; background: var(--card-2); border: 1px solid var(--line); box-shadow: 0 10px 30px rgba(0, 0, 0, .4); display: flex; gap: 10px; align-items: center; animation: up .2s ease-out; }
.toast .dot { margin: 0; }
@keyframes up { from { transform: translateY(10px); opacity: 0; } }
