/* CDS Research Portal v0.21.4.12 — Mobile Responsive UX */
.cds-mobile-portal-launch{display:none}

/* ---------- TABLE / PANEL SAFETY AT ALL WIDTHS ---------- */
.portal-content,
.portal-workspace,
.portal-main,
.page,
main,
section,
article,
.card,
.panel{min-width:0}

.table-wrap,
.table-scroll,
.results-table-wrap,
.data-table-wrap,
.portal-table-wrap,
.studio-table-wrap,
.option-chain-wrap,
.cds-mobile-scroll{
  max-width:100%;
  overflow-x:auto;
  -webkit-overflow-scrolling:touch;
}

/* ---------- MOBILE ---------- */
@media (max-width:900px){
  html,body{
    width:100%;
    max-width:100%;
    overflow-x:hidden!important;
  }

  body{
    -webkit-text-size-adjust:100%;
    text-size-adjust:100%;
  }

  /* Public landing: guaranteed mobile path into the research portal */
  .cds-mobile-portal-launch{
    display:flex!important;
    position:fixed;
    left:10px;
    right:10px;
    bottom:max(10px,env(safe-area-inset-bottom));
    z-index:30000;
    min-height:54px;
    padding:9px 15px;
    align-items:center;
    justify-content:space-between;
    gap:12px;
    border-radius:15px;
    text-decoration:none!important;
    background:#59d9b8;
    color:#061722!important;
    border:1px solid rgba(255,255,255,.18);
    box-shadow:0 12px 34px rgba(0,0,0,.34);
    font-size:14px;
    font-weight:900;
  }
  .cds-mobile-portal-launch small{
    display:block;
    font-size:10px;
    line-height:1.25;
    font-weight:750;
    opacity:.70;
    margin-top:2px;
  }
  body.cds-public-mobile-access{
    padding-bottom:82px!important;
  }

  /* Portal menu button */
  #portalSidebarToggle.portal-sidebar-toggle{
    display:flex!important;
    position:fixed!important;
    left:10px!important;
    top:max(10px,env(safe-area-inset-top))!important;
    z-index:31020!important;
    width:46px!important;
    height:46px!important;
    min-width:46px!important;
    min-height:46px!important;
    align-items:center!important;
    justify-content:center!important;
    padding:0!important;
    border-radius:12px!important;
    background:#0b2637!important;
    color:#effaff!important;
    border:1px solid #2a5872!important;
    box-shadow:0 8px 24px rgba(0,0,0,.28)!important;
    font-size:22px!important;
    line-height:1!important;
  }

  /* Off-canvas sidebar */
  #portalSidebar.portal-sidebar{
    display:block!important;
    position:fixed!important;
    inset:0 auto 0 0!important;
    width:min(88vw,330px)!important;
    max-width:330px!important;
    height:100dvh!important;
    z-index:31010!important;
    transform:translateX(-105%)!important;
    transition:transform .22s ease!important;
    overflow-y:auto!important;
    overscroll-behavior:contain;
    -webkit-overflow-scrolling:touch;
    box-shadow:18px 0 45px rgba(0,0,0,.42)!important;
  }
  #portalSidebar.portal-sidebar.cds-mobile-open{
    transform:translateX(0)!important;
  }

  #portalSidebarBackdrop.portal-sidebar-backdrop{
    display:none!important;
  }
  #portalSidebarBackdrop.portal-sidebar-backdrop.cds-mobile-open{
    display:block!important;
    position:fixed!important;
    inset:0!important;
    z-index:31000!important;
    background:rgba(0,8,14,.68)!important;
    backdrop-filter:blur(2px);
  }

  #portalSidebarClose.portal-sidebar-close{
    display:flex!important;
    min-width:44px!important;
    min-height:44px!important;
    align-items:center!important;
    justify-content:center!important;
  }

  .portal-side-link,
  .portal-side-nav a,
  .portal-side-nav button{
    min-height:46px!important;
    touch-action:manipulation;
  }

  /* Main page should no longer retain desktop sidebar offset */
  .portal-shell,
  .portal-main,
  .portal-content,
  .portal-workspace,
  .portal-page,
  .main-content,
  body > main{
    width:100%!important;
    max-width:100%!important;
    min-width:0!important;
    margin-left:0!important;
  }

  /* Header */
  .topbar{
    min-width:0!important;
    width:100%!important;
    padding:
      max(12px,env(safe-area-inset-top))
      12px
      12px
      68px!important;
    gap:10px!important;
    flex-wrap:wrap!important;
  }
  .topbar>div:first-child{
    min-width:0!important;
    flex:1 1 100%!important;
  }
  .topbar h1{
    font-size:clamp(20px,6vw,29px)!important;
    line-height:1.14!important;
    white-space:normal!important;
    overflow-wrap:anywhere;
  }
  .topbar h1 small{display:none!important}
  .topbar p{
    display:none!important;
  }
  #healthBadge,.badge.waiting{
    max-width:100%!important;
    white-space:normal!important;
  }

  /* General cards and workspace grids */
  .grid,
  .cards,
  .card-grid,
  .dashboard-grid,
  .analytics-grid,
  .metrics-grid,
  .portal-grid,
  .studio-grid,
  .options-grid,
  .two-col,
  .three-col,
  .four-col{
    grid-template-columns:1fr!important;
  }

  .card,.panel,.workspace-card,.analytics-card{
    max-width:100%!important;
    min-width:0!important;
  }

  /* Inputs and action rows */
  input,select,textarea,button,a[role="button"]{
    max-width:100%;
  }

  .toolbar,
  .controls,
  .control-row,
  .filter-row,
  .form-row,
  .action-row,
  .studio-controls,
  .option-controls,
  .ratio-controls{
    flex-wrap:wrap!important;
  }

  /* Top/tab navigation becomes swipeable instead of wrapping into chaos */
  .tabs,
  .tabbar,
  .studio-tabs,
  .studio-subtabs,
  .studio-subtab-row,
  .portal-tabs,
  .workspace-tabs,
  [role="tablist"]{
    display:flex!important;
    flex-wrap:nowrap!important;
    max-width:100%!important;
    overflow-x:auto!important;
    overflow-y:hidden!important;
    -webkit-overflow-scrolling:touch;
    scrollbar-width:thin;
    scroll-snap-type:x proximity;
    gap:8px!important;
    padding-bottom:4px;
  }
  .tabs>*,
  .tabbar>*,
  .studio-tabs>*,
  .studio-subtabs>*,
  .studio-subtab-row>*,
  .portal-tabs>*,
  .workspace-tabs>*,
  [role="tablist"]>*{
    flex:0 0 auto!important;
    scroll-snap-align:start;
    min-height:44px;
    white-space:nowrap;
  }

  /* Advanced Screener Studio */
  .studio-subtab{
    min-height:44px!important;
    padding:0 14px!important;
  }
  .studio-toolbar,
  .studio-toolbar-row{
    max-width:100%!important;
    overflow-x:auto!important;
    -webkit-overflow-scrolling:touch;
  }

  /* Tables: preserve columns but scroll locally */
  table{
    width:max-content!important;
    min-width:100%!important;
    max-width:none!important;
    font-size:12px!important;
  }
  th,td{
    white-space:nowrap;
    padding-left:9px!important;
    padding-right:9px!important;
  }

  /* Make common direct tables scroll even when no wrapper exists */
  .panel:has(> table),
  .card:has(> table),
  section:has(> table),
  .analytics-card:has(> table){
    overflow-x:auto!important;
    -webkit-overflow-scrolling:touch;
  }

  /* Sector & Industry analytics */
  .cds-rotation-vfix-plot,
  .cds-rotation-host{
    min-width:620px!important;
  }
  .cds-rotation-vfix-card{
    overflow-x:auto!important;
    -webkit-overflow-scrolling:touch;
  }
  .cds-rotation-vfix-legend,
  .cds-rotation-legend{
    min-width:max-content;
  }

  /* Futures & OI / Options */
  .options-workspace,
  .options-layout,
  .futures-oi-layout,
  .fo-layout,
  .oi-layout{
    grid-template-columns:1fr!important;
  }
  .options-left,
  .options-right,
  .fo-left,
  .fo-right{
    width:100%!important;
    min-width:0!important;
  }
  .option-chain,
  .futures-table,
  .oi-table{
    overflow-x:auto!important;
    -webkit-overflow-scrolling:touch;
  }

  /* Chart areas */
  canvas,svg{
    max-width:100%;
  }
  .chart,
  .chart-wrap,
  .chart-container,
  .tv-chart,
  .tradingview-widget-container,
  .apexcharts-canvas{
    max-width:100%!important;
    min-width:0!important;
  }

  /* Ratio Charts dedicated page */
  .cds-ratio-studio-page{
    padding:0 10px 22px!important;
  }
  .cds-ratio-studio-title-row,
  .cds-ratio-workspace-title{
    flex-direction:column!important;
    gap:8px!important;
  }
  .cds-ratio-studio-tabs{
    flex-wrap:nowrap!important;
    overflow-x:auto!important;
    -webkit-overflow-scrolling:touch;
    padding-bottom:5px;
  }
  .cds-ratio-studio-tab{
    flex:0 0 auto!important;
    min-height:44px!important;
  }
  .cds-ratio-controls.page{
    display:grid!important;
    grid-template-columns:1fr!important;
  }
  .cds-ratio-controls.page .cds-ratio-swap,
  .cds-ratio-controls.page .run{
    width:100%!important;
  }
  .cds-ratio-svg-host{
    height:340px!important;
    min-width:0!important;
  }

  /* Avoid impossible desktop min-widths */
  [style*="min-width: 1000"],
  [style*="min-width:1000"],
  [style*="min-width: 900"],
  [style*="min-width:900"]{
    min-width:0!important;
  }

  /* Make modals usable on phone */
  .modal,
  .dialog,
  [role="dialog"]{
    max-width:calc(100vw - 20px)!important;
    max-height:calc(100dvh - 20px)!important;
    overflow:auto!important;
  }
}

@media(max-width:520px){
  .topbar{padding-left:64px!important}
  .portal-side-link,.portal-side-nav a,.portal-side-nav button{font-size:13px!important}
  th,td{font-size:11px!important}
}
