/* IuVe Unified App Shell — SSOT for internal app layout/sidebar/drawer. */
:root {
  --iuve-shell-sidebar-width: 260px;
  --iuve-shell-sidebar-collapsed-width: 72px;
  --iuve-shell-topbar-height: 58px;
  --iuve-shell-bg: #ffffff;
  --iuve-shell-sidebar-bg: #ffffff;
  --iuve-shell-border: #e5e7eb;
  --iuve-shell-text: #111827;
  --iuve-shell-muted: #64748b;
  --iuve-shell-hover: #f3f4f6;
  --iuve-shell-active: #eef2ff;
  --iuve-shell-active-text: #1d4ed8;
  --iuve-z-base: 1;
  --iuve-z-sidebar: 40;
  --iuve-z-topbar: 1200;
  --iuve-z-overlay: 1500;
  --iuve-z-drawer: 1600;
  --iuve-z-dropdown: 10000;
  --iuve-z-modal: 13000;
}

html, body { min-height: 100%; }
body { margin: 0; overflow-x: hidden; background: var(--iuve-shell-bg); }
body.iuve-shell-lock { overflow: hidden !important; }

/* Neutralize old dashboard/workspace/sidebar layout ownership inside the unified shell. */
.iuve-shell.app-shell:not(.app-shell-v2),
body.iuve-shell.app-shell:not(.app-shell-v2) {
  display: grid !important;
  grid-template-columns: var(--iuve-shell-sidebar-width) minmax(0, 1fr) !important;
  min-height: 100vh !important;
  height: 100vh !important;
  width: 100% !important;
  max-width: none !important;
  overflow: hidden !important;
  background: var(--iuve-shell-bg) !important;
}
.iuve-shell.app-shell::before,
.iuve-shell.app-shell::after,
body.iuve-shell.app-shell::before,
body.iuve-shell.app-shell::after {
  content: none !important;
  display: none !important;
  pointer-events: none !important;
}
.iuve-shell.nav-hidden,
.iuve-shell.nav-collapsed {
  grid-template-columns: var(--iuve-shell-sidebar-width) minmax(0, 1fr) !important;
}

.iuve-shell .app-content,
.iuve-shell .iuve-main {
  grid-column: 2 !important;
  min-width: 0 !important;
  width: 100% !important;
  max-width: none !important;
  min-height: 100vh !important;
  height: 100vh !important;
  overflow-y: auto !important;
  overflow-x: hidden !important;
  background: #fff !important;
  position: relative !important;
  display: flex !important;
  flex-direction: column !important;
}

/* Sidebar */
.iuve-sidebar,
.iuve-shell #app-side-nav,
.iuve-shell .side-nav,
.iuve-shell .sidebar-v2 {
  grid-column: 1 !important;
  position: sticky !important;
  top: 0 !important;
  left: 0 !important;
  transform: none !important;
  width: var(--iuve-shell-sidebar-width) !important;
  min-width: var(--iuve-shell-sidebar-width) !important;
  max-width: var(--iuve-shell-sidebar-width) !important;
  height: 100vh !important;
  min-height: 100vh !important;
  display: flex !important;
  flex-direction: column !important;
  z-index: var(--iuve-z-sidebar) !important;
  background: var(--iuve-shell-sidebar-bg) !important;
  color: var(--iuve-shell-text) !important;
  border-right: 1px solid var(--iuve-shell-border) !important;
  box-shadow: none !important;
  overflow: hidden !important;
}

.iuve-sidebar__header,
.iuve-shell .side-nav-header,
.iuve-shell .sidebar-v2__header {
  height: 58px !important;
  min-height: 58px !important;
  display: flex !important;
  align-items: center !important;
  justify-content: space-between !important;
  gap: 8px !important;
  padding: 0 12px !important;
  border-bottom: 1px solid var(--iuve-shell-border) !important;
  background: #fff !important;
}
.iuve-shell .side-nav-brand,
.iuve-shell .sidebar-v2__brand {
  display: inline-flex !important;
  align-items: center !important;
  gap: 10px !important;
  min-width: 0 !important;
  text-decoration: none !important;
  color: var(--iuve-shell-text) !important;
  font-weight: 600 !important;
}
.iuve-shell .side-nav-logo,
.iuve-shell .sidebar-v2__logo { width: 24px !important; height: 24px !important; display: block !important; }
.iuve-shell .side-nav-brand-text,
.iuve-shell .sidebar-v2__brand-text { font-size: 16px !important; line-height: 1 !important; white-space: nowrap !important; }

.iuve-shell .side-nav-scroll,
.iuve-shell .sidebar-v2__scroll {
  flex: 1 1 auto !important;
  overflow-y: auto !important;
  overflow-x: hidden !important;
  padding: 10px 8px 12px !important;
  scrollbar-width: thin !important;
}
.iuve-shell .side-nav-footer,
.iuve-shell .sidebar-v2__footer {
  flex: 0 0 auto !important;
  padding: 8px !important;
  border-top: 1px solid var(--iuve-shell-border) !important;
  background: #fff !important;
}

.iuve-shell.app-shell-v2 .sidebar-v2__section,
.iuve-shell.app-shell-v2 .side-nav-section {
  border-bottom: 0 !important;
}
.iuve-shell .sidebar-v2__section:last-child { border-bottom: 0 !important; }
.iuve-shell .sidebar-v2__section-label,
.iuve-shell .side-nav-subcontrol-label {
  display: block !important;
  padding: 8px 8px 6px !important;
  margin: 0 !important;
  color: var(--iuve-shell-muted) !important;
  font-size: 11px !important;
  font-weight: 700 !important;
  letter-spacing: .065em !important;
  text-transform: uppercase !important;
}

.iuve-shell .sidebar-v2__item,
.iuve-shell .side-nav-action,
.iuve-shell .side-nav-new-chat,
.iuve-shell .side-nav-logout-btn {
  width: 100% !important;
  min-height: 38px !important;
  display: flex !important;
  align-items: center !important;
  gap: 12px !important;
  padding: 8px 10px !important;
  border-radius: 10px !important;
  border: 0 !important;
  background: transparent !important;
  color: #172033 !important;
  text-decoration: none !important;
  font: inherit !important;
  text-align: left !important;
  cursor: pointer !important;
  box-shadow: none !important;
}
.iuve-shell .sidebar-v2__item:hover,
.iuve-shell .side-nav-action:hover,
.iuve-shell .side-nav-new-chat:hover,
.iuve-shell .side-nav-logout-btn:hover { background: var(--iuve-shell-hover) !important; color: #0f172a !important; }
.iuve-shell:not(.app-shell-v2) .sidebar-v2__item.active,
.iuve-shell:not(.app-shell-v2) .side-nav-action.active { background: var(--iuve-shell-active) !important; color: var(--iuve-shell-active-text) !important; font-weight: 600 !important; }
.iuve-shell .sidebar-v2__item-icon,
.iuve-shell .side-nav-link-icon { width: 20px !important; height: 20px !important; min-width: 20px !important; display: inline-flex !important; align-items: center !important; justify-content: center !important; color: currentColor !important; }
.iuve-shell .sidebar-v2__item-icon svg,
.iuve-shell .side-nav-link-icon svg { width: 20px !important; height: 20px !important; }
.iuve-shell .sidebar-v2__item-label,
.iuve-shell .side-nav-link-text,
.iuve-shell .side-nav-logout-text { display: inline-block !important; overflow: hidden !important; text-overflow: ellipsis !important; white-space: nowrap !important; }

.iuve-shell .sidebar-v2__primary-actions { display: grid !important; gap: 4px !important; }
.iuve-shell .side-nav-subcontrols { padding: 4px 6px 0 !important; }
.iuve-shell .side-nav-subcontrol { position: relative !important; }
.iuve-shell .side-nav-subcontrol-row { display: flex !important; align-items: center !important; gap: 6px !important; }
.iuve-shell .side-nav-subcontrol-select {
  flex: 1 1 auto !important;
  min-width: 0 !important;
  height: 34px !important;
  border: 0 !important;
  background: transparent !important;
  color: #172033 !important;
  font: inherit !important;
}
.iuve-shell .side-nav-subcontrol-chip,
.iuve-shell .mode-chip.side-nav-subcontrol-chip {
  width: 34px !important;
  height: 34px !important;
  min-width: 34px !important;
  border-radius: 10px !important;
  border: 1px solid #cbd5e1 !important;
  background: #fff !important;
  color: #0f172a !important;
  display: inline-flex !important;
  align-items: center !important;
  justify-content: center !important;
  padding: 0 !important;
}
.iuve-shell .side-nav-subcontrol-status { margin: 2px 0 0 !important; padding: 0 2px !important; font-size: 11px !important; color: var(--iuve-shell-muted) !important; }
.iuve-shell .side-nav-actions-popover {
  position: absolute !important;
  z-index: var(--iuve-z-dropdown) !important;
  top: 38px !important;
  right: 0 !important;
  width: 210px !important;
  background: #fff !important;
  border: 1px solid var(--iuve-shell-border) !important;
  border-radius: 12px !important;
  box-shadow: 0 18px 42px rgba(15, 23, 42, .16) !important;
  padding: 6px !important;
}
.iuve-shell .side-nav-project-action { width: 100% !important; display: flex !important; gap: 8px !important; align-items: center !important; border: 0 !important; background: transparent !important; padding: 8px !important; border-radius: 8px !important; text-align: left !important; }
.iuve-shell .side-nav-project-action:hover { background: #f8fafc !important; }
.iuve-shell .side-nav-project-action--danger { color: #dc2626 !important; }

.iuve-shell .sidebar-v2__toggle,
.iuve-shell .side-nav-shell-toggle,
.iuve-shell .sidebar-v2__topbar-toggle,
.iuve-mobile-topbar__toggle {
  width: 34px !important;
  height: 34px !important;
  min-width: 34px !important;
  display: inline-flex !important;
  align-items: center !important;
  justify-content: center !important;
  border: 0 !important;
  background: transparent !important;
  color: #1f2937 !important;
  border-radius: 10px !important;
  padding: 0 !important;
  cursor: pointer !important;
}
.iuve-shell .sidebar-v2__toggle:hover,
.iuve-mobile-topbar__toggle:hover { background: var(--iuve-shell-hover) !important; }
.iuve-shell .sidebar-v2__toggle svg,
.iuve-mobile-topbar__toggle svg { width: 20px !important; height: 20px !important; }
.iuve-shell:not(.app-shell-v2) .sidebar-v2__toggle--expand { display: none !important; }
.iuve-shell:not(.app-shell-v2) .sidebar-v2__toggle--close-mobile { display: none !important; }

@media (min-width: 768px) {
  .iuve-shell.app-shell-v2.nav-collapsed .sidebar-v2__toggle--collapse,
  .iuve-shell.app-shell-v2.nav-collapsed .side-nav-collapse-btn,
  .iuve-shell.app-shell-v2.nav-collapsed #nav-collapse-sidebar {
    display: none !important;
  }
}

.iuve-overlay {
  position: fixed !important;
  inset: 0 !important;
  z-index: var(--iuve-z-overlay) !important;
  border: 0 !important;
  padding: 0 !important;
  margin: 0 !important;
  background: rgba(15, 23, 42, .36) !important;
  opacity: 0 !important;
  pointer-events: none !important;
  transition: opacity .18s ease !important;
}
.iuve-overlay[hidden] { display: none !important; }

.iuve-shell:not(.app-shell-v2) .workspace-mobile-nav,
.iuve-shell:not(.app-shell-v2) .iuve-mobile-topbar {
  display: none !important;
}
.iuve-shell:not(.app-shell-v2) .shell-open-fab { display: none !important; }

/* Page content must be the fluid center column. */
.iuve-shell main,
.iuve-shell .dashboard-layout,
.iuve-shell .workspace-layout,
.iuve-shell .marketplace-layout,
.iuve-shell #unified-main,
.iuve-shell .ic-page {
  width: 100% !important;
  max-width: none !important;
  min-width: 0 !important;
  box-sizing: border-box !important;
}
.iuve-shell .dashboard-layout,
.iuve-shell .workspace-layout,
.iuve-shell .marketplace-layout { padding-left: clamp(16px, 3vw, 32px) !important; padding-right: clamp(16px, 3vw, 32px) !important; }

/* Chat page: ChatGPT-like central column while shell remains full-width. */
body[data-page="iuve-chat"] .iuve-shell .app-content { overflow: hidden !important; }
body[data-page="iuve-chat"] .iuve-shell #unified-main { flex: 1 1 auto !important; min-height: 0 !important; display: flex !important; flex-direction: column !important; overflow: hidden !important; }
body[data-page="iuve-chat"] .iuve-shell .unified-wrap,
body[data-page="iuve-chat"] .iuve-shell .unified-card { width: 100% !important; max-width: none !important; min-width: 0 !important; flex: 1 1 auto !important; }
body[data-page="iuve-chat"] .iuve-shell #unified-messages { max-width: 860px !important; width: min(100%, 860px) !important; margin-left: auto !important; margin-right: auto !important; padding-left: 16px !important; padding-right: 16px !important; }
body[data-page="iuve-chat"] .iuve-shell #unified-composer-area { max-width: 860px !important; width: min(calc(100% - 32px), 860px) !important; margin-left: auto !important; margin-right: auto !important; }

/* Legacy iuve-overlay only; sidebar v2 uses #sidebar-v2-overlay via drawer CSS. */

@media (min-width: 768px) and (max-width: 1023px) {
  .iuve-shell.app-shell:not(.app-shell-v2),
  body.iuve-shell.app-shell:not(.app-shell-v2) { grid-template-columns: var(--iuve-shell-sidebar-width) minmax(0, 1fr) !important; }
}

@media (max-width: 767px) {
  .app-shell.app-shell-v2.iuve-shell,
  body.iuve-shell.app-shell-v2 {
    display: grid !important;
    grid-template-columns: var(--sidebar-v2-collapsed, 56px) minmax(0, 1fr) !important;
    height: auto !important;
    overflow: visible !important;
  }

  .app-shell.app-shell-v2 .app-content,
  .app-shell.app-shell-v2 .iuve-main {
    grid-column: auto !important;
    width: auto !important;
    height: auto !important;
    min-height: 0 !important;
    padding-top: 0 !important;
  }

  .app-shell.app-shell-v2 .workspace-mobile-nav,
  .app-shell.app-shell-v2 .iuve-mobile-topbar {
    display: none !important;
  }

  .iuve-shell.app-shell:not(.app-shell-v2),
  body.iuve-shell.app-shell:not(.app-shell-v2) {
    display: block !important;
    grid-template-columns: none !important;
    height: 100vh !important;
    overflow: hidden !important;
  }
  .iuve-shell .app-content,
  .iuve-shell .iuve-main {
    grid-column: auto !important;
    width: 100% !important;
    height: 100vh !important;
    min-height: 100vh !important;
    padding-top: var(--iuve-shell-topbar-height) !important;
  }
  .workspace-mobile-nav,
  .iuve-mobile-topbar {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    height: var(--iuve-shell-topbar-height) !important;
    z-index: var(--iuve-z-topbar) !important;
    display: flex !important;
    align-items: center !important;
    gap: 10px !important;
    padding: 0 12px !important;
    background: rgba(255,255,255,.96) !important;
    backdrop-filter: blur(14px) !important;
    border-bottom: 1px solid var(--iuve-shell-border) !important;
  }
  .iuve-mobile-topbar__brand { display: inline-flex !important; align-items: center !important; gap: 9px !important; font-weight: 600 !important; color: #111827 !important; }
  .iuve-mobile-topbar__logo { width: 24px !important; height: 24px !important; }
  .iuve-mobile-topbar__title { overflow: hidden !important; text-overflow: ellipsis !important; white-space: nowrap !important; }
  /* Legacy off-canvas drawer only — v2 rail/drawer lives in iuve-sidebar-drawer-v2.css */
  .iuve-sidebar,
  .iuve-shell.app-shell:not(.app-shell-v2) #app-side-nav,
  .iuve-shell.app-shell:not(.app-shell-v2) .side-nav,
  .iuve-shell.app-shell:not(.app-shell-v2) .sidebar-v2 {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    width: min(86vw, var(--iuve-shell-sidebar-width)) !important;
    min-width: 0 !important;
    max-width: min(86vw, var(--iuve-shell-sidebar-width)) !important;
    height: 100dvh !important;
    min-height: 100dvh !important;
    z-index: var(--iuve-z-drawer) !important;
    transform: translateX(-105%) !important;
    transition: transform .22s ease !important;
    box-shadow: 18px 0 38px rgba(15, 23, 42, .18) !important;
  }
  body.iuve-sidebar-open .iuve-shell.app-shell:not(.app-shell-v2) #app-side-nav,
  body.iuve-sidebar-open .iuve-shell.app-shell:not(.app-shell-v2) .iuve-sidebar,
  .iuve-shell.app-shell:not(.app-shell-v2).is-sidebar-open #app-side-nav,
  .iuve-shell.app-shell:not(.app-shell-v2).is-sidebar-open .iuve-sidebar { transform: translateX(0) !important; }
  body.iuve-sidebar-open .iuve-overlay,
  .iuve-shell.is-sidebar-open .iuve-overlay { display: block !important; opacity: 1 !important; pointer-events: auto !important; }
  .iuve-shell.app-shell:not(.app-shell-v2) .sidebar-v2__toggle--close-mobile { display: inline-flex !important; }
  .iuve-shell.app-shell:not(.app-shell-v2) .sidebar-v2__toggle--collapse { display: none !important; }
  .iuve-shell .dashboard-layout,
  .iuve-shell .workspace-layout,
  .iuve-shell .marketplace-layout { padding-left: 14px !important; padding-right: 14px !important; }
  body[data-page="iuve-chat"] .iuve-shell #unified-messages { width: 100% !important; max-width: none !important; padding-left: 12px !important; padding-right: 12px !important; }
  body[data-page="iuve-chat"] .iuve-shell #unified-composer-area { width: calc(100% - 20px) !important; max-width: none !important; }
}
