:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --border: #dfe3e8;
  --text: #1c2024;
  --muted: #667085;
  --accent: #2563eb;
  --ok: #067647;
  --ok-bg: #ecfdf3;
  --warn: #b54708;
  --warn-bg: #fffaeb;
  --error: #b42318;
  --error-bg: #fef3f2;
  --info-bg: #eff6ff;
  --radius: 8px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

body.centered {
  display: grid;
  place-items: center;
  min-height: 100vh;
}

main { padding: 24px; max-width: 1400px; margin: 0 auto; }
h1 { font-size: 22px; margin: 0 0 4px; }
h2 { font-size: 16px; margin: 0 0 12px; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.9em; }
pre { margin: 0; white-space: pre-wrap; word-break: break-word; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.muted { color: var(--muted); }
.small { font-size: 12px; }
.link-muted { color: var(--muted); font-size: 13px; }

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

.topbar {
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 12px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.brand { font-weight: 700; color: var(--text); }
.brand span { color: var(--accent); }
.topbar nav { display: flex; gap: 16px; flex: 1; }
.topbar nav a { color: var(--muted); padding: 4px 0; }
.topbar nav a.on { color: var(--text); box-shadow: inset 0 -2px var(--accent); }
.me { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.me img { width: 24px; height: 24px; border-radius: 50%; }

/* ---------- blocos ---------- */

.page-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  margin-bottom: 16px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 16px;
}

.card.login { width: min(380px, 92vw); text-align: center; }
.card.login h1 { font-size: 26px; }
/* `.card.actions` cai na regra de `.actions`, na secao de formularios. */

.alert {
  padding: 10px 12px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  margin: 0 0 12px;
}
.alert.ok { background: var(--ok-bg); border-color: #abefc6; color: var(--ok); }
.alert.warn { background: var(--warn-bg); border-color: #fedf89; color: var(--warn); }
.alert.error { background: var(--error-bg); border-color: #fecdca; color: var(--error); }

/* ---------- tabelas ---------- */

table { width: 100%; border-collapse: collapse; background: var(--surface); }
.matrix, .plain {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
th, td {
  padding: 8px 10px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
thead th {
  background: #fafbfc;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
}
tbody tr:last-child td { border-bottom: none; }
td.pick, th.pick { width: 32px; text-align: center; }
.tagcell { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px; }

/* Estado de cada celula da matriz de drift. */
.s-ok { background: var(--ok-bg); }
.s-behind { background: var(--warn-bg); color: var(--warn); font-weight: 600; }
.s-ahead { background: var(--info-bg); }
.s-error { background: var(--error-bg); }
.s-unknown { color: var(--muted); }

/* ---------- badges ---------- */

.badge, .tag {
  display: inline-block;
  padding: 1px 7px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  border: 1px solid var(--border);
  background: #f2f4f7;
  color: var(--muted);
}
.tag { font-style: normal; margin-right: 4px; }
.tag.approver { background: var(--info-bg); color: var(--accent); border-color: #bfdbfe; }

.badge.error, .c-failed, .c-failure, .c-rejected {
  background: var(--error-bg); color: var(--error); border-color: #fecdca;
}
.badge.warn, .c-pending_approval, .c-executing, .c-dispatching, .c-pending, .c-building {
  background: var(--warn-bg); color: var(--warn); border-color: #fedf89;
}
.c-done, .c-success, .c-approved {
  background: var(--ok-bg); color: var(--ok); border-color: #abefc6;
}

/* ---------- formularios ---------- */

.field { display: block; margin-bottom: 12px; font-size: 13px; color: var(--muted); }

/* Cobre todos os campos de texto, nao so type="text" — o valor de um secret
   e type="password" e ficava sem estilo nenhum. */
input[type="text"],
input[type="password"],
input[type="search"],
input[type="url"],
input[type="number"],
input[type="email"],
textarea,
select {
  display: block;
  width: 100%;
  margin-top: 4px;
  padding: 8px 10px;
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
}
input:focus-visible, textarea:focus-visible, select:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}
.tag-input { max-width: 160px; margin: 0; }
form.inline { display: flex; gap: 8px; align-items: center; }
form.inline input[type="text"] { width: 240px; margin: 0; }

/* Grupo de botoes lado a lado. Vale solto dentro de um card e no proprio card. */
.actions, .form-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
}
.actions form, .form-actions form { margin: 0; }
.form-actions { margin-top: 16px; }

.btn {
  display: inline-block;
  padding: 8px 14px;
  font: inherit;
  font-weight: 500;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
}
.btn:hover { background: #f2f4f7; text-decoration: none; }
.btn:disabled { opacity: 0.6; cursor: progress; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: #1d4ed8; }
.btn.danger { background: var(--error); border-color: var(--error); color: #fff; }
.btn.block { display: block; width: 100%; margin-top: 16px; }

.sticky-actions {
  position: sticky;
  bottom: 0;
  display: flex;
  gap: 16px;
  align-items: center;
  justify-content: flex-end;
  padding: 12px 16px;
  margin-top: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.sticky-actions label { display: flex; gap: 8px; align-items: center; font-size: 13px; }
.sticky-actions select { width: auto; margin: 0; }

/* ---------- diversos ---------- */

.timeline { list-style: none; padding: 0; margin: 0; }
.timeline li { padding: 8px 0; border-bottom: 1px solid var(--border); }
.timeline li:last-child { border-bottom: none; }
.description { font: inherit; }
.payload { max-width: 520px; max-height: 120px; overflow: auto; }

/* ---------- secrets ---------- */

.tag.owner { background: #fdf2fa; color: #c11574; border-color: #fcceee; }
.head-actions { display: flex; gap: 8px; align-items: center; }
.head-actions form { margin: 0; }
.row { display: flex; gap: 16px; flex-wrap: wrap; }
.row .field { flex: 1; min-width: 200px; }
.reveal {
  display: inline-block;
  max-width: 100%;
  padding: 2px 6px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 4px;
  word-break: break-all;
}

.check {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 12px;
  margin-bottom: 16px;
  background: var(--info-bg);
  border: 1px solid #bfdbfe;
  border-radius: var(--radius);
}
.check input { margin-top: 3px; }
.check span { display: block; }

.c-missing, .c-blocked { background: var(--error-bg); color: var(--error); border-color: #fecdca; }
/* `skipped` e verde: "sem modificacoes" e desfecho bom, nao pendencia. Vale
   para os dois badges da linha — o de status e o de preflight ("nao se
   aplica") — porque os dois so aparecem juntos, no item que virou no-op. */
.c-found, .c-skipped { background: var(--ok-bg); color: var(--ok); border-color: #abefc6; }
.c-unknown, .c-awaiting_secrets { background: var(--warn-bg); color: var(--warn); border-color: #fedf89; }

/* Celula editavel da matriz de secrets: valor em cima, nome embaixo. O input
   de valor cresce, o botao nao — senao o campo some em coluna estreita. */
.cell-edit { display: flex; gap: 4px; align-items: center; margin: 2px 0; }
.cell-edit input {
  flex: 1 1 auto;
  min-width: 0;
  font-family: var(--mono, ui-monospace, monospace);
  font-size: 12px;
  padding: 4px 6px;
  border: 1px solid var(--border, #d0d5dd);
  border-radius: 4px;
}
.cell-edit input[name="newVariableName"] { font-size: 11px; opacity: 0.85; }
.btn.small { padding: 3px 8px; font-size: 12px; line-height: 1.4; flex: 0 0 auto; }

/* --- Sinal de que algo esta acontecendo ------------------------------------
   A app e server-rendered: todo POST e uma navegacao, e o navegador fica na
   pagina antiga enquanto o servidor fala com GitHub, SSM e AWS. Sem sinal
   nenhum isso parece travamento. Estes tres elementos cobrem os casos:
   barra no topo para navegacao, botao ocupado para o clique, e skeleton
   para fragmento que ainda vai chegar. */

.progress {
  position: fixed;
  top: 0;
  left: 0;
  height: 3px;
  width: 0;
  background: var(--accent);
  z-index: 9999;
  transition: width 200ms ease-out, opacity 200ms linear 200ms;
  pointer-events: none;
}
.progress[hidden] { display: none; }
.progress.done { width: 100% !important; opacity: 0; }

/* Botao ocupado: nao usa :disabled porque desabilitar antes do submit pode
   descartar name/value do botao no payload. O bloqueio de clique duplo e
   feito no app.js, aqui e so o visual. */
.btn.is-busy {
  opacity: 0.75;
  cursor: progress;
  pointer-events: none;
  position: relative;
  padding-left: 26px;
}
.btn.is-busy::before {
  content: "";
  position: absolute;
  left: 8px;
  top: 50%;
  width: 11px;
  height: 11px;
  margin-top: -6px;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: spin 600ms linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Fragmento carregando: mantem a altura para a pagina nao pular. */
.is-loading { position: relative; min-height: 40px; }
.is-loading::after {
  content: "carregando...";
  display: block;
  padding: 12px 0;
  color: var(--muted);
  font-size: 13px;
}
.is-loading > * { opacity: 0.35; }

/* ---------- modal de disparo ----------
   Diferente da barra de navegacao do topo, esta porcentagem e real: vem de
   `/changes/:id/progress`, contando itens que ja sairam de `pending`. */
.modal {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  padding: 24px;
  max-width: 460px;
  width: calc(100% - 32px);
}
.modal::backdrop { background: rgba(28, 32, 36, 0.45); }
.modal h2 { margin: 0 0 8px; font-size: 17px; }

.meter {
  height: 8px;
  margin: 16px 0 8px;
  border-radius: 999px;
  background: var(--bg);
  border: 1px solid var(--border);
  overflow: hidden;
}
.meter > span {
  display: block;
  width: 0;
  height: 100%;
  background: var(--accent);
  transition: width 240ms ease;
}

.dispatch-error {
  margin: 12px 0 0;
  font-size: 13px;
  color: var(--error);
}

@media (prefers-reduced-motion: reduce) {
  .progress { transition: none; }
  .btn.is-busy::before { animation-duration: 2s; }
  .meter > span { transition: none; }
}
