/* AI Project Universe V5.4 — reliable document scrolling + unified navigation
   Targets: SentiScope, Academic Evidence Hub, Computer Vision, AI Architect Lab. */

/* --------------------------------------------------------------------------
   1. ONE RELIABLE DOCUMENT SCROLLER
   -------------------------------------------------------------------------- */
html[data-scroll-theme="sentiment-analysis"],
html[data-scroll-theme="academic-evidence"] {
  width: 100% !important;
  min-width: 0 !important;
  min-height: 100% !important;
  height: auto !important;
  max-height: none !important;
  overflow-x: hidden !important;
  overflow-y: auto !important;
  scrollbar-gutter: stable;
  overscroll-behavior-y: auto !important;
  scroll-behavior: smooth;
}

html[data-scroll-theme="sentiment-analysis"] body,
html[data-scroll-theme="academic-evidence"] body {
  width: 100% !important;
  min-width: 0 !important;
  min-height: 100vh !important;
  min-height: 100dvh !important;
  height: auto !important;
  max-height: none !important;
  margin: 0 !important;
  overflow-x: clip !important;
  overflow-y: visible !important;
  position: relative !important;
  inset: auto !important;
  touch-action: pan-y pinch-zoom;
  -webkit-overflow-scrolling: touch;
}

html[data-scroll-theme="sentiment-analysis"] :is(#root,#app,#__next,[data-reactroot]),
html[data-scroll-theme="academic-evidence"] :is(#root,#app,#__next,[data-reactroot]) {
  width: 100% !important;
  min-width: 0 !important;
  min-height: 100dvh !important;
  height: auto !important;
  max-height: none !important;
  overflow: visible !important;
}

html[data-scroll-theme="sentiment-analysis"] [data-apu-v54-scroll-shell="true"],
html[data-scroll-theme="academic-evidence"] [data-apu-v54-scroll-shell="true"] {
  width: 100% !important;
  min-width: 0 !important;
  min-height: 100dvh !important;
  height: auto !important;
  max-height: none !important;
  overflow: visible !important;
  align-items: stretch !important;
}

html[data-scroll-theme="sentiment-analysis"] [data-apu-v54-scroll-main="true"],
html[data-scroll-theme="academic-evidence"] [data-apu-v54-scroll-main="true"] {
  min-width: 0 !important;
  min-height: 100dvh !important;
  height: auto !important;
  max-height: none !important;
  overflow: visible !important;
  position: relative !important;
  inset: auto !important;
}

html[data-scroll-theme="sentiment-analysis"] [data-apu-v54-scroll-content="true"],
html[data-scroll-theme="academic-evidence"] [data-apu-v54-scroll-content="true"] {
  width: 100% !important;
  min-width: 0 !important;
  min-height: 0 !important;
  height: auto !important;
  max-height: none !important;
  overflow-x: visible !important;
  overflow-y: visible !important;
  overscroll-behavior: auto !important;
}

/* Preserve horizontal scrolling only where it is actually needed. */
html[data-scroll-theme="sentiment-analysis"] :is(.table-wrap,.table-responsive,.apu-table-wrap,.apu-mobile-table-shell,[data-apu-horizontal-scroll="true"]),
html[data-scroll-theme="academic-evidence"] :is(.table-wrap,.table-responsive,.apu-table-wrap,.apu-mobile-table-shell,[data-apu-horizontal-scroll="true"]) {
  width: 100% !important;
  max-width: 100% !important;
  min-width: 0 !important;
  overflow-x: auto !important;
  overflow-y: hidden !important;
  overscroll-behavior-inline: contain;
  -webkit-overflow-scrolling: touch;
}

@media (min-width: 54.001rem) {
  html[data-scroll-theme="sentiment-analysis"] [data-apu-v54-scroll-sidebar="true"],
  html[data-scroll-theme="academic-evidence"] [data-apu-v54-scroll-sidebar="true"] {
    position: sticky !important;
    top: 0 !important;
    align-self: flex-start !important;
    height: 100vh !important;
    height: 100dvh !important;
    max-height: 100dvh !important;
    overflow-x: hidden !important;
    overflow-y: auto !important;
    overscroll-behavior: contain;
  }
}

@media (max-width: 54rem) {
  html[data-scroll-theme="sentiment-analysis"],
  html[data-scroll-theme="academic-evidence"] {
    scrollbar-gutter: auto !important;
  }

  html[data-scroll-theme="sentiment-analysis"] [data-apu-v54-scroll-shell="true"],
  html[data-scroll-theme="academic-evidence"] [data-apu-v54-scroll-shell="true"] {
    display: block !important;
  }

  html[data-scroll-theme="sentiment-analysis"] [data-apu-v54-scroll-sidebar="true"],
  html[data-scroll-theme="academic-evidence"] [data-apu-v54-scroll-sidebar="true"] {
    display: none !important;
  }

  html[data-scroll-theme="sentiment-analysis"] [data-apu-v54-scroll-main="true"],
  html[data-scroll-theme="academic-evidence"] [data-apu-v54-scroll-main="true"] {
    width: 100% !important;
    min-height: 0 !important;
    margin: 0 !important;
    padding-top: 0 !important;
  }

  html[data-scroll-theme="sentiment-analysis"] [data-apu-v54-scroll-content="true"],
  html[data-scroll-theme="academic-evidence"] [data-apu-v54-scroll-content="true"] {
    padding-bottom: max(5.5rem, env(safe-area-inset-bottom)) !important;
  }

  /* The generated V5 bar is the single mobile navigation surface. */
  html[data-scroll-theme="sentiment-analysis"] .apu-v5-mobile-project-bar,
  html[data-scroll-theme="academic-evidence"] .apu-v5-mobile-project-bar {
    position: sticky !important;
    top: 0 !important;
    z-index: 2147482500 !important;
  }

  html[data-scroll-theme="sentiment-analysis"] .apu-v5-mobile-nav-drawer,
  html[data-scroll-theme="academic-evidence"] .apu-v5-mobile-nav-drawer {
    position: fixed !important;
    top: 61px !important;
    left: 8px !important;
    right: 8px !important;
    width: auto !important;
    max-height: calc(100dvh - 69px) !important;
    overflow-x: hidden !important;
    overflow-y: auto !important;
    overscroll-behavior: contain;
    z-index: 2147482490 !important;
  }

  html[data-scroll-theme="academic-evidence"] :is(
    [data-apu-academic-legacy-nav="true"],
    [data-apu-v54-academic-legacy="true"]
  ) {
    display: none !important;
  }
}

/* --------------------------------------------------------------------------
   2. COMPUTER VISION — IT HELPDESK-STYLE NAVIGATION
   -------------------------------------------------------------------------- */
html[data-scroll-theme="computer-vision"] {
  --apu-v54-cv-sidebar: 260px;
  --apu-v54-cv-line: rgba(161, 161, 161,.18);
  --apu-v54-cv-panel: #101010;
  --apu-v54-cv-panel-2: #171717;
  --apu-v54-cv-accent: #7b7b7b;
  --apu-v54-cv-text: #ededed;
  --apu-v54-cv-muted: #a1a1a1;
  min-height: 100% !important;
  height: auto !important;
  overflow-x: hidden !important;
  overflow-y: auto !important;
  scrollbar-gutter: stable;
}

html[data-scroll-theme="computer-vision"] body,
html[data-scroll-theme="computer-vision"] #root {
  min-width: 0 !important;
  min-height: 100dvh !important;
  height: auto !important;
  max-height: none !important;
  overflow-x: clip !important;
  overflow-y: visible !important;
}

html[data-scroll-theme="computer-vision"] [data-apu-v54-cv-shell="true"],
html[data-scroll-theme="computer-vision"] [data-apu-v54-cv-main-column="true"],
html[data-scroll-theme="computer-vision"] [data-apu-v54-cv-main="true"] {
  min-width: 0 !important;
  min-height: 100dvh !important;
  height: auto !important;
  max-height: none !important;
}

html[data-scroll-theme="computer-vision"] [data-apu-v54-cv-main-column="true"] {
  overflow: visible !important;
}

html[data-scroll-theme="computer-vision"] [data-apu-v54-cv-main="true"] {
  overflow: visible !important;
  padding-bottom: max(5rem, env(safe-area-inset-bottom)) !important;
}

.apu-v54-cv-mobile-bar,
.apu-v54-cv-mobile-drawer,
.apu-v54-cv-mobile-scrim {
  display: none;
}

@media (min-width: 54.001rem) {
  html[data-scroll-theme="computer-vision"] [data-slot="sidebar"] {
    width: var(--apu-v54-cv-sidebar) !important;
    min-width: var(--apu-v54-cv-sidebar) !important;
  }

  html[data-scroll-theme="computer-vision"] [data-slot="sidebar-container"] {
    display: flex !important;
    width: var(--apu-v54-cv-sidebar) !important;
    height: 100vh !important;
    height: 100dvh !important;
    background: var(--apu-v54-cv-panel) !important;
    border-right: 1px solid var(--apu-v54-cv-line) !important;
    box-shadow: 12px 0 34px rgba(0,0,0,.22) !important;
    z-index: 120 !important;
  }

  html[data-scroll-theme="computer-vision"] [data-slot="sidebar-inner"] {
    background: linear-gradient(180deg,var(--apu-v54-cv-panel),#0f0f0f) !important;
    color: var(--apu-v54-cv-text) !important;
    overflow: hidden !important;
  }

  html[data-scroll-theme="computer-vision"] [data-slot="sidebar-header"] {
    min-height: 76px !important;
    padding: 16px 18px !important;
    border-bottom: 1px solid var(--apu-v54-cv-line) !important;
  }

  html[data-scroll-theme="computer-vision"] :is([data-slot="sidebar-content"],[data-sidebar="content"]) {
    flex: 1 1 auto !important;
    min-height: 0 !important;
    padding: 12px 10px !important;
    overflow-x: hidden !important;
    overflow-y: auto !important;
    scrollbar-width: thin;
  }

  html[data-scroll-theme="computer-vision"] [data-slot="sidebar-menu-button"] {
    min-height: 44px !important;
    padding: 10px 12px !important;
    border-radius: 10px !important;
    color: var(--apu-v54-cv-muted) !important;
    transition: background .18s ease,color .18s ease,transform .18s ease !important;
  }

  html[data-scroll-theme="computer-vision"] [data-slot="sidebar-menu-button"]:hover {
    background: rgba(123, 123, 123,.10) !important;
    color: #fff !important;
    transform: translateX(2px);
  }

  html[data-scroll-theme="computer-vision"] [data-slot="sidebar-menu-button"][data-active="true"] {
    background: linear-gradient(90deg,rgba(123, 123, 123,.25),rgba(123, 123, 123,.06)) !important;
    color: #d8d8d8 !important;
    border-left: 3px solid var(--apu-v54-cv-accent) !important;
  }

  html[data-scroll-theme="computer-vision"] .apu-v54-cv-topbar {
    position: sticky !important;
    top: 0 !important;
    z-index: 90 !important;
    display: flex !important;
    min-height: 64px !important;
    height: 64px !important;
    padding: 0 24px !important;
    background: rgba(16, 16, 16,.96) !important;
    border-bottom: 1px solid var(--apu-v54-cv-line) !important;
    box-shadow: 0 8px 22px rgba(0,0,0,.16) !important;
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
  }

  html[data-scroll-theme="computer-vision"] .apu-v54-cv-topbar > button {
    display: none !important;
  }

  .apu-v54-cv-topbar-title {
    display: flex;
    flex-direction: column;
    gap: 2px;
    color: var(--apu-v54-cv-text);
  }

  .apu-v54-cv-topbar-title strong {
    font: 750 15px/1.2 Inter,system-ui,sans-serif;
    letter-spacing: .01em;
  }

  .apu-v54-cv-topbar-title small {
    color: var(--apu-v54-cv-muted);
    font: 600 11px/1.2 Inter,system-ui,sans-serif;
    letter-spacing: .08em;
    text-transform: uppercase;
  }
}

@media (max-width: 54rem) {
  html[data-scroll-theme="computer-vision"] {
    scrollbar-gutter: auto;
  }

  html[data-scroll-theme="computer-vision"] [data-slot="sidebar"],
  html[data-scroll-theme="computer-vision"] .apu-v54-cv-topbar {
    display: none !important;
  }

  html[data-scroll-theme="computer-vision"] [data-apu-v54-cv-shell="true"] {
    display: block !important;
  }

  html[data-scroll-theme="computer-vision"] [data-apu-v54-cv-main-column="true"] {
    width: 100% !important;
    min-height: 0 !important;
  }

  html[data-scroll-theme="computer-vision"] [data-apu-v54-cv-main="true"] {
    width: 100% !important;
    min-height: 0 !important;
    margin: 0 !important;
    padding: 18px 12px max(5.5rem,env(safe-area-inset-bottom)) !important;
  }

  .apu-v54-cv-mobile-bar {
    position: sticky;
    top: 0;
    z-index: 2147482600;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    min-height: 64px;
    padding: max(8px,env(safe-area-inset-top)) 12px 8px;
    background: #101010;
    color: #fff;
    border-bottom: 1px solid rgba(156, 156, 156,.36);
    box-shadow: 0 8px 24px rgba(0,0,0,.28);
  }

  .apu-v54-cv-mobile-brand {
    min-width: 0;
    display: flex;
    align-items: center;
    gap: 10px;
  }

  .apu-v54-cv-mobile-mark {
    width: 38px;
    height: 38px;
    flex: 0 0 38px;
    display: grid;
    place-items: center;
    border-radius: 11px;
    background: linear-gradient(135deg,#606060,#939393);
    color: white;
    font: 900 12px/1 Inter,system-ui,sans-serif;
    box-shadow: 0 8px 22px rgba(96, 96, 96,.28);
  }

  .apu-v54-cv-mobile-brand-copy {
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
  }

  .apu-v54-cv-mobile-brand-copy strong,
  .apu-v54-cv-mobile-brand-copy small {
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .apu-v54-cv-mobile-brand-copy strong {
    font: 800 13px/1.2 Inter,system-ui,sans-serif;
  }

  .apu-v54-cv-mobile-brand-copy small {
    color: #a2a2a2;
    font: 650 10px/1.2 Inter,system-ui,sans-serif;
    letter-spacing: .05em;
    text-transform: uppercase;
  }

  .apu-v54-cv-mobile-toggle,
  .apu-v54-cv-mobile-close {
    min-height: 42px;
    border: 1px solid rgba(156, 156, 156,.55);
    border-radius: 11px;
    background: #202020;
    color: #f5f5f5;
    font: 800 12px/1 Inter,system-ui,sans-serif;
    cursor: pointer;
  }

  .apu-v54-cv-mobile-toggle {
    min-width: 72px;
    padding: 0 13px;
  }

  .apu-v54-cv-mobile-scrim {
    position: fixed;
    inset: 0;
    z-index: 2147482570;
    display: block;
    padding: 0;
    border: 0;
    background: rgba(8, 8, 8,.68);
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: opacity .2s ease,visibility 0s linear .2s;
  }

  .apu-v54-cv-mobile-scrim.is-open {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
    transition: opacity .2s ease;
  }

  .apu-v54-cv-mobile-drawer {
    position: fixed;
    top: 64px;
    bottom: 0;
    left: 0;
    z-index: 2147482580;
    display: flex;
    flex-direction: column;
    width: min(86vw,320px);
    max-width: calc(100vw - 44px);
    background: linear-gradient(180deg,#101010,#0f0f0f);
    color: #ededed;
    border-right: 1px solid rgba(156, 156, 156,.30);
    box-shadow: 24px 0 56px rgba(0,0,0,.45);
    transform: translate3d(-105%,0,0);
    visibility: hidden;
    pointer-events: none;
    transition: transform .22s ease,visibility 0s linear .22s;
  }

  .apu-v54-cv-mobile-drawer.is-open {
    transform: translate3d(0,0,0);
    visibility: visible;
    pointer-events: auto;
    transition: transform .22s ease;
  }

  .apu-v54-cv-mobile-drawer-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    min-height: 66px;
    padding: 11px 12px 11px 16px;
    border-bottom: 1px solid rgba(161, 161, 161,.16);
  }

  .apu-v54-cv-mobile-drawer-head strong {
    font: 800 13px/1.2 Inter,system-ui,sans-serif;
  }

  .apu-v54-cv-mobile-close {
    min-width: 68px;
    padding: 0 11px;
    border-color: rgba(142, 142, 142,.48);
    background: #1d1d1d;
  }

  .apu-v54-cv-mobile-nav {
    flex: 1 1 auto;
    min-height: 0;
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: 12px;
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
  }

  .apu-v54-cv-mobile-nav a {
    width: 100%;
    min-height: 46px;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 11px 12px;
    border-radius: 10px;
    color: #aeaeae;
    text-decoration: none;
    font: 700 13px/1.3 Inter,system-ui,sans-serif;
  }

  .apu-v54-cv-mobile-nav a:hover,
  .apu-v54-cv-mobile-nav a[aria-current="page"] {
    background: linear-gradient(90deg,rgba(123, 123, 123,.25),rgba(123, 123, 123,.06));
    color: #e8e8e8;
    box-shadow: inset 3px 0 0 #7b7b7b;
  }

  .apu-v54-cv-mobile-nav svg {
    width: 18px;
    height: 18px;
    flex: 0 0 18px;
  }

  html[data-scroll-theme="computer-vision"][data-apu-v54-cv-menu-open="true"] body {
    overflow: hidden !important;
  }
}

/* --------------------------------------------------------------------------
   3. AI ARCHITECT — FULL VERTICAL MODULE NAVIGATION
   -------------------------------------------------------------------------- */
@media (max-width: 767px) {
  html[data-scroll-theme="ai-architect"] .ai-architect-drawer {
    inset: 58px 0 0 0 !important;
    width: 100% !important;
    max-width: none !important;
    height: calc(100dvh - 58px) !important;
    max-height: none !important;
    border: 0 !important;
    border-top: 1px solid rgba(175, 175, 175,.30) !important;
    border-radius: 0 !important;
    background: #0f0f0f !important;
    overflow: hidden !important;
    flex-direction: column !important;
  }

  html[data-scroll-theme="ai-architect"] .ai-architect-drawer.flex {
    display: flex !important;
  }

  html[data-scroll-theme="ai-architect"] .ai-drawer-heading {
    position: sticky !important;
    top: 0 !important;
    z-index: 3 !important;
    flex: 0 0 52px !important;
    min-height: 52px !important;
    background: #161616 !important;
  }

  html[data-scroll-theme="ai-architect"] .ai-architect-drawer nav {
    flex: 1 1 auto !important;
    min-height: 0 !important;
    width: 100% !important;
    height: auto !important;
    max-height: none !important;
    display: flex !important;
    flex-direction: column !important;
    align-items: stretch !important;
    gap: 4px !important;
    padding: 6px 10px max(10px,env(safe-area-inset-bottom)) !important;
    overflow-x: hidden !important;
    overflow-y: auto !important;
    overscroll-behavior: contain !important;
    -webkit-overflow-scrolling: touch !important;
  }

  html[data-scroll-theme="ai-architect"] .ai-architect-drawer nav > a {
    width: 100% !important;
    flex: 0 0 auto !important;
  }

  html[data-scroll-theme="ai-architect"] .ai-architect-drawer nav > a > div {
    width: 100% !important;
    min-height: 40px !important;
    display: flex !important;
    align-items: center !important;
    justify-content: flex-start !important;
    padding: 7px 11px !important;
    font-size: 12px !important;
    line-height: 1.15 !important;
    white-space: normal !important;
  }
}

@media (min-width: 768px) {
  html[data-scroll-theme="ai-architect"] .ai-architect-drawer {
    display: flex !important;
    flex-direction: column !important;
    width: 260px !important;
    min-width: 260px !important;
    height: calc(100dvh - 3.5rem) !important;
    max-height: calc(100dvh - 3.5rem) !important;
    overflow: hidden !important;
  }

  html[data-scroll-theme="ai-architect"] .ai-architect-drawer nav {
    width: 100% !important;
    flex: 1 1 auto !important;
    min-height: 0 !important;
    display: flex !important;
    flex-direction: column !important;
    align-items: stretch !important;
    overflow-x: hidden !important;
    overflow-y: auto !important;
    scrollbar-width: thin;
  }

  html[data-scroll-theme="ai-architect"] .ai-architect-drawer nav > a,
  html[data-scroll-theme="ai-architect"] .ai-architect-drawer nav > a > div {
    width: 100% !important;
  }
}

@media (prefers-reduced-motion: reduce) {
  html[data-scroll-theme="sentiment-analysis"],
  html[data-scroll-theme="academic-evidence"] {
    scroll-behavior: auto !important;
  }
  .apu-v54-cv-mobile-drawer,
  .apu-v54-cv-mobile-scrim {
    transition: none !important;
  }
}
