/* ==================================================================================================
   App shell & layouts — owner: design-system agent
   Markup: templates/layouts/app.html, partials/{sidebar,topbar,tabbar,user_menu,workspace_switcher}.html

   r4 «Birge OS» (spec docs/specs/04-birge-os-redesign.md §8).
   .app                    grid: sidebar | main. Modifiers: .is-rail (desktop icon rail, cookie
                           `sidebar=collapsed`), .is-drawer-open (< 1024px off-canvas sidebar open),
                           .has-tabbar (< 768px iOS-style floating tab bar is shown)
   .sidebar …              floating panel; .sidebar__header / __nav / __footer, .sidebar-search,
                           .nav-item, .nav-section, .ws-tile
   .topbar                 sticky transparent toolbar (.is-scrolled → scroll edge effect);
                           .topbar__capsule = the glass group of global tools
   .page                   main content area (padding; view-transition-name: page).
                           Modifiers via {% block page_class %}: page--flush (no padding),
                           page--full (fills the viewport height, e.g. boards)
   .tabbar                 mobile floating tab bar
   .view-tabs/.view-tab    project views: segmented control in the scope bar (.subbar)
   .project-switch         phone title menu (project views)
   .settings-layout        settings with side nav (.settings-nav / .settings-nav__item)
   .auth / .auth-card      sign-in pages · .mkt (marketing) · .status-page (errors)
   ================================================================================================== */

/* -- Skip link ------------------------------------------------------------------------------------ */
.skip-link {
  position: fixed;
  z-index: calc(var(--z-progress) + 1);
  top: calc(var(--safe-top) + 8px);
  left: 8px;
  padding: 8px 14px;
  border-radius: var(--radius-full);
  background: var(--accent);
  color: var(--text-on-accent);
  font-weight: var(--fw-semibold);
  transform: translateY(-160%);
  transition: transform var(--dur-2) var(--ease-out);
}
.skip-link:focus-visible {
  transform: none;
}

/* -- Top progress bar (htmx requests & page loads) — r4 · 8.12 ---------------------------------- */
.progress-bar {
  position: fixed;
  z-index: var(--z-progress);
  top: 0;
  left: 0;
  width: 100%;
  height: 2.5px;
  pointer-events: none;
  opacity: 0;
  transform: scaleX(var(--progress, 0));
  transform-origin: 0 50%;
  background: linear-gradient(90deg, var(--accent), var(--c-purple));
  box-shadow: 0 0 8px color-mix(in srgb, var(--accent) 50%, transparent);
  transition:
    transform 240ms var(--ease-out),
    opacity 300ms ease 120ms;
}
.progress-bar.is-active {
  opacity: 1;
  transition:
    transform 240ms var(--ease-out),
    opacity 120ms ease;
}

/* -- App grid (r4 · 8.2) ------------------------------------------------------------------------- */
html {
  background: var(--wallpaper);
  background-attachment: fixed;
}
@media (prefers-contrast: more) {
  html {
    background: var(--bg);
  }
}
.app {
  /* Re-declared here: a --sidebar-w set on .app (8.3 resize) must move the column too. */
  --sidebar-w-clamped: clamp(220px, var(--sidebar-w), 320px);
  --sidebar-col: calc(var(--sidebar-w-clamped) + 2 * var(--sidebar-inset));
  --rail-col: calc(var(--rail-w) + 2 * var(--sidebar-inset));
  min-height: 100vh;
  min-height: 100dvh;
}
.app__main {
  min-width: 0;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
}
@media (min-width: 1024px) {
  .app {
    display: grid;
    grid-template-columns: var(--sidebar-col) minmax(0, 1fr);
  }
  .app.is-rail {
    grid-template-columns: var(--rail-col) minmax(0, 1fr);
  }
  .app.is-animating {
    transition: grid-template-columns var(--dur-smooth) var(--spring-smooth);
  }
}

/* -- Sidebar (r4 · 8.3–8.4) -----------------------------------------------------------------------
   Desktop (≥ 1024px): a floating panel 8px in from the window edges (radius 18, hairline, glass rim,
   soft shadow, a 4% accent breath at the top) — macOS Tahoe. Glyphs are accent-colored; the
   selection is a neutral fill (grey when the window is inactive, 8.8). Every leading glyph sits on
   the same axis as the rail's centre, so collapsing to the rail never moves an icon.
   Tablets (768–1023px): an iPadOS slide-over glass panel from the left over a light scrim.
   Phones (< 768px): the tab bar's "Menu" opens it as a bottom sheet (grabber, inset grouped
   lists, 48px rows, 17px text); drag it down to close (app.js initSidebarSwipe). */
.sidebar {
  display: flex;
  flex-direction: column;
  min-width: 0;
  view-transition-name: sidebar;
  -webkit-user-select: none;
  user-select: none;
}
@media (min-width: 1024px) {
  .sidebar {
    position: sticky;
    top: var(--sidebar-inset);
    z-index: var(--z-sidebar);
    height: calc(100vh - 2 * var(--sidebar-inset));
    height: calc(100dvh - 2 * var(--sidebar-inset));
    margin: var(--sidebar-inset);
    overflow: hidden;
    border: 0.5px solid var(--glass-border);
    border-radius: var(--radius-panel);
    background: var(--glass-sheen), var(--mat-sidebar);
    -webkit-backdrop-filter: var(--mat-filter-strong);
    backdrop-filter: var(--mat-filter-strong);
    box-shadow: var(--glass-rim), var(--shadow-md);
  }
  .btn.sidebar__close,
  .sidebar-scrim {
    display: none;
  }
}
.sidebar__header {
  display: flex;
  align-items: center;
  gap: 4px;
  min-height: 52px;
  padding: 10px 8px 4px 10px;
}
.sidebar__nav {
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden auto;
  overscroll-behavior: contain;
  padding: 4px 8px 12px;
  scrollbar-width: none;
}
.sidebar__nav:hover {
  scrollbar-width: thin;
}
.sidebar__footer {
  padding: 6px 8px 8px;
  border-top: 0;
}
.sidebar__close {
  margin-left: auto;
}

/* Tablets & phones: off-canvas */
@media (max-width: 1023px) {
  .sidebar {
    position: fixed;
    z-index: calc(var(--z-tabbar) + 2); /* above the phone tab bar (the Menu sheet covers it) */
    top: calc(var(--safe-top) + 8px);
    bottom: 8px;
    left: calc(var(--safe-left) + 8px);
    width: min(300px, calc(100vw - 32px));
    overflow: hidden;
    border: 0.5px solid var(--glass-border);
    border-radius: var(--radius-panel);
    background: var(--glass-sheen), var(--mat-thick);
    -webkit-backdrop-filter: var(--mat-filter-strong);
    backdrop-filter: var(--mat-filter-strong);
    box-shadow: var(--glass-rim), var(--shadow-xl);
    visibility: hidden;
    transform: translateX(calc(-100% - 24px));
    transition:
      transform var(--dur-smooth) var(--spring-smooth),
      visibility 0s linear var(--dur-smooth);
  }
  .app.is-drawer-open .sidebar {
    visibility: visible;
    transform: none;
    transition:
      transform var(--dur-smooth) var(--spring-smooth),
      visibility 0s;
  }
  .app.is-dragging .sidebar {
    transform: translateX(var(--drag-x, 0px));
    transition: none;
  }
  .sidebar-scrim {
    position: fixed;
    inset: 0;
    z-index: calc(var(--z-tabbar) + 1);
    background: var(--scrim-light);
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--dur-3) ease;
  }
  .app.is-drawer-open .sidebar-scrim {
    opacity: 1;
    pointer-events: auto;
  }
  :root:has(.app.is-drawer-open) {
    overflow: hidden;
  }
  .btn.sidebar__toggle {
    display: none;
  }
  .sidebar__close {
    width: 30px;
    height: 30px;
    border-radius: var(--radius-full);
    background: var(--fill-1);
    color: var(--text-2);
  }
  .sidebar__close .icon {
    width: 16px;
    height: 16px;
  }
}
:root[data-transparency="reduced"] .sidebar {
  background: var(--bg-sidebar);
}
@media (prefers-reduced-transparency: reduce) {
  .sidebar {
    background: var(--bg-sidebar);
  }
}
@media (max-width: 767px) {
  .sidebar {
    top: auto;
    right: 0;
    bottom: 0;
    left: 0;
    width: auto;
    max-height: calc(100dvh - var(--safe-top) - 16px);
    padding-bottom: var(--safe-bottom);
    border-width: 0.5px 0 0;
    border-radius: 32px 32px 0 0;
    background: var(--bg);
    -webkit-backdrop-filter: none;
    backdrop-filter: none;
    transform: translateY(105%);
    transition:
      transform var(--dur-sheet) var(--spring-sheet),
      visibility 0s linear var(--dur-sheet);
  }
  :root[data-transparency="reduced"] .sidebar {
    background: var(--bg);
  }
  .app.is-drawer-open .sidebar {
    transform: none;
    transition:
      transform var(--dur-sheet) var(--spring-sheet),
      visibility 0s;
  }
  .app.is-dragging .sidebar {
    transform: translateY(var(--drag-y, 0px));
    transition: none;
  }
  .sidebar::before {
    /* grabber */
    content: "";
    position: absolute;
    z-index: 1;
    top: 6px;
    left: 50%;
    width: 36px;
    height: 5px;
    margin-left: -18px;
    border-radius: 3px;
    background: var(--fill-3);
    pointer-events: none;
  }
  .sidebar-scrim {
    background: var(--scrim);
  }
  .sidebar__header {
    padding: 18px 12px 8px 16px;
    touch-action: none; /* the drag-down handle (app.js) */
  }
  .sidebar__nav {
    padding: 4px 16px 16px;
  }
  .sidebar .nav-list {
    overflow: hidden;
    border-radius: var(--radius-card);
    background: var(--surface);
    gap: 0;
  }
  .sidebar .nav-list > li + li .nav-item::before {
    /* iOS separator: starts after the glyph */
    content: "";
    position: absolute;
    top: 0;
    right: 0;
    left: 50px;
    height: 0.5px;
    background: var(--line);
  }
  .sidebar .nav-item {
    min-height: 48px;
    padding: 0 16px;
    gap: 14px;
    border-radius: 0;
    font-size: var(--type-body);
    font-weight: var(--fw-regular);
  }
  .sidebar .nav-item > .icon {
    width: 20px;
    height: 20px;
  }
  .sidebar .nav-item.is-active {
    background: var(--fill-1);
  }
  .sidebar .nav-item--entity .icon-tile {
    --tile: 22px;
    --size: 22px;
  }
  .sidebar .nav-item__trail,
  .sidebar .nav-badge .badge {
    font-size: var(--type-subhead);
  }
  .sidebar .nav-section {
    margin-top: 0;
  }
  .sidebar .nav-section__header {
    height: auto;
    padding: 18px 16px 6px;
  }
  .sidebar .nav-section__title {
    font-size: var(--type-footnote);
    font-weight: var(--fw-regular);
    text-transform: none;
  }
  .sidebar .nav-section__toggle {
    height: auto;
  }
  .sidebar .nav-section__toggle .icon {
    opacity: 1;
  }
  .sidebar .nav-section__empty {
    padding: 12px 16px;
    border-radius: var(--radius-card);
    background: var(--surface);
    font-size: var(--type-subhead);
  }
  .sidebar__footer {
    padding: 0 16px 12px;
  }
  .sidebar .user-button {
    min-height: 56px;
    padding: 8px 14px;
    border-radius: var(--radius-card);
    background: var(--surface);
  }
}

/* Brand (sidebar without workspace, auth & marketing headers) */
.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  font-family: var(--font-display);
  font-size: var(--fs-xl);
  font-weight: var(--fw-bold);
  letter-spacing: var(--tracking-snug);
  color: var(--text);
}
.brand__mark {
  width: 32px;
  height: 32px;
  flex-shrink: 0;
}
.sidebar .brand {
  flex: 1;
  padding: 0 6px;
}
.sidebar .brand__mark {
  width: 28px;
  height: 28px;
}

/* Workspace tile (app-icon squircle, r4 · 6.3) & switcher. Size: --size (or --tile). */
.ws-tile {
  --size: var(--tile, 32px);
  display: inline-grid;
  place-items: center;
  flex-shrink: 0;
  width: var(--size);
  height: var(--size);
  overflow: hidden;
  border-radius: calc(var(--size) * 0.25);
  background: var(--tone-gradient);
  color: var(--tone-on);
  font-size: calc(var(--size) * 0.4);
  font-weight: var(--fw-bold);
  letter-spacing: 0;
  line-height: 1;
  box-shadow:
    inset 0 0.5px 0 rgb(255 255 255 / 0.35),
    inset 0 0 0 0.5px rgb(0 0 0 / 0.06),
    0 1px 2px rgb(0 0 0 / 0.12);
}
.ws-tile img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.ws-tile--sm {
  --size: 22px;
}
.ws-tile--lg {
  --size: 44px;
}
.ws-switcher {
  flex: 1 1 auto;
  min-width: 0;
}
.ws-switcher__button {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-width: 0;
  height: 44px;
  padding: 0 8px 0 6px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  text-align: left;
  transition:
    background-color var(--dur-1) ease,
    transform var(--dur-snappy) var(--spring-snappy);
}
.ws-switcher__button .ws-tile {
  --size: 28px;
}
.ws-switcher__button:hover,
.ws-switcher__button[aria-expanded="true"] {
  background: var(--sidebar-hover);
}
.ws-switcher__button:active {
  transform: scale(0.98);
}
.ws-switcher__text {
  display: flex;
  flex: 1;
  flex-direction: column;
  min-width: 0;
  line-height: 1.2;
}
.ws-switcher__name {
  overflow: hidden;
  font-size: var(--fs-md);
  font-weight: var(--fw-semibold);
  text-overflow: ellipsis;
  white-space: nowrap;
}
.ws-switcher__meta {
  overflow: hidden;
  color: var(--text-3);
  font-size: var(--fs-xs);
  text-overflow: ellipsis;
  white-space: nowrap;
}
.ws-switcher__chevron {
  color: var(--text-3);
}

/* Search field (opens Spotlight, ⌘K) — desktop; tablets/phones search from the toolbar. */
.sidebar-search {
  position: relative;
  display: flex;
  flex-shrink: 0;
  align-items: center;
  gap: 8px;
  height: 30px;
  margin: 4px 8px 6px;
  padding: 0 6px 0 14px; /* glyph on the rail's centre axis (see .nav-item) */
  border: 0;
  border-radius: var(--radius-sm);
  background: var(--fill-1);
  color: var(--text-3-on-fill);
  font-size: var(--fs-md);
  text-align: left;
  transition: background-color var(--dur-1) ease;
}
.sidebar-search:hover {
  background: var(--fill-2);
}
.sidebar-search > .icon {
  flex-shrink: 0;
}
.sidebar-search__label {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.sidebar-search .kbd {
  margin-left: auto;
}
@media (max-width: 1023px) {
  .sidebar-search {
    display: none;
  }
}

/* Navigation rows */
.nav-list {
  display: grid;
  /* minmax(0, 1fr): long labels (ky/ru, text size XL) ellipsize instead of widening the column */
  grid-template-columns: minmax(0, 1fr);
  gap: 1px;
  margin: 0;
  padding: 0;
  list-style: none;
}
.nav-item {
  position: relative;
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-width: 0;
  min-height: var(--row-h);
  /* 13px (not 10): glyphs sit on the rail's centre axis, so nothing jumps when it collapses */
  padding: 0 10px 0 13px;
  border: 0;
  border-radius: 10px; /* 18 − 8 (concentric) */
  background: transparent;
  color: var(--text);
  font-size: var(--fs-md);
  font-weight: var(--fw-medium);
  text-align: left;
  white-space: nowrap;
  cursor: default;
  transition: background-color var(--dur-1) ease;
}
.nav-item:has(> .icon-tile) {
  padding-left: 12px;
}
.nav-item > .icon {
  --icon-stroke: 1.9;
  width: 18px;
  height: 18px;
  color: var(--sidebar-icon);
  transition:
    color var(--dur-2) ease,
    transform var(--dur-snappy) var(--spring-snappy);
}
.nav-item:hover {
  background: var(--sidebar-hover);
}
.nav-item:active,
.nav-item.is-active {
  background: var(--sidebar-selection);
}
/* Inside a starred project both "Projects" and the favorite match: the favorite carries the
   state, "Projects" keeps only its glyph fill. */
.sidebar__nav:has(.nav-item--entity.is-active) .nav-item.is-active:not(.nav-item--entity) {
  background: transparent;
}
.sidebar__nav:has(.nav-item--entity.is-active) .nav-item.is-active:not(.nav-item--entity):hover {
  background: var(--sidebar-hover);
}
.nav-item__label {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.nav-item__trail {
  display: inline-flex;
  align-items: center;
  margin-left: auto;
  color: var(--text-3);
  font-size: var(--fs-sm);
  font-variant-numeric: tabular-nums;
}
.nav-item .icon-tile,
.nav-item--entity .icon-tile {
  --tile: 20px;
  --size: 20px;
}
.nav-badge:not(:has(.badge)) {
  display: none;
}
/* Counters: a plain grey number (macOS Mail), not a badge. */
.nav-badge .badge {
  min-width: 0;
  height: auto;
  padding: 0;
  background: none;
  color: var(--text-3);
  font-size: var(--fs-sm);
  font-weight: var(--fw-medium);
  box-shadow: none;
  animation: none;
}

/* Sections */
.nav-section {
  margin-top: 14px;
}
.nav-section__header {
  display: flex;
  align-items: center;
  gap: 4px;
  height: 24px;
  padding: 0 6px 0 13px;
}
.nav-section__title {
  min-width: 0;
  overflow: hidden;
  color: var(--text-3);
  font-size: var(--fs-xs);
  font-weight: var(--fw-semibold);
  letter-spacing: 0.005em;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.nav-section__toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  width: 100%;
  min-width: 0;
  height: 24px;
  padding: 0;
  border: 0;
  border-radius: 6px;
  background: none;
  color: inherit;
  cursor: default;
}
.nav-section__toggle .icon {
  flex-shrink: 0;
  color: var(--text-3);
  opacity: 0;
  transition:
    opacity var(--dur-2) ease,
    transform var(--dur-snappy) var(--spring-snappy);
}
.nav-section:hover .nav-section__toggle .icon,
.nav-section__toggle:focus-visible .icon {
  opacity: 1;
}
.nav-section__toggle[aria-expanded="false"] .icon {
  transform: rotate(-90deg);
}

@media (hover: none) {
  .nav-section__toggle .icon {
    opacity: 1;
  }
}
.nav-section__empty {
  padding: 4px 10px 6px 13px;
  color: var(--text-3);
  font-size: var(--fs-sm);
  line-height: 1.4;
  text-wrap: pretty;
}
.nav-section__body[hidden] {
  display: none;
}
@media (prefers-reduced-motion: no-preference) {
  .nav-section__body:not([hidden]) {
    animation: nav-section-in var(--dur-3) var(--ease-out);
  }
}
@keyframes nav-section-in {
  from {
    opacity: 0;
    transform: translateY(-4px);
  }
}

/* Appearance row (sidebar footer) — only off-canvas (< 1024px: tablets, the phone Menu sheet), so
   the theme is one tap away there. Desktops switch it in the toolbar capsule. */
.sidebar-appearance {
  display: none;
}
@media (max-width: 1023px) {
  .sidebar-appearance {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin: 0 0 8px;
    padding: 2px 2px 8px;
  }
}
.sidebar-appearance__title {
  padding-inline: 8px;
  color: var(--text-3);
  font-size: var(--fs-xs);
  font-weight: var(--fw-semibold);
}
.sidebar-appearance__control .segmented__item {
  height: 34px;
}
@media (pointer: coarse) {
  .sidebar-appearance__control .segmented__item {
    height: 38px;
  }
}
@media (max-width: 767px) {
  .sidebar-appearance {
    padding: 0 0 4px;
  }
  .sidebar-appearance__title {
    padding: 8px 16px 2px;
    font-size: var(--type-footnote);
    font-weight: var(--fw-regular);
  }
}

/* User menu button (sidebar footer) */
.user-button {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-width: 0;
  min-height: 44px;
  padding: 6px 8px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  text-align: left;
  transition:
    background-color var(--dur-1) ease,
    transform var(--dur-snappy) var(--spring-snappy);
}
.user-button:hover,
.user-button[aria-expanded="true"] {
  background: var(--sidebar-hover);
}
.user-button:active {
  transform: scale(0.98);
}
.user-button__text {
  display: flex;
  flex: 1;
  flex-direction: column;
  min-width: 0;
  line-height: 1.25;
}
.user-button__name {
  overflow: hidden;
  font-size: var(--fs-md);
  font-weight: var(--fw-semibold);
  text-overflow: ellipsis;
  white-space: nowrap;
}
.user-button__email {
  overflow: hidden;
  color: var(--text-3);
  font-size: var(--fs-xs);
  text-overflow: ellipsis;
  white-space: nowrap;
}
.user-button > .icon {
  color: var(--text-3);
}

/* Rail mode (desktop only, cookie sidebar=collapsed) — icons only, labels become tooltips. Every
   glyph keeps the x it has in the expanded panel (the rail's centre axis), so the collapse has no
   jumps: the column animates, labels fade, icons stay put. */
@media (min-width: 1024px) {
  .app.is-rail .sidebar__header {
    flex-direction: column;
    align-items: flex-start;
    gap: 6px;
  }
  .app.is-rail .sidebar__toggle {
    margin-left: 6px;
  }
  .app.is-rail .ws-switcher {
    flex: 0 0 auto;
  }
  .app.is-rail .ws-switcher__button,
  .app.is-rail .user-button {
    width: 44px;
  }
  .app.is-rail .sidebar-search {
    justify-content: center;
    width: 44px;
    margin-inline: 8px;
    padding: 0;
  }
  .app.is-rail .sidebar-search :is(.sidebar-search__label, .kbd) {
    display: none;
  }
  .app.is-rail .ws-switcher__text,
  .app.is-rail .ws-switcher__chevron,
  .app.is-rail .user-button__text,
  .app.is-rail .user-button > .icon,
  .app.is-rail .brand__text,
  .app.is-rail .nav-section__header,
  .app.is-rail .nav-section__empty,
  .app.is-rail .nav-item__trail:not(.nav-badge),
  .app.is-rail .nav-item__label {
    display: none;
    opacity: 0;
  }
  .app.is-rail .nav-item {
    width: 44px;
  }
  /* Dock-like magnification */
  .app.is-rail .nav-item:hover > .icon {
    transform: scale(1.14);
  }
  .app.is-rail .nav-item--entity .icon-tile {
    --tile: 24px;
    --size: 24px;
  }
  .app.is-rail .nav-item:has(> .icon-tile) {
    padding-left: 10px;
  }
  .app.is-rail .nav-section {
    margin-top: 10px;
    padding-top: 10px;
    border-top: 0.5px solid var(--line);
  }
  .app.is-rail .nav-section__body[hidden] {
    display: block;
  }
  .app.is-rail .nav-badge {
    position: absolute;
    top: 4px;
    right: 6px;
  }
  .app.is-rail .nav-badge .badge {
    min-width: 8px;
    width: 8px;
    height: 8px;
    padding: 0;
    border-radius: 50%;
    background: var(--danger-solid);
    font-size: 0;
    box-shadow: 0 0 0 2px var(--bg-sidebar);
  }
  .app.is-rail .nav-badge .badge--accent {
    background: var(--accent);
  }
  .app.is-rail .sidebar__toggle .icon {
    transform: scaleX(-1);
  }
  /* Rail tooltips: CSS-only, to the right of the item. The nav must not clip them. */
  .app.is-rail .sidebar,
  .app.is-rail .sidebar__nav {
    overflow: visible;
  }
  .app.is-rail [data-rail-tooltip]::after {
    content: attr(data-rail-tooltip);
    position: absolute;
    z-index: var(--z-tooltip);
    top: 50%;
    left: calc(100% + 12px);
    padding: 5px 9px;
    border-radius: 7px;
    background: var(--tooltip-bg);
    color: var(--tooltip-fg);
    font-size: var(--fs-xs);
    font-weight: var(--fw-medium);
    line-height: 1.3;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    translate: -4px -50%;
    transition:
      opacity var(--dur-1) ease,
      translate var(--dur-1) ease;
  }
  .app.is-rail [data-rail-tooltip]:hover::after,
  .app.is-rail [data-rail-tooltip]:focus-visible::after {
    opacity: 1;
    translate: 0 -50%;
    transition-delay: 150ms;
  }
  .app.is-animating .sidebar,
  .app.is-animating .sidebar__nav {
    overflow: hidden;
  }
  .app.is-animating [data-rail-tooltip]::after {
    display: none;
  }
}
@media (min-width: 1024px) and (prefers-reduced-motion: no-preference) {
  /* While the sidebar collapses/expands (.is-animating, set by App.sidebar for --dur-smooth): labels
     fade out before the column narrows and back in once it has room. Never on page load. */
  .app.is-animating .sidebar :is(.nav-item__label, .ws-switcher__text, .ws-switcher__chevron, .user-button__text, .user-button > .icon, .nav-section__header, .nav-section__empty, .nav-item__trail:not(.nav-badge), .brand__text, .sidebar-search__label, .sidebar-search .kbd) {
    transition:
      opacity var(--dur-2) var(--ease-out) 110ms,
      display var(--dur-2) allow-discrete 110ms;
  }
  .app.is-animating.is-rail .sidebar :is(.nav-item__label, .ws-switcher__text, .ws-switcher__chevron, .user-button__text, .user-button > .icon, .nav-section__header, .nav-section__empty, .nav-item__trail:not(.nav-badge), .brand__text, .sidebar-search__label, .sidebar-search .kbd) {
    transition:
      opacity var(--dur-1) ease,
      display var(--dur-1) allow-discrete;
  }
  @starting-style {
    .app.is-animating:not(.is-rail) .sidebar :is(.nav-item__label, .ws-switcher__text, .ws-switcher__chevron, .user-button__text, .user-button > .icon, .nav-section__header, .nav-section__empty, .nav-item__trail:not(.nav-badge), .brand__text, .sidebar-search__label, .sidebar-search .kbd) {
      opacity: 0;
    }
  }
}
@media (min-width: 1024px) and (max-height: 640px) {
  .app.is-rail .sidebar__nav {
    overflow-y: auto;
  }
}

/* -- Toolbar (.topbar) — r4 · 8.5 / 8.7 ------------------------------------------------------------
   Transparent: the content's background shows through. Once content scrolls underneath
   (.is-scrolled, app.js) a scroll edge effect fades in — blur + a gradient into the background,
   no hairline. The header is a size container (`app-topbar`), so its parts adapt to the width the
   main column really has (sidebar expanded, rail or off-canvas), not to the viewport.
   Row: [☰ tablets] [title_prefix · breadcrumbs › title · title_suffix] [page actions · glass
   capsule (⌕ < 1024px · theme · chat (tablets) · bell) · New task].
   Large titles: .has-large-title (app.js) hides the small title until the page's
   .page-header__title with the same text scrolls under the bar (.is-condensed), like iOS. */
.topbar {
  position: sticky;
  top: 0;
  z-index: var(--z-sticky);
  padding-top: var(--safe-top);
  isolation: isolate;
  container: app-topbar / inline-size;
  -webkit-user-select: none;
  user-select: none;
}
.topbar::before {
  /* scroll edge effect */
  content: "";
  position: absolute;
  z-index: -1;
  inset: 0 0 -18px;
  background: linear-gradient(
    to bottom,
    color-mix(in srgb, var(--bg) 78%, transparent) 0%,
    color-mix(in srgb, var(--bg) 56%, transparent) 55%,
    transparent 100%
  );
  -webkit-backdrop-filter: blur(12px) saturate(160%);
  backdrop-filter: blur(12px) saturate(160%);
  -webkit-mask-image: linear-gradient(to bottom, #000 0%, #000 60%, transparent 100%);
  mask-image: linear-gradient(to bottom, #000 0%, #000 60%, transparent 100%);
  opacity: 0;
  transition: opacity var(--dur-2) ease;
  pointer-events: none;
}
.topbar.is-scrolled::before {
  opacity: 1;
}
:root[data-transparency="reduced"] .topbar::before {
  -webkit-backdrop-filter: none;
  backdrop-filter: none;
  background: var(--bg);
  -webkit-mask-image: none;
  mask-image: none;
  box-shadow: 0 0.5px 0 var(--line);
  inset: 0;
}
@media (prefers-reduced-transparency: reduce) {
  .topbar::before {
    background: var(--bg);
    -webkit-mask-image: none;
    mask-image: none;
    box-shadow: 0 0.5px 0 var(--line);
    inset: 0;
  }
}
.topbar__row {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  height: var(--topbar-h);
  padding: 0 max(var(--page-pad-x), var(--safe-right)) 0 max(var(--page-pad-x), var(--safe-left));
}
.topbar__menu {
  margin-left: -6px;
}
.topbar__heading {
  display: flex;
  flex: 1 1 auto;
  align-items: center;
  gap: 10px;
  min-width: 0;
}
.topbar__titles {
  display: flex;
  flex: 0 1 auto;
  align-items: center;
  gap: 6px;
  min-width: 0;
}
.topbar__title {
  min-width: 0;
  overflow: hidden;
  font-family: var(--font-sans);
  font-size: var(--type-title3);
  font-weight: var(--fw-semibold);
  letter-spacing: var(--tracking-snug);
  text-overflow: ellipsis;
  white-space: nowrap;
  transition:
    opacity var(--dur-2) ease,
    translate var(--dur-2) ease;
}
.topbar__title:empty {
  display: none;
}
.topbar.has-large-title:not(.is-condensed) .topbar__title {
  opacity: 0;
  translate: 0 4px;
  pointer-events: none;
}
.topbar.has-large-title:not(.is-condensed) .topbar__titles > .breadcrumbs::after {
  opacity: 0;
}
.topbar__actions {
  display: flex;
  flex-shrink: 0;
  align-items: center;
  gap: 8px;
}
.topbar__page-actions {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}
.topbar__tools {
  display: flex;
  align-items: center;
  gap: 8px;
}
.topbar__page-actions:not(:has(*)),
.topbar__tools:not(:has(*)) {
  display: none;
}
/* Labelled page actions that may collapse — .btn--collapsible: icon + .btn__label, an aria-label
   and a data-tooltip with the same text. Below 960px of toolbar they turn into icon buttons so the
   heading keeps its room; the tooltip only shows while the label is hidden. */
.topbar__page-actions .btn--collapsible[data-tooltip]::after {
  display: none;
}
@container app-topbar (max-width: 959px) {
  .topbar__page-actions .btn--collapsible {
    width: var(--control-h);
    padding: 0;
  }
  .topbar__page-actions .btn--collapsible > .btn__label {
    display: none;
  }
  .topbar__page-actions .btn--collapsible[data-tooltip]::after {
    display: block;
  }
}

/* The glass capsule of global tools: 32px round icon buttons. */
.topbar__capsule:not(:has(> :not([hidden]))) {
  display: none;
}
.topbar__capsule > * {
  flex-shrink: 0;
}
.topbar__capsule :is(.search-trigger, .btn--icon, .theme-toggle, .notif-bell__button) {
  display: inline-grid;
  place-items: center;
  width: 32px;
  height: 32px;
  min-width: 0;
  padding: 0;
  border: 0;
  border-radius: var(--radius-full);
  background: none;
  box-shadow: none;
  color: var(--text-2);
}
.topbar__capsule :is(.search-trigger, .btn--icon, .theme-toggle, .notif-bell__button):hover {
  background: var(--fill-1);
  color: var(--text);
}
.topbar__capsule :is(.search-trigger, .btn--icon, .theme-toggle, .notif-bell__button) > * {
  grid-area: 1 / 1; /* glyph + badge holder share the one cell */
}
.topbar__capsule :is(.notif-bell__badge, .topbar__chat-badge) .badge {
  top: -3px;
  right: -4px;
}
.topbar__capsule :is(.search-trigger, .btn--icon, .notif-bell__button) > .icon {
  --icon-stroke: 1.9;
  width: 18px;
  height: 18px;
}
.topbar__capsule .search-trigger :is(.search-trigger__label, .kbd) {
  display: none;
}
@media (min-width: 1024px) {
  .topbar__capsule .search-trigger {
    display: none; /* desktops search from the sidebar (8.3) */
  }
}
/* Tablets (768–1023px, partials/topbar_chat.html): Chat with the live unread badge next to the
   bell — the off-canvas sidebar and the phone tab bar are both out of view there. */
.topbar__chat {
  position: relative;
}
.topbar__chat-badge .badge {
  position: absolute;
  top: -1px;
  right: -3px;
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  box-shadow: 0 0 0 2px var(--bg);
  font-size: 10px;
  pointer-events: none;
}
.topbar__new {
  height: 36px;
  padding: 0 16px 0 12px;
}
.topbar__new .btn__label {
  white-space: nowrap;
}
@container app-topbar (max-width: 560px) {
  .topbar__new .btn__label {
    display: none;
  }
  .topbar__new {
    width: 36px;
    padding: 0;
  }
}
@media (min-width: 1024px) {
  .btn.topbar__menu {
    display: none;
  }
}

/* Breadcrumbs: plain links/spans inside {% block breadcrumbs %}; separators are automatic. A quiet
   13px trail before the title; crumbs keep their size (up to 220px each, then "…") — the title
   gives way first; narrow toolbars drop the leading crumbs. Pages whose title is a short key (a
   task's "WEB-12") put .topbar--crumbs-first on the topbar: there the crumbs give way instead. */
.breadcrumbs {
  display: flex;
  flex-shrink: 0;
  align-items: center;
  min-width: 0;
  max-width: 100%;
  color: var(--text-3);
  font-size: var(--fs-sm);
  font-weight: var(--fw-medium);
  white-space: nowrap;
}
.breadcrumbs:not(:has(*)) {
  display: none;
}
/* Block boxes (not flex) so text-overflow can draw the "…"; the separator is an inline-block. */
.breadcrumbs > * {
  display: block;
  min-width: 0;
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
}
.breadcrumbs > .breadcrumbs__key {
  flex-shrink: 0;
}
.breadcrumbs > a {
  border-radius: 6px;
  transition: color var(--dur-1) ease;
}
.breadcrumbs > a:hover {
  color: var(--text);
}
.breadcrumbs > * + *::before,
.topbar__titles > .breadcrumbs:has(*)::after {
  content: "";
  flex-shrink: 0;
  width: 12px;
  height: 12px;
  margin-inline: 3px;
  background: var(--text-3);
  -webkit-mask: var(--chevron-mask) center / contain no-repeat;
  mask: var(--chevron-mask) center / contain no-repeat;
  transition: opacity var(--dur-2) ease;
}
.breadcrumbs > * + *::before {
  display: inline-block;
  vertical-align: -0.1em;
}
@media (min-width: 768px) {
  @container app-topbar (max-width: 699px) {
    .breadcrumbs > :not(:last-child),
    .breadcrumbs > * + *::before {
      display: none;
    }
  }
}
.topbar--crumbs-first .breadcrumbs {
  flex-shrink: 1;
}
.topbar--crumbs-first .topbar__titles > .topbar__title {
  flex-shrink: 0;
}
@media (min-width: 768px) {
  @container app-topbar (max-width: 959px) {
    .topbar--crumbs-first .breadcrumbs > :first-child:not(:last-child),
    .topbar--crumbs-first .breadcrumbs > :first-child:not(:last-child) + *::before {
      display: none;
    }
  }
  @container app-topbar (max-width: 819px) {
    .topbar--crumbs-first .topbar__new {
      width: 36px;
      padding: 0;
    }
    .topbar--crumbs-first .topbar__new .btn__label {
      display: none;
    }
  }
}

/* Search trigger outside the capsule (legacy placements): a compact round icon button. */
.search-trigger {
  display: inline-flex;
  flex-shrink: 0;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: var(--control-h);
  min-width: var(--control-h);
  padding: 0;
  border: 0;
  border-radius: var(--radius-full);
  background: transparent;
  color: var(--text-2);
  font-size: var(--fs-sm);
  transition:
    background-color var(--dur-1) ease,
    color var(--dur-1) ease,
    transform var(--dur-snappy) var(--spring-snappy);
}
.search-trigger:hover {
  background: var(--fill-1);
  color: var(--text);
}
.search-trigger:active {
  transform: scale(0.94);
}
.search-trigger > .icon {
  flex-shrink: 0;
}
.search-trigger__label,
.search-trigger .kbd {
  display: none;
}

/* Phones: the iOS navigation bar (44px + safe area) — back capsule, ≤ 2 round glass buttons. */
@media (max-width: 767px) {
  .topbar__row {
    gap: 8px;
  }
  .topbar .btn--icon,
  .topbar__capsule .search-trigger {
    width: 36px;
    height: 36px;
    border-radius: var(--radius-full);
    background: var(--glass-sheen), var(--mat-thin);
    -webkit-backdrop-filter: var(--mat-filter);
    backdrop-filter: var(--mat-filter);
    box-shadow: var(--glass-rim), var(--shadow-sm);
  }
  .topbar__capsule {
    gap: 8px;
    height: auto;
    padding: 0;
    background: none;
    border: 0;
    box-shadow: none;
    -webkit-backdrop-filter: none;
    backdrop-filter: none;
  }
  .app.has-tabbar .topbar__menu,
  .app.has-tabbar .topbar__new,
  .app.has-tabbar .topbar__theme {
    display: none;
  }
  .topbar__title {
    font-size: var(--type-headline);
  }
  /* Breadcrumbs collapse into the iOS back button: ‹ + the parent page's title (last crumb). */
  .breadcrumbs > :not(:last-child) {
    display: none;
  }
  .topbar__titles > .breadcrumbs:has(*)::after {
    display: none;
  }
  .breadcrumbs > :last-child {
    position: relative;
    display: block;
    flex-shrink: 1;
    max-width: 40vw;
    height: 36px;
    margin-left: -4px;
    padding: 0 12px 0 28px;
    border-radius: var(--radius-full);
    background: var(--glass-sheen), var(--mat-thin);
    -webkit-backdrop-filter: var(--mat-filter);
    backdrop-filter: var(--mat-filter);
    box-shadow: var(--glass-rim), var(--shadow-sm);
    color: var(--accent-ink);
    font-size: var(--type-body);
    font-weight: var(--fw-regular);
    line-height: 36px;
  }
  .breadcrumbs > :last-child::before {
    content: "";
    position: absolute;
    top: 8px;
    left: 6px;
    display: block;
    width: 20px;
    height: 20px;
    margin: 0;
    background: var(--accent);
    -webkit-mask: var(--chevron-left-mask) center / contain no-repeat;
    mask: var(--chevron-left-mask) center / contain no-repeat;
  }
  .breadcrumbs > a:last-child:active {
    opacity: 0.6;
  }
  /* Once the large title is gone and the small one shows, the back button keeps only its chevron. */
  .topbar.is-condensed .breadcrumbs > :last-child,
  .topbar:not(.has-large-title):has(.topbar__title:not(:empty)) .breadcrumbs > :last-child {
    width: 36px;
    padding: 0;
    font-size: 0;
  }
}

/* -- Page (r4 · 8.11) ------------------------------------------------------------------------------ */
.page {
  flex: 1 0 auto;
  min-width: 0;
  padding: var(--page-pad-y) max(var(--page-pad-x), var(--safe-right)) calc(var(--page-pad-y) + var(--safe-bottom) + 24px) max(var(--page-pad-x), var(--safe-left));
  view-transition-name: page;
}
.page:focus {
  outline: none;
}
.page--flush {
  padding: 0;
}
.page--full {
  display: flex;
  flex-direction: column;
  min-height: 0;
}

/* Page header inside content (the large title) */
.page-header {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px 16px;
  margin-bottom: 20px;
}
.page-header__text {
  flex: 1 1 280px;
  min-width: 0;
}
.page-header__title {
  font-family: var(--font-display);
  font-size: var(--type-large);
  font-weight: var(--fw-bold);
  line-height: 1.12;
  letter-spacing: var(--tracking-tight);
  text-wrap: balance;
}
.page-header__subtitle {
  margin-top: 4px;
  color: var(--text-2);
  font-size: var(--type-subhead);
  text-wrap: pretty;
}
.page-header__actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}
@media (max-width: 767px) {
  .page-header {
    margin-top: -4px;
    margin-bottom: 16px;
  }
  .page-header__actions {
    width: 100%;
  }
}
.section-header {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  margin-bottom: var(--space-3);
}
.section-header__title {
  flex: 1;
  min-width: 0;
  font-size: var(--type-title3);
  font-weight: var(--fw-semibold);
  letter-spacing: var(--tracking-snug);
}

/* -- Tab bar — iOS 26 (phones, r4 · 8.9) -----------------------------------------------------------
   A floating glass capsule (Home · My tasks · Chat · Inbox · Menu) with a grey selection lens that
   slides between tabs, plus a separate accent "+" circle. Shrinks while scrolling down (app.js). */
.tabbar {
  display: none;
}
@media (max-width: 767px) {
  .tabbar {
    position: fixed;
    z-index: var(--z-tabbar);
    right: max(12px, var(--safe-right));
    bottom: max(8px, calc(var(--safe-bottom) - 8px));
    left: max(12px, var(--safe-left));
    display: flex;
    align-items: center;
    gap: 10px;
    pointer-events: none;
    view-transition-name: tabbar;
    -webkit-user-select: none;
    user-select: none;
  }
  .tabbar__capsule {
    --tab-count: 5;
    position: relative;
    flex: 1 1 auto;
    display: grid;
    grid-template-columns: repeat(var(--tab-count), minmax(0, 1fr));
    min-width: 0;
    height: var(--tabbar-h);
    padding: 4px;
    border: 0.5px solid var(--glass-border);
    border-radius: var(--radius-full);
    background: var(--glass-sheen), var(--mat-chrome);
    -webkit-backdrop-filter: var(--mat-filter-strong);
    backdrop-filter: var(--mat-filter-strong);
    box-shadow: var(--glass-rim), var(--shadow-lg);
    pointer-events: auto;
    transform-origin: 50% 100%;
    transition: transform var(--dur-smooth) var(--spring-smooth);
  }
  :root[data-transparency="reduced"] .tabbar__capsule {
    background: var(--surface-elevated);
  }
  .tabbar__pill {
    position: absolute;
    top: 4px;
    bottom: 4px;
    left: 4px;
    width: calc((100% - 8px) / var(--tab-count));
    border-radius: var(--radius-full);
    background: var(--fill-2);
    opacity: 0;
    transform: translateX(calc(var(--tab-index, 0) * 100%));
    transition:
      transform var(--dur-snappy) var(--spring-snappy),
      opacity var(--dur-2) ease;
    view-transition-name: tabbar-pill;
  }
  .tabbar.has-active .tabbar__pill {
    opacity: 1;
  }
  .tabbar__item {
    position: relative;
    z-index: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    min-width: 0;
    height: 100%;
    padding: 0 2px;
    border: 0;
    border-radius: var(--radius-full);
    background: none;
    color: var(--text-2);
    font-size: var(--type-caption2);
    font-weight: var(--fw-semibold);
    -webkit-tap-highlight-color: transparent;
  }
  .tabbar__item .icon {
    --icon-stroke: 1.9;
    transition: transform var(--dur-snappy) var(--spring-snappy);
  }
  .tabbar__item:active .icon {
    transform: scale(0.88);
  }
  .tabbar__item.is-active {
    color: var(--accent);
  }
  .tabbar__label {
    max-width: 100%;
    letter-spacing: -0.01em;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    transition: opacity var(--dur-2) ease;
  }
  /* The holder (may be empty or hold "\n") only places the badge; the capsule is the inner .badge
     (syncBadges / chat.js write <span class="badge">N</span>). */
  .tabbar__badge {
    position: absolute;
    top: 5px;
    left: calc(50% + 5px);
    line-height: 0;
  }
  .tabbar__badge .badge {
    display: inline-block;
    min-width: 18px;
    height: 18px;
    padding: 0 5px;
    border-radius: var(--radius-full);
    background: var(--badge-bg);
    color: var(--text-on-accent);
    font-size: 11px;
    font-weight: var(--fw-semibold);
    line-height: 18px;
    text-align: center;
    font-variant-numeric: tabular-nums;
    box-shadow: 0 0 0 2px var(--surface);
  }
  .tabbar__create {
    flex: 0 0 auto;
    display: grid;
    place-items: center;
    width: var(--tabbar-h);
    height: var(--tabbar-h);
    border: 0;
    border-radius: var(--radius-full);
    background: linear-gradient(180deg, color-mix(in oklab, var(--accent) 86%, white), var(--accent));
    color: var(--text-on-accent);
    box-shadow:
      inset 0 0.5px 0 rgb(255 255 255 / 0.35),
      var(--shadow-accent),
      var(--shadow-md);
    pointer-events: auto;
    -webkit-tap-highlight-color: transparent;
    transition: transform var(--dur-snappy) var(--spring-snappy);
  }
  .tabbar__create:active {
    transform: scale(0.9);
  }
  /* Scrolling down: the bar shrinks */
  .tabbar.is-minimized .tabbar__capsule {
    transform: translateY(8px) scale(0.9);
  }
  .tabbar.is-minimized .tabbar__label {
    opacity: 0;
  }
  .tabbar.is-minimized .tabbar__item .icon {
    transform: translateY(7px);
  }
  .tabbar.is-minimized .tabbar__create {
    transform: translateY(8px) scale(0.84);
  }
  .app.has-tabbar .page {
    padding-bottom: calc(var(--tabbar-h) + max(var(--safe-bottom), 8px) + 32px);
  }
}
@media (max-width: 374px) {
  /* Small phones: long ky/ru labels ("Иштерим", "Кабарлар") still fit. */
  .tabbar {
    gap: 8px;
  }
  .tabbar__item {
    padding: 0;
  }
  .tabbar__label {
    font-size: 10px;
    letter-spacing: -0.02em;
  }
}

/* -- Project layout (r4 · 8.6): identity + project tools in the toolbar, the scope bar under it ------
   Row 1 (layouts/project.html): tile · Projects › name · key · ★ · status · members · "…"  ⟷
   capsule (⌕ < 1024 · theme · bell) · New task. Row 2 (.subbar = scope bar): the views as a
   segmented control + the view's toolbar on the right. What gives way as the toolbar narrows
   (container app-topbar, ≥ 768px): breadcrumb < 1100px → key chip + members < 940px (Members stays
   in the "…" menu) → New task label < 820px. The title keeps the rest and is the last thing to
   truncate (app.js adds a tooltip then). Phones: the title becomes a menu of the views
   (.project-switch) and the segmented control hides. */
.project-ident {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}
.project-ident__meta {
  display: flex;
  flex-shrink: 0;
  align-items: center;
  gap: 6px;
}
.project-ident__tools {
  display: flex;
  flex-shrink: 0;
  align-items: center;
  gap: 2px;
}
.app .topbar--project .topbar__titles {
  flex: 0 1 auto;
}
.app .topbar--project .breadcrumbs {
  flex-shrink: 0;
}
.app .topbar--project .topbar__title {
  flex-shrink: 1;
  min-width: 6ch;
}
.app .topbar--project .project-menu__members {
  display: flex;
}
.project-ident__tools .project-members .avatar-stack {
  --avatar-ring: var(--bg);
}
@media (min-width: 768px) {
  @container app-topbar (max-width: 1099px) {
    .app .topbar--project .breadcrumbs {
      display: none;
    }
  }
  @container app-topbar (max-width: 939px) {
    .app .topbar--project .project-ident__key,
    .app .topbar--project .project-members {
      display: none;
    }
  }
  @container app-topbar (max-width: 819px) {
    .app .topbar--project .topbar__new {
      width: 36px;
      padding: 0;
    }
    .app .topbar--project .topbar__new .btn__label {
      display: none;
    }
  }
}

/* Phone title menu (iOS "title menu"): the project name + ⌄ opens the list of views. */
.project-switch {
  min-width: 0;
}
.project-switch__button {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  max-width: 62vw;
  height: 34px;
  padding: 0 10px;
  border: 0;
  border-radius: var(--radius-full);
  background: none;
  color: var(--text);
  font-size: var(--type-headline);
  font-weight: var(--fw-semibold);
  -webkit-tap-highlight-color: transparent;
}
.project-switch__button:active,
.project-switch__button[aria-expanded="true"] {
  background: var(--fill-1);
}
.project-switch__name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.project-switch__button .icon {
  flex-shrink: 0;
  color: var(--text-3);
}
@media (max-width: 767px) {
  /* Phones: back · name ⌄ · ★ · status · "…" · search — the rest lives in the "…" menu. */
  .app .topbar--project :is(.project-ident__key, .project-members, .project-ident__archived) {
    display: none;
  }
  .topbar--project .topbar__title {
    /* the h1 stays for screen readers; the title menu shows the name */
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
  }
  .topbar--project .topbar__heading {
    gap: 4px;
  }
  /* The star belongs to the title, not to the bar's buttons: no glass circle. */
  .topbar--project .project-ident__meta .btn--icon {
    width: 32px;
    height: 32px;
    background: none;
    box-shadow: none;
    -webkit-backdrop-filter: none;
    backdrop-filter: none;
  }
  .topbar--project .project-switch {
    flex: 0 1 auto;
  }
  /* Phones: the back button keeps only its chevron next to the title menu. */
  .topbar--project .breadcrumbs > :last-child {
    width: 36px;
    padding: 0;
    font-size: 0;
  }
}

/* Scope bar (.subbar): the views as a segmented control (a white thumb slides to the chosen view —
   app.js moves it at once on click, the cross-document view transition `view-tab-indicator`
   carries it to the next page), the view's toolbar on the right; when both don't fit the toolbar
   drops to its own line. Settings — not a view — is a gear at the end. */
.subbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 12px;
  min-width: 0;
  min-height: var(--subbar-h);
  padding: 0 max(var(--page-pad-x), var(--safe-right)) 6px max(var(--page-pad-x), var(--safe-left));
  container: app-subbar / inline-size;
}
.view-tabs {
  position: relative;
  display: inline-flex;
  flex: 0 1 auto;
  align-items: center;
  gap: 0;
  min-width: 0;
  height: 32px;
  padding: 2px;
  border-radius: var(--radius-full);
  background: var(--fill-2);
  overflow-x: auto;
  overscroll-behavior-x: contain;
  scroll-padding-inline: 40px;
  scrollbar-width: none;
  isolation: isolate; /* one stacking context: the thumb is under EVERY tab's label */
}
.view-tabs::-webkit-scrollbar {
  display: none;
}
.view-tab {
  position: relative; /* no isolation — or the sliding thumb would cover another tab's label */
  display: inline-flex;
  flex-shrink: 0;
  align-items: center;
  gap: 6px;
  height: 28px;
  padding: 0 12px;
  border-radius: var(--radius-full);
  color: var(--text-2);
  font-size: var(--fs-sm);
  font-weight: var(--fw-medium);
  white-space: nowrap;
  cursor: default;
  transition: color var(--dur-2) ease;
}
.view-tab:hover {
  color: var(--text);
}
.view-tab:focus-visible {
  outline-offset: -2px;
}
.view-tab.is-active,
.view-tab.is-pending {
  color: var(--text);
  font-weight: var(--fw-semibold);
}
.view-tab.is-leaving {
  color: var(--text-2);
  font-weight: var(--fw-medium);
}
.view-tab .icon {
  width: 15px;
  height: 15px;
}
.view-tab > :not(.view-tab__indicator) {
  position: relative;
  z-index: 1;
}
.view-tab__indicator {
  position: absolute;
  z-index: 0;
  top: 0;
  bottom: 0;
  left: 0;
  width: 100%;
  border-radius: var(--radius-full);
  background: var(--segmented-thumb);
  box-shadow: var(--segmented-thumb-shadow);
  transition:
    transform var(--dur-snappy) var(--spring-snappy),
    width var(--dur-snappy) var(--spring-snappy);
  view-transition-name: view-tab-indicator;
}
/* Settings: a gear at the end (label kept for screen readers, shown as a tooltip). */
.subbar .view-tabs > .view-tab.view-tab--settings {
  margin-left: 6px;
  padding: 0 8px;
}
.view-tab--settings .view-tab__label {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}
/* Short of room: only the chosen view keeps its label (the others: glyph, label for screen readers). */
@container app-subbar (max-width: 1000px) {
  .view-tab:not(.is-active, .view-tab--settings) .view-tab__label {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
  }
  .view-tab {
    padding: 0 10px;
  }
}
@media (max-width: 767px) {
  .view-tabs {
    display: none; /* phones: the title menu (.project-switch) */
  }
}

/* Scroll strips (the settings pill strip, in-page .tabs, [data-scroll-fade], view tabs): fade the
   edge that has more to scroll to. app.js toggles .can-scroll-start / .can-scroll-end. */
:is(.view-tabs, .settings-nav, .tabs, [data-scroll-fade]).can-scroll-end {
  -webkit-mask-image: linear-gradient(to right, black calc(100% - 44px), transparent);
  mask-image: linear-gradient(to right, black calc(100% - 44px), transparent);
}
:is(.view-tabs, .settings-nav, .tabs, [data-scroll-fade]).can-scroll-start {
  -webkit-mask-image: linear-gradient(to right, transparent, black 44px);
  mask-image: linear-gradient(to right, transparent, black 44px);
}
:is(.view-tabs, .settings-nav, .tabs, [data-scroll-fade]).can-scroll-start.can-scroll-end {
  -webkit-mask-image: linear-gradient(to right, transparent, black 44px, black calc(100% - 44px), transparent);
  mask-image: linear-gradient(to right, transparent, black 44px, black calc(100% - 44px), transparent);
}
.project-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2);
  margin-bottom: var(--space-4);
}
.project-toolbar:not(:has(*)) {
  display: none;
}
.subbar > .subbar__tools.project-toolbar {
  flex: 1 1 360px;
  justify-content: flex-end;
  min-width: 0;
  margin: 0;
  padding: 0;
}
.subbar > .subbar__tools.project-toolbar:not(:has(*)) {
  display: none;
}
/* Wrapped onto its own line (< 1024px): start-aligned under the views, scrolls sideways. */
@media (max-width: 1023px) {
  .subbar > .subbar__tools.project-toolbar {
    flex: 1 1 100%;
    flex-wrap: nowrap;
    justify-content: flex-start;
    margin-inline: calc(-1 * max(var(--page-pad-x), var(--safe-left))) calc(-1 * max(var(--page-pad-x), var(--safe-right)));
    padding: 0 max(var(--page-pad-x), var(--safe-right)) 0 max(var(--page-pad-x), var(--safe-left));
    overflow-x: auto;
    scrollbar-width: none;
  }
}
@media (max-width: 767px) {
  .subbar {
    min-height: 0;
    padding-bottom: 8px;
  }
  .subbar:not(:has(> .subbar__tools.project-toolbar > *)) {
    display: none;
  }
}

/* -- Settings layout ----------------------------------------------------------------------------- */
.settings-layout {
  display: grid;
  gap: var(--space-5);
  max-width: 1080px;
  margin-inline: auto;
}
.settings-nav {
  display: flex;
  gap: 2px;
}
.settings-nav__label {
  padding: 6px 10px 4px;
  color: var(--text-3);
  font-size: var(--fs-xs);
  font-weight: var(--fw-semibold);
}
.settings-nav__item {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  height: var(--row-h);
  padding: 0 10px;
  border-radius: var(--radius-sm);
  color: var(--text-2);
  font-weight: var(--fw-medium);
  white-space: nowrap;
  transition:
    background-color var(--dur-1) ease,
    box-shadow var(--dur-1) ease,
    color var(--dur-1) ease;
}
.settings-nav__item .icon {
  color: var(--text-2);
}
.settings-nav__item:hover {
  background: var(--fill-1);
}
.settings-nav__item.is-active {
  background: var(--fill-2);
  color: var(--text);
}
.settings-nav__item.is-active .icon {
  color: var(--accent);
}
.settings-content {
  min-width: 0;
  max-width: 760px;
}
@media (min-width: 1024px) {
  .settings-layout {
    grid-template-columns: 220px minmax(0, 1fr);
    align-items: start;
    gap: var(--space-10);
  }
  .settings-nav {
    position: sticky;
    top: calc(var(--topbar-h) + var(--safe-top) + 16px);
    flex-direction: column;
  }
}
@media (max-width: 1023px) {
  .settings-nav {
    margin-inline: calc(var(--page-pad-x) * -1);
    padding: 2px var(--page-pad-x) 4px;
    overflow-x: auto;
    overscroll-behavior-x: contain;
    gap: 6px;
    scroll-padding-inline: var(--page-pad-x);
    scrollbar-width: none;
  }
  .settings-nav::-webkit-scrollbar {
    display: none;
  }
  .settings-nav__label {
    display: none;
  }
  .settings-nav__item {
    flex-shrink: 0;
    height: 36px;
    padding: 0 14px;
    border-radius: var(--radius-full);
    background: var(--fill-1);
  }
  .settings-nav__item:active {
    transform: scale(0.97);
  }
  .settings-nav__item.is-active {
    background: var(--surface-inverse);
    box-shadow: none;
    color: var(--text-inverse);
  }
  .settings-nav__item.is-active .icon {
    color: inherit;
  }
}

/* -- Auth layout --------------------------------------------------------------------------------- */
.auth {
  position: relative;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
  padding: max(16px, var(--safe-top)) max(16px, var(--safe-right)) max(16px, var(--safe-bottom)) max(16px, var(--safe-left));
  overflow: hidden;
  isolation: isolate;
}
.auth__bg {
  position: fixed;
  z-index: -1;
  inset: 0;
  overflow: hidden;
  background: var(--bg);
}
.auth__bg::before,
.auth__bg::after {
  content: "";
  position: absolute;
  inset: -30%;
  background:
    radial-gradient(38% 42% at 22% 28%, color-mix(in srgb, var(--c-blue) 34%, transparent), transparent 70%),
    radial-gradient(34% 38% at 78% 22%, color-mix(in srgb, var(--c-purple) 26%, transparent), transparent 70%),
    radial-gradient(40% 44% at 70% 78%, color-mix(in srgb, var(--c-mint) 24%, transparent), transparent 70%),
    radial-gradient(30% 34% at 26% 82%, color-mix(in srgb, var(--c-pink) 18%, transparent), transparent 70%);
  filter: saturate(1.15);
}
.auth__bg::after {
  inset: 0;
  background:
    radial-gradient(120% 90% at 50% 0%, transparent 40%, var(--bg) 100%),
    linear-gradient(to bottom, transparent, color-mix(in srgb, var(--bg) 40%, transparent));
  filter: none;
}
@media (prefers-reduced-motion: no-preference) {
  .auth__bg::before {
    animation: mesh-drift 26s var(--ease-in-out) infinite alternate;
  }
}
@keyframes mesh-drift {
  0% {
    transform: translate3d(0, 0, 0) rotate(0deg) scale(1);
  }
  50% {
    transform: translate3d(3%, -2%, 0) rotate(8deg) scale(1.05);
  }
  100% {
    transform: translate3d(-3%, 3%, 0) rotate(-6deg) scale(1.02);
  }
}
.auth__top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  max-width: 1120px;
  width: 100%;
  margin-inline: auto;
  min-height: 44px;
}
.auth__top .brand {
  flex: 0 1 auto;
  min-width: 0;
}
.auth__top .brand__text {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.auth__tools {
  display: flex;
  flex-shrink: 0;
  align-items: center;
  gap: var(--space-2);
}
/* Narrow phones: the pills show language codes (KY · RU · EN) so the brand keeps its room. */
@media (max-width: 400px) {
  .auth__top .lang-switch__name {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
  }
  .auth__top .lang-switch__code {
    display: inline;
  }
  .auth__top .lang-switch__item {
    padding-inline: 9px;
    letter-spacing: 0.02em;
  }
}
.auth__main {
  display: flex;
  flex: 1;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-5);
  padding-block: var(--space-8);
}
.auth-card {
  width: 100%;
  max-width: 420px;
  padding: 32px 28px 28px;
  border: 1px solid light-dark(rgb(255 255 255 / 0.7), rgb(255 255 255 / 0.08));
  border-radius: var(--radius-2xl);
  background: light-dark(rgb(255 255 255 / 0.72), rgb(28 28 30 / 0.66));
  -webkit-backdrop-filter: saturate(180%) blur(28px);
  backdrop-filter: saturate(180%) blur(28px);
  box-shadow: var(--shadow-xl);
}
@media (prefers-reduced-motion: no-preference) {
  .auth-card {
    animation: card-in 600ms var(--ease-out) both;
  }
}
@keyframes card-in {
  from {
    opacity: 0;
    transform: translateY(14px) scale(0.985);
  }
}
@media (max-width: 479px) {
  .auth-card {
    padding: 28px 20px 22px;
    border-radius: var(--radius-xl);
  }
}
.auth-card__head {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-2);
  margin-bottom: var(--space-6);
  text-align: center;
}
.auth-card__logo {
  width: 56px;
  height: 56px;
  margin-bottom: var(--space-2);
  filter: drop-shadow(0 8px 18px color-mix(in srgb, var(--c-indigo) 35%, transparent));
}
.auth-card__title {
  font-size: var(--fs-title-2);
  font-weight: var(--fw-bold);
  letter-spacing: var(--tracking-tight);
}
.auth-card__subtitle {
  color: var(--text-2);
  font-size: var(--fs-lg);
}
.auth-card__subtitle:empty {
  display: none;
}
.auth__footer {
  color: var(--text-2);
  font-size: var(--fs-md);
  text-align: center;
}
.auth__footer:not(:has(*)):empty {
  display: none;
}
.auth__legal {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: var(--space-2) var(--space-4);
  color: var(--text-3);
  font-size: var(--fs-xs);
}

/* Language switcher pills (auth/marketing) */
.lang-switch {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  padding: 3px;
  border-radius: var(--radius-full);
  background: var(--fill-1);
}
.lang-switch__item {
  height: 26px;
  padding: 0 10px;
  border: 0;
  border-radius: var(--radius-full);
  background: none;
  color: var(--text-2);
  font-size: var(--fs-xs);
  font-weight: var(--fw-semibold);
  transition:
    background-color var(--dur-1) ease,
    color var(--dur-1) ease,
    transform var(--dur-1) var(--ease-out);
}
.lang-switch__item:hover {
  color: var(--text);
}
.lang-switch__item:active {
  transform: scale(0.96);
}
.lang-switch__code {
  display: none;
}
@media (pointer: coarse) {
  .lang-switch__item {
    height: 34px;
  }
}
.lang-switch__item[aria-current="true"] {
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-sm);
}

/* -- Marketing layout ---------------------------------------------------------------------------- */
.mkt {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
}
.mkt-nav {
  position: sticky;
  top: 0;
  z-index: var(--z-sticky);
  padding-top: var(--safe-top);
  border-bottom: 1px solid var(--glass-line);
  background: var(--glass-bg);
  -webkit-backdrop-filter: var(--glass-filter);
  backdrop-filter: var(--glass-filter);
}
.mkt-nav__inner {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  max-width: 1120px;
  height: 56px;
  margin-inline: auto;
  padding-inline: max(20px, var(--safe-left)) max(20px, var(--safe-right));
}

.mkt-main {
  flex: 1;
}

.mkt-footer {
  border-top: 1px solid var(--line);
  color: var(--text-2);
  font-size: var(--fs-sm);
}
.mkt-footer__inner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  max-width: 1120px;
  margin-inline: auto;
  padding: var(--space-8) max(20px, var(--safe-right)) calc(var(--space-8) + var(--safe-bottom)) max(20px, var(--safe-left));
}
.mkt-footer__links {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-4);
}
.mkt-footer__links a:hover {
  color: var(--text);
}

/* -- Status pages (errors, standalone) -----------------------------------------------------------
   r3: calm and plain — the canvas, the logo, a small mono code chip, one clear sentence, the way
   out (secondary "Go back" + primary "Home"). No decoration; light and dark from tokens.
   layouts/standalone_error.html (400/500, no request) mirrors this with inline styles. */
.status-page {
  position: relative;
  isolation: isolate;
  display: grid;
  place-items: center;
  min-height: 100vh;
  min-height: 100dvh;
  padding: 24px max(20px, var(--safe-right)) calc(24px + var(--safe-bottom)) max(20px, var(--safe-left));
  background: var(--bg);
  text-align: center;
}
.status-page__tools {
  position: absolute;
  top: max(16px, var(--safe-top));
  right: max(16px, var(--safe-right));
}
.status-page__inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-3);
  max-width: 440px;
  margin-top: -6vh;
}
.status-page__inner > img {
  width: 40px;
  height: 40px;
  margin-bottom: var(--space-3);
}
.status-page__code {
  display: inline-flex;
  align-items: center;
  height: 22px;
  padding: 0 8px;
  border-radius: var(--radius-full);
  box-shadow: inset 0 0 0 1px var(--line);
  color: var(--text-3);
  font-family: var(--font-mono);
  font-size: var(--fs-xs);
  font-weight: var(--fw-medium);
  letter-spacing: 0.02em;
}
.status-page__title {
  margin: 0;
  font-size: var(--fs-title-2);
  font-weight: var(--fw-semibold);
  letter-spacing: var(--tracking-tight);
  text-wrap: balance;
}
.status-page__text {
  max-width: 42ch;
  margin: 0;
  color: var(--text-2);
  font-size: var(--fs-md);
  line-height: 1.55;
  text-wrap: pretty;
}
.status-page__actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: var(--space-2);
  margin-top: var(--space-3);
}
@media (max-width: 479px) {
  .status-page__title {
    font-size: var(--fs-title-3);
  }
}

/* -- Placeholder (stub) page ---------------------------------------------------------------------- */
.stub {
  display: grid;
  gap: var(--space-6);
}
.stub__hero {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-12) var(--space-4) var(--space-8);
  text-align: center;
}
.stub__preview {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(240px, 100%), 1fr));
  gap: var(--space-4);
}
