/* ============================================================================
   IREX User Guide — layout chrome + guide-specific media.
   Fonts, colors, type scale, lists, tables: docs-site.css
   (→ colors_and_type.css).
   ========================================================================== */

@import url("docs-site.css");

:root {
  /*
    Content column = reading measure (--docs-measure from docs-site.css).
    With left Contents + right On this page, keep one shared width for
    prose, tables, and figures (industry default ~45–48rem).
  */
  --maxw: var(--docs-measure, 50rem);
  --maxw-home: 1080px;
  --navw: 280px;
  --pagetocw: 200px;
  --topbar-h: 4.25rem;
}

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

html {
  -webkit-text-size-adjust: 100%;
  /* Keep in-page anchors / focus targets clear of the sticky topbar */
  scroll-padding-top: calc(var(--topbar-h) + var(--space-4));
  /* Same gutter as docs-site.css — stop topbar jump short↔long pages */
  scrollbar-gutter: stable;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font-body);
  font-size: var(--fs-base);
  line-height: var(--lh-relaxed);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

img { max-width: 100%; height: auto; }

a {
  color: var(--link);
  text-decoration: none;
  border-bottom: 1px solid transparent;
  transition: border-color 0.15s ease, color 0.15s ease;
}
a:hover { color: var(--link); border-bottom-color: currentColor; }
a:active { color: var(--link-press); }

/* ---- App layout: full-width topbar + left nav + content ---------------- */
.guide-app {
  display: grid;
  grid-template-columns: var(--navw) minmax(0, 1fr);
  grid-template-rows: auto 1fr;
  grid-template-areas:
    "top top"
    "nav main";
  min-height: 100vh;
  background: var(--bg);
}

.guide-topbar {
  grid-area: top;
  display: flex;
  align-items: center;
  gap: var(--space-4);
  min-height: var(--topbar-h);
  padding: 0 var(--space-5);
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 50;
  overflow: visible;
}
.guide-topbar-brand {
  display: flex;
  align-items: center;
  text-decoration: none;
  flex-shrink: 0;
}
.guide-topbar-brand:hover { text-decoration: none; }
.guide-topbar-brand img { height: 34px; width: auto; display: block; }
.guide-topbar-tag {
  font-family: var(--font-head);
  font-weight: 600;
  font-size: 0.6875rem;
  letter-spacing: var(--tracking-label);
  text-transform: uppercase;
  color: var(--fg-subtle);
}
/* Legacy: tag alone on the right (home before docs-topnav) */
.guide-topbar:not(:has(.docs-topnav)):not(:has(.guide-topbar-back)) .guide-topbar-tag {
  margin-left: auto;
}
.guide-topbar-back {
  margin-left: auto;
  font-family: var(--font-head);
  font-weight: 600;
  font-size: 0.8125rem;
  color: var(--link);
  text-decoration: none;
  border-bottom: 1px solid transparent;
  transition: border-color 0.15s ease, color 0.15s ease;
}
.guide-topbar:has(.docs-topnav) .guide-topbar-back {
  margin-left: 0;
  display: none; /* User Guide nav link replaces Guide home */
}
.guide-topbar-back:hover {
  color: var(--link);
  border-bottom-color: currentColor;
  text-decoration: none;
}
.guide-topbar-back:active { color: var(--link-press); }

.guide-shell {
  grid-area: main;
  max-width: var(--maxw);
  width: 100%;
  margin: 0;
  padding: var(--space-6) var(--space-5) var(--space-9);
  min-width: 0;
  /* No page TOC: keep the reading column next to the sidenav (not floating mid-screen). */
  justify-self: start;
}
.guide-shell--home { max-width: var(--maxw-home); }

/*
  Topic pages: always reserve the On-this-page column *before* guide.js injects
  .guide-pagetoc. Otherwise the article jumps from left-aligned → centered on
  first paint (CLS). Home shells (.guide-shell--home) stay single-column.
*/
.guide-app .guide-shell:has(> .guide-article):not(.guide-shell--home) {
  display: grid;
  grid-template-columns: minmax(0, 1fr) var(--pagetocw);
  column-gap: var(--space-6);
  max-width: none;
  width: 100%;
  align-items: start;
  justify-self: stretch;
}
.guide-app .guide-shell:has(> .guide-article):not(.guide-shell--home) > .guide-article {
  grid-column: 1;
  min-width: 0;
  max-width: var(--maxw);
  width: 100%;
  justify-self: center;
}
.guide-pagetoc {
  grid-column: 2;
  position: sticky;
  top: calc(var(--topbar-h) + var(--space-6));
  align-self: start;
  max-height: calc(100vh - var(--topbar-h) - var(--space-8));
  overflow: auto;
  padding: 0 0 var(--space-4);
  justify-self: end;
  width: var(--pagetocw);
}
.guide-pagetoc-label {
  margin: 0 0 var(--space-3);
  font-family: var(--font-head);
  font-weight: 600;
  font-size: 0.6875rem;
  letter-spacing: var(--tracking-label);
  text-transform: uppercase;
  color: var(--fg-subtle);
}
.guide-pagetoc-list {
  list-style: none;
  margin: 0;
  padding: 0;
  border-left: 1px solid var(--border);
}
.guide-pagetoc-list a {
  display: block;
  padding: 0.35rem 0 0.35rem 0.75rem;
  margin-left: -1px;
  border-left: 2px solid transparent;
  font-family: var(--font-body);
  font-size: 0.8125rem;
  line-height: 1.35;
  color: var(--fg-muted);
  text-decoration: none;
  border-bottom: 0;
  transition: color 0.15s ease, border-color 0.15s ease;
}
.guide-pagetoc-list a:hover {
  color: var(--fg);
  border-bottom: 0;
  border-left-color: var(--border);
}
.guide-pagetoc-list a[aria-current="location"] {
  color: var(--fg);
  font-weight: 600;
  border-left-color: var(--accent);
}
.guide-pagetoc-list .guide-pagetoc-item--h3 a {
  padding-left: 1.25rem;
}
@media (max-width: 1200px) {
  .guide-app .guide-shell:has(> .guide-article):not(.guide-shell--home) {
    grid-template-columns: minmax(0, 1fr);
    max-width: var(--maxw);
    justify-self: start;
  }
  .guide-app .guide-shell:has(> .guide-article):not(.guide-shell--home) > .guide-article {
    max-width: none;
    justify-self: stretch;
  }
  .guide-pagetoc { display: none; }
}

/* When shell still contains a legacy in-page topbar (before JS moves it), hide border clash —
   BUT only after .guide-app exists. Pre-JS (body > .guide-shell) keeps topbar visible below. */
.guide-app .guide-shell > .guide-topbar { display: none; }

/*
  Pre-JS first paint: reserve the final desktop chrome so content does not jump
  when guide.js wraps into .guide-app and injects the sidenav.
  (Heavy pages / cold cache make the defer gap more visible — e.g. set-up-right-of-way-violations.)
*/
body > .guide-shell {
  margin-left: var(--navw);
  padding-top: calc(var(--topbar-h) + var(--space-6));
}
body > .guide-shell > .guide-topbar {
  display: flex;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  width: 100%;
  margin: 0;
  z-index: 50;
}
body > .guide-shell::before {
  content: "";
  position: fixed;
  top: var(--topbar-h);
  left: 0;
  bottom: 0;
  width: var(--navw);
  border-right: 1px solid var(--border);
  background: var(--bg);
  pointer-events: none;
  z-index: 30;
}
@media (max-width: 960px) {
  body > .guide-shell {
    margin-left: 0;
    padding-top: calc(var(--topbar-h) + var(--space-5));
  }
  body > .guide-shell::before { display: none; }
}

.guide-sidenav {
  grid-area: nav;
  position: sticky;
  top: var(--topbar-h);
  align-self: start;
  height: calc(100vh - var(--topbar-h));
  display: flex;
  flex-direction: column;
  background: var(--bg);
  border-right: 1px solid var(--border);
  z-index: 40;
}

.guide-sidenav-head {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  /* Match .guide-shell content top padding so TOC label aligns with page eyebrow */
  padding: var(--space-6) var(--space-4) var(--space-3);
  flex-shrink: 0;
}

.guide-sidenav-label {
  margin: 0;
  font-family: var(--font-head);
  font-weight: 600;
  font-size: 0.6875rem;
  letter-spacing: var(--tracking-label);
  text-transform: uppercase;
  color: var(--accent);
}

.guide-sidenav-close {
  display: none;
  margin-left: auto;
  width: 2rem;
  height: 2rem;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--fg-muted);
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
}
.guide-sidenav-close:hover { color: var(--accent); }

.guide-sidenav-scroll {
  overflow: auto;
  padding: 0 var(--space-3) var(--space-7);
  flex: 1;
}

.guide-sidenav-list {
  list-style: none;
  margin: 0;
  padding: 0;
}
.guide-sidenav-list--nested {
  margin: 0.15rem 0 0.35rem 0.55rem;
  padding-left: 0.55rem;
  border-left: 1px solid var(--border);
  display: none;
}
.guide-sidenav-item--branch.is-open > .guide-sidenav-list--nested {
  display: block;
}

.guide-sidenav-row {
  display: flex;
  align-items: flex-start;
  gap: 0.15rem;
}

.guide-sidenav-link {
  flex: 1;
  min-width: 0;
  display: block;
  padding: 0.4rem 0.5rem;
  border-radius: var(--radius-sm);
  font-family: var(--font-body);
  font-weight: 500;
  font-size: 0.8125rem;
  line-height: 1.35;
  color: var(--fg-muted);
  text-decoration: none;
  border-left: 2px solid transparent;
  border-bottom: 0;
}
.guide-sidenav-link:hover {
  color: var(--link);
  background: var(--teal-wash);
  text-decoration: none;
  border-bottom-color: transparent;
}
.guide-sidenav-item--branch > .guide-sidenav-row > .guide-sidenav-link {
  font-family: var(--font-head);
  font-weight: 600;
  color: var(--fg);
  font-size: 0.8125rem;
}
.guide-sidenav-list--nested .guide-sidenav-item--branch > .guide-sidenav-row > .guide-sidenav-link {
  font-family: var(--font-body);
  font-weight: 600;
  font-size: 0.8125rem;
}
/* Active: restrained teal wash + red accent bar (brand-aligned) */
li.is-active > .guide-sidenav-row > .guide-sidenav-link,
.guide-sidenav-link[aria-current="page"] {
  color: var(--irex-teal);
  background: var(--teal-wash);
  font-weight: 600;
  border-left-color: var(--irex-red);
}
li.is-active > .guide-sidenav-row > .guide-sidenav-link:hover,
.guide-sidenav-link[aria-current="page"]:hover {
  color: var(--teal-press);
  background: var(--teal-wash);
}

.guide-sidenav-toggle {
  flex-shrink: 0;
  width: 1.5rem;
  height: 1.5rem;
  margin-top: 0.2rem;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--fg-subtle);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.guide-sidenav-toggle:hover {
  background: var(--neutral-150);
  color: var(--fg);
}
.guide-sidenav-toggle span {
  display: block;
  width: 0;
  height: 0;
  border-left: 5px solid currentColor;
  border-top: 4px solid transparent;
  border-bottom: 4px solid transparent;
  transform: rotate(0deg);
  transition: transform 0.15s ease;
}
.guide-sidenav-item--branch.is-open > .guide-sidenav-row > .guide-sidenav-toggle span {
  transform: rotate(90deg);
}

.guide-nav-open-btn {
  display: none;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font-head);
  font-weight: 600;
  font-size: 0.6875rem;
  letter-spacing: var(--tracking-label);
  text-transform: uppercase;
  padding: 0.4rem 0.65rem;
  cursor: pointer;
}
.guide-nav-open-btn:hover { border-color: var(--irex-teal); color: var(--irex-teal); }

.guide-nav-backdrop {
  display: none;
}

/* Hide leftover breadcrumb chrome in topic bodies */
.guide-content .CHBreadcrumb { display: none; }

@media (max-width: 960px) {
  .guide-app {
    grid-template-columns: 1fr;
    grid-template-areas:
      "top"
      "main";
  }
  .guide-sidenav {
    position: fixed;
    left: 0;
    top: 0;
    height: 100vh;
    width: min(320px, 88vw);
    transform: translateX(-105%);
    transition: transform 0.2s ease;
    box-shadow: none;
    border-right: 1px solid var(--border);
    z-index: 60;
  }
  html.guide-nav-open .guide-sidenav {
    transform: translateX(0);
    box-shadow: var(--shadow-md);
  }
  .guide-sidenav-close { display: inline-flex; align-items: center; justify-content: center; }
  .guide-nav-open-btn { display: inline-block; }
  .guide-nav-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(38, 39, 40, 0.4);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
    z-index: 55;
  }
  html.guide-nav-open .guide-nav-backdrop {
    opacity: 1;
    pointer-events: auto;
  }
  html.guide-nav-open { overflow: hidden; }
}

@media (max-width: 960px) {
  .guide-topbar {
    flex-wrap: nowrap;
    gap: var(--space-3);
    padding: 0 var(--space-4);
  }
}

@media (max-width: 640px) {
  .guide-shell { padding: var(--space-5) var(--space-4) var(--space-7); }
  .guide-topbar {
    flex-wrap: nowrap;
    min-height: var(--topbar-h);
    padding: 0 var(--space-4);
  }
}

.guide-eyebrow {
  font-family: var(--font-head);
  font-weight: var(--w-semibold);
  font-size: var(--fs-label);
  letter-spacing: var(--tracking-label);
  text-transform: uppercase;
  color: var(--accent);
  margin: 0 0 var(--space-3);
}

.guide-title {
  font-family: var(--font-head);
  font-weight: var(--w-bold);
  font-size: var(--docs-title);
  line-height: var(--lh-snug);
  letter-spacing: var(--tracking-tight);
  margin: 0 0 var(--space-4);
  color: var(--fg);
}

.guide-lead {
  font-size: var(--docs-lead);
  line-height: var(--lh-relaxed);
  color: var(--fg-muted);
  margin: 0 0 var(--space-7);
  max-width: 40rem;
}
.guide-lead code {
  font-size: 0.9em;
  background: var(--bg-subtle);
  padding: 0.1em 0.35em;
  border-radius: var(--radius-sm);
}

.guide-home-header { margin-bottom: var(--space-6); }

.guide-article { min-width: 0; }

/* YouTube / video embeds — full reading-column width, 16:9 */
.guide-content iframe.guide-video,
.guide-content iframe[src*="youtube.com/embed"],
.guide-content iframe[src*="youtube-nocookie.com/embed"],
.guide-content iframe[data-youtube] {
  display: block;
  width: 100%;
  max-width: var(--docs-measure, 50rem);
  aspect-ratio: 16 / 9;
  height: auto;
  margin: var(--space-4) 0 var(--space-5);
  border: 0;
  border-radius: var(--radius-md);
  background: #000;
}

/* Prose (type, lists, tables, callouts) comes from docs-site.css via .guide-content */

/* Content screenshots:
   - width: up to the full article column (as originally on the grid)
   - height: capped so tall panels don't dominate
   - width:auto avoids upscaling tiny dialogs beyond intrinsic size
   - lightbox shows full resolution */
.guide-content img,
.guide-content img.screenshot,
.guide-content img.guide-shot {
  display: block;
  width: auto;
  max-width: 100%;
  max-height: min(70vh, 420px);
  height: auto;
  object-fit: contain;
  object-position: center top;
  margin: var(--space-4) auto var(--space-5);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  background: var(--bg-subtle);
  cursor: zoom-in;
}

/* Inline UI icons (sliders, 3-dots, note glyphs) stay compact in the text flow */
.guide-content img.guide-icon {
  display: inline-block;
  width: auto;
  max-width: 1.75rem;
  height: 1.25em;
  margin: 0 0.2em;
  vertical-align: -0.2em;
  border: 0;
  border-radius: 0;
  box-shadow: none;
  background: transparent;
  cursor: default;
}

/* Side-by-side figure rows (legacy w3-row / w3-half layout) */
.guide-content .guide-cols {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--space-4);
  margin: 0 0 var(--space-5);
  max-width: var(--docs-measure, 50rem);
}
.guide-content .guide-cols__col { min-width: 0; }
.guide-content .guide-cols img.guide-shot {
  margin-top: var(--space-2);
  margin-bottom: var(--space-2);
}
@media (max-width: 640px) {
  .guide-content .guide-cols { grid-template-columns: 1fr; }
}

/* ---- Figures: diagrams authored as inline SVG -------------------------- */
.guide-content figure {
  margin: var(--space-2) 0 var(--space-6);
  max-width: var(--docs-measure, 50rem);
}
/* Narrow viewports scroll the diagram instead of shrinking its labels to
   nothing — min-width keeps SVG text legible on a phone. */
.guide-content .guide-figscroll { overflow-x: auto; }
.guide-content figure svg {
  display: block;
  width: 100%;
  height: auto;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
}
.guide-content .guide-figscroll svg { min-width: 640px; }
.guide-content figcaption {
  margin-top: var(--space-3);
  font-size: var(--fs-sm);
  line-height: var(--lh-normal);
  color: var(--fg-subtle);
}

.guide-code {
  margin: 0 0 var(--space-5);
  padding: var(--space-4);
  background: var(--neutral-100);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  overflow-x: auto;
  font-size: 0.875rem;
  line-height: 1.5;
}
.guide-code code {
  font-family: ui-monospace, "Cascadia Code", "Segoe UI Mono", Consolas, monospace;
  color: var(--fg);
  white-space: pre;
}

.guide-missing-snippet {
  margin: 0 0 var(--space-5);
  padding: var(--space-4);
  background: var(--red-wash);
  border: 1px solid #f0c4cd;
  border-radius: var(--radius-md);
  color: var(--fg);
  font-size: 0.9375rem;
}

.guide-toc-wrap {
  border-top: 1px solid var(--border);
  padding-top: var(--space-6);
}

.guide-toc,
.guide-toc-nested {
  list-style: none;
  margin: 0;
  padding: 0;
}
.guide-toc > li {
  margin: 0 0 var(--space-3);
  padding: var(--space-3) 0;
  border-bottom: 1px solid var(--neutral-150);
}
.guide-toc > li > a {
  font-family: var(--font-head);
  font-weight: 700;
  font-size: 1.0625rem;
  color: var(--fg);
  text-decoration: none;
  border-bottom: 1px solid transparent;
}
.guide-toc > li > a:hover {
  color: var(--link);
  border-bottom-color: currentColor;
  text-decoration: none;
}
.guide-toc-nested {
  margin-top: var(--space-3);
  padding-left: var(--space-5);
}
.guide-toc-nested li { margin: 0 0 var(--space-2); }
.guide-toc-nested a {
  font-family: var(--font-body);
  font-weight: 500;
  font-size: 0.9375rem;
  color: var(--fg);
  text-decoration: none;
  border-bottom: 1px solid transparent;
}
.guide-toc-nested a:hover {
  color: var(--link);
  border-bottom-color: currentColor;
  text-decoration: none;
}

.guide-missing-asset {
  color: var(--fg-muted);
  font-style: italic;
}

@media (max-width: 640px) {
  .guide-shell { padding: var(--space-5) var(--space-4) var(--space-7); }
}
