/* ==========================================================================
   Control System Standards Atlas — Main Stylesheet
   Style: Technical manual. No framework. No animations. No rounded corners.
   ========================================================================== */

/* --- Reset & Base ---------------------------------------------------------- */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  /* Light theme tokens */
  --color-bg:         #f8f8f6;
  --color-bg-panel:   #f2f2ef;
  --color-bg-alt:     #f2f2ef;
  --color-bg-code:    #eeecea;
  --color-bg-elevated: #ffffff;
  --color-bg-stripe:  #fafaf8;
  --color-border:     #c8c8c4;
  --color-border-mid: #a0a09a;
  --color-text:       #1e1e1e;
  --color-text-muted: #5a5a58;
  --color-accent:     #2b5797;
  --color-accent-hover: #1e3e6e;
  --color-warn:       #8b6914;
  --color-warn-bg:    #fdf6e3;
  --color-lifecycle-hover: #e8eff8;
  --color-sidebar-hover:  #e8e8e5;
  --color-sidebar-active: #e8eff8;

  /* Topnav tokens (dark bar in both modes) */
  --color-topnav-bg:           #1a1a1a;
  --color-topnav-text:         #e8e8e8;
  --color-topnav-text-strong:  #ffffff;
  --color-topnav-border:       #333333;
  --color-topnav-link:         #c0c0c0;
  --color-topnav-hover-bg:     #2a2a2a;
  --color-topnav-btn-border:   #555555;

  --font-sans:  system-ui, -apple-system, "Segoe UI", Helvetica, Arial, sans-serif;
  --font-mono:  ui-monospace, "SFMono-Regular", "SF Mono", Menlo, Consolas, monospace;

  --sidebar-width:  240px;
  --context-width:  220px;
  --topnav-height:  44px;
}

html {
  font-size: 16px;
  color: var(--color-text);
  background: var(--color-bg);
}

body {
  font-family: var(--font-sans);
  line-height: 1.6;
  min-height: 100vh;
}

a {
  color: var(--color-accent);
  text-decoration: none;
}
a:hover {
  color: var(--color-accent-hover);
  text-decoration: underline;
}

code, pre, .mono {
  font-family: var(--font-mono);
  font-size: 0.875em;
}

pre {
  background: var(--color-bg-code);
  border: 1px solid var(--color-border);
  padding: 1rem;
  overflow-x: auto;
  margin: 1rem 0;
}

code {
  background: var(--color-bg-code);
  border: 1px solid var(--color-border);
  padding: 0.1em 0.3em;
}

pre code {
  background: none;
  border: none;
  padding: 0;
}

h1, h2, h3, h4, h5, h6 {
  font-weight: 600;
  line-height: 1.3;
  margin-bottom: 0.5rem;
}
h1 { font-size: 1.6rem; margin-top: 0; }
h2 { font-size: 1.3rem; margin-top: 2rem; border-bottom: 1px solid var(--color-border); padding-bottom: 0.3rem; }
h3 { font-size: 1.1rem; margin-top: 1.5rem; }
h4 { font-size: 1rem; margin-top: 1rem; }

p { margin-bottom: 0.875rem; }

ul, ol {
  margin: 0.5rem 0 0.875rem 1.5rem;
}

table {
  border-collapse: collapse;
  width: 100%;
  margin: 1rem 0;
  font-size: 0.9rem;
}
th, td {
  border: 1px solid var(--color-border);
  padding: 0.45rem 0.75rem;
  text-align: left;
  vertical-align: top;
}
th {
  background: var(--color-bg-panel);
  font-weight: 600;
  position: sticky;
  top: 0;
}
tr:nth-child(even) td {
  background: var(--color-bg-stripe);
}

/* --- Top Navigation -------------------------------------------------------- */
.topnav {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--topnav-height);
  background: var(--color-topnav-bg);
  color: var(--color-topnav-text);
  display: flex;
  align-items: center;
  z-index: 100;
  border-bottom: 2px solid var(--color-accent);
}

.topnav__brand {
  padding: 0 1rem;
  font-family: var(--font-mono);
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--color-topnav-text-strong);
  white-space: nowrap;
  text-decoration: none;
  letter-spacing: 0.01em;
}
.topnav__brand:hover {
  color: var(--color-topnav-text-strong);
  text-decoration: none;
}

.topnav__links {
  display: flex;
  list-style: none;
  margin: 0;
  padding: 0;
  gap: 0;
  border-left: 1px solid var(--color-topnav-border);
}
.topnav__links li {
  margin: 0;
}
.topnav__links a {
  display: block;
  padding: 0 0.875rem;
  height: var(--topnav-height);
  line-height: var(--topnav-height);
  color: var(--color-topnav-link);
  font-size: 0.8rem;
  white-space: nowrap;
  border-right: 1px solid var(--color-topnav-border);
  text-decoration: none;
}
.topnav__links a:hover,
.topnav__links a.active {
  color: var(--color-topnav-text-strong);
  background: var(--color-topnav-hover-bg);
  text-decoration: none;
}

.topnav__hamburger {
  display: none;
  margin-left: auto;
  margin-right: 1rem;
  background: none;
  border: 1px solid var(--color-topnav-btn-border);
  color: var(--color-topnav-link);
  padding: 0.25rem 0.5rem;
  cursor: pointer;
  font-size: 1rem;
}

/* --- Site Layout ----------------------------------------------------------- */
.site-body {
  display: grid;
  grid-template-columns: var(--sidebar-width) 1fr var(--context-width);
  grid-template-rows: 1fr;
  grid-template-areas: "sidebar main context";
  min-height: calc(100vh - var(--topnav-height));
  margin-top: var(--topnav-height);
}

/* --- Sidebar --------------------------------------------------------------- */
.sidebar {
  grid-area: sidebar;
  background: var(--color-bg-panel);
  border-right: 1px solid var(--color-border);
  overflow-y: auto;
  position: sticky;
  top: var(--topnav-height);
  height: calc(100vh - var(--topnav-height));
}

.sidebar__section {
  border-bottom: 1px solid var(--color-border);
}

.sidebar__section summary,
.sidebar__heading {
  padding: 0.6rem 0.875rem;
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--color-text-muted);
  cursor: pointer;
  list-style: none;
  user-select: none;
  display: block;
}

.sidebar__section summary::-webkit-details-marker {
  display: none;
}

.sidebar__section summary::after {
  content: " ▶";
  font-size: 0.6rem;
}

.sidebar__section[open] > summary::after {
  content: " ▼";
}

.sidebar__links {
  list-style: none;
  margin: 0;
  padding: 0 0 0.5rem 0;
}

.sidebar__links a {
  display: block;
  padding: 0.3rem 0.875rem 0.3rem 1.25rem;
  font-size: 0.8rem;
  color: var(--color-text);
  text-decoration: none;
  border-left: 2px solid transparent;
}
.sidebar__links a:hover {
  background: var(--color-sidebar-hover);
  text-decoration: none;
}
.sidebar__links a.active {
  border-left-color: var(--color-accent);
  color: var(--color-accent);
  background: var(--color-sidebar-active);
}

/* sub-level indent */
.sidebar__links .sub {
  padding-left: 2rem;
  font-size: 0.78rem;
  color: var(--color-text-muted);
}
.sidebar__links .sub:hover {
  color: var(--color-text);
}

/* --- Main Content ---------------------------------------------------------- */
.main-content {
  grid-area: main;
  padding: 1.5rem 2rem;
  max-width: 900px;
  min-width: 0;
}

.breadcrumb {
  font-size: 0.78rem;
  color: var(--color-text-muted);
  margin-bottom: 1.25rem;
  font-family: var(--font-mono);
}
.breadcrumb a {
  color: var(--color-text-muted);
}
.breadcrumb a:hover {
  color: var(--color-accent);
}
.breadcrumb span {
  padding: 0 0.3em;
}

.page-header {
  margin-bottom: 1.5rem;
  padding-bottom: 1rem;
  border-bottom: 2px solid var(--color-border);
}

.page-header__label {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--color-accent);
  margin-bottom: 0.25rem;
  display: block;
}

/* --- Context Panel --------------------------------------------------------- */
.context-panel {
  grid-area: context;
  background: var(--color-bg-panel);
  border-left: 1px solid var(--color-border);
  overflow-y: auto;
  position: sticky;
  top: var(--topnav-height);
  height: calc(100vh - var(--topnav-height));
  padding: 1rem;
  font-size: 0.8rem;
}

.context-panel__section {
  margin-bottom: 1.25rem;
}

.context-panel__title {
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--color-text-muted);
  margin-bottom: 0.5rem;
  padding-bottom: 0.25rem;
  border-bottom: 1px solid var(--color-border);
}

.context-panel ul {
  list-style: none;
  margin: 0;
  padding: 0;
}
.context-panel li {
  padding: 0.2rem 0;
}
.context-panel a {
  color: var(--color-accent);
  font-size: 0.78rem;
}

/* --- Badges --------------------------------------------------------------- */
.badge {
  display: inline-block;
  font-family: var(--font-mono);
  font-size: 0.68rem;
  font-weight: 600;
  padding: 0.1em 0.4em;
  border: 1px solid;
  vertical-align: middle;
  margin-left: 0.25em;
}

.badge--verify {
  color: var(--color-warn);
  border-color: var(--color-warn);
  background: var(--color-warn-bg);
}

.badge--local {
  color: #1a6b1a;
  border-color: #4a9a4a;
  background: #f0faf0;
}

.badge--gap {
  color: #7a1a1a;
  border-color: #aa4a4a;
  background: #fdf0f0;
}

.badge--inferred {
  color: #5a3a00;
  border-color: #8a6a00;
  background: #fdfae8;
}

/* --- Standards Cards ------------------------------------------------------- */
.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 1rem;
  margin: 1.25rem 0;
}

.card {
  border: 1px solid var(--color-border);
  padding: 1rem;
  background: var(--color-bg-elevated);
}

.card__label {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--color-accent);
  display: block;
  margin-bottom: 0.3rem;
}

.card__title {
  font-size: 0.95rem;
  font-weight: 600;
  margin-bottom: 0.4rem;
  display: block;
  color: var(--color-text);
}

.card__desc {
  font-size: 0.8rem;
  color: var(--color-text-muted);
  margin-bottom: 0.6rem;
}

.card__path {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: var(--color-text-muted);
  border-top: 1px solid var(--color-border);
  padding-top: 0.5rem;
  margin-top: 0.5rem;
}

.card__link {
  display: inline-block;
  margin-top: 0.5rem;
  font-size: 0.8rem;
  color: var(--color-accent);
  font-weight: 600;
}

/* --- Lifecycle Ribbon ------------------------------------------------------ */
.lifecycle-ribbon {
  display: flex;
  gap: 0;
  overflow-x: auto;
  margin: 1.25rem 0;
  border: 1px solid var(--color-border);
}

.lifecycle-stage {
  flex: 1;
  min-width: 100px;
  padding: 0.75rem 0.5rem;
  border-right: 1px solid var(--color-border);
  text-align: center;
  background: var(--color-bg-elevated);
}
.lifecycle-stage:last-child {
  border-right: none;
}
.lifecycle-stage:hover {
  background: var(--color-lifecycle-hover);
}

.lifecycle-stage__num {
  display: block;
  font-family: var(--font-mono);
  font-size: 0.65rem;
  color: var(--color-text-muted);
  margin-bottom: 0.2rem;
}
.lifecycle-stage__name {
  display: block;
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--color-text);
  margin-bottom: 0.2rem;
}
.lifecycle-stage__std {
  display: block;
  font-size: 0.65rem;
  color: var(--color-accent);
  font-family: var(--font-mono);
}

/* --- Scenario Cards -------------------------------------------------------- */
.scenario-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1rem;
  margin: 1.25rem 0;
}

.scenario-card {
  border: 1px solid var(--color-border);
  padding: 1rem;
  background: var(--color-bg-elevated);
}

.scenario-card__num {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  color: var(--color-text-muted);
  display: block;
  margin-bottom: 0.25rem;
}

.scenario-card__title {
  font-size: 0.95rem;
  font-weight: 600;
  display: block;
  margin-bottom: 0.4rem;
  color: var(--color-text);
}

.scenario-card__start {
  font-size: 0.78rem;
  color: var(--color-text-muted);
  margin-bottom: 0.4rem;
}
.scenario-card__start strong {
  color: var(--color-text);
}

/* --- Trust Boundary -------------------------------------------------------- */
.trust-boundary {
  margin-top: 2.5rem;
  border: 1px solid var(--color-border);
  border-top: 3px solid var(--color-warn);
  padding: 1rem 1.25rem;
  background: var(--color-warn-bg);
  font-size: 0.82rem;
}

.trust-boundary__title {
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--color-warn);
  margin-bottom: 0.5rem;
}

/* --- Repo Tree Preview ----------------------------------------------------- */
.repo-tree {
  background: var(--color-bg-code);
  border: 1px solid var(--color-border);
  padding: 1rem;
  font-family: var(--font-mono);
  font-size: 0.8rem;
  overflow-x: auto;
  margin: 1rem 0;
}
.repo-tree a {
  color: var(--color-accent);
}

/* --- Mermaid diagrams ------------------------------------------------------ */
.mermaid-wrap {
  overflow-x: auto;
  margin: 1rem 0;
  border: 1px solid var(--color-border);
  padding: 1rem;
  background: #ffffff;
}

/* --- Hero ------------------------------------------------------------------ */
.hero {
  margin-bottom: 2.5rem;
  padding: 1.5rem 0 1.5rem 0;
  border-bottom: 2px solid var(--color-border);
}

.hero__title {
  font-size: 1.8rem;
  font-weight: 700;
  margin-bottom: 0.5rem;
  color: var(--color-text);
}

.hero__subtitle {
  font-size: 1rem;
  color: var(--color-text-muted);
  margin-bottom: 1.25rem;
  max-width: 600px;
}

.hero__cta {
  display: inline-block;
  padding: 0.45rem 1.1rem;
  border: 1px solid var(--color-accent);
  color: var(--color-accent);
  font-size: 0.875rem;
  font-weight: 600;
  margin-right: 0.75rem;
  text-decoration: none;
}
.hero__cta:hover {
  background: var(--color-accent);
  color: #ffffff;
  text-decoration: none;
}
.hero__cta--secondary {
  border-color: var(--color-border-mid);
  color: var(--color-text);
}
.hero__cta--secondary:hover {
  background: var(--color-border);
  color: var(--color-text);
}

/* --- Section headers in homepage ------------------------------------------ */
.section-label {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--color-text-muted);
  margin-bottom: 0.25rem;
  display: block;
}

/* --- Responsive: Tablet (768-1023px) -------------------------------------- */
@media (max-width: 1023px) {
  .site-body {
    grid-template-columns: var(--sidebar-width) 1fr;
    grid-template-areas: "sidebar main";
  }
  .context-panel {
    display: none;
  }
}

/* --- Responsive: Mobile (<768px) ------------------------------------------ */
@media (max-width: 767px) {
  .site-body {
    grid-template-columns: 1fr;
    grid-template-areas: "main";
  }
  .sidebar {
    display: none;
    position: fixed;
    top: var(--topnav-height);
    left: 0;
    bottom: 0;
    width: var(--sidebar-width);
    z-index: 50;
    box-shadow: 2px 0 8px rgba(0,0,0,0.2);
  }
  .sidebar.is-open {
    display: block;
  }
  .topnav__hamburger {
    display: block;
  }
  .topnav__links {
    display: none;
  }
  .main-content {
    padding: 1rem;
  }
  .lifecycle-ribbon {
    flex-direction: column;
  }
  .lifecycle-stage {
    border-right: none;
    border-bottom: 1px solid var(--color-border);
    text-align: left;
    padding: 0.5rem 1rem;
  }
  .lifecycle-stage:last-child {
    border-bottom: none;
  }
}

/* --- Accessibility: Focus Indicators -------------------------------------- */
:focus-visible {
  outline: 2px solid var(--color-accent);
  outline-offset: 2px;
}

/* Remove default outline only when :focus-visible is supported and not needed */
:focus:not(:focus-visible) {
  outline: none;
}

/* Skip-to-content link for keyboard users */
.skip-link {
  position: absolute;
  top: -40px;
  left: 0;
  background: var(--color-accent);
  color: #fff;
  padding: 0.4rem 0.8rem;
  z-index: 200;
  font-size: 0.875rem;
}
.skip-link:focus {
  top: 0;
}

/* ==========================================================================
   Diagram lightbox
   ========================================================================== */
.mermaid {
  cursor: zoom-in;
}

.lightbox-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.78);
  z-index: 500;
  align-items: center;
  justify-content: center;
  padding: 2rem;
}

.lightbox-overlay.is-active {
  display: flex;
}

.lightbox-inner {
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  padding: 2.5rem 1.5rem 1.5rem;
  width: 92vw;
  height: 88vh;
  overflow: hidden;
  position: relative;
  cursor: grab;
  user-select: none;
}

.lightbox-inner svg {
  /* Dimensions set dynamically by JS */
  display: block;
}

.lightbox-hint {
  position: absolute;
  bottom: 0.5rem;
  left: 50%;
  transform: translateX(-50%);
  font-size: 0.7rem;
  color: var(--color-text-muted);
  white-space: nowrap;
  pointer-events: none;
  margin: 0;
}

.lightbox-close {
  position: absolute;
  top: 0.5rem;
  right: 0.75rem;
  background: none;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  color: var(--color-text-muted);
  line-height: 1;
  padding: 0.25rem;
}

.lightbox-close:hover {
  color: var(--color-text);
}

/* === Field Engineering ===================================================== */

.checklist-use-context {
  background: var(--color-bg-alt);
  border-left: 3px solid var(--color-accent);
  padding: 0.6rem 1rem;
  margin: 1rem 0 1.5rem;
  font-size: 0.95rem;
}

.checklist-body ul {
  list-style: none;
  padding-left: 0;
}

.checklist-body ul li {
  padding: 0.35rem 0 0.35rem 1.75rem;
  position: relative;
  border-bottom: 1px solid var(--color-border);
}

.checklist-body ul li::before {
  content: "☐";
  position: absolute;
  left: 0;
  font-size: 1.1rem;
  color: var(--color-text-muted);
}

.field-checklist__cross-links {
  margin-top: 2.5rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--color-border);
  display: flex;
  gap: 2rem;
  flex-wrap: wrap;
}

.cross-links-group h4 {
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--color-text-muted);
  margin-bottom: 0.5rem;
}

.cross-links-group ul {
  list-style: none;
  padding: 0;
  margin: 0;
}

.cross-links-group ul li {
  margin-bottom: 0.3rem;
  font-size: 0.9rem;
}

.field-checklist__back-link {
  margin-top: 2rem;
  font-size: 0.9rem;
}

/* ==========================================================================
   Template header (commissioning templates)
   ========================================================================== */
.template-header {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.6rem 1.5rem;
  border: 1px solid var(--color-border);
  border-radius: 4px;
  padding: 1rem 1.25rem;
  margin-bottom: 1.5rem;
}
.template-header__field {
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
}
.template-header__label {
  font-size: 0.8rem;
  white-space: nowrap;
  color: var(--color-text-muted);
}
.template-header__line {
  flex: 1;
  border-bottom: 1px solid var(--color-border);
  min-width: 60px;
}

/* Checklist items */
.checklist-body li.checklist-item {
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
  list-style: none;
  padding: 0.2rem 0;
}
.checklist-body ul { padding-left: 0; }

/* Sidebar group labels */
.sidebar__group-label {
  font-size: 0.7rem;
  text-transform: uppercase;
  color: var(--color-text-muted);
  padding: 0.4rem 1rem 0.1rem;
  letter-spacing: 0.05em;
}

@media print {
  .lightbox-overlay { display: none !important; }
  .checklist-item__checkbox {
    -webkit-appearance: none;
    appearance: none;
    width: 11px;
    height: 11px;
    border: 1px solid #000;
    flex-shrink: 0;
    margin-top: 2px;
  }
}

/* ==========================================================================
   Print stylesheet
   ========================================================================== */
@media print {
  .topnav,
  .sidebar,
  .context-panel,
  .skip-link,
  #sidebar-toggle,
  .trust-boundary {
    display: none !important;
  }

  .site-body {
    display: block;
  }

  .main-content {
    margin: 0;
    padding: 0;
    max-width: 100%;
    width: 100%;
  }

  a[href]:after {
    content: " (" attr(href) ")";
    font-size: 0.85em;
    color: #555;
  }

  a[href^="#"]:after,
  a[href^="javascript:"]:after {
    content: "";
  }

  h2, h3 {
    page-break-after: avoid;
  }

  table {
    page-break-inside: avoid;
  }

  pre {
    page-break-inside: avoid;
    white-space: pre-wrap;
  }

  /* Field Engineering print */
  .field-checklist__cross-links,
  .field-checklist__back-link { display: none; }
}

/* ==========================================================================
   Search
   ========================================================================== */
.topnav__search {
  position: relative;
  margin-left: auto;
  margin-right: 0.75rem;
}

.topnav__search-input {
  background: #2a2a2a;
  border: 1px solid #444;
  color: #e8e8e8;
  font-family: var(--font-sans);
  font-size: 0.8rem;
  padding: 0.3rem 0.6rem;
  width: 180px;
  outline: none;
}

.topnav__search-input::placeholder {
  color: #888;
}

.topnav__search-input:focus {
  border-color: var(--color-accent);
  width: 220px;
  transition: width 0.15s;
}

.search-dropdown {
  display: none;
  position: absolute;
  top: calc(100% + 4px);
  right: 0;
  min-width: 280px;
  background: #fff;
  border: 1px solid var(--color-border);
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
  z-index: 200;
  max-height: 320px;
  overflow-y: auto;
}

.search-dropdown.is-open {
  display: block;
}

.search-result {
  display: block;
  padding: 0.5rem 0.75rem;
  color: var(--color-text);
  border-bottom: 1px solid var(--color-border);
  text-decoration: none;
}

.search-result:last-child {
  border-bottom: none;
}

.search-result:hover,
.search-result.is-selected {
  background: var(--color-bg-panel);
}

.search-result__section {
  display: block;
  font-size: 0.7rem;
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 0.1rem;
}

.search-result__title {
  font-size: 0.875rem;
  font-weight: 500;
}

.search-dropdown__empty {
  padding: 0.6rem 0.75rem;
  color: var(--color-text-muted);
  font-size: 0.875rem;
}

@media (max-width: 768px) {
  .topnav__search { display: none; }
}

@media print {
  .topnav__search { display: none !important; }
}

/* ==========================================================================
   Crosswalk comparison selector
   ========================================================================== */
.compare-selector {
  display: flex;
  gap: 1rem;
  align-items: center;
  margin: 1.5rem 0;
  flex-wrap: wrap;
}

.compare-selector select {
  border: 1px solid var(--color-border);
  background: var(--color-bg);
  font-family: var(--font-sans);
  font-size: 0.9rem;
  padding: 0.4rem 0.6rem;
  min-width: 180px;
}

.compare-selector__vs {
  font-weight: 600;
  color: var(--color-text-muted);
}

.compare-result {
  margin-top: 1.5rem;
}

.compare-result[hidden] {
  display: none;
}

.compare-no-data {
  background: var(--color-bg-panel);
  border: 1px solid var(--color-border);
  padding: 1rem;
  color: var(--color-text-muted);
  font-size: 0.9rem;
  margin-top: 1.5rem;
}

.compare-no-data[hidden] {
  display: none;
}

/* --- Glossary ------------------------------------------------------------- */
.glossary-az {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem 0.5rem;
  padding: 0.75rem 0;
  border-top: 1px solid var(--color-border);
  border-bottom: 1px solid var(--color-border);
  margin-bottom: 2rem;
  font-family: var(--font-mono);
  font-size: 0.85rem;
}

.glossary-az a {
  color: var(--color-accent);
  font-weight: 600;
  text-decoration: none;
  padding: 0.1em 0.3em;
}

.glossary-az a:hover {
  text-decoration: underline;
}

.glossary-letter {
  font-family: var(--font-mono);
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--color-text-muted);
  border-bottom: 1px solid var(--color-border);
  margin: 2rem 0 1rem;
  padding-bottom: 0.25rem;
}

.glossary-entry {
  margin-bottom: 1.75rem;
  padding: 1rem 1.25rem;
  border: 1px solid var(--color-border);
  border-radius: 4px;
}

.glossary-entry__header {
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-bottom: 0.5rem;
}

.glossary-entry__acronym {
  font-family: var(--font-mono);
  font-size: 1rem;
  font-weight: 700;
  color: var(--color-text);
}

.glossary-entry__term {
  font-size: 0.9rem;
  color: var(--color-text-muted);
}

.glossary-entry__definition {
  margin: 0.5rem 0 0.75rem;
  font-size: 0.92rem;
  line-height: 1.6;
}

.glossary-entry__meta {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 0.2rem 1rem;
  font-size: 0.82rem;
  margin: 0;
}

.glossary-entry__meta dt {
  font-family: var(--font-mono);
  font-weight: 600;
  color: var(--color-text-muted);
  white-space: nowrap;
}

.glossary-entry__meta dd {
  margin: 0;
}

.glossary-entry__meta a {
  color: var(--color-accent);
  text-decoration: none;
}

.glossary-entry__meta a:hover {
  text-decoration: underline;
}

/* Domain badge variants */
.badge--domain {
  font-size: 0.62rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.badge--domain-safety {
  color: #1a5c8a;
  border-color: #4a8cba;
  background: #eef5fb;
}

.badge--domain-electrical {
  color: #5a3a00;
  border-color: #8a6a00;
  background: #fdfae8;
}

.badge--domain-standards-bodies {
  color: #1a6b1a;
  border-color: #4a9a4a;
  background: #f0faf0;
}

.badge--domain-regulatory {
  color: #5a1a6b;
  border-color: #8a4a9a;
  background: #faf0fd;
}

/* --- Dark theme ------------------------------------------------------------ */
[data-theme="dark"] {
  --color-bg:            #1a1a1a;
  --color-bg-panel:      #242424;
  --color-bg-alt:        #242424;
  --color-bg-code:       #2a2a2a;
  --color-bg-elevated:   #252525;
  --color-bg-stripe:     #1f1f1f;
  --color-border:        #3a3a3a;
  --color-border-mid:    #505050;
  --color-text:          #e8e8e6;
  --color-text-muted:    #9a9a98;
  --color-accent:        #6b9fd4;
  --color-accent-hover:  #8ab8e8;
  --color-warn:          #d4a84b;
  --color-warn-bg:       #2a2000;
  --color-lifecycle-hover: #1e2a38;
  --color-sidebar-hover:  #2e2e2e;
  --color-sidebar-active: #1a2a3a;

  /* Topnav slightly darker in dark mode */
  --color-topnav-bg:      #0f0f0f;
  --color-topnav-border:  #222222;
  --color-topnav-hover-bg: #1f1f1f;
  --color-topnav-btn-border: #444444;
}

/* OS-level dark preference — fallback when JS hasn't set data-theme yet */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --color-bg:            #1a1a1a;
    --color-bg-panel:      #242424;
    --color-bg-code:       #2a2a2a;
    --color-bg-elevated:   #252525;
    --color-bg-stripe:     #1f1f1f;
    --color-border:        #3a3a3a;
    --color-border-mid:    #505050;
    --color-text:          #e8e8e6;
    --color-text-muted:    #9a9a98;
    --color-accent:        #6b9fd4;
    --color-accent-hover:  #8ab8e8;
    --color-warn:          #d4a84b;
    --color-warn-bg:       #2a2000;
    --color-lifecycle-hover: #1e2a38;
    --color-sidebar-hover:  #2e2e2e;
    --color-sidebar-active: #1a2a3a;
    --color-topnav-bg:      #0f0f0f;
    --color-topnav-border:  #222222;
    --color-topnav-hover-bg: #1f1f1f;
    --color-topnav-btn-border: #444444;
  }
}

/* Theme toggle button */
.topnav__theme-toggle {
  background: none;
  border: 1px solid var(--color-topnav-btn-border);
  color: var(--color-topnav-link);
  padding: 0.2rem 0.5rem;
  cursor: pointer;
  font-size: 0.95rem;
  margin-left: 0.5rem;
  line-height: 1;
  flex-shrink: 0;
}
.topnav__theme-toggle:hover {
  color: var(--color-topnav-text-strong);
  border-color: var(--color-topnav-btn-border);
}

/* ============================================================
   Standards Relationship Graph
   ============================================================ */

.standards-graph-wrap {
  margin: 1.5rem 0;
}

.standards-graph-canvas {
  width: 100%;
  background: var(--color-bg-elevated);
  border: 1px solid var(--color-border);
  border-radius: 6px;
}

.standards-graph-wrap--full .standards-graph-canvas {
  height: 520px;
}

.standards-graph-wrap--mini .standards-graph-canvas {
  height: 280px;
  pointer-events: none; /* disable pan/zoom on mini */
}

.standards-graph-link {
  text-align: right;
  font-size: 0.8rem;
  margin: 0.4rem 0 0;
}

/* Legend */
.standards-graph-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.75rem;
  font-size: 0.75rem;
}

.legend-item {
  padding: 2px 8px;
  border-radius: 3px;
  color: #fff;
  font-weight: 500;
}

.legend-item--requires    { background: #f59e0b; }
.legend-item--pairs-with  { background: #3b82f6; }
.legend-item--enforces    { background: #10b981; }
.legend-item--aligns-with { background: #9ca3af; }
.legend-item--planned     { background: transparent; border: 2px dashed #9ca3af; color: var(--color-text-muted); }

/* ============================================================
   RAG File Browser
   ============================================================ */

/* Override site-body grid for the browser page */
.rag-browser-body .site-body {
  display: grid;
  grid-template-columns: 280px 1fr;
  grid-template-rows: 1fr;
  height: calc(100vh - var(--topnav-height, 48px));
  overflow: hidden;
}

/* Hide normal sidebar on browser page — tree panel replaces it */
.rag-browser-body .sidebar {
  display: none;
}

/* ---- Tree panel ------------------------------------------ */
.rag-tree-panel {
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--color-border);
  background: var(--color-sidebar-bg, var(--color-bg-alt));
  overflow: hidden;
}

.rag-tree-header {
  padding: 0.75rem 1rem 0.5rem;
  border-bottom: 1px solid var(--color-border);
  flex-shrink: 0;
}

.rag-tree-root {
  display: block;
  font-size: 0.7rem;
  color: var(--color-text-muted);
  margin-top: 0.2rem;
  word-break: break-all;
}

.rag-tree-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 0.5rem 0;
}

/* Tree structure */
.rag-tree {
  list-style: none;
  margin: 0;
  padding: 0;
}

.rag-tree--nested {
  padding-left: 1rem;
  border-left: 1px solid var(--color-border);
  margin-left: 0.6rem;
}

/* Dir node */
.rag-tree__dir {
  margin: 0;
}

.rag-dir-details {
  margin: 0;
}

.rag-dir-details > summary {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.3rem 0.75rem;
  cursor: pointer;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--color-text);
  list-style: none;
  user-select: none;
}

.rag-dir-details > summary::-webkit-details-marker { display: none; }

.rag-dir-details > summary:hover {
  background: var(--color-hover, rgba(0,0,0,0.05));
}

.rag-icon--dir {
  font-size: 0.6rem;
  transition: transform 0.15s;
  color: var(--color-text-muted);
}

.rag-dir-details[open] > summary .rag-icon--dir {
  transform: rotate(90deg);
}

/* File node */
.rag-tree__file {
  margin: 0;
}

.rag-file-btn {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  width: 100%;
  padding: 0.25rem 0.75rem;
  background: none;
  border: none;
  cursor: pointer;
  font-size: 0.78rem;
  color: var(--color-text-muted);
  text-align: left;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.rag-file-btn:hover {
  background: var(--color-hover, rgba(0,0,0,0.05));
  color: var(--color-text);
}

.rag-file-btn--active {
  background: var(--color-accent, #2563eb);
  color: #fff !important;
}

.rag-icon--file {
  flex-shrink: 0;
  font-size: 0.75rem;
}

/* ---- Main content area ------------------------------------ */
.rag-file-content {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--color-bg);
}

.rag-file-header {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.6rem 1.25rem;
  border-bottom: 1px solid var(--color-border);
  background: var(--color-bg-alt);
  flex-shrink: 0;
  min-height: 42px;
}

.rag-file-path {
  font-family: var(--font-mono, monospace);
  font-size: 0.78rem;
  color: var(--color-text-muted);
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.rag-raw-link {
  font-size: 0.75rem;
  flex-shrink: 0;
}

.rag-file-body {
  flex: 1;
  overflow-y: auto;
  padding: 1.5rem 2rem;
}

/* Prose resets inside browser */
.rag-file-body h1 { font-size: 1.5rem; margin-top: 0; }
.rag-file-body h2 { font-size: 1.2rem; }
.rag-file-body h3 { font-size: 1rem; }
.rag-file-body table { border-collapse: collapse; width: 100%; font-size: 0.85rem; }
.rag-file-body th, .rag-file-body td { border: 1px solid var(--color-border); padding: 0.4rem 0.6rem; }
.rag-file-body th { background: var(--color-bg-alt); }
.rag-file-body pre { background: var(--color-bg-alt); padding: 1rem; border-radius: 4px; overflow-x: auto; }
.rag-file-body code { font-size: 0.85em; }
.rag-file-body blockquote { border-left: 3px solid var(--color-accent, #2563eb); padding-left: 1rem; color: var(--color-text-muted); margin-left: 0; }

/* States */
.rag-placeholder, .rag-loading { color: var(--color-text-muted); font-style: italic; }
.rag-error { color: var(--color-danger, #dc2626); }

/* ─── Training curriculum ──────────────────────────────────────────────────── */

/* Verification note */
.training-verification {
  background: var(--color-bg-alt);
  border-left: 3px solid var(--color-accent, #2563eb);
  border-radius: 0 4px 4px 0;
  padding: 0.75rem 1rem;
  margin-bottom: 2rem;
  font-size: 0.9rem;
  color: var(--color-text-muted);
}

/* Start-here cards */
.start-here-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1rem;
  margin: 1.25rem 0 2rem;
}
.start-here-card {
  background: var(--color-bg-alt);
  border: 1px solid var(--color-border);
  border-radius: 6px;
  padding: 1rem 1.25rem;
}
.start-here-card h4 {
  margin: 0 0 0.4rem;
  font-size: 0.95rem;
}
.start-here-card p {
  margin: 0 0 0.6rem;
  font-size: 0.85rem;
  color: var(--color-text-muted);
}
.start-here-card ul {
  margin: 0;
  padding-left: 1.1rem;
  font-size: 0.85rem;
}

/* Learning path cards */
.learning-paths-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1rem;
  margin: 1.25rem 0 2rem;
}
.learning-path-card {
  border: 1px solid var(--color-border);
  border-radius: 6px;
  padding: 1rem 1.25rem;
}
.learning-path-card h4 {
  margin: 0 0 0.4rem;
  font-size: 0.95rem;
}
.learning-path-card p {
  margin: 0;
  font-size: 0.85rem;
  color: var(--color-text-muted);
}

/* Training chips / badges */
.training-chip {
  display: inline-block;
  font-size: 0.72rem;
  font-weight: 600;
  padding: 0.15rem 0.5rem;
  border-radius: 3px;
  margin-right: 0.25rem;
  white-space: nowrap;
  vertical-align: middle;
}
.chip-beginner   { background: #d1fae5; color: #065f46; }
.chip-intermediate { background: #dbeafe; color: #1e40af; }
.chip-advanced   { background: #fef3c7; color: #92400e; }
.chip-concept    { background: #f3f4f6; color: #374151; }
.chip-reference  { background: #e0e7ff; color: #3730a3; }
.chip-code       { background: #fce7f3; color: #9d174d; }
.chip-featured   { background: #fef9c3; color: #713f12; }

[data-theme="dark"] .chip-beginner     { background: #065f46; color: #d1fae5; }
[data-theme="dark"] .chip-intermediate { background: #1e3a8a; color: #bfdbfe; }
[data-theme="dark"] .chip-advanced     { background: #78350f; color: #fde68a; }
[data-theme="dark"] .chip-concept      { background: #374151; color: #e5e7eb; }
[data-theme="dark"] .chip-reference    { background: #312e81; color: #c7d2fe; }
[data-theme="dark"] .chip-code         { background: #831843; color: #fbcfe8; }
[data-theme="dark"] .chip-featured     { background: #713f12; color: #fef08a; }

/* Module table wrapper */
.training-table-wrap {
  overflow-x: auto;
  margin: 1rem 0 2rem;
}
.training-table-wrap table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}
.training-table-wrap th {
  background: var(--color-bg-alt);
  text-align: left;
  padding: 0.5rem 0.75rem;
  border-bottom: 2px solid var(--color-border);
  white-space: nowrap;
}
.training-table-wrap td {
  padding: 0.5rem 0.75rem;
  border-bottom: 1px solid var(--color-border);
  vertical-align: top;
}
.training-table-wrap tr:last-child td { border-bottom: none; }
.training-table-wrap td:first-child { min-width: 200px; }
.training-table-wrap .td-chips { white-space: nowrap; }

/* Featured row highlight */
.training-table-wrap tr.featured-row td:first-child {
  font-weight: 600;
}

/* Browse-by-topic cards (reuse card-grid pattern with label override) */
.topic-group-label {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--color-text-muted);
  margin-bottom: 0.25rem;
}

/* Related standards strip */
.related-standards-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 0.75rem;
  margin: 1rem 0 2rem;
  list-style: none;
  padding: 0;
}
.related-standards-list li {
  background: var(--color-bg-alt);
  border: 1px solid var(--color-border);
  border-radius: 6px;
  padding: 0.75rem 1rem;
  font-size: 0.875rem;
}
.related-standards-list li a {
  font-weight: 600;
  display: block;
  margin-bottom: 0.25rem;
}
.related-standards-list li span {
  color: var(--color-text-muted);
  font-size: 0.8rem;
}

@media (max-width: 640px) {
  .start-here-grid,
  .learning-paths-grid,
  .related-standards-list {
    grid-template-columns: 1fr;
  }
  .training-table-wrap th.hide-mobile,
  .training-table-wrap td.hide-mobile {
    display: none;
  }
}

/* Module metadata bar */
.module-meta-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
  margin: 0.75rem 0 1rem;
  padding: 0.6rem 0.75rem;
  background: var(--color-bg-alt);
  border: 1px solid var(--color-border);
  border-radius: 4px;
  font-size: 0.85rem;
}
.module-meta-item {
  color: var(--color-text-muted);
  white-space: nowrap;
}
.module-meta-item strong {
  color: var(--color-text);
}

/* Module outcome block */
.module-outcome {
  background: var(--color-bg-alt);
  border-left: 3px solid var(--color-accent, #2563eb);
  border-radius: 0 4px 4px 0;
  padding: 0.65rem 1rem;
  margin-bottom: 1.5rem;
  font-size: 0.9rem;
}

/* Module prerequisites */
.module-prereqs {
  font-size: 0.875rem;
  margin-bottom: 1.25rem;
  color: var(--color-text-muted);
}
.module-prereqs strong {
  color: var(--color-text);
}
.module-prereq-item {
  margin-left: 0.25rem;
}

/* =====================================================================
   Workflows section
   ===================================================================== */

.workflow-card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1.25rem;
  margin-bottom: 2rem;
}

.workflow-card {
  border: 1px solid var(--color-border);
  border-radius: 6px;
  padding: 1.25rem;
  background: var(--color-bg);
  transition: border-color 0.15s;
}

.workflow-card:hover {
  border-color: var(--color-accent, #2563eb);
}

.workflow-card-header {
  margin-bottom: 0.6rem;
}

.workflow-card h3 {
  margin: 0.25rem 0 0.5rem;
  font-size: 1rem;
}

.workflow-card p {
  font-size: 0.875rem;
  color: var(--color-text-muted);
  margin: 0 0 0.75rem;
}

.workflow-badge {
  display: inline-block;
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 0.18rem 0.5rem;
  border-radius: 3px;
  margin-bottom: 0.25rem;
}

.workflow-badge.motor {
  background: #dbeafe;
  color: #1e40af;
}
[data-theme="dark"] .workflow-badge.motor {
  background: #1e3a5f;
  color: #93c5fd;
}

.workflow-badge.drive {
  background: #ede9fe;
  color: #5b21b6;
}
[data-theme="dark"] .workflow-badge.drive {
  background: #3b1f6e;
  color: #c4b5fd;
}

.workflow-badge.electrical {
  background: #fef9c3;
  color: #713f12;
}
[data-theme="dark"] .workflow-badge.electrical {
  background: #422006;
  color: #fde68a;
}

.workflow-meta {
  display: flex;
  gap: 0.35rem;
  flex-wrap: wrap;
}

.wf-tag {
  display: inline-block;
  font-size: 0.7rem;
  padding: 0.15rem 0.45rem;
  background: var(--color-bg-alt);
  border: 1px solid var(--color-border);
  border-radius: 3px;
  color: var(--color-text-muted);
}

/* Related workflows block on training module pages */
.related-workflows {
  margin: 1.5rem 0;
  padding: 1rem 1.25rem;
  background: var(--color-bg-alt);
  border-radius: 6px;
  border: 1px solid var(--color-border);
}

.related-workflows h4 {
  margin: 0 0 0.6rem;
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--color-text-muted);
}

.related-workflows ul {
  margin: 0;
  padding-left: 1.2rem;
  font-size: 0.875rem;
}

.related-workflows li {
  margin-bottom: 0.25rem;
}
