/* ============================================================
   APP SHELL — TopBar (50px) + Sidebar (240/56px) + Main
   ============================================================ */
.app {
  display: grid;
  grid-template-rows: var(--topbar-h) 1fr;
  height: 100vh;
}
.app-body {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  min-height: 0;
}
.app[data-sidebar="collapsed"] .app-body { grid-template-columns: var(--sidebar-w-c) 1fr; }

/* ── TOPBAR (§5.2) ──
   backdrop-filter is expensive — every scroll under the topbar triggers a
   compositor repaint of the blurred region. Three mitigations:
     1. `--topbar-bg` already has alpha so the solid-fallback looks fine.
     2. Blur radius reduced 14 → 8 (linear cost vs radius).
     3. Gated behind @supports + disabled on prefers-reduced-transparency. */
.topbar {
  height: var(--topbar-h);
  background: var(--topbar-bg);
  border-bottom: 1px solid var(--border-faint);
  padding: 0 var(--s-4);
  display: flex; align-items: center; gap: var(--s-3);
  z-index: 50;
}
@supports ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
  .topbar {
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
  }
}
@media (prefers-reduced-transparency: reduce) {
  .topbar { backdrop-filter: none; -webkit-backdrop-filter: none; }
}
.tb-toggle {
  width: 32px; height: 32px;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: var(--r-6);
  color: var(--text-secondary);
  transition: background var(--t-fast);
}
.tb-toggle:hover { background: var(--bg-hover); }
.tb-toggle:active { background: var(--bg-active); }
/* Non-interactive workspace marker (the switcher feature is not wired up).
   Kept as a presentation label, no hover/active state to avoid implying an
   action that does nothing. */
.tb-workspace {
  display: inline-flex; align-items: center; gap: var(--s-2);
  height: 32px; padding: 0 var(--s-2);
  border-radius: var(--r-6);
}
.tb-ws-tile {
  width: 24px; height: 24px;
  border-radius: var(--r-4);
  background: var(--asana-coral);
  color: var(--on-coral); font-weight: 600; font-size: var(--t-sm);
  display: inline-flex; align-items: center; justify-content: center;
  overflow: hidden;
}
.tb-ws-tile img { width: 100%; height: 100%; object-fit: cover; display: block; }
.tb-ws-name { font-size: var(--t-base); font-weight: 500; color: var(--text-primary); }
.tb-spacer { flex: 1; }
/* Topbar search — Asana-style rounded pill.
   Subtle border at rest · crisp white outline when focused (the Asana ref
   pattern). The white outline is the visible focus signal, not a coral ring. */
.tb-search {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: var(--s-2);
  height: 36px;
  width: 480px;
  max-width: 50vw;
  padding: 0 var(--s-4);
  background: var(--bg-soft);
  border: 1px solid var(--border-soft);
  border-radius: var(--r-pill);
  color: var(--text-muted);
  font-size: var(--t-base);
  transition: background var(--t-fast), border-color var(--t-fast), box-shadow var(--t-fast);
}
.tb-search:hover {
  background: var(--bg-active);
  border-color: var(--border-medium);
}
/* Focused state — clean white outline · subtle halo · calm not loud */
.tb-search:focus-within {
  background: var(--surface);
  border-color: var(--border-strong);
  box-shadow: 0 0 0 1px var(--border-soft);
}
.tb-search-icon {
  flex-shrink: 0;
  width: 16px;
  height: 16px;
  color: var(--text-muted);
}
.tb-search-input {
  flex: 1;
  min-width: 0;
  height: 100%;
  background: transparent;
  border: none;
  outline: none;
  box-shadow: none;
  color: var(--text-primary);
  font: inherit;
  font-size: var(--t-base);
}
/* Aggressively kill any browser/system focus ring on the input.
   The dropdown opening below is the visible focus signal. */
.tb-search-input:focus,
.tb-search-input:focus-visible,
.tb-search:focus-within {
  outline: none;
  box-shadow: none;
}
.tb-search-input::placeholder { color: var(--text-muted); }
.tb-search .kbd {
  flex-shrink: 0;
  font-size: var(--t-xs);
  font-weight: 500;
  background: var(--surface);
  color: var(--text-secondary);
  border: 1px solid var(--border-soft);
  padding: 0 6px;
  height: 18px;
  line-height: 16px;
  border-radius: var(--r-4);
  text-transform: none;
  letter-spacing: 0;
  transition: opacity var(--t-fast);
}
/* Hide kbd hint once user is typing */
.tb-search:focus-within .kbd { opacity: 0; pointer-events: none; }
.tb-avatar {
  width: 28px; height: 28px; border-radius: var(--r-pill);
  background: var(--asana-coral); color: var(--on-coral);
  display: inline-flex; align-items: center; justify-content: center;
  font-size: var(--t-sm); font-weight: 500;
  overflow: hidden;
  padding: 0;
}
.tb-avatar img { width: 100%; height: 100%; object-fit: cover; display: block; }

/* ── SIDEBAR (§5.3) ── */
.sidebar {
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border-soft);
  padding: var(--s-3) var(--s-2);
  overflow-y: auto;
  z-index: 40;
  transition: width var(--t-normal);
}
.sb-section { margin-top: var(--s-5); }
.sb-section:first-child { margin-top: 0; }
.sb-section > a + a { margin-top: var(--s-1); }
.sb-heading {
  display: flex; align-items: center; justify-content: space-between;
  height: 24px; padding: 0 var(--s-3);
  margin-bottom: var(--s-1);
  font-size: 11px; line-height: 16px;
  font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--text-muted);
}
.sb-heading button {
  width: 16px; height: 16px;
  display: inline-flex; align-items: center; justify-content: center;
  color: var(--text-muted);
  border-radius: var(--r-4);
}
.sb-heading button:hover { background: var(--bg-hover); }
.sb-item {
  display: flex; align-items: center; gap: var(--s-3);
  min-height: 36px; padding: var(--s-2) var(--s-3);
  border-radius: var(--r-6);
  font-size: 13px; font-weight: 500;
  color: var(--text-primary);
  text-decoration: none;
  position: relative;
  transition: background var(--t-fast);
  white-space: nowrap;
}
.sb-item:hover { background: var(--bg-hover); text-decoration: none; }
.sb-item:active { background: var(--bg-active); }
.sb-item[aria-current="page"] {
  background: var(--bg-active);
  color: var(--text-primary);
  font-weight: 600;
}
.sb-item[aria-current="page"]::before {
  content: ""; position: absolute; left: 0; top: 8px; bottom: 8px;
  width: 2px; border-radius: var(--r-pill);
  background: var(--cat-accent, var(--asana-coral));
}
.sb-item .lucide { color: var(--text-secondary); flex-shrink: 0; width: 16px; height: 16px; }
.sb-item[aria-current="page"] .lucide { color: var(--cat-accent, var(--asana-coral)); }
.sb-bucket { display: flex; align-items: center; gap: var(--s-2); }
.sb-bucket-dot { width: 10px; height: 10px; border-radius: var(--r-pill); flex-shrink: 0; }
.sb-bucket-count {
  margin-left: auto; font-size: var(--t-sm); color: var(--text-muted); font-weight: 400;
}
.sb-projects { margin-top: var(--s-1); display: flex; flex-direction: column; gap: 2px; }
.sb-project {
  display: flex; align-items: center; gap: var(--s-2);
  height: 32px; padding: 0 var(--s-2) 0 28px;
  border-radius: var(--r-6);
  font-size: var(--t-base);
  color: var(--text-primary);
  text-decoration: none;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  transition: background var(--t-fast);
}
.sb-project:hover { background: var(--bg-hover); text-decoration: none; }
.sb-project:active { background: var(--bg-active); }
.sb-project[aria-current="page"] { background: var(--surface); box-shadow: var(--shadow-sm); }
.sb-project-dot { width: 6px; height: 6px; border-radius: var(--r-pill); flex-shrink: 0; }
.sb-project-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sb-project-star { color: var(--asana-coral); font-size: 12px; flex-shrink: 0; }

/* ── Collapsible groups (Categories, Companies under Projects) ── */
.sb-group { display: flex; flex-direction: column; margin-top: 2px; }
.sb-group-toggle {
  display: flex; align-items: center; gap: var(--s-3);
  min-height: 32px; padding: var(--s-1) var(--s-3);
  width: 100%;
  background: transparent;
  border: 0;
  border-radius: var(--r-6);
  font-size: var(--t-sm); font-weight: 500;
  color: var(--text-secondary);
  text-align: left;
  cursor: pointer;
  transition: background var(--t-fast), color var(--t-fast);
}
.sb-group-toggle:hover { background: var(--bg-hover); color: var(--text-primary); }
.sb-group-toggle:focus-visible { box-shadow: var(--focus-ring); outline: none; }
.sb-chevron {
  width: 14px; height: 14px;
  flex-shrink: 0;
  color: var(--text-muted);
  transition: transform var(--t-fast);
}
.sb-group[data-expanded="true"] .sb-chevron { transform: rotate(90deg); }
.sb-group-body {
  display: none;
  flex-direction: column;
  margin-top: 2px;
  padding-left: var(--s-2);
  gap: 2px;
}
.sb-group[data-expanded="true"] .sb-group-body { display: flex; }

/* Nested items inside a group sit slightly indented and use a softer label. */
.sb-item--nested {
  min-height: 32px;
  font-size: var(--t-sm);
  font-weight: 500;
}

/* Company logo tile inside the sidebar — small unified version of .pp-logo. */
.sb-co-logo {
  flex: 0 0 18px;
  width: 18px; height: 18px;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: var(--r-4);
  overflow: hidden;
  box-sizing: border-box;
  background: #ffffff;
  border: 1px solid var(--border-soft);
}
.sb-co-logo--img img {
  width: 100%; height: 100%;
  object-fit: contain;
  display: block;
}
.sb-co-logo--mono {
  background: var(--surface);
  border: 1px solid var(--border-soft);
  font-size: 10px; font-weight: 600;
  color: var(--text-secondary);
}

/* collapsed sidebar */
.app[data-sidebar="collapsed"] .sb-heading,
.app[data-sidebar="collapsed"] .sb-bucket-count,
.app[data-sidebar="collapsed"] .sb-projects,
.app[data-sidebar="collapsed"] .sb-group,
.app[data-sidebar="collapsed"] .sb-item span:not(.sb-bucket-dot):not(.lucide),
.app[data-sidebar="collapsed"] .sb-item .sb-bucket span { display: none; }
.app[data-sidebar="collapsed"] .sb-item { justify-content: center; padding: 0; }

/* ── MAIN ── */
.main {
  display: flex; flex-direction: column;
  min-width: 0; min-height: 0;
  overflow-y: auto;
  background: var(--bg);
}
/* Mouse focus (programmatic, e.g. after route() refocuses): no ring — would be noise. */
.main:focus:not(:focus-visible) { outline: none; box-shadow: none; }
/* Keyboard focus (skip-link target): inset hairline ring so users can confirm
   the jump landed. Inset because main owns its own scroll context. */
.main:focus-visible {
  outline: none;
  box-shadow: inset 0 0 0 2px var(--asana-coral-ring);
}
.page-header {
  padding: var(--s-4) var(--s-6) 0;
  display: flex; flex-direction: column; gap: var(--s-2);
  border-bottom: none;
}
.page-body { padding: var(--s-6); flex: 1; }

/* ── PROJECT HEADER (§5.4) ── */
.project-header { padding: var(--s-4) var(--s-6) 0; display: flex; flex-direction: column; gap: var(--s-3); }
.project-header-row { display: flex; align-items: flex-start; gap: var(--s-3); }
.project-icon-tile {
  width: 32px; height: 32px;
  border-radius: var(--r-6);
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 18px;
  flex-shrink: 0;
}
.project-title-block { flex: 1; min-width: 0; }
.project-title { font-size: var(--t-xl); line-height: var(--lh-xl); font-weight: 600; letter-spacing: -0.01em; color: var(--text-primary); }
.project-sub { font-size: var(--t-sm); color: var(--text-secondary); margin-top: var(--s-0-5); }
.project-code {
  display: inline-block;
  font-family: var(--font-mono); font-size: 10px;
  color: var(--text-muted);
  background: var(--bg-soft);
  padding: 1px 6px; border-radius: var(--r-4);
  letter-spacing: 0.02em;
}
.project-header-actions { display: flex; align-items: center; gap: var(--s-2); }

/* ── TAB BAR (§5.5) ── */
.tab-bar {
  display: flex; align-items: stretch;
  height: var(--tab-h);
  border-bottom: 1px solid var(--border-soft);
  padding: 0 var(--s-6);
  gap: var(--s-1);
  background: var(--bg);
}
.tab {
  display: inline-flex; align-items: center;
  height: var(--tab-h); padding: 0 var(--s-3);
  font-size: var(--t-sm); font-weight: 500;
  color: var(--text-secondary);
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  transition: color var(--t-fast), background var(--t-fast);
  text-decoration: none;
}
.tab:hover { color: var(--text-primary); background: var(--bg-hover); text-decoration: none; }
.tab:active { background: var(--bg-active); }
.tab[aria-current="page"] {
  color: var(--text-primary);
  border-bottom-color: var(--db-accent, var(--asana-coral));
}

/* ── MOBILE (§9) ── */
@media (max-width: 1024px) {
  .app-body { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; top: var(--topbar-h); left: 0; bottom: 0;
    width: 280px;
    transform: translateX(-100%);
    transition: transform var(--t-normal);
    z-index: 80;
  }
  .app[data-sidebar-mobile="open"] .sidebar { transform: translateX(0); }
  .scrim {
    position: fixed; inset: var(--topbar-h) 0 0 0;
    background: var(--scrim);
    z-index: 70;
    opacity: 0; pointer-events: none;
    transition: opacity var(--t-normal);
  }
  .app[data-sidebar-mobile="open"] .scrim { opacity: 1; pointer-events: auto; }
  .tb-search { min-width: auto; width: 36px; padding: 0; justify-content: center; }
  .tb-search > span:not(.lucide), .tb-search .kbd { display: none; }
  /* Hide the inline input on phone/tablet — the .tb-search wrapper acts as
     a tap target that opens the full-screen palette instead. Without this,
     the placeholder "Search projects…" renders inside the 36px-wide pill
     and reads as a broken "S…" fragment. */
  .tb-search .tb-search-input { display: none; }
}
