/* BI WA Enterprise UI — UI-6
   Responsive consolidation. Rules remain bounded to the certified ADM shell,
   Viewer and their owned overlays; saved report geometry is never rewritten. */

body:not(.viewer-mode) #appShell.biwa-enterprise-ui,
body:not(.viewer-mode) #appShell.biwa-enterprise-ui > .main,
body:not(.viewer-mode) #appShell.biwa-enterprise-ui > .main > .tab {
  min-width: 0;
}

body:not(.viewer-mode) #appShell.biwa-enterprise-ui :is(h1, h2, h3, h4, strong, b, label, .sub, .mini-help),
body.viewer-mode #onlinePortalShell :is(h1, h2, h3, strong, b, label, .online-portal-report-name) {
  overflow-wrap: anywhere;
}

body:not(.viewer-mode) #appShell.biwa-enterprise-ui :is(input, select, textarea),
body.viewer-mode #onlinePortalShell :is(input, select, textarea) {
  max-width: 100%;
}

body:not(.viewer-mode) #appShell.biwa-enterprise-ui :is(.result, .visual-table-wrap, .matrix-scroll, pre, code),
body.viewer-mode #onlinePortalShell :is(.visual-table-wrap, .matrix-scroll, pre, code) {
  max-width: 100%;
  overflow: auto;
}

/* Visualização: o viewport externo deve possuir os dois eixos de navegação. */
body:not(.viewer-mode) #appShell.biwa-enterprise-ui #tablesTab .table-view-result > .visual-table-wrap {
  overflow: visible;
}

body:not(.viewer-mode) #profileModal .biwa-modal__card,
body.viewer-mode #profileModal .biwa-modal__card {
  max-height: calc(100dvh - 32px);
}

body:not(.viewer-mode) #profileModal .biwa-modal__body,
body.viewer-mode #profileModal .biwa-modal__body {
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
}

body:not(.viewer-mode) #userAccountMenu,
body.viewer-mode #userAccountMenu {
  max-width: calc(100vw - 16px);
  max-height: calc(100dvh - 16px);
  overflow-y: auto;
}

body.viewer-mode #onlinePortalShell {
  min-width: 0;
  min-height: 100dvh;
  height: 100dvh;
}

body.viewer-mode #onlinePortalShell .online-portal-main,
body.viewer-mode #onlinePortalShell .online-portal-canvas-viewport,
body.viewer-mode #onlinePortalShell .online-portal-canvas-stage {
  min-width: 0;
  min-height: 0;
}

body.viewer-mode #dashboardFilterRuntimeModal .dashboard-filter-runtime-card {
  max-height: calc(100dvh - 16px);
}

body.viewer-mode #dashboardFilterRuntimeModal .dashboard-filter-runtime-heading {
  min-width: 0;
}

body.viewer-mode #dashboardFilterRuntimeModal .dashboard-filter-runtime-heading h3 {
  overflow-wrap: anywhere;
}

@media (max-width: 980px) {
  body:not(.viewer-mode) #appShell.biwa-enterprise-ui > .main {
    min-width: 0;
    padding: 12px 14px;
  }

  body:not(.viewer-mode) #appShell.biwa-enterprise-ui > .main > .tab > .page-head {
    min-width: 0;
    gap: 10px;
    padding: 11px 14px;
  }

  body:not(.viewer-mode) #appShell.biwa-enterprise-ui > .main > .tab > .page-head :is(.actions, .page-head-actions, .dashboard-refresh-actions) {
    min-width: 0;
    max-width: 100%;
  }

  body:not(.viewer-mode) #appShell.biwa-enterprise-ui #settingsTab .settings-tabs {
    flex-wrap: nowrap;
    max-width: 100%;
    overflow-x: auto;
    overflow-y: hidden;
    overscroll-behavior-inline: contain;
    scrollbar-width: thin;
  }

  body:not(.viewer-mode) #appShell.biwa-enterprise-ui #settingsTab .settings-tab-btn {
    flex: 0 0 auto;
    min-height: 40px;
  }

  body:not(.viewer-mode) #appShell.biwa-enterprise-ui #schemaTab :is(.pbix-actions, .schema-actions, .actions),
  body:not(.viewer-mode) #appShell.biwa-enterprise-ui #onlineTab :is(.online-builder-actions, .actions),
  body:not(.viewer-mode) #appShell.biwa-enterprise-ui #historyTab :is(.history-actions, .actions) {
    flex-wrap: wrap;
    max-width: 100%;
  }

  body:not(.viewer-mode) #appShell.biwa-enterprise-ui #modelTab #modelSubtabs,
  body:not(.viewer-mode) #appShell.biwa-enterprise-ui #transformTab .transform-ribbon-tabs {
    max-width: 100%;
    overflow-x: auto;
    overflow-y: hidden;
    scrollbar-width: thin;
  }

  body:not(.viewer-mode) #appShell.biwa-enterprise-ui #connectionsTab #connectionDiagram,
  body:not(.viewer-mode) #appShell.biwa-enterprise-ui #transformTab #transformPreview {
    contain: layout paint;
  }

  body.viewer-mode #onlinePortalShell .online-portal-actions,
  body.viewer-mode #onlinePortalShell .online-portal-filter-summary {
    max-width: 100%;
    overscroll-behavior-inline: contain;
  }
}

@media (max-width: 768px) {
  body:not(.viewer-mode) #appShell.biwa-enterprise-ui > .main {
    padding: 10px 12px;
  }

  body:not(.viewer-mode) #appShell.biwa-enterprise-ui > .main > .tab > .page-head {
    align-items: flex-start;
    border-radius: 12px;
  }

  body:not(.viewer-mode) #appShell.biwa-enterprise-ui > .main > .tab > .page-head .btn,
  body:not(.viewer-mode) #appShell.biwa-enterprise-ui > .main > .tab > .page-head button {
    min-height: 40px;
  }

  body:not(.viewer-mode) #appShell.biwa-enterprise-ui #homeTab :is(.biwa-home-grid, .home-widget-grid, .biwa-home-editor-grid) {
    grid-template-columns: minmax(0, 1fr);
  }

  body:not(.viewer-mode) #appShell.biwa-enterprise-ui #tablesTab #tableFilterSidebar {
    width: 100%;
    max-height: min(360px, 48dvh);
  }

  body:not(.viewer-mode) #appShell.biwa-enterprise-ui #modelTab :is(.model-topbar, .model-section-head),
  body:not(.viewer-mode) #appShell.biwa-enterprise-ui #connectionsTab .page-head-dark,
  body:not(.viewer-mode) #appShell.biwa-enterprise-ui #transformTab .transform-topbar {
    align-items: flex-start;
    flex-wrap: wrap;
  }

  body:not(.viewer-mode) #appShell.biwa-enterprise-ui #connectionsTab .page-head-dark .actions,
  body:not(.viewer-mode) #appShell.biwa-enterprise-ui #transformTab .transform-topbar .actions {
    width: 100%;
    max-width: 100%;
    overflow-x: auto;
    flex-wrap: nowrap;
    scrollbar-width: thin;
  }

  body:not(.viewer-mode) #appShell.biwa-enterprise-ui #connectionsTab .page-head-dark .actions > *,
  body:not(.viewer-mode) #appShell.biwa-enterprise-ui #transformTab .transform-topbar .actions > * {
    flex: 0 0 auto;
  }

  body:not(.viewer-mode) #appShell.biwa-enterprise-ui #reportDesignerShell,
  body:not(.viewer-mode) #appShell.biwa-enterprise-ui #reportDesignerShell.visuals-collapsed,
  body:not(.viewer-mode) #appShell.biwa-enterprise-ui #reportDesignerShell.data-collapsed,
  body:not(.viewer-mode) #appShell.biwa-enterprise-ui #reportDesignerShell.visuals-collapsed.data-collapsed {
    grid-template-columns: minmax(0, 1fr) !important;
  }

  body:not(.viewer-mode) #appShell.biwa-enterprise-ui #sqlTab #visualizationsPane:not(.collapsed) {
    position: fixed;
    z-index: 40;
    top: 8px;
    bottom: 8px;
    left: 0;
    right: auto;
    width: min(280px, calc(100vw - 52px));
    height: auto;
    transform: translateX(calc(-100% + 44px));
    transition: transform .16s ease;
  }

  body:not(.viewer-mode) #appShell.biwa-enterprise-ui #sqlTab #dataPane:not(.collapsed) {
    position: fixed;
    z-index: 40;
    top: 8px;
    right: 0;
    bottom: 8px;
    left: auto;
    width: min(280px, calc(100vw - 52px));
    height: auto;
    transform: translateX(calc(100% - 44px));
    transition: transform .16s ease;
  }

  body:not(.viewer-mode) #appShell.biwa-enterprise-ui #sqlTab #visualizationsPane:not(.collapsed):focus-within,
  body:not(.viewer-mode) #appShell.biwa-enterprise-ui #sqlTab #dataPane:not(.collapsed):focus-within {
    transform: translateX(0);
  }

  body:not(.viewer-mode) #appShell.biwa-enterprise-ui #sqlTab #visualizationsPane:not(.collapsed):not(:focus-within) > :not(.pane-title),
  body:not(.viewer-mode) #appShell.biwa-enterprise-ui #sqlTab #dataPane:not(.collapsed):not(:focus-within) > :not(.pane-title) {
    visibility: hidden;
  }

  body:not(.viewer-mode) #appShell.biwa-enterprise-ui #sqlTab #visualizationsPane:not(.collapsed):not(:focus-within) .pane-title > :not(.pane-collapse-btn),
  body:not(.viewer-mode) #appShell.biwa-enterprise-ui #sqlTab #dataPane:not(.collapsed):not(:focus-within) .pane-title > :not(.pane-collapse-btn) {
    visibility: hidden;
  }

  body:not(.viewer-mode) #appShell.biwa-enterprise-ui #reportCanvasViewport {
    width: 100%;
    min-width: 0;
  }

  body.viewer-mode #dashboardFilterRuntimeModal {
    align-items: stretch;
    padding: 8px;
  }

  body.viewer-mode #dashboardFilterRuntimeModal .dashboard-filter-runtime-card {
    display: grid;
    grid-template-rows: auto minmax(0, 1fr) auto;
    width: calc(100vw - 16px) !important;
    max-width: calc(100vw - 16px) !important;
    min-width: 0;
    max-height: calc(100dvh - 16px);
    overflow: hidden;
  }

  body.viewer-mode #dashboardFilterRuntimeModal .dashboard-filter-layout-viewport {
    width: 100%;
    min-width: 0;
    min-height: 0;
    max-height: none;
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior: contain;
  }

  body.viewer-mode #dashboardFilterRuntimeModal .dashboard-filter-layout-canvas {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
    width: 100% !important;
    height: auto !important;
    min-width: 0;
    padding: 2px;
  }

  body.viewer-mode #dashboardFilterRuntimeModal .dashboard-filter-layout-canvas > .dashboard-filter-field {
    position: relative !important;
    inset: auto !important;
    width: auto !important;
    height: auto !important;
    min-height: 92px;
    transform: none !important;
  }

  body.viewer-mode #dashboardFilterRuntimeModal .dashboard-filter-runtime-actions {
    position: relative;
    z-index: 2;
    flex-wrap: wrap;
  }

  body:not(.viewer-mode) #profileModal .biwa-modal__card,
  body.viewer-mode #profileModal .biwa-modal__card {
    display: grid;
    grid-template-rows: auto minmax(0, 1fr) auto;
    max-height: calc(100dvh - 16px);
  }
}

@media (max-width: 430px) {
  body:not(.viewer-mode) #appShell.biwa-enterprise-ui > .main {
    padding: 8px;
  }

  body:not(.viewer-mode) #appShell.biwa-enterprise-ui > .main > .tab > .page-head {
    margin-bottom: 10px;
    padding: 9px 10px;
  }

  body:not(.viewer-mode) #appShell.biwa-enterprise-ui > .main > .tab > .page-head h2 {
    font-size: 17px;
  }

  body:not(.viewer-mode) #appShell.biwa-enterprise-ui #settingsTab .settings-panel,
  body:not(.viewer-mode) #appShell.biwa-enterprise-ui #schemaTab :is(.panel, .biwa-panel),
  body:not(.viewer-mode) #appShell.biwa-enterprise-ui #onlineTab :is(.panel, .biwa-panel) {
    min-width: 0;
    padding-right: 12px;
    padding-left: 12px;
  }

  body:not(.viewer-mode) #appShell.biwa-enterprise-ui #tablesTab .page-head-actions {
    width: 100%;
    min-width: 0;
    flex-wrap: wrap;
  }

  body:not(.viewer-mode) #appShell.biwa-enterprise-ui #tablesTab .page-head-actions #tablesSelect {
    flex: 1 1 160px;
    min-width: 0;
    width: auto;
  }

  body:not(.viewer-mode) #appShell.biwa-enterprise-ui #tablesTab .page-head-actions #reloadTableBtn {
    flex: 0 0 auto;
    min-width: 104px;
    white-space: nowrap;
  }

  body:not(.viewer-mode) #appShell.biwa-enterprise-ui #modelTab #modelSubtabs > *,
  body:not(.viewer-mode) #appShell.biwa-enterprise-ui #transformTab .transform-ribbon-tabs > * {
    flex: 0 0 auto;
    min-height: 40px;
  }

  body:not(.viewer-mode) #appShell.biwa-enterprise-ui #connectionsTab #connectionDiagram {
    min-height: min(520px, 62dvh);
  }

  body:not(.viewer-mode) #appShell.biwa-enterprise-ui #transformTab #transformPreview {
    min-height: min(300px, 42dvh);
  }

  body:not(.viewer-mode) #appShell.biwa-enterprise-ui #transformTab #transformSourceSelect {
    min-height: 40px;
  }

  body:not(.viewer-mode) #appShell.biwa-enterprise-ui .powerbi-editor-head .editor-main-actions {
    width: 100%;
    max-width: 100%;
    overflow-x: auto;
    flex-wrap: nowrap;
    scrollbar-width: thin;
  }

  body:not(.viewer-mode) #appShell.biwa-enterprise-ui .powerbi-editor-head .editor-main-actions > * {
    flex: 0 0 auto;
  }

  body.viewer-mode #onlinePortalShell .online-portal-title strong,
  body.viewer-mode #onlinePortalShell .online-portal-report-name {
    max-width: 100%;
    white-space: normal;
    overflow-wrap: anywhere;
  }

  body.viewer-mode #onlinePortalShell .online-portal-actions :is(button, select),
  body.viewer-mode #onlinePortalShell .online-portal-nav-item {
    min-height: 40px;
  }

  body.viewer-mode #dashboardFilterRuntimeModal .dashboard-filter-layout-canvas {
    grid-template-columns: minmax(0, 1fr);
  }

  body.viewer-mode #dashboardFilterRuntimeModal .dashboard-filter-runtime-actions .btn {
    min-height: 42px;
  }

  body:not(.viewer-mode) #profileModal,
  body.viewer-mode #profileModal {
    padding: 8px;
  }

  body:not(.viewer-mode) #profileModal .biwa-modal__card,
  body.viewer-mode #profileModal .biwa-modal__card {
    width: calc(100vw - 16px);
    max-width: calc(100vw - 16px);
  }
}

/* Short landscape screens need the same bounded filter workspace as phones. */
@media (max-height: 520px) and (orientation: landscape) {
  body.viewer-mode #dashboardFilterRuntimeModal {
    align-items: stretch;
    padding: 8px;
  }

  body.viewer-mode #dashboardFilterRuntimeModal .dashboard-filter-runtime-card {
    display: grid;
    grid-template-rows: auto minmax(0, 1fr) auto;
    width: calc(100vw - 16px) !important;
    max-width: calc(100vw - 16px) !important;
    min-width: 0;
    max-height: calc(100dvh - 16px);
    overflow: hidden;
  }

  body.viewer-mode #dashboardFilterRuntimeModal .dashboard-filter-layout-viewport {
    width: 100%;
    min-width: 0;
    min-height: 0;
    max-height: none;
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior: contain;
  }

  body.viewer-mode #dashboardFilterRuntimeModal .dashboard-filter-layout-canvas {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
    width: 100% !important;
    height: auto !important;
    min-width: 0;
    padding: 2px;
  }

  body.viewer-mode #dashboardFilterRuntimeModal .dashboard-filter-layout-canvas > .dashboard-filter-field {
    position: relative !important;
    inset: auto !important;
    width: auto !important;
    height: auto !important;
    min-height: 92px;
    transform: none !important;
  }

  body.viewer-mode #dashboardFilterRuntimeModal .dashboard-filter-runtime-actions {
    position: relative;
    z-index: 2;
    flex-wrap: wrap;
  }
}
