/* Overlay surfaces live here with their responsive adaptations. */
.command-overlay {
  position: fixed;
  inset: 0;
  z-index: var(--z-modal);
  display: grid;
  place-items: start center;
  overflow: auto;
  background: rgb(15 23 42 / 24%);
  padding: min(14vh, 8rem) 1rem 2rem;
  backdrop-filter: blur(12px) saturate(120%);
}

.command-overlay[hidden] { display: none; }

.command-panel {
  width: min(42rem, 100%);
  overflow: hidden;
  border: 1px solid rgb(255 255 255 / 68%);
  border-radius: 1.5rem;
  background: rgb(250 250 252 / 88%);
  box-shadow: 0 28px 80px rgb(15 23 42 / 20%);
  backdrop-filter: blur(32px) saturate(180%);
}

.command-input-row {
  display: grid;
  min-height: 4rem;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 0.75rem;
  border-bottom: 1px solid var(--border-subtle);
  padding: 0 1rem;
}

.command-input-row > .icon { width: 1.25rem; height: 1.25rem; color: var(--text-tertiary); }
.command-input-row input { min-height: 3rem; border: 0; border-radius: 0; padding: 0; font-size: var(--font-size-base); box-shadow: none; }
.command-input-row input:focus { box-shadow: none; }
.key-button { border: 0; background: transparent; color: var(--text-tertiary); font-family: var(--font-sans); font-size: 0.6875rem; }

.command-body {
  max-height: min(25rem, 56vh);
  overflow-y: auto;
  padding: 0.75rem;
}

.command-label {
  padding: 0.25rem 0.5rem 0.5rem;
  color: var(--text-tertiary);
  font-size: 0.6875rem;
  font-weight: var(--font-weight-semibold);
  letter-spacing: 0;
}

.command-panel footer {
  display: flex;
  min-height: 2.75rem;
  align-items: center;
  gap: 1rem;
  border-top: 1px solid var(--border-subtle);
  background: var(--surface-subtle);
  color: var(--text-tertiary);
  padding: 0.5rem 1rem;
  font-size: 0.625rem;
}

.command-panel footer span:last-child { margin-left: auto; }

.drawer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  z-index: calc(var(--z-overlay) + 2);
  display: grid;
  width: min(30rem, 92vw);
  grid-template-rows: auto minmax(0, 1fr);
  border-left: 1px solid rgb(255 255 255 / 48%);
  background: rgb(250 250 252 / 82%);
  box-shadow: -18px 0 64px rgb(15 23 42 / 14%);
  backdrop-filter: blur(32px) saturate(180%);
  transform: translateX(105%);
  transition: transform 320ms cubic-bezier(0.32, 0.72, 0, 1);
}

.drawer.is-open,
.drawer[aria-hidden="false"] { transform: translateX(0); }

.drawer.is-open + .drawer-scrim,
.drawer[aria-hidden="false"] + .drawer-scrim {
  visibility: visible;
  opacity: 1;
}

.drawer__head {
  display: grid;
  min-height: var(--header-height);
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 1rem;
  border-bottom: 1px solid rgb(15 23 42 / 7%);
  background: rgb(255 255 255 / 22%);
  padding: 0.75rem 1.25rem;
}

.drawer__body { min-height: 0; overflow-y: auto; padding: 1.25rem; }

.toast-region {
  position: fixed;
  right: 1.25rem;
  bottom: 1.25rem;
  z-index: calc(var(--z-modal) + 5);
  display: grid;
  width: min(23rem, calc(100vw - 2rem));
  gap: 0.625rem;
  pointer-events: none;
}

.toast-region > * { pointer-events: auto; box-shadow: var(--shadow-md); }

body:has(.command-overlay:not([hidden])),
body:has(.drawer[aria-hidden="false"]),
body:has(.sidebar.is-open) { overflow: hidden; }

/* Compact desktop: preserve information density before switching navigation modes. */
@media (max-width: 68.75rem) {
  .app-shell {
    grid-template-columns: 13.5rem minmax(0, 1fr);
  }

  .sidebar { width: 13.5rem; }

  .brand-lockup { padding-inline: 0.75rem; }
  .prototype-tag { display: none; }

  .topbar {
    grid-template-columns: minmax(9rem, 0.8fr) minmax(15rem, 1.6fr) auto;
    gap: 0.75rem;
    padding-inline: 1rem;
  }

  .demo-data-label { display: none; }
  .view-root { padding: 1.25rem; }
}

/* Tablet and mobile: navigation becomes a modal drawer. */
@media (max-width: 47.5rem) {
  .app-shell {
    display: block;
    min-height: 100vh;
  }

  .sidebar {
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    z-index: var(--z-overlay);
    width: min(18rem, calc(100vw - 3rem));
    height: 100vh;
    height: 100dvh;
    min-height: 0;
    box-shadow: 18px 0 52px rgb(15 23 42 / 16%);
    transform: translateX(-105%);
    transition: transform 320ms cubic-bezier(0.32, 0.72, 0, 1);
  }

  .sidebar.is-open,
  .sidebar[data-open="true"],
  .app-shell.is-menu-open .sidebar,
  body.menu-open .sidebar {
    transform: translateX(0);
  }

  .sidebar.is-open ~ .mobile-scrim,
  .sidebar[data-open="true"] ~ .mobile-scrim,
  .app-shell.is-menu-open .mobile-scrim,
  body.menu-open .mobile-scrim {
    visibility: visible;
    opacity: 1;
  }

  .brand-lockup { padding-inline: 1rem; }
  .prototype-tag { display: inline; }
  .mobile-menu-button { display: inline-grid; }

  .topbar {
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 0.5rem;
    padding-inline: 0.75rem;
  }

  .topbar__context small { display: none; }
  .global-search { display: none; }
  .topbar__actions { gap: 0.125rem; }
  .topbar__actions .avatar--button { display: none; }
  .view-root { min-height: calc(100vh - var(--header-height)); padding: 1rem; }
  .site-contact { align-items: flex-start; flex-direction: column; padding: var(--space-5) 1rem var(--space-8); }
  .site-contact__link { width: 100%; justify-content: center; }

  .filter-tabs {
    width: 100%;
    max-width: 100%;
    overflow-x: auto;
    overscroll-behavior-inline: contain;
    scrollbar-width: thin;
  }

  .filter-tabs > button { flex: 0 0 auto; }

  .command-overlay {
    align-items: end;
    padding: 1rem 0 0;
  }

  .command-panel {
    width: 100%;
    max-height: calc(100vh - 1rem);
    max-height: calc(100dvh - 1rem);
    border-radius: 1.5rem 1.5rem 0 0;
  }

  .command-body { max-height: min(27rem, 62vh); }
  .command-panel footer { gap: 0.5rem; }
  .command-panel footer span:last-child { display: none; }

  .drawer {
    top: auto;
    width: 100%;
    max-height: 92vh;
    max-height: 92dvh;
    border-top: 1px solid var(--border-subtle);
    border-left: 0;
    border-radius: 1.5rem 1.5rem 0 0;
    box-shadow: 0 -18px 52px rgb(15 23 42 / 16%);
    transform: translateY(105%);
  }

  .drawer.is-open,
  .drawer[aria-hidden="false"] { transform: translateY(0); }

  .drawer__head { min-height: 3.75rem; padding-inline: 1rem; }
  .drawer__body { padding: 1rem; }

  .toast-region {
    right: 1rem;
    bottom: max(1rem, env(safe-area-inset-bottom));
    left: 1rem;
    width: auto;
  }
}

@media (max-width: 30rem) {
  .topbar__context { gap: 0.375rem; }
  .topbar__context strong { max-width: 9rem; font-size: var(--font-size-sm); }
  .notification-button { width: 2.25rem; }

  .view-root { padding: 0.75rem; }
  .site-contact { padding-inline: 0.75rem; }
  .command-input-row { min-height: 3.5rem; padding-inline: 0.75rem; }
  .command-panel footer span:nth-child(2) { display: none; }
}

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

  .command-panel,
  .reveal { animation: none; }

  .btn,
  .icon-button,
  .text-action,
  .rail-step,
  :is(.filter-tabs, .workbench-tabs, .governance-tabs, .mode-switch) > button { transition: none; }
}

@media (prefers-reduced-transparency: reduce) {
  .sidebar,
  .topbar,
  .command-panel,
  .drawer {
    background: var(--surface-raised);
    backdrop-filter: none;
  }

  .command-overlay {
    background: rgb(15 23 42 / 48%);
    backdrop-filter: none;
  }
}

@media (prefers-contrast: more) {
  .sidebar,
  .topbar,
  .command-panel,
  .drawer {
    border-color: var(--color-ink-500);
  }

  .nav-item.is-active { outline: 2px solid var(--color-brand-700); outline-offset: -2px; }
}
