:root {
  color-scheme: light dark;
  --bg: #f3f4f7;
  --panel: #ffffff;
  --panel-muted: #f8f9fb;
  --border: #e3e6eb;
  --text: #161a1f;
  --muted: #6b7280;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --accent-soft: #eaf0fe;
  --danger: #dc2626;
  --danger-soft: #fdecec;
  --ok: #16a34a;
  --ok-soft: #e9f8ee;
  --off: #9ca3af;
  --radius: 10px;
  --radius-sm: 7px;
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.06);
  --shadow-md: 0 6px 20px rgba(16, 24, 40, 0.10);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14171c;
    --panel: #1c2027;
    --panel-muted: #20252d;
    --border: #2c313a;
    --text: #e7e9ec;
    --muted: #9aa1ab;
    --accent-soft: #1d2b4d;
    --danger-soft: #3a1f21;
    --ok-soft: #16281d;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 10px 28px rgba(0, 0, 0, 0.45);
  }
}

* { box-sizing: border-box; }

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

h1, h2, h3, h4 { font-weight: 700; letter-spacing: -0.01em; }

header {
  padding: 0.65rem 1.75rem;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
  box-shadow: var(--shadow-sm);
  display: flex;
  align-items: center;
  gap: 1.1rem;
  position: sticky;
  top: 0;
  z-index: 10;
}

.header-logo { height: 52px; width: auto; display: block; }

.header-server-picker {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding-left: 1rem;
  border-left: 1px solid var(--border);
}

#server-select {
  padding: 0.45rem 0.6rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  min-width: 220px;
  font-size: 0.9rem;
}

.subtitle { color: var(--muted); font-size: 0.9rem; }
.header-right { margin-left: auto; display: flex; align-items: center; gap: 0.6rem; }
.backup-module-title {
  margin: 0;
  padding-left: 1rem;
  border-left: 1px solid var(--border);
  font-size: 1.05rem;
  font-weight: 700;
}

/* Botão "← Módulos": navegação secundária, não deve competir visualmente com ações primárias do
   header — por isso sem borda/fundo, só texto com hover sutil, em vez de outro botão "caixa". */
.btn-ghost {
  border: none;
  background: none;
  color: var(--muted);
  padding: 0.35rem 0.5rem;
  font-weight: 600;
}
.btn-ghost:hover { color: var(--accent); border-color: transparent; background: var(--accent-soft); border-radius: var(--radius-sm); }

main {
  max-width: 1180px;
  margin: 0 auto;
  padding: 1.75rem;
  width: 100%;
}

/* Componente genérico pra agrupar uma tabela/formulário/bloco de conteúdo num cartão — usado em
   todas as telas que antes jogavam tabela e formulário soltos direto no fundo da página. */
.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 1.35rem 1.5rem;
  margin-bottom: 1.5rem;
}
.card:last-child { margin-bottom: 0; }
.card > h3:first-child,
.card > .panel-header:first-child { margin-top: 0; }
.card > h4 {
  margin: 1.5rem 0 0.25rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--border);
}
.card > h4:first-child { margin-top: 0; padding-top: 0; border-top: none; }

#detail-panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 1.5rem;
}

.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.9rem;
  gap: 0.75rem;
}

.panel-header h2, .panel-header h3 { margin: 0; }

.dot {
  display: inline-block;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  flex-shrink: 0;
  background: var(--off);
}
.dot.online { background: var(--ok); box-shadow: 0 0 0 3px var(--ok-soft); }
.dot.stopped { background: var(--danger); box-shadow: 0 0 0 3px var(--danger-soft); }

section h3 { margin-top: 1.5rem; margin-bottom: 0.6rem; font-size: 1.05rem; }

.server-status-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.6rem 1.5rem;
  margin-bottom: 1rem;
  font-size: 0.9rem;
  color: var(--muted);
}
.server-status-row .dot { margin-right: 0.4rem; }
#btn-refresh-dashboard { margin-left: auto; }

.stat-summary {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 0.6rem 1.5rem;
  background: var(--panel-muted);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 1rem 1.1rem;
  margin: 1.1rem 0 1.5rem;
}

.stat-item {
  display: flex;
  align-items: baseline;
  gap: 0.45rem;
}

.stat-item .stat-label,
.stat-item .stat-value {
  font-size: 0.95rem;
}
.stat-item .stat-label { color: var(--muted); }
.stat-item .stat-value { font-weight: 700; font-size: 1.15rem; }
.stat-item.ok .stat-value { color: var(--ok); }
.stat-item.danger .stat-value { color: var(--danger); }

.dashboard-pool-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.7rem 0.5rem;
  border-bottom: 1px solid var(--border);
}
.dashboard-pool-row:last-child { border-bottom: none; }
.dashboard-pool-row .pool-name { font-weight: 600; }
.dashboard-pool-row .pool-meta { color: var(--muted); font-size: 0.8rem; }

.dashboard-monitored-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.7rem 0.5rem;
  border-bottom: 1px solid var(--border);
}
.dashboard-monitored-row:last-child { border-bottom: none; }
.dashboard-monitored-row .monitored-name { flex: 1; }

.monitored-checkbox { width: auto; }

.alert-toggle {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.8rem;
  color: var(--muted);
  white-space: nowrap;
}
.alert-toggle input { width: auto; }
.alert-interval { width: 3.5rem; padding: 0.3rem 0.4rem; }

.services-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  align-items: center;
  margin-bottom: 0.9rem;
}
.services-filters input[type="text"] {
  flex: 1;
  min-width: 180px;
}
.services-filters select { width: auto; }

#services-table th[data-sort] {
  cursor: pointer;
  user-select: none;
}
#services-table th[data-sort]:hover { color: var(--text); }
#services-table th[data-sort]::after {
  content: "";
  display: inline-block;
  width: 0.7em;
  margin-left: 0.2rem;
  opacity: 0.5;
}
#services-table th.sorted-asc::after { content: "▲"; opacity: 1; }
#services-table th.sorted-desc::after { content: "▼"; opacity: 1; }

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

th, td {
  text-align: left;
  padding: 0.65rem 0.6rem;
  border-bottom: 1px solid var(--border);
}

th {
  color: var(--muted);
  font-weight: 600;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--panel-muted); }
td a { color: var(--accent); font-weight: 600; text-decoration: none; }
td a:hover { text-decoration: underline; }

button {
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 0.45rem 0.85rem;
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 500;
  transition: border-color 0.12s, background-color 0.12s, box-shadow 0.12s, transform 0.05s;
}

button:hover { border-color: var(--accent); }
button:active { transform: translateY(1px); }
button:disabled { opacity: 0.5; cursor: not-allowed; }
button:disabled:hover { border-color: var(--border); }
button:disabled:active { transform: none; }
button.primary {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
  font-weight: 600;
}
button.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); box-shadow: var(--shadow-sm); }
button.danger { color: var(--danger); border-color: var(--danger); }
button.danger:hover { background: var(--danger-soft); }
button.small { padding: 0.3rem 0.6rem; font-size: 0.8rem; margin-right: 0.3rem; }
button.small:last-child { margin-right: 0; }
button.link {
  background: none;
  border: none;
  padding: 0;
  color: var(--danger);
  text-decoration: underline;
  font-size: inherit;
  font-weight: 500;
}
button.link:hover { border-color: transparent; }

.action-select {
  padding: 0.3rem 0.4rem;
  font-size: 0.8rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
}

textarea {
  width: 100%;
  font-family: ui-monospace, Consolas, monospace;
  font-size: 0.85rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.6rem;
  background: var(--panel-muted);
  color: var(--text);
  resize: vertical;
}

.hint { color: var(--muted); font-size: 0.85rem; margin: 0.25rem 0 0.75rem; line-height: 1.5; }
.hint code {
  background: var(--panel-muted);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.05rem 0.3rem;
  font-size: 0.85em;
}
.empty { color: var(--muted); font-style: italic; padding: 0.5rem 0; }
.hidden { display: none !important; }

.status-pill {
  display: inline-block;
  padding: 0.15rem 0.6rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
  background: var(--panel-muted);
  border: 1px solid var(--border);
  color: var(--muted);
}
.status-pill.Succeeded, .status-pill.Running {
  color: var(--ok);
  background: var(--ok-soft);
  border-color: transparent;
}
.status-pill.Failed, .status-pill.TimedOut {
  color: var(--danger);
  background: var(--danger-soft);
  border-color: transparent;
}
.status-pill.Dispatched { color: var(--accent); background: var(--accent-soft); border-color: transparent; }

#empty-state {
  color: var(--muted);
  padding: 3rem 1rem;
  text-align: center;
  font-size: 1rem;
}

dialog {
  border-radius: var(--radius);
  border: 1px solid var(--border);
  padding: 1.5rem;
  background: var(--panel);
  color: var(--text);
  min-width: 320px;
  box-shadow: var(--shadow-md);
}
dialog::backdrop { background: rgba(16, 20, 26, 0.45); backdrop-filter: blur(1px); }
dialog h3 { margin-top: 0; }

/* Label/input/select/textarea estilizados globalmente, não só dentro de <dialog> — antes disso,
   qualquer formulário fora de um dialog (ex: "Novo job de backup", que mora direto na página do
   módulo Backup) ficava sem estilo nenhum: rótulo e campo espremidos numa linha só só porque
   "label { flex-direction: column }" só tinha regra para contexto de dialog. */
label {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 0.9rem;
}
input, select, textarea {
  font: inherit;
  font-size: 0.92rem;
  font-weight: 400;
  color: var(--text);
  padding: 0.55rem 0.65rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg);
}
input:focus, select:focus, textarea:focus {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
  border-color: var(--accent);
}
.dialog-actions { display: flex; justify-content: flex-end; gap: 0.6rem; margin-top: 1.25rem; }
dialog.wide { min-width: 480px; max-width: 90vw; }
.checkbox-label { flex-direction: row !important; align-items: center; gap: 0.5rem !important; font-weight: 500 !important; color: var(--text) !important; }
.checkbox-label input { width: auto; }

/* Layout em grade pra formulários com vários campos curtos (job/origem de backup) — cada campo
   quebra linha sozinho conforme o espaço disponível, em vez de empilhar um por linha inteira ou
   espremer tudo numa linha só. Grid (não flexbox) de propósito: quando um rótulo quebra em duas
   linhas (ex: "Pasta de destino (dentro do storage de backup)"), o grid estica todos os itens
   daquela linha pra mesma altura, e "justify-content: flex-end" no label empurra o conteúdo pro
   fim da caixa — assim todo campo da mesma linha fica alinhado pela mesma base, independente do
   rótulo vizinho ter uma ou duas linhas. Com flexbox isso não acontecia: cada item só tinha a
   altura do seu próprio conteúdo, e o campo ao lado de um rótulo maior ficava mais alto que os
   outros.
*/
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 0.9rem 1.25rem;
  align-items: stretch;
}
.form-grid > label { justify-content: flex-end; margin-bottom: 0; }
.form-grid > .dialog-actions,
.form-grid > p.hint { grid-column: 1 / -1; }
#backup-source-ssh-fields:not(.hidden) { display: contents; }

#permissions-service-list {
  max-height: 300px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.6rem 0.75rem;
  margin-top: 0.5rem;
  background: var(--panel-muted);
}
#permissions-service-list label {
  flex-direction: row;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.3rem;
  font-size: 0.85rem;
  font-weight: 400;
  color: var(--text);
}
#permissions-service-list input { width: auto; }

#pool-members-list {
  list-style: decimal;
  padding-left: 1.5rem;
  margin: 0.5rem 0;
}
#pool-members-list li {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.3rem 0;
  font-size: 0.9rem;
}
#pool-members-list li .member-name { flex: 1; }

#pool-member-candidates {
  max-height: 300px;
  overflow-y: auto;
  margin-top: 0.4rem;
}
#pool-member-candidates .candidate-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.35rem 0.5rem;
  font-size: 0.85rem;
  border-bottom: 1px solid var(--border);
}

.pool-run-controls {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  margin: 0.5rem 0;
}
.pool-run-controls select { padding: 0.5rem; width: auto; }

.pool-run-progress {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.6rem 0.75rem;
  margin: 0.5rem 0;
  font-size: 0.85rem;
  background: var(--panel-muted);
}
.pool-run-progress .progress-row { display: flex; justify-content: space-between; padding: 0.2rem 0; }

.module-picker-wrapper {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
}

.module-picker-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  padding: 2.5rem;
  width: 100%;
  max-width: 540px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  text-align: center;
}

.module-picker-logo { display: block; max-width: 300px; width: 100%; height: auto; margin-bottom: 0.5rem; }
.module-picker-card h1 { margin: 0.5rem 0 1.25rem; font-size: 1.35rem; }

.module-options {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  width: 100%;
  margin-bottom: 1.5rem;
}

.module-option {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.25rem;
  padding: 1.1rem 1.35rem;
  text-align: left;
  font-size: 0.95rem;
  border-radius: var(--radius);
  transition: border-color 0.12s, box-shadow 0.12s, transform 0.08s;
}
.module-option strong { font-size: 1.05rem; }
.module-option span { color: var(--muted); font-size: 0.85rem; font-weight: 400; }
.module-option:hover { border-color: var(--accent); box-shadow: var(--shadow-sm); transform: translateY(-1px); }

.login-wrapper {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
}

.login-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  padding: 2.5rem;
  width: 100%;
  max-width: 420px;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.login-card h1 { margin: 0 0 0.25rem; font-size: 1.4rem; }
.login-logo { display: block; max-width: 300px; width: 100%; height: auto; margin: 0 auto 1rem; }
.login-card button { margin-top: 0.75rem; padding: 0.65rem; font-size: 0.95rem; }
.login-error { color: var(--danger); font-size: 0.85rem; margin: 0 0 0.5rem; font-weight: 500; }

/* Campo de senha com botão de mostrar/ocultar ("olhinho") — reutilizado no login, na criação de
   usuário e na redefinição de senha. */
.password-field { position: relative; display: flex; }
.password-field input { flex: 1; padding-right: 2.3rem; }
.password-toggle {
  position: absolute;
  right: 0.25rem;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  padding: 0.25rem;
  margin: 0;
  cursor: pointer;
  color: var(--muted);
  display: flex;
  align-items: center;
  justify-content: center;
}
.password-toggle:hover { color: var(--text); border: none; }
.password-toggle .eye-slash { opacity: 0; transition: opacity 0.1s; }
.password-toggle.is-visible .eye-slash { opacity: 1; }

#toast-container {
  position: fixed;
  bottom: 1.25rem;
  right: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  z-index: 100;
  max-width: 360px;
}

.toast {
  background: var(--panel);
  border: 1px solid var(--border);
  border-left: 4px solid var(--danger);
  border-radius: var(--radius-sm);
  padding: 0.7rem 0.9rem;
  font-size: 0.85rem;
  box-shadow: var(--shadow-md);
  animation: toast-in 0.15s ease-out;
}

.toast strong { display: block; margin-bottom: 0.2rem; }

@keyframes toast-in {
  from { transform: translateY(8px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

pre.output {
  white-space: pre-wrap;
  font-size: 0.8rem;
  background: var(--panel-muted);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.6rem;
  max-height: 200px;
  overflow-y: auto;
}

/* O layout acima foi desenhado pra desktop (cabeçalho numa linha só, linhas de serviço em 3
   colunas lado a lado, tabelas largas) e nunca teve um ponto de quebra pra telas estreitas —
   nessa largura os itens ficam espremidos/cortados em vez de empilhar. */
@media (max-width: 768px) {
  header {
    flex-wrap: wrap;
    padding: 0.6rem 1rem;
  }
  .header-logo { height: 40px; }
  .header-server-picker { flex-basis: 100%; border-left: none; padding-left: 0; }
  #server-select { flex: 1; min-width: 0; }
  .header-right { margin-left: 0; }
  .backup-module-title { border-left: none; padding-left: 0; }

  main { padding: 1rem; }
  .card { padding: 1rem; }

  .stat-summary {
    grid-template-columns: repeat(2, 1fr);
    gap: 0.5rem 0.75rem;
    padding: 0.75rem;
  }
  .stat-item { flex-wrap: wrap; gap: 0.2rem 0.4rem; }
  .stat-item .stat-label,
  .stat-item .stat-value {
    font-size: 0.85rem;
  }

  .dashboard-pool-row,
  .dashboard-monitored-row {
    flex-direction: column;
    align-items: stretch;
    gap: 0.35rem;
  }
  .dashboard-monitored-row .action-select { width: 100%; }

  .form-grid { grid-template-columns: 1fr; }

  table { display: block; overflow-x: auto; white-space: nowrap; }
}
