/* Authenticated application shell: persistent sidebar, page bar, and drawers. */

html {
  overflow-x: clip;
  max-width: 100%;
}

html.is-fetching::before {
  content: "";
  position: fixed;
  top: 0;
  left: 0;
  z-index: 90;
  width: 100%;
  height: 0.125rem;
  background: var(--secondary);
  pointer-events: none;
}

.turbo-progress-bar {
  display: none !important;
}

html.is-nav-open {
  overflow: hidden;
}

body.is-app {
  display: block;
  min-height: 100dvh;
  background: var(--background);
}

.app-stage {
  min-height: 100dvh;
  padding: 0.75rem;
  background:
    radial-gradient(125% 90% at 50% -8%, color-mix(in oklch, var(--secondary) 22%, var(--background)), var(--background) 58%);
}

.app-shell {
  display: grid;
  grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
  min-height: calc(100dvh - 1.5rem);
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 1rem;
  background: var(--card);
  box-shadow: var(--shadow-lg);
}

.app-sidebar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  flex-direction: column;
  width: var(--sidebar-width);
  height: 100dvh;
  border-right: 1px solid var(--border);
  background: var(--sidebar);
  color: var(--sidebar-foreground);
}

.sidebar-panel {
  display: flex;
  flex-direction: column;
  min-height: 100%;
  min-width: 0;
}

.sidebar-head,
.sidebar-foot {
  display: grid;
  gap: 0.5rem;
  padding: 0.75rem 0.75rem 0.7rem;
}

.sidebar-head .wordmark {
  font-size: 0.9375rem;
}

.sidebar-foot {
  margin-top: auto;
  border-top: 1px solid var(--border);
}

.sidebar-identity {
  display: grid;
  gap: 0.2rem;
  min-width: 0;
}

.sidebar-workspace-name,
.sidebar-user,
.sidebar-workspace-meta,
.app-mobile-title,
.page-bar-crumbs span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sidebar-workspace-name {
  margin: 0;
  color: var(--foreground);
  font-size: var(--text-record);
  font-weight: var(--weight-semibold);
  letter-spacing: var(--tracking-section);
}

.sidebar-workspace-meta,
.sidebar-user {
  margin: 0;
  color: var(--muted-foreground);
  font-size: var(--text-meta);
  line-height: var(--leading-meta);
}

.sidebar-nav {
  display: grid;
  gap: 0.65rem;
  padding: 0.45rem 0.55rem 0.75rem;
  overflow: auto;
  flex: 1;
  min-height: 0;
}

.sidebar-group {
  display: grid;
  gap: 0.12rem;
}

.sidebar-group-label {
  margin: 0 0 0.2rem;
  padding: 0 0.55rem;
  color: var(--muted-foreground);
  text-transform: uppercase;
  line-height: 1.25;
}

.nav-item {
  display: flex;
  min-width: 0;
  min-height: 2.5rem;
  align-items: center;
  justify-content: flex-start;
  gap: 0.5rem;
  padding: 0.35rem 0.7rem;
  border-radius: var(--radius-pill);
  color: var(--sidebar-foreground);
  font-size: 0.875rem;
  font-weight: var(--weight-medium);
  letter-spacing: var(--tracking-body);
  line-height: 1.3;
  text-decoration: none;
  transition: background 180ms ease, color 180ms ease, box-shadow 180ms ease;
}

.nav-icon {
  flex: none;
  width: 1rem;
  height: 1rem;
  opacity: 0.72;
}

.nav-label {
  min-width: 0;
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.nav-item .nav-count {
  margin-left: auto;
}

.nav-item:hover {
  color: var(--sidebar-foreground);
  background: var(--muted-surface);
}

.nav-item.is-current,
.nav-item[aria-current="page"] {
  color: var(--foreground);
  background: var(--muted-surface);
  box-shadow: none;
  font-weight: var(--weight-semibold);
}

.nav-utility .nav-count,
.app-mobile-status .nav-count {
  display: inline-flex;
  min-width: 1.25rem;
  justify-content: center;
  padding: 0.1rem 0.35rem;
  border-radius: var(--radius-pill);
  color: var(--secondary-foreground);
  background: var(--secondary);
  font-size: 0.6875rem;
  font-weight: var(--weight-semibold);
}

.nav-health {
  color: var(--warning-foreground);
}

.sidebar-foot .theme-control,
.sidebar-sign-out,
.sidebar-head .nav-item {
  width: 100%;
}

.sidebar-sign-out {
  justify-content: flex-start;
}

.app-canvas {
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--background);
}

.app-mobile-bar {
  display: none;
  min-height: 3.5rem;
  max-height: 5.5rem;
  align-items: center;
  gap: 0.75rem;
  padding: 0.5rem 0.85rem;
  border-bottom: 1px solid var(--border);
  background: color-mix(in oklch, var(--background) 88%, transparent);
  backdrop-filter: blur(16px);
}

.app-nav-trigger {
  display: inline-flex;
  width: 3rem;
  min-width: 3rem;
  height: 3rem;
  align-items: center;
  justify-content: center;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--foreground);
  background: var(--card);
  cursor: pointer;
}

.app-mobile-identity {
  display: grid;
  min-width: 0;
  flex: 1;
}

.app-mobile-kicker {
  color: var(--muted-foreground);
  font-size: var(--text-label);
  font-weight: var(--weight-semibold);
  letter-spacing: var(--tracking-label);
  text-transform: uppercase;
}

.app-mobile-title {
  color: var(--foreground);
  font-size: 0.9375rem;
  font-weight: var(--weight-semibold);
}

.page-bar {
  display: flex;
  min-height: 2.75rem;
  align-items: center;
  gap: 1rem;
  margin: 0.75rem 0.75rem 0;
  padding: 0.35rem 0.85rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sheet);
  background: color-mix(in oklch, var(--card) 86%, transparent);
  box-shadow: var(--shadow);
  backdrop-filter: blur(16px);
}

.page-bar-copy {
  display: grid;
  min-width: 0;
  flex: 1;
  gap: 0.1rem;
}

.page-bar-crumbs {
  display: flex;
  min-width: 0;
  align-items: center;
  gap: 0.4rem;
  color: var(--muted-foreground);
  font-size: var(--text-meta);
}

.page-bar-title {
  margin: 0;
  overflow: hidden;
  color: var(--foreground);
  font-size: 0.9375rem;
  font-weight: var(--weight-semibold);
  letter-spacing: var(--tracking-section);
  line-height: 1.25;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.page-bar-actions,
.page-bar-status {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
}

.app-content {
  container-type: inline-size;
  container-name: canvas;
  min-width: 0;
  max-width: 100%;
}

.is-app .flash-region {
  width: min(100% - 2rem, 46rem);
  margin: 0.85rem auto 0;
}

.is-app .page-shell,
.is-app .workbench-shell,
.is-app .account-health-page,
.is-app .crew-work-page,
.is-app .scorecard-page,
.is-app .knowledge-shell,
.is-app .memory-shell,
.is-app .crew-shell,
.is-app .runtime-shell,
.is-app .webhook-page,
.is-app .data-controls-shell {
  width: min(100% - 2rem, 72rem);
  margin-inline: auto;
  padding: 1.5rem 0 3rem;
}

.is-app .case-workspace,
.is-app .crew-work-page {
  width: min(100% - 1.25rem, 92rem);
  padding-top: 1rem;
}

.app-drawer {
  width: 100%;
  max-width: none;
  height: 100%;
  max-height: none;
  margin: 0;
  padding: 0;
  border: 0;
  background: transparent;
}

.app-drawer[open] {
  display: block;
}

.app-drawer::backdrop {
  background: color-mix(in oklch, black 50%, transparent);
  backdrop-filter: blur(8px);
}

.app-drawer-panel {
  position: fixed;
  left: 2.5%;
  right: 2.5%;
  bottom: 0.75rem;
  display: flex;
  flex-direction: column;
  width: 95%;
  max-height: min(85dvh, 42rem);
  overflow: auto;
  padding: 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sheet);
  background: var(--background);
  box-shadow: var(--shadow-lg);
  animation: drawer-in 280ms cubic-bezier(0.22, 1, 0.36, 1);
}

.app-drawer-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}

.app-drawer .sidebar-group .nav-item {
  animation: drawer-row 220ms ease both;
}

.app-drawer .sidebar-group .nav-item:nth-child(1) { animation-delay: 30ms; }
.app-drawer .sidebar-group .nav-item:nth-child(2) { animation-delay: 60ms; }
.app-drawer .sidebar-group .nav-item:nth-child(3) { animation-delay: 90ms; }
.app-drawer .sidebar-group .nav-item:nth-child(4) { animation-delay: 120ms; }

@keyframes drawer-in {
  from { opacity: 0; transform: translateY(4rem); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes drawer-row {
  from { opacity: 0; transform: translateY(0.5rem); }
  to { opacity: 1; transform: translateY(0); }
}

.app-drawer .sidebar-head .wordmark {
  display: none;
}

.app-drawer .nav-item,
.app-drawer .sidebar-sign-out,
.app-drawer .theme-toggle {
  min-height: 49px;
}

@media (max-width: 64rem) {
  .app-stage {
    padding: 0;
    background: var(--background);
  }

  .app-shell {
    grid-template-columns: minmax(0, 1fr);
    min-height: 100dvh;
    border: 0;
    border-radius: 0;
    box-shadow: none;
  }

  .app-sidebar {
    display: none;
  }

  .app-mobile-bar {
    display: flex;
  }

  .page-bar {
    display: none;
  }

  .app-drawer .sidebar-head {
    padding-top: 0.35rem;
  }
}

@media (min-width: 64.0625rem) {
  .app-drawer {
    display: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  .app-drawer-panel,
  .app-drawer .sidebar-group .nav-item,
  .nav-item {
    animation: none;
    transition: none;
  }
}
