/* ═══════════════════════════════════════════════════════════════════════════
   SysOps — base layout & animated background
   Two rows of chrome above the content: the topbar (identity + system status +
   operator utilities) and the topnav (grouped primary navigation). The nav
   lives horizontally under the topbar on wide screens and collapses into a
   slide-in drawer on narrow ones.
   ═══════════════════════════════════════════════════════════════════════════ */

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.55;
  color: var(--text);
  background-color: var(--bg-0);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow-x: hidden;
}

/* Layered animated backdrop: grid + drifting aurora + scanline sheen. */
body::before,
body::after {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
}

body::before {
  background-image:
    linear-gradient(rgba(var(--accent-rgb), 0.055) 1px, transparent 1px),
    linear-gradient(90deg, rgba(var(--accent-rgb), 0.055) 1px, transparent 1px),
    radial-gradient(1100px 620px at 12% -8%, rgba(var(--accent-rgb), 0.16), transparent 62%),
    radial-gradient(900px 540px at 92% 4%, rgba(var(--accent-rgb), 0.14), transparent 60%),
    radial-gradient(800px 700px at 50% 118%, rgba(96, 165, 250, 0.1), transparent 65%);
  background-size: 46px 46px, 46px 46px, 200% 200%, 200% 200%, 200% 200%;
  animation: aurora 26s var(--ease) infinite alternate;
}

body::after {
  background: repeating-linear-gradient(
    to bottom,
    rgba(255, 255, 255, 0.014) 0 1px,
    transparent 1px 3px
  );
  opacity: 0.55;
  mix-blend-mode: overlay;
}

@keyframes aurora {
  0% {
    background-position: 0 0, 0 0, 0% 0%, 100% 0%, 50% 100%;
  }
  100% {
    background-position: 0 46px, 46px 0, 14% 12%, 86% 10%, 46% 82%;
  }
}

:root[data-theme="light"] body::after {
  display: none;
}

/* The first-party network background (public/js/background.js). It paints the
   whole viewport behind everything, so when it runs the CSS grid/aurora backdrop
   steps aside and the two do not compete. */
.app-bg {
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  display: block;
}

:root[data-bg="network"] body::before,
:root[data-bg="network"] body::after {
  display: none;
}

@media (prefers-reduced-motion: reduce) {
  .app-bg {
    /* The canvas draws one static frame; nothing else here animates it. */
    animation: none;
  }
}

.main {
  position: relative;
  z-index: 1;
  min-height: 100vh;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

/* ──────────────────────────────── topbar ──────────────────────────────── */

.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  height: var(--topbar-h);
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 var(--gutter);
  background: rgba(10, 10, 11, 0.92);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(var(--glass-blur));
  -webkit-backdrop-filter: blur(var(--glass-blur));
}

:root[data-theme="light"] .topbar {
  background: rgba(255, 255, 255, 0.85);
}

/* The brand is a link back to Overview now that it sits in the topbar. */
.brand {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 4px 6px;
  border-radius: var(--radius-sm);
  text-decoration: none;
  color: inherit;
  transition: background var(--dur-fast) var(--ease);
}

.brand:hover {
  background: rgba(var(--accent-rgb), 0.07);
}

.brand-mark {
  width: 34px;
  height: 34px;
  flex: 0 0 34px;
  display: grid;
  place-items: center;
  border-radius: 10px;
  background: linear-gradient(140deg, rgba(var(--accent-rgb), 0.32), rgba(var(--accent-rgb), 0.12));
  border: 1px solid rgba(var(--accent-rgb), 0.45);
  box-shadow: 0 0 20px rgba(var(--accent-rgb), 0.3), inset 0 0 14px rgba(var(--accent-rgb), 0.12);
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 16px;
  color: var(--accent);
  animation: brand-pulse 5.5s ease-in-out infinite;
}

@keyframes brand-pulse {
  0%, 100% { box-shadow: 0 0 16px rgba(var(--accent-rgb), 0.24), inset 0 0 12px rgba(var(--accent-rgb), 0.1); }
  50% { box-shadow: 0 0 30px rgba(var(--accent-rgb), 0.44), inset 0 0 18px rgba(var(--accent-rgb), 0.18); }
}

.brand-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.brand-title {
  font-size: 14.5px;
  font-weight: 700;
  letter-spacing: 0.02em;
  line-height: 1.25;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.brand-tagline {
  font-size: 9.5px;
  text-transform: uppercase;
  letter-spacing: 0.16em;
  color: var(--text-faint);
  line-height: 1.3;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar-spacer {
  flex: 1 1 auto;
}

/* Connection + TLS readouts, moved out of the old sidebar footer. */
.topbar-status {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.status-pill {
  display: flex;
  align-items: center;
  gap: 7px;
  max-width: 190px;
  padding: 5px 10px;
  border-radius: var(--radius-pill);
  background: var(--panel-sunken);
  border: 1px solid var(--line);
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-mute);
  white-space: nowrap;
}

.status-pill .truncate {
  min-width: 0;
}

/* The nav toggle belongs to the narrow-viewport drawer only. Scoped to the
   topbar so the later `.btn { display: inline-flex }` rule (components.css loads
   after this file) cannot win on specificity and show it on a wide screen, where
   it has nothing to open. */
.topbar .menu-toggle {
  display: none;
}

/* ──────────────────────────────── topnav ──────────────────────────────── */

.topnav {
  position: sticky;
  top: var(--topbar-h);
  z-index: 25;
  flex: 0 0 auto;
  background: rgba(10, 10, 11, 0.92);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(var(--glass-blur));
  -webkit-backdrop-filter: blur(var(--glass-blur));
}

:root[data-theme="light"] .topnav {
  background: rgba(255, 255, 255, 0.88);
}

/* Deliberately no `overflow` on these rows: the group menus are absolutely
   positioned children, and an overflow context here would clip them. They wrap
   instead, which is why the bar has a min-height rather than a fixed one. */
.topnav-inner {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px 12px;
  min-height: var(--topnav-h);
  padding: 6px var(--gutter);
}

.topnav-groups {
  display: flex;
  align-items: stretch;
  /* Fill the row's height so an active item's underline lands on the row's
     bottom edge rather than floating under the text. */
  align-self: stretch;
  flex-wrap: wrap;
  gap: 2px;
  /* Never shrink: if this block were allowed to compress, the items would break
     mid-row onto a second line and the bar would grow into what looks like two
     stacked nav rows. It stays whole and lets the row's other child wrap first. */
  flex: 0 0 auto;
}

.nav-group {
  position: relative;
  display: flex;
  align-items: stretch;
  /* Atomic, so an individual item can never be split or squeezed. */
  flex: 0 0 auto;
}

/* The group button: a flat nav item with a chevron, underlined when the page on
   screen lives in this group. */
.nav-section {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  margin: 0;
  height: 100%;
  padding: 0 12px;
  background: none;
  border: 0;
  border-bottom: 2px solid transparent;
  border-radius: 0;
  font-family: inherit;
  font-size: 13px;
  font-weight: 550;
  letter-spacing: 0.01em;
  color: var(--text-dim);
  cursor: pointer;
  white-space: nowrap;
  transition: color var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease);
}

.nav-section:hover {
  background: none;
  color: var(--text);
}

/* A page pinned directly onto the navbar rather than hidden inside a dropdown.
   Same flat item as a group button, but with no chevron. */
.nav-item.nav-direct {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  flex: 0 0 auto;
  height: 100%;
  padding: 0 12px;
  border: 0;
  border-bottom: 2px solid transparent;
  border-radius: 0;
  font-size: 13px;
  font-weight: 550;
  letter-spacing: 0.01em;
  color: var(--text-dim);
  white-space: nowrap;
  transition: color var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease);
}

.nav-item.nav-direct:hover {
  background: none;
  color: var(--text);
}

.nav-item.nav-direct.active {
  color: var(--accent);
  background: none;
  border-color: transparent;
  border-bottom-color: var(--accent);
}

/* The left bar belongs to items inside a menu; a top-level item underlines
   instead of drawing the bar. */
.nav-item.nav-direct.active::before {
  display: none;
}

.nav-item.nav-direct .nav-icon {
  width: auto;
  flex: 0 0 auto;
}

/* `has-active` means "the page on screen lives in this group" — set by app.js
   so the operator can see where they are without opening every menu. */
.nav-group.has-active > .nav-section {
  color: var(--accent);
  background: none;
  border-color: transparent;
  border-bottom-color: var(--accent);
}

.nav-section .nav-chevron {
  flex: 0 0 auto;
  font-size: 11px;
  line-height: 1;
  opacity: 0.6;
  transition: transform var(--dur-fast) var(--ease);
}

.nav-group.collapsed .nav-chevron {
  transform: rotate(-90deg);
}

/* The dropdown panel. On narrow screens this becomes an inline list inside the
   drawer (see the responsive block below). */
.nav-items {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  z-index: 40;
  display: flex;
  flex-direction: column;
  gap: 1px;
  min-width: 232px;
  max-height: min(70vh, 560px);
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 6px;
  border-radius: var(--radius);
  background: var(--panel-solid);
  border: 1px solid var(--line-strong);
  box-shadow: var(--shadow-2);
}

/* Keep the trailing groups' menus inside the viewport. */
.nav-group:nth-last-child(-n + 2) .nav-items {
  left: auto;
  right: 0;
}

.nav-items.collapsed {
  display: none;
}

.nav-item {
  position: relative;
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  color: var(--text-dim);
  text-decoration: none;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid transparent;
  transition: background var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease),
    border-color var(--dur-fast) var(--ease);
}

.nav-item .nav-icon {
  width: 18px;
  flex: 0 0 18px;
  text-align: center;
  font-family: var(--font-mono);
  font-size: 14px;
  opacity: 0.9;
}

.nav-item:hover {
  background: rgba(var(--accent-rgb), 0.1);
  color: var(--text);
}

.nav-item.active {
  background: linear-gradient(90deg, rgba(var(--accent-rgb), 0.18), rgba(var(--accent-rgb), 0.03));
  border-color: rgba(var(--accent-rgb), 0.32);
  color: var(--text);
}

.nav-item.active::before {
  content: "";
  position: absolute;
  left: 0;
  top: 18%;
  bottom: 18%;
  width: 3px;
  border-radius: 0 4px 4px 0;
  background: var(--accent);
  box-shadow: var(--glow-accent);
}

.nav-badge {
  margin-left: auto;
  font-family: var(--font-mono);
  font-size: 10.5px;
  padding: 1px 7px;
  border-radius: var(--radius-pill);
  background: rgba(var(--crit-rgb), 0.16);
  border: 1px solid rgba(var(--crit-rgb), 0.4);
  color: var(--crit);
}

.nav-badge.muted {
  background: rgba(148, 163, 184, 0.12);
  border-color: var(--line);
  color: var(--text-mute);
}

/* Current page readout, parked at the right end of the nav row. It wraps to its
   own line as a unit when the row is tight, rather than crushing the pills. */
.topnav-page {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-left: auto;
  flex: 0 0 auto;
  min-width: 0;
  padding-left: 12px;
}

.topnav-page-title {
  font-size: 13.5px;
  font-weight: 620;
  letter-spacing: 0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topnav-page-sub {
  font-size: 11px;
  color: var(--text-faint);
  font-family: var(--font-mono);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ─────────────────────────────── content ─────────────────────────────── */

.view {
  padding: var(--gutter);
  display: flex;
  flex-direction: column;
  gap: var(--gutter);
  flex: 1 1 auto;
  min-width: 0;
}

.view-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

.view-title {
  margin: 0;
  font-size: 22px;
  font-weight: 650;
  letter-spacing: -0.01em;
}

.view-title span {
  color: var(--accent);
}

.view-desc {
  margin: 4px 0 0;
  color: var(--text-mute);
  font-size: 12.5px;
  max-width: 76ch;
}

/* ───────────────────────────── grid helpers ───────────────────────────── */

.grid {
  display: grid;
  gap: clamp(14px, 1vw, 24px);
}

.grid.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid.cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid.auto-fit { grid-template-columns: repeat(auto-fit, minmax(min(100%, 260px), 1fr)); }
.grid.auto-fit-wide { grid-template-columns: repeat(auto-fit, minmax(min(100%, 360px), 1fr)); }

.span-2 { grid-column: span 2; }
.span-3 { grid-column: span 3; }
.span-full { grid-column: 1 / -1; }

.row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.row.tight { gap: 6px; }
.row.between { justify-content: space-between; }
.row.end { justify-content: flex-end; }
.stack { display: flex; flex-direction: column; gap: 14px; }

/* ─────────────────────────── responsive layout ─────────────────────────── */

@media (max-width: 1180px) {
  .grid.cols-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid.cols-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 900px) {
  /* The nav row becomes a drawer. Same toggle, scrim and body class as before,
     so the keyboard path and the close-on-navigate behaviour are unchanged. */
  .topnav {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 60;
    width: min(86vw, var(--drawer-w));
    transform: translateX(-104%);
    transition: transform var(--dur) var(--ease);
    box-shadow: var(--shadow-3);
    border-bottom: 0;
    border-right: 1px solid var(--line);
    background: linear-gradient(180deg, rgba(10, 10, 11, 0.98), rgba(10, 10, 11, 0.96));
  }

  :root[data-theme="light"] .topnav {
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.98), rgba(244, 247, 252, 0.95));
  }

  body.nav-open .topnav { transform: translateX(0); }

  .topnav-inner {
    flex-direction: column;
    align-items: stretch;
    flex-wrap: nowrap;
    gap: 4px;
    height: 100%;
    padding: 16px 12px;
    overflow-y: auto;
    overscroll-behavior: contain;
  }

  .topnav-groups {
    flex-direction: column;
    align-items: stretch;
    flex-wrap: nowrap;
  }

  .nav-section {
    justify-content: space-between;
    width: 100%;
    height: auto;
    border-bottom: 0;
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.2em;
    color: var(--text-faint);
    padding: 13px 10px 5px;
  }

  .nav-group.has-active > .nav-section {
    background: none;
    border-color: transparent;
    border-bottom: 0;
    color: var(--text-dim);
  }

  /* Direct items are ordinary rows in the drawer, not underlined tabs. */
  .nav-item.nav-direct {
    width: 100%;
    height: auto;
    border-bottom: 0;
    padding: 8px 10px;
  }

  .nav-item.nav-direct.active {
    color: var(--accent);
    border-bottom: 0;
  }

  /* Inline list, not a floating panel. */
  .nav-items {
    position: static;
    min-width: 0;
    max-height: none;
    overflow: visible;
    padding: 0;
    border: 0;
    border-radius: 0;
    background: none;
    box-shadow: none;
  }

  .topnav-page { display: none; }

  .nav-scrim {
    position: fixed;
    inset: 0;
    z-index: 55;
    background: rgba(2, 4, 10, 0.62);
    backdrop-filter: blur(3px);
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--dur) var(--ease);
  }

  body.nav-open .nav-scrim { opacity: 1; pointer-events: auto; }

  .topbar .menu-toggle { display: inline-flex; }

  .grid.cols-2,
  .grid.cols-3,
  .grid.cols-4 { grid-template-columns: minmax(0, 1fr); }

  .span-2,
  .span-3 { grid-column: span 1; }

  :root { --gutter: 14px; }
}

@media (max-width: 640px) {
  .topbar-status { display: none; }
}

@media (max-width: 560px) {
  .view { gap: 14px; }
  .view-title { font-size: 19px; }
  .topbar { gap: 8px; }
  .brand-tagline { display: none; }
  .hide-sm { display: none !important; }
}

/* ─────────────────── big screens: cards grow, not multiply ─────────────────── */

@media (min-width: 1500px) {
  :root { --gutter: 28px; }
  .grid.auto-fit { grid-template-columns: repeat(auto-fit, minmax(min(100%, 300px), 1fr)); }
  .grid.auto-fit-wide { grid-template-columns: repeat(auto-fit, minmax(min(100%, 400px), 1fr)); }
  .view-title { font-size: 26px; }
  .view-desc { font-size: 13.5px; }
}

@media (min-width: 1900px) {
  :root { --gutter: 36px; }
  .grid.auto-fit { grid-template-columns: repeat(auto-fit, minmax(min(100%, 340px), 1fr)); }
  .grid.auto-fit-wide { grid-template-columns: repeat(auto-fit, minmax(min(100%, 460px), 1fr)); }
  .view-title { font-size: 30px; }
}

/* ──────────────────────────── utility classes ──────────────────────────── */

.mono { font-family: var(--font-mono); }
.muted { color: var(--text-mute); }
.faint { color: var(--text-faint); }
.dim { color: var(--text-dim); }
.ok { color: var(--ok); }
.warn { color: var(--warn); }
.crit { color: var(--crit); }
.info { color: var(--info); }
.accent { color: var(--accent); }
.nowrap { white-space: nowrap; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.center { text-align: center; }
.right { text-align: right; }
.tiny { font-size: 11px; }
.small { font-size: 12px; }
.strong { font-weight: 650; }
.upper { text-transform: uppercase; letter-spacing: 0.14em; }
.hidden { display: none !important; }
.flex-1 { flex: 1 1 auto; min-width: 0; }
.scroll-y { overflow-y: auto; overscroll-behavior: contain; }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: rgba(148, 163, 184, 0.22);
  border-radius: 8px;
  border: 2px solid transparent;
  background-clip: content-box;
}
::-webkit-scrollbar-thumb:hover { background: rgba(var(--accent-rgb), 0.4); background-clip: content-box; }

::selection { background: rgba(var(--accent-rgb), 0.32); color: #fff; }

:focus-visible {
  outline: 2px solid rgba(var(--accent-rgb), 0.8);
  outline-offset: 2px;
  border-radius: 4px;
}

.skip-link {
  position: absolute;
  left: -9999px;
  top: 0;
  z-index: 200;
  padding: 10px 16px;
  background: var(--panel-solid);
  border: 1px solid var(--accent);
  border-radius: 0 0 var(--radius-sm) 0;
}
.skip-link:focus { left: 0; }
