:root {
  --bg: #0b0f14;
  --panel: #141b23;
  --panel-2: #1b2530;
  --line: #263241;
  --text: #e6edf3;
  --muted: #8b98a5;
  --green: #22c55e;
  --amber: #f59e0b;
  --red: #ef4444;
  --blue: #3b82f6;
  --radius: 14px;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 -apple-system, Segoe UI, Roboto, Ubuntu, sans-serif;
  min-height: 100vh;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 14px 20px;
  background: linear-gradient(180deg, #10171f, #0b0f14);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 5;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand .logo { font-size: 28px; }
.brand h1 { margin: 0; font-size: 18px; letter-spacing: .3px; }
.brand small { color: var(--muted); }

.stats { display: flex; gap: 10px; margin-left: auto; }
.stat {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 6px 14px;
  text-align: center;
  min-width: 74px;
}
.stat b { display: block; font-size: 20px; }
.stat span { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .5px; }
.stat.ok b { color: var(--green); }
.stat.qr b { color: var(--amber); }
.stat.off b { color: var(--red); }

.conn { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 12px; }
.conn .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--amber); }
.conn.online .dot { background: var(--green); }
.conn.offline .dot { background: var(--red); }

.toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 20px;
  flex-wrap: wrap;
}
.toolbar form { display: flex; gap: 6px; }
.toolbar .spacer { flex: 1; }
input, button {
  font: inherit;
  border-radius: 10px;
  border: 1px solid var(--line);
  outline: none;
}
input {
  background: var(--panel);
  color: var(--text);
  padding: 9px 12px;
}
input[type="number"] { width: 74px; }
button {
  background: var(--blue);
  color: #fff;
  padding: 9px 14px;
  cursor: pointer;
  transition: filter .15s, transform .05s;
}
button:hover { filter: brightness(1.1); }
button:active { transform: translateY(1px); }
button.ghost { background: var(--panel-2); }
button.warn { background: #7c5210; }
button.danger { background: #7c1d1d; }
.chk { color: var(--muted); display: flex; align-items: center; gap: 6px; }

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 14px;
  padding: 4px 20px 40px;
}
.empty { color: var(--muted); text-align: center; padding: 60px 20px; }

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.card-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
}
.card-head .name {
  font-weight: 600;
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  cursor: text;
}
.menu-btn { background: transparent; border: none; color: var(--muted); padding: 2px 6px; }

.badge {
  font-size: 11px;
  padding: 3px 8px;
  border-radius: 20px;
  text-transform: uppercase;
  letter-spacing: .4px;
  background: var(--panel-2);
  color: var(--muted);
  white-space: nowrap;
}
.badge[data-s="connected"] { background: rgba(34,197,94,.15); color: var(--green); }
.badge[data-s="qr"] { background: rgba(245,158,11,.15); color: var(--amber); }
.badge[data-s="authenticating"] { background: rgba(59,130,246,.15); color: var(--blue); }
.badge[data-s="starting"] { background: rgba(59,130,246,.12); color: var(--blue); }
.badge[data-s="disconnected"], .badge[data-s="error"] { background: rgba(239,68,68,.15); color: var(--red); }
.badge[data-s="stopped"], .badge[data-s="idle"] { background: var(--panel-2); color: var(--muted); }

.qrbox {
  aspect-ratio: 1 / 1;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #0e141b;
  position: relative;
}
.qrbox .qr {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: none;
  background: #fff;
}
.qrbox .qr-none {
  text-align: center;
  color: var(--muted);
  padding: 16px;
}
.qr-none .phone { font-size: 20px; font-weight: 700; color: var(--text); margin-bottom: 4px; }
.qr-none .hint { font-size: 12px; }
.card.show-qr .qr { display: block; }
.card.show-qr .qr-none { display: none; }

.card-foot {
  display: flex;
  gap: 4px;
  padding: 8px;
  flex-wrap: wrap;
}
.card-foot button { flex: 1; font-size: 12px; padding: 7px 4px; background: var(--panel-2); }
.card-foot button.warn { background: #5a3c0c; }
.card-foot button.danger { background: #5a1616; flex: 0 0 auto; }

/* ---------- Tabs / views ---------- */
.tabs { display: flex; gap: 4px; }
.tab {
  background: transparent; border: 1px solid transparent; color: var(--muted);
  padding: 7px 16px; border-radius: 10px;
}
.tab.active { background: var(--panel-2); color: var(--text); border-color: var(--line); }
.view.hidden, .hidden { display: none !important; }
.primary { background: var(--green); }
.muted { color: var(--muted); }

/* ---------- Campanhas ---------- */
.camp-form {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  margin: 4px 20px 16px; padding: 18px; display: flex; flex-direction: column; gap: 12px;
}
.camp-form h3 { margin: 0; }
.fld { display: flex; flex-direction: column; gap: 5px; }
.fld > span { color: var(--muted); font-size: 12px; }
.fld code { background: var(--panel-2); padding: 1px 5px; border-radius: 5px; }
.camp-form textarea {
  background: var(--panel-2); color: var(--text); border: 1px solid var(--line);
  border-radius: 10px; padding: 10px; font: inherit; resize: vertical;
}
.acc-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 6px; }
.acc { display: flex; align-items: center; gap: 6px; background: var(--panel-2);
  border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px; font-size: 13px; }
fieldset.ab { border: 1px solid var(--line); border-radius: 12px; padding: 12px; }
fieldset.ab legend { color: var(--muted); padding: 0 6px; font-size: 12px; }
.ab-checks { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 6px; margin-bottom: 10px; }
.ab-nums { display: flex; flex-wrap: wrap; gap: 10px; }
.numf { display: flex; flex-direction: column; gap: 3px; }
.numf > span { color: var(--muted); font-size: 11px; }
.numf input { width: 120px; }
.camp-actions { display: flex; gap: 8px; }

.camp-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 14px; padding: 4px 20px 40px; }
.ccard { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; display: flex; flex-direction: column; gap: 10px; }
.cc-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.cbadge { font-size: 11px; padding: 3px 8px; border-radius: 20px; text-transform: uppercase; letter-spacing: .4px; background: var(--panel-2); color: var(--muted); }
.cbadge[data-s="running"] { background: rgba(59,130,246,.15); color: var(--blue); }
.cbadge[data-s="done"] { background: rgba(34,197,94,.15); color: var(--green); }
.cbadge[data-s="paused"] { background: rgba(245,158,11,.15); color: var(--amber); }
.cbadge[data-s="stopped"], .cbadge[data-s="error"] { background: rgba(239,68,68,.15); color: var(--red); }
.bar { height: 8px; background: var(--panel-2); border-radius: 6px; overflow: hidden; }
.bar-fill { height: 100%; background: linear-gradient(90deg, var(--blue), var(--green)); transition: width .3s; }
.cc-stats { display: flex; gap: 12px; font-size: 12px; flex-wrap: wrap; }
.cc-stats .ok { color: var(--green); }
.cc-stats .bad { color: var(--red); }
.cc-stats .warn { color: var(--amber); }
.cc-foot { display: flex; gap: 5px; flex-wrap: wrap; }
.cc-foot button { font-size: 12px; padding: 7px 10px; background: var(--panel-2); }
.cc-foot button.primary { background: var(--green); }
.cc-foot button.warn { background: #5a3c0c; }
.cc-foot button.danger { background: #5a1616; }
.cc-logs { background: #0b1017; border: 1px solid var(--line); border-radius: 8px; padding: 10px; font-size: 11px; max-height: 180px; overflow: auto; white-space: pre-wrap; color: var(--muted); margin: 0; }

.rep-badge { font-size: 10px; padding: 2px 7px; border-radius: 20px; background: var(--panel-2); color: var(--muted); white-space: nowrap; }
.rep-badge[data-g="Confiável"] { background: rgba(59,130,246,.15); color: #7dd3fc; }
.rep-badge[data-g="Saudável"] { background: rgba(34,197,94,.15); color: var(--green); }
.rep-badge[data-g="Aquecendo"] { background: rgba(245,158,11,.15); color: var(--amber); }
.rep-badge[data-g="Em risco"] { background: rgba(239,68,68,.15); color: var(--red); }
.rep-line { font-size: 10px; color: var(--muted); padding: 2px 10px 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.alerts-btn { position: relative; }
.alerts-btn b { color: var(--amber); }
.alerts-feed {
  position: fixed; top: 62px; right: 16px; width: 340px; max-height: 60vh; overflow: auto;
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 8px; z-index: 20;
  box-shadow: 0 12px 40px rgba(0,0,0,.5);
}
.al { font-size: 12px; padding: 8px 10px; border-radius: 8px; margin-bottom: 5px; background: var(--panel-2); border-left: 3px solid var(--muted); }
.al span { display: block; color: var(--muted); font-size: 10px; margin-top: 2px; }
.al.danger { border-left-color: var(--red); }
.al.warn { border-left-color: var(--amber); }
.al.info { border-left-color: var(--blue); }

.toasts { position: fixed; bottom: 16px; right: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 30; }
.toast {
  background: var(--panel); border: 1px solid var(--line); border-left: 4px solid var(--blue);
  border-radius: 10px; padding: 10px 14px; font-size: 13px; max-width: 360px;
  box-shadow: 0 8px 24px rgba(0,0,0,.5); animation: slidein .25s ease;
}
.toast.danger { border-left-color: var(--red); }
.toast.warn { border-left-color: var(--amber); }
.toast.info { border-left-color: var(--blue); }
.toast.out { opacity: 0; transform: translateX(20px); transition: .4s; }
@keyframes slidein { from { opacity: 0; transform: translateX(20px); } to { opacity: 1; transform: none; } }

.card.health-lost { border-color: var(--red); box-shadow: 0 0 0 1px rgba(239,68,68,.35); }
.dotc { display: inline-block; width: 8px; height: 8px; border-radius: 50%; }
.dotc.on { background: var(--green); }
.dotc.off { background: var(--muted); }
.worker-tag { font-size: 10px; background: var(--panel-2); border: 1px solid var(--line); border-radius: 6px; padding: 1px 6px; color: var(--muted); }
.proxy-line { font-size: 10px; color: var(--muted); padding: 4px 10px 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

@media (max-width: 640px) {
  .stats { flex-wrap: wrap; }
  .topbar { flex-wrap: wrap; }
}
