:root {
  --bg: #0a0e13;
  --surface: #111821;
  --surface-2: #17202b;
  --border: #223041;
  --text: #e7edf3;
  --muted: #8a99a8;
  --ok: #2ecc71;
  --attention: #f5c518;
  --unstable: #ff8c1a;
  --down: #ff4d4f;
  --emergency: #ff2d55;
  --stopped: #6b7785;
  --starting: #3fa7ff;
  --accent: #3fa7ff;
  --radius: 10px;
  --gap: clamp(10px, 1.1vw, 18px);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-variant-numeric: tabular-nums;
  min-height: 100vh;
}
@media (min-width: 1800px) { body { font-size: 17px; } }   /* TV */
a { color: var(--accent); }
code { background: var(--surface-2); padding: 1px 5px; border-radius: 4px; font-size: .9em; }
[hidden] { display: none !important; }
.muted { color: var(--muted); font-size: .9em; }
h2 { font-size: 1.05rem; margin: 0; letter-spacing: .02em; }
h3 { font-size: .95rem; margin: 18px 0 8px; color: var(--muted); font-weight: 600; }

/* ---------- topo ---------- */
.topbar {
  display: flex; align-items: center; gap: var(--gap); flex-wrap: wrap;
  padding: 10px clamp(16px, 2vw, 28px);
  background: var(--surface); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 5;
}
.brand { display: flex; align-items: center; gap: 10px; font-size: 1.1rem; white-space: nowrap; }
.logo { width: 28px; height: 28px; fill: none; stroke: var(--ok); stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }
.overall {
  flex: 1 1 280px; text-align: center; font-weight: 700; font-size: clamp(1rem, 1.6vw, 1.5rem);
  padding: 8px 16px; border-radius: 999px; border: 1px solid var(--border); letter-spacing: .03em;
}
.overall-OK { background: rgba(46, 204, 113, .14); color: var(--ok); border-color: rgba(46, 204, 113, .5); }
.overall-ATENCAO { background: rgba(245, 197, 24, .14); color: var(--attention); border-color: rgba(245, 197, 24, .5); }
.overall-CRITICO { background: rgba(255, 77, 79, .16); color: var(--down); border-color: rgba(255, 77, 79, .6); animation: pulse 1.6s ease-in-out infinite; }
.overall-unknown { color: var(--muted); }
@keyframes pulse { 50% { box-shadow: 0 0 0 6px rgba(255, 77, 79, .12); } }
.top-right { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.clock { font-size: 1.05rem; font-weight: 600; }
.nav a { color: var(--muted); text-decoration: none; padding: 6px 10px; border-radius: 6px; }
.nav a.active { color: var(--text); background: var(--surface-2); }
.user { color: var(--muted); font-size: .9em; }
.badge { font-size: .72rem; font-weight: 700; padding: 2px 8px; border-radius: 999px; letter-spacing: .04em; }
.badge.sim { background: #6b3fd6; color: #fff; }

.stale {
  margin: 12px clamp(16px, 2vw, 28px) 0; padding: 12px 16px; border-radius: var(--radius);
  background: rgba(245, 197, 24, .12); border: 1px solid rgba(245, 197, 24, .55); color: var(--attention);
  font-weight: 600;
}
.stale.bad { background: rgba(255, 77, 79, .14); border-color: rgba(255, 77, 79, .6); color: var(--down); }

main { padding: var(--gap) clamp(16px, 2vw, 28px) 32px; display: grid; gap: var(--gap); }

/* ---------- KPIs ---------- */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: var(--gap); }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; min-width: 0; }
.kpi-label { color: var(--muted); font-size: .85em; text-transform: uppercase; letter-spacing: .06em; }
.kpi-value { font-size: clamp(1.6rem, 2.6vw, 2.6rem); font-weight: 700; line-height: 1.15; margin-top: 4px; overflow-wrap: anywhere; }
.kpi-value.small { font-size: clamp(1.1rem, 1.7vw, 1.6rem); }
.kpi-sub { color: var(--muted); font-size: .85em; margin-top: 2px; }
.kpi.lvl-ATENCAO { border-color: var(--attention); }
.kpi.lvl-CRITICO { border-color: var(--down); }
.kpi.lvl-EMERGENCIA { border-color: var(--emergency); animation: pulse 1.2s infinite; }

/* ---------- problemas ---------- */
.problems { display: grid; gap: 8px; }
.problem { display: flex; gap: 12px; align-items: baseline; flex-wrap: wrap; padding: 10px 14px; border-radius: var(--radius);
  background: var(--surface); border-left: 5px solid var(--down); }
.problem b { min-width: 0; }

/* ---------- painéis ---------- */
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; min-width: 0; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 10px; flex-wrap: wrap; }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 460px), 1fr)); gap: var(--gap); }
.help { color: var(--muted); margin: 0 0 12px; font-size: .9em; }

/* ---------- PODs ---------- */
.pods { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 270px), 1fr)); gap: var(--gap); }
.pod { background: var(--surface-2); border: 1px solid var(--border); border-left: 6px solid var(--stopped); border-radius: var(--radius);
  padding: 12px 14px; display: grid; gap: 6px; min-width: 0; }
.pod-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.pod-name { font-weight: 700; font-size: 1.05rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pod-meta { color: var(--muted); font-size: .85em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pod-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; font-size: .9em; }
.pod-stats .k { color: var(--muted); font-size: .78em; display: block; text-transform: uppercase; letter-spacing: .05em; }
.pod-foot { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.pod-reason { color: var(--muted); font-size: .82em; min-height: 1.2em; }
.spark { width: 120px; height: 28px; flex: none; }
.spark polyline { fill: none; stroke: var(--accent); stroke-width: 1.6; }
.spark circle { fill: var(--down); }
.tag { font-size: .7rem; font-weight: 700; padding: 2px 7px; border-radius: 999px; background: var(--surface); border: 1px solid var(--border); color: var(--muted); white-space: nowrap; }
.tag.crit { color: var(--attention); border-color: rgba(245, 197, 24, .5); }
.state { font-size: .75rem; font-weight: 800; padding: 3px 9px; border-radius: 999px; letter-spacing: .05em; white-space: nowrap; }

.st-OK { --c: var(--ok); } .st-INSTAVEL { --c: var(--unstable); } .st-FORA { --c: var(--down); }
.st-PARADO { --c: var(--stopped); } .st-INICIANDO { --c: var(--starting); } .st-REMOVIDO { --c: var(--stopped); }
.st-ATENCAO { --c: var(--attention); } .st-CRITICO { --c: var(--down); } .st-EMERGENCIA { --c: var(--emergency); }
.st-SEM_DADOS { --c: var(--down); }
.pod[class*="st-"] { border-left-color: var(--c); }
.state[class*="st-"] { background: color-mix(in srgb, var(--c) 18%, transparent); color: var(--c); border: 1px solid color-mix(in srgb, var(--c) 55%, transparent); }
.problem[class*="st-"] { border-left-color: var(--c); }
.pod.st-FORA, .pod.st-EMERGENCIA { animation: pulse 1.6s infinite; }

/* ---------- gráficos ---------- */
.chart { width: 100%; min-height: 220px; }
.chart .empty, .empty { color: var(--muted); padding: 24px 0; text-align: center; }
.uplot, .uplot * { color: var(--muted); }
.u-legend { font-size: .8rem; }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.seg button { background: transparent; color: var(--muted); border: 0; padding: 5px 10px; cursor: pointer; font: inherit; font-size: .85em; }
.seg button.on { background: var(--surface-2); color: var(--text); }

.avail { display: grid; gap: 8px; }
.av-row { display: grid; grid-template-columns: minmax(90px, 1fr) 2fr 70px; gap: 10px; align-items: center; font-size: .9em; }
.av-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.av-bar { height: 10px; background: var(--surface-2); border-radius: 999px; overflow: hidden; }
.av-fill { height: 100%; background: var(--ok); }
.av-fill.mid { background: var(--attention); } .av-fill.low { background: var(--down); }
.av-pct { text-align: right; font-weight: 600; }

/* ---------- timeline ---------- */
.incident { display: flex; gap: 10px; align-items: center; justify-content: space-between; flex-wrap: wrap;
  border: 1px solid var(--border); border-left: 5px solid var(--c, var(--down)); border-radius: 8px; padding: 8px 12px; margin-bottom: 8px; background: var(--surface-2); }
.timeline { list-style: none; margin: 0; padding: 0; max-height: 440px; overflow: auto; }
.timeline li { display: grid; grid-template-columns: 92px 1fr; gap: 10px; padding: 7px 0; border-bottom: 1px solid var(--border); font-size: .88em; }
.timeline time { color: var(--muted); }
.timeline .alert-line { color: var(--muted); }
.ok-txt { color: var(--ok); } .bad-txt { color: var(--down); } .warn-txt { color: var(--attention); }

/* ---------- formulários/tabelas ---------- */
.btn { background: var(--accent); color: #04121f; border: 0; border-radius: 8px; padding: 8px 14px; font: inherit; font-weight: 700; cursor: pointer; }
.btn:disabled { opacity: .55; cursor: progress; }
.btn.ghost { background: transparent; color: var(--text); border: 1px solid var(--border); font-weight: 600; }
.btn.small { padding: 5px 10px; font-size: .85em; }
.btn.warn { background: var(--attention); }
input[type=text], input[type=url], input[type=number], input[type=password], select {
  background: var(--bg); color: var(--text); border: 1px solid var(--border); border-radius: 7px; padding: 7px 9px; font: inherit; width: 100%; min-width: 0;
}
input:focus, select:focus, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
input[type=checkbox] { width: 18px; height: 18px; accent-color: var(--accent); }
.table-wrap { overflow-x: auto; }
.tbl { width: 100%; border-collapse: collapse; font-size: .9em; }
.tbl th, .tbl td { text-align: left; padding: 8px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.tbl th { color: var(--muted); font-weight: 600; font-size: .85em; text-transform: uppercase; letter-spacing: .04em; white-space: nowrap; }
.tbl tr.inactive td { opacity: .45; }
.tbl td.c { text-align: center; }
.tbl .w-url { min-width: 260px; } .tbl .w-num { width: 110px; } .tbl .w-alias { min-width: 140px; }
.form { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 10px 14px; align-items: end; }
.form label { display: grid; gap: 4px; color: var(--muted); font-size: .85em; }
.form .full { grid-column: 1 / -1; }
.matrix { width: 100%; border-collapse: collapse; font-size: .9em; }
.matrix th, .matrix td { padding: 6px; border-bottom: 1px solid var(--border); text-align: center; }
.matrix th:first-child, .matrix td:first-child { text-align: left; }
.channels { display: grid; gap: 8px; }
.channel { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 8px 12px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface-2); flex-wrap: wrap; }

/* ---------- toast ---------- */
.toast { position: fixed; right: 16px; bottom: 16px; max-width: min(420px, calc(100vw - 32px)); background: var(--surface-2); border: 1px solid var(--border);
  border-left: 5px solid var(--ok); border-radius: 8px; padding: 12px 16px; z-index: 20; box-shadow: 0 8px 30px rgba(0,0,0,.4); }
.toast.err { border-left-color: var(--down); }

@media (max-width: 640px) {
  .topbar { gap: 8px; }
  .overall { order: 3; flex-basis: 100%; }
  .top-right { width: 100%; justify-content: space-between; }
  .user { display: none; }
  .timeline li { grid-template-columns: 70px 1fr; }
  .pod-stats { grid-template-columns: repeat(2, 1fr); }
}

/* ---------- login ---------- */
.login-page { display: grid; place-items: center; padding: 16px; }
.login-box { width: min(420px, 100%); background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 28px; display: grid; gap: 14px; }
.login-box .brand { font-size: 1.3rem; }
.login-form { grid-template-columns: 1fr; }
.login-form .btn { width: 100%; padding: 11px; }
.login-error { color: var(--down); background: rgba(255, 77, 79, .1); border: 1px solid rgba(255, 77, 79, .45); border-radius: 8px; padding: 10px 12px; }
.small-print { font-size: .82em; margin: 0; }

/* ---------- campos com unidade ---------- */
.adorn { display: flex; align-items: stretch; border: 1px solid var(--border); border-radius: 7px; background: var(--bg); overflow: hidden; }
.adorn:focus-within { outline: 2px solid var(--accent); outline-offset: 1px; }
.adorn input { border: 0; border-radius: 0; text-align: right; outline: none; }
.adorn-pre, .adorn-suf { display: grid; place-items: center; padding: 0 10px; color: var(--muted); background: var(--surface-2); font-size: .9em; white-space: nowrap; }
input.invalid, .adorn:has(input.invalid) { border-color: var(--down) !important; }
