/* ==========================================================================
   TOKENS — a camada que carrega o "gênero Datadog" (fonte: demo aprovada)
   ========================================================================== */
:root {
  /* Superfícies */
  --nav-bg: #1b1638;
  --nav-hover: #2c2452;
  --bg: #ffffff;
  --bg-subtle: #f7f7fa;
  --border: #e3e3ea;

  /* Texto */
  --text: #33334d;
  --text-muted: #73738c;
  --text-faint: #9c9cb0;

  /* Acento — usado com parcimônia */
  --accent: #632ca6;
  --accent-hover: #4f2385;

  /* Semântica de status — sólidos, sem pastel */
  --ok: #3ba55d;
  --warn: #d9a514;
  --crit: #d64540;
  --paused: #9c9cb0;

  /* Tipografia */
  --font: "Inter", -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
  --fs-base: 13px;
  --fs-small: 12px;
  --fs-micro: 11px;

  /* Geometria */
  --radius: 3px;
  --row-h: 36px;
}

* { box-sizing: border-box; margin: 0; }
html { font-size: var(--fs-base); }

body {
  font-family: var(--font);
  color: var(--text);
  background: var(--bg);
  display: grid;
  grid-template-columns: 48px 1fr;
  grid-template-rows: 44px 1fr;
  grid-template-areas: "nav topbar" "nav main";
  height: 100vh;
  overflow: hidden;
}

a { color: var(--accent); }

/* ==========================================================================
   SIDEBAR
   ========================================================================== */
.sidenav {
  grid-area: nav;
  background: var(--nav-bg);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 8px 0;
  gap: 2px;
}
.sidenav .logo {
  width: 28px; height: 28px;
  border-radius: var(--radius);
  background: var(--accent);
  color: #fff;
  display: grid; place-items: center;
  font-weight: 700; font-size: 14px;
  margin-bottom: 10px;
}
.sidenav a {
  width: 36px; height: 36px;
  display: grid; place-items: center;
  border-radius: var(--radius);
  color: #b9b3d4;
}
.sidenav a:hover { background: var(--nav-hover); color: #fff; }
.sidenav a.active { background: var(--nav-hover); color: #fff; box-shadow: inset 2px 0 0 var(--accent); }
.sidenav a svg { width: 18px; height: 18px; }
.sidenav .spacer { flex: 1; }

/* ==========================================================================
   TOPBAR
   ========================================================================== */
.topbar {
  grid-area: topbar;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 16px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
}
.breadcrumb { font-size: var(--fs-small); color: var(--text-muted); white-space: nowrap; }
.breadcrumb strong { color: var(--text); font-weight: 600; }
.search {
  flex: 1; max-width: 480px;
  display: flex; align-items: center; gap: 6px;
  height: 28px; padding: 0 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-subtle);
  color: var(--text-faint);
  font-family: var(--mono); font-size: var(--fs-small);
}
.search input {
  border: 0; background: transparent; outline: 0;
  font: inherit; color: var(--text); width: 100%;
}
.topbar .push { margin-left: auto; }
/* Indicador de "live" — informativo, não é um controle (sem chevron) */
.liverange {
  display: flex; align-items: center; gap: 6px;
  height: 28px; padding: 0 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: var(--fs-small);
  color: var(--text-muted);
  background: var(--bg);
  white-space: nowrap;
}
.live-dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--ok);
  animation: pulse 2s infinite;
}
@keyframes pulse { 50% { opacity: .4; } }

/* ==========================================================================
   MAIN
   ========================================================================== */
main {
  grid-area: main;
  display: grid;
  grid-template-columns: 200px 1fr;
  overflow: hidden;
}
main.single { grid-template-columns: 1fr; }  /* página de alertas: sem facets */

/* Facets */
.facets {
  border-right: 1px solid var(--border);
  background: var(--bg-subtle);
  padding: 12px;
  overflow-y: auto;
  font-size: var(--fs-small);
}
.facet-group { margin-bottom: 16px; }
.facet-group h3 {
  font-size: var(--fs-micro);
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--text-faint);
  font-weight: 600;
  margin-bottom: 6px;
}
.facet {
  display: flex; align-items: center; gap: 6px;
  padding: 3px 4px;
  border-radius: var(--radius);
  cursor: pointer;
  color: var(--text);
}
.facet:hover { background: #ececf2; }
.facet .count {
  margin-left: auto;
  color: var(--text-faint);
  font-variant-numeric: tabular-nums;
}
.facet input { accent-color: var(--accent); }

/* Área de conteúdo */
.content { display: flex; flex-direction: column; overflow: hidden; }

.list-header {
  display: flex; align-items: baseline; gap: 10px;
  padding: 14px 16px 10px;
}
.list-header h1 { font-size: 16px; font-weight: 600; }
.list-header .meta {
  font-size: var(--fs-small);
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}
.list-header .actions { margin-left: auto; display: flex; gap: 8px; }

/* Botões */
button, .btn {
  font: inherit; font-size: var(--fs-small);
  height: 26px; padding: 0 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--text);
  cursor: pointer;
}
button:hover { border-color: var(--text-faint); }
button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff; font-weight: 600;
}
button.primary:hover { background: var(--accent-hover); }
button.primary:disabled {
  background: var(--bg-subtle); border-color: var(--border);
  color: var(--text-faint); cursor: default; font-weight: 400;
}
button:disabled { cursor: default; color: var(--text-faint); }
button.danger:hover { border-color: var(--crit); color: var(--crit); }
button:focus-visible, a:focus-visible, input:focus-visible,
select:focus-visible, .facet input:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 1px;
}

/* ==========================================================================
   TABELA
   ========================================================================== */
.table-wrap { overflow: auto; flex: 1; }
table { width: 100%; border-collapse: collapse; }
thead th {
  position: sticky; top: 0; z-index: 1;
  background: var(--bg-subtle);
  border-bottom: 1px solid var(--border);
  font-size: var(--fs-micro);
  text-transform: uppercase;
  letter-spacing: .06em;
  font-weight: 600;
  color: var(--text-muted);
  text-align: left;
  padding: 6px 12px;
  white-space: nowrap;
}
thead th.right { text-align: right; }
tbody td {
  border-bottom: 1px solid var(--border);
  padding: 0 12px;
  height: var(--row-h);
  font-size: var(--fs-small);
  vertical-align: middle;
  white-space: nowrap;
}
tbody tr:hover { background: #fafafd; }

.host { font-family: var(--mono); font-weight: 600; color: var(--text); }
.host-sub { font-size: var(--fs-micro); color: var(--text-faint); font-family: var(--mono); }
td.num { font-variant-numeric: tabular-nums; color: var(--text-muted); }

/* Status — pill sólida */
.pill {
  display: inline-flex; align-items: center;
  height: 18px; padding: 0 7px;
  border-radius: var(--radius);
  font-size: var(--fs-micro);
  font-weight: 700;
  letter-spacing: .03em;
  color: #fff;
  text-transform: uppercase;
}
.pill.ok { background: var(--ok); }
.pill.warn { background: var(--warn); }
.pill.crit { background: var(--crit); }
.pill.paused { background: var(--paused); }

/* Sparkline */
.spark { display: block; }
.spark polyline { fill: none; stroke: var(--accent); stroke-width: 1.5; }
.spark .fill { fill: var(--accent); opacity: .08; stroke: none; }
.spark-empty {
  display: inline-block; width: 90px;
  font-size: var(--fs-micro); color: var(--text-faint);
  font-family: var(--mono);
}

/* Tags de ambiente */
.tag {
  display: inline-block;
  padding: 1px 6px;
  border-radius: var(--radius);
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  font-family: var(--mono);
  font-size: var(--fs-micro);
  color: var(--text-muted);
}

/* Comando de deploy */
.command { display: flex; align-items: center; gap: 6px; }
.command code {
  font-family: var(--mono);
  font-size: var(--fs-micro);
  color: var(--text-muted);
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2px 6px;
  max-width: 260px;
  overflow: hidden;
  text-overflow: ellipsis;
}
.row-actions { display: flex; gap: 6px; justify-content: flex-end; }
.row-actions button { height: 22px; padding: 0 8px; font-size: var(--fs-micro); }

/* Painel de adicionar */
.add-panel {
  border-bottom: 1px solid var(--border);
  background: var(--bg-subtle);
  padding: 12px 16px;
  display: none;
}
.add-panel.open { display: block; }
.form-row { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; }
.field { display: flex; flex-direction: column; gap: 3px; }
.field.grow { flex: 1; min-width: 200px; }
.field label {
  font-size: var(--fs-micro);
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--text-muted);
  font-weight: 600;
}
.field input, .field select {
  font: inherit; font-size: var(--fs-small);
  height: 26px; padding: 0 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--text);
}
.field input:focus, .field select:focus {
  outline: 0; border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(99, 44, 166, .15);
}
.field input.mono { font-family: var(--mono); }
.field input.num { width: 90px; font-variant-numeric: tabular-nums; }
.form-hint { font-size: var(--fs-micro); color: var(--text-faint); margin-top: 8px; }

/* Mensagens (erro/aviso) */
.msg {
  font-size: var(--fs-small);
  padding: 7px 10px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  margin-bottom: 10px;
}
.msg.error { color: var(--crit); border-color: var(--crit); background: #fdf3f3; }
.msg.warn { color: #8a6d0b; border-color: var(--warn); background: #fdfaf0; }

/* Estado vazio */
.empty {
  text-align: center; color: var(--text-muted);
  padding: 28px 16px; font-size: var(--fs-small);
}

/* ==========================================================================
   PÁGINA DE ALERTAS — form inline por linha, toggle, hints
   ========================================================================== */
.rule-name { font-weight: 600; color: var(--text); }
.rule-hint {
  font-size: var(--fs-micro); color: var(--text-faint);
  white-space: normal; max-width: 520px; margin-top: 2px;
}
tr.rule td { height: auto; padding-top: 9px; padding-bottom: 9px; }
tr.rule.off { opacity: .55; }
.rule-form { display: flex; gap: 12px; align-items: flex-end; }
.cfg { display: flex; align-items: baseline; gap: 5px; }
.unit { font-size: var(--fs-micro); color: var(--text-faint); font-family: var(--mono); white-space: nowrap; }
.save-line { display: flex; align-items: center; gap: 8px; }
.rule-default { font-size: var(--fs-micro); color: var(--text-faint); }
.saved-flash { color: var(--ok); font-size: var(--fs-micro); font-weight: 600; }
.sync-error { color: var(--crit); font-size: var(--fs-micro); margin-top: 2px; }
.table-note {
  font-size: var(--fs-micro); color: var(--text-muted);
  padding: 10px 16px; border-top: 1px solid var(--border);
}
.pad { padding: 10px 16px 0; }
.reset-cell { display: flex; flex-direction: column; align-items: flex-end; gap: 3px; }

/* Toggle */
.toggle { position: relative; display: inline-block; width: 34px; height: 18px; flex-shrink: 0; }
.toggle input { opacity: 0; width: 0; height: 0; }
.toggle .slider {
  position: absolute; inset: 0;
  background: var(--paused);
  border-radius: 999px; cursor: pointer;
  transition: background .12s;
}
.toggle .slider::before {
  content: ""; position: absolute;
  width: 14px; height: 14px; left: 2px; top: 2px;
  background: #fff; border-radius: 50%;
  transition: transform .12s;
}
.toggle input:checked + .slider { background: var(--accent); }
.toggle input:checked + .slider::before { transform: translateX(16px); }
.toggle input:focus-visible + .slider { outline: 2px solid var(--accent); outline-offset: 1px; }

/* Loading (htmx) */
.htmx-indicator { opacity: 0; transition: opacity .12s; }
.htmx-request .htmx-indicator, .htmx-request.htmx-indicator { opacity: 1; }
.spinner {
  display: inline-block; width: 11px; height: 11px;
  border: 2px solid var(--text-faint); border-top-color: transparent;
  border-radius: 50%; animation: spin .7s linear infinite;
  vertical-align: middle;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Login */
.login-wrap {
  grid-column: 1 / -1; grid-row: 1 / -1;
  display: grid; place-items: center; background: var(--bg-subtle);
}
.login-box {
  width: 320px; background: var(--bg);
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: 28px 24px;
}
.login-box .logo {
  width: 32px; height: 32px; border-radius: var(--radius);
  background: var(--accent); color: #fff;
  display: grid; place-items: center; font-weight: 700; margin-bottom: 16px;
}
.login-box h1 { font-size: 15px; font-weight: 600; margin-bottom: 16px; }
.login-box .field { margin-bottom: 12px; }
.login-box button { width: 100%; height: 30px; }

/* Toast de erro inesperado */
#toast {
  position: fixed; bottom: 16px; left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--crit); color: #fff;
  font-size: var(--fs-small); padding: 8px 14px;
  border-radius: var(--radius);
  opacity: 0; pointer-events: none; transition: opacity .15s, transform .15s;
  max-width: 90vw;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

@media (prefers-reduced-motion: reduce) {
  .live-dot, .spinner { animation: none; }
  #toast { transition: opacity .15s; }
}
