/* PathKEY design system v3 — foundation, shell and components.
 *
 * Paints with the role tokens in css/tokens.css only (no colour literals
 * here: test/tokens.test.mjs checks). Page stylesheets (css/*.css) build on
 * these classes and never redefine them. Order: base · type · layout
 * utilities · shell · components · page patterns written before v3 ·
 * responsive · print. The contract is docs/foundation-api.md. */

/* ============================================================== base === */
*, *::before, *::after { box-sizing: border-box; }
html {
  background: var(--bg-canvas);
  -webkit-text-size-adjust: 100%;
  scroll-padding-top: calc(var(--topline-h) + var(--appbar-h) + 16px);   /* focus never hides under the app bar */
}
body {
  margin: 0;
  font: var(--fw-regular) var(--fs-14)/var(--lh-14) var(--font-ui);
  color: var(--text);
  background: var(--bg-canvas);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}
body.has-savebar { scroll-padding-bottom: calc(var(--savebar-now, var(--savebar-h)) + 16px); }
::selection { background: var(--ak-teal-100); color: var(--text); }
[hidden] { display: none !important; }                    /* author display rules never beat [hidden] (A11Y-05) */
:focus-visible { outline: none; box-shadow: var(--focus-ring); }
a { color: var(--text-link); text-decoration-thickness: 1px; text-underline-offset: 2px; }
a:hover { color: var(--accent-pressed); }
p { margin: 0; }
hr { border: 0; border-top: 1px solid var(--line); margin: 0; }
fieldset { border: 0; padding: 0; margin: 0; min-width: 0; }
template { display: none; }
img, svg { max-width: 100%; }
button { font: inherit; color: inherit; }
input, textarea { caret-color: var(--accent); }
input:-webkit-autofill { -webkit-box-shadow: 0 0 0 40px var(--bg-surface) inset; -webkit-text-fill-color: var(--text); }
input[type=number]::-webkit-inner-spin-button, input[type=number]::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
input[type=number] { -moz-appearance: textfield; }
.icon-sprite, #pk-sprite { position: absolute; width: 0; height: 0; overflow: hidden; }

/* ============================================================== type === */
h1, h2, h3, h4 { margin: 0; color: var(--text); font-family: var(--font-ui); text-wrap: balance; }
h1 { font-size: var(--fs-26); line-height: var(--lh-26); font-weight: var(--fw-bold); letter-spacing: var(--track-display); }
h2 { font-size: var(--fs-20); line-height: var(--lh-20); font-weight: var(--fw-bold); letter-spacing: var(--track-tight); }
h3 { font-size: var(--fs-16); line-height: var(--lh-16); font-weight: var(--fw-semibold); letter-spacing: var(--track-tight); }
h4 { font-size: 15px; line-height: 22px; font-weight: var(--fw-semibold); }
h1:focus, h2:focus { outline: none; box-shadow: none; }
p, li, td { text-wrap: pretty; }

.eyebrow {
  font-size: var(--fs-11); line-height: var(--lh-11); font-weight: var(--fw-bold);
  letter-spacing: var(--track-eyebrow); text-transform: uppercase; color: var(--text-eyebrow);
}
.heading-accent { color: var(--text-heading-accent); }
.muted { color: var(--text-muted); }
.small { font-size: var(--fs-13); line-height: var(--lh-13); }
.lede, .page-desc { color: var(--text-muted); font-size: var(--fs-14); line-height: 21px; max-width: 76ch; }
.num, td.num, th.num, .kpi-value { font-variant-numeric: tabular-nums lining-nums; }
.hint { font-size: var(--fs-12); line-height: var(--lh-12); color: var(--text-muted); }
code, kbd, .code { font-family: var(--font-code); }
.kbd {
  display: inline-grid; place-items: center; min-width: 18px; height: 18px; padding: 0 5px;
  font: var(--fw-medium) var(--fs-11)/1 var(--font-ui); color: var(--text-muted);
  background: var(--bg-sunken); border-radius: var(--r-4); letter-spacing: 0;
}
.vh, .sr-only {
  position: absolute !important; width: 1px; height: 1px; margin: -1px; padding: 0;
  overflow: hidden; clip-path: inset(50%); white-space: nowrap; border: 0;
}

/* ================================================= layout utilities === */
.stack { display: flex; flex-direction: column; }
.row { display: flex; align-items: center; }
.gap-1 { gap: var(--sp-1); } .gap-2 { gap: var(--sp-2); } .gap-3 { gap: var(--sp-3); }
.gap-4 { gap: var(--sp-4); } .gap-5 { gap: var(--sp-5); } .gap-6 { gap: var(--sp-6); }
.grow { flex: 1 1 0%; min-width: 0; }
.wrap { flex-wrap: wrap; }
.scroll-x { overflow-x: auto; }
.cols-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 260px), 1fr)); gap: var(--sp-4); }
.cols-3 { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 150px), 1fr)); gap: var(--sp-4); }

/* ============================================================= shell === */
.app { min-height: 100vh; min-height: 100dvh; display: flex; flex-direction: column; background: var(--bg-canvas); }
.skip-link {
  position: absolute; left: var(--sp-4); top: -48px; z-index: calc(var(--z-tooltip) + 1);
  padding: var(--sp-2) var(--sp-4); border-radius: var(--r-full);
  background: var(--bg-surface); color: var(--accent-text); font-weight: var(--fw-semibold);
  transition: top var(--dur-2) var(--ease);
}
.skip-link:focus { top: var(--sp-3); box-shadow: var(--shadow-3), var(--focus-ring); }

/* the thin gold bar across the very top, then the app bar */
.app-top { position: sticky; top: 0; z-index: var(--z-appbar); }
.topline { height: var(--topline-h); background: var(--cta); }
.appbar {
  height: var(--appbar-h); display: flex; align-items: center; gap: var(--sp-3);
  padding: 0 var(--sp-4) 0 0; background: var(--bg-surface); border-bottom: 1px solid var(--line);
}
.appbar-brand {
  width: var(--rail-w); flex: none; display: flex; align-items: center; padding-left: var(--sp-5); height: 100%;
  text-decoration: none; color: var(--text); border-radius: var(--r-8);
}
.appbar-brand:focus-visible { box-shadow: var(--focus-ring-inset); }
.appbar-brand img { display: block; height: 36px; width: auto; }
.appbar-brand .brand-mark-img { display: none; height: 30px; width: 30px; }
.appbar-product { flex: none; display: flex; align-items: baseline; gap: var(--sp-2); min-width: 0; margin-left: calc(-1 * var(--sp-3)); padding-left: var(--sp-4); border-left: 1px solid var(--line); line-height: 24px; }
.appbar-product strong { font-size: var(--fs-14); font-weight: var(--fw-semibold); letter-spacing: var(--track-tight); }
.appbar-product span { font-size: var(--fs-13); color: var(--text-muted); white-space: nowrap; }
/* MVP roles, then the MVP demo: "View as" Admin · Coach · Company · Respondent, at the top right, for an account
   that has more than one perspective */
.area-switch { flex: none; display: inline-flex; align-items: center; gap: 2px; padding: 2px; border-radius: var(--r-full); background: var(--bg-sunken); }
.area-switch-label { padding: 0 6px 0 10px; color: var(--text-muted); font: var(--fw-medium) var(--fs-12)/1 var(--font-ui); white-space: nowrap; }
.bare-top .area-switch { margin-right: var(--sp-2); }
/* The Guide, next to the switch: a checklist in a popover */
.appbar-guide { flex: none; margin-left: var(--sp-1); }
.guide-badge { margin-left: 2px; padding: 1px 6px; border-radius: var(--r-full); background: var(--bg-sunken); color: var(--text-muted); font-size: var(--fs-11); }
.popover.guide-pop { max-width: min(400px, calc(100vw - 16px)); }
.guide-panel { padding: var(--sp-3); display: flex; flex-direction: column; gap: var(--sp-2); width: 380px; max-width: 100%; }
.guide-head { display: flex; align-items: baseline; justify-content: space-between; gap: var(--sp-3); }
.guide-head h2 { font-size: var(--fs-14); line-height: var(--lh-14, 1.4); }
.guide-count { font-size: var(--fs-12); white-space: nowrap; }
.guide-sub { margin: 0; font-size: var(--fs-12); color: var(--text-2); }
.guide-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 2px; }
.guide-step { display: flex; align-items: center; gap: var(--sp-2); }
.guide-check { flex: none; width: 16px; height: 16px; margin: 0 2px 0 4px; accent-color: var(--cta); }
.guide-go { flex: 1; min-width: 0; display: flex; align-items: center; gap: var(--sp-2); padding: 6px var(--sp-2); border-radius: var(--r-8); color: var(--text); text-decoration: none; }
@media (hover: hover) and (pointer: fine) { .guide-go:hover { background: var(--bg-hover); } }
.guide-go:focus-visible { box-shadow: var(--focus-ring-inset); outline: none; }
.guide-go > .icon { flex: none; color: var(--icon); }
.guide-num { flex: none; width: 20px; height: 20px; display: inline-grid; place-items: center; border-radius: var(--r-full); background: var(--bg-sunken); font-size: var(--fs-11); color: var(--text-2); }
.guide-text { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.guide-label { font-size: var(--fs-13); font-weight: var(--fw-medium); }
.guide-meta { font-size: var(--fs-12); color: var(--text-muted); }
.guide-step.is-done .guide-label { color: var(--text-muted); text-decoration: line-through; }
.guide-foot { display: flex; justify-content: flex-end; padding-top: var(--sp-2); border-top: 1px solid var(--line-soft); }
/* The respondent mode: Back to Coach on the respondent pages and the report */
.respondent-back:empty { display: none; }
.respondent-bar { display: flex; align-items: center; justify-content: flex-end; gap: var(--sp-3); }
.app-top > .respondent-back .respondent-bar { padding: var(--sp-2) var(--gutter, 16px); background: var(--bg-surface); border-bottom: 1px solid var(--line); }
.respondent-bar-text { display: inline-flex; align-items: center; gap: var(--sp-2); font-size: var(--fs-13); color: var(--text-2); }
.area-switch-opt { display: inline-flex; align-items: center; gap: 5px; height: 28px; padding: 0 12px; border-radius: var(--r-full);
  color: var(--text-2); font: var(--fw-medium) var(--fs-13)/1 var(--font-ui); text-decoration: none; white-space: nowrap; }
@media (hover: hover) and (pointer: fine) { .area-switch-opt:hover { color: var(--text); } }
.area-switch-opt[aria-current="page"] { background: var(--bg-surface); color: var(--text); box-shadow: var(--shadow-seg); }
.appbar-search {
  flex: 0 1 440px; min-width: 0; height: var(--h-md); display: flex; align-items: center; gap: var(--sp-2);
  margin-left: var(--sp-3); padding: 0 var(--sp-2) 0 var(--sp-3); border: 1px solid transparent; border-radius: var(--r-full);
  background: var(--bg-sunken); color: var(--text-muted); cursor: pointer; text-align: left;
  transition: background var(--dur-1) var(--ease), border-color var(--dur-1) var(--ease);
}
@media (hover: hover) and (pointer: fine) { .appbar-search:hover { background: var(--bg-pressed); } }
.appbar-search .appbar-search-text { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: var(--fs-13); }
.appbar-search .kbd { background: var(--bg-surface); }
.appbar-spacer { flex: 1; }
.appbar-tools { display: flex; align-items: center; gap: var(--sp-1); }
.appbar-divider { width: 1px; height: 24px; background: var(--line); margin: 0 var(--sp-2); }
.account-btn {
  display: flex; align-items: center; gap: var(--sp-2); height: 40px; padding: 0 var(--sp-2) 0 var(--sp-1);
  border: 0; border-radius: var(--r-full); background: none; cursor: pointer; text-align: left;
  transition: background var(--dur-1) var(--ease);
}
.account-btn[aria-expanded="true"] { background: var(--bg-hover); }
@media (hover: hover) and (pointer: fine) { .account-btn:hover { background: var(--bg-hover); } }
.account-btn > .icon { color: var(--icon); }
.account-text { display: flex; flex-direction: column; min-width: 0; max-width: 190px; }
.account-name { font-size: var(--fs-13); line-height: 17px; font-weight: var(--fw-medium); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.account-role { font-size: var(--fs-11); line-height: 14px; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.appbar .appbar-menu-btn { display: none; }

.app-body {
  flex: 1; display: flex; min-height: 0;
  /* the rail's column runs the full page height, even past a sticky rail */
  background: linear-gradient(90deg, var(--bg-surface) 0 calc(var(--rail-w) - 1px), var(--line) calc(var(--rail-w) - 1px) var(--rail-w), transparent var(--rail-w));
}
.work {
  flex: 1; min-width: 0; display: flex; flex-direction: column;
  background: var(--wash-image) top left / 100% 320px no-repeat, var(--bg-canvas);
}
.work:focus { outline: none; box-shadow: none; }
.work > .page { flex: 1; }

/* left rail */
.rail {
  width: var(--rail-w); flex: none; position: sticky; top: calc(var(--topline-h) + var(--appbar-h));
  height: calc(100vh - var(--topline-h) - var(--appbar-h)); height: calc(100dvh - var(--topline-h) - var(--appbar-h));
  display: flex; flex-direction: column; background: var(--bg-surface); border-right: 1px solid var(--line);
  z-index: var(--z-sticky); transition: width var(--dur-3) var(--ease);
}
.rail-scroll { flex: 1; overflow-y: auto; overflow-x: hidden; padding: var(--sp-4) var(--sp-3); scrollbar-width: thin; }
.nav-group + .nav-group { margin-top: var(--sp-5); }
.nav-heading {
  padding: 0 var(--sp-3) var(--sp-2); font-size: var(--fs-11); line-height: var(--lh-11); font-weight: var(--fw-semibold);
  letter-spacing: var(--track-caps); text-transform: uppercase; color: var(--text-muted); white-space: nowrap;
}
.nav-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 2px; }
.nav-item {
  position: relative; display: flex; align-items: center; gap: var(--sp-3); height: 38px; padding: 0 var(--sp-3);
  border-radius: var(--r-control); color: var(--text-2); font-size: var(--fs-14); font-weight: var(--fw-regular);
  text-decoration: none; white-space: nowrap; background: none; border: 0; width: 100%; cursor: pointer; text-align: left;
  transition: background var(--dur-1) var(--ease), color var(--dur-1) var(--ease);
}
.nav-item .icon { color: var(--icon); transition: color var(--dur-1) var(--ease); }
@media (hover: hover) and (pointer: fine) { .nav-item:hover { background: var(--bg-hover); color: var(--text); } }
.nav-item[aria-current="page"] { background: var(--bg-selected); color: var(--accent-text); font-weight: var(--fw-medium); }
.nav-item[aria-current="page"] .icon { color: var(--accent); }
.nav-item[aria-current="page"]::before {
  content: ""; position: absolute; left: calc(-1 * var(--sp-3)); top: 7px; bottom: 7px; width: 3px;
  background: var(--accent); border-radius: 0 3px 3px 0;
}
.nav-item:focus-visible { box-shadow: var(--focus-ring-inset); }
.nav-label { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.nav-count { font-size: var(--fs-12); color: var(--text-muted); font-variant-numeric: tabular-nums; }
.nav-count.is-needs-you {
  min-width: 20px; height: 20px; display: inline-grid; place-items: center; padding: 0 6px; border-radius: var(--r-full);
  background: var(--highlight-soft); color: var(--highlight-strong-text); font-size: var(--fs-11); font-weight: var(--fw-semibold);
}
.rail-foot { border-top: 1px solid var(--line-soft); padding: var(--sp-3); display: flex; flex-direction: column; gap: var(--sp-2); }
.rail-eu { display: flex; align-items: center; gap: var(--sp-2); padding: 0 var(--sp-2); font-size: var(--fs-12); color: var(--text-muted); white-space: nowrap; }
.rail-eu .icon { color: var(--accent); }
.rail-foot .rail-toggle { justify-content: flex-start; width: 100%; padding-left: var(--sp-2); color: var(--text-muted); }

/* collapsed rail: icons only, tooltips carry the names */
.app.is-rail-collapsed { --rail-w: var(--rail-w-collapsed); }
.app.is-rail-collapsed .rail-scroll { padding-left: var(--sp-2); padding-right: var(--sp-2); }
.app.is-rail-collapsed .nav-heading { visibility: hidden; height: 1px; padding: 0; overflow: hidden; }
.app.is-rail-collapsed .nav-group + .nav-group { margin-top: var(--sp-3); border-top: 1px solid var(--line-soft); padding-top: var(--sp-3); }
.app.is-rail-collapsed .nav-item { justify-content: center; padding: 0; width: 44px; height: 40px; margin: 0 auto; }
.app.is-rail-collapsed .nav-item::before { left: calc(-1 * var(--sp-2) - 2px); }
.app.is-rail-collapsed .nav-label { display: none; }
.app.is-rail-collapsed .rail .nav-count:not(.is-needs-you) { display: none; }   /* an icon rail keeps only what needs you */
.app.is-rail-collapsed .rail .nav-count.is-needs-you { position: absolute; top: 7px; right: 8px; width: 7px; height: 7px; min-width: 0; padding: 0; border-radius: 50%; background: var(--highlight); box-shadow: 0 0 0 1px var(--highlight-ring); color: transparent; font-size: 0; }
.app.is-rail-collapsed .rail-eu span, .app.is-rail-collapsed .rail-toggle .btn-label, .app.is-rail-collapsed .rail-slot { display: none; }
.app.is-rail-collapsed .rail-eu, .app.is-rail-collapsed .rail-foot .rail-toggle { justify-content: center; padding: 0; }
.app.is-rail-collapsed .appbar-brand { width: auto; padding-right: var(--sp-5); }

/* coach bottom navigation (phones only) */
.bottom-nav { display: none; }

/* route entrance: content only, on navigation only (never on an in-page update) */
@keyframes pk-enter { from { opacity: 0; transform: translateY(var(--lift)); } to { opacity: 1; transform: none; } }
.work.is-entering > :not(.page), .work.is-entering > .page > * { animation: pk-enter var(--dur-3) var(--ease-enter) both; }
.work.is-entering > .page > :nth-child(2) { animation-delay: var(--stagger); }
.work.is-entering > .page > :nth-child(3) { animation-delay: calc(var(--stagger) * 2); }
.work.is-entering > .page > :nth-child(n + 4) { animation-delay: calc(var(--stagger) * 3); }

/* bare layouts: sign-in, onboarding, respondent, report */
.bare-top {
  height: var(--appbar-h); display: flex; align-items: center; gap: var(--sp-3); padding: 0 var(--sp-5);
  background: var(--bg-surface); border-bottom: 1px solid var(--line);
}
.bare-top img { display: block; height: 36px; width: auto; }
.bare-top .brand-mark-img { display: none; height: 30px; width: 30px; }
.bare-top .appbar-spacer { flex: 1; }
.app[data-layout="onboarding"] .page { max-width: 760px; margin: 0 auto; }
.app[data-layout="report"] .work { background: var(--bg-desk); }
.app[data-layout="report"] .report-bar { top: var(--topline-h); }
.app[data-layout="respond"] .work { display: block; }
.app[data-layout="respond"] .progress-sticky { top: calc(var(--topline-h) + var(--appbar-h)); z-index: var(--z-sticky); }
.app[data-layout="respond"] .respond > .empty-state { margin-top: var(--sp-8); background: var(--bg-surface); border: 1px solid var(--line); box-shadow: var(--shadow-2); }
.respond-foot {
  display: flex; align-items: center; justify-content: center; gap: var(--sp-2); padding: var(--sp-4) var(--sp-5) var(--sp-6);
  font-size: var(--fs-12); color: var(--text-muted); text-align: center;
}
.respond-foot .icon { color: var(--accent); }

/* sign in: brand panel on the wash, form on white */
.signin { flex: 1; display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
.signin-brand {
  background: var(--bg-wash); border-right: 1px solid var(--line);
  padding: var(--sp-12) var(--sp-12) var(--sp-8); display: flex; flex-direction: column; gap: var(--sp-5);
}
.signin-brand img { width: 262px; height: auto; display: block; }
.signin-display { font-size: 42px; line-height: 46px; font-weight: var(--fw-bold); letter-spacing: var(--track-display); color: var(--text); margin-top: auto; text-wrap: balance; }
.signin-lines { color: var(--text-muted); font-size: var(--fs-16); line-height: 26px; max-width: 44ch; }
.signin-products { display: flex; flex-wrap: wrap; gap: var(--sp-2); }
.signin-foot { margin-top: auto; display: flex; align-items: center; gap: var(--sp-2); color: var(--text-muted); font-size: var(--fs-13); }
.signin-foot .icon { color: var(--accent); }
.signin-form { display: flex; flex-direction: column; align-items: center; justify-content: center; padding: var(--sp-10) var(--sp-6); background: var(--bg-surface); }
.signin-form > * { width: 100%; max-width: 420px; }
.signin-compact { display: none; }
.signin-eu { display: none; align-items: center; gap: var(--sp-2); margin-top: var(--sp-8); color: var(--text-muted); font-size: var(--fs-12); }
.signin-eu .icon { color: var(--accent); }

/* page scaffold (used by every page) */
.page { --page-gap: var(--sp-5); padding: var(--sp-6) var(--gutter) var(--sp-12); display: flex; flex-direction: column; gap: var(--page-gap); width: 100%; min-width: 0; }
.page > * { max-width: var(--content-max); }
.page-head, .obj-head { display: flex; align-items: flex-end; gap: var(--sp-4); flex-wrap: wrap; padding-bottom: var(--sp-5); border-bottom: 1px solid var(--line); }
.page-head > .grow, .obj-head > .grow { display: flex; flex-direction: column; gap: var(--sp-1); flex: 1 1 320px; }
.page-head > .row, .obj-head .toolbar-r { display: flex; gap: var(--sp-2); flex-wrap: wrap; align-items: center; }
.page-head .eyebrow { margin-bottom: 2px; }
.page-head h1, .obj-head h1 { font-size: var(--fs-26); line-height: var(--lh-26); }

/* not found / could not display */
.state-page { flex: 1; display: grid; place-items: center; align-content: center; gap: var(--sp-3); padding: var(--sp-12) var(--gutter); }
.state-page .empty-state { max-width: 560px; width: 100%; }
.state-page .empty-title { font-size: var(--fs-20); line-height: var(--lh-20); font-weight: var(--fw-bold); letter-spacing: var(--track-tight); }
.state-ref { font-size: var(--fs-12); color: var(--text-muted); }
.state-ref .num { color: var(--text-2); font-weight: var(--fw-medium); user-select: all; }

/* ========================================================= components === */
/* ---- icons ---- */
.icon { width: 16px; height: 16px; flex: none; fill: none; stroke: currentColor; stroke-linecap: round; stroke-linejoin: round; stroke-width: 2.25; vertical-align: -3px; }
.icon-12 { width: 12px; height: 12px; stroke-width: 3; vertical-align: -1px; }
.icon-14 { width: 14px; height: 14px; stroke-width: 2.571; vertical-align: -2px; }
.icon-20 { width: 20px; height: 20px; stroke-width: 1.8; }
.icon-24 { width: 24px; height: 24px; stroke-width: 1.5; }
.icon-gap { width: 16px; flex: none; }
.icon-tile {
  width: 40px; height: 40px; flex: none; display: inline-grid; place-items: center; border-radius: var(--r-tile);
  background: var(--accent-soft); color: var(--accent);
  --icon-accent: var(--icon-accent-tile);   /* the duotone gold stroke lives in tiles only */
}
.icon-tile-gold { background: var(--highlight-soft); }
.icon-tile-32 { width: 32px; height: 32px; border-radius: var(--r-8); }
.icon-tile-56 { width: 56px; height: 56px; border-radius: var(--r-12); }
.icon-tile-56 .icon { width: 24px; height: 24px; stroke-width: 1.5; }

/* ---- buttons: pills ---- */
.btn {
  --btn-h: var(--h-md);
  position: relative; display: inline-flex; align-items: center; justify-content: center; gap: var(--sp-2);
  height: var(--btn-h); padding: 0 var(--sp-4); border-radius: var(--r-full);
  border: 1.5px solid var(--accent); background: var(--bg-surface); color: var(--accent-text);
  font: var(--fw-semibold) var(--fs-13)/1 var(--font-ui); letter-spacing: 0; white-space: nowrap;
  text-decoration: none; cursor: pointer; user-select: none;
  transition: background var(--dur-1) var(--ease), border-color var(--dur-1) var(--ease), color var(--dur-1) var(--ease), box-shadow var(--dur-1) var(--ease), transform var(--dur-1) var(--ease);
}
.btn-sm { --btn-h: var(--h-sm); padding: 0 var(--sp-3); gap: 6px; font-size: var(--fs-12); }
.btn-lg { --btn-h: var(--h-lg); padding: 0 var(--sp-5); font-size: var(--fs-14); }
.btn-xl { --btn-h: var(--h-xl); padding: 0 var(--sp-6); font-size: var(--fs-16); }
.btn .kbd { margin-left: var(--sp-1); }
/* primary: the gold pill, ink text, trailing arrow — the one main action on a page */
.btn-cta, .page-head .btn-primary, .obj-head .btn-primary {
  background: var(--cta); border-color: var(--cta); color: var(--text-on-cta); box-shadow: var(--shadow-cta);
}
.btn-cta .kbd, .page-head .btn-primary .kbd { background: var(--kbd-on-cta); color: var(--text-on-cta); }
.btn-arrow { transition: transform var(--dur-2) var(--ease); }
/* confirm: the teal-filled pill (dialog confirms, save bars, primaries written before v3) */
.btn-confirm, .btn-primary, .btn-ink {
  background: var(--accent); border-color: var(--accent); color: var(--text-on-accent); box-shadow: var(--shadow-confirm);
}
.btn-confirm .kbd, .btn-primary .kbd { background: var(--kbd-on-fill); color: var(--text-on-accent); }
.btn-secondary { background: var(--bg-surface); border-color: var(--accent); color: var(--accent-text); }
.btn-soft { background: var(--accent-soft); border-color: transparent; color: var(--accent-text); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--text-2); }
.btn-danger { background: transparent; border-color: transparent; color: var(--crit-text); }
.btn-destructive { background: var(--crit); border-color: var(--crit); color: var(--text-on-accent); }
.btn-link { height: auto; padding: 0; border: 0; background: none; color: var(--text-link); border-radius: var(--r-4); }
.btn-icon { width: var(--btn-h); padding: 0; flex: none; }
.btn-icon.btn-ghost { color: var(--text-muted); }
/* Hover only where a pointer really hovers: on touch, the tapped spot keeps
 * :hover, and the next screen's button under the finger would look pressed. */
@media (hover: hover) and (pointer: fine) {
  .btn:hover { background: var(--accent-soft); color: var(--accent-pressed); }
  .btn-cta:hover, .page-head .btn-primary:hover, .obj-head .btn-primary:hover { background: var(--cta-hover); border-color: var(--cta-hover); color: var(--text-on-cta); }
  .btn:hover .btn-arrow { transform: translateX(2px); }
  .btn-confirm:hover, .btn-primary:hover, .btn-ink:hover { background: var(--accent-hover); border-color: var(--accent-hover); color: var(--text-on-accent); }
  .btn-soft:hover { background: var(--accent-soft-2); }
  .btn-ghost:hover { background: var(--bg-hover); color: var(--text); }
  .btn-danger:hover { background: var(--crit-soft); color: var(--crit-text); }
  .btn-destructive:hover { background: var(--crit-text); border-color: var(--crit-text); color: var(--text-on-accent); }
  .btn-link:hover { background: none; text-decoration: underline; color: var(--accent-pressed); }
  .btn-icon.btn-ghost:hover { color: var(--text); }
}
/* press, disabled and pressed-toggle states come after hover so they win over it */
.btn:active:not(:disabled):not([aria-disabled="true"]) { transform: translateY(.5px); }
.btn:disabled, .btn[aria-disabled="true"] {
  background: var(--bg-sunken); border-color: transparent; color: var(--text-disabled); box-shadow: none; cursor: not-allowed;
}
.btn-cta:active, .page-head .btn-primary:active, .obj-head .btn-primary:active { background: var(--cta-pressed); border-color: var(--cta-pressed); }
.btn-confirm:active, .btn-primary:active, .btn-ink:active { background: var(--accent-pressed); border-color: var(--accent-pressed); }
.btn-ghost:disabled, .btn-danger:disabled, .btn-link:disabled { background: transparent; }
.btn-icon[aria-pressed="true"] { background: var(--accent-soft); color: var(--accent-text); }
/* busy: a 14px spinner replaces the leading icon, the label stays, the width holds */
@keyframes pk-spin { to { transform: rotate(360deg); } }
.btn.is-busy { cursor: progress; }
.btn.is-busy::before {
  content: ""; width: 14px; height: 14px; flex: none; border-radius: 50%;
  border: 1.5px solid currentColor; border-right-color: transparent; animation: pk-spin 700ms linear infinite;
}
.btn.is-busy > .icon:first-child { display: none; }
/* a button waiting behind an open dialog does not spin; the dialog's own save does */
body:has(dialog[open]) .btn.is-busy:not(.dlg-ok)::before { display: none; }
body:has(dialog[open]) .btn.is-busy:not(.dlg-ok) > .icon:first-child { display: inline-block; }

/* ---- chips, tags, status, pills ---- */
.chip {
  display: inline-flex; align-items: center; gap: 5px; height: 22px; padding: 0 9px; border-radius: var(--r-full);
  font-size: var(--fs-12); line-height: 1; font-weight: var(--fw-medium); white-space: nowrap;
  background: var(--bg-sunken); color: var(--text-2); border: 1px solid transparent;
}
.chip-neutral { background: var(--bg-sunken); color: var(--text-2); }
.chip-accent, .chip-teal, .chip-info { background: var(--accent-soft); color: var(--accent-text); }
.chip-highlight, .chip-brass { background: var(--highlight-soft); color: var(--highlight-strong-text); }
.chip-ok { background: var(--ok-soft); color: var(--ok-text); }
.chip-warn { background: var(--warn-soft); color: var(--warn-text); }
.chip-crit { background: var(--crit-soft); color: var(--crit-text); }
.chip-outline { background: transparent; border-color: var(--line-control); color: var(--text-2); }
.chip-sample, .tag-demo { background: transparent; border: 1px dashed var(--line-field); color: var(--text-2); }
.chip .dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; flex: none; }
.chip-link { cursor: pointer; font-family: inherit; background: var(--bg-surface); border-color: var(--line); color: var(--accent-text); }
@media (hover: hover) and (pointer: fine) { .chip-link:hover { border-color: var(--accent); background: var(--accent-soft); } }
.tag {
  display: inline-flex; align-items: center; height: 22px; padding: 0 10px; border-radius: var(--r-full);
  font-size: var(--fs-11); font-weight: var(--fw-bold); letter-spacing: .08em; text-transform: uppercase; white-space: nowrap;
}
.tag-teal { background: var(--ak-teal-100); color: var(--accent-text); }
.tag-gold { background: var(--highlight-soft); color: var(--highlight-strong-text); }
.pill {
  display: inline-flex; align-items: center; height: 20px; padding: 0 8px; border-radius: var(--r-full);
  font-size: var(--fs-11); font-weight: var(--fw-semibold); letter-spacing: .06em; text-transform: uppercase;
  color: var(--accent-text); background: var(--ak-teal-100); white-space: nowrap;
}
.sample { display: inline-flex; align-items: center; gap: 2px; }
.toggletip { display: inline-grid; place-items: center; width: 22px; height: 22px; border: 0; border-radius: 50%; background: none; color: var(--icon); cursor: pointer; }
@media (hover: hover) and (pointer: fine) { .toggletip:hover { color: var(--accent); background: var(--bg-hover); } }
.lang-pill {
  display: inline-flex; align-items: center; gap: 3px; height: 18px; padding: 0 5px; border-radius: var(--r-4);
  border: 1px solid var(--line-control); font-size: 10px; font-weight: var(--fw-semibold); letter-spacing: .04em; color: var(--text-2);
}
.lang-pill.is-incomplete::after { content: ""; width: 6px; height: 6px; border-radius: 50%; border: 1.5px solid var(--warn); }

/* status: a mark (filled = settled, ring = missing / not started, unsaved = yours) plus a word */
.status { display: inline-flex; align-items: center; gap: 7px; font-size: var(--fs-12); line-height: var(--lh-12); color: var(--text-2); font-weight: var(--fw-medium); }
.status-mark { width: 8px; height: 8px; flex: none; border-radius: 50%; background: var(--icon); }
.status[data-tone="ok"] .status-mark { background: var(--ok); }
.status[data-tone="accent"] .status-mark { background: var(--accent); }
.status[data-tone="crit"] .status-mark { background: var(--crit); }
.status[data-tone="highlight"] .status-mark { background: var(--highlight); box-shadow: 0 0 0 1px var(--highlight-ring); }
.status[data-shape="ring"] .status-mark { background: transparent; border: 1.5px solid var(--line-field); }
.status[data-shape="ring"][data-tone="warn"] .status-mark { border-color: var(--warn); }
.status[data-shape="unsaved"] .status-mark, .mark-unsaved {
  width: 8px; height: 8px; border-radius: 50%; background: var(--highlight); box-shadow: 0 0 0 1px var(--highlight-ring), 0 0 0 4px var(--highlight-soft);
}
.mark-unsaved { display: inline-block; flex: none; }
.mark-ring { display: inline-block; width: 8px; height: 8px; border-radius: 50%; border: 1.5px solid var(--warn); }
/* the status words pages wrote before v3: class ok | warn | crit | info */
.status:not([data-shape])::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--icon); flex: none; }
.status.ok::before { background: var(--ok); }
.status.warn::before { background: transparent; border: 1.5px solid var(--warn); }
.status.crit::before { background: var(--crit); }
.status.info::before { background: var(--accent); }

.avatar {
  display: inline-grid; place-items: center; flex: none; border-radius: 50%; overflow: hidden;
  background: var(--ak-teal-100); color: var(--accent-text); font-weight: var(--fw-semibold); font-size: var(--fs-11); letter-spacing: .02em;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; box-shadow: inset 0 0 0 1px var(--line); }
.avatar-28 { width: 28px; height: 28px; } .avatar-32 { width: 32px; height: 32px; }
.avatar-40 { width: 40px; height: 40px; font-size: var(--fs-13); } .avatar-56 { width: 56px; height: 56px; font-size: var(--fs-16); }

/* ---- meters: rounded, teal gradient, gold for a highlight ---- */
.meter-wrap { display: inline-flex; align-items: center; gap: var(--sp-2); min-width: 0; }
.meter { display: block; flex: none; width: var(--meter-w, 100%); height: 6px; background: var(--data-track); border-radius: var(--r-full); overflow: hidden; }
.meter-wrap .meter { width: var(--meter-w, 64px); }
.meter-fill, .meter > span { display: block; height: 100%; border-radius: var(--r-full); background: var(--data-fill); transition: width var(--dur-4) var(--ease-move); }
.meter-highlight .meter-fill { background: var(--data-fill-highlight); }
.meter-ok .meter-fill { background: var(--ok); }
.meter-warn .meter-fill, .meter.low > span { background: var(--warn); }
.meter-crit .meter-fill { background: var(--crit); }
.meter-label { font-size: var(--fs-12); color: var(--text-muted); font-variant-numeric: tabular-nums; white-space: nowrap; }

/* ---- KPI strip: one card, cells split by hairlines ---- */
.kpi-strip {
  display: grid; grid-template-columns: repeat(var(--kpi-n, 4), minmax(0, 1fr)); gap: 1px;
  background: var(--line-soft); border: 1px solid var(--line); border-radius: var(--r-card); overflow: hidden; box-shadow: var(--shadow-card);
}
.kpi-cell {
  position: relative; display: flex; flex-direction: column; gap: 6px; padding: var(--sp-4) var(--sp-5);
  background: var(--bg-surface); color: var(--text); text-decoration: none; min-width: 0;
  transition: background var(--dur-1) var(--ease);
}
@media (hover: hover) and (pointer: fine) { a.kpi-cell:hover { background: var(--bg-subtle); color: var(--text); } }
a.kpi-cell:focus-visible { box-shadow: var(--focus-ring-inset); }
.kpi-label { display: flex; align-items: center; gap: 6px; font-size: var(--fs-12); color: var(--text-muted); }
.kpi-label .icon { color: var(--accent); }
.kpi-value { font-size: 28px; line-height: 34px; font-weight: var(--fw-bold); letter-spacing: var(--track-tight); color: var(--text-kpi); }
.kpi-unit { font-size: var(--fs-13); font-weight: var(--fw-regular); color: var(--text-muted); margin-left: 4px; letter-spacing: 0; }
.kpi-unit.is-tight { font: inherit; color: inherit; letter-spacing: inherit; margin-left: 0; }   /* "31%": the sign belongs to the number */
.kpi-sub { font-size: var(--fs-12); color: var(--text-muted); display: flex; align-items: center; gap: 5px; }
.kpi-sub strong { color: var(--text-2); font-weight: var(--fw-medium); }
.kpi-sub.is-ok { color: var(--ok-text); }
.kpi-cell.is-attention { background: var(--highlight-faint); }
.kpi-cell.is-attention::before { content: ""; position: absolute; left: 0; right: 0; top: 0; height: 2px; background: var(--highlight); }
.kpi-cell.is-attention .kpi-label, .kpi-cell.is-attention .kpi-label .icon { color: var(--highlight-text); }

/* ---- cards (and the .panel pages wrote before v3) ---- */
.card, .panel {
  display: flex; flex-direction: column; min-width: 0;
  background: var(--bg-surface); border: 1px solid var(--line); border-radius: var(--r-card); box-shadow: var(--shadow-card);
  overflow: clip;                          /* table heads keep the rounded corners; clip (not hidden) keeps sticky children working */
}
.card-head, .panel-head {
  display: flex; align-items: center; gap: var(--sp-3); flex-wrap: wrap; min-height: 56px;
  padding: var(--sp-3) var(--sp-5); border-bottom: 1px solid var(--line-soft);
}
.card-titles { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.card-title, .panel-head h4, .panel-head h3 { font-size: 15px; line-height: 22px; font-weight: var(--fw-semibold); letter-spacing: var(--track-tight); }
.card-sub { font-size: var(--fs-12); color: var(--text-muted); }
.card-action { display: flex; gap: var(--sp-2); align-items: center; }
.card-body, .panel-body { padding: var(--sp-5); display: flex; flex-direction: column; gap: var(--sp-4); min-width: 0; }
.panel-body.tight { padding: var(--sp-2); }
.card-body.is-flush { padding: 0; }
.card-foot, .panel-foot {
  margin-top: auto; padding: var(--sp-3) var(--sp-5); border-top: 1px solid var(--line-soft); background: var(--bg-subtle);
  font-size: var(--fs-12); color: var(--text-muted); border-radius: 0 0 var(--r-card) var(--r-card);
}
.panel-foot { display: flex; align-items: center; gap: var(--sp-3); flex-wrap: wrap; font-size: var(--fs-13); color: var(--text); }
.well { display: flex; gap: var(--sp-2); padding: var(--sp-3); border-radius: var(--r-control); background: var(--bg-sunken); font-size: var(--fs-12); color: var(--text-muted); }
.bare-list { display: flex; flex-direction: column; }
/* A button, chip or small control dropped straight into a column body keeps its own width. */
:where(.card-body, .panel-body, .dlg-body, .drawer-body) > :where(.btn, .chip, .tag, .status, .sample, .lang-pill, .avatar, .segmented, .seg, .dir-toggle, .meter-wrap, .switch, .toggletip) { align-self: flex-start; }
.bare-list > * + * { border-top: 1px solid var(--line-soft); }

/* ---- empty state: the brand wash, an icon tile, one sentence, one action ---- */
.empty-state {
  display: flex; flex-direction: column; align-items: center; text-align: center; gap: var(--sp-3);
  padding: var(--sp-10) var(--sp-6); border-radius: var(--r-card); background: var(--bg-wash);
}
.empty-text { display: flex; flex-direction: column; gap: var(--sp-1); max-width: 52ch; }
.empty-title { font-size: var(--fs-16); line-height: var(--lh-16); font-weight: var(--fw-semibold); color: var(--text); }
.empty-sub { font-size: var(--fs-13); line-height: var(--lh-13); color: var(--text-muted); }
.empty-action { display: flex; gap: var(--sp-2); flex-wrap: wrap; justify-content: center; margin-top: var(--sp-1); }
.card .empty-state, .panel .empty-state { border-radius: 0 0 var(--r-card) var(--r-card); }
.panel-body > .empty-state, .card-body > .empty-state { border-radius: var(--r-12); }
.dt-empty .empty-state { padding: var(--sp-8) var(--sp-4); border-radius: 0; }

/* ---- banners ---- */
.banner {
  display: flex; align-items: flex-start; gap: var(--sp-3); padding: var(--sp-3) var(--sp-4); border-radius: var(--r-control);
  font-size: var(--fs-13); line-height: var(--lh-13); color: var(--text-2); background: var(--info-soft);
}
.banner > .icon { margin-top: 2px; color: var(--info); }
.banner-text { flex: 1; min-width: 0; }
.banner strong { font-weight: var(--fw-semibold); color: var(--text); }
.banner-action { flex: none; }
.banner .btn-icon { margin: -4px -6px -4px 0; }
.banner-info { background: var(--info-soft); }
.banner-ok { background: var(--ok-soft); } .banner-ok > .icon { color: var(--ok); }
.banner-warn { background: var(--warn-soft); } .banner-warn > .icon { color: var(--warn); }
.banner-crit { background: var(--crit-soft); } .banner-crit > .icon { color: var(--crit); }
.banner-crit strong { color: var(--crit-text); }   /* only the lead phrase is red; the sentence stays calm */

/* ---- page and object headers ---- */
.page-header { display: flex; flex-direction: column; gap: var(--sp-5); padding-bottom: var(--sp-5); border-bottom: 1px solid var(--line); }
.page-header-row, .object-header-row { display: flex; align-items: flex-end; gap: var(--sp-4); flex-wrap: wrap; }
.page-header-text, .object-header-text { flex: 1 1 360px; min-width: 0; display: flex; flex-direction: column; gap: var(--sp-1); }
.page-actions { display: flex; align-items: center; gap: var(--sp-2); flex-wrap: wrap; }
.page-desc strong { color: var(--text-2); font-weight: var(--fw-medium); font-variant-numeric: tabular-nums; }
.object-header { display: flex; flex-direction: column; gap: var(--sp-4); padding-bottom: var(--sp-5); border-bottom: 1px solid var(--line); }
.object-header-row { align-items: center; }
.object-title-row { display: flex; align-items: center; gap: var(--sp-3); flex-wrap: wrap; }
.object-meta { font-size: var(--fs-13); color: var(--text-muted); }
/* the snapping header: once the object header has scrolled under the app bar,
 * a condensed bar (tile, title, status) stays pinned beneath it */
.object-snap-anchor { position: sticky; top: calc(var(--topline-h) + var(--appbar-h)); z-index: var(--z-sticky); height: 0; }
.page > .object-snap-anchor { margin-bottom: calc(-1 * var(--page-gap)); }
.object-snap {
  position: absolute; top: 0; left: calc(-1 * var(--gutter)); right: calc(-1 * var(--gutter)); height: 48px;
  display: flex; align-items: center; gap: var(--sp-3); padding: 0 var(--gutter);
  background: var(--bg-glass); -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line); box-shadow: var(--shadow-2); pointer-events: none;
  opacity: 0; visibility: hidden; transform: translateY(calc(-1 * var(--lift)));
  transition: opacity var(--dur-3) var(--ease-enter), transform var(--dur-3) var(--ease-enter), visibility 0s linear var(--dur-3);
}
.object-snap.is-snapped { opacity: 1; visibility: visible; transform: none; transition-delay: 0s; }
.object-snap-title { font-size: var(--fs-16); line-height: var(--lh-16); font-weight: var(--fw-semibold); color: var(--text); min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.breadcrumbs ol { list-style: none; margin: 0 0 var(--sp-2); padding: 0; display: flex; flex-wrap: wrap; align-items: center; font-size: var(--fs-12); }
.breadcrumbs li { display: inline-flex; align-items: center; color: var(--text-2); }
.breadcrumbs a { color: var(--text-link); text-decoration: none; font-weight: var(--fw-medium); }
.breadcrumbs a:hover { text-decoration: underline; }
.crumb-sep { margin: 0 var(--sp-2); color: var(--text-disabled); }
/* the breadcrumb pages wrote before v3 */
.crumbs { display: flex; align-items: center; gap: var(--sp-2); font-size: var(--fs-12); color: var(--text-muted); flex-wrap: wrap; }
.crumbs button { font: inherit; font-weight: var(--fw-medium); color: var(--text-link); background: none; border: 0; padding: 0; cursor: pointer; border-radius: var(--r-4); }
.crumbs button:hover { text-decoration: underline; }
.crumbs .sep { color: var(--text-disabled); }
.crumbs [aria-current] { color: var(--text-2); font-weight: var(--fw-regular); }

/* ---- segmented control (one sliding thumb) and the strength control ---- */
.segmented {
  position: relative; display: inline-flex; align-items: center; padding: 2px; border-radius: var(--r-full);
  background: var(--bg-sunken); box-shadow: inset 0 0 0 1px var(--line-soft); max-width: 100%; overflow-x: auto; scrollbar-width: none;
  scroll-snap-type: x proximity; scroll-padding-inline: var(--edge-fade);
}
.segmented::-webkit-scrollbar, .tabbar::-webkit-scrollbar { display: none; }
.seg-select { display: none; }
/* A strip wider than its box fades out on the side that hides more (the
 * shell sets data-overflow after every render and while it scrolls), so a
 * cut-off option reads as "there is more", never as a broken control. */
:is(.segmented, .tabbar)[data-overflow="end"] { mask-image: linear-gradient(to right, var(--mask-solid) calc(100% - var(--edge-fade)), transparent); }
:is(.segmented, .tabbar)[data-overflow="start"] { mask-image: linear-gradient(to left, var(--mask-solid) calc(100% - var(--edge-fade)), transparent); }
:is(.segmented, .tabbar)[data-overflow="both"] { mask-image: linear-gradient(to right, transparent, var(--mask-solid) var(--edge-fade), var(--mask-solid) calc(100% - var(--edge-fade)), transparent); }
.seg-thumb {
  position: absolute; top: 2px; bottom: 2px; left: 0; width: var(--thumb-w, 0); border-radius: var(--r-full);
  background: var(--bg-surface); box-shadow: var(--shadow-seg); transform: translateX(var(--thumb-x, 0));
  transition: transform var(--dur-2) var(--ease-move), width var(--dur-2) var(--ease-move); pointer-events: none;
}
.segmented:not([data-thumb-ready]) .seg-thumb { display: none; }
.seg-opt {
  position: relative; z-index: 1; display: inline-flex; align-items: center; gap: 6px; height: 28px; padding: 0 var(--sp-3);
  border: 0; border-radius: var(--r-full); background: none; color: var(--text-muted); font-size: var(--fs-12); font-weight: var(--fw-medium);
  white-space: nowrap; cursor: pointer; transition: color var(--dur-2) var(--ease);
}
@media (hover: hover) and (pointer: fine) { .seg-opt:hover { color: var(--text); } }
.seg-opt[aria-checked="true"] { color: var(--text); }
.segmented:not([data-thumb-ready]) .seg-opt[aria-checked="true"] { background: var(--bg-surface); box-shadow: var(--shadow-seg); }
.seg-opt:focus-visible { box-shadow: var(--focus-ring-inset); }
.seg-count { font-size: var(--fs-11); color: var(--icon); }
.segmented-sm .seg-opt { height: 24px; padding: 0 var(--sp-2); }
.strength .seg-opt[aria-checked="true"] { color: var(--accent-text); }
.strength .seg-opt[aria-checked="true"][data-s="none"] { color: var(--text-2); }
.bars { display: inline-flex; align-items: flex-end; gap: 1.5px; height: 10px; }
.bars i { width: 3px; border-radius: 1px; background: var(--line-control); }
.bars i:nth-child(1) { height: 4px; } .bars i:nth-child(2) { height: 7px; } .bars i:nth-child(3) { height: 10px; }
.bars[data-level="1"] i:nth-child(-n + 1), .bars[data-level="2"] i:nth-child(-n + 2), .bars[data-level="3"] i { background: var(--icon); }
.seg-opt[aria-checked="true"] .bars[data-level="1"] i:nth-child(-n + 1),
.seg-opt[aria-checked="true"] .bars[data-level="2"] i:nth-child(-n + 2),
.seg-opt[aria-checked="true"] .bars[data-level="3"] i { background: var(--accent); }
/* the view filter pages wrote before v3 */
.seg { display: inline-flex; background: var(--bg-sunken); border-radius: var(--r-full); padding: 2px; gap: 2px; box-shadow: inset 0 0 0 1px var(--line-soft); flex-wrap: wrap; }
.seg button {
  font-family: inherit; font-size: var(--fs-12); font-weight: var(--fw-medium); height: 28px; padding: 0 var(--sp-3); border: 0; border-radius: var(--r-full);
  background: none; color: var(--text-muted); cursor: pointer; transition: background var(--dur-2) var(--ease), color var(--dur-2) var(--ease);
}
@media (hover: hover) and (pointer: fine) { .seg button:hover { color: var(--text); } }
.seg button[aria-pressed="true"] { background: var(--bg-surface); color: var(--text); box-shadow: var(--shadow-seg); }
.seg button .num { font-size: var(--fs-11); color: var(--icon); margin-left: 4px; }

/* direction toggle: "Raises it" / "Lowers it" (never red: reverse scoring is normal) */
.dir-toggle {
  display: inline-flex; align-items: center; gap: 5px; height: 26px; padding: 0 10px; border-radius: var(--r-full);
  border: 1px solid transparent; background: transparent; color: var(--text-2); font: var(--fw-medium) var(--fs-12)/1 var(--font-ui);
  white-space: nowrap; cursor: pointer; transition: background var(--dur-1) var(--ease);
}
@media (hover: hover) and (pointer: fine) { .dir-toggle:hover { background: var(--bg-hover); } }
.dir-toggle[aria-pressed="true"] { background: var(--accent-soft); color: var(--accent-text); }

/* ---- tabs with a sliding underline ---- */
.tabbar { position: relative; display: flex; gap: var(--sp-1); border-bottom: 1px solid var(--line); overflow-x: auto; scrollbar-width: none; scroll-snap-type: x proximity; scroll-padding-inline: var(--edge-fade); }
.tabbar > .tab-item, .segmented > .seg-opt { scroll-snap-align: start; flex: none; }
.tab-item {
  display: inline-flex; align-items: center; gap: 6px; height: 40px; padding: 0 var(--sp-3); border: 0; background: none;
  font: var(--fw-regular) var(--fs-14)/1 var(--font-ui); color: var(--text-2); text-decoration: none; cursor: pointer; white-space: nowrap;
}
@media (hover: hover) and (pointer: fine) { .tab-item:hover { color: var(--text); } }
.tab-item[aria-selected="true"] { color: var(--text); font-weight: var(--fw-medium); }
.tab-item:focus-visible { box-shadow: var(--focus-ring-inset); border-radius: var(--r-6); }
.tab-count { font-size: var(--fs-12); color: var(--text-muted); }
.tab-ink {
  position: absolute; bottom: 0; left: 0; height: 2px; width: var(--ink-w, 0); background: var(--accent); border-radius: 2px 2px 0 0;
  transform: translateX(var(--ink-x, 0)); transition: transform var(--dur-2) var(--ease-move), width var(--dur-2) var(--ease-move);
}
.tabbar:not([data-ink-ready]) .tab-ink { display: none; }
.tabbar:not([data-ink-ready]) .tab-item[aria-selected="true"] { box-shadow: inset 0 -2px 0 var(--accent); }

/* ---- accordion: animated, the whole title toggles, a closed body is inert ---- */
.accordion { background: var(--bg-surface); border: 1px solid var(--line); border-radius: var(--r-card); box-shadow: var(--shadow-card); }
.accordion-head { display: flex; align-items: center; gap: var(--sp-2); min-height: 52px; padding: 0 var(--sp-4) 0 var(--sp-2); }
.accordion-title { flex: 1; min-width: 0; margin: 0; font-size: var(--fs-14); }
.accordion-btn {
  width: 100%; display: flex; align-items: center; gap: var(--sp-2); min-height: 44px; padding: 0 var(--sp-2);
  border: 0; border-radius: var(--r-control); background: none; text-align: left; cursor: pointer;
  font: var(--fw-semibold) var(--fs-14)/1.3 var(--font-ui); color: var(--text);
}
@media (hover: hover) and (pointer: fine) { .accordion-btn:hover { background: var(--bg-hover); } }
.accordion-chevron { color: var(--icon); transition: transform var(--dur-3) var(--ease); }
.accordion.is-open .accordion-chevron { transform: rotate(90deg); }
.accordion-count { font-size: var(--fs-12); font-weight: var(--fw-regular); color: var(--text-muted); }
.accordion-chips, .accordion-actions { display: flex; align-items: center; gap: var(--sp-2); flex-wrap: wrap; }
.accordion-body { display: grid; grid-template-rows: 0fr; transition: grid-template-rows var(--dur-3) var(--ease-enter); }
.accordion.is-open > .accordion-body { grid-template-rows: 1fr; }
.accordion-inner { overflow: hidden; min-height: 0; opacity: 0; transition: opacity var(--dur-3) var(--ease) 40ms; }
.accordion.is-open > .accordion-body > .accordion-inner { opacity: 1; border-top: 1px solid var(--line-soft); }
/* the accordion pages wrote before v3 */
.acc { background: var(--bg-surface); border: 1px solid var(--line); border-radius: var(--r-card); box-shadow: var(--shadow-card); }
.acc-head { display: flex; align-items: center; gap: var(--sp-3); padding: var(--sp-3) var(--sp-4); flex-wrap: wrap; }
.acc-toggle { display: inline-grid; place-items: center; width: 28px; height: 28px; border-radius: var(--r-full); border: 0; background: none; color: var(--icon); cursor: pointer; flex: none; }
@media (hover: hover) and (pointer: fine) { .acc-toggle:hover { background: var(--bg-hover); color: var(--text); } }
.acc-toggle svg { width: 14px; height: 14px; transition: transform var(--dur-3) var(--ease); }
.acc.is-open > .acc-head .acc-toggle svg { transform: rotate(90deg); }
.acc-title { display: flex; align-items: center; gap: var(--sp-2); flex-wrap: wrap; min-width: 0; }
.acc-title h3 { font-size: 15px; line-height: 22px; }
.acc-meta { display: flex; align-items: center; gap: var(--sp-2); flex-wrap: wrap; font-size: var(--fs-12); color: var(--text-muted); }
.acc-actions { margin-left: auto; display: flex; gap: var(--sp-1); flex-wrap: wrap; align-items: center; }
/* On a phone the title keeps its line; the actions wrap under it, lined up with it. */
@media screen and (max-width: 767px) {
  .acc-head { --acc-lead: calc(var(--grip-w) + 28px + 2 * var(--sp-3)); }   /* grip, toggle and their gaps */
  .acc-head > .grow { flex: 1 1 calc(100% - var(--acc-lead) - 1px); }
  .acc-head > .acc-actions { flex-basis: 100%; margin-left: 0; padding-left: var(--acc-lead); }
}
.acc-body { display: grid; grid-template-rows: 0fr; transition: grid-template-rows var(--dur-3) var(--ease-enter); }
.acc.is-open > .acc-body { grid-template-rows: 1fr; }
.acc-body > .acc-inner { overflow: hidden; min-height: 0; visibility: hidden; transition: visibility 0s var(--dur-3); }   /* collapsed = out of the tab order */
.acc.is-open > .acc-body > .acc-inner { border-top: 1px solid var(--line-soft); visibility: visible; transition-delay: 0s; }

/* ---- stepper: numbered teal circles ---- */
.stepper { list-style: none; margin: 0; padding: 0; display: flex; align-items: center; gap: var(--sp-2); flex-wrap: wrap; }
.step { display: flex; align-items: center; gap: var(--sp-2); color: var(--text-muted); font-size: var(--fs-13); }
.step + .step::before { content: ""; width: 28px; height: 1.5px; background: var(--line-control); border-radius: 1px; transition: background var(--dur-4) var(--ease); }
.step.is-done + .step::before { background: var(--accent); }
.step a { display: inline-flex; align-items: center; gap: var(--sp-2); color: inherit; text-decoration: none; border-radius: var(--r-full); }
.step-mark {
  width: 26px; height: 26px; flex: none; display: inline-grid; place-items: center; border-radius: 50%;
  border: 1.5px solid var(--line-field); color: var(--text-muted); font-size: var(--fs-12); font-weight: var(--fw-semibold); font-variant-numeric: tabular-nums;
  background: var(--bg-surface);
}
.step.is-current { color: var(--text); font-weight: var(--fw-medium); }
.step.is-current .step-mark { border: 2px solid var(--accent); color: var(--accent-text); }
.step.is-done .step-mark { background: var(--accent); border-color: var(--accent); color: var(--text-on-accent); }

/* ---- data table (and the tables pages wrote before v3) ---- */
.dt-wrap { overflow-x: auto; }
table.dt, table.data, table.grid { width: 100%; border-collapse: separate; border-spacing: 0; font-size: var(--fs-13); line-height: var(--lh-13); }
table.dt th, table.data th, table.grid th {
  height: 36px; padding: 0 var(--sp-3); text-align: left; vertical-align: middle; white-space: nowrap;
  font-size: var(--fs-11); font-weight: var(--fw-semibold); letter-spacing: var(--track-caps); text-transform: uppercase; color: var(--text-muted);
  background: var(--bg-subtle); border-bottom: 1px solid var(--line);
}
table.dt td, table.data td, table.grid td { padding: 11px var(--sp-3); border-bottom: 1px solid var(--line-soft); vertical-align: middle; }
table.dt td:first-child, table.dt th:first-child, table.data td:first-child, table.data th:first-child, table.grid td:first-child, table.grid th:first-child { padding-left: var(--sp-4); }
table.dt td:last-child, table.dt th:last-child, table.data td:last-child, table.data th:last-child, table.grid td:last-child, table.grid th:last-child { padding-right: var(--sp-4); }
table.dt tbody tr:last-child td, table.data tbody tr:last-child td, table.grid tbody tr:last-child td { border-bottom: 0; }
table.dt tbody tr, table.data tbody tr, table.grid tbody tr { transition: background var(--dur-1) var(--ease); }
@media (hover: hover) and (pointer: fine) { table.dt tbody tr:hover, table.data tbody tr:hover, table.grid tbody tr:hover { background: var(--bg-subtle); } }
table.dt td.num, table.dt th.num, table.data td.n, table.data th.n, table.grid td.n, table.grid th.n { text-align: right; font-variant-numeric: tabular-nums; }
table.data td.tight { width: 1%; white-space: nowrap; }
table.dt-dense td { padding-top: 7px; padding-bottom: 7px; }
.panel-body.tight > table.grid td:first-child, .panel-body.tight table.grid th:first-child { padding-left: var(--sp-3); }
.dt-sort { display: inline-flex; align-items: center; gap: 4px; border: 0; background: none; padding: 0; font: inherit; color: inherit; letter-spacing: inherit; text-transform: inherit; cursor: pointer; }
.dt-sort:hover { color: var(--text); }
.dt-select { width: 40px; }
.dt-go { width: 36px; text-align: right; color: var(--icon); }
.dt-go .icon { transition: transform var(--dur-1) var(--ease); }
tr.is-link { cursor: pointer; }
@media (hover: hover) and (pointer: fine) { tr.is-link:hover .dt-go .icon { transform: translateX(2px); color: var(--accent); } }
.dt-primary { color: var(--text); font-weight: var(--fw-medium); text-decoration: none; }
.dt-primary:hover { color: var(--accent-text); text-decoration: underline; }
tr.dt-group th { height: 32px; background: var(--bg-subtle); text-transform: none; letter-spacing: 0; font-size: var(--fs-12); font-weight: var(--fw-medium); color: var(--text-2); }
.dt-foot { padding: var(--sp-3) var(--sp-4); background: var(--bg-subtle); border-top: 1px solid var(--line-soft); font-size: var(--fs-12); color: var(--text-muted); }
@media (hover: hover) and (pointer: fine) { table.dt tbody tr.dt-empty:hover { background: none; } }
table.qe td, table.qw td { padding: var(--sp-2) var(--sp-3); vertical-align: top; }
table.qw input.w { width: 64px; padding: 2px 6px; text-align: right; min-height: 28px; }
table.qw th.n { vertical-align: bottom; height: 120px; }
.th-rot { display: inline-block; writing-mode: vertical-rl; transform: rotate(180deg); white-space: nowrap; max-height: 110px; overflow: hidden; text-overflow: ellipsis; font-weight: var(--fw-semibold); letter-spacing: .02em; text-transform: none; font-size: var(--fs-12); }

/* ---- fields ---- */
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field > label, .field-legend { font-size: var(--fs-12); line-height: var(--lh-12); font-weight: var(--fw-medium); color: var(--text-2); }
.field-optional { font-weight: var(--fw-regular); color: var(--text-muted); }
.field-error { display: flex; align-items: flex-start; gap: 5px; font-size: var(--fs-12); line-height: var(--lh-12); color: var(--crit-text); }
.field-error .icon { margin-top: 2px; }
:where(input:not([type=checkbox]):not([type=radio]):not([type=range]):not([type=color]):not([type=file]), select, textarea) {
  width: 100%; min-height: var(--h-md); padding: 7px var(--sp-3); border: 1px solid var(--line-field); border-radius: var(--r-control);
  background-color: var(--bg-surface); color: var(--text); font: var(--fw-regular) var(--fs-13)/18px var(--font-ui);
  transition: border-color var(--dur-1) var(--ease), box-shadow var(--dur-1) var(--ease);
}
:where(input:not([type=checkbox]):not([type=radio]), select, textarea):hover { border-color: var(--line-field-hover); }
:where(input:not([type=checkbox]):not([type=radio]), select, textarea):focus { outline: none; border-color: var(--accent); box-shadow: var(--ring-field); }
input::placeholder, textarea::placeholder { color: var(--text-placeholder); }
:where(input, select, textarea)[aria-invalid="true"] { border-color: var(--crit); }
:where(input, textarea)[readonly] { background-color: var(--bg-subtle); color: var(--text-2); }
:where(input, select, textarea):disabled { background-color: var(--bg-sunken); color: var(--text-disabled); border-color: var(--line); cursor: not-allowed; }
:where(input.num, input[type=number]) { text-align: right; font-variant-numeric: tabular-nums; }
:where(textarea) { resize: vertical; min-height: 72px; line-height: 20px; }
:where(select) {
  appearance: none; padding-right: 34px; cursor: pointer;
  background-image: var(--chevron-img); background-repeat: no-repeat; background-position: right 12px center; background-size: 12px 12px;
}
.input-wrap { position: relative; display: flex; align-items: center; }
.input-wrap .input-icon { position: absolute; left: 11px; color: var(--icon); pointer-events: none; }
.input-wrap.has-icon input { padding-left: 32px; }
.input-wrap .input-kbd { position: absolute; right: 8px; pointer-events: none; }
.input-wrap input[type=search] { padding-right: 34px; }
.textarea-wrap { position: relative; display: block; }
.textarea-count { position: absolute; right: 10px; bottom: 6px; font-size: var(--fs-11); color: var(--text-muted); }
input[type=search]::-webkit-search-decoration { -webkit-appearance: none; }

/* checkbox, radio and switch */
.checkbox, .check { display: flex; align-items: flex-start; gap: var(--sp-3); cursor: pointer; min-height: 24px; }
.checkbox.is-disabled { cursor: not-allowed; color: var(--text-disabled); }
.checkbox-text { display: flex; flex-direction: column; gap: 2px; font-size: var(--fs-13); }
.checkbox-hint { font-size: var(--fs-12); color: var(--text-muted); }
input[type=checkbox], input[type=radio] {
  appearance: none; flex: none; width: 16px; height: 16px; margin: 2px 0 0; border: 1px solid var(--line-field); background: var(--bg-surface);
  display: inline-grid; place-items: center; cursor: pointer; transition: background var(--dur-2) var(--ease), border-color var(--dur-2) var(--ease);
}
input[type=checkbox] { border-radius: var(--r-4); }
input[type=radio] { border-radius: 50%; }
input[type=checkbox]:hover, input[type=radio]:hover { border-color: var(--line-field-hover); }
input[type=checkbox]:checked, input[type=radio]:checked { background: var(--accent); border-color: var(--accent); }
input[type=checkbox]::after {
  content: ""; width: 9px; height: 5px; border: 2px solid var(--text-on-accent); border-top: 0; border-right: 0;
  transform: rotate(-45deg) translate(1px, -1px) scale(0); transition: transform var(--dur-2) var(--ease-enter);
}
input[type=checkbox]:checked::after { transform: rotate(-45deg) translate(1px, -1px) scale(1); }
input[type=radio]::after { content: ""; width: 6px; height: 6px; border-radius: 50%; background: var(--text-on-accent); transform: scale(0); transition: transform var(--dur-2) var(--ease-enter); }
input[type=radio]:checked::after { transform: scale(1); }
input[type=checkbox]:focus-visible, input[type=radio]:focus-visible { box-shadow: var(--focus-ring); }
input[type=checkbox]:disabled, input[type=radio]:disabled { background: var(--bg-sunken); border-color: var(--line); cursor: not-allowed; }
input[type=range] { accent-color: var(--accent); }
.switch { display: inline-flex; align-items: center; gap: var(--sp-3); cursor: pointer; position: relative; }
.switch-input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch-track { position: relative; width: 30px; height: 18px; flex: none; border-radius: var(--r-full); background: var(--line-field); transition: background var(--dur-2) var(--ease); }
.switch-knob { position: absolute; top: 3px; left: 3px; width: 12px; height: 12px; border-radius: 50%; background: var(--bg-surface); box-shadow: var(--shadow-1); transition: transform var(--dur-2) var(--ease-move); }
.switch-input:checked + .switch-track { background: var(--accent); }
.switch-input:checked + .switch-track .switch-knob { transform: translateX(12px); }
.switch-input:focus-visible + .switch-track { box-shadow: var(--focus-ring); }
.switch-label { font-size: var(--fs-13); }
.radio-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 200px), 1fr)); gap: var(--sp-2); }
.radio-card {
  display: flex; align-items: flex-start; gap: var(--sp-3); padding: var(--sp-3) var(--sp-4); border: 1px solid var(--line-control);
  border-radius: var(--r-control); background: var(--bg-surface); cursor: pointer; transition: border-color var(--dur-1) var(--ease), background var(--dur-1) var(--ease);
}
.radio-card:hover { border-color: var(--line-field-hover); }
.radio-card:has(input:checked) { border-color: var(--accent); background: var(--bg-selected-row); box-shadow: inset 0 0 0 1px var(--accent); }
.radio-card.is-disabled { cursor: not-allowed; background: var(--bg-subtle); color: var(--text-disabled); }
.radio-card-text { display: flex; flex-direction: column; gap: 2px; }
.radio-card-label { font-weight: var(--fw-medium); font-size: var(--fs-13); }
.radio-card-sub { font-size: var(--fs-12); color: var(--text-muted); }
.dob-row { display: flex; gap: var(--sp-2); }
.dob-part { display: flex; flex-direction: column; gap: 4px; }
.dob-label { font-size: var(--fs-12); color: var(--text-muted); }
.dob-day input { width: 64px; } .dob-month input { width: 64px; } .dob-year input { width: 88px; }
.dob-part input { text-align: center; }

/* ---- skeleton: appears after 150 ms at real heights ---- */
@keyframes pk-appear { to { opacity: 1; } }
@keyframes pk-shimmer { from { background-position: 150% 0; } to { background-position: -50% 0; } }
.skeleton { opacity: 0; animation: pk-appear 1ms linear 150ms forwards; }
.sk {
  display: block; height: 12px; border-radius: var(--r-4);
  background: linear-gradient(90deg, var(--bg-sunken) 30%, var(--bg-pressed) 50%, var(--bg-sunken) 70%) 0 0 / 200% 100% var(--bg-sunken);
  animation: pk-shimmer var(--dur-shimmer) linear infinite;
}
.sk-kpi { height: 28px; width: 40%; }
.sk-lines { display: flex; flex-direction: column; gap: 14px; padding: var(--sp-4) 0; }
.sk-table { display: flex; flex-direction: column; }
.sk-row { display: flex; align-items: center; gap: var(--sp-6); height: 44px; padding: 0 var(--sp-4); border-bottom: 1px solid var(--line-soft); }
.sk-row .sk:first-child { flex: 1; max-width: 50%; }
.kpi-strip.is-skeleton .kpi-cell { gap: 10px; }
.sk-head { height: 36px; background: var(--bg-subtle); border-bottom-color: var(--line); }
.sk-head .sk { height: 8px; }
.sk-title { height: 26px; width: min(320px, 60%); }
.page-header .sk { background-image: linear-gradient(90deg, var(--bg-pressed) 30%, var(--line) 50%, var(--bg-pressed) 70%); }   /* visible on the wash */
.sk-desc { width: min(480px, 80%); margin-top: var(--sp-2); }
.route-skeleton .skeleton { animation-delay: 0ms; }   /* the page skeleton itself only appears after 150 ms */

/* ---- zone bar (read-only 0–100) ---- */
.zone { position: relative; padding-top: 18px; }
.zone-caps { position: absolute; top: 0; left: 0; right: 0; height: 14px; }
.zone-caps span { position: absolute; transform: translateX(-50%); font-size: 10px; font-weight: var(--fw-semibold); letter-spacing: var(--track-caps); text-transform: uppercase; color: var(--text-muted); white-space: nowrap; }
.zone-track {
  position: relative; height: 12px; border-radius: var(--r-4);
  background: linear-gradient(90deg, var(--zone-low) 0 var(--mid), var(--zone-mid) var(--mid) var(--high), var(--zone-high) var(--high) 100%);
}
.zone-track::before, .zone-track::after { content: ""; position: absolute; top: 0; bottom: 0; width: 1px; background: var(--line-strong); }
.zone-track::before { left: var(--mid); } .zone-track::after { left: var(--high); }
.zone-marker { position: absolute; top: -3px; bottom: -3px; width: 2px; margin-left: -1px; background: var(--text); border-radius: 1px; transition: left var(--dur-4) var(--ease-move); }
.zone-marker.is-strong { width: 3px; margin-left: -1.5px; background: var(--accent-text); }
.zone-ghost { position: absolute; top: 50%; width: 8px; height: 8px; margin: -4px 0 0 -4px; border-radius: 50%; border: 1.5px solid var(--line-field); background: var(--bg-surface); }
/* the score meter pages wrote before v3 */
.zone-bar { --mid-at: 40%; --high-at: 70%; position: relative; height: 12px; border-radius: var(--r-4);
  background: linear-gradient(90deg, var(--zone-low) 0 var(--mid-at), var(--zone-mid) var(--mid-at) var(--high-at), var(--zone-high) var(--high-at) 100%); }
.zone-bar > i { position: absolute; top: -3px; width: 3px; height: 18px; background: var(--text); border-radius: 2px; transform: translateX(-50%); transition: left var(--dur-4) var(--ease-move); }
.zone-legend { display: flex; justify-content: space-between; font-size: var(--fs-11); color: var(--text-muted); font-variant-numeric: tabular-nums; }

/* ---- dialogs, drawers, bottom sheets ---- */
dialog { color: var(--text); }
dialog::backdrop { background: var(--bg-scrim); }
.dlg {
  width: calc(100% - 32px); max-width: 640px; max-height: calc(100dvh - 48px); padding: 0; border: 1px solid var(--line); border-radius: var(--r-dialog);
  background: var(--bg-surface); box-shadow: var(--shadow-4); overflow: hidden;
}
.dlg[open] { display: flex; flex-direction: column; animation: pk-dlg-in var(--dur-3) var(--ease-enter); }
.dlg[open]::backdrop { animation: pk-fade-in var(--dur-3) var(--ease-enter); }
.dlg.is-closing { animation: pk-dlg-out var(--dur-exit) var(--ease-exit) forwards; }
.dlg.is-closing::backdrop { animation: pk-fade-out var(--dur-exit) var(--ease-exit) forwards; }
@keyframes pk-dlg-in { from { opacity: 0; transform: translateY(var(--lift)) scale(.98); } to { opacity: 1; transform: none; } }
@keyframes pk-dlg-out { to { opacity: 0; transform: translateY(2px) scale(.99); } }
@keyframes pk-fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes pk-fade-out { to { opacity: 0; } }
.dlg-480 { max-width: 480px; } .dlg-640 { max-width: 640px; } .dlg-800 { max-width: 800px; }
.dlg-form { display: flex; flex-direction: column; min-height: 0; max-height: inherit; }
.dlg-head { display: flex; align-items: flex-start; gap: var(--sp-3); padding: var(--sp-5) var(--sp-4) var(--sp-3) var(--sp-6); }
.dlg-titles { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 4px; padding-top: 5px; }
.dlg-title { font-size: 18px; line-height: 24px; font-weight: var(--fw-bold); letter-spacing: var(--track-tight); }
.dlg-sub { font-size: var(--fs-13); line-height: var(--lh-13); color: var(--text-muted); }
.dlg-body { flex: 1; min-height: 0; overflow-y: auto; padding: var(--sp-2) var(--sp-6) var(--sp-5); display: flex; flex-direction: column; gap: var(--sp-4); }
.dlg-text { font-size: var(--fs-14); line-height: 21px; color: var(--text-2); }
.dlg-error { margin: 0 var(--sp-6) var(--sp-3); padding: var(--sp-2) var(--sp-3); border-radius: var(--r-control); background: var(--crit-soft); color: var(--crit-text); font-size: var(--fs-13); font-weight: var(--fw-medium); }
/* OK is first in the DOM (Enter confirms); row-reverse shows Cancel before it */
.dlg-foot { display: flex; flex-direction: row-reverse; justify-content: flex-start; align-items: center; gap: var(--sp-2); padding: var(--sp-4) var(--sp-6); border-top: 1px solid var(--line-soft); background: var(--bg-subtle); }
.drawer {
  margin: 0 0 0 auto; height: 100dvh; max-height: 100dvh; width: min(var(--drawer-w, 400px), 100vw); max-width: 100vw; padding: 0; border: 0;
  border-left: 1px solid var(--line); background: var(--bg-surface); box-shadow: var(--shadow-4); overflow: hidden;
}
.drawer[open] { display: flex; flex-direction: column; animation: pk-drawer-in var(--dur-3) var(--ease-enter); }
.drawer[open]::backdrop { animation: pk-fade-in var(--dur-3) var(--ease-enter); }
.drawer.is-closing { animation: pk-drawer-out var(--dur-exit) var(--ease-exit) forwards; }
.drawer.is-closing::backdrop { animation: pk-fade-out var(--dur-exit) var(--ease-exit) forwards; }
@keyframes pk-drawer-in { from { opacity: 0; transform: translateX(16px); } to { opacity: 1; transform: none; } }
@keyframes pk-drawer-out { to { opacity: 0; transform: translateX(16px); } }
.drawer-grabber { display: none; }
.drawer-head { display: flex; align-items: flex-start; gap: var(--sp-3); padding: var(--sp-5) var(--sp-4) var(--sp-4) var(--sp-5); border-bottom: 1px solid var(--line-soft); }
.drawer-body { flex: 1; overflow-y: auto; padding: var(--sp-5); display: flex; flex-direction: column; gap: var(--sp-4); }
.drawer-foot { display: flex; gap: var(--sp-2); justify-content: flex-end; padding: var(--sp-4) var(--sp-5); border-top: 1px solid var(--line-soft); background: var(--bg-subtle); }
.drawer.is-nav { margin: 0 auto 0 0; border-left: 0; border-right: 1px solid var(--line); }
.drawer.is-nav[open] { animation-name: pk-drawer-in-left; }
.drawer.is-nav.is-closing { animation-name: pk-drawer-out-left; }
@keyframes pk-drawer-in-left { from { opacity: 0; transform: translateX(-16px); } to { opacity: 1; transform: none; } }
@keyframes pk-drawer-out-left { to { opacity: 0; transform: translateX(-16px); } }
.drawer.is-nav .drawer-body { padding: var(--sp-3); gap: 0; }
.drawer.is-nav .nav-item[aria-current="page"]::before { left: calc(-1 * var(--sp-3)); }

/* ---- menus, popovers, tooltips (top layer when available) ---- */
.popover, .tooltip, .toast-stack { margin: 0; inset: auto; border: 0; padding: 0; background: transparent; color: inherit; overflow: visible; }
.popover {
  position: fixed; z-index: var(--z-popover); min-width: 200px; max-width: min(320px, calc(100vw - 16px)); padding: 4px;
  background: var(--bg-surface); border: 1px solid var(--line); border-radius: var(--r-menu); box-shadow: var(--shadow-3); color: var(--text);
  animation: pk-pop-in var(--dur-2) var(--ease-enter);
}
.popover[data-side="top"] { animation-name: pk-pop-in-up; }
.popover.is-closing { animation: pk-fade-out var(--dur-exit) var(--ease-exit) forwards; }
@keyframes pk-pop-in { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: none; } }
@keyframes pk-pop-in-up { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
.menu-item {
  display: flex; align-items: center; gap: var(--sp-3); width: 100%; min-height: 34px; padding: 0 var(--sp-3); border: 0; border-radius: var(--r-8);
  background: none; color: var(--text); font: var(--fw-regular) var(--fs-13)/1.3 var(--font-ui); text-align: left; text-decoration: none; cursor: pointer;
}
.menu-item .icon { color: var(--icon); }
.menu-item:focus { background: var(--bg-hover); outline: none; color: var(--text); }
@media (hover: hover) and (pointer: fine) { .menu-item:hover { background: var(--bg-hover); color: var(--text); } }
.menu-item:focus-visible { box-shadow: var(--focus-ring-inset); }
.menu-item[aria-disabled="true"] { color: var(--text-disabled); cursor: not-allowed; }
.menu-item.is-danger, .menu-item.is-danger .icon { color: var(--crit-text); }
.menu-label { flex: 1; min-width: 0; }
.menu-item .kbd { margin-left: auto; }
.menu-sep { height: 1px; margin: 4px 6px; background: var(--line-soft); }
.menu-heading { padding: 8px 12px 6px; font-size: var(--fs-11); font-weight: var(--fw-semibold); letter-spacing: var(--track-caps); text-transform: uppercase; color: var(--text-muted); }
.menu-account { display: flex; align-items: center; gap: var(--sp-3); padding: 10px 12px 12px; border-bottom: 1px solid var(--line-soft); margin-bottom: 4px; }
.menu-account-text { display: flex; flex-direction: column; min-width: 0; }
.menu-account-text strong { font-size: var(--fs-13); font-weight: var(--fw-semibold); }
.menu-account-text span { font-size: var(--fs-12); color: var(--text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.menu-anchor { display: inline-flex; }
.help-panel { padding: var(--sp-3); display: flex; flex-direction: column; gap: var(--sp-3); min-width: 280px; }
.help-panel h2 { font-size: var(--fs-13); line-height: var(--lh-13); }
.help-links { display: flex; flex-direction: column; margin: 0 calc(-1 * var(--sp-2)) calc(-1 * var(--sp-2)); padding-top: var(--sp-2); border-top: 1px solid var(--line-soft); }
.help-links .menu-item { min-height: 40px; }
.menu-sub { display: block; margin-top: 1px; font-size: var(--fs-12); color: var(--text-muted); }
.shortcut-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.shortcut-list li { display: flex; justify-content: space-between; align-items: center; gap: var(--sp-4); font-size: var(--fs-13); color: var(--text-2); }
.shortcut-group { font-size: var(--fs-11); font-weight: var(--fw-bold); letter-spacing: var(--track-caps); text-transform: uppercase; color: var(--text-eyebrow); margin: var(--sp-2) 0 calc(var(--sp-1) * -1); }
.shortcut-group:first-child { margin-top: 0; }
.shortcut-keys { display: inline-flex; gap: 4px; flex: none; }
.dlg-body .shortcut-list + .shortcut-group { margin-top: var(--sp-5); }
.tooltip {
  position: fixed; z-index: var(--z-tooltip); max-width: 240px; padding: 6px 8px; border-radius: var(--r-6);
  background: var(--bg-inverse); color: var(--text-on-accent); font-size: var(--fs-12); line-height: 16px; pointer-events: none;
  opacity: 0; transform: translateY(2px); transition: opacity var(--dur-1) var(--ease), transform var(--dur-1) var(--ease);
}
.tooltip.is-visible { opacity: 1; transform: none; }

/* ---- toasts: the only dark surface, bottom-left of the content area ---- */
.toast-stack {
  position: fixed; z-index: var(--z-toast); left: calc(var(--toast-left, var(--rail-w)) + var(--sp-4)); bottom: var(--sp-4);
  width: min(380px, calc(100vw - 32px)); display: flex; flex-direction: column; gap: var(--sp-2); pointer-events: none;
  transition: bottom var(--dur-3) var(--ease);
}
body.rail-collapsed .toast-stack { --toast-left: var(--rail-w-collapsed); }
body.has-savebar .toast-stack { bottom: calc(var(--savebar-now, var(--savebar-h)) + var(--sp-3)); }
body.is-bare-layout .toast-stack { left: 50%; transform: translateX(-50%); }
.toast {
  display: flex; align-items: flex-start; gap: var(--sp-3); padding: 12px 8px 12px 14px; border-radius: var(--r-12);
  background: var(--bg-inverse); color: var(--text-on-accent); box-shadow: var(--shadow-3); font-size: var(--fs-13); line-height: 19px;
  pointer-events: auto;                    /* hovering a toast holds it (the stack itself lets clicks through) */
  animation: pk-toast-in var(--dur-3) var(--ease-enter);
}
.toast.is-leaving { animation: pk-toast-out var(--dur-exit) var(--ease-exit) forwards; }
@keyframes pk-toast-in { from { opacity: 0; transform: translateY(var(--lift)); } to { opacity: 1; transform: none; } }
@keyframes pk-toast-out { to { opacity: 0; transform: translateY(2px); } }
.toast-icon { margin-top: 2px; color: var(--accent-on-inverse); }
.toast-error .toast-icon { color: var(--crit-on-inverse); }
.toast-text { flex: 1; min-width: 0; }
.toast-ref { display: block; margin-top: 2px; font-size: var(--fs-12); opacity: .8; }
.toast-action, .toast-close { pointer-events: auto; flex: none; border: 0; background: none; cursor: pointer; }
.toast-action { height: 24px; padding: 0 8px; border-radius: var(--r-full); color: var(--accent-on-inverse); font-weight: var(--fw-semibold); font-size: var(--fs-13); }
.toast-action:hover { background: var(--kbd-on-fill); }
.toast-close { width: 24px; height: 24px; display: grid; place-items: center; border-radius: 50%; color: var(--text-on-accent); opacity: .75; }
.toast-close:hover { opacity: 1; background: var(--kbd-on-fill); }
.toast-action:focus-visible, .toast-close:focus-visible { box-shadow: var(--focus-ring-inverse); }

/* ---- save bar: glass, fixed to the bottom of the content area ---- */
.savebar {
  position: fixed; z-index: var(--z-savebar); left: var(--rail-w); right: 0; bottom: 0; min-height: var(--savebar-h);
  display: flex; align-items: center; gap: var(--sp-4); padding: var(--sp-2) var(--gutter);
  background: var(--bg-glass); -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px); box-shadow: var(--shadow-bar);
  animation: pk-savebar-in var(--dur-3) var(--ease-enter);
}
@keyframes pk-savebar-in { from { transform: translateY(100%); } to { transform: none; } }
.savebar-lead { display: flex; align-items: center; gap: var(--sp-3); min-width: 0; }
.savebar-text { display: flex; flex-direction: column; }
.savebar-text strong { font-size: var(--fs-13); font-weight: var(--fw-semibold); }
.savebar-sub { font-size: var(--fs-12); color: var(--text-muted); }
.savebar-impact { flex: 1; min-width: 0; font-size: var(--fs-13); color: var(--text-2); font-variant-numeric: tabular-nums; }
.savebar-impact.is-error { color: var(--crit-text); display: flex; gap: 6px; align-items: center; }
.savebar-actions { display: flex; gap: var(--sp-2); margin-left: auto; }
body.has-savebar .page { padding-bottom: calc(var(--savebar-now, var(--savebar-h)) + var(--sp-6)); }

/* ---- command palette ---- */
.dlg.palette { max-width: 640px; margin-top: 12vh; margin-bottom: auto; }
.palette-input-row { display: flex; align-items: center; gap: var(--sp-3); padding: 0 var(--sp-3) 0 var(--sp-5); border-bottom: 1px solid var(--line-soft); }
.palette-input-row .icon { color: var(--icon); }
.palette-input-row input.palette-input { flex: 1; height: 56px; border: 0; box-shadow: none; padding: 0; font-size: var(--fs-16); background: none; }
.palette-results { max-height: min(420px, 60vh); overflow-y: auto; padding: 6px; }
.palette-group { padding: 10px 10px 4px; font-size: var(--fs-11); font-weight: var(--fw-semibold); letter-spacing: var(--track-caps); text-transform: uppercase; color: var(--text-muted); }
.palette-item {
  display: flex; align-items: center; gap: var(--sp-3); width: 100%; min-height: 40px; padding: 0 10px; border: 0; border-radius: var(--r-8);
  background: none; font: var(--fw-regular) var(--fs-14)/1.3 var(--font-ui); color: var(--text); text-align: left; cursor: pointer;
}
.palette-item .icon { color: var(--icon); }
.palette-item-label { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.palette-item mark { background: none; color: var(--accent-text); font-weight: var(--fw-semibold); }
.palette-item[aria-selected="true"] { background: var(--bg-selected); }
.palette-item[aria-selected="true"] .icon { color: var(--accent); }
.palette-item-parent { font-size: var(--fs-12); color: var(--text-muted); margin-left: auto; white-space: nowrap; }
.palette-empty { padding: var(--sp-8) var(--sp-4); text-align: center; color: var(--text-muted); font-size: var(--fs-13); }
.palette-foot { display: flex; gap: var(--sp-4); flex-wrap: wrap; padding: 10px var(--sp-5); border-top: 1px solid var(--line-soft); background: var(--bg-subtle); font-size: var(--fs-12); color: var(--text-muted); }

/* ===================================== page patterns written before v3 === */
/* Kept on tokens so every page looks like the rest until its owner rebuilds it. */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 170px), 1fr)); gap: 1px; background: var(--line-soft); border: 1px solid var(--line); border-radius: var(--r-card); overflow: hidden; box-shadow: var(--shadow-card); }
.tile { display: flex; flex-direction: column; gap: 4px; padding: var(--sp-4) var(--sp-5); background: var(--bg-surface); min-width: 0; }
.tile-v { font-size: 28px; line-height: 34px; font-weight: var(--fw-bold); letter-spacing: var(--track-tight); color: var(--text-kpi); font-variant-numeric: tabular-nums; }
.tile-l { font-size: var(--fs-12); color: var(--text-muted); }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 150px), 1fr)); gap: 1px; background: var(--line-soft); border: 1px solid var(--line); border-radius: var(--r-card); overflow: hidden; }
.kpi { display: flex; flex-direction: column; gap: 2px; padding: var(--sp-3) var(--sp-4); background: var(--bg-surface); min-width: 0; }
.kpi-v { font-size: var(--fs-20); line-height: var(--lh-20); font-weight: var(--fw-bold); color: var(--text-kpi); font-variant-numeric: tabular-nums; letter-spacing: var(--track-tight); }
.kpi-v.is-warn { color: var(--warn-text); }
.kpi-l { font-size: var(--fs-12); color: var(--text-muted); }
.filterbar {
  display: flex; align-items: center; gap: var(--sp-3); flex-wrap: wrap; padding: var(--sp-3) var(--sp-4);
  background: var(--bg-surface); border: 1px solid var(--line); border-radius: var(--r-card); box-shadow: var(--shadow-card);
}
.filterbar .search { max-width: 320px; }
.filterbar .count { margin-left: auto; font-size: var(--fs-12); color: var(--text-muted); font-variant-numeric: tabular-nums; }
.toolbar { align-items: center; }
input.search {
  border-radius: var(--r-full); padding-left: 34px; max-width: 360px;
  background-image: var(--search-img); background-repeat: no-repeat; background-position: 12px center; background-size: 14px 14px;
}
.subnav { display: flex; gap: var(--sp-1); border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.subtab {
  font: var(--fw-regular) var(--fs-14)/1 var(--font-ui); height: 40px; padding: 0 var(--sp-3); border: 0; border-bottom: 2px solid transparent; margin-bottom: -1px;
  background: none; color: var(--text-2); cursor: pointer; display: inline-flex; gap: var(--sp-2); align-items: center; transition: color var(--dur-1) var(--ease);
}
@media (hover: hover) and (pointer: fine) { .subtab:hover { color: var(--text); } }
.subtab[aria-current="page"] { color: var(--text); font-weight: var(--fw-medium); border-bottom-color: var(--accent); }
.subtab .num { font-size: var(--fs-12); }
.lib-item { display: flex; align-items: center; gap: var(--sp-3); padding: var(--sp-3) var(--sp-5); flex-wrap: wrap; }
.lib-item .grow { display: flex; flex-direction: column; gap: 1px; min-width: 200px; }
.rule-pill { font-size: var(--fs-12); background: var(--bg-sunken); border: 1px solid var(--line); border-radius: var(--r-6); padding: 1px var(--sp-2); color: var(--text-2); white-space: nowrap; display: inline-block; margin: 1px 0; }
.rule-ed { display: flex; flex-direction: column; gap: var(--sp-2); }
.rule-mode { width: auto; align-self: flex-start; font-size: var(--fs-13); }
.rule-row { display: grid; grid-template-columns: 170px minmax(120px, 1fr) 80px minmax(110px, 1fr); gap: var(--sp-2); align-items: center; }
.rule-row.hd { grid-template-columns: 200px minmax(200px, 1fr) 100px; }
.rule-row select, .rule-row input { font-size: var(--fs-13); }
.rule-row.measure { grid-template-columns: 120px minmax(140px, 1fr) 130px 150px; }
.fs { border: 1px solid var(--line); border-radius: var(--r-control); padding: var(--sp-4); position: relative; }
.fs > legend { padding: 0 6px; }
.fs-tools { position: absolute; top: var(--sp-2); right: var(--sp-2); }
.q-tools { opacity: .45; transition: opacity var(--dur-1) var(--ease); }
.q-row:hover .q-tools, .q-row:focus-within .q-tools { opacity: 1; }
.panel > .empty-state { margin: 0; }
/* score cards, the scoring explainer and the score editor (scorecard.js) */
.score-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 300px), 1fr)); gap: var(--sp-3); }
.score-card { border: 1px solid var(--line); border-radius: var(--r-12); padding: var(--sp-4); display: flex; flex-direction: column; gap: var(--sp-3); background: var(--bg-surface); min-width: 0; }
.score-card > .row > .grow strong { font-size: 15px; font-weight: var(--fw-semibold); }
.feeds { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 5px; }
.feeds li { display: grid; grid-template-columns: 96px 1fr; gap: var(--sp-2); align-items: baseline; min-width: 0; }
.feeds li.is-missing { color: var(--crit-text); }
.feeds li > .small { overflow-wrap: anywhere; }
.feed-w { font-size: var(--fs-11); font-weight: var(--fw-semibold); letter-spacing: .04em; text-transform: uppercase; color: var(--accent-text); background: var(--accent-soft); border-radius: var(--r-full); padding: 1px 8px; white-space: nowrap; text-align: center; }
.feed-w.is-neg { color: var(--highlight-strong-text); background: var(--highlight-soft); }
.score-foot { border-top: 1px solid var(--line-soft); padding-top: var(--sp-3); margin-top: auto; align-items: center; }
.explainer { border: 1px solid var(--line); border-left: 4px solid var(--highlight); background: var(--bg-surface); border-radius: var(--r-card); box-shadow: var(--shadow-card); }
.explainer > summary { list-style: none; cursor: pointer; padding: var(--sp-4) var(--sp-5); display: flex; gap: var(--sp-3); align-items: baseline; flex-wrap: wrap; border-radius: var(--r-card); }
.explainer > summary::-webkit-details-marker { display: none; }
.explainer > summary::before {
  content: ""; width: 12px; height: 12px; flex: none; align-self: center; transform: rotate(-90deg);
  background: var(--chevron-img) center / 12px 12px no-repeat; transition: transform var(--dur-2) var(--ease);
}
.explainer[open] > summary::before { transform: none; }
.explainer-body { padding: 0 var(--sp-5) var(--sp-5); display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr); gap: var(--sp-6); align-items: start; }
.steps { margin: 0; padding-left: 1.4em; display: flex; flex-direction: column; gap: var(--sp-2); font-size: var(--fs-13); color: var(--text-2); }
.steps li::marker { color: var(--accent); font-weight: var(--fw-bold); }
.steps strong { color: var(--text); font-weight: var(--fw-semibold); }
.example { background: var(--bg-subtle); border: 1px solid var(--line-soft); border-radius: var(--r-control); padding: var(--sp-4); display: flex; flex-direction: column; gap: var(--sp-2); }
.q-picks { max-height: 46vh; overflow-y: auto; border: 1px solid var(--line); border-radius: var(--r-control); padding: var(--sp-2) var(--sp-3); display: flex; flex-direction: column; gap: var(--sp-3); }
.q-pick-group { display: flex; flex-direction: column; gap: var(--sp-1); }
.q-pick-group > .eyebrow { padding: var(--sp-2) 0 var(--sp-1); position: sticky; top: 0; background: var(--bg-surface); }
.q-pick { display: grid; grid-template-columns: 150px 150px 1fr; gap: var(--sp-2); align-items: center; padding: 3px 4px; border-radius: var(--r-6); }
.q-pick.is-on { background: var(--accent-soft); }
.q-pick select { font-size: var(--fs-12); min-height: var(--h-sm); padding-top: 3px; padding-bottom: 3px; }
.q-pick:not(.is-on) select[name^="d__"] { visibility: hidden; }
/* drag and drop (dnd.js): the grip, the lifted row, its neighbours, the landing line */
[data-sortable] { position: relative; }
.drag-handle { display: inline-grid; place-items: center; width: var(--grip-w); height: 28px; border: 0; background: none; color: var(--text-disabled); cursor: grab; border-radius: var(--r-6); flex: none; padding: 0; touch-action: none; }
.drag-handle:focus-visible { color: var(--text-2); background: var(--bg-hover); }
@media (hover: hover) and (pointer: fine) { .drag-handle:hover { color: var(--text-2); background: var(--bg-hover); } }
html.is-dragging, html.is-dragging * { cursor: grabbing !important; user-select: none; -webkit-user-select: none; }
[data-dnd] { transition: transform var(--dur-2) var(--ease-move); }
[data-dnd="lifted"], [data-dnd="landing"] {
  position: relative; z-index: var(--z-sticky); background: var(--bg-surface); box-shadow: var(--shadow-3);
  transition: transform var(--dur-2) var(--ease-move), box-shadow var(--dur-1) var(--ease);
}
html.is-dragging [data-dnd="lifted"] { transition: box-shadow var(--dur-1) var(--ease); }
[data-dnd="lifted"] { outline: 1px solid var(--line); }
[data-dnd="lifted"] > .drag-handle, [data-dnd="lifted"] .drag-handle:focus-visible { color: var(--accent); }
tr[data-dnd="lifted"], tr[data-dnd="landing"] { box-shadow: var(--shadow-3); }
.is-sorting { isolation: isolate; }
.dnd-line { position: fixed; z-index: var(--z-popover); height: 2px; margin-top: -1px; background: var(--accent); border-radius: 2px; pointer-events: none; transition: top var(--dur-2) var(--ease-move); }
.dnd-line::before { content: ""; position: absolute; left: -3px; top: -2px; width: 6px; height: 6px; border-radius: 50%; background: var(--accent); }
/* two-line pack buttons written before v3 (coach Bundles) grow with their text */
.btn.pack { height: auto; min-height: var(--btn-h); border-radius: var(--r-card); }
/* the staged-changes bar pages wrote before v3 */
.footbar {
  position: sticky; bottom: var(--sp-3); z-index: var(--z-savebar); display: flex; align-items: center; gap: var(--sp-3); padding: var(--sp-2) var(--sp-2) var(--sp-2) var(--sp-5);
  background: var(--bg-glass); -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px); color: var(--text); font-weight: var(--fw-medium);
  border: 1px solid var(--line); border-radius: var(--r-full); box-shadow: var(--shadow-3); animation: pk-enter var(--dur-3) var(--ease-enter) both;
}
.footbar::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--highlight); box-shadow: 0 0 0 1px var(--highlight-ring), 0 0 0 4px var(--highlight-soft); flex: none; }
/* the weight control pages wrote before v3 */
.wseg { display: inline-flex; background: var(--bg-sunken); border-radius: var(--r-full); padding: 2px; box-shadow: inset 0 0 0 1px var(--line-soft); }
.wseg button {
  font: var(--fw-medium) var(--fs-12)/1 var(--font-ui); height: 26px; padding: 0 10px; border: 0; border-radius: var(--r-full);
  background: none; color: var(--text-muted); cursor: pointer; white-space: nowrap; transition: background var(--dur-2) var(--ease), color var(--dur-2) var(--ease);
}
@media (hover: hover) and (pointer: fine) { .wseg button:hover { color: var(--text); } }
.wseg button[aria-pressed="true"] { background: var(--bg-surface); color: var(--accent-text); box-shadow: var(--shadow-seg); }
.wseg button[aria-pressed="true"][data-s="none"] { color: var(--text-2); }
/* master–detail */
.split { display: grid; grid-template-columns: minmax(240px, var(--master-w)) minmax(0, 1fr); gap: var(--sp-5); align-items: start; }
.master { position: sticky; top: calc(var(--topline-h) + var(--appbar-h) + var(--sp-4)); max-height: calc(100vh - var(--topline-h) - var(--appbar-h) - var(--sp-8)); overflow-y: auto; background: var(--bg-surface); border: 1px solid var(--line); border-radius: var(--r-card); box-shadow: var(--shadow-card); scrollbar-width: thin; }
.master-item { display: flex; align-items: center; gap: var(--sp-3); padding: var(--sp-2) var(--sp-4); cursor: pointer; text-align: left; width: 100%; background: none; border: 0; border-bottom: 1px solid var(--line-soft); font: inherit; color: var(--text); position: relative; }
@media (hover: hover) and (pointer: fine) { .master-item:hover { background: var(--bg-hover); } }
.master-item[aria-current="true"] { background: var(--bg-selected); color: var(--accent-text); }
.master-item[aria-current="true"]::before { content: ""; position: absolute; left: 0; top: 6px; bottom: 6px; width: 3px; border-radius: 0 3px 3px 0; background: var(--accent); }
.master-item:focus-visible { box-shadow: var(--focus-ring-inset); }
.master-group { padding: var(--sp-3) var(--sp-4) var(--sp-1); }
.linkish { font: inherit; color: var(--text-link); background: none; border: 0; padding: 0; cursor: pointer; font-weight: var(--fw-medium); text-decoration: underline; text-decoration-thickness: 1px; text-underline-offset: 2px; border-radius: var(--r-4); }
.linkish:hover { color: var(--accent-pressed); }
.key-rule { width: 54px; height: 3px; background: var(--highlight); border-radius: 2px; }
.dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; flex: none; }
/* the sign-in form written before v3, stacked in the shell's form column */
.signin-form .auth-page { display: flex; flex-direction: column; gap: var(--sp-4); max-width: 420px; margin: 0; padding: 0; }
.signin-form .auth-page > * { width: 100%; }
.signin-form .auth-card { box-shadow: var(--shadow-2); border-radius: var(--r-card); }
/* brand marks written before v3 are replaced by the shell's real lockup */
.auth-card > .row:first-child:has(> .brand-mark), .respond > header .brand-mark { display: none; }

/* =================================================== responsive shell === */
/* laptop and tablet: the rail folds to icons; its toggle opens it over the page */
/* "View as": the words go first, then the perspectives' names (their icons, names still read aloud) */
@media screen and (max-width: 1439px) { .area-switch-label { display: none; } }
@media screen and (max-width: 1199px) {
  .area-switch-opt { padding: 0 9px; }
  .area-switch-opt > span { position: absolute; width: 1px; height: 1px; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
}
@media screen and (max-width: 1279px) {
  .app:not(.is-rail-open) { --rail-w: var(--rail-w-collapsed); }
  .app:not(.is-rail-open) .rail-scroll { padding-left: var(--sp-2); padding-right: var(--sp-2); }
  .app:not(.is-rail-open) .nav-heading { visibility: hidden; height: 1px; padding: 0; overflow: hidden; }
  .app:not(.is-rail-open) .nav-group + .nav-group { margin-top: var(--sp-3); border-top: 1px solid var(--line-soft); padding-top: var(--sp-3); }
  .app:not(.is-rail-open) .nav-item { justify-content: center; padding: 0; width: 44px; height: 40px; margin: 0 auto; }
  .app:not(.is-rail-open) .nav-item::before { left: calc(-1 * var(--sp-2) - 2px); }
  .app:not(.is-rail-open) .nav-label { display: none; }
  .app:not(.is-rail-open) .rail .nav-count:not(.is-needs-you) { display: none; }
  .app:not(.is-rail-open) .rail .nav-count.is-needs-you { position: absolute; top: 7px; right: 8px; width: 7px; height: 7px; min-width: 0; padding: 0; border-radius: 50%; background: var(--highlight); box-shadow: 0 0 0 1px var(--highlight-ring); color: transparent; font-size: 0; }
  .app:not(.is-rail-open) .rail-eu span, .app:not(.is-rail-open) .rail-toggle .btn-label, .app:not(.is-rail-open) .rail-slot { display: none; }
  .app:not(.is-rail-open) .rail-eu, .app:not(.is-rail-open) .rail-foot .rail-toggle { justify-content: center; padding: 0; }
  .app.is-rail-open .rail { position: fixed; left: 0; box-shadow: var(--shadow-3); z-index: var(--z-drawer); }
  .app.is-rail-open .app-body { padding-left: var(--rail-w-collapsed); }
  .appbar-brand { width: auto; padding-right: var(--sp-5); }
  .toast-stack { --toast-left: var(--rail-w-collapsed); }
  .savebar { left: var(--rail-w-collapsed); }
  .split { grid-template-columns: minmax(0, 1fr); }
  .master { position: static; max-height: 50vh; }
}
@media screen and (max-width: 1023px) {
  :root { --gutter: 20px; }
  .appbar-product span, .account-text { display: none; }
  .signin { grid-template-columns: minmax(0, 1fr); }
  .signin-brand { display: none; }
  .signin-compact { display: flex; justify-content: flex-start; margin-bottom: var(--sp-6); }   /* one alignment axis with the form */
  .signin-compact img { height: 40px; width: auto; }
  .signin-eu { display: flex; }
  .explainer-body { grid-template-columns: 1fr; }
}
/* phone: admin gets a menu button and a drawer, coach a bottom tab bar */
@media screen and (max-width: 767px) {
  :root { --gutter: var(--gutter-phone); }
  .rail { display: none; }
  .app-body { background: none; }
  .appbar { padding: 0 var(--sp-2) 0 var(--sp-1); gap: var(--sp-1); }
  .appbar .appbar-menu-btn { display: inline-flex; }
  .appbar-brand { padding: 0 var(--sp-1) 0 var(--sp-2); }
  .appbar-brand .brand-lockup-img { display: none; }
  .appbar-brand .brand-mark-img { display: block; }
  .appbar-product { display: none; }   /* the mark stands alone: never lock it up with "PathKEY" (design §3.5) */
  .area-switch { display: none; }   /* the account menu has the switch on a phone */
  .appbar-guide .btn-label, .appbar-guide .guide-badge { display: none; }   /* the Guide: its icon alone */
  .respondent-bar-text { display: none; }
  .appbar-search { flex: 0 0 auto; width: 36px; height: 36px; margin-left: 0; padding: 0; justify-content: center; background: none; }

  .appbar-search .appbar-search-text, .appbar-search .kbd { display: none; }
  .appbar-divider, .appbar-help, .account-btn > .icon { display: none; }
  .toast-stack { left: 50%; transform: translateX(-50%); bottom: var(--sp-3); }
  body.has-bottom-nav .toast-stack { bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + var(--sp-3)); }
  .savebar { left: 0; padding: var(--sp-2) var(--sp-3); flex-wrap: wrap; }
  /* the coach tab bar stays at the bottom: the save bar sits on it, toasts above both */
  body.has-bottom-nav .savebar { bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom)); }
  body.has-bottom-nav.has-savebar .toast-stack { bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + var(--savebar-now, var(--savebar-h)) + var(--sp-3)); }
  .savebar .kbd { display: none; }
  .savebar-impact { display: none; }
  .bottom-nav {
    display: grid; grid-template-columns: repeat(var(--tabs, 4), minmax(0, 1fr)); position: fixed; left: 0; right: 0; bottom: 0; z-index: var(--z-tabbar);
    height: calc(var(--tabbar-h) + env(safe-area-inset-bottom)); padding: 0 0 env(safe-area-inset-bottom);
    background: var(--bg-surface); border-top: 1px solid var(--line); box-shadow: var(--shadow-bar);
  }
  .tab-link {
    position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
    color: var(--text-muted); text-decoration: none; font-size: var(--fs-11); line-height: 1;
  }
  .tab-link .icon { width: 20px; height: 20px; stroke-width: 1.8; }
  .tab-link[aria-current="page"] { color: var(--accent-text); font-weight: var(--fw-semibold); }
  .tab-link[aria-current="page"] .icon { color: var(--accent); }
  .tab-link:focus-visible { box-shadow: var(--focus-ring-inset); }
  .tab-link .nav-count.is-needs-you { position: absolute; top: 5px; left: calc(50% + 6px); height: 18px; min-width: 18px; font-size: 10px; }
  .tab-link .nav-count:not(.is-needs-you) { display: none; }
  .app[data-layout="coach"] .work { padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom)); }
  .page { padding-top: var(--sp-5); --page-gap: var(--sp-4); }
  .page-head, .obj-head, .page-header, .object-header { padding-bottom: var(--sp-4); }
  /* object headers: no icon tile of its own row; the ⋯ menu stays on the
   * title's line at the right; the action pills share the full width below */
  .object-header-row { position: relative; row-gap: var(--sp-3); }
  .object-header-row > .icon-tile { display: none; }
  .object-header-row > .page-actions { flex: 1 1 100%; }
  .object-header-row > .page-actions > :is(.btn, .menu-anchor:not(:has(> .btn-icon))) { flex: 1 1 auto; }
  .object-header-row > .page-actions > .menu-anchor:has(> .btn-icon) { position: absolute; top: calc(var(--object-lead, 0px) - 4px); right: 0; }
  .object-header-row > .page-actions:not(:has(> .btn, > .menu-anchor > .btn:not(.btn-icon))) { display: contents; }   /* only the ⋯: no empty row */
  .object-header-row:has(> .object-header-text > .eyebrow) { --object-lead: calc(var(--lh-11) + var(--sp-1)); }
  .object-header-row:has(> .page-actions > .menu-anchor > .btn-icon) > .object-header-text { padding-right: calc(var(--h-lg) + var(--sp-2)); }
  h1, .page-head h1, .obj-head h1 { font-size: 22px; line-height: 28px; }
  .kpi-strip { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .kpi-value, .tile-v { font-size: 24px; line-height: 30px; }
  .card-head, .panel-head { padding: var(--sp-3) var(--sp-4); }
  .card-body, .panel-body { padding: var(--sp-4); }
  .rule-row, .rule-row.hd, .rule-row.measure { grid-template-columns: 1fr 1fr; }
  .rule-row.measure > span:first-child { grid-column: 1 / -1; }
  .q-pick { grid-template-columns: 1fr 1fr; }
  .q-pick > span { grid-column: 1 / -1; }
  .bare-top { padding: 0 var(--sp-4); }
  .bare-top img { height: 32px; }
  /* onboarding on a phone: the mark, View as by its icons, the Guide and Sign out by theirs (DW-07, DW-10) */
  .bare-top .brand-lockup-img { display: none; }
  .bare-top .brand-mark-img { display: block; height: 30px; }
  .bare-top .area-switch { display: inline-flex; margin-right: 0; }
  .bare-top .bare-signout .btn-label { position: absolute; width: 1px; height: 1px; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
  /* dialogs become bottom sheets */
  .dlg { width: 100%; max-width: 100%; margin: auto 0 0; border-radius: var(--r-dialog) var(--r-dialog) 0 0; max-height: 92dvh; border-bottom: 0; }
  .dlg[open] { animation-name: pk-sheet-in; }
  .dlg.is-closing { animation-name: pk-sheet-out; }
  .dlg-head { padding: var(--sp-4) var(--sp-3) var(--sp-2) var(--sp-5); }
  .dlg-body { padding: var(--sp-2) var(--sp-5) var(--sp-4); }
  .dlg-foot { padding: var(--sp-3) var(--sp-5) calc(var(--sp-3) + env(safe-area-inset-bottom)); }
  .dlg-foot .btn { flex: 1; }
  .dlg.palette { margin: var(--sp-3) var(--sp-2) auto; border-radius: var(--r-dialog); width: calc(100% - 16px); }
  .drawer:not(.is-nav) { margin: auto 0 0; width: 100%; height: auto; max-height: 92dvh; border-left: 0; border-radius: var(--r-dialog) var(--r-dialog) 0 0; }
  .drawer:not(.is-nav)[open] { animation-name: pk-sheet-in; }
  .drawer:not(.is-nav) .drawer-grabber { display: block; width: 32px; height: 4px; border-radius: 2px; background: var(--line-control); margin: 8px auto 0; }
  .drawer.is-nav { width: min(300px, 86vw); }
  /* tables become card rows */
  .dt-cards table.dt thead { display: none; }
  .dt-cards table.dt, .dt-cards table.dt tbody, .dt-cards table.dt tr, .dt-cards table.dt td { display: block; width: 100%; }
  .dt-cards table.dt tr { padding: var(--sp-3) var(--sp-4); border-bottom: 1px solid var(--line-soft); position: relative; }
  .dt-cards table.dt td { padding: 2px 0; border: 0; text-align: left; }
  .dt-cards table.dt td:not(:first-child):not(.dt-go):not(.dt-select)::before { content: attr(data-label) " · "; color: var(--text-muted); font-size: var(--fs-12); }
  .dt-cards table.dt td.dt-go { position: absolute; right: var(--sp-3); top: 50%; transform: translateY(-50%); width: auto; }
}
/* small phones: a filter with more than three options becomes a select */
@media screen and (max-width: 479px) {
  .segmented.has-select { display: none; }
  .seg-select { display: block; width: 100%; }
}
@keyframes pk-sheet-in { from { transform: translateY(24px); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes pk-sheet-out { to { transform: translateY(24px); opacity: 0; } }
@media (pointer: coarse) {
  .btn { --btn-h: 40px; }
  .btn-sm { --btn-h: 34px; }
  .nav-item { height: 44px; }
  .menu-item { min-height: 44px; }
  :root { --grip-w: 32px; }
  .drag-handle { height: 40px; color: var(--icon); }
}
@media (prefers-reduced-motion: reduce) {
  .sk { animation: none; }
  .skeleton { animation-delay: 0ms; }
  .btn.is-busy::before { animation-duration: 1.6s; }
}

/* ============================================================== print === */
@media print {
  @page { size: A4; margin: 0; }
  /* A route entering on screen must not shift whole A4 sheets during print. */
  .work.is-entering > :not(.page), .work.is-entering > .page > * { animation: none; }
  html, body { background: var(--bg-surface); }
  .app-top, .rail, .bottom-nav, .no-print, .toast-stack, .savebar, .skip-link, .bare-top, .respond-foot, .tooltip, .object-snap-anchor, .dnd-line { display: none !important; }
  .app, .app-body, .work { display: block; background: none; }
}
