/* App Shell V2 foundations. Visual shell rules are added feature-by-feature. */
:root {
  --vix-layout-mode: wide;
  --vix-visual-viewport-block-size: 100vh;
  --vix-visual-viewport-block-size: 100svh;
  --vix-visual-viewport-block-size: 100dvh;
  --vix-shell-safe-top: env(safe-area-inset-top, 0px);
  --vix-shell-safe-right: env(safe-area-inset-right, 0px);
  --vix-shell-safe-bottom: env(safe-area-inset-bottom, 0px);
  --vix-shell-safe-left: env(safe-area-inset-left, 0px);
  --vix-z-shell: 100;
  --vix-z-sticky-action: 800;
  --vix-z-drawer-scrim: 1200;
  --vix-z-drawer: 1210;
  --vix-z-modal: 2000;
}

/* Structural shell identity changes only at the two approved boundaries. */
@media (max-width: 1179px) {
  :root {
    --vix-layout-mode: compact;
  }
}

@media (max-width: 767px) {
  :root {
    --vix-layout-mode: phone;
  }
}

/* App Shell V2 is inert unless the staged flag adds this body class. */
body.vix-app-shell-v2 {
  --vix-topbar-height: 56px;
  --vix-shell-top-inset: calc(var(--vix-topbar-height) + var(--vix-shell-safe-top));
  --vix-content-block-size: calc(var(--vix-visual-viewport-block-size) - var(--vix-shell-top-inset));
}

.vix-icon-button {
  inline-size: 48px;
  block-size: 48px;
  min-inline-size: 48px;
  min-block-size: 48px;
  flex: 0 0 48px;
  aspect-ratio: 1;
  padding: 0;
}

.vix-icon-button > svg {
  inline-size: 22px;
  block-size: 22px;
}

.vix-overlay-host {
  position: fixed;
  inset: 0;
  z-index: var(--vix-z-modal);
  width: 100vw;
  height: var(--vix-visual-viewport-block-size);
  overflow: visible;
  pointer-events: none;
}

[data-vix-capability-hidden="true"] {
  display: none !important;
}

.vix-capability-notice {
  position: fixed;
  z-index: calc(var(--vix-z-modal) + 2);
  left: 50%;
  bottom: calc(20px + var(--vix-shell-safe-bottom));
  max-width: min(92vw, 440px);
  transform: translateX(-50%);
  padding: 12px 16px;
  border: 1px solid rgba(255, 46, 187, 0.55);
  border-radius: 12px;
  background: rgba(20, 18, 27, 0.96);
  color: #fff;
  box-shadow: 0 12px 36px rgba(0, 0, 0, 0.48);
  font-size: 0.88rem;
  text-align: center;
  pointer-events: none;
}

.vix-capability-notice[hidden] {
  display: none !important;
}

.vix-overlay-host > * {
  pointer-events: auto;
}

body.vix-overlay-open {
  overflow: hidden !important;
}

body.vix-app-shell-v2 .lightbox-modal {
  inset: 0;
  width: 100%;
  height: var(--vix-visual-viewport-block-size);
  padding:
    max(16px, var(--vix-shell-safe-top))
    max(16px, var(--vix-shell-safe-right))
    max(16px, var(--vix-shell-safe-bottom))
    max(16px, var(--vix-shell-safe-left));
  box-sizing: border-box;
}

body.vix-app-shell-v2 .lightbox-image {
  max-width: 100%;
  max-height: 100%;
}

body.vix-app-shell-v2 .lightbox-close {
  top: max(12px, var(--vix-shell-safe-top));
  right: max(12px, var(--vix-shell-safe-right));
}

body.vix-app-shell-v2 .mobile-dashboard,
body.vix-app-shell-v2 .mobile-back-bar,
body.vix-app-shell-v2 .mobile-swipe-indicator {
  display: none !important;
}

body.vix-app-shell-v2 .hamburger-btn {
  display: flex !important;
  min-width: 44px;
  min-height: 44px;
  align-items: center;
  justify-content: center;
}

body.vix-app-shell-v2 .top-navbar {
  height: calc(var(--vix-topbar-height) + var(--vix-shell-safe-top));
  padding: var(--vix-shell-safe-top) max(12px, var(--vix-shell-safe-right)) 0 max(12px, var(--vix-shell-safe-left));
  z-index: var(--vix-z-shell);
}

body.vix-app-shell-v2 .vix-topbar-title {
  display: none;
  min-width: 0;
  margin-left: auto;
  color: var(--text-secondary);
  font-size: 0.9rem;
  font-weight: 700;
  text-overflow: ellipsis;
  overflow: hidden;
  white-space: nowrap;
}

body.vix-app-shell-v2 .vix-drawer-header,
body.vix-app-shell-v2 .vix-nav-section-label {
  display: none;
}

body.vix-app-shell-v2 .container {
  top: var(--vix-shell-top-inset);
  height: var(--vix-content-block-size);
  min-height: 0;
  overflow: hidden;
}

body.vix-app-shell-v2 .tab-section[data-vix-scroll-contract] {
  width: 100%;
  height: 100%;
  min-width: 0;
  min-height: 0;
  max-height: 100%;
  overflow: hidden !important;
}

body.vix-app-shell-v2 [data-vix-scroll-owner] {
  min-width: 0;
  min-height: 0;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

body.vix-app-shell-v2 [data-vix-scroll-contract="page"] > [data-vix-scroll-owner],
body.vix-app-shell-v2 [data-vix-scroll-contract="page"][data-vix-scroll-owner] {
  height: 100%;
  max-height: 100%;
  overflow-y: auto !important;
  overflow-x: hidden;
}

body.vix-app-shell-v2 #marketplaceSection > .marketplace-page,
body.vix-app-shell-v2 #educationSection > .education-page {
  width: 100%;
  box-sizing: border-box;
}

body.vix-app-shell-v2 #educationSection[data-vix-scroll-contract="workspace"] {
  height: 100% !important;
  min-height: 0 !important;
  overflow: hidden !important;
}

body.vix-app-shell-v2 #librarySection > .library-container {
  height: 100%;
  min-height: 0;
  overflow: hidden;
}

body.vix-app-shell-v2 #librarySection .library-grid-wrapper {
  height: 100%;
  min-height: 0;
  overflow-y: auto !important;
}

body.vix-app-shell-v2 #videoSection[data-vix-scroll-contract="workspace"],
body.vix-app-shell-v2 #editSection[data-vix-scroll-contract="workspace"] {
  height: 100% !important;
  min-height: 0 !important;
  max-height: 100%;
}

body.vix-app-shell-v2 #videoSection .video-workspace-stage,
body.vix-app-shell-v2 #videoSection .video-workspace-panel,
body.vix-app-shell-v2 #editSection .edit-subtab-content.active {
  min-height: 0;
}

body.vix-app-shell-v2 #videoSection [data-vix-scroll-owner="video"],
body.vix-app-shell-v2 #editSection [data-vix-scroll-owner="edit"] {
  overflow-y: auto !important;
  overflow-x: hidden;
}

body.vix-app-shell-v2 #imageSection[data-vix-scroll-contract="floating-action"].active {
  position: relative;
  display: block !important;
  overflow: hidden !important;
  --vix-image-composer-clearance: 220px;
}

body.vix-app-shell-v2 #imageSection.image-command-mode > .right-panel {
  position: absolute;
  inset: 0;
  width: 100% !important;
  height: 100% !important;
  min-height: 0 !important;
  max-height: 100%;
  box-sizing: border-box;
  padding-bottom: var(--vix-image-composer-clearance) !important;
  overflow-y: auto !important;
  overflow-x: hidden !important;
}

body.vix-app-shell-v2 #imageSection.image-command-mode > .image-command-overlay {
  position: absolute;
  inset: auto 0 0;
  z-index: var(--vix-z-sticky, 120);
  display: flex;
  justify-content: center;
  width: 100%;
  padding: 0 24px max(16px, var(--vix-shell-safe-bottom));
  box-sizing: border-box;
  pointer-events: none;
}

body.vix-app-shell-v2 #imageSection.image-command-mode > .image-command-overlay > .image-command-bar {
  position: relative !important;
  inset: auto !important;
  width: min(1200px, calc(100% - 48px));
  max-width: none;
  margin: 0;
  flex: 0 0 auto;
  pointer-events: auto;
}

@media (min-width: 901px) {
  body.vix-app-shell-v2 #imageSection.image-command-mode.show-image-advanced.image-more-dock-left > .image-command-overlay {
    padding-left: calc(var(--image-more-dock-width) + var(--image-more-dock-gap) + 44px);
  }

  body.vix-app-shell-v2 #imageSection.image-command-mode.show-image-advanced.image-more-dock-right > .image-command-overlay {
    padding-right: calc(var(--image-more-dock-width) + var(--image-more-dock-gap) + 44px);
  }
}

body.vix-app-shell-v2 #captionSection[data-vix-scroll-contract="split"].active,
body.vix-app-shell-v2 #captionSection .caption-layout,
body.vix-app-shell-v2 #captionSection .caption-container {
  height: 100% !important;
  min-height: 0 !important;
  max-height: 100%;
  overflow: hidden !important;
}

body.vix-app-shell-v2 #captionSection .caption-chat-area {
  min-height: 0;
  overflow-y: auto !important;
}

body.vix-app-shell-v2 #captionSection .caption-input-container {
  position: relative;
  flex: 0 0 auto;
  padding: 12px max(12px, var(--vix-shell-safe-right)) max(12px, var(--vix-shell-safe-bottom)) max(12px, var(--vix-shell-safe-left));
}

body.vix-app-shell-v2 #captionSection .caption-input-wrapper {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
  width: min(100%, 768px);
  max-width: 100%;
  padding: 6px;
  border-radius: 28px;
  box-sizing: border-box;
}

body.vix-app-shell-v2 #captionSection .caption-input {
  min-width: 0;
  width: 100%;
}

body.vix-app-shell-v2 #captionSection :is(.caption-attach-btn, .caption-send-btn) {
  width: 48px;
  height: 48px;
  min-width: 48px;
  min-height: 48px;
  padding: 0;
  border-radius: 50%;
}

body.vix-app-shell-v2.landing-visible .container {
  display: none !important;
}

body.vix-app-shell-v2 .nav-tab:focus-visible,
body.vix-app-shell-v2 .vix-drawer-close:focus-visible,
body.vix-app-shell-v2 .hamburger-btn:focus-visible {
  outline: 3px solid #28a9ff;
  outline-offset: -3px;
}

@media (max-width: 1179px) {
  body.vix-app-shell-v2:not(.landing-visible) .container {
    display: flex !important;
    position: fixed !important;
    inset: var(--vix-shell-top-inset) 0 auto 0 !important;
    width: 100% !important;
    height: var(--vix-content-block-size) !important;
    min-height: 0 !important;
    margin: 0 !important;
    padding: 0 0 var(--vix-shell-safe-bottom) !important;
    flex-direction: row !important;
    overflow: hidden;
  }

  body.vix-app-shell-v2 .top-navbar {
    display: flex;
  }

  body.vix-app-shell-v2 .navbar-brand {
    min-width: 0;
  }

  body.vix-app-shell-v2 .vix-topbar-title {
    display: block;
  }

  body.vix-app-shell-v2 .main-nav,
  body.vix-app-shell-v2 .container.mobile-tool-active .main-nav,
  body.vix-app-shell-v2 .main-nav.collapsed {
    display: flex !important;
    position: fixed !important;
    inset: calc(var(--vix-topbar-height) + var(--vix-shell-safe-top)) auto 0 0 !important;
    width: min(320px, calc(100vw - 24px)) !important;
    height: auto !important;
    padding: 0 0 var(--vix-shell-safe-bottom) !important;
    background: linear-gradient(180deg, #17131d 0%, #0b0d13 100%);
    border-right: 1px solid rgba(255,255,255,0.12);
    box-shadow: 20px 0 60px rgba(0,0,0,0.48);
    transform: translateX(-105%) !important;
    transition: transform 180ms ease;
    overflow: hidden;
    z-index: var(--vix-z-drawer);
  }

  body.vix-app-shell-v2 .main-nav.mobile-open {
    transform: translateX(0) !important;
  }

  body.vix-app-shell-v2 .mobile-overlay {
    display: block !important;
    position: fixed !important;
    inset: calc(var(--vix-topbar-height) + var(--vix-shell-safe-top)) 0 0 0 !important;
    background: rgba(3, 3, 8, 0.68);
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: opacity 180ms ease, visibility 180ms ease;
    z-index: var(--vix-z-drawer-scrim);
  }

  body.vix-app-shell-v2 .mobile-overlay.active {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
  }

  body.vix-app-shell-v2.vix-drawer-open {
    overflow: hidden;
  }

  body.vix-app-shell-v2 .vix-drawer-header {
    display: flex;
    flex: 0 0 auto;
    align-items: center;
    justify-content: space-between;
    min-height: 64px;
    padding: 10px 14px 10px 18px;
    border-bottom: 1px solid rgba(255,255,255,0.08);
    background: rgba(14, 13, 20, 0.96);
  }

  body.vix-app-shell-v2 .vix-drawer-brand {
    display: flex;
    align-items: center;
    gap: 12px;
    color: var(--text-primary);
    font-size: 0.84rem;
    font-weight: 800;
    letter-spacing: 0.12em;
    text-transform: uppercase;
  }

  body.vix-app-shell-v2 .vix-drawer-brand img {
    display: block;
    width: auto;
    height: 36px;
  }

  body.vix-app-shell-v2 .vix-drawer-close {
    width: 44px;
    height: 44px;
    border: 1px solid rgba(255,255,255,0.12);
    border-radius: 12px;
    background: rgba(255,255,255,0.05);
    color: var(--text-primary);
    font-size: 1.65rem;
    line-height: 1;
    cursor: pointer;
  }

  body.vix-app-shell-v2 .nav-tabs-container {
    display: flex;
    flex: 1 1 auto;
    flex-direction: column;
    align-items: stretch;
    gap: 4px;
    min-height: 0;
    padding: 10px 12px 18px;
    overflow: auto;
    overscroll-behavior: contain;
    scrollbar-gutter: stable;
  }

  body.vix-app-shell-v2 .vix-nav-section-label {
    display: block;
    margin: 15px 10px 5px;
    color: #8f8a99;
    font-size: 0.68rem;
    font-weight: 900;
    letter-spacing: 0.16em;
    text-transform: uppercase;
  }

  body.vix-app-shell-v2 .nav-tab,
  body.vix-app-shell-v2 .nav-tab.coming-soon-tab {
    display: flex;
    flex: 0 0 auto;
    width: 100%;
    min-height: 52px;
    padding: 8px 12px;
    flex-direction: row;
    align-items: center;
    justify-content: flex-start;
    gap: 14px;
    border: 1px solid transparent;
    border-radius: 14px;
    color: var(--text-secondary);
    text-align: left;
  }

  body.vix-app-shell-v2 .nav-tab:hover {
    background: rgba(255,255,255,0.06);
  }

  body.vix-app-shell-v2 .nav-tab.active {
    background: linear-gradient(90deg, rgba(255,46,187,0.18), rgba(39,165,255,0.12));
    border-color: rgba(255,46,187,0.35);
    color: var(--text-primary);
  }

  body.vix-app-shell-v2 .nav-tab::before {
    display: none !important;
  }

  body.vix-app-shell-v2 .nav-icon {
    flex: 0 0 28px;
    width: 28px;
    height: 28px;
    display: grid;
    place-items: center;
    margin: 0;
  }

  body.vix-app-shell-v2 .nav-label {
    display: flex !important;
    flex: 1 1 auto;
    align-items: center;
    justify-content: space-between;
    min-width: 0;
    font-size: 0.95rem;
    font-weight: 750;
    writing-mode: horizontal-tb !important;
  }

  body.vix-app-shell-v2 .user-area {
    position: static;
    display: grid;
    flex: 0 0 auto;
    grid-template-columns: 44px 44px minmax(0, 1fr);
    align-items: center;
    gap: 8px;
    width: auto;
    min-height: 70px;
    margin: 0;
    padding: 10px 14px max(10px, var(--vix-shell-safe-bottom));
    border-top: 1px solid rgba(255,255,255,0.08);
    background: rgba(14, 13, 20, 0.98);
  }

  body.vix-app-shell-v2 .theme-toggle,
  body.vix-app-shell-v2 .user-avatar {
    width: 44px;
    height: 44px;
    margin: 0;
  }

  body.vix-app-shell-v2 .user-credits {
    min-width: 0;
    margin: 0;
    padding: 8px 10px;
    text-align: center;
    text-overflow: ellipsis;
    overflow: hidden;
  }

  body.vix-app-shell-v2 .tab-section {
    min-width: 0;
  }
}

@media (max-width: 767px) {
  body.vix-app-shell-v2 .navbar-brand-sub {
    display: none;
  }

  body.vix-app-shell-v2 .navbar-logo {
    height: 34px;
  }

  body.vix-app-shell-v2 #imageSection.image-command-mode > .image-command-overlay {
    padding: 0 12px max(10px, var(--vix-shell-safe-bottom));
  }

  body.vix-app-shell-v2 #imageSection.image-command-mode > .image-command-overlay > .image-command-bar {
    width: 100%;
  }

  body.vix-app-shell-v2 #captionSection .caption-chat-area {
    padding: 20px 12px 12px;
  }
}

@media (prefers-reduced-motion: reduce) {
  body.vix-app-shell-v2 .main-nav,
  body.vix-app-shell-v2 .mobile-overlay {
    transition: none;
  }
}

@media (forced-colors: active) {
  body.vix-app-shell-v2 .nav-tab.active,
  body.vix-app-shell-v2 .vix-drawer-close,
  body.vix-app-shell-v2 .hamburger-btn {
    border: 2px solid ButtonText;
  }
}
