/* Aegis policies landing page — chapter pages with a contents sidebar,
   attachments and policies in modals, and a Home modal over it all. The
   design tokens follow the client's mockup. */
:root {
  --paper:  #FFFFFF;   /* page ground                                 */
  --soft:   #F4F5F8;   /* neutral tint: inputs, hovers, the chat thread */
  --card:   #FFFFFF;
  --ink:    #21252B;   /* graphite text                               */
  --steel:  #4A5470;   /* navy-tinted gray, secondary text            */
  --safety: #011689;   /* Aegis navy — links, focus, active text      */
  --gold:   #FCB600;   /* Aegis gold — bars, number tabs, highlights  */
  --line:   #DDE0E6;   /* hairline rules (neutral, for a white ground) */
  --mark:   #FFE18F;   /* search highlight (gold tint)                */
  --sidebar-w: 312px;
  /* One family throughout: Quasimoda from the Adobe Fonts web project
     (ADOBE_FONTS_KIT), bold for headings; Barlow stands in until the kit
     loads or when it is unset. */
  --font-body: "quasimoda", Barlow, "Segoe UI", system-ui, sans-serif;
  --font-heading: var(--font-body);
  --font-label: var(--font-body);
}

* { box-sizing: border-box; }
html { scroll-padding-top: 24px; }
body.no-sidebar { --page-top: 88px; }
.no-sidebar [id] { scroll-margin-top: 88px; }
@media (prefers-reduced-motion: no-preference) { html { scroll-behavior: smooth; } }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 400 16.5px/1.65 var(--font-body);
}

/* ============ sidebar ============ */
nav#sidebar {
  position: fixed; inset: 0 auto 0 0; width: var(--sidebar-w);
  background: var(--card); border-right: 1px solid var(--line);
  display: flex; flex-direction: column; z-index: 30;
}
/* The Home button: the logo, pinned top-left. The Home modal minimizes
   toward it. */
.homebtn {
  display: flex; align-items: center; gap: 12px; width: 100%; text-align: left;
  padding: 18px 20px 14px; border: 0; border-bottom: 3px solid var(--safety); background: var(--card); cursor: pointer; font: inherit;
}
.homebtn:hover { background: var(--soft); }
.homebtn:focus-visible { outline: 2px solid var(--safety); outline-offset: -2px; }
.homebtn .logo { width: 128px; height: auto; display: block; flex: none; }
.homebtn-text { display: flex; flex-direction: column; min-width: 0; }
.homebtn .sub { font: 600 11px/1.3 var(--font-label); letter-spacing: .1em; text-transform: uppercase; color: var(--steel); }
.homebtn .hint { font: 600 12px/1.3 var(--font-label); color: var(--safety); margin-top: 2px; }
.draft-tag {
  display: inline-block; background: var(--gold); color: var(--safety); font-weight: 700; font-size: 10.5px;
  letter-spacing: .08em; text-transform: uppercase; padding: 1px 6px; border-radius: 2px; margin-right: 4px;
  transform: skewX(-12deg);
}
.sidefoot { padding: 10px 16px 14px; border-top: 1px solid var(--line); font-size: 12px; color: var(--steel); display: flex; flex-wrap: wrap; align-items: center; gap: 4px 8px; }

.searchwrap { position: relative; padding: 12px 16px; border-bottom: 1px solid var(--line); }
#search {
  width: 100%; padding: 9px 12px; font: inherit; font-size: 15px;
  border: 1.5px solid var(--line); border-radius: 0; background: var(--soft); color: var(--ink);
}
#search:focus { outline: 2px solid var(--safety); outline-offset: 1px; border-color: transparent; }

.results {
  position: absolute; left: 10px; right: 10px; top: calc(100% - 6px);
  background: var(--card); border: 1px solid var(--line); border-radius: 0;
  box-shadow: 0 10px 28px rgba(33,37,43,.16); max-height: 62vh; overflow: auto; z-index: 50;
}
.results .count { padding: 8px 14px; font-size: 12px; color: var(--steel); text-transform: uppercase; letter-spacing: .08em; border-bottom: 1px solid var(--line); }
.results a { display: block; padding: 10px 14px; text-decoration: none; color: inherit; border-bottom: 1px solid var(--line); }
.results a:last-child { border-bottom: 0; }
.results a:hover, .results a:focus-visible { background: var(--soft); }
.results .r-title { font-weight: 600; font-size: 14.5px; }
.results .r-crumb { font-size: 12px; color: var(--steel); margin-top: 1px; }
.results .r-snip  { font-size: 13px; color: var(--steel); margin-top: 3px; }
.results .none { padding: 14px; font-size: 14px; color: var(--steel); }
mark { background: var(--mark); color: inherit; padding: 0 1px; border-radius: 2px; }

/* ---- table of contents ---- */
.toc { overflow-y: auto; flex: 1; padding: 8px 8px 20px; }
.toc details { border-bottom: 1px solid var(--line); }
.toc summary { list-style: none; cursor: pointer; display: flex; align-items: baseline; gap: 8px; padding: 9px 10px; }
.toc summary::-webkit-details-marker { display: none; }
.toc summary::before { content: "▸"; color: var(--steel); font-size: 11px; transition: transform .15s; }
@media (prefers-reduced-motion: reduce) { .toc summary::before { transition: none; } }
.toc details[open] > summary::before { transform: rotate(90deg); }
.toc summary a { font: 600 13.5px/1.3 var(--font-label); letter-spacing: .03em; text-transform: uppercase; color: var(--ink); text-decoration: none; }
.toc summary a .n { color: var(--steel); }
.toc ul { list-style: none; margin: 0 0 6px; padding: 0 0 0 26px; }
.toc ul:empty { display: none; }
.toc li a { display: block; padding: 4.5px 8px; font-size: 14px; color: var(--steel); text-decoration: none; border-left: 2px solid transparent; }
.toc li.lvl3 a { padding-left: 22px; font-size: 13px; }
.toc li a:hover { color: var(--ink); }
.toc li a.active { color: var(--safety); border-left: 3px solid var(--gold); font-weight: 600; }
.toc summary.active { border-left: 3px solid var(--gold); padding-left: 7px; }
.toc summary.active a { color: var(--safety); }
.toc a:focus-visible, .toc summary:focus-visible { outline: 2px solid var(--safety); outline-offset: 1px; }

/* ============ top bar (sidebar off) ============ */
.appbar {
  position: fixed; top: 0; left: 0; right: 0; height: 64px; z-index: 30;
  display: flex; align-items: center; gap: 14px; padding: 0 20px;
  background: var(--card); border-bottom: 3px solid var(--safety);
}
.appbar-logo { border: 0; background: transparent; padding: 4px; cursor: pointer; border-radius: 6px; display: inline-flex; }
.appbar-logo img { height: 34px; width: auto; display: block; }
.appbar-logo:hover, .appbar-home:hover { background: var(--soft); }
.appbar-logo:focus-visible, .appbar-home:focus-visible { outline: 2px solid var(--safety); }
.appbar-home { border: 0; background: transparent; cursor: pointer; padding: 6px 10px; border-radius: 6px; font: 600 14px var(--font-label); letter-spacing: .04em; text-transform: uppercase; color: var(--safety); }
.appbar-sep { color: #B8BCC8; font-size: 18px; }
.appbar-title { flex: 1; min-width: 0; font: 700 17px/1.2 var(--font-heading); color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.appbar-title .n { color: var(--steel); margin-right: .35em; }
.appbar-search { flex: 0 1 380px; min-width: 200px; padding: 0; border: 0; }
.appbar-search #search { background: var(--soft); }
.appbar-search .results { left: 0; right: 0; top: calc(100% + 6px); }
body.no-sidebar nav#sidebar, body.no-sidebar .topbar, body.no-sidebar .backdrop { display: none; }
body.no-sidebar main#content { margin: 0 auto; max-width: 1240px; padding: 96px 48px 60px; }
body.no-sidebar { scroll-padding-top: 88px; }
body.no-sidebar .outline-inner { top: 88px; max-height: calc(100vh - 112px); }
@media (max-width: 760px) {
  .appbar { height: auto; flex-wrap: wrap; padding: 8px 12px; gap: 8px 10px; }
  .appbar-title { flex-basis: 100%; order: 3; font-size: 15px; }
  .appbar-search { flex: 1 1 100%; order: 4; }
  .appbar-sep { display: none; }
  body.no-sidebar main#content { padding: 150px 16px 48px; }
}

/* ============ chapter pages ============ */
main#content { margin-left: var(--sidebar-w); padding: 40px 56px 60px; }
.chapter[hidden] { display: none; }
.chapter-layout { display: grid; grid-template-columns: minmax(0, 76ch) 16rem; gap: 2.5rem; align-items: start; }
.outline { align-self: stretch; } /* full row height, so the sticky outline follows the whole chapter */
@media (max-width: 1180px) { .chapter-layout { grid-template-columns: minmax(0, 76ch); } .outline { display: none; } }
.chapter-body { min-width: 0; }

.notice {
  max-width: 76ch; background: #FFF4D1; border: 1px solid #F3D98A; border-left: 4px solid var(--gold);
  border-radius: 6px; padding: 10px 14px; font-size: 15px; margin-bottom: 8px;
}

main h1, .doc-title {
  font: 800 32px/1.15 var(--font-heading);
  letter-spacing: -.01em;
  margin: .3em 0 .5em; padding-bottom: .3em; border-bottom: 3px solid var(--safety);
  color: var(--safety);
}
main h1 .num, .tile-num {
  display: inline-block; background: var(--gold); color: var(--safety);
  font-size: .68em; line-height: 1; padding: .24em .5em .18em;
  margin-right: .5em; transform: skewX(-12deg); border-radius: 2px; vertical-align: .1em;
}
main h1.unnumbered { font-size: 26px; }
main h2 { font: 700 22px/1.25 var(--font-heading); margin: 1.9em 0 .4em; color: var(--safety); }
main h2 .subnum { color: var(--steel); }
main h3, .doc-body h3 { font: 600 17.5px/1.3 var(--font-heading); margin: 1.5em 0 .3em; }
main h4, .doc-body h4 { font: 600 16px/1.3 var(--font-heading); margin: 1.3em 0 .3em; color: var(--steel); }
.doc-body h3 { font-size: 19px; color: var(--safety); }

main p, .doc-body p { margin: .55em 0; }
main a, .doc-body a { color: var(--safety); }
main img, .doc-body img { max-width: 100%; height: auto; border: 0; margin: 10px 0; }
main ul, main ol, .doc-body ul, .doc-body ol { padding-left: 1.4em; }
main li, .doc-body li { margin: .25em 0; }
.hb-table-wrap { overflow-x: auto; }
.body table { border-collapse: collapse; width: 100%; margin: 14px 0; font-size: 15px; }
.body th { text-align: left; border-bottom: 2px solid var(--ink); font: 600 13px/1.4 var(--font-label); letter-spacing: .05em; text-transform: uppercase; padding: 7px 10px; }
.body td { border-bottom: 1px solid var(--line); padding: 7px 10px; vertical-align: top; }
.hb-unavailable { border: 1px dashed var(--line); border-radius: 6px; padding: 8px 12px; color: var(--steel); font-size: 14px; font-style: italic; }

/* paragraph links: every block and heading carries an id; a small link
   button appears in the margin on hover (always visible when focused) */
.body [id], main h1[id], main h2[id], main h3[id], main h4[id], .doc-body h3[id], .doc-body h4[id] { position: relative; }
.linkbtn {
  position: absolute; left: -30px; top: .25em; width: 22px; height: 22px;
  border: 0; border-radius: 4px; background: transparent; color: var(--steel);
  font-size: 14px; line-height: 22px; text-align: center; cursor: pointer; opacity: 0; transition: opacity .12s;
}
[id]:hover > .linkbtn, .linkbtn:focus-visible { opacity: 1; }
.linkbtn:hover { background: var(--mark); color: var(--safety); }
h1 > .linkbtn, h2 > .linkbtn { top: .35em; }
p.signature { margin: .15em 0; font-weight: 600; color: var(--steel); }

/* arriving at a deep link or a search result */
.flash { animation: flash 1.6s ease-out 1; }
@keyframes flash { 0% { background: var(--mark); } 100% { background: transparent; } }
@media (prefers-reduced-motion: reduce) { .flash { animation: none; outline: 2px solid var(--safety); } }
mark.hl { background: var(--mark); box-shadow: 0 0 0 1px var(--gold); }

/* in-chapter outline */
.outline-inner { position: sticky; top: 24px; max-height: calc(100vh - 48px); overflow: auto; padding-left: 1rem; border-left: 1px solid var(--line); font-size: .875rem; }
.outline-title { font-weight: 600; font-size: .75rem; text-transform: uppercase; letter-spacing: .08em; color: var(--steel); }
.outline ul { list-style: none; margin: .5rem 0 0; padding: 0; }
.outline li { margin: .15rem 0; }
.outline a { display: block; padding: .25rem .4rem; border-radius: 6px; color: var(--steel); text-decoration: none; }
.outline a:hover { color: var(--ink); background: var(--soft); }
.outline li.deep a { padding-left: 1.1rem; font-size: .83rem; }
.outline a.active { color: var(--safety); background: #EEF1FC; font-weight: 600; }

/* previous / next */
.pager { display: flex; justify-content: space-between; gap: 1rem; margin-top: 3rem; padding-top: 1.25rem; border-top: 1px solid var(--line); }
.pagelink {
  display: inline-flex; align-items: center; gap: .75rem; padding: .75rem 1rem; border-radius: 0;
  border: 1px solid var(--line); background: var(--card); color: var(--safety); text-decoration: none; font-weight: 600; max-width: 48%;
}
.pagelink small { display: block; font-weight: 500; color: var(--steel); font-size: .75rem; }
.pagelink:hover { background: var(--soft); border-color: var(--safety); }
.pagelink.next { text-align: right; margin-left: auto; }
.pagelink .arrow { font-size: 1.2rem; }

.colophon { margin-top: 50px; padding-top: 14px; border-top: 1px solid var(--line); font-size: 12.5px; color: var(--steel); letter-spacing: .05em; text-transform: uppercase; max-width: 76ch; }
.colophon a.dl { text-transform: none; letter-spacing: 0; }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
  background: var(--ink); color: #fff; padding: 9px 14px; border-radius: 6px; font-size: 14px; z-index: 200;
  box-shadow: 0 8px 24px rgba(0,0,0,.2);
}

/* download links: a small PDF tag wherever a document is introduced */
a.dl, span.dl {
  display: inline-flex; align-items: center; gap: 4px; padding: 1px 7px; border-radius: 4px;
  border: 1px solid var(--line); background: var(--card); color: var(--safety);
  font: 600 12px var(--font-label); letter-spacing: .04em; text-transform: uppercase; text-decoration: none; white-space: nowrap;
}
a.dl::before, span.dl::before { content: "↓"; font-weight: 700; }
a.dl:hover { border-color: var(--safety); background: #EEF1FC; text-decoration: none; }
span.dl { color: var(--steel); border-style: dashed; }
.dl-block { display: inline-flex; }

/* ============ modals (attachments, policies) ============ */
dialog { color: var(--ink); }
dialog::backdrop { background: rgba(33,37,43,.45); }
.doc-modal {
  width: min(880px, calc(100vw - 32px)); max-height: calc(100vh - 48px);
  padding: 0; border: 1px solid var(--line); border-radius: 14px; background: var(--card);
  box-shadow: 0 30px 80px rgba(33,37,43,.35); overflow: hidden; display: none; flex-direction: column;
}
.doc-modal[open] { display: flex; }
.doc-head { display: flex; align-items: center; gap: 12px; padding: 14px 18px; border-bottom: 3px solid var(--safety); background: var(--card); }
.doc-kind { flex: none; font: 600 11px var(--font-label); letter-spacing: .1em; text-transform: uppercase; color: var(--safety); background: #EEF1FC; padding: 3px 8px; border-radius: 4px; }
.doc-title { flex: 1; min-width: 0; margin: 0; padding: 0; border: 0; font-size: 22px; }
.doc-close, .home-close {
  flex: none; width: 36px; height: 36px; border: 0; border-radius: 8px; background: transparent; color: var(--steel); cursor: pointer; font-size: 18px;
}
a.home-close { display: inline-flex; align-items: center; justify-content: center; text-decoration: none; }
.doc-close:hover, .home-close:hover { background: var(--soft); color: var(--ink); }
.doc-body { overflow: auto; padding: 8px 48px 28px 48px; font-size: 16px; }
.doc-body .body [id] { position: relative; }
.doc-body .linkbtn { left: -28px; }

/* ============ Home modal ============ */
.home-modal {
  width: min(1480px, calc(100vw - 32px)); max-height: calc(100vh - 32px);
  padding: 32px 40px 40px; border: 1px solid var(--line); border-radius: 16px; background: var(--paper);
  box-shadow: 0 30px 80px rgba(33,37,43,.35); overflow: auto; transform-origin: top left;
}
.home-corner { position: absolute; top: 14px; right: 14px; display: flex; align-items: center; gap: 6px; }
.hub-link {
  display: inline-flex; align-items: center; padding: 6px 12px; border-radius: 8px;
  font: 600 13px var(--font-label); letter-spacing: .03em; color: var(--safety); text-decoration: none;
  border: 1px solid var(--line); background: var(--card);
}
.hub-link:hover { border-color: var(--safety); background: #EEF1FC; }
.hub-link:focus-visible { outline: 2px solid var(--safety); outline-offset: 2px; }
.dash-hero { display: flex; flex-direction: column; align-items: center; text-align: center; padding: 8px 0 36px; }
.dash-logo { width: 220px; height: auto; margin: 0 0 10px; border: 0; }
.dash-sub { font: 600 15px/1.3 var(--font-label); letter-spacing: .12em; text-transform: uppercase; color: var(--steel); }
.dash-edition { font-size: 13px; color: var(--steel); margin-top: 6px; }
.dash-search { position: relative; width: min(640px, 100%); margin-top: 26px; }
.dash-search .search-input {
  width: 100%; padding: 14px 18px; font: inherit; font-size: 17px;
  border: 1.5px solid var(--line); border-radius: 0; background: var(--card); color: var(--ink);
  box-shadow: 0 8px 24px rgba(33,37,43,.06);
}
.dash-search .search-input:focus { outline: 2px solid var(--safety); outline-offset: 1px; border-color: transparent; }
.dash-search .results { left: 0; right: 0; text-align: left; }
.dash-note { margin: 14px 0 0; font-size: 14px; color: #5A4300; background: #FFF4D1; border: 1px solid #F3D98A; border-radius: 6px; padding: 6px 12px; }

.dash-cols { display: grid; grid-template-columns: minmax(0, 11fr) minmax(0, 9fr); gap: 32px; align-items: start; }
@media (max-width: 1200px) { .dash-cols { grid-template-columns: minmax(0, 1fr); } }
.dash-col { container-type: inline-size; min-width: 0; }
.dash-h { font: 800 28px/1.15 var(--font-heading); letter-spacing: -.01em; margin: 0; padding-bottom: .3em; border-bottom: 3px solid var(--safety); color: var(--safety); }
.overview-lead { color: var(--steel); margin: .6em 0 1em; }

.tiles { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; margin-bottom: 1.5em; align-items: stretch; }
@container (max-width: 700px) { .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@container (max-width: 700px) { .tiles-policies { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@container (max-width: 540px) { .tiles-policies { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@container (max-width: 420px) { .tiles, .tiles-policies { grid-template-columns: minmax(0, 1fr); } }
.tile { container-type: inline-size; display: flex; flex-direction: column; gap: 6px; min-height: 120px; background: var(--card); border: 1px solid var(--line); border-top: 3px solid var(--safety); border-radius: 0; padding: 12px 14px 10px; }
.tile-title { display: block; font: 700 17px/1.2 var(--font-heading); color: var(--safety); text-decoration: none; margin-bottom: 6px; }
.tile-title:hover { text-decoration: underline; }
.tile-list { list-style: none; margin: 0; padding: 0; }
.tile-list li { margin: 0; }
.tile-list a { display: block; padding: 2px 0 2px 6px; margin-left: -8px; font-size: 14px; color: var(--ink); text-decoration: none; border-left: 2px solid transparent; }
.tile-list a:hover { color: var(--safety); border-left-color: var(--gold); }
.tile-list-wide { column-count: 2; column-gap: 16px; }
.tile-list-wide li { break-inside: avoid; }
@container (max-width: 300px) { .tile-list-wide { column-count: 1; } }
.tile-read { margin-top: auto; color: var(--steel); font-size: 14px; text-decoration: none; }
.tile-read:hover { color: var(--safety); }
.tile-foot { margin-top: auto; display: flex; justify-content: flex-end; align-items: baseline; gap: 8px; }
.tile-foot .tile-read { margin-top: 0; }
.tile-policy .tile-title { font-size: 16px; }
.tile-click { cursor: pointer; transition: border-color .12s, box-shadow .12s; }
.tile-click:hover, .tile-click:focus-visible { border-color: var(--safety); box-shadow: 0 6px 18px rgba(1,22,137,.10); outline: none; }
.tile-click:hover .tile-title { text-decoration: underline; }

/* the handbook side of Home: one row per chapter, sections in three columns */
.chrows { display: flex; flex-direction: column; gap: 8px; margin-bottom: 1.2em; }
.chrow { background: var(--card); border: 1px solid var(--line); border-left: 4px solid var(--safety); border-radius: 0; padding: 10px 14px 8px; }
.chrow-bare { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; padding: 8px 14px; }
.chrow.tile-click:hover .chrow-title { text-decoration: underline; }

/* attachments under Company Policies: collapsed by default, one-click boxes */
.att-section { margin-top: 1.4em; }
.att-section summary { list-style: none; cursor: pointer; display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; border-bottom: 3px solid var(--safety); padding-bottom: .3em; }
.att-section summary::-webkit-details-marker { display: none; }
.att-section summary::before { content: "▸"; color: var(--steel); font-size: 14px; transition: transform .15s; }
.att-section[open] > summary::before { transform: rotate(90deg); }
.dash-h-sm { font-size: 22px; flex: 1; border-bottom: 0; padding-bottom: 0; }
.att-hint { font-size: 13px; color: var(--steel); }
.att-section summary:focus-visible { outline: 2px solid var(--safety); outline-offset: 2px; }
.tiles-att { margin-top: 12px; }
.tile-att { min-height: 0; padding: 10px 12px; border-top-color: var(--steel); }
.tile-att .tile-title { font-size: 14.5px; margin: 0; }
.chrow-title { display: inline-block; font: 700 16px/1.2 var(--font-heading); color: var(--safety); text-decoration: none; margin-bottom: 6px; }
.chrow-bare .chrow-title { margin-bottom: 0; }
.chrow-title:hover { text-decoration: underline; }
.chrow-list { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0 18px; }
.chrow-list a { display: block; padding: 2px 0 2px 6px; margin-left: -8px; font-size: 13.5px; line-height: 1.35; color: var(--ink); text-decoration: none; border-left: 2px solid transparent; }
.chrow-list a:hover { color: var(--safety); border-left-color: var(--gold); }
@container (max-width: 620px) { .chrow-list { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@container (max-width: 400px) { .chrow-list { grid-template-columns: minmax(0, 1fr); } }
main h1 .kind { display: block; font: 600 11px/1.2 var(--font-label); letter-spacing: .1em; text-transform: uppercase; color: var(--steel); margin-bottom: 6px; }
.dl-line { margin: -.3em 0 1em; }
.tile-summary { margin: 0; font-size: 13.5px; line-height: 1.45; color: var(--steel); display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.tile-placeholder { border-style: dashed; border-top-style: solid; background: transparent; }
.tile-placeholder .tile-title { color: var(--steel); }
.tile-placeholder code { font-size: 12px; background: var(--soft); padding: 1px 4px; border-radius: 3px; }

.chiprow { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin: 0 0 1.5em; }
.chiprow-label { font: 600 12.5px var(--font-label); letter-spacing: .08em; text-transform: uppercase; color: var(--steel); margin-right: 6px; }
.chip {
  display: inline-flex; align-items: center; gap: 4px; padding: 4px 10px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--card); color: var(--ink); font: 500 13px var(--font-body);
  text-decoration: none; cursor: pointer; text-align: left;
}
.chip:hover { border-color: var(--safety); background: var(--soft); }
.chip:disabled { opacity: .55; cursor: default; }
.chip.source { background: #EEF1FC; border-color: #CFD8F6; color: var(--safety); }

/* ============ chat pop-up (bottom right; right rail when docked; bottom sheet on phones) ============ */
.chat, .chat-launcher { --chat-cond: "Barlow Condensed", var(--font-heading); }
.chat-launcher {
  position: fixed; right: 22px; bottom: 20px; z-index: 60;
  display: inline-flex; align-items: center; gap: 8px; padding: 11px 18px;
  border: 0; border-radius: 999px; background: var(--safety); color: #fff;
  font: 600 15px var(--font-body); cursor: pointer; box-shadow: 0 10px 28px rgba(1,22,137,.3);
}
.chat-launcher:hover { filter: brightness(1.15); }
.chat-launcher-icon { color: var(--gold); display: inline-flex; }
.chat-launcher .ico-down, .chat-launcher[aria-expanded="true"] .ico-spark { display: none; }
.chat-launcher[aria-expanded="true"] .ico-down { display: block; }
.chat-launcher:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }
.chat {
  position: fixed; right: 22px; bottom: 76px; z-index: 61;
  width: min(440px, calc(100vw - 44px)); height: min(680px, calc(100vh - 110px));
  display: flex; flex-direction: column; background: var(--card); color: var(--ink);
  border: 1px solid var(--line); border-radius: 14px; overflow: hidden;
  box-shadow: 0 24px 60px rgba(33,37,43,.22);
}
.chat[hidden] { display: none; }
.chat .sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.chat-grab { display: none; flex: none; align-self: center; width: 40px; height: 4px; margin-top: 8px; border-radius: 2px; background: var(--line); }

/* header */
.chat-head { flex: none; display: flex; align-items: center; gap: 12px; padding: 14px 12px 12px 16px; background: var(--card); border-bottom: 3px solid var(--safety); }
.chat-avatar { flex: none; width: 36px; height: 36px; border-radius: 6px; background: var(--safety); color: var(--gold); display: inline-flex; align-items: center; justify-content: center; }
.chat-head-text { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.chat-title { font: 700 18px/1 var(--chat-cond); letter-spacing: .06em; text-transform: uppercase; color: var(--safety); }
.chat-status { display: flex; align-items: center; gap: 6px; font: 400 12.5px/1.2 var(--font-body); color: var(--steel); }
.chat-status #chatStatusText { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-dot { flex: none; width: 7px; height: 7px; border-radius: 50%; background: #1B9E5A; }
.chat-status.off .chat-dot, .chat-status.busy .chat-dot { background: var(--gold); }
.chat-status.busy .chat-dot { animation: chat-pulse 1.4s ease-in-out infinite; }
.chat-btn { flex: none; width: 32px; height: 32px; border: 0; border-radius: 6px; background: transparent; color: var(--steel); cursor: pointer; display: inline-flex; align-items: center; justify-content: center; }
.chat-btn[hidden] { display: none; }
.chat-btn:hover { background: var(--soft); color: var(--safety); }
.chat-btn:focus-visible, .chat .act:focus-visible, .chat .sg:focus-visible, .chat .ctx:focus-visible, .chat .src-card:focus-visible, .chat .src-pill:focus-visible, .chat a.cite:focus-visible { outline: 2px solid var(--safety); outline-offset: 2px; }
.chat-btn .ico-undock { display: none; }
@keyframes chat-pulse { 50% { opacity: .35; } }
@keyframes chat-blink { 50% { opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .chat-status.busy .chat-dot { animation: none; } .chat .caret { animation: none; } }

/* thread */
.chat-thread { flex: 1; min-height: 0; overflow: auto; padding: 18px 18px 16px; display: flex; flex-direction: column; gap: 18px; background: var(--soft); }
.chat-thread > * { flex: none; }
.chat-notice { background: #FFF4D1; border: 1px solid #F3D98A; border-radius: 4px; padding: 8px 10px; font-size: 13px; color: #5A4300; line-height: 1.45; }
.chat-intro[hidden] { display: none; }
.chat-intro { display: flex; flex-direction: column; gap: 18px; padding-top: 4px; }
.intro-top { display: flex; flex-direction: column; gap: 8px; }
.intro-tag { align-self: flex-start; background: var(--gold); color: var(--safety); font: 700 10.5px/1.6 var(--font-body); letter-spacing: .08em; text-transform: uppercase; padding: 1px 7px; border-radius: 2px; transform: skewX(-12deg); }
.intro-title { margin: 0; font: 700 30px/1.05 var(--chat-cond); letter-spacing: -.005em; color: var(--safety); }
.intro-lead { margin: 0; font-size: 14.5px; line-height: 1.5; color: var(--steel); }
.reading { display: flex; flex-direction: column; gap: 8px; padding: 12px 14px; background: var(--card); border: 1px solid var(--line); border-top: 3px solid var(--safety); border-radius: 4px; }
.reading[hidden] { display: none; }
.reading-label { font: 600 11px/1.3 var(--font-body); letter-spacing: .1em; text-transform: uppercase; color: var(--steel); }
.reading-title { font: 700 16px/1.2 var(--chat-cond); color: var(--ink); }
.reading-title .n { color: var(--steel); margin-right: .3em; }
.reading-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 4px; }
.chat .ctx { display: inline-flex; align-items: center; gap: 6px; padding: 7px 12px; border: 1.5px solid var(--safety); border-radius: 4px; background: var(--card); color: var(--safety); font: 600 13px var(--font-body); letter-spacing: .02em; cursor: pointer; }
.chat .ctx:hover:not(:disabled) { background: var(--safety); color: #fff; }
.chat .ctx:disabled, .chat .sg:disabled { opacity: .55; cursor: default; }
.suggest { display: flex; flex-direction: column; gap: 8px; }
.chat .sg { display: flex; align-items: center; gap: 12px; width: 100%; text-align: left; padding: 11px 12px; border: 1px solid var(--line); border-radius: 4px; background: var(--card); color: var(--ink); font: 500 14.5px/1.3 var(--font-body); cursor: pointer; }
.chat .sg:hover:not(:disabled) { border-color: var(--safety); background: var(--soft); }
.chat .sg svg { flex: none; color: var(--safety); }
.chat .sg span { flex: 1; min-width: 0; }
.chat .sg .chev { margin-left: auto; color: #9AA1B4; }

/* turns */
.msg.user { display: flex; justify-content: flex-end; }
.msg-bubble { max-width: 86%; background: var(--safety); color: #fff; padding: 10px 14px; border-radius: 10px 10px 2px 10px; font-size: 15px; line-height: 1.45; white-space: pre-wrap; overflow-wrap: anywhere; }
.msg.bot { display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.msg-eyebrow { display: flex; align-items: center; gap: 8px; font: 600 11px/1.3 var(--font-body); letter-spacing: .1em; text-transform: uppercase; color: var(--steel); }
.msg-mark { width: 10px; height: 10px; background: var(--gold); transform: skewX(-12deg); display: inline-block; }
.msg-found { display: flex; flex-direction: column; gap: 6px; }
.msg-found-label { font-size: 12px; color: var(--steel); }
.msg-found-row { display: flex; flex-wrap: wrap; gap: 6px; }
.chat .src-pill { display: inline-flex; align-items: center; gap: 7px; padding: 5px 10px 5px 6px; border: 1px solid var(--line); border-radius: 4px; background: var(--card); color: var(--ink); font: 500 12.5px/1.2 var(--font-body); text-decoration: none; max-width: 100%; }
.chat .src-pill:hover, .chat .hot { border-color: var(--safety); }
.chat .src-pill:hover { color: var(--safety); }
.chat .hot { box-shadow: 0 0 0 3px rgba(252,182,0,.4); }
.chat .src-n { flex: none; width: 18px; height: 18px; border-radius: 3px; background: var(--gold); color: var(--safety); font: 700 11px/18px var(--chat-cond); text-align: center; }
.msg-answer { font-size: 15px; line-height: 1.6; color: var(--ink); overflow-wrap: anywhere; min-height: 1.6em; }
.msg-answer p { margin: 0 0 10px; }
.msg-answer > :last-child, .msg-answer li > :last-child { margin-bottom: 0; }
.msg-answer ul, .msg-answer ol { margin: 0 0 10px; padding-left: 22px; }
.msg-answer li { margin: 0 0 4px; }
.msg-answer strong { font-weight: 700; }
.msg-answer code { font: 13px/1.4 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; background: #E9ECF3; border-radius: 3px; padding: 1px 5px; }
.msg-answer a.cite { display: inline-block; min-width: 16px; height: 16px; margin-left: 3px; padding: 0 3px; border-radius: 3px; background: var(--gold); color: var(--safety); font: 700 10.5px/16px var(--chat-cond); text-align: center; text-decoration: none; vertical-align: 2px; }
.msg-answer a.cite:hover, .msg-answer a.cite.hot { background: var(--safety); color: #fff; box-shadow: none; }
.chat .caret { display: inline-block; width: 8px; height: 16px; margin-left: 2px; background: var(--gold); vertical-align: -2px; animation: chat-blink 1s steps(2) infinite; }
.msg-sources { display: flex; flex-direction: column; gap: 6px; }
.msg-sources-label { font: 600 11px/1.3 var(--font-body); letter-spacing: .1em; text-transform: uppercase; color: var(--steel); }
.chat .src-card { display: flex; gap: 10px; padding: 10px 12px; background: var(--card); border: 1px solid var(--line); border-radius: 4px; text-decoration: none; color: var(--ink); }
.chat .src-card:hover, .chat .src-card.hot { border-color: var(--safety); }
.chat .src-card:hover .go { color: var(--safety); }
.chat .src-card .src-n { width: 20px; height: 20px; font-size: 12px; line-height: 20px; }
.src-body { display: flex; flex-direction: column; gap: 3px; min-width: 0; flex: 1; }
.src-title { font: 700 14px/1.25 var(--chat-cond); color: var(--safety); }
.src-crumb { font-size: 11.5px; color: var(--steel); }
.src-quote { margin-top: 3px; padding-left: 8px; border-left: 2px solid var(--gold); font-size: 12.5px; line-height: 1.45; font-style: italic; color: var(--steel); display: -webkit-box; -webkit-line-clamp: 4; -webkit-box-orient: vertical; overflow: hidden; }
.chat .go { flex: none; align-self: center; color: #9AA1B4; }
.msg-actions { display: flex; align-items: center; gap: 2px; margin-top: -4px; }
.chat .act { display: inline-flex; align-items: center; gap: 5px; height: 28px; padding: 0 9px; border: 1px solid transparent; border-radius: 4px; background: transparent; color: var(--steel); font: 500 12.5px var(--font-body); cursor: pointer; }
.chat .act:hover { border-color: var(--line); background: var(--card); color: var(--safety); }
.msg-flag { margin: 0; font-size: 12.5px; color: var(--steel); font-style: italic; }
.msg.note { color: var(--steel); font-size: 14px; display: flex; align-items: center; gap: 8px; }
.msg.note .chat-dot { background: var(--gold); animation: chat-pulse 1.4s ease-in-out infinite; }
.msg.error .msg-error { background: #FFF1F1; border: 1px solid #F3C2C2; border-radius: 4px; padding: 9px 12px; font-size: 14px; line-height: 1.45; color: #7A1F1F; }

/* composer */
.chat-composer { flex: none; display: flex; flex-direction: column; gap: 8px; padding: 12px 14px 10px; border-top: 1px solid var(--line); background: var(--card); }
.chat-field { display: flex; align-items: flex-end; gap: 10px; padding: 10px 12px; border: 1.5px solid var(--line); border-radius: 6px; background: var(--soft); }
.chat-field:focus-within { border-color: var(--safety); box-shadow: 0 0 0 3px rgba(1,22,137,.16); }
.chat-field textarea { flex: 1; min-width: 0; min-height: 1.5em; align-self: center; max-height: 112px; overflow-y: auto; border: 0; background: transparent; resize: none; padding: 0; outline: none; font: 400 15px/1.5 var(--font-body); color: var(--ink); }
.chat-field textarea::placeholder { color: #8A91A5; }
.chat-field textarea:disabled { cursor: not-allowed; }
.chat-send, .chat-stop { flex: none; width: 40px; height: 40px; border-radius: 4px; display: inline-flex; align-items: center; justify-content: center; cursor: pointer; }
.chat-send { border: 0; background: var(--safety); color: #fff; }
.chat-send:hover:not(:disabled) { background: #000C4D; }
.chat-send:disabled { opacity: .4; cursor: default; }
.chat-stop { border: 1.5px solid var(--safety); background: var(--card); color: var(--safety); }
.chat-stop:hover { background: var(--safety); color: #fff; }
.chat-stop[hidden], .chat-send[hidden] { display: none; }
.chat-send:focus-visible, .chat-stop:focus-visible { outline: 2px solid var(--safety); outline-offset: 2px; }
.chat-hint { font-size: 11.5px; color: var(--steel); }
.chat-disclaimer { margin: 0; font-size: 11px; line-height: 1.4; color: var(--steel); }

/* docked: a full-height rail on the right (wide screens only) */
@media screen and (min-width: 1100px) {
  body.chat-docked .chat { top: 0; right: 0; bottom: 0; width: 440px; height: auto; border: 0; border-left: 1px solid var(--line); border-radius: 0; box-shadow: none; }
  body.chat-docked main#content { margin-right: 440px; }
  body.chat-docked .appbar { right: 440px; }
  body.chat-docked .chat-launcher { display: none; }
  body.chat-docked .chat-btn .ico-dock { display: none; }
  body.chat-docked .chat-btn .ico-undock { display: block; }
}
@media (max-width: 1099.98px) { #chatDock { display: none; } }

/* ============ top bar (mobile) + backdrop ============ */
.topbar { display: none; }
.backdrop { display: none; }
@media (max-width: 960px) {
  .topbar {
    display: flex; align-items: center; gap: 12px;
    position: fixed; top: 0; left: 0; right: 0; height: 54px; z-index: 40;
    background: var(--card); border-bottom: 1px solid var(--line); padding: 0 12px;
  }
  .topbar-home { display: inline-flex; align-items: center; gap: 8px; border: 0; background: transparent; cursor: pointer; padding: 6px; }
  .topbar .topicon { width: 22px; height: auto; }
  .topbar .brand { font: 700 15px/1 var(--font-label); letter-spacing: .06em; text-transform: uppercase; color: var(--safety); }
  #menuBtn { font: 600 14px var(--font-body); padding: 7px 12px; border: 1.5px solid var(--ink); background: var(--card); border-radius: 6px; cursor: pointer; }
  #menuBtn:focus-visible { outline: 2px solid var(--safety); }
  nav#sidebar { transform: translateX(-102%); transition: transform .2s; width: min(86vw, 340px); }
  @media (prefers-reduced-motion: reduce) { nav#sidebar { transition: none; } }
  body.nav-open nav#sidebar { transform: none; box-shadow: 0 0 40px rgba(0,0,0,.25); }
  body.nav-open .backdrop { display: block; position: fixed; inset: 0; background: rgba(33,37,43,.35); z-index: 25; }
  main#content { margin-left: 0; padding: 74px 20px 60px; }
  html { scroll-padding-top: 66px; }
  .linkbtn { left: -24px; }
  .chat { right: 12px; bottom: 70px; width: min(440px, calc(100vw - 24px)); }
  .chat-launcher { right: 12px; bottom: 14px; }
  .home-modal { padding: 24px 16px 32px; }
  .doc-body { padding: 8px 20px 24px 28px; }
}

/* phones: the chat is a bottom sheet (after the 960px block so it wins over its popup rules) */
@media (max-width: 760px) {
  .chat { left: 0; right: 0; bottom: 0; width: auto; height: 85vh; height: 85dvh; border: 0; border-radius: 18px 18px 0 0; box-shadow: 0 -16px 48px rgba(33,37,43,.28); }
  .chat-grab { display: block; }
  .chat-head { padding-top: 8px; gap: 10px; }
  .chat-avatar { width: 34px; height: 34px; }
  .chat-btn { width: 36px; height: 36px; }
  .chat-thread { padding: 16px 16px 14px; gap: 16px; }
  .msg-bubble, .msg-answer { font-size: 15.5px; }
  .chat-field textarea { font-size: 16px; }
  .chat-send, .chat-stop { width: 44px; height: 44px; }
}

/* ============ print ============ */
@media print {
  nav#sidebar, .topbar, .backdrop, .chat, .chat-launcher, .linkbtn, .notice, .pager, .outline { display: none; }
  main#content { margin: 0; padding: 0; }
  body { background: #fff; }
}
