/* =========================================================================
   Painel do Servidor Sier — sistema visual
   Consola de operações: densa, legível ao relance, sem ornamento.
   O estado é comunicado por cor E por texto — nunca só por cor.
   ========================================================================= */

:root {
  color-scheme: dark light;

  /* Superfícies (escuro por omissão: é o que se usa numa sala de operações) */
  --bg:          #0b0f14;
  --bg-raised:   #111721;
  --bg-sunken:   #080b0f;
  --bg-hover:    #18202c;
  --border:      #1f2937;
  --border-soft: #161e29;

  /* Texto */
  --fg:          #e6edf3;
  --fg-muted:    #8b98a9;
  --fg-faint:    #5b6675;

  /* Acento — distinto das cores de estado, para não confundir ação com saúde */
  --accent:      #2dd4bf;
  --accent-deep: #0d9488;
  --accent-fg:   #04201d;

  /* Estado */
  --ok:      #34d399;
  --ok-bg:   #0d2b22;
  --warn:    #fbbf24;
  --warn-bg: #2e2410;
  --bad:     #f87171;
  --bad-bg:  #2f1618;
  --idle:    #64748b;
  --idle-bg: #171d26;
  --info:    #60a5fa;
  --info-bg: #10203a;

  --radius:    10px;
  --radius-sm: 6px;
  --sidebar-w: 232px;

  --mono: ui-monospace, "SF Mono", "Cascadia Mono", "Roboto Mono", Menlo, Consolas, monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;

  --shadow: 0 4px 16px rgb(0 0 0 / 0.4);
}

@media (prefers-color-scheme: light) {
  :root {
    --bg:          #f6f8fa;
    --bg-raised:   #ffffff;
    --bg-sunken:   #eef1f5;
    --bg-hover:    #eaeef3;
    --border:      #d5dce4;
    --border-soft: #e5eaf0;
    --fg:          #16202c;
    --fg-muted:    #5a6878;
    --fg-faint:    #8b98a9;
    --accent:      #0d9488;
    --accent-deep: #0f766e;
    --accent-fg:   #ffffff;
    --ok:      #047857;  --ok-bg:   #dcfae9;
    --warn:    #a16207;  --warn-bg: #fdf0d0;
    --bad:     #b91c1c;  --bad-bg:  #fde2e2;
    --idle:    #64748b;  --idle-bg: #e8ecf1;
    --info:    #1d4ed8;  --info-bg: #dbe8fe;
    --shadow: 0 3px 12px rgb(15 30 50 / 0.10);
  }
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 15px/1.55 var(--sans);
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 { margin: 0; font-weight: 620; line-height: 1.25; letter-spacing: -0.01em; }
h1 { font-size: 1.4rem; }
h2 { font-size: 1.1rem; }
h3 { font-size: 0.95rem; }
p  { margin: 0 0 0.6em; }
a  { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code, pre, .mono, .num { font-family: var(--mono); font-size: 0.86em; }

.muted { color: var(--fg-muted); }
.faint { color: var(--fg-faint); }
.small { font-size: 0.85rem; }
.nowrap { white-space: nowrap; }
.right  { text-align: right; }
.center { text-align: center; }

/* ---------------------------------------------------------------- arranque */
.boot {
  min-height: 100dvh; display: grid; place-content: center;
  justify-items: center; gap: 1rem; color: var(--fg-muted);
}
.boot-spinner {
  width: 30px; height: 30px; border-radius: 50%;
  border: 2.5px solid var(--border); border-top-color: var(--accent);
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------------------------------------------------------------- estrutura */
.shell { display: grid; grid-template-columns: var(--sidebar-w) 1fr; min-height: 100dvh; }

.sidebar {
  background: var(--bg-sunken);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100dvh; overflow-y: auto;
}

.brand {
  display: flex; align-items: center; gap: 0.6rem;
  padding: 1rem 1.1rem; border-bottom: 1px solid var(--border-soft);
}
.brand-mark {
  width: 26px; height: 26px; border-radius: 7px; flex: none;
  background: linear-gradient(140deg, var(--accent), var(--accent-deep));
  display: grid; place-content: center;
  color: var(--accent-fg); font-weight: 800; font-size: 12px; letter-spacing: -0.03em;
}
.brand-text strong { display: block; font-size: 0.9rem; letter-spacing: -0.01em; }
.brand-text span   { display: block; font-size: 0.72rem; color: var(--fg-faint); }

.nav { padding: 0.6rem; display: flex; flex-direction: column; gap: 1px; flex: 1; }
.nav-group { margin-top: 0.9rem; padding: 0 0.6rem 0.3rem;
  font-size: 0.68rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--fg-faint); }
.nav a {
  display: flex; align-items: center; gap: 0.6rem;
  padding: 0.44rem 0.6rem; border-radius: var(--radius-sm);
  color: var(--fg-muted); font-size: 0.875rem; text-decoration: none;
}
.nav a:hover { background: var(--bg-hover); color: var(--fg); }
.nav a.active { background: var(--bg-hover); color: var(--fg); font-weight: 560;
  box-shadow: inset 2px 0 0 var(--accent); }
.nav a .badge { margin-left: auto; }
.nav-icon { width: 16px; height: 16px; flex: none; opacity: 0.8; }

.sidebar-foot {
  padding: 0.7rem 0.9rem; border-top: 1px solid var(--border-soft);
  font-size: 0.78rem; color: var(--fg-faint);
  display: flex; align-items: center; justify-content: space-between; gap: 0.5rem;
}

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

.topbar {
  display: flex; align-items: center; gap: 1rem;
  padding: 0.9rem 1.4rem; border-bottom: 1px solid var(--border);
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(8px);
  position: sticky; top: 0; z-index: 20;
}
.topbar h1 { flex: 1; min-width: 0; }
.topbar .sub { display: block; font-size: 0.78rem; font-weight: 400; color: var(--fg-muted); }

.content { padding: 1.4rem; flex: 1; min-width: 0; }
.content > section { margin-bottom: 1.6rem; }

/* ---------------------------------------------------------------- cartões */
.card {
  background: var(--bg-raised); border: 1px solid var(--border);
  border-radius: var(--radius); overflow: hidden;
}
.card-head {
  display: flex; align-items: center; gap: 0.7rem;
  padding: 0.75rem 1rem; border-bottom: 1px solid var(--border-soft);
}
.card-head h2, .card-head h3 { flex: 1; min-width: 0; }
.card-body { padding: 1rem; }
.card-body.tight { padding: 0; }

.grid { display: grid; gap: 1rem; }
.grid.cols-2 { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.grid.cols-3 { grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); }
.grid.cols-4 { grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); }

/* ---------------------------------------------------------------- métricas */
.metric { padding: 0.9rem 1rem; }
.metric-label { font-size: 0.73rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--fg-faint); }
.metric-value { font-size: 1.6rem; font-weight: 640; letter-spacing: -0.02em; margin-top: 0.15rem;
  font-variant-numeric: tabular-nums; }
.metric-value .unit { font-size: 0.9rem; font-weight: 400; color: var(--fg-muted); margin-left: 0.15rem; }
.metric-sub { font-size: 0.78rem; color: var(--fg-muted); margin-top: 0.1rem; }

.meter { height: 6px; border-radius: 3px; background: var(--bg-sunken); overflow: hidden; margin-top: 0.55rem; }
.meter > i { display: block; height: 100%; border-radius: 3px; background: var(--accent);
  transition: width 0.4s ease; }
.meter.is-warn > i { background: var(--warn); }
.meter.is-bad  > i { background: var(--bad); }

/* ---------------------------------------------------------------- estado */
.badge {
  display: inline-flex; align-items: center; gap: 0.35rem;
  padding: 0.13rem 0.5rem; border-radius: 100px;
  font-size: 0.74rem; font-weight: 560; white-space: nowrap;
  background: var(--idle-bg); color: var(--idle);
}
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; flex: none; }
.badge.no-dot::before { display: none; }
.badge.ok   { background: var(--ok-bg);   color: var(--ok); }
.badge.warn { background: var(--warn-bg); color: var(--warn); }
.badge.bad  { background: var(--bad-bg);  color: var(--bad); }
.badge.info { background: var(--info-bg); color: var(--info); }
.badge.pulse::before { animation: pulse 1.8s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: 0.35; } }

/* ---------------------------------------------------------------- tabelas */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 0.875rem; }
thead th {
  text-align: left; padding: 0.5rem 0.85rem;
  font-size: 0.71rem; text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--fg-faint); font-weight: 620;
  border-bottom: 1px solid var(--border); white-space: nowrap;
  background: var(--bg-sunken); position: sticky; top: 0;
}
tbody td { padding: 0.55rem 0.85rem; border-bottom: 1px solid var(--border-soft); vertical-align: middle; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: var(--bg-hover); }
td .num, td .mono { font-variant-numeric: tabular-nums; }

/* ---------------------------------------------------------------- botões */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.4rem;
  padding: 0.42rem 0.8rem; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--bg-raised); color: var(--fg);
  font: inherit; font-size: 0.85rem; font-weight: 520; cursor: pointer;
  white-space: nowrap; transition: background 0.12s, border-color 0.12s;
}
.btn:hover:not(:disabled) { background: var(--bg-hover); border-color: var(--fg-faint); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-sm { padding: 0.26rem 0.55rem; font-size: 0.79rem; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-fg); font-weight: 600; }
.btn-primary:hover:not(:disabled) { background: var(--accent-deep); border-color: var(--accent-deep); }
.btn-danger  { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 40%, var(--border)); }
.btn-danger:hover:not(:disabled) { background: var(--bad-bg); border-color: var(--bad); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--fg-muted); }
.btn-ghost:hover:not(:disabled) { background: var(--bg-hover); color: var(--fg); }
.btn-row { display: flex; flex-wrap: wrap; gap: 0.45rem; }

/* ---------------------------------------------------------------- formulários */
label { display: block; font-size: 0.83rem; font-weight: 540; margin-bottom: 0.3rem; }
input[type=text], input[type=password], input[type=email], input[type=number],
select, textarea {
  width: 100%; padding: 0.5rem 0.65rem;
  background: var(--bg-sunken); color: var(--fg);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  font: inherit; font-size: 0.9rem;
}
input:focus-visible, select:focus-visible, textarea:focus-visible,
.btn:focus-visible, a:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 1px;
}
textarea { font-family: var(--mono); font-size: 0.83rem; line-height: 1.5; resize: vertical; min-height: 320px; }
.field { margin-bottom: 0.9rem; }
.field-hint { font-size: 0.78rem; color: var(--fg-muted); margin-top: 0.25rem; }

/* ---------------------------------------------------------------- entrada */
.login-wrap { min-height: 100dvh; display: grid; place-items: center; padding: 1.5rem; }
.login {
  width: 100%; max-width: 380px;
  background: var(--bg-raised); border: 1px solid var(--border);
  border-radius: 14px; padding: 1.8rem; box-shadow: var(--shadow);
}
.login .brand { border: 0; padding: 0 0 1.3rem; }
.login .err {
  background: var(--bad-bg); color: var(--bad); border: 1px solid color-mix(in srgb, var(--bad) 30%, transparent);
  padding: 0.55rem 0.75rem; border-radius: var(--radius-sm); font-size: 0.85rem; margin-bottom: 0.9rem;
}
.totp-input { letter-spacing: 0.4em; font-family: var(--mono); text-align: center; font-size: 1.15rem; }

/* ---------------------------------------------------------------- diálogos */
.dialog {
  border: 1px solid var(--border); border-radius: 12px;
  background: var(--bg-raised); color: var(--fg);
  padding: 1.3rem; max-width: 480px; width: calc(100vw - 2rem);
  box-shadow: var(--shadow);
}
.dialog::backdrop { background: rgb(0 0 0 / 0.55); backdrop-filter: blur(2px); }
.dialog h2 { margin-bottom: 0.6rem; }
.dialog menu { display: flex; justify-content: flex-end; gap: 0.5rem; padding: 0; margin: 1.2rem 0 0; }
.dialog-wide { max-width: min(1000px, calc(100vw - 2rem)); }
#confirm-typed { margin-top: 0.9rem; }
#confirm-typed code { background: var(--bg-sunken); padding: 0.1rem 0.3rem; border-radius: 4px; }

.job-head { display: flex; align-items: flex-start; gap: 1rem; margin-bottom: 0.8rem; }
.job-head > div:first-child { flex: 1; min-width: 0; }
.job-actions { display: flex; gap: 0.4rem; }
.job-output {
  background: var(--bg-sunken); border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 0.8rem; margin: 0; height: min(60vh, 480px); overflow: auto;
  font-family: var(--mono); font-size: 0.8rem; line-height: 1.5;
  white-space: pre-wrap; word-break: break-word;
}
.job-output .l-stderr { color: var(--warn); }
.job-output .l-meta   { color: var(--accent); }

/* ---------------------------------------------------------------- avisos */
.toasts {
  position: fixed; bottom: 1rem; right: 1rem; z-index: 100;
  display: flex; flex-direction: column; gap: 0.5rem; max-width: 380px;
}
.toast {
  background: var(--bg-raised); border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius-sm); padding: 0.65rem 0.85rem;
  box-shadow: var(--shadow); font-size: 0.86rem;
  animation: toast-in 0.18s ease-out;
}
.toast.ok  { border-left-color: var(--ok); }
.toast.bad { border-left-color: var(--bad); }
.toast.warn{ border-left-color: var(--warn); }
.toast strong { display: block; margin-bottom: 0.1rem; }
@keyframes toast-in { from { opacity: 0; transform: translateX(12px); } }

/* ---------------------------------------------------------------- alertas */
.alert {
  display: flex; gap: 0.7rem; align-items: flex-start;
  padding: 0.7rem 0.9rem; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--bg-raised); font-size: 0.87rem;
}
.alert.warn { background: var(--warn-bg); border-color: color-mix(in srgb, var(--warn) 30%, transparent); }
.alert.bad  { background: var(--bad-bg);  border-color: color-mix(in srgb, var(--bad) 30%, transparent); }
.alert.info { background: var(--info-bg); border-color: color-mix(in srgb, var(--info) 30%, transparent); }
.alert strong { display: block; }
.alert-list { display: flex; flex-direction: column; gap: 0.5rem; }

/* ---------------------------------------------------------------- programas */
.prog-card { display: flex; flex-direction: column; }
.prog-head { display: flex; align-items: flex-start; gap: 0.7rem; padding: 0.9rem 1rem 0.7rem; }
.prog-head h3 { flex: 1; min-width: 0; }
.prog-kind { font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.05em;
  color: var(--fg-faint); font-weight: 600; }
.prog-desc { padding: 0 1rem; font-size: 0.83rem; color: var(--fg-muted);
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.prog-facts { padding: 0.7rem 1rem; display: flex; flex-wrap: wrap; gap: 0.35rem 0.9rem;
  font-size: 0.79rem; color: var(--fg-muted); }
.prog-facts b { color: var(--fg); font-weight: 560; }
.prog-foot { margin-top: auto; padding: 0.7rem 1rem; border-top: 1px solid var(--border-soft);
  display: flex; gap: 0.4rem; flex-wrap: wrap; }

.kv { display: grid; grid-template-columns: minmax(120px, auto) 1fr; gap: 0.4rem 1rem; font-size: 0.87rem; }
.kv dt { color: var(--fg-muted); }
.kv dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }

/* ---------------------------------------------------------------- diversos */
.empty { padding: 2.2rem 1rem; text-align: center; color: var(--fg-muted); font-size: 0.9rem; }
.spinner-inline { display: inline-block; width: 13px; height: 13px; border-radius: 50%;
  border: 2px solid var(--border); border-top-color: var(--accent);
  animation: spin 0.8s linear infinite; vertical-align: -2px; }
.toolbar { display: flex; gap: 0.5rem; align-items: center; flex-wrap: wrap; margin-bottom: 0.9rem; }
.toolbar .grow { flex: 1; }
.tabs { display: flex; gap: 0.2rem; border-bottom: 1px solid var(--border); margin-bottom: 1rem; }
.tabs button {
  padding: 0.5rem 0.8rem; border: 0; background: transparent; color: var(--fg-muted);
  font: inherit; font-size: 0.87rem; cursor: pointer; border-bottom: 2px solid transparent;
}
.tabs button.active { color: var(--fg); border-bottom-color: var(--accent); font-weight: 560; }
.log-view {
  background: var(--bg-sunken); border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 0.8rem; margin: 0; max-height: 62vh; overflow: auto;
  font-family: var(--mono); font-size: 0.79rem; line-height: 1.5; white-space: pre-wrap; word-break: break-word;
}
.trunc { display: block; max-width: 34ch; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------------------------------------------------------------- responsivo */
@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; border-right: 0; border-bottom: 1px solid var(--border); }
  .nav { flex-direction: row; flex-wrap: wrap; }
  .nav-group { display: none; }
  .nav a.active { box-shadow: inset 0 -2px 0 var(--accent); }
  .content { padding: 1rem; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
