/* UI-4: densidade das ferramentas técnicas, exclusiva do ADM Enterprise. */
body:not(.viewer-mode) #appShell.biwa-enterprise-ui #modelTab,
body:not(.viewer-mode) #appShell.biwa-enterprise-ui #connectionsTab,
body:not(.viewer-mode) #appShell.biwa-enterprise-ui #transformTab {
  --ui4-gap: var(--biwa-space-2);
  --ui4-border: var(--biwa-color-border);
  --ui4-surface: var(--biwa-color-surface);
  --ui4-subtle: var(--biwa-color-surface-subtle);
  color: var(--biwa-color-text-primary);
  min-width: 0;
}

/* Modelo: o diagnóstico mantém destaque e rolagem própria; as listas ficam úteis no notebook. */
body:not(.viewer-mode) #appShell.biwa-enterprise-ui #modelTab .model-topbar {
  background: var(--biwa-shell-header-bg);
  border-radius: var(--biwa-shell-radius);
  padding: 11px 16px;
  margin-bottom: var(--ui4-gap);
  gap: 10px;
}
body:not(.viewer-mode) #appShell.biwa-enterprise-ui #modelTab .model-topbar-left h2 { font-size: 19px; }
body:not(.viewer-mode) #appShell.biwa-enterprise-ui #modelTab .model-stats { gap: 5px; }
body:not(.viewer-mode) #appShell.biwa-enterprise-ui #modelTab .model-stat { padding: 4px 8px; font-size: 11px; }
body:not(.viewer-mode) #appShell.biwa-enterprise-ui #modelTab #modelHealthContainer:not([style*="display: none"]),
body:not(.viewer-mode) #appShell.biwa-enterprise-ui #modelTab #modelErrorsContainer:not([style*="display: none"]) {
  max-height: 160px;
  overflow-y: auto;
  overflow-x: hidden;
  flex-shrink: 0;
  margin-bottom: var(--ui4-gap);
  scrollbar-width: thin;
}
body:not(.viewer-mode) #appShell.biwa-enterprise-ui #modelTab .model-section {
  border-color: var(--ui4-border);
  border-radius: var(--biwa-radius-md);
  box-shadow: var(--biwa-shadow-sm);
  margin-bottom: var(--ui4-gap);
}
body:not(.viewer-mode) #appShell.biwa-enterprise-ui #modelTab .model-section-head {
  padding: 8px 12px;
  background: var(--ui4-subtle);
  border-color: var(--ui4-border);
}
body:not(.viewer-mode) #appShell.biwa-enterprise-ui #modelTab .model-section #modelCardsGrid {
  padding: 9px;
  max-height: 151px;
  gap: 7px;
  grid-template-columns: repeat(auto-fill, minmax(194px, 1fr));
  scrollbar-width: thin;
}
body:not(.viewer-mode) #appShell.biwa-enterprise-ui #modelTab #modelCardsGrid:has(.model-card) {
  display: grid;
  align-content: start;
  justify-content: stretch;
  min-height: 0;
  border: 0;
  border-radius: 0;
  background: var(--ui4-surface);
  text-align: left;
}
body:not(.viewer-mode) #appShell.biwa-enterprise-ui #modelTab .model-card {
  padding: 9px;
  gap: 5px;
  border-color: var(--ui4-border);
  border-radius: var(--biwa-radius-md);
  box-shadow: var(--biwa-shadow-sm);
  transition: border-color .15s ease, box-shadow .15s ease;
}
body:not(.viewer-mode) #appShell.biwa-enterprise-ui #modelTab .model-card:hover {
  transform: none;
  border-color: var(--biwa-color-primary);
  box-shadow: var(--biwa-shadow-md);
}
body:not(.viewer-mode) #appShell.biwa-enterprise-ui #modelTab .model-card-icon { width: 28px; height: 28px; font-size: 12px; }
body:not(.viewer-mode) #appShell.biwa-enterprise-ui #modelTab .model-card-name { font-size: 12px; font-weight: 750; }
body:not(.viewer-mode) #appShell.biwa-enterprise-ui #modelTab .model-card-meta { font-size: 10px; gap: 3px; }
body:not(.viewer-mode) #appShell.biwa-enterprise-ui #modelTab .model-card-meta span { background: var(--ui4-subtle); padding: 1px 4px; }
body:not(.viewer-mode) #appShell.biwa-enterprise-ui #modelTab #modelSubtabs { margin-bottom: var(--ui4-gap); flex-wrap: nowrap; }
body:not(.viewer-mode) #appShell.biwa-enterprise-ui #modelTab .model-subtab { min-width: 0; min-height: 32px; padding: 5px 9px; }
body:not(.viewer-mode) #appShell.biwa-enterprise-ui #modelTab .model-subpanel-grid { min-width: 0; gap: var(--ui4-gap); }
body:not(.viewer-mode) #appShell.biwa-enterprise-ui #modelTab .model-subpanel-grid .panel {
  min-width: 0;
  border-color: var(--ui4-border);
  box-shadow: var(--biwa-shadow-sm);
}
body:not(.viewer-mode) #appShell.biwa-enterprise-ui #modelTab .model-subpanel-grid .panel-head { margin-bottom: 8px; }
body:not(.viewer-mode) #appShell.biwa-enterprise-ui #modelTab .model-subpanel-grid .model-list,
body:not(.viewer-mode) #appShell.biwa-enterprise-ui #modelTab .model-subpanel-grid .column-picker,
body:not(.viewer-mode) #appShell.biwa-enterprise-ui #modelTab .model-subpanel-grid .model-measure-cards { scrollbar-width: thin; }

/* Conexões: canvas recebe a primeira coluna flexível; painéis têm rolagem interna. */
body:not(.viewer-mode) #appShell.biwa-enterprise-ui #connectionsTab .page-head-dark { margin-bottom: var(--ui4-gap); padding: 10px 16px; }
body:not(.viewer-mode) #appShell.biwa-enterprise-ui #connectionsTab .page-head-dark h2 { font-size: 19px; }
body:not(.viewer-mode) #appShell.biwa-enterprise-ui #connectionsTab #connectionsLayout.connections-layout:not(.resources-collapsed):not(.relationship-collapsed) {
  grid-template-columns: minmax(0, 1fr) minmax(190px, 210px) minmax(220px, 245px) !important;
  gap: var(--ui4-gap);
  min-width: 0;
}
body:not(.viewer-mode) #appShell.biwa-enterprise-ui #connectionsTab #connectionsLayout .connections-panel,
body:not(.viewer-mode) #appShell.biwa-enterprise-ui #connectionsTab #connectionsLayout .connections-canvas-panel {
  padding: 10px;
  border-color: var(--ui4-border);
  border-radius: var(--biwa-radius-md);
  box-shadow: var(--biwa-shadow-sm);
  min-width: 0;
}
body:not(.viewer-mode) #appShell.biwa-enterprise-ui #connectionsTab #connectionsLayout .panel-head { margin-bottom: var(--ui4-gap); }
body:not(.viewer-mode) #appShell.biwa-enterprise-ui #connectionsTab #connectionsLayout .panel-head h3 { font-size: 13px; }
body:not(.viewer-mode) #appShell.biwa-enterprise-ui #connectionsTab #connectionResourceList {
  min-height: 0;
  max-height: none;
  overflow-y: auto;
  overflow-x: hidden;
  scrollbar-width: thin;
}
body:not(.viewer-mode) #appShell.biwa-enterprise-ui #connectionsTab .connection-resource-row { min-width: 0; padding: 5px 6px; gap: 5px; }
body:not(.viewer-mode) #appShell.biwa-enterprise-ui #connectionsTab #connectionDiagram {
  min-height: 0;
  max-height: none;
  padding: 8px;
  border-color: var(--biwa-color-border-strong);
  scrollbar-width: thin;
  overscroll-behavior: contain;
}
body:not(.viewer-mode) #appShell.biwa-enterprise-ui #connectionsTab #connRelationshipEdit {
  min-width: 0;
  overflow-y: auto;
  overflow-x: hidden;
  scrollbar-width: thin;
}
body:not(.viewer-mode) #appShell.biwa-enterprise-ui #connectionsTab .edit-rel-fields { gap: 6px; }
body:not(.viewer-mode) #appShell.biwa-enterprise-ui #connectionsTab .edit-rel-row { min-width: 0; }
body:not(.viewer-mode) #appShell.biwa-enterprise-ui #connectionsTab .edit-rel-row select { min-height: 32px; padding: 4px 7px; }
body:not(.viewer-mode) #appShell.biwa-enterprise-ui #connectionsTab .edit-rel-actions { flex-wrap: wrap; gap: 5px; }
body:not(.viewer-mode) #appShell.biwa-enterprise-ui #connectionsTab .edit-rel-actions .btn { min-height: 32px; padding: 5px 8px; }
body:not(.viewer-mode) #appShell.biwa-enterprise-ui #connectionsTab #connectionDiagram:fullscreen {
  padding: 12px;
  max-height: none;
  background: var(--ui4-surface);
}

/* Transformar: comandos densos, prévia flexível e etapas/consultas com scroll próprio. */
body:not(.viewer-mode) #appShell.biwa-enterprise-ui #transformTab .transform-shell {
  min-width: 0;
  height: calc(100vh - 48px);
  gap: var(--ui4-gap);
}
body:not(.viewer-mode) #appShell.biwa-enterprise-ui #transformTab .transform-topbar { padding: 9px 14px; gap: 8px; }
body:not(.viewer-mode) #appShell.biwa-enterprise-ui #transformTab .transform-topbar h2 { font-size: 19px; }
body:not(.viewer-mode) #appShell.biwa-enterprise-ui #transformTab .transform-ribbon {
  border-color: var(--ui4-border);
  border-radius: var(--biwa-radius-md);
  box-shadow: var(--biwa-shadow-sm);
}
body:not(.viewer-mode) #appShell.biwa-enterprise-ui #transformTab .transform-ribbon-head {
  padding: 5px 8px 0;
  gap: 8px;
  background: var(--ui4-subtle);
  border-color: var(--ui4-border);
}
body:not(.viewer-mode) #appShell.biwa-enterprise-ui #transformTab .transform-source-controls {
  flex: 0 1 420px;
  min-width: 0;
  grid-template-columns: minmax(160px, 1fr) 102px;
  gap: 6px;
  padding-bottom: 5px;
}
body:not(.viewer-mode) #appShell.biwa-enterprise-ui #transformTab .transform-source-controls .biwa-field { font-size: 10px; gap: 2px; }
body:not(.viewer-mode) #appShell.biwa-enterprise-ui #transformTab .transform-source-controls .biwa-control {
  min-height: 30px;
  height: 30px;
  padding: 4px 7px;
  font-size: 11px;
}
body:not(.viewer-mode) #appShell.biwa-enterprise-ui #transformTab .transform-ribbon-tabs { flex: 1 1 auto; }
body:not(.viewer-mode) #appShell.biwa-enterprise-ui #transformTab .transform-ribbon-tab {
  min-height: 31px;
  padding: 5px 8px 7px;
  font-size: 11px;
  color: var(--biwa-color-text-secondary);
}
body:not(.viewer-mode) #appShell.biwa-enterprise-ui #transformTab .transform-ribbon-tab.active { color: var(--biwa-color-primary-pressed); }
body:not(.viewer-mode) #appShell.biwa-enterprise-ui #transformTab .transform-ribbon-content { min-height: 0; padding: 6px 8px; }
body:not(.viewer-mode) #appShell.biwa-enterprise-ui #transformTab .transform-ribbon-panel { gap: 5px; }
body:not(.viewer-mode) #appShell.biwa-enterprise-ui #transformTab .transform-ribbon-panel .btn {
  min-height: 30px;
  padding: 5px 9px;
  font-size: 11px;
  line-height: 1.2;
}
body:not(.viewer-mode) #appShell.biwa-enterprise-ui #transformTab .transform-layout {
  min-width: 0;
  grid-template-columns: minmax(0, 1fr) minmax(252px, 290px) !important;
  gap: var(--ui4-gap);
}
body:not(.viewer-mode) #appShell.biwa-enterprise-ui #transformTab .transform-center,
body:not(.viewer-mode) #appShell.biwa-enterprise-ui #transformTab .transform-right {
  min-width: 0;
  min-height: 0;
  padding: 10px;
  border-color: var(--ui4-border);
  border-radius: var(--biwa-radius-md);
  box-shadow: var(--biwa-shadow-sm);
}
body:not(.viewer-mode) #appShell.biwa-enterprise-ui #transformTab #transformPreview {
  min-width: 0;
  min-height: 0;
  overflow: auto;
  scrollbar-width: thin;
}
body:not(.viewer-mode) #appShell.biwa-enterprise-ui #transformTab .transform-right {
  display: flex;
  flex-direction: column;
  gap: 5px;
  overflow: hidden;
}
body:not(.viewer-mode) #appShell.biwa-enterprise-ui #transformTab .transform-right h3 { margin: 0; font-size: 13px; }
body:not(.viewer-mode) #appShell.biwa-enterprise-ui #transformTab .transform-right .mini-help { margin: 0; font-size: 11px; line-height: 1.25; }
body:not(.viewer-mode) #appShell.biwa-enterprise-ui #transformTab #transformStepsList,
body:not(.viewer-mode) #appShell.biwa-enterprise-ui #transformTab #savedTransformsList {
  min-height: 48px;
  max-height: none;
  grid-template-columns: minmax(0, 1fr);
  overflow-y: auto;
  overflow-x: hidden;
  align-content: start;
  scrollbar-width: thin;
}
body:not(.viewer-mode) #appShell.biwa-enterprise-ui #transformTab #transformStepsList { flex: 1 1 34%; }
body:not(.viewer-mode) #appShell.biwa-enterprise-ui #transformTab #savedTransformsList { flex: 1 1 66%; }
body:not(.viewer-mode) #appShell.biwa-enterprise-ui #transformTab .step-compact { min-width: 0; max-width: 100%; }
body:not(.viewer-mode) #appShell.biwa-enterprise-ui #transformTab .step-compact-label {
  white-space: normal;
  overflow: visible;
  overflow-wrap: anywhere;
}
body:not(.viewer-mode) #appShell.biwa-enterprise-ui #transformTab .step-item {
  min-width: 0;
  padding: 6px;
  gap: 4px;
  border-color: var(--ui4-border);
  border-radius: var(--biwa-radius-sm);
  background: var(--ui4-subtle);
}
body:not(.viewer-mode) #appShell.biwa-enterprise-ui #transformTab .saved-transform-item {
  grid-template-columns: minmax(0, 1fr) auto auto;
}
body:not(.viewer-mode) #appShell.biwa-enterprise-ui #transformTab .saved-transform-item .step-title { min-width: 0; overflow-wrap: anywhere; font-size: 11px; }
body:not(.viewer-mode) #appShell.biwa-enterprise-ui #transformTab .saved-transform-item .icon-btn { width: 28px; min-width: 28px; height: 28px; }
body:not(.viewer-mode) #appShell.biwa-enterprise-ui #transformTab .transform-sql-details { flex: 0 0 auto; min-width: 0; }
body:not(.viewer-mode) #appShell.biwa-enterprise-ui #transformTab .transform-sql-details[open] textarea { max-height: 180px; overflow: auto; }

@media (max-width: 1180px) {
  body:not(.viewer-mode) #appShell.biwa-enterprise-ui #transformTab .transform-ribbon-head { align-items: stretch; flex-direction: column; }
  body:not(.viewer-mode) #appShell.biwa-enterprise-ui #transformTab .transform-source-controls { width: 100%; flex: none; }
  body:not(.viewer-mode) #appShell.biwa-enterprise-ui #transformTab .transform-ribbon-tabs { width: 100%; }
}
@media (max-width: 1220px) {
  body:not(.viewer-mode) #appShell.biwa-enterprise-ui #connectionsTab #connectionsLayout.connections-layout:not(.resources-collapsed):not(.relationship-collapsed) { grid-template-columns: minmax(0, 1fr) !important; }
  body:not(.viewer-mode) #appShell.biwa-enterprise-ui #transformTab .transform-shell { height: auto; min-height: calc(100vh - 48px); overflow: visible; }
  body:not(.viewer-mode) #appShell.biwa-enterprise-ui #transformTab .transform-layout { grid-template-columns: minmax(0, 1fr) !important; overflow: visible; }
  body:not(.viewer-mode) #appShell.biwa-enterprise-ui #transformTab .transform-right { min-height: 240px; max-height: 400px; }
}
@media (max-width: 1450px) and (min-width: 1221px) {
  body:not(.viewer-mode) #appShell.biwa-enterprise-ui #modelTab #modelHealthContainer:not([style*="display: none"]),
  body:not(.viewer-mode) #appShell.biwa-enterprise-ui #modelTab #modelErrorsContainer:not([style*="display: none"]) { max-height: 128px; }
  body:not(.viewer-mode) #appShell.biwa-enterprise-ui #modelTab .model-section #modelCardsGrid { max-height: 125px; }
}
