/* ============================================================================
   base.css — reset, type, the shell grid, the auth card, page states.
   Colours and sizes come from tokens.css only. Component rules live in
   components.css; nothing here styles a component.
   ========================================================================== */
*, *::before, *::after { box-sizing: border-box; }
html { color-scheme: light dark; -webkit-text-size-adjust: 100%; }
:root[data-theme="light"] { color-scheme: light; }
:root[data-theme="dark"] { color-scheme: dark; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: var(--text-base);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }

h1, h2, h3, p, dl, dd, ul, figure { margin: 0; }
h1 { font-size: var(--text-lg); font-weight: 600; line-height: 1.25; }
h2 { font-size: var(--text-md); font-weight: 600; line-height: 1.25; }
h3 { font-size: var(--text-base); font-weight: 600; line-height: 1.25; }
small { font-size: var(--text-sm); }
a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); text-decoration: underline; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: default; }
pre { margin: 0; font-family: var(--font-mono); font-size: var(--text-sm); white-space: pre-wrap; word-break: break-word; }
details > summary { cursor: pointer; font-weight: 500; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

/* utilities used across sections */
.u-num { font-family: var(--font-mono); font-variant-numeric: tabular-nums; text-align: right; }
.u-mono { font-family: var(--font-mono); }
.u-help { font-size: var(--text-sm); color: var(--ink-2); }
.u-err { display: block; font-size: var(--text-sm); color: var(--bad); margin-top: var(--s-1); }
.u-eyebrow { font-size: var(--text-sm); color: var(--ink-3); margin-bottom: var(--s-1); }
.sub { display: block; font-size: var(--text-sm); color: var(--ink-3); }
.spacer { flex: 1 1 auto; }
.spin {
  display: inline-block; width: 12px; height: 12px; margin-right: var(--s-2); vertical-align: -1px;
  border-radius: var(--r-round); border: 2px solid currentColor; border-right-color: transparent;
  animation: cp-spin 0.9s linear infinite;
}
@keyframes cp-spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spin { animation: none; } }

/* ---------- the shell ----------
   Rail on the surface colour with a hairline, never a dark rail. Below 900 px
   the rail becomes an off-canvas drawer opened by the top-bar menu button. */
.shell { display: grid; grid-template-columns: var(--rail-w) minmax(0, 1fr); min-height: 100vh; }
.rail {
  position: sticky; top: 0; height: 100vh;
  display: flex; flex-direction: column; gap: var(--s-4);
  padding: var(--s-4) var(--s-3);
  background: var(--surface); border-right: 1px solid var(--line);
  overflow-y: auto;
}
.brand { padding: var(--s-1) var(--s-2); line-height: 1.25; }
.brand b { display: block; font-size: var(--text-md); font-weight: 600; }
.brand b em { font-style: normal; color: var(--accent); }
.brand small { color: var(--ink-2); }

.work { display: flex; flex-direction: column; min-width: 0; }
.topbar {
  display: none; align-items: center; gap: var(--s-3);
  height: 56px; padding: 0 var(--s-3) 0 var(--s-2);
  border-bottom: 1px solid var(--line); background: var(--paper);
  position: sticky; top: 0; z-index: 5;
}
.topbar h1 { font-size: var(--text-md); flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.burger { display: none; }
.page { flex: 1; padding: var(--s-6); display: flex; flex-direction: column; gap: var(--s-5); min-width: 0; }
.page > * { max-width: 1200px; width: 100%; }
.scrim { position: fixed; inset: 0; background: var(--scrim); z-index: 19; }

/* nav */
.nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.nav-sec { font-size: var(--text-sm); color: var(--ink-3); padding: var(--s-3) var(--s-2) var(--s-1); }
.nav-item {
  display: flex; align-items: center; gap: var(--s-2);
  min-height: 36px; padding: var(--s-2) 10px; border-radius: var(--r-1);
  color: var(--ink-2); text-decoration: none;
}
.nav-item:hover { background: var(--surface-2); color: var(--ink); text-decoration: none; }
.nav-item[aria-current="page"] { background: var(--surface-2); color: var(--ink); font-weight: 500; box-shadow: inset 2px 0 0 var(--accent); }
.nav-count {
  margin-left: auto; font-family: var(--font-mono); font-size: var(--text-sm); line-height: 1;
  padding: var(--s-1) 6px; border-radius: var(--r-1); background: var(--surface-2); color: var(--ink);
}
/* red only while the count includes critical items (Tokens board badge rule) */
.nav-count-critical { background: var(--bad); color: #FFFFFF; }

/* vaulter switcher: a real listbox, not a prompt */
.grp-wrap { position: relative; }
.grp {
  display: flex; align-items: center; gap: var(--s-2); width: 100%; text-align: left;
  padding: var(--s-2) 10px; border: 1px solid var(--line); border-radius: var(--r-1); background: var(--surface);
}
.grp:not(:disabled):hover { border-color: var(--line-strong); }
.grp > span:first-child { flex: 1; min-width: 0; display: flex; flex-direction: column; line-height: 1.25; }
.grp small { font-size: var(--text-sm); color: var(--ink-3); }
.grp b { font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.grp-caret { color: var(--ink-3); }
.grp-menu {
  position: absolute; left: 0; right: 0; top: calc(100% + var(--s-1)); z-index: 30;
  list-style: none; margin: 0; padding: var(--s-1);
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-1); box-shadow: var(--shadow-lg);
  max-height: 320px; overflow-y: auto;
}
.grp-opt {
  display: flex; align-items: center; width: 100%; text-align: left;
  min-height: 36px; padding: var(--s-2) 10px; border: 0; border-radius: var(--r-1); background: transparent;
}
.grp-opt:hover, .grp-opt:focus-visible { background: var(--surface-2); outline-offset: -2px; }
.grp-opt[aria-selected="true"] { font-weight: 500; box-shadow: inset 2px 0 0 var(--accent); }
.grp-opt-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* rail foot */
.rail-foot { display: flex; align-items: center; gap: var(--s-2); padding: var(--s-2); border-top: 1px solid var(--line); }
.avatar {
  flex: none; width: 32px; height: 32px; border-radius: var(--r-round);
  background: var(--accent-soft); color: var(--accent);
  display: inline-flex; align-items: center; justify-content: center; font-weight: 600; font-size: var(--text-sm);
}
.who { flex: 1; min-width: 0; display: flex; flex-direction: column; line-height: 1.25; }
.who b { font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.who small { color: var(--ink-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon-btn {
  flex: none; width: 32px; height: 32px; padding: 0; border-radius: var(--r-1);
  border: 1px solid transparent; background: transparent; color: var(--ink-3);
  display: inline-flex; align-items: center; justify-content: center; font-size: var(--text-md);
}
.icon-btn:hover { background: var(--surface-2); color: var(--ink); }

/* page head and states */
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--s-4); flex-wrap: wrap; }
.ph-copy p:last-child { color: var(--ink-2); margin-top: var(--s-1); }
.state {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-2);
  padding: var(--s-6) var(--s-5); text-align: center;
  display: flex; flex-direction: column; align-items: center; gap: var(--s-2);
}
.state h2 { margin-top: 0; }
.state p { color: var(--ink-2); max-width: 48ch; }
.state-rule { display: block; width: 32px; height: 2px; background: var(--line-strong); border-radius: var(--r-round); }
.state-error .state-rule { background: var(--bad); }

/* ---------- auth card (index.html, 404.html) ---------- */
.auth { min-height: 100vh; display: grid; place-items: center; padding: var(--s-4); }
.auth-card {
  width: 100%; max-width: 380px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-2);
  padding: var(--s-5);
}
.auth-brand { font-size: var(--text-lg); font-weight: 600; line-height: 1.25; }
.auth-brand em { font-style: normal; color: var(--accent); }
.auth-tag { font-size: var(--text-sm); color: var(--ink-2); margin-bottom: var(--s-5); }
.auth-form { display: flex; flex-direction: column; gap: var(--s-4); }
.auth-alt { text-align: center; font-size: var(--text-sm); }
.linklike { padding: 0; border: 0; background: none; color: var(--accent); font-size: inherit; }
.linklike:hover { color: var(--accent-hover); text-decoration: underline; }

/* ---------- responsive ---------- */
@media (max-width: 899px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .rail {
    position: fixed; left: 0; top: 0; bottom: 0; height: auto; width: min(var(--rail-w), 86vw); z-index: 20;
    transform: translateX(-100%); transition: transform 160ms ease-out;
    box-shadow: none;
  }
  .rail.is-open { transform: none; box-shadow: var(--shadow-lg); }
  .topbar { display: flex; }
  .burger { display: inline-flex; }
  .page { padding: var(--s-4); gap: var(--s-4); }
  /* the top bar already names the section */
  .page-head .u-eyebrow, .page-head h1 { display: none; }
  .ph-copy p:last-child { margin-top: 0; }
}
@media (prefers-reduced-motion: reduce) { .rail { transition: none; } }
@media (max-width: 600px) {
  :root { --control-h: 44px; }
}
