/* Shared field editor contract: stable columns, readable values, and one local scroll boundary. */
body.owner-shell-v1 :is(.cc-record-editor__field-rows, .knowledge-v2__custom-field-rows) {
  display: grid;
  gap: 8px;
  min-width: 0;
  max-width: 100%;
  max-height: min(58vh, 620px);
  overflow: auto;
  scrollbar-gutter: stable;
  overscroll-behavior: contain;
}

body.owner-shell-v1 :is(.cc-record-editor__field-row, .knowledge-v2__custom-field-row) {
  display: grid;
  grid-template-columns: minmax(150px, .8fr) minmax(280px, 2fr) minmax(130px, .55fr) auto;
  gap: 10px;
  align-items: end;
  min-width: 0;
  width: 100%;
  box-sizing: border-box;
}

/* The shared editor owns its geometry. A field must not jump to a different
   column model merely because it gains focus. */
body.owner-shell-v1 .knowledge-v2__custom-field-row:focus-within {
  grid-template-columns: minmax(150px, .8fr) minmax(280px, 2fr) minmax(130px, .55fr) auto;
}

body.owner-shell-v1 :is(.cc-record-editor__field-row, .knowledge-v2__custom-field-row) > * {
  min-width: 0;
}

body.owner-shell-v1 :is(.cc-record-editor__field-row, .knowledge-v2__custom-field-row) :is(input, select, textarea) {
  box-sizing: border-box;
  width: 100%;
  max-width: 100%;
  min-width: 0;
}

body.owner-shell-v1 :is(.cc-record-editor__field-row, .knowledge-v2__custom-field-row) textarea {
  min-height: 5.5rem;
  resize: both;
  overflow: auto;
}

body.owner-shell-v1 :is(.cc-record-editor__field-value, .knowledge-v2__custom-field-value) {
  min-width: 0;
  width: 100%;
}

/* Detail views keep long custom-field values readable instead of forcing them
   into the narrow second column used for compact metadata. */
body.owner-shell-v1 .knowledge-v2__metadata > .knowledge-v2__metadata-row--custom {
  grid-column: 1 / -1;
  grid-template-columns: minmax(120px, 180px) minmax(0, 1fr);
}

body.owner-shell-v1 .knowledge-v2__metadata > .knowledge-v2__metadata-row--custom dd {
  text-align: left;
  white-space: pre-wrap;
}

@media (max-width: 760px) {
  body.owner-shell-v1 :is(.cc-record-editor__field-rows, .knowledge-v2__custom-field-rows) {
    max-height: 62vh;
  }

  body.owner-shell-v1 :is(.cc-record-editor__field-row, .knowledge-v2__custom-field-row) {
    grid-template-columns: minmax(0, 1fr);
  }

  body.owner-shell-v1 .knowledge-v2__custom-field-row:focus-within {
    grid-template-columns: minmax(0, 1fr);
  }

  body.owner-shell-v1 :is(.cc-record-editor__field-row, .knowledge-v2__custom-field-row) > :is(.cc-record-editor__remove, .knowledge-v2__remove-field) {
    width: 100%;
  }

  body.owner-shell-v1 .knowledge-v2__metadata > .knowledge-v2__metadata-row--custom {
    grid-template-columns: minmax(0, 1fr);
  }
}
