/* JDRC_VISUAL_CLEANUP_V14_4 */
/* V14.4 Visual Cleanup
   Final additive polish for the V14 visual system. No application logic or subsystem identity changes. */

/* Prevent late-stage layout overflow without flattening component sizing. */
body[data-jdrc-surface]{
  overflow-x:clip;
}

[data-jdrc-surface] :where(
  .section,
  .section-heading,
  .portal-dashboard,
  .portal-panel,
  .panel-title,
  .pit-feed-shell,
  .pit-feed-card,
  .pit-feed-section-head,
  .pit-feed-toolbar,
  .pit-os-shell,
  .pit-os-card,
  .pit-os-card-head,
  .pit-os-grid,
  .jdrc-page-shell,
  .jdrc-panel,
  .membership-plan-card,
  .membership-economy-v5,
  .reload-xp-v6-panel,
  .reward-v7-panel,
  .sponsor-section,
  .sponsor-section-head,
  .sponsor-dashboard-card,
  .sponsor-card-heading,
  .admin-layout,
  .admin-content,
  .admin-panel,
  .pool-card,
  .economy-card,
  .progression-card,
  .profit-v8-card,
  .pit-sponsor-v4-card,
  .sw-race-hero,
  .sw-race-panel,
  .sw-race-section
){
  min-width:0;
}

/* Long racer names, URLs, IDs, notes, and API/admin feedback must never force horizontal page scrolling. */
[data-jdrc-surface] :where(
  p,
  li,
  dd,
  small,
  .fine-print,
  .form-message,
  .empty-state,
  .pit-feed-text,
  .pit-feed-comment,
  .pit-os-item,
  .pit-os-room-msg,
  .pit-os-source,
  .sponsor-message,
  .sponsor-billing-line,
  .sw-race-guardrail,
  .sw-race-entry-status
){
  overflow-wrap:anywhere;
}

[data-jdrc-surface] :where(pre,code){
  max-width:100%;
}
[data-jdrc-surface] pre{
  overflow:auto;
  overscroll-behavior-inline:contain;
}

/* Media remains inside its owning surface even when source dimensions are larger. */
[data-jdrc-surface] :where(img,video,canvas,svg,iframe){
  max-width:100%;
}
[data-jdrc-surface] :where(img,video){
  height:auto;
}

/* Sticky subsystem controls now clear the normalized V14 header instead of hiding underneath it. */
[data-jdrc-surface="pit-feed"] .pit-feed-toolbar,
[data-jdrc-surface="pit"] .pit-os-tabs{
  top:calc(var(--jdrc-v14-header-min) + 8px);
}

[data-jdrc-surface="admin"] .admin-tabs{
  top:calc(var(--jdrc-v14-header-min) + 14px);
  max-height:calc(100dvh - var(--jdrc-v14-header-min) - 28px);
  overflow-y:auto;
  overscroll-behavior:contain;
  scrollbar-gutter:stable;
}

/* Anchor targets opened from nav/deep links land below sticky chrome. */
[data-jdrc-surface] :where(section[id],article[id],div[id]){
  scroll-margin-top:calc(var(--jdrc-v14-header-min) + 22px);
}

/* Status chips should compress or wrap rather than escape narrow cards. */
[data-jdrc-surface] :where(
  .status-chip,
  .pit-os-chip,
  .pit-os-tag,
  .pit-feed-rule-chip,
  .pit-feed-tags span,
  .membership-value-status,
  .reward-v7-status,
  .sponsor-account-status,
  .sponsor-plan-badge,
  .sw-race-status,
  .sw-race-source,
  .sw-race-entry-chip,
  .sw-race-rules-version
){
  max-width:100%;
  white-space:normal;
  overflow-wrap:anywhere;
  text-align:center;
}

/* Final interaction cleanup: disabled controls cannot appear active. */
[data-jdrc-surface] :where(button,input,select,textarea):disabled,
[data-jdrc-surface] [aria-disabled="true"]{
  opacity:.52;
  cursor:not-allowed!important;
  filter:saturate(.72);
}
[data-jdrc-surface] :where(button,input,select,textarea):disabled:active,
[data-jdrc-surface] [aria-disabled="true"]:active{
  transform:none!important;
}

[data-jdrc-surface] :where(input[type="checkbox"],input[type="radio"]){
  accent-color:var(--jdrc-v14-accent);
}

/* Preserve readable button text when localized/long labels are used. */
[data-jdrc-surface] :where(
  .button,
  .sponsor-primary,
  .sponsor-secondary,
  .sponsor-nav-button,
  .pit-feed-tab,
  .pit-os-tabs button,
  .admin-tab
){
  text-wrap:balance;
}

/* Dense Admin tables already own their minimum widths; normalize their scrolling container. */
[data-jdrc-surface="admin"] :where(.music-batch-table-wrap,.progression-rank-table-wrap){
  max-width:100%;
  overflow:auto;
  overscroll-behavior-inline:contain;
  scrollbar-gutter:stable;
  border-radius:12px;
}

/* Dialogs stay reachable on short and narrow viewports. */
[data-jdrc-surface="sponsor"] .sponsor-dialog,
[data-jdrc-surface="admin"] .editor-dialog{
  max-width:calc(100vw - 20px);
  max-height:calc(100dvh - 20px);
  overscroll-behavior:contain;
}

/* Give scrollable chips/tabs a stable touch strip without changing their content. */
[data-jdrc-surface="pit"] .pit-os-tabs,
[data-jdrc-surface="admin"] .admin-tabs{
  scrollbar-width:thin;
}

/* Mobile finishing pass. Existing mobile nav systems remain authoritative. */
@media(max-width:760px){
  .site-header,
  .sponsor-header{
    padding-top:max(8px,env(safe-area-inset-top,0px));
  }

  [data-jdrc-surface="pit-feed"] .pit-feed-toolbar,
  [data-jdrc-surface="pit"] .pit-os-tabs{
    top:calc(var(--jdrc-v14-header-min) + 6px);
  }

  [data-jdrc-surface="admin"] .admin-tabs{
    top:calc(var(--jdrc-v14-header-min) + 8px);
    max-height:none;
  }

  [data-jdrc-surface] :where(.panel-title,.pit-feed-section-head,.pit-os-card-head,.sponsor-card-heading){
    flex-wrap:wrap;
  }

  [data-jdrc-surface] :where(.pit-feed-composer-bottom,.pit-os-inline-form,.sponsor-billing-line){
    min-width:0;
  }
}

@media(max-width:520px){
  [data-jdrc-surface="pit-feed"] .pit-feed-composer-bottom,
  [data-jdrc-surface="pit"] .pit-os-inline-form,
  [data-jdrc-surface="sponsor"] .sponsor-billing-line{
    align-items:stretch;
    flex-direction:column;
  }

  [data-jdrc-surface="pit"] .pit-os-inline-form input,
  [data-jdrc-surface="pit-feed"] .pit-feed-comment-form input{
    min-width:0;
  }
}

@media(prefers-reduced-motion:reduce){
  [data-jdrc-surface]{scroll-behavior:auto!important}
}
