/* ---------- Tokens ---------- */
:root {
  color-scheme: light;
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #898781;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);
  --wash: rgba(11, 11, 11, 0.05);
  --accent: #2a78d6;
  --s1: #2a78d6;
  --s2: #eb6834;
  --good: #0ca30c;
  --warning: #fab219;
  --critical: #d03b3b;
  --shadow: 0 4px 18px rgba(0, 0, 0, 0.10);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --page: #0d0d0d;
    --surface: #1a1a19;
    --ink: #ffffff;
    --ink-2: #c3c2b7;
    --grid: #2c2c2a;
    --axis: #383835;
    --border: rgba(255, 255, 255, 0.10);
    --wash: rgba(255, 255, 255, 0.06);
    --accent: #3987e5;
    --s1: #3987e5;
    --s2: #d95926;
    --shadow: 0 4px 18px rgba(0, 0, 0, 0.5);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0d0d0d;
  --surface: #1a1a19;
  --ink: #ffffff;
  --ink-2: #c3c2b7;
  --grid: #2c2c2a;
  --axis: #383835;
  --border: rgba(255, 255, 255, 0.10);
  --wash: rgba(255, 255, 255, 0.06);
  --accent: #3987e5;
  --s1: #3987e5;
  --s2: #d95926;
  --shadow: 0 4px 18px rgba(0, 0, 0, 0.5);
}

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--page);
  color: var(--ink);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3, p, dl, dd { margin: 0; }
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }
.sprite { position: absolute; width: 0; height: 0; overflow: hidden; }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.muted { color: var(--ink-2); }
.small { font-size: 13px; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- Login ---------- */
.login {
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 16px;
}
.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border-radius: 16px;
  box-shadow: 0 0 0 1px var(--border);
  padding: 28px 24px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.login-logo { border-radius: 14px; margin-bottom: 4px; }
.login-card h1 { font-size: 22px; font-weight: 600; }
.login-card label { font-size: 13px; color: var(--ink-2); margin-top: 6px; }
.login-card input[type="password"] {
  width: 100%;
  padding: 11px 12px;
  border-radius: 10px;
  border: 1px solid var(--axis);
  background: var(--page);
}
.login-card input[type="password"]:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: transparent; }
.login-card .check { display: flex; align-items: center; gap: 8px; color: var(--ink); font-size: 14px; }
.check input { width: 16px; height: 16px; accent-color: var(--accent); }
.error { color: var(--critical); font-size: 14px; }
.btn-primary {
  margin-top: 8px;
  padding: 11px 16px;
  border: 0;
  border-radius: 10px;
  background: var(--accent);
  color: #fff;
  font-weight: 600;
}
.btn-primary:disabled { opacity: 0.6; cursor: default; }

/* ---------- Painel ---------- */
.dash {
  max-width: 1320px;
  margin: 0 auto;
  padding: max(16px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) 32px max(16px, env(safe-area-inset-left));
}
.top {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px 16px;
  margin-bottom: 16px;
}
.host { min-width: 0; }
.host h1 {
  font-size: 22px;
  font-weight: 600;
  overflow-wrap: anywhere;
}
.host p { font-size: 13px; overflow-wrap: anywhere; }
.top-actions { display: flex; align-items: center; gap: 4px; }

.status {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  margin-right: 4px;
  border-radius: 999px;
  box-shadow: 0 0 0 1px var(--border);
  background: var(--surface);
  font-size: 13px;
  color: var(--ink-2);
  white-space: nowrap;
}
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.status[data-state="live"] .status-dot { background: var(--good); animation: pulse 2s ease-in-out infinite; }
.status[data-state="offline"] .status-dot { background: var(--critical); }
@keyframes pulse { 50% { opacity: 0.35; } }
@media (prefers-reduced-motion: reduce) { .status-dot { animation: none !important; } }

.icon-btn {
  width: 40px;
  height: 40px;
  display: inline-grid;
  place-items: center;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--ink-2);
}
.icon-btn:hover { background: var(--wash); color: var(--ink); }

/* Filtro de período: uma linha acima de tudo que ele afeta */
.filters {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  margin-bottom: 16px;
}
.filters-label { font-size: 13px; color: var(--ink-2); margin-right: 4px; }
.seg {
  padding: 6px 12px;
  border-radius: 999px;
  border: 0;
  background: transparent;
  color: var(--ink-2);
  font-size: 14px;
}
.seg:hover { background: var(--wash); }
.seg[aria-pressed="true"] {
  background: var(--surface);
  color: var(--ink);
  font-weight: 600;
  box-shadow: 0 0 0 1px var(--border);
}
.updated { margin-left: auto; font-size: 13px; }

.grid {
  display: grid;
  gap: 16px;
  grid-template-columns: minmax(0, 1fr);
}
@media (min-width: 760px) { .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (min-width: 1160px) { .grid { grid-template-columns: repeat(3, minmax(0, 1fr)); } }

.card {
  background: var(--surface);
  border-radius: 16px;
  box-shadow: 0 0 0 1px var(--border);
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-width: 0;
}
.card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.card-head > div { min-width: 0; }
.card h2 { font-size: 16px; font-weight: 600; }
.card-head p { overflow-wrap: anywhere; }
.section-title { font-size: 13px; font-weight: 600; color: var(--ink-2); margin-top: 2px; }

.figure { display: flex; align-items: baseline; flex-wrap: wrap; gap: 4px 10px; }
.figure .value { font-size: 44px; font-weight: 600; line-height: 1; letter-spacing: -0.02em; }
.figure .muted { font-size: 14px; }

/* Selo de status: ícone colorido + texto, nunca só a cor */
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px 4px 8px;
  border-radius: 999px;
  box-shadow: 0 0 0 1px var(--border);
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
}
.chip:empty { display: none; }
.chip[data-level="ok"] svg { color: var(--good); }
.chip[data-level="warn"] svg { color: var(--warning); }
.chip[data-level="crit"] svg { color: var(--critical); }

.stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--grid);
}
.stats dt { font-size: 12px; color: var(--ink-2); }
.stats dd { font-size: 15px; font-weight: 600; margin-top: 2px; }

/* Medidor: o preenchimento carrega a severidade, o trilho é um tom claro da mesma cor */
.meter {
  --fill: var(--accent);
  position: relative;
  height: 8px;
  border-radius: 4px;
  background: var(--grid);
  background: color-mix(in srgb, var(--fill) 20%, var(--surface));
  overflow: hidden;
}
.meter[data-level="warn"] { --fill: var(--warning); }
.meter[data-level="crit"] { --fill: var(--critical); }
.meter-fill {
  height: 100%;
  width: 0;
  border-radius: 4px;
  background: var(--fill);
  transition: width 0.4s ease;
}
@media (prefers-reduced-motion: reduce) { .meter-fill { transition: none; } }

.cores {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(104px, 1fr));
  gap: 10px 14px;
}
.core .meter { height: 6px; }
.row-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  margin-bottom: 4px;
}
.row-head .name { color: var(--ink-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-head .val { font-weight: 600; display: inline-flex; align-items: center; gap: 4px; font-variant-numeric: tabular-nums; }
.row-head .val svg[data-level="warn"] { color: var(--warning); }
.row-head .val svg[data-level="crit"] { color: var(--critical); }

.fs-list { display: flex; flex-direction: column; gap: 14px; }
.fs .row-head { font-size: 14px; }
.fs .row-head .name { color: var(--ink); font-weight: 500; }
.fs-foot { font-size: 12px; color: var(--ink-2); margin-top: 4px; overflow-wrap: anywhere; }
.swap-empty { font-size: 14px; color: var(--ink-2); }

/* ---------- Gráficos ---------- */
.chart {
  position: relative;
  height: 170px;
  touch-action: pan-y;
  border-radius: 8px;
  transition: opacity 0.3s ease;
}
.chart.stale { opacity: 0.45; }
.chart svg.plot { display: block; width: 100%; height: 100%; overflow: visible; }
.chart .gridline { stroke: var(--grid); stroke-width: 1; shape-rendering: crispEdges; }
.chart .baseline { stroke: var(--axis); stroke-width: 1; shape-rendering: crispEdges; }
.chart .tick { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart .line { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .area { stroke: none; opacity: 0.1; }
.chart .s1 { stroke: var(--s1); }
.chart .s2 { stroke: var(--s2); }
.chart .area.s1, .chart .dot.s1 { fill: var(--s1); }
.chart .area.s2, .chart .dot.s2 { fill: var(--s2); }
.chart .dot { stroke: var(--surface); stroke-width: 2; }
.chart .crosshair { stroke: var(--ink-2); stroke-width: 1; shape-rendering: crispEdges; }
.chart .empty { fill: var(--ink-2); font-size: 13px; }

.tooltip {
  position: absolute;
  top: 0;
  left: 0;
  z-index: 3;
  pointer-events: none;
  background: var(--surface);
  border-radius: 8px;
  box-shadow: 0 0 0 1px var(--border), var(--shadow);
  padding: 6px 10px;
  font-size: 12px;
  white-space: nowrap;
}
.tooltip .t-time { color: var(--ink-2); margin-bottom: 2px; }
.tooltip .t-row { display: flex; align-items: center; gap: 6px; }
.tooltip .t-row strong { font-size: 13px; font-weight: 600; }
.tooltip .t-row span { color: var(--ink-2); }

.key { display: inline-block; width: 14px; height: 2px; border-radius: 1px; background: var(--s1); }
.key.s2, .key-write { background: var(--s2); }
.key-read { background: var(--s1); }
.legend { display: flex; flex-wrap: wrap; gap: 6px 18px; font-size: 13px; }
.legend-item { display: inline-flex; align-items: center; gap: 6px; }
.legend-label { color: var(--ink-2); }
.legend strong { font-weight: 600; }

.table-view summary {
  font-size: 13px;
  color: var(--ink-2);
  cursor: pointer;
  width: fit-content;
  padding: 2px 0;
}
.table-view summary:hover { color: var(--ink); }
.table-view table {
  width: 100%;
  margin-top: 8px;
  border-collapse: collapse;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}
.table-view th, .table-view td { padding: 4px 6px; text-align: right; border-bottom: 1px solid var(--grid); }
.table-view th:first-child, .table-view td:first-child { text-align: left; }
.table-view thead th { color: var(--ink-2); font-weight: 600; }
.table-view tbody.sum th { color: var(--ink-2); font-weight: 500; }

/* ---------- Alertas ---------- */
.banner {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  margin-bottom: 16px;
  border-radius: 12px;
  background: var(--surface);
  box-shadow: 0 0 0 1px var(--critical);
  font-size: 14px;
}
.banner svg { color: var(--critical); flex: none; }
.banner span { flex: 1; min-width: 0; }
.banner-link { color: var(--accent); font-weight: 600; white-space: nowrap; text-decoration: none; }
.banner-link:hover { text-decoration: underline; }

.alerts-card { margin-top: 16px; }
.btn-ghost {
  padding: 8px 14px;
  border-radius: 10px;
  border: 0;
  background: transparent;
  box-shadow: 0 0 0 1px var(--border);
  color: var(--ink);
  font-size: 14px;
  white-space: nowrap;
}
.btn-ghost:hover { background: var(--wash); }
.btn-ghost:disabled, .push-actions .btn-primary:disabled { opacity: 0.6; cursor: default; }

.push-box {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px 16px;
  padding: 14px;
  border-radius: 12px;
  background: var(--page);
}
.push-info { min-width: 0; flex: 1 1 280px; }
.push-info strong { font-size: 14px; font-weight: 600; }
.push-msg { margin-top: 4px; color: var(--ink); }
.push-msg:empty { display: none; }
.push-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.push-actions .btn-primary { margin-top: 0; padding: 8px 14px; font-size: 14px; }

.incidents { display: flex; flex-direction: column; }
.incidents > p { font-size: 14px; color: var(--ink-2); }
.incident { border-top: 1px solid var(--grid); }
.incident:last-child { border-bottom: 1px solid var(--grid); }
.incident summary {
  display: grid;
  grid-template-columns: 9.5em minmax(0, 1fr) auto auto auto;
  align-items: center;
  gap: 4px 16px;
  padding: 10px 2px;
  cursor: pointer;
  font-size: 14px;
  list-style: none;
}
.incident summary::-webkit-details-marker { display: none; }
.incident summary:hover { background: var(--wash); }
.inc-status { display: inline-flex; align-items: center; gap: 6px; font-weight: 500; white-space: nowrap; }
.inc-status[data-state="open"] svg { color: var(--critical); }
.inc-status[data-state="closed"] svg { color: var(--good); }
.inc-status[data-state="interrupted"] svg { color: var(--warning); }
.inc-what { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.inc-when, .inc-dur { color: var(--ink-2); white-space: nowrap; }
.inc-peak { white-space: nowrap; font-weight: 500; }
.inc-body { padding: 4px 2px 16px; display: flex; flex-direction: column; gap: 8px; font-size: 13px; }
.inc-body h4 { margin: 6px 0 0; font-size: 12px; font-weight: 600; color: var(--ink-2); }
.inc-body .scroll { overflow-x: auto; }
.inc-body table { width: 100%; border-collapse: collapse; font-size: 12px; }
.inc-body th, .inc-body td { padding: 4px 6px; text-align: right; border-bottom: 1px solid var(--grid); white-space: nowrap; }
.inc-body th:first-child, .inc-body td:first-child,
.inc-body th.text, .inc-body td.text { text-align: left; }
.inc-body thead th { color: var(--ink-2); font-weight: 600; }
.inc-body td { font-variant-numeric: tabular-nums; }

@media (max-width: 620px) {
  .incident summary { grid-template-columns: minmax(0, 1fr) auto; }
  .inc-what { grid-column: 1; grid-row: 2; }
  .inc-when { grid-column: 2; grid-row: 1; text-align: right; }
  .inc-peak { grid-column: 2; grid-row: 2; text-align: right; }
  .inc-dur { grid-column: 1 / -1; grid-row: 3; font-size: 13px; }
}

.dialog {
  width: min(420px, calc(100vw - 32px));
  border: 0;
  border-radius: 16px;
  padding: 24px;
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 0 0 1px var(--border), var(--shadow);
}
.dialog::backdrop { background: rgba(0, 0, 0, 0.45); }
.dialog form { display: flex; flex-direction: column; gap: 12px; }
.dialog h2 { font-size: 18px; font-weight: 600; }
.steps { margin: 0; padding-left: 20px; display: flex; flex-direction: column; gap: 6px; }

@media (max-width: 420px) {
  .figure .value { font-size: 40px; }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .stats > div:first-child { grid-column: 1 / -1; }
  .status { padding: 6px 10px; }
}

@media (forced-colors: active) {
  .meter { border: 1px solid CanvasText; }
  .meter-fill { background: Highlight; }
  .chart .line { stroke: CanvasText; }
}
