* {
  box-sizing: border-box;
}
html,
body {
  margin: 0;
  height: 100%;
}
body {
  background: var(--bg);
  color: var(--ink);
  font: var(--fs)/1.5 var(--font);
}
h1 {
  font-size: var(--fs-lg);
  margin: 0 0 var(--sp-3);
}
a {
  color: var(--accent);
  text-decoration: none;
}
button {
  font: inherit;
}

/* shell layout: sidebar >=1024px, bottom tab bar below */
#app {
  display: grid;
  min-height: 100vh;
  grid-template-columns: var(--sidebar-w) 1fr;
  grid-template-areas: "nav bars" "nav view";
  grid-template-rows: auto 1fr;
}
#nav {
  grid-area: nav;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: var(--sp-3);
  gap: var(--sp-1);
}
/* #nav .brand / #nav .navfoot moved up here, BEFORE the mobile media query
   below: both rules share the media query's #nav .brand/.navfoot selector
   specificity (1 ID + 1 class), so with equal specificity source order is the
   tiebreak -- these base rules must precede the media query in the cascade,
   or the media query's `display: none` loses to them on mobile viewports and
   the nav footer re-appears, overflowing the 390px bottom tab bar. */
#nav .brand {
  font-weight: 650;
  padding: var(--sp-2);
}
#nav .navfoot {
  margin-top: auto;
  border-top: 1px solid var(--border);
  padding-top: var(--sp-2);
  font-size: var(--fs-sm);
  color: var(--mut);
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
}
#shellbars {
  grid-area: bars;
}
#view {
  grid-area: view;
  padding: var(--sp-4);
  max-width: 1400px;
  width: 100%;
  outline: none;
}
@media (max-width: 1023px) {
  #app {
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas: "bars" "view" "nav";
    grid-template-rows: auto 1fr auto;
  }
  #nav {
    flex-direction: row;
    border-right: 0;
    border-top: 1px solid var(--border);
    position: sticky;
    bottom: 0;
    min-height: var(--tabbar-h);
    justify-content: space-around;
    z-index: 5;
  }
  #nav .brand,
  #nav .navfoot {
    display: none;
  }
  #view {
    padding: var(--sp-3);
  }
}
#nav a.navlink {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  padding: var(--sp-2) var(--sp-3);
  border-radius: var(--rad);
  color: var(--ink);
  min-height: var(--touch);
}
#nav a.navlink[aria-current="page"] {
  background: var(--accent);
  color: var(--accent-ink);
}
#nav .navbadge {
  margin-left: auto;
  font-size: var(--fs-sm);
  background: var(--bad-bg);
  color: var(--bad);
  border-radius: 9px;
  padding: 0 7px;
}
/* Mobile bottom tab bar: icon-over-label, equal-width tabs that can't overflow.
   Deliberately a SEPARATE media block placed AFTER the #nav a.navlink / #nav
   .navbadge base rules directly above -- not merged into the earlier
   `@media (max-width: 1023px)` block near the top of this file, which sits
   BEFORE those base rules in source order. Same selector => same specificity,
   so a media-query override only wins the cascade if it comes LATER in source
   than the rule it's meant to override (this is exactly the #nav .navfoot bug
   fixed earlier in this file, avoided here by placement). flex: 1 1 0 +
   min-width: 0 is the key invariant: it forces the 5 tabs to divide the row
   equally and shrink below their content size instead of overflowing it,
   regardless of label length or viewport width. */
@media (max-width: 1023px) {
  #nav a.navlink {
    position: relative;
    flex: 1 1 0;
    min-width: 0;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    padding: var(--sp-1);
    text-align: center;
    font-size: 10px;
    line-height: 1.1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  #nav .navbadge {
    position: absolute;
    top: 2px;
    right: 8px;
    margin-left: 0;
  }
}

.banner {
  padding: var(--sp-2) var(--sp-4);
  font-weight: 600;
}
.banner.bad {
  background: var(--bad-bg);
  color: var(--bad);
}
.banner.warn {
  background: var(--warn-bg);
  color: var(--warn);
  display: flex;
  gap: var(--sp-3);
  align-items: center;
}

/* cards / KPI strip */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--rad-lg);
  min-width: 0;
}
.card > h2 {
  font-size: var(--fs-sm);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--mut);
  margin: 0;
  padding: var(--sp-3) var(--sp-4);
  border-bottom: 1px solid var(--border);
}
.kpis {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: var(--sp-3);
  margin-bottom: var(--sp-4);
}
.kpi {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--rad);
  padding: var(--sp-3);
  display: block;
  color: var(--ink);
}
.kpi small {
  display: block;
  font-size: 9px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--mut);
}
.kpi b {
  font-size: var(--fs-kpi);
  font-weight: 650;
  font-variant-numeric: tabular-nums;
}

/* tables */
.tblwrap {
  overflow-x: auto;
}
table.data {
  width: 100%;
  border-collapse: collapse;
  font-variant-numeric: tabular-nums;
}
table.data th {
  position: sticky;
  top: 0;
  background: var(--surface);
  text-align: left;
  font-size: var(--fs-sm);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--mut);
  padding: 0 var(--sp-3);
  height: var(--row-h);
  border-bottom: 1px solid var(--border);
}
table.data td {
  padding: 0 var(--sp-3);
  height: var(--row-h);
  border-bottom: 1px solid var(--border);
}
body.dense table.data td,
body.dense table.data th {
  height: var(--row-h-dense);
}
tr.expandrow > td {
  background: var(--surface2);
  height: auto;
  padding: var(--sp-3);
}

/* chips / pills / buttons */
.chip {
  font-size: var(--fs-sm);
  font-weight: 600;
  padding: 1px 8px;
  border-radius: 9px;
  background: var(--surface2);
}
.chip.ok {
  background: var(--ok-bg);
  color: var(--ok);
}
.chip.warn {
  background: var(--warn-bg);
  color: var(--warn);
}
.chip.bad {
  background: var(--bad-bg);
  color: var(--bad);
}
.chip.info {
  background: var(--info-bg);
  color: var(--info);
}
.btn {
  border: 1px solid var(--border);
  background: var(--surface2);
  color: var(--ink);
  border-radius: var(--rad);
  padding: var(--sp-1) var(--sp-3);
  min-height: 30px;
  cursor: pointer;
}
.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
}
.btn.danger {
  background: var(--bad-bg);
  border-color: var(--bad);
  color: var(--bad);
}
@media (max-width: 1023px) {
  .btn {
    min-height: var(--touch);
  }
}

/* queue */
ul.queue {
  list-style: none;
  margin: 0;
  padding: 0;
}
ul.queue li {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: var(--sp-3);
  min-height: var(--queue-h);
  padding: var(--sp-2) var(--sp-3);
  border-bottom: 1px solid var(--border);
  border-left: 3px solid transparent;
}
ul.queue li.sev-hi {
  border-left-color: var(--bad);
}
ul.queue li.sev-md {
  border-left-color: var(--warn);
}
ul.queue li.sev-lo {
  border-left-color: var(--info);
}
ul.queue li.sev-mn {
  border-left-color: var(--mut);
}
ul.queue .qmain {
  flex: 1;
  min-width: 0;
}
ul.queue .qtitle {
  font-weight: 600;
}
ul.queue .qsub {
  color: var(--mut);
  font-size: var(--fs-sm);
}
ul.queue .qacts {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-2);
  align-items: center;
}
.empty {
  padding: var(--sp-6);
  color: var(--mut);
  text-align: center;
}

/* toasts + confirm (class names kept from legacy so lib.js code ports verbatim) */
#toasts {
  position: fixed;
  right: var(--sp-4);
  bottom: calc(var(--tabbar-h) + var(--sp-4));
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
  z-index: 40;
}
.toast {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--rad);
  padding: var(--sp-2) var(--sp-3);
  transition: opacity 0.3s;
}
.toast.bad {
  border-color: var(--bad);
  color: var(--bad);
}
.toast.warn {
  border-color: var(--warn);
  color: var(--warn);
}
.toast.out {
  opacity: 0;
}
.confirmov {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
}
.confirmbox {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--rad-lg);
  padding: var(--sp-4);
  max-width: 420px;
}
.cbtns {
  display: flex;
  gap: var(--sp-2);
  justify-content: flex-end;
  margin-top: var(--sp-3);
}
.mini {
  border: 1px solid var(--border);
  background: var(--surface2);
  color: var(--ink);
  border-radius: var(--rad);
  padding: var(--sp-1) var(--sp-3);
  cursor: pointer;
}
.mini.danger {
  border-color: var(--bad);
  color: var(--bad);
}

/* gate */
#gate {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  z-index: 60;
}
/* [hidden] must win over the higher-specificity #gate/#app display rules above
   (attribute selector adds 0,1,0, so #gate[hidden] at 1,1,0 beats #gate at 1,0,0) */
#gate[hidden],
#app[hidden] {
  display: none;
}
.gatebox {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--rad-lg);
  padding: var(--sp-6);
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
  width: 300px;
}
.gatebox input {
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--ink);
  border-radius: var(--rad);
  padding: var(--sp-2) var(--sp-3);
  min-height: var(--touch);
}
.gatebox .sub,
#gatemsg {
  color: var(--mut);
  margin: 0;
}
#gatemsg:empty {
  display: none;
}

/* pager + filter bar */
.pagerbar {
  display: flex;
  gap: var(--sp-2);
  align-items: center;
  padding: var(--sp-2) var(--sp-3);
  color: var(--mut);
  font-size: var(--fs-sm);
}
.filterbar {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-2);
  padding: var(--sp-3);
  border-bottom: 1px solid var(--border);
}
.filterbar input,
.filterbar select {
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--ink);
  border-radius: var(--rad);
  padding: var(--sp-1) var(--sp-2);
  min-height: 30px;
}

/* ---- observability: tiles, fleet grid ---- */

.obs-tiles {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: var(--sp-3);
  margin-bottom: var(--sp-4);
}
.obs-tile {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--rad);
  padding: var(--sp-3);
  min-width: 0;
}
.obs-tile small {
  display: block;
  font-size: 9px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--mut);
}
.obs-tile b {
  font-size: var(--fs-kpi);
  font-weight: 650;
  font-variant-numeric: tabular-nums;
  display: block;
}
.obs-tile b.qstat {
  font-size: var(--fs-lg);
  font-weight: 600;
  line-height: 1.3;
}

/* brand platform icons (platIcon) + clickable post URLs (posts page) */
.plat-ic {
  width: 16px;
  height: 16px;
  vertical-align: middle;
  display: inline-block;
}
.postlink {
  color: inherit;
  text-decoration: none;
}
.postlink:hover {
  text-decoration: underline;
}

.fleetgrid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: var(--sp-2);
}
.mcard {
  border: 1px solid var(--border);
  border-left: 3px solid var(--ok);
  border-radius: var(--rad);
  padding: var(--sp-2) var(--sp-3);
  background: var(--surface);
  min-width: 0;
  cursor: pointer;
}
/* status accent (priority: offline > asleep > online-failing > online-healthy) */
.mcard.st-healthy {
  border-left-color: var(--ok);
}
.mcard.st-failing {
  border-left-color: var(--bad);
  background: var(--bad-bg);
}
.mcard.st-warning {
  border-left-color: var(--warn);
  background: var(--warn-bg);
}
.mcard.st-asleep {
  border-left-color: var(--info);
  background: var(--info-bg);
}
.mcard.st-offline {
  border-left-color: var(--mut);
  opacity: 0.72;
}
.mcard .mrow1 {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: var(--sp-2);
}
.mcard .mid {
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.mcard .big {
  font-size: 16px;
  font-weight: 650;
  font-variant-numeric: tabular-nums;
}
.mcard .msub {
  font-size: var(--fs-sm);
  color: var(--mut);
}

/* right slide-over drawer */
.drawer-ov {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  z-index: 40;
  display: flex;
  justify-content: flex-end;
}
.drawer {
  width: min(420px, 92vw);
  height: 100%;
  background: var(--surface);
  border-left: 1px solid var(--accent);
  overflow-y: auto;
  padding: var(--sp-4);
}
.drawer h2 {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  margin: 0 0 var(--sp-2);
}
.statetl {
  display: flex;
  gap: 1px;
  height: 10px;
  border-radius: 2px;
  overflow: hidden;
}
.statetl span {
  display: block;
}
