/* =============================================================================
   05_page_chrome.css — canonical page-scaffold tokens + generic page chrome.

   Part of the page-scaffold unification (docs/page_scaffold.md). The numeric
   "05_" prefix sorts FIRST among asset CSS (digits < letters), so this is the
   EARLIEST layer: styles.css and zz_*.css load after it and win at equal
   specificity. That is intentional — the --sp-page-* tokens here are the
   canonical base that per-page CSS overrides.

   ADDITIVE / INERT in Stage 0. Nothing consumes --sp-page-* yet, and every
   ELEMENT-level rule below is gated on `.sp-page-shell`, which no page renders
   until its own migration stage. On routes where 00_theme_bootstrap.js already
   stamps `body.sp-route-theme-{t}`, the token declarations resolve but have no
   consumer → zero visual change.

   CONVENTION: scaffolded shells carry dict DOM ids, so target CLASSES here
   (.sp-page-shell, .sp-page--{slug}, .sp-theme-{t}), never ids.
   ============================================================================= */

/* ---- Canonical tokens: DARK ---------------------------------------------- */
/* Pre-mount: bootstrap route stamp on <body>. Post-mount: the scaffolded shell. */
body.sp-route-theme-dark,
body:where([data-sp-has~="page-shell-dark"]):not(.sp-s):not(.sp-s) {
  --sp-page-bg: #171b21;
  --sp-page-panel: #20252d;
  --sp-page-panel-strong: #20252d;
  --sp-page-border: #2d3440;
  --sp-page-text: #f4f5f7;
  --sp-page-muted: #89919e;
  --sp-page-accent: color-mix(in srgb, var(--sp-accent-primary) 88%, #ffffff 12%);
  --sp-page-header-bg: rgba(20, 24, 30, 0.92);
  --sp-page-header-panel: #20252d;
  --sp-page-header-text: #f6f7f9;
  --sp-page-header-muted: #8f97a4;
  --sp-page-header-icon: #8f97a4;
  --sp-page-header-border: #252b35;
  --sp-page-header-control: #232933;
  --sp-page-header-control-text: #d9dde3;
}

/* ---- Canonical tokens: LIGHT --------------------------------------------- */
body.sp-route-theme-light,
body:where([data-sp-has~="page-shell-light"]):not(.sp-s):not(.sp-s) {
  --sp-page-bg: #f5f5f6;
  --sp-page-panel: #ffffff;
  --sp-page-panel-strong: #ffffff;
  --sp-page-border: #e7e9ee;
  --sp-page-text: #151922;
  --sp-page-muted: #8b93a0;
  --sp-page-accent: var(--sp-accent-primary);
  --sp-page-header-bg: rgba(255, 255, 255, 0.92);
  --sp-page-header-panel: #ffffff;
  --sp-page-header-text: #222833;
  --sp-page-header-muted: #848c98;
  --sp-page-header-icon: #848c98;
  --sp-page-header-border: #eceef2;
  --sp-page-header-control: #f2f4f7;
  --sp-page-header-control-text: #717885;
}

/* ---- Generic chrome — INERT on legacy pages (gated on .sp-page-shell) ----- */
/* A page that adopts page_shell() gets its body/app background, color-scheme,
   and a themed global header for free. Legacy pages have no .sp-page-shell, so
   none of this applies to them. */
body:where([data-sp-has~="page-shell-dark"]):not(.sp-s):not(.sp-s) {
  color-scheme: dark;
}
body:where([data-sp-has~="page-shell-light"]):not(.sp-s):not(.sp-s) {
  color-scheme: light;
}

body:where([data-sp-has~="page-shell"]):not(.sp-s) {
  background: var(--sp-page-bg);
}
body:where([data-sp-has~="page-shell"]):not(.sp-s) #app-container {
  background: var(--sp-page-bg);
}

/* The global header follows the page theme — the fix for "the header stays
   light over a dark page". Off --sp-page-header-* so it tracks each page. */


/* ---- Standard top panel — INERT until a page renders page_topbar() -------- */
.sp-page-topbar {
  width: 100%;
}
.sp-page-topbar--sticky {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--sp-page-header-bg);
  -webkit-backdrop-filter: saturate(1.2) blur(12px);
  backdrop-filter: saturate(1.2) blur(12px);
  border-bottom: 1px solid var(--sp-page-header-border);
}
.sp-page-topbar__row {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 48px;
  max-width: 1260px;
  margin: 0 auto;
  padding: 0 16px;
}
.sp-page-topbar__back {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: 10px;
  border: 1px solid var(--sp-page-header-border);
  background: var(--sp-page-header-control);
  color: var(--sp-page-header-control-text);
  cursor: pointer;
  text-decoration: none;
  flex: 0 0 auto;
}
.sp-page-topbar__title {
  font-family: "Manrope", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-weight: 700;
  font-size: 17px;
  line-height: 1.2;
  color: var(--sp-page-header-text);
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.sp-page-topbar__actions {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 0 0 auto;
}
.sp-page-topbar__toolbar {
  max-width: 1260px;
  margin: 0 auto;
  padding: 0 16px 8px;
}

/* ---- Scale tokens - UI redesign Phase 0b (docs/ui_redesign_kickoff.md) ----
   ADDITIVE + INERT: global scale variables only - type / space / radius / z /
   motion, per docs/ui_unification_plan.md section 2. Nothing consumes them
   yet; the component kit (10_ui_kit.css) starts consuming them in Phase 1.
   Accent hexes intentionally stay where they are today (styles.css
   .sp-accent-* blocks) - single-source accent dedup is a later stage.
   Scales are theme-independent, hence :root. */
:root {
  /* type - Manrope for UI; --sp-font-mono now lives in assets/00_tokens.css */
  --sp-font-sans: "Manrope", "Segoe UI", system-ui, sans-serif;
  --sp-font-12: 12px;
  --sp-font-13: 13px;
  --sp-font-14: 14px;
  --sp-font-16: 16px;
  --sp-font-18: 18px;
  --sp-font-22: 22px;
  --sp-font-28: 28px;
  --sp-font-weight-medium: 500;
  --sp-font-weight-bold: 700;
  --sp-font-weight-heavy: 800;

  /* space */
  --sp-space-1: 4px;
  --sp-space-2: 8px;
  --sp-space-3: 12px;
  --sp-space-4: 16px;
  --sp-space-5: 24px;
  --sp-space-6: 32px;
  --sp-space-7: 48px;

  /* radius */
  --sp-radius-sm: 8px;
  --sp-radius-md: 12px;
  --sp-radius-lg: 16px;
  /* --sp-radius-pill lives in assets/00_tokens.css */

  /* z-index layers */
  --sp-z-base: 0;
  --sp-z-raised: 10;
  --sp-z-sticky: 20;
  --sp-z-overlay: 40;
  --sp-z-modal: 100;
  --sp-z-toast: 1000;

  /* motion - 150-250ms ease-out family; respect prefers-reduced-motion at
     consumption sites */
  --sp-ease: cubic-bezier(0.2, 0, 0, 1);
  --sp-dur-fast: 150ms;
  --sp-dur-med: 200ms;
  --sp-dur-slow: 250ms;
}
