/* Os editores distribuem a altura disponivel; somente colecoes rolam. */
#layout-editor[open], #map-editor[open] {
  height:min(820px,calc(100dvh - 32px));
  max-height:calc(100dvh - 32px);
  overflow:hidden;
}
#layout-editor[open] { height:calc(100dvh - 32px); }
#layout-editor .editor-header { min-height:56px; padding-block:8px; }
#layout-editor .wizard-toolbar { margin:10px 0 8px; }
#layout-editor .section-disclosure>.section-disclosure-summary { min-height:40px; padding-block:4px; }
#layout-editor .editor-content, #map-editor .editor-content {
  display:flex; flex-direction:column; min-height:0; overflow:hidden;
}
#layout-editor .wizard-toolbar, #map-editor .wizard-toolbar { flex:none; }
#layout-form, #layout-fields, #map-editor #map-fields {
  display:flex; flex-direction:column; flex:1; min-height:0; margin:0;
}
#layout-editor #layout-form {
  min-width:0; margin-bottom:12px; padding:12px;
  border:1px solid #dbe7f8; border-radius:8px;
}
/* A primeira etapa rola inteira quando os dados e os anexos excedem a altura. */
#layout-editor #layout-form:has(.layout-general-section:not([hidden])) {
  overflow-y:auto; overscroll-behavior:contain;
}
#layout-editor #layout-fields:has(>.layout-general-section:not([hidden])) { flex:1 0 auto; }
#layout-fields[hidden], #wizard-review[hidden] { display:none!important; }
#layout-fields:not(:has(>.editor-section:not([hidden]))) { display:none; }
#layout-fields:has(>.editor-section:not([hidden])) { gap:8px; }
#layout-fields>.editor-section { flex:none; margin:0; }
#layout-fields>.layout-files-section,
#layout-fields>[aria-labelledby="structure-heading"] { flex:1; min-height:0; overflow:hidden; }
#layout-fields:has(>.layout-general-section:not([hidden]))>.layout-files-section {
  flex:none; overflow:visible;
}
#layout-fields>[aria-labelledby="structure-heading"] { display:flex; flex-direction:column; }
#layout-fields>[aria-labelledby="structure-heading"]>.section-disclosure,
#layout-fields>[aria-labelledby="structure-heading"]>.section-disclosure>.section-disclosure-content,
#layout-editor .records-panel,
#layout-editor .records-panel>.section-disclosure,
#layout-editor .records-panel>.section-disclosure>.section-disclosure-content {
  display:flex; flex-direction:column; flex:1; min-height:0; overflow:hidden;
}
#layout-editor .section-disclosure-summary, #layout-editor .config-row { flex:none; }
#layout-editor .records-table { flex:1; min-height:0; overflow-y:auto; overflow-x:hidden; overscroll-behavior:contain; }
#layout-editor .records-table-head { position:static; }
/* Uma unica rolagem permite que os campos ocupem toda a colecao, sem teto de linhas. */
#layout-editor .records-panel { padding:0; border:0; border-radius:0; }
#layout-editor .records-panel>.group-heading { flex:none; margin:4px 0 8px; }
#layout-editor .field-table-scroll { max-height:none; overflow:visible; scrollbar-gutter:auto; }
#layout-editor .record-body { padding:8px 10px; }
#layout-editor .record-data-section { gap:4px; padding-bottom:8px; }
#layout-editor .record-data-section .record-grid { margin:0; }
#layout-editor .record-grid:has(.group-record[hidden]) { grid-template-columns:repeat(2,minmax(0,1fr)); }
#layout-editor .record-fields-section { gap:4px; }
#layout-editor .record-fields-heading .field-add-actions { margin:4px 0; }
#layout-editor .record-fields-heading .button { min-height:30px; padding-block:4px; }
#layout-editor .field-table-scroll { --field-row-height:36px; }
#layout-editor .field-table td { padding-block:2px; }
#layout-editor .field-table th:first-child,
#layout-editor .field-table td:first-child { width:58px; white-space:nowrap; }
#layout-editor .field-table input[data-field="order"] {
  padding-inline:2px; text-overflow:clip; font-variant-numeric:tabular-nums; appearance:textfield;
}
#layout-editor .field-table input[data-field="order"]::-webkit-inner-spin-button,
#layout-editor .field-table input[data-field="order"]::-webkit-outer-spin-button { margin:0; -webkit-appearance:none; }
#layout-editor .description-editor textarea { max-height:80px; resize:none; }
#wizard-review, #wizard-checks { display:flex; flex-direction:column; flex:1; min-height:0; }
#wizard-checks>.review-group { display:flex; flex-direction:column; flex:0 1 auto; min-height:0; }
#wizard-checks .section-disclosure { display:flex; flex-direction:column; flex:1; min-height:0; overflow:hidden; }
#wizard-checks .section-disclosure::details-content,
#layout-fields>[aria-labelledby="structure-heading"]>.section-disclosure::details-content,
#layout-editor .records-panel>.section-disclosure::details-content {
  display:flex; flex-direction:column; flex:1; min-height:0;
}
#wizard-checks .section-disclosure-content { flex:1; min-height:0; overflow-y:auto; overscroll-behavior:contain; }
#wizard-checks>.review-group:has(>.section-disclosure:not([open])) { flex:none; }
#map-editor #map-fields>[data-map-panel]:not([hidden]) { flex:1; min-height:0; overflow:hidden; }
/* Preserva os 5px externos do foco e permite alcancar todos os campos. */
#map-editor #map-fields>[data-map-panel="1"]:not([hidden]) {
  overflow-y:auto; padding:6px; overscroll-behavior:contain;
}
#map-editor .map-general-section { align-items:stretch; align-content:start; grid-template-rows:auto auto minmax(0,1fr); }
#map-editor .map-general-column, #map-editor .map-layout-documents,
#map-editor .map-layout-documents>.section-disclosure,
#map-editor .map-layout-documents .section-disclosure-content,
#map-editor #map-record-selection { display:flex; flex-direction:column; min-height:0; }
#map-editor .map-layout-documents, #map-editor #map-record-selection { flex:1; }
#map-editor .map-layout-documents>.section-disclosure { flex:1; }
#map-editor .map-layout-documents>.section-disclosure::details-content,
#map-editor [data-map-panel="3"]>.section-disclosure::details-content {
  display:flex; flex-direction:column; min-height:0;
}
#map-editor .map-layout-documents .layout-file-list, #map-editor #map-record-options,
#map-editor #map-issues { min-height:0; overflow-y:auto; overscroll-behavior:contain; }
#map-editor #map-record-options { flex:1; max-height:none; }
#map-editor #map-history, #map-editor #map-proposal { flex:none; max-height:20dvh; overflow-y:auto; }
#map-editor [data-map-panel="3"]>.section-disclosure { display:flex; flex-direction:column; max-height:100%; }
#map-editor [data-map-panel="3"] .section-disclosure-content { min-height:0; overflow-y:auto; }
#map-editor [data-map-panel="4"]:not([hidden]) { display:flex; flex-direction:column; gap:8px; }
#map-editor [data-map-panel="4"]>.editor-section-heading,
#map-editor [data-map-panel="4"]>label, #map-editor [data-map-panel="4"]>button { flex:none; }
#map-editor #map-test-result { min-height:0; overflow-y:auto; overscroll-behavior:contain; }
@media(max-height:800px) {
  #layout-editor .editor-header, #map-editor .editor-header { min-height:56px; padding:8px 18px; }
  #layout-editor .wizard-toolbar, #map-editor .wizard-toolbar { margin:10px 0 8px; }
  #layout-editor .section-disclosure>.section-disclosure-summary,
  #map-editor .section-disclosure>.section-disclosure-summary { min-height:40px; padding-block:4px; }
  #layout-editor .section-disclosure>.section-disclosure-content { padding-top:2px; padding-bottom:8px; }
  #layout-editor .config-row { margin-bottom:6px; }
  #layout-editor .description-editor textarea { min-height:54px; height:54px; }
  #layout-editor .review-row { min-height:34px; padding-block:4px; gap:8px; }
}
@media(max-width:700px) {
  #layout-editor[open], #map-editor[open] { height:calc(100dvh - 16px); max-height:calc(100dvh - 16px); }
  #layout-editor #layout-form { padding:8px; margin-bottom:8px; }
  #layout-editor .field-table th:first-child,
  #layout-editor .field-table td:first-child { width:46px; }
  #layout-editor .record-grid:has(.group-record[hidden]) { grid-template-columns:minmax(0,1fr); }
  #layout-editor .editor-section-heading { flex-wrap:wrap; }
  #layout-editor .records-panel>.group-heading { flex-wrap:nowrap; align-items:center; gap:8px; }
  #layout-editor .records-panel>.group-heading>div { min-width:0; }
  #layout-editor .records-panel>.group-heading .button { flex:none; padding-inline:6px; font-size:11px; }
  #layout-editor .records-table-head>span { min-width:0; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
  #map-editor .map-general-section { grid-template-rows:auto auto minmax(0,1fr); }
  #layout-editor .config-row { gap:6px; }
}

/* Mapeamentos ajusta Revisão e Finalização ao conteúdo; Layouts preserva a altura inicial. */
#map-editor.is-review[open]{height:fit-content;max-height:calc(100dvh - 32px)}
#map-editor.is-review .editor-content{flex:0 1 auto;max-height:calc(100dvh - 170px)}
#map-editor.is-review #map-fields{flex:0 1 auto}
#map-editor.is-review #map-validation{max-height:calc(100dvh - 390px);overflow-y:auto}

#map-editor.is-finalization[open]{height:fit-content;max-height:calc(100dvh - 32px)}
#map-editor.is-finalization .editor-content{flex:0 1 auto;overflow-y:auto}
#map-editor.is-finalization #map-fields{display:none}
.review-pendencies { margin-top:12px; padding-top:10px; border-top:1px solid #dce5f0; }
.review-pendencies h4 { margin:0 0 6px; font-size:13px; font-weight:600; }
.review-pendencies ul { margin:0; padding-left:20px; max-height:180px; overflow-y:auto; }
.review-pendencies li { margin:5px 0; font-size:12px; overflow-wrap:anywhere; }
@media(max-width:700px){#map-editor.is-finalization .editor-content{max-height:calc(100dvh - 170px)}}

/* O mesmo editor ocupa o workspace; confirmacoes e consultas continuam modais. */
.main-content.editor-page-open {
  display:flex; flex-direction:column; padding:0; overflow:hidden;
}
.editor-page-open > :is(#layout-list,#maps-list)[hidden] { display:none; }
.main-content.editor-page-open > :is(#layout-editor,#map-editor,#publication-editor)[open] {
  position:static; flex:1; width:100%; max-width:none; height:100%; max-height:none;
  min-height:0; margin:0; border:0; border-radius:0; box-shadow:none;
}
.editor-page-open > :is(#layout-editor,#map-editor,#publication-editor) > .editor-content {
  flex:1; min-height:0; max-height:none;
}
.editor-page-open > #map-editor.is-review #map-validation { max-height:none; }
.dashboard-shell:has(.editor-page-open) { height:100dvh; min-height:0; overflow:hidden; }
@media(max-width:760px) {
  .dashboard-shell:has(.editor-page-open) .workspace-body { grid-template-rows:minmax(0,1fr); }
}
