/* ═══════════════════════════════════════════════════════════════════
   AXIS Console — IDE shell
   ───────────────────────────────────────────────────────────────────
   Structure ported from Iliad (axis-iliad's App.tsx + index.css .ide-*
   rules — the sibling AXIS product) for brand consistency across the
   product family. Iliad is React/CSS Grid; this is the same grid
   algorithm and class names, re-implemented for Foundry's vanilla-JS
   shell (see js/app/shell.js for the render logic that populates it).
   All values below reference Foundry's own --av-* tokens (see
   averionics-theme.css, itself ported from Iliad's palette) rather than
   introducing a second parallel token vocabulary.
   ═══════════════════════════════════════════════════════════════════ */

html, body { overflow-x: hidden; max-width: 100%; }

.ide-shell {
  --rail-w: 52px;
  --sidebar-w: 240px;
  --tabstrip-h: 36px;
  --statusbar-h: 32px;
  display: grid;
  grid-template-columns: var(--rail-w) var(--sidebar-w) minmax(0, 1fr);
  grid-template-rows: var(--tabstrip-h) minmax(0, 1fr);
  grid-template-areas:
    "rail tabs tabs"
    "rail side main";
  height: 100vh;
  height: 100dvh;
  max-height: calc(100vh - var(--statusbar-h));
  max-height: calc(100dvh - var(--statusbar-h));
  width: 100%;
  overflow: hidden;
  background: var(--av-bg-canvas);
  color: var(--av-fg-primary);
  font-family: var(--av-font-ui);
  transition: grid-template-columns var(--av-duration-panel, 220ms) var(--av-easing-out, ease);
}
.ide-shell.sidebar-collapsed { --sidebar-w: 0px; }

/* ── Full-bleed override (Studio's own layout owns the whole main area) ── */
.ide-shell.studio-mode .ide-main {
  padding: 0;
  overflow: hidden;
}
.ide-shell.studio-mode #route-outlet {
  height: 100%;
  overflow: hidden;
}
/* Studio's own chrome (its topbar + rails + history strip) fills the outlet —
   port of the pre-IDE-shell rule that was dropped in the layout migration; without
   it the studio body collapses to content height and leaves a dead band below. */
.ide-shell.studio-mode .studio-body {
  height: 100%;
  min-height: 0;
}
/* The shell's marketing footer is for scrolling document routes (Docs/Billing/…),
   NOT the full-bleed Studio app view — it otherwise floats in that dead band. */
.ide-shell.studio-mode .ide-footer {
  display: none;
}

/* ═══ Column 1 — activity rail ═══════════════════════════════════ */
.ide-rail {
  grid-area: rail;
  grid-row: 1 / 3;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 10px 0;
  background: var(--av-bg-surface-2);
  border-right: 1px solid var(--av-line-soft);
  box-shadow:
    inset -1px 0 0 0 color-mix(in srgb, var(--av-accent-cyan) 26%, transparent),
    inset 1px 0 0 0 color-mix(in srgb, var(--av-line-strong) 70%, transparent);
  z-index: 30;
}
.ide-rail-spacer { flex: 1 1 auto; }
.ide-rail-btn {
  display: flex; align-items: center; justify-content: center;
  width: 38px; height: 38px;
  border: 1px solid transparent;
  border-radius: var(--av-radius-md);
  background: transparent;
  color: var(--av-fg-tertiary);
  font-size: 1.05rem; line-height: 1; cursor: pointer;
  text-decoration: none;
  transition: color 0.12s ease, background 0.12s ease,
              border-color 0.12s ease, box-shadow 0.12s ease, transform 0.06s ease;
}
.ide-rail-btn:hover {
  color: var(--av-fg-primary);
  background: var(--av-bg-surface-3);
  border-color: color-mix(in srgb, var(--av-line-strong) 80%, transparent);
}
.ide-rail-btn:active {
  transform: translateY(0.5px);
  background: var(--av-bg-surface-3);
  border-color: var(--av-line-strong);
}
.ide-rail-btn[aria-current="page"],
.ide-rail-btn.active {
  color: var(--av-accent-cyan);
  background: color-mix(in srgb, var(--av-accent-cyan) 12%, transparent);
  border-color: color-mix(in srgb, var(--av-accent-cyan) 30%, transparent);
  box-shadow:
    inset -2px 0 0 0 var(--av-accent-cyan),
    0 0 10px color-mix(in srgb, var(--av-accent-cyan) 16%, transparent);
}
.ide-rail-btn[aria-current="page"]:hover,
.ide-rail-btn.active:hover {
  background: color-mix(in srgb, var(--av-accent-cyan) 16%, var(--av-bg-surface-3));
}
.ide-rail-btn:focus-visible { outline: none; box-shadow: var(--av-glow-cyan); }
.ide-rail-hamburger { display: none; }

/* ═══ Column 2 — labeled sidebar (grouped nav tree) ═══════════════ */
.ide-sidebar {
  grid-area: side;
  display: flex; flex-direction: column;
  min-width: 0;
  background: var(--av-bg-surface-1);
  border-right: 1px solid var(--av-line-soft);
  overflow: hidden auto;
}
.sidebar-collapsed .ide-sidebar { border-right: none; }
.ide-sidebar > * {
  transition: opacity 0.14s ease, transform 0.16s ease;
}
.sidebar-collapsed .ide-sidebar > * {
  opacity: 0;
  transform: translateX(-6px);
  pointer-events: none;
}

.ide-sidebar-brand {
  display: flex; align-items: center; justify-content: space-between; gap: 9px;
  width: 100%;
  padding: 0 12px 0 14px;
  height: var(--tabstrip-h);
  flex-shrink: 0;
  border: none; border-bottom: 1px solid var(--av-line-soft);
  box-shadow: inset 0 -1px 0 0 color-mix(in srgb, var(--av-accent-cyan) 22%, transparent);
  background: transparent;
  font: inherit;
  cursor: pointer; white-space: nowrap;
  text-decoration: none; color: inherit;
  transition: background 0.12s;
}
.ide-sidebar-brand:hover { background: var(--av-bg-surface-2); }
.ide-sidebar-brand:focus-visible { outline: none; box-shadow: var(--av-glow-cyan); }
.ide-sidebar-brand-name {
  font-size: 0.9rem; font-weight: 700; line-height: 1;
  letter-spacing: -0.015em; color: var(--av-fg-primary);
  overflow: hidden; text-overflow: ellipsis;
}

.ide-tree { padding: 4px 8px 18px; display: flex; flex-direction: column; gap: 0; }
.ide-tree-group {
  font-family: var(--av-font-mono);
  font-size: 0.6rem; letter-spacing: 0.16em; text-transform: uppercase;
  color: color-mix(in srgb, var(--av-fg-tertiary) 82%, transparent);
  padding: 8px 8px 5px;
  -webkit-user-select: none; user-select: none;
}
.ide-tree-group:first-child { padding-top: 6px; }
.ide-tree-item + .ide-tree-group {
  margin-top: 8px;
  padding-top: 9px;
  border-top: 1px solid color-mix(in srgb, var(--av-line-soft) 60%, transparent);
}
.ide-tree-item {
  display: flex; align-items: center; gap: 9px;
  width: 100%;
  min-height: 28px;
  padding: 0 9px;
  border: none; border-left: 2px solid transparent;
  border-radius: 0 var(--av-radius-md) var(--av-radius-md) 0;
  background: transparent;
  color: var(--av-fg-primary);
  font-family: var(--av-font-ui); font-size: 0.815rem; text-align: left;
  text-decoration: none;
  cursor: pointer; white-space: nowrap;
  transition: background 0.1s, color 0.1s, border-color 0.1s, box-shadow 0.1s;
}
.ide-tree-item:hover {
  background: var(--av-bg-surface-2);
  color: var(--av-fg-primary);
  border-left-color: color-mix(in srgb, var(--av-accent-cyan) 35%, transparent);
}
.ide-tree-item:hover .ide-tree-ico { color: var(--av-fg-primary); }
.ide-tree-item[aria-current="page"],
.ide-tree-item.active {
  color: var(--av-accent-cyan);
  background: color-mix(in srgb, var(--av-accent-cyan) 12%, transparent);
  border-left-color: var(--av-accent-cyan);
  box-shadow: inset 1px 0 0 0 color-mix(in srgb, var(--av-accent-cyan) 55%, transparent);
  font-weight: 600;
}
.ide-tree-item[aria-current="page"] .ide-tree-ico,
.ide-tree-item.active .ide-tree-ico { color: var(--av-accent-cyan); }
.ide-tree-item:focus-visible { outline: none; box-shadow: var(--av-glow-cyan); }
.ide-tree-ico {
  width: 18px; height: 18px;
  display: inline-flex; align-items: center; justify-content: center;
  opacity: 0.92; flex-shrink: 0; color: var(--av-fg-tertiary);
}

/* ═══ Column 3 / Row 1 — tab strip + breadcrumb locator ═══════════ */
.ide-tabstrip {
  grid-area: tabs;
  display: flex; align-items: stretch; gap: 0;
  padding-right: 2px;
  background: var(--av-bg-surface-2);
  border-bottom: 1px solid var(--av-line-soft);
  box-shadow: inset 0 -1px 0 0 color-mix(in srgb, var(--av-accent-cyan) 26%, transparent);
}
.ide-tab {
  position: relative;
  display: flex; align-items: center; gap: 8px;
  padding: 0 18px;
  font-family: var(--av-font-mono); font-size: 0.78rem;
  color: var(--av-fg-tertiary); background: transparent;
  border-right: 1px solid var(--av-line-soft);
  border-top: 2px solid transparent;
  transition: color 0.12s ease, background 0.12s ease, border-color 0.12s ease;
}
.ide-tab.active {
  color: var(--av-fg-primary);
  background: var(--av-bg-surface-1);
  border-top-color: var(--av-accent-cyan);
  margin-bottom: -1px;
  padding-bottom: 1px;
}
.ide-tab-ico {
  color: var(--av-accent-cyan); font-size: 0.5rem; line-height: 1;
  filter: drop-shadow(0 0 4px color-mix(in srgb, var(--av-accent-cyan) 45%, transparent));
}
.ide-tab-label { white-space: nowrap; letter-spacing: 0.01em; }
.ide-locator {
  display: flex; align-items: center; gap: 9px;
  padding: 0 16px; margin-left: 2px;
  border-left: 1px solid color-mix(in srgb, var(--av-line-soft) 70%, transparent);
  font-family: var(--av-font-mono); font-size: 0.68rem; letter-spacing: 0.06em;
  line-height: 1; align-self: center;
}
.loc-sys { color: var(--av-fg-tertiary); letter-spacing: 0.1em; text-transform: uppercase; opacity: 0.9; }
.loc-sep { color: var(--av-accent-cyan); font-size: 0.6rem; opacity: 0.8; }
.loc-page { color: var(--av-fg-primary); font-weight: 600; letter-spacing: 0.05em; }
.ide-tel-dot {
  margin-left: auto; margin-right: 16px; align-self: center;
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--av-state-success);
  box-shadow: 0 0 0 1px color-mix(in srgb, var(--av-state-success) 35%, transparent);
  animation: ide-telpulse 2.4s ease-out infinite;
}
@keyframes ide-telpulse {
  0%   { box-shadow: 0 0 0 0 color-mix(in srgb, var(--av-state-success) 55%, transparent); }
  70%  { box-shadow: 0 0 0 6px transparent; }
  100% { box-shadow: 0 0 0 0 transparent; }
}

/* ═══ Column 3 / Row 2 — main panel (the only scroll region) ══════ */
.ide-main {
  grid-area: main;
  min-width: 0; min-height: 0;
  overflow: auto;
  padding: 24px 32px 8px;
  background: var(--av-bg-canvas);
  box-shadow: inset 0 1px 0 0 color-mix(in srgb, var(--av-line-soft) 60%, transparent);
  scroll-padding-top: 12px;
  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}
@media (prefers-reduced-motion: reduce) {
  .ide-main { scroll-behavior: auto; }
}
/* Grid-item blowout guard (P1 2026-07-07 mobile regression, see
   __tests__/mobile-overflow.test.js): min-width:0 must hold on the whole
   chain from the grid item down to the route-mounted content, or a wide
   unwrappable descendant (e.g. a <pre> block) forces the layout viewport
   wide on narrow screens instead of reflowing. */
#route-outlet {
  min-width: 0;
}
.ide-main > .page-enter {
  max-width: 1160px;
  margin-inline: auto;
  animation: ide-slide-up 0.18s cubic-bezier(0.22, 1, 0.36, 1) both;
}
@keyframes ide-slide-up {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: translateY(0); }
}
@media (prefers-reduced-motion: reduce) {
  .ide-main > .page-enter { animation: none; }
}

/* ── Shell-owned page footer (every route, after its own content) ── */
.ide-footer {
  max-width: 1160px;
  margin: 56px auto 0;
  padding: 20px 16px 28px;
  text-align: center;
  border-top: 1px solid transparent;
  border-image: linear-gradient(
    to right, transparent,
    var(--av-line-soft) 18%, var(--av-line-soft) 82%,
    transparent
  ) 1;
}
.ide-footer p, .ide-footer {
  color: var(--av-fg-tertiary);
  font-family: var(--av-font-mono);
  font-size: 0.72rem;
  letter-spacing: 0.02em;
  /* No opacity here: --av-fg-tertiary is already the palette's dedicated
     de-emphasized-text token: stacking opacity on top of it dropped dark-mode
     contrast to 4.08:1 against the shell background, failing WCAG 2.1 AA's
     4.5:1 minimum (axe-core color-contrast, caught once the E2E auth-mock
     gap — memory project_e2e_auth_mock_gap — stopped silently skipping the
     a11y scan on every gated route). Un-opacified: ~6.8:1, comfortable margin. */
}
.ide-footer a { color: var(--av-fg-tertiary); text-decoration: none; }
.ide-footer a:hover { color: var(--av-accent-cyan); text-decoration: underline; }
.ide-footer a:focus-visible { outline: none; box-shadow: var(--av-glow-cyan); border-radius: 2px; color: var(--av-accent-cyan); }
.ide-footer-sep { opacity: 0.6; }

/* ═══ Status bar — fixed, outside the grid entirely ═══════════════ */
.ide-statusbar {
  position: fixed; left: 0; right: 0; bottom: 0; height: var(--statusbar-h, 32px);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 16px;
  background: var(--av-bg-surface-1);
  border-top: 1px solid var(--av-line-soft);
  color: var(--av-fg-tertiary);
  font-family: var(--av-font-mono); font-size: 0.6875rem;
  z-index: 8000;
}
.ide-statusbar-side { display: flex; align-items: center; gap: 16px; }
.ide-statusbar-dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--av-fg-tertiary);
  display: inline-block;
}
.ide-statusbar-dot.online { background: var(--av-state-success); }
.ide-statusbar-dot.offline { background: var(--av-state-danger); }

/* ═══ Mobile off-canvas drawer ═════════════════════════════════════ */
.nav-mobile-drawer {
  position: fixed; inset: 0;
  background: rgba(0, 0, 0, 0.5);
  /* Above .ide-statusbar (8000) — a modal drawer must cover the whole shell,
     status bar included, or it peeks through at the bottom on small viewports. */
  z-index: 9000;
  display: flex; flex-direction: column; align-items: stretch;
  overflow-y: auto;
  animation: ide-slide-down 0.2s ease-out both;
}
@keyframes ide-slide-down {
  from { opacity: 0; transform: translateY(-8px); }
  to   { opacity: 1; transform: translateY(0); }
}
.nav-drawer-item {
  display: flex; align-items: center; gap: 10px;
  padding: 16px 20px;
  font-size: 1rem; font-weight: 500; font-family: var(--av-font-ui);
  color: var(--av-fg-primary); background: var(--av-bg-surface-1);
  border: none; border-bottom: 1px solid var(--av-line-soft);
  text-decoration: none;
  cursor: pointer; text-align: left;
  transition: background 0.12s;
}
.nav-drawer-item:first-child { margin-top: 0; }
.nav-drawer-item:hover { background: var(--av-bg-surface-2); }
.nav-drawer-item[aria-current="page"],
.nav-drawer-item.active {
  color: var(--av-accent-cyan);
  background: color-mix(in srgb, var(--av-accent-cyan) 8%, var(--av-bg-surface-1));
  border-left: 3px solid var(--av-accent-cyan);
}

/* ═══ Responsive — rail-only + off-canvas drawer below 900px ══════ */
@media (max-width: 900px) {
  .ide-shell {
    grid-template-columns: var(--rail-w) minmax(0, 1fr);
    grid-template-areas:
      "rail tabs"
      "rail main";
  }
  .ide-sidebar { display: none; }
  .ide-rail-hamburger { display: flex; }
  .ide-locator { display: none; }
}
@media (max-width: 600px) {
  .ide-main { padding: 14px 14px 8px; }
  .ide-main > .page-enter { max-width: none; }
  .ide-footer { margin-top: 40px; padding: 18px 14px 24px; }
}

@keyframes spin { to { transform: rotate(360deg); } }
#shell-boot-loader {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 60vh;
  gap: 0.75rem;
  color: var(--av-fg-tertiary, #888);
  font-size: 0.875rem;
}
#shell-boot-loader svg { animation: spin 1s linear infinite; }
