/* ==========================================================================
   AOS Shell — Sidenav / Topbar / LiveRail / Rail / mobile collapse
   Ported from design/claude-design/aos-shell.jsx (Sidenav, Topbar, LiveRail,
   Shell, MobileShell). Source is a fixed 1440x900 / 390x844 artboard pair —
   production shell is fluid (100vw / 100dvh) with a CSS-driven responsive
   collapse instead of a second fixed mobile artboard. MobileShell's fake
   iOS status bar is intentionally NOT ported.
   ========================================================================== */

.shell {
  /* 100% (of the margin-0 body), not 100vw: 100vw includes the vertical
     scrollbar, so any scrolling route overflowed ~15px horizontally. */
  width: 100%;
  height: 100vh;
  height: 100dvh;
  display: grid;
  grid-template-columns: 64px minmax(0, 1fr);
  grid-template-rows: 64px minmax(0, 1fr);
  grid-template-areas:
    "sidenav topbar"
    "sidenav main";
  background: var(--aos-bg-canvas);
  overflow: hidden;
}

.shell.has-rail {
  grid-template-columns: 64px minmax(0, 1fr) 360px;
  grid-template-areas:
    "sidenav topbar topbar"
    "sidenav main rail";
}

.shell-main {
  grid-area: main;
  overflow-y: auto;
  overflow-x: hidden;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

/* main.js focuses #main on every route change (SR-announce pattern for
   in-page navigation) — that focus behavior is intentional and stays. But
   #main/.shell-main is a programmatic focus target, not an interactive
   element, so it should never paint a visible ring (Chrome was drawing its
   native `rgb(0,95,204) auto` ring around the whole content pane). Scoped to
   this selector only — do not touch --nfn-shadow-focus or any other
   interactive element's :focus-visible rule. */
#main:focus,
#main:focus-visible,
.shell-main:focus,
.shell-main:focus-visible {
  outline: none;
}

/* ---------- Sidenav ---------- */
.sidenav {
  grid-area: sidenav;
  width: 64px;
  height: 100%;
  background: var(--aos-bg-surface-2);
  border-right: 1px solid var(--aos-border-subtle);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 14px 0;
}

.sidenav-logo {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  margin-bottom: 18px;
  background: var(--aos-accent);
  color: var(--aos-accent-on);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--aos-font-mono);
  font-weight: 700;
  font-size: 14px;
  letter-spacing: -0.04em;
  flex: 0 0 auto;
  text-decoration: none; /* logo is an anchor in the v2 shell */
}

.sidenav-items {
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 1;
}

.sidenav-items-bottom {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.sidenav-item {
  position: relative;
  width: 40px;
  height: 40px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--aos-text-tertiary);
  background: transparent;
  cursor: pointer;
  border: none;
  text-decoration: none; /* nav items are anchors in the v2 shell */
}

.sidenav-item:hover {
  color: var(--aos-text-secondary);
  background: var(--nfn-bg-subtle);
}

.sidenav-item.active,
.sidenav-item.active:hover {
  color: var(--aos-accent);
  background: var(--aos-accent-subtle);
}

.sidenav-item:focus-visible {
  outline: none;
  box-shadow: var(--nfn-shadow-focus);
}

.sidenav-item.active::after {
  content: '';
  position: absolute;
  left: -12px;
  top: 8px;
  bottom: 8px;
  width: 2px;
  border-radius: 2px;
  background: var(--aos-accent);
}

.sidenav-avatar {
  width: 28px;
  height: 28px;
  border-radius: 999px;
  background: #2a3a2a;
  color: var(--aos-accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--aos-font-mono);
  font-size: 11px;
  font-weight: 600;
  margin-top: 6px;
  border: 1px solid var(--aos-border-default);
}

/* ---------- Topbar ---------- */
.topbar {
  grid-area: topbar;
  height: 64px;
  background: var(--aos-bg-surface-2);
  border-bottom: 1px solid var(--aos-border-subtle);
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  padding: 0 20px;
  gap: 16px;
}

.topbar-titles {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.topbar-kicker {
  font-size: 11px;
  color: var(--aos-text-tertiary);
  font-weight: 500;
}

.topbar-title-row {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.topbar-title {
  font-size: 18px;
  font-weight: 600;
  color: var(--aos-text-primary);
  /* Truncate instead of painting over the actions column when space runs
     out (E3 matrix: at 375px the title overlapped the stale chip). */
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.topbar-breadcrumb {
  font-size: 14px;
  font-weight: 600;
  color: var(--aos-text-tertiary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.topbar-breadcrumb.current {
  color: var(--aos-text-primary);
}

.topbar-breadcrumb-sep {
  color: var(--aos-text-disabled);
  display: inline-flex;
  align-items: center;
}

.topbar-search {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 360px;
  max-width: 100%;
  height: 36px;
  background: var(--aos-bg-input);
  border: 1px solid var(--aos-border-default);
  border-radius: 8px;
  padding: 0 12px;
  color: var(--aos-text-tertiary);
}

.topbar-search-placeholder {
  flex: 1;
  font-size: 13px;
  color: var(--aos-text-tertiary);
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  justify-content: flex-end;
}

/* Stale chip: full text shows by default; the compact span (E3 phone
   variant) only appears ≤767px, see media query below. Keeping both spans
   in the DOM and toggling with display lets the chip stay a single element
   with one aria-label carrying the full text at any width. */
.stale-chip-compact {
  display: none;
}

.topbar-icon-btn {
  position: relative;
  width: 36px;
  height: 36px;
  border-radius: 8px;
  background: transparent;
  border: 1px solid transparent;
  color: var(--aos-text-tertiary);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.topbar-icon-btn:hover {
  color: var(--aos-text-secondary);
  background: var(--nfn-bg-subtle);
}

.topbar-icon-btn:focus-visible,
.topbar-mobile-add:focus-visible {
  outline: none;
  box-shadow: var(--nfn-shadow-focus);
}

/* Drawer trigger — hidden at desktop widths, shown <768px (see media query). */
.topbar-menu-btn {
  display: none;
}

.topbar-icon-btn .badge-dot {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 6px;
  height: 6px;
  border-radius: 999px;
  background: var(--aos-status-error);
}

.topbar-mobile-add {
  width: 36px;
  height: 36px;
  border-radius: 999px;
  background: var(--aos-accent);
  color: var(--aos-accent-on);
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

/* ---------- Live rail ---------- */
.live-rail {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 20px;
  background: var(--aos-bg-surface-1);
  border-bottom: 1px solid var(--aos-border-subtle);
}

.live-rail-status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  color: var(--aos-text-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 500;
}

.live-rail-status-dot {
  width: 6px;
  height: 6px;
  border-radius: 999px;
  background: var(--aos-accent);
  box-shadow: 0 0 0 3px rgba(77, 179, 82, .15);
}

.live-rail-status-dot.stale {
  background: var(--aos-text-disabled);
  box-shadow: none;
}

.live-rail-divider {
  width: 1px;
  height: 14px;
  background: var(--aos-border-subtle);
}

.live-rail-spacer {
  flex: 1;
}

.live-rail-poll {
  font-family: var(--aos-font-mono);
  font-size: 11px;
  color: var(--aos-text-tertiary);
  letter-spacing: 0.02em;
}

/* ---------- Rail (right panel) ---------- */
.rail {
  grid-area: rail;
  border-left: 1px solid var(--aos-border-subtle);
  background: var(--aos-bg-surface-1);
  overflow-y: auto;
  overflow-x: hidden;
  min-height: 0;
}

/* ==========================================================================
   Responsive collapse
   <768px  — sidenav becomes an off-canvas drawer; bottom tab bar replaces it
   <900px  — fab replaces the topbar "Capture" button; search hides
   ========================================================================== */

@media (max-width: 899px) {
  .topbar-search {
    display: none;
  }

  /* With the search (middle column) gone, the 1fr/auto/1fr grid would seat
     .topbar-actions in the center auto column. Two columns: titles | actions. */
  .topbar {
    grid-template-columns: minmax(0, 1fr) auto;
  }

  /* The FAB (below) shows at this width and sits at bottom:92px, height 36px
     — it was overlapping the last scrollable row (Today on Home, a row tag
     on Backlog). 140px ~= FAB reach from the viewport bottom (92 + 36) plus
     clearance, so the last row can always scroll clear of it. At <767px the
     767 breakpoint below raises this further to also clear the tabbar. */
  .shell-main {
    padding-bottom: 140px;
  }
}

@media (max-width: 767px) {
  /* Actions (stale chip / Capture / alerts) eat the row at phone widths and
     squeeze the kicker to one word per line (E3 matrix, 375px). The chip is
     an alarm and must stay; the kicker is decoration — drop it instead.
     Keyboard hints are meaningless on touch and their width pushed the
     alerts bell 15px off-viewport — drop those too. */
  .topbar-kicker,
  .topbar .kbd {
    display: none;
  }

  /* Compact chip variant (approved E3 follow-up): "Stale · snapshot 34m
     old" (~141px) squeezes the title to nothing at phone widths. Swap to
     "Stale 34m" so the title survives; full text stays available to
     screen readers via the chip's aria-label. */
  .stale-chip-full {
    display: none;
  }

  .stale-chip-compact {
    display: inline;
  }
}

.fab {
  display: none;
  position: fixed;
  right: 20px;
  bottom: 92px;
  z-index: 30;
  width: 36px;
  height: 36px;
  border-radius: 999px;
  background: var(--aos-accent);
  color: var(--aos-accent-on);
  border: none;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: var(--nfn-shadow-md);
}

/* 36px visual, >=44px hit area */
.fab::before {
  content: '';
  position: absolute;
  inset: -4px;
  border-radius: 999px;
}

.fab:focus-visible {
  outline: none;
  box-shadow: var(--nfn-shadow-focus);
}

@media (max-width: 899px) {
  .fab {
    display: flex;
  }
}

.tabbar {
  display: none;
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 30;
  height: 76px;
  padding-bottom: 18px;
  padding-top: 8px;
  grid-template-columns: repeat(4, 1fr);
  border-top: 1px solid var(--aos-border-subtle);
  background: var(--aos-bg-surface-2);
}

.tabbar-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  color: var(--aos-text-tertiary);
  font-size: 11px;
  font-weight: 500;
  cursor: pointer;
  background: transparent;
  border: none;
  text-decoration: none; /* tab items are anchors in the v2 shell */
}

.tabbar-item:active {
  color: var(--aos-text-secondary);
}

.tabbar-item.active {
  color: var(--aos-accent);
}

.tabbar-item:focus-visible {
  outline: none;
  box-shadow: var(--nfn-shadow-focus);
  border-radius: 8px;
}

@media (max-width: 767px) {
  .shell,
  .shell.has-rail {
    grid-template-columns: 1fr;
    grid-template-rows: 64px 1fr;
    grid-template-areas:
      "topbar"
      "main";
  }

  /* Default: off-canvas. When a rail opens at this width, ui/rail.js's
     applyMobileSheet() sets `display` inline — inline style beats this
     non-`!important` rule — plus position/inset for a near-full-height
     sheet. See the file-header comment in rail.js for the full contract. */
  .shell .rail {
    display: none;
  }

  /* Clears both the 76px tabbar AND the FAB, which still floats above it
     (bottom:92px) at this width — the FAB's own overlap fix (899px query
     above) used 140px, so match it rather than let this narrower breakpoint
     regress to just the tabbar's 76px. */
  .shell-main {
    padding-bottom: 140px;
  }

  .sidenav {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 50;
    transform: translateX(-100%);
    transition: transform 200ms ease;
  }

  .shell.drawer-open .sidenav {
    transform: translateX(0);
  }

  /* Scrim visibility is owned by the [hidden] attribute (main.js and
     ui/rail.js toggle it), made authoritative by the [hidden] guard in
     components.css. The previous `.shell.drawer-open .drawer-scrim` chain
     could never match: #drawer-scrim is a sibling of .shell, not a
     descendant — it had never been exercised. No display rules here. */
  .drawer-scrim {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 40;
  }

  /* Drawer trigger enters at the left edge of the topbar. Third column:
     menu | titles | actions. */
  .topbar {
    grid-template-columns: auto minmax(0, 1fr) auto;
  }

  .topbar-menu-btn {
    display: flex;
  }

  .tabbar {
    display: grid;
  }
}
