:root {
  --bg: #0d0f14; --bg2: #11141b; --panel: #161a22; --panel2: #1e232d; --border: #2a313d;
  --fg: #e7ebf2; --muted: #94a0b2; --faint: #6b7686;
  --accent: #4f8cff; --accent2: #6ea8ff; --ok: #3fb950; --warn: #d29922; --err: #f85149;
  --mono: ui-monospace, "Cascadia Code", "SF Mono", Consolas, monospace;
  --shadow: 0 8px 30px rgba(0,0,0,.35);
  --radius: 10px;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; color: var(--fg);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 14px; line-height: 1.5;
  background: radial-gradient(1200px 600px at 20% -10%, #182033 0%, var(--bg) 55%) fixed;
}
.hidden { display: none !important; }
.brand { display: flex; align-items: center; gap: 9px; font-weight: 700; font-size: 15px; letter-spacing: .2px; }
.brand .dot { width: 11px; height: 11px; border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), #a06bff); box-shadow: 0 0 12px rgba(79,140,255,.6); }

/* Usuário logado (header) */
.current-user { font-size: 12px; color: var(--muted); margin-right: 4px; }
.current-user:not(:empty)::before { content: "👤 "; }

/* Buttons */
button { font: inherit; cursor: pointer; border-radius: 8px; border: 1px solid var(--border);
  background: var(--panel2); color: var(--fg); padding: 8px 14px; transition: filter .12s, border-color .12s, background .12s; }
button:hover:not(:disabled) { filter: brightness(1.18); border-color: #3a4454; }
button:disabled { opacity: .45; cursor: default; }
button.primary { background: linear-gradient(180deg, var(--accent2), var(--accent)); border-color: #3b74e0; color: #fff; font-weight: 600; }
button.ghost { background: transparent; }
button.block { width: 100%; margin-top: 14px; padding: 10px; }
button.danger { background: var(--err); border-color: var(--err); color: #fff; font-weight: 600; margin-top: 8px; }
button.danger:hover:not(:disabled) { filter: brightness(1.1); }

/* Inputs */
input, select, textarea { font: inherit; width: 100%; background: var(--bg2); color: var(--fg);
  border: 1px solid var(--border); border-radius: 8px; padding: 9px 10px; transition: border-color .12s, box-shadow .12s; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(79,140,255,.18); }
select { appearance: none; background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 16px) 55%, calc(100% - 11px) 55%; background-size: 5px 5px; background-repeat: no-repeat; padding-right: 30px; }
label { display: block; font-size: 12px; color: var(--muted); margin: 12px 0 5px; font-weight: 500; }
a { color: var(--accent2); }

/* Login */
#login { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login-card { width: 100%; max-width: 360px; background: var(--panel); border: 1px solid var(--border);
  border-radius: 14px; padding: 30px; box-shadow: var(--shadow); }
.login-card .brand { font-size: 18px; margin-bottom: 6px; }
.login-card p { color: var(--muted); margin: 0 0 18px; font-size: 13px; }
.login-card input, .login-card button { margin-top: 10px; }
.err { color: var(--err); font-size: 13px; min-height: 18px; margin-top: 10px; }

/* Shell */
header { position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 18px;
  flex-wrap: wrap; row-gap: 8px;
  padding: 11px 20px; background: rgba(18,21,28,.85); backdrop-filter: blur(8px); border-bottom: 1px solid var(--border); }
header .tabs { display: flex; flex-wrap: wrap; gap: 3px; background: var(--bg2); border: 1px solid var(--border); border-radius: 10px; padding: 3px; }
header .tabs button { border: none; background: transparent; padding: 6px 14px; border-radius: 7px; color: var(--muted); font-weight: 500; }
header .tabs button:hover { color: var(--fg); filter: none; }
header .tabs button.active { background: var(--panel2); color: #fff; box-shadow: 0 1px 4px rgba(0,0,0,.3); }
/* Ações (tour, relatórios, sair) num grupo único: margin-left:auto empurra pra direita e,
   quando não cabem, quebram JUNTAS para a linha de baixo (em vez de o spacer solto separar
   o botão do tour dos demais). flex-wrap protege o grupo em telas bem estreitas. */
header .header-actions { display: flex; align-items: center; flex-wrap: wrap; gap: 10px; margin-left: auto; }
header .reports-link { font-size: 13px; font-weight: 500; color: var(--muted); text-decoration: none;
  border: 1px solid var(--border); border-radius: 8px; padding: 7px 13px; transition: color .12s, border-color .12s, background .12s; }
header .reports-link:hover { color: var(--fg); border-color: #3a4454; background: var(--panel2); }
/* Altura igual para botões e links da barra. Os dois vinham de regras separadas (botão:
   14px/8px, link: 13px/7px) e ficavam 39px contra 35,5px — a diferença aparecia como um
   item mais alto que os vizinhos. Fixar a altura evita que a divergência volte quando
   uma das duas regras mudar. */
header .header-actions > button,
header .header-actions > .reports-link {
  display: inline-flex; align-items: center; height: 34px;
  padding-block: 0; font-size: 13px; line-height: 1;
}
main { padding: 20px; max-width: 1500px; margin: 0 auto; }

.cols { display: grid; grid-template-columns: 300px 1fr; gap: 18px; align-items: start; }
/* Grid item tem min-width:auto por padrão → coluna expande p/ caber conteúdo largo
   (tabela/imagem) e estoura a largura da página. min-width:0 deixa encolher; o overflow
   fica contido no elemento largo (tabela rola sozinha, imagem escala). */
.cols > * { min-width: 0; }
@media (max-width: 820px) { .cols { grid-template-columns: 1fr; } }
/* Relatório recém-executado: bloco próprio, largura total, abaixo do grid. */
.report-card { margin-top: 18px; }
.report-card.hidden { display: none; }
.report-open { font-size: 12px; color: var(--accent); text-decoration: none; white-space: nowrap; }
.report-open:hover { text-decoration: underline; }
.card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.card h2 { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--faint); margin: 0 0 12px; font-weight: 600; }
.card-head { display: flex; align-items: center; justify-content: space-between; }
.card-head h2 { margin: 0; }
.row { display: flex; gap: 10px; }
.row > * { flex: 1; }
.pill { font-size: 12px; color: var(--muted); background: var(--bg2); border: 1px solid var(--border); border-radius: 999px; padding: 3px 11px; }
.empty { color: var(--faint); font-style: italic; }

/* Tree */
.tree { font-size: 13px; line-height: 1.6; max-height: 72vh; overflow: auto; user-select: none; }
.tree .ico { display: inline-block; width: 18px; opacity: .75; }
.tree .dir, .tree .file {
  display: flex; align-items: center; gap: 3px; cursor: pointer;
  padding: 4px 8px; border-radius: 6px; white-space: nowrap; color: var(--fg);
}
.tree .dir { font-weight: 600; color: var(--muted); }
.tree .dir .caret { display: inline-block; width: 13px; font-size: 10px; color: var(--faint); transition: transform .12s; }
.tree .dir:hover, .tree .file:hover { background: var(--panel2); }
.tree .file { color: var(--fg); }
.tree .file .ico { opacity: .55; }
.tree .file.active { background: linear-gradient(180deg, var(--accent2), var(--accent)); color: #fff; }
.tree .file.active .ico { opacity: 1; }
/* Linha-guia de aninhamento + colapso */
.tree .tchildren { position: relative; }
.tree .tnode.collapsed > .tchildren { display: none; }
.tree .tnode.collapsed > .dir .caret { transform: rotate(-90deg); }

/* Editor */
#editor { height: 62vh; font-family: var(--mono); font-size: 13px; line-height: 1.55; resize: vertical; }
.editbar { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.editbar .path { font-family: var(--mono); font-size: 12px; color: var(--muted); flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.saved { color: var(--ok); font-size: 12px; white-space: nowrap; }

/* Log + markdown */
#run-log { background: #07090d; border: 1px solid var(--border); border-radius: 8px; padding: 12px; font-family: var(--mono);
  font-size: 12px; line-height: 1.5; white-space: pre-wrap; max-height: 42vh; overflow: auto; color: #b9c2d0; margin-top: 10px; }
.run-log-loading { display: inline-flex; align-items: center; gap: 10px; color: var(--muted); font-style: italic; }
.dot-spinner { display: inline-flex; gap: 4px; }
.dot-spinner i { width: 6px; height: 6px; border-radius: 50%; background: var(--accent2); display: inline-block; animation: dot-pulse 1.4s ease-in-out infinite; }
.dot-spinner i:nth-child(2) { animation-delay: .2s; }
.dot-spinner i:nth-child(3) { animation-delay: .4s; }
@keyframes dot-pulse { 0%, 80%, 100% { opacity: .25; transform: scale(.8); } 40% { opacity: 1; transform: scale(1); } }
.md { line-height: 1.6; overflow-wrap: anywhere; }
.md > :first-child { margin-top: 0; }
.md h1 { font-size: 21px; } .md h2 { font-size: 17px; border-bottom: 1px solid var(--border); padding-bottom: 5px; margin-top: 24px; }
.md h3 { font-size: 15px; } .md h4 { font-size: 13px; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; }
.md code { background: var(--panel2); padding: 1px 6px; border-radius: 5px; font-family: var(--mono); font-size: 12px; }
.md pre { background: #07090d; border: 1px solid var(--border); border-radius: 8px; padding: 12px; overflow: auto; }
.md pre code { background: none; padding: 0; }
/* Screenshots do relatório escalam p/ caber — nunca empurram a página na horizontal. */
.md img { max-width: 100%; height: auto; border-radius: 6px; }
.md table { border-collapse: collapse; margin: 12px 0; font-size: 13px; display: block; overflow-x: auto; width: max-content; max-width: 100%; }
.md th, .md td { border: 1px solid var(--border); padding: 6px 11px; text-align: left; }
.md th { background: var(--panel2); font-weight: 600; }
.md tr:nth-child(even) td { background: rgba(255,255,255,.02); }
.md blockquote { border-left: 3px solid var(--accent); margin: 10px 0; padding: 4px 14px; color: var(--muted); background: rgba(79,140,255,.05); border-radius: 0 6px 6px 0; }
.md hr { border: none; border-top: 1px solid var(--border); margin: 18px 0; }
.md a { text-decoration: none; } .md a:hover { text-decoration: underline; }

/* Lists (runs & bugs) */
.list { list-style: none; margin: 0; padding: 0; font-size: 13px; max-height: 38vh; overflow: auto; }
.list li { padding: 8px 10px; border-radius: 7px; cursor: pointer; border: 1px solid transparent; }
.list li:hover { background: var(--panel2); border-color: var(--border); }
.list .meta { color: var(--faint); font-size: 11px; cursor: default; }
.meta { color: var(--faint); font-size: 12px; }

/* Rotinas (agendamento) */
#sch-list { max-height: 72vh; overflow: auto; display: flex; flex-direction: column; gap: 10px; }
.sch-row { border: 1px solid var(--border); border-radius: 9px; padding: 12px 14px; background: var(--bg2); }
.sch-row-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 4px; }
.sch-row-head b { font-size: 14px; }
.sch-row .meta { margin-top: 3px; }
.sch-row .meta code { background: var(--panel2); padding: 1px 6px; border-radius: 5px; font-family: var(--mono); }
.sch-actions { display: flex; align-items: center; gap: 8px; margin-top: 10px; flex-wrap: wrap; }
/* `margin-top: 0` anula a margem do `button.danger` (pensada para quando ele aparece
   isolado em bloco) — aqui ela desalinhava o Excluir em relação aos demais. */
.sch-actions button { padding: 5px 11px; font-size: 12px; margin-top: 0; }
/* Excluir é a ação destrutiva: fica separada das demais, no canto direito do card. */
.sch-actions button.danger { margin-left: auto; }

.toast { position: fixed; bottom: 18px; right: 18px; background: var(--panel2); border: 1px solid var(--border);
  padding: 11px 16px; border-radius: 9px; font-size: 13px; box-shadow: var(--shadow); animation: slidein .18s ease; }
@keyframes slidein { from { transform: translateY(8px); opacity: 0; } to { transform: none; opacity: 1; } }

/* Scrollbar */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: #2a313d; border-radius: 6px; border: 2px solid var(--bg); }
::-webkit-scrollbar-thumb:hover { background: #39424f; }

/* ── Histórico de versões + diff (aba Arquivos) ── */
.hist { margin-top: 12px; border: 1px solid var(--border); border-radius: 10px; background: var(--panel2); }
.hist.hidden { display: none; }
.hist-head { display: flex; align-items: center; justify-content: space-between;
  padding: 10px 12px; border-bottom: 1px solid var(--border); font-size: 13px; }

.hist-list { display: flex; flex-direction: column; max-height: 190px; overflow-y: auto; }
.hist-item { display: grid; grid-template-columns: auto 1fr auto; gap: 10px; align-items: center;
  text-align: left; padding: 8px 12px; border: 0; border-bottom: 1px solid rgba(255,255,255,.05);
  background: transparent; color: var(--fg); font-size: 12px; border-radius: 0; }
.hist-item:hover { background: rgba(255,255,255,.04); }
.hist-item.sel { background: rgba(79,140,255,.14); box-shadow: inset 2px 0 0 var(--accent); }
.hist-item .quando { color: var(--muted); white-space: nowrap; }
.hist-item .quem { font-weight: 600; }
.hist-item .tam { font-size: 11px; }
.hist-list .muted { padding: 12px; font-size: 12px; }

.hist-diff { border-top: 1px solid var(--border); }
.hist-diff.hidden { display: none; }
.hist-diff-head { display: flex; align-items: center; gap: 12px; padding: 8px 12px;
  border-bottom: 1px solid var(--border); font-size: 12px; color: var(--muted); }
.hist-diff-head .stats { margin-left: auto; font-variant-numeric: tabular-nums; }
.hist-diff-head .add { color: #4ea87b; font-weight: 600; }
.hist-diff-head .del { color: #e06c6c; font-weight: 600; }

.diff-body { max-height: 340px; overflow: auto; font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px; line-height: 1.55; }
.dl { display: grid; grid-template-columns: 42px 42px 18px 1fr; white-space: pre-wrap; word-break: break-word; }
.dl .ln { color: #5c6675; text-align: right; padding-right: 8px; user-select: none; font-size: 11px; }
.dl .sg { text-align: center; user-select: none; }
.l-add { background: rgba(78,168,123,.12); }
.l-add .sg, .l-add .tx { color: #8fd6b0; }
.l-del { background: rgba(224,108,108,.12); }
.l-del .sg, .l-del .tx { color: #f0a3a3; }
.l-eq .tx { color: var(--muted); }

/* ── Busca e criação de arquivos (aba Arquivos) ── */
/* margin-top afasta do cabeçalho (o `.card-head h2` zera a margem do título, então o
   respiro precisa vir daqui). */
.file-search { margin-top: 12px; margin-bottom: 10px; font-size: 13px; }
.search-results { max-height: 72vh; overflow: auto; font-size: 12px; }
.search-results.hidden { display: none; }
.search-results .muted { color: var(--muted); padding: 10px 4px; }
.sr-sec { font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--faint);
  margin: 12px 0 6px; font-weight: 600; }
.sr-sec:first-child { margin-top: 0; }
.sr-file, .sr-hit { cursor: pointer; padding: 6px 8px; border-radius: 6px; }
.sr-file:hover, .sr-hit:hover { background: var(--panel2); }
.sr-hit-file { color: var(--muted); font-size: 11px; margin-bottom: 2px; }
.sr-ln { color: var(--faint); }
.sr-hit-txt { font-family: var(--mono); font-size: 11.5px; line-height: 1.45;
  white-space: pre-wrap; word-break: break-word; }
.search-results mark { background: rgba(79,140,255,.32); color: var(--fg); border-radius: 3px; padding: 0 2px; }

/* ── Agendamento amigável (aba Rotinas) ── */
.dias-semana { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 4px; }
.dias-semana label { display: inline-flex; align-items: center; gap: 5px; margin: 0;
  font-size: 12px; color: var(--fg); cursor: pointer; }
.dias-semana input { width: auto; margin: 0; }
.sch-resumo { margin-top: 10px; padding: 8px 10px; border-radius: 8px; font-size: 12px;
  background: var(--bg2); border: 1px solid var(--border); color: var(--muted); }
.hint { display: block; margin-top: 4px; font-size: 11px; color: var(--faint); }

/* Ícone nativo do seletor de hora/data: o navegador o desenha escuro por padrão, o que
   o faz sumir no tema escuro. `invert` deixa branco, garantindo o contraste. */
input[type="time"]::-webkit-calendar-picker-indicator,
input[type="date"]::-webkit-calendar-picker-indicator {
  filter: invert(1);
  opacity: .75;
  cursor: pointer;
}
input[type="time"]::-webkit-calendar-picker-indicator:hover,
input[type="date"]::-webkit-calendar-picker-indicator:hover { opacity: 1; }

/* Excluir no editor: contorno vermelho em vez de fundo sólido — a ação é destrutiva,
   mas não deve competir visualmente com o Salvar (a ação principal). */
button.danger-outline { border-color: rgba(248,81,73,.55); color: #f0a3a3; background: transparent; }
button.danger-outline:hover:not(:disabled) { background: rgba(248,81,73,.12); border-color: var(--err); color: #fff; }

/* ── Usuários (aba de administrador) ── */
/* A grade padrão (300px) foi desenhada para a árvore de arquivos; a lista de usuários
   precisa de mais espaço para o e-mail, o papel e as ações caberem na mesma linha. */
#tab-users.cols { grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr); }
@media (max-width: 900px) { #tab-users.cols { grid-template-columns: 1fr; } }
.u-row {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 9px 10px; border-bottom: 1px solid var(--border);
}
.u-row:last-child { border-bottom: 0; }
.u-id { flex: 1 1 220px; min-width: 0; overflow-wrap: anywhere; }
.u-nome { color: var(--muted); font-weight: 400; }
.u-acoes { display: flex; align-items: center; gap: 6px; flex: none; }
/* `button.danger` traz `margin-top: 8px` (pensado para botão de bloco); numa linha de
   ações isso desalinharia o Excluir em relação aos vizinhos. */
.u-acoes button { padding: 5px 10px; font-size: 12px; margin-top: 0; }
.u-badge {
  display: inline-block; margin-left: 6px; padding: 1px 7px; border-radius: 999px;
  font-size: 11px; font-weight: 600; background: var(--panel2); color: var(--muted);
  border: 1px solid var(--border);
}
.u-badge.admin { color: var(--accent2); border-color: var(--accent); }
.u-voce { font-size: 12px; color: var(--faint); font-style: italic; }
.u-help { margin-top: 14px; font-size: 12.5px; color: var(--muted); }

/* ── Ambiente ── */
/* Staging fica em destaque: o operador precisa perceber, de relance, que aquele
   disparo ou rotina NÃO é produção. */
.amb-staging { color: var(--warn); font-weight: 700; }
/* Aviso de servidor desatualizado: precisa competir com o campo, não sussurrar. */
.hint.warn { color: var(--warn); font-weight: 600; }
#f-ambiente.staging, #sch-ambiente.staging {
  border-color: var(--warn);
  box-shadow: 0 0 0 1px var(--warn) inset;
}
