:root {
  --bg: #0f1420;
  --panel: #171e2e;
  --border: #232c40;
  --text: #e7ecf5;
  --muted: #8b95ab;
  --accent: #4d8dff;
  --green: #2ecc71;
  --red: #ff5c5c;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 1.5rem;
  border-bottom: 1px solid var(--border);
}
.topbar .brand { color: var(--text); text-decoration: none; font-weight: 700; }
.topbar nav a { color: var(--muted); text-decoration: none; margin-left: 1rem; }
.topbar nav a:hover { color: var(--text); }
.user-pill {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.25rem 0.75rem;
  font-size: 0.85rem;
}

/* Páginas públicas (login, home, legais) ficam centradas e com medida de
   leitura confortável. */
.container { max-width: 1100px; margin: 0 auto; padding: 2rem 1.5rem; }

/* Já o painel usa a tela inteira: são tabelas largas e muitas colunas —
   limitar a 1100px desperdiçava metade do monitor e cortava colunas. */
.app-main .container { max-width: none; padding: 1.75rem 2rem; }

/* Texto corrido continua com largura de leitura mesmo em tela cheia. */
.legal { max-width: 820px; }

.app-layout { display: flex; align-items: stretch; min-height: 100vh; }
.sidebar {
  width: 240px;
  flex-shrink: 0;
  background: var(--panel);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 1.5rem 1rem;
}
.sidebar .brand {
  color: var(--text);
  text-decoration: none;
  font-weight: 700;
  display: flex;
  flex-direction: column;
  line-height: 1.2;
  margin-bottom: 2rem;
  padding: 0 0.5rem;
}
.sidebar .brand span { font-size: 0.7rem; font-weight: 400; color: var(--muted); }
.sidebar-nav { display: flex; flex-direction: column; gap: 0.25rem; }
.sidebar-nav a {
  color: var(--muted);
  text-decoration: none;
  padding: 0.6rem 0.75rem;
  border-radius: 8px;
  font-size: 0.9rem;
}
.sidebar-nav a:hover { background: var(--bg); color: var(--text); }
.sidebar-nav a.active { background: var(--bg); color: var(--accent); font-weight: 600; }
.sidebar-footer {
  margin-top: auto;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
.sidebar-footer .user-pill { text-align: center; }
.user-pill-off { color: var(--muted); border-style: dashed; font-size: 0.75rem; }
.user-pill-fb { color: #7fb2ff; border-color: rgba(24,119,242,0.4); font-size: 0.78rem; }
.nav-secao {
  display: block;
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--muted);
  padding: 0.9rem 0.75rem 0.35rem;
}
.nav-secao-footer { padding: 0 0 0.25rem; text-align: center; }
.sidebar-nav a.nav-destaque {
  background: rgba(24,119,242,0.14);
  color: #7fb2ff;
  font-weight: 600;
}
.sidebar-nav a.nav-destaque:hover { background: rgba(24,119,242,0.22); color: #a3c8ff; }
.sidebar-footer a { color: var(--muted); text-decoration: none; text-align: center; font-size: 0.85rem; }
.sidebar-footer a:hover { color: var(--text); }
.app-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.app-main .container { flex: 1; width: 100%; }

/* Notebook: menu lateral mais estreito pra sobrar largura pra tabela. */
@media (max-width: 1280px) {
  .sidebar { width: 200px; }
  .app-main .container { padding: 1.5rem 1.25rem; }
}

/* Tablet/celular: o menu vira uma barra horizontal no topo. */
@media (max-width: 900px) {
  .app-layout { flex-direction: column; }
  .sidebar {
    width: 100%;
    flex-direction: row;
    align-items: center;
    padding: 0.75rem 1rem;
    overflow-x: auto;
    border-right: none;
    border-bottom: 1px solid var(--border);
    gap: 0.5rem;
  }
  .sidebar .brand { margin-bottom: 0; margin-right: 0.75rem; white-space: nowrap; }
  .sidebar-nav { flex-direction: row; flex-shrink: 0; }
  .sidebar-nav a { white-space: nowrap; padding: 0.5rem 0.7rem; }
  /* O rótulo "Administração" só faz sentido empilhado na vertical. */
  .nav-secao { display: none; }
  .sidebar-footer {
    margin-top: 0;
    margin-left: auto;
    padding-top: 0;
    border-top: none;
    flex-direction: row;
    align-items: center;
    gap: 0.75rem;
    white-space: nowrap;
  }
  .app-main .container { padding: 1.25rem 1rem; }
  .page-header { gap: 1rem; }
  .page-header h1 { font-size: 1.35rem; }
}

@media (max-width: 640px) {
  /* Filtros e busca ocupam a linha inteira em vez de espremer. */
  .filtros-grid { flex-direction: column; align-items: stretch; }
  .filtros-grid > div { width: 100%; }
  .account-form select,
  .account-form input[type="date"],
  .filtro-acao .btn { width: 100%; }
  .filter-row { flex-direction: column; align-items: stretch; }
  .search-input { min-width: 0; width: 100%; }
  .segmented { justify-content: space-between; }
  .card { padding: 1rem; }
  .card-header { flex-direction: column; align-items: flex-start; gap: 0.75rem; }
}

.hero { text-align: center; padding: 3rem 1rem; }
.hero h1 { font-size: 2rem; margin-bottom: 0.5rem; }
.hero p { color: var(--muted); max-width: 560px; margin: 0 auto 1.5rem; }
.hero-compact { padding: 3rem 1rem 1.5rem; }

.login-card {
  max-width: 380px;
  margin: 0 auto 3rem;
  text-align: center;
  padding: 2.25rem 2rem;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.35);
  border-top: 2px solid var(--accent);
}
.login-icon {
  width: 48px;
  height: 48px;
  margin: 0 auto 1.25rem;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 12px;
  background: rgba(77, 141, 255, 0.12);
  color: var(--accent);
}
.login-card .form { max-width: none; text-align: left; }
.login-card .form label { color: var(--text); font-weight: 500; }
.login-card .form input {
  padding: 0.7rem 0.85rem;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.login-card .form input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(77, 141, 255, 0.2);
}
.otp-input {
  font-size: 1.5rem;
  letter-spacing: 0.5rem;
  text-align: center;
  font-variant-numeric: tabular-nums;
}
.mfa-back { margin-top: 1.25rem; margin-bottom: 0; font-size: 0.85rem; }
.mfa-back a { color: var(--accent); text-decoration: none; }

.danger-zone { border-color: rgba(255, 92, 92, 0.35); }
.danger-zone h2 { color: var(--red); }
.btn-danger { background: var(--red); }
.btn-danger:hover { background: #e04a4a; }
.checkbox-label {
  flex-direction: row !important;
  align-items: center;
  gap: 0.5rem !important;
  color: var(--text) !important;
}
.checkbox-label input { width: auto; }
.stored-count { margin-top: 0.75rem; font-size: 0.85rem; }
.diag-link { margin-top: 1.25rem; margin-bottom: 0; font-size: 0.85rem; }
.diag-link a { color: var(--accent); }

/* ---- Ativação do 2FA ---- */
.qr-area {
  display: flex;
  gap: 1.75rem;
  align-items: center;
  flex-wrap: wrap;
  margin: 1.25rem 0;
  padding: 1.25rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 12px;
}
.qr-box {
  background: var(--panel);
  padding: 0.5rem;
  border-radius: 8px;
  line-height: 0;
  flex-shrink: 0;
}
.qr-box svg { display: block; width: 190px; height: 190px; }
.qr-manual { min-width: 220px; }
.secret-code {
  display: inline-block;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.5rem 0.75rem;
  font-size: 0.95rem;
  letter-spacing: 0.08em;
  color: var(--accent);
  word-break: break-all;
}
.secret-hint { font-size: 0.78rem; margin-top: 0.5rem; }
.confirm-form { max-width: 260px; }
.cancel-form { margin-top: 0.75rem; }
.btn-link {
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 0.85rem;
  padding: 0;
  text-decoration: underline;
}
.btn-link:hover { color: var(--text); }
.btn-small.btn-danger { background: var(--red); }
.recursos {
  list-style: none;
  padding: 0;
  margin: 0;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 1.25rem;
}
.recursos li { color: var(--muted); font-size: 0.9rem; line-height: 1.5; }
.recursos strong {
  display: block;
  color: var(--text);
  font-size: 0.95rem;
  margin-bottom: 0.25rem;
}

.fb-button {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  background: #1877f2;
  color: #fff;
  text-decoration: none;
  padding: 0.75rem 1.5rem;
  border-radius: 8px;
  font-weight: 600;
}
.fb-button:hover { background: #166fe0; }

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.5rem;
  margin-bottom: 1.5rem;
}
.card-header { display: flex; justify-content: space-between; align-items: center; }

.legal h2 { margin-top: 1.5rem; font-size: 1.05rem; }
.legal p, .legal li { color: #c7cede; line-height: 1.6; }

/* ---- Cabeçalho de página + seletor de conta ---- */
.page-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 1.5rem;
  flex-wrap: wrap;
  margin-bottom: 1.5rem;
}
.page-header h1 { margin: 0 0 0.25rem; font-size: 1.6rem; }
.page-sub { margin: 0; color: var(--muted); font-size: 0.85rem; }

.account-form label {
  display: block;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  margin-bottom: 0.35rem;
}
.account-form-row { display: flex; gap: 0.5rem; }
.filtros-grid { display: flex; gap: 0.75rem; align-items: flex-end; flex-wrap: wrap; }
.filtros-grid > div { display: flex; flex-direction: column; }
.filtro-acao { justify-content: flex-end; }
.account-form input[type="date"] {
  background: var(--panel);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 0.5rem 0.75rem;
  font-size: 0.9rem;
  color-scheme: dark;
}
.account-form input[type="date"]:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(77,141,255,0.2);
}
.filtros-grid .hidden { display: none; }
.account-form select {
  background: var(--panel);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 0.5rem 0.75rem;
  font-size: 0.9rem;
  min-width: 240px;
}
.account-form select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(77,141,255,0.2);
}

/* ---- Tiles de indicadores ---- */
.stat-row {
  display: grid;
  /* auto-fit + minmax: em tela larga os 6 indicadores cabem numa linha só;
     conforme estreita, quebram sozinhos em 3, 2 e 1 por linha. */
  grid-template-columns: repeat(auto-fit, minmax(165px, 1fr));
  gap: 0.85rem;
  margin-bottom: 1.5rem;
}
.stat-tile {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0.9rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  min-width: 0; /* deixa o conteúdo encolher dentro do grid */
}
.stat-label { font-size: 0.75rem; color: var(--muted); line-height: 1.3; }
/* Valor grande usa algarismos proporcionais (tabular só em colunas).
   clamp() encolhe o número em telas estreitas em vez de estourar a caixa. */
.stat-value {
  font-size: clamp(1.25rem, 1.6vw + 0.6rem, 1.6rem);
  font-weight: 600;
  letter-spacing: -0.01em;
  line-height: 1.15;
}
.stat-nota { font-size: 0.75rem; color: var(--muted); }
/* Orçamento do dia consumido: cor + o próprio valor R$ 0,00 já dizem. */
.esgotado { color: var(--muted); }

/* ---- Linha de filtros ---- */
.filter-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
  margin-top: 1.25rem;
}
.segmented {
  display: inline-flex;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 3px;
  gap: 2px;
}
.segmented-item {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.4rem 0.85rem;
  border-radius: 7px;
  font-size: 0.85rem;
  color: var(--muted);
  text-decoration: none;
  white-space: nowrap;
}
.segmented-item:hover { color: var(--text); }
.segmented-item.is-active { background: var(--panel); color: var(--text); font-weight: 600; }
.segmented-count {
  font-size: 0.72rem;
  background: var(--border);
  color: var(--muted);
  border-radius: 999px;
  padding: 0.05rem 0.4rem;
  font-variant-numeric: tabular-nums;
}
.segmented-item.is-active .segmented-count { background: var(--accent); color: #fff; }

.search-input {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 0.5rem 0.85rem;
  font-size: 0.88rem;
  min-width: 260px;
}
.search-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(77,141,255,0.2);
}

/* ---- Tabela de dados ---- */
.data-table th { position: sticky; top: 0; background: var(--panel); z-index: 1; }
.data-table tbody tr:hover { background: rgba(255,255,255,0.02); }
.data-table td.num, .data-table th.num { text-align: right; font-variant-numeric: tabular-nums; }
/* Nome longo não pode empurrar as colunas de números pra fora da tela:
   corta com reticências e o nome inteiro fica no title (tooltip). */
.campaign-name {
  max-width: 340px;
  min-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
@media (min-width: 1600px) {
  .campaign-name { max-width: 520px; }
}

/* Estado: cor + símbolo + rótulo (nunca cor sozinha). */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.2rem 0.6rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 500;
  white-space: nowrap;
}
.badge-ativa { background: rgba(12,163,12,0.15); color: #4ad04a; }
.badge-pausada { background: rgba(139,149,171,0.18); color: var(--muted); }
.badge-falha { background: rgba(255,92,92,0.14); color: #ff8f8f; }

/* Aviso de tentativa de acesso: a informação de que alguém já sabe o nome
   de usuário merece destaque, não uma linha discreta na tabela. */
.aviso-acesso {
  background: rgba(255, 92, 92, 0.08);
  border: 1px solid rgba(255, 92, 92, 0.35);
  border-left: 3px solid var(--red);
  border-radius: 8px;
  padding: 0.9rem 1.1rem;
  margin: 0.5rem 0 1rem;
}
.aviso-acesso strong { color: #ffb4b4; }
.aviso-acesso p { margin: 0.5rem 0 0; color: var(--muted); font-size: 0.88rem; line-height: 1.55; }
.aviso-acesso p strong { color: var(--text); }

.origem-nova { color: #ffb4b4; }
.marca-nova {
  display: inline-block;
  margin-left: 0.4rem;
  padding: 0.05rem 0.4rem;
  border-radius: 999px;
  font-size: 0.68rem;
  background: rgba(255, 92, 92, 0.16);
  color: #ff8f8f;
  vertical-align: middle;
}

.empty-line { padding: 1.5rem 0; text-align: center; }
.table-footer { padding-top: 1rem; text-align: center; }
.empty-state { text-align: center; padding: 2.5rem 1.5rem; }
.empty-state h2 { margin-top: 0; }

.account-picker { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; margin-top: 0.75rem; }
.account-picker label { color: var(--muted); margin-right: 0.5rem; }
.chip {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  text-decoration: none;
  padding: 0.4rem 0.9rem;
  border-radius: 999px;
  font-size: 0.85rem;
}
.chip-active { border-color: var(--accent); color: var(--accent); }

.btn {
  background: var(--accent);
  color: #fff;
  text-decoration: none;
  padding: 0.5rem 1rem;
  border-radius: 8px;
  font-size: 0.9rem;
  font-weight: 600;
  border: none;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.05s ease;
}
.btn:hover { background: #3d7ce0; }
.btn:active { transform: translateY(1px); }
.btn-block { display: block; width: 100%; padding: 0.75rem 1rem; font-size: 0.95rem; }
.btn-small {
  background: var(--accent);
  color: #fff;
  text-decoration: none;
  padding: 0.25rem 0.6rem;
  border-radius: 6px;
  font-size: 0.8rem;
}

/* A tabela rola dentro do próprio cartão — a página nunca rola na
   horizontal. Nas telas largas ela simplesmente ocupa tudo e não sobra
   barra de rolagem. */
.table-wrap {
  overflow-x: auto;
  margin-top: 1rem;
  scrollbar-width: thin;
}
table { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
th, td { padding: 0.55rem 0.7rem; text-align: left; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { color: var(--muted); font-weight: 600; font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.02em; }

.status { padding: 0.15rem 0.5rem; border-radius: 999px; font-size: 0.75rem; white-space: nowrap; }
.status-active { background: rgba(46,204,113,0.15); color: var(--green); }
.status-paused { background: rgba(139,149,171,0.2); color: var(--muted); }
.status-erro { background: rgba(255,92,92,0.15); color: var(--red); }

.detalhe-col { white-space: normal; max-width: 520px; line-height: 1.45; }

.erro-item {
  border: 1px solid var(--border);
  border-left: 3px solid var(--red);
  border-radius: 8px;
  padding: 0.85rem 1rem;
  margin-bottom: 0.75rem;
  background: var(--bg);
}
.erro-cabecalho { display: flex; justify-content: space-between; gap: 1rem; font-size: 0.85rem; margin-bottom: 0.4rem; }
.erro-mensagem { margin: 0 0 0.5rem; color: #ffb4b4; font-size: 0.9rem; }
.erro-stack {
  margin: 0;
  font-size: 0.75rem;
  color: var(--muted);
  overflow-x: auto;
  white-space: pre;
  line-height: 1.5;
}

.inline-form { display: flex; gap: 0.4rem; align-items: center; }
.inline-form input { width: 90px; background: var(--bg); border: 1px solid var(--border); color: var(--text); border-radius: 6px; padding: 0.3rem 0.5rem; }
.inline-form button { background: var(--accent); color: #fff; border: none; border-radius: 6px; padding: 0.3rem 0.6rem; cursor: pointer; }

.form { display: flex; flex-direction: column; gap: 1rem; max-width: 480px; }
.form label { display: flex; flex-direction: column; gap: 0.35rem; font-size: 0.9rem; color: var(--muted); }
.form input, .form select {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 0.6rem 0.75rem;
  font-size: 0.95rem;
}

.flash { background: rgba(77,141,255,0.15); border: 1px solid var(--accent); color: var(--text); padding: 0.75rem 1rem; border-radius: 8px; margin-bottom: 1rem; }
.flash-error { background: rgba(255,92,92,0.12); border-color: var(--red); }

.muted { color: var(--muted); }
.hidden { display: none; }

.error-fallback {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  padding: 2rem;
  background: var(--bg);
  color: var(--text);
}
.error-fallback a { color: var(--accent); }

.footer { text-align: center; color: var(--muted); font-size: 0.8rem; padding: 2rem 1rem; }
.footer a { color: var(--muted); }
