:root {
  color-scheme: dark;
  --bg: #0d1117;
  --bg-raised: #151b23;
  --bg-input: #0b0f14;
  --line: #262d36;
  --line-soft: #1c222a;
  --text: #e6edf3;
  --text-dim: #8b949e;
  --text-faint: #6e7681;
  --accent: #3d8bfd;
  --accent-ink: #ffffff;
  --ok: #3fb950;
  --warn: #d29922;
  --bad: #f85149;
  --radius: 8px;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  display: flex;
  flex-direction: column;
}

h1, h2 { margin: 0; font-weight: 600; }
h1 { font-size: 15px; letter-spacing: -0.01em; }
h2 { font-size: 12px; text-transform: uppercase; letter-spacing: 0.07em; color: var(--text-dim); }

/* ---------------------------------------------------------------- topbar */

.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--line);
  background: var(--bg-raised);
  flex: 0 0 auto;
}

.brand { display: flex; align-items: center; gap: 10px; }

.brand-mark {
  display: grid;
  place-items: center;
  width: 26px; height: 26px;
  border-radius: 6px;
  background: #0a66c2;
  color: #fff;
  font-weight: 700;
  font-size: 13px;
  letter-spacing: -0.03em;
}

.topbar-status { margin-left: auto; display: flex; align-items: center; gap: 8px; }

.chip {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 5px 11px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--bg-input);
  color: var(--text-dim);
  font-size: 12px;
  cursor: pointer;
}
.chip:hover { border-color: #384049; color: var(--text); }
.chip .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--text-faint); flex: 0 0 auto; }
.chip.is-ok .dot { background: var(--ok); }
.chip.is-warn .dot { background: var(--warn); }
.chip.is-bad .dot { background: var(--bad); }

/* ---------------------------------------------------------------- layout */

.layout {
  flex: 1 1 auto;
  display: grid;
  grid-template-columns: 290px minmax(0, 1fr) 280px;
  min-height: 0;
}

.sidebar, .queue {
  overflow-y: auto;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.sidebar { border-right: 1px solid var(--line); }
.queue { border-left: 1px solid var(--line); }

.panel {
  background: var(--bg-raised);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.hint { margin: 0; font-size: 11.5px; line-height: 1.45; color: var(--text-faint); }
.hint strong, .hint em { color: var(--text-dim); font-style: normal; }

/* ---------------------------------------------------------------- fields */

.field { display: flex; flex-direction: column; gap: 5px; font-size: 12px; color: var(--text-dim); }
.field > span { font-weight: 500; }
.field small { font-size: 11px; color: var(--text-faint); line-height: 1.4; }

input[type="text"], input[type="number"], textarea {
  width: 100%;
  padding: 7px 9px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--bg-input);
  color: var(--text);
  font: inherit;
  font-size: 13px;
}
input:focus, textarea:focus { outline: none; border-color: var(--accent); }
textarea { resize: vertical; font-size: 12.5px; }

.checkline { display: flex; flex-wrap: wrap; gap: 12px; font-size: 12.5px; color: var(--text-dim); }
.checkline label, .switch { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; }
.switch { font-size: 12.5px; color: var(--text-dim); }
input[type="checkbox"], input[type="radio"] { accent-color: var(--accent); margin: 0; }

.actions { display: flex; gap: 8px; }
.actions .btn { flex: 1; }

/* ---------------------------------------------------------------- buttons */

.btn {
  padding: 7px 13px;
  border-radius: 6px;
  border: 1px solid var(--line);
  background: var(--bg-input);
  color: var(--text);
  font: inherit;
  font-size: 12.5px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
}
.btn:hover:not(:disabled) { border-color: #3d4650; background: #171d25; }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-primary:hover:not(:disabled) { background: #5299fd; border-color: #5299fd; }
.btn-ghost { background: transparent; }

/* ---------------------------------------------------------------- typeahead */

.typeahead { position: relative; }

.typeahead-menu {
  position: absolute;
  z-index: 20;
  inset-inline: 0;
  top: calc(100% + 4px);
  max-height: 260px;
  overflow-y: auto;
  background: #10161d;
  border: 1px solid var(--line);
  border-radius: 6px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.5);
}

.typeahead-menu button {
  display: flex; align-items: center; gap: 9px;
  width: 100%;
  padding: 8px 10px;
  border: 0;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 12.5px;
  text-align: left;
  cursor: pointer;
}
.typeahead-menu button:hover { background: #1a2129; }
.typeahead-menu img { width: 22px; height: 22px; border-radius: 4px; object-fit: cover; flex: 0 0 auto; }
.typeahead-menu .ta-sub { color: var(--text-faint); font-size: 11px; }
.typeahead-menu .ta-empty { padding: 10px; color: var(--text-faint); font-size: 12px; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }

.chips .tag {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 6px 4px 9px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--bg-input);
  font-size: 12px;
}
.chips .tag code { font-family: var(--mono); font-size: 10.5px; color: var(--text-faint); }
.chips .tag button {
  border: 0; background: transparent; color: var(--text-faint);
  cursor: pointer; font-size: 14px; line-height: 1; padding: 0 2px;
}
.chips .tag button:hover { color: var(--bad); }

/* ------------------------------------------------------------------ abas */

.tabs {
  display: flex; gap: 2px;
  padding: 8px 14px 0;
  background: var(--bg-raised);
  border-bottom: 1px solid var(--line);
  flex: 0 0 auto;
}

.tab {
  padding: 7px 14px;
  border: 1px solid transparent;
  border-bottom: 0;
  border-radius: 6px 6px 0 0;
  background: transparent;
  color: var(--text-faint);
  font: inherit;
  font-size: 12.5px;
  cursor: pointer;
}
.tab:hover { color: var(--text-dim); }
.tab.is-active { background: var(--bg); border-color: var(--line); color: var(--text); margin-bottom: -1px; }

select.mini, input.mini {
  padding: 5px 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--bg-input);
  color: var(--text);
  font: inherit;
  font-size: 12px;
  max-width: 170px;
}
select.mini:disabled, input.mini:disabled { opacity: 0.4; }
input.mini { width: 150px; }

.saved { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 3px; }
.saved li { display: flex; align-items: center; gap: 6px; }
.saved .link {
  flex: 1; text-align: left; border: 0; background: transparent;
  color: var(--text-dim); font: inherit; font-size: 12.5px; cursor: pointer;
  padding: 4px 6px; border-radius: 5px;
}
.saved .link:hover { background: var(--bg-input); color: var(--text); }
.saved .x { border: 0; background: transparent; color: var(--text-faint); cursor: pointer; font-size: 14px; padding: 0 4px; }
.saved .x:hover { color: var(--bad); }

details summary { cursor: pointer; font-size: 12px; color: var(--text-faint); padding: 2px 0; }
details summary:hover { color: var(--text-dim); }
details[open] summary { margin-bottom: 8px; }

.col-emp { width: 150px; }

/* ------------------------------------------------- filtros por palavra */

.criterios {
  padding: 10px 14px 12px;
  border-bottom: 1px solid var(--line);
  background: var(--bg-raised);
  display: flex;
  flex-direction: column;
  gap: 7px;
  flex: 0 0 auto;
}

.criterios-head { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.criterios-head strong { font-size: 12px; }
.criterios-head .hint { margin: 0; flex: 1 1 320px; min-width: 0; }
.criterios-head code {
  font-family: var(--mono); font-size: 10.5px;
  background: var(--bg-input); padding: 1px 4px; border-radius: 3px;
}

.criterio { display: flex; align-items: center; gap: 6px; }
.criterio-termos {
  flex: 1;
  min-width: 0;
  padding: 5px 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--bg-input);
  color: var(--text);
  font: inherit;
  font-size: 12px;
}
.criterio-termos:focus { outline: none; border-color: var(--accent); }
.criterio-conta { font-size: 10.5px; color: var(--text-faint); min-width: 52px; text-align: right; }
.criterio .x {
  border: 0; background: transparent; color: var(--text-faint);
  cursor: pointer; font-size: 15px; line-height: 1; padding: 0 4px;
}
.criterio .x:hover { color: var(--bad); }

/* ---------------------------------------------------------------- results */

.results { display: flex; flex-direction: column; min-width: 0; min-height: 0; }

.results-toolbar {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
  background: var(--bg-raised);
  flex: 0 0 auto;
  /* Em telas estreitas os seletores e botões não caberiam numa linha só; sem o
     wrap eles comprimem até ficar ilegíveis. */
  flex-wrap: wrap;
}
.results-toolbar .spacer { flex: 1 1 0; min-width: 0; }
.results-toolbar .btn { flex: 0 0 auto; }
.select-all { display: inline-flex; align-items: center; gap: 8px; font-size: 12.5px; color: var(--text-dim); cursor: pointer; }

.results-meta {
  padding: 7px 14px;
  font-size: 11.5px;
  color: var(--text-faint);
  border-bottom: 1px solid var(--line-soft);
  display: flex; align-items: center; gap: 12px;
  flex: 0 0 auto;
}
.results-meta .sep { color: var(--line); }

.table-wrap { flex: 1 1 auto; overflow: auto; position: relative; }

table.people { width: 100%; border-collapse: collapse; font-size: 13px; }

table.people thead th {
  position: sticky; top: 0; z-index: 2;
  background: #12181f;
  border-bottom: 1px solid var(--line);
  padding: 8px 10px;
  text-align: left;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-faint);
}

table.people td { padding: 9px 10px; border-bottom: 1px solid var(--line-soft); vertical-align: top; }
table.people tbody tr:hover { background: #121820; }
table.people tbody tr.is-selected { background: #101c2c; }
table.people tbody tr.is-blocked { opacity: 0.45; }

.col-check { width: 34px; }
.col-deg, .col-state { width: 92px; }
.col-loc { width: 170px; }

.person-cell { display: flex; gap: 9px; align-items: flex-start; }
.person-cell img, .person-cell .avatar-fallback {
  width: 32px; height: 32px; border-radius: 50%; flex: 0 0 auto; object-fit: cover;
}
.avatar-fallback { display: grid; place-items: center; background: #1e2731; color: var(--text-faint); font-size: 12px; font-weight: 600; }
.person-cell a { color: var(--text); text-decoration: none; font-weight: 500; }
.person-cell a:hover { color: var(--accent); text-decoration: underline; }
.person-cell .sub { font-size: 11px; color: var(--text-faint); font-family: var(--mono); }

.headline { color: var(--text-dim); font-size: 12.5px; line-height: 1.4; }
.about { margin-top: 4px; padding-top: 4px; border-top: 1px dashed var(--line); font-size: 11.5px; color: var(--text-faint); }
mark { background: rgba(61, 139, 253, 0.28); color: #cfe3ff; border-radius: 2px; padding: 0 1px; }

.badge {
  display: inline-block;
  padding: 2px 7px;
  border-radius: 999px;
  font-size: 11px;
  border: 1px solid var(--line);
  color: var(--text-dim);
}
.badge.ok { color: var(--ok); border-color: rgba(63, 185, 80, 0.35); }
.badge.warn { color: var(--warn); border-color: rgba(210, 153, 34, 0.35); }
.badge.bad { color: var(--bad); border-color: rgba(248, 81, 73, 0.35); }

.empty { padding: 40px 20px; text-align: center; color: var(--text-faint); font-size: 13px; }
.empty[hidden] { display: none; }

/* ---------------------------------------------------------------- queue */

.queue-counts { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; text-align: center; }
.queue-counts div { background: var(--bg-input); border: 1px solid var(--line-soft); border-radius: 6px; padding: 7px 4px; }
.queue-counts strong { display: block; font-size: 17px; font-variant-numeric: tabular-nums; }
.queue-counts span { font-size: 10.5px; color: var(--text-faint); }

.queue-next {
  font-size: 12px;
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
  padding: 7px 9px;
  background: var(--bg-input);
  border: 1px solid var(--line-soft);
  border-radius: 6px;
}
.queue-next.is-paused { color: var(--warn); }
/* Erros se acumulando: o aviso vale antes da pausa, não só depois. */
.queue-next.is-high { color: var(--warn); border-color: var(--warn); }

.meter { display: grid; grid-template-columns: 52px 1fr 46px; align-items: center; gap: 8px; font-size: 11.5px; color: var(--text-dim); }
.meter .bar { height: 5px; border-radius: 3px; background: var(--bg-input); border: 1px solid var(--line-soft); overflow: hidden; }
.meter .bar i { display: block; height: 100%; background: var(--accent); transition: width 0.3s; }
.meter.is-high .bar i { background: var(--warn); }
.meter.is-full .bar i { background: var(--bad); }
.meter span { text-align: right; font-variant-numeric: tabular-nums; color: var(--text-faint); }

.log { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 5px; max-height: 260px; overflow-y: auto; }
.log li { font-size: 11.5px; line-height: 1.4; color: var(--text-faint); border-left: 2px solid var(--line); padding-left: 8px; }
.log li.ok { border-color: var(--ok); color: var(--text-dim); }
.log li.bad { border-color: var(--bad); color: #f0a9a4; }
.log li time { display: block; font-size: 10px; color: var(--text-faint); opacity: 0.7; }

/* ---------------------------------------------------------------- dialogs */

dialog {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg-raised);
  color: var(--text);
  padding: 0;
  max-width: 560px;
  width: calc(100% - 40px);
  max-height: 86vh;
}
dialog::backdrop { background: rgba(0, 0, 0, 0.6); }

.dialog-body { padding: 18px; display: flex; flex-direction: column; gap: 14px; overflow-y: auto; max-height: 86vh; }
.dialog-body h2 { font-size: 14px; text-transform: none; letter-spacing: 0; color: var(--text); }
.dialog-body p { margin: 0; font-size: 12.5px; color: var(--text-dim); line-height: 1.55; }
.dialog-body code { font-family: var(--mono); font-size: 11.5px; background: var(--bg-input); padding: 1px 4px; border-radius: 3px; }

fieldset { border: 1px solid var(--line-soft); border-radius: 7px; padding: 12px; margin: 0; display: flex; flex-direction: column; gap: 9px; }
legend { padding: 0 6px; font-size: 11px; text-transform: uppercase; letter-spacing: 0.07em; color: var(--text-faint); }

.steps { margin: 0; padding-left: 18px; font-size: 12.5px; color: var(--text-dim); line-height: 1.6; display: flex; flex-direction: column; gap: 5px; }

.recipe-list { display: flex; flex-direction: column; gap: 6px; }
.recipe-row {
  display: grid; grid-template-columns: 8px 1fr auto; align-items: center; gap: 9px;
  padding: 8px 10px;
  background: var(--bg-input);
  border: 1px solid var(--line-soft);
  border-radius: 6px;
  font-size: 12px;
}
.recipe-row .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--warn); }
.recipe-row.is-ok .dot { background: var(--ok); }
.recipe-row .meta { color: var(--text-faint); font-size: 10.5px; font-family: var(--mono); word-break: break-all; }
.recipe-row .state { font-size: 11px; color: var(--text-faint); white-space: nowrap; }

menu { display: flex; justify-content: flex-end; gap: 8px; margin: 0; padding: 0; }

/* ------------------------------------------------------------ diagnóstico */

#dlg-diagnose { max-width: 760px; }

.verdict {
  padding: 11px 13px;
  border-radius: 7px;
  border: 1px solid rgba(210, 153, 34, 0.4);
  background: rgba(210, 153, 34, 0.09);
  color: #f2d492;
  font-size: 12.5px;
  line-height: 1.55;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 10px;
}

.diag-head { font-size: 11px; font-family: var(--mono); color: var(--text-faint); word-break: break-all; }

.diag-card {
  border: 1px solid var(--line-soft);
  border-left: 3px solid var(--bad);
  border-radius: 7px;
  padding: 11px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: var(--bg-input);
}
.diag-card.is-ok { border-left-color: var(--ok); }
.diag-card h3 { margin: 0; font-size: 12.5px; font-weight: 600; }

.diag-stat { font-size: 12px; color: var(--text-dim); font-variant-numeric: tabular-nums; }

.diag-shape { display: grid; grid-template-columns: 132px 1fr; gap: 3px 10px; margin: 0; font-size: 11.5px; }
.diag-shape dt { color: var(--text-faint); }
.diag-shape dd { margin: 0; color: var(--text-dim); word-break: break-word; font-family: var(--mono); font-size: 11px; }

.diag-sample { font-size: 11.5px; color: var(--ok); }

.diag-card details summary { font-size: 11.5px; color: var(--text-faint); cursor: pointer; }
.diag-card details pre {
  margin: 6px 0 0;
  padding: 8px;
  background: #0a0e13;
  border: 1px solid var(--line-soft);
  border-radius: 5px;
  font-size: 10.5px;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-all;
  max-height: 190px;
  overflow-y: auto;
  color: var(--text-dim);
}

/* ---------------------------------------------------------------- toasts */

.toast-stack { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 100; }

.toast {
  padding: 10px 14px;
  border-radius: 7px;
  border: 1px solid var(--line);
  background: #10161d;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.5);
  font-size: 12.5px;
  max-width: 380px;
  animation: rise 0.18s ease-out;
}
.toast.ok { border-color: rgba(63, 185, 80, 0.4); }
.toast.bad { border-color: rgba(248, 81, 73, 0.45); }

@keyframes rise { from { opacity: 0; transform: translateY(6px); } }

@media (max-width: 1180px) {
  .layout { grid-template-columns: 260px minmax(0, 1fr); }
  .queue { grid-column: 1 / -1; border-left: 0; border-top: 1px solid var(--line); flex-direction: row; flex-wrap: wrap; }
  .queue .panel { flex: 1 1 240px; }
}

/* --------------------------------------------------- painel em destaque */

/* O caminho mais confiável para os filtros que só aceitam ID: sinalizar isso
   visualmente evita que a pessoa lute com os campos numéricos primeiro. */
.panel.destaque {
  border: 1px solid rgba(61, 139, 253, 0.35);
  background: rgba(61, 139, 253, 0.06);
  border-radius: 8px;
  padding: 12px;
}
.panel.destaque h2 { color: var(--accent); }
#url-resumo:empty { display: none; }
#url-resumo { padding-top: 2px; }

/* ------------------------------------------------- preview da nota */

/* Existe porque configurar a nota às cegas mandou um marcador não resolvido
   para contatos reais. Ver o texto final, com nomes da base, é a diferença
   entre notar em dois segundos e descobrir depois de enviar. */
.preview-nota {
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--bg-input);
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.preview-cabeca { display: flex; align-items: baseline; gap: 8px; }
.preview-cabeca strong { font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-dim); }
.preview-cabeca span { margin-left: auto; font-family: var(--mono); font-size: 10.5px; color: var(--text-faint); }
.preview-cabeca span.is-full { color: var(--warn); }

.preview-exemplo { border-left: 2px solid var(--line); padding-left: 9px; }
.preview-quem { font-size: 10.5px; color: var(--text-faint); }
.preview-exemplo p { margin: 2px 0 0; font-size: 12px; line-height: 1.5; color: var(--text); }

.preview-alerta {
  padding: 8px 10px;
  border-radius: 6px;
  border: 1px solid rgba(248, 81, 73, 0.45);
  background: rgba(248, 81, 73, 0.1);
  color: #ffb3ae;
  font-size: 11.5px;
  line-height: 1.45;
}

/* ------------------------------------------------------- tela do navegador */

/* A janela do Chrome dirigido, quando a ferramenta roda num servidor.

   `[hidden]` não basta sozinho aqui: o elemento tem `display: flex` explícito
   logo abaixo, e display no CSS vence o atributo. */
.tela-wrap[hidden] { display: none; }

.tela-wrap {
  display: flex;
  flex-direction: column;
  min-height: 0;
  flex: 1;
}

.tela-barra {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
}

.tela-barra .hint { margin: 0 0 0 auto; font-size: 11px; }

/* O estado do controle precisa ser legível de relance: é a diferença entre um
   clique inofensivo e um clique que navega para fora no meio de um envio. */
.tela-estado {
  font-family: var(--mono);
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-faint);
  padding: 2px 7px;
  border: 1px solid var(--line);
  border-radius: 999px;
}

.tela-estado.is-vivo {
  color: var(--warn);
  border-color: rgba(210, 153, 34, 0.5);
  background: rgba(210, 153, 34, 0.1);
}

#tela {
  flex: 1;
  width: 100%;
  min-height: 520px;
  border: 0;
  background: #000;
  display: block;
}
