/* ============================================================
   XPages Master — dual-theme token system (UI spec §2).
   Every colour pair in here is checked against WCAG 2.1 AA by
   scripts/audit-contrast.js: 4.5:1 for text, 3:1 for control
   boundaries and meaningful graphics.
   The theme is resolved to an explicit data-bs-theme by
   /js/theme.js before first paint, so Bootstrap's own components
   switch with us. The media query below is the no-JS fallback.

   The palette is declared three times and the three must stay in
   sync; the audit fails if the two dark copies differ.
   ============================================================ */
:root{
  --page:#cbd6e2; --card:#ffffff; --sunk:#f1f4f7;
  --ink:#131c26; --ink-2:#333f4b; --mute:#4e5862;
  --rule:#c3cdd6; --rule-strong:#6d7985;
  --accent:#0b6340; --accent-soft:#e2efe8;
  --danger:#b3261e; --success:#136a3e; --warn:#7a5300;
  --link:#14528f;
  --warn-bg:#fdf3e2; --warn-bd:#8f6914;
  --neutral-bg:#e6eaee; --neutral-fg:#414c56;
  --progress-bg:#e3eefb; --progress-fg:#14528f;
  --done-bg:#e0f2e8; --done-fg:#0f5a35;
  --chrome-bg:#131c26; --chrome-ink:#e8eef4; --chrome-mute:#9fb0c0;
  --chrome-rule:#2b3742; --chrome-hover:#1e2a36;
  --chrome-accent:#4fc48d; --chrome-accent-ink:#0b1016; --chrome-control:#77848f;
  --shadow:0 1px 2px rgba(16,24,32,.05);
  --brand-text:#1f3a5f; --brand-bar:#1f3a5f;
  --brand-btn:#1f3a5f; --brand-btn-fg:#ffffff;
  --brand-chrome:#556985; --brand-chrome-fg:#ffffff;
  --nav-h:57px;
}
@media (prefers-color-scheme:dark){
  :root:not([data-bs-theme="light"]){
    --page:#0b1016; --card:#1e2833; --sunk:#27333f;
    --ink:#e8eef4; --ink-2:#c2cdd8; --mute:#98a6b4;
    --rule:#333f4c; --rule-strong:#77848f;
    --accent:#4fc48d; --accent-soft:#15291f;
    --danger:#ff9b91; --success:#6edb9f; --warn:#e6b355;
    --link:#8ec5f7;
    --warn-bg:#2c2113; --warn-bd:#e6b355;
    --neutral-bg:#242e38; --neutral-fg:#b9c5d1;
    --progress-bg:#12293f; --progress-fg:#8ec5f7;
    --done-bg:#0f2a1d; --done-fg:#71dda3;
    --chrome-bg:#0b1016; --chrome-ink:#e8eef4; --chrome-mute:#9fb0c0;
    --chrome-rule:#232e3a; --chrome-hover:#151d26;
    --chrome-accent:#4fc48d; --chrome-accent-ink:#0b1016; --chrome-control:#77848f;
    --shadow:0 1px 2px rgba(0,0,0,.5);
    --brand-text:#7f8fa4; --brand-bar:#6b7d95;
    --brand-btn:#60738d; --brand-btn-fg:#ffffff;
    --brand-chrome:#556985; --brand-chrome-fg:#ffffff;
  }
}
[data-bs-theme="dark"]{
  --page:#0b1016; --card:#1e2833; --sunk:#27333f;
  --ink:#e8eef4; --ink-2:#c2cdd8; --mute:#98a6b4;
  --rule:#333f4c; --rule-strong:#77848f;
  --accent:#4fc48d; --accent-soft:#15291f;
  --danger:#ff9b91; --success:#6edb9f; --warn:#e6b355;
  --link:#8ec5f7;
  --warn-bg:#2c2113; --warn-bd:#e6b355;
  --neutral-bg:#242e38; --neutral-fg:#b9c5d1;
  --progress-bg:#12293f; --progress-fg:#8ec5f7;
  --done-bg:#0f2a1d; --done-fg:#71dda3;
  --chrome-bg:#0b1016; --chrome-ink:#e8eef4; --chrome-mute:#9fb0c0;
  --chrome-rule:#232e3a; --chrome-hover:#151d26;
  --chrome-accent:#4fc48d; --chrome-accent-ink:#0b1016; --chrome-control:#77848f;
  --shadow:0 1px 2px rgba(0,0,0,.5);
  --brand-text:#7f8fa4; --brand-bar:#6b7d95;
  --brand-btn:#60738d; --brand-btn-fg:#ffffff;
  --brand-chrome:#556985; --brand-chrome-fg:#ffffff;
}

/* ---------- base ---------- */
/* nothing may push the page sideways; a safety net only (UI spec §10) */
html,body{max-width:100%;overflow-x:hidden}
body{background:var(--page);color:var(--ink);font-size:14.5px;
  font-family:system-ui,-apple-system,"Segoe UI",Roboto,sans-serif}
.mono,.num{font-variant-numeric:tabular-nums;
  font-family:ui-monospace,"SF Mono",Menlo,Consolas,monospace}
h1,h2,h3,h4,h5,h6{color:var(--ink)}
hr{border-color:var(--rule-strong);opacity:1}
.text-muted{color:var(--mute)!important}
.text-danger{color:var(--danger)!important}
.text-success{color:var(--success)!important}
.text-warning{color:var(--warn)!important}
code{color:var(--ink)}

/* Bootstrap's link blue is replaced by a token that clears 4.5:1 on every
   surface a link can sit on, in both themes. */
a{color:var(--link)}
a:hover,a:focus{color:var(--link);text-decoration-thickness:2px}

/* focus: one visible, high-contrast treatment everywhere. On the dark chrome
   the content accent is a dark green on near-black, so the navbar and footer
   carry their own; a menu that opens from the navbar is a card again. */
html{--focus:var(--accent)}
.site-header,.site-footer{--focus:var(--chrome-accent)}
.site-header .dropdown-menu{--focus:var(--accent)}
:where(a,button,input,select,textarea,summary,[tabindex]):focus-visible{
  outline:3px solid var(--focus);outline-offset:2px;border-radius:4px}
/* Bootstrap swaps the outline of these for a faint glow; put the ring back. */
.btn:focus-visible,.btn-close:focus-visible,.nav-link:focus-visible,
.navbar-toggler:focus-visible,.dropdown-item:focus-visible{
  outline:3px solid var(--focus);outline-offset:2px;box-shadow:none}

.skip{position:absolute;left:-9999px;top:0;z-index:1080;
  background:var(--card);color:var(--ink);padding:.6rem 1rem;border:2px solid var(--accent);
  border-radius:0 0 6px 0;font-weight:600}
.skip:focus{left:0}

h1,h2,h3,.card,.alert,
input,select,textarea,summary,[tabindex]{scroll-margin-top:calc(var(--nav-h) + 16px)}

/* the field the page has sent you to */
.field-attention{animation:field-ping 1.1s ease-out 1}
@keyframes field-ping{
  0%{box-shadow:0 0 0 0 color-mix(in srgb,var(--accent) 55%,transparent)}
  100%{box-shadow:0 0 0 12px transparent}
}

/* ---------- shell ---------- */
body.app-shell{min-height:100vh;display:flex;flex-direction:column;padding-top:var(--nav-h)}
body.app-shell > main{flex:1 0 auto;width:100%;max-width:1320px}

/* Fixed, not sticky: the nav lives inside <header>, which is a flex item of
   the shell, so a sticky nav could only stick within its own header box. */
.site-header{position:fixed;top:0;left:0;right:0;z-index:1030}
/* the bar is exactly --nav-h tall, whatever it holds */
.site-header .navbar{width:100%;min-height:var(--nav-h)}
.navbar{background:var(--chrome-bg);border-bottom:1px solid var(--chrome-rule);
  --bs-navbar-toggler-border-color:var(--chrome-control)}
.navbar .navbar-brand{color:var(--chrome-ink)}
.navbar-brand-mark{width:30px;height:30px;border-radius:6px;background:var(--brand-chrome);
  color:var(--brand-chrome-fg);display:grid;place-items:center;font-weight:700;font-size:13px;flex:0 0 auto}
.navbar .nav-link{color:var(--chrome-mute);font-weight:500;padding:.35rem .8rem;border-radius:6px}
.navbar .nav-link:hover{color:var(--chrome-ink);background:var(--chrome-hover)}
.navbar .nav-link.active{color:var(--chrome-ink);background:var(--chrome-hover);font-weight:600}
.navbar-toggler{color:var(--chrome-ink);padding:.3rem .55rem}
.navbar-toggler svg{width:20px;height:20px;fill:none;stroke:currentColor;stroke-width:2;
  stroke-linecap:round;display:block}

.site-footer{flex-shrink:0;border-top:1px solid var(--chrome-rule);background:var(--chrome-bg);
  color:var(--chrome-mute);font-size:12.5px}
.footer-inner{max-width:1320px;margin:0 auto;padding:.9rem 1.5rem;
  display:flex;align-items:center;gap:.5rem;flex-wrap:wrap}
.footer-grow{flex:1 1 auto}

/* theme switch */
.theme-switch{display:inline-flex;border:1px solid var(--chrome-control);border-radius:7px;overflow:hidden}
.theme-switch button{background:transparent;color:var(--chrome-mute);border:0;padding:.3rem .5rem;
  display:grid;place-items:center;line-height:0}
.theme-switch button+button{border-left:1px solid var(--chrome-control)}
.theme-switch button:hover{background:var(--chrome-hover);color:var(--chrome-ink)}
.theme-switch button[aria-pressed="true"]{background:var(--chrome-accent);color:var(--chrome-accent-ink)}
.theme-switch button:focus-visible{outline-offset:-3px}
.theme-switch svg{width:15px;height:15px;fill:none;stroke:currentColor;stroke-width:2;
  stroke-linecap:round;stroke-linejoin:round}

/* ---------- page head: every page's only <h1> sits in a card ---------- */
.page-head{background:var(--card);border:1px solid var(--rule);border-radius:10px;
  box-shadow:var(--shadow);padding:1rem 1.15rem;margin-bottom:1rem;
  display:flex;justify-content:space-between;align-items:flex-end;gap:1rem;flex-wrap:wrap}
.page-head h1{margin:0}
.page-head .page-head-sub{color:var(--mute);font-size:13px;margin:.15rem 0 0}
/* the headline figure on the right of a page head */
.page-head .figure{display:block;font-size:1.35rem;font-weight:600;line-height:1.1;color:var(--brand-text)}
.section-label{font-size:10.5px;font-weight:700;letter-spacing:.14em;text-transform:uppercase;
  color:var(--mute)}

/* ---------- cards ---------- */
.card{background:var(--card);color:var(--ink);border:1px solid var(--rule);border-radius:10px;
  box-shadow:var(--shadow)}
/* card headers can also hold a badge or a small form */
.card-header{background:var(--card);border-bottom:1px solid var(--rule);color:var(--ink);
  font-weight:600;font-size:13px;padding:.7rem 1rem;
  display:flex;align-items:center;justify-content:space-between;flex-wrap:wrap;gap:.5rem .75rem}
.card-header:first-child{border-radius:10px 10px 0 0}
.card-header>form{flex-wrap:wrap}
.card-header h2{font-size:13px;font-weight:600;margin:0}

/* ---------- tables ---------- */
.table{--bs-table-bg:transparent;--bs-table-color:var(--ink);--bs-table-border-color:var(--rule)}
table.tight{font-size:13.5px;color:var(--ink)}
table.tight th{font-size:10.5px;font-weight:700;letter-spacing:.09em;text-transform:uppercase;
  color:var(--mute);border-bottom:1px solid var(--rule-strong)!important;white-space:nowrap;
  background:var(--sunk)}
table.tight td{border-bottom:1px solid var(--rule);vertical-align:middle;color:var(--ink)}
table.tight tr:last-child td{border-bottom:none}
/* Tables scroll inside their own box, never the page. The box is positioned
   so that visually-hidden text inside it (which is absolutely positioned) is
   clipped with the rest instead of widening the page. */
.table-responsive{-webkit-overflow-scrolling:touch;position:relative}
.table-responsive>table.tight{min-width:460px}

/* Wide record tables become one card per row below xl. The table element must
   stop laying out as a table or it keeps its content width and pushes the page
   sideways; that drops implicit table semantics, so the markup carries
   explicit ARIA roles. */
@media (max-width:1199.98px){
  table.stacked{display:block;width:100%;min-width:0!important}
  table.stacked tbody{display:block;width:100%}
  table.stacked thead{position:absolute;width:1px;height:1px;overflow:hidden;clip:rect(0,0,0,0)}
  table.stacked tr{display:block;border:1px solid var(--rule);border-radius:9px;
    padding:.5rem .75rem;margin-bottom:.6rem;background:var(--card)}
  table.stacked td{display:flex;justify-content:space-between;align-items:center;gap:1rem;
    border:0;border-bottom:1px solid var(--rule);padding:.42rem 0;text-align:left!important}
  table.stacked tr td:last-child{border-bottom:0}
  table.stacked td::before{content:attr(data-label);font-size:10.5px;font-weight:700;
    letter-spacing:.08em;text-transform:uppercase;color:var(--mute);flex:0 0 auto}
  table.stacked td:empty{display:none}
  table.stacked td.rowhead{border-bottom:1px solid var(--rule-strong);padding-top:0;
    font-size:1.05rem;font-weight:600}
  table.stacked td.rowhead::before{content:none}
  table.stacked td.row-actions{flex-wrap:wrap;justify-content:flex-start}
  table.stacked td.row-actions::before{flex-basis:100%}
  .stacked-wrap{overflow:visible!important}
  .stacked-wrap>table.tight{min-width:0}
}

/* ---------- status badges — the word carries the meaning ---------- */
.badge-status{font-size:10.5px;font-weight:700;letter-spacing:.06em;text-transform:uppercase;
  padding:.28em .6em;border-radius:5px;border:1px solid transparent;display:inline-block}
.s-neutral{background:var(--neutral-bg);color:var(--neutral-fg);border-color:var(--rule-strong)}
.s-progress{background:var(--progress-bg);color:var(--progress-fg);border-color:var(--progress-fg)}
.s-done{background:var(--done-bg);color:var(--done-fg);border-color:var(--done-fg)}

/* ---------- buttons ---------- */
.btn-brand{--bs-btn-color:var(--brand-btn-fg);--bs-btn-bg:var(--brand-btn);
  --bs-btn-border-color:var(--brand-btn);
  --bs-btn-hover-color:var(--brand-btn-fg);--bs-btn-hover-bg:var(--brand-btn);
  --bs-btn-hover-border-color:var(--brand-btn);
  --bs-btn-active-color:var(--brand-btn-fg);--bs-btn-active-bg:var(--brand-btn);
  --bs-btn-active-border-color:var(--brand-btn);
  --bs-btn-disabled-color:var(--brand-btn-fg);--bs-btn-disabled-bg:var(--brand-btn);
  --bs-btn-disabled-border-color:var(--brand-btn);font-weight:500}
.btn-brand:hover,.btn-brand:focus-visible{filter:brightness(1.14)}
.navbar .btn-brand{--bs-btn-color:var(--brand-chrome-fg);--bs-btn-bg:var(--brand-chrome);
  --bs-btn-border-color:var(--brand-chrome);
  --bs-btn-hover-color:var(--brand-chrome-fg);--bs-btn-hover-bg:var(--brand-chrome);
  --bs-btn-hover-border-color:var(--brand-chrome);
  --bs-btn-active-color:var(--brand-chrome-fg);--bs-btn-active-bg:var(--brand-chrome);
  --bs-btn-active-border-color:var(--brand-chrome)}

/* Passkey sign-in is a peer of the password, not a lesser option. */
.btn-passkey{--bs-btn-color:var(--accent);--bs-btn-bg:var(--accent-soft);
  --bs-btn-border-color:var(--accent);--bs-btn-border-width:2px;
  --bs-btn-hover-color:var(--card);--bs-btn-hover-bg:var(--accent);
  --bs-btn-hover-border-color:var(--accent);
  --bs-btn-active-color:var(--card);--bs-btn-active-bg:var(--accent);
  --bs-btn-active-border-color:var(--accent);
  font-weight:600;display:inline-flex;align-items:center;justify-content:center;gap:.5rem}
.btn-passkey:focus-visible{color:var(--card);background:var(--accent)}
.btn-passkey svg{width:17px;height:17px;fill:none;stroke:currentColor;stroke-width:2;
  stroke-linecap:round;stroke-linejoin:round}

.btn-outline-secondary{--bs-btn-color:var(--ink-2);--bs-btn-border-color:var(--rule-strong);
  --bs-btn-hover-color:var(--ink);--bs-btn-hover-bg:var(--sunk);
  --bs-btn-hover-border-color:var(--rule-strong);
  --bs-btn-active-color:var(--ink);--bs-btn-active-bg:var(--sunk);
  --bs-btn-active-border-color:var(--rule-strong);
  --bs-btn-disabled-color:var(--mute);--bs-btn-disabled-border-color:var(--rule-strong)}
/* Bootstrap's own danger red fails 4.5:1 in the dark theme, so it is replaced. */
.btn-outline-danger{--bs-btn-color:var(--danger);--bs-btn-border-color:var(--danger);
  --bs-btn-hover-color:var(--card);--bs-btn-hover-bg:var(--danger);
  --bs-btn-hover-border-color:var(--danger);
  --bs-btn-active-color:var(--card);--bs-btn-active-bg:var(--danger);
  --bs-btn-active-border-color:var(--danger);
  --bs-btn-disabled-color:var(--danger);--bs-btn-disabled-border-color:var(--danger)}
.btn-link{--bs-btn-color:var(--link);--bs-btn-hover-color:var(--link);--bs-btn-active-color:var(--link)}
.btn svg.icon,.dropdown-item svg.icon{width:15px;height:15px;fill:none;stroke:currentColor;
  stroke-width:2;stroke-linecap:round;stroke-linejoin:round;flex:0 0 auto;vertical-align:-2px}

/* ---------- forms ---------- */
.form-label{font-size:12px;font-weight:600;color:var(--ink-2);margin-bottom:.25rem}
.form-control,.form-select{background-color:var(--card);color:var(--ink);border-color:var(--rule-strong)}
.form-control::placeholder{color:var(--mute);opacity:1}
.form-control:focus,.form-select:focus{background-color:var(--card);color:var(--ink);
  border-color:var(--accent);box-shadow:0 0 0 .2rem color-mix(in srgb,var(--accent) 26%,transparent)}
.form-control:disabled{background-color:var(--sunk);color:var(--mute)}
/* invalid controls read as invalid without relying on colour alone */
.form-control:user-invalid,.form-select:user-invalid{border-color:var(--danger);border-width:2px}

/* ---------- alerts and flashes ---------- */
.alert{border-radius:8px;color:var(--ink)}
.alert a{color:var(--link)}
.alert-light{background:var(--sunk);border-color:var(--rule-strong)}
.alert-warning{background:var(--warn-bg);border-color:var(--warn-bd)}
.alert-success{background:var(--done-bg);border-color:var(--done-fg)}
.alert-danger{background:var(--warn-bg);border-color:var(--danger)}
.alert code{font-size:1em;font-weight:600;overflow-wrap:anywhere}

/* ---------- dropdown menu ---------- */
.navbar .dropdown-toggle{background:none;border:0;color:var(--chrome-mute);font-weight:500;
  padding:.3rem .6rem;border-radius:6px}
.navbar .dropdown-toggle:hover{background:var(--chrome-hover);color:var(--chrome-ink)}
.navbar .dropdown-toggle.active{background:var(--chrome-hover);color:var(--chrome-ink);font-weight:600}
.navbar .dropdown-toggle::after{color:var(--chrome-mute)}
.dropdown-menu{background:var(--card);border:1px solid var(--rule-strong);border-radius:9px;
  box-shadow:0 8px 28px -12px rgba(16,24,32,.4);padding:.35rem;min-width:12rem}
/* holds an email address, so no uppercasing and no letter-spacing */
.dropdown-header{color:var(--mute);font-size:12px;font-weight:600;padding:.4rem .6rem;max-width:15rem}
.dropdown-item{color:var(--ink);border-radius:6px;padding:.42rem .6rem;font-size:14px}
.dropdown-item:hover,.dropdown-item:focus{background:var(--sunk);color:var(--ink)}
.dropdown-item.active,.dropdown-item:active{background:var(--accent-soft);color:var(--accent);
  font-weight:600}
.dropdown-divider{border-color:var(--rule);margin:.3rem 0;opacity:1}

/* ---------- avatars ---------- */
.user-chip{width:26px;height:26px;border-radius:50%;flex:0 0 auto;overflow:hidden;
  background:var(--brand-chrome);color:var(--brand-chrome-fg);
  display:grid;place-items:center;font-size:11px;font-weight:700;letter-spacing:.02em}
.avatar-lg{width:84px;height:84px;border-radius:50%;flex:0 0 auto;overflow:hidden;
  background:var(--brand-btn);color:var(--brand-btn-fg);
  display:grid;place-items:center;font-size:26px;font-weight:700;
  border:1px solid var(--rule-strong)}
.user-chip img,.avatar-lg img{width:100%;height:100%;object-fit:cover;border-radius:50%;display:block}

/* ---------- step rail ---------- */
.steps{list-style:none;display:flex;flex-wrap:wrap;gap:.35rem;margin:0;padding:.5rem .75rem;
  background:var(--card);border:1px solid var(--rule);border-radius:.5rem}
.steps li{display:flex;align-items:center;gap:.45rem;font-size:13px;color:var(--mute);
  padding:.15rem .6rem .15rem .15rem}
.steps li + li::before{content:"";width:14px;height:1px;background:var(--rule-strong);
  margin-right:.45rem;flex:0 0 auto}
.steps .mark{flex:0 0 auto;width:20px;height:20px;border-radius:50%;
  display:grid;place-items:center;font-size:11px;font-weight:700;
  border:1px solid var(--rule-strong);color:var(--mute);background:var(--card)}
.steps .now,.steps .done{color:var(--ink);font-weight:600}
.steps .now .mark,.steps .done .mark{background:var(--accent-soft);color:var(--accent);
  border-color:var(--accent)}

/* ---------- feature list, "or" divider, disclosure ---------- */
.feature-list{list-style:none;margin:0;padding:0;display:flex;flex-direction:column;gap:.8rem}
.feature-list li{display:flex;gap:.7rem;align-items:flex-start;font-size:13.5px;color:var(--ink-2)}
.feature-list strong{color:var(--ink);font-weight:600}
.feature-mark{flex:0 0 auto;width:20px;height:20px;border-radius:50%;
  background:var(--accent-soft);display:grid;place-items:center;margin-top:.1rem}
.feature-mark svg{width:12px;height:12px;fill:none;stroke:var(--accent);
  stroke-width:3;stroke-linecap:round;stroke-linejoin:round}

.sep-or{display:flex;align-items:center;gap:.75rem;margin:1rem 0;color:var(--mute);font-size:12px}
.sep-or::before,.sep-or::after{content:"";flex:1;height:1px;background:var(--rule-strong)}

/* An advanced detail that is right there but not in the way. */
details.opt > summary{cursor:pointer;font-size:13px;color:var(--ink-2);
  padding:.35rem .5rem;border:1px solid var(--rule);border-radius:.375rem;
  background:var(--sunk)}
details.opt > summary:hover{color:var(--ink)}

/* ---------- guided tour ---------- */
.tour-mask{position:fixed;inset:0;background:rgba(8,12,16,.62);z-index:1080}
.tour-hole{position:absolute;z-index:1081;border-radius:10px;pointer-events:none;
  box-shadow:0 0 0 3px var(--chrome-accent),0 0 0 9999px rgba(8,12,16,.62)}
.tour-pop{position:absolute;z-index:1082;max-width:340px;background:var(--card);
  color:var(--ink);border:1px solid var(--rule-strong);border-radius:11px;
  padding:1rem 1.1rem;box-shadow:0 14px 40px -12px rgba(0,0,0,.55)}
.tour-step{font-size:10.5px;font-weight:700;letter-spacing:.13em;text-transform:uppercase;
  color:var(--mute);margin:0 0 .35rem}
.tour-title{font-size:1rem;font-weight:600;margin:0 0 .35rem;color:var(--ink)}
.tour-body{font-size:13.5px;color:var(--ink-2);margin:0 0 .9rem}
.tour-actions{display:flex;align-items:center;gap:.4rem}
.tour-grow{flex:1 1 auto}
.tour-actions .btn-link{--bs-btn-color:var(--mute);--bs-btn-hover-color:var(--ink);
  text-decoration:underline;padding-left:0}
body.tour-open{overflow:hidden}
.tour-launch{color:var(--mute);text-decoration:underline;font-size:12.5px;
  background:none;border:0;padding:0}
.tour-launch:hover{color:var(--ink)}

/* ============================================================
   Chat page. On a wide screen the thread scrolls in its own box
   and the page does not: the shell becomes a fixed-height column
   and the thread card takes whatever is left. On a phone or a
   short window that would leave the thread a sliver, so there it
   keeps a fixed share of the height and the page scrolls to the
   composer.
   ============================================================ */
.chat-side-inner .card + .card{margin-top:1rem}
@media (min-width:992px){
  /* the cards are always shown on a wide screen; the collapse only applies below lg */
  .chat-side-inner.collapse:not(.show){display:block}
}
@media (min-width:992px) and (min-height:560px){
  body.chat-page{height:100vh;height:100dvh;min-height:0}
  body.chat-page > main{flex:1 1 auto;min-height:0;display:flex;flex-direction:column;overflow-y:auto}
  body.chat-page .chat-layout{flex:1 1 auto;min-height:0}
  body.chat-page .chat-side,
  body.chat-page .chat-main{min-height:0;height:100%;display:flex;flex-direction:column}
  body.chat-page .chat-thread{flex:1 1 0;height:auto;min-height:120px}
  body.chat-page .chat-composer,
  body.chat-page .code-panel{flex:0 0 auto}
  body.chat-page .chat-side-inner{flex:1 1 auto;min-height:0;display:flex!important;
    flex-direction:column;gap:1rem}
  body.chat-page .chat-side-inner .card{flex:1 1 0;min-height:0;display:flex;flex-direction:column}
  body.chat-page .chat-side-inner .card + .card{margin-top:0}
  body.chat-page .chat-side-inner .card > nav{flex:1 1 auto;min-height:0;overflow-y:auto}
  body.chat-page .chat-side-inner .chat-list{max-height:none;overflow:visible}
  /* a tall code box must not squeeze the thread away */
  body.chat-page .code-input{max-height:26vh}
}

.chat-list{list-style:none;margin:0;padding:.35rem;max-height:14rem;overflow-y:auto;
  position:relative}
.chat-list .chat-list-btn{display:block;width:100%;text-align:left;background:none;border:0;
  color:var(--ink);font-size:13.5px;padding:.4rem .6rem;border-radius:6px;
  white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.chat-list .chat-list-btn:hover{background:var(--sunk)}
.chat-list .chat-list-btn[aria-current="true"]{background:var(--accent-soft);color:var(--accent);
  font-weight:600}
.chat-list .chat-list-btn:focus-visible{outline-offset:-3px}
.chat-list .chat-list-links{display:flex;flex-wrap:wrap;gap:.1rem .75rem;align-items:baseline;
  padding:0 .6rem .45rem;font-size:12px;color:var(--mute)}
.chat-list .chat-list-empty{padding:.4rem .6rem;font-size:13px;color:var(--mute)}
.chat-side-foot{border-top:1px solid var(--rule);padding:.5rem .95rem;font-size:12.5px}

.chat-thread{overflow-y:auto;padding:1rem;display:flex;flex-direction:column;gap:.9rem;
  position:relative;height:clamp(260px,52vh,560px)}
/* messages keep their own height; the thread scrolls instead of squeezing them */
.chat-thread > *{flex-shrink:0}
.chat-empty{margin:auto;text-align:center;max-width:34rem;padding:1rem}
.chat-empty[hidden]{display:none}
.msg{max-width:100%;overflow-wrap:anywhere}
/* the user's turn: a quiet sunk block on the right, never a filled bubble */
.msg-user{align-self:flex-end;max-width:min(46rem,88%);background:var(--sunk);color:var(--ink);
  border:1px solid var(--rule);border-radius:10px;padding:.6rem .85rem;white-space:pre-wrap;
  max-height:22rem;overflow-y:auto}
.msg-assistant{align-self:stretch}
.msg-assistant > .card-body{padding:.9rem 1rem}
.msg-error{align-self:stretch;margin:0}
.chat-wait{display:flex;align-items:center;gap:.6rem;color:var(--ink-2);font-size:13.5px;
  padding:.2rem .1rem;flex-wrap:wrap}
.chat-wait .spinner-border{width:1rem;height:1rem;border-width:2px;color:var(--accent);flex:0 0 auto}
.chat-wait .steps{flex:1 1 100%}
.chat-status{font-size:12.5px;color:var(--ink-2);margin:-.5rem 0 .5rem;padding:0 .15rem}
.chat-status:empty{display:none}
.chat-composer[hidden]{display:none}

/* rendered Markdown from the server (escape-first renderer) */
.md-body{font-size:14.5px;line-height:1.6}
.md-body > :last-child{margin-bottom:0}
/* headings arrive one level down (the page keeps the only <h1>) */
.md-body h2{font-size:1.25rem;font-weight:600;margin:1.2rem 0 .6rem}
.md-body h3{font-size:1.1rem;font-weight:600;margin:1.1rem 0 .5rem}
.md-body h4{font-size:1rem;font-weight:600;margin:1rem 0 .4rem}
.md-body h5,.md-body h6{font-size:.95rem;font-weight:600;margin:.9rem 0 .35rem}
.md-body > :first-child{margin-top:0}
.md-body pre{background:var(--sunk);color:var(--ink);border:1px solid var(--rule-strong);
  border-radius:8px;padding:.75rem .9rem;overflow-x:auto;font-size:12.5px;line-height:1.5;
  font-family:ui-monospace,"SF Mono",Menlo,Consolas,monospace}
.md-body :not(pre) > code{background:var(--sunk);color:var(--ink);border:1px solid var(--rule);
  border-radius:4px;padding:.05em .3em;font-size:.9em}
.md-body pre code{background:none;border:0;padding:0;font-size:inherit}
.md-body blockquote{border-left:3px solid var(--rule-strong);margin:0 0 1rem;
  padding:.1rem 0 .1rem .85rem;color:var(--ink-2)}
.md-body blockquote p{margin:0}
.md-body hr{margin:1rem 0}
.md-body .table-responsive{margin:0 0 1rem;border:1px solid var(--rule);border-radius:8px}
.md-body table.tight{margin:0}
.md-body table.tight th,.md-body table.tight td{padding:.4rem .6rem}
.md-body table.tight th{white-space:normal}

.chat-video video{display:block;width:100%;max-height:60vh;background:#000;border-radius:8px}
.chat-video-meta{font-size:12.5px;color:var(--mute);margin:.35rem 0 0}
.chat-downloads{display:flex;flex-wrap:wrap;align-items:center;gap:.4rem;margin:.75rem 0}
.chat-downloads-label{font-size:12px;font-weight:600;color:var(--ink-2)}
.msg-assistant details.opt{margin-top:.75rem}
.msg-assistant details.opt ul{margin:.5rem 0 0;padding-left:1.2rem;font-size:13px;color:var(--ink-2)}

.chat-composer .card-body{padding:.75rem 1rem}
.chat-input{resize:none;max-height:240px;overflow-y:auto}
.chat-actions{display:flex;align-items:center;flex-wrap:wrap;gap:.4rem;margin-top:.5rem}
.chat-actions .grow{flex:1 1 auto}
.chat-help{font-size:12px;color:var(--mute);margin:.5rem 0 0}
.code-panel[hidden]{display:none}
.code-input{font-family:ui-monospace,"SF Mono",Menlo,Consolas,monospace;font-size:12.5px;
  line-height:1.5;white-space:pre;overflow:auto;resize:vertical;min-height:9rem}
.code-input.is-dropping{border-color:var(--accent);border-width:2px}
.code-language{width:auto;max-width:100%}

/* ---------- preferences ---------- */
@media (prefers-reduced-motion:reduce){
  *,*::before,*::after{animation:none!important;transition:none!important;scroll-behavior:auto!important}
  /* a spinner that cannot spin says nothing; the status line carries the words */
  .chat-wait .spinner-border{display:none}
}
@media (prefers-contrast:more){
  :root{--rule:var(--rule-strong)}
  .card,.page-head{border-width:2px}
}

/* ============================================================
   Responsive (UI spec §10).
   ============================================================ */
@media (max-width:991.98px){
  /* the navbar's right-hand cluster stacks once collapsed */
  .navbar-collapse .nav-actions{flex-direction:column;align-items:stretch!important;
    gap:.5rem!important;padding-top:.75rem;margin-top:.5rem;border-top:1px solid var(--chrome-rule)}
  .navbar-collapse .nav-actions .btn{width:100%}
  .navbar-collapse .theme-switch{align-self:flex-start}
  /* the collapsed menu can exceed the viewport on a phone */
  .site-header .navbar-collapse{max-height:calc(100vh - var(--nav-h));overflow-y:auto}
  /* Below lg the toggle itself shows the address, so the menu header repeats it. */
  .navbar .dropdown-header,
  .navbar .dropdown-menu > li:first-child + li > .dropdown-divider{display:none}
  /* In the collapsed menu the account menu opens in the flow, not on top of
     it: the collapse scrolls, and a floating menu would be clipped by it. */
  .navbar .dropdown-menu{position:static;width:100%;margin-top:.35rem;box-shadow:none}
  .navbar .dropdown-toggle{width:100%;text-align:left}
}
@media (max-width:767.98px){
  body{font-size:15px}
  main.container-fluid{padding-left:1rem!important;padding-right:1rem!important}
  /* header block stops trying to be a two-column layout */
  .page-head{flex-direction:column;align-items:flex-start;padding:.9rem 1rem}
  .page-head .text-end{text-align:left!important}
  /* alerts with an action stack the action underneath */
  .alert-stack{flex-direction:column;align-items:flex-start!important;gap:.6rem}
  .alert-stack .btn{align-self:flex-start}
}
@media (max-width:575.98px){
  h1.h4{font-size:1.28rem}
  .footer-inner{padding:.8rem 1rem;font-size:12px}
  .steps li{font-size:12px}
  .tour-pop{max-width:none}
  .msg-user{max-width:96%}
}

/* touch targets: 44px minimum where the pointer is a finger */
@media (pointer:coarse){
  /* 44px controls plus the bar's own padding: the header is taller here, and
     everything that keys off its height follows */
  :root{--nav-h:63px}
  .theme-switch button{min-width:44px;min-height:44px}
  .navbar .nav-link,.navbar .dropdown-toggle,.navbar-toggler,.navbar .navbar-brand{min-height:44px;
    display:flex;align-items:center}
  .navbar-toggler{min-width:44px;justify-content:center}
  .btn,.form-control,textarea.form-control,.form-select,.dropdown-item,.chat-list .chat-list-btn,
  details.opt > summary,.tour-launch{min-height:44px}
  .btn{display:inline-flex;align-items:center;justify-content:center}
  .btn-close{min-width:44px;min-height:44px;box-sizing:border-box}
  .chat-list .chat-list-links a{min-height:44px;display:inline-flex;align-items:center}
}

/* ---------- narrow auth and message cards (UI spec §4.4) ---------- */
.card-narrow{margin:2rem auto;max-width:460px}
.field-file{max-width:22rem}
