/* Lot 2: permanent HUB chrome only. No font, color or legacy token on #app,
   #appContainer, main, sections, media, canvases or project overlays.
   The shared quota dialog below is the sole dialog exception.
   Detached documents receive this link but cannot match the hub/app gate. */

:where(html[data-ps-theme="studio"][data-ps-window="hub"][data-ps-screen="app"]) #appHeader {
  min-width: 0;
  gap: 16px;
  background: var(--ps-shell-header-bg);
  border-bottom-color: var(--ps-line);
  box-shadow: var(--ps-shell-reflection), 0 4px 14px #0003;
  font-family: var(--ps-font-ui);
  color: var(--ps-text);
}

:where(html[data-ps-theme="studio"][data-ps-window="hub"][data-ps-screen="app"]) #appHeader > .logo {
  min-width: 0;
  font: 600 18px/22px var(--ps-font-ui);
  letter-spacing: -.04em;
  color: var(--ps-ink);
}

:where(html[data-ps-theme="studio"][data-ps-window="hub"][data-ps-screen="app"]) #appHeader > .logo::before {
  content: "";
  display: block;
  flex: 0 0 28px;
  width: 28px;
  height: 28px;
  background: url("../assets/logo/pixelsound-logo.png") center / contain no-repeat;
}

:where(html[data-ps-theme="studio"][data-ps-window="hub"][data-ps-screen="app"]) #headerStudioLogo {
  flex-shrink: 0;
  border-color: var(--ps-line-strong);
  background: var(--ps-surface-soft);
}

:where(html[data-ps-theme="studio"][data-ps-window="hub"][data-ps-screen="app"]) #headerStudioName {
  min-width: 0;
  max-width: 20vw;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--ps-muted);
  font: 400 11px/16px var(--ps-font-ui);
  letter-spacing: 0;
}

:where(html[data-ps-theme="studio"][data-ps-window="hub"][data-ps-screen="app"]) #adminBadge {
  flex-shrink: 0;
  color: var(--ps-gold-light);
  background: var(--ps-surface-soft);
  border-color: var(--ps-line-strong);
  font-family: var(--ps-font-ui);
  font-weight: 600;
  letter-spacing: 0;
}

:where(html[data-ps-theme="studio"][data-ps-window="hub"][data-ps-screen="app"]) #appHeader > .user-info {
  flex-shrink: 0;
  min-width: 0;
  color: var(--ps-muted);
  font: 400 13px/16px var(--ps-font-ui);
}

:where(html[data-ps-theme="studio"][data-ps-window="hub"][data-ps-screen="app"]) #userEmail {
  min-width: 0;
  max-width: 28vw;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

:where(html[data-ps-theme="studio"][data-ps-window="hub"][data-ps-screen="app"]) #appHeader > .user-info > button {
  flex-shrink: 0;
  border-radius: 4px;
  border-color: var(--ps-line-strong);
  background: var(--ps-surface-soft);
  color: var(--ps-text);
  font: 600 13px/16px var(--ps-font-ui);
  box-shadow: none;
  transition: background-color .2s ease, border-color .2s ease, color .2s ease;
}

:where(html[data-ps-theme="studio"][data-ps-window="hub"][data-ps-screen="app"]) #appHeader > .user-info > button:hover:not(:disabled) {
  border-color: var(--ps-gold);
  background: var(--ps-bg-soft);
  color: var(--ps-ink);
  box-shadow: none;
}

/* The sidebar's backing continues behind its reserved Appearance footer.
   Only the navigation scrolls above it; workspace height is not reduced. */
:where(html[data-ps-theme="studio"][data-ps-window="hub"][data-ps-screen="app"]) #appContainer {
  --ps-shell-header-height: 56px;
  --ps-shell-appearance-space: 64px;
}

:where(html[data-ps-theme="studio"][data-ps-window="hub"][data-ps-screen="app"]) #appContainer::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 220px;
  background: var(--ps-surface-soft);
  border-right: 1px solid var(--ps-line);
  pointer-events: none;
}

:where(html[data-ps-theme="studio"][data-ps-window="hub"][data-ps-screen="app"]) #mainNav {
  position: relative;
  height: calc(100% - var(--ps-shell-appearance-space));
  max-height: calc(100vh - var(--ps-shell-header-height) - var(--ps-shell-appearance-space));
  overflow-y: auto;
  overscroll-behavior-y: contain;
  scrollbar-width: thin;
  scrollbar-color: var(--ps-line-strong) var(--ps-surface-soft);
  background: var(--ps-surface-soft);
  border-right-color: var(--ps-line);
  box-shadow: none;
  font-family: var(--ps-font-ui);
  color: var(--ps-text);
}

:where(html[data-ps-theme="studio"][data-ps-window="hub"][data-ps-screen="app"]) #mainNav > h3 {
  color: var(--ps-muted);
  font: 600 10px/16px var(--ps-font-ui);
  letter-spacing: .12em;
}

:where(html[data-ps-theme="studio"][data-ps-window="hub"][data-ps-screen="app"]) #mainNav > h3::before {
  content: "";
  display: inline-block;
  width: 12px;
  height: 1px;
  margin: 0 7px 3px 0;
  background: var(--ps-copper);
}

:where(html[data-ps-theme="studio"][data-ps-window="hub"][data-ps-screen="app"]) #mainNav > button {
  border-radius: 6px;
  border-color: transparent;
  background: transparent;
  color: var(--ps-muted);
  font: 400 14px/20px var(--ps-font-ui);
  box-shadow: none;
  transition: background-color .2s ease, border-color .2s ease, color .2s ease;
}

:where(html[data-ps-theme="studio"][data-ps-window="hub"][data-ps-screen="app"]) #mainNav > button:hover:not(:disabled) {
  border-color: var(--ps-line);
  background: var(--ps-bg-soft);
  color: var(--ps-text);
  box-shadow: none;
}

/* Active appearance derives from the displayed section, including role fallback
   and workspace exit cancellation. There is no second navigation state in JS. */
:where(html[data-ps-theme="studio"][data-ps-window="hub"][data-ps-screen="app"]) #appContainer:has(> main > :is(#section-projects, #section-project-new, #section-project-detail):not(.hidden)) > #mainNav > [data-ps-section="projects"],
:where(html[data-ps-theme="studio"][data-ps-window="hub"][data-ps-screen="app"]) #appContainer:has(> main > #section-account:not(.hidden)) > #mainNav > [data-ps-section="account"],
:where(html[data-ps-theme="studio"][data-ps-window="hub"][data-ps-screen="app"]) #appContainer:has(> main > #section-studio:not(.hidden)) > #mainNav > [data-ps-section="studio"],
:where(html[data-ps-theme="studio"][data-ps-window="hub"][data-ps-screen="app"]) #appContainer:has(> main > #section-admin:not(.hidden)) > #mainNav > [data-ps-section="admin"],
:where(html[data-ps-theme="studio"][data-ps-window="hub"][data-ps-screen="app"]) #appContainer:has(> main > #section-jobs:not(.hidden)) > #mainNav > [data-ps-section="jobs"],
:where(html[data-ps-theme="studio"][data-ps-window="hub"][data-ps-screen="app"]) #appContainer:has(> main > #section-voice-manager:not(.hidden)) > #mainNav > [data-ps-section="voice-manager"],
:where(html[data-ps-theme="studio"][data-ps-window="hub"][data-ps-screen="app"]) #appContainer:has(> main > #section-production-tracker:not(.hidden)) > #mainNav > [data-ps-section="production-tracker"] {
  background: var(--ps-surface-solid);
  border-color: var(--ps-line);
  color: var(--ps-ink);
  font-weight: 600;
  box-shadow: inset 3px 0 var(--ps-gold);
}

:where(html[data-ps-theme="studio"][data-ps-window="hub"][data-ps-screen="app"]) #navToggleBtn {
  border-color: var(--ps-line-strong);
  background: var(--ps-surface-solid);
  color: var(--ps-gold-light);
  font-family: var(--ps-font-ui);
  box-shadow: var(--ps-shell-reflection), 0 2px 7px #0003;
  transition: background-color .2s ease, border-color .2s ease, color .2s ease;
}

:where(html[data-ps-theme="studio"][data-ps-window="hub"][data-ps-screen="app"]) #navToggleBtn:hover:not(:disabled) {
  border-color: var(--ps-gold);
  background: var(--ps-bg-soft);
  color: var(--ps-ink);
  box-shadow: var(--ps-shell-reflection), 0 2px 7px #0003;
}

:where(html[data-ps-theme="studio"][data-ps-window="hub"][data-ps-screen="app"]) #appHeader > .user-info > button:focus-visible,
:where(html[data-ps-theme="studio"][data-ps-window="hub"][data-ps-screen="app"]) #mainNav > button:focus-visible,
:where(html[data-ps-theme="studio"][data-ps-window="hub"][data-ps-screen="app"]) #navToggleBtn:focus-visible {
  outline: 2px solid var(--ps-focus);
  outline-offset: 2px;
}

:where(html[data-ps-theme="studio"][data-ps-window="hub"][data-ps-screen="app"]) #appHeader > .user-info > button:disabled,
:where(html[data-ps-theme="studio"][data-ps-window="hub"][data-ps-screen="app"]) #mainNav > button:disabled,
:where(html[data-ps-theme="studio"][data-ps-window="hub"][data-ps-screen="app"]) #navToggleBtn:disabled {
  opacity: .55;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

:where(html[data-ps-theme="studio"][data-ps-window="hub"][data-ps-screen="app"]) #appContainer.nav-collapsed::before {
  width: 0;
  border: 0;
}

:where(html[data-ps-theme="studio"][data-ps-window="hub"][data-ps-screen="app"]) #appContainer.nav-collapsed > #mainNav {
  width: 0;
  flex-basis: 0;
  height: 0;
  padding: 0;
  border: 0;
  overflow: hidden;
  visibility: hidden;
  box-shadow: none;
}

/* With navigation closed, Appearance stays compact and fixed as in Original.
   Only the header bounds the workspace; no footer height is reserved. */
:where(html[data-ps-theme="studio"][data-ps-window="hub"][data-ps-screen="app"]) #appContainer.nav-collapsed > main {
  max-height: calc(100vh - var(--ps-shell-header-height));
}

:where(html[data-ps-theme="studio"][data-ps-window="hub"][data-ps-screen="app"]) #ps-theme-switcher {
  border-color: var(--ps-line-strong);
  border-radius: 6px;
  box-shadow: var(--ps-shell-reflection), 0 2px 7px #0003;
}

:where(html[data-ps-theme="studio"][data-ps-window="hub"][data-ps-screen="app"]) #ps-theme-switcher:hover {
  border-color: var(--ps-gold);
  color: var(--ps-ink);
}

@media (max-width: 760px) {
  :where(html[data-ps-theme="studio"][data-ps-window="hub"][data-ps-screen="app"]) #appHeader {
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
    padding: 10px 14px;
  }
  :where(html[data-ps-theme="studio"][data-ps-window="hub"][data-ps-screen="app"]) #appHeader > .logo {
    gap: 6px;
  }
  :where(html[data-ps-theme="studio"][data-ps-window="hub"][data-ps-screen="app"]) #headerStudioName {
    flex: 1;
    max-width: none;
    font-size: 10px;
  }
  :where(html[data-ps-theme="studio"][data-ps-window="hub"][data-ps-screen="app"]) #appHeader > .user-info {
    justify-content: space-between;
  }
  :where(html[data-ps-theme="studio"][data-ps-window="hub"][data-ps-screen="app"]) #userEmail {
    max-width: calc(100vw - 130px);
  }
  :where(html[data-ps-theme="studio"][data-ps-window="hub"][data-ps-screen="app"]) #appContainer {
    --ps-shell-header-height: 88px;
  }
  /* Retain New Project's existing horizontal navigation at this breakpoint. */
  :where(html[data-ps-theme="studio"][data-ps-window="hub"][data-ps-screen="app"]) #appContainer:has(> main > #section-project-new:not(.hidden))::before {
    width: 100%;
    height: 0;
    border: 0;
  }
  :where(html[data-ps-theme="studio"][data-ps-window="hub"][data-ps-screen="app"]) #appContainer:has(> main > #section-project-new:not(.hidden)) > #mainNav {
    height: auto;
    max-height: none;
    overflow-y: hidden;
  }
  :where(html[data-ps-theme="studio"][data-ps-window="hub"][data-ps-screen="app"]) #appContainer.nav-collapsed:has(> main > #section-project-new:not(.hidden)) > #mainNav {
    height: 0;
  }
}

/* Shared native quota portal: no application ownership is required.
   Keep the HUB gate outside :where() so this common paint takes precedence
   over older application portal paint, including inline historical colors.
   All dimensions, font metrics, top-layer handling and events stay historical. */
html[data-ps-theme="studio"][data-ps-window="hub"][data-ps-screen="app"] #quotaUploadModal {
  background: #0009 !important;
  color: var(--ps-text) !important;
}

html[data-ps-theme="studio"][data-ps-window="hub"][data-ps-screen="app"] #quotaUploadModal [data-ps-quota-ui="card"] {
  background: var(--ps-surface-solid) !important;
  color: var(--ps-text) !important;
  border-color: var(--ps-line) !important;
  box-shadow: 0 24px 60px #0006 !important;
}

html[data-ps-theme="studio"][data-ps-window="hub"][data-ps-screen="app"] #quotaUploadModal :is([data-ps-quota-ui="header"], [data-ps-quota-ui="actions"]) {
  border-color: var(--ps-line) !important;
}

html[data-ps-theme="studio"][data-ps-window="hub"][data-ps-screen="app"] #quotaUploadModal #quotaUploadTitle {
  color: var(--ps-ink) !important;
}

html[data-ps-theme="studio"][data-ps-window="hub"][data-ps-screen="app"] #quotaUploadModal [data-ps-quota-ui="body"] {
  color: var(--ps-text) !important;
}

html[data-ps-theme="studio"][data-ps-window="hub"][data-ps-screen="app"] #quotaUploadModal .muted {
  color: var(--ps-muted) !important;
}

html[data-ps-theme="studio"][data-ps-window="hub"][data-ps-screen="app"] #quotaUploadModal [data-ps-quota-ui="body"] strong {
  color: var(--ps-text) !important;
}

html[data-ps-theme="studio"][data-ps-window="hub"][data-ps-screen="app"] #quotaUploadModal :is([data-ps-quota-ui="actions"], [data-ps-quota-ui="notice"]) {
  background: var(--ps-bg-soft) !important;
  border-color: var(--ps-line) !important;
  color: var(--ps-text) !important;
}

/* The functional colors already used by the migrated quota portals. */
html[data-ps-theme="studio"][data-ps-window="hub"][data-ps-screen="app"] #quotaUploadModal [data-ps-quota-ui="success"] {
  background: #123b2d !important;
  color: #a7e3bd !important;
  border-color: #4c8b6466 !important;
}

html[data-ps-theme="studio"][data-ps-window="hub"][data-ps-screen="app"] #quotaUploadModal [data-ps-quota-ui="error"] {
  background: #451f24 !important;
  color: #ffb4b4 !important;
  border-color: #ad666666 !important;
}

html[data-ps-theme="studio"][data-ps-window="hub"][data-ps-screen="app"] #quotaUploadModal button {
  background: var(--ps-surface-soft) !important;
  color: var(--ps-text) !important;
  border-color: var(--ps-line-strong) !important;
  box-shadow: none !important;
}

html[data-ps-theme="studio"][data-ps-window="hub"][data-ps-screen="app"] #quotaUploadModal button:hover:not(:disabled) {
  background: var(--ps-bg-soft) !important;
  border-color: var(--ps-gold) !important;
}

html[data-ps-theme="studio"][data-ps-window="hub"][data-ps-screen="app"] #quotaUploadModal #quotaUploadConfirmBtn {
  background: var(--ps-button-bg) !important;
  color: var(--ps-button-text) !important;
  border-color: var(--ps-button-border) !important;
  box-shadow: var(--ps-button-shadow) !important;
}

html[data-ps-theme="studio"][data-ps-window="hub"][data-ps-screen="app"] #quotaUploadModal #quotaUploadConfirmBtn:hover:not(:disabled) {
  background: var(--ps-button-hover) !important;
}

html[data-ps-theme="studio"][data-ps-window="hub"][data-ps-screen="app"] #quotaUploadModal button:disabled {
  box-shadow: none !important;
}

html[data-ps-theme="studio"][data-ps-window="hub"][data-ps-screen="app"] #quotaUploadModal button:focus-visible {
  outline: 2px solid var(--ps-focus) !important;
  outline-offset: 3px;
}

@media (prefers-reduced-motion: reduce) {
  :where(html[data-ps-theme="studio"][data-ps-window="hub"][data-ps-screen="app"]) #mainNav,
  :where(html[data-ps-theme="studio"][data-ps-window="hub"][data-ps-screen="app"]) #mainNav > button,
  :where(html[data-ps-theme="studio"][data-ps-window="hub"][data-ps-screen="app"]) #navToggleBtn,
  :where(html[data-ps-theme="studio"][data-ps-window="hub"][data-ps-screen="app"]) #appHeader > .user-info > button {
    transition: none;
  }
}
