:root {
  --bc-blue: #234075;
  --bc-blue-dark: #1a2f57;
  --bc-gold: #e3a82b;
  --ink: #24292f;
  --muted: #5b6470;
  --line: #d8dde3;
  --bg: #f6f7f9;
  --card: #ffffff;
  --accent-bg: #eef2f8;
  --flash: #fff3c4;
  --rev: #b4520f;
  --sidebar-w: 320px;
}
* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  color: var(--ink);
  background: var(--bg);
  font-size: 15px;
  line-height: 1.55;
}

/* ---------- header ---------- */
#topbar {
  position: sticky; top: 0; z-index: 50;
  display: flex; align-items: center; gap: 14px;
  background: var(--bc-blue); color: #fff;
  padding: 8px 16px;
  border-bottom: 3px solid var(--bc-gold);
}
#topbar .brand { color: #fff; text-decoration: none; font-size: 19px; font-weight: 700; letter-spacing: .5px; white-space: nowrap; }
#topbar .brand span { color: var(--bc-gold); }
#nav-toggle { display: none; background: none; border: 1px solid rgba(255,255,255,.4); color: #fff; font-size: 16px; border-radius: 6px; padding: 3px 9px; cursor: pointer; }
.searchwrap { flex: 1; max-width: 560px; }
#searchbox {
  width: 100%; padding: 7px 12px; border-radius: 6px; border: none;
  font-size: 14px; background: rgba(255,255,255,.95);
}
.toplinks { display: flex; gap: 4px; margin-left: auto; }
.toplinks a { color: #e8ecf3; text-decoration: none; font-size: 13.5px; padding: 5px 10px; border-radius: 6px; }
.toplinks a:hover { background: rgba(255,255,255,.12); }

/* ---------- layout ---------- */
#layout { display: flex; min-height: calc(100vh - 50px); }
#sidebar {
  width: var(--sidebar-w); flex: 0 0 var(--sidebar-w);
  background: var(--card); border-right: 1px solid var(--line);
  overflow-y: auto; height: calc(100vh - 50px);
  position: sticky; top: 50px;
  padding: 10px 8px 40px;
  font-size: 13.5px;
}
#content { flex: 1; min-width: 0; padding: 26px 40px 80px; max-width: 1000px; }

/* ---------- sidebar tree ---------- */
#tree .division-h {
  font-weight: 700; color: var(--bc-blue); font-size: 12.5px;
  text-transform: uppercase; letter-spacing: .06em;
  margin: 14px 6px 4px; padding-bottom: 3px; border-bottom: 2px solid var(--bc-gold);
}
#tree details { margin: 0; }
#tree summary {
  cursor: pointer; padding: 4px 6px; border-radius: 6px; list-style: none;
  display: flex; gap: 6px; align-items: baseline; user-select: none;
}
#tree summary::before { content: "▸"; font-size: 10px; color: var(--muted); transition: transform .12s; flex: 0 0 auto; }
#tree details[open] > summary::before { transform: rotate(90deg); }
#tree summary:hover { background: var(--accent-bg); }
#tree .p-num { font-weight: 700; color: var(--bc-blue); white-space: nowrap; }
#tree .sect > summary { padding-left: 18px; font-weight: 600; color: #37414e; }
#tree a.subsect, #tree a.leaf {
  display: block; padding: 3px 6px 3px 38px; color: var(--ink);
  text-decoration: none; border-radius: 6px; font-size: 13px;
}
#tree a.leaf { padding-left: 24px; }
#tree a:hover { background: var(--accent-bg); }
#tree a.active { background: var(--bc-blue); color: #fff; }
#tree .s-num { color: var(--muted); margin-right: 5px; }
#tree a.active .s-num { color: #ffd98a; }

/* ---------- content ---------- */
.loading { color: var(--muted); padding: 40px; text-align: center; }
.crumbs { font-size: 13px; color: var(--muted); margin-bottom: 14px; }
.crumbs a { color: var(--bc-blue); text-decoration: none; }
.crumbs a:hover { text-decoration: underline; }
h1.pagetitle { font-size: 24px; margin: 0 0 4px; color: var(--bc-blue-dark); }
.pagesub { color: var(--muted); margin: 0 0 22px; font-size: 14px; }

.article-block {
  background: var(--card); border: 1px solid var(--line); border-radius: 10px;
  padding: 18px 24px; margin-bottom: 18px;
}
.article-block h3 {
  margin: 0 0 10px; font-size: 17px; color: var(--bc-blue-dark);
  display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap;
}
.article-block h3 .art-num { color: var(--bc-blue); }
.sentence { margin: 8px 0 8px 8px; }
.sentence > .num, .clause > .num, .subclause > .num {
  font-weight: 700; color: var(--bc-blue); margin-right: 6px;
}
.clause { margin: 4px 0 4px 34px; }
.subclause { margin: 3px 0 3px 34px; }
.see-also { color: var(--muted); font-size: 13.5px; margin: 4px 0 4px 8px; }
.deleted { color: var(--muted); font-style: italic; }

/* refs */
a.xref { color: var(--bc-blue); text-decoration: none; border-bottom: 1px solid #b9c6dd; }
a.xref:hover { background: var(--accent-bg); }
a.term { color: inherit; text-decoration: none; border-bottom: 1px dotted var(--bc-gold); font-style: italic; cursor: help; }
a.term:hover { background: #fdf3dd; }
a.std { color: #5a4a9f; text-decoration: none; border-bottom: 1px dotted #b3a8e0; }
a.ext { color: var(--bc-blue); }

/* revision badge */
.rev-badge {
  display: inline-block; font-size: 10.5px; font-weight: 700;
  color: #fff; background: var(--rev); border: none; cursor: pointer;
  padding: 1px 7px; border-radius: 10px; margin-left: 6px; vertical-align: 2px;
}
.rev-history {
  margin: 8px 0 8px 24px; border-left: 3px solid var(--rev);
  background: #fdf6f0; padding: 10px 14px; border-radius: 0 8px 8px 0; font-size: 13.5px;
}
.rev-history h5 { margin: 8px 0 2px; font-size: 12.5px; color: var(--rev); }
.rev-history p { margin: 2px 0; }
.rev-history .rev-note { color: var(--muted); font-size: 12.5px; }

/* tables */
.tablewrap { overflow-x: auto; margin: 14px 0; }
.code-table { border-collapse: collapse; width: 100%; font-size: 13.5px; background: #fff; }
.code-table caption {
  caption-side: top; text-align: center; padding: 8px 6px; font-weight: 700;
  color: var(--bc-blue-dark);
}
.code-table caption .tbl-sub { display: block; font-weight: 400; font-size: 12.5px; color: var(--muted); }
.code-table th, .code-table td { border: 1px solid #c6ccd4; padding: 5px 9px; vertical-align: middle; }
.code-table th { background: var(--accent-bg); }
.table-notes { font-size: 12.5px; color: #44505e; margin: 6px 2px 0; }
.table-notes li { margin: 2px 0; }

/* figures */
figure.code-figure { margin: 18px auto; text-align: center; max-width: 720px; }
figure.code-figure img { max-width: 100%; border: 1px solid var(--line); border-radius: 6px; background: #fff; }
figure.code-figure figcaption { font-size: 13px; color: var(--muted); margin-top: 6px; }

/* equations, symbols */
.equation { margin: 10px 0; text-align: center; overflow-x: auto; }
math { font-size: 1.1em; }
dl.vars { margin: 8px 0 8px 24px; font-size: 13.5px; }
dl.vars dt { font-weight: 700; float: left; clear: left; margin-right: 10px; }
dl.vars dd { margin-left: 90px; margin-bottom: 3px; }
dl.defs dt { font-weight: 700; margin-top: 10px; }
dl.defs dd { margin-left: 20px; }

/* appendix notes */
.appnote-block { background: var(--card); border: 1px solid var(--line); border-left: 4px solid var(--bc-gold); border-radius: 10px; padding: 18px 24px; margin-bottom: 18px; }
.appnote-block h3 { margin: 0 0 10px; color: var(--bc-blue-dark); font-size: 16.5px; }
.note-division h4 { margin: 16px 0 6px; color: var(--bc-blue); font-size: 15px; }

/* cards, home */
.statgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; margin: 18px 0 26px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 14px; text-align: center; }
.stat b { display: block; font-size: 22px; color: var(--bc-blue); }
.stat span { font-size: 12.5px; color: var(--muted); }
.partgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(270px, 1fr)); gap: 12px; margin-top: 14px; }
.partcard {
  background: var(--card); border: 1px solid var(--line); border-radius: 10px;
  padding: 14px 16px; text-decoration: none; color: var(--ink); display: block;
}
.partcard:hover { border-color: var(--bc-blue); box-shadow: 0 2px 10px rgba(35,64,117,.12); }
.partcard b { color: var(--bc-blue); }
.partcard .div-tag { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.disclaimer {
  margin-top: 34px; padding: 14px 18px; background: #fbf3e2;
  border: 1px solid #ecd9a8; border-radius: 10px; font-size: 13px; color: #6b5620;
}

/* search results */
.result { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 12px 18px; margin-bottom: 10px; }
.result a.rtitle { font-weight: 700; color: var(--bc-blue); text-decoration: none; font-size: 15px; }
.result .rsnippet { font-size: 13.5px; color: #44505e; margin-top: 4px; }
.result mark { background: var(--flash); padding: 0 1px; }

/* glossary/standards */
.letter-h { font-size: 20px; color: var(--bc-blue); border-bottom: 2px solid var(--bc-gold); margin: 26px 0 10px; }
.gloss-term { background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: 10px 16px; margin-bottom: 8px; }
.gloss-term b { color: var(--bc-blue-dark); }
.agency-h { font-size: 17px; color: var(--bc-blue); margin: 24px 0 8px; }
.std-table { width: 100%; border-collapse: collapse; font-size: 13.5px; background: #fff; }
.std-table th, .std-table td { border: 1px solid var(--line); padding: 5px 10px; text-align: left; }
.std-table th { background: var(--accent-bg); }

/* amendments */
.amend-date { font-size: 18px; color: var(--bc-blue); margin: 24px 0 8px; }
.amend { background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: 10px 16px; margin-bottom: 8px; font-size: 13.5px; }
.amend .atype { font-size: 11px; font-weight: 700; text-transform: uppercase; padding: 1px 7px; border-radius: 9px; margin-right: 8px; }
.amend .atype.revision { background: #fdeee2; color: var(--rev); }
.amend .atype.original { background: var(--accent-bg); color: var(--bc-blue); }

/* target highlight */
.flash { animation: flashbg 2.4s ease-out; }
@keyframes flashbg { 0%, 40% { background: var(--flash); } 100% { background: transparent; } }

/* tooltip */
#tooltip {
  position: fixed; z-index: 200; max-width: 380px;
  background: #2c3440; color: #f2f4f7; font-size: 13px; line-height: 1.45;
  padding: 10px 13px; border-radius: 8px; box-shadow: 0 4px 18px rgba(0,0,0,.3);
  pointer-events: none;
}
#tooltip b { color: var(--bc-gold); }

@media (max-width: 900px) {
  #nav-toggle { display: block; }
  #sidebar { position: fixed; left: 0; top: 50px; z-index: 40; transform: translateX(-100%); transition: transform .18s; box-shadow: 4px 0 18px rgba(0,0,0,.15); }
  body.nav-open #sidebar { transform: none; }
  #content { padding: 18px 16px 60px; }
  .toplinks { display: none; }
}
@media print {
  #topbar, #sidebar { display: none; }
  #content { padding: 0; max-width: none; }
  .article-block, .appnote-block { border: none; padding: 0 0 10px; }
}
