html, body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: var(--fs);
  line-height: var(--lh);
  font-weight: var(--fw-regular);
  min-height: 100vh;
}

a { color: var(--ink); transition: color var(--t-fast); }
a:hover { color: var(--accent); }

/* ───── App shell layout ─────────────────────────────────────────────── */

.app {
  display: grid;
  grid-template-rows: var(--nav-h) 1fr;
  grid-template-columns: var(--rail-w) 1fr;
  grid-template-areas:
    "nav  nav"
    "rail main";
  min-height: 100vh;
}

.app--no-rail {
  grid-template-columns: 1fr;
  grid-template-areas:
    "nav"
    "main";
}

/* Mobile (<720px): defined further down, AFTER the base .nav-top / .nav-top__links /
   .nav-top__user-name / .main rules. Source order matters — when the override
   block was placed before the base rules (pre-Session-29) the base rules
   silently won, so the inline link list and full nav-top padding rendered at
   narrow viewports despite the @media being authored. See the mobile @media
   block near the bottom of this file. */

.nav-top  { grid-area: nav; }
.nav-rail { grid-area: rail; }
.main     { grid-area: main; }

/* ───── Top nav ─────────────────────────────────────────────────────── */

.nav-top {
  display: flex;
  align-items: center;
  gap: var(--sp-5);
  padding: 0 var(--sp-5);
  height: var(--nav-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}

.nav-top__brand {
  font-size: var(--fs-md);
  font-weight: var(--fw-semi);
  letter-spacing: -0.01em;
  color: var(--ink);
  display: flex;
  align-items: center;
  gap: var(--sp-2);
}
/* Current brand mark — the currant logo (partials/logo_current.php).
   It's dark-line tattoo art: it must stay dark-lines-on-light-paper to read,
   so the structure is theme-stable (paper = the always-light --ink-hero; line
   = the logo's signature dark) while the FRUIT tracks the theme (--accent /
   --accent-strong). That keeps it legible on dark-chrome navs (Tuxedo) where a
   plain --ink inversion washed out, and identical to the light-theme look on
   every theme. The favicon mirrors these mappings in JS (initThemedFavicon).
   --logo-ink is the one fixed value: no token is reliably dark across themes
   (sanrio/kawaii even make --surface-hero an accent colour). */
.logo-current {
  height: 38px;
  width: auto;
  display: block;
  flex: none;
  --logo-ink: #0a2129;
}
.logo-current__halo  { fill: var(--ink-hero); }
.logo-current__line  { fill: var(--logo-ink); }
.logo-current__berry { fill: var(--accent); }
.logo-current__leaf  { fill: var(--accent-strong); }
.logo-current__glint { fill: var(--ink-hero); }

.nav-top__links {
  display: flex;
  align-items: center;
  align-self: stretch;   /* full nav height, so a group's flush dropdown can anchor to the nav's bottom edge */
  gap: var(--sp-1);
  margin-left: var(--sp-4);
}
.nav-top__link {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  padding: 6px var(--sp-3);
  font-size: var(--fs-sm);
  color: var(--ink-2);
  border-radius: var(--r);
  transition: background var(--t-fast), color var(--t-fast);
}
.nav-top__link:hover { background: var(--hover); color: var(--ink); }
.nav-top__link.is-active { color: var(--ink); background: var(--active); }
.nav-top__link.is-active:hover { background: var(--active); }

/* ─── Nav-top tab groups (Batch B / session 20) ─────────────────────────────
 * Theme-first: container = `.nav-top__group` (flex wrapper, no styling of its
 * own). Trigger reuses `.nav-top__link`. Menu floater piggybacks on the
 * proven `.chip-picker__menu` look — same tokens, same border/shadow recipe,
 * works on every theme without bespoke rules. Items inside the menu reuse
 * `.nav-top__link` so theme tokens, hover, and is-active behave identically
 * to the top-level nav.
 */
.nav-top__group {
  position: relative;
  display: inline-flex;
  align-self: stretch;   /* fill the nav height so the menu anchors flush to the nav's bottom edge */
  align-items: center;   /* keep the toggle button vertically centered */
}
.nav-top__group-toggle {
  background: transparent;
  border: 0;
  cursor: pointer;
  font: inherit;
}
.nav-top__group-caret {
  display: inline-block;
  margin-left: 2px;
  font-size: 10px;
  line-height: 1;
  transition: transform var(--t-fast);
}
.nav-top__group-toggle[aria-expanded="true"] .nav-top__group-caret {
  transform: rotate(180deg);
}
.nav-top__group-menu {
  position: absolute;
  z-index: 30;
  top: 100%;                       /* flush under the nav-top bottom edge */
  left: 0;
  min-width: 200px;
  padding: 4px 0;
  background: var(--surface);
  border: 1px solid var(--border-strong, var(--surface-2));
  border-top: 0;                   /* the nav's bottom border is the menu's top edge */
  border-radius: 0 0 var(--r) var(--r);   /* square top corners → reads as attached to the bar */
  box-shadow: var(--shadow);
}
.nav-top__group-menu[hidden] { display: none; }
.nav-top__group-menu .nav-top__link {
  display: flex;
  border-radius: 0;
  padding: 6px var(--sp-3);
}

.nav-top__badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 18px;
  height: 18px;
  padding: 0 6px;
  font-size: 11px;
  font-weight: var(--fw-medium);
  border-radius: var(--r);
  background: var(--accent);
  color: var(--ink-on-strong);
  margin-left: 2px;
}

.nav-top__spacer { flex: 1; }

.nav-top__user {
  display: flex;
  align-items: center;
  align-self: stretch;   /* full nav height so the status dropdown sits flush under the bar */
  gap: var(--sp-3);
}
.nav-top__user-link {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  padding: 4px 8px;
  border-radius: var(--r);
  text-decoration: none;
  transition: background var(--t-fast);
}
.nav-top__user-link:hover { background: var(--hover); }
.nav-top__user-name {
  font-size: var(--fs-sm);
  color: var(--ink-2);
}
.nav-top__user-link:hover .nav-top__user-name { color: var(--ink); }
.nav-top__avatar {
  width: 28px; height: 28px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--surface-2);
  color: var(--ink);
  font-size: var(--fs-xs);
  font-weight: var(--fw-medium);
  border: 2px solid var(--avatar-color, var(--border-strong));
  overflow: hidden;
}
.nav-top__avatar--img { padding: 0; object-fit: cover; }

/* User-chip status menu — the chip is a profile link; hover / focus-within
   reveals a dropdown to set your own presence + status message. Lives inside
   .nav-top so it inherits the (dark-on-tuxedo) chrome tokens. */
/* Stretch the chip to the full nav height + centre its content, so the dropdown's
   top:100% lands exactly on the nav's bottom edge (no overshoot above the bar). */
.nav-top__user-menu { position: relative; display: flex; align-self: stretch; align-items: center; }
.nav-top__user-dropdown {
  position: absolute;
  z-index: 30;
  top: 100%;
  right: 0;
  min-width: 252px;
  padding: var(--sp-3);
  display: none;
  flex-direction: column;
  gap: var(--sp-2);
  background: var(--surface);
  border: 1px solid var(--border-strong, var(--surface-2));
  border-top: 0;
  border-radius: 0 0 var(--r) var(--r);
  box-shadow: var(--shadow);
  color: var(--ink);
}
.nav-top__user-menu:hover .nav-top__user-dropdown,
.nav-top__user-menu:focus-within .nav-top__user-dropdown { display: flex; }
.nav-top__status-head {
  font-size: var(--fs-xs);
  font-weight: var(--fw-semi);
  color: var(--ink-3);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.nav-top__user-dropdown .presence-picker { flex-direction: column; gap: var(--sp-1); }
.nav-top__user-dropdown .presence-chip { width: 100%; }
.nav-top__status-text { width: 100%; }
/* Shown instead of the picker when you're not on a work task (no online modifier
   without a running task — presence follows the time tracker). */
.nav-top__status-hint { margin: 0; font-size: var(--fs-xs); color: var(--ink-3); line-height: var(--lh); }

.nav-top__bell {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px; height: 32px;
  color: var(--ink-2);
  border-radius: var(--r);
  transition: background var(--t-fast), color var(--t-fast);
}
.nav-top__bell:hover { background: var(--hover); color: var(--ink); }
.nav-top__bell svg,
.nav-top__bell .icon { width: 18px; height: 18px; }
.nav-top__bell-badge {
  position: absolute;
  top: 2px;
  right: 2px;
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  font-size: 10px;
  font-weight: var(--fw-semi);
  background: var(--accent);
  color: var(--ink-on-strong);
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

/* (the old top-nav "Sign out" link/rule was removed session 22 — "Sign out"
   moved to the user-edit page header, where it reuses .btn--ghost.) */

/* ───── Left rail ───────────────────────────────────────────────────── */

.nav-rail {
  background: var(--bg);
  border-right: 1px solid var(--border);
  padding: var(--sp-3) var(--sp-2);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
}

.nav-rail__section-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--ink-3);
  padding: var(--sp-2) var(--sp-3) var(--sp-1);
  font-weight: var(--fw-medium);
}

.nav-rail__new-btn {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  padding: 8px var(--sp-3);
  font-size: var(--fs-sm);
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--r);
  margin-bottom: var(--sp-2);
  transition: background var(--t-fast), border-color var(--t-fast);
}
.nav-rail__new-btn:hover {
  background: var(--surface-2);
  border-color: var(--accent);
  color: var(--ink);
}
.nav-rail__new-btn svg { width: 14px; height: 14px; }

.nav-rail__list {
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.nav-rail__filter {
  font-size: var(--fs-xs);
  padding: 5px var(--sp-2);
  margin-bottom: var(--sp-1);
}

.nav-rail__item {
  display: grid;
  grid-template-columns: auto 1fr;
  grid-template-rows: auto auto;
  align-items: center;
  column-gap: var(--sp-2);
  padding: 6px var(--sp-3);
  font-size: var(--fs-sm);
  color: var(--ink-2);
  border-radius: var(--r);
  transition: background var(--t-fast), color var(--t-fast);
}
.nav-rail__item:hover { background: var(--hover); color: var(--ink); }
.nav-rail__item-dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  flex-shrink: 0;
  background: var(--dev-color, var(--ink-3));
  grid-row: 1 / span 2;
  align-self: center;
}
.nav-rail__item-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}
.nav-rail__item-sub {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
  font-size: var(--fs-xs);
  color: var(--ink-3);
  line-height: 1.3;
}

/* ───── Main content area ───────────────────────────────────────────── */

.main {
  padding: var(--sp-5);
  min-width: 0;
}

/* Mobile (<720px): hide the desktop rail + top-nav links; the hamburger
   in .nav-top opens the slide-in .nav-drawer (in layout.php), which
   carries the primary nav + the page-specific rail content.
   `.app >` scopes the hide to the DESKTOP rail (a direct child of .app);
   the drawer's copy (inside .nav-drawer__rail) is unaffected. See
   components.css .nav-top__hamburger + .nav-drawer* + app.js initNavDrawer().
   Block placed AFTER the base .nav-top / .nav-top__links / .nav-top__user-name
   / .main rules so source order doesn't undo it (Session-29). */
@media (max-width: 720px) {
  .app {
    grid-template-columns: 1fr;
    grid-template-areas:
      "nav"
      "main";
  }
  .app > .nav-rail { display: none; }
  .nav-top  { padding: 0 var(--sp-3); gap: var(--sp-3); }
  .nav-top__links { display: none; }
  .nav-top__user-name { display: none; }
  .main { padding: var(--sp-3); }
}

.page {
  max-width: var(--content-max);
  margin: 0 auto;
}

.page__header {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--sp-3);
  margin-bottom: var(--sp-4);
}
.page__header-actions {
  display: inline-flex;
  flex-wrap: wrap;
  gap: var(--sp-2);
  align-items: center;
}
/* Profile (/users/{id}/edit) header: big avatar inline-left of the title block. */
.page__header--profile { align-items: center; }
.page__header-main {
  display: flex;
  align-items: center;
  gap: var(--sp-4);
  min-width: 0;
}
.page__title {
  font-size: var(--fs-2xl);
  font-weight: var(--fw-semi);
  letter-spacing: -0.02em;
  color: var(--ink);
  margin: 0;
}
.page__welcome {
  font-size: var(--fs-3xl);
  font-weight: var(--fw-semi);
  letter-spacing: -0.025em;
  color: var(--ink);
  margin: 0;
}
.page__hero {
  font-size: var(--fs-4xl);
  font-weight: var(--fw-semi);
  letter-spacing: -0.025em;
  color: var(--ink-hero);
  margin: 0;
}

/* Skip-to-content link — invisible until keyboard-focused. Lets keyboard
   users bypass nav-top + sidebar straight to <main>. WCAG 2.4.1 bypass-blocks. */
.skip-link {
  position: absolute;
  top: -100px;
  left: var(--sp-3);
  padding: var(--sp-2) var(--sp-4);
  background: var(--accent);
  color: var(--ink-on-strong);
  font-weight: var(--fw-semi);
  font-size: var(--fs-sm);
  border-radius: var(--r);
  text-decoration: none;
  z-index: 99999;
  transition: top var(--t-fast);
}
.skip-link:focus {
  top: var(--sp-3);
  outline: 2px solid var(--ink-on-strong);
  outline-offset: 2px;
}
.main:focus { outline: none; }

.page__subtitle {
  font-size: var(--fs-sm);
  color: var(--ink-3);
  margin-top: 2px;
}

/* Flash messages */
.flashes {
  margin-bottom: var(--sp-4);
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
}
.flash {
  padding: var(--sp-3) var(--sp-4);
  border-radius: var(--r-none);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-top-width: 3px;
  font-size: var(--fs-sm);
}
.flash--error    { border-top-color: var(--danger); }
.flash--success  { border-top-color: var(--accent); }
.flash--info     { border-top-color: var(--ink-3); }

/* Empty state */
.empty {
  text-align: center;
  padding: var(--sp-7) var(--sp-5);
  color: var(--ink-3);
  font-size: var(--fs-sm);
}

/* Auth screen — used by login + first-user bootstrap */
.auth-shell {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--sp-5);
  background: var(--bg);
}
.auth-card {
  width: 100%;
  max-width: 360px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: var(--sp-6);
}
.auth-card__brand {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  margin-bottom: var(--sp-5);
  font-size: var(--fs-md);
  font-weight: var(--fw-semi);
}
.auth-card h1 {
  font-size: var(--fs-xl);
  font-weight: var(--fw-semi);
  margin-bottom: var(--sp-2);
}
.auth-card p.sub {
  font-size: var(--fs-sm);
  color: var(--ink-3);
  margin-bottom: var(--sp-5);
}
.auth-form {
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
}

/* Passkey sign-in block (login page only). Revealed by JS when the browser
   supports WebAuthn. Sits below the password Sign-in button. */
.auth-passkey {
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
  margin-top: var(--sp-1);
}
.auth-passkey__divider {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  color: var(--ink-2);
  font-size: var(--fs-sm);
}
.auth-passkey__divider::before,
.auth-passkey__divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--border);
}
.auth-passkey__msg {
  margin: 0;
  min-height: 1em;
  font-size: var(--fs-sm);
  color: var(--ink-2);
  text-align: center;
}
.auth-passkey__msg.is-error { color: var(--danger); }

/* ── Theme-matched, trackless scrollbars ─────────────────────────────────────
   Each theme defines --color-scheme (light|dark); apply it so native UI (form
   controls, default scrollbar gutter) follows the theme. The scrollbar itself
   is trackless: no painted track, just a tinted thumb drawn from theme tokens,
   so it recolors automatically across all themes. Firefox uses the standard
   scrollbar-* properties; WebKit/Blink use the ::-webkit-scrollbar pseudos. */
:root {
  color-scheme: var(--color-scheme, light);
}

/* Firefox / standard — thin thumb, transparent track */
html {
  scrollbar-width: thin;
  scrollbar-color: var(--border-strong) transparent;
}

/* WebKit / Blink — trackless: transparent track, tinted rounded thumb */
*::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}
*::-webkit-scrollbar-track,
*::-webkit-scrollbar-corner {
  background: transparent;
}
*::-webkit-scrollbar-thumb {
  background-color: var(--border-strong);
  border-radius: 999px;
  /* transparent border carves the thumb in from the edges so it floats,
     trackless, with breathing room on both sides */
  border: 2px solid transparent;
  background-clip: padding-box;
}
*::-webkit-scrollbar-thumb:hover {
  background-color: var(--ink-3);
}
