/*
  Content pages: case studies, articles, indexes, playbook, resources.
  Builds on the tokens and components in styles.css. Charts are drawn by content.js.
  Layout: a centred, page-wide column (up to 80rem); long reads get a sticky sidebar.
*/

:root {
  --mono: ui-monospace, "Cascadia Code", "JetBrains Mono", Menlo, Consolas, monospace;
  --code-bg: #F4F7FA;
  --wash: #F3F6FA;
  --wrap: 80rem;
  --side: 18rem;
}

/* ---------- page frame ---------- */
.wrap { width: 100%; max-width: var(--wrap); margin-inline: auto; }
.page .panel { max-width: none; }
.doc, .index { display: grid; grid-template-columns: minmax(0, 1fr); gap: 1.25rem; }
.page .doc-solo { max-width: 52rem; margin-inline: auto; }

.kicker { margin: 0 0 1rem; font-weight: 500; color: var(--muted); font-size: 0.9375rem; }
.kicker a { color: var(--link); font-weight: 600; text-decoration: none; }
.kicker a:hover { text-decoration: underline; }

/* hero: full width, text held to a readable measure */
.doc-hero h1 { max-width: 28ch; }
.doc-hero .lede { margin-top: 1rem; max-width: 62ch; }
.doc-meta { display: flex; flex-wrap: wrap; gap: 0.25rem 1.25rem; margin: 1.25rem 0 0; color: var(--muted); font-size: 0.9375rem; max-width: none; }
.doc-meta span + span::before { content: "·"; margin-right: 1.25rem; color: var(--edge); }
.doc-meta span + span { margin-left: -1.25rem; }

/* main column plus sticky sidebar */
.doc-grid { display: grid; grid-template-columns: minmax(0, 1fr) var(--side); gap: 1.25rem; align-items: start; }
.doc-side { position: sticky; top: 1.25rem; display: grid; gap: 1rem; max-height: calc(100vh - 2.5rem); overflow-y: auto; scrollbar-width: thin; }
.side-card { background: var(--panel); border: 1px solid var(--edge); border-radius: 3px; padding: 1rem 1.1rem; }
.side-title { margin: 0; font-family: var(--body); font-weight: 600; font-size: 0.9375rem; color: var(--ink); letter-spacing: 0; }
.side-card .chips { margin-top: 0.75rem; }
.side-links { list-style: none; margin: 0.6rem 0 0; padding: 0; font-size: 0.9375rem; }
.side-links li + li { margin-top: 0.45rem; }
.side-links a { text-decoration: none; }
.side-links a:hover { text-decoration: underline; }

.toc details > summary { cursor: pointer; list-style: none; display: flex; align-items: center; justify-content: space-between; }
.toc details > summary::-webkit-details-marker { display: none; }
.toc details > summary::after { content: "–"; color: var(--muted); font-weight: 400; }
.toc details:not([open]) > summary::after { content: "+"; }
.toc ol { margin: 0.6rem 0 0; padding-left: 1.2rem; font-size: 0.875rem; line-height: 1.45; }
.toc li { padding: 0.18rem 0; }
.toc a { text-decoration: none; color: var(--text); }
.toc a:hover { color: var(--link); text-decoration: underline; }
.toc a.active { color: var(--ink); font-weight: 600; }

.related { margin-top: 0.75rem; }
.related-head { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 0.5rem 1.5rem; margin-bottom: 1rem; padding: 0 0.25rem; }
.related-head h2 { font-size: var(--s2); }

@media (max-width: 1080px) {
  .doc-grid { display: flex; flex-direction: column; }
  .doc-side { display: contents; }
  .doc-side .toc { order: -1; }
  .doc-side .toc details:not([open]) ol { display: none; }
  .doc-body { order: 0; width: 100%; }
  .side-extra { order: 1; width: 100%; }
  .doc-grid > * { width: 100%; }
}

/* ---------- chips, badges, stats ---------- */
.chips { list-style: none; margin: 1.25rem 0 0; padding: 0; display: flex; flex-wrap: wrap; gap: 0.4rem; }
.chips li {
  font-size: 0.8125rem; font-weight: 500; color: var(--text); line-height: 1.2;
  padding: 0.3rem 0.55rem; border: 1px solid var(--edge); border-radius: 3px; background: var(--wash);
}
.badge {
  display: inline-block; font-size: 0.8125rem; font-weight: 600; color: var(--signal);
  border: 1px solid currentColor; border-radius: 3px; padding: 0.1rem 0.45rem; margin-right: 0.5rem;
}
.badge-note { color: var(--muted); font-size: 0.9375rem; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(12rem, 1fr)); gap: 0.75rem; margin: 1.75rem 0 0; }
.stats div { border: 1px solid var(--edge); border-radius: 3px; padding: 0.9rem 1rem; background: var(--wash); }
.stats dt { font-size: 0.8125rem; color: var(--muted); line-height: 1.35; }
.stats dd { margin: 0.25rem 0 0; font-weight: 600; font-size: var(--s2); color: var(--ink); line-height: 1.1; letter-spacing: -0.01em; }

/* ---------- prose ---------- */
.doc-body > :first-child { margin-top: 0; }
.prose p, .prose li { max-width: 74ch; }
.prose h2 { font-family: var(--display); font-weight: 500; font-size: var(--s1); margin: 2.75rem 0 0; scroll-margin-top: 1.5rem; }
.prose h3 { font-size: 1.125rem; margin: 1.75rem 0 0; scroll-margin-top: 1.5rem; }
.prose h2 + p, .prose h3 + p { margin-top: 0.75rem; }
.prose ul { margin: 1rem 0 0; padding-left: 1.2rem; }
.prose ol { margin: 1rem 0 0; padding-left: 1.4rem; }
.prose li + li { margin-top: 0.5rem; }
.prose li > p { margin-top: 0.4rem; }
.prose strong { color: var(--ink); font-weight: 600; }
.prose hr { border: 0; border-top: 1px solid var(--edge); margin: 2.5rem 0; }
.prose img { max-width: 100%; height: auto; border: 1px solid var(--edge); border-radius: 3px; }
.prose blockquote { margin: 1.5rem 0 0; padding: 0.25rem 0 0.25rem 1.1rem; border-left: 3px solid var(--edge); color: var(--muted); }
.prose blockquote p { margin-top: 0.5rem; }
.prose .lede { margin-top: 0; }

.prose code, .doc-body code {
  font-family: var(--mono); font-weight: 400; font-size: 0.875em; color: var(--ink);
  background: var(--code-bg); border: 1px solid #E1E8EF; border-radius: 3px; padding: 0.05em 0.3em;
}
.prose a code { color: inherit; }
.prose :not(pre) > code { overflow-wrap: anywhere; }

pre.code {
  position: relative; margin: 1.25rem 0 0; padding: 2.1rem 1.1rem 1rem; overflow-x: auto;
  background: var(--code-bg); border: 1px solid var(--edge); border-radius: 3px;
  font-family: var(--mono); font-size: 0.8125rem; line-height: 1.6; color: #1D2B3C; tab-size: 4;
}
pre.code code { background: none; border: 0; padding: 0; font-size: inherit; color: inherit; white-space: pre; }
pre.code[data-lang]::before {
  content: attr(data-lang); position: absolute; top: 0.45rem; left: 1.1rem;
  font-family: var(--body); font-size: 0.75rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em;
}
pre.code .copy {
  position: absolute; top: 0.3rem; right: 0.35rem; min-height: 28px; padding: 0 0.6rem;
  font: 500 0.75rem var(--body); color: var(--link); background: var(--panel);
  border: 1px solid var(--edge); border-radius: 3px; cursor: pointer;
}
pre.code .copy:hover { color: var(--ink); border-color: var(--muted); }

/* Pygments tokens, tuned for AA contrast on --code-bg */
.code .c, .code .c1, .code .cm, .code .cs, .code .ch, .code .cp, .code .cpf { color: #5E6B7B; font-style: italic; }
.code .k, .code .kd, .code .kn, .code .kr, .code .kt, .code .kc, .code .kp, .code .ow { color: #1F4E79; font-weight: 600; }
.code .s, .code .s1, .code .s2, .code .sa, .code .sb, .code .sc, .code .sd, .code .se, .code .sh, .code .si, .code .sx, .code .dl { color: #0F6B52; }
.code .m, .code .mi, .code .mf, .code .mh, .code .il, .code .mo { color: #A6360A; }
.code .nf, .code .fm, .code .nc, .code .nn { color: #6A3F97; }
.code .nb, .code .bp, .code .nv, .code .vc, .code .vg, .code .vi { color: #1F4E79; }
.code .nd, .code .na, .code .nt { color: #8F2E08; }
.code .o, .code .p { color: #3A4A5E; }
.code .gd { color: #A6360A; }
.code .gi { color: #0F6B52; }
.code .err { color: inherit; background: none; }

/* tables */
.table-wrap { margin: 1.25rem 0 0; overflow-x: auto; border: 1px solid var(--edge); border-radius: 3px; }
.prose table, .table-wrap table { width: 100%; border-collapse: collapse; font-size: 0.9375rem; line-height: 1.45; }
.table-wrap th, .table-wrap td { padding: 0.55rem 0.75rem; text-align: left; vertical-align: top; border-bottom: 1px solid #E6ECF2; }
.table-wrap thead th { background: var(--wash); color: var(--ink); font-weight: 600; border-bottom-color: var(--edge); white-space: nowrap; }
.table-wrap tbody tr:last-child > * { border-bottom: 0; }
.table-wrap tbody tr:hover > * { background: #F8FAFC; }
.table-wrap td { font-variant-numeric: tabular-nums; }
.table-wrap caption { caption-side: top; text-align: left; padding: 0.5rem 0.75rem; font-weight: 600; color: var(--ink); background: var(--wash); border-bottom: 1px solid var(--edge); }

/* callouts */
.callout { margin: 1.5rem 0 0; padding: 0.9rem 1.1rem; background: var(--wash); border: 1px solid var(--edge); border-left: 3px solid var(--link); border-radius: 3px; }
.callout-warning { border-left-color: var(--signal); }
.callout-tip { border-left-color: #16997A; }
.callout .callout-title { margin: 0; font-weight: 600; color: var(--ink); }
.callout > :nth-child(2) { margin-top: 0.35rem; }

/* footnotes */
.footnotes { margin-top: 2.5rem; font-size: 0.9375rem; color: var(--muted); }
.footnotes-sep { border: 0; border-top: 1px solid var(--edge); margin-top: 2.5rem; }
.footnote-ref a, .footnote-backref { text-decoration: none; }

/* ---------- charts ---------- */
.chart {
  margin: 2.25rem 0 0; padding: 1.1rem 1.2rem 1rem;
  border: 1px solid var(--edge); border-radius: 3px; background: var(--panel);
  box-shadow: 0 1px 0 rgba(14, 27, 44, 0.03);
}
.chart-head { display: block; }
.chart-title { display: block; font-weight: 600; color: var(--ink); line-height: 1.3; font-size: 1.0625rem; }
.chart-sub { display: block; margin-top: 0.15rem; color: var(--muted); font-size: 0.9375rem; }

.chart-controls { display: flex; flex-wrap: wrap; align-items: center; gap: 0.6rem 1rem; margin-top: 0.85rem; }
.chart-tools { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem; margin-left: auto; }
.seg { display: inline-flex; flex-wrap: wrap; align-items: center; gap: 0; border: 1px solid var(--edge); border-radius: 3px; background: var(--wash); padding: 2px; }
.seg-label { font-size: 0.8125rem; font-weight: 600; color: var(--muted); padding: 0 0.55rem 0 0.4rem; }
.seg button {
  min-height: 32px; padding: 0 0.7rem; border: 0; border-radius: 2px; background: transparent; cursor: pointer;
  font: 500 0.8125rem var(--body); color: var(--text);
}
.seg button:hover { color: var(--ink); background: #E8EEF5; }
.seg button[aria-pressed="true"] { background: var(--ink); color: #FFFFFF; }
.chart-btn {
  min-height: 34px; padding: 0 0.75rem; border: 1px solid var(--edge); border-radius: 3px; background: var(--panel);
  font: 500 0.8125rem var(--body); color: var(--link); cursor: pointer;
}
.chart-btn:hover { border-color: var(--link); color: var(--ink); }

.chart-legend { list-style: none; margin: 0.75rem 0 0; padding: 0; display: flex; flex-wrap: wrap; gap: 0.35rem 0.4rem; font-size: 0.875rem; }
.chart-legend li { display: inline-flex; align-items: center; gap: 0.45rem; }
.chart-legend li.legend-ref { color: var(--muted); padding: 0 0.5rem; }
.chart-legend button {
  display: inline-flex; align-items: center; gap: 0.5rem; min-height: 32px; padding: 0 0.65rem;
  border: 1px solid transparent; border-radius: 3px; background: transparent; cursor: pointer;
  font: 500 0.875rem var(--body); color: var(--text);
}
.chart-legend button:hover:not(:disabled) { border-color: var(--edge); background: var(--wash); }
.chart-legend button[aria-pressed="false"] { color: #8A97A8; text-decoration: line-through; text-decoration-thickness: 1px; }
.chart-legend button[aria-pressed="false"] .key { opacity: 0.3; }
.chart-legend button:disabled { cursor: default; }
.key { display: inline-block; width: 10px; height: 10px; border-radius: 2px; background: var(--c); flex: none; }
.key-line { width: 18px; height: 3px; border-radius: 2px; }
.key-dash { background: repeating-linear-gradient(90deg, var(--c) 0 5px, transparent 5px 8px); }
.key-dot { border-radius: 50%; }

.chart-scale { display: inline-flex; align-items: center; gap: 0.5rem; font-size: 0.8125rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.chart-scale .scale-bar { width: 9rem; height: 10px; border-radius: 2px; border: 1px solid var(--edge); }
.chart-scale .scale-label { font-weight: 600; color: var(--ink); }

.chart-plot { position: relative; margin-top: 0.75rem; min-height: 260px; border-radius: 3px; }
.chart-plot:focus-visible { outline: 2px solid var(--signal); outline-offset: 4px; }
.chart-plot:not(.drawn) { background: repeating-linear-gradient(0deg, transparent 0 63px, #EEF2F6 63px 64px); }
.chart-plot.drawn { min-height: 0; }
.chart-svg { display: block; overflow: visible; font-family: var(--body); font-variant-numeric: tabular-nums; touch-action: pan-y; user-select: none; }
.chart-svg .overlay { cursor: crosshair; }
.chart-svg .dim { opacity: 0.18; transition: opacity 0.15s; }
.chart-svg .bar { transition: opacity 0.15s; }
.chart-svg .bar.dim { opacity: 0.35; }
.chart-tip {
  position: absolute; z-index: 5; pointer-events: none; min-width: 10rem; max-width: 20rem;
  background: var(--panel); border: 1px solid var(--edge); border-radius: 3px;
  box-shadow: 0 6px 20px rgba(14, 27, 44, 0.14); padding: 0.55rem 0.7rem; font-size: 0.8125rem; line-height: 1.4;
}
.chart-tip p { margin: 0; max-width: none; display: flex; align-items: center; gap: 0.45rem; }
.chart-tip p + p { margin-top: 0.2rem; }
.chart-tip .tip-head { font-weight: 600; color: var(--ink); margin-bottom: 0.3rem; }
.chart-tip strong { margin-left: auto; padding-left: 0.9rem; color: var(--ink); font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }
.chart-hint { margin: 0.6rem 0 0; font-size: 0.8125rem; color: var(--muted); }
.chart-table { margin-top: 0.4rem; font-size: 0.875rem; }
.chart-table summary { cursor: pointer; color: var(--link); font-weight: 500; min-height: 32px; display: inline-flex; align-items: center; }
.chart-table .table-wrap { max-height: 24rem; overflow: auto; margin-top: 0.4rem; }
.chart-table .table-wrap + .table-wrap { margin-top: 0.75rem; }
.chart-table table { font-size: 0.8125rem; }
.chart-caption { margin: 0.5rem 0 0; color: var(--muted); font-size: 0.875rem; }

/* ---------- cards and lists ---------- */
.cards { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(19rem, 1fr)); gap: 1rem; }
.card a {
  display: flex; flex-direction: column; height: 100%;
  background: var(--panel); border: 1px solid var(--edge); border-left: 3px solid var(--link); border-radius: 3px;
  padding: 1.15rem 1.25rem 1.25rem; text-decoration: none; color: var(--text);
  transition: border-color 0.15s, box-shadow 0.15s, transform 0.15s;
}
.card a:hover, .card a:focus-visible { border-left-color: var(--signal); box-shadow: 0 6px 18px rgba(14, 27, 44, 0.08); transform: translateY(-1px); }
.card a:hover h3 { color: var(--link); }
.card h3 { margin-top: 0.4rem; }
.card p { margin: 0.5rem 0 0; font-size: 0.9375rem; }
.card .chips { margin-top: auto; padding-top: 1rem; }
.entry-meta { display: block; font-size: var(--s-1); color: var(--muted); font-weight: 500; }
@media (prefers-reduced-motion: reduce) { .card a { transition: none; } .card a:hover { transform: none; } }

.downloads { list-style: none; margin: 0.75rem 0 0; padding: 0; border-top: 1px solid var(--edge); }
.downloads li { border-bottom: 1px solid var(--edge); padding: 0.2rem 0; }
.downloads a { display: flex; align-items: center; gap: 0.6rem; min-height: 44px; text-decoration: none; font-weight: 500; line-height: 1.3; }
.downloads a:hover .dl-label { text-decoration: underline; text-underline-offset: 0.2em; }
.downloads svg { flex: none; color: var(--signal); }
.dl-meta { margin-left: auto; color: var(--muted); font-size: 0.8125rem; font-weight: 400; white-space: nowrap; font-variant-numeric: tabular-nums; }
.dl-note { margin: 0 0 0.5rem 1.6rem; color: var(--muted); font-size: 0.875rem; max-width: 70ch; }
.doc-side .downloads a { display: grid; grid-template-columns: 16px minmax(0, 1fr); gap: 0.15rem 0.6rem; align-items: start; padding: 0.35rem 0; font-size: 0.9375rem; }
.doc-side .downloads svg { margin-top: 0.2rem; }
.doc-side .dl-meta { grid-column: 2; margin-left: 0; }
.doc-side .dl-note { font-size: 0.8125rem; margin-left: calc(16px + 0.6rem); }

/* ---------- index pages ---------- */
.index-head { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr); gap: 1.5rem 3rem; align-items: end; }
.index-intro > :first-child { margin-top: 0; }
.index-intro h1 + .lede { margin-top: 1rem; }
.jump { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 0.5rem; align-content: end; }
.jump a {
  display: inline-flex; align-items: center; gap: 0.45rem; min-height: 40px; padding: 0 0.8rem;
  border: 1px solid var(--edge); border-radius: 3px; background: var(--panel);
  text-decoration: none; font-weight: 500; font-size: 0.9375rem; color: var(--link);
}
.jump a:hover { border-color: var(--link); }
.jump a[aria-current="page"] { background: var(--ink); border-color: var(--ink); color: #FFFFFF; }
.count { font-size: 0.8125rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.jump a[aria-current="page"] .count { color: #C9D5E2; }

.group { margin-top: 1rem; scroll-margin-top: 1.5rem; }
.group-head {
  display: flex; flex-wrap: wrap; align-items: baseline; gap: 0.25rem 1.5rem;
  margin-bottom: 1rem; padding: 0.9rem 1.2rem; background: var(--panel); border: 1px solid var(--edge); border-radius: 3px;
}
.group-head h2 { font-size: var(--s2); }
.group-head p { margin: 0; color: var(--muted); max-width: 60ch; }

.resource-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(26rem, 1fr)); gap: 1.25rem; align-items: start; }
.list-panel h2 { font-size: var(--s1); }

@media (max-width: 900px) {
  .index-head { grid-template-columns: minmax(0, 1fr); }
  .resource-grid { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 720px) {
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .stats dd { font-size: var(--s1); }
  pre.code { font-size: 0.78rem; }
  .chart { padding: 0.9rem 0.8rem 0.8rem; margin-left: -0.25rem; margin-right: -0.25rem; }
  .chart-tools { margin-left: 0; }
  .chart-scale .scale-bar { width: 6rem; }
  .cards { grid-template-columns: minmax(0, 1fr); }
}
