/* Domain-wide LVL site sidebar (works with hub + marketing pages) — v7 */

:root {
  --lvl-sidebar-w: 272px;
}

/* Soften scrollbar + brand polish */
aside.sidebar.lvl-site-sidebar .sidebar-brand strong {
  letter-spacing: -0.02em;
}
aside.sidebar.lvl-site-sidebar .nav-section {
  margin-top: 0.85rem;
  opacity: 0.9;
}

/* When site-nav injects a fixed sidebar on marketing pages */
body.lvl-has-site-nav {
  --lvl-nav-pad: 0px;
}

/* Injected shell (pages without .hub) */
body.lvl-has-site-nav:not(:has(.hub)) {
  padding-left: var(--lvl-sidebar-w);
}
@media (max-width: 960px) {
  body.lvl-has-site-nav:not(:has(.hub)) {
    padding-left: 0;
  }
}

/* Prefer :has when available; fallback class from JS optional */
@supports not selector(body:has(.hub)) {
  body.lvl-has-site-nav.lvl-marketing-pad {
    padding-left: var(--lvl-sidebar-w);
  }
  @media (max-width: 960px) {
    body.lvl-has-site-nav.lvl-marketing-pad {
      padding-left: 0;
    }
  }
}

aside.sidebar.lvl-site-sidebar,
.hub aside.sidebar {
  background: linear-gradient(175deg, #121a2c 0%, #0d1422 45%, #0a101c 100%);
  border-right: 1px solid rgba(148, 163, 184, 0.14);
  padding: 0.9rem 0.75rem 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.12rem;
  z-index: 70;
  box-shadow: 8px 0 32px rgba(0, 0, 0, 0.22);
}

aside.sidebar.lvl-site-sidebar {
  position: fixed;
  top: 0;
  left: 0;
  width: var(--lvl-sidebar-w);
  height: 100vh;
  overflow: hidden;
}

.lvl-side-nav-scroll,
#side-nav {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  min-height: 0;
  padding-bottom: 0.5rem;
  scrollbar-width: thin;
  scrollbar-color: rgba(148, 163, 184, 0.35) transparent;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.45rem 0.55rem 0.85rem;
  text-decoration: none;
  color: inherit;
  flex-shrink: 0;
}
.sidebar-brand:hover {
  text-decoration: none;
  color: #fff;
}
.sidebar-brand .logo,
.logo {
  width: 2.25rem;
  height: 2.25rem;
  border-radius: 0.65rem;
  background: linear-gradient(135deg, #5b8cff, #8b5cf6);
  display: grid;
  place-items: center;
  font-weight: 700;
  color: #fff;
  font-family: "Space Grotesk", Inter, system-ui, sans-serif;
  box-shadow: 0 0 18px rgba(91, 140, 255, 0.35);
  font-size: 0.75rem;
}
.sidebar-brand strong {
  display: block;
  font-size: 0.92rem;
  font-weight: 700;
}
.sidebar-brand span {
  display: block;
  font-size: 0.68rem;
  color: #8b9bb8;
}

.nav-section {
  margin-top: 0.7rem;
  padding: 0.35rem 0.6rem 0.25rem;
  font-size: 0.62rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #6b7a99;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  padding: 0.52rem 0.7rem;
  border-radius: 0.6rem;
  color: #b0bdd6;
  font-size: 0.84rem;
  font-weight: 500;
  text-decoration: none;
  border: 1px solid transparent;
  transition: background 0.12s, color 0.12s, border-color 0.12s;
}
.nav-link:hover {
  color: #ffffff;
  background: rgba(79, 140, 255, 0.12);
  text-decoration: none;
}
.nav-link.active {
  color: #fff;
  background: linear-gradient(90deg, rgba(79, 140, 255, 0.22), rgba(139, 92, 246, 0.12));
  border-color: rgba(147, 197, 253, 0.28);
  box-shadow: inset 3px 0 0 #60a5fa;
}
.nav-link .ico {
  width: 1.15rem;
  text-align: center;
  opacity: 0.9;
  flex-shrink: 0;
  font-size: 0.85rem;
}
.nav-link .lbl {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sidebar-foot {
  flex-shrink: 0;
  margin-top: 0.35rem;
  padding: 0.75rem 0.55rem 0.15rem;
  border-top: 1px solid rgba(148, 163, 184, 0.12);
  font-size: 0.7rem;
  color: #6b7a99;
  line-height: 1.45;
}
.sidebar-foot a {
  color: #93c5fd;
}

/* Mobile drawer */
.sidebar-backdrop,
.lvl-site-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  z-index: 65;
}
.sidebar-backdrop.open,
.lvl-site-backdrop.open {
  display: block;
}

/* Floating menu control — visible whenever drawer mode is active (≤960px) */
.lvl-nav-fab.menu-btn,
button.lvl-nav-fab,
#lvl-nav-fab {
  display: none;
  position: fixed;
  top: 0.85rem;
  left: 0.85rem;
  z-index: 90;
  border: 1px solid rgba(148, 163, 184, 0.28);
  background: rgba(11, 16, 32, 0.95);
  color: #fff;
  border-radius: 0.6rem;
  padding: 0.55rem 0.75rem;
  cursor: pointer;
  font-size: 1.1rem;
  line-height: 1;
  backdrop-filter: blur(12px);
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.35);
  min-width: 2.5rem;
  min-height: 2.5rem;
  align-items: center;
  justify-content: center;
}
.lvl-nav-fab.menu-btn:hover,
button.lvl-nav-fab:hover,
#lvl-nav-fab:hover {
  border-color: rgba(96, 165, 250, 0.55);
  background: rgba(20, 30, 55, 0.98);
}
.lvl-nav-fab.menu-btn:focus-visible,
#lvl-nav-fab:focus-visible,
#menu-btn:focus-visible {
  outline: 2px solid #60a5fa;
  outline-offset: 2px;
}

/* When nav is open, keep control above drawer chrome */
body.lvl-nav-open #lvl-nav-fab,
body.lvl-nav-open #menu-btn {
  z-index: 95;
}

@media (max-width: 960px) {
  body.lvl-has-site-nav:not(:has(.hub)) {
    padding-left: 0;
  }
  aside.sidebar.lvl-site-sidebar {
    transform: translateX(-105%);
    transition: transform 0.2s ease;
    width: min(288px, 88vw);
  }
  aside.sidebar.lvl-site-sidebar.open {
    transform: translateX(0);
  }
  .lvl-nav-fab.menu-btn,
  button.lvl-nav-fab,
  #lvl-nav-fab {
    display: inline-flex;
  }
  /* Hub topbar menu button — always interactive on small screens */
  .hub .topbar .menu-btn,
  #menu-btn.menu-btn {
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 90;
  }
  /* Prefer one control: hide floating fab when hub already has topbar menu */
  .hub #lvl-nav-fab {
    display: none !important;
  }
  body.lvl-has-site-nav .nav .nav-inner {
    padding-left: 3rem;
  }
  body.lvl-nav-open {
    overflow: hidden;
  }
}

/* Hub pages: sticky column on desktop; off-canvas drawer on mobile.
   IMPORTANT: mobile must beat .hub .sidebar { position:sticky } so the
   opaque sidebar does not occupy the first full viewport row and hide .main. */
.hub {
  grid-template-columns: var(--lvl-sidebar-w) 1fr;
  min-height: 100vh;
}
.hub .sidebar,
.hub aside.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.hub .main {
  min-width: 0;
  min-height: 100vh;
  position: relative;
  z-index: 1;
  background: hsl(var(--background, 220 25% 6%));
  color: hsl(var(--foreground, 220 10% 97%));
}

@media (max-width: 960px) {
  .hub {
    grid-template-columns: 1fr;
  }
  /* Fixed off-canvas — out of document flow so .main is the only grid row */
  .hub .sidebar,
  .hub aside.sidebar,
  .hub aside.sidebar#sidebar {
    position: fixed !important;
    top: 0;
    left: 0;
    bottom: 0;
    width: min(288px, 88vw);
    height: 100vh;
    max-height: 100dvh;
    z-index: 70;
    transform: translateX(-105%);
    transition: transform 0.2s ease;
    overflow-y: auto;
  }
  .hub .sidebar.open,
  .hub aside.sidebar.open,
  .hub aside.sidebar#sidebar.open {
    transform: translateX(0);
  }
  .hub .main {
    width: 100%;
    grid-column: 1 / -1;
  }
  /* Ensure backdrop can sit under drawer */
  .hub ~ .sidebar-backdrop,
  .sidebar-backdrop {
    z-index: 65;
  }
}

/* Reduce top marketing nav clutter slightly when sidebar present on desktop */
@media (min-width: 961px) {
  body.lvl-has-site-nav .nav-links a[href="/docs/"],
  body.lvl-has-site-nav .nav-links a[href="/status/"] {
    /* keep — domain sidebar is primary */
  }
}

/* —— Grok Imagine visual layer (domain-wide) —— */
body.lvl-has-site-nav.lvl-marketing-pad {
  background-color: #060912;
  background-image:
    linear-gradient(180deg, rgba(6, 9, 18, 0.88) 0%, rgba(6, 9, 18, 0.96) 100%),
    url("/assets/imagine/bg-mesh.jpg");
  background-size: cover;
  background-position: center top;
  background-attachment: fixed;
}
@media (prefers-reduced-motion: reduce) {
  body.lvl-has-site-nav.lvl-marketing-pad { background-attachment: scroll; }
}
aside.sidebar.lvl-site-sidebar {
  background:
    linear-gradient(175deg, rgba(18, 26, 44, 0.96) 0%, rgba(13, 20, 34, 0.97) 45%, rgba(10, 16, 28, 0.98) 100%),
    url("/assets/imagine/bg-mesh.jpg") center / cover;
  backdrop-filter: blur(14px);
}

/* —— Imagine UI chrome (also in imagine-ui.css; kept for cascade) —— */
aside.sidebar.lvl-site-sidebar {
  background-image:
    linear-gradient(175deg, rgba(12, 18, 32, 0.9) 0%, rgba(8, 12, 22, 0.95) 100%),
    url("/assets/imagine/ui-side.jpg") !important;
  background-size: cover !important;
  background-position: center top !important;
}
.nav-link:hover {
  background: linear-gradient(90deg, rgba(37,99,235,.25), rgba(15,23,42,.5)) !important;
}
.nav-link.active {
  background: linear-gradient(90deg, rgba(37,99,235,.4), rgba(15,23,42,.45)) !important;
  box-shadow: inset 0 0 0 1px rgba(96,165,250,.35);
}
.lvl-nav-fab.menu-btn,
.menu-btn {
  background-image:
    linear-gradient(145deg, rgba(37,99,235,.5), rgba(15,23,42,.7)),
    url("/assets/imagine/ui-btn-primary.jpg") !important;
  background-size: cover !important;
  border-color: rgba(147,197,253,.4) !important;
  color: #fff !important;
}
