/* Compact cross-module layout contract. Keeps navigation and local controls inside the viewport. */
:where(
  .mayak-quality-shell,
  .mayak-logistics-shell,
  .mayak-supply-shell,
  .mayak-equipment-shell,
  .mayak-sales-shell,
  .mayak-platform-shell,
  .mayak-workspace-shell,
  .company-structure-page
) {
  overflow-x: hidden;
}

#mayakAgentTree .mayak-agent-toolbar,
#mayakSupplyModule .supply-toolbar,
.project-production-chain-actions,
.project-composition-toolbar {
  flex-wrap: wrap !important;
  overflow-x: hidden !important;
}

:where(
  .quality-page,
  .logistics-page,
  .equipment-page,
  .sales-page,
  .mayak-module-page,
  .company-structure-management-content
) {
  min-width: 0;
}

:where(
  .quality-page,
  .logistics-page,
  .equipment-page,
  .sales-page
) {
  padding-inline: clamp(12px, 1.6vw, 22px);
  padding-top: clamp(12px, 1.4vw, 20px);
}

:where(
  .quality-nav,
  .logistics-nav,
  .equipment-tabs,
  .supply-tabs,
  .sales-section-nav,
  .mayak-module-tabs,
  .mayak-profile-tabs,
  .mayak-work-view-tabs,
  .mayak-warehouse-tabs,
  .company-structure-management-tabs,
  .company-structure-modebar > div,
  .company-structure-object-types
) {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  max-width: 100%;
  overflow-x: hidden;
  scrollbar-width: none;
}

:where(
  .quality-nav,
  .logistics-nav,
  .equipment-tabs,
  .supply-tabs,
  .sales-section-nav,
  .mayak-module-tabs,
  .company-structure-management-tabs,
  .company-structure-object-types
)::-webkit-scrollbar {
  display: none;
}

:where(
  .quality-nav,
  .logistics-nav,
  .equipment-tabs,
  .supply-tabs,
  .sales-section-nav,
  .mayak-module-tabs,
  .company-structure-management-tabs,
  .company-structure-object-types
) > :where(button, a, span) {
  flex: 0 1 auto;
  max-width: 100%;
}

/* Lazy module styles are appended after the shell styles; keep the navigation contract authoritative. */
#mayakQualityModule .quality-nav,
#mayakLogisticsModule .logistics-nav,
#mayakSupplyModule .supply-tabs,
#mayakEquipmentModule .equipment-tabs,
#mayakSalesModule .sales-section-nav,
#mayakWorkspaceModules .mayak-module-tabs,
.company-structure-page .company-structure-management-tabs,
.company-structure-page .company-structure-object-types,
.company-structure-page > .company-structure-modebar > div,
.company-structure-page .company-structure-inspector-tabs,
.company-structure-page.is-map-builder .company-structure-tools,
.company-structure-page.is-map-builder .company-structure-lensbar > div {
  flex-wrap: wrap !important;
  overflow-x: hidden !important;
}

/* Compact strips: controls reflow instead of creating a second, horizontal page. */
:where(
  .mayak-agent-toolbar,
  .audit-journal-stats,
  .mayak-widget-presets,
  .mayak-role-scope,
  .mayak-role-news-filter-options,
  .redesign-attention-filters,
  .redesign-help-filters,
  .project-production-chain-actions,
  .project-composition-toolbar,
  .mayak-task-editor-tabs,
  .mayak-calendar-options,
  .mayak-work-filter-top,
  .mayak-work-filter-primary,
  .mayak-work-filter-footer,
  .mayak-work-header .mayak-module-actions,
  .mayak-inbound-navigation,
  .mayak-stock-navigation,
  .mayak-storage-navigation,
  .mayak-storage-subnav,
  .mayak-wtask-secondary
) {
  flex-wrap: wrap;
  max-width: 100%;
  overflow-x: hidden;
  white-space: normal;
}

body.has-redesign-ui :is(
  .mayak-metric-grid.mayak-work-metrics,
  .mayak-work-filter-top,
  .mayak-work-filter-primary,
  .mayak-work-filter-footer,
  .mayak-work-header .mayak-module-actions,
  .mayak-module-tabs.mayak-work-view-tabs,
  .mayak-task-editor-tabs
) {
  flex-wrap: wrap !important;
  min-width: 0 !important;
  overflow-x: hidden !important;
  white-space: normal !important;
}

body.has-redesign-ui .mayak-module-tabs.mayak-work-view-tabs {
  grid-template-columns: repeat(auto-fit, minmax(86px, 1fr)) !important;
}

body.has-redesign-ui .mayak-work-filter-top > *,
body.has-redesign-ui .mayak-work-filter-primary > * {
  min-width: 0;
  max-width: 100%;
}

#mayakEquipmentModule[data-mayak-ui-version="2"] :is(
  .mayak-v2-equipment-tab-row,
  .mayak-v2-equipment-command-row,
  .equipment-header-actions
),
#mayakSalesModule[data-mayak-ui-version="2"] :is(
  .mayak-v2-sales-tab-row,
  .mayak-v2-sales-command-row,
  .sales-header > div:last-child
),
body.mayak-v2-warehouse-active :is(
  .mayak-v2-warehouse-command-row,
  .mayak-v2-warehouse-tab-row,
  .mayak-inbound-navigation,
  .mayak-stock-navigation,
  .mayak-storage-navigation,
  .mayak-wtask-secondary
) {
  flex-wrap: wrap !important;
  overflow-x: hidden !important;
}

#mayakSalesModule .sales-board-scroll,
#mayakSalesModule .sales-table-wrap {
  max-width: 100%;
  overflow-x: hidden !important;
}

#mayakSalesModule .sales-board {
  grid-auto-flow: row !important;
  grid-auto-columns: initial !important;
  grid-template-columns: repeat(auto-fit, minmax(min(250px, 100%), 1fr));
  width: 100% !important;
  min-width: 0 !important;
}

#mayakSalesModule .sales-table {
  width: 100%;
  min-width: 0 !important;
  table-layout: fixed;
}

#mayakSalesModule .sales-table :is(th, td) {
  min-width: 0;
  overflow-wrap: anywhere;
}

.company-structure-page.is-enterprise-mode > .company-structure-modebar,
.company-structure-phase2-toolbar {
  flex-wrap: wrap !important;
  overflow-x: hidden !important;
}

.company-structure-page .company-structure-map-summary,
#mayakSupplyModule .supply-summary {
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)) !important;
  overflow-x: hidden !important;
}

:where(
  .quality-module-actions,
  .logistics-module-actions,
  .equipment-module-actions,
  .sales-module-actions,
  .supply-toolbar,
  .mayak-toolbar,
  .mayak-module-actions,
  .mayak-warehouse-commandbar,
  .company-structure-header-actions
) {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
  min-width: 0;
  overflow-x: visible;
}

.supply-toolbar > :is(button, select, .supply-search),
.mayak-warehouse-commandbar > :is(button, form, span) {
  flex: 0 1 auto;
  min-width: 0;
}

.mayak-warehouse-commandbar > form {
  flex: 1 1 300px;
}

:where(
  .mayak-button.is-icon-only,
  .quality-button.is-icon-only,
  .logistics-button.is-icon-only,
  .equipment-button.is-icon-only,
  .sales-button.is-icon,
  .supply-button.is-icon-only,
  .company-structure-button.is-icon-only,
  [data-module-action="refresh"].is-icon-only
) {
  width: 34px;
  min-width: 34px;
  min-height: 34px;
  padding: 0;
  flex: 0 0 34px;
  align-items: center;
  justify-content: center;
}

:where(
  .mayak-button.is-icon-only,
  .quality-button.is-icon-only,
  .logistics-button.is-icon-only,
  .equipment-button.is-icon-only,
  .sales-button.is-icon,
  .supply-button.is-icon-only,
  .company-structure-button.is-icon-only
) svg {
  width: 17px;
  height: 17px;
}

:where(
  .quality-header,
  .logistics-header,
  .equipment-header,
  .sales-header,
  .mayak-panel-header,
  .company-structure-management-content > header
) {
  min-width: 0;
  gap: 12px;
}

:where(
  .quality-header,
  .logistics-header,
  .equipment-header,
  .sales-header,
  .mayak-panel-header,
  .company-structure-management-content > header
) > * {
  min-width: 0;
}

:where(
  .quality-panel,
  .logistics-panel,
  .equipment-panel,
  .sales-panel,
  .mayak-module-panel,
  .company-structure-management-content,
  .company-structure-management-content article,
  .company-structure-management-content section
) :where(p, small, strong, dd, td, th, label, button) {
  overflow-wrap: anywhere;
}

.mayak-profile-access-modules {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  max-width: 100%;
  overflow-x: visible;
}

.company-structure-object-types {
  margin-bottom: 10px;
  overflow: visible;
}

.company-structure-management-tabs {
  gap: 3px;
  padding-block: 6px;
}

/* Structure registries keep every field visible by shrinking and wrapping rows, not the page. */
.company-structure-page .company-structure-registry-table,
.company-structure-page .company-structure-mapping-list,
.company-structure-page .company-structure-diagnostic-table {
  max-width: 100%;
  min-width: 0 !important;
  overflow-x: hidden !important;
}

.company-structure-page .company-structure-registry-table > div {
  grid-template-columns: repeat(5, minmax(88px, 1fr)) !important;
  min-width: 0 !important;
  gap: 6px;
}

.company-structure-page .company-structure-registry-table.is-relationships > div {
  grid-template-columns: repeat(6, minmax(76px, 1fr)) !important;
}

.company-structure-page .company-structure-mapping-list > div {
  grid-template-columns: minmax(110px, 1fr) 20px minmax(110px, 1fr) minmax(160px, 1.2fr) !important;
  min-width: 0 !important;
}

.company-structure-page .company-structure-diagnostic-table > div {
  grid-template-columns: minmax(64px, .7fr) repeat(2, minmax(78px, 1fr)) minmax(120px, 1.5fr) repeat(3, minmax(72px, 1fr)) !important;
  min-width: 0 !important;
}

.company-structure-page .company-structure-export-sample dl {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 4px;
  margin: 0;
  padding: 7px;
  border-radius: 7px;
  background: var(--cs-builder-surface-soft, var(--redesign-bg));
}

.company-structure-page .company-structure-export-sample dl > div {
  min-width: 0;
}

.company-structure-page .company-structure-export-sample :is(dt, dd) {
  margin: 0;
  overflow-wrap: anywhere;
}

.company-structure-page .company-structure-export-sample dt {
  color: var(--cs-builder-muted, var(--company-structure-muted));
  font-size: 8px;
}

.company-structure-page .company-structure-export-sample dd {
  color: var(--cs-builder-text, var(--company-structure-text));
  font-size: 9px;
  font-weight: 700;
}

.company-structure-management-tabs button,
.company-structure-modebar button {
  min-height: 32px;
  padding: 5px 10px;
}

.company-structure-button[data-cs-membership-access-reload],
.company-structure-button[data-cs-phase2-refresh-diagnostics] {
  width: 34px;
  min-width: 34px;
  min-height: 34px;
}

/* Company register: layout-only safeguards; no data or interaction changes. */
.company-directory-workspace > .companies-workspace.is-company-directory,
.company-directory-workspace > .companies-workspace.is-company-directory > *,
.company-directory-workspace > .companies-workspace.is-company-directory .company-panel-head,
.company-directory-workspace > .companies-workspace.is-company-directory .company-directory-filters {
  min-width: 0;
}

.company-directory-workspace > .companies-workspace.is-company-directory .company-panel-head,
.company-directory-workspace > .companies-workspace.is-company-directory .company-directory-filters {
  align-items: center;
  gap: 6px;
}

.company-directory-workspace > .companies-workspace.is-company-directory .company-panel-head > *,
.company-directory-workspace > .companies-workspace.is-company-directory .company-directory-filters > * {
  max-width: 100%;
}

:where(
  .quality-layer,
  .logistics-layer,
  .equipment-dialog-layer,
  .sales-dialog-layer,
  .mayak-dialog-layer,
  .company-structure-dialog-layer
) :where(.quality-drawer, .logistics-drawer, .equipment-dialog, .sales-dialog, .mayak-dialog, .company-structure-dialog) {
  max-width: min(100%, 720px);
  max-height: calc(100dvh - 24px);
  overflow: auto;
}

@media (max-width: 920px) {
  :where(
    .quality-header,
    .logistics-header,
    .equipment-header,
    .sales-header,
    .mayak-panel-header,
    .company-structure-management-content > header
  ) {
    flex-wrap: wrap;
  }

  :where(
    .quality-module-actions,
    .logistics-module-actions,
    .equipment-module-actions,
    .sales-module-actions,
    .supply-toolbar,
    .mayak-warehouse-commandbar,
    .company-structure-header-actions
  ) {
    justify-content: flex-start;
  }
}

@media (max-width: 640px) {
  :where(
    .quality-page,
    .logistics-page,
    .equipment-page,
    .sales-page,
    .supply-workbench,
    .mayak-module-page
  ) {
    padding-inline: 10px;
  }

  .mayak-warehouse-commandbar > form,
  .supply-toolbar .supply-search {
    flex-basis: 100%;
  }

  .company-structure-page .company-structure-registry-table > div,
  .company-structure-page .company-structure-registry-table.is-relationships > div,
  .company-structure-page .company-structure-mapping-list > div,
  .company-structure-page .company-structure-diagnostic-table > div {
    grid-template-columns: minmax(0, 1fr) !important;
  }

  .company-structure-page .company-structure-mapping-list > div > :nth-child(2) {
    display: none;
  }
}
