/* ============================================================
   Layout: app shell, sidebar, topbar, page grid, responsive rules.
   ============================================================ */

.app-shell { display: flex; min-height: 100vh; }

/* ---------------------------------------------------------------- sidebar: liquid glass
   Layered translucency (blur+saturate, tinted overlay, hairline edge,
   soft shadow) over the app background. Perf: this is the ONLY blurred
   surface ever stacked with the topbar's own blur (they never overlap
   on screen - one is the full-height left rail, the other sits to its
   right - so there is never more than one blur composited over the
   same pixels). All nav animation below touches only transform/opacity.
   These rules replace a previous conflicting !important block that
   used to live in passwall-glass.css (see that file's history) -
   fighting it with more !important wasn't going to work. */

.sidebar {
  width: var(--sidebar-w);
  flex: none;
  display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh;
  transition: width var(--duration-base) var(--ease-out);
  z-index: var(--z-sticky);
  border-right: 1px solid var(--glass-border);
  box-shadow: var(--glass-shadow);
  background: var(--glass-tint);
}
@supports (backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px)) {
  .sidebar {
    backdrop-filter: blur(var(--glass-blur)) saturate(var(--glass-sat));
    -webkit-backdrop-filter: blur(var(--glass-blur)) saturate(var(--glass-sat));
  }
}
@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
  /* No compositor support: fall back to a plain opaque panel rather
     than a half-transparent, unblurred smear over page content. */
  .sidebar { background: var(--bg-panel); }
}
.app-shell.is-collapsed .sidebar { width: var(--sidebar-w-collapsed); }

.sidebar-brand {
  display: flex; align-items: center; gap: var(--space-2);
  height: var(--topbar-h); padding: 0 var(--space-4); flex: none;
  font-weight: var(--weight-semibold); font-size: var(--text-sm); letter-spacing: var(--tracking-tight);
  color: var(--text); border-bottom: 1px solid var(--glass-border); overflow: hidden; white-space: nowrap;
}
.sidebar-brand .icon { color: var(--accent); }

.sidebar-nav { flex: 1; overflow-y: auto; overflow-x: hidden; padding: var(--space-2) var(--space-2) var(--space-3); scrollbar-width: thin; }
.sidebar-nav::-webkit-scrollbar { width: 6px; }
.sidebar-nav::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: var(--radius-full); }
.sidebar-nav::-webkit-scrollbar-track { background: transparent; }

.nav-group { margin-top: var(--space-4); }
.nav-group:first-child { margin-top: var(--space-2); }
.nav-group-label {
  font-size: 11px; font-weight: var(--weight-semibold); letter-spacing: var(--tracking-wide);
  text-transform: uppercase; color: var(--text-faint); padding: 0 10px var(--space-1);
}
.app-shell.is-collapsed .nav-group-label { display: none; }
.app-shell.is-collapsed .nav-group { margin-top: var(--space-3); padding-top: var(--space-3); border-top: 1px solid var(--glass-border); }
.app-shell.is-collapsed .nav-group:first-child { margin-top: var(--space-2); padding-top: 0; border-top: none; }

.nav-item {
  position: relative;
  display: flex; align-items: center; gap: var(--space-3);
  padding: 9px 10px; margin: 1px 0; border-radius: var(--radius-md);
  color: var(--text-dim); font-size: var(--text-sm); font-weight: var(--weight-medium);
  text-decoration: none; white-space: nowrap; overflow: hidden;
  transition: background var(--duration-fast) var(--ease-out), color var(--duration-fast) var(--ease-out),
              box-shadow var(--duration-fast) var(--ease-out), transform var(--duration-fast) var(--ease-out);
}
.nav-item .icon { flex: none; }
.nav-item:hover { background: var(--bg-hover); color: var(--text); }
.nav-item:active { transform: scale(0.98); }
.nav-item:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.nav-item.active {
  color: var(--accent);
  background: var(--glass-tint-active);
  box-shadow: inset 0 0 0 1px var(--accent-ring);
}
/* Active indicator - a positioned pseudo-element on the active row
   itself, not a separately-animated sibling element to lay out. This
   is a multi-page app (full navigation per route, not a SPA), so there
   is no continuous element to slide between two positions across a
   route change the way a client-routed app could - the honest
   equivalent here is a quick grow-in on paint, transform+opacity only. */
.nav-item.active::before {
  content: ""; position: absolute; left: -6px; top: 50%;
  width: 3px; height: 16px; border-radius: var(--radius-full);
  background: linear-gradient(180deg, var(--accent), var(--accent-solid));
  transform-origin: center;
  animation: nav-indicator-in var(--duration-base) var(--ease-out) backwards;
}
.app-shell.is-collapsed .nav-item.active::before { left: -2px; }
@keyframes nav-indicator-in {
  from { opacity: 0; transform: translateY(-50%) scaleY(0); }
  to { opacity: 1; transform: translateY(-50%) scaleY(1); }
}

.app-shell.is-collapsed .nav-item span.label,
.app-shell.is-collapsed .sidebar-brand span.label { display: none; }
.app-shell.is-collapsed .nav-item { justify-content: center; }

/* collapsed-rail tooltips: reuse [data-tooltip] (components.css) but to
   the side, and only while actually collapsed - expanded rows already
   show their own label, a redundant tooltip there would just be noise. */
.nav-item[data-tooltip]::after { display: none; }
.app-shell.is-collapsed .nav-item[data-tooltip]::after {
  display: block;
  bottom: auto; left: calc(100% + 10px); top: 50%; transform: translateY(-50%) translateX(-4px);
}
.app-shell.is-collapsed .nav-item[data-tooltip]:hover::after,
.app-shell.is-collapsed .nav-item[data-tooltip]:focus-visible::after {
  transform: translateY(-50%) translateX(0);
}

.sidebar-foot { border-top: 1px solid var(--glass-border); padding: var(--space-2); flex: none; }

/* ---------------------------------------------------------------- topbar */

.topbar {
  position: sticky; top: 0; z-index: var(--z-sticky);
  display: flex; align-items: center; gap: var(--space-3);
  height: var(--topbar-h); padding: 0 var(--space-4);
  border-bottom: 1px solid var(--glass-border);
  background: var(--glass-tint);
}
@supports (backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px)) {
  .topbar {
    backdrop-filter: blur(var(--glass-blur)) saturate(var(--glass-sat));
    -webkit-backdrop-filter: blur(var(--glass-blur)) saturate(var(--glass-sat));
  }
}
@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
  .topbar { background: color-mix(in srgb, var(--bg-panel) 92%, transparent); }
}
.topbar-status { display: flex; align-items: center; gap: var(--space-2); margin-right: auto; min-width: 0; }
.topbar-status .state-label { font-size: var(--text-sm); font-weight: var(--weight-semibold); white-space: nowrap; }
.topbar-status .uptime { font-size: var(--text-xs); color: var(--text-dim); font-variant-numeric: tabular-nums; white-space: nowrap; }
.topbar-actions { display: flex; align-items: center; gap: var(--space-2); flex: none; }
.sidebar-toggle { display: none; }

@media (prefers-reduced-motion: reduce) {
  .sidebar, .nav-item, .nav-item.active::before, .sidebar-backdrop { transition: none !important; }
  .nav-item, .app-shell.is-drawer-open .nav-item { animation: none !important; opacity: 1 !important; transform: none !important; }
  .nav-item.active::before { animation: none !important; opacity: 1 !important; transform: translateY(-50%) scaleY(1) !important; }
}

/* ---------------------------------------------------------------- page content */

.app-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
main.page {
  max-width: var(--content-max-w); width: 100%; margin: 0 auto;
  padding: var(--space-6) var(--space-6) var(--space-16);
}

.section { margin-top: var(--space-6); }
.section:first-child { margin-top: 0; }
.section-head { display: flex; align-items: baseline; justify-content: space-between; gap: var(--space-3); margin-bottom: var(--space-3); }
.section-head h2 { font-size: var(--text-md); }
.section-head .hint { margin: 0; }

/* ---------------------------------------------------------------- hero status panel */

.hero {
  display: flex; align-items: center; justify-content: space-between; gap: var(--space-4); flex-wrap: wrap;
  background: var(--bg-panel); border: 1px solid var(--border); border-radius: var(--radius-lg);
  padding: var(--space-6); margin-bottom: var(--space-6); box-shadow: var(--shadow-sm);
}
.hero-state { display: flex; align-items: center; gap: var(--space-3); }
.hero-state .dot-lg { width: 12px; height: 12px; border-radius: 50%; flex: none; }
.hero-state .state-text { font-size: var(--text-xl); font-weight: var(--weight-semibold); letter-spacing: var(--tracking-tight); line-height: 1; }
.state-LIVE .state-text { color: var(--live); }
.state-STOPPED .state-text { color: var(--text-dim); }
.state-ERROR .state-text { color: var(--live); }
.state-STARTING .state-text { color: var(--warning); }
.state-RECONNECTING .state-text { color: var(--warning); }
.dot-LIVE { background: var(--live); animation: pulse-ring 1.8s var(--ease-out) infinite; }
.dot-STOPPED { background: var(--text-faint); }
.dot-ERROR { background: var(--live); }
.dot-STARTING { background: var(--warning); animation: pulse 1.4s var(--ease-out) infinite; }
/* Not pulse-ring here: that keyframe's ring color is hardcoded to
   --live-tint (red), which would look wrong against an amber dot - the
   plain opacity pulse (same as badge-activating elsewhere) stays
   correctly amber. */
.dot-RECONNECTING { background: var(--warning); animation: pulse 1.4s var(--ease-out) infinite; }

.restart-rate-badge { margin-left: auto; }
.restart-rate-badge.is-alarm .dot { animation: pulse 1s var(--ease-out) infinite; }
.is-stale { opacity: 0.45; transition: opacity 0.3s var(--ease-out); }

/* ---------------------------------------------------------------- responsive */

.mobile-only { display: none; }
.mobile-bar { display: none; }
.sidebar-backdrop { display: none; }

@media (max-width: 1023px) {
  /* Off-canvas drawer: transform-only (no width/left animation), so the
     browser can composite this on its own layer instead of repainting.
     `visibility` flips at the end of the transition (not instantly) so
     the drawer stays reachable by touch during the slide but drops out
     of layout/tab-order once fully hidden. */
  .sidebar {
    position: fixed; left: 0; top: 0; transform: translateX(-100%);
    box-shadow: var(--glass-shadow);
    visibility: hidden;
    transition: transform var(--duration-base) var(--ease-out), visibility 0s linear var(--duration-base);
    padding-top: env(safe-area-inset-top, 0px);
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }
  .app-shell.is-drawer-open .sidebar {
    transform: translateX(0); visibility: visible;
    transition: transform var(--duration-base) var(--ease-out);
  }
  .app-shell.is-collapsed .sidebar { width: var(--sidebar-w); }
  .app-shell.is-collapsed .nav-group-label { display: block; }
  .app-shell.is-collapsed .nav-group { border-top: none; padding-top: 0; margin-top: var(--space-4); }
  .app-shell.is-collapsed .nav-group:first-child { margin-top: var(--space-2); }
  .app-shell.is-collapsed .nav-item span.label,
  .app-shell.is-collapsed .sidebar-brand span.label { display: inline; }
  .app-shell.is-collapsed .nav-item { justify-content: flex-start; }

  /* touch targets: the 56px minimum applies to the drawer specifically
     (fingers, not a mouse) - the desktop rail keeps its tighter density */
  .nav-item { min-height: 56px; padding: 14px 12px; font-size: var(--text-base); }
  .sidebar-foot .btn.btn-icon { min-height: 56px; min-width: 56px; }

  /* staggered reveal on open - capped item count so a long list doesn't
     keep animating after the drawer is already visible; opacity+transform
     only, GPU-composited, no layout thrash */
  .nav-item { opacity: 1; transform: none; }
  .app-shell.is-drawer-open .nav-item {
    animation: nav-item-in var(--duration-base) var(--ease-out) backwards;
  }
  .app-shell.is-drawer-open .nav-group:nth-child(1) .nav-item:nth-child(1) { animation-delay: 40ms; }
  .app-shell.is-drawer-open .nav-group:nth-child(1) .nav-item:nth-child(2) { animation-delay: 60ms; }
  .app-shell.is-drawer-open .nav-group:nth-child(1) .nav-item:nth-child(3) { animation-delay: 80ms; }
  .app-shell.is-drawer-open .nav-group:nth-child(2) .nav-item:nth-child(1) { animation-delay: 100ms; }
  .app-shell.is-drawer-open .nav-group:nth-child(2) .nav-item:nth-child(2) { animation-delay: 120ms; }
  .app-shell.is-drawer-open .nav-group:nth-child(2) .nav-item:nth-child(3) { animation-delay: 140ms; }
  .app-shell.is-drawer-open .nav-group:nth-child(2) .nav-item:nth-child(4) { animation-delay: 160ms; }
  .app-shell.is-drawer-open .nav-group:nth-child(3) .nav-item:nth-child(1) { animation-delay: 180ms; }
  .app-shell.is-drawer-open .nav-group:nth-child(3) .nav-item:nth-child(2) { animation-delay: 200ms; }
  .app-shell.is-drawer-open .nav-group:nth-child(3) .nav-item:nth-child(3) { animation-delay: 220ms; }
  .app-shell.is-drawer-open .nav-group:nth-child(4) .nav-item:nth-child(1) { animation-delay: 240ms; }
  .app-shell.is-drawer-open .nav-group:nth-child(4) .nav-item:nth-child(2) { animation-delay: 260ms; }
  @keyframes nav-item-in { from { opacity: 0; transform: translateX(-8px); } to { opacity: 1; transform: none; } }

  .sidebar-backdrop {
    display: block; position: fixed; inset: 0; background: rgba(8, 10, 14, 0.5);
    z-index: calc(var(--z-sticky) - 1); opacity: 0; pointer-events: none;
    transition: opacity var(--duration-base) var(--ease-out);
  }
  .app-shell.is-drawer-open .sidebar-backdrop { opacity: 1; pointer-events: auto; }

  .sidebar-toggle { display: inline-flex; }
  main.page { padding: var(--space-4) var(--space-4) calc(var(--space-16) + 64px); }

  .mobile-bar {
    display: flex; gap: var(--space-2); align-items: center;
    position: fixed; left: 0; right: 0; bottom: 0; z-index: var(--z-sticky);
    padding: var(--space-3) var(--space-4) calc(var(--space-3) + env(safe-area-inset-bottom, 0px));
    background: color-mix(in srgb, var(--bg-panel) 96%, transparent);
    backdrop-filter: blur(8px);
    border-top: 1px solid var(--border);
  }
  .mobile-bar .btn { flex: 1; height: 56px; font-size: var(--text-base); }
  .mobile-bar .btn-icon { flex: 0 0 56px; width: 56px; }
}

@media (max-width: 767px) {
  .hero { flex-direction: column; align-items: stretch; }
  .hero .btn-row { width: 100%; }
  .hero .btn-row .btn { flex: 1; }
  .topbar-status .uptime { display: none; }
  .form-grid, .grid { grid-template-columns: 1fr; }
  .service-row { flex-wrap: wrap; }
  .service-row .service-meta { margin-left: 0; order: 3; width: 100%; }
}

@media (min-width: 1440px) {
  main.page { padding-left: var(--space-8); padding-right: var(--space-8); }
}

/* ---------------------------------------------------------------- remote-desktop overlay (Part 4) */

.vnc-overlay { position: fixed; inset: 0; z-index: var(--z-modal); background: #000; display: flex; flex-direction: column; }
.vnc-overlay[hidden] { display: none; }
.vnc-overlay-bar {
  display: flex; align-items: center; gap: var(--space-3);
  padding: var(--space-2) var(--space-3) var(--space-2) var(--space-4);
  background: var(--bg-panel); border-bottom: 1px solid var(--border);
  padding-top: calc(var(--space-2) + env(safe-area-inset-top, 0px));
}
.vnc-overlay-title { display: inline-flex; align-items: center; gap: var(--space-2); font-weight: var(--weight-semibold); flex: 1; min-width: 0; }
.vnc-overlay-screen { flex: 1; min-height: 0; }
.vnc-overlay-screen > * { width: 100%; height: 100%; }
