/*
 * Shared responsive safety layer.
 *
 * This file is injected after each page-specific stylesheet by the server.
 * Keep the rules structural and conservative: they protect small viewports
 * without changing the established desktop design of individual modules.
 */

html,
body {
  min-width: 0;
  max-width: 100%;
}

body {
  overflow-x: clip;
}

[data-public-header],
[data-public-footer],
main,
main > section,
main :where(article, aside, section, form, fieldset, div) {
  min-width: 0;
}

main :where(img, video, canvas) {
  max-width: 100%;
}

main :where(h1, h2, h3, h4) {
  max-width: 100%;
  overflow-wrap: anywhere;
  text-wrap: balance;
}

main :where(p, li, dd, figcaption, label, output) {
  overflow-wrap: anywhere;
  text-wrap: pretty;
}

main :where(pre, code, kbd, samp) {
  max-width: 100%;
  overflow-wrap: normal;
}

:where(
  .table-wrap,
  .table-container,
  .table-scroll,
  .people-table-wrap,
  .qms-table-wrap,
  .data-table-wrap,
  .results-table-wrap,
  .editorial-table-wrap,
  .survey-table-wrap
) {
  max-width: 100%;
  overflow-x: auto;
  overscroll-behavior-inline: contain;
  scrollbar-width: thin;
  -webkit-overflow-scrolling: touch;
}

:where(dialog, .modal-panel, .drawer-dialog, .sheet, .popover-panel) {
  max-width: calc(100vw - 24px);
  max-height: calc(100dvh - 24px);
  overscroll-behavior: contain;
}

@media (pointer: coarse) {
  :where(
    button,
    a.button,
    [role="button"],
    select,
    input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="file"]):not([type="hidden"])
  ) {
    min-height: 44px;
    touch-action: manipulation;
  }
}

@media (max-width: 980px) {
  :where(
    .sticky-sidebar,
    .filters-sidebar,
    .details-sidebar,
    .settings-sidebar,
    .editor-sidebar,
    .public-tool-sidebar
  ) {
    position: static;
    top: auto;
  }

  :where(.split-layout, .workbench-layout, .workspace-layout) {
    min-width: 0;
  }
}

@media (max-width: 760px) {
  [data-public-header] .site-header {
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
  }

  [data-public-header] .brand {
    min-height: 44px;
  }

  [data-public-header] .mobile-nav {
    max-height: calc(100dvh - 66px);
    overflow-y: auto;
    overscroll-behavior: contain;
    padding-bottom: max(14px, env(safe-area-inset-bottom));
  }

  [data-public-header] .mobile-nav a {
    min-height: 44px;
    display: flex;
    align-items: center;
    border-radius: 12px;
    white-space: normal;
  }

  [data-public-footer] nav a {
    min-height: 44px;
    display: flex;
    align-items: center;
  }

  main {
    max-width: 100%;
  }

  main :where(h1) {
    line-height: 1.02;
    letter-spacing: -.035em;
  }

  :where(
    .monitor-toolbar,
    .qms-toolbar,
    .access-toolbar,
    .audit-filter,
    .filter-toolbar,
    .form-toolbar
  ) {
    width: 100%;
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    align-items: stretch;
  }

  :where(
    .monitor-toolbar,
    .qms-toolbar,
    .access-toolbar,
    .audit-filter,
    .filter-toolbar,
    .form-toolbar
  ) > * {
    width: 100%;
    max-width: none;
    min-width: 0;
  }

  :where(
    .hero-actions,
    .row-actions,
    .result-actions,
    .form-actions,
    .modal-actions,
    .drawer-actions,
    .card-actions
  ) {
    max-width: 100%;
    flex-wrap: wrap;
  }

  :where(
    .hero-actions,
    .form-actions,
    .modal-actions,
    .drawer-actions
  ) > :where(button, .button, a) {
    max-width: 100%;
  }

  :where(dialog, .modal-panel, .drawer-dialog, .sheet) {
    width: calc(100vw - 16px);
    max-width: calc(100vw - 16px);
    max-height: calc(100dvh - 16px);
    margin: 8px;
  }

  :where(.toast-region, .notification-popover) {
    max-width: calc(100vw - 24px);
  }
}

@media (max-width: 520px) {
  :where(.container, .chrome-container) {
    max-width: 100%;
  }

  main :where(.button, button) {
    overflow-wrap: anywhere;
  }

  :where(.panel, .content-card, .module-card, .m3-card, .ui-card) {
    max-width: 100%;
  }
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }
}
