/* Accessibility + mobile release hardening. No market-state palette or semantic ownership. */
:where(a,button,input,select,textarea,[tabindex]):focus-visible {
  outline: 2px solid currentColor;
  outline-offset: 3px;
}

:where(
  .mobile-menu,
  #mode-menu-btn,
  [data-maic-copy-context],
  #maic-entry-continue,
  #workflow-next-btn,
  #workflow-review-btn,
  #workflow-routing-btn,
  .icon-close,
  [role="button"],
  button,
  .btn
) {
  min-width: 44px;
  min-height: 44px;
}

/*
 * Mobile safety contract
 * ----------------------
 * This stylesheet is injected after product/page styles into every sealed HTML
 * surface. It owns only last-mile viewport safety: no horizontal document
 * overflow, fluid media, scroll-contained dense tables, reachable overlays,
 * touch-sized controls, and single-column fallbacks for dense workstation grids.
 * It does not create or reinterpret market state, pricing, access, evidence, or
 * portfolio semantics.
 */
@media (max-width: 760px) {
  html {
    max-width: 100%;
    overflow-x: clip;
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
  }

  body {
    max-width: 100%;
    overflow-x: clip !important;
  }

  :where(
    main,section,article,aside,header,footer,nav,form,div,
    .panel,.surface,.card,.metric-card,.cortex-card,.rfag-module,.tvei-module,
    .docs-shell,.docs-content,.legal-shell,.performance-public-main,
    .seo-shell,.checkout-container,.container-inner,.content-wrapper
  ) {
    min-width: 0 !important;
  }

  :where(img,svg,video,iframe,picture) {
    max-width: 100% !important;
    height: auto;
  }

  canvas {
    max-width: 100% !important;
  }

  :where([style*="width:"][style*="px"],[style*="min-width:"]) {
    max-width: 100% !important;
  }

  :where(p,li,dd,dt,small,strong,span,a,h1,h2,h3,h4,h5,h6) {
    overflow-wrap: anywhere;
  }

  :where(pre,code,.address-text,.truncate-link,.terminal-title) {
    max-width: 100%;
    overflow-wrap: normal;
    word-break: normal;
  }

  pre {
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch;
  }

  :where(
    .docs-table-wrap,
    .maic-performance-table-wrap,
    .legal-table,
    .table-responsive,
    .table-wrap,
    [class*="table-wrap"],
    .decision-dendrogram
  ) {
    max-width: 100% !important;
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-inline: contain;
  }

  table {
    display: block !important;
    width: 100% !important;
    max-width: 100% !important;
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-inline: contain;
  }

  table :where(th,td) {
    white-space: nowrap;
  }

  :where(input:not([type="checkbox"]):not([type="radio"]),select,textarea) {
    width: 100%;
    max-width: 100%;
    min-height: 44px;
    font-size: 16px !important;
  }

  textarea {
    min-height: 112px;
  }

  :where(
    .dashboard-grid,.quant-grid,.topic-grid,.dense-topic-grid,
    .docs-layout,.docs-status,.performance-method-grid,.maic-performance-grid,
    .product-selection-grid,.ops-audit-grid,.topology-mesh,.entity-grid,
    .footer-telemetry,.core-workflow-state,.core-workflow-actions,
    .maic-v7-primary,.maic-v7-grid,.maic-v7-permissions,
    .authority-shell-grid,.authority-action-row,.pipeline-compact-grid,
    .live-visual-grid,.allocation-map,.access-grid,.library-grid,
    .protocol-grid,.trust-icons,.vf-lineage-logic
  ) {
    grid-template-columns: minmax(0,1fr) !important;
  }

  :where([style*="grid-template-columns"]) {
    grid-template-columns: minmax(0,1fr) !important;
  }

  :where(
    .hero-actions,.archive-action-group,.protocol-footer,.receipt-action-group,
    .pdf-confirm-buttons,.core-workflow-actions,.authority-action-row,
    .review-form .actions,.checkout-header,.receipt-summary-item
  ) {
    width: 100%;
    flex-wrap: wrap !important;
  }

  :where(
    .hero-actions,.protocol-footer,.receipt-action-group,.pdf-confirm-buttons,
    .core-workflow-actions,.authority-action-row
  ) > :where(button,.btn,a) {
    width: 100%;
    max-width: 100%;
  }

  :where(
    .tabs-container,.section-nav,.replay-selector,.maic-performance-legend,
    .replay-memory-badges,.footer-map-group
  ) {
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-inline: contain;
    scrollbar-width: none;
  }

  :where(
    .tabs-container,.section-nav,.replay-selector,.maic-performance-legend,
    .replay-memory-badges
  )::-webkit-scrollbar {
    display: none;
  }

  :where(
    .detail-drawer,.ai-dd-drawer,.palette-shell,.protocol-shell,
    .maic-entry-card,.maic-routing-shell,.friction-modal,.pdf-preview-shell,
    #copilot-widget,.mode-menu-dropdown,.maic-v9564-legacy-topology-modal
  ) {
    width: calc(100vw - 16px) !important;
    max-width: calc(100vw - 16px) !important;
    max-height: calc(100dvh - 16px) !important;
    box-sizing: border-box !important;
    overflow: auto !important;
    overscroll-behavior: contain;
  }

  :where(.review-modal .review-form,.review-form) {
    width: calc(100vw - 24px) !important;
    max-width: calc(100vw - 24px) !important;
    max-height: calc(100dvh - 24px) !important;
    overflow: auto !important;
    overscroll-behavior: contain;
  }

  :where(.site-header-inner,.seo-header,.header,.brand-container,.nav-actions) {
    min-width: 0 !important;
    max-width: 100% !important;
  }

  :where(.nav-actions,.seo-lang-switch,.archive-review-header) {
    flex-wrap: wrap !important;
  }

  :where(.phase-rail) {
    display: none !important;
  }

  :where(.topology-node,.mesh-node,.entity-block,.product-card,.ops-evidence-card) {
    width: 100% !important;
    max-width: 100% !important;
  }

  :where(.maic-performance-chart,.replay-stage,.replay-shell,.allocation-map) {
    max-width: 100% !important;
    overflow: hidden;
  }

  :where(.kicker,.eyebrow,[class*="badge"],[class*="tag"],.status-indicator,.vip-tag) {
    white-space: normal !important;
  }

  :where(#copilot-trigger,.ai-dd-launcher) {
    right: max(12px,env(safe-area-inset-right)) !important;
    bottom: max(12px,env(safe-area-inset-bottom)) !important;
  }

  :where(.site-footer,.seo-footer,footer) {
    padding-left: max(14px,env(safe-area-inset-left));
    padding-right: max(14px,env(safe-area-inset-right));
  }
}

@media (max-width: 430px) {
  :where(
    .maic-performance-metrics,#authority-oos-metric-grid,#authority-oos-yearly-grid,
    #authority-oos-adverse-grid,.authority-oos-event-detail-grid,
    .footer-site-map,.footer-map-group
  ) {
    grid-template-columns: minmax(0,1fr) !important;
  }

  :where(.footer-map-group) {
    width: 100%;
    justify-content: flex-start;
  }

  :where(.footer-map-group > span) {
    width: 100%;
    text-align: left;
  }

  :where(.maic-performance-card,.panel,.surface,.card,.product-card,.ops-evidence-card) {
    padding-left: 12px !important;
    padding-right: 12px !important;
  }

  :where(.hero-section,.seo-hero,.aci-hero,.performance-public-hero) h1 {
    font-size: clamp(1.9rem,10vw,2.55rem) !important;
    line-height: 1.05;
  }

  :where(.topology-node,.mesh-node) {
    padding-left: 16px !important;
    padding-right: 16px !important;
  }

  .mobile-state-bar {
    max-width: 100vw;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
}

@media (pointer: coarse) and (max-width: 760px) {
  :where(button,.btn,[role="button"],.node-route,.topic-open-link,.nav-review) {
    min-height: 44px;
  }

  .maic-tooltip .tooltip-text {
    width: min(280px,calc(100vw - 24px)) !important;
    max-width: calc(100vw - 24px) !important;
  }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }
}
