/* InsurEco artifact kit · document — the default.
 *
 * For reports, briefs, specs, plans and write-ups: a page someone reads top to
 * bottom. Layers on tokens.css (colour, type, brand) and iec-ui.css
 * (components); load all three, in that order:
 *
 *   <link rel="stylesheet" href="https://brand.insureco.io/tokens.css">
 *   <link rel="stylesheet" href="https://brand.insureco.io/iec-ui.css">
 *   <link rel="stylesheet" href="https://brand.insureco.io/kits/document.css">
 *
 * Every value resolves through tokens.css — there is no hex in this file, so
 * data-theme and data-brand restyle it with no extra work. Prose styles apply
 * inside .iec-doc only, so a chart library's DOM elsewhere is left alone.
 */

/* ── Page ────────────────────────────────────────────────────────────── */
html { background: var(--bg); color-scheme: dark; }
html[data-theme="light"] { color-scheme: light; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font-family: var(--font-sans); font-size: 16px; line-height: 1.7; font-weight: 400;
  -webkit-font-smoothing: antialiased;
}
*, *::before, *::after { box-sizing: border-box; }
img, svg, video { max-width: 100%; height: auto; }
::selection { background: var(--brand-wash); color: var(--text); }

/* The page. Put your whole page in one .iec-doc.
 *
 * Two widths (#22). Prose holds a reading measure (--measure, 760px, what the
 * whole page used to be). Tables, code, figures and card grids use the wider
 * page (--doc-wide, 1200px): they size to their content, so a small table still
 * lines up with the prose and a large one gets room instead of a scrollbar.
 * .iec-wide sends any other block to the full page width. This applies to the
 * blocks directly in .iec-doc and to those one level down in a <section>. */
.iec-doc {
  --measure: 760px; --doc-wide: 1200px; --toc-width: 200px;
  max-width: var(--doc-wide); margin: 0 auto;
  padding: var(--space-16) var(--space-6) var(--space-24);
}
.iec-doc--wide { --measure: 1040px; --doc-wide: 1400px; }
.iec-doc > :not(.iec-wide),
.iec-doc > :is(section, article) > :not(.iec-wide) { max-width: var(--measure); margin-inline: auto; }
.iec-doc > :is(section, article):not(.iec-wide) { max-width: none; }
.iec-doc > :is(.iec-table-wrap, pre, figure),
.iec-doc > :is(section, article) > :is(.iec-table-wrap, pre, figure) {
  width: fit-content; min-width: min(100%, var(--measure)); max-width: 100%;
}
.iec-doc > :is(.iec-grid, .iec-wide),
.iec-doc > :is(section, article) > :is(.iec-grid, .iec-wide) { max-width: none; }

/* A contents list placed inside .iec-doc (right after the title) becomes a
 * sticky sidebar on a wide screen — no wrapper needed, and it stays an
 * addressable block (#22). Narrower, it is the static list at the top. */
@media (min-width: 1100px) {
  .iec-doc:has(> .iec-toc) {
    max-width: calc(var(--toc-width) + var(--space-16) + var(--doc-wide));
    display: grid; grid-template-columns: var(--toc-width) minmax(0, 1fr);
    column-gap: var(--space-16); row-gap: 0;
  }
  .iec-doc:has(> .iec-toc) > * { grid-column: 2; margin-inline: 0; }
  .iec-doc:has(> .iec-toc) > :is(section, article) > * { margin-inline: 0; }
  .iec-doc:has(> .iec-toc) > .iec-doc-header { grid-column: 1 / -1; grid-row: 1; max-width: none; }
  .iec-doc:has(> .iec-toc) > .iec-toc {
    grid-column: 1; grid-row: 1 / span 400; align-self: start; margin: 0;
    position: sticky; top: var(--space-6); max-height: calc(100vh - var(--space-10)); overflow-y: auto;
    background: var(--bg);
  }
  .iec-doc:has(> .iec-toc):has(> .iec-doc-header) > .iec-toc { grid-row: 2 / span 400; }
  .iec-doc:has(> .iec-toc) > .iec-toc :is(ol, ul) { grid-template-columns: minmax(0, 1fr); }
}

/* Sidebar table of contents + reading column, as a wrapper. Still supported;
 * the TOC-inside-.iec-doc form above is simpler and is what the portal edits.
 * Collapses under 900px. */
.iec-doc-layout {
  max-width: calc(var(--toc-width, 200px) + var(--space-16) + 1200px); margin: 0 auto;
  padding: var(--space-16) var(--space-6) var(--space-24);
  display: grid; grid-template-columns: 200px minmax(0, 1fr); gap: var(--space-16);
}
.iec-doc-layout > .iec-doc { padding: 0; margin: 0; max-width: none; }
.iec-doc-layout > .iec-doc > *,
.iec-doc-layout > .iec-doc > :is(section, article) > * { margin-inline: 0; }
.iec-doc-layout > .iec-doc-header { grid-column: 1 / -1; }
@media (max-width: 900px) {
  .iec-doc-layout { grid-template-columns: minmax(0, 1fr); gap: var(--space-8); padding-top: var(--space-10); }
}
@media (max-width: 640px) {
  .iec-doc { padding: var(--space-10) var(--space-4) var(--space-16); }
  .iec-doc-layout { padding-left: var(--space-4); padding-right: var(--space-4); }
}

/* ── Header ──────────────────────────────────────────────────────────── */
/* <header class="iec-doc-header">
 *   <span class="iec-eyebrow">Team · kind of document</span>
 *   <h1>Title</h1> <p class="iec-lede">…</p>
 *   <div class="iec-meta"><span>…</span><span>…</span></div>
 * </header> */
.iec-doc-header {
  padding-bottom: var(--space-8); margin-bottom: var(--space-10);
  border-bottom: 1px solid var(--border);
}
.iec-doc-header .iec-eyebrow { margin-bottom: var(--space-4); }
.iec-doc-header h1 {
  font-family: var(--font-sans); font-weight: 300; font-size: clamp(36px, 6vw, 56px);
  line-height: 1.1; margin: 0 0 var(--space-4); color: var(--text); text-wrap: balance;
}
.iec-lede { font-size: 20px; line-height: 1.55; color: var(--text-muted); margin: 0 0 var(--space-6); max-width: 60ch; }
.iec-meta {
  display: flex; flex-wrap: wrap; gap: var(--space-2) var(--space-6);
  font-family: var(--font-mono); font-size: 12px; letter-spacing: .03em; color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

/* ── Table of contents ───────────────────────────────────────────────── */
/* Sticky only as the sidebar of .iec-doc-layout, where it has a column of its
 * own. Anywhere else (inside .iec-doc, or the layout stacked under 900px) it is
 * a static, compact list: a sticky TOC in the reading column pins over the
 * prose, and on a phone a long one covers most of the screen (#20).
 * Collapsible form: <details class="iec-toc"><summary>Contents</summary><ol>…</ol></details> */
.iec-toc { margin: 0 0 var(--space-10); }
.iec-doc-layout > .iec-toc {
  position: sticky; top: var(--space-6); align-self: start; margin: 0;
  max-height: calc(100vh - var(--space-10)); overflow-y: auto; background: var(--bg);
}
.iec-toc .iec-eyebrow { margin-bottom: var(--space-3); }
.iec-toc > summary {
  cursor: pointer; list-style: none; display: flex; align-items: center; gap: var(--space-2);
  min-height: 44px; margin-bottom: var(--space-2);
  font-family: var(--font-mono); font-size: 11.2px; letter-spacing: .1em; text-transform: uppercase; color: var(--text-muted);
}
.iec-toc > summary::-webkit-details-marker { display: none; }
.iec-toc > summary::after { content: "+"; font-size: 14px; color: var(--brand-accent-ink); }
.iec-toc[open] > summary::after { content: "\2212"; }
.iec-toc > summary:focus-visible { outline: 2px solid var(--focus-ring); outline-offset: 2px; }
/* Placed inside .iec-doc, the TOC would inherit prose list padding and
 * underlined accent links; these keep it looking like the sidebar. */
.iec-doc .iec-toc :is(ol, ul) { margin: 0; padding: 0; }
.iec-doc .iec-toc li { margin: 0; }
.iec-doc .iec-toc a { color: var(--text-muted); text-decoration: none; }
.iec-doc .iec-toc a:hover { color: var(--text); }
/* iec-ui.js marks the section in view. */
.iec-toc a[aria-current="true"] { color: var(--text); border-left-color: var(--brand-accent-ink); }
/* Outside the sidebar the list flows into columns instead of one long stack. */
.iec-toc :is(ol, ul) { grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); column-gap: var(--space-6); }
@media (min-width: 901px) {
  .iec-doc-layout > .iec-toc :is(ol, ul) { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 900px) {
  .iec-doc-layout > .iec-toc { position: static; max-height: none; overflow: visible; }
}
@media (max-width: 640px) {
  .iec-toc :is(ol, ul) { grid-template-columns: repeat(2, minmax(0, 1fr)); column-gap: var(--space-4); }
  .iec-toc a { font-size: 13px; }
}
.iec-toc ol, .iec-toc ul { list-style: none; margin: 0; padding: 0; display: grid; gap: var(--space-1); }
.iec-toc a {
  display: block; padding: var(--space-1) 0 var(--space-1) var(--space-3);
  border-left: 1px solid var(--border); color: var(--text-muted);
  font-size: 13.6px; line-height: 1.5; text-decoration: none;
}
.iec-toc a:hover { color: var(--text); border-left-color: var(--brand-accent-ink); }
.iec-toc a:focus-visible { outline: 2px solid var(--focus-ring); outline-offset: 2px; }

/* ── Prose ───────────────────────────────────────────────────────────── */
.iec-doc h1, .iec-doc h2, .iec-doc h3, .iec-doc h4 { color: var(--text); text-wrap: balance; }
.iec-doc h1 { font-weight: 300; font-size: clamp(32px, 5vw, 44px); line-height: 1.12; margin: 0 0 var(--space-6); }
.iec-doc h2 {
  font-weight: 300; font-size: 30px; line-height: 1.2;
  margin: var(--space-16) 0 var(--space-4); scroll-margin-top: var(--space-6);
}
.iec-doc h3 { font-weight: 600; font-size: 20px; line-height: 1.3; margin: var(--space-10) 0 var(--space-3); scroll-margin-top: var(--space-6); }
.iec-doc h4 {
  font-family: var(--font-mono); font-weight: 400; font-size: 11.2px; letter-spacing: .1em;
  text-transform: uppercase; color: var(--text-muted); margin: var(--space-8) 0 var(--space-2);
}
/* Only the page's first block starts flush. A section's h2 keeps its top margin,
 * which is the space between sections (it was zeroed, leaving sections 16px apart). */
.iec-doc > :first-child, .iec-doc > :first-child > :first-child,
.iec-doc > .iec-toc + :is(section, article) > :first-child,
.iec-card > :first-child, .iec-callout > :first-child, .iec-doc li > :first-child { margin-top: 0; }
.iec-doc p { margin: 0 0 var(--space-4); }
.iec-doc strong { font-weight: 600; color: var(--text); }
.iec-doc a { color: var(--brand-accent-ink); text-decoration: underline; text-underline-offset: 3px; text-decoration-thickness: 1px; }
.iec-doc a:hover { text-decoration-thickness: 2px; }
.iec-doc a:focus-visible { outline: 2px solid var(--focus-ring); outline-offset: 2px; border-radius: 2px; }
.iec-doc ul, .iec-doc ol { margin: 0 0 var(--space-4); padding-left: var(--space-6); }
.iec-doc li { margin-bottom: var(--space-2); }
.iec-doc li::marker { color: var(--text-muted); }
.iec-doc hr { border: 0; height: 1px; background: var(--border); margin: var(--space-10) 0; }
.iec-doc blockquote {
  margin: 0 0 var(--space-6); padding: var(--space-4) var(--space-6);
  border: 1px solid var(--border); border-radius: var(--radius-md); background: var(--bg-raised);
  color: var(--text-muted);
}
.iec-doc blockquote p:last-child { margin-bottom: 0; }

/* One phrase per page, in the brand's serif. */
.iec-serif { font-family: var(--font-serif); font-style: italic; font-weight: 400; }

/* ── Code ────────────────────────────────────────────────────────────── */
.iec-doc code, .iec-doc kbd, .iec-doc samp { font-family: var(--font-mono); font-size: .86em; }
.iec-doc :not(pre) > code {
  background: var(--bg-inset); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 1px 6px;
}
.iec-doc kbd {
  border: 1px solid var(--border); border-bottom-width: 2px; border-radius: var(--radius-sm);
  padding: 0 6px; background: var(--bg-raised);
}
.iec-doc pre {
  margin: 0 0 var(--space-6); padding: var(--space-4) var(--space-6); overflow-x: auto;
  background: var(--bg-inset); border: 1px solid var(--border); border-radius: var(--radius-md);
  line-height: 1.6; font-size: 14px;
}
.iec-doc pre code { font-size: inherit; }

/* ── Tables ──────────────────────────────────────────────────────────── */
/* Wrap a wide table in .iec-table-wrap so it scrolls instead of the page. The
 * edge shade appears only while there is more table to scroll to (local covers
 * over scroll-attached shadows); it needs no script. */
.iec-table-wrap {
  overflow-x: auto; margin: 0 0 var(--space-6); border: 1px solid var(--border); border-radius: var(--radius-md);
  --iec-scroll-bg: var(--bg); --iec-scroll-shade: color-mix(in srgb, var(--text) 16%, transparent);
  background:
    linear-gradient(to right, var(--iec-scroll-bg) 30%, transparent) left / 32px 100% no-repeat local,
    linear-gradient(to left, var(--iec-scroll-bg) 30%, transparent) right / 32px 100% no-repeat local,
    linear-gradient(to right, var(--iec-scroll-shade), transparent) left / 12px 100% no-repeat scroll,
    linear-gradient(to left, var(--iec-scroll-shade), transparent) right / 12px 100% no-repeat scroll;
}
.iec-card .iec-table-wrap { --iec-scroll-bg: var(--bg-raised); }
.iec-doc table { width: 100%; border-collapse: collapse; font-size: 15px; font-variant-numeric: tabular-nums; margin: 0 0 var(--space-6); }
.iec-table-wrap table { margin: 0; }
.iec-doc th, .iec-doc td { text-align: left; vertical-align: top; padding: var(--space-3) var(--space-4); border-bottom: 1px solid var(--border); }
.iec-doc th {
  background: var(--bg-inset); color: var(--text-muted); font-weight: 400;
  font-family: var(--font-mono); font-size: 11.2px; letter-spacing: .1em; text-transform: uppercase;
}
.iec-doc tr:last-child td { border-bottom: 0; }
.iec-doc td.num, .iec-doc th.num { text-align: right; }

/* ── Figures ─────────────────────────────────────────────────────────── */
.iec-doc figure { margin: 0 0 var(--space-8); }
.iec-doc figcaption { margin-top: var(--space-3); font-size: 13.6px; color: var(--text-muted); }

/* ── Blocks ──────────────────────────────────────────────────────────── */
/* A raised card. Anything you want to set apart: a decision, a summary. */
.iec-card {
  background: var(--bg-raised); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: var(--space-6);
  margin: 0 0 var(--space-6);
}
.iec-card > :last-child { margin-bottom: 0; }
.iec-card .iec-eyebrow { margin-bottom: var(--space-3); }

/* A callout. The eyebrow says what kind; the colour comes from a role, never a
 * coloured left border. Pick one: --note (default), --decision, --warn, --bad.
 * <aside class="iec-callout iec-callout--warn">
 *   <span class="iec-callout__label">Heads up</span><p>…</p></aside> */
.iec-callout {
  --c-fg: var(--role-info-fg); --c-bg: var(--role-info-bg); --c-bd: var(--role-info-bd);
  background: var(--c-bg); border: 1px solid var(--c-bd); border-radius: var(--radius-md);
  padding: var(--space-4) var(--space-6); margin: 0 0 var(--space-6); color: var(--text);
}
.iec-callout--decision { --c-fg: var(--brand-accent-ink); --c-bg: var(--brand-wash); --c-bd: var(--brand-accent-ink); }
.iec-callout--warn { --c-fg: var(--role-attention-fg); --c-bg: var(--role-attention-bg); --c-bd: var(--role-attention-bd); }
.iec-callout--bad  { --c-fg: var(--role-bad-fg); --c-bg: var(--role-bad-bg); --c-bd: var(--role-bad-bd); }
.iec-callout--good { --c-fg: var(--role-good-fg); --c-bg: var(--role-good-bg); --c-bd: var(--role-good-bd); }
.iec-callout__label {
  display: block; margin-bottom: var(--space-2); color: var(--c-fg);
  font-family: var(--font-mono); font-size: 11.2px; letter-spacing: .1em; text-transform: uppercase;
}
.iec-callout > :last-child { margin-bottom: 0; }

/* Key / value facts. <dl class="iec-kv"><dt>Owner</dt><dd>Derek</dd>…</dl> */
.iec-kv {
  display: grid; grid-template-columns: max-content minmax(0, 1fr);
  gap: var(--space-2) var(--space-6); margin: 0 0 var(--space-6);
}
.iec-kv dt { font-family: var(--font-mono); font-size: 12px; letter-spacing: .03em; color: var(--text-muted); padding-top: 3px; }
.iec-kv dd { margin: 0; }
@media (max-width: 520px) { .iec-kv { grid-template-columns: minmax(0, 1fr); } .iec-kv dd { margin-bottom: var(--space-2); } }

/* Responsive columns of cards. */
.iec-grid { display: grid; gap: var(--space-4); margin: 0 0 var(--space-6); grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.iec-grid > .iec-card { margin: 0; }

/* Numbered steps, numerals in mono. <ol class="iec-steps"><li><h3>…</h3><p>…</p></li></ol> */
.iec-doc ol.iec-steps { list-style: none; padding: 0; counter-reset: iec-step; display: grid; gap: var(--space-6); }
.iec-steps > li { counter-increment: iec-step; position: relative; padding-left: 64px; margin: 0; }
.iec-steps > li::before {
  content: counter(iec-step, decimal-leading-zero); position: absolute; left: 0; top: 0;
  font-family: var(--font-mono); font-weight: 700; font-size: 22px; line-height: 1.3; color: var(--text-dim);
}
.iec-steps > li > :first-child { margin-top: 0; }

/* ── Shared blocks inside a document ───────────────────────────────────── */
/* iec-ui.css loads before this file, so the prose rules above would restyle
 * the shared content blocks (#24). These put each block back in charge of
 * its own lists, headings, table heads, code and quotes. */
.iec-doc :is(.iec-timeline, .iec-checklist, .iec-people),
.iec-doc .iec-proscons__col ul { padding-left: 0; }
.iec-doc :is(.iec-timeline, .iec-checklist, .iec-people, .iec-proscons__col ul) > li { margin-bottom: 0; }
.iec-doc .iec-timeline__title {
  font-family: var(--font-sans); font-weight: 600; font-size: 17px; letter-spacing: 0;
  text-transform: none; color: var(--text); margin: var(--space-1) 0 var(--space-2);
}
.iec-doc .iec-timeline__item > p { margin: 0; }
.iec-doc .iec-compare thead th {
  font-family: var(--font-sans); font-weight: 600; font-size: 15px; letter-spacing: 0;
  text-transform: none; color: var(--text); background: var(--bg-inset);
}
.iec-doc .iec-compare thead th.iec-compare__pick { background: var(--brand-wash); }
.iec-doc .iec-compare tbody th {
  font-family: var(--font-mono); font-weight: 400; font-size: 12px; letter-spacing: .03em;
  text-transform: none; color: var(--text-muted); background: transparent;
}
.iec-doc .iec-code pre { margin: 0; border: 0; border-radius: 0; background: transparent; }
.iec-doc .iec-code__head { margin: 0; font-size: 12px; }
.iec-doc .iec-pullquote blockquote { margin: 0; padding: 0; border: 0; border-radius: 0; background: none; color: var(--text); }
.iec-doc .iec-pullquote figcaption { font-family: var(--font-mono); font-size: 12px; }
.iec-doc .iec-diagram figcaption { margin-top: var(--space-3); }
/* A pull quote is prose width; a diagram uses the whole wide track. */
.iec-doc > .iec-pullquote,
.iec-doc > :is(section, article) > .iec-pullquote { width: auto; min-width: 0; max-width: var(--measure); }
.iec-doc > .iec-diagram,
.iec-doc > :is(section, article) > .iec-diagram { width: auto; min-width: 0; max-width: none; }

/* ── Density ─────────────────────────────────────────────────────────── */
/* data-density="compact" on <html>, the .iec-doc, or a section: tighter rhythm
 * for runbooks and references. Same type scale, less air (#24). The reference
 * kit is compact by default. */
:is([data-density="compact"] .iec-doc, .iec-doc[data-density="compact"]) { line-height: 1.6; }
:is([data-density="compact"] .iec-doc, .iec-doc[data-density="compact"]) h2 { font-size: 26px; margin-top: var(--space-10); margin-bottom: var(--space-3); }
:is([data-density="compact"] .iec-doc, .iec-doc[data-density="compact"]) h3 { font-size: 18px; margin-top: var(--space-8); margin-bottom: var(--space-2); }
:is([data-density="compact"] .iec-doc, .iec-doc[data-density="compact"]) :is(p, ul, ol, dl, .iec-kv, .iec-callout, .iec-card, .iec-table-wrap, pre, figure) { margin-bottom: var(--space-3); }
:is([data-density="compact"] .iec-doc, .iec-doc[data-density="compact"]) li { margin-bottom: var(--space-1); }
:is([data-density="compact"] .iec-doc, .iec-doc[data-density="compact"]) :is(th, td) { padding: var(--space-2) var(--space-3); font-size: 14px; }
:is([data-density="compact"] .iec-doc, .iec-doc[data-density="compact"]) .iec-callout { padding: var(--space-3) var(--space-4); }
:is([data-density="compact"] .iec-doc, .iec-doc[data-density="compact"]) .iec-doc-header { padding-bottom: var(--space-6); margin-bottom: var(--space-6); }

/* ── Print ───────────────────────────────────────────────────────────── */
@media print {
  html, body { background: Canvas; color: CanvasText; }
  .iec-toc { display: none; }
  .iec-doc-layout { display: block; padding: 0; }
  .iec-doc { padding: 0; max-width: none; display: block; }
  .iec-doc a { color: inherit; }
}
