/* XProxy Cockpit — tema escuro, limpo, responsivo. */
:root {
  --bg: #0c0f16;
  --bg-soft: #141925;
  --bg-card: #161c2b;
  --border: #232b3d;
  --text: #e6ecf5;
  --muted: #8a96ad;
  --accent: #4f8cff;
  --accent-2: #22d3a6;
  --green: #28c76f;
  --red: #ff5b6e;
  --amber: #f5b94a;
  --shadow: 0 6px 20px rgba(0, 0, 0, 0.35);
  font-size: 16px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, Helvetica, Arial, sans-serif;
  background: radial-gradient(1200px 600px at 80% -10%, #16213a 0%, var(--bg) 55%);
  color: var(--text);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

/* Top bar */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.85rem 1.4rem;
  background: rgba(12, 15, 22, 0.85);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(8px);
  position: sticky;
  top: 0;
  z-index: 10;
}
.brand { display: flex; align-items: baseline; gap: 0.6rem; }
.logo {
  font-weight: 800;
  font-size: 1.35rem;
  letter-spacing: 0.5px;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.subtitle { color: var(--muted); font-size: 0.85rem; }

.conn-state {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.85rem;
  color: var(--muted);
}
.dot {
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--muted);
  box-shadow: 0 0 0 0 rgba(40, 199, 111, 0.5);
}
.conn-state.online .dot { background: var(--green); animation: pulse 2s infinite; }
.conn-state.offline .dot { background: var(--red); }
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(40, 199, 111, 0.5); }
  70% { box-shadow: 0 0 0 8px rgba(40, 199, 111, 0); }
  100% { box-shadow: 0 0 0 0 rgba(40, 199, 111, 0); }
}

.container {
  max-width: 1320px;
  margin: 0 auto;
  padding: 1.2rem 1.4rem 3rem;
}

/* Cards de métricas */
.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 0.9rem;
  margin-bottom: 1.2rem;
}
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 0.9rem 1rem;
  box-shadow: var(--shadow);
  transition: transform 0.15s ease, border-color 0.15s ease;
}
.card:hover { transform: translateY(-2px); border-color: #2f3a52; }
.card-label {
  color: var(--muted);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 0.35rem;
}
.card-value {
  font-size: 1.9rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
}
.card-value.flash { animation: flash 0.5s ease; }
@keyframes flash { 0% { color: var(--accent-2); } 100% { color: var(--text); } }

.health-row { display: flex; gap: 0.5rem; font-size: 1rem; }
.pill {
  font-size: 0.78rem;
  font-weight: 600;
  padding: 0.28rem 0.6rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: #1b2233;
  color: var(--muted);
}
.pill.ok { color: #0c1a12; background: var(--green); border-color: var(--green); }
.pill.bad { color: #1c0c10; background: var(--red); border-color: var(--red); }

/* Grid principal */
.grid {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 1.1rem;
  margin-bottom: 1.2rem;
}
@media (max-width: 920px) {
  .grid { grid-template-columns: 1fr; }
}

.panel {
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow);
  overflow: hidden;
}
.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.8rem 1rem;
  border-bottom: 1px solid var(--border);
}
.panel-head h2 { margin: 0; font-size: 0.95rem; font-weight: 600; }
.count {
  background: #1b2233;
  border: 1px solid var(--border);
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 600;
  padding: 0.15rem 0.55rem;
  border-radius: 999px;
}
.legend { display: flex; gap: 0.8rem; font-size: 0.75rem; color: var(--muted); }
.lg::before {
  content: "";
  display: inline-block;
  width: 10px; height: 10px;
  border-radius: 3px;
  margin-right: 0.35rem;
  vertical-align: middle;
}
.lg-qpm::before { background: var(--accent); }
.lg-heap::before { background: var(--amber); }

.chart-wrap { padding: 0.8rem 1rem 1rem; height: 300px; }
.chart-panel canvas { width: 100% !important; }

/* Lista de clients */
.client-list { list-style: none; margin: 0; padding: 0.4rem; max-height: 340px; overflow-y: auto; }
.client-list li {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  padding: 0.6rem 0.7rem;
  border-radius: 10px;
  transition: background 0.15s ease;
}
.client-list li:hover { background: #1b2233; }
.client-list .empty, .feed .empty { color: var(--muted); padding: 1.2rem; text-align: center; }
.client-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--green); flex: 0 0 auto; }
.client-meta { display: flex; flex-direction: column; min-width: 0; }
.client-name { font-weight: 600; font-size: 0.92rem; }
.client-sub { color: var(--muted); font-size: 0.76rem; }

/* Feed de queries */
.feed-panel .feed { max-height: 460px; overflow-y: auto; padding: 0.5rem; }
.feed-row {
  display: grid;
  grid-template-columns: 90px 1fr auto auto auto;
  gap: 0.8rem;
  align-items: center;
  padding: 0.55rem 0.7rem;
  border-radius: 10px;
  border: 1px solid transparent;
  animation: slideIn 0.25s ease;
}
.feed-row:hover { background: #1b2233; }
@keyframes slideIn { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; transform: none; } }
.q-status {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 0.22rem 0.5rem;
  border-radius: 6px;
  text-align: center;
}
.q-status.running { background: rgba(79, 140, 255, 0.16); color: var(--accent); }
.q-status.done { background: rgba(40, 199, 111, 0.16); color: var(--green); }
.q-status.failed { background: rgba(255, 91, 110, 0.16); color: var(--red); }
.q-sql {
  font-family: "JetBrains Mono", "Fira Code", ui-monospace, monospace;
  font-size: 0.82rem;
  color: #cdd6e6;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.q-id { color: var(--muted); font-size: 0.74rem; font-family: ui-monospace, monospace; }
.q-rows, .q-dur { color: var(--muted); font-size: 0.78rem; font-variant-numeric: tabular-nums; white-space: nowrap; }
.q-rows b, .q-dur b { color: var(--text); font-weight: 600; }

@media (max-width: 640px) {
  .feed-row { grid-template-columns: 78px 1fr; }
  .q-id, .q-rows, .q-dur { grid-column: 2; }
}

::-webkit-scrollbar { width: 9px; height: 9px; }
::-webkit-scrollbar-thumb { background: #2a3346; border-radius: 6px; }
::-webkit-scrollbar-track { background: transparent; }

/* ===== Abas principais (Cockpit / Cadastro) ===== */
.tabs { display: flex; gap: 0.3rem; }
.tab {
  background: transparent;
  border: 1px solid transparent;
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 600;
  padding: 0.4rem 0.9rem;
  border-radius: 9px;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}
.tab:hover { color: var(--text); background: #1b2233; }
.tab.active {
  color: var(--text);
  background: #1b2233;
  border-color: var(--border);
}
.view[hidden] { display: none; }

/* ===== Barra do Cadastro (sub-abas) ===== */
.admin-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}
.subtabs { display: flex; gap: 0.3rem; }
.subtab {
  background: var(--bg-soft);
  border: 1px solid var(--border);
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 600;
  padding: 0.45rem 1rem;
  border-radius: 9px;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}
.subtab:hover { color: var(--text); }
.subtab.active {
  color: #08111e;
  background: var(--accent);
  border-color: var(--accent);
}
.admin-sub { display: flex; flex-direction: column; gap: 1.1rem; }
.admin-sub[hidden] { display: none; }
.admin-sub .panel { padding-bottom: 0.3rem; }

/* ===== Alerta / feedback ===== */
.admin-alert {
  border-radius: 10px;
  padding: 0.7rem 1rem;
  margin-bottom: 1rem;
  font-size: 0.86rem;
  border: 1px solid var(--border);
}
.admin-alert[hidden] { display: none; }
.admin-alert.ok { background: rgba(40, 199, 111, 0.12); border-color: var(--green); color: #b9f4d3; }
.admin-alert.err { background: rgba(255, 91, 110, 0.12); border-color: var(--red); color: #ffc9d0; }
.admin-alert.warn { background: rgba(245, 185, 74, 0.12); border-color: var(--amber); color: #ffe6b3; }

/* ===== Formulários ===== */
.form-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.7rem;
  padding: 0.9rem 1rem 1rem;
}
.inp {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 9px;
  color: var(--text);
  font-size: 0.86rem;
  padding: 0.5rem 0.7rem;
  min-width: 180px;
  flex: 1 1 200px;
}
.inp:focus { outline: none; border-color: var(--accent); }
select.inp { flex: 0 1 320px; cursor: pointer; }
.chk {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  color: var(--muted);
  font-size: 0.84rem;
  white-space: nowrap;
  cursor: pointer;
  flex: 0 0 auto;
}
.chk input { accent-color: var(--accent); width: 16px; height: 16px; }

/* ===== Botões ===== */
.btn {
  font-size: 0.83rem;
  font-weight: 600;
  padding: 0.5rem 0.95rem;
  border-radius: 9px;
  border: 1px solid var(--border);
  cursor: pointer;
  background: var(--bg-card);
  color: var(--text);
  transition: filter 0.15s ease, background 0.15s ease;
  white-space: nowrap;
}
.btn:hover { filter: brightness(1.15); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #08111e; }
.btn-ghost { background: transparent; color: var(--muted); }
.btn-ghost:hover { color: var(--text); background: #1b2233; }
.btn-danger { background: transparent; border-color: var(--red); color: var(--red); }
.btn-danger:hover { background: var(--red); color: #1c0c10; filter: none; }
.btn-sm { padding: 0.32rem 0.6rem; font-size: 0.76rem; }

/* ===== Tabelas ===== */
.table-wrap { overflow-x: auto; padding: 0.2rem 0.4rem 0.6rem; }
.tbl { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
.tbl th {
  text-align: left;
  color: var(--muted);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 600;
  padding: 0.6rem 0.7rem;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.tbl td {
  padding: 0.55rem 0.7rem;
  border-bottom: 1px solid #1a2032;
  vertical-align: middle;
}
.tbl tr:hover td { background: #1b2233; }
.tbl .ta-r { text-align: right; }
.tbl .actions { display: flex; gap: 0.4rem; justify-content: flex-end; flex-wrap: wrap; }
.empty-row td { color: var(--muted); text-align: center; padding: 1.2rem; }
.mono { font-family: ui-monospace, "JetBrains Mono", monospace; font-size: 0.8rem; }
.tag {
  display: inline-block;
  font-size: 0.72rem;
  font-weight: 700;
  padding: 0.16rem 0.5rem;
  border-radius: 6px;
}
.tag.on { background: rgba(40, 199, 111, 0.16); color: var(--green); }
.tag.off { background: rgba(138, 150, 173, 0.16); color: var(--muted); }
.tag.live { background: rgba(79, 140, 255, 0.16); color: var(--accent); }
.tag.yes { background: rgba(245, 185, 74, 0.16); color: var(--amber); }

/* ===== ACL ===== */
.acl-pick {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  padding: 0.9rem 1rem;
}
.acl-lbl { color: var(--muted); font-size: 0.85rem; }
.acl-body { padding: 0.4rem 1rem 1.1rem; }
.acl-hint { color: var(--amber); font-size: 0.85rem; padding: 0.6rem 0; }
.acl-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 0.5rem;
}
.acl-item {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  padding: 0.55rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: var(--bg);
  cursor: pointer;
}
.acl-item:hover { border-color: #2f3a52; }
.acl-item input { accent-color: var(--accent); width: 16px; height: 16px; }
.acl-item .nm { font-size: 0.86rem; }
.acl-item .off-lbl { color: var(--muted); font-size: 0.74rem; margin-left: auto; }

/* ===== Modal de segredo ===== */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(4, 6, 11, 0.72);
  display: flex; align-items: center; justify-content: center;
  z-index: 50; padding: 1rem;
  backdrop-filter: blur(3px);
}
.modal-backdrop[hidden] { display: none; }
.modal {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 1.3rem 1.4rem;
  width: min(560px, 100%);
}
.modal h3 { margin: 0 0 0.5rem; font-size: 1.05rem; }
.modal-warn { color: var(--amber); font-size: 0.85rem; margin: 0 0 0.9rem; }
.secret-box {
  display: flex; gap: 0.6rem; align-items: center;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.6rem 0.7rem;
}
.secret-box code {
  flex: 1 1 auto;
  font-family: ui-monospace, monospace;
  font-size: 0.86rem;
  color: var(--accent-2);
  word-break: break-all;
}
.modal-actions { display: flex; justify-content: flex-end; margin-top: 1rem; }

@media (max-width: 640px) {
  .tabs { order: 3; width: 100%; justify-content: center; }
}
