:root {
  --font: ui-monospace, "SF Mono", Menlo, Consolas, "DejaVu Sans Mono", monospace;
  --fs: 12px;
}
: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);
  --s1: #2a78d6;
  --s2: #eb6834;
  --s3: #1baf7a;
  --good: #0ca30c;
  --warning: #fab219;
  --serious: #ec835a;
  --critical: #d03b3b;
  --bar-track: #f0efec;
  --ok-ink: #007a00;
  --g-blue: #2a78d6;
  --g-orange: #eb6834;
  --g-aqua: #1baf7a;
  --g-yellow: #eda100;
  --g-magenta: #e87ba4;
  --g-green: #008300;
  --g-violet: #6250d6;
  --g-red: #e34948;
  --heat-ok-bg: #d7f0d7;
  --heat-ok-ink: #0d5c0d;
  --heat-warn-bg: #fde7a8;
  --heat-warn-ink: #6e4300;
  --heat-crit-bg: #f6c2c2;
  --heat-crit-ink: #8a1414;
  --warn-ink: #a36200;
  --crit-ink: #c62828;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --page: #0d0d0d;
    --surface: #1a1a19;
    --ink: #f0efec;
    --ink-2: #c3c2b7;
    --grid: #2c2c2a;
    --axis: #383835;
    --border: rgba(255, 255, 255, 0.10);
    --s1: #3987e5;
    --s2: #d95926;
    --s3: #199e70;
    --bar-track: #2c2c2a;
    --ok-ink: #3dbf3d;
    --g-blue: #3987e5;
    --g-orange: #d95926;
    --g-aqua: #199e70;
    --g-yellow: #c98500;
    --g-magenta: #d55181;
    --g-green: #008300;
    --g-violet: #9085e9;
    --g-red: #e66767;
    --heat-ok-bg: #16331a;
    --heat-ok-ink: #8fe39a;
    --heat-warn-bg: #4a3a0c;
    --heat-warn-ink: #ffd86b;
    --heat-crit-bg: #521c1c;
    --heat-crit-ink: #ff9b9b;
    --warn-ink: #f5b324;
    --crit-ink: #f26b6b;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0d0d0d;
  --surface: #1a1a19;
  --ink: #f0efec;
  --ink-2: #c3c2b7;
  --grid: #2c2c2a;
  --axis: #383835;
  --border: rgba(255, 255, 255, 0.10);
  --s1: #3987e5;
  --s2: #d95926;
  --s3: #199e70;
  --bar-track: #2c2c2a;
  --ok-ink: #3dbf3d;
  --g-blue: #3987e5;
  --g-orange: #d95926;
  --g-aqua: #199e70;
  --g-yellow: #c98500;
  --g-magenta: #d55181;
  --g-green: #008300;
  --g-violet: #9085e9;
  --g-red: #e66767;
  --heat-ok-bg: #16331a;
  --heat-ok-ink: #8fe39a;
  --heat-warn-bg: #4a3a0c;
  --heat-warn-ink: #ffd86b;
  --heat-crit-bg: #521c1c;
  --heat-crit-ink: #ff9b9b;
  --warn-ink: #f5b324;
  --crit-ink: #f26b6b;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--page);
  color: var(--ink);
  font: var(--fs)/1.45 var(--font);
}
a { color: inherit; }
.muted { color: var(--muted); }
.num { font-variant-numeric: tabular-nums; }
button {
  font: inherit;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 12px;
  cursor: pointer;
}
button:hover { border-color: var(--muted); }
button.link { border: 0; background: none; padding: 0; color: var(--ink-2); text-decoration: underline; }
input, select {
  font: inherit;
  color: var(--ink);
  background: var(--page);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 10px;
  width: 100%;
}

.top {
  display: flex;
  align-items: center;
  gap: 6px 16px;
  padding: 6px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}
.brand { font-weight: 600; text-decoration: none; }
.top nav { margin-left: auto; display: flex; gap: 16px; align-items: center; }
.top nav a { color: var(--ink-2); }
.top form { margin: 0; }
html, body { height: 100%; }
body { display: flex; flex-direction: column; }
.top { flex: none; }
main { padding: 12px 16px; flex: 1; min-height: 0; width: 100%; }

.overview { display: flex; flex-direction: column; min-height: 100%; }
.overview .grid { flex: 1; grid-auto-rows: minmax(170px, 1fr); }
.overview .card { display: flex; flex-direction: column; }
.card .spark { flex: 1; min-height: 36px; height: auto; }
.tile { flex: 1 1 auto; }

.detail { display: flex; flex-direction: column; gap: 12px; }
.side { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); align-items: start; }
td.name { max-width: 0; width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
table.kv th { color: var(--muted); font-weight: 400; font-size: calc(var(--fs) * 0.929); padding: 3px 12px 3px 0; white-space: nowrap; }
table.kv td { border: 0; padding: 3px 0; max-width: none; white-space: normal; word-break: break-word; }
.panel { display: flex; flex-direction: column; }

@media (min-width: 1100px) and (min-height: 620px) {
  main { overflow: hidden; }
  .overview { height: 100%; min-height: 0; }
  .overview .panel.heat { flex: 1; min-height: 0; }
  .detail {
    display: grid;
    height: 100%;
    grid-template-columns: minmax(320px, 26%) 1fr;
    grid-template-rows: auto 1fr;
  }
  .detail .detail-head { grid-column: 1 / -1; margin: 0; }
  .side { display: flex; flex-direction: column; align-items: stretch; min-height: 0; }
  .side .panel { min-height: 0; overflow: auto; flex: none; }
  .side .panel.grow { flex: 1 1 0; }
  .detail .charts {
    min-height: 0;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    grid-template-rows: repeat(2, minmax(0, 1fr));
  }
  .detail .charts .panel { min-height: 0; }
  .detail .charts .chart { flex: 1; min-height: 0; height: auto; }
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 12px;
}
.strip {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
  align-items: stretch;
}
.tile {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 12px;
  min-width: 120px;
}
.tile .k { font-size: calc(var(--fs) * 0.786); color: var(--muted); }
.tile .v { font-size: calc(var(--fs) * 1); font-weight: 500; white-space: nowrap; }
.tile .v a { color: var(--ink-2); font-weight: 400; }
.layout { display: flex; gap: 4px; margin-left: auto; align-self: center; }
.layout button[aria-pressed="true"] { background: var(--ink); color: var(--surface); border-color: var(--ink); }
.heat { overflow: auto; }
table.heatmap { border-collapse: separate; border-spacing: 3px; width: 100%; height: 100%; }
table.heatmap th { text-align: center; font-size: calc(var(--fs) * 0.857); color: var(--muted); font-weight: 500; padding: 2px 4px 6px; }
table.heatmap th:first-child { text-align: left; }
table.heatmap td { border: 0; }
td.hn { white-space: nowrap; padding: 0 12px 0 6px; font-weight: 600; font-size: calc(var(--fs) * 1.071); }
td.hn a { text-decoration: none; }
td.hn a:hover { text-decoration: underline; }
td.hc { text-align: center; font-weight: 600; font-size: calc(var(--fs) * 1.071); font-variant-numeric: tabular-nums; border-radius: 5px; padding: 8px 6px; white-space: nowrap; cursor: default; }
td.hc:hover { outline: 2px solid var(--ink-2); outline-offset: -2px; }
.hc-ok { background: var(--heat-ok-bg); color: var(--heat-ok-ink); }
.hc-warn { background: var(--heat-warn-bg); color: var(--heat-warn-ink); }
.hc-crit { background: var(--heat-crit-bg); color: var(--heat-crit-ink); }
.hc-net { background: rgba(42, 120, 214, var(--heat)); color: var(--ink); }
.hc-off { background: var(--bar-track); color: var(--muted); font-weight: 400; }
.card {
  display: block;
  text-decoration: none;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px;
}
.card:hover { border-color: var(--muted); }
.card.down { opacity: 0.75; }
.card-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.card-head h2 { font-size: calc(var(--fs) * 1.071); margin: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 4px 8px;
  margin: 12px 0 8px;
}
.stat .k { font-size: calc(var(--fs) * 0.786); color: var(--muted); }
.stat .v { font-size: calc(var(--fs) * 1.143); font-weight: 500; }
.spark { display: block; width: 100%; height: 36px; }
.card-foot { display: flex; justify-content: space-between; font-size: calc(var(--fs) * 0.857); color: var(--muted); margin-top: 6px; }

.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: calc(var(--fs) * 0.857);
  color: var(--ink-2);
  white-space: nowrap;
}
.badge::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--dot, var(--muted));
}
.badge.good { --dot: var(--good); }
.badge.warning { --dot: var(--warning); }
.badge.serious { --dot: var(--serious); }
.badge.critical { --dot: var(--critical); }

.detail-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 8px 16px; margin-bottom: 4px; }
.detail-head h1 { font-size: calc(var(--fs) * 1.429); margin: 0; }
.ranges { display: flex; gap: 4px; margin-left: auto; }
.ranges button[aria-pressed="true"] { background: var(--ink); color: var(--surface); border-color: var(--ink); }

.charts {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(420px, 1fr));
  gap: 12px;
}
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px;
  min-width: 0;
}
.panel h3 { margin: 0 0 2px; font-size: calc(var(--fs) * 0.929); font-weight: 600; }
.panel .now { color: var(--ink-2); font-size: calc(var(--fs) * 0.857); margin-bottom: 8px; min-height: 17px; }
.legend { display: flex; gap: 12px; font-size: calc(var(--fs) * 0.857); color: var(--ink-2); }
.legend i { display: inline-block; width: 10px; height: 2px; vertical-align: middle; margin-right: 4px; }
.chart { display: block; width: 100%; height: 160px; touch-action: pan-y; }
.chart text { fill: var(--muted); font-size: calc(var(--fs) * 0.714); font-variant-numeric: tabular-nums; }
.chart .gridline { stroke: var(--grid); stroke-width: 1; }
.chart .baseline { stroke: var(--axis); stroke-width: 1; }
.chart .cross { stroke: var(--muted); stroke-width: 1; }

table { width: 100%; border-collapse: collapse; font-size: calc(var(--fs) * 0.929); }
th { text-align: left; font-weight: 500; color: var(--muted); font-size: calc(var(--fs) * 0.857); padding: 4px 6px; }
td { padding: 5px 6px; border-top: 1px solid var(--border); }
td:first-child { max-width: 260px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
td.r, th.r { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.bar { height: 6px; border-radius: 3px; background: var(--bar-track); overflow: hidden; min-width: 60px; }
.bar span { display: block; height: 100%; border-radius: 3px; background: var(--good); }
.bar.lv-warn span { background: var(--warning); }
.bar.lv-crit span { background: var(--critical); }
.lv-ok { color: var(--ok-ink); }
.lv-warn { color: var(--warn-ink); }
.lv-crit { color: var(--crit-ink); font-weight: 600; }
.bar.lv-ok, .bar.lv-warn, .bar.lv-crit { color: inherit; }

.tip {
  position: fixed;
  pointer-events: none;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 8px;
  font-size: calc(var(--fs) * 0.857);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
  z-index: 10;
  white-space: nowrap;
}
.tip b { font-weight: 500; }
.tip .t { color: var(--muted); margin-bottom: 2px; }

.empty { color: var(--ink-2); padding: 32px 0; text-align: center; }
.danger { color: var(--critical); }
.settings { max-width: 420px; display: grid; gap: 10px; }
.settings h2 { font-size: calc(var(--fs) * 1.143); margin: 8px 0 0; }
.error { color: var(--critical); margin: 0; }
.ok { color: var(--ink-2); margin: 0; }

body.login { display: grid; place-items: center; min-height: 100vh; padding: 16px; }
.login-box {
  width: 100%;
  max-width: 320px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 24px;
  display: grid;
  gap: 10px;
}
.login-box h1 { font-size: calc(var(--fs) * 1.286); margin: 0 0 8px; }

@media (max-width: 520px) {
  .charts { grid-template-columns: 1fr; }
  .stats { grid-template-columns: repeat(2, 1fr); }
  td:first-child { max-width: 120px; }
  td, th { padding-left: 4px; padding-right: 4px; }
  .top { gap: 10px; }
}
input[type="range"] { padding: 0; border: 0; background: none; }

.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 8px; margin-bottom: 6px; font-size: calc(var(--fs) * 0.857); }
.seg-btns { display: flex; flex-wrap: wrap; gap: 0; }
.seg-btns button { padding: 2px 8px; border-radius: 0; margin-left: -1px; font-size: inherit; }
.seg-btns button:first-child { border-radius: 5px 0 0 5px; margin-left: 0; }
.seg-btns button:last-child { border-radius: 0 5px 5px 0; }
.toolbar .layout { margin-left: auto; }
#fleet-status { display: flex; flex-wrap: wrap; gap: 2px 14px; color: var(--ink); font-size: calc(var(--fs) * 0.929); }
.hs { white-space: nowrap; cursor: default; }
.hs .k { color: var(--muted); }
.hs a { color: var(--ink-2); }
.heat.panel { padding: 4px 6px; }
table.heatmap th { padding-top: 4px; padding-bottom: 4px; }
.seg-btns button[aria-pressed="true"] { background: var(--ink); color: var(--surface); border-color: var(--ink); }
.tagchip { display: inline-block; margin-left: 6px; padding: 0 6px; border: 1px solid var(--border); border-radius: 9px; font-size: calc(var(--fs) * 0.786); font-weight: 400; color: var(--ink-2); vertical-align: 1px; }
.detail-head .tagchip { margin-left: 0; }
table.heatmap th.sortable { cursor: pointer; user-select: none; white-space: nowrap; }
table.heatmap th.sortable:hover { color: var(--ink); }
table.heatmap th.sorted { color: var(--ink); }
table.heatmap tr.colored td.hn { box-shadow: inset 5px 0 0 var(--gc); padding-left: 14px; border-radius: 4px; }
table.heatmap tr.grp td { padding: 10px 6px 2px; font-weight: 600; border: 0; }
table.heatmap tr[data-host] { cursor: context-menu; }
.gdot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 6px; background: var(--bar-track); border: 1px solid var(--border); vertical-align: -1px; }
.grp-h { grid-column: 1 / -1; font-weight: 600; padding: 6px 2px 0; }
.overview .card.colored { border-top: 4px solid var(--gc); }
.card-tags { margin: 4px 0 0 -6px; }

.ctx {
  position: fixed;
  z-index: 20;
  width: 260px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.2);
  padding: 10px;
  display: grid;
  gap: 6px;
}
.ctx[hidden] { display: none; }
.ctx-h { font-weight: 600; }
.ctx-k { font-size: calc(var(--fs) * 0.786); color: var(--muted); margin-top: 4px; }
.sw { display: flex; gap: 5px; flex-wrap: wrap; }
.swatch { width: 22px; height: 22px; padding: 0; border-radius: 50%; border: 2px solid transparent; outline: 1px solid var(--border); }
.swatch.on { border-color: var(--surface); outline: 2px solid var(--ink); }
.swatch.none { background: linear-gradient(135deg, transparent 45%, var(--muted) 45% 55%, transparent 55%); }
.ctx-tags { display: flex; flex-wrap: wrap; gap: 4px; }
.chip { padding: 2px 8px; border-radius: 10px; font-size: calc(var(--fs) * 0.857); }
.chip.on { background: var(--ink); color: var(--surface); border-color: var(--ink); }
.ctx-in { padding: 5px 8px; }
.ctx-open { font-size: calc(var(--fs) * 0.857); color: var(--ink-2); }
