:root {
  --blue: #000091;
  --blue-soft: #1212a8;
  --ink: #1b1814;
  --muted: #6b6258;
  --paper: #faf8f3;
  --panel: #fdfcf7;
  --line: #d6cdbb;
  --line-soft: #ebe4d3;
  --amber: #8a5a00;
  --amber-bg: #fff4d6;
  --gray: #5c5448;
  --target: rgba(0, 0, 145, 0.08);
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, "Helvetica Neue", Arial, sans-serif;
  --serif: "Source Serif Pro", "Iowan Old Style", Georgia, "Times New Roman", serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  /* Reading-size scale. Only affects the legal body + tooltip, never chrome. */
  --read-scale: 1;
}
html[data-font-scale="small"]  { --read-scale: 0.9; }
html[data-font-scale="large"]  { --read-scale: 1.125; }
html[data-font-scale="xlarge"] { --read-scale: 1.25; }
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 16px/1.6 var(--serif);
  text-rendering: optimizeLegibility;
}
a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 2px; }

/* Topbar — quiet, no glassmorphism. */
.topbar {
  position: sticky; top: 0; z-index: 40;
  display: flex; align-items: center; gap: 12px;
  height: 52px; padding: 0 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  font: 14px/1 var(--sans);
}
.topbar .brand {
  color: var(--blue);
  font-weight: 700;
  letter-spacing: 0.01em;
  white-space: nowrap;
  flex: 0 0 auto;
}
.topbar .crumb {
  flex: 1 1 0; min-width: 0;
  color: var(--muted);
  font-size: 13px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.topbar .topnav {
  display: flex; gap: 6px; align-items: center;
  flex: 0 0 auto;
}
.topbar .topnav a, .topbar .topnav > span {
  padding: 6px 10px; border-radius: 6px;
  color: var(--ink); font-size: 13px;
  white-space: nowrap;
}
.topbar .topnav a:hover { background: var(--line-soft); text-decoration: none; }
.topbar .topnav .disabled { color: var(--muted); opacity: 0.55; cursor: default; }
/* Sidebar toggle: hidden on desktop, shown on mobile via SIDEBAR_STYLE. */
.topbar .sidebar-toggle { flex: 0 0 auto; }

/* Article shell. Left padding reserves a gutter for alinéa markers so
   they never clip on narrower viewports. Header + body share the same
   inner edge. */
.layout { max-width: none; margin: 0; padding: 28px 40px 96px 80px; }
.article-head {
  margin-bottom: 22px;
  padding-bottom: 18px;
  border-bottom: 1px solid var(--line);
}
.article-head .kicker {
  display: block; margin: 0 0 6px;
  color: var(--muted);
  font: 600 12.5px/1.3 var(--sans);
  letter-spacing: 0.05em; text-transform: uppercase;
}
.article-head h1 {
  margin: 0;
  color: var(--blue);
  font: 700 30px/1.18 var(--sans);
  letter-spacing: -0.015em;
  text-wrap: balance;
}
.article-head .meta {
  margin-top: 10px;
  color: var(--muted);
  font: 13.5px/1.5 var(--sans);
}
.article-head .meta strong { color: var(--ink); font-weight: 600; }
.article-head .crumb-path {
  margin-top: 8px;
  color: var(--muted);
  font: 12.5px/1.45 var(--sans);
}
.article-head .crumb-path span + span::before { content: " › "; color: var(--line); padding: 0 4px; }
/* On narrow screens, fold the long structural path so it doesn't dominate.
   Reveal it on hover/focus or via a small disclosure tap (just hide overflow
   with a visual hint here; full disclosure can wait). */
@media (max-width: 720px) {
  .article-head .crumb-path {
    font-size: 11.5px;
    line-height: 1.4;
  }
  .article-head .crumb-path span:nth-child(n+3):nth-last-child(n+2) { display: none; }
  .article-head .crumb-path::after {
    content: " (chemin abrégé)";
    color: var(--muted); font-style: italic; font-size: 10.5px;
    margin-left: 4px;
  }
}

/* Legend chips. */
.legend {
  display: flex; flex-wrap: wrap; gap: 6px;
  margin: 14px 0 0;
  font: 12px/1 var(--sans);
}
.legend .chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 9px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  background: var(--panel);
}
.legend .chip .dot {
  width: 8px; height: 8px; border-radius: 50%; display: inline-block;
}
.legend .chip[data-state="resolved"] .dot { background: var(--blue); }
.legend .chip[data-state="external"] .dot { background: var(--amber); }
.legend .chip[data-state="unresolved"] .dot { background: var(--gray); }

/* Body. */
.body { margin-top: 24px; }
.body p {
  position: relative;
  margin: 0 0 1.1em;
  padding-left: 0;
  font-size: 19px; line-height: 1.7;
}
.body p:last-child { margin-bottom: 0; }

/* Alinéa permalink marker — sits in the gutter, appears on paragraph hover/focus. */
.alinea-marker {
  position: absolute;
  left: -2.4em;
  top: 0.15em;
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 2.1em; height: 1.6em;
  color: var(--muted);
  font: 600 11px/1 var(--sans);
  border: 1px solid transparent;
  border-radius: 4px;
  text-decoration: none;
  opacity: 0;
  transition: opacity 120ms ease-out, color 120ms ease-out, background 120ms ease-out;
  scroll-margin-top: 72px;
}
.body p:hover .alinea-marker,
.alinea-marker:focus-visible {
  opacity: 1;
  outline: none;
}
/* When an alinéa has incoming references, the marker stays persistently
   visible (tinted) so the reader sees at a glance which paragraphs are
   cited elsewhere. A small superscript shows the count. */
.alinea-marker[data-backlinks] {
  opacity: 0.78;
  color: var(--blue);
  background: rgba(0, 0, 145, 0.05);
  border-color: var(--line);
  min-width: 2.6em;
}
.body p:hover .alinea-marker[data-backlinks] { opacity: 1; }
.alinea-marker .alinea-bk {
  /* Sits as a tiny pill after §N inside the flex layout. */
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 1.3em; height: 1.1em;
  margin-left: 3px;
  padding: 0 3px;
  border-radius: 7px;
  background: var(--blue);
  color: var(--paper);
  font: 700 9px/1 var(--mono);
  letter-spacing: 0;
  font-variant-numeric: tabular-nums;
}
/* On mobile (marker is inline, full-color), keep the badge readable. */
.has-sidebar .alinea-marker[data-backlinks] {
  /* Inherits the inline mobile rule; the badge already contrasts. */
}
.alinea-marker:hover,
.alinea-marker:focus-visible {
  color: var(--blue);
  background: var(--line-soft);
  border-color: var(--blue);
}
.alinea-marker:focus-visible {
  box-shadow: 0 0 0 2px rgba(0, 0, 145, 0.22);
}
.alinea-marker.copied::after {
  content: "copié";
  position: absolute;
  left: 100%; margin-left: 6px;
  padding: 3px 6px;
  background: var(--ink); color: var(--paper);
  border-radius: 4px;
  font: 600 10px/1 var(--sans);
  white-space: nowrap;
  opacity: 1;
  animation: fadeOut 1.4s ease-out forwards;
}
@keyframes fadeOut { 0% { opacity: 1; } 70% { opacity: 1; } 100% { opacity: 0; } }

/* :target highlight on the targeted alinéa (parent <p>). */
.body p:has(.alinea-marker:target) {
  background: var(--target);
  border-radius: 4px;
  padding: 6px 8px 6px 8px;
  margin-left: -8px;
}

/* Invisible scroll-target anchors (sentence-level, subdivisions). */
.target-anchor { scroll-margin-top: 72px; }

/* BOFiP right inspector. Opens only after a section/paragraph click. */
.bofip-doc .body p,
.has-sidebar .body p {
  border-radius: 4px;
  transition: background 140ms ease-out, box-shadow 140ms ease-out;
}
.bofip-doc .body p:hover,
.has-sidebar .body p:hover {
  background: rgba(0, 0, 145, 0.035);
  cursor: pointer;
}
.bofip-doc .body p.bofip-anchor-selected,
.has-sidebar .body p.bofip-anchor-selected {
  background: var(--target);
  box-shadow: 0 0 0 1px rgba(0, 0, 145, 0.12);
}
.bofip-ref-panel {
  position: fixed;
  top: 52px;
  right: 0;
  z-index: 35;
  width: min(390px, calc(100vw - 20px));
  height: calc(100vh - 52px);
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border-left: 1px solid var(--line);
  box-shadow: -12px 0 32px rgba(25, 20, 12, 0.12);
  transform: translateX(100%);
  transition: transform 180ms ease-out;
  font: 14px/1.45 var(--sans);
}
.bofip-ref-panel.open {
  transform: translateX(0);
}
.bofip-ref-panel-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 18px 18px 14px;
  border-bottom: 1px solid var(--line);
}
.bofip-ref-kicker {
  display: block;
  color: var(--muted);
  font: 600 11px/1.2 var(--sans);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.bofip-ref-panel h2 {
  margin: 4px 0 0;
  color: var(--ink);
  font: 700 18px/1.25 var(--sans);
}
.bofip-ref-close {
  width: 32px;
  height: 32px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--paper);
  color: var(--muted);
  font: 22px/1 var(--sans);
  cursor: pointer;
}
.bofip-ref-close:hover,
.bofip-ref-close:focus-visible {
  color: var(--blue);
  border-color: var(--blue);
  outline: none;
}
.bofip-ref-meta {
  padding: 12px 18px;
  color: var(--muted);
  border-bottom: 1px solid var(--line-soft);
  font: 13px/1.45 var(--sans);
}
.bofip-ref-list {
  overflow: auto;
  padding: 8px 0 18px;
}
.bofip-ref-item {
  display: block;
  padding: 10px 18px;
  color: var(--ink);
  border-bottom: 1px solid var(--line-soft);
}
.bofip-ref-item:hover {
  background: var(--line-soft);
  text-decoration: none;
}
.bofip-ref-item strong {
  display: block;
  color: var(--blue);
  font: 650 14px/1.25 var(--sans);
}
.bofip-ref-item span {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font: 12px/1.35 var(--sans);
}
.bofip-ref-empty {
  margin: 0;
  padding: 18px;
  color: var(--muted);
  font: 13px/1.5 var(--sans);
}

/* Master-detail panel: BOFiP items become buttons that switch the panel
   to a detail view showing the actual paragraph text. CGI items remain
   plain links (they navigate). */
.bofip-ref-item.is-bofip {
  width: 100%;
  text-align: left;
  background: transparent;
  border: 0;
  border-bottom: 1px solid var(--line-soft);
  cursor: pointer;
  font: inherit;
  display: flex;
  align-items: baseline;
  gap: 10px;
}
.bofip-ref-item.is-bofip > * { flex: 1; }
.bofip-ref-item.is-bofip .bofip-ref-chev {
  flex: 0 0 auto;
  color: var(--muted);
  font: 600 14px/1 var(--sans);
  transition: color 120ms ease-out, transform 120ms ease-out;
}
.bofip-ref-item.is-bofip:hover .bofip-ref-chev,
.bofip-ref-item.is-bofip:focus-visible .bofip-ref-chev {
  color: var(--blue);
  transform: translateX(2px);
}
.bofip-ref-item.is-bofip:focus-visible {
  outline: none;
  background: var(--line-soft);
  box-shadow: inset 0 0 0 2px rgba(0, 0, 145, 0.22);
}

/* Detail view inside the panel. */
.bofip-ref-detail {
  display: flex;
  flex-direction: column;
}
.bofip-ref-detail-head {
  padding: 10px 18px 6px;
  border-bottom: 1px solid var(--line-soft);
}
.bofip-ref-back {
  display: inline-flex; align-items: center; gap: 6px;
  border: 0;
  background: transparent;
  color: var(--blue);
  cursor: pointer;
  padding: 4px 0;
  font: 600 13px/1.2 var(--sans);
}
.bofip-ref-back:hover { text-decoration: underline; text-underline-offset: 2px; }
.bofip-ref-back:focus-visible {
  outline: none;
  box-shadow: 0 0 0 2px rgba(0, 0, 145, 0.22);
  border-radius: 4px;
}
.bofip-ref-detail-title {
  padding: 12px 18px;
  border-bottom: 1px solid var(--line-soft);
  background: var(--paper);
}
.bofip-ref-detail-title strong {
  display: block;
  color: var(--blue);
  font: 700 14px/1.3 var(--sans);
}
.bofip-ref-detail-meta {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font: 12px/1.4 var(--sans);
}
.bofip-ref-paragraph {
  padding: 16px 18px 20px;
  color: var(--ink);
  font: calc(15px * var(--read-scale)) / 1.6 var(--serif);
  white-space: pre-wrap;       /* preserve 
 from the upstream payload */
  overflow-wrap: anywhere;
}
.bofip-ref-hit {
  background: rgba(0, 0, 145, 0.14);
  color: var(--blue);
  padding: 1px 2px;
  border-radius: 2px;
  box-decoration-break: clone;
  -webkit-box-decoration-break: clone;
}
.bofip-ref-open {
  margin: 0 18px 18px;
  padding: 8px 12px;
  background: var(--blue);
  color: var(--paper);
  border-radius: 6px;
  font: 600 13px/1.2 var(--sans);
  text-decoration: none;
  text-align: center;
  align-self: flex-start;
}
.bofip-ref-open:hover { background: var(--blue-soft); text-decoration: none; }
.bofip-ref-open:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px rgba(0, 0, 145, 0.22);
}

/* Expand toggle in the panel header. */
.bofip-ref-expand {
  width: 32px;
  height: 32px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--paper);
  color: var(--muted);
  font: 18px/1 var(--sans);
  cursor: pointer;
  margin-right: 4px;
}
.bofip-ref-expand:hover,
.bofip-ref-expand:focus-visible {
  color: var(--blue);
  border-color: var(--blue);
  outline: none;
}
.bofip-ref-expand[aria-pressed="true"] {
  background: var(--blue);
  color: var(--paper);
  border-color: var(--blue);
}

/* Wide-mode panel. The article column reflows via the existing :has() rule
   below — we override padding-right when .wide is set. */
.bofip-ref-panel.wide {
  width: min(720px, calc(100vw - 24px));
}
@media (min-width: 1024px) {
  body.has-sidebar:has(.bofip-ref-panel.wide) .layout > article,
  body.bofip-doc:has(.bofip-ref-panel.wide) .layout {
    padding-right: calc(min(720px, 56vw) + 40px);
  }
}

/* When the right panel is open, push the article content left so it doesn't
   sit under the panel. Smooth transition matches the panel slide-in. */
.has-sidebar .layout > article,
.bofip-doc .layout {
  transition: padding-right 180ms ease-out;
}
@media (min-width: 1024px) {
  body.has-sidebar:has(.bofip-ref-panel.open) .layout > article {
    padding-right: calc(min(390px, 32vw) + 40px);
  }
  body.bofip-doc:has(.bofip-ref-panel.open) .layout {
    padding-right: calc(min(390px, 32vw) + 40px);
  }
}
@media (max-width: 760px) {
  .bofip-ref-panel {
    top: auto;
    bottom: 0;
    width: 100vw;
    height: min(70vh, 560px);
    border-left: 0;
    border-top: 1px solid var(--line);
    transform: translateY(100%);
  }
  .bofip-ref-panel.open { transform: translateY(0); }
}

/* Citation marks — three states, distinguished by hue + a tiny superscript index.
   No yellow highlight, no bold. Underline color carries the state. */
.cite {
  border-bottom: 1px dotted var(--blue);
  text-decoration: none;
  color: inherit;
  padding-bottom: 1px;
  cursor: help;
  outline: none;
}
.cite:hover, .cite:focus-visible {
  background: rgba(0, 0, 145, 0.05);
  border-bottom-style: solid;
  border-radius: 2px;
}
.cite.external { border-bottom-color: var(--amber); }
.cite.external:hover, .cite.external:focus-visible { background: rgba(138, 90, 0, 0.08); }
.cite.unresolved { border-bottom-color: var(--gray); border-bottom-style: dashed; color: var(--gray); }
.cite.unresolved:hover, .cite.unresolved:focus-visible { background: rgba(92, 84, 72, 0.06); }
.cite .cite-idx {
  display: inline-block;
  font: 600 10px/1 var(--sans);
  vertical-align: super;
  margin-left: 2px;
  color: var(--blue);
  letter-spacing: 0;
}
.cite.external .cite-idx { color: var(--amber); }
.cite.unresolved .cite-idx { color: var(--gray); }
.cite:focus-visible { box-shadow: 0 0 0 3px rgba(0, 0, 145, 0.18); border-radius: 2px; }

/* Tooltip — accessible card, can be pinned. */
.tooltip {
  position: fixed; z-index: 100;
  width: min(620px, calc(100vw - 24px));
  max-height: min(520px, calc(100vh - 80px));
  overflow: auto;
  padding: 14px 16px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 10px 32px rgba(25, 20, 12, 0.16);
  color: var(--ink);
  font: 14px/1.5 var(--sans);
  display: none;
}
.tooltip.open { display: block; }
.tooltip.pinned {
  box-shadow: 0 10px 32px rgba(25, 20, 12, 0.22), 0 0 0 2px var(--blue);
}
.tooltip .tip-bar {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 12px;
}
.tooltip .tip-hint { font-size: 11px; }
.tooltip .tip-hint kbd {
  display: inline-block; padding: 1px 5px; border: 1px solid var(--line);
  border-radius: 3px; background: var(--paper);
  font: 600 10px/1.2 var(--mono);
}
.tip-card { padding: 10px 0; border-top: 1px solid var(--line-soft); }
.tip-card:first-of-type { border-top: 0; padding-top: 0; }
.tip-head { display: flex; gap: 8px; align-items: baseline; flex-wrap: wrap; }
.tip-head .badge {
  padding: 2px 7px;
  border-radius: 3px;
  font: 600 10px/1.4 var(--sans);
  letter-spacing: 0.02em;
  text-transform: uppercase;
  background: var(--line-soft); color: var(--muted);
}
.tip-card.resolved .badge { background: rgba(0, 0, 145, 0.1); color: var(--blue); }
.tip-card.external .badge { background: var(--amber-bg); color: var(--amber); }
.tip-card.unresolved .badge { background: var(--line-soft); color: var(--gray); }
.tip-head strong, .tip-head strong a {
  color: var(--blue);
  font: 600 14px/1.3 var(--sans);
}
.tip-card.external .tip-head strong, .tip-card.external .tip-head strong a { color: var(--amber); }
.tip-card.unresolved .tip-head strong { color: var(--gray); }
.tip-span {
  display: block;
  margin: 6px 0;
  padding: 4px 8px;
  background: var(--paper);
  border-left: 2px solid var(--line);
  color: var(--muted);
  font: 13px/1.4 var(--serif);
}
.target-text {
  margin-top: 6px;
  padding: 8px 10px;
  background: var(--paper);
  border-left: 2px solid var(--blue);
  border-radius: 0 4px 4px 0;
}
.tip-card.external .target-text { border-left-color: var(--amber); }
.target-text h3 {
  margin: 0 0 4px;
  color: var(--blue);
  font: 600 13px/1.3 var(--sans);
}
.target-text p {
  margin: 0;
  color: var(--ink);
  font: 13px/1.55 var(--serif);
  position: static;
}
.target-text code {
  display: block;
  color: var(--muted);
  font: 11px/1.4 var(--mono);
  margin-bottom: 4px;
  overflow-wrap: anywhere;
}
.tooltip dl {
  display: grid; grid-template-columns: 70px 1fr;
  gap: 2px 10px;
  margin: 8px 0 0;
  color: var(--muted);
  font: 12px/1.4 var(--sans);
}
.tooltip dt { color: var(--muted); }
.tooltip dd { margin: 0; color: var(--ink); overflow-wrap: anywhere; }

/* Mobile. Collapse the gutter and inline the marker. */
@media (max-width: 720px) {
  .layout { padding: 18px 16px 80px; }
  .article-head h1 { font-size: 26px; }
  .body p { padding-left: 0; }
  .alinea-marker {
    position: static;
    opacity: 1;
    margin-right: 6px;
    color: var(--blue);
    background: var(--line-soft);
    border-color: var(--line);
  }
  .body p:has(.alinea-marker:target) { margin-left: 0; padding-left: 8px; }
  /* Topbar: hide crumb + prev/next labels so the remaining items fit. The
     toggle, brand, font-scale buttons stay reachable. */
  .topbar { padding: 0 12px; gap: 8px; }
  .topbar .crumb { display: none; }
  .topbar .topnav > a[rel="‹ précédent"],
  .topbar .topnav > a[rel="suivant ›"],
  .topbar .topnav > a[rel="up"],
  .topbar .topnav > a[rel="home"],
  .topbar .topnav > .disabled { display: none; }
  .topbar .topnav { gap: 4px; }
}

/* Print — drop tooltip, drop topbar, drop gutter markers, expand layout. */
@media print {
  :root { --paper: #fff; --panel: #fff; }
  body { font-size: 11pt; }
  .topbar, .legend, .tooltip, .alinea-marker, .topnav { display: none !important; }
  .layout { max-width: none; padding: 0; }
  .article-head { border-bottom: 1px solid #999; }
  .article-head h1 { color: #000; font-size: 18pt; }
  .cite { color: inherit; border-bottom: 1px dotted #444; }
  .cite .cite-idx { color: #444; }
  .body p { padding-left: 0; }
  a { color: inherit; }
}

/* Reading-size overrides. Re-declares font-size on the legal body, tooltip,
   and reference target preview so they scale with --read-scale. The original
   `font:` shorthand still sets family + line-height; only size is overridden. */
.body p              { font-size: calc(19px * var(--read-scale)); line-height: 1.7; }
.tooltip             { font-size: calc(14px * var(--read-scale)); }
.tip-span            { font-size: calc(13px * var(--read-scale)); }
.target-text p       { font-size: calc(13px * var(--read-scale)); }
.target-text h3      { font-size: calc(13px * var(--read-scale)); }
.cite .cite-idx      { font-size: calc(10px * var(--read-scale)); }

/* Font-scale buttons in the topbar. */
.font-scale {
  display: inline-flex;
  gap: 2px;
  margin-right: 8px;
}
.font-scale button {
  display: inline-flex;
  align-items: center; justify-content: center;
  min-width: 30px; height: 28px;
  padding: 0 8px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
  font: 600 12px/1 var(--sans);
  cursor: pointer;
  border-radius: 6px;
}
.font-scale button:first-child { border-top-right-radius: 0; border-bottom-right-radius: 0; }
.font-scale button:last-child  { border-top-left-radius: 0;  border-bottom-left-radius: 0;  margin-left: -1px; }
.font-scale button:hover:not(:disabled) { color: var(--blue); border-color: var(--blue); z-index: 1; }
.font-scale button:focus-visible {
  outline: none;
  box-shadow: 0 0 0 2px rgba(0, 0, 145, 0.18);
  border-color: var(--blue);
  z-index: 1;
}
.font-scale button:disabled { opacity: 0.45; cursor: default; }
.font-scale .small-a  { font-size: 11px; }
.font-scale .large-a  { font-size: 14px; }
@media (max-width: 600px) {
  /* Keep the buttons reachable but slimmer. */
  .font-scale { margin-right: 4px; }
  .font-scale button { min-width: 26px; height: 26px; padding: 0 6px; }
}

/* BOFiP backlink section appended at the bottom of articles. */
.bofip-refs {
  margin: 28px 0 0;
  padding-top: 22px;
  border-top: 1px solid var(--line);
}
.bofip-refs h2 {
  margin: 0 0 12px;
  color: var(--blue);
  font: 600 16px/1.3 var(--sans);
  letter-spacing: -0.01em;
}
.bofip-refs ul { margin: 0; padding: 0; list-style: none; }
.bofip-refs li {
  padding: 10px 0;
  border-top: 1px solid var(--line-soft);
}
.bofip-refs li:first-child { border-top: 0; }
.bofip-refs a {
  display: block;
  color: var(--blue);
  font: 600 14px/1.3 var(--sans);
  text-decoration: none;
}
.bofip-refs a:hover { text-decoration: underline; text-underline-offset: 2px; }
.bofip-refs span {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font: 13px/1.4 var(--sans);
}
.bofip-refs code {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font: 12px/1.4 var(--mono);
  white-space: normal;
}

/* ---------- Index page ---------- */
body.index-page { background: var(--paper); color: var(--ink); }
.index-shell { max-width: none; margin: 0; padding: 28px 40px 80px; }
.index-shell .crumb-trail {
  margin: 0 0 6px;
  color: var(--muted);
  font: 13px/1.4 var(--sans);
}
.index-shell h1 {
  margin: 0;
  color: var(--blue);
  font: 700 28px/1.2 var(--sans);
  letter-spacing: -0.01em;
}
.index-shell .lead {
  margin: 6px 0 22px;
  color: var(--muted);
  font: 14px/1.5 var(--sans);
}
.index-shell .lead strong { color: var(--ink); font-weight: 600; }
/* Discreet pill so the BOFiP link doesn't drown in the metric line. */
.index-shell .lead .lead-link {
  display: inline-block;
  padding: 2px 9px;
  margin-left: 4px;
  background: var(--panel);
  color: var(--blue);
  border: 1px solid var(--line);
  border-radius: 999px;
  font-weight: 600;
  text-decoration: none;
  white-space: nowrap;
  transition: background 120ms ease-out, border-color 120ms ease-out;
}
.index-shell .lead .lead-link:hover {
  background: rgba(0, 0, 145, 0.06);
  border-color: var(--blue);
  text-decoration: none;
}
.index-shell .lead .lead-link:focus-visible {
  outline: none;
  border-color: var(--blue);
  box-shadow: 0 0 0 2px rgba(0, 0, 145, 0.22);
}

/* Quiet summary row — not a hero-metric grid. */
.summary-row {
  display: flex; flex-wrap: wrap; gap: 18px;
  margin: 0 0 22px;
  padding: 14px 16px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  font: 13px/1.4 var(--sans);
  color: var(--muted);
}
.summary-row .stat strong {
  color: var(--ink); font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.tools-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px; align-items: center;
  margin: 0 0 14px;
}
/* BOFiP variant: the topic-chips row can grow past one line, so the
   chips group + search stack vertically and the chips wrap freely. */
.tools-row-stack { display: block; }
.tools-row-stack .code-chips { margin-bottom: 12px; }
.tools-row-stack .search-wrap { width: 100%; }
.bofip-topic-chips { max-height: 5.2em; overflow: hidden; transition: max-height 200ms ease-out; }
.bofip-topic-chips.expanded { max-height: 600px; }
.bofip-topic-chips .code-chip { font-size: 11.5px; padding: 5px 10px; }
.code-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.code-chip {
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--muted);
  padding: 6px 11px;
  border-radius: 999px;
  font: 600 12px/1 var(--sans);
  cursor: pointer;
  user-select: none;
  font-variant-numeric: tabular-nums;
}
.code-chip:hover { color: var(--ink); border-color: var(--blue); }
.code-chip:focus-visible {
  outline: none;
  border-color: var(--blue);
  box-shadow: 0 0 0 2px rgba(0, 0, 145, 0.22);
}
.code-chip[aria-pressed="true"] {
  background: var(--blue);
  color: var(--paper);
  border-color: var(--blue);
}
.code-chip .count { opacity: 0.7; margin-left: 4px; }

.search-wrap { position: relative; min-width: 280px; }
.search-wrap input {
  width: 100%;
  height: 36px;
  padding: 0 36px 0 12px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--ink);
  font: 14px/1.2 var(--sans);
  outline: none;
}
.search-wrap input:focus { border-color: var(--blue); box-shadow: 0 0 0 2px rgba(0, 0, 145, 0.16); }
.search-wrap .kbd-hint {
  position: absolute;
  right: 10px; top: 50%; transform: translateY(-50%);
  font: 600 10px/1.1 var(--mono);
  color: var(--muted);
  border: 1px solid var(--line);
  padding: 2px 5px;
  border-radius: 3px;
  background: var(--paper);
  pointer-events: none;
}
.search-wrap input:not(:placeholder-shown) ~ .kbd-hint { display: none; }

.result-count {
  margin: 0 0 10px;
  color: var(--muted);
  font: 13px/1.4 var(--sans);
}
.result-count strong { color: var(--ink); font-weight: 600; font-variant-numeric: tabular-nums; }

.article-table-wrap {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}
.article-table {
  width: 100%;
  border-collapse: collapse;
  font: 14px/1.35 var(--sans);
}
.article-table thead th {
  background: var(--line-soft);
  color: var(--muted);
  text-align: left;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font: 600 11px/1.3 var(--sans);
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
}
.article-table td {
  padding: 9px 14px;
  border-bottom: 1px solid var(--line-soft);
  vertical-align: top;
}
.article-table tbody tr:last-child td { border-bottom: 0; }
.article-table tbody tr:hover td { background: var(--line-soft); }
.code-row th {
  background: var(--paper);
  color: var(--blue);
  font: 600 11px/1.3 var(--sans);
  letter-spacing: 0.04em; text-transform: uppercase;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  border-top: 1px solid var(--line);
  position: sticky; top: 0;
}
.article-num a {
  color: var(--blue);
  font-weight: 600;
  text-decoration: none;
}
.article-num a:hover { text-decoration: underline; text-underline-offset: 2px; }
.article-code { color: var(--muted); font-size: 12px; }
.article-refs {
  width: 90px;
  text-align: right;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  font-size: 13px;
}
.article-refs strong { color: var(--ink); font-weight: 600; }
.article-refs.zero strong { color: var(--muted); font-weight: 400; }

.empty-state {
  padding: 40px 20px;
  text-align: center;
  color: var(--muted);
  font: 14px/1.5 var(--sans);
}

@media (max-width: 720px) {
  .tools-row { grid-template-columns: 1fr; }
  .search-wrap { min-width: 0; }
  .article-table th:nth-child(2), .article-table td:nth-child(2) { display: none; }
}

/* Toast (used by copy-citation affordance). */
.toast {
  position: fixed; bottom: 22px; left: 50%;
  transform: translateX(-50%) translateY(8px);
  background: var(--ink); color: var(--paper);
  padding: 8px 14px;
  border-radius: 6px;
  font: 600 13px/1.3 var(--sans);
  box-shadow: 0 10px 32px rgba(0, 0, 0, 0.25);
  opacity: 0;
  pointer-events: none;
  transition: opacity 180ms ease-out, transform 180ms ease-out;
  z-index: 200;
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* Copy-citation button on article header. */
.head-actions {
  display: flex; gap: 8px; align-items: center; flex-wrap: wrap;
  margin-top: 10px;
}
.head-actions button {
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
  padding: 6px 11px;
  border-radius: 6px;
  font: 600 12px/1.2 var(--sans);
  cursor: pointer;
}
.head-actions button:hover { border-color: var(--blue); color: var(--blue); }
.head-actions button:focus-visible {
  outline: none;
  box-shadow: 0 0 0 2px rgba(0, 0, 145, 0.18);
  border-color: var(--blue);
}

/* BOFiP encart on the main index. */
.bofip-card {
  display: flex; gap: 24px; align-items: center; flex-wrap: wrap;
  margin: 32px 0 0;
  padding: 20px 22px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
}
.bofip-card-text { flex: 1; min-width: 260px; }
.bofip-card-kicker {
  display: block;
  margin-bottom: 4px;
  color: var(--muted);
  font: 600 11px/1.2 var(--sans);
  letter-spacing: 0.04em; text-transform: uppercase;
}
.bofip-card h2 {
  margin: 0 0 6px;
  color: var(--ink);
  font: 600 18px/1.25 var(--sans);
  letter-spacing: -0.01em;
}
.bofip-card p {
  margin: 0;
  color: var(--muted);
  font: 14px/1.55 var(--sans);
}
.bofip-card p strong { color: var(--ink); font-weight: 600; font-variant-numeric: tabular-nums; }
.bofip-card-cta {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 9px 16px;
  background: var(--blue);
  color: var(--paper);
  border-radius: 7px;
  font: 600 13px/1.2 var(--sans);
  text-decoration: none;
  white-space: nowrap;
}
.bofip-card-cta:hover {
  background: var(--blue-soft);
  text-decoration: none;
}
.bofip-card-cta:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px rgba(0, 0, 145, 0.22);
}
@media (max-width: 640px) {
  .bofip-card { padding: 16px; }
  .bofip-card-cta { width: 100%; justify-content: center; }
}

/* ---------- Article-page sidebar (search + navigation) ---------- */

/* When the body opts in via .has-sidebar, the sidebar anchors flush to
   the viewport's left edge (no margin, no border-radius). The article
   column centers in the remaining space with its own readable max-width,
   so the legal text stays comfortable on wide monitors while the sidebar
   feels like a permanent rail. */
.has-sidebar .layout {
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
  gap: 0;
  max-width: none;
  margin: 0;
  padding: 0;
}
.has-sidebar .layout > article {
  min-width: 0;
  /* No max-width: text takes all space in the article column. The sidebar
     anchors the left edge; the right edge follows the viewport. */
  margin: 0;
  padding: 32px 40px 96px 80px;
}

.sidebar {
  position: sticky;
  top: 52px;
  align-self: start;
  height: calc(100vh - 52px);
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border-right: 1px solid var(--line);
  overflow: hidden;
}
.sidebar-head {
  padding: 16px 14px 14px;
  border-bottom: 1px solid var(--line-soft);
  background: var(--panel);
}
.sidebar-search { position: relative; }
.sidebar-search input {
  width: 100%; height: 34px;
  padding: 0 36px 0 12px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--ink);
  font: 13px/1.2 var(--sans);
  outline: none;
}
.sidebar-search input:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 2px rgba(0, 0, 145, 0.16);
}
.sidebar-search .kbd-hint {
  position: absolute;
  right: 8px; top: 50%; transform: translateY(-50%);
  font: 600 10px/1.1 var(--mono);
  color: var(--muted);
  border: 1px solid var(--line);
  padding: 2px 5px;
  border-radius: 3px;
  background: var(--paper);
  pointer-events: none;
}
.sidebar-search input:not(:placeholder-shown) ~ .kbd-hint { display: none; }

.sidebar-chips {
  display: flex; flex-wrap: wrap; gap: 4px;
  margin-top: 10px;
}
.sidebar-chip {
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--muted);
  padding: 3px 8px;
  border-radius: 999px;
  font: 600 11px/1 var(--sans);
  cursor: pointer;
}
.sidebar-chip:hover { color: var(--ink); border-color: var(--blue); }
.sidebar-chip:focus-visible {
  outline: none;
  border-color: var(--blue);
  box-shadow: 0 0 0 2px rgba(0, 0, 145, 0.22);
}
.sidebar-chip[aria-pressed="true"] {
  background: var(--blue); color: var(--paper); border-color: var(--blue);
}

.sidebar-list {
  flex: 1; min-height: 0;
  overflow-y: auto;
  padding: 4px 0 8px;
  outline: none;
}
.sidebar-list a {
  display: flex; align-items: baseline; justify-content: space-between;
  gap: 8px;
  padding: 6px 14px;
  color: var(--ink);
  font: 14px/1.35 var(--sans);
  text-decoration: none;
  border-left: 2px solid transparent;
  /* Perf: skip rendering for off-screen items in the 2 300-row CGI list.
     contain-intrinsic-size gives the browser a layout hint so the scrollbar
     accurately reflects total scroll height before items hydrate. */
  contain: content;
  content-visibility: auto;
  contain-intrinsic-size: 0 28px;
}
.sidebar-list a:focus-visible {
  outline: none;
  background: var(--line-soft);
  border-left-color: var(--blue);
  box-shadow: inset 0 0 0 2px rgba(0, 0, 145, 0.18);
}
.sidebar-list a:hover { background: var(--line-soft); }
.sidebar-list a.current {
  background: rgba(0, 0, 145, 0.06);
  border-left-color: var(--blue);
  color: var(--blue);
  font-weight: 600;
}
.sidebar-list a .refs {
  color: var(--muted);
  font: 11px/1 var(--mono);
  font-variant-numeric: tabular-nums;
}
.sidebar-list a.current .refs { color: var(--blue); opacity: 0.7; }
.sidebar-list .sidebar-empty {
  padding: 24px 12px;
  text-align: center;
  color: var(--muted);
  font: 13px/1.4 var(--sans);
}

/* Mobile toggle (in topbar) and off-canvas. */
.sidebar-toggle {
  display: none;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
  padding: 5px 9px;
  border-radius: 6px;
  font: 600 12px/1 var(--sans);
  cursor: pointer;
}
.sidebar-toggle:hover { border-color: var(--blue); color: var(--blue); }
.sidebar-backdrop {
  display: none;
  position: fixed; inset: 52px 0 0 0;
  background: rgba(0, 0, 0, 0.36);
  z-index: 30;
}

@media (max-width: 1023px) {
  .has-sidebar .layout {
    grid-template-columns: minmax(0, 1fr);
    gap: 0;
    padding: 0;
  }
  .has-sidebar .layout > article {
    max-width: none;
    margin: 0;
    padding: 18px 16px 80px;
  }
  /* Inline the alinéa marker when the article column loses its gutter,
     otherwise the absolute-positioned marker overflows off-screen. */
  .has-sidebar .alinea-marker {
    position: static;
    opacity: 1;
    margin-right: 6px;
    color: var(--blue);
    background: var(--line-soft);
    border-color: var(--line);
  }
  .has-sidebar .body p:has(.alinea-marker:target) {
    margin-left: 0; padding-left: 8px;
  }
  .sidebar-toggle { display: inline-flex; }
  .sidebar {
    position: fixed;
    top: 52px; left: 0;
    width: min(340px, 86vw);
    height: calc(100vh - 52px);
    border-radius: 0;
    border-top: 0; border-left: 0; border-bottom: 0;
    transform: translateX(-100%);
    transition: transform 200ms ease-out;
    z-index: 35;
  }
  .sidebar.open { transform: translateX(0); }
  body.sidebar-open .sidebar-backdrop { display: block; }
}

/* Print: hide the sidebar; collapse 2-col to 1-col. */
@media print {
  .has-sidebar .layout { grid-template-columns: 1fr; padding-left: 0; }
  .has-sidebar .layout > article { padding-left: 0; }
  .sidebar, .sidebar-toggle, .sidebar-backdrop { display: none !important; }
}

/* Auto dark mode. Tokens re-tinted; Marianne blue lifted for legibility. */
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --blue: #8d8dff;
    --blue-soft: #a8a8ff;
    --ink: #ebe6dd;
    --muted: #9c9385;
    --paper: #14110b;
    --panel: #1c1813;
    --line: #2f271c;
    --line-soft: #251e15;
    --amber: #f0bf6e;
    --amber-bg: #2a1c05;
    --gray: #8a8377;
    --target: rgba(141, 141, 255, 0.18);
  }
  .cite:hover, .cite:focus-visible { background: rgba(141, 141, 255, 0.12); }
  .cite.external:hover, .cite.external:focus-visible { background: rgba(240, 191, 110, 0.14); }
  .cite.unresolved:hover, .cite.unresolved:focus-visible { background: rgba(138, 131, 119, 0.12); }
  .tip-card.resolved .badge { background: rgba(141, 141, 255, 0.18); color: var(--blue); }
  .tip-card.external .badge { background: rgba(240, 191, 110, 0.16); color: var(--amber); }
  .tooltip { box-shadow: 0 10px 32px rgba(0, 0, 0, 0.5); }
  .tooltip.pinned { box-shadow: 0 10px 32px rgba(0, 0, 0, 0.55), 0 0 0 2px var(--blue); }
  .toast { background: #ebe6dd; color: #14110b; }
}
