/* App shell: the main content column owns scrolling. */
.app-shell {
  display: grid;
  grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  padding-top: env(safe-area-inset-top);
}

.app-shell-body {
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow: hidden;
}

.app-main {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: var(--geist-space-6x);
  min-height: 0;
  overflow-y: auto;
  padding: var(--geist-space-6x)
    calc(var(--geist-space-6x) + env(safe-area-inset-right))
    calc(var(--geist-space-10x) + env(safe-area-inset-bottom))
    calc(var(--geist-space-6x) + env(safe-area-inset-left));
}

.app-main > * {
  flex-shrink: 0;
  max-width: var(--content-max);
}

.app-main > .cockpit-section:not(:first-child) {
  margin-top: var(--geist-space-6x);
}

body:not(:has(.app-shell)) .app-main {
  padding: var(--geist-space-6x);
}

/* Sidebar */
.app-sidebar {
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
  overscroll-behavior: contain;
  background: var(--canvas);
  box-shadow: 1px 0 0 var(--ds-gray-alpha-300);
  padding-left: env(safe-area-inset-left);
}

.app-sidebar-head {
  display: flex;
  align-items: center;
  justify-content: center;
  height: var(--header-height);
  padding: 0 var(--geist-space-4x);
  border-bottom: 1px solid var(--hairline);
  flex-shrink: 0;
}

.app-sidebar-brand,
.app-sidebar-brand:hover {
  color: var(--ink);
  text-decoration: none;
}

.app-sidebar-brand {
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.app-sidebar-brand .brand {
  font-size: 16px;
}

.app-sidebar-brand:focus-visible,
.nav-item:focus-visible {
  outline: none;
  box-shadow: var(--ds-focus-ring);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: var(--geist-space-2x);
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: 12px;
  font-weight: 600;
  line-height: 1;
  letter-spacing: 0;
  white-space: nowrap;
}

.brand-mark {
  display: inline-flex;
  align-items: stretch;
  gap: 0.18em;
  height: 0.85em;
  flex-shrink: 0;
}

.brand-bar {
  width: 0.32em;
  background: var(--brand);
}

.app-sidebar-nav {
  display: grid;
  align-content: start;
  gap: 1px;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: var(--geist-space-3x) var(--geist-space-2x);
}

.nav-item {
  display: flex;
  align-items: center;
  gap: var(--geist-space-3x);
  padding: var(--geist-space-2x) var(--geist-space-3x);
  border-radius: var(--radius);
  color: var(--ink-muted);
  font-family: var(--font-sans);
  font-size: 14px;
  font-weight: 400;
  line-height: 20px;
  text-decoration: none;
  cursor: pointer;
  transition: background-color .15s cubic-bezier(.4, 0, .2, 1), color .15s cubic-bezier(.4, 0, .2, 1), box-shadow .15s cubic-bezier(.4, 0, .2, 1);
}

.nav-item:hover {
  background: var(--ds-gray-alpha-100);
  color: var(--ink);
}

.app-sidebar .nav-item.is-active,
.app-sidebar .nav-item.is-active:hover {
  background: var(--ds-gray-alpha-200);
  color: var(--ink);
  font-weight: 500;
}

.nav-item-icon {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  color: inherit;
}

.nav-item-label {
  flex: 1;
}

.app-sidebar .nav-item .badge {
  border-radius: var(--radius-full);
  background: var(--surface-muted);
  box-shadow: var(--ring);
}

.app-sidebar-foot {
  display: grid;
  flex-shrink: 0;
  gap: 1px;
  padding: var(--geist-space-2x);
  box-shadow: 0 -1px 0 var(--ds-gray-alpha-300);
}

.app-sidebar-foot form {
  width: 100%;
  margin: 0;
}

button.nav-item {
  width: 100%;
  appearance: none;
  background: transparent;
  border: 0;
  font: inherit;
  text-align: left;
}

@media (pointer: coarse) {
  .app-sidebar .nav-item { min-height: 44px; }
}

.app-sidebar-signout {
  width: 100%;
}

.status-dot {
  width: 8px;
  height: 8px;
  flex-shrink: 0;
  border-radius: var(--radius-full);
  background: var(--ink-subtle);
}

.status-dot.is-running {
  background: var(--info);
  animation: status-pulse 1.5s var(--ease) infinite;
}

.status-dot.is-ok {
  background: var(--success);
}

.status-dot.is-error {
  background: var(--error);
}

@keyframes status-pulse {
  50% { opacity: 0.35; }
}

/* Topbar */
.app-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--geist-space-4x);
  height: var(--header-height);
  padding: 0 var(--geist-space-6x);
  flex-shrink: 0;
  background: color-mix(in srgb, var(--canvas) 80%, transparent);
  backdrop-filter: blur(12px);
  border-left: 1px solid var(--hairline);
  border-bottom: 1px solid var(--hairline);
}

.app-topbar-lead,
.app-topbar-user {
  display: flex;
  align-items: center;
  gap: var(--geist-space-3x);
}

.app-topbar-lead {
  min-width: 0;
}

.app-topbar-title {
  overflow: hidden;
  margin: 0;
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: 14px;
  font-weight: var(--font-weight-semibold);
  letter-spacing: 0;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.app-topbar-user {
  flex-shrink: 0;
}

.app-topbar-actions {
  display: flex;
  align-items: center;
  gap: var(--geist-space-1x);
}

.app-topbar-sync {
  color: var(--ink-muted);
  font-family: var(--font-mono);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.app-topbar-divider {
  flex-shrink: 0;
  padding-inline: var(--geist-space-1x);
  color: var(--hairline-strong);
  font-size: 14px;
  line-height: 1;
}

.app-topbar-account {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 36px;
  width: 36px;
  height: 36px;
  color: var(--ink-muted);
  cursor: default;
}

.app-topbar-menu.btn {
  display: none;
}

.app-topbar .btn-icon {
  min-width: 36px;
  width: 36px;
  height: 36px;
}

.app-shell-backdrop {
  display: none;
}

@media (max-width: 671px) {
  .app-shell {
    grid-template-columns: minmax(0, 1fr);
  }

  .app-sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: var(--z-drawer);
    width: var(--sidebar-width);
    visibility: hidden;
    border-radius: 0 var(--radius-lg) var(--radius-lg) 0;
    box-shadow: var(--ds-shadow-modal);
    transform: translateX(-100%) scale(var(--ds-motion-overlay-scale));
    transform-origin: left center;
    transition: transform var(--ds-motion-overlay-duration) var(--ds-motion-overlay-timing), visibility var(--ds-motion-overlay-duration);
  }

  .app-shell.is-drawer-open .app-sidebar {
    visibility: visible;
    transform: translateX(0) scale(1);
  }

  .app-shell.is-drawer-open .app-shell-backdrop:not([hidden]) {
    display: block;
    position: fixed;
    inset: 0;
    z-index: var(--z-backdrop);
    background: var(--ds-overlay-backdrop-color);
    opacity: var(--ds-overlay-backdrop-opacity);
    animation: shell-backdrop-in var(--ds-motion-overlay-duration) var(--ds-motion-overlay-timing) both;
  }

  @keyframes shell-backdrop-in {
    from { opacity: 0; }
    to { opacity: var(--ds-overlay-backdrop-opacity); }
  }

  .app-topbar,
  .app-main {
    padding-inline: var(--geist-space-3x);
  }

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

  .app-topbar-user {
    display: none;
  }
}

@media (min-width: 672px) {
  .app-sidebar .app-sidebar-signout {
    display: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  .app-sidebar {
    transition: none;
  }

  .status-dot.is-running,
  .app-shell.is-drawer-open .app-shell-backdrop:not([hidden]) {
    animation: none;
  }
}
