/* RealLead self-hosted — painel de operações */
@import url('https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@500;600;700&family=Inter:wght@400;500;600&family=IBM+Plex+Mono:wght@500;600&display=swap');

:root {
  --ink: #0e1613;
  --paper: #eef0ec;
  --surface: #ffffff;
  --line: #dfe3dd;
  --muted: #6a7469;
  --signal: #0f9d58;      /* entradas / positivo */
  --signal-soft: #e6f4ec;
  --churn: #d84a4f;       /* saídas */
  --churn-soft: #fbe9ea;
  --amber: #d9930b;       /* capacidade */
  --display: 'Space Grotesk', system-ui, sans-serif;
  --body: 'Inter', system-ui, sans-serif;
  --mono: 'IBM Plex Mono', ui-monospace, monospace;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(14, 22, 19, 0.06), 0 8px 24px rgba(14, 22, 19, 0.05);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--body);
  color: var(--ink);
  background:
    radial-gradient(1200px 600px at 100% -10%, #e3ebe4 0%, transparent 60%),
    var(--paper);
  min-height: 100vh;
  line-height: 1.5;
}
a { color: inherit; }
button { font-family: var(--body); cursor: pointer; }
:focus-visible { outline: 2px solid var(--signal); outline-offset: 2px; }

/* ---- Marca --------------------------------------------------------------- */
.brand { font-family: var(--display); font-weight: 700; letter-spacing: -0.02em; }
.brand .dot { color: var(--signal); }

/* ---- Tela de login ------------------------------------------------------- */
.auth-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}
.auth-card {
  width: 100%;
  max-width: 400px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 32px;
}
.auth-card .brand { font-size: 28px; margin-bottom: 4px; }
.auth-card .sub { color: var(--muted); font-size: 14px; margin-bottom: 24px; }
.auth-tabs { display: flex; gap: 4px; background: var(--paper); padding: 4px; border-radius: 10px; margin-bottom: 20px; }
.auth-tabs button {
  flex: 1; border: 0; background: transparent; padding: 9px; border-radius: 7px;
  font-weight: 600; color: var(--muted); font-size: 14px;
}
.auth-tabs button.active { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }

label { display: block; font-size: 13px; font-weight: 500; margin: 0 0 6px; }
input[type=email], input[type=password], input[type=text], input[type=date] {
  width: 100%; padding: 11px 12px; border: 1px solid var(--line);
  border-radius: 9px; font-size: 15px; font-family: var(--body); background: var(--surface);
  color: var(--ink);
}
input:focus { border-color: var(--signal); outline: none; }
.field { margin-bottom: 16px; }

.btn {
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  padding: 10px 16px; border-radius: 9px; font-weight: 600; font-size: 14px;
}
.btn:hover { border-color: var(--ink); }
.btn-primary { background: var(--ink); color: #fff; border-color: var(--ink); width: 100%; padding: 12px; }
.btn-primary:hover { background: #1b2a24; }
.btn-signal { background: var(--signal); color: #fff; border-color: var(--signal); }
.btn-signal:hover { background: #0c8348; border-color: #0c8348; }
.btn-ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn-danger { color: var(--churn); border-color: transparent; background: transparent; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.error { color: var(--churn); font-size: 13px; margin-top: 12px; min-height: 18px; }
.hint { color: var(--muted); font-size: 12px; margin-top: 8px; }

/* ---- App ----------------------------------------------------------------- */
.hidden { display: none !important; }
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 24px; border-bottom: 1px solid var(--line); background: var(--surface);
  position: sticky; top: 0; z-index: 10;
}
.topbar .brand { font-size: 20px; }
.topbar .who { color: var(--muted); font-size: 13px; margin-right: 12px; }
.topbar .right { display: flex; align-items: center; }

.container { max-width: 1120px; margin: 0 auto; padding: 24px; }
.section { margin-bottom: 28px; }
.section-head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 14px; gap: 12px; }
.section-head h2 {
  font-family: var(--display); font-size: 13px; font-weight: 600; letter-spacing: 0.08em;
  text-transform: uppercase; color: var(--muted); margin: 0;
}

/* Conexões */
.conn-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; }
.conn-card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px; display: flex; flex-direction: column; gap: 8px;
}
.conn-card .name { font-weight: 600; font-family: var(--display); }
.conn-card .phone { font-family: var(--mono); font-size: 13px; color: var(--muted); }
.conn-card .actions { display: flex; gap: 6px; margin-top: 6px; }
.status { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 600; }
.status::before { content: ''; width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.status.conectado::before { background: var(--signal); }
.status.aguardando_qr::before, .status.conectando::before, .status.reconectando::before { background: var(--amber); }
.status.desconectado::before { background: var(--churn); }
.conn-add {
  border: 1.5px dashed var(--line); border-radius: var(--radius); background: transparent;
  display: grid; place-items: center; min-height: 118px; color: var(--muted); font-weight: 600;
}
.conn-add:hover { border-color: var(--signal); color: var(--signal); }

/* Filtro */
.toolbar {
  display: flex; flex-wrap: wrap; align-items: flex-end; gap: 12px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px;
}
.toolbar .field { margin: 0; }
.toolbar label { color: var(--muted); }
.presets { display: flex; gap: 6px; flex-wrap: wrap; }
.presets .btn { padding: 8px 12px; font-size: 13px; }
.spacer { flex: 1; }

/* Cartões de totais */
.stats { display: grid; grid-template-columns: repeat(5, 1fr); gap: 12px; margin-top: 16px; }
.stat {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px;
}
.stat .k { font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); font-weight: 600; }
.stat .v { font-family: var(--mono); font-size: 26px; font-weight: 600; margin-top: 6px; letter-spacing: -0.02em; }
.stat.pos .v { color: var(--signal); }
.stat.neg .v { color: var(--churn); }

/* Tabela de grupos */
.table-wrap { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
table { width: 100%; border-collapse: collapse; }
thead th {
  text-align: right; font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em;
  color: var(--muted); font-weight: 600; padding: 12px 14px; border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
thead th:first-child { text-align: left; }
tbody td { padding: 12px 14px; border-bottom: 1px solid var(--line); text-align: right; font-family: var(--mono); font-size: 14px; }
tbody tr:last-child td { border-bottom: 0; }
tbody td:first-child { text-align: left; font-family: var(--body); font-weight: 500; }
tbody tr:hover { background: #f8faf7; }
.num.pos { color: var(--signal); }
.num.neg { color: var(--churn); }
.capacity { display: flex; align-items: center; gap: 8px; justify-content: flex-end; }
.bar { width: 90px; height: 6px; border-radius: 4px; background: var(--paper); overflow: hidden; }
.bar > span { display: block; height: 100%; background: var(--signal); }
.bar.high > span { background: var(--amber); }
.bar.full > span { background: var(--churn); }
.gname { display: flex; align-items: center; gap: 10px; }
.checkall { display: flex; align-items: center; gap: 8px; }
.group-tools { display: flex; align-items: center; gap: 16px; }
#search {
  width: 260px; padding: 8px 12px; border: 1px solid var(--line); border-radius: 9px;
  font-size: 14px; font-family: var(--body); background: var(--surface); color: var(--ink);
}
#search:focus { border-color: var(--signal); outline: none; }
.num.zero { color: var(--muted); }

.empty { padding: 48px 24px; text-align: center; color: var(--muted); }
.empty h3 { font-family: var(--display); color: var(--ink); margin: 0 0 6px; }

/* Modal */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(14,22,19,0.4); display: grid; place-items: center; z-index: 50; padding: 24px;
}
.modal {
  background: var(--surface); border-radius: 16px; padding: 28px; max-width: 380px; width: 100%;
  text-align: center; box-shadow: var(--shadow);
}
.modal h3 { font-family: var(--display); margin: 0 0 4px; }
.modal p { color: var(--muted); font-size: 14px; margin: 4px 0 20px; }
.qr-box { width: 240px; height: 240px; margin: 0 auto 16px; display: grid; place-items: center; background: var(--paper); border-radius: 12px; }
.qr-box img { width: 240px; height: 240px; border-radius: 12px; }
.spinner { width: 28px; height: 28px; border: 3px solid var(--line); border-top-color: var(--signal); border-radius: 50%; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: var(--ink); color: #fff; padding: 12px 20px; border-radius: 10px; font-size: 14px;
  box-shadow: var(--shadow); z-index: 60; opacity: 0; transition: opacity .2s, transform .2s;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(-4px); }

@media (max-width: 820px) {
  .stats { grid-template-columns: repeat(2, 1fr); }
  .container { padding: 16px; }
  .bar { width: 60px; }
  thead th.opt, tbody td.opt { display: none; }
  .section-head { flex-wrap: wrap; }
  .group-tools { width: 100%; flex-wrap: wrap; }
  #search { width: 100%; }
}
