/* Cobalt Mobile Usability Repair v4
   Mobile-only repair. Every rule is contained in mobile media queries. */

@media (max-width: 900px) {
  :root {
    --cmu-safe-top: env(safe-area-inset-top, 0px);
    --cmu-safe-right: env(safe-area-inset-right, 0px);
    --cmu-safe-bottom: env(safe-area-inset-bottom, 0px);
    --cmu-safe-left: env(safe-area-inset-left, 0px);
  }

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

  body.cmu-overlay-open,
  body.pb-panel-ui.pb-saas-sidebar-open,
  body.pb-panel-ui.cmu-panel-popover-open {
    overflow: hidden !important;
    overscroll-behavior: none;
  }

  body.clm-page button,
  body.clm-page summary,
  body.clm-page a,
  body.cs-saas-body button,
  body.cs-saas-body summary,
  body.cs-saas-body a,
  body.pb-panel-ui button,
  body.pb-panel-ui summary,
  body.pb-panel-ui a {
    touch-action: manipulation;
  }

  body.clm-page input,
  body.clm-page select,
  body.clm-page textarea,
  body.cs-saas-body input,
  body.cs-saas-body select,
  body.cs-saas-body textarea,
  body.pb-panel-ui input,
  body.pb-panel-ui select,
  body.pb-panel-ui textarea {
    max-width: 100%;
    font-size: 16px;
  }

  /* ------------------------------------------------------------------
     Public landing: compact header, reliable main menu and user menu
     ------------------------------------------------------------------ */
  body.clm-page .clm-header {
    z-index: 1600;
    background: #090d17;
    -webkit-backdrop-filter: none !important;
    backdrop-filter: none !important;
  }

  body.clm-page .clm-header-inner {
    width: calc(100% - 20px);
    min-width: 0;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 8px;
  }

  body.clm-page .clm-brand,
  body.clm-page .clm-brand-copy {
    min-width: 0;
  }

  body.clm-page .clm-brand {
    max-width: 100%;
  }

  body.clm-page .clm-brand-copy strong {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  body.clm-page .clm-header-actions {
    min-width: 0;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 6px;
  }

  body.clm-page .clm-premium,
  body.clm-page .clm-header-actions > .clm-button--compact,
  body.clm-page .clm-header-actions > .clm-login,
  body.clm-page .clm-header-actions > .pb-language-switcher,
  body.clm-page .clm-header-actions > .pb-language-trigger--landing {
    display: none !important;
  }

  body.clm-page .clm-user-menu {
    display: block !important;
    position: relative;
    z-index: 1603;
    flex: 0 0 auto;
  }

  body.clm-page .clm-user-menu > summary,
  body.clm-page .clm-mobile-trigger {
    width: 44px;
    min-width: 44px;
    height: 44px;
    min-height: 44px;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 1px solid rgba(140, 162, 196, .18);
    border-radius: 8px;
    background: rgba(255, 255, 255, .025);
  }

  body.clm-page .clm-user-menu > summary {
    gap: 0;
  }

  body.clm-page .clm-user-menu > summary .clm-user-name,
  body.clm-page .clm-user-menu > summary .clm-user-chevron {
    display: none !important;
  }

  body.clm-page .clm-user-menu > summary .clm-user-avatar {
    width: 34px;
    height: 34px;
    flex-basis: 34px;
  }

  body.clm-page .clm-mobile-trigger {
    gap: 3px;
    cursor: pointer;
  }

  body.clm-page .clm-mobile-trigger span {
    width: 4px;
    height: 4px;
  }

  body.clm-page .clm-mobile-trigger b {
    display: none;
  }

  body.clm-page .clm-mobile-nav,
  body.clm-page .clm-user-popover {
    position: fixed;
    z-index: 1602;
    top: var(--cmu-landing-panel-top, calc(38px + var(--clm-header-height)));
    right: 0;
    bottom: 0;
    left: 0;
    width: auto;
    max-width: none;
    max-height: none;
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    border: 0;
    border-top: 1px solid rgba(140, 162, 196, .18);
    border-radius: 0;
    background: rgba(7, 11, 19, .995);
    box-shadow: none;
  }


  body.clm-page .clm-mobile-nav[hidden] {
    display: none !important;
  }

  body.clm-page .clm-mobile-nav {
    padding: 12px 16px calc(20px + var(--cmu-safe-bottom));
  }

  body.clm-page .clm-mobile-nav nav {
    display: grid;
    gap: 0;
  }

  body.clm-page .clm-mobile-nav nav a {
    min-height: 52px;
    display: flex;
    align-items: center;
    padding: 0 4px;
    border-bottom: 1px solid rgba(140, 162, 196, .12);
    color: #edf2fa;
    font-size: .92rem;
    font-weight: 780;
  }

  body.clm-page .clm-mobile-actions {
    display: grid;
    grid-template-columns: 1fr;
    gap: 10px;
    margin-top: 16px;
  }

  body.clm-page .clm-mobile-actions .clm-button {
    width: 100%;
    min-height: 48px;
  }

  body.clm-page .clm-user-popover {
    padding: 10px 12px calc(18px + var(--cmu-safe-bottom));
  }

  body.clm-page .clm-user-identity {
    position: sticky;
    top: -10px;
    z-index: 1;
    margin: -10px -12px 4px;
    padding: 16px 14px;
    background: #090e17;
  }

  body.clm-page .clm-user-group {
    padding: 12px 2px 2px;
  }

  body.clm-page .clm-user-group > span {
    padding: 0 10px 7px;
  }

  body.clm-page .clm-user-group a,
  body.clm-page .clm-user-group button,
  body.clm-page .clm-user-footer a {
    min-height: 48px;
    padding-inline: 10px;
    font-size: .78rem;
  }

  body.clm-page.cmu-overlay-open .cobalt-sale-ribbon {
    display: none !important;
  }

  /* Keep the landing content readable without changing the desktop design. */
  body.clm-page .clm-hero-grid,
  body.clm-page .clm-shell {
    min-width: 0;
  }

  body.clm-page .clm-hero h1,
  body.clm-page .clm-why h2,
  body.clm-page .clm-story h2,
  body.clm-page .clm-playground h2,
  body.clm-page .clm-premium-section h2,
  body.clm-page .clm-faq h2,
  body.clm-page .clm-final-cta h2 {
    overflow-wrap: normal;
    word-break: normal;
    hyphens: auto;
  }

  /* ------------------------------------------------------------------
     Logged-in SaaS shell: avatar remains available next to mobile menu
     ------------------------------------------------------------------ */
  body.cs-saas-body .cs-topbar {
    z-index: 1600;
  }

  body.cs-saas-body .cs-topbar-inner {
    width: calc(100% - 20px) !important;
    min-width: 0;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 8px;
  }

  body.cs-saas-body .cs-brand,
  body.cs-saas-body .cs-brand span {
    min-width: 0;
  }

  body.cs-saas-body .cs-topbar-actions {
    min-width: 0;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 6px;
  }

  body.cs-saas-body .cs-premium-link,
  body.cs-saas-body .cs-topbar-actions > .pb-language-switcher,
  body.cs-saas-body .cs-topbar-actions > .pb-language-trigger--saas {
    display: none !important;
  }

  body.cs-saas-body .cs-user-menu,
  body.cs-saas-body .cs-mobile-menu {
    display: block !important;
    position: relative;
    z-index: 1603;
    flex: 0 0 auto;
  }

  body.cs-saas-body .cs-user-menu > summary,
  body.cs-saas-body .cs-mobile-menu > summary {
    min-width: 44px;
    width: 44px;
    min-height: 44px;
    height: 44px;
    display: grid;
    place-items: center;
    padding: 0;
    border: 1px solid rgba(140, 162, 196, .18);
    border-radius: 6px;
    background: rgba(255, 255, 255, .025);
    line-height: 1;
  }

  body.cs-saas-body .cs-user-menu > summary {
    grid-template-columns: 1fr;
  }

  body.cs-saas-body .cs-user-summary,
  body.cs-saas-body .cs-user-chevron {
    display: none !important;
  }

  body.cs-saas-body .cs-user-avatar {
    width: 34px;
    height: 34px;
  }

  body.cs-saas-body .cs-mobile-menu > summary {
    width: auto;
    min-width: 52px;
    padding-inline: 10px;
    font-size: .72rem;
    font-weight: 780;
  }

  body.cs-saas-body .cs-user-popover,
  body.cs-saas-body .cs-mobile-menu > nav {
    position: fixed;
    z-index: 1602;
    top: var(--cmu-saas-panel-top, var(--cs-header-height, 64px));
    right: 0;
    bottom: 0;
    left: 0;
    width: auto;
    max-width: none;
    max-height: none;
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    border: 0;
    border-top: 1px solid rgba(140, 162, 196, .18);
    border-radius: 0;
    background: #0b0f16;
    box-shadow: none;
  }

  body.cs-saas-body .cs-user-popover {
    padding-bottom: calc(16px + var(--cmu-safe-bottom));
  }

  body.cs-saas-body .cs-mobile-menu > nav {
    display: grid;
    padding: 8px 14px calc(18px + var(--cmu-safe-bottom));
  }

  body.cs-saas-body .cs-mobile-menu > nav a {
    min-height: 52px;
    display: flex;
    align-items: center;
    padding: 0 4px;
    border-bottom: 1px solid rgba(140, 162, 196, .12);
    line-height: 1.3;
  }

  body.cs-saas-body .cs-user-identity {
    position: sticky;
    top: 0;
    z-index: 1;
    background: #0b0f16;
  }

  body.cs-saas-body .cs-menu-group a,
  body.cs-saas-body .cs-menu-group button,
  body.cs-saas-body .cs-menu-footer a {
    min-height: 48px;
  }

  body.cs-saas-body.cmu-overlay-open .cobalt-sale-ribbon {
    display: none !important;
  }

  /* ------------------------------------------------------------------
     Guild/module shell: preserve existing UI, repair only scroll/viewport
     ------------------------------------------------------------------ */
  body.pb-panel-ui .pb-saas-sidebar {
    height: calc(100dvh - var(--pb-saas-topbar-h)) !important;
    max-height: calc(100dvh - var(--pb-saas-topbar-h)) !important;
    padding-bottom: var(--cmu-safe-bottom);
    overflow: hidden !important;
  }

  body.pb-panel-ui .pb-saas-nav {
    min-height: 0;
    overflow-x: hidden !important;
    overflow-y: auto !important;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
  }

  body.pb-panel-ui .pb-saas-popover {
    right: 8px !important;
    left: 8px !important;
    width: auto !important;
    max-width: none !important;
    max-height: calc(100dvh - var(--pb-saas-topbar-h) - 14px - var(--cmu-safe-bottom)) !important;
    overflow-x: hidden !important;
    overflow-y: auto !important;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
  }

  body.pb-panel-ui .pb-saas-server-list {
    max-height: none;
  }

  body.pb-panel-ui .pb-saas-mobile-bottom {
    min-height: calc(66px + var(--cmu-safe-bottom));
  }

  body.pb-panel-ui .cobalt-sale-ribbon {
    bottom: calc(74px + var(--cmu-safe-bottom));
  }

  /* Existing wrappers remain authoritative; no JavaScript table rewriting. */
  body.cs-saas-body .cs-table-wrap,
  body.pb-panel-ui .table-wrap,
  body.pb-panel-ui .mobile-table-scroll,
  body.pb-panel-ui .pb-mobile-table-shell {
    max-width: 100%;
    overflow-x: auto;
    overscroll-behavior-inline: contain;
    -webkit-overflow-scrolling: touch;
  }

  body.clm-page dialog,
  body.clm-page [role="dialog"],
  body.cs-saas-body dialog,
  body.cs-saas-body [role="dialog"],
  body.pb-panel-ui dialog,
  body.pb-panel-ui [role="dialog"] {
    max-width: calc(100vw - 20px);
    max-height: calc(100dvh - 20px - var(--cmu-safe-top) - var(--cmu-safe-bottom));
    overflow-y: auto;
    overscroll-behavior: contain;
  }
}

@media (max-width: 560px) {
  body.clm-page .clm-header-inner,
  body.cs-saas-body .cs-topbar-inner {
    width: calc(100% - 16px) !important;
  }

  body.clm-page .clm-brand-copy small,
  body.cs-saas-body .cs-brand small {
    display: none !important;
  }

  body.clm-page .clm-brand-copy strong {
    font-size: .94rem;
  }

  body.clm-page .clm-hero h1 {
    font-size: clamp(2.7rem, 14.5vw, 3.55rem);
    line-height: .98;
  }

  body.clm-page .clm-hero-copy > p {
    font-size: .94rem;
  }

  body.clm-page .cobalt-sale-ribbon {
    width: calc(100vw - 12px);
    bottom: max(6px, var(--cmu-safe-bottom));
  }

  body.clm-page .cobalt-sale-ribbon-main strong {
    max-width: 46vw;
  }

  body.cs-saas-body .cs-mobile-menu > summary {
    min-width: 48px;
    padding-inline: 8px;
    font-size: .68rem;
  }
}
