/* ===========================================================================
   Sitewise — Reset, shell, layout, page composition
   =========================================================================== */

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: var(--t-base);
  line-height: var(--lh-body);
  letter-spacing: var(--tr-normal);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

h1, h2, h3, h4, h5, h6, p, figure, ul, ol, dl, dd { margin: 0; }
ul, ol { padding: 0; list-style: none; }
img, svg, video { display: block; max-width: 100%; }
.ico { width: 16px; height: 16px; flex: 0 0 auto; }
[hidden] { display: none !important; }
button, input, select, textarea { font: inherit; color: inherit; letter-spacing: inherit; }
button { cursor: pointer; }
a { color: var(--info); text-decoration-color: color-mix(in oklch, var(--info) 35%, transparent); text-underline-offset: 2px; }
a:hover { text-decoration-color: currentColor; }

h1, h2, h3, h4 { line-height: var(--lh-tight); letter-spacing: var(--tr-tight); font-weight: 600; text-wrap: balance; }
p { text-wrap: pretty; }

:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
  border-radius: var(--r-xs);
}
/* Never remove focus, only shape it */
:focus:not(:focus-visible) { outline: none; }

::selection { background: var(--brand-wash-2); color: var(--ink); }

.u-sr {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.u-skip {
  position: absolute; left: var(--s-4); top: var(--s-4); z-index: var(--z-tooltip);
  transform: translateY(-200%); background: var(--ink); color: var(--ink-invert);
  padding: var(--s-4) var(--s-8); border-radius: var(--r-sm); font-weight: 600;
  transition: transform var(--dur-2) var(--ease-out);
}
.u-skip:focus { transform: translateY(0); }

/* ===========================================================================
   App shell
   =========================================================================== */

.shell {
  display: grid;
  grid-template-columns: var(--nav-w) minmax(0, 1fr);
  min-height: 100vh;
  min-height: 100dvh;
}

/* --- Sidebar ---------------------------------------------------------- */
.nav {
  grid-column: 1;
  border-right: 1px solid var(--line);
  background: var(--bg);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  height: 100dvh;
  z-index: var(--z-sticky);
}

.nav__brand {
  display: flex; align-items: center; gap: var(--s-5);
  height: var(--header-h);
  padding: 0 var(--s-8);
  border-bottom: 1px solid var(--line);
  flex: 0 0 auto;
  text-decoration: none;
  color: inherit;
}
.nav__mark {
  width: 26px; height: 26px; flex: 0 0 auto;
  border-radius: var(--r-xs);
  background: var(--ink);
  display: grid; place-items: center;
}
.nav__mark svg { width: 15px; height: 15px; color: var(--brand); }
.nav__word {
  font-size: 0.9375rem; font-weight: 700; letter-spacing: -0.02em;
  font-stretch: 108%;
}
.nav__word em { font-style: normal; color: var(--brand-ink); }

.nav__scroll { flex: 1 1 auto; overflow-y: auto; padding: var(--s-6) 0 var(--s-12); }

.nav__group { padding: var(--s-6) var(--s-5) var(--s-2); }
.nav__group-label {
  font-size: var(--t-2xs); font-weight: 600; text-transform: uppercase;
  letter-spacing: var(--tr-label); color: var(--ink-muted);
  padding: 0 var(--s-5) var(--s-3);
}

.nav__link {
  display: flex; align-items: center; gap: var(--s-6);
  padding: var(--s-4) var(--s-5);
  margin: 1px var(--s-5);
  border-radius: var(--r-sm);
  color: var(--ink-2);
  text-decoration: none;
  font-size: var(--t-base);
  font-weight: 500;
  transition: background-color var(--dur-1) ease, color var(--dur-1) ease;
  position: relative;
}
.nav__link svg { width: 16px; height: 16px; flex: 0 0 auto; color: var(--ink-faint); transition: color var(--dur-1) ease; }
.nav__link:hover { background: var(--surface); color: var(--ink); }
.nav__link:hover svg { color: var(--ink-2); }
.nav__link[aria-current='page'] {
  background: var(--surface-2);
  color: var(--ink);
  font-weight: 600;
}
.nav__link[aria-current='page'] svg { color: var(--brand-ink); }
.nav__count {
  margin-left: auto;
  font-family: var(--font-mono); font-size: var(--t-2xs); font-variant-numeric: tabular-nums;
  background: var(--surface-2); color: var(--ink-muted);
  padding: 1px var(--s-3); border-radius: var(--r-pill); min-width: 20px; text-align: center;
}
.nav__count--attn { background: var(--brand); color: oklch(0.16 0.03 62); font-weight: 700; }

.nav__foot { flex: 0 0 auto; border-top: 1px solid var(--line); padding: var(--s-6); }

/* --- Header ----------------------------------------------------------- */
.main { grid-column: 2; min-width: 0; display: flex; flex-direction: column; }

.header {
  position: sticky; top: 0; z-index: var(--z-sticky);
  display: flex; align-items: center; gap: var(--s-8);
  height: var(--header-h);
  padding: 0 var(--s-12);
  border-bottom: 1px solid var(--line);
  background: color-mix(in oklch, var(--bg) 88%, transparent);
  backdrop-filter: saturate(180%) blur(12px);
}
.header__title { font-size: var(--t-md); font-weight: 650; letter-spacing: var(--tr-tight); }
.header__sub { color: var(--ink-muted); font-size: var(--t-sm); }
.header__actions { margin-left: auto; display: flex; align-items: center; gap: var(--s-5); flex-shrink: 0; }

.navtoggle { display: none; }

/* --- Page ------------------------------------------------------------- */
.page { padding: var(--s-12); max-width: var(--page-max); width: 100%; flex: 1 1 auto; }
.page--flush { padding: 0; }
.page--narrow { max-width: 900px; }

.page__head { margin-bottom: var(--s-12); }
.page__title { font-size: var(--t-xl); font-weight: 650; font-stretch: 104%; letter-spacing: var(--tr-display); }
.page__lede { color: var(--ink-muted); margin-top: var(--s-3); max-width: var(--reading-max); }

.section { margin-top: var(--s-16); }
.section__head {
  display: flex; align-items: baseline; gap: var(--s-8);
  padding-bottom: var(--s-5); margin-bottom: var(--s-8);
  border-bottom: 1px solid var(--line);
}
.section__title { font-size: var(--t-md); font-weight: 650; }
.section__note { color: var(--ink-muted); font-size: var(--t-sm); }
.section__actions { margin-left: auto; display: flex; gap: var(--s-4); flex-wrap: wrap; }

/* --- Generic layout helpers ------------------------------------------- */
.row { display: flex; align-items: center; gap: var(--s-6); }
.row--tight { gap: var(--s-4); }
.row--wrap { flex-wrap: wrap; }
.col { display: flex; flex-direction: column; gap: var(--s-6); }
.spacer { flex: 1 1 auto; }

.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: var(--s-12); }
.grid-3 { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: var(--s-10); }
.split { display: grid; grid-template-columns: minmax(0, 1.35fr) minmax(0, 1fr); gap: var(--s-16); align-items: start; }

/* ===========================================================================
   Summary strip — hairline-divided, NOT a row of shadow cards
   =========================================================================== */
.strip {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  overflow: hidden;
  background: var(--bg);
}
.strip__cell {
  padding: var(--s-8) var(--s-10);
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  min-width: 0;
}
.strip__cell:last-child { border-right: 0; }
.strip__label {
  font-size: var(--t-2xs); font-weight: 600; text-transform: uppercase;
  letter-spacing: var(--tr-label); color: var(--ink-muted);
  display: flex; align-items: center; gap: var(--s-3);
}
.strip__value {
  font-family: var(--font-mono); font-variant-numeric: tabular-nums;
  font-size: var(--t-2xl); font-weight: 500; letter-spacing: -0.03em;
  margin-top: var(--s-3); line-height: 1.1; color: var(--ink);
}
.strip__value--sm { font-size: var(--t-lg); }
.strip__meta { font-size: var(--t-xs); color: var(--ink-muted); margin-top: var(--s-2); }
.strip__value.is-pos { color: var(--positive); }
.strip__value.is-neg { color: var(--negative); }
.strip__value.is-attn { color: var(--brand-ink); }

/* Rows fill remaining track space cleanly at any wrap count */
@supports (grid-template-columns: subgrid) {
  .strip__cell { border-bottom: 0; }
}

/* ===========================================================================
   Panel — a bordered region. Never nested.
   =========================================================================== */
.panel {
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  background: var(--bg);
  overflow: hidden;
}
.panel__head {
  display: flex; align-items: center; gap: var(--s-6);
  padding: var(--s-8) var(--s-10);
  border-bottom: 1px solid var(--line);
  background: var(--bg);
}
.panel__title { font-size: var(--t-base); font-weight: 650; }
.panel__note { font-size: var(--t-xs); color: var(--ink-muted); }
.panel__body { padding: var(--s-10); }
.panel__body--flush { padding: 0; }
.panel__foot {
  padding: var(--s-6) var(--s-10); border-top: 1px solid var(--line);
  background: var(--surface); font-size: var(--t-sm); color: var(--ink-muted);
  display: flex; align-items: center; gap: var(--s-6);
}

/* ===========================================================================
   Responsive
   =========================================================================== */
@media (max-width: 1100px) {
  .split { grid-template-columns: minmax(0, 1fr); }
}

@media (max-width: 900px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .nav {
    position: fixed; inset: 0 auto 0 0; width: min(84vw, var(--nav-w));
    transform: translateX(-101%);
    transition: transform var(--dur-3) var(--ease-out);
    z-index: var(--z-drawer);
    box-shadow: var(--sh-drawer);
  }
  body.nav-open .nav { transform: translateX(0); }
  body.nav-open::after {
    content: ''; position: fixed; inset: 0; z-index: var(--z-raised);
    background: oklch(0.2 0 0 / 0.32);
  }
  .main { grid-column: 1; }
  .navtoggle { display: inline-grid; }
  .header { padding: 0 var(--s-8); }
  .page { padding: var(--s-8); }
}

@media (max-width: 600px) {
  .page { padding: var(--s-6); }
  .header__sub { display: none; }
  .strip { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .strip__value { font-size: var(--t-lg); }
  .strip__cell { border-bottom: 1px solid var(--line); }
  .strip__cell:nth-child(2n) { border-right: 0; }
  /* Rows carrying a title on one side and a figure on the other have to
     stack here, or the two collide. */
  .row--stack-sm { flex-direction: column; align-items: stretch; gap: var(--s-6); }
  .row--stack-sm .u-right { text-align: left; }
}

@media print {
  .nav, .header, .demo, .no-print { display: none !important; }
  .shell { grid-template-columns: 1fr; }
  body { font-size: 11pt; }
  .panel { break-inside: avoid; }
}
